[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M77YT2W64KZTT4FHTAVGDWB7":3,"skill-same:01M77YT2W64KZTT4FHTAVGDWB7":94},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":14,"repositoryHtmlUrl":47,"repositoryHomepageUrl":6,"ownerHtmlUrl":48,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":49,"install":50,"resources":63},"01M77YT2W64KZTT4FHTAVGDWB7","ts-sdk-author",null,"Design, build, verify, and publish production-grade TypeScript SDKs as npm packages inside a pnpm monorepo. Covers workspace layout, public API and module boundaries, plugin extension points, branded types and library-tuned tsconfig, tsdown bundling (vs tsup\u002Ftsc-only\u002Funbuild), package.json exports with dual ESM+CJS and isomorphic conditions (browser\u002Fworkers\u002FRN\u002Fdeno), Turborepo pipelines, publint and @arethetypeswrong\u002Fcli verification, changesets pre-release mode, npm dist-tags (latest\u002Fnext\u002Fbeta\u002Frc\u002Fcanary), and the alpha→beta→rc→stable release lifecycle. Triggers on: build a TS SDK, extract core library, package.json exports, dual ESM CJS, tsdown config, tsup vs tsdown, publint, attw, changesets prerelease, npm dist-tag, beta to rc, canary release, pnpm workspace SDK, isomorphic SDK, tsconfig library, npm provenance, shipping a TypeScript library.","livelybug\u002Fharness-repo-skill-collection","livelybug","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F13627060?v=4","01M77WSX1288SYJ0XVWQSFZ3X0","Burt","01M77WSX1QBFK4S4JDZTBC76CT",0,"MIT","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: ts-sdk-author\ndescription: >\n  Design, build, verify, and publish production-grade TypeScript SDKs as npm\n  packages inside a pnpm monorepo. Covers workspace layout, public API and\n  module boundaries, plugin extension points, branded types and library-tuned\n  tsconfig, tsdown bundling (vs tsup\u002Ftsc-only\u002Funbuild), package.json exports\n  with dual ESM+CJS and isomorphic conditions (browser\u002Fworkers\u002FRN\u002Fdeno),\n  Turborepo pipelines, publint and @arethetypeswrong\u002Fcli verification,\n  changesets pre-release mode, npm dist-tags (latest\u002Fnext\u002Fbeta\u002Frc\u002Fcanary),\n  and the alpha→beta→rc→stable release lifecycle. Triggers on: build a TS\n  SDK, extract core library, package.json exports, dual ESM CJS, tsdown\n  config, tsup vs tsdown, publint, attw, changesets prerelease, npm\n  dist-tag, beta to rc, canary release, pnpm workspace SDK, isomorphic SDK,\n  tsconfig library, npm provenance, shipping a TypeScript library.\nlicense: MIT\nmetadata:\n  author: oh-my-openclaw\n  version: \"1.0\"\n  composed_from:\n    - agent-cli-architecture\n    - typescript-pro\n    - turborepo\n    - monorepo-navigator\n  sources:\n    - code-architecture-refactoring\n    - architecture-patterns\n    - turborepo\n    - fastify\n    - Jeffallan\u002Fclaude-skills (typescript-pro)\n    - turborepo (official docs)\n    - monorepo-navigator\n    - publint.dev (rule catalog)\n    - arethetypeswrong.github.io (problem catalog)\n    - tsdown.dev (official docs)\n    - changesets\u002Fchangesets (prerelease + dist-tags docs)\n    - GitHub package.json originals — tRPC, vercel\u002Fai, Inngest, Sanity client, Hono, Zustand, TanStack query-core\n---\n\n# TypeScript SDK Author\n\nEnd-to-end workflow for shipping a TypeScript SDK as a standalone npm package\nfrom inside a pnpm monorepo: workspace layout, public API design, build\nconfiguration, distribution shape, monorepo pipeline, verification, and the\nfull release lifecycle including beta \u002F rc \u002F canary channels.\n\nThe seven references hold the depth. This file is the unified workflow plus\na quick-reference for the patterns you reach for daily.\n\n---\n\n## When to Use This Skill\n\n- Extracting a core library (e.g. `packages\u002Fcore`, `packages\u002Fsdk`) out of an\n  existing CLI or app inside a pnpm workspace\n- Designing the public API surface of a TypeScript library that strangers will\n  consume — branded types, generic clients, plugin extension points\n- Choosing a build tool — tsdown vs tsup vs tsc-only vs unbuild\n- Authoring the `package.json` `exports` field with dual ESM+CJS, isomorphic\n  runtime conditions, and subpath plugin entries\n- Configuring Turborepo so the SDK rebuilds only when its inputs change and\n  downstream apps consume the SDK's build output (or raw `src` via a custom\n  condition)\n- Wiring `publint --strict` and `attw --pack` into `prepublishOnly` or CI\n- Managing pre-release channels — `canary` per commit, `next` for the upcoming\n  major, `beta` \u002F `rc` for stabilization, `latest` for stable — and the\n  transitions between them (`beta.N` → `rc.0` → `1.0.0` → `1.1.0-beta.0`)\n- Setting up changesets with GitHub Actions `changesets\u002Faction@v1` plus\n  npm provenance\n\n---\n\n## Execution Workflow\n\nA single TS SDK build flows through these seven phases. Skip any phase and\nsomething will break later — the dependencies between phases are real.\n\n### Phase 1 — Workspace & Package Skeleton\n\nLay down the monorepo and create the empty SDK package.\n\nCore moves:\n\n1. Adopt `apps\u002F` + `packages\u002F` + optional `tools\u002F` at the workspace root\n2. Place the SDK in `packages\u002F\u003Csdk-name>\u002F` (or `packages\u002Fcore\u002F`)\n3. Give it a scoped name (`@\u003Corg>\u002F\u003Csdk-name>`)\n4. Wire workspace-internal deps with the `workspace:*` protocol\n5. Decide BEFORE anything else: this package will eventually be published,\n   so design the boundary and naming with that in mind\n\n```\nmy-repo\u002F\n├── pnpm-workspace.yaml\n├── package.json          # root: only devDeps + workspace scripts\n├── apps\u002F\n│   └── example-app\u002F      # consumer of the SDK\n└── packages\u002F\n    ├── sdk\u002F              # ← the SDK\n    └── shared-tsconfig\u002F  # internal-only, never published\n```\n\n```yaml\n# pnpm-workspace.yaml\npackages:\n  - \"apps\u002F*\"\n  - \"packages\u002F*\"\n```\n\n**Read next:** `references\u002Fworkspace-and-layout.md` — §2 layout, §3 SDK naming\npatterns, §4 internal package creation, §5 `package.json` skeleton, §7 multi\n-repo → monorepo migration.\n\n### Phase 2 — Public API Surface\n\nBefore writing any code, decide what the SDK's public face looks like.\n\nTwo parallel concerns:\n\n**A. Module boundaries.** The `src\u002F` tree splits cleanly into `api\u002F` (what\ngets re-exported and is part of the contract) and `internal\u002F` (do not import\nfrom outside the package). The `package.json` `exports` field is your\ncheapest enforcement mechanism — anything not listed there cannot be\nimported by consumers.\n\n```\npackages\u002Fsdk\u002Fsrc\u002F\n├── index.ts          # barrel — re-exports from api\u002F\n├── api\u002F\n│   ├── client.ts\n│   └── types.ts\n└── internal\u002F\n    ├── transport.ts  # NOT exported\n    └── state.ts      # NOT exported\n```\n\n**B. Type design.** SDK types are consumed by strangers, must not leak\ninternals, must be evolvable. Use:\n\n- **Branded types** for opaque IDs: `type UserId = Brand\u003Cstring, \"UserId\">`\n- **Generic clients** with sensible defaults so adding type params later is\n  non-breaking: `createClient\u003CSchema = DefaultSchema>(...)`\n- **Discriminated unions** for result types: `Result\u003CT, E>` with\n  `{ ok: true; value: T } | { ok: false; error: E }`\n- **Builder pattern** for type-safe configuration when option combinations\n  matter\n- **Interfaces** (not type aliases) when users may need to extend the type\n  via declaration merging\n\n**Read next:**\n\n- `references\u002Fmodule-boundaries-and-plugins.md` — §2 `src\u002F` boundary,\n  §3 runtime layering, §4 provider\u002Fadapter, §5 plugin extension, §6 boundary\n  enforcement, §7 patterns vs anti-patterns\n- `references\u002Ftype-design-for-public-api.md` — §1 branded types, §2 generic\n  surfaces, §3 conditional\u002Fmapped types, §4 type guards, §5 builder, §6\n  utility types ship\u002Finternal, §7 tsconfig for libraries, §8 API evolution\n\n### Phase 3 — Build Configuration\n\nYou need (a) a `tsconfig.json` tuned for library output, and (b) a bundler\nthat produces the actual `dist\u002F`.\n\n**tsconfig for libraries** — the critical flags:\n\n```jsonc\n\u002F\u002F tsconfig.build.json — library build config\n{\n  \"compilerOptions\": {\n    \"target\": \"es2022\",\n    \"module\": \"nodenext\",\n    \"moduleResolution\": \"nodenext\",\n    \"strict\": true,\n    \"declaration\": true,             \u002F\u002F emit .d.ts\n    \"declarationMap\": true,          \u002F\u002F sourcemap from .d.ts → .ts\n    \"sourceMap\": true,\n    \"verbatimModuleSyntax\": true,    \u002F\u002F TS 5.0+ — strict import elision\n    \"isolatedDeclarations\": true,    \u002F\u002F TS 5.5+ — explicit return types on public API\n    \"composite\": true,               \u002F\u002F enable project references\n    \"outDir\": \".\u002Fdist\",\n    \"rootDir\": \".\u002Fsrc\"\n  },\n  \"include\": [\"src\"]\n}\n```\n\n**Bundler choice in 2026:** `tsdown`. tRPC and Inngest migrated to it from\ntsup; tsup's own README now says *\"This project is not actively maintained\nanymore. Please consider using tsdown instead.\"*\n\nMinimum viable `tsdown.config.ts`:\n\n```ts\nimport { defineConfig } from \"tsdown\";\n\nexport default defineConfig({\n  entry: [\"src\u002Findex.ts\", \"src\u002Fplugin\u002Findex.ts\", \"src\u002Ftesting\u002Findex.ts\"],\n  format: [\"esm\", \"cjs\"],\n  dts: true,\n  sourcemap: true,\n  treeshake: true,\n  clean: true,\n  outExtensions: ({ format }) => ({\n    js: format === \"esm\" ? \".mjs\" : \".cjs\",\n    dts: format === \"esm\" ? \".d.mts\" : \".d.cts\",\n  }),\n});\n```\n\n**Alternatives:**\n\n- `tsc-only` \u002F `zshy` — small SDK with no runtime deps, source-faithful publish\n- `unbuild` — only when already in UnJS ecosystem\n- `tsup` — community familiarity but losing mind-share; viable for inertia\n\n**Read next:**\n\n- `references\u002Ftsdown-bundling.md` — §3 verdict, §4 working config, §6–§8\n  alternatives, §11 selection decision tree\n- `references\u002Ftype-design-for-public-api.md` §7 — full library tsconfig\n  walkthrough\n\n### Phase 4 — Distribution Shape (`package.json` `exports`)\n\nThis is where most TS SDK bugs live. Five invariants:\n\n1. `types` **must** be first inside each `import` \u002F `require` branch\n2. `default` **must** be last\n3. Dual ESM+CJS needs **separate** `.d.mts` and `.d.cts` (TS 5.0+)\n4. Always include `\".\u002Fpackage.json\": \".\u002Fpackage.json\"` (lets publint\u002Fattw introspect)\n5. `module` before `require` if you use both\n\nThe canonical dual shape (verbatim from `@trpc\u002Fserver`):\n\n```json\n{\n  \"exports\": {\n    \".\u002Fpackage.json\": \".\u002Fpackage.json\",\n    \".\": {\n      \"import\": {\n        \"types\": \".\u002Fdist\u002Findex.d.mts\",\n        \"default\": \".\u002Fdist\u002Findex.mjs\"\n      },\n      \"require\": {\n        \"types\": \".\u002Fdist\u002Findex.d.cts\",\n        \"default\": \".\u002Fdist\u002Findex.cjs\"\n      }\n    }\n  }\n}\n```\n\nAdd subpaths for plugin entry points so they version separately from the\nroot barrel:\n\n```json\n{\n  \"exports\": {\n    \".\":          { \"import\": { ... }, \"require\": { ... } },\n    \".\u002Fplugin\":   { \"import\": { ... }, \"require\": { ... } },\n    \".\u002Ftesting\":  { \"import\": { ... }, \"require\": { ... } }\n  }\n}\n```\n\nFor isomorphic SDKs (browser \u002F workers \u002F RN \u002F edge), runtime conditions\ncome **before** `import` \u002F `require`:\n\n```json\n{\n  \".\": {\n    \"browser\":      { \"import\": \".\u002Fdist\u002Fbrowser.mjs\" },\n    \"workerd\":      { \"import\": \".\u002Fdist\u002Fworkerd.mjs\" },\n    \"react-native\": { \"import\": \".\u002Fdist\u002Frn.mjs\" },\n    \"deno\":         { \"import\": \".\u002Fdist\u002Fdeno.mjs\" },\n    \"import\":       { \"types\": \".\u002Fdist\u002Findex.d.mts\", \"default\": \".\u002Fdist\u002Findex.mjs\" },\n    \"require\":      { \"types\": \".\u002Fdist\u002Findex.d.cts\", \"default\": \".\u002Fdist\u002Findex.cjs\" }\n  }\n}\n```\n\n**Read next:** `references\u002Fpackage-json-exports.md` — §3 the five rules,\n§4 tRPC dual pattern annotated, §5 ESM-only pattern, §6 subpath plugins,\n§7 isomorphic conditions (Sanity client pattern), §9 common mistakes\nbad → fixed → why.\n\n### Phase 5 — Monorepo Pipeline (Turborepo)\n\nOnce the SDK builds in isolation, wire it into the workspace so:\n\n- Apps rebuild only when SDK output changes (caching)\n- Local dev rebuilds SDK in watch mode while the app reloads\n- CI builds only affected packages on PRs\n\nMinimum viable `turbo.json`:\n\n```json\n{\n  \"$schema\": \"https:\u002F\u002Fturborepo.com\u002Fschema.json\",\n  \"tasks\": {\n    \"build\": {\n      \"dependsOn\": [\"^build\"],\n      \"inputs\": [\"src\u002F**\", \"tsconfig*.json\", \"tsdown.config.ts\", \"package.json\"],\n      \"outputs\": [\"dist\u002F**\"]\n    },\n    \"test\":      { \"dependsOn\": [\"^build\"], \"inputs\": [\"src\u002F**\", \"test\u002F**\"] },\n    \"lint\":      { \"inputs\": [\"src\u002F**\"] },\n    \"typecheck\": { \"dependsOn\": [\"^build\"], \"inputs\": [\"src\u002F**\", \"tsconfig*.json\"] },\n    \"dev\":       { \"persistent\": true, \"cache\": false }\n  }\n}\n```\n\nDaily `--filter` patterns:\n\n```bash\npnpm turbo run build --filter=@acme\u002Fsdk                   # SDK alone\npnpm turbo run dev   --filter=@acme\u002Fsdk... --filter=@acme\u002Fexample-app\npnpm turbo run test  --filter=...@acme\u002Fsdk                # affected-by-SDK\npnpm turbo run lint  --filter=[HEAD^1]                    # affected since last commit\n```\n\n**Critical rules:** put scripts in **each** package's `package.json`, not in\nroot. Root only delegates `turbo run X`.\n\n**Read next:** `references\u002Fturborepo-for-sdk.md` — §2 minimum viable\n`turbo.json`, §3 per-package vs root, §4 `dependsOn`, §5 caching\ninputs\u002Foutputs, §6 `--filter` patterns, §7 boundaries field, §8 CI patterns,\n§9 dev mode with watch.\n\n### Phase 6 — Verification\n\nBefore publish, two static checks + one runtime check are non-negotiable:\n\n```bash\n# After pnpm build:\npnpm exec publint --strict                   # static lint of package.json\npnpm exec attw --pack .                      # simulate Node\u002FBun\u002FDeno\u002Fbundler resolution\n\n# Then pack + install in a sandbox dir\npnpm pack\ncd \u002Ftmp\u002Fsandbox && npm init -y && npm install \u002Fpath\u002Fto\u002Fyour-pkg-1.0.0.tgz\nnode -e \"console.log(require('@acme\u002Fsdk'))\"                          # CJS reaches\nnode --input-type=module -e \"import('@acme\u002Fsdk').then(console.log)\"  # ESM reaches\n```\n\nWire all three into `prepublishOnly`:\n\n```json\n{\n  \"scripts\": {\n    \"prepublishOnly\": \"pnpm build && pnpm exec publint --strict && pnpm exec attw --pack .\"\n  }\n}\n```\n\n**Why both publint and attw?** publint statically checks `package.json`\nshape; attw actually simulates how each consumer runtime resolves your\ntarball. The most common attw failure is **Masquerading ESM** — a `.js`\nfile that contains ESM but is exposed under `require` — which publint\ncannot catch.\n\n**Read next:** `references\u002Fverification-and-publishing.md` — §2 publint\nrules + 3 common failures, §3 attw resolution-mode table + 7 failure modes,\n§4 smoke tests (tarball → fresh dir).\n\n### Phase 7 — Release Lifecycle\n\nThis is where most SDK projects accumulate debt. Get it right from day 1.\n\n**Semver + pre-release identifiers:**\n\n```\n0.x.y           # pre-1.0 — breaking changes allowed in minors\n1.0.0-alpha.0   # internal feature spike\n1.0.0-beta.0    # feature-complete, API may still shift\n1.0.0-rc.0      # frozen, blocker-only fixes\n1.0.0           # stable\n1.0.1           # patch on stable\n1.1.0-beta.0    # next minor's beta cycle while 1.0.x ships patches\n```\n\n**npm dist-tags — never publish a pre-release to `latest`:**\n\n```bash\n# Publish a beta under the `beta` tag (NOT `latest`)\nnpm publish --tag beta\n\n# Recover from a mistaken latest:\nnpm dist-tag add @acme\u002Fsdk@1.0.0 latest      # repoint latest to stable\nnpm dist-tag rm  @acme\u002Fsdk beta              # if no longer needed\n```\n\nConvention tags: `latest` (stable), `next` (upcoming major prerelease),\n`beta`, `rc`, `canary` (per-commit), `alpha`, `experimental`, `nightly`.\n\n**changesets pre-release mode — the canonical transitions:**\n\n```bash\n# Cut beta line\npnpm changeset pre enter beta\npnpm changeset                  # write a changeset\npnpm changeset version          # bumps to 1.0.0-beta.0\npnpm changeset publish\n\n# Feature-complete; move beta → rc\npnpm changeset pre exit\npnpm changeset pre enter rc\npnpm changeset version          # bumps to 1.0.0-rc.0\npnpm changeset publish\n\n# RC stable; ship 1.0.0\npnpm changeset pre exit\npnpm changeset version          # bumps to 1.0.0\npnpm changeset publish\n\n# Open next minor's beta line\npnpm changeset pre enter beta\npnpm changeset version          # bumps to 1.1.0-beta.0\n```\n\n**npm provenance** — turn it on:\n\n```json\n{\n  \"publishConfig\": {\n    \"access\": \"public\",\n    \"provenance\": true\n  }\n}\n```\n\nPair with `id-token: write` permission in the GitHub Actions release job;\nnpm will display a verified attestation on the package page.\n\n**Read next:** `references\u002Fverification-and-publishing.md` — §5 semver\nrefresher, §6 dist-tag rules, §7 full lifecycle state diagram, §8 case\nstudies (Next.js \u002F vercel-ai \u002F tRPC \u002F Storybook \u002F Stripe with real version\nsequences), §9 changesets pre-release flow, §10 GitHub Actions release\nworkflow, §11 provenance, §12 yank vs deprecate, §13 strategy decision tree.\n\n---\n\n## Quick Reference\n\n### File \u002F Field Cheat Sheet\n\n| File | Owns | Quick check |\n|---|---|---|\n| `pnpm-workspace.yaml` | Which dirs are packages | `apps\u002F*` + `packages\u002F*` |\n| Root `package.json` | Workspace devDeps + `turbo run` delegates | No package-level build script in root |\n| Package `package.json` | `name`, `version`, `type`, `exports`, `files`, `sideEffects`, `bin`, `scripts.prepublishOnly` | Run `publint --strict` |\n| Package `tsconfig.json` | Editor + `tsc --noEmit` | `strict: true` + `declaration: true` |\n| `tsconfig.build.json` | Library build config | `isolatedDeclarations: true` if you want fast `.d.ts` |\n| `tsdown.config.ts` | Bundling | `format: ['esm', 'cjs']` + dual `outExtensions` |\n| `turbo.json` | Task pipeline | `dependsOn: ['^build']` for compile order |\n| `.changeset\u002Fconfig.json` | Release policy | `commit: false`, `access: public` |\n\n### Bundler Selection at a Glance\n\n| Situation | Choice |\n|---|---|\n| Modern TS SDK, dual ESM+CJS, plugin subpaths | **tsdown** |\n| Zero runtime deps, want raw source-faithful publish | `tsc` only \u002F `zshy` |\n| Existing project on tsup that works | Stay on tsup; plan tsdown migration |\n| UnJS \u002F Nuxt ecosystem | unbuild |\n| Need bundle-splitting + advanced rollup config | Direct `rolldown` |\n\n### Module-Format Decision\n\n| Situation | Recommendation |\n|---|---|\n| Default for new SDK in 2026 | **dual ESM + CJS** |\n| Library has stable consumer base ≥ Node 22 | ESM-only is defensible |\n| Library is internal-only inside a Node app | ESM-only |\n| Library is consumed by Jest, older Next.js, Lambda CJS | **dual** is mandatory |\n\n### Release Tag at a Glance\n\n| Tag | Meaning | `npm install pkg@?` resolves |\n|---|---|---|\n| `latest` | The current stable | `npm install pkg` |\n| `next` | Upcoming major prerelease | `npm install pkg@next` |\n| `beta` | Feature-complete stabilization | `npm install pkg@beta` |\n| `rc` | Frozen, blocker-only | `npm install pkg@rc` |\n| `canary` | Per-commit\u002Fper-PR snapshot | `npm install pkg@canary` |\n| `experimental` | Unstable spike | `npm install pkg@experimental` |\n\n### One-Liner Snippets You'll Type Often\n\n```bash\n# Add the SDK as a workspace-internal dep\npnpm add @acme\u002Fsdk@workspace:* --filter @acme\u002Fexample-app\n\n# Build SDK + everything that depends on it\npnpm turbo run build --filter=...@acme\u002Fsdk\n\n# Pre-publish gate\npnpm build && pnpm exec publint --strict && pnpm exec attw --pack .\n\n# Cut a snapshot release for a PR (vercel\u002Fai pattern)\npnpm changeset version --snapshot pr-123\npnpm publish --tag pr-123 --no-git-checks\n```\n\n---\n\n## Pre-Publish Checklist\n\nRun through this once per release. Skipping any item is how broken SDKs\nship.\n\n### Build artifact\n\n- [ ] `pnpm build` produces `dist\u002F` with both `.mjs` and `.cjs` (if dual) or just `.mjs` (if ESM-only)\n- [ ] `.d.mts` and `.d.cts` exist for dual, OR `.d.ts` only for ESM-only\n- [ ] Source maps emitted (`.mjs.map`, `.d.mts.map`)\n- [ ] `dist\u002F` size is reasonable (`du -sh dist\u002F` — sanity check, no surprise bloat)\n\n### package.json\n\n- [ ] `name` is scoped (`@org\u002Fname`) — required if you'll ever go private later\n- [ ] `version` matches what you're about to publish\n- [ ] `type` matches your default format (`\"module\"` for ESM-default, omit for CJS-default)\n- [ ] `exports` has `\".\u002Fpackage.json\": \".\u002Fpackage.json\"`\n- [ ] Every `exports` branch has `types` first, `default` last\n- [ ] `files` lists `dist` (and `src` if shipping sources for IDE jump-to-def)\n- [ ] `sideEffects: false` (unless you genuinely have top-level side effects)\n- [ ] `publishConfig.access: \"public\"` for first scoped publish\n- [ ] `publishConfig.provenance: true`\n\n### Verification\n\n- [ ] `publint --strict` passes\n- [ ] `attw --pack .` passes (or only has expected `node10` warnings)\n- [ ] Smoke test: pack + install in `\u002Ftmp` + CJS + ESM + TS consumer all resolve\n\n### Release\n\n- [ ] Correct dist-tag chosen (`latest` only for stable)\n- [ ] If pre-release: `pnpm changeset pre enter \u003Ctag>` was run BEFORE `version`\n- [ ] If stable: `pnpm changeset pre exit` was run if previously in pre-mode\n- [ ] CHANGELOG.md reflects the change\n- [ ] Git tag matches version (e.g. `v1.0.0-beta.3`)\n- [ ] Provenance attestation visible on npm package page\n\n---\n\n## Common Mistakes\n\n| Mistake | What goes wrong | Fix |\n|---|---|---|\n| `types` not first inside `exports` branch | TS picks up `.js` as type source → cascade of errors at consumer | Move `types` to top of each `import` \u002F `require` branch (publint will flag) |\n| Single `.d.ts` for dual ESM+CJS | TS resolves the `.d.ts` against the wrong module mode | Emit `.d.mts` + `.d.cts` (TS 5.0+); tsdown does this automatically |\n| Missing `\".\u002Fpackage.json\": \".\u002Fpackage.json\"` in exports | publint\u002Fattw cannot introspect your package | Always include it |\n| Publishing pre-release to `latest` | Every `npm install pkg` user gets your beta | Use `npm publish --tag beta`; recover via `npm dist-tag add pkg@stable latest` |\n| Forgetting `pnpm changeset pre exit` before stable release | Stable version comes out as `1.0.0-beta.N` instead of `1.0.0` | Always `pre exit` before final |\n| Root `package.json` containing the actual build script | Defeats Turborepo parallelism + caching | Per-package scripts; root only delegates via `turbo run` |\n| Deep imports into `dist\u002Finternal\u002F...` from consumers | Consumers couple to internals; your refactors break them | Don't list internals in `exports`; use ESLint `no-restricted-imports` |\n| Leaking internal types into public API surface | Users see types they shouldn't depend on | Re-export only from `src\u002Fapi\u002F*.ts`; don't `export *` from internals |\n| Missing `sideEffects: false` with no side effects | Bundlers can't tree-shake your library | Add `\"sideEffects\": false` or list the actual side-effecting files |\n| Forgetting `id-token: write` permission for provenance | Provenance attestation fails silently in CI | Add `permissions: { id-token: write, contents: read }` to release job |\n| Mixing watch + build in same Turbo task | Cache invalidates constantly; watch never settles | Separate `build` (cacheable) and `dev` (`persistent: true, cache: false`) |\n| `exports` with both `module` and unrelated runtime conditions in wrong order | Edge runtime picks the wrong file | Runtime conditions (`browser`, `workerd`) → `module` → `import` → `require` → `default` |\n| Using `enum` in public API types | Forces consumers into TS-only land, breaks erasable syntax | Use union of string literals or `as const` objects |\n| Using `default` export from the SDK root | Breaks tree-shaking + interop story | Always named exports |\n\n---\n\n## Reference Files\n\n| File | Use when |\n|---|---|\n| `references\u002Fworkspace-and-layout.md` | Setting up `apps\u002F` + `packages\u002F` + `tools\u002F`; naming the SDK package; creating internal packages; choosing dep field (`dependencies` \u002F `peerDependencies` \u002F `devDependencies`); migrating from multi-repo |\n| `references\u002Fmodule-boundaries-and-plugins.md` | Splitting `src\u002F` into `api\u002F` vs `internal\u002F`; designing the orchestration layer vs adapters vs tools; building a plugin extension model with lifecycle hooks; enforcing boundaries via eslint-plugin-boundaries \u002F dependency-cruiser \u002F Turbo `boundaries` |\n| `references\u002Ftype-design-for-public-api.md` | Branded types; generic clients; conditional + mapped types; type-safe builders; which utility types to ship vs keep internal; tsconfig flags for libraries (`verbatimModuleSyntax`, `isolatedDeclarations`, `composite`); API evolution patterns |\n| `references\u002Fpackage-json-exports.md` | Authoring the `exports` field; dual ESM+CJS with separate `.d.mts`\u002F`.d.cts`; subpath plugin entries; isomorphic runtime conditions (`browser`, `workerd`, `react-native`, `deno`, `edge-light`); fixing common `exports` bugs |\n| `references\u002Ftsdown-bundling.md` | Choosing tsdown vs tsup vs tsc-only vs unbuild; minimum-viable `tsdown.config.ts`; subpath output mapping; side-effects + tree-shaking; watch & dev mode; bundler selection decision tree |\n| `references\u002Fturborepo-for-sdk.md` | Writing `turbo.json` for an SDK monorepo; `dependsOn: ['^build']`; caching `inputs`\u002F`outputs`; `--filter` patterns for SDK dev; the `boundaries` field; CI with remote cache + affected-only builds; dev mode with `persistent: true` |\n| `references\u002Fverification-and-publishing.md` | publint + attw setup; tarball smoke tests; semver + pre-release identifiers; npm dist-tags; the full beta → rc → stable → next-cycle state machine; changesets pre-release mode; the canonical `beta → rc` transition command sequence; GitHub Actions release workflow with snapshot PRs; npm provenance; yank vs deprecate; release-strategy decision tree |\n\n---\n\n## Source Skills\n\nThis skill was composed from four source skills inside `oh-my-openclaw`:\n\n- **`agent-cli-architecture`** (architect-claw) — workspace structure, module\n  boundaries, runtime layering, plugin extension patterns. Generalized from\n  \"agent CLI\" framing to general \"SDK + supporting CLI\".\n- **`typescript-pro`** (frontend-claw) — branded types, generics, conditional\n  types, type guards, utility types, tsconfig deep dive. Reframed toward\n  library\u002FSDK-author concerns.\n- **`turborepo`** (frontend-claw) — task pipelines, caching, `--filter`,\n  `boundaries`. Heavily trimmed to SDK-monorepo-relevant subset.\n- **`monorepo-navigator`** (architect-claw) — pnpm workspaces, changesets,\n  publishing, migration.\n\nPlus original research on `package.json exports`, dual ESM\u002FCJS in 2026,\nthe tsdown landscape, publint + attw, and the alpha→beta→rc→stable\nlifecycle, with verbatim examples from the GitHub `package.json` of\ntRPC, vercel\u002Fai, Inngest, Sanity client, Hono, Zustand, and TanStack\nquery-core.\n","# TypeScript SDK Author\n\nEnd-to-end workflow for shipping a TypeScript SDK as a standalone npm package\nfrom inside a pnpm monorepo: workspace layout, public API design, build\nconfiguration, distribution shape, monorepo pipeline, verification, and the\nfull release lifecycle including beta \u002F rc \u002F canary channels.\n\nThe seven references hold the depth. This file is the unified workflow plus\na quick-reference for the patterns you reach for daily.\n\n---\n\n## When to Use This Skill\n\n- Extracting a core library (e.g. `packages\u002Fcore`, `packages\u002Fsdk`) out of an\n  existing CLI or app inside a pnpm workspace\n- Designing the public API surface of a TypeScript library that strangers will\n  consume — branded types, generic clients, plugin extension points\n- Choosing a build tool — tsdown vs tsup vs tsc-only vs unbuild\n- Authoring the `package.json` `exports` field with dual ESM+CJS, isomorphic\n  runtime conditions, and subpath plugin entries\n- Configuring Turborepo so the SDK rebuilds only when its inputs change and\n  downstream apps consume the SDK's build output (or raw `src` via a custom\n  condition)\n- Wiring `publint --strict` and `attw --pack` into `prepublishOnly` or CI\n- Managing pre-release channels — `canary` per commit, `next` for the upcoming\n  major, `beta` \u002F `rc` for stabilization, `latest` for stable — and the\n  transitions between them (`beta.N` → `rc.0` → `1.0.0` → `1.1.0-beta.0`)\n- Setting up changesets with GitHub Actions `changesets\u002Faction@v1` plus\n  npm provenance\n\n---\n\n## Execution Workflow\n\nA single TS SDK build flows through these seven phases. Skip any phase and\nsomething will break later — the dependencies between phases are real.\n\n### Phase 1 — Workspace & Package Skeleton\n\nLay down the monorepo and create the empty SDK package.\n\nCore moves:\n\n1. Adopt `apps\u002F` + `packages\u002F` + optional `tools\u002F` at the workspace root\n2. Place the SDK in `packages\u002F\u003Csdk-name>\u002F` (or `packages\u002Fcore\u002F`)\n3. Give it a scoped name (`@\u003Corg>\u002F\u003Csdk-name>`)\n4. Wire workspace-internal deps with the `workspace:*` protocol\n5. Decide BEFORE anything else: this package will eventually be published,\n   so design the boundary and naming with that in mind\n\n```\nmy-repo\u002F\n├── pnpm-workspace.yaml\n├── package.json          # root: only devDeps + workspace scripts\n├── apps\u002F\n│   └── example-app\u002F      # consumer of the SDK\n└── packages\u002F\n    ├── sdk\u002F              # ← the SDK\n    └── shared-tsconfig\u002F  # internal-only, never published\n```\n\n```yaml\n# pnpm-workspace.yaml\npackages:\n  - \"apps\u002F*\"\n  - \"packages\u002F*\"\n```\n\n**Read next:** `references\u002Fworkspace-and-layout.md` — §2 layout, §3 SDK naming\npatterns, §4 internal package creation, §5 `package.json` skeleton, §7 multi\n-repo → monorepo migration.\n\n### Phase 2 — Public API Surface\n\nBefore writing any code, decide what the SDK's public face looks like.\n\nTwo parallel concerns:\n\n**A. Module boundaries.** The `src\u002F` tree splits cleanly into `api\u002F` (what\ngets re-exported and is part of the contract) and `internal\u002F` (do not import\nfrom outside the package). The `package.json` `exports` field is your\ncheapest enforcement mechanism — anything not listed there cannot be\nimported by consumers.\n\n```\npackages\u002Fsdk\u002Fsrc\u002F\n├── index.ts          # barrel — re-exports from api\u002F\n├── api\u002F\n│   ├── client.ts\n│   └── types.ts\n└── internal\u002F\n    ├── transport.ts  # NOT exported\n    └── state.ts      # NOT exported\n```\n\n**B. Type design.** SDK types are consumed by strangers, must not leak\ninternals, must be evolvable. Use:\n\n- **Branded types** for opaque IDs: `type UserId = Brand\u003Cstring, \"UserId\">`\n- **Generic clients** with sensible defaults so adding type params later is\n  non-breaking: `createClient\u003CSchema = DefaultSchema>(...)`\n- **Discriminated unions** for result types: `Result\u003CT, E>` with\n  `{ ok: true; value: T } | { ok: false; error: E }`\n- **Builder pattern** for type-safe configuration when option combinations\n  matter\n- **Interfaces** (not type aliases) when users may need to extend the type\n  via declaration merging\n\n**Read next:**\n\n- `references\u002Fmodule-boundaries-and-plugins.md` — §2 `src\u002F` boundary,\n  §3 runtime layering, §4 provider\u002Fadapter, §5 plugin extension, §6 boundary\n  enforcement, §7 patterns vs anti-patterns\n- `references\u002Ftype-design-for-public-api.md` — §1 branded types, §2 generic\n  surfaces, §3 conditional\u002Fmapped types, §4 type guards, §5 builder, §6\n  utility types ship\u002Finternal, §7 tsconfig for libraries, §8 API evolution\n\n### Phase 3 — Build Configuration\n\nYou need (a) a `tsconfig.json` tuned for library output, and (b) a bundler\nthat produces the actual `dist\u002F`.\n\n**tsconfig for libraries** — the critical flags:\n\n```jsonc\n\u002F\u002F tsconfig.build.json — library build config\n{\n  \"compilerOptions\": {\n    \"target\": \"es2022\",\n    \"module\": \"nodenext\",\n    \"moduleResolution\": \"nodenext\",\n    \"strict\": true,\n    \"declaration\": true,             \u002F\u002F emit .d.ts\n    \"declarationMap\": true,          \u002F\u002F sourcemap from .d.ts → .ts\n    \"sourceMap\": true,\n    \"verbatimModuleSyntax\": true,    \u002F\u002F TS 5.0+ — strict import elision\n    \"isolatedDeclarations\": true,    \u002F\u002F TS 5.5+ — explicit return types on public API\n    \"composite\": true,               \u002F\u002F enable project references\n    \"outDir\": \".\u002Fdist\",\n    \"rootDir\": \".\u002Fsrc\"\n  },\n  \"include\": [\"src\"]\n}\n```\n\n**Bundler choice in 2026:** `tsdown`. tRPC and Inngest migrated to it from\ntsup; tsup's own README now says *\"This project is not actively maintained\nanymore. Please consider using tsdown instead.\"*\n\nMinimum viable `tsdown.config.ts`:\n\n```ts\nimport { defineConfig } from \"tsdown\";\n\nexport default defineConfig({\n  entry: [\"src\u002Findex.ts\", \"src\u002Fplugin\u002Findex.ts\", \"src\u002Ftesting\u002Findex.ts\"],\n  format: [\"esm\", \"cjs\"],\n  dts: true,\n  sourcemap: true,\n  treeshake: true,\n  clean: true,\n  outExtensions: ({ format }) => ({\n    js: format === \"esm\" ? \".mjs\" : \".cjs\",\n    dts: format === \"esm\" ? \".d.mts\" : \".d.cts\",\n  }),\n});\n```\n\n**Alternatives:**\n\n- `tsc-only` \u002F `zshy` — small SDK with no runtime deps, source-faithful publish\n- `unbuild` — only when already in UnJS ecosystem\n- `tsup` — community familiarity but losing mind-share; viable for inertia\n\n**Read next:**\n\n- `references\u002Ftsdown-bundling.md` — §3 verdict, §4 working config, §6–§8\n  alternatives, §11 selection decision tree\n- `references\u002Ftype-design-for-public-api.md` §7 — full library tsconfig\n  walkthrough\n\n### Phase 4 — Distribution Shape (`package.json` `exports`)\n\nThis is where most TS SDK bugs live. Five invariants:\n\n1. `types` **must** be first inside each `import` \u002F `require` branch\n2. `default` **must** be last\n3. Dual ESM+CJS needs **separate** `.d.mts` and `.d.cts` (TS 5.0+)\n4. Always include `\".\u002Fpackage.json\": \".\u002Fpackage.json\"` (lets publint\u002Fattw introspect)\n5. `module` before `require` if you use both\n\nThe canonical dual shape (verbatim from `@trpc\u002Fserver`):\n\n```json\n{\n  \"exports\": {\n    \".\u002Fpackage.json\": \".\u002Fpackage.json\",\n    \".\": {\n      \"import\": {\n        \"types\": \".\u002Fdist\u002Findex.d.mts\",\n        \"default\": \".\u002Fdist\u002Findex.mjs\"\n      },\n      \"require\": {\n        \"types\": \".\u002Fdist\u002Findex.d.cts\",\n        \"default\": \".\u002Fdist\u002Findex.cjs\"\n      }\n    }\n  }\n}\n```\n\nAdd subpaths for plugin entry points so they version separately from the\nroot barrel:\n\n```json\n{\n  \"exports\": {\n    \".\":          { \"import\": { ... }, \"require\": { ... } },\n    \".\u002Fplugin\":   { \"import\": { ... }, \"require\": { ... } },\n    \".\u002Ftesting\":  { \"import\": { ... }, \"require\": { ... } }\n  }\n}\n```\n\nFor isomorphic SDKs (browser \u002F workers \u002F RN \u002F edge), runtime conditions\ncome **before** `import` \u002F `require`:\n\n```json\n{\n  \".\": {\n    \"browser\":      { \"import\": \".\u002Fdist\u002Fbrowser.mjs\" },\n    \"workerd\":      { \"import\": \".\u002Fdist\u002Fworkerd.mjs\" },\n    \"react-native\": { \"import\": \".\u002Fdist\u002Frn.mjs\" },\n    \"deno\":         { \"import\": \".\u002Fdist\u002Fdeno.mjs\" },\n    \"import\":       { \"types\": \".\u002Fdist\u002Findex.d.mts\", \"default\": \".\u002Fdist\u002Findex.mjs\" },\n    \"require\":      { \"types\": \".\u002Fdist\u002Findex.d.cts\", \"default\": \".\u002Fdist\u002Findex.cjs\" }\n  }\n}\n```\n\n**Read next:** `references\u002Fpackage-json-exports.md` — §3 the five rules,\n§4 tRPC dual pattern annotated, §5 ESM-only pattern, §6 subpath plugins,\n§7 isomorphic conditions (Sanity client pattern), §9 common mistakes\nbad → fixed → why.\n\n### Phase 5 — Monorepo Pipeline (Turborepo)\n\nOnce the SDK builds in isolation, wire it into the workspace so:\n\n- Apps rebuild only when SDK output changes (caching)\n- Local dev rebuilds SDK in watch mode while the app reloads\n- CI builds only affected packages on PRs\n\nMinimum viable `turbo.json`:\n\n```json\n{\n  \"$schema\": \"https:\u002F\u002Fturborepo.com\u002Fschema.json\",\n  \"tasks\": {\n    \"build\": {\n      \"dependsOn\": [\"^build\"],\n      \"inputs\": [\"src\u002F**\", \"tsconfig*.json\", \"tsdown.config.ts\", \"package.json\"],\n      \"outputs\": [\"dist\u002F**\"]\n    },\n    \"test\":      { \"dependsOn\": [\"^build\"], \"inputs\": [\"src\u002F**\", \"test\u002F**\"] },\n    \"lint\":      { \"inputs\": [\"src\u002F**\"] },\n    \"typecheck\": { \"dependsOn\": [\"^build\"], \"inputs\": [\"src\u002F**\", \"tsconfig*.json\"] },\n    \"dev\":       { \"persistent\": true, \"cache\": false }\n  }\n}\n```\n\nDaily `--filter` patterns:\n\n```bash\npnpm turbo run build --filter=@acme\u002Fsdk                   # SDK alone\npnpm turbo run dev   --filter=@acme\u002Fsdk... --filter=@acme\u002Fexample-app\npnpm turbo run test  --filter=...@acme\u002Fsdk                # affected-by-SDK\npnpm turbo run lint  --filter=[HEAD^1]                    # affected since last commit\n```\n\n**Critical rules:** put scripts in **each** package's `package.json`, not in\nroot. Root only delegates `turbo run X`.\n\n**Read next:** `references\u002Fturborepo-for-sdk.md` — §2 minimum viable\n`turbo.json`, §3 per-package vs root, §4 `dependsOn`, §5 caching\ninputs\u002Foutputs, §6 `--filter` patterns, §7 boundaries field, §8 CI patterns,\n§9 dev mode with watch.\n\n### Phase 6 — Verification\n\nBefore publish, two static checks + one runtime check are non-negotiable:\n\n```bash\n# After pnpm build:\npnpm exec publint --strict                   # static lint of package.json\npnpm exec attw --pack .                      # simulate Node\u002FBun\u002FDeno\u002Fbundler resolution\n\n# Then pack + install in a sandbox dir\npnpm pack\ncd \u002Ftmp\u002Fsandbox && npm init -y && npm install \u002Fpath\u002Fto\u002Fyour-pkg-1.0.0.tgz\nnode -e \"console.log(require('@acme\u002Fsdk'))\"                          # CJS reaches\nnode --input-type=module -e \"import('@acme\u002Fsdk').then(console.log)\"  # ESM reaches\n```\n\nWire all three into `prepublishOnly`:\n\n```json\n{\n  \"scripts\": {\n    \"prepublishOnly\": \"pnpm build && pnpm exec publint --strict && pnpm exec attw --pack .\"\n  }\n}\n```\n\n**Why both publint and attw?** publint statically checks `package.json`\nshape; attw actually simulates how each consumer runtime resolves your\ntarball. The most common attw failure is **Masquerading ESM** — a `.js`\nfile that contains ESM but is exposed under `require` — which publint\ncannot catch.\n\n**Read next:** `references\u002Fverification-and-publishing.md` — §2 publint\nrules + 3 common failures, §3 attw resolution-mode table + 7 failure modes,\n§4 smoke tests (tarball → fresh dir).\n\n### Phase 7 — Release Lifecycle\n\nThis is where most SDK projects accumulate debt. Get it right from day 1.\n\n**Semver + pre-release identifiers:**\n\n```\n0.x.y           # pre-1.0 — breaking changes allowed in minors\n1.0.0-alpha.0   # internal feature spike\n1.0.0-beta.0    # feature-complete, API may still shift\n1.0.0-rc.0      # frozen, blocker-only fixes\n1.0.0           # stable\n1.0.1           # patch on stable\n1.1.0-beta.0    # next minor's beta cycle while 1.0.x ships patches\n```\n\n**npm dist-tags — never publish a pre-release to `latest`:**\n\n```bash\n# Publish a beta under the `beta` tag (NOT `latest`)\nnpm publish --tag beta\n\n# Recover from a mistaken latest:\nnpm dist-tag add @acme\u002Fsdk@1.0.0 latest      # repoint latest to stable\nnpm dist-tag rm  @acme\u002Fsdk beta              # if no longer needed\n```\n\nConvention tags: `latest` (stable), `next` (upcoming major prerelease),\n`beta`, `rc`, `canary` (per-commit), `alpha`, `experimental`, `nightly`.\n\n**changesets pre-release mode — the canonical transitions:**\n\n```bash\n# Cut beta line\npnpm changeset pre enter beta\npnpm changeset                  # write a changeset\npnpm changeset version          # bumps to 1.0.0-beta.0\npnpm changeset publish\n\n# Feature-complete; move beta → rc\npnpm changeset pre exit\npnpm changeset pre enter rc\npnpm changeset version          # bumps to 1.0.0-rc.0\npnpm changeset publish\n\n# RC stable; ship 1.0.0\npnpm changeset pre exit\npnpm changeset version          # bumps to 1.0.0\npnpm changeset publish\n\n# Open next minor's beta line\npnpm changeset pre enter beta\npnpm changeset version          # bumps to 1.1.0-beta.0\n```\n\n**npm provenance** — turn it on:\n\n```json\n{\n  \"publishConfig\": {\n    \"access\": \"public\",\n    \"provenance\": true\n  }\n}\n```\n\nPair with `id-token: write` permission in the GitHub Actions release job;\nnpm will display a verified attestation on the package page.\n\n**Read next:** `references\u002Fverification-and-publishing.md` — §5 semver\nrefresher, §6 dist-tag rules, §7 full lifecycle state diagram, §8 case\nstudies (Next.js \u002F vercel-ai \u002F tRPC \u002F Storybook \u002F Stripe with real version\nsequences), §9 changesets pre-release flow, §10 GitHub Actions release\nworkflow, §11 provenance, §12 yank vs deprecate, §13 strategy decision tree.\n\n---\n\n## Quick Reference\n\n### File \u002F Field Cheat Sheet\n\n| File | Owns | Quick check |\n|---|---|---|\n| `pnpm-workspace.yaml` | Which dirs are packages | `apps\u002F*` + `packages\u002F*` |\n| Root `package.json` | Workspace devDeps + `turbo run` delegates | No package-level build script in root |\n| Package `package.json` | `name`, `version`, `type`, `exports`, `files`, `sideEffects`, `bin`, `scripts.prepublishOnly` | Run `publint --strict` |\n| Package `tsconfig.json` | Editor + `tsc --noEmit` | `strict: true` + `declaration: true` |\n| `tsconfig.build.json` | Library build config | `isolatedDeclarations: true` if you want fast `.d.ts` |\n| `tsdown.config.ts` | Bundling | `format: ['esm', 'cjs']` + dual `outExtensions` |\n| `turbo.json` | Task pipeline | `dependsOn: ['^build']` for compile order |\n| `.changeset\u002Fconfig.json` | Release policy | `commit: false`, `access: public` |\n\n### Bundler Selection at a Glance\n\n| Situation | Choice |\n|---|---|\n| Modern TS SDK, dual ESM+CJS, plugin subpaths | **tsdown** |\n| Zero runtime deps, want raw source-faithful publish | `tsc` only \u002F `zshy` |\n| Existing project on tsup that works | Stay on tsup; plan tsdown migration |\n| UnJS \u002F Nuxt ecosystem | unbuild |\n| Need bundle-splitting + advanced rollup config | Direct `rolldown` |\n\n### Module-Format Decision\n\n| Situation | Recommendation |\n|---|---|\n| Default for new SDK in 2026 | **dual ESM + CJS** |\n| Library has stable consumer base ≥ Node 22 | ESM-only is defensible |\n| Library is internal-only inside a Node app | ESM-only |\n| Library is consumed by Jest, older Next.js, Lambda CJS | **dual** is mandatory |\n\n### Release Tag at a Glance\n\n| Tag | Meaning | `npm install pkg@?` resolves |\n|---|---|---|\n| `latest` | The current stable | `npm install pkg` |\n| `next` | Upcoming major prerelease | `npm install pkg@next` |\n| `beta` | Feature-complete stabilization | `npm install pkg@beta` |\n| `rc` | Frozen, blocker-only | `npm install pkg@rc` |\n| `canary` | Per-commit\u002Fper-PR snapshot | `npm install pkg@canary` |\n| `experimental` | Unstable spike | `npm install pkg@experimental` |\n\n### One-Liner Snippets You'll Type Often\n\n```bash\n# Add the SDK as a workspace-internal dep\npnpm add @acme\u002Fsdk@workspace:* --filter @acme\u002Fexample-app\n\n# Build SDK + everything that depends on it\npnpm turbo run build --filter=...@acme\u002Fsdk\n\n# Pre-publish gate\npnpm build && pnpm exec publint --strict && pnpm exec attw --pack .\n\n# Cut a snapshot release for a PR (vercel\u002Fai pattern)\npnpm changeset version --snapshot pr-123\npnpm publish --tag pr-123 --no-git-checks\n```\n\n---\n\n## Pre-Publish Checklist\n\nRun through this once per release. Skipping any item is how broken SDKs\nship.\n\n### Build artifact\n\n- [ ] `pnpm build` produces `dist\u002F` with both `.mjs` and `.cjs` (if dual) or just `.mjs` (if ESM-only)\n- [ ] `.d.mts` and `.d.cts` exist for dual, OR `.d.ts` only for ESM-only\n- [ ] Source maps emitted (`.mjs.map`, `.d.mts.map`)\n- [ ] `dist\u002F` size is reasonable (`du -sh dist\u002F` — sanity check, no surprise bloat)\n\n### package.json\n\n- [ ] `name` is scoped (`@org\u002Fname`) — required if you'll ever go private later\n- [ ] `version` matches what you're about to publish\n- [ ] `type` matches your default format (`\"module\"` for ESM-default, omit for CJS-default)\n- [ ] `exports` has `\".\u002Fpackage.json\": \".\u002Fpackage.json\"`\n- [ ] Every `exports` branch has `types` first, `default` last\n- [ ] `files` lists `dist` (and `src` if shipping sources for IDE jump-to-def)\n- [ ] `sideEffects: false` (unless you genuinely have top-level side effects)\n- [ ] `publishConfig.access: \"public\"` for first scoped publish\n- [ ] `publishConfig.provenance: true`\n\n### Verification\n\n- [ ] `publint --strict` passes\n- [ ] `attw --pack .` passes (or only has expected `node10` warnings)\n- [ ] Smoke test: pack + install in `\u002Ftmp` + CJS + ESM + TS consumer all resolve\n\n### Release\n\n- [ ] Correct dist-tag chosen (`latest` only for stable)\n- [ ] If pre-release: `pnpm changeset pre enter \u003Ctag>` was run BEFORE `version`\n- [ ] If stable: `pnpm changeset pre exit` was run if previously in pre-mode\n- [ ] CHANGELOG.md reflects the change\n- [ ] Git tag matches version (e.g. `v1.0.0-beta.3`)\n- [ ] Provenance attestation visible on npm package page\n\n---\n\n## Common Mistakes\n\n| Mistake | What goes wrong | Fix |\n|---|---|---|\n| `types` not first inside `exports` branch | TS picks up `.js` as type source → cascade of errors at consumer | Move `types` to top of each `import` \u002F `require` branch (publint will flag) |\n| Single `.d.ts` for dual ESM+CJS | TS resolves the `.d.ts` against the wrong module mode | Emit `.d.mts` + `.d.cts` (TS 5.0+); tsdown does this automatically |\n| Missing `\".\u002Fpackage.json\": \".\u002Fpackage.json\"` in exports | publint\u002Fattw cannot introspect your package | Always include it |\n| Publishing pre-release to `latest` | Every `npm install pkg` user gets your beta | Use `npm publish --tag beta`; recover via `npm dist-tag add pkg@stable latest` |\n| Forgetting `pnpm changeset pre exit` before stable release | Stable version comes out as `1.0.0-beta.N` instead of `1.0.0` | Always `pre exit` before final |\n| Root `package.json` containing the actual build script | Defeats Turborepo parallelism + caching | Per-package scripts; root only delegates via `turbo run` |\n| Deep imports into `dist\u002Finternal\u002F...` from consumers | Consumers couple to internals; your refactors break them | Don't list internals in `exports`; use ESLint `no-restricted-imports` |\n| Leaking internal types into public API surface | Users see types they shouldn't depend on | Re-export only from `src\u002Fapi\u002F*.ts`; don't `export *` from internals |\n| Missing `sideEffects: false` with no side effects | Bundlers can't tree-shake your library | Add `\"sideEffects\": false` or list the actual side-effecting files |\n| Forgetting `id-token: write` permission for provenance | Provenance attestation fails silently in CI | Add `permissions: { id-token: write, contents: read }` to release job |\n| Mixing watch + build in same Turbo task | Cache invalidates constantly; watch never settles | Separate `build` (cacheable) and `dev` (`persistent: true, cache: false`) |\n| `exports` with both `module` and unrelated runtime conditions in wrong order | Edge runtime picks the wrong file | Runtime conditions (`browser`, `workerd`) → `module` → `import` → `require` → `default` |\n| Using `enum` in public API types | Forces consumers into TS-only land, breaks erasable syntax | Use union of string literals or `as const` objects |\n| Using `default` export from the SDK root | Breaks tree-shaking + interop story | Always named exports |\n\n---\n\n## Reference Files\n\n| File | Use when |\n|---|---|\n| `references\u002Fworkspace-and-layout.md` | Setting up `apps\u002F` + `packages\u002F` + `tools\u002F`; naming the SDK package; creating internal packages; choosing dep field (`dependencies` \u002F `peerDependencies` \u002F `devDependencies`); migrating from multi-repo |\n| `references\u002Fmodule-boundaries-and-plugins.md` | Splitting `src\u002F` into `api\u002F` vs `internal\u002F`; designing the orchestration layer vs adapters vs tools; building a plugin extension model with lifecycle hooks; enforcing boundaries via eslint-plugin-boundaries \u002F dependency-cruiser \u002F Turbo `boundaries` |\n| `references\u002Ftype-design-for-public-api.md` | Branded types; generic clients; conditional + mapped types; type-safe builders; which utility types to ship vs keep internal; tsconfig flags for libraries (`verbatimModuleSyntax`, `isolatedDeclarations`, `composite`); API evolution patterns |\n| `references\u002Fpackage-json-exports.md` | Authoring the `exports` field; dual ESM+CJS with separate `.d.mts`\u002F`.d.cts`; subpath plugin entries; isomorphic runtime conditions (`browser`, `workerd`, `react-native`, `deno`, `edge-light`); fixing common `exports` bugs |\n| `references\u002Ftsdown-bundling.md` | Choosing tsdown vs tsup vs tsc-only vs unbuild; minimum-viable `tsdown.config.ts`; subpath output mapping; side-effects + tree-shaking; watch & dev mode; bundler selection decision tree |\n| `references\u002Fturborepo-for-sdk.md` | Writing `turbo.json` for an SDK monorepo; `dependsOn: ['^build']`; caching `inputs`\u002F`outputs`; `--filter` patterns for SDK dev; the `boundaries` field; CI with remote cache + affected-only builds; dev mode with `persistent: true` |\n| `references\u002Fverification-and-publishing.md` | publint + attw setup; tarball smoke tests; semver + pre-release identifiers; npm dist-tags; the full beta → rc → stable → next-cycle state machine; changesets pre-release mode; the canonical `beta → rc` transition command sequence; GitHub Actions release workflow with snapshot PRs; npm provenance; yank vs deprecate; release-strategy decision tree |\n\n---\n\n## Source Skills\n\nThis skill was composed from four source skills inside `oh-my-openclaw`:\n\n- **`agent-cli-architecture`** (architect-claw) — workspace structure, module\n  boundaries, runtime layering, plugin extension patterns. Generalized from\n  \"agent CLI\" framing to general \"SDK + supporting CLI\".\n- **`typescript-pro`** (frontend-claw) — branded types, generics, conditional\n  types, type guards, utility types, tsconfig deep dive. Reframed toward\n  library\u002FSDK-author concerns.\n- **`turborepo`** (frontend-claw) — task pipelines, caching, `--filter`,\n  `boundaries`. Heavily trimmed to SDK-monorepo-relevant subset.\n- **`monorepo-navigator`** (architect-claw) — pnpm workspaces, changesets,\n  publishing, migration.\n\nPlus original research on `package.json exports`, dual ESM\u002FCJS in 2026,\nthe tsdown landscape, publint + attw, and the alpha→beta→rc→stable\nlifecycle, with verbatim examples from the GitHub `package.json` of\ntRPC, vercel\u002Fai, Inngest, Sanity client, Hono, Zustand, and TanStack\nquery-core.\n",{"name":5,"license":15,"metadata":24,"description":43},{"author":25,"sources":26,"version":39,"composed_from":40},"oh-my-openclaw",[27,28,29,30,31,32,33,34,35,36,37,38],"code-architecture-refactoring","architecture-patterns","turborepo","fastify","Jeffallan\u002Fclaude-skills (typescript-pro)","turborepo (official docs)","monorepo-navigator","publint.dev (rule catalog)","arethetypeswrong.github.io (problem catalog)","tsdown.dev (official docs)","changesets\u002Fchangesets (prerelease + dist-tags docs)","GitHub package.json originals — tRPC, vercel\u002Fai, Inngest, Sanity client, Hono, Zustand, TanStack query-core","1.0",[41,42,29,33],"agent-cli-architecture","typescript-pro","Design, build, verify, and publish production-grade TypeScript SDKs as npm packages inside a pnpm monorepo. Covers workspace layout, public API and module boundaries, plugin extension points, branded types and library-tuned tsconfig, tsdown bundling (vs tsup\u002Ftsc-only\u002Funbuild), package.json exports with dual ESM+CJS and isomorphic conditions (browser\u002Fworkers\u002FRN\u002Fdeno), Turborepo pipelines, publint and @arethetypeswrong\u002Fcli verification, changesets pre-release mode, npm dist-tags (latest\u002Fnext\u002Fbeta\u002Frc\u002Fcanary), and the alpha→beta→rc→stable release lifecycle. Triggers on: build a TS SDK, extract core library, package.json exports, dual ESM CJS, tsdown config, tsup vs tsdown, publint, attw, changesets prerelease, npm dist-tag, beta to rc, canary release, pnpm workspace SDK, isomorphic SDK, tsconfig library, npm provenance, shipping a TypeScript library.\n","main","db7ec54874a66d3d14414a1624060f2c3304bfea","mindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection","https:\u002F\u002Fgithub.com\u002Flivelybug","2026-06-30 11:01:33",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add livelybug\u002Fharness-repo-skill-collection --skill ts-sdk-author",{"tool":56,"command":57},"bunx","bunx skills add livelybug\u002Fharness-repo-skill-collection --skill ts-sdk-author",{"tool":59,"command":60},"pnpm","pnpm dlx skills add livelybug\u002Fharness-repo-skill-collection --skill ts-sdk-author","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002FSKILL.md",true,[64,70,74,78,82,86,90],{"path":65,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":69},"references\u002Fmodule-boundaries-and-plugins.md","REFERENCE","参考文档",38187,"https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002Freferences\u002Fmodule-boundaries-and-plugins.md",{"path":71,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":72,"sourceHtmlUrl":73},"references\u002Fpackage-json-exports.md",29245,"https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002Freferences\u002Fpackage-json-exports.md",{"path":75,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":76,"sourceHtmlUrl":77},"references\u002Ftsdown-bundling.md",23323,"https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002Freferences\u002Ftsdown-bundling.md",{"path":79,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":80,"sourceHtmlUrl":81},"references\u002Fturborepo-for-sdk.md",18321,"https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002Freferences\u002Fturborepo-for-sdk.md",{"path":83,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":84,"sourceHtmlUrl":85},"references\u002Ftype-design-for-public-api.md",27628,"https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002Freferences\u002Ftype-design-for-public-api.md",{"path":87,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":88,"sourceHtmlUrl":89},"references\u002Fverification-and-publishing.md",47882,"https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002Freferences\u002Fverification-and-publishing.md",{"path":91,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":92,"sourceHtmlUrl":93},"references\u002Fworkspace-and-layout.md",23569,"https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Fts-sdk-author\u002Freferences\u002Fworkspace-and-layout.md",[95,102,110,117,124,131],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":19},"01M77YR91TM1A88E7HQCR1MP93","first-principles-thinking","Systematic first principles thinking for any problem domain. Use when the user says \"analyze from first principles\", \"第一性原理\", \"从根本分析\", \"从零开始思考\", \"think from scratch\", \"question this design\", \"is this the right approach\", \"challenge assumptions\", \"挑战假设\", \"为什么要这样做\", \"有没有更好的方案\", \"why are we doing it this way\", or needs to evaluate decisions, designs, or strategies without relying on analogies, conventions, or \"best practices\". Also triggers on \"这个设计合理吗\", \"从本质上看\", \"回到基本面\", \"what's really true here\", \"what are we assuming\", or any request to decompose a problem to its fundamentals.","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Fmindfold-ai\u002FTrellis\u002F.agents\u002Fskills\u002Ffirst-principles-thinking\u002FSKILL.md",[],[],{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":19},"01M77XYNDRVTWV4VDRS80NVQQN","returns-reverse-logistics","Codified expertise for returns authorization, receipt and inspection, disposition decisions, refund processing, fraud detection, and warranty claims management. Informed by returns operations managers with 15+ years experience. Includes grading frameworks, disposition economics, fraud pattern recognition, and vendor recovery processes. Use when handling product returns, reverse logistics, refund decisions, return fraud detection, or warranty claims.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Faffaan-m\u002FECC\u002Fskills\u002Freturns-reverse-logistics\u002FSKILL.md",[],[],{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":19},"01M77XWJ913D93VJBMJZMWZBZE","quality-nonconformance","Codified expertise for quality control, non-conformance investigation, root cause analysis, corrective action, and supplier quality management in regulated manufacturing. Informed by quality engineers with 15+ years experience across FDA, IATF 16949, and AS9100 environments. Includes NCR lifecycle management, CAPA systems, SPC interpretation, and audit methodology. Use when investigating non-conformances, performing root cause analysis, managing CAPAs, interpreting SPC data, or handling supplier quality issues.","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Faffaan-m\u002FECC\u002Fskills\u002Fquality-nonconformance\u002FSKILL.md",[],[],{"skillNo":118,"name":119,"nameZh":6,"description":120,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":121,"categories":122,"keywords":123,"publishedAt":19},"01M77XVNY9GYR1E2SDM5S3B8R4","production-scheduling","Codified expertise for production scheduling, job sequencing, line balancing, changeover optimization, and bottleneck resolution in discrete and batch manufacturing. Informed by production schedulers with 15+ years experience. Includes TOC\u002Fdrum-buffer-rope, SMED, OEE analysis, disruption response frameworks, and ERP\u002FMES interaction patterns. Use when scheduling production, resolving bottlenecks, optimizing changeovers, responding to disruptions, or balancing manufacturing lines.","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Faffaan-m\u002FECC\u002Fskills\u002Fproduction-scheduling\u002FSKILL.md",[],[],{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":19},"01M77XQDT4K9PH1AA4WEG744QM","logistics-exception-management","Codified expertise for handling freight exceptions, shipment delays, damages, losses, and carrier disputes. Informed by logistics professionals with 15+ years operational experience. Includes escalation protocols, carrier-specific behaviors, claims procedures, and judgment frameworks. Use when handling shipping exceptions, freight claims, delivery issues, or carrier disputes.","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Faffaan-m\u002FECC\u002Fskills\u002Flogistics-exception-management\u002FSKILL.md",[],[],{"skillNo":132,"name":133,"nameZh":6,"description":134,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":106,"licenseFileUrl":6,"sourceHtmlUrl":135,"categories":136,"keywords":137,"publishedAt":19},"01M77XM8P4DM4KXVE9Z2JHJWF6","inventory-demand-planning","Codified expertise for demand forecasting, safety stock optimization, replenishment planning, and promotional lift estimation at multi-location retailers. Informed by demand planners with 15+ years experience managing hundreds of SKUs. Includes forecasting method selection, ABC\u002FXYZ analysis, seasonal transition management, and vendor negotiation frameworks. Use when forecasting demand, setting safety stock, planning replenishment, managing promotions, or optimizing inventory levels.","https:\u002F\u002Fgithub.com\u002Flivelybug\u002Fharness-repo-skill-collection\u002Fblob\u002Fmain\u002Faffaan-m\u002FECC\u002Fskills\u002Finventory-demand-planning\u002FSKILL.md",[],[]]