@phi-code-admin/phi-code 0.56.3 → 0.56.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phi-code-admin/phi-code",
3
- "version": "0.56.3",
3
+ "version": "0.56.5",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "files": [
26
26
  "dist",
27
+ "skills",
27
28
  "extensions",
28
29
  "README.md",
29
30
  "LICENSE",
@@ -0,0 +1,44 @@
1
+ # API Design Skill
2
+
3
+ ## When to use
4
+ Designing REST APIs, GraphQL schemas, or any HTTP endpoints.
5
+
6
+ ## REST Conventions
7
+ - `GET /users` — List users
8
+ - `GET /users/:id` — Get user by ID
9
+ - `POST /users` — Create user
10
+ - `PUT /users/:id` — Replace user
11
+ - `PATCH /users/:id` — Update user fields
12
+ - `DELETE /users/:id` — Delete user
13
+
14
+ ## Status Codes
15
+ - `200` OK — Success
16
+ - `201` Created — Resource created
17
+ - `204` No Content — Success, no body
18
+ - `400` Bad Request — Invalid input
19
+ - `401` Unauthorized — No/invalid auth
20
+ - `403` Forbidden — Auth OK but no permission
21
+ - `404` Not Found — Resource doesn't exist
22
+ - `409` Conflict — Duplicate/conflict
23
+ - `422` Unprocessable — Validation failed
24
+ - `429` Too Many Requests — Rate limited
25
+ - `500` Internal Error — Server bug
26
+
27
+ ## Response Format
28
+ ```json
29
+ {
30
+ "data": { ... },
31
+ "meta": { "page": 1, "total": 42 },
32
+ "errors": [{ "code": "VALIDATION", "message": "Email required", "field": "email" }]
33
+ }
34
+ ```
35
+
36
+ ## Best Practices
37
+ - Version your API: `/api/v1/users`
38
+ - Use pagination: `?page=1&limit=20`
39
+ - Filter: `?status=active&role=admin`
40
+ - Sort: `?sort=-created_at` (prefix `-` for descending)
41
+ - Rate limit all endpoints
42
+ - Validate all inputs with schemas (Zod, Joi)
43
+ - Use CORS properly
44
+ - Document with OpenAPI/Swagger
@@ -0,0 +1,37 @@
1
+ # Coding Standards Skill
2
+
3
+ ## When to use
4
+ When writing, reviewing, or refactoring code in any language.
5
+
6
+ ## TypeScript/JavaScript
7
+ - Use `const` by default, `let` when reassignment needed, never `var`
8
+ - Prefer `async/await` over raw Promises
9
+ - Use TypeScript strict mode
10
+ - Naming: `camelCase` variables/functions, `PascalCase` types/classes, `UPPER_SNAKE` constants
11
+ - Prefer named exports over default exports
12
+ - Handle errors: never swallow exceptions silently
13
+ - Validate inputs at API boundaries
14
+
15
+ ## Python
16
+ - Follow PEP 8
17
+ - Type hints on all functions
18
+ - Use dataclasses or Pydantic for structured data
19
+ - `with` statements for resource management
20
+ - List comprehensions over map/filter where readable
21
+
22
+ ## General Principles
23
+ - DRY but don't over-abstract (Rule of Three)
24
+ - Functions: single responsibility, <30 lines ideally
25
+ - Comments: explain WHY, not WHAT
26
+ - No magic numbers: use named constants
27
+ - Fail fast: validate early, return early
28
+ - Prefer composition over inheritance
29
+
30
+ ## Code Review Checklist
31
+ - [ ] Types are correct and complete
32
+ - [ ] Error handling is proper
33
+ - [ ] No security vulnerabilities (injection, XSS, etc.)
34
+ - [ ] Tests cover the changes
35
+ - [ ] No unnecessary complexity
36
+ - [ ] Names are clear and descriptive
37
+ - [ ] No hardcoded secrets or credentials
@@ -0,0 +1,52 @@
1
+ # Database Skill
2
+
3
+ ## When to use
4
+ SQL queries, schema design, migrations, query optimization.
5
+
6
+ ## Schema Design
7
+ - Use UUIDs for public-facing IDs, integers for internal
8
+ - Always add `created_at` and `updated_at` timestamps
9
+ - Use `NOT NULL` by default, allow NULL only when needed
10
+ - Index foreign keys and frequently queried columns
11
+ - Use enums or lookup tables for fixed sets of values
12
+
13
+ ## PostgreSQL
14
+ ```sql
15
+ -- Create table with best practices
16
+ CREATE TABLE users (
17
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
18
+ email VARCHAR(255) UNIQUE NOT NULL,
19
+ name VARCHAR(255) NOT NULL,
20
+ role VARCHAR(50) NOT NULL DEFAULT 'user',
21
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
22
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
23
+ );
24
+
25
+ -- Index for common queries
26
+ CREATE INDEX idx_users_email ON users(email);
27
+ CREATE INDEX idx_users_role ON users(role);
28
+
29
+ -- Trigger for updated_at
30
+ CREATE OR REPLACE FUNCTION update_updated_at()
31
+ RETURNS TRIGGER AS $$
32
+ BEGIN NEW.updated_at = NOW(); RETURN NEW; END;
33
+ $$ LANGUAGE plpgsql;
34
+
35
+ CREATE TRIGGER users_updated_at
36
+ BEFORE UPDATE ON users
37
+ FOR EACH ROW EXECUTE FUNCTION update_updated_at();
38
+ ```
39
+
40
+ ## Query Optimization
41
+ - Use `EXPLAIN ANALYZE` to understand query plans
42
+ - Index columns used in WHERE, JOIN, ORDER BY
43
+ - Avoid `SELECT *` — select only needed columns
44
+ - Use pagination (LIMIT/OFFSET or cursor-based)
45
+ - Use `pg_trgm` for fuzzy text search
46
+ - Use connection pooling (PgBouncer)
47
+
48
+ ## Migrations
49
+ - Always write both up and down migrations
50
+ - Never modify a deployed migration — create a new one
51
+ - Test migrations on a copy of production data
52
+ - Backup before running migrations in production
@@ -0,0 +1,36 @@
1
+ # DevOps Skill
2
+
3
+ ## When to use
4
+ Docker, CI/CD, deployment, monitoring, infrastructure tasks.
5
+
6
+ ## Docker
7
+ - Always use multi-stage builds for production
8
+ - Pin image versions (never use `latest` in production)
9
+ - Use `.dockerignore` to reduce context
10
+ - Health checks: `HEALTHCHECK CMD curl -f http://localhost:PORT/health`
11
+ - Non-root user: `USER node` or `USER 1000`
12
+ - Use named volumes for persistence
13
+ - Compose: separate dev and prod configs
14
+
15
+ ## CI/CD
16
+ - GitHub Actions: `.github/workflows/`
17
+ - Pipeline: lint → test → build → deploy
18
+ - Cache dependencies between runs
19
+ - Use environment secrets, never hardcode
20
+ - Branch protection rules on main
21
+
22
+ ## Monitoring
23
+ - Health endpoint: `GET /health` → `{ status: "ok", uptime: ... }`
24
+ - Structured logging (JSON)
25
+ - Error tracking (Sentry, etc.)
26
+ - Resource monitoring (CPU, memory, disk)
27
+
28
+ ## Troubleshooting
29
+ ```bash
30
+ docker compose logs -f <service> # Live logs
31
+ docker stats # Resource usage
32
+ docker system df # Disk usage
33
+ docker exec -it <container> sh # Shell access
34
+ ss -tlnp # Open ports
35
+ journalctl -u <service> -f # Systemd logs
36
+ ```
@@ -0,0 +1,55 @@
1
+ # Docker Operations Skill
2
+
3
+ ## When to use
4
+ Writing Dockerfiles, docker-compose configs, debugging containers.
5
+
6
+ ## Dockerfile Best Practices
7
+ ```dockerfile
8
+ # Multi-stage build
9
+ FROM node:22-alpine AS builder
10
+ WORKDIR /app
11
+ COPY package*.json ./
12
+ RUN npm ci --only=production
13
+ COPY . .
14
+ RUN npm run build
15
+
16
+ FROM node:22-alpine
17
+ WORKDIR /app
18
+ COPY --from=builder /app/dist ./dist
19
+ COPY --from=builder /app/node_modules ./node_modules
20
+ USER node
21
+ EXPOSE 3000
22
+ HEALTHCHECK CMD wget -qO- http://localhost:3000/health || exit 1
23
+ CMD ["node", "dist/index.js"]
24
+ ```
25
+
26
+ ## Docker Compose
27
+ ```yaml
28
+ services:
29
+ app:
30
+ build: .
31
+ ports: ["3000:3000"]
32
+ environment:
33
+ - NODE_ENV=production
34
+ volumes:
35
+ - app-data:/app/data
36
+ restart: unless-stopped
37
+ healthcheck:
38
+ test: ["CMD", "wget", "-qO-", "http://localhost:3000/health"]
39
+ interval: 30s
40
+ timeout: 10s
41
+ retries: 3
42
+
43
+ volumes:
44
+ app-data:
45
+ ```
46
+
47
+ ## Debugging
48
+ ```bash
49
+ docker compose logs -f <service> # Follow logs
50
+ docker compose exec <svc> sh # Shell into container
51
+ docker compose ps # Status
52
+ docker compose restart <service> # Restart
53
+ docker system prune -af # Clean everything
54
+ docker volume ls # List volumes
55
+ ```
@@ -0,0 +1,37 @@
1
+ # Git Workflow Skill
2
+
3
+ ## When to use
4
+ Any git operations: branching, committing, merging, rebasing.
5
+
6
+ ## Branch Strategy
7
+ - `main` — Production, always stable
8
+ - `feat/<name>` — New features
9
+ - `fix/<name>` — Bug fixes
10
+ - `chore/<name>` — Maintenance tasks
11
+
12
+ ## Conventional Commits
13
+ ```
14
+ feat: add user authentication
15
+ fix: resolve memory leak in cache
16
+ docs: update API documentation
17
+ chore: upgrade dependencies
18
+ refactor: simplify error handling
19
+ test: add integration tests for auth
20
+ perf: optimize database queries
21
+ ci: add GitHub Actions workflow
22
+ ```
23
+
24
+ ## Workflow
25
+ 1. `git checkout -b feat/<name>` from main
26
+ 2. Make focused, atomic commits
27
+ 3. `git push origin feat/<name>`
28
+ 4. Create PR with description
29
+ 5. Review, approve, squash merge into main
30
+ 6. Delete feature branch
31
+
32
+ ## Recovery
33
+ - Undo last commit (keep changes): `git reset --soft HEAD~1`
34
+ - Undo last commit (discard): `git reset --hard HEAD~1`
35
+ - Stash changes: `git stash` / `git stash pop`
36
+ - Cherry-pick: `git cherry-pick <hash>`
37
+ - Interactive rebase: `git rebase -i HEAD~N`
@@ -0,0 +1,33 @@
1
+ # GitHub Workflow Skill
2
+
3
+ ## When to use
4
+ When working with GitHub repositories: creating repos, managing branches, pull requests, issues, releases, and GitHub Actions.
5
+
6
+ ## Best Practices
7
+ - Always create feature branches: `git checkout -b feat/<name>`
8
+ - Use conventional commits: `feat:`, `fix:`, `docs:`, `chore:`, `refactor:`, `test:`
9
+ - Write descriptive PR titles and bodies
10
+ - Link issues in PR descriptions: `Closes #123`
11
+ - Use GitHub Actions for CI/CD
12
+ - Keep commits atomic and focused
13
+ - Squash merge for cleaner history
14
+
15
+ ## PR Template
16
+ ```markdown
17
+ ## What
18
+ Brief description of changes
19
+
20
+ ## Why
21
+ Motivation and context
22
+
23
+ ## How
24
+ Implementation approach
25
+
26
+ ## Testing
27
+ How this was tested
28
+
29
+ ## Checklist
30
+ - [ ] Tests pass
31
+ - [ ] Documentation updated
32
+ - [ ] No breaking changes
33
+ ```
@@ -0,0 +1,57 @@
1
+ # Performance Optimization Skill
2
+
3
+ ## When to use
4
+ Profiling, optimizing, caching, reducing latency or resource usage.
5
+
6
+ ## Profiling First
7
+ - Never optimize without profiling first
8
+ - Measure before and after every change
9
+ - Focus on the bottleneck (Amdahl's Law)
10
+
11
+ ## Node.js
12
+ ```bash
13
+ # CPU profiling
14
+ node --prof app.js
15
+ node --prof-process isolate-*.log > profile.txt
16
+
17
+ # Memory profiling
18
+ node --inspect app.js
19
+ # Then use Chrome DevTools → Memory tab
20
+
21
+ # Benchmarking
22
+ hyperfine 'node script.js'
23
+ ```
24
+
25
+ ## Common Optimizations
26
+ ### Caching
27
+ - In-memory: LRU cache for hot data
28
+ - Redis/Memcached for distributed cache
29
+ - HTTP caching: `Cache-Control`, `ETag`, `Last-Modified`
30
+ - CDN for static assets
31
+
32
+ ### Database
33
+ - Add missing indexes (check `EXPLAIN ANALYZE`)
34
+ - Connection pooling
35
+ - Batch operations instead of N+1 queries
36
+ - Denormalize for read-heavy tables
37
+ - Use materialized views for complex aggregations
38
+
39
+ ### Network
40
+ - Enable compression (gzip/brotli)
41
+ - Minimize payload size
42
+ - Use HTTP/2 or HTTP/3
43
+ - Connection keep-alive
44
+ - Lazy loading for non-critical resources
45
+
46
+ ### Code
47
+ - Avoid unnecessary allocations in hot paths
48
+ - Use streams for large data processing
49
+ - Parallelize independent I/O operations (`Promise.all`)
50
+ - Debounce/throttle high-frequency operations
51
+ - Use worker threads for CPU-intensive tasks
52
+
53
+ ## Benchmarking Rules
54
+ - Warm up before measuring
55
+ - Run multiple iterations
56
+ - Report median, not mean (avoid outlier influence)
57
+ - Control for external factors (other processes, network)
@@ -0,0 +1,37 @@
1
+ # Prompt Architect Skill
2
+
3
+ ## When to use
4
+ Crafting structured prompts for LLMs, especially for sub-agents and automated workflows.
5
+
6
+ ## Prompt Structure
7
+ ```
8
+ [ROLE] Who the model should be
9
+ [CONTEXT] Background information
10
+ [TASK] What to do (specific, measurable)
11
+ [FORMAT] Expected output format
12
+ [CONSTRAINTS] Rules and limitations
13
+ [EXAMPLES] Few-shot examples if needed
14
+ ```
15
+
16
+ ## Best Practices
17
+ - Be specific: "Write a TypeScript function" > "Write code"
18
+ - Set constraints: max length, format, language
19
+ - Use delimiters: `---`, `###`, XML tags for sections
20
+ - Chain of thought: "Think step by step" for complex reasoning
21
+ - Few-shot: provide 2-3 examples for consistent output
22
+ - Negative examples: "Do NOT include..." for clarity
23
+
24
+ ## For Sub-Agents
25
+ When creating prompts for sub-agent tasks:
26
+ - Include ALL necessary context (the sub-agent has no memory)
27
+ - Specify the exact output format expected
28
+ - Set clear success criteria
29
+ - Include relevant file paths and code snippets
30
+ - Limit scope: one clear task per sub-agent
31
+
32
+ ## Anti-Patterns
33
+ - ❌ Vague instructions ("make it better")
34
+ - ❌ Missing context (assuming the model knows your codebase)
35
+ - ❌ No output format (getting inconsistent results)
36
+ - ❌ Too many tasks in one prompt (losing focus)
37
+ - ❌ Contradictory instructions
@@ -0,0 +1,46 @@
1
+ # Security Skill
2
+
3
+ ## When to use
4
+ Code review for security, implementing auth, handling sensitive data.
5
+
6
+ ## OWASP Top 10 Checks
7
+ 1. **Injection** — Parameterized queries, never string concatenation for SQL
8
+ 2. **Broken Auth** — Strong passwords, MFA, secure session management
9
+ 3. **Sensitive Data** — Encrypt at rest and in transit, never log secrets
10
+ 4. **XXE** — Disable external entity processing in XML parsers
11
+ 5. **Broken Access Control** — Check permissions on every request
12
+ 6. **Misconfig** — No default credentials, disable debug in production
13
+ 7. **XSS** — Sanitize output, use CSP headers
14
+ 8. **Insecure Deserialization** — Validate before deserializing
15
+ 9. **Known Vulnerabilities** — Keep dependencies updated
16
+ 10. **Insufficient Logging** — Log security events, monitor anomalies
17
+
18
+ ## Secrets Management
19
+ - NEVER commit secrets to git
20
+ - Use environment variables or secret managers
21
+ - Rotate keys regularly
22
+ - Use `.env` files locally, secrets manager in production
23
+ - Add `.env` to `.gitignore`
24
+
25
+ ## Auth Patterns
26
+ ```typescript
27
+ // Hash passwords (never store plain text)
28
+ const hash = await bcrypt.hash(password, 12);
29
+
30
+ // JWT with short expiry
31
+ const token = jwt.sign({ userId }, SECRET, { expiresIn: "15m" });
32
+
33
+ // Always validate input
34
+ const schema = z.object({
35
+ email: z.string().email(),
36
+ password: z.string().min(8),
37
+ });
38
+ ```
39
+
40
+ ## Headers
41
+ ```
42
+ Strict-Transport-Security: max-age=31536000; includeSubDomains
43
+ Content-Security-Policy: default-src 'self'
44
+ X-Content-Type-Options: nosniff
45
+ X-Frame-Options: DENY
46
+ ```
@@ -0,0 +1,36 @@
1
+ # Self-Improving Agent Skill
2
+
3
+ ## When to use
4
+ After any error, correction, or learning moment. Also before major tasks to review past learnings.
5
+
6
+ ## Protocol
7
+
8
+ ### On Error
9
+ 1. Document the error in `~/.phi/memory/learnings.md`
10
+ 2. Note: what happened, why, how to prevent it
11
+ 3. If it's a recurring pattern, create a rule
12
+
13
+ ### On Correction
14
+ When the user corrects you:
15
+ 1. Acknowledge the correction
16
+ 2. Write to memory: what was wrong, what's right
17
+ 3. Apply immediately
18
+
19
+ ### On Success
20
+ When a complex task succeeds:
21
+ 1. Note the approach that worked
22
+ 2. If novel, document for future reference
23
+
24
+ ### Before Major Tasks
25
+ 1. Read `~/.phi/memory/learnings.md`
26
+ 2. Check for relevant past mistakes
27
+ 3. Apply learned rules
28
+
29
+ ## Memory Format
30
+ ```markdown
31
+ ## YYYY-MM-DD — Learning
32
+ **Context:** What was happening
33
+ **Error/Insight:** What went wrong or what was learned
34
+ **Rule:** What to do differently
35
+ **Category:** [code|config|workflow|communication]
36
+ ```
@@ -0,0 +1,40 @@
1
+ # Testing Skill
2
+
3
+ ## When to use
4
+ Writing tests, designing test strategies, debugging test failures.
5
+
6
+ ## Test Pyramid
7
+ 1. **Unit tests** (70%) — Fast, isolated, test single functions
8
+ 2. **Integration tests** (20%) — Test component interactions
9
+ 3. **E2E tests** (10%) — Test full user flows
10
+
11
+ ## Best Practices
12
+ - Test behavior, not implementation details
13
+ - One assertion per test (ideally)
14
+ - Arrange → Act → Assert pattern
15
+ - Use descriptive test names: `should return 404 when user not found`
16
+ - Mock external dependencies, not internal logic
17
+ - Test edge cases: empty, null, boundary values, errors
18
+ - Don't test library code
19
+
20
+ ## TypeScript (Vitest/Jest)
21
+ ```typescript
22
+ describe("UserService", () => {
23
+ it("should create a user with valid data", async () => {
24
+ const user = await createUser({ name: "Test", email: "test@example.com" });
25
+ expect(user.id).toBeDefined();
26
+ expect(user.name).toBe("Test");
27
+ });
28
+
29
+ it("should throw on duplicate email", async () => {
30
+ await createUser({ name: "A", email: "dup@example.com" });
31
+ await expect(createUser({ name: "B", email: "dup@example.com" }))
32
+ .rejects.toThrow("Email already exists");
33
+ });
34
+ });
35
+ ```
36
+
37
+ ## Test Coverage
38
+ - Aim for 80%+ on critical paths
39
+ - 100% on business logic
40
+ - Don't chase 100% everywhere (diminishing returns)