Skip to content

Three-layer CLI command structure: optimized for AI pattern recognition #11

@deepracticexs

Description

@deepracticexs

Background

NodeSpec is designed as an AI-first tool. Our CLI command structure should prioritize AI's pattern recognition capabilities over human memorization convenience.

Design Decision: Three-layer Structure

nodespec [role] [domain] [action] [args]

Example:

nodespec scaffold monorepo init [name]
nodespec scaffold package add <name>
nodespec scaffold app add <name>
nodespec scaffold config init

Why Three Layers (vs Flat Action)

Alternative Considered: Flat Action (Rejected)

nodespec scaffold [action] [args]
nodespec scaffold init-monorepo [name]
nodespec scaffold add-package <name>
nodespec scaffold add-app <name>

Comparison

Aspect Three-layer (domain + action) Flat action (verb-domain)
Pattern Inference ✅ Cartesian product: {domain} × {action} ❌ Linear: only same-verb patterns
Learning Cost ✅ 3 domains + 5 actions = 8 concepts → 15 commands ❌ 15 composite actions = 15 concepts
Add New Domain ✅ Auto inherits all actions ❌ Must define N new composite commands
Add New Action ✅ Auto applies to all domains ❌ Must define M new composite commands
Command Length ⚠️ Longer (not a problem for AI) ✅ Shorter (but loses composability)

AI Pattern Recognition Advantages

  1. Combinatorial Reasoning:

    • Given: scaffold package add
    • AI infers: scaffold {package|app|service} {add|remove|list}
    • Clear combination space
  2. Low Learning Cost:

    • Learn: 3 domains + 5 actions = 8 concepts
    • Generate: 3 × 5 = 15 valid commands
    • High knowledge compression ratio
  3. Extensibility:

    # Add new domain "plugin" → all actions available
    nodespec scaffold plugin add <name>
    nodespec scaffold plugin remove <name>
    nodespec scaffold plugin list
    
    # Add new action "validate" → applies to all domains  
    nodespec scaffold package validate
    nodespec scaffold app validate
    nodespec scaffold config validate
  4. Semantic Clarity:

    • Think: "I want to operate on {domain}, perform {action}"
    • Matches human reasoning and AI prompting

Implementation Structure

commands/
├── scaffold/
│   ├── index.ts              # scaffold role
│   ├── monorepo/
│   │   ├── init.ts           # action
│   │   └── create.ts         # action
│   ├── package/
│   │   ├── add.ts
│   │   ├── remove.ts
│   │   └── list.ts
│   ├── app/
│   │   ├── add.ts
│   │   ├── remove.ts
│   │   └── list.ts
│   └── config/
│       ├── init.ts
│       └── update.ts

Pattern Template

For AI to generate commands:

Role: {scaffold, architect, product, test, ...}
Domain: {monorepo, package, app, service, config, ...}
Action: {init, create, add, remove, list, update, validate, ...}

Template: nodespec <role> <domain> <action> [args]

Human Convenience (Optional)

While optimizing for AI, we can still provide aliases for humans:

# Alias (optional)
nodespec init → nodespec scaffold monorepo init
nodespec add package <name> → nodespec scaffold package add <name>

Internal: three-layer structure
External: optional shortcuts

Decision Rationale

Primary contradiction: Simplicity vs Composability

  • For humans: Shorter commands are easier to remember
  • For AI: Structured patterns are easier to infer

Resolution: Optimize for AI's strengths (pattern recognition), not human weaknesses (memory)

This is a "design for AI, not for humans" decision, aligning with NodeSpec's vision of making Node.js development AI-native.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions