@happyvertical/smrt-education 0.60.16 → 0.60.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/course-bundle-import.md +11 -0
- package/dist/course-bundle-service.d.ts.map +1 -1
- package/dist/course-bundle.d.ts +1 -1
- package/dist/course-bundle.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/smrt-knowledge.json +5 -5
- package/dist/smrt-knowledge.okf.md +2 -2
- package/package.json +10 -10
package/dist/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": "1.0.0",
|
|
3
3
|
"timestamp": 0,
|
|
4
4
|
"packageName": "@happyvertical/smrt-education",
|
|
5
|
-
"packageVersion": "0.60.
|
|
5
|
+
"packageVersion": "0.60.17",
|
|
6
6
|
"objects": {
|
|
7
7
|
"@happyvertical/smrt-education:CatalogProviderCollection": {
|
|
8
8
|
"name": "catalogprovidercollection",
|
package/dist/smrt-knowledge.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"sensitiveFieldsExcluded": true,
|
|
4
4
|
"generatedAt": "1970-01-01T00:00:00.000Z",
|
|
5
5
|
"packageName": "@happyvertical/smrt-education",
|
|
6
|
-
"packageVersion": "0.60.
|
|
6
|
+
"packageVersion": "0.60.17",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
10
|
+
"manifest": "8bdaa2bc474088694c55cb9885e96dd70b70152b48b89b8a9a44cd5c7ef5b3a7",
|
|
11
|
+
"packageJson": "0785c6e010bd5c40a5041578de45a9944524da9dc1ef930c0d91efb244c4583e",
|
|
12
12
|
"agents": "44f253815661ccb7ef613ae3a517a31c022c583940ba2afce2974017c32a972d",
|
|
13
13
|
"moduleDoc:agents/lesson-materials.md": "f58c0fc813a366c1d69bb636a67c99996996ad90d5b6b3ccc724ea1034e4d0d0",
|
|
14
14
|
"moduleDoc:agents/learner-service.md": "d7edf68000aec96b52920fb5e8dc4ff4e20b1d81b34413809e8212a885e1c3f9",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"moduleDoc:agents/course-generation-review.md": "7f6d5e67ed56ec9923bd00df05650b363fb0db30c1b1f004c8b203f9c62cd117",
|
|
21
21
|
"moduleDoc:agents/question-records.md": "c1648cccc27ed46b1b60cded93b20c7f3812cbcd2c37f183fd727ac030364703",
|
|
22
22
|
"moduleDoc:agents/question-extraction.md": "75972dda9b2f837471fb42f963ef143a098005c919a1a49db7ce395a5e5e50a7",
|
|
23
|
-
"moduleDoc:agents/course-bundle-import.md": "
|
|
23
|
+
"moduleDoc:agents/course-bundle-import.md": "ab55eff560e776fe3ef874f036c955c141f3002c606f4245c69ed86f9909979f",
|
|
24
24
|
"moduleDoc:agents/class-crunchlabs.md": "c8490ede1897d7c74805d2769f9531dfb37e25c65e409ac8465935b0c8e7af2f",
|
|
25
25
|
"moduleDoc:agents/source-import.md": "30ee823589d655442bcf1abcd86a2132172065b4bc5e3c4d89b1e8b7afcc66bc",
|
|
26
26
|
"moduleDoc:agents/family-intake.md": "540b6d37f438496acb0208b6ac7258264e2142bce3d2f986967b7741606fe4f7",
|
|
@@ -16499,7 +16499,7 @@
|
|
|
16499
16499
|
{
|
|
16500
16500
|
"path": "agents/course-bundle-import.md",
|
|
16501
16501
|
"module": "course-bundle-import",
|
|
16502
|
-
"content": "# Course bundle import\n\n`CourseBundleImportService` (SMRT #4578, extends `CourseAuthoringService`,\nconsumed by Hearth #94) imports a course bundle, a zip with an optional manifest\nor a plain file set, as bounded evidence, hands its supported members to the\nhost for ingestion extraction and proposes sections and lessons for review.\nRisk is high: untrusted archive parsing and new schema. It reuses the course\nauthorizer: `importBundle` needs `education.course.author`, `readImport`\n`education.course.read-draft`, `proposeStructure` `education.course.generate`\n(via `CourseGenerationReviewService`). Operations: `import-course-bundle`,\n`read-course-bundle`. Server only (Node `zlib`/`crypto`); no new dependency.\n\n## Flow\n\n1. `importBundle({ ...actor, bundle, limits?, onProgress?, receiveMember? })`\n authorizes **before parsing**, unpacks (stage `unpack`), classifies and lays\n out the structure (`classify`), writes the evidence in one transaction and\n then calls `receiveMember` for each accepted member (`extract`), outside any\n transaction. `bundle` is `{ archive: Uint8Array }` or `{ files: [{ path,\n bytes }] }`. Hostile or damaged input throws `CourseBundleRefusedError`\n (`reason`, optional `entry`) and writes nothing.\n2. `receiveMember(member, { replayed })` is the host's ingestion seam: call\n `IngestionService.receive` with `sourceKind: 'course_import'` and the member\n bytes, then queue extraction and `preserveQuestionExtractionAnalysis` as in\n [question extraction](question-extraction.md). Members carry `role`\n (manifest page role), `lessonKey`, `sectionKey`. It runs on a replay too\n (ingestion dedups by content hash), so an interrupted first run resumes. Its\n return values are in `result.receipts`.\n3. `proposeStructure({ ...actor, importId, bundle, courseId,\n expectedHeadRevisionId })` (stage `propose`) re-supplies the bundle (bytes\n are never retained), checks it is the imported one, and runs a deterministic\n `CourseMaterialGenerator` (`smrt-bundle-import`) through\n `requestGeneration`/`runGeneration`. The result is an ordinary proposal: a\n new draft revision of additions and fills; conflicts wait for\n `decideProposal`. Nothing is released, assigned or published. The request key\n is `bundle:<courseId>:<bundleIdentity>`, so a retry returns the same job; the\n same key with another head is `CourseRequestKeyConflictError`.\n4. `readImport({ ...actor, importId })` returns the recorded evidence.\n\nProgress is an observer callback (`onProgress({ stage, completed, total })`,\nstages `unpack`, `classify`, `render`, `extract`, `propose`; each starts at `completed: 0`;\n`render` is emitted only when the bundle has Word/PowerPoint members).\nIngestion has no public job-progress seam, so none is invented. A throwing\nlistener never affects the import.\n\n## Hard bounds (`COURSE_BUNDLE_LIMITS`; a host may only lower them)\n\n| limit | value |\n|---|---|\n| `maxArchiveBytes` (input) | 100 MiB |\n| `maxEntries` | 200 |\n| `maxEntryBytes` (inflated) | 50 MiB |\n| `maxTotalBytes` (inflated) | 200 MiB |\n| `maxCompressionRatio` (members over `ratioFloorBytes` = 64 KiB) | 100 |\n| `maxPathBytes` / `maxSegmentBytes` / `maxPathDepth` | 512 / 255 / 8 |\n| `maxManifestBytes` | 256 KiB |\n| `maxLessons` (the proposal schema's cap) | 50 |\n| `maxLessonBodyChars` | 100 000 |\n| `maxOfficeMembers` (Word/PowerPoint members rendered per bundle) | 50 |\n| `maxRenderedBytes` (PDF accepted back from the converter) | 50 MiB |\n| `conversionTimeoutMs` (one Office member) | 60 000 |\n| `maxThumbnailBytes` (first-page image accepted back from the converter) | 5 MiB |\n| archive nesting | 1: a zip inside a zip is never expanded |\n\nA lesson whose combined text members exceed `maxLessonBodyChars` refuses the\nbundle (`lesson_too_large`, `entry` = lesson key) at import; text is never\ntrimmed or dropped. A plain file set enforces `maxTotalBytes` on its member\nbytes exactly as an archive does on inflated bytes.\n\nThe reader (`course-bundle-zip.ts`) parses the end record and central directory,\nvalidates every offset and size against the real buffer, inflates with\n`maxOutputLength` equal to the declared size (declared sizes are never trusted:\na mismatch either way is `size_mismatch`), checks CRC32 and re-checks the total\non actual output. Stored and deflate only. Refusals (`CourseBundleRefusalReason`)\ncover: not a zip, truncated, ambiguous end record (two end records that both fit\nthe file, for example one forged in a comment), zip64, multi-disk, central\ndirectory not ending at the end record, entries out of range or overlapping,\nlocal header name/method mismatch, encrypted entries (flags 0/6/13, AES method),\nsymlink and special files (unix mode; DOS reparse flag), unsupported method,\nbad CRC, ratio, entry count, totals, duplicate names (case/NFC-insensitive,\nbackslashes normalised first) and bad paths (`..`, `.`, empty segments, absolute,\ndrive letter or `:` anywhere, NUL/control/bidi characters, lone surrogates,\ntoo long or deep). An **honestly** oversize member (declared over\n`maxEntryBytes`) is not inflated and is recorded `refused / entry_too_large`.\n\n## Members and statuses\n\nBy content (never by extension alone): `docx`/`pptx`/`xlsx` (see below), `pdf` (`%PDF-` in the first 1 KiB),\n`image` (PNG, JPEG, WebP), `text` (`.txt`/`.md`, strict UTF-8, no control\ncharacters, body-sized), `manifest` (root `manifest.json`), else `unsupported`.\nStatus: `accepted` (handed to extraction), `duplicate` (same sha256 as an earlier\nmember in canonical order; recorded once as evidence, `duplicateOfPath`, never\nextracted again), `unsupported` (`unsupported_type`, `nested_archive`,\n`unreadable_text`), `refused` (`encrypted_pdf`, `entry_too_large`), `metadata`\n(the manifest). Nothing is dropped. An encrypted PDF is any PDF with an\n`/Encrypt` token anywhere in its bytes (trailer, xref stream): a false positive\non literal text inside an uncompressed stream is refused, never read.\n\n## Word and PowerPoint members (SMRT #4615)\n\nA `.docx`/`.pptx`/`.xlsx` member is an OOXML package only when the name and the\ncontent agree: a zip whose entries include `[Content_Types].xml` and\n`word/document.xml` (docx), `ppt/presentation.xml` (pptx) or `xl/workbook.xml`\n(xlsx). A workbook (a supply list) is rendered and kept like the others but has\nno text reader. Before the bytes go anywhere, the\npackage itself passes the same bounded zip reader (ratio, overlap, paths, CRC,\n100 MiB inflated); a failure is `refused / unsafe_office`, never a refusal of the\nwhole bundle. Other zips stay `unsupported / nested_archive`.\n\nTwo separate things happen to an accepted Office member, both after\nauthorization and before the evidence is written:\n\n- **Pages**: a `DocumentConverter` (`document-converter.ts`) renders the original\n to PDF. The importer enforces the byte and time limits itself (input\n `maxEntryBytes`, output `maxRenderedBytes`, `conversionTimeoutMs` with an abort\n signal and a hard race, so an adapter that ignores the signal still times out),\n and rejects output that is not a PDF or is encrypted. The converter is told a\n neutral file name (`document.docx`), never the bundle path. Identical documents\n are rendered once.\n- **Text**: an injectable `OfficeTextReader` (best effort; a failure or a `null`\n costs the member nothing) returns whole-document text and, for decks, text and\n speaker notes per slide. Office text is handed to the host on the accepted\n member (`officeText`) and is **never** inlined into a proposed lesson body:\n teacher guides and notes carry answers, and audience belongs to manifest v2.\n\n`receiveMember` gets the original `bytes` (store them as the private original\nasset: \"Open in PowerPoint\" for decks) and `rendered` (`{ bytes, sha256, mediaType:\n'application/pdf', converterId }`, store as a private asset beside the original:\nthe pages for \"Present\"/reading). The member row records `renderedSha256` and\n`renderedSizeBytes`; bytes are still not retained here. A converter may also\nreturn a first-page image (`DocumentConversionResult.thumbnail`); the importer\nkeeps it only when it is a PNG/JPEG/WebP within `maxThumbnailBytes` and hands it\nover as `rendered.thumbnail` (`{ bytes, sha256, mediaType }`), else null. An\nunusable thumbnail never fails the member. Gotenberg draws none, so it is null.\n\n**Fail closed.** Any converter problem records that member `unsupported` with a\nreason and writes the rest of the bundle normally: `converter_unavailable` (none\nconfigured), `converter_failed` (unreachable or 5xx), `converter_timeout`,\n`converter_too_large`, `converter_rejected` (HTTP 4xx, not a PDF, encrypted),\n`office_limit` (beyond `maxOfficeMembers`, in natural path order). A member that\nfailed is not a lesson in the proposal, and identical copies of a failed document\nfail the same way rather than becoming duplicates of nothing. Outcomes are part\nof the append-only evidence, so a replay does not retry a recorded failure (to\nretry, change the bundle). A replay does re-render recorded-accepted members so the\nhost receives the bytes again; if it can no longer render one it throws\n`DocumentConversionError` rather than silently dropping an accepted member.\n\n### Host configuration\n\n```ts\nconst service = new CourseBundleImportService(db, authorizer, {\n converter: new GotenbergDocumentConverter({\n baseUrl: process.env.GOTENBERG_URL, // for example http://gotenberg:3000\n timeoutMs: 60_000,\n maxBytes: 50 * 1024 * 1024,\n }),\n officeTextReader, // optional, see below\n});\n```\n\n`GotenbergDocumentConverter` posts to `<baseUrl>/forms/libreoffice/convert`, talks\nto nothing else, refuses redirects and URLs with credentials, and caps the response\nas it streams. Run Gotenberg as an internal-only service with **no outbound\nnetwork**, its own size/time limits and no shared volume with the app; this\npackage assumes untrusted files never run next to the application. Tests use\n`FakeDocumentConverter` (records calls; `failWith`, `failWhen`, `delayMs`, `output`).\n\n`OfficeTextReader` reads Office text through the SDK without this package\ndepending on `@happyvertical/documents`: the host imports `extractOffice`\n(released in `@happyvertical/documents` 0.111.4, sdk#1486, Kreuzberg) and passes\nit to `createOfficeTextReader(extractOffice)`, which returns whole-document\ntext for Word and text plus speaker notes per slide for PowerPoint (images are\nnever requested). An absent engine reads as `null`; a corrupt file rejects and\nthe importer treats that as \"no text\". The repository's current `catalog:`\npin is 0.111.3, which predates the Office processors, so the host bumps the SDK\nset (and its minimum release age) before it can import `extractOffice`.\n\n## Manifest (`manifest.json`, version 1, closed)\n\n```json\n{ \"version\": 1, \"course\": { \"subject\": \"Math\" },\n \"sections\": [ { \"key\": \"unit-1\", \"title\": \"Unit One\",\n \"lessons\": [ { \"key\": \"sums\", \"title\": \"Sums\",\n \"members\": [ { \"path\": \"sheets/sums.pdf\", \"role\": \"exercise\" } ] } ] } ] }\n```\nEvery object is closed: an unknown key anywhere is `manifest_unknown_key` (with\nits path in `entry`); another version is `manifest_version`. Keys match\n`[A-Za-z0-9._:-]{1,120}` and are unique; roles are the extraction page roles\n(`exercise`, `example`, `instructions`, `cover`, `answer_key`, `mixed`,\n`unknown`); a listed path must exist and be listed once. The manifest is a source\nfact: roles are `source`, anything the extractor infers stays `inferred`, and a\nmanifest/extraction disagreement belongs in extraction review, not here. Without\na manifest each accepted member is one lesson, sections come from the top-level\ndirectory and order is natural path order (digit runs compare numerically, no\nlocale). Manifest order: the manifest, declared members, then the rest by path.\nLesson bodies are the readable text members of a lesson, joined; PDFs and images\nare never inlined. Members whose declared role is `answer_key` or `mixed` never\ncontribute text to a lesson body (they remain recorded evidence members); the\nproposal rationale only counts how many were withheld.\n\n## Manifest version 2 (SMRT #4615)\n\nA root `manifest.json` with `\"version\": 2` is laid out by the `manifest-v2`\nreader; version 1 keeps its own reader and page roles. The schema is closed in\nthe same way: an unknown key anywhere is `manifest_unknown_key` (with its path in\n`entry`), another version is `manifest_version`.\n\n```json\n{ \"version\": 2, \"course\": { \"subject\": \"Science\" },\n \"courseMembers\": [ { \"path\": \"unit/supplies.pdf\", \"role\": \"attachment\", \"title\": \"Supply list\" } ],\n \"sections\": [ { \"key\": \"unit\", \"title\": \"Unit\", \"lessons\": [ {\n \"key\": \"l1\", \"title\": \"Lesson 1\",\n \"members\": [ { \"path\": \"l1/log.docx\", \"role\": \"learner-pages\" },\n { \"path\": \"l1/deck.pptx\", \"role\": \"slides\" },\n { \"path\": \"l1/guidance.pdf\", \"role\": \"assessment-guidance\" } ],\n \"pages\": [ { \"member\": \"l1/log.docx\", \"from\": 1, \"to\": 4, \"label\": \"Mission log\" } ],\n \"videos\": [ { \"reference\": \"dQw4w9WgXcQ\", \"title\": \"Recap\", \"step\": 1 } ] } ] } ] }\n```\n\n- **Members** (lesson `members` and root `courseMembers`): `path` (must exist, listed\n once), `role` (required) one of `teacher-guide`, `slides`, `learner-pages`,\n `assessment`, `assessment-guidance`, `handout`, `printable`, `answer-key`,\n `attachment` (`manifest_role` otherwise; a video is a reference, never a file),\n optional `audience`, `title` and (lesson members only) `step`. The audience is the role default\n (`LESSON_ASSET_DEFAULT_AUDIENCE`) unless stated; `answer-key` and\n `assessment-guidance` are always guardian (a learner audience is\n `manifest_audience`). Members not listed stay recorded evidence with no role.\n- **Lesson steps** (SMRT #4656): a lesson member or video may declare\n `step: { key, order, label? }` (a closed object; `manifest_invalid` for a key over\n 32 characters or outside `A-Za-z0-9._:-`, a non-finite or non-number `order`\n (|order| up to 1,000,000), or an empty label; `manifest_unknown_key` for anything\n else, and a course member cannot carry one). Materials that share a `key` are\n one step; fractions order `1b` after `1`. A video's `step` is still accepted as a\n whole number (its rank); the object form also ranks it by `floor(order)`.\n- **Pages**: `{ member, from, to, label? }` ranges over a member of the same lesson\n (PDF, Word or PowerPoint; the rendered PDF for Office). Each page becomes a\n `LessonPage` keyed `p<n>`, labelled `<label> <n>` (default `Page <n>`), ordered by\n declaration. Bad, overlapping or unpageable ranges are `manifest_pages`; at most\n 500 pages per lesson.\n- **Videos**: `{ reference, title, step, audience? }` where `reference` is a bare id\n or an allowlisted https YouTube URL (`parseYouTubeReference`; anything else is\n `manifest_video`), `step` an integer 0-9999 or a lesson step object (see above). They become `LessonExternalVideo`\n rows; nothing is downloaded.\n- **Course members** become `CourseAsset` rows, not tied to any lesson.\n- **Unit and parts** (SMRT #4632): `course.key` (a manifest key) names the unit\n and `course.title` its course title; `part: { index, count }` (1-50) marks one\n bundle of a unit split across several, and requires `course.key`\n (`manifest_invalid` otherwise). Sections and lessons may carry a unit-wide\n `order` (0-9999); without one the position in this manifest is used, and\n the order counts as implicit when parts are merged.\n\nGuardian-audience text (teacher guides, guidance, keys) never enters a proposed\nlesson body; only learner-audience text members do. Under v2 `role` on the member\nevidence row is the material role and `audience` the effective audience (NULL on\nrows recorded before v2). The plan carries `materials` (also on\n`CourseBundleImportResult.materials`): the resolved materials, pages and videos,\nplus `skipped` for declared members that were unsupported, refused or failed\nrendering. A duplicate member resolves to the earlier identical member's bytes\n(`assetPath`) and one material per (place, role, content).\n\n`receiveMember` also gets `audience` and `courseLevel`, and an optional `title`\n(SMRT #4653): the manifest title of the one material the member holds (\"Teacher\nMission Manual\"), so a host can name the assets it stores. It is absent when the\nmanifest gave none or the member backs several materials with different titles.\n**Material titles**: `attachCourse` records that title on the `lesson_assets` /\n`course_assets` row (`title`; null on a lesson row without one, `''` on a course\nrow), the same for the original and rendered halves of a pair. Lesson and course\nmaterial views show the row title and fall back to the stored asset's name when\nthere is none. A re-attach fills a missing title; a different one is a\n`conflict` unless `supersede` restates it. **Lesson steps** (#4656): the declared\nstep is recorded on the `lesson_assets` row (`step_key`, `step_order`, `step_label`;\nboth halves of an original/rendered pair share it) and on `lesson_external_videos`\n(`step_key`, `step_position`, `step_label`; its existing integer `step_order` stays\nthe rank, `floor(order)` for an object step). All are additive nullable columns.\nA re-attach fills a row's missing step without a conflict; a different step is a\n`conflict` unless `supersede` restates it (replays are unchanged). Hosts read it\nwith `SubmissionService.listLessonSteps` ([lesson materials](lesson-materials.md)).\n**Slides** keep the original\ndeck (hand `bytes` to the host as a private asset: \"Open in PowerPoint\") and its\nrendered pages (`rendered`: \"Present\").\n\n### Attaching a family course (SMRT #4632)\n\n`attachCourse({ ...actor, importId, bundle, assets, courseId?, title?,\nlicenseKind? })` (`education.course.author`, operation `attach-course-bundle`) is\nthe published path from an import to a course: in one transaction it creates (or\nfinds) the family course, its sections and lessons, and writes the materials as\n`applyMaterials` does. `assets` maps member path to `{ original, rendered?,\nthumbnail? }` asset ids the host stored from `receiveMember`.\n\n- **Course**: a non-authored family draft (`sourceKey` `course-bundle`,\n `sourceRef` the unit key, `licenseKind` default `personal-use-copy`, title from\n the request, `course.title`, subject or first section). Ids derive from (family,\n unit key), sections and lessons from (course, key), so every part of a unit and\n every retry find the same rows. Lessons keep the manifest key in `externalRef`,\n `order` as `sortOrder` and, on creation, learner-audience text as `body` (after\n review choices). Nothing is released or published.\n- **Unit key**: `course.key`, else `bundle:<bundleIdentity>` (a one-part unit).\n- **Parts**: one `CourseBundleAttachment` per import (unique per import and per\n (course, part)). Attach parts in any order; the result says `part.attached` and\n `part.complete`. Fails closed and writes nothing: a `courseId` of another unit or\n another part count is `unit-mismatch`; a second import for an attached part is\n `part-conflict`. A replay is `replayed: true` and writes nothing new.\n- **Shared sections and lessons**: parts that share a key must agree, and the\n result never depends on arrival order. `CourseBundlePlacement`\n (`course_bundle_placements`) records each key's title and whether its order was\n declared. Another title, two different declared orders, or a declared order\n against an implicit one is `part-conflict` (nothing written). Between implicit\n positions the part with the lowest index decides; a lower part arriving later\n re-sorts the row. An existing row with no placement is `part-conflict`.\n- **Concurrency**: every attach transaction takes, in order, the import row lock\n (shared with `chooseMaterialAudience` and `applyMaterials`) and the unit lock: a\n `CourseBundleUnit` row (`course_bundle_units`, one per family and unit key)\n created if absent and then locked before anything that decides the outcome\n (attachments, the course, placements, choices) is read. On PostgreSQL a\n concurrent first create of the same unit waits and adopts the winner's row,\n so two first attaches can never both pass the checks.\n- **Zero renderings**: with no converter, Word/PowerPoint members are recorded\n `converter_unavailable` and listed in `skipped`; no rendered or original join,\n page or thumbnail is written for them, and nothing is faked. `retryRendering`\n later, then attach again: the replay adds the newly accepted materials.\n- `readImport` reports `attachment` (course, unit key, part) once attached.\n\n### Bringing a unit up to a newer build (SMRT #4645)\n\n`attachCourse({ ..., supersede: true })` is the explicit, opt-in way to replace\nthe build attached for a part. Without it nothing changes: another import for an\nattached part is `part-conflict`, and a placement whose title differs is\n`part-conflict`. It uses the same authorization (`education.course.author`),\ntenant rules and lock order (import row, then unit row) as any attach.\n\n- **Which build is newer**: manifests carry no build stamp, so \"newer\" is the\n import record: the importing bundle's `recordedAt` must be strictly later\n than the attached import's. Otherwise `stale-build` (an older or\n same-instant build never overwrites a newer one; re-attaching a superseded\n import is the same). `supersede` with no other build attached for the part is\n an ordinary attach.\n- **Identity**: sections and lessons keep their ids (derived from course id +\n key), so enrolments, progress and submissions stay attached. Titles and order\n follow the newer build (`renamed` counts changed titles); a key that a lower\n part decided still must agree (`part-conflict`). Lesson `body` is not\n rewritten. Sections and lessons the newer build no longer lists stay.\n- **Part count change** stays `unit-mismatch`, supersede or not.\n- **Materials**: the newer build's materials are attached; an existing row\n (same lesson, asset, role) is restated in place (order, title, current again; a\n renamed material shows its new title though it keeps its earlier asset),\n not a `conflict`; its audience stays the family's. Pages are restated and\n never retired (learner work points at page keys).\n- **Retirement**: file materials and external videos the replaced build wrote\n that the newer build does not carry get `retiredAt`. Rows are never deleted,\n so work that references them still resolves; learner and catalog material\n lists skip retired rows. `retired` counts them. Which rows belong to the\n replaced build: `sourceImportId` (new on `lesson_assets`, `course_assets`,\n `lesson_external_videos`, written by every attach/apply); rows from before it\n existed (null) are adopted when their lesson is one of the replaced import's\n lessons, and course materials when that import had course members. Rows\n from another part or source are never touched. A material that returns in a\n later build is current again.\n- **Audit**: the part's `CourseBundleAttachment` moves to the newer import (the\n one sanctioned attachment change, `supersedeWith`) and an append-only\n `CourseBundleSupersession` row (`course_bundle_supersessions`: course, unit\n key, part, new import, replaced import, actor, time) records which replaced\n which. The replaced import no longer reads as attached.\n- **Replay** of the same supersede is `replayed: true` and changes nothing.\n- Schema (additive): `retired_at` and `source_import_id` on `lesson_assets`,\n `course_assets`, `lesson_external_videos`; table `course_bundle_supersessions`.\n\n### Audience before and after attach\n\n`chooseMaterialAudience({ ...actor, importId, path | video: { lessonKey, videoId },\naudience })` (`education.course.author`, operation `choose-course-bundle-audience`)\nrecords a review choice (`course_bundle_audience_choices`, one per import and\ntarget; a later choice replaces it) within the role's bounds: keys and assessment\nguidance never become learner material (`invalid-audience`), and a path must be a\ndeclared v2 material of the import. `readImport` lists `audienceChoices`.\n`attachCourse` and `applyMaterials` apply them (a slides choice applies to the\nrendered pages; the original deck stays guardian). After attach a choice is\n`already-attached`: change the row with `SubmissionService.setMaterialAudience`.\nOn a re-attach an existing row keeps its audience (the family's choice), except an\noriginal, which is repaired to guardian.\n\n### Applying materials\n\n`applyMaterials({ ...actor, importId, bundle, courseId, lessons, assets })`\n(`education.course.author`, operation `apply-course-bundle-materials`) writes the\nrows in one transaction. The host has stored each accepted member as a private\nasset and created the course's lessons: `lessons` maps manifest lesson key to the\n`Lesson` id, `assets` maps member path to `{ original, rendered }` asset ids.\nSlides join both the original deck (`rendition: 'original'`) and the rendered PDF\n(`rendition: 'rendered'`, `renditionOfAssetId` the original); the original join is always\nguardian-only whatever the deck's declared audience (the audience applies to the\nrendered PDF; the model refuses a learner original), and a join written earlier with a\nwider audience is repaired on re-apply (`repaired`); any other Word/PowerPoint\nmember joins only its rendered PDF, so a learner is never handed an editable\noriginal. `assets[path].thumbnail` is recorded on the rendered join (or a plain\nfile's own join); rows written before this release get their rendition and\nthumbnail filled in on re-apply (`updated`). `LessonAsset`/`CourseAsset` saves keep their private-asset rule (guardian-\nonly roles and personal-use-copy courses need private assets). It targets\nfamily-owned courses; an authored course is `authored-course` because authored\nmaterial changes through course authoring. Idempotent: an identical row is\n`unchanged`, a row with other details (order, title, rendition, a video's title or\nstep) is `CourseBundleMaterialsError('conflict')`; audience is not compared (see\nabove). A missing asset or lesson is `asset-missing`/`lesson-missing`, a thumbnail\nunder another owner than its material `asset-owner`; any error writes nothing. A\nmember named twice (material and page range) is listed once in `skipped`.\n\n### Retrying a failed rendering\n\n`retryRendering({ ...actor, importId, bundle, paths?, receiveMember? })`\n(`education.course.author`, operation `retry-course-bundle-rendering`, needs a\nconverter) renders the Word/PowerPoint members whose first import recorded a\n*transient* failure (`converter_unavailable`, `converter_failed`,\n`converter_timeout`; `COURSE_BUNDLE_RETRYABLE_REASONS`). The first import's member\nrows are never rewritten. A success appends one `course_bundle_renderings` row\nper (import, content hash); every reader (`readImport`, replayed imports,\nproposals) overlays it, so the member reads `accepted` (identical copies as\nduplicates) with its rendered hash. A failure records nothing, so asking again is\nalways allowed; a second retry of a repaired member is `unchanged` and renders\nnothing. Converter rejections, size limits and the Office member cap are not\nretryable: change the bundle. The bundle must be the imported one.\n\n## Readers\n\n`BundleReader { formatId, detect, prepare }` in a `BundleReaderRegistry`;\nbuilt-ins are `manifest-v2`, `manifest-v1` and `plain-files`. SCORM and Common Cartridge are\n**not implemented** (their manifests describe launch resources and activity\ntrees that do not map to sections/lessons without design); a host can register\na reader ahead of the built-ins (`register(reader, { first: true })`).\n\n## Identity and replay\n\n`bundleIdentity` (`cbi1-...`) digests the sorted (path, sha256) pairs, so\nre-zipping, reordering and timestamps replay. One `CourseBundleImport` per\n(tenant, identity); a concurrent first import replays once on the unique index.\n\n## Models (closed, required tenant, no REST/CLI/MCP/AI, append-only)\n\n`CourseBundleImport` (`course_bundle_imports`: identity, format, reader,\nmanifest version, counts, actor), `CourseBundleMember` (`course_bundle_members`:\nunique tenant/import/path; ordinal, sha256, size, media type, kind, status,\nreason, duplicate-of, role, audience, section and lesson key) and\n`CourseBundleRendering` (`course_bundle_renderings`: a deliberate retry's success). Hashes and placements only:\nbytes stay with the host's ingestion receipts. Rewrites and deletes throw.\n`CourseBundleAttachment` (`course_bundle_attachments`) and the mutable\n`CourseBundleAudienceChoice` (`course_bundle_audience_choices`) and\n`CourseBundleSupersession` (`course_bundle_supersessions`, append-only audit of a\nnewer build taking a part) and\n`CourseBundlePlacement` (`course_bundle_placements`) and `CourseBundleUnit`\n(`course_bundle_units`) belong to the attach path. Normal manifest migrations create the tables and add `audience` (NULL\non older rows) and, on `lesson_assets`/`course_assets`, `rendition`,\n`rendition_of_asset_id` and `thumbnail_asset_id` (additive; older joins read as a\nfile as supplied with no thumbnail).\n\n## Not in this release\n\n- Material rows for authored courses: a proposal still carries lesson text only;\n authored course material goes through `CourseMaterialInput` and release. The\n family path is `attachCourse`; `proposeStructure` stays the authored-draft path.\n- Ingestion's receipt contract is unchanged: there is no `application/zip` part\n type or `parentEvidenceId` in ingestion. The education side unpacks and the\n host receives members one by one, so archive-to-member lineage lives in\n `course_bundle_members` (and the host's receipts), not in ingestion evidence.\n Changing ingestion's published receipt is a separate design decision.\n- A manifest/extraction disagreement is not compared automatically.\n- SCORM / Common Cartridge readers; zip64; nested archives; encrypted zips.\n"
|
|
16502
|
+
"content": "# Course bundle import\n\n`CourseBundleImportService` (SMRT #4578, extends `CourseAuthoringService`,\nconsumed by Hearth #94) imports a course bundle, a zip with an optional manifest\nor a plain file set, as bounded evidence, hands its supported members to the\nhost for ingestion extraction and proposes sections and lessons for review.\nRisk is high: untrusted archive parsing and new schema. It reuses the course\nauthorizer: `importBundle` needs `education.course.author`, `readImport`\n`education.course.read-draft`, `proposeStructure` `education.course.generate`\n(via `CourseGenerationReviewService`). Operations: `import-course-bundle`,\n`read-course-bundle`. Server only (Node `zlib`/`crypto`); no new dependency.\n\n## Flow\n\n1. `importBundle({ ...actor, bundle, limits?, onProgress?, receiveMember? })`\n authorizes **before parsing**, unpacks (stage `unpack`), classifies and lays\n out the structure (`classify`), writes the evidence in one transaction and\n then calls `receiveMember` for each accepted member (`extract`), outside any\n transaction. `bundle` is `{ archive: Uint8Array }` or `{ files: [{ path,\n bytes }] }`. Hostile or damaged input throws `CourseBundleRefusedError`\n (`reason`, optional `entry`) and writes nothing.\n2. `receiveMember(member, { replayed })` is the host's ingestion seam: call\n `IngestionService.receive` with `sourceKind: 'course_import'` and the member\n bytes, then queue extraction and `preserveQuestionExtractionAnalysis` as in\n [question extraction](question-extraction.md). Members carry `role`\n (manifest page role), `lessonKey`, `sectionKey`. It runs on a replay too\n (ingestion dedups by content hash), so an interrupted first run resumes. Its\n return values are in `result.receipts`.\n3. `proposeStructure({ ...actor, importId, bundle, courseId,\n expectedHeadRevisionId })` (stage `propose`) re-supplies the bundle (bytes\n are never retained), checks it is the imported one, and runs a deterministic\n `CourseMaterialGenerator` (`smrt-bundle-import`) through\n `requestGeneration`/`runGeneration`. The result is an ordinary proposal: a\n new draft revision of additions and fills; conflicts wait for\n `decideProposal`. Nothing is released, assigned or published. The request key\n is `bundle:<courseId>:<bundleIdentity>`, so a retry returns the same job; the\n same key with another head is `CourseRequestKeyConflictError`.\n4. `readImport({ ...actor, importId })` returns the recorded evidence.\n\nProgress is an observer callback (`onProgress({ stage, completed, total })`,\nstages `unpack`, `classify`, `render`, `extract`, `propose`; each starts at `completed: 0`;\n`render` is emitted only when the bundle has Word/PowerPoint members).\nIngestion has no public job-progress seam, so none is invented. A throwing\nlistener never affects the import.\n\n## Hard bounds (`COURSE_BUNDLE_LIMITS`; a host may only lower them)\n\n| limit | value |\n|---|---|\n| `maxArchiveBytes` (input) | 100 MiB |\n| `maxEntries` | 200 |\n| `maxEntryBytes` (inflated) | 50 MiB |\n| `maxTotalBytes` (inflated) | 200 MiB |\n| `maxCompressionRatio` (members over `ratioFloorBytes` = 64 KiB) | 100 |\n| `maxPathBytes` / `maxSegmentBytes` / `maxPathDepth` | 512 / 255 / 8 |\n| `maxManifestBytes` | 256 KiB |\n| `maxLessons` (the proposal schema's cap) | 50 |\n| `maxLessonBodyChars` | 100 000 |\n| `maxOfficeMembers` (Word/PowerPoint members rendered per bundle) | 50 |\n| `maxRenderedBytes` (PDF accepted back from the converter) | 50 MiB |\n| `conversionTimeoutMs` (one Office member) | 60 000 |\n| `maxThumbnailBytes` (first-page image accepted back from the converter) | 5 MiB |\n| archive nesting | 1: a zip inside a zip is never expanded |\n\nA lesson whose combined text members exceed `maxLessonBodyChars` refuses the\nbundle (`lesson_too_large`, `entry` = lesson key) at import; text is never\ntrimmed or dropped. A plain file set enforces `maxTotalBytes` on its member\nbytes exactly as an archive does on inflated bytes.\n\nThe reader (`course-bundle-zip.ts`) parses the end record and central directory,\nvalidates every offset and size against the real buffer, inflates with\n`maxOutputLength` equal to the declared size (declared sizes are never trusted:\na mismatch either way is `size_mismatch`), checks CRC32 and re-checks the total\non actual output. Stored and deflate only. Refusals (`CourseBundleRefusalReason`)\ncover: not a zip, truncated, ambiguous end record (two end records that both fit\nthe file, for example one forged in a comment), zip64, multi-disk, central\ndirectory not ending at the end record, entries out of range or overlapping,\nlocal header name/method mismatch, encrypted entries (flags 0/6/13, AES method),\nsymlink and special files (unix mode; DOS reparse flag), unsupported method,\nbad CRC, ratio, entry count, totals, duplicate names (case/NFC-insensitive,\nbackslashes normalised first) and bad paths (`..`, `.`, empty segments, absolute,\ndrive letter or `:` anywhere, NUL/control/bidi characters, lone surrogates,\ntoo long or deep). An **honestly** oversize member (declared over\n`maxEntryBytes`) is not inflated and is recorded `refused / entry_too_large`.\n\n## Members and statuses\n\nBy content (never by extension alone): `docx`/`pptx`/`xlsx` (see below), `pdf` (`%PDF-` in the first 1 KiB),\n`image` (PNG, JPEG, WebP), `text` (`.txt`/`.md`, strict UTF-8, no control\ncharacters, body-sized), `manifest` (root `manifest.json`), else `unsupported`.\nStatus: `accepted` (handed to extraction), `duplicate` (same sha256 as an earlier\nmember in canonical order; recorded once as evidence, `duplicateOfPath`, never\nextracted again), `unsupported` (`unsupported_type`, `nested_archive`,\n`unreadable_text`), `refused` (`encrypted_pdf`, `entry_too_large`), `metadata`\n(the manifest). Nothing is dropped. An encrypted PDF is any PDF with an\n`/Encrypt` token anywhere in its bytes (trailer, xref stream): a false positive\non literal text inside an uncompressed stream is refused, never read.\n\n## Word and PowerPoint members (SMRT #4615)\n\nA `.docx`/`.pptx`/`.xlsx` member is an OOXML package only when the name and the\ncontent agree: a zip whose entries include `[Content_Types].xml` and\n`word/document.xml` (docx), `ppt/presentation.xml` (pptx) or `xl/workbook.xml`\n(xlsx). A workbook (a supply list) is rendered and kept like the others but has\nno text reader. Before the bytes go anywhere, the\npackage itself passes the same bounded zip reader (ratio, overlap, paths, CRC,\n100 MiB inflated); a failure is `refused / unsafe_office`, never a refusal of the\nwhole bundle. Other zips stay `unsupported / nested_archive`.\n\nTwo separate things happen to an accepted Office member, both after\nauthorization and before the evidence is written:\n\n- **Pages**: a `DocumentConverter` (`document-converter.ts`) renders the original\n to PDF. The importer enforces the byte and time limits itself (input\n `maxEntryBytes`, output `maxRenderedBytes`, `conversionTimeoutMs` with an abort\n signal and a hard race, so an adapter that ignores the signal still times out),\n and rejects output that is not a PDF or is encrypted. The converter is told a\n neutral file name (`document.docx`), never the bundle path. Identical documents\n are rendered once.\n- **Text**: an injectable `OfficeTextReader` (best effort; a failure or a `null`\n costs the member nothing) returns whole-document text and, for decks, text and\n speaker notes per slide. Office text is handed to the host on the accepted\n member (`officeText`) and is **never** inlined into a proposed lesson body:\n teacher guides and notes carry answers, and audience belongs to manifest v2.\n\n`receiveMember` gets the original `bytes` (store them as the private original\nasset: \"Open in PowerPoint\" for decks) and `rendered` (`{ bytes, sha256, mediaType:\n'application/pdf', converterId }`, store as a private asset beside the original:\nthe pages for \"Present\"/reading). The member row records `renderedSha256` and\n`renderedSizeBytes`; bytes are still not retained here. A converter may also\nreturn a first-page image (`DocumentConversionResult.thumbnail`); the importer\nkeeps it only when it is a PNG/JPEG/WebP within `maxThumbnailBytes` and hands it\nover as `rendered.thumbnail` (`{ bytes, sha256, mediaType }`), else null. An\nunusable thumbnail never fails the member. Gotenberg draws none, so it is null.\n\n**Fail closed.** Any converter problem records that member `unsupported` with a\nreason and writes the rest of the bundle normally: `converter_unavailable` (none\nconfigured), `converter_failed` (unreachable or 5xx), `converter_timeout`,\n`converter_too_large`, `converter_rejected` (HTTP 4xx, not a PDF, encrypted),\n`office_limit` (beyond `maxOfficeMembers`, in natural path order). A member that\nfailed is not a lesson in the proposal, and identical copies of a failed document\nfail the same way rather than becoming duplicates of nothing. Outcomes are part\nof the append-only evidence, so a replay does not retry a recorded failure (to\nretry, change the bundle). A replay does re-render recorded-accepted members so the\nhost receives the bytes again; if it can no longer render one it throws\n`DocumentConversionError` rather than silently dropping an accepted member.\n\n### Host configuration\n\n```ts\nconst service = new CourseBundleImportService(db, authorizer, {\n converter: new GotenbergDocumentConverter({\n baseUrl: process.env.GOTENBERG_URL, // for example http://gotenberg:3000\n timeoutMs: 60_000,\n maxBytes: 50 * 1024 * 1024,\n }),\n officeTextReader, // optional, see below\n});\n```\n\n`GotenbergDocumentConverter` posts to `<baseUrl>/forms/libreoffice/convert`, talks\nto nothing else, refuses redirects and URLs with credentials, and caps the response\nas it streams. Run Gotenberg as an internal-only service with **no outbound\nnetwork**, its own size/time limits and no shared volume with the app; this\npackage assumes untrusted files never run next to the application. Tests use\n`FakeDocumentConverter` (records calls; `failWith`, `failWhen`, `delayMs`, `output`).\n\n`OfficeTextReader` reads Office text through the SDK without this package\ndepending on `@happyvertical/documents`: the host imports `extractOffice`\n(released in `@happyvertical/documents` 0.111.4, sdk#1486, Kreuzberg) and passes\nit to `createOfficeTextReader(extractOffice)`, which returns whole-document\ntext for Word and text plus speaker notes per slide for PowerPoint (images are\nnever requested). An absent engine reads as `null`; a corrupt file rejects and\nthe importer treats that as \"no text\". The repository's current `catalog:`\npin is 0.111.3, which predates the Office processors, so the host bumps the SDK\nset (and its minimum release age) before it can import `extractOffice`.\n\n## Manifest (`manifest.json`, version 1, closed)\n\n```json\n{ \"version\": 1, \"course\": { \"subject\": \"Math\" },\n \"sections\": [ { \"key\": \"unit-1\", \"title\": \"Unit One\",\n \"lessons\": [ { \"key\": \"sums\", \"title\": \"Sums\",\n \"members\": [ { \"path\": \"sheets/sums.pdf\", \"role\": \"exercise\" } ] } ] } ] }\n```\nEvery object is closed: an unknown key anywhere is `manifest_unknown_key` (with\nits path in `entry`); another version is `manifest_version`. Keys match\n`[A-Za-z0-9._:-]{1,120}` and are unique; roles are the extraction page roles\n(`exercise`, `example`, `instructions`, `cover`, `answer_key`, `mixed`,\n`unknown`); a listed path must exist and be listed once. The manifest is a source\nfact: roles are `source`, anything the extractor infers stays `inferred`, and a\nmanifest/extraction disagreement belongs in extraction review, not here. Without\na manifest each accepted member is one lesson, sections come from the top-level\ndirectory and order is natural path order (digit runs compare numerically, no\nlocale). Manifest order: the manifest, declared members, then the rest by path.\nLesson bodies are the readable text members of a lesson, joined; PDFs and images\nare never inlined. Members whose declared role is `answer_key` or `mixed` never\ncontribute text to a lesson body (they remain recorded evidence members); the\nproposal rationale only counts how many were withheld.\n\n## Manifest version 2 (SMRT #4615)\n\nA root `manifest.json` with `\"version\": 2` is laid out by the `manifest-v2`\nreader; version 1 keeps its own reader and page roles. The schema is closed in\nthe same way: an unknown key anywhere is `manifest_unknown_key` (with its path in\n`entry`), another version is `manifest_version`.\n\n```json\n{ \"version\": 2, \"course\": { \"subject\": \"Science\" },\n \"courseMembers\": [ { \"path\": \"unit/supplies.pdf\", \"role\": \"attachment\", \"title\": \"Supply list\" } ],\n \"sections\": [ { \"key\": \"unit\", \"title\": \"Unit\", \"lessons\": [ {\n \"key\": \"l1\", \"title\": \"Lesson 1\",\n \"members\": [ { \"path\": \"l1/log.docx\", \"role\": \"learner-pages\" },\n { \"path\": \"l1/deck.pptx\", \"role\": \"slides\" },\n { \"path\": \"l1/guidance.pdf\", \"role\": \"assessment-guidance\" } ],\n \"pages\": [ { \"member\": \"l1/log.docx\", \"from\": 1, \"to\": 4, \"label\": \"Mission log\" } ],\n \"videos\": [ { \"reference\": \"dQw4w9WgXcQ\", \"title\": \"Recap\", \"step\": 1 } ] } ] } ] }\n```\n\n- **Members** (lesson `members` and root `courseMembers`): `path` (must exist, listed\n once), `role` (required) one of `teacher-guide`, `slides`, `learner-pages`,\n `assessment`, `assessment-guidance`, `handout`, `printable`, `answer-key`,\n `attachment` (`manifest_role` otherwise; a video is a reference, never a file),\n optional `audience`, `title` and (lesson members only) `step`. The audience is the role default\n (`LESSON_ASSET_DEFAULT_AUDIENCE`) unless stated; `answer-key` and\n `assessment-guidance` are always guardian (a learner audience is\n `manifest_audience`). Members not listed stay recorded evidence with no role.\n- **Lesson steps** (SMRT #4656): a lesson member or video may declare\n `step: { key, order, label? }` (a closed object; `manifest_invalid` for a key over\n 32 characters or outside `A-Za-z0-9._:-`, a non-finite or non-number `order`\n (|order| up to 1,000,000), or an empty label; `manifest_unknown_key` for anything\n else, and a course member cannot carry one). Materials that share a `key` are\n one step; fractions order `1b` after `1`. A video's `step` is still accepted as a\n whole number (its rank); the object form also ranks it by `floor(order)`.\n- **Pages**: `{ member, from, to, label? }` ranges over a member of the same lesson\n (PDF, Word or PowerPoint; the rendered PDF for Office). Each page becomes a\n `LessonPage` keyed `p<n>`, labelled `<label> <n>` (default `Page <n>`), ordered by\n declaration. Bad, overlapping or unpageable ranges are `manifest_pages`; at most\n 500 pages per lesson.\n- **Videos**: `{ reference, title, step, audience? }` where `reference` is a bare id\n or an allowlisted https YouTube URL (`parseYouTubeReference`; anything else is\n `manifest_video`), `step` an integer 0-9999 or a lesson step object (see above). They become `LessonExternalVideo`\n rows; nothing is downloaded.\n- **Course members** become `CourseAsset` rows, not tied to any lesson.\n- **Unit and parts** (SMRT #4632): `course.key` (a manifest key) names the unit\n and `course.title` its course title; `part: { index, count }` (1-50) marks one\n bundle of a unit split across several, and requires `course.key`\n (`manifest_invalid` otherwise). Sections and lessons may carry a unit-wide\n `order` (0-9999); without one the position in this manifest is used, and\n the order counts as implicit when parts are merged.\n\nGuardian-audience text (teacher guides, guidance, keys) never enters a proposed\nlesson body; only learner-audience text members do. Under v2 `role` on the member\nevidence row is the material role and `audience` the effective audience (NULL on\nrows recorded before v2). The plan carries `materials` (also on\n`CourseBundleImportResult.materials`): the resolved materials, pages and videos,\nplus `skipped` for declared members that were unsupported, refused or failed\nrendering. A duplicate member resolves to the earlier identical member's bytes\n(`assetPath`) and one material per (place, role, content).\n\n`receiveMember` also gets `audience` and `courseLevel`, and an optional `title`\n(SMRT #4653): the manifest title of the one material the member holds (\"Teacher\nMission Manual\"), so a host can name the assets it stores. It is absent when the\nmanifest gave none or the member backs several materials with different titles.\n**Material titles**: `attachCourse` records that title on the `lesson_assets` /\n`course_assets` row (`title`; null on a lesson row without one, `''` on a course\nrow), the same for the original and rendered halves of a pair. Lesson and course\nmaterial views show the row title and fall back to the stored asset's name when\nthere is none. A re-attach fills a missing title; a different one is a\n`conflict` unless `supersede` restates it. **Lesson steps** (#4656): the declared\nstep is recorded on the `lesson_assets` row (`step_key`, `step_order`, `step_label`;\nboth halves of an original/rendered pair share it) and on `lesson_external_videos`\n(`step_key`, `step_position`, `step_label`; its existing integer `step_order` stays\nthe rank, `floor(order)` for an object step). All are additive nullable columns.\nA re-attach fills a row's missing step without a conflict; a different step is a\n`conflict` unless `supersede` restates it (replays are unchanged). Hosts read it\nwith `SubmissionService.listLessonSteps` ([lesson materials](lesson-materials.md)).\n**Slides** keep the original\ndeck (hand `bytes` to the host as a private asset: \"Open in PowerPoint\") and its\nrendered pages (`rendered`: \"Present\").\n\n### Attaching a family course (SMRT #4632)\n\n`attachCourse({ ...actor, importId, bundle, assets, courseId?, title?,\nlicenseKind? })` (`education.course.author`, operation `attach-course-bundle`) is\nthe published path from an import to a course: in one transaction it creates (or\nfinds) the family course, its sections and lessons, and writes the materials as\n`applyMaterials` does. `assets` maps member path to `{ original, rendered?,\nthumbnail? }` asset ids the host stored from `receiveMember`.\n\n- **Course**: a non-authored family draft (`sourceKey` `course-bundle`,\n `sourceRef` the unit key, `licenseKind` default `personal-use-copy`, title from\n the request, `course.title`, subject or first section). Ids derive from (family,\n unit key), sections and lessons from (course, key), so every part of a unit and\n every retry find the same rows. Lessons keep the manifest key in `externalRef`,\n `order` as `sortOrder` and, on creation, learner-audience text as `body` (after\n review choices). Nothing is released or published.\n- **Unit key**: `course.key`, else `bundle:<bundleIdentity>` (a one-part unit).\n- **Parts**: one `CourseBundleAttachment` per import (unique per import and per\n (course, part)). Attach parts in any order; the result says `part.attached` and\n `part.complete`. Fails closed and writes nothing: a `courseId` of another unit or\n another part count is `unit-mismatch`; a second import for an attached part is\n `part-conflict`. A replay is `replayed: true` and writes nothing new.\n- **Shared sections and lessons**: parts that share a key must agree, and the\n result never depends on arrival order. `CourseBundlePlacement`\n (`course_bundle_placements`) records each key's title and whether its order was\n declared. Another title, two different declared orders, or a declared order\n against an implicit one is `part-conflict` (nothing written). Between implicit\n positions the part with the lowest index decides; a lower part arriving later\n re-sorts the row. An existing row with no placement is `part-conflict`.\n- **Concurrency**: every attach transaction takes, in order, the import row lock\n (shared with `chooseMaterialAudience` and `applyMaterials`) and the unit lock: a\n `CourseBundleUnit` row (`course_bundle_units`, one per family and unit key)\n created if absent and then locked before anything that decides the outcome\n (attachments, the course, placements, choices) is read. On PostgreSQL a\n concurrent first create of the same unit waits and adopts the winner's row,\n so two first attaches can never both pass the checks.\n- **Zero renderings**: with no converter, Word/PowerPoint members are recorded\n `converter_unavailable` and listed in `skipped`; no rendered or original join,\n page or thumbnail is written for them, and nothing is faked. `retryRendering`\n later, then attach again: the replay adds the newly accepted materials.\n- `readImport` reports `attachment` (course, unit key, part) once attached.\n\n### Bringing a unit up to a newer build (SMRT #4645)\n\n`attachCourse({ ..., supersede: true })` is the explicit, opt-in way to replace\nthe build attached for a part. Without it nothing changes: another import for an\nattached part is `part-conflict`, and a placement whose title differs is\n`part-conflict`. It uses the same authorization (`education.course.author`),\ntenant rules and lock order (import row, then unit row) as any attach.\n\n- **Which build is newer**: manifests carry no build stamp, so \"newer\" is the\n import record: the importing bundle's `recordedAt` must be strictly later\n than the attached import's. Otherwise `stale-build` (an older or\n same-instant build never overwrites a newer one; re-attaching a superseded\n import is the same). `supersede` with no other build attached for the part is\n an ordinary attach.\n- **Identity**: sections and lessons keep their ids (derived from course id +\n key), so enrolments, progress and submissions stay attached. Titles and order\n follow the newer build (`renamed` counts changed titles); a key that a lower\n part decided still must agree (`part-conflict`). Lesson `body` is not\n rewritten. Sections and lessons the newer build no longer lists stay.\n- **Part count change** stays `unit-mismatch`, supersede or not.\n- **Materials**: the newer build's materials are attached; an existing row\n (same lesson, asset, role) is restated in place (order, title, current again; a\n renamed material shows its new title though it keeps its earlier asset),\n not a `conflict`; its audience stays the family's. Pages are restated and\n never retired (learner work points at page keys).\n- **Retirement**: file materials and external videos the replaced build wrote\n that the newer build does not carry get `retiredAt`. Rows are never deleted,\n so work that references them still resolves; learner and catalog material\n lists skip retired rows. `retired` counts them. Which rows belong to the\n replaced build: `sourceImportId` (new on `lesson_assets`, `course_assets`,\n `lesson_external_videos`, written by every attach/apply); rows from before it\n existed (null) are adopted when their lesson is one of the replaced import's\n lessons, and course materials when that import had course members. Rows\n from another part or source are never touched. A material that returns in a\n later build is current again.\n- **Audit**: the part's `CourseBundleAttachment` moves to the newer import (the\n one sanctioned attachment change, `supersedeWith`) and an append-only\n `CourseBundleSupersession` row (`course_bundle_supersessions`: course, unit\n key, part, new import, replaced import, actor, time) records which replaced\n which. The replaced import no longer reads as attached.\n- **Replay** of the same supersede is `replayed: true` and changes nothing.\n- Schema (additive): `retired_at` and `source_import_id` on `lesson_assets`,\n `course_assets`, `lesson_external_videos`; table `course_bundle_supersessions`.\n\n### Audience before and after attach\n\n`chooseMaterialAudience({ ...actor, importId, path | video: { lessonKey, videoId },\naudience })` (`education.course.author`, operation `choose-course-bundle-audience`)\nrecords a review choice (`course_bundle_audience_choices`, one per import and\ntarget; a later choice replaces it) within the role's bounds: keys and assessment\nguidance never become learner material (`invalid-audience`), and a path must be a\ndeclared v2 material of the import. `readImport` lists `audienceChoices`.\n`attachCourse` and `applyMaterials` apply them (a slides choice applies to the\nrendered pages; the original deck stays guardian). After attach a choice is\n`already-attached`: change the row with `SubmissionService.setMaterialAudience`.\nOn a re-attach an existing row keeps its audience (the family's choice), except an\noriginal, which is repaired to guardian.\n\n### Applying materials\n\n`applyMaterials({ ...actor, importId, bundle, courseId, lessons, assets })`\n(`education.course.author`, operation `apply-course-bundle-materials`) writes the\nrows in one transaction. The host has stored each accepted member as a private\nasset and created the course's lessons: `lessons` maps manifest lesson key to the\n`Lesson` id, `assets` maps member path to `{ original, rendered }` asset ids.\nSlides join both the original deck (`rendition: 'original'`) and the rendered PDF\n(`rendition: 'rendered'`, `renditionOfAssetId` the original); the original join is always\nguardian-only whatever the deck's declared audience (the audience applies to the\nrendered PDF; the model refuses a learner original), and a join written earlier with a\nwider audience is repaired on re-apply (`repaired`); any other Word/PowerPoint\nmember joins only its rendered PDF, so a learner is never handed an editable\noriginal. `assets[path].thumbnail` is recorded on the rendered join (or a plain\nfile's own join); rows written before this release get their rendition and\nthumbnail filled in on re-apply (`updated`). `LessonAsset`/`CourseAsset` saves keep their private-asset rule (guardian-\nonly roles and personal-use-copy courses need private assets). It targets\nfamily-owned courses; an authored course is `authored-course` because authored\nmaterial changes through course authoring. Idempotent: an identical row is\n`unchanged`, a row with other details (order, title, rendition, a video's title or\nstep) is `CourseBundleMaterialsError('conflict')`; audience is not compared (see\nabove). A missing asset or lesson is `asset-missing`/`lesson-missing`, a thumbnail\nunder another owner than its material `asset-owner`; any error writes nothing. A\nmember named twice (material and page range) is listed once in `skipped`.\n\n### Retrying a failed rendering\n\n`retryRendering({ ...actor, importId, bundle, paths?, receiveMember? })`\n(`education.course.author`, operation `retry-course-bundle-rendering`, needs a\nconverter) renders the Word/PowerPoint members whose first import recorded a\n*transient* failure (`converter_unavailable`, `converter_failed`,\n`converter_timeout`; `COURSE_BUNDLE_RETRYABLE_REASONS`). The first import's member\nrows are never rewritten. A success appends one `course_bundle_renderings` row\nper (import, content hash); every reader (`readImport`, replayed imports,\nproposals) overlays it, so the member reads `accepted` (identical copies as\nduplicates) with its rendered hash. A failure records nothing, so asking again is\nalways allowed; a second retry of a repaired member is `unchanged` and renders\nnothing. Converter rejections, size limits and the Office member cap are not\nretryable: change the bundle. The bundle must be the imported one.\n\n## Readers\n\n`BundleReader { formatId, detect, prepare }` in a `BundleReaderRegistry`;\nbuilt-ins are `manifest-v2`, `manifest-v1` and `plain-files`. SCORM and Common Cartridge are\n**not implemented** (their manifests describe launch resources and activity\ntrees that do not map to sections/lessons without design); a host can register\na reader ahead of the built-ins (`register(reader, { first: true })`).\n\n`plain-files` has no manifest to say what a file is for, so each member is a\nlearner-visible `attachment` on its own lesson (Office files as their rendering,\nPDFs and images as supplied; Markdown/text also becomes the lesson body). It\nnever guesses teacher-only files (smrt#4715).\n\n`attachCourse` gives the course, sections and lessons it creates the\ndeterministic slugs `bundle-course-<id>`, `bundle-section-<id>` and\n`bundle-lesson-<id>` (the id is the `bundleUuid`). Slugs are unique per tenant, so\ntitle-derived ones (\"files\", \"lesson-1\") collided on a tenant's second course\n(smrt#4716). Rows written earlier keep their slugs; replay finds rows by id.\n\n## Identity and replay\n\n`bundleIdentity` (`cbi1-...`) digests the sorted (path, sha256) pairs, so\nre-zipping, reordering and timestamps replay. One `CourseBundleImport` per\n(tenant, identity); a concurrent first import replays once on the unique index.\n\n## Models (closed, required tenant, no REST/CLI/MCP/AI, append-only)\n\n`CourseBundleImport` (`course_bundle_imports`: identity, format, reader,\nmanifest version, counts, actor), `CourseBundleMember` (`course_bundle_members`:\nunique tenant/import/path; ordinal, sha256, size, media type, kind, status,\nreason, duplicate-of, role, audience, section and lesson key) and\n`CourseBundleRendering` (`course_bundle_renderings`: a deliberate retry's success). Hashes and placements only:\nbytes stay with the host's ingestion receipts. Rewrites and deletes throw.\n`CourseBundleAttachment` (`course_bundle_attachments`) and the mutable\n`CourseBundleAudienceChoice` (`course_bundle_audience_choices`) and\n`CourseBundleSupersession` (`course_bundle_supersessions`, append-only audit of a\nnewer build taking a part) and\n`CourseBundlePlacement` (`course_bundle_placements`) and `CourseBundleUnit`\n(`course_bundle_units`) belong to the attach path. Normal manifest migrations create the tables and add `audience` (NULL\non older rows) and, on `lesson_assets`/`course_assets`, `rendition`,\n`rendition_of_asset_id` and `thumbnail_asset_id` (additive; older joins read as a\nfile as supplied with no thumbnail).\n\n## Not in this release\n\n- Material rows for authored courses: a proposal still carries lesson text only;\n authored course material goes through `CourseMaterialInput` and release. The\n family path is `attachCourse`; `proposeStructure` stays the authored-draft path.\n- Ingestion's receipt contract is unchanged: there is no `application/zip` part\n type or `parentEvidenceId` in ingestion. The education side unpacks and the\n host receives members one by one, so archive-to-member lineage lives in\n `course_bundle_members` (and the host's receipts), not in ingestion evidence.\n Changing ingestion's published receipt is a separate design decision.\n- A manifest/extraction disagreement is not compared automatically.\n- SCORM / Common Cartridge readers; zip64; nested archives; encrypted zips.\n"
|
|
16503
16503
|
},
|
|
16504
16504
|
{
|
|
16505
16505
|
"path": "agents/class-crunchlabs.md",
|
|
@@ -5,10 +5,10 @@ description: "Tenant-aware learning catalog models and authorized catalog access
|
|
|
5
5
|
status: "stable"
|
|
6
6
|
generated:
|
|
7
7
|
by: "smrt/scripts/generate-knowledge-okf.ts"
|
|
8
|
-
at: "2026-11-
|
|
8
|
+
at: "2026-11-10T17:41:00Z"
|
|
9
9
|
audience: "internal"
|
|
10
10
|
evidence_level: "source-inspected"
|
|
11
|
-
source_revision: "sha256:
|
|
11
|
+
source_revision: "sha256:a4abf71802a67ad12b69001f812f0b1caffd12bedc2e453c9c1adc7073c3ebca"
|
|
12
12
|
sources:
|
|
13
13
|
- id: "manifest"
|
|
14
14
|
resource: "https://github.com/happyvertical/smrt/blob/main/packages/education/package.json"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-education",
|
|
3
|
-
"version": "0.60.
|
|
3
|
+
"version": "0.60.17",
|
|
4
4
|
"smrtJsdoc": "strict",
|
|
5
5
|
"description": "Tenant-aware learning catalog models and authorized catalog access for SMRT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@happyvertical/smrt-assets": "0.60.
|
|
33
|
-
"@happyvertical/smrt-core": "0.60.
|
|
34
|
-
"@happyvertical/smrt-profiles": "0.60.
|
|
35
|
-
"@happyvertical/smrt-tenancy": "0.60.
|
|
36
|
-
"@happyvertical/smrt-users": "0.60.
|
|
37
|
-
"@happyvertical/files": "^0.
|
|
38
|
-
"@happyvertical/sql": "^0.
|
|
32
|
+
"@happyvertical/smrt-assets": "0.60.17",
|
|
33
|
+
"@happyvertical/smrt-core": "0.60.17",
|
|
34
|
+
"@happyvertical/smrt-profiles": "0.60.17",
|
|
35
|
+
"@happyvertical/smrt-tenancy": "0.60.17",
|
|
36
|
+
"@happyvertical/smrt-users": "0.60.17",
|
|
37
|
+
"@happyvertical/files": "^0.112.2",
|
|
38
|
+
"@happyvertical/sql": "^0.112.2",
|
|
39
39
|
"pdf-lib": "1.17.1",
|
|
40
|
-
"@happyvertical/smrt-ingestion": "0.60.
|
|
40
|
+
"@happyvertical/smrt-ingestion": "0.60.17"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@happyvertical/smrt-vitest": "0.60.
|
|
43
|
+
"@happyvertical/smrt-vitest": "0.60.17",
|
|
44
44
|
"@types/node": "24.13.6",
|
|
45
45
|
"typescript": "6.0.3",
|
|
46
46
|
"vite": "8.1.6",
|