author-typescript-code
ALWAYS invoke this skill when writing or fixing implementation code for TypeScript. NEVER write or fix TypeScript implementation without this skill.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1
- Forks
- 1
01 前言 Front Matter
- name
- author-typescript-code
- description
- ALWAYS invoke this skill when writing or fixing implementation code for TypeScript. NEVER write or fix TypeScript implementation without this skill.
- allowed-tools
- Read, Write, Glob, Grep, Edit, {{! tool('use_skill') !}}, Bash(npx tsc:*), Bash(npx eslint:*), Bash(npx vitest:*)
02 资源文件 6
- 参考文档references/outcome-engineering-patterns.md2.9 KB
- 参考文档references/test-patterns.md3.9 KB
- 参考文档references/verification-checklist.md3.6 KB
- 参考文档references/vocabulary-registry-pattern.md4.5 KB
- 参考文档workflows/implementation.md8.4 KB
- 参考文档workflows/remediation.md4.4 KB
03 SKILL.md 正文
{!% require_skill 'typescript:typescript-code-standards' %!}
{!% require_skill 'typescript:typescript-test-standards' %!}
<objective> TypeScript implementation code that satisfies its node's established evidence and passes every selected deterministic check. </objective>
<bundled_files>
- References:
${CLAUDE_SKILL_DIR}/references/ - Workflows:
${CLAUDE_SKILL_DIR}/workflows/
Never search the product directory for bundled skill files.
</bundled_files>
<reference_loading>
Standards are pre-loaded above. Check for spx/local/typescript.md and spx/local/typescript-tests.md at the repository root and apply each file that exists as repo-local routing to the product's governing specs and decisions. A local overlay supplements skill behavior; it does not declare product truth.
</reference_loading>
<essential_principles> NO MOCKING. DEPENDENCY INJECTION. BEHAVIOR ONLY. EVIDENCE FIRST.
- Use dependency injection, NEVER mocking frameworks
- Test behavior (what the code does), not implementation (how it does it)
- Run all verification tools before declaring completion
- Type safety first:
strict: true, noanywithout justification
</essential_principles>
<mandatory_code_patterns> These patterns are enforced by the reviewer. Violations will be REJECTED.
Domain-significant constants
Move domain-significant string and number literals whose meaning can drift to semantically named module-level constants. Keep typed literals inline when extraction adds no domain meaning, following ${CLAUDE_SKILL_DIR}/references/vocabulary-registry-pattern.md.
// ❌ REJECTED: Magic values inline
function validateScore(score: number): boolean {
return score >= 0 && score <= 100;
}
// ✅ REQUIRED: Named constants
const MIN_SCORE = 0;
const MAX_SCORE = 100;
function validateScore(score: number): boolean {
return score >= MIN_SCORE && score <= MAX_SCORE;
}
Share constants between code and tests — tests import from the module under test:
// src/scoring.ts
export const MIN_SCORE = 0;
export const MAX_SCORE = 100;
// spx/.../tests/scoring.mapping.l1.test.ts
import { MIN_SCORE, validateScore } from "@/scoring";
it("rejects below minimum", () => {
expect(validateScore(MIN_SCORE - 1)).toBe(false);
});
Dependency Injection
External dependencies must be injected, not imported directly:
// ❌ REJECTED: Direct import
import { execa } from "execa";
async function syncFiles(src: string, dest: string): Promise<boolean> {
const result = await execa("rsync", [src, dest]);
return result.exitCode === 0;
}
// ✅ REQUIRED: Dependency injection
interface SyncDeps {
execa: typeof execa;
}
async function syncFiles(
src: string,
dest: string,
deps: SyncDeps,
): Promise<boolean> {
const result = await deps.execa("rsync", [src, dest]);
return result.exitCode === 0;
}
</mandatory_code_patterns>
<hierarchy_of_authority> Where to look for guidance, in order of precedence:
| Priority | Source | What It Provides |
|---|---|---|
| 1 | Loaded PDRs, ADRs, and specs | Product and architecture truth |
| 2 | {{! file('root_guide') !}} and overlays |
Product-specific workflow and local constraints |
| 3 | Loaded TypeScript skills | Language implementation and testing standards |
| 4 | docs/, README.md |
Supplementary product explanation |
| 5 | Existing code | Lower-layer implementation evidence, never governing truth |
CRITICAL: Existing code is NOT authoritative.
- Documentation describes intent — what SHOULD be done
- Existing code shows implementation — what WAS done (may be legacy, wrong, or outdated)
- When docs and code conflict, docs win
- When no docs exist, ASK before copying existing patterns
Never copy patterns from existing code without verifying they match documented intent.
</hierarchy_of_authority>
<codebase_discovery> BEFORE writing any code, discover what already exists.
Phase 0: Discovery (MANDATORY)
Run these searches before implementation:
# 1. Read product documentation
Read: README.md, docs/, {{! file('root_guide') !}}, CONTRIBUTING.md
# 2. Load the authoritative methodology
Read: relevant skills and spec docs before inferring any convention
# 3. Check available dependencies (don't add what exists)
Read: package.json → dependencies, devDependencies
# 4. Locate concrete artifacts to reuse
Glob/Grep: actual modules, harnesses, fixtures, registries, and entrypoints
# 5. Confirm local file placement
Read: existing files in the same target directory
What to Discover
| Question | How to Answer It |
|---|---|
| What conventions govern this work? | Read the relevant skill, spec, ADR/PDR, {{! file('root_guide') !}}, and product docs first |
| What libraries are available? | package.json → dependencies |
| What concrete modules already exist to reuse? | Glob/Grep for actual modules, registries, harnesses, fixtures, and helpers |
| What error classes already exist? | Locate existing error modules; do not infer policy from random call sites |
| What logging facility already exists? | Locate the logger module or logging package, then follow documented rules |
| How are configs structured? | Find config modules and config docs; do not infer config policy from ad hoc use |
| If this is a script, which arg parser is canonical? | Read package.json, docs, and existing checked-in scripts/ entrypoints |
Discovery Anti-Patterns
// ❌ WRONG: Adding lodash when ramda is already used
import _ from "lodash"; // package.json has ramda, not lodash
// ❌ WRONG: Creating new logger when one exists
const logger = console; // Product has @lib/logger
// ❌ WRONG: Inventing naming convention
function fetch_user_by_id() {} // Product uses camelCase
// ❌ WRONG: New error class when domain errors exist
class MyError extends Error {} // Product has @/errors
// ❌ WRONG: Inferring architecture from grep results
// "I saw three files use pattern X, so pattern X is the standard"
Authority rule: Skills, specs, ADRs/PDRs, {{! file('root_guide') !}}, and product docs answer "how should this be done?" Code search answers only "where is the existing artifact I should reuse?"
Script Entry Points
When editing a checked-in entrypoint under scripts/, treat it as boundary code:
- use the repository's canonical argument parsing library
- do not hand-roll
process.argvparsing - keep the script thin and dispatch to one orchestrator module or a small dispatcher
- allow relative imports, boundary env parsing, and console output when that avoids circular dependency problems
Before changing script behavior, answer these questions:
- Where is the orchestrator module this script should call?
- If the orchestrator touches a boundary, where is the harness?
- If there is no harness, where is the fixture data?
- Where is the spec for the orchestrator or harness?
- Where are the tests for the orchestrator or harness?
Discovery Checklist
Before writing code, confirm:
- [ ] Loaded the relevant skill and spec documents before inferring conventions
- [ ] Read
package.json— know what libraries are available - [ ] Located reusable modules, harnesses, fixtures, registries, or helpers
- [ ] Identified the canonical logger/config/error modules from docs or known entrypoints
- [ ] If editing
scripts/, identified the canonical argument parsing library - [ ] If editing
scripts/, found the orchestrator's spec and tests (or the harness/fixture gap)
Never treat grep results as authority. If existing code conflicts with the skill, spec, or docs, the documented rule wins.
</codebase_discovery>
<testing_methodology>
Use skill product-tree:verify before adding or revising evidence. When it selects test, use skill typescript:typescript-test-standards and use skill typescript:author-typescript-test for TypeScript expression.
Use /typescript-test-standards as the canonical source for:
- filename conventions
- allowed doubles and dependency-injection rules
- property-based testing requirements
- harness ownership and fixture placement
- source-owned test values and inline diagnostics
Use skill typescript:author-typescript-test for:
- router-driven level selection
- concrete Vitest and Playwright implementation patterns
- RED-phase expectations and test-writing workflows
- TypeScript-specific examples for the selected test level
When implementation changes affect test-owned interfaces, harnesses, or fixture boundaries, keep the production code aligned with both skills rather than re-declaring testing policy here. </testing_methodology>
<audit_requirement_handoff>
For each /verify routing row whose verification type is audit, re-read the routed spec or decision artifact and confirm the exact subject still carries ([audit:{rule-slug}]) or the pathless ([audit]) that the foundation admits for a toolchain without slug support. The completion report includes one Audit requirements row per audit routing row with the full spx/... source path, exact subject text, and status preserved. The row count must equal the routing result's audit-row count; when that count is zero, report Audit requirements: none selected.
</audit_requirement_handoff>
<context_loading> BEFORE ANY IMPLEMENTATION: Load complete specification context.
If working on a product-tree work item (enabler/outcome):
- Use skill
product-tree:contextualizeFIRST with the node path - If context loading fails: ABORT - do not proceed until all required documents exist
- If context loading succeeds: Proceed with implementation using loaded context
The product-tree:contextualize skill provides:
- Complete ancestor hierarchy (product → all ancestor nodes → target)
- All ADRs/PDRs at every level along the path
- Lower-index siblings (they constrain the target via dependency encoding)
- Target node spec with typed assertions
Example invocation: Invoke /contextualize with spx/<node-path>.
If product-tree:contextualize returns an error: The error message will specify which document is missing and how to create it. Create the missing document before proceeding with implementation.
If NOT working on product-tree work item: Proceed directly to implementation mode with provided spec. </context_loading>
<two_modes> This skill operates in one of two modes depending on the input:
| Input | Mode | Workflow |
|---|---|---|
| Spec (ADR/PDR, node spec) | Implementation | ${CLAUDE_SKILL_DIR}/workflows/implementation.md |
| Rejection feedback from reviewer | Remediation | ${CLAUDE_SKILL_DIR}/workflows/remediation.md |
Determine the mode from the input, then follow the appropriate workflow. </two_modes>
<core_principles>
-
Spec Is Law: The specification is the contract. Implement exactly what it says.
-
Evidence-Driven Development: Establish evidence through
/verifybefore implementation. Use RED/GREEN when test is selected, run the declared threshold when evaluate is selected, and preserve pathless audit requirements for their isolated verifier. -
Type Safety First: Use strict TypeScript with
strict: true. Noanywithout justification. -
Self-Verification: Before declaring completion, run the repository-selected typecheck, lint, validation, and every deterministic command selected by
/verify. Use rawtsc,eslint, andvitestcommands only when the repository defines no wrapper. -
Humility: The code must pass review. Write code that will survive adversarial review.
-
Clean Architecture: Dependency injection, single responsibility, no circular imports, no deep relative imports.
</core_principles>
<reference_index>
| File | Purpose |
|---|---|
${CLAUDE_SKILL_DIR}/references/outcome-engineering-patterns.md |
Subprocess, resource cleanup, config |
${CLAUDE_SKILL_DIR}/references/test-patterns.md |
Debuggability-first test organization |
${CLAUDE_SKILL_DIR}/references/verification-checklist.md |
Pre-submission verification |
${CLAUDE_SKILL_DIR}/references/vocabulary-registry-pattern.md |
Closed vocabulary source-of-truth |
</reference_index>
<workflows_index>
| Workflow | Purpose |
|---|---|
${CLAUDE_SKILL_DIR}/workflows/implementation.md |
TDD phases, code standards |
${CLAUDE_SKILL_DIR}/workflows/remediation.md |
Fix issues from review feedback |
</workflows_index>
<what_not_to_do> Never Self-Approve: Always submit for review.
Never Skip Selected Evidence: Run every selected test and eval command, and preserve every pathless audit requirement. Never fabricate a test for an eval- or audit-backed assertion.
Never Ignore Type Errors:
// WRONG
const result = someFunction(); // @ts-ignore
// RIGHT
const result: ExpectedType = someFunction();
Never Hardcode Secrets:
// WRONG
const API_KEY = "sk-1234567890abcdef";
// RIGHT
const API_KEY = process.env.API_KEY;
if (!API_KEY) throw new Error("API_KEY required");
Never Use Deep Relative Imports:
Before writing any import, ask: "Is this a module-internal file (same module, moves together), stable production infrastructure (lib/, shared/), or test-only infrastructure used from tests (testing/harnesses/)?"
// WRONG: Deep relatives to stable locations — will REJECT in review
import { treeBuilder } from "../../../../../../testing/harnesses/tree-builder";
import { Logger } from "../../../../lib/logging";
import { Config } from "../../../shared/config";
// RIGHT: Configure path aliases in tsconfig.json
import { Logger } from "@lib/logging";
import { Config } from "@shared/config";
// In tests only:
import { treeBuilder } from "@testing/harnesses/tree-builder";
Depth Rules:
./sibling— ✅ OK (same directory, module-internal)../parent— ⚠️ Review (is it truly module-internal?)../../or deeper — ❌ REJECT (use path alias)
Configure tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
"@testing/*": ["testing/*"],
"@lib/*": ["lib/*"]
}
}
}
</what_not_to_do>
<tool_invocation>
<command_resolution>
Resolve commands from repository docs, package scripts, Makefile, Justfile, or local agent instructions. Use raw tool commands only when the repository has no validation wrapper.
When sources conflict, resolve in this priority: local agent instructions, repository docs, Justfile, Makefile, package scripts, raw tool fallback.
allowed-tools preapproves only the listed raw-tool fallbacks. A repository-canonical wrapper outside those patterns uses the runtime's normal per-call approval path; NEVER select a fallback merely to avoid that approval.
</command_resolution>
# Resolve placeholders using <command_resolution> before running these commands.
#
# TypeScript validation
<product-typecheck-command>
# Auto-fix style issues when the repository exposes a canonical fix command
<product-lint-fix-command>
# Lint validation
<product-lint-command>
# Tests
<product-test-command>
# Bare-repo fallback examples only when no repository wrapper exists:
# npx tsc --noEmit
# npx eslint src/ test/ --fix
# npx eslint src/ test/
# npx vitest run
</tool_invocation>
<failure_modes>
Selected a raw fallback to avoid wrapper approval
- What happened: Claude selected a preapproved raw
npxcommand even though the repository declared a canonical wrapper outsideallowed-tools. - Why it failed:
allowed-toolsdefines commands that run without per-call approval; it does not override repository command authority. - How to avoid: Resolve repository commands first and use the runtime's normal per-call approval path for the canonical wrapper. Use raw fallbacks only when the repository declares no wrapper.
</failure_modes>
<success_criteria> The implementation is ready for review when:
- [ ] The product's resolved TypeScript type-check command passes
- [ ] The product's resolved TypeScript lint/format check command passes
- [ ] Every TypeScript test command selected by
/verifypasses and every selected eval command meets its declared threshold - [ ] The
Audit requirementsreport has onepreservedrow per audit routing row from/verify, or reportsnone selectedwhen the routing result has none - [ ] The implementation follows the rules of skill
typescript:typescript-code-standardsand anyspx/local/typescript.mdoverlay loaded for the repository - [ ] Any coverage, documentation, TODO, logging, or security threshold enforced by the product's resolved commands or loaded standards passes through those commands
- [ ] FIX mode addresses every supplied reviewer finding with a code change or a stated evidence-based rejection
</success_criteria>
04 同仓库更多 Skills
plugin
暂无简介
sanitize-powerpoint
ALWAYS invoke this skill when sanitizing, cleaning up, auditing, or aligning a PowerPoint (.pptx) deck — slide-master and layout structure, layout type attributes, stray fonts, non-theme colors, or layout naming. NEVER hand-edit pptx XML without this skill.
draw-excalidraw
ALWAYS invoke this skill when creating Excalidraw diagrams, visualizing workflows, architectures, or concepts. NEVER generate Excalidraw JSON without this skill.
typescript-test-standards
TypeScript test standards enforced across all skills. Loaded by other skills, not invoked directly.
typescript-code-standards
TypeScript code standards enforced across all skills. Loaded by other skills, not invoked directly.
typescript-architecture-standards
TypeScript ADR conventions enforced across architect and auditor skills. Loaded by other skills, not invoked directly.