AgentSkillsCN

Tp Init

TP 初始化

SKILL.md

/tp:init - Template Project Initializer

This skill initializes a new project from the TanStack Start + Cloudflare D1 + Better Auth template. It replaces all template placeholders, creates a D1 database, generates auth secrets, and prepares the project for development.

Invocation

User types /tp:init or asks to initialize/set up the project from this template.

Workflow

Step 1: Ask for Project Name

Use AskUserQuestion to ask the user for their project name. Recommend kebab-case (e.g., my-awesome-app).

Derive the following variables from the input:

  • PROJECT_NAME = user input as-is (kebab-case)
  • WORKER_NAME = same as PROJECT_NAME
  • DB_NAME = {PROJECT_NAME}-db
  • DISPLAY_NAME = Title Case conversion (e.g., my-awesome-appMy Awesome App)

Step 2: Verify Cloudflare Login

Run:

bash
npx wrangler whoami

If the command fails or shows "not authenticated":

  • Tell the user to run npx wrangler login first
  • Stop the workflow here — do not continue

Step 3: Create D1 Database

Run:

bash
npx wrangler d1 create {DB_NAME}

Parse the output to extract the database_id value. The output will contain a line like:

code
database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

If the command fails (e.g., name conflict, network error):

  • Show the error to the user
  • Stop the workflow here

Step 4: Generate Better Auth Secret

Try openssl first:

bash
openssl rand -hex 32

If openssl is not available, fall back to Node.js:

bash
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Store the result as AUTH_SECRET.

Step 5: Update Project Files

Update the following files using Edit/Write tools:

5.1 package.json

  • Change "name" from "tanstack-start-d1-better-auth-template" to "{PROJECT_NAME}"

5.2 wrangler.jsonc

  • Change "name" from "tanstack-start-app" to "{WORKER_NAME}"
  • Change "database_name" from "tanstack-start-db" to "{DB_NAME}"
  • Change "database_id" to the value parsed from Step 3

5.3 .cta.json

  • Change "projectName" from "tanstack-start-d1-better-auth-template" to "{PROJECT_NAME}"

5.4 public/manifest.json

  • Change "short_name" from "TanStack App" to "{DISPLAY_NAME}"
  • Change "name" from "Create TanStack App Sample" to "{DISPLAY_NAME}"

5.5 src/routes/__root.tsx

  • Change the title in meta from "TanStack Start Starter" to "{DISPLAY_NAME}"
  • Change the logo text bag (inside the <Link> component) to "{DISPLAY_NAME}"

5.6 .env.local (create new file)

Create .env.local with:

code
BETTER_AUTH_URL=http://localhost:3000
BETTER_AUTH_SECRET={AUTH_SECRET}

Step 6: Install Dependencies

Run:

bash
npm install

This regenerates package-lock.json with the updated project name.

Step 7: (Optional) Reset Git History

Ask the user with AskUserQuestion whether they want to reset git history.

Options:

  • Yes, reset git history — Start fresh with a clean initial commit
  • No, keep current history — Keep the template's git history

If the user chooses yes, run:

bash
rm -rf .git && git init && git add -A && git commit -m "Initial commit from template"

Step 8: Show Completion Summary

Display a summary like this:

code
Project initialized successfully!

  Project Name:  {PROJECT_NAME}
  Worker Name:   {WORKER_NAME}
  D1 Database:   {DB_NAME} ({DB_ID})
  Auth Secret:   Generated in .env.local

Next steps:
  1. npm run db:push          # Push schema to local D1
  2. npm run dev              # Start dev server (port 3000)
  3. npm run deploy           # Deploy to Cloudflare Workers

Error Handling

  • Cloudflare not logged in → Show npx wrangler login instruction and stop
  • D1 creation fails → Show error message and stop
  • openssl not found → Silently fall back to Node.js crypto
  • package-lock.json → Do NOT manually edit; npm install handles it automatically