kstack-hono
Hono の RPC を使う TypeScript コードを書く・修正する・レビューするときの規約。型付きクライアント(hono/client の hc、hc<typeof app>、AppType、hcWithType)を API サーバーのパッケージから export し、フロントエンドや他のサービスはそれを import するだけにする構成を扱う。monorepo で API とクライアント(SPA、別 Worker、テスト)が別パッケージになっている場面、RPC クライアントの作成、package.json の exports 設計、レビュー指摘への対応でも発火させる。
How do I install this agent skill?
npx skills add https://github.com/taiki-kuraishi/skill --skill kstack-honoIs this agent skill safe to install?
- Gen Agent Trust Hubpass
This skill provides best-practice guidelines for implementing type-safe RPC clients using Hono in TypeScript monorepos. It contains architectural recommendations and code snippets for efficient development and does not present any security risks.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
kstack-hono
Hono の RPC を書くときの規約。理由を理解した上で適用すること。
型付きクライアントは API のパッケージから export する
hc<typeof app>(...) を利用側のパッケージで組み立てない。API のパッケージに client 用の entry を作り、型を計算済みのクライアント生成関数を export する。
// Bad: 利用側が server の app 型と hono/client を個別に知っている
import type { app } from "@acme/api/server";
import { hc } from "hono/client";
export const apiClient = hc<typeof app>(import.meta.env.VITE_API_URL);
// Good: API パッケージの src/client.ts
import { hc } from "hono/client";
// server は型としてだけ import する。実行時のコードはクライアントの bundle に入らない
import type { app } from "./server";
// コンパイル時に型を一度だけ計算させる
const client = hc<typeof app>("");
export type Client = typeof client;
export const hcWithType = (...args: Parameters<typeof hc>): Client => hc<typeof app>(...args);
// API パッケージの package.json
{ "exports": { "./client": "./src/client.ts" } }
// 利用側
import { hcWithType } from "@acme/api/client";
export const apiClient = hcWithType(import.meta.env.VITE_API_URL, {
init: { credentials: "include" },
});
なぜ: クライアントの型は server の route 定義から決まるので、定義と同じパッケージが持てば、利用側は app の型や hc の型引数を知らずに済み、利用側が増えても hc<typeof app> が重複しない。Hono の公式ガイドが推奨するとおり、型を計算済みの関数を使うと tsserver が利用のたびに route の型を展開せず、IDE が軽くなる。
@acme/api/client は実行時に import されるので、利用側では devDependencies ではなく dependencies に置く。app はメソッドチェーン 1 本で定義しておかないと RPC の型推論が切れる。
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/taiki-kuraishi/skill/kstack-hono">View kstack-hono on skillZs</a>