# The @sypnia/learn package

> Read and validate lesson files, render a lesson for a level, run checks, and read progress from your code.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://learn.docs.sypnia.com/tools/sdk/

For agents: @sypnia/learn (MIT, TypeScript, Node 20+). Entry points: @sypnia/learn/format (parseCourse(dir), parseLesson(file), lint(dir) → {problems[]}, render(lesson, {level, language, slots}) → {html, text, blocks}); @sypnia/learn/checks (runChecks(lesson, {repo, commit, runner}) — local runner for authors); @sypnia/learn/client (createLearn({token|session, baseUrl}) → courses.list/get, lessons.get(id,{level}), next(), exercises.start(lessonId,{project}), exercises.check(id), progress.list/export/delete, explain({kind, ref}), offers.list/dismiss). Default baseUrl https://learn.api.sypnia.com/v1; session from ~/.config/sypnia (npx @sypnia/app login).

```bash
npm install @sypnia/learn
```

| Import                 | For                                                                         |
| ---------------------- | --------------------------------------------------------------------------- |
| `@sypnia/learn/format` | reading, validating and rendering lesson files: for authors and their tools |
| `@sypnia/learn/checks` | running a lesson's checks on your machine while you write it                |
| `@sypnia/learn/client` | the Learn API: courses, lessons, exercises, progress, explanations          |

## Authors

`lint-course.ts`

```ts
import { lint, parseLesson, render } from '@sypnia/learn/format';

const { problems } = await lint('./learn/use-cases-first');
if (problems.length) console.table(problems);

const lesson = await parseLesson('./learn/use-cases-first/failures-have-names.lesson.md');
const { text } = render(lesson, { level: 'starter', language: 'en', slots: { case: { title: 'Order for today', failures: [{ name: 'OutOfStock' }] } } });
```

## Apps and scripts

`next-lesson.ts`

```ts
import { createLearn } from '@sypnia/learn/client';

const learn = createLearn(); // the session of `npx @sypnia/app login`
const next = await learn.next();
const exercise = await learn.exercises.start(next.id, { project: 'la-espiga' });
const result = await learn.exercises.check(exercise.id);
console.log(result.status, result.checks);
```

`createLearn({ token, baseUrl })` takes a personal access token and your engine's address instead. A token belongs to a person: Learn has no secret key for apps, because every record belongs to someone.
