ts-procedures 10.2.0 → 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.
- package/CHANGELOG.md +12 -0
- package/README.md +9 -6
- package/agent_config/bin/postinstall.mjs +20 -89
- package/agent_config/bin/setup.mjs +51 -264
- package/agent_config/lib/install-skills.mjs +108 -0
- package/docs/ai-agent-setup.md +19 -27
- package/docs/client-error-handling.md +1 -1
- package/docs/http-integrations.md +1 -1
- package/package.json +1 -1
- package/agent_config/claude-code/.claude-plugin/plugin.json +0 -5
- package/agent_config/claude-code/agents/ts-procedures-architect.md +0 -138
- package/agent_config/copilot/copilot-instructions.md +0 -521
- package/agent_config/cursor/cursorrules +0 -521
- package/agent_config/lib/install-claude.mjs +0 -57
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/SKILL.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/anti-patterns.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/api-reference.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/checklist.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/patterns.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/astro-catchall.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/client.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/hono.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/procedure.md +0 -0
- /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/stream-procedure.md +0 -0
package/docs/ai-agent-setup.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# AI Agent Setup
|
|
4
4
|
|
|
5
|
-
ts-procedures ships
|
|
5
|
+
ts-procedures ships a single, spec-compliant **Agent Skill** that gives AI coding tools framework-aware context when writing ts-procedures code in your project. It follows the open [Agent Skills](https://www.anthropic.com/engineering/equipping-agents-for-the-real-world-with-agent-skills) / `SKILL.md` standard, so a wide range of tools — Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and others — read the same files.
|
|
6
6
|
|
|
7
7
|
## Quick Setup
|
|
8
8
|
|
|
@@ -10,52 +10,44 @@ ts-procedures ships with built-in AI assistant configuration for **Claude Code**
|
|
|
10
10
|
npx ts-procedures-setup
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
This installs
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npx ts-procedures-setup claude # Claude Code only
|
|
17
|
-
npx ts-procedures-setup cursor # Cursor only
|
|
18
|
-
npx ts-procedures-setup copilot # GitHub Copilot only
|
|
19
|
-
```
|
|
13
|
+
This installs the skill into the standard agent directories. There are no per-tool targets — one skill works everywhere.
|
|
20
14
|
|
|
21
15
|
## What Gets Installed
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
|
26
|
-
|
|
27
|
-
|
|
|
17
|
+
The same skill is copied into two standard locations:
|
|
18
|
+
|
|
19
|
+
| Path | Read by |
|
|
20
|
+
|------|---------|
|
|
21
|
+
| `.agents/skills/ts-procedures/` | The cross-tool standard — 30+ agents (Codex, Cursor, GitHub Copilot, Gemini CLI, …) scan `.agents/skills` from the working directory up to the repo root |
|
|
22
|
+
| `.claude/skills/ts-procedures/` | Claude Code's native project skills location |
|
|
23
|
+
|
|
24
|
+
The skill bundles the framework reference plus `review` / `scaffold` modes (checklist + templates) and Kotlin/Swift client-codegen reference, using progressive disclosure so tools load detail only as needed.
|
|
28
25
|
|
|
29
26
|
## Auto-Updates
|
|
30
27
|
|
|
31
|
-
After initial setup,
|
|
28
|
+
After initial setup, the skill is automatically refreshed on every `npm install` or `npm update` via the package's postinstall hook. When ts-procedures publishes a new version, your AI tools get the latest framework guidance with no manual steps. Auto-update is opt-in: it only runs once the skill has been installed at least once.
|
|
32
29
|
|
|
33
|
-
##
|
|
30
|
+
## Skill Modes
|
|
34
31
|
|
|
35
|
-
Once installed,
|
|
32
|
+
Once installed, the `ts-procedures` skill exposes three modes selected by the first word of its arguments:
|
|
36
33
|
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- *Review* — `/ts-procedures review <path>` checks code against a 60+ item checklist
|
|
41
|
-
- **Architecture agent** — `ts-procedures-architect` helps plan procedure structure, schema design, and HTTP implementation choices
|
|
34
|
+
- *Reference* (no argument) — core API, schema system, error handling, decision framework, plus Kotlin/Swift client-codegen reference (auto-discovered by the agent)
|
|
35
|
+
- *Scaffold* — `scaffold <type> <Name>` generates procedures, streams, and HTTP setups with correct patterns
|
|
36
|
+
- *Review* — `review <path>` checks code against a 60+ item checklist
|
|
42
37
|
|
|
43
38
|
## CLI Options
|
|
44
39
|
|
|
45
40
|
```bash
|
|
46
|
-
npx ts-procedures-setup --force # Overwrite without prompting
|
|
47
41
|
npx ts-procedures-setup --dry-run # Preview what would be created/updated
|
|
48
42
|
npx ts-procedures-setup --check # Exit with code 1 if files are outdated (for CI)
|
|
49
43
|
```
|
|
50
44
|
|
|
51
45
|
## Gitignore
|
|
52
46
|
|
|
53
|
-
The
|
|
47
|
+
The installed skill is generated and regenerated on `npm install`. You can add the install roots to `.gitignore`:
|
|
54
48
|
|
|
55
49
|
```gitignore
|
|
56
|
-
# Auto-generated AI agent
|
|
50
|
+
# Auto-generated AI agent skill (regenerated on npm install)
|
|
51
|
+
.agents/skills/ts-procedures/
|
|
57
52
|
.claude/skills/ts-procedures/
|
|
58
|
-
.claude/agents/ts-procedures-*.md
|
|
59
53
|
```
|
|
60
|
-
|
|
61
|
-
Cursor and Copilot files use marker-based sections that coexist with your own rules, so they should typically be committed.
|
|
@@ -414,7 +414,7 @@ A framework-level "skip `onError` for `.safe()`" toggle was deliberately deferre
|
|
|
414
414
|
|
|
415
415
|
- Codegen setup, per-call options, hooks, and typed-error wiring: [`docs/client-and-codegen.md`](./client-and-codegen.md)
|
|
416
416
|
- Client types and interfaces: package source under `src/client/` (`types.ts`, `errors.ts`, `error-dispatch.ts`)
|
|
417
|
-
- Agent config patterns and anti-patterns: [`agent_config/
|
|
417
|
+
- Agent config patterns and anti-patterns: [`agent_config/skills/ts-procedures/patterns.md`](../agent_config/skills/ts-procedures/patterns.md) and [`anti-patterns.md`](../agent_config/skills/ts-procedures/anti-patterns.md)
|
|
418
418
|
|
|
419
419
|
---
|
|
420
420
|
|
|
@@ -178,7 +178,7 @@ new HonoAppBuilder({
|
|
|
178
178
|
}).register(procs, /* ... */).build()
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
(Need to route different error classes to different status codes? Use the taxonomy — that's exactly what it's designed for. Hand-writing `instanceof` ladders inside `onError` is [anti-pattern #20](../agent_config/
|
|
181
|
+
(Need to route different error classes to different status codes? Use the taxonomy — that's exactly what it's designed for. Hand-writing `instanceof` ladders inside `onError` is [anti-pattern #20](../agent_config/skills/ts-procedures/anti-patterns.md).)
|
|
182
182
|
|
|
183
183
|
`HonoAppBuilder`'s `onError` signature: `(procedure, c: Context, error) => Response | Promise<Response>` — for streaming procedures, pre-stream only.
|
|
184
184
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-procedures",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.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,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.
|