add-a-package
Use when adding a new package under packages/ (or an app under apps/). Covers the placement check, the dependency direction, public API, wiring, tests, and docs.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- add-a-package
- description
- Use when adding a new package under packages/ (or an app under apps/). Covers the placement check, the dependency direction, public API, wiring, tests, and docs.
03 SKILL.md 正文
add-a-package
Prerequisites
- An agreed spec (or accepted RFC) for the capability — see prd-to-spec.
- Read .ai/memories/architecture.md.
- The toolchain exists (pnpm workspace, wireit scripts, oxlint and stylelint, Vitest, tsx for
tools/). Copy the shape of an existing package underpackages/:package.jsonwith thebuild(tsdown) andtypecheck(tsc -p tsconfig.json) wireit scripts (andtestonce it has its first real test),tsconfig.json(withdeclarationandisolatedDeclarationsfor a library: every export needs an explicit type), andtsdown.config.ts(seetsdown.base.ts; add each entry point).
Workflow
- Decide it is a package. It must have one reason to exist, a public API
other code can use without its internals, and a place in the dependency
direction. If it is a helper of one package, keep it inside that package; no
utilsorcommonpackage; name the concern. A package that holds a credential is the shell's concern: new credential-handling code goes in the shell, never in a leaf or an app. - Place it in the graph. Today:
contracts(data only) is a leaf;snapshotandplay-clientdepend on it;signinghas no kit dependency at run time;shelldepends onsigning,snapshot, andplay-client; thewrapperapp depends onshell. Never put logic incontracts; data vendored from the backend goes there, and only tests import its test-only entry. State which packages the new one may import and which may import it; the graph stays acyclic, a package never imports an app. Record the placement in the packages' spec and in the architecture memory. - Layout:
packages/<name>/withsrc/(internals),src/index.ts(the only public entry point, holding onlyexport ... fromre-exports; no otherindex.tsanywhere in the package),test/,package.json, and atsconfigthat extends the shared strict base.package.jsonhas anexportsmap to the entry point only,"type": "module", an explicitfileslist that selects only itsdistoutput (["dist"]; neversrc,.wireit,*.tsbuildinfo, or a config file; npm addspackage.jsonand the README itself), and no lifecycle scripts.tools/package-files.test.tsandpnpm check:package-filesfail without it; add the new library to thedependenciesof the rootcheck:package-filesscript. - Dependencies: a workspace dependency on another kit package is allowed only along the dependency direction. A third-party runtime dependency needs an ADR first; a development tool needs a recorded decision. Pin per the lockfile policy; never add a lifecycle script.
- Enforce the direction: add the package to the import-restriction rules of
the lint configuration so a forbidden import fails: a pair of
overridesentries in.oxlintrc.json(one for the package, one for its test files) carrying ano-restricted-importsrule, and the package's name added to the restricted groups of the others. Add a negative case totools/fixtures/import-direction-cases.ts(the dependency-direction cases; the other rule cases are inlint-rule-cases.tsandstyle-rule-cases.ts) proving the rule fires, and add the package to the rootbuildandtypecheckwireit dependencies (andtestwhen it gets its first test), and topackages/*/tsdown.config.tscoverage of the roottsconfig.json. Wire the graph: a package resolves another through itsexports, which point atdist/, so itsbuild,typecheck, andtestwireit scripts list thebuildof every kit package it imports (and ofcontractswhen its tests import the test-only entry) independencies; otherwise they may see a missing or staledist/. Add the new package'sbuildto thedependenciesof each package or app that will import it. - API and types: strict TypeScript, no
any, named exports (ADR-001),typeoverinterfaceand arrow functions overfunction(AGENTS.md), no side effects at import. Money amounts are strings orbigint. Errors are typed. Nothing in the package logs or stores a key or token. - Build gotcha (
contracts): use named re-exports in its runtime source;export * as nsmakes rolldown emit an unmapped helper chunk thatpnpm check:build-outputrejects. - Tests: unit tests, vector replay for wire or crypto formats, and the check that the public entry point exports exactly what the spec lists.
- Release: a changeset; mark the package private until it is meant to be
published; if it is published, its
exports, provenance, and license are set per the release runbook (planned). - Docs: a spec for its contract (with its Boundary section), the
package map in
.ai/memories/architecture.mdandoverview.md, the README package list, and the package's ownREADME.md. The README is public documentation that ships to npm: write it for a consumer (what it is, when to use it, install line, entry points, guarantees), with links only into this repository (absolutehttps://github.com/IntraverseGame/se-client-kit/blob/main/...; any other host fails) and no contributor material; copy the shape of an existing one. Add the npm metadata to the library'spackage.json(description,keywords,license,repositorywithdirectory,bugs,homepage).tools/readmes.test.tsfails without the README or if it breaks the rules.
Constraints
- No new runtime dependency without an ADR; no
util/common/helperspackage. - Never import another package's internals; use its public entry point.
- Public repository: no secrets, internal hostnames, or unpublished backend internals in the new package or its fixtures.
Useful commands
pnpm check
pnpm lint
Expected output
A building, linted, tested package with a public entry point, an enforced place in the dependency direction, and updated specs and memories.
References
04 同仓库更多 Skills
<skill-name>
Use when <situation>. One or two sentences.
write-tests
Use when adding or changing behavior, signing code, contracts, or the UI. Chooses the right test level and applies the repository's test rules.
spec-drift-sync
Use before merging any non-trivial change. Reconciles code with specs, and code/specs with memories, runbooks, and telemetry docs (Spec Drift Synchronization).
shepherd-a-pull-request
Use when reviewing a pull request on GitHub, following up on a review after new pushes, or answering review comments on your own pull request. The `gh` procedure behind the pr-shepherd agent, with draft-then-confirm posting.
prd-to-spec
Use when given a rough PRD, feature request, or raw requirement. Turns it into a spec update, an RFC when the change is significant or contested, and an ADR for hard-to-reverse decisions.
ask-the-human
Use when you hit an open question, a decision that is not yours to make, a gap or ambiguity in a spec, or a draft that needs a human's confirmation. Asks through the host's structured-question tool with concrete options and a recommendation, instead of guessing or burying the question in prose.