#!/usr/bin/env node
import'./chunk-5TAVYPOV.js';import*as c from'path';import*as i from'fs';import*as d from'js-yaml';import o from'chalk';import {execSync}from'child_process';var f=".paradigm/tutorial/state.json",h=".paradigm/tutorial/curriculum.yaml";function p(n){let e=c.join(n,f);if(i.existsSync(e))try{return JSON.parse(i.readFileSync(e,"utf8"))}catch{}return {currentStep:null,completedSteps:[],fixedBugs:[]}}function g(n,e){let s=c.join(n,f),t=c.dirname(s);i.existsSync(t)||i.mkdirSync(t,{recursive:true}),i.writeFileSync(s,JSON.stringify(e,null,2),"utf8");}function y(n){let e=c.join(n,".paradigm/tutorial");i.existsSync(e)||i.mkdirSync(e,{recursive:true});let s={title:"Paradigm Tutorial - ShopFlow Example",description:"Learn Paradigm by exploring the ShopFlow e-commerce example",steps:[{id:"step-1-explore-structure",title:"Explore Project Structure",description:"Understand how Paradigm organizes project knowledge",file:"step-1-explore-structure.md",checkpoints:[{type:"file-exists",path:".purpose"},{type:"file-exists",path:"portal.yaml"},{type:"file-exists",path:".paradigm/config.yaml"}]},{id:"step-2-understand-purpose",title:"Understanding Purpose Files",description:"Learn how Purpose files define features and components",file:"step-2-understand-purpose.md",checkpoints:[{type:"file-exists",path:".purpose"}]},{id:"step-3-understand-gates",title:"Understanding Gates",description:"Learn how Gates define authorization and access control",file:"step-3-understand-gates.md",checkpoints:[{type:"file-exists",path:"portal.yaml"}]},{id:"step-4-explore-symbols",title:"Exploring Symbols",description:"Understand Paradigm's symbol system and how they connect",file:"step-4-explore-symbols.md",checkpoints:[{type:"command-success",command:"paradigm status"}]},{id:"step-5-visualize",title:"Visualize in Dreamscape",description:"See your project knowledge visualized in the Dreamscape",file:"step-5-visualize.md",checkpoints:[{type:"command-success",command:"paradigm dream aggregate"}]}],bugs:[]},t=c.join(e,"curriculum.yaml");i.writeFileSync(t,d.dump(s),"utf8");let r=[{file:"step-1-explore-structure.md",content:`# Step 1: Explore Project Structure

Welcome to the Paradigm tutorial! In this step, you'll explore how Paradigm organizes project knowledge.

## What You'll Learn

- How Paradigm uses files to structure project knowledge
- The purpose of different Paradigm files
- How to navigate a Paradigm project

## Tasks

1. **Examine the root .purpose file**
   - Open \`.purpose\` in the root directory
   - Notice how it defines features (\`@\`) and components (\`#\`)
   - See how features reference components and gates

2. **Check the portal.yaml file**
   - Open \`portal.yaml\`
   - Notice how gates (\`^\`) define authorization rules
   - See how gates have locks, keys, and prizes

3. **Explore .paradigm directory**
   - Look at \`.paradigm/config.yaml\` - this is the Paradigm configuration
   - Check \`.paradigm/specs/\` - these define the symbol system
   - Browse \`.paradigm/docs/\` - reference documentation

4. **Notice the nested structure**
   - Check \`auth/.purpose\`, \`payments/.purpose\`, etc.
   - See how Purpose files can be organized by domain

## Checkpoint

When you're ready, run:
\`\`\`bash
paradigm tutorial checkpoint
\`\`\`

This will verify you've explored the key files.
`},{file:"step-2-understand-purpose.md",content:`# Step 2: Understanding Purpose Files

Purpose files are the foundation of Paradigm. They define what your project does and how it's structured.

## What You'll Learn

- How Purpose files define features (\`@\`) and components (\`#\`)
- How to read and understand Purpose file syntax
- How features reference other symbols

## Tasks

1. **Read the root .purpose file**
   - Open \`.purpose\` and read through it
   - Identify all features (lines starting with \`- id: "@\`)
   - Identify all components (lines starting with \`- id: "#\`)

2. **Understand feature definitions**
   - Look at \`@product-browse\` - what components does it use?
   - Look at \`@checkout-flow\` - what gates does it require?
   - Notice how features reference other features

3. **Explore nested Purpose files**
   - Open \`auth/.purpose\` - what features are defined here?
   - Open \`payments/.purpose\` - how does it relate to checkout?
   - See how domain-specific Purpose files organize knowledge

4. **Trace a feature**
   - Pick a feature like \`@checkout-flow\`
   - Follow its references to see what it depends on
   - Understand the relationships between features, components, and gates

## Key Concepts

- **Features (\`@\`)** - User-facing capabilities
- **Components (\`#\`)** - Reusable code units
- **References** - How features connect to components and gates

## Checkpoint

Run:
\`\`\`bash
paradigm tutorial checkpoint
\`\`\`
`},{file:"step-3-understand-gates.md",content:`# Step 3: Understanding Gates

Gates define authorization and access control in Paradigm. They're like security checkpoints.

## What You'll Learn

- How gates (\`^\`) define access control
- The structure of locks, keys, and prizes
- How gates protect features

## Tasks

1. **Examine portal.yaml**
   - Open \`portal.yaml\` and read through it
   - Notice the structure: gates \u2192 locks \u2192 keys
   - See how prizes are awarded when gates pass

2. **Understand a simple gate**
   - Look at \`^auth-required\`
   - What lock does it have?
   - What key expression checks authentication?
   - What prize is awarded?

3. **Explore a complex gate**
   - Look at \`^admin-panel\`
   - How many locks does it have?
   - What conditions must be met?
   - What prizes are available?

4. **See gates in action**
   - Go back to \`.purpose\` files
   - Find features that reference gates (like \`^auth-required\`)
   - Understand how gates protect features

## Key Concepts

- **Gates (\`^\`)** - Access control points
- **Locks** - Conditions that must be met
- **Keys** - Expressions that unlock locks
- **Prizes** - Rewards when gates pass

## Checkpoint

Run:
\`\`\`bash
paradigm tutorial checkpoint
\`\`\`
`},{file:"step-4-explore-symbols.md",content:`# Step 4: Exploring Symbols

Paradigm uses a symbol system to create a shared language between code, developers, and AI.

## What You'll Learn

- All the symbol types in Paradigm
- Concatenated symbols (compound ideas like \`?@\`, \`?#\`, \`?!\`)
- How symbols reference each other
- How to use paradigm commands to explore symbols

## Tasks

1. **Run paradigm status**
   \`\`\`bash
   paradigm status
   \`\`\`
   - See how many features, components, gates, etc. are defined
   - Notice the symbol counts

2. **Understand symbol types**
   - \`@\` - Features (user-facing capabilities)
   - \`#\` - Components (reusable code units)
   - \`$\` - Flows (multi-step processes)
   - \`%\` - State (global/user state)
   - \`~\` - Deprecated (marked for removal)
   - \`^\` - Gates (access control)
   - \`!\` - Signals (events/errors)
   - \`?\` - Ideas (exploration)

3. **Understand concatenated symbols (compound ideas)**
   Ideas can specify what type of symbol they're exploring by using a compound prefix:
   - \`?@subscription-model\` - Idea for a feature
   - \`?#dark-mode-toggle\` - Idea for a component
   - \`?$express-checkout\` - Idea for a flow
   - \`?%user-preferences\` - Idea for state
   - \`?~old-api-removal\` - Idea for deprecation
   - \`?^premium-access\` - Idea for a gate
   - \`?!payment-webhook\` - Idea for a signal
   
   **Why use compound ideas?**
   - **Categorization**: Makes it clear what type of symbol the idea relates to
   - **Discoverability**: In the Dreamscape visualizer, compound ideas connect to their target symbol type
   - **Planning**: Helps organize ideas by what they would become if implemented
   
   **Simple vs Compound:**
   - \`?subscription-model\` - General idea, no specific type
   - \`?@subscription-model\` - Idea specifically for a feature

4. **Trace symbol relationships**
   - Pick a feature like \`@checkout-flow\`
   - See what gates it requires
   - See what components it uses
   - See what flows it's part of
   - Look for compound ideas in \`.premise\` files

5. **Explore with paradigm commands**
   \`\`\`bash
   paradigm purpose validate
   paradigm gate validate
   \`\`\`
   - Validate your Purpose files
   - Validate your gate configuration

## Key Concepts

- Symbols create a traceable web of relationships
- Compound ideas (\`?@\`, \`?#\`, etc.) categorize ideas by their target symbol type
- In the Dreamscape visualizer, compound ideas visually connect to their symbol type
- AI agents can follow these relationships
- Symbols make project knowledge discoverable

## Checkpoint

Run:
\`\`\`bash
paradigm tutorial checkpoint
\`\`\`
`},{file:"step-5-visualize.md",content:`# Step 5: Visualize in Dreamscape

The Dreamscape is Paradigm's infinite canvas where all project knowledge flows together.

## What You'll Learn

- How to aggregate all symbols into the Dreamscape
- How to visualize your project knowledge
- How to explore relationships visually

## Tasks

1. **Aggregate symbols**
   \`\`\`bash
   paradigm dream aggregate
   \`\`\`
   - This combines all Purpose and Gate files
   - Creates a unified symbol index
   - Prepares data for visualization

2. **Open the Dreamscape**
   \`\`\`bash
   paradigm visualize
   \`\`\`
   - This opens the visualizer in your browser
   - You'll see all your symbols as nodes
   - Connections show relationships

3. **Explore visually**
   - Click on features to see their connections
   - See how gates protect features
   - Understand the flow of information
   - Notice how everything connects

4. **Understand the big picture**
   - See how ShopFlow is structured
   - Understand feature dependencies
   - Visualize authorization topology

## Key Concepts

- The Dreamscape shows everything at once
- Visual exploration helps understand relationships
- Symbols become nodes, references become connections

## Checkpoint

Run:
\`\`\`bash
paradigm tutorial checkpoint
\`\`\`

## Next Steps

Congratulations! You've completed the tutorial. You now understand:
- How Paradigm structures project knowledge
- How Purpose files define features and components
- How Gates define authorization
- How symbols create relationships
- How to visualize everything in the Dreamscape

Continue exploring ShopFlow, or start using Paradigm in your own projects!
`}];for(let a of r){let l=c.join(e,a.file);i.writeFileSync(l,a.content,"utf8");}}function u(n){let e=c.join(n,h);return i.existsSync(e)||y(n),d.load(i.readFileSync(e,"utf8"))}async function w(n,e,s){let t=s.steps.find(r=>r.id===e);if(!t)return  false;for(let r of t.checkpoints||[])switch(r.type){case "file-exists":{let a=c.join(n,r.path);if(!i.existsSync(a))return console.log(o.red(`\u274C Missing: ${r.path}`)),false;break}case "symbol-count":break;case "gate-count":break;case "command-success":{try{execSync(r.command,{cwd:n,stdio:"pipe"});}catch{return console.log(o.red(`\u274C Command failed: ${r.command}`)),false}break}case "bug-fixed":{if(!p(n).fixedBugs.includes(r.bug))return console.log(o.red(`\u274C Bug not fixed: ${r.bug}`)),false;break}}return  true}async function v(n){let e=n?c.resolve(n):process.cwd();try{let s=c.join(e,h);i.existsSync(s)||(console.log(o.blue(`
\u{1F4DA} Generating tutorial curriculum...
`)),y(e),console.log(o.green(`\u2705 Tutorial curriculum generated!
`)));let t=u(e),r=p(e);if(!r.currentStep&&t.steps.length>0&&(r.currentStep=t.steps[0].id,g(e,r)),console.log(o.blue(`
\u{1F393} Paradigm Tutorial
`)),console.log(`Current Step: ${r.currentStep||"Not started"}`),console.log(`Completed Steps: ${r.completedSteps.length}/${t.steps.length}
`),r.currentStep){let a=t.steps.find(l=>l.id===r.currentStep);if(a){let l=c.join(e,".paradigm/tutorial",a.file);i.existsSync(l)&&(console.log(o.cyan(`\u{1F4D6} ${a.title}`)),console.log(o.gray(a.description)),console.log(o.gray(`
View full instructions: ${l}
`)));}}console.log("Commands:"),console.log("  paradigm tutorial step <n>     Show step n"),console.log("  paradigm tutorial checkpoint   Validate current checkpoint"),console.log("  paradigm tutorial next         Move to next step"),console.log("  paradigm tutorial status       Show progress"),console.log(`  paradigm tutorial reset        Reset tutorial
`);}catch(s){console.error(o.red(`\u274C Error: ${s.message}`)),process.exit(1);}}async function b(n,e){let s=n?c.resolve(n):process.cwd();try{let t=u(s),r=e?parseInt(e,10)-1:0;(r<0||r>=t.steps.length)&&(console.error(o.red(`\u274C Invalid step number: ${e}`)),process.exit(1));let a=t.steps[r],l=c.join(s,".paradigm/tutorial",a.file);if(i.existsSync(l)){console.log(o.blue(`
\u{1F4D6} Step ${r+1}: ${a.title}
`));let m=i.readFileSync(l,"utf8");console.log(m);}else console.error(o.red(`\u274C Step file not found: ${l}`)),process.exit(1);}catch(t){console.error(o.red(`\u274C Error: ${t.message}`)),process.exit(1);}}async function C(n){let e=n?c.resolve(n):process.cwd();try{let s=u(e),t=p(e);if(!t.currentStep){console.log(o.yellow("\u26A0\uFE0F  No active step. Run `paradigm tutorial start` first."));return}if(console.log(o.blue(`
\u{1F50D} Validating checkpoint for step: ${t.currentStep}
`)),await w(e,t.currentStep,s)){console.log(o.green(`\u2705 All checkpoints passed!
`));let a=s.steps.findIndex(l=>l.id===t.currentStep);if(a<s.steps.length-1){let l=s.steps[a+1],m=c.join(e,".paradigm/tutorial",l.file);i.existsSync(m)&&(console.log(o.cyan(`
\u{1F4D6} Next Step: ${l.title}
`)),console.log(o.gray(l.description)),console.log(o.gray(`
Run 'paradigm tutorial step ${a+2}' to view full instructions.
`)));}else console.log(o.green(`
\u{1F389} Congratulations! You've completed all steps!
`)),console.log(o.gray(`Run 'paradigm tutorial next' to mark this step as complete.
`));}else console.log(o.red(`\u274C Some checkpoints failed. Review the errors above.
`)),process.exit(1);}catch(s){console.error(o.red(`\u274C Error: ${s.message}`)),process.exit(1);}}async function P(n){let e=n?c.resolve(n):process.cwd();try{let s=u(e),t=p(e);if(!t.currentStep){console.log(o.yellow("\u26A0\uFE0F  No active step. Run `paradigm tutorial start` first."));return}await w(e,t.currentStep,s)||(console.log(o.red(`
\u274C Cannot proceed. Please complete current step checkpoints first.
`)),process.exit(1)),t.completedSteps.includes(t.currentStep)||t.completedSteps.push(t.currentStep);let a=s.steps.findIndex(l=>l.id===t.currentStep);a<s.steps.length-1?(t.currentStep=s.steps[a+1].id,g(e,t),console.log(o.green(`
\u2705 Step completed! Moving to next step.
`)),await b(n,String(a+2))):(t.currentStep=null,g(e,t),console.log(o.green(`
\u{1F389} Congratulations! You've completed the tutorial!
`)));}catch(s){console.error(o.red(`\u274C Error: ${s.message}`)),process.exit(1);}}async function z(n){let e=n?c.resolve(n):process.cwd();try{let s=u(e),t=p(e);if(console.log(o.blue(`
\u{1F4CA} Tutorial Progress
`)),console.log(`Current Step: ${t.currentStep||"Not started"}`),console.log(`Completed: ${t.completedSteps.length}/${s.steps.length}`),console.log(`Bugs Fixed: ${t.fixedBugs.length}
`),t.currentStep){let r=s.steps.find(a=>a.id===t.currentStep);r&&(console.log(o.cyan(`Current: ${r.title}`)),console.log(o.gray(r.description)));}console.log("");}catch(s){console.error(o.red(`\u274C Error: ${s.message}`)),process.exit(1);}}async function $(n){let e=n?c.resolve(n):process.cwd(),s=c.join(e,f);i.existsSync(s)&&i.unlinkSync(s),console.log(o.green("\n\u2705 Tutorial reset. Run `paradigm tutorial start` to begin again.\n"));}async function T(n){let e=n?c.resolve(n):process.cwd();try{let s=u(e),t=p(e);console.log(o.blue(`
\u{1F41B} Intentional Bugs
`));for(let r of s.bugs||[]){let a=t.fixedBugs.includes(r.id);console.log(`${a?o.green("\u2705"):o.yellow("\u23F3")} ${r.title}`),console.log(o.gray(`   ${r.description}`)),r.hint&&console.log(o.gray(`   Hint: ${r.hint}`)),console.log("");}}catch(s){console.error(o.red(`\u274C Error: ${s.message}`)),process.exit(1);}}export{T as tutorialBugsCommand,C as tutorialCheckpointCommand,P as tutorialNextCommand,$ as tutorialResetCommand,v as tutorialStartCommand,z as tutorialStatusCommand,b as tutorialStepCommand};