- Node.js with TypeScript for the CLI runtime.
- ESM-first package structure for modern Playwright, Stagehand, and Tiptap compatibility.
- Package manager to be selected during implementation; prefer
npmunless the project adoptspnpmoryarn.
- Use
commanderfor commands and options. - Keep commands thin and delegate work to modules under
src/. - Expected command modules:
src/cli.tssrc/auth/src/parser/src/browser/src/publish/
- Playwright provides browser control, tracing, screenshots, and page evaluation.
- Browserbase provides optional persistent cloud browser sessions and remote execution.
- Local Stagehand runs a visible local browser with
.substack-cli/chrome-profilefor password-based login and development. - Stagehand handles semantic navigation and actions so workflows are less dependent on brittle CSS selectors.
- Camoufox is an optional browser adapter to evaluate after the core Browserbase path works. The JavaScript ecosystem exists, but the most documented Camoufox path is still Playwright-compatible browser launch/connect rather than a first-party Substack solution.
- Front matter parsing extracts title, subtitle, slug, tags, publish mode, and schedule time.
- Markdown parser converts local Markdown to normalized HTML.
- Tiptap converts normalized HTML into ProseMirror JSON using server-compatible utilities.
- Custom Tiptap extensions represent Substack-specific editor features:
- paywall divider
- subscribe widget
- embeds
- callout or note blocks
- Zod validates generated payload shape before browser execution.
inspect: parse and validate content without opening a browser.draft: create or update a draft, defaulting to a non-publishing flow.publish: publish only after confirmation or--yes.schedule: schedule only after validating an explicit timestamp.- Browser automation should use Stagehand
observe()before criticalact()calls where possible. - Direct editor-state injection remains experimental; paste/input fallback is required.
- Environment variables:
BROWSERBASE_API_KEYBROWSERBASE_PROJECT_IDSTAGEHAND_MODELSUBSTACK_PUBLICATION_URLSUBSTACK_EMAILSUBSTACK_PASSWORD
- Local config file:
.substack-cli/config.jsonfor non-secret defaults.
- Secure credential storage:
- Browserbase persistent session IDs or Playwright
storageState. - OS keychain adapter later if raw credentials are ever required.
- Never commit
.env, storage-state files, traces, or screenshots that may contain account data.
- Browserbase persistent session IDs or Playwright
- Unit tests for Markdown parsing, Tiptap schema output, and config validation.
- Integration tests with mocked browser/session adapters.
- Optional end-to-end tests against a controlled test publication.
- Use TypeScript strict mode, ESLint, Prettier, and Vitest.