ts-procedures 8.2.0 → 8.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.
- package/agent_config/bin/setup.mjs +2 -2
- package/agent_config/claude-code/.claude-plugin/plugin.json +1 -1
- package/agent_config/claude-code/agents/ts-procedures-architect.md +1 -1
- package/agent_config/claude-code/skills/ts-procedures/SKILL.md +348 -5
- package/agent_config/claude-code/skills/ts-procedures/api-reference.md +1 -1
- package/agent_config/lib/install-claude.mjs +4 -4
- package/docs/ai-agent-setup.md +5 -6
- package/package.json +1 -1
- package/agent_config/claude-code/skills/ts-procedures-kotlin/SKILL.md +0 -106
- package/agent_config/claude-code/skills/ts-procedures-review/SKILL.md +0 -48
- package/agent_config/claude-code/skills/ts-procedures-scaffold/SKILL.md +0 -50
- package/agent_config/claude-code/skills/ts-procedures-swift/SKILL.md +0 -119
- /package/agent_config/claude-code/skills/{ts-procedures-review → ts-procedures}/checklist.md +0 -0
- /package/agent_config/claude-code/skills/{ts-procedures-scaffold → ts-procedures}/templates/astro-catchall.md +0 -0
- /package/agent_config/claude-code/skills/{ts-procedures-scaffold → ts-procedures}/templates/client.md +0 -0
- /package/agent_config/claude-code/skills/{ts-procedures-scaffold → ts-procedures}/templates/hono.md +0 -0
- /package/agent_config/claude-code/skills/{ts-procedures-scaffold → ts-procedures}/templates/procedure.md +0 -0
- /package/agent_config/claude-code/skills/{ts-procedures-scaffold → ts-procedures}/templates/stream-procedure.md +0 -0
|
@@ -92,7 +92,7 @@ function setupClaude({ dryRun, check } = {}) {
|
|
|
92
92
|
// Mirror install-claude.mjs: copy every file under each source skill dir, plus the agent.
|
|
93
93
|
const claudeFiles = [];
|
|
94
94
|
const skillsSrc = join(AGENT_CONFIG_DIR, 'claude-code', 'skills');
|
|
95
|
-
for (const skill of ['ts-procedures'
|
|
95
|
+
for (const skill of ['ts-procedures']) {
|
|
96
96
|
const walk = (dir, prefix) => {
|
|
97
97
|
for (const entry of readdirSync(dir)) {
|
|
98
98
|
const full = join(dir, entry);
|
|
@@ -128,7 +128,7 @@ function setupClaude({ dryRun, check } = {}) {
|
|
|
128
128
|
console.log(` ${f}`);
|
|
129
129
|
}
|
|
130
130
|
console.log('');
|
|
131
|
-
console.log(' Skills: ts-procedures
|
|
131
|
+
console.log(' Skills: ts-procedures (use `/ts-procedures review <path>` and `/ts-procedures scaffold <type> <Name>`; Kotlin/Swift codegen reference included)');
|
|
132
132
|
console.log(' Agent: ts-procedures-architect (architecture planning)\n');
|
|
133
133
|
return false;
|
|
134
134
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-procedures",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
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
5
|
}
|
|
@@ -134,4 +134,4 @@ type AuthContext = { userId: string; requestId: string; db: Database }
|
|
|
134
134
|
|
|
135
135
|
## Next Steps
|
|
136
136
|
|
|
137
|
-
After planning, use `/ts-procedures
|
|
137
|
+
After planning, use `/ts-procedures scaffold <type> <Name>` to generate each procedure with correct patterns and tests.
|
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ts-procedures
|
|
3
|
-
description: "TypeScript RPC framework reference for ts-procedures — schema
|
|
4
|
-
|
|
3
|
+
description: "TypeScript RPC framework reference for ts-procedures — type-safe schema-validated procedures (TypeBox, AJV), error classes and taxonomy, HonoAppBuilder, SSE/streaming, and client code generation for TypeScript, Kotlin (Android/JVM, kotlinx-serialization), and Swift (iOS/macOS/Apple, Codable). Use when writing, reviewing, scaffolding, or debugging ts-procedures procedures, HTTP builders, schemas, error handling, or generated clients."
|
|
4
|
+
argument-hint: "[review <path> | scaffold <type> <Name>]"
|
|
5
|
+
allowed-tools: Read, Write, Edit, Grep, Glob
|
|
5
6
|
---
|
|
6
7
|
|
|
8
|
+
<!-- MAINTAINER NOTES (not part of the skill content):
|
|
9
|
+
1. Write/Edit are granted skill-wide because Scaffold Mode generates files. Claude Code
|
|
10
|
+
cannot scope allowed-tools per-mode within a single SKILL.md, so the write capability is
|
|
11
|
+
kept dormant by the File-write guard below — writes happen only when the literal first
|
|
12
|
+
word of $ARGUMENTS is `scaffold`. If the modes are ever split back into separate skills,
|
|
13
|
+
re-scope tools per skill accordingly.
|
|
14
|
+
2. The former standalone `ts-procedures-review` skill ran with `context: fork` and
|
|
15
|
+
`effort: high`. Those are skill-level settings that cannot be scoped to one mode, so
|
|
16
|
+
Review Mode now runs inline in the main context instead of a forked one. Review Mode
|
|
17
|
+
recovers isolation by suggesting a subagent for large reviews (see that section). -->
|
|
18
|
+
|
|
7
19
|
# ts-procedures Framework Reference
|
|
8
20
|
|
|
9
21
|
You are assisting a developer using **ts-procedures**, a TypeScript RPC framework that creates type-safe, schema-validated procedure calls with a single function definition. Always follow these rules when writing or reviewing code.
|
|
10
22
|
|
|
23
|
+
## Modes
|
|
24
|
+
|
|
25
|
+
This skill has three modes, selected by the **first whitespace-delimited word of `$ARGUMENTS`**:
|
|
26
|
+
|
|
27
|
+
| First word of `$ARGUMENTS` | Mode | What happens |
|
|
28
|
+
|----------------------------|------|--------------|
|
|
29
|
+
| *(empty)* | **Reference** | The framework knowledge below auto-loads. Read [patterns.md](patterns.md), [anti-patterns.md](anti-patterns.md), or [api-reference.md](api-reference.md) as needed. Kotlin/Swift client codegen have dedicated reference sections lower down. |
|
|
30
|
+
| `review` | **Review Mode** | Audit the file/dir at the path argument against [checklist.md](checklist.md). Read-only. See the **Review Mode** section below. |
|
|
31
|
+
| `scaffold` | **Scaffold Mode** | Generate implementation + test files from [templates/](templates). **Writes files.** See the **Scaffold Mode** section below. |
|
|
32
|
+
|
|
33
|
+
**File-write guard.** This skill writes files in **Scaffold Mode only**. Scaffold Mode is entered **if and only if** the literal first word of `$ARGUMENTS` is `scaffold`. In every other case — empty `$ARGUMENTS` (reference), `review`, or any reference/codegen question (including Kotlin and Swift) — operate strictly read-only: use Read/Grep/Glob, never Write or Edit. Do **not** infer write permission from the surrounding task ("the user is obviously building an API, so I'll scaffold") — during an active build that reasoning is always pre-satisfied and is exactly the trap to avoid. Only the literal `scaffold` first word unlocks file writes. If you are unsure which mode you are in, you are not in Scaffold Mode.
|
|
34
|
+
|
|
11
35
|
## What Are You Trying to Do?
|
|
12
36
|
|
|
13
37
|
Load the right reference for your task:
|
|
@@ -15,8 +39,8 @@ Load the right reference for your task:
|
|
|
15
39
|
- **Writing new procedures or HTTP routes?** Read [patterns.md](patterns.md) — prescribed code examples for every procedure type and HTTP integration
|
|
16
40
|
- **Reviewing or debugging existing code?** Read [anti-patterns.md](anti-patterns.md) — 20 common mistakes with before/after fixes and severity ratings
|
|
17
41
|
- **Need exact API signatures or type definitions?** Read [api-reference.md](api-reference.md) — complete API documentation with type signatures for every export
|
|
18
|
-
- **Generating a Kotlin client for Android/JVM consumers?**
|
|
19
|
-
- **Generating a Swift client for iOS/macOS/Apple-platform consumers?**
|
|
42
|
+
- **Generating a Kotlin client for Android/JVM consumers?** See the **Kotlin Client Codegen** section below — it covers `--target kotlin` end-to-end.
|
|
43
|
+
- **Generating a Swift client for iOS/macOS/Apple-platform consumers?** See the **Swift Client Codegen** section below — it covers `--target swift` end-to-end.
|
|
20
44
|
|
|
21
45
|
## Core Flow
|
|
22
46
|
|
|
@@ -173,8 +197,327 @@ The npm package ships user-facing documentation with narrative explanations and
|
|
|
173
197
|
| `docs/http-integrations.md` | Hono unified builder (`HonoAppBuilder` — RPC + HTTP + streaming with stratified config), **error taxonomy (canonical)**, DocRegistry (unified constructor, `.documentError()`) |
|
|
174
198
|
| `docs/client-and-codegen.md` | Client code generation, `createApiClient`/`createClient`, typed error dispatch, per-route `Errors` unions, per-call options, client-level defaults, typed RequestMeta augmentation, CLI options |
|
|
175
199
|
| `docs/client-error-handling.md` | **Canonical guide** for 7.0+ client error surface: normalized error classes, `.safe()` Result API, `ClientErrorMap` augmentation, custom `ErrorClassifier`, migration from `ClientRequestError`. |
|
|
200
|
+
| `docs/codegen-kotlin.md` | Kotlin target consumer setup (Gradle deps, contextual serializers, sealed interfaces) |
|
|
201
|
+
| `docs/codegen-swift.md` | Swift target consumer setup (SPM/Xcode integration, JSONDecoder config, discriminated unions, error dispatch patterns) |
|
|
176
202
|
| `CHANGELOG.md` | Release notes — see `[7.0.0]` for the safe-result API, new error classes, and `ClientRequestError` → `ClientHttpError` rename. See `[6.0.0]` for the peer error-handling model (taxonomy + `onError` + `onRequestError`). |
|
|
177
203
|
|
|
178
204
|
## Workflow
|
|
179
205
|
|
|
180
|
-
After planning with the **ts-procedures-architect** agent, use `/ts-procedures
|
|
206
|
+
After planning with the **ts-procedures-architect** agent, use `/ts-procedures scaffold <type> <Name>` to generate implementations. Use `/ts-procedures review <path>` to validate existing code.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Review Mode
|
|
211
|
+
|
|
212
|
+
*Entered when the first word of `$ARGUMENTS` is `review`. Read-only — never Write or Edit in this mode. Run thoroughly and at high effort.*
|
|
213
|
+
|
|
214
|
+
> **Isolation note:** as a standalone skill this review ran in a forked context. Folded into one skill it runs inline. For a large review where you want isolation (so the audit doesn't pollute the main conversation), dispatch this review to a subagent and relay its findings.
|
|
215
|
+
|
|
216
|
+
Parse the remainder of `$ARGUMENTS` (everything after `review`) as a file or directory path. If a directory, review all `.ts` and `.tsx` files within it.
|
|
217
|
+
|
|
218
|
+
### Instructions
|
|
219
|
+
|
|
220
|
+
1. Read the target file(s).
|
|
221
|
+
2. Identify ts-procedures imports (`ts-procedures`, `ts-procedures/hono`, `ts-procedures/http`, `ts-procedures/http-docs`, `ts-procedures/http-errors`, `ts-procedures/client`, `ts-procedures/codegen`) to determine file types.
|
|
222
|
+
3. Check each file against the categorized checklist in [checklist.md](checklist.md).
|
|
223
|
+
4. For detailed code examples of each violation pattern, reference [anti-patterns.md](anti-patterns.md) — it shows 20 common mistakes with before/after code fixes and severity ratings.
|
|
224
|
+
5. Output findings grouped by severity.
|
|
225
|
+
|
|
226
|
+
### Output Format
|
|
227
|
+
|
|
228
|
+
For each finding:
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
[SEVERITY] file:line — Violation
|
|
232
|
+
Problem: What's wrong
|
|
233
|
+
Fix: Concrete before/after code
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Severity levels:
|
|
237
|
+
- **CRITICAL** — Will cause bugs, silent failures, resource leaks, or runtime errors. Must fix.
|
|
238
|
+
- **WARNING** — Anti-pattern that hurts maintainability or correctness. Should fix.
|
|
239
|
+
- **SUGGESTION** — Improvement for readability, type safety, or DX. Nice to have.
|
|
240
|
+
|
|
241
|
+
### Summary
|
|
242
|
+
|
|
243
|
+
After individual findings, provide:
|
|
244
|
+
- Total findings by severity
|
|
245
|
+
- Overall assessment (healthy / needs attention / significant issues)
|
|
246
|
+
- Top 3 priorities to address
|
|
247
|
+
- If structural issues found, suggest `/ts-procedures scaffold <type> <Name>` to generate correct implementations
|
|
248
|
+
|
|
249
|
+
### Reference
|
|
250
|
+
|
|
251
|
+
See [checklist.md](checklist.md) for the complete categorized checklist by file type.
|
|
252
|
+
See [anti-patterns.md](anti-patterns.md) for detailed code examples of each violation.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Scaffold Mode
|
|
257
|
+
|
|
258
|
+
*Entered when the first word of `$ARGUMENTS` is `scaffold`. This is the only mode that writes files (see the File-write guard above).*
|
|
259
|
+
|
|
260
|
+
Parse `$ARGUMENTS` as `scaffold <type> <Name>`. The first word (`scaffold`) is the mode selector; `<type>` is the second word, `<Name>` is the third.
|
|
261
|
+
|
|
262
|
+
If `<type>` or `<Name>` is missing, ask the user for them before writing anything.
|
|
263
|
+
|
|
264
|
+
### Instructions
|
|
265
|
+
|
|
266
|
+
1. Validate `<type>` is a recognized type (see table below). Case-insensitive. **If it is not an exact match for one of the valid types, do not improvise or guess a template — list the valid types and ask the user to pick one.**
|
|
267
|
+
2. Validate `<Name>` is PascalCase (e.g., `UserProfile`).
|
|
268
|
+
3. Derive placeholder variants from the provided PascalCase Name:
|
|
269
|
+
- `{{Name}}` — PascalCase as given (e.g., `UserProfile`)
|
|
270
|
+
- `{{name}}` — camelCase (e.g., `userProfile`)
|
|
271
|
+
- `{{kebab}}` — kebab-case (e.g., `user-profile`)
|
|
272
|
+
4. Read the template file from `templates/<type>.md` (relative to this skill directory).
|
|
273
|
+
5. Replace all `{{Name}}`, `{{name}}`, and `{{kebab}}` placeholders with the appropriate variants.
|
|
274
|
+
6. Generate the implementation file(s) following the template exactly.
|
|
275
|
+
7. Also generate a colocated test file following ts-procedures test conventions.
|
|
276
|
+
|
|
277
|
+
### Valid Types
|
|
278
|
+
|
|
279
|
+
| Type | Template | Files Generated |
|
|
280
|
+
|------|----------|----------------|
|
|
281
|
+
| `procedure` | `templates/procedure.md` | `{{Name}}.procedure.ts`, `{{Name}}.procedure.test.ts` |
|
|
282
|
+
| `stream-procedure` | `templates/stream-procedure.md` | `{{Name}}.stream.ts`, `{{Name}}.stream.test.ts` |
|
|
283
|
+
| `hono` | `templates/hono.md` | `{{Name}}.hono.ts`, `{{Name}}.hono.test.ts` |
|
|
284
|
+
| `client` | `templates/client.md` | `{{Name}}.client.ts`, `{{Name}}.client.test.ts` |
|
|
285
|
+
| `astro-catchall` | `templates/astro-catchall.md` | `src/pages/api/[...rest].ts` |
|
|
286
|
+
|
|
287
|
+
### Rules
|
|
288
|
+
|
|
289
|
+
- Use `ctx.error()` for ad-hoc business errors; for structured errors with status codes and typed client dispatch, throw custom error classes and register them via `defineErrorTaxonomy` in the builder's `errors` config (see the HTTP builder templates).
|
|
290
|
+
- Never throw raw `Error` — either use `ctx.error()` or a typed class registered in the taxonomy.
|
|
291
|
+
- `schema.params` is validated at runtime; `schema.returnType` is documentation only.
|
|
292
|
+
- Pass `ctx.signal` to all downstream async calls.
|
|
293
|
+
- Stream handlers always have `ctx.signal` (guaranteed `AbortSignal`).
|
|
294
|
+
- Use TypeBox for schema definitions (`import { Type } from 'typebox'`).
|
|
295
|
+
- AJV config: `allErrors: true`, `coerceTypes: true`, `removeAdditional: true`.
|
|
296
|
+
- Test files use `describe`/`test` from vitest.
|
|
297
|
+
|
|
298
|
+
### Workflow
|
|
299
|
+
|
|
300
|
+
Use the **ts-procedures-architect** agent to plan your API structure first, then scaffold each procedure. After scaffolding, use `/ts-procedures review <path>` to validate the implementation.
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Kotlin Client Codegen
|
|
305
|
+
|
|
306
|
+
*Reference section — read-only. The Kotlin target is **types-only**: no runtime, no adapter, no error registry. Mobile/Android consumers own the HTTP layer.*
|
|
307
|
+
|
|
308
|
+
You are assisting a developer who needs to generate Kotlin types from a `ts-procedures` server's `DocEnvelope`.
|
|
309
|
+
|
|
310
|
+
### When this section applies
|
|
311
|
+
|
|
312
|
+
- The user mentions Kotlin, Android, kotlinx-serialization, mobile client, or `--target kotlin`.
|
|
313
|
+
- The user wants to share API types between a `ts-procedures` server and a Kotlin/JVM consumer.
|
|
314
|
+
- The user is debugging Kotlin codegen output, Gradle setup, or contextual serializer registration.
|
|
315
|
+
|
|
316
|
+
If the user is generating a **TypeScript** client, use the main reference above. For **Swift / iOS / macOS / Apple-platform** consumers, see the **Swift Client Codegen** section below.
|
|
317
|
+
|
|
318
|
+
### Quickstart
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
npx ts-procedures-codegen \
|
|
322
|
+
--target kotlin \
|
|
323
|
+
--kotlin-package com.example.api \
|
|
324
|
+
--url https://api.example.com/_ts-procedures.json \
|
|
325
|
+
--out ./src/main/kotlin/com/example/api
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
One `.kt` file per scope. Types accessed as `Users.GetUser.Response`, `Users.GetUser.Body.Address` (nested classes via `inlineTypes: true`), `Users.GetUser.Errors.NotFound`.
|
|
329
|
+
|
|
330
|
+
### CLI flags (Kotlin-specific)
|
|
331
|
+
|
|
332
|
+
| Flag | Default | Purpose |
|
|
333
|
+
|---|---|---|
|
|
334
|
+
| `--target kotlin` | `ts` | Switch to the Kotlin codegen path |
|
|
335
|
+
| `--kotlin-package <com.example.api>` | required | Sets the `package` declaration on every emitted `.kt` file |
|
|
336
|
+
| `--kotlin-serializer <kotlinx\|none>` | `kotlinx` | `kotlinx` emits `@Serializable`; `none` emits plain data classes for Moshi/Gson/hand-written serialization |
|
|
337
|
+
| `--unsupported-unions <throw\|fallback>` | `throw` | **Currently a no-op for Kotlin** — ajsc v7.2 silently emits an empty `data class` for untagged `oneOf` regardless. CLI warns when set |
|
|
338
|
+
|
|
339
|
+
`--array-item-naming`, `--depluralize`, `--uncountable-words` also apply to the Kotlin target.
|
|
340
|
+
|
|
341
|
+
### Output shape (what consumers see)
|
|
342
|
+
|
|
343
|
+
```kotlin
|
|
344
|
+
package com.example.api
|
|
345
|
+
|
|
346
|
+
import kotlinx.serialization.Serializable
|
|
347
|
+
import kotlinx.serialization.SerialName
|
|
348
|
+
import kotlinx.serialization.Contextual
|
|
349
|
+
import kotlinx.serialization.json.JsonClassDiscriminator
|
|
350
|
+
|
|
351
|
+
object Users {
|
|
352
|
+
object GetUser {
|
|
353
|
+
const val method = "GET"
|
|
354
|
+
const val pathTemplate = "/users/{id}"
|
|
355
|
+
fun path(p: PathParams): String = "/users/${p.id}"
|
|
356
|
+
|
|
357
|
+
@Serializable data class PathParams(val id: String)
|
|
358
|
+
|
|
359
|
+
@Serializable
|
|
360
|
+
data class Response(
|
|
361
|
+
val id: String,
|
|
362
|
+
@SerialName("created-at") @Contextual val createdAt: java.time.Instant,
|
|
363
|
+
val address: Address,
|
|
364
|
+
) {
|
|
365
|
+
@Serializable data class Address(val street: String, val city: String)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
object Errors {
|
|
369
|
+
@Serializable
|
|
370
|
+
data class NotFound(val name: String = "NotFound", val message: String)
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
For routes without path params, `path` is a `const val`, not a function.
|
|
377
|
+
|
|
378
|
+
### Consumer-side setup the dev MUST do
|
|
379
|
+
|
|
380
|
+
The generated code requires these on the Android/JVM side. **Don't let the user assume the codegen handles them.**
|
|
381
|
+
|
|
382
|
+
1. **Gradle:** `kotlin("plugin.serialization")` plugin + `org.jetbrains.kotlinx:kotlinx-serialization-json` dependency. (`kotlinx-serialization-core` is a transitive dep; no need to declare it explicitly.)
|
|
383
|
+
|
|
384
|
+
2. **Contextual serializers:** `format: date-time`/`uuid`/`uri`/`date`/`time` map to JVM stdlib types annotated with `@Contextual`. The consumer's `Json` configuration MUST register `contextual(java.time.Instant::class, ...)` etc., otherwise decoding fails. We don't ship the serializers — choice between ISO-8601 and epoch ms is application-specific.
|
|
385
|
+
|
|
386
|
+
3. **Discriminated unions:** `@JsonClassDiscriminator` is read automatically by `kotlinx-serialization-json` — no extra config needed.
|
|
387
|
+
|
|
388
|
+
4. **No runtime dispatch:** error types are emitted as nested data classes (`Users.GetUser.Errors.NotFound`), but there's no `instanceof`-style registry, no `dispatchTypedError`. Consumers catch HTTP failures themselves and inspect `body.name` (a regular `String` field, not a type-system discriminator) to decide which error data class to deserialize against. This is by design; don't suggest implementing it.
|
|
389
|
+
|
|
390
|
+
The full setup guide lives at `docs/codegen-kotlin.md` in the `ts-procedures` repo.
|
|
391
|
+
|
|
392
|
+
### Documented limitations to flag during reviews
|
|
393
|
+
|
|
394
|
+
- **Untagged `oneOf` produces an empty `data class`.** Won't round-trip. Add a server-side discriminator, hand-write a `KSerializer`, or pre-process the envelope.
|
|
395
|
+
- **Tuples > 3 elements throw** at codegen time. Refactor to a struct schema upstream.
|
|
396
|
+
- **`additionalProperties: { type: T }` is silently dropped** with a KDoc note. Add a sibling `Map<String, T>` field by hand if your contract uses extra keys.
|
|
397
|
+
- **Schema-level `examples` are not modeled.** They're documentation-only on the server side; consumers don't see them.
|
|
398
|
+
|
|
399
|
+
### Anti-patterns (Kotlin)
|
|
400
|
+
|
|
401
|
+
- Suggesting the Kotlin target ships an HTTP adapter or error registry.
|
|
402
|
+
- Recommending `--kotlin-serializer none` without noting the consumer is responsible for adapter setup.
|
|
403
|
+
- Treating `--unsupported-unions fallback` as functional for Kotlin — it's a no-op (the CLI itself warns when set).
|
|
404
|
+
- Saying KMP (Kotlin Multiplatform) is supported — JVM only for now.
|
|
405
|
+
- Mixing `--target kotlin` flags into a TypeScript-target invocation; some flags are silently ignored, others (like `--kotlin-package`) are required only for kotlin.
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## Swift Client Codegen
|
|
410
|
+
|
|
411
|
+
*Reference section — read-only. The Swift target is **types-only**: no runtime, no adapter, no error registry. iOS / macOS / Apple-platform consumers own the HTTP layer.*
|
|
412
|
+
|
|
413
|
+
You are assisting a developer who needs to generate Swift types from a `ts-procedures` server's `DocEnvelope`.
|
|
414
|
+
|
|
415
|
+
### When this section applies
|
|
416
|
+
|
|
417
|
+
- The user mentions Swift, iOS, macOS, watchOS, tvOS, visionOS, Apple platforms, `Codable`, `URLSession`, or `--target swift`.
|
|
418
|
+
- The user wants to share API types between a `ts-procedures` server and a Swift consumer.
|
|
419
|
+
- The user is debugging Swift codegen output, SPM/Xcode integration, `JSONDecoder` configuration, or `Codable` conformance issues.
|
|
420
|
+
|
|
421
|
+
If the user is generating a **TypeScript** client, use the main reference above. For **Kotlin/Android** consumers, see the **Kotlin Client Codegen** section above.
|
|
422
|
+
|
|
423
|
+
### Quickstart
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
npx ts-procedures-codegen \
|
|
427
|
+
--target swift \
|
|
428
|
+
--url https://api.example.com/_ts-procedures.json \
|
|
429
|
+
--out ./Sources/MyApp/Generated
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
One `.swift` file per scope. Types accessed as `Users.GetUser.Response`, `Users.GetUser.PathParams`, `Users.GetUser.Response.Address` (nested structs via `inlineTypes: true`), `Users.GetUser.Errors.NotFound`.
|
|
433
|
+
|
|
434
|
+
**Note:** unlike the Kotlin target, no `--swift-package` flag exists or is required. Swift modules are defined by Xcode/SPM targets.
|
|
435
|
+
|
|
436
|
+
### CLI flags (Swift-specific)
|
|
437
|
+
|
|
438
|
+
| Flag | Default | Purpose |
|
|
439
|
+
|---|---|---|
|
|
440
|
+
| `--target swift` | `ts` | Switch to the Swift codegen path |
|
|
441
|
+
| `--swift-serializer <codable\|none>` | `codable` | `codable` emits `: Codable` + `CodingKeys`; `none` emits plain structs (consumer handles serialization) |
|
|
442
|
+
| `--swift-access-level <public\|internal>` | `public` | Threads through to ajsc's `accessLevel`; use `internal` when generated types shouldn't appear in module ABI |
|
|
443
|
+
| `--unsupported-unions <throw\|fallback>` | `throw` | **Functional for Swift** (unlike Kotlin where it's a no-op) — `fallback` emits a self-contained `AnyCodable` helper for untagged `anyOf`/`oneOf` |
|
|
444
|
+
|
|
445
|
+
`--array-item-naming`, `--depluralize`, `--uncountable-words` also apply to the Swift target.
|
|
446
|
+
|
|
447
|
+
### Output shape (what consumers see)
|
|
448
|
+
|
|
449
|
+
```swift
|
|
450
|
+
import Foundation
|
|
451
|
+
|
|
452
|
+
public enum Users {
|
|
453
|
+
public enum GetUser {
|
|
454
|
+
public static let method = "GET"
|
|
455
|
+
public static let pathTemplate = "/users/{id}"
|
|
456
|
+
public static func path(_ p: PathParams) -> String { return "/users/\(p.id)" }
|
|
457
|
+
|
|
458
|
+
public struct PathParams: Codable {
|
|
459
|
+
public let id: String
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
public struct Response: Codable {
|
|
463
|
+
public let id: String
|
|
464
|
+
public let createdAt: Date
|
|
465
|
+
public let address: Address
|
|
466
|
+
|
|
467
|
+
enum CodingKeys: String, CodingKey {
|
|
468
|
+
case id
|
|
469
|
+
case createdAt = "created-at"
|
|
470
|
+
case address
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
public struct Address: Codable {
|
|
474
|
+
public let street: String
|
|
475
|
+
public let city: String
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
public enum Errors {
|
|
480
|
+
public struct NotFound: Codable {
|
|
481
|
+
public let name: String
|
|
482
|
+
public let message: String
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
For routes without path params, `path` is a `static let`, not a function. Namespaces are caseless `enum`s (the standard Swift idiom — uninstantiable, zero runtime cost).
|
|
490
|
+
|
|
491
|
+
### Consumer-side setup the dev MUST do
|
|
492
|
+
|
|
493
|
+
The generated code requires these on the Apple-platform side. **Don't let the user assume the codegen handles them.**
|
|
494
|
+
|
|
495
|
+
1. **Drop generated files into your SPM target or Xcode source group.** Any target containing the generated dir picks them up — no special build config. SPM globs sources recursively; for Xcode, use **File → Add Files to "<TargetName>"…** and ensure target membership is checked.
|
|
496
|
+
|
|
497
|
+
2. **Configure `JSONDecoder.dateDecodingStrategy = .iso8601`.** **Required** if the schema uses any `format: date-time` field (which become `Foundation.Date`). Without this, decoding fails with `DecodingError.typeMismatch`. Symmetric: set `JSONEncoder.dateEncodingStrategy = .iso8601` for request bodies.
|
|
498
|
+
|
|
499
|
+
3. **HTTP transport is the consumer's choice.** `URLSession` (with `async/await`) is the default recommendation — it's built-in and works on all Apple platforms with no dependencies. Alamofire / other libraries are fine but never required.
|
|
500
|
+
|
|
501
|
+
4. **No runtime dispatch.** Error types are emitted as nested structs (`Users.GetUser.Errors.NotFound`), but there's no registry, no `instanceof`-style lookup, no `dispatchTypedError`. Consumers catch HTTP failures themselves and dispatch on status code or `body.name` (a regular `String` field, not a type-system discriminator) to decide which error struct to decode against. To make error structs throwable, declare a one-line `extension X.Errors.NotFound: Error {}` in user code (keep it out of the generated file so re-runs don't clobber it). This is by design; don't suggest implementing a registry.
|
|
502
|
+
|
|
503
|
+
The full setup guide lives at `docs/codegen-swift.md` in the `ts-procedures` repo.
|
|
504
|
+
|
|
505
|
+
### Documented limitations to flag during reviews
|
|
506
|
+
|
|
507
|
+
- **`format: date` and `format: time` map to `String`.** Foundation has no native date-only or time-only type. Parse with `DateFormatter` if a typed value is needed.
|
|
508
|
+
- **`type: integer` maps to `Int64`** (not `Int`). 32-bit Apple platforms exist; `Int64` guarantees range parity.
|
|
509
|
+
- **`type: number` maps to `Double`.** For monetary values, convert to `Decimal` at the parse boundary.
|
|
510
|
+
- **Heterogeneous tuples throw under `Codable`.** Swift tuples aren't `Codable`. Schemas with positional-tuple `items: [...]` arrays throw at codegen time. Refactor to a struct schema upstream.
|
|
511
|
+
- **`additionalProperties: { type: T }` is silently dropped** with a doc-comment. Add a sibling `[String: T]` field by hand if your contract uses extra keys.
|
|
512
|
+
- **`not` and `patternProperties` throw at codegen time.** Simplify the schema upstream.
|
|
513
|
+
- **Untagged `oneOf` throws by default.** Add a discriminator, or pass `--unsupported-unions fallback` to emit `AnyCodable`-typed values (loses static typing).
|
|
514
|
+
|
|
515
|
+
### Anti-patterns (Swift)
|
|
516
|
+
|
|
517
|
+
- **Suggesting the Swift target ships a networking layer or HTTP adapter.** It does not — consumers own `URLSession`/etc. entirely.
|
|
518
|
+
- **Recommending Alamofire as required.** `URLSession` + `async/await` is fine and ships with the OS. Alamofire is a personal-preference choice, not a dependency of the generated code.
|
|
519
|
+
- **Conflating `--swift-serializer none` with "no setup needed".** `none` removes `Codable` conformance and `CodingKeys` — the consumer then needs their own serialization plan (hand-rolled, SwiftyJSON, etc.). It's strictly *more* setup, not less.
|
|
520
|
+
- **Treating `--unsupported-unions fallback` as a no-op for Swift.** Unlike Kotlin (where it's silently dropped), the Swift target actually emits an `AnyCodable` helper that round-trips correctly. Use it when needed.
|
|
521
|
+
- **Suggesting backwards compatibility with Swift 4 / pre-async-await.** Assume Swift 5.5+ (the async/await era). Sample dispatch code in docs uses `async throws`.
|
|
522
|
+
- **Suggesting the codegen emits `: Error` conformance on error structs.** It doesn't (`Codable` only) — consumers add a one-line extension. Don't ask for this to be added to the codegen; it would force users into a particular error model.
|
|
523
|
+
- **Mixing `--target swift` flags into a TypeScript-target invocation.** The flags are silently ignored; no harm, but the user is probably running the wrong target.
|
|
@@ -1222,7 +1222,7 @@ const adapter = createFetchAdapter({ fetch: customFetch })
|
|
|
1222
1222
|
|
|
1223
1223
|
## generateClient(options)
|
|
1224
1224
|
|
|
1225
|
-
> For **Kotlin** client codegen (Android/JVM, types-only output), see the
|
|
1225
|
+
> For **Kotlin** client codegen (Android/JVM, types-only output), see the *Kotlin Client Codegen* section in `SKILL.md`. For **Swift** client codegen (iOS/macOS/Apple platforms, types-only output), see the *Swift Client Codegen* section in `SKILL.md`. The reference below covers TypeScript codegen only.
|
|
1226
1226
|
|
|
1227
1227
|
Build-time CLI and programmatic API for generating typed client files from a `DocEnvelope`.
|
|
1228
1228
|
|
|
@@ -6,7 +6,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
7
7
|
const SOURCE_DIR = join(__dirname, '..', 'claude-code');
|
|
8
8
|
|
|
9
|
-
const SKILL_NAMES = ['ts-procedures'
|
|
9
|
+
const SKILL_NAMES = ['ts-procedures'];
|
|
10
10
|
const AGENT_FILES = ['ts-procedures-architect.md'];
|
|
11
11
|
|
|
12
12
|
function listFilesRecursive(dir) {
|
|
@@ -26,9 +26,9 @@ function listFilesRecursive(dir) {
|
|
|
26
26
|
* Install Claude Code integration files into a project's .claude/ directory.
|
|
27
27
|
*
|
|
28
28
|
* Creates:
|
|
29
|
-
* .claude/skills/ts-procedures/ —
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* .claude/skills/ts-procedures/ — Unified skill: framework reference plus
|
|
30
|
+
* `review`/`scaffold` $ARGUMENTS modes (checklist +
|
|
31
|
+
* templates bundled) and Kotlin/Swift codegen reference
|
|
32
32
|
* .claude/agents/ts-procedures-architect.md — Architecture planning agent
|
|
33
33
|
*
|
|
34
34
|
* @param {string} projectRoot — Absolute path to the consuming project's root
|
package/docs/ai-agent-setup.md
CHANGED
|
@@ -22,7 +22,7 @@ npx ts-procedures-setup copilot # GitHub Copilot only
|
|
|
22
22
|
|
|
23
23
|
| Tool | Files | Auto-updates? |
|
|
24
24
|
|------|-------|---------------|
|
|
25
|
-
| **Claude Code** | `.claude/skills/ts-procedures
|
|
25
|
+
| **Claude Code** | `.claude/skills/ts-procedures/` (single skill — reference + `review`/`scaffold` modes + Kotlin/Swift codegen), `.claude/agents/ts-procedures-architect.md` | Yes |
|
|
26
26
|
| **Cursor** | `.cursorrules` (marker-based section) | Yes |
|
|
27
27
|
| **GitHub Copilot** | `.github/copilot-instructions.md` (marker-based section) | Yes |
|
|
28
28
|
|
|
@@ -34,9 +34,10 @@ After initial setup, rules are automatically refreshed on every `npm install` or
|
|
|
34
34
|
|
|
35
35
|
Once installed, Claude Code gets:
|
|
36
36
|
|
|
37
|
-
- **
|
|
38
|
-
-
|
|
39
|
-
-
|
|
37
|
+
- **Unified `ts-procedures` skill** — one skill with three modes selected by the first word of its arguments:
|
|
38
|
+
- *Reference* (no argument) — core API, schema system, error handling, decision framework, plus Kotlin/Swift client-codegen reference (auto-discovered by Claude Code)
|
|
39
|
+
- *Scaffold* — `/ts-procedures scaffold <type> <Name>` generates procedures, streams, and HTTP setups with correct patterns
|
|
40
|
+
- *Review* — `/ts-procedures review <path>` checks code against a 60+ item checklist
|
|
40
41
|
- **Architecture agent** — `ts-procedures-architect` helps plan procedure structure, schema design, and HTTP implementation choices
|
|
41
42
|
|
|
42
43
|
## CLI Options
|
|
@@ -54,8 +55,6 @@ The `.claude/` files are auto-generated and regenerated on `npm install`. You ca
|
|
|
54
55
|
```gitignore
|
|
55
56
|
# Auto-generated AI agent rules (regenerated on npm install)
|
|
56
57
|
.claude/skills/ts-procedures/
|
|
57
|
-
.claude/skills/ts-procedures-scaffold/
|
|
58
|
-
.claude/skills/ts-procedures-review/
|
|
59
58
|
.claude/agents/ts-procedures-*.md
|
|
60
59
|
```
|
|
61
60
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-procedures",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.1",
|
|
4
4
|
"description": "A TypeScript RPC framework that creates type-safe, schema-validated procedure calls with a single function definition. Define your procedures once and get full type inference, runtime validation, and framework integration hooks.",
|
|
5
5
|
"main": "build/exports.js",
|
|
6
6
|
"types": "build/exports.d.ts",
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ts-procedures-kotlin
|
|
3
|
-
description: "Kotlin client codegen for ts-procedures — generate types-only Kotlin source from a ts-procedures DocEnvelope for Android/JVM consumers. Use when the user mentions Kotlin, Android, mobile clients, kotlinx-serialization, or asks how to generate non-TypeScript types from a ts-procedures server."
|
|
4
|
-
user-invocable: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# ts-procedures — Kotlin Client Codegen
|
|
8
|
-
|
|
9
|
-
You are assisting a developer who needs to generate Kotlin types from a `ts-procedures` server's `DocEnvelope`. The Kotlin target is **types-only** — no runtime, no adapter, no error registry. Mobile/Android consumers own the HTTP layer.
|
|
10
|
-
|
|
11
|
-
## When this skill applies
|
|
12
|
-
|
|
13
|
-
- The user mentions Kotlin, Android, kotlinx-serialization, mobile client, or `--target kotlin`.
|
|
14
|
-
- The user wants to share API types between a `ts-procedures` server and a Kotlin/JVM consumer.
|
|
15
|
-
- The user is debugging Kotlin codegen output, Gradle setup, or contextual serializer registration.
|
|
16
|
-
|
|
17
|
-
If the user is generating a **TypeScript** client, redirect them to the main `ts-procedures` skill. For **Swift / iOS / macOS / Apple-platform** consumers, redirect to `ts-procedures-swift`.
|
|
18
|
-
|
|
19
|
-
## Quickstart
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npx ts-procedures-codegen \
|
|
23
|
-
--target kotlin \
|
|
24
|
-
--kotlin-package com.example.api \
|
|
25
|
-
--url https://api.example.com/_ts-procedures.json \
|
|
26
|
-
--out ./src/main/kotlin/com/example/api
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
One `.kt` file per scope. Types accessed as `Users.GetUser.Response`, `Users.GetUser.Body.Address` (nested classes via `inlineTypes: true`), `Users.GetUser.Errors.NotFound`.
|
|
30
|
-
|
|
31
|
-
## CLI flags (Kotlin-specific)
|
|
32
|
-
|
|
33
|
-
| Flag | Default | Purpose |
|
|
34
|
-
|---|---|---|
|
|
35
|
-
| `--target kotlin` | `ts` | Switch to the Kotlin codegen path |
|
|
36
|
-
| `--kotlin-package <com.example.api>` | required | Sets the `package` declaration on every emitted `.kt` file |
|
|
37
|
-
| `--kotlin-serializer <kotlinx\|none>` | `kotlinx` | `kotlinx` emits `@Serializable`; `none` emits plain data classes for Moshi/Gson/hand-written serialization |
|
|
38
|
-
| `--unsupported-unions <throw\|fallback>` | `throw` | **Currently a no-op for Kotlin** — ajsc v7.2 silently emits an empty `data class` for untagged `oneOf` regardless. CLI warns when set |
|
|
39
|
-
|
|
40
|
-
`--array-item-naming`, `--depluralize`, `--uncountable-words` also apply to the Kotlin target.
|
|
41
|
-
|
|
42
|
-
## Output shape (what consumers see)
|
|
43
|
-
|
|
44
|
-
```kotlin
|
|
45
|
-
package com.example.api
|
|
46
|
-
|
|
47
|
-
import kotlinx.serialization.Serializable
|
|
48
|
-
import kotlinx.serialization.SerialName
|
|
49
|
-
import kotlinx.serialization.Contextual
|
|
50
|
-
import kotlinx.serialization.json.JsonClassDiscriminator
|
|
51
|
-
|
|
52
|
-
object Users {
|
|
53
|
-
object GetUser {
|
|
54
|
-
const val method = "GET"
|
|
55
|
-
const val pathTemplate = "/users/{id}"
|
|
56
|
-
fun path(p: PathParams): String = "/users/${p.id}"
|
|
57
|
-
|
|
58
|
-
@Serializable data class PathParams(val id: String)
|
|
59
|
-
|
|
60
|
-
@Serializable
|
|
61
|
-
data class Response(
|
|
62
|
-
val id: String,
|
|
63
|
-
@SerialName("created-at") @Contextual val createdAt: java.time.Instant,
|
|
64
|
-
val address: Address,
|
|
65
|
-
) {
|
|
66
|
-
@Serializable data class Address(val street: String, val city: String)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
object Errors {
|
|
70
|
-
@Serializable
|
|
71
|
-
data class NotFound(val name: String = "NotFound", val message: String)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
For routes without path params, `path` is a `const val`, not a function.
|
|
78
|
-
|
|
79
|
-
## Consumer-side setup the dev MUST do
|
|
80
|
-
|
|
81
|
-
The generated code requires these on the Android/JVM side. **Don't let the user assume the codegen handles them.**
|
|
82
|
-
|
|
83
|
-
1. **Gradle:** `kotlin("plugin.serialization")` plugin + `org.jetbrains.kotlinx:kotlinx-serialization-json` dependency. (`kotlinx-serialization-core` is a transitive dep; no need to declare it explicitly.)
|
|
84
|
-
|
|
85
|
-
2. **Contextual serializers:** `format: date-time`/`uuid`/`uri`/`date`/`time` map to JVM stdlib types annotated with `@Contextual`. The consumer's `Json` configuration MUST register `contextual(java.time.Instant::class, ...)` etc., otherwise decoding fails. We don't ship the serializers — choice between ISO-8601 and epoch ms is application-specific.
|
|
86
|
-
|
|
87
|
-
3. **Discriminated unions:** `@JsonClassDiscriminator` is read automatically by `kotlinx-serialization-json` — no extra config needed.
|
|
88
|
-
|
|
89
|
-
4. **No runtime dispatch:** error types are emitted as nested data classes (`Users.GetUser.Errors.NotFound`), but there's no `instanceof`-style registry, no `dispatchTypedError`. Consumers catch HTTP failures themselves and inspect `body.name` (a regular `String` field, not a type-system discriminator) to decide which error data class to deserialize against. This is by design; don't suggest implementing it.
|
|
90
|
-
|
|
91
|
-
The full setup guide lives at `docs/codegen-kotlin.md` in the `ts-procedures` repo.
|
|
92
|
-
|
|
93
|
-
## Documented limitations to flag during reviews
|
|
94
|
-
|
|
95
|
-
- **Untagged `oneOf` produces an empty `data class`.** Won't round-trip. Add a server-side discriminator, hand-write a `KSerializer`, or pre-process the envelope.
|
|
96
|
-
- **Tuples > 3 elements throw** at codegen time. Refactor to a struct schema upstream.
|
|
97
|
-
- **`additionalProperties: { type: T }` is silently dropped** with a KDoc note. Add a sibling `Map<String, T>` field by hand if your contract uses extra keys.
|
|
98
|
-
- **Schema-level `examples` are not modeled.** They're documentation-only on the server side; consumers don't see them.
|
|
99
|
-
|
|
100
|
-
## Anti-patterns
|
|
101
|
-
|
|
102
|
-
- Suggesting the Kotlin target ships an HTTP adapter or error registry.
|
|
103
|
-
- Recommending `--kotlin-serializer none` without noting the consumer is responsible for adapter setup.
|
|
104
|
-
- Treating `--unsupported-unions fallback` as functional for Kotlin — it's a no-op (the CLI itself warns when set).
|
|
105
|
-
- Saying KMP (Kotlin Multiplatform) is supported — JVM only for now.
|
|
106
|
-
- Mixing `--target kotlin` flags into a TypeScript-target invocation; some flags are silently ignored, others (like `--kotlin-package`) are required only for kotlin.
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ts-procedures-review
|
|
3
|
-
description: "Review ts-procedures code for pattern adherence, schema correctness, error handling, and signal propagation."
|
|
4
|
-
argument-hint: "<path>"
|
|
5
|
-
allowed-tools: Read Grep Glob
|
|
6
|
-
context: fork
|
|
7
|
-
effort: high
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
# Review ts-procedures Code
|
|
11
|
-
|
|
12
|
-
Parse `$ARGUMENTS` as a file or directory path. If a directory, review all `.ts` and `.tsx` files within it.
|
|
13
|
-
|
|
14
|
-
## Instructions
|
|
15
|
-
|
|
16
|
-
1. Read the target file(s).
|
|
17
|
-
2. Identify ts-procedures imports (`ts-procedures`, `ts-procedures/hono`, `ts-procedures/http`, `ts-procedures/http-docs`, `ts-procedures/http-errors`, `ts-procedures/client`, `ts-procedures/codegen`) to determine file types.
|
|
18
|
-
3. Check each file against the categorized checklist in [checklist.md](checklist.md).
|
|
19
|
-
4. For detailed code examples of each violation pattern, reference [anti-patterns.md](../ts-procedures/anti-patterns.md) — it shows 20 common mistakes with before/after code fixes and severity ratings.
|
|
20
|
-
5. Output findings grouped by severity.
|
|
21
|
-
|
|
22
|
-
## Output Format
|
|
23
|
-
|
|
24
|
-
For each finding:
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
[SEVERITY] file:line — Violation
|
|
28
|
-
Problem: What's wrong
|
|
29
|
-
Fix: Concrete before/after code
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Severity levels:
|
|
33
|
-
- **CRITICAL** — Will cause bugs, silent failures, resource leaks, or runtime errors. Must fix.
|
|
34
|
-
- **WARNING** — Anti-pattern that hurts maintainability or correctness. Should fix.
|
|
35
|
-
- **SUGGESTION** — Improvement for readability, type safety, or DX. Nice to have.
|
|
36
|
-
|
|
37
|
-
## Summary
|
|
38
|
-
|
|
39
|
-
After individual findings, provide:
|
|
40
|
-
- Total findings by severity
|
|
41
|
-
- Overall assessment (healthy / needs attention / significant issues)
|
|
42
|
-
- Top 3 priorities to address
|
|
43
|
-
- If structural issues found, suggest `/ts-procedures:scaffold <type> <Name>` to generate correct implementations
|
|
44
|
-
|
|
45
|
-
## Reference
|
|
46
|
-
|
|
47
|
-
See [checklist.md](checklist.md) for the complete categorized checklist by file type.
|
|
48
|
-
See [anti-patterns.md](../ts-procedures/anti-patterns.md) for detailed code examples of each violation.
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ts-procedures-scaffold
|
|
3
|
-
description: "Generate ts-procedures implementations with correct patterns — procedures, streams, Hono apps (RPC, streams, REST in one builder), and client setup."
|
|
4
|
-
argument-hint: "<type> <Name>"
|
|
5
|
-
allowed-tools: Read Write
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Scaffold ts-procedures Code
|
|
9
|
-
|
|
10
|
-
Scaffold a `$0` ts-procedures implementation named `$1`.
|
|
11
|
-
|
|
12
|
-
If either argument is missing, ask the user for `<type>` and `<Name>`.
|
|
13
|
-
|
|
14
|
-
## Instructions
|
|
15
|
-
|
|
16
|
-
1. Validate `$0` is a recognized type (see table below). Case-insensitive.
|
|
17
|
-
2. Validate `$1` is PascalCase (e.g., `UserProfile`).
|
|
18
|
-
3. Derive placeholder variants from the provided PascalCase Name:
|
|
19
|
-
- `{{Name}}` — PascalCase as given (e.g., `UserProfile`)
|
|
20
|
-
- `{{name}}` — camelCase (e.g., `userProfile`)
|
|
21
|
-
- `{{kebab}}` — kebab-case (e.g., `user-profile`)
|
|
22
|
-
4. Read the template file from `templates/$0.md` (relative to this skill directory).
|
|
23
|
-
5. Replace all `{{Name}}`, `{{name}}`, and `{{kebab}}` placeholders with the appropriate variants.
|
|
24
|
-
6. Generate the implementation file(s) following the template exactly.
|
|
25
|
-
7. Also generate a colocated test file following ts-procedures test conventions.
|
|
26
|
-
|
|
27
|
-
## Valid Types
|
|
28
|
-
|
|
29
|
-
| Type | Template | Files Generated |
|
|
30
|
-
|------|----------|----------------|
|
|
31
|
-
| `procedure` | `templates/procedure.md` | `{{Name}}.procedure.ts`, `{{Name}}.procedure.test.ts` |
|
|
32
|
-
| `stream-procedure` | `templates/stream-procedure.md` | `{{Name}}.stream.ts`, `{{Name}}.stream.test.ts` |
|
|
33
|
-
| `hono` | `templates/hono.md` | `{{Name}}.hono.ts`, `{{Name}}.hono.test.ts` |
|
|
34
|
-
| `client` | `templates/client.md` | `{{Name}}.client.ts`, `{{Name}}.client.test.ts` |
|
|
35
|
-
| `astro-catchall` | `templates/astro-catchall.md` | `src/pages/api/[...rest].ts` |
|
|
36
|
-
|
|
37
|
-
## Rules
|
|
38
|
-
|
|
39
|
-
- Use `ctx.error()` for ad-hoc business errors; for structured errors with status codes and typed client dispatch, throw custom error classes and register them via `defineErrorTaxonomy` in the builder's `errors` config (see the HTTP builder templates).
|
|
40
|
-
- Never throw raw `Error` — either use `ctx.error()` or a typed class registered in the taxonomy.
|
|
41
|
-
- `schema.params` is validated at runtime; `schema.returnType` is documentation only.
|
|
42
|
-
- Pass `ctx.signal` to all downstream async calls.
|
|
43
|
-
- Stream handlers always have `ctx.signal` (guaranteed `AbortSignal`).
|
|
44
|
-
- Use TypeBox for schema definitions (`import { Type } from 'typebox'`).
|
|
45
|
-
- AJV config: `allErrors: true`, `coerceTypes: true`, `removeAdditional: true`.
|
|
46
|
-
- Test files use `describe`/`test` from vitest.
|
|
47
|
-
|
|
48
|
-
## Workflow
|
|
49
|
-
|
|
50
|
-
Use the **ts-procedures-architect** agent to plan your API structure first, then scaffold each procedure. After scaffolding, use `/ts-procedures:review <path>` to validate the implementation.
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ts-procedures-swift
|
|
3
|
-
description: "Swift client codegen for ts-procedures — generate types-only Swift source from a ts-procedures DocEnvelope for iOS/macOS/Apple-platform consumers. Use when the user mentions Swift, iOS, macOS, Apple platforms, Codable, or asks how to generate non-TypeScript types from a ts-procedures server."
|
|
4
|
-
user-invocable: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# ts-procedures — Swift Client Codegen
|
|
8
|
-
|
|
9
|
-
You are assisting a developer who needs to generate Swift types from a `ts-procedures` server's `DocEnvelope`. The Swift target is **types-only** — no runtime, no adapter, no error registry. iOS / macOS / Apple-platform consumers own the HTTP layer.
|
|
10
|
-
|
|
11
|
-
## When this skill applies
|
|
12
|
-
|
|
13
|
-
- The user mentions Swift, iOS, macOS, watchOS, tvOS, visionOS, Apple platforms, `Codable`, `URLSession`, or `--target swift`.
|
|
14
|
-
- The user wants to share API types between a `ts-procedures` server and a Swift consumer.
|
|
15
|
-
- The user is debugging Swift codegen output, SPM/Xcode integration, `JSONDecoder` configuration, or `Codable` conformance issues.
|
|
16
|
-
|
|
17
|
-
If the user is generating a **TypeScript** client, redirect them to the main `ts-procedures` skill. For **Kotlin/Android** consumers, redirect to `ts-procedures-kotlin`.
|
|
18
|
-
|
|
19
|
-
## Quickstart
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npx ts-procedures-codegen \
|
|
23
|
-
--target swift \
|
|
24
|
-
--url https://api.example.com/_ts-procedures.json \
|
|
25
|
-
--out ./Sources/MyApp/Generated
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
One `.swift` file per scope. Types accessed as `Users.GetUser.Response`, `Users.GetUser.PathParams`, `Users.GetUser.Response.Address` (nested structs via `inlineTypes: true`), `Users.GetUser.Errors.NotFound`.
|
|
29
|
-
|
|
30
|
-
**Note:** unlike the Kotlin target, no `--swift-package` flag exists or is required. Swift modules are defined by Xcode/SPM targets.
|
|
31
|
-
|
|
32
|
-
## CLI flags (Swift-specific)
|
|
33
|
-
|
|
34
|
-
| Flag | Default | Purpose |
|
|
35
|
-
|---|---|---|
|
|
36
|
-
| `--target swift` | `ts` | Switch to the Swift codegen path |
|
|
37
|
-
| `--swift-serializer <codable\|none>` | `codable` | `codable` emits `: Codable` + `CodingKeys`; `none` emits plain structs (consumer handles serialization) |
|
|
38
|
-
| `--swift-access-level <public\|internal>` | `public` | Threads through to ajsc's `accessLevel`; use `internal` when generated types shouldn't appear in module ABI |
|
|
39
|
-
| `--unsupported-unions <throw\|fallback>` | `throw` | **Functional for Swift** (unlike Kotlin where it's a no-op) — `fallback` emits a self-contained `AnyCodable` helper for untagged `anyOf`/`oneOf` |
|
|
40
|
-
|
|
41
|
-
`--array-item-naming`, `--depluralize`, `--uncountable-words` also apply to the Swift target.
|
|
42
|
-
|
|
43
|
-
## Output shape (what consumers see)
|
|
44
|
-
|
|
45
|
-
```swift
|
|
46
|
-
import Foundation
|
|
47
|
-
|
|
48
|
-
public enum Users {
|
|
49
|
-
public enum GetUser {
|
|
50
|
-
public static let method = "GET"
|
|
51
|
-
public static let pathTemplate = "/users/{id}"
|
|
52
|
-
public static func path(_ p: PathParams) -> String { return "/users/\(p.id)" }
|
|
53
|
-
|
|
54
|
-
public struct PathParams: Codable {
|
|
55
|
-
public let id: String
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public struct Response: Codable {
|
|
59
|
-
public let id: String
|
|
60
|
-
public let createdAt: Date
|
|
61
|
-
public let address: Address
|
|
62
|
-
|
|
63
|
-
enum CodingKeys: String, CodingKey {
|
|
64
|
-
case id
|
|
65
|
-
case createdAt = "created-at"
|
|
66
|
-
case address
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public struct Address: Codable {
|
|
70
|
-
public let street: String
|
|
71
|
-
public let city: String
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
public enum Errors {
|
|
76
|
-
public struct NotFound: Codable {
|
|
77
|
-
public let name: String
|
|
78
|
-
public let message: String
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
For routes without path params, `path` is a `static let`, not a function. Namespaces are caseless `enum`s (the standard Swift idiom — uninstantiable, zero runtime cost).
|
|
86
|
-
|
|
87
|
-
## Consumer-side setup the dev MUST do
|
|
88
|
-
|
|
89
|
-
The generated code requires these on the Apple-platform side. **Don't let the user assume the codegen handles them.**
|
|
90
|
-
|
|
91
|
-
1. **Drop generated files into your SPM target or Xcode source group.** Any target containing the generated dir picks them up — no special build config. SPM globs sources recursively; for Xcode, use **File → Add Files to "<TargetName>"…** and ensure target membership is checked.
|
|
92
|
-
|
|
93
|
-
2. **Configure `JSONDecoder.dateDecodingStrategy = .iso8601`.** **Required** if the schema uses any `format: date-time` field (which become `Foundation.Date`). Without this, decoding fails with `DecodingError.typeMismatch`. Symmetric: set `JSONEncoder.dateEncodingStrategy = .iso8601` for request bodies.
|
|
94
|
-
|
|
95
|
-
3. **HTTP transport is the consumer's choice.** `URLSession` (with `async/await`) is the default recommendation — it's built-in and works on all Apple platforms with no dependencies. Alamofire / other libraries are fine but never required.
|
|
96
|
-
|
|
97
|
-
4. **No runtime dispatch.** Error types are emitted as nested structs (`Users.GetUser.Errors.NotFound`), but there's no registry, no `instanceof`-style lookup, no `dispatchTypedError`. Consumers catch HTTP failures themselves and dispatch on status code or `body.name` (a regular `String` field, not a type-system discriminator) to decide which error struct to decode against. To make error structs throwable, declare a one-line `extension X.Errors.NotFound: Error {}` in user code (keep it out of the generated file so re-runs don't clobber it). This is by design; don't suggest implementing a registry.
|
|
98
|
-
|
|
99
|
-
The full setup guide lives at `docs/codegen-swift.md` in the `ts-procedures` repo.
|
|
100
|
-
|
|
101
|
-
## Documented limitations to flag during reviews
|
|
102
|
-
|
|
103
|
-
- **`format: date` and `format: time` map to `String`.** Foundation has no native date-only or time-only type. Parse with `DateFormatter` if a typed value is needed.
|
|
104
|
-
- **`type: integer` maps to `Int64`** (not `Int`). 32-bit Apple platforms exist; `Int64` guarantees range parity.
|
|
105
|
-
- **`type: number` maps to `Double`.** For monetary values, convert to `Decimal` at the parse boundary.
|
|
106
|
-
- **Heterogeneous tuples throw under `Codable`.** Swift tuples aren't `Codable`. Schemas with positional-tuple `items: [...]` arrays throw at codegen time. Refactor to a struct schema upstream.
|
|
107
|
-
- **`additionalProperties: { type: T }` is silently dropped** with a doc-comment. Add a sibling `[String: T]` field by hand if your contract uses extra keys.
|
|
108
|
-
- **`not` and `patternProperties` throw at codegen time.** Simplify the schema upstream.
|
|
109
|
-
- **Untagged `oneOf` throws by default.** Add a discriminator, or pass `--unsupported-unions fallback` to emit `AnyCodable`-typed values (loses static typing).
|
|
110
|
-
|
|
111
|
-
## Anti-patterns
|
|
112
|
-
|
|
113
|
-
- **Suggesting the Swift target ships a networking layer or HTTP adapter.** It does not — consumers own `URLSession`/etc. entirely.
|
|
114
|
-
- **Recommending Alamofire as required.** `URLSession` + `async/await` is fine and ships with the OS. Alamofire is a personal-preference choice, not a dependency of the generated code.
|
|
115
|
-
- **Conflating `--swift-serializer none` with "no setup needed".** `none` removes `Codable` conformance and `CodingKeys` — the consumer then needs their own serialization plan (hand-rolled, SwiftyJSON, etc.). It's strictly *more* setup, not less.
|
|
116
|
-
- **Treating `--unsupported-unions fallback` as a no-op for Swift.** Unlike Kotlin (where it's silently dropped), the Swift target actually emits an `AnyCodable` helper that round-trips correctly. Use it when needed.
|
|
117
|
-
- **Suggesting backwards compatibility with Swift 4 / pre-async-await.** Assume Swift 5.5+ (the async/await era). Sample dispatch code in docs uses `async throws`.
|
|
118
|
-
- **Suggesting the codegen emits `: Error` conformance on error structs.** It doesn't (`Codable` only) — consumers add a one-line extension. Don't ask for this to be added to the codegen; it would force users into a particular error model.
|
|
119
|
-
- **Mixing `--target swift` flags into a TypeScript-target invocation.** The flags are silently ignored; no harm, but the user is probably running the wrong target.
|
/package/agent_config/claude-code/skills/{ts-procedures-review → ts-procedures}/checklist.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/agent_config/claude-code/skills/{ts-procedures-scaffold → ts-procedures}/templates/hono.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|