Naalya Handbook

Lesson planning

Schemes of work, weekly lesson plans and records of work. Who can open them, how they get signed, and how Pip helps.

A teacher writes three kinds of document for each subject they teach in a stream. All three are Tiptap documents (JSON, see Templates), stored as content plus a server-rendered contentHtml, and edited live over the collaboration socket.

DocumentStatusesGets approved by
Scheme of workdraft, approvedThe signing chain, through revisions
Lesson plandraft, published, submitted, approved, returnedPublish only, or one department signer when the campus turns approval on
Record of workdraft, approvedThe signing chain, through revisions

Every route needs signed-in staff and Feature.LESSON_PLANNING. Most routes carry no @RequirePermissions: access is decided in the services, below.

Writing a scheme

Teach it. assertCanAuthor: the caller must teach that subject in that stream. There is no admin bypass on writes.

Check the year. The term gives the campus; the year must be unlocked and the term must belong to it. See year gates.

One per slot. A second scheme for the same subject, stream and term is a 409, as is a stream already covered by a scheme group. That is what main did before 6bfb9f6b. The rules on main now are at the end of this page.

Pick a start. Send templateId (a published scheme template, whose orientation is copied) or content, never both. Neither gives an empty document. The new scheme is draft.

Other scheme actions:

  • Duplicate copies a scheme to another stream the caller teaches, same subject and term. The target must be empty.
  • Group shares one scheme. Teachers are invited and accept or leave through scheme-groups. A group scheme has no stream, and can't be deleted directly: the last member leaving dissolves it.
  • Delete soft-deletes the scheme and every lesson plan under it, whoever wrote them, in one transaction. Shares go, an open revision is returned with the reason Scheme of work deleted, and the live documents close.

Lesson plans and records hang off the scheme

A lesson plan needs an approved scheme. Subject, stream, term, campus and year are copied from the scheme, never trusted from the client; a mismatched campusAcademicYearId is refused. The client sends only weekNumber, title, an optional plannedDate, and a template or content.

A record of work needs an approved scheme for that class. The week must fall inside the term, one record per week, and the title is the subject name plus the week.

Getting signed

Schemes and records go through revisions. A lesson plan is either published, or approved by one signer.

The signing chain. Slot 1 is always the subject's own department. Slots 2 onwards come from the campus set-up. Each slot is signed by a department head, or by a head or manager when the signer rule is heads_and_managers. Submitting checks every slot has someone who can sign. Signers work through slots in order, and a lock stops two people signing the same slot.

On the last signature the scheme or record becomes approved. Viewers then see the approved revision's content, not the live draft. Submitting snapshots the live document, even one open on another API copy.

Force approve (manage on scheme_of_work) skips the chain, but not for a document you wrote or can edit.

Lesson plans, by campus set-up:

ApprovalAuthor canSigner
Off (default)Publish and unpublishNone
OnSubmit from draft or returned. Publishing is refusedOne eligible signer of the subject's department approves or returns it

Signing set-up

GET and PUT /scheme-governance, per campus, need read and update on scheme_of_work.

FieldDefaultRule
Signer ruleheadsheads or heads_and_managers
Lesson-plan approvalOff
Extra slotsNonePositions 2, 3, 4 with no gaps; each a different department, from this campus or no campus

Who sees what

LessonPlanningAccessService places each caller on each document:

ReaderSees asStatuses
Teacher of the subject in that streamAuthorAll
Holder of an edit shareEditorAll
Holder of any other shareViewerAll
Class teacher of the streamViewerPublished or approved only
Holder of a scoped read (lesson_plan for plans, scheme_of_work for schemes and records)ViewerAll, including drafts
Anyone elseRefused: You do not have access to this document

A group document counts any accepted member stream. A department signer may open a lesson plan they are eligible to sign.

Lists (from API 52aac0dc6) take the caller's staff id, taught pairs and class-teacher streams from the cached permission context, and run their lookups together. Opening or changing one document still reads the tables. An empty match is an empty page, never an error. A drafts-only plan list leaves out the class-teacher branches; a record list shows class teachers approved rows only.

Audit rows store scalar fields and contentBytes only, never the document itself (lesson-planning.snapshots.ts). Copy that pattern for any new document-bearing resource.

Asking Pip

Pip is the in-document assistant at pip/documents/:type/:id, where type is scheme, plan or record. Staff only.

ActionWhoRefused when
See state (getPipDocumentState)Anyone who can open the documentcanAsk is false for viewers, a locked year, or a draft being prepared
Ask (createPipRequest)EditorsSame three, or Pip is busy on this document
Answer Pip's questionOnly the person who asked, while Pip waits
StopThe asker, or anyone who can edit
UndoEditors, unlocked year, within 30 minutesPip is still working on this, Nothing left to undo

One API copy owns each request; Stop and Undo reach it through Redis. Timings are on Several copies. The prefill worker runs up to 15 scheme and 15 lesson-plan drafts at once.

File search. Pip's searchFiles looks only in the lesson-planning folder for the document's term, subject and stream (or the group's streams), then keeps hits for weeks fileScopeFor allows. Records can't be searched. Rover's searchLessonFiles covers the teacher's own uploads plus every subject-stream they teach. Each hit is a file name, week, folder and at most 600 characters. No index, no school reference, or no hits gives No lesson files are indexed for this school yet.

When the document model answers with text and no tool call, that text is shown. It is cut to 120 characters (PIP_SAY_MAX_CHARS) and sent as say. The run then finishes with done and an empty summary. A blank reply sends done only. The unit test uses the line "All done, the weeks are filled." The test was read and not run. The screen was not opened. This client, in pip-document.agent.ts, still uses openai.apiKey and openai.model.

Scheme drafts

POST /schemes-of-work/:id/prefill queues a draft. The brief includes termWeekCount only when weeksIn is above 0. That count is the whole or part weeks from the term's first day to its last: the day span is rounded, one day is added, the result is divided by 7, and that is rounded up. A missing term counts as 0, so the field is left off.

The prompt may add week rows until the table reaches that length. Each added row has the same number of cells as the header. Topics stay in syllabus order and are spread across the weeks. When the topics run out, the last weeks are for revision and assessment of those topics. Planning cells are filled. Remarks, comments, reflection, signatures, and the other teacher columns stay blank. Planning cells stay empty only when the curriculum search returns nothing at all.

A document is not saved when more than half of the counted rows are empty. The check splits the HTML on each row start, skips the first two pieces, and treats a row as empty when at most one cell has text. There must be more than one counted row. The model is then told, once: "Most week rows in your draft are empty. Plan every week of the term from the material you found, fill every planning cell, and return the whole document again." A second empty result throws The draft came back with empty weeks. The loop runs for passes 0 to 6. If the extra pass falls outside that loop, the thrown text is The prefill kept searching without producing a draft.

The worker does not retry the job. It reports the message through readableFailure. A message that starts with a curly brace or a square bracket, or is longer than 160 characters, is stored as Something went wrong while drafting. Try again in a moment. The empty-weeks message is shorter than that, so it is stored as written. apply sets aiPrefillStatus to failed and keeps the text on aiPrefillError. It does not replace the document. Dismiss clears a failed row. The method comment says that takes the banner away. The screen was not opened, and no draft was run.

The draft client in scheme-prefill.agent.ts still uses openai.apiKey and openai.model. The same text is on main at b2fc729e7b793c7acda530dc6e3231acc15bf077, which merges staging da48a190. Those commits share one tree. A merge to main is not a running deploy.

Routes

Every path starts with /api/v1. A blank extra check means access is decided in the service.

On main: each teacher owns a scheme

API main 6bfb9f6bdb004fd3a909405c2c826cf1e383249b (merge of PR #677, 25 November 2026, 04:29 GMT) promotes PR #676. It shares tree c02ff4560f9a809a1a213073f5651c40eba7b25f with staging 0d611c966e84961c64e909ab50f424a0f2510b6f. Compare d229592a...6bfb9f6b is 78 files, 3177 additions and 901 deletions. Those files are the per-teacher scheme set. No calendar file and no OpenRouter file are in that compare. A merge to API main is not a running deploy. No host was checked and no request was sent. The tests in that compare were not run. Hub main 2dd88361a1c6ae1509fb913c66cc8a2a6eab340c (merge of PR #468, 25 November 2026, 05:00 GMT) shares tree e599c26b217549696c01a22eb6128a75e593979d with staging 413b5cfe122223ceae33640ef5671fd0bdd800c7 (PR #467). Compare 413b5cfe...2dd88361 changes no files, so the Hub screens from that compare are on Hub main. Compare 8db705ac...413b5cfe is 25 files, 837 additions and 357 deletions. A merge to Hub main is not a running deploy. No screen was opened.

The paragraphs above, apart from the group sentence and the invite operation id, stay true of main before this commit. On this tree:

  • A scheme is unique per school, subject, stream, term, and createdByStaffId, only where it is not deleted. The same teacher again is 409 with You already have a scheme of work for this subject, stream and term. A teacher who already co-writes a group for that slot is 409 with You already share a group scheme of work for this subject, stream and term.
  • A record of work adds the week and the same teacher to that unique key. The conflict is You already have a record of work for this week. Creating one needs that teacher's own approved scheme, or the request is A record of work needs your own approved scheme of work for this class.
  • A lesson plan follows the scheme owner. The caller is the author only when they created the scheme, or they are an accepted member of a group scheme, and they still teach that subject in the stream. Another teacher's write is This document belongs to another teacher.
  • A scheme group invites teachers. The new table is scheme_group_x_teacher, one row per group, teacher, and stream, with status invited or accepted. POST /scheme-groups/:groupId/invite is inviteSchemeGroupTeacher and takes staffId and streamId. Creating a group takes teachers, each a staff id and a stream id. Accepting soft-deletes that teacher's own scheme and its lesson plans, returns an open revision with Joined a scheme group, and removes the share grants. The notice and the email say the shared scheme replaces their own when that is so. Leaving still forks a private copy. The last accepted member dissolves the group.
  • Migration 1795563273548-per-teacher-schemes recreates the two unique indexes, creates the new table, and copies current subject teachers from scheme_group_x_stream. It does not drop that old table, and it does not run a pre-check. The plan file names a query for accepted group streams with no current teacher. That query was not run.
  • Pip and Rover file search use each writer's folder, a stream plus an owner code. A group search reaches accepted members only. Rover no longer searches every subject and stream the teacher teaches.
  • The approvers' weekly records desk is one row per teacher per class. A missing row is not_filed only when that teacher's own scheme is approved.
  • Rover adds list_scheme_group_candidates and invite_scheme_group_teacher. create_scheme_group takes teachers instead of stream ids. The collaboration socket and Pip pass the scheme creator into the same author check.
  • The main chat client is still OpenAI. maxRetries is 8. The comment says a rate-limited call waits four to eight minutes in all. That schedule was not measured. The slide reader in the same file sets no maxRetries.
  • On the scheme page at that Hub commit, the menu says Create scheme group until a group exists, then Invite teacher, and only while someone is left to invite. The dialog title is Create scheme group or Invite a teacher, and the description says "Tap a teacher to invite them to write this scheme with you. They join once they accept." One tap sends that teacher. The first tap creates the group. The success toast is the teacher's name plus "invited". A failure is Failed to invite teacher.
  • Accept opens Replace your scheme? when the invitation says the teacher's own scheme would be replaced. The text is "You already have a scheme for this class. If you join, it is replaced by the shared one." The buttons are Replace mine and Cancel.
  • The header lists the class, then the accepted teachers' names, then invited names followed by "invited". Leave group shows when the caller's access is author and they have an accepted membership. The dialog title is Leave scheme group? and the confirm button is Leave group. Success is Left the scheme group, with "You now have your own copy of the scheme and plans."
  • A shared scheme tile shows the sharer's avatar. Its hover card has Shared by.
  • The share picker no longer shows Suggestions while the box is empty. It searches 300 milliseconds after a name is typed, eight names at a time.
  • School settings add Question for staff on the Teams tab and the WhatsApp tab, kind ai_enquiry.created. The description is "Sent when Rover gets a question on WhatsApp or email that it cannot answer." That is the same kind the API sends on main 6bfb9f6b. The Hub row is on Hub main 2dd88361.
  • This Hub compare changes the generated create-group body from streamIds to teachers, and adds that alert kind. It does not add the calendar write operations. Those are already in the client from Hub PR #466, and this same tree includes them. The agenda view in this compare only keeps two columns from growing past their grid. The add-event screens are on PR #223. The generated route table elsewhere in this handbook is still the older snapshot. A note on that page says the operation on this tree is inviteSchemeGroupTeacher.

On main: accepting an invite can leave the other group

API main d0fbb4030a82d967dabf2924f2dd2bdf69de3af0 (merge of PR #684, 27 November 2026, 05:54 GMT) shares tree b5541dbd743bd310a98aa75ad70e34f6be00a3c2 with staging cbad7b4a604721243241066f96ac6f3368af5e45. That tree includes PR #680. Compare 6bfb9f6b...d0fbb403 changes scheme-group.service.ts. Hub main 4000c140ac169acb1d62cb9c0d723f8ad81b8542 (merge of PR #476, 27 November 2026, 07:51 GMT) shares tree 6588a7b8027560176c6edf029334cb9504bb0090 with staging 0836a1e4205f209be6b4c38d787d094a7ad2a2bb. Compare 2dd88361...4000c140 includes the invitation surface and the campus schemes list. A merge to main is not a running deploy. The tests in those compares were not run. No screen was opened.

  • An invitation now has leavesGroup. It is true when the teacher already co-writes a group for that subject, stream, and term. replacesOwnScheme is true when they have their own scheme for that slot, or they are the only accepted member of that group.
  • Accepting no longer stops because they already co-write that class. It deletes that accepted membership. If the delete changes nothing, the answer is 409 You are not a member of this group. If nobody accepted remains, the old group is dissolved with Joined another scheme group, and that scheme and its plans are retired. If others remain, the old group carries on and its scheme stays. Their own scheme is still closed when they have one.
  • The Hub dialog uses replacesOwnScheme first. That still opens Replace your scheme? with Replace mine and Cancel. When only leavesGroup is set, the title is Leave your group?, the text is "You already share a scheme for this class with other teachers. If you join, you leave that group.", and the buttons are Leave and join and Cancel. Success is Joined the scheme group. A failure is Failed to join the group.
  • On Create scheme group, when this scheme has no group yet and a pending invite matches its subject, term, and stream, the dialog says "You are already invited to" the invite's scheme title "for this class." Join accepts that invite.
  • The campus schemes list folds by subject. A closed subject shows up to four teacher photos, then +N. Open all and Close all show when there is more than one subject, and they change only the subjects on screen. A subject outside the current filter keeps the open or closed state it already had. A search, a filter, or a tile other than all opens the subjects on screen unless one was already stored closed. Three or fewer subjects do the same.
  • /staff-hub/campus/$campusId/schemes-of-work/records redirects to the schemes page. The file comment says records have no list page of their own.
  • Rover's list_scheme_group_invitations and respond_scheme_group_invitation now mention leavesGroup. The respond text says the other group carries on for the other teachers, or ends if they were the only one, and to say that before they confirm. The subject-teacher prompt and the scheme skill say the same.

Where to go next

On this page