Part I — Foundations · Chapter 1 · Lesson 3 of 5 · 8 min read
Lesson 3: The Command-Line Workflow—Run, REPL, Format, Check, Docs, Debug, and DAP
Lesson level: Foundation
Purpose: Build a disciplined edit–check–run–inspect workflow and understand when each PeaLang command belongs in development or automation.
Learning objectives
By the end of this lesson, you should be able to:
- run PeaLang source files safely;
- experiment in the interactive environment;
- format source or verify formatting without rewriting it;
- perform static source checks before execution;
- generate documentation from source;
- start a debugging session with optional breakpoints;
- explain how the Debug Adapter Protocol supports editor integration; and
- combine these commands into a repeatable development loop.
3.1 One command, several feedback loops
The pea command is the main entry point for language development. Each subcommand answers a different question. run asks whether the program executes. repl supports quick experiments. fmt normalizes layout. check finds source diagnostics without running the program. docs extracts documentation. debug opens an interactive inspection path. dap exposes debugger operations to compatible tools.
A reliable workflow uses the cheapest, safest feedback first. Format and check before execution; run focused examples before larger tests; use debugging when output and diagnostics no longer explain behavior.
3.2 Run a source file
The standard execution form is:
pea run FILE
For example:
pea run hello.pea
The runtime resolves the source path, reads UTF-8 text, associates execution with the file’s directory, and reports language or operating-system failures as errors. A successful run returns a success status; a failure returns a nonzero status suitable for scripts and automation.
Process execution is denied by default. The run command accepts an explicit --allow-process option, but it should be used only for trusted code with a justified requirement. It is not a general remedy for a failing script. Ordinary course examples do not require it.
Convenience form. When one source path is supplied without a recognized subcommand, the CLI can run that file directly. This book nevertheless uses pea run FILE because the intent remains obvious in notes, scripts, and CI logs.
3.3 Use the REPL for focused experiments
Start the interactive environment with:
pea repl
Calling pea with no arguments also opens the REPL. The prompt preserves variables and definitions between entries, making it useful for testing expressions, standard-library calls, and short language constructs before placing them in a source file.
The REPL recognizes these control commands:
- :help — display the available REPL controls;
- :vars — list visible user-level global names;
- :clear — reset the interpreter state;
- exit or quit — leave the REPL.
For a multi-line block, the REPL continues collecting input while opening braces outnumber closing braces. A language error is displayed, and the interactive process remains available for the next attempt.
Choose the right surface. Use the REPL to answer a small question quickly. Move code into a .pea file when it must be repeatable, reviewable, testable, documented, or shared.
3.4 Format source consistently
Format one or more files or directories with:
pea fmt PATH [PATH ...]
The formatter discovers .pea files beneath the supplied paths, rewrites them into canonical form, and prints the files it formatted. Use it before review so changes in spacing and layout do not distract from changes in behavior.
To verify formatting without rewriting files, use:
pea fmt --check PATH [PATH ...]
Check mode identifies files that differ from canonical formatting and returns a failure status when changes are required. This makes it appropriate for continuous integration and pre-commit validation.
Safe habit: During active editing, format locally and review the diff. In automation, use --check so the pipeline reports drift rather than mutating the workspace.
3.5 Check source without running it
Run static source checks with:
pea check PATH [PATH ...]
The checker discovers .pea files, analyzes their source, and renders diagnostics with file context. It returns a failure status when error-level diagnostics are found. Because it does not execute the program, it is safer and faster than using execution as the first syntax check.
The check command is distinct from later analysis tools. Basic checking focuses on source diagnostics. Optional typing and flow-aware semantic analysis use dedicated commands covered in the type-system chapter.
3.6 A minimal edit loop
- Edit a small, coherent change.
- Run pea fmt on the changed source.
- Run pea check on the relevant file or directory.
- Run the smallest example that exercises the change.
- Inspect output and exit status.
- Escalate to the debugger only when the observed behavior remains unexplained.
This ordering shortens feedback and separates formatting, static diagnostics, runtime behavior, and interactive investigation into distinct signals.
3.7 Generate source documentation
Generate documentation from one source file with:
pea docs FILE
Without an output option, generated content is printed to standard output. To write it to a file, use:
pea docs FILE -o OUTPUT
For example:
pea docs rules.pea -o rules.md
Documentation generation reads the named source file and produces documentation from its supported declarations and comments. Treat the output as derived material: update the source, regenerate the document, and avoid manually maintaining divergent copies.
3.8 Start a debugging session
Inspect a source file with:
pea debug FILE
To register a source-line breakpoint at startup, add one or more breakpoint options:
pea debug FILE --break=LINE
The command constructs a debug session for the file, registers requested line breakpoints, starts execution, and prints the resulting debugger state in structured form. A breakpoint is meaningful only when it corresponds to executable source.
Use debugging to inspect control flow, variables, stack frames, and evaluation state. Before debugging, confirm that the file passes basic checking and that you can reproduce the unexpected behavior with a focused input.
3.9 Debug Adapter Protocol
Start the source-level Debug Adapter Protocol service with:
pea dap
The adapter communicates through Content-Length framed JSON over standard input and output. It supports initialization, launch, breakpoint configuration, continue, next, step in, step out, thread and stack inspection, scopes, variables, expression evaluation, disconnect, and termination.
DAP is primarily an integration surface for editors and IDEs. A compatible client sends protocol requests and renders the results as familiar debugging controls. Because protocol traffic uses standard input and output, do not mix unrelated console output into the adapter channel.
PeaLang also includes a VM-oriented adapter started with pea vm-dap. The source-level dap command is the appropriate starting point for this lesson; VM-specific debugging is covered with bytecode and VM internals.
3.10 Command selection guide
| Need | Command | Key behavior |
|---|---|---|
| Execute a source file | pea run FILE | Runs with process execution denied unless explicitly enabled. |
| Try a short experiment | pea repl | Preserves interactive state until cleared or exited. |
| Normalize source layout | pea fmt PATH | Rewrites discovered .pea files. |
| Verify formatting in automation | pea fmt --check PATH | Reports drift and returns failure without rewriting. |
| Find source diagnostics | pea check PATH | Checks without executing the program. |
| Generate documentation | pea docs FILE -o OUTPUT | Produces derived documentation from source. |
| Inspect execution | pea debug FILE --break=LINE | Starts a debug session with an optional breakpoint. |
| Connect an editor debugger | pea dap | Runs the source-level protocol adapter over standard streams. |
3.11 Exit status and automation
Command-line workflows depend on more than printed messages. A zero exit status indicates success; a nonzero status lets shell scripts, pre-commit hooks, and CI pipelines stop when a required condition fails. Formatting check, source check, and execution failures can therefore act as quality gates.
A simple validation sequence is:
pea fmt --check .
pea check .
pea run hello.pea
In a real project, native tests would follow. Keep diagnostic stages separate so a failure clearly identifies formatting, static analysis, runtime, or test behavior.
3.12 Common mistakes
- Running before checking: this mixes source diagnostics with runtime failures and slows investigation.
- Using the REPL as the only record: interactive state is convenient but not reproducible. Move useful experiments into source and tests.
- Using fmt in CI without --check: automation should report formatting drift rather than modify tracked files.
- Enabling process execution casually: preserve the secure default unless trusted code has an explicit requirement.
- Setting a breakpoint on a non-executable line: choose a line containing executable behavior.
- Writing extra output to a DAP channel: protocol clients expect framed messages, not mixed human-readable logs.
- Editing generated documentation directly: change the source and regenerate the output.
3.13 Troubleshooting
- If a command sees no files, verify the supplied path and .pea extension.
- If formatting check fails, run ordinary formatting locally, review the changes, and rerun check mode.
- If check succeeds but run fails, investigate runtime inputs, permissions, imports, and behavior rather than syntax alone.
- If the REPL appears to wait, check whether an opening brace still needs a closing brace.
- If a breakpoint does not trigger, verify the line number and that execution reaches an executable statement.
- If an editor cannot start DAP, verify its launch configuration and ensure the adapter’s standard streams are reserved for protocol traffic.
3.14 Hands-on lab: Build a repeatable CLI workflow
Goal: Practice every command in this lesson against a small learning file.
- Create workflow.pea containing two print statements and deliberately uneven spacing.
- Run pea fmt workflow.pea, then inspect the rewritten file.
- Run pea fmt --check workflow.pea and confirm that no formatting drift remains.
- Run pea check workflow.pea.
- Run pea run workflow.pea and record its output.
- Use the REPL to evaluate one expression related to the file; inspect :vars, then use :clear.
- Generate documentation to workflow.md.
- Start a debug session with a breakpoint on an executable line.
- Record which commands changed files, which only inspected them, and which executed code.
Deliverable: A short workflow report containing each command, its purpose, whether it modifies files, whether it executes PeaLang code, its observed result, and any nonzero exit status. Do not enable process execution for this lab.
3.15 Review questions
- Why is pea run FILE clearer than the single-path convenience form?
- When should an experiment move from the REPL into a source file?
- What is the difference between pea fmt and pea fmt --check?
- Why should pea check normally precede execution?
- How do you write generated documentation to a file?
- What makes a source line a useful breakpoint location?
- Which transport does the DAP command use?
- Why should CI stages remain separate?
3.16 Applied challenge
Design a local pre-review routine for a PeaLang project. Include formatting, static checking, one focused run, documentation regeneration when public declarations change, and criteria for opening a debugger. Then design the corresponding non-mutating CI routine and explain every difference.
Lesson summary
The PeaLang CLI supports a progression from fast feedback to deep inspection. Use the REPL for disposable experiments, source files for repeatability, formatting and checking for early feedback, run for behavior, docs for derived reference material, debug for focused investigation, and DAP for editor integration. Preserve secure defaults and use exit statuses to build reliable automation.
Lesson status: Approved.