@happyvertical/smrt-education 0.59.0 → 0.59.1
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/group-sharing.md +7 -0
- package/dist/chunks/workbook-photo-service-CjcB0y8Y.js.map +1 -1
- package/dist/group-sharing-contracts.d.ts +4 -0
- package/dist/group-sharing-contracts.d.ts.map +1 -1
- package/dist/group-sharing-reader.d.ts.map +1 -1
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1 -1
- package/dist/smrt-knowledge.json +5 -5
- package/package.json +8 -8
package/dist/manifest.json
CHANGED
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.59.
|
|
6
|
+
"packageVersion": "0.59.1",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
10
|
+
"manifest": "e12ad63483f8603eafb0bfc8b63a48ca972a1ebca33f24e2f6478fa6889060bc",
|
|
11
|
+
"packageJson": "474110dd446c3d295b233c04b548c4973553731487b1e51872b6e3e687a766f6",
|
|
12
12
|
"agents": "6f6c8fbb6bd5e2fa28c992987c889d7cc3b067566f1415863228908494a57ca3",
|
|
13
13
|
"moduleDoc:agents/lesson-materials.md": "f103812b0f5ebfda446747ae9e4d7a97254e22b12aebc2ec43a865c5bd56e56a",
|
|
14
14
|
"moduleDoc:agents/learner-service.md": "d7edf68000aec96b52920fb5e8dc4ff4e20b1d81b34413809e8212a885e1c3f9",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"moduleDoc:agents/family-intake.md": "540b6d37f438496acb0208b6ac7258264e2142bce3d2f986967b7741606fe4f7",
|
|
27
27
|
"moduleDoc:agents/catalog-previews.md": "5f4e0352274009b3ce00408017a16666036d24df695a7078c27317ba4e66f0a7",
|
|
28
28
|
"moduleDoc:agents/learner-plan.md": "b4691c3ec541be921ba8c550f5e080c8b351e736ba50c29cf3a2a8674c642af6",
|
|
29
|
-
"moduleDoc:agents/group-sharing.md": "
|
|
29
|
+
"moduleDoc:agents/group-sharing.md": "e669510ec47392b88315a84ffa34dd64020aeb799d7bcbf213f2f07ede02ea92",
|
|
30
30
|
"moduleDoc:agents/tutor-context.md": "7207a4051eeb77af0a161ae17caf724375d3d5e30d3bf52a4c06793cfc6c5507"
|
|
31
31
|
},
|
|
32
32
|
"exports": [
|
|
@@ -15723,7 +15723,7 @@
|
|
|
15723
15723
|
{
|
|
15724
15724
|
"path": "agents/group-sharing.md",
|
|
15725
15725
|
"module": "group-sharing",
|
|
15726
|
-
"content": "# Homeschool group sharing contract\n\nArchitecture and pre-implementation test design for [SMRT #4469](https://github.com/happyvertical/smrt/issues/4469), consumed by Hearth #41. This document defines the intended contract; it is not a claim that implementation or validation has passed. Risk is high: explicit cross-tenant authorization, private child media, concurrent consent mutation and new persistent schema.\n\n## Ownership and boundary\n\nA group has an independent users `Tenant`, created with `TenantService` in the caller transaction, and ordinary users memberships/roles/permissions for its supervisors. Family tenants remain independent; do not make them descendants of the group. A supervisor never receives family membership, an inherited family role, a guardian relationship, or a family resource grant. Profiles remain canonical identities. Users `Group` is tenant-local RBAC, not the homeschool relationship.\n\nEducation owns a per-child group relationship in the child's exact family tenant. Its identity is `(familyTenantId, learnerId, groupTenantId)`, allowing several children and several groups without copying work. All work, immutable attempts/revisions, source files, releases, marks and comments stay family-owned. Revoking participation or narrowing a policy changes access, never deletes learning history or attribution.\n\n`ResourceGrantService.checkResourceOperationPermission` first requires permission in the resource's tenant. It cannot authorize these family reads without broadening supervisor authority. Reuse users permission checks in the group tenant; do not use ResourceGrant as a cache of policy matches. `TenantService` seeds roles during initialization and does not itself wrap create+ownership in a transaction; initialize/provision under the service's executor and reject partial creation.\n\nThe only cross-tenant entry is an explicit `GroupSharingService` operation. A trusted host authorizer receives the exact active executor and verifies current stored session, user, group membership and operation permission. Education then validates the persisted group, exact family/child edge and current policy before using exact family-scoped collection reads. No user-supplied SQL, cross-family list, system context, `allowCrossTenant` escape, synthesized guardian authorization, or direct collection handle is exposed. A reviewed scope switch may select only the already validated exact family and restore the caller context; it never turns a family collection into an unscoped query.\n\nGroup roster discovery uses only `GroupLearnerRosterEntry` enumerated with exact group tenant and group ID predicates. Its opaque selectors route to each exact family-owned membership and current policy, which are independently checked before any learner name or work is projected. A roster row is not an access grant: stale, revoked, corrupt or mismatched edges are denied. Never discover group participants by an unscoped query over family-owned memberships, invitations or work. Acceptance writes the roster index in the same transaction as the family edge/policy and invitation status. Revocation can retain that index for stable opaque history; it must confer no continued access. Concurrent acceptance/retry creates one index row, and rollback leaves none.\n\n## Closed persistence\n\nAll models disable API, MCP, CLI and AI mutation/discovery surfaces. Exports/manifests/recipe registration must preserve that closure. Use qualified cross-package references to users/profiles and local foreign keys inside education. Models are root-importable for generated registration. Tenant predicates are explicit on every family lookup, including foreign-key validation. Do not silently upsert immutable identities.\n\n| Model | Ownership and minimum fields | Invariants |\n| --- | --- | --- |\n| `EducationGroup` | Group tenant; name, active flag, creator user/profile | One record per group tenant. No family data. Group creation and users owner membership commit together. |\n| `GroupLearnerInvitation` | Group tenant; group, opaque familyTenantId/learnerId selectors, exact invited parent user, creator, expiry, status, accepted edge ID, accepted policy digest | Status pending/accepted/revoked/declined; expiry required; immutable scope. Group staff creates a targeted invitation without reading or confirming family/learner data. Validate the exact family/learner only at parent acceptance. ID selects an invitation, never proves parent identity. |\n| `GroupLearnerMembership` | Family tenant; group, learner, consent parent, status active/revoked, policyVersion | Unique family/learner/group tuple. Revocation is durable. A fresh invitation is required to reactivate a revoked edge; old accepted invitation cannot reactivate it. No one-child-only uniqueness. |\n| `GroupLearnerRosterEntry` | Group tenant; groupId, familyTenantId, learnerId, membershipId | Unique group/membership tuple; immutable opaque scope index, populated atomically with acceptance. Stores no names, work or policy payload and confers no access. |\n| `GroupSharingPolicy` | Family tenant; membership, monotonically increasing version, schemaVersion=1, canonical policy JSON, parent actor/time | Immutable append-only snapshots; edge points at current version. Unique membership/version. Explicit policy at acceptance; no implicit share-all. |\n| `GroupRevisionComment` | Family tenant; edge, learner, activity, attempt, exact revision, author user/profile, body, createdAt, childVisible=false, visibility parent/time/version=0 | Stable author and revision binding; cannot grade, alter assessment/evidence or silently move to a newer revision. Only parent changes child visibility. Group departure retains row. |\n\nUse guarded JSON getters/setters and runtime validation for policy documents. Enforce tuple uniqueness with database schema constraints. Validate status/version on model writes and revalidate persisted values on service reads, failing closed on corrupt or unknown values. The public model decorator does not expose SQL CHECK constraints; do not broaden core or claim database CHECK enforcement for these fields. Use normal manifest migrations; never create schema at runtime. Invitation delivery/authentication is host-owned; group invitations do not mint identity sessions, and acceptance requires an independently authenticated current parent. Initial release may use exact known parent IDs; mailbox identity onboarding is not implied by an invitation ID.\n\n## Service API and policy\n\nAll requests carry authenticated `actorUserId`, actor session/context binding and explicit resource selectors; none of those are accepted as authority merely because they are present. Proposed public operations:\n\n- `createGroup`, `getGroup`: current group administration/reading through users permissions; provision atomically.\n- `inviteLearner`: current group invitation authority creates a group-owned invitation for an exact known parent and opaque preknown family/learner selectors; it does not read family data, prove those selectors exist or require the inviter to be a guardian. `revokeInvitation` requires current group invitation authority. `declineInvitation` requires the exact currently authenticated invited parent and makes a pending invitation terminal without revealing learner data. `acceptInvitation({ invitationId, policy })`: the exact named parent must currently be guardian of the selected child in the selected family; acceptance requires explicit valid policy. Accept locks the invitation and child/group edge, rechecks active group, parent authority and expiry, inserts edge/policy/group-owned roster index and marks accepted atomically. The parent need not be a group member or supervisor.\n- `setSharingPolicy({ membershipId, expectedVersion, policy })`, `revokeMembership`: current family guardian only. An accepted retry returns the same edge only when parent and original canonical policy digest match and current edge remains active; it never resets policy changed later. Wrong-parent retries fail. Changed acceptance payload conflicts. Expired, revoked or declined pending invitations fail. Accepted historical retry may return original result after expiry only while its current edge is active and parent remains authorized.\n- `previewSharing({ membershipId, policy? })`: current parent; evaluates saved or explicitly proposed policy using exactly the evaluator and projection used for supervisor reads. Proposed preview does not persist or grant access. Return per-item allowed facets and parent-facing reasons.\n- `listSharedWork`, `getSharedWork`, `getSharedRevision`, `readSharedMedia`, `getSharedProgress`: current group supervisor, exact active edge and current policy, with bounded pagination. Reauthorize each call and each selected resource; no reusable authorization result escapes the invocation.\n- `addRevisionComment`, `listRevisionComments`: supervisor comment write requires currently shared exact work/revision and group comment permission; parent reads retained family comments independently of group revocation. Child reads require own learner identity and the current saved parent comment-visibility policy; version-zero comments inherit that policy. `setCommentChildVisibility({ commentId, expectedVersion, visible })` is parent-only.\n\nPolicy v1 has explicit booleans `shareWork`, `shareMedia`, `shareFeedback`, `shareProgress`, `parentReviewedOnly`; `historyFrom` is a required valid UTC instant; `commentVisibility` is required and accepts only `parent-only` or `learner-visible`; the host presents `parent-only` as the initial default but the service requires an explicit saved choice. `subjects` and `courseIds` are explicit selector objects (`all` or nonempty `include` values). Unknown version/keys/enums, malformed or missing required fields fail closed. Empty include selects nothing or is rejected consistently; it never means all. An explicit all selector intentionally allows unknown metadata; any restriction requires matching authoritative metadata. Subject comes from the retained activity's authorized course metadata, not a browser label or inferred assessment text. Course metadata is resolved through the same authorized self/ancestor/global catalog scope for options, preview and supervisor reads, after validating the child's exact family-owned enrollment. Catalog scope conveys no family or guardian authority to a supervisor. Synthetic routing courses for unfiled captures are excluded from selector options; unfiled capture facts retain unknown course and subject even if a technical placeholder has a label or subject. Genuine enrolled courses remain selectable before any capture. An unfiled activity or missing course/subject does not match a restricted selector. Both restrictions intersect when present.\n\nOne pure evaluator takes normalized policy and verified work/revision facts. All public reads and preview call it. History is based on immutable attempt capture time, inclusive at the cutoff; reanalysis/re-filing does not make old work new. Each correction attempt is evaluated separately. `parentReviewedOnly` requires a valid guardian revision of the selected attempt; AI analysis, child release acknowledgement or merely having some other reviewed attempt is insufficient. Feedback is projected only when enabled and the exact selected revision satisfies the review gate; work and media DTOs never incidentally contain feedback, marks or hidden historical question text. Progress may be enabled independently of feedback/work payloads: derive it only from permitted attempts/revisions, never from the whole-family summary. Media is allowed only for an allowed work attempt and the explicit media flag. New matching work appears automatically through evaluation, without per-work grants or background grant materialization.\n\nSupervisor projections contain stable activity/attempt/submission/revision IDs and authorized data only. They expose no writable models, family settings, sibling counts, source storage URLs, answer keys, personal-use catalog assets or ingestion scratch. Work identity does not authorize all revisions. Default omitted revision selects a deterministic permitted current revision; explicit unavailable revision refuses, never silently falls back. Policy flags remain independent; test every combination where one facet could leak through another.\n\n### Fixed exported contracts for implementation\n\nPut shared types and validators in `src/group-sharing-contracts.ts`; models import them, while the pure evaluator imports types only. The following names are the consumer contract, not alternate spellings for workers to invent:\n\n```ts\ntype GroupSharingSelector =\n | { mode: 'all' }\n | { mode: 'include'; values: string[] };\ninterface GroupSharingPolicyV1 {\n schemaVersion: 1;\n shareWork: boolean;\n shareMedia: boolean;\n shareFeedback: boolean;\n shareProgress: boolean;\n parentReviewedOnly: boolean;\n commentVisibility: 'parent-only' | 'learner-visible';\n historyFrom: string;\n subjects: GroupSharingSelector;\n courseIds: GroupSharingSelector;\n}\ninterface GroupSharingActor {\n actorUserId: string;\n sessionId: string;\n}\ninterface GroupSharingScope extends GroupSharingActor {\n groupId: string;\n familyTenantId: string;\n learnerId: string;\n}\ninterface GroupSharedWorkSelector extends GroupSharingScope {\n activityId: string;\n attemptId: string;\n revisionId?: string;\n}\ninterface GroupSharingWorkFacts {\n capturedAt: string;\n courseId: string | null;\n subject: string | null;\n parentReviewed: boolean;\n}\ninterface GroupSharingDecision {\n eligible: boolean;\n work: boolean;\n media: boolean;\n feedback: boolean;\n progress: boolean;\n reasons: string[];\n}\n```\n\nExport `validateGroupSharingPolicy`, `evaluateGroupSharingPolicy(policy, facts)`, `GroupSharingAuthorizationError`, and `GroupSharingConflictError`. `GroupSharingWorkFacts` is populated only by the owning reader, never request JSON. Return names are `EducationGroupView`, `GroupLearnerInvitationView`, `GroupLearnerMembershipView`, `GroupSharedWorkView`, `GroupSharedRevisionView`, `GroupSharingPreview`, `GroupSharedProgressView`, and `GroupRevisionCommentView`. Views are immutable data DTOs, with no model instances or executor. Use `familyTenantId` in requests; family-owned models store that as their required `tenantId`. Invitation and roster-index ownership are the explicit exceptions: its `tenantId` is the group tenant and `familyTenantId` is a distinct opaque scope field. Invitation group staff DTOs disclose only submitted selectors/status, never dereferenced family names, existence or child data. `groupId` references EducationGroup, whose `tenantId` is the users group tenant. Do not confuse these two tenant selectors.\n\nEligibility means course/subject/history/review gates pass; facets intersect eligibility with their explicit flag. `media` additionally requires `shareWork`, so the first implementation exposes original media only with work enabled. Progress can remain enabled while work/feedback DTOs are disabled. Assessment-derived text, answers, scores, computed answer regions and annotated renditions count as feedback. With feedback disabled but work/media enabled, the authorized original child submission bytes remain accessible: marks physically present in those original bytes are intrinsic source content, not a hidden assessment projection. Hosts must make that parent choice clear. A hidden guardian-origin reference/cover or answer-key file is never promoted to an original child submission merely by this toggle.\n\nThe authorization callback is `GroupSharingAuthorizer(request)` where request carries actor, exact group/family/learner selectors as applicable, a discriminated action and `executor: DatabaseInterface`. Actions are `education.group.create`, `education.group.manage`, `education.group.read`, `education.group.invite`, `education.group.share`, `education.group.review`, `education.group.comment`, and `education.group.child-comments`. The host verifies live identity and its effective permissions/guardian terms; the service independently verifies persisted resource scope, current edge/policy and exact selectors. Callback success never bypasses those checks. The reader accepts this callback, never a boolean token, and exposes only read/projection methods. No generic `authorizeAsGuardian` or arbitrary collection callback belongs to this API.\n\n## Owning workbook/media seams\n\nCurrent `LessonWorkService` activity/timeline APIs require learner/guardian authority; replacing the authorizer with unconditional true would create a broad guardian backdoor. Add an explicit read-only owning projection seam with a required exact-resource authorization callback, invoked on its active executor before loading private data and again at final projection/delivery where appropriate. It must not expose mutation methods or accept an externally cached authorization boolean. This seam can live in a dedicated education sharing reader that uses owned collections with exact predicates; private workbook algorithms should be shared through an owning helper rather than copied or private-state access.\n\nThe selected attempt must belong to exact family/learner/activity/submission; selected revision must belong to that attempt. Original bytes must be owned through `SubmissionAsset`, match the retained source ID/hash and belong to the learner's private asset owner. Photo covers/reference-only receipts are not work. The ordinary `signSubmissionAsset` returns a signed URL after learner authorization; it is insufficient for this sharing contract. `readSharedMedia` must run current policy/role/session/edge checks for every HTTP delivery and open the exact `withPrivateAssetAccess` scope only within that request. Return bytes or execute a scoped streaming callback; never return public/presigned storage URLs or a long-lived capability. The host route must invoke it even for a replayed/direct URL and configure private storage/cache headers. No framework can revoke bytes already delivered; successful reads linearize at their final authority check. A revocation completed before a new request must always deny that request.\n\nShared progress recomputes from the permitted subset of current guardian evidence and never calls the full guardian summary then merely redacts its citations. With `shareProgress=true` and `shareFeedback=false`, its strict field allowlist is counts of shared completed work, distinct practice episodes, and assistance categories (independent/assisted/unknown) only. Completion here means a permitted work attempt exists as completed/captured work, never a correctness threshold or private Grade-derived completion decision. Do not expose correctness, points, possible points, scores, concept labels, question identities/text/answers, feedback or outcome-derived aggregates. No question-level evidence citations appear in this counts-only shape. This restriction must hold even for a single attempt, where an aggregate would reveal the entire withheld outcome. When feedback is also enabled, authorized descriptive concept evidence may additionally be projected with permitted citations and existing episode deduplication; it still cannot include hidden subject/history/sibling evidence.\n\nComments remain outside Grades, assessment revision bodies, scoring and progress evidence. Parent-only comments can be shown to their currently authorized author/supervisors and guardians; this means hidden from children by default, not anonymous. Parent can retrieve original author/time after revocation. Child comment access always checks the current saved policy: `parent-only` denies all child comment reads immediately, including previously visible comments; `learner-visible` permits default comments whose `visibilityVersion` is zero. A parent may additionally set an individual override: when `visibilityVersion > 0`, `childVisible` must be true as well as the saved policy being `learner-visible`. Thus a saved learner-visible choice needs no per-comment opt-in, an individual false override narrows it, and an individual true override can never broaden parent-only. Policy changes apply on the next read and never rewrite the original comment or its attribution.\n\n## Transaction and race semantics\n\nUse one active executor for current users/session checks, guardian relationship terms, group state, edge/policy and owned data. Authorization hooks must not capture the outer pool. Mutations run in the education transaction/composite queue with deterministic lock ordering (learner, group/edge, invitation/comment as applicable); acquire the learner lock in the same order as workbook capture/review. PostgreSQL must arbitrate with row locks or conditional writes plus unique keys; process-local locks alone are insufficient. SQLite serialization must not overlap statements on a single native handle. Failed nested operations poison/roll back the enclosing operation even if a callback catches an error.\n\nConcurrent identical acceptance converges to one active edge, one first policy, one group-owned roster entry and one accepted invitation result. Competing policies cannot both win; one conflicts. Concurrent policy updates using one expectedVersion produce one successor. Education-owned edge/policy/invitation mutations participate in the same lock/guard protocol: acceptance versus invitation revoke and comment writes versus edge revoke/policy narrowing are serialized, so the losing mutation cannot commit on stale education-owned state. External users sessions, roles/memberships and guardian-term writers do not participate in that protocol. Their authority linearizes at the final successful live authority read on the active executor, not at transaction commit. An operation authorized before a concurrent external revocation may finish; a new request starting after that revocation committed must deny. A same-executor callback or second read alone cannot close the final-check-to-commit window, and this contract does not claim otherwise. Do not use a transaction snapshot established before the request to satisfy a new request's current-authority check. Stronger commit-time exclusion would require an actual owning users/profiles writer protocol and is outside this contract. Media reads use final-check linearization; bytes already delivered cannot be recalled. Database, authorizer or asset failures propagate as failures, never authorize on fallback. Failed group creation, acceptance and policy append leave no partial tenant/owner/edge/policy/roster/acceptance state. No service starts containers.\n\n## Behavior-to-test matrix\n\nThis is the test-design-contract matrix. Every row requires recorded execution evidence before release. Common context abbreviations: P = independently authenticated current family guardian; S = authenticated group supervisor; C = own child; X = outsider, sibling or other-group actor. TX means the same exact executor for authorization and persistence. SQ/PG means in-process SQLite and PostgreSQL; Node is the supported server runtime. Browser is intentionally not an authorization runtime. Command S: `pnpm --filter @happyvertical/smrt-education exec vitest run src/__tests__/group-sharing-lifecycle.test.ts src/__tests__/group-sharing-adversarial.test.ts src/__tests__/group-sharing-reader.test.ts src/__tests__/group-sharing-comments.test.ts`; command P: `pnpm --filter @happyvertical/smrt-education test:postgres`; command M: `pnpm --filter @happyvertical/smrt-education exec vitest run src/__tests__/group-sharing-models.test.ts src/__tests__/group-sharing-manifest.test.ts`; command B: package `typecheck`, `build`, `verify:pack`. The shared behavioral harness must be imported by both SQLite and `group-sharing.optional.test.ts`; a skipped optional PG suite is not passing PG evidence.\n\n| ID / behavior | Reachable trigger | Positive | Negative / failure | Actor/context | Executor / transaction | Runtime / dialect | External edge | Level / command |\n| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n| G01 isolated group | createGroup | owner membership and group in distinct tenant | rollback after tenant insert; no family membership/parent hierarchy | P, X | TX provision atomic | Node SQ/PG | TenantService failure, unknown permission | integration S/P |\n| G02 closed persistence | generated registration/discovery | package imports models/recipe | no REST/CLI/MCP/AI CRUD advertised | untrusted caller | manifest, no DB needed | Node; schema SQ/PG | packed root exports | contract M/B |\n| G03 edge cardinality | invite/accept multiple edges | two children × two groups coexist | duplicate tuple or rebinding learner/family | P, X | TX unique constraints | Node SQ/PG | malformed IDs | integration S/P |\n| G04 invite targeting | inviteLearner/accept | group inviter creates without family lookup; exact parent accepts with current effective guardian terms; exact parent declines | other parent, expired relationship, wrong family/group/sibling, expired/revoked/declined invite | P/X | TX current session + relationships | Node SQ/PG | absent/expired session, authorizer throw | adversarial S/P |\n| G05 explicit policy | acceptInvitation | valid explicit v1 choice | omitted policy, unknown version/key, malformed date/selector/boolean | P | TX no partial writes | Node SQ/PG | untrusted JSON | service S/P |\n| G06 retry | accept same invite | same edge/policy/result, even after later policy narrowing | changed payload/parent; revoked edge never reactivated | P/X | TX immutable digest | Node SQ/PG | request replay | integration S/P |\n| G07 acceptance race | two accepts | identical requests converge | differing policy, revoke/expiry wins; injected failure rolls all back | P | independent root connections PG, serialized SQ; unique arbiter | Node SQ/PG | failure between edge/policy/roster/accepted writes; retry leaves one index row | concurrency S/P |\n| G08 policy version | setSharingPolicy | append version and preserve previous snapshots | stale expected version, supervisor write, invalid payload | P/S | TX compare-and-set | Node SQ/PG | concurrent updates, upstream auth failure | concurrency S/P |\n| G09 automatic evaluator | new capture/list | matching new work appears without grant creation | unknown restricted subject/course; course and subject mismatch | S/P preview | TX exact family queries | Node SQ/PG | unfiled/missing metadata | unit + service S/P |\n| G10 history/review | get work/revision | inclusive cutoff and reviewed exact attempt | old attempt reanalysis, other attempt's review, provisional-only revision, malformed ancestry | S | TX immutable facts | Node SQ/PG | future/invalid dates, stale revision ID | unit + adversarial S/P |\n| G11 facet independence | every public DTO | explicit work/media/feedback/progress combinations | disabled feedback leaks through marks/status/comment or progress; disabled media via anchors | S | TX projection | Node SQ/PG | omitted optional payload fields | table-driven S/P |\n| G12 preview parity | preview and subsequent reads | identical allowed IDs/facets under same saved/proposed policy | unauthorized preview; proposal creates grant/write | P/S | same evaluator/TX | Node SQ/PG | policy parse failure | contract S/P |\n| G13 current authority | list/detail/revision/media/comment/summary | active S exact group+edge | stale session, removed role, inactive membership/group, wrong active context, sibling/group edge | S/X | current TX reads, cache:false | Node SQ/PG | every public service path | adversarial parameterized S/P |\n| G14 narrowing/revoke | reuse IDs/direct route after change | parent retains originals/history | previously allowed S denied after policy/edge/group/role/session revoke | P/S | TX; final check | Node SQ/PG | stale URL and request replay | service + host contract S/P |\n| G15 exact source ownership | readSharedMedia | exact SubmissionAsset retained hash and private owner | foreign asset/submission/revision, source cover, answer key, tampered hash, public URL | S/X | TX + exact private scope | Node SQ/PG | storage missing/failure; no leaked locator | integration S/P |\n| G16 immutable work IDs | list/get/correction/reanalysis | stable attempt/revision IDs and source citation | foreign revision, selector fallback, reanalysis counted as new practice | S | TX read-only | Node SQ/PG | workbook reader seam | integration S/P |\n| G17 scoped progress | getSharedProgress | counts-only allowlist without feedback; descriptive evidence with feedback; episodes deduped | single-attempt or multi-attempt withheld correctness/score/concept/question leakage; hidden evidence contributes counts | S | TX filtered evidence before aggregate | Node SQ/PG | nullable scores/unknown assistance | integration S/P |\n| G18 comment author/binding | add/list comments | exact visible revision, stored current author | forged author, hidden/foreign revision, supervisor grade/evidence mutation | S/P | TX immutable bind | Node SQ/PG | malformed/empty/oversize text | adversarial S/P |\n| G19 comment visibility | set visibility/child list | saved learner-visible exposes version-zero defaults; explicit false narrows; parent-only immediately hides all | missing/unknown policy field, default parent-only C read, sibling, supervisor visibility update, stale version | P/C/S/X | TX guarded visibility version | Node SQ/PG | visibilityVersion=0 inherits; >0 requires childVisible plus saved learner-visible | integration S/P |\n| G20 retained family records | revoke then family read | originals, revisions, comments/attribution remain | supervisor retains old access; cascade removes learning rows | P/S | TX family authority independent of group | Node SQ/PG | no byte cleanup on revoke | integration S/P |\n| G21 transaction affinity | host hooks in operation | all callbacks observe exact TX including nested reads | outer-pool hook usage, swallowed failure commits, closed service reuse | P/S | instrument executor; rollback injection | Node SQ/PG | callback failure | integration S/P |\n| G22 interleaving authorization | comment/media vs revoke/narrow | own edge/invite/policy mutations serialize; pre-external-revoke authorized operation may finish | stale own-edge check commits after winning revoke; new post-commit session/role/guardian-revoke request succeeds | P/S | independent PG transactions/barriers; SQ serial equivalent | Node SQ/PG | deterministic barriers for own-edge race and external final-check/new-request semantics | race S/P |\n| G23 migration compatibility | manifest upgrade + normal schema apply | six closed models migrate on empty/existing DB; old workbook history unchanged | missing schema fails without runtime DDL; duplicate edge/roster tuple blocked; corrupt status/version read denied | deploy | explicit migration TX | Node SQ/PG | native UUID FKs, migration failure | schema U/P/B |\n| G24 recipe/plugin contract | recipe discovery and packed import | group recipe registered, service/types usable | generated CRUD exposed or missing root symbol | host | N/A: static registration, no persistence | Node | downstream manifest/recipe consumer | contract M/B |\n| G25 bounded query scope | list pagination/direct service | exact group-owned roster enumeration then each exact family edge/policy check; bounded results/stable cursors | forged/stale roster grants access; caller limit hides deny; cursor reveals foreign work; raw cross-family edge query | S/X | TX group index read then exact family predicates | Node SQ/PG | invalid cursor/limit | adversarial S/P |\n| G26 staff group discovery | listMyGroups after login | own active groups; inactive group only for current manager | other user/session, removed membership, inactive nonmanager group | S/X with original session context | TX users own-membership enumeration then exact group scope | Node SQ/PG | unknown group tenant and authorizer error | integration S/P |\n| G27 family/child navigation | listLearnerMemberships access guardian/child | parent retained summaries; own child active group names | sibling, wrong actor, child guardian-policy/history escalation; revoked/disabled child edge | P/C/X | TX exact family/learner, current own-user proof | Node SQ/PG | invalid access selector | adversarial S/P |\n| G28 invitation preview/list | getInvitation/listInvitations | named guardian preview without group membership; staff opaque selectors | wrong invitee, missing guardian proof, staff family dereference | P/S/X | TX exact group invite; parent exact family proof | Node SQ/PG | parent/staff explicit access discriminator | integration S/P |\n| G29 retained policy history | getSharingPolicyHistory after leave | immutable versions/actors/time and scoped numeric pagination | supervisor/child read, malformed cursor/limit, foreign edge | P/S/C/X | TX exact family edge, guardian before/after | Node SQ/PG | unknown stored policy or version fails closed | integration S/P |\n| G30 opaque revision binding | feedback withheld; new revision before comment | work exposes immutable comment ID; comment remains on opened revision | foreign/provisional assessment under selected-review gate, hidden assessment payload | S | TX exact attempt/revision and current policy | Node SQ/PG | opaque comment selector independent of feedback | reader/comments S/P |\n\n| G31 pre-consent policy options | getSharingPolicyOptions exact family/learner before invite acceptance | current guardian receives labeled learner course/subject options without a group edge | child/supervisor/outsider, wrong family/learner, stale guardian/session, private answer/catalog data | P/S/C/X | TX exact family/learner guardian before/after; no policy mutation | Node SQ/PG | groupId omitted; current scoped metadata only | reader S/P |\n| G32 metadata/private capability isolation | ordinary member group home vs roster/work | education.group.read permits group metadata/discovery only; education.group.review permits authorized private scope | metadata-only member roster/work/revision/media/progress, role/action escalation | current stored ordinary member/S | TX role/session/group plus exact edge/policy before/after | Node SQ/PG | guardian review remains separate exact guardian proof | adversarial S/P |\n\n## Implementation ownership partitions\n\nCoordinate these partitions before editing; integrations are serial, not concurrent edits to the same file.\n\n1. Persistence/contracts worker: `src/group-sharing-models.ts`, `src/group-sharing-contracts.ts`, `src/__tests__/group-sharing-models.test.ts`. Own validation/types/closed models and unique schema; freeze exported interfaces first.\n2. Lifecycle worker: `src/group-sharing-service.ts`, `src/group-sharing-authorization.ts`, `src/__tests__/group-sharing-lifecycle-workflows.ts`. Own group/invitation/edge/policy state machine, shared transaction and current-authority boundary. Do not implement a second workbook reader.\n3. Read/projection worker: `src/group-sharing-reader.ts`, `src/group-sharing-policy.ts`, `src/__tests__/group-sharing-read-workflows.ts`. Own same evaluator for preview/reads, exact work/media projection and scoped summary. Any changes needed to `src/workbook-service.ts` or `src/submission-service.ts` belong exclusively to this worker after parent approves the owning seam. Do not widen LearnerAuthorizer.\n4. Integration owner: `src/group-sharing-comments.ts`, shared test runner `src/__tests__/group-sharing-workflows.ts`, SQLite/PG entrypoints, `src/index.ts`, `src/recipes.ts`, recipe help, package docs/AGENTS and generated artifacts. Integrate comment API after lifecycle/read interfaces stabilize, run full validation/review once. Could delegate comments as a separate non-overlapping worker after contracts freeze.\n5. Architecture owner: this document only. Record executable evidence/results through the parent session; proposed matrix rows do not substitute for executed tests.\n\n## Upstream/host contract gaps to resolve before release\n\n- Existing workbook guardian projections and signed asset API are not a sharing boundary. The new owning read seam and host authenticated media route are mandatory, not optional integration notes.\n- Host current-session/group permission and current guardian-term verification must use the provided transaction executor. No external app is permitted to supply an always-allow callback or stale role snapshot. Document exact action names/role seed in implementation.\n- Course.subject is a mutable string; define whether policy uses current authoritative metadata (recommended for immediate narrowing) or immutable metadata snapshots. This design uses current authoritative course metadata and immutable capture time. Missing/re-filed metadata is reevaluated each read.\n- PostgreSQL concurrent tests need independent connections and deterministic barriers. One connection or in-process mutex does not establish multi-process acceptance/revocation safety. Integration owner supplies the isolated existing test service; workers do not provision containers.\n- Public consumer contract must record the published SMRT version, exported types/actions, migration/recipe activation and media route obligations. Hearth consumes that release only; no local tarball or host shim.\n\n## Host integration and migrations\n\nThe public `GroupSharingService(db, authorize, options?)` facade owns lifecycle,\nreader and comment operations. Internal reader/comment classes are not root\nexports: their borrowed-executor flags are owning implementation details.\n`options` uses the normal `SubmissionServiceOptions` private storage adapter.\nThe facade supports atomic `withTransaction` composition; any failed queued\noperation poisons the complete transaction, and escaped services reject reuse.\n\n`updateGroup` changes the bounded display name or active flag under live\n`education.group.manage` authority. Management can reactivate an inactive group;\nnormal read, invitation and supervisor operations cannot use an inactive group.\nDisabling does not delete family rows. `removeLearner` is group-management\nrevocation, `leaveGroup`/`revokeMembership` are guardian revocation.\n`listMemberships` enumerates only the active group's roster index and rechecks\neach authoritative family edge under `education.group.review`. `getGroup` and\nactive `listMyGroups` use `education.group.read` for group metadata only; that\ncapability never authorizes child roster or shared work, revisions, media or\nprogress. Those private supervisor operations require `education.group.review`\nand the current exact family edge/policy. Hosts may grant ordinary members group\nmetadata reading without any private learner access. `listLearnerMemberships` is exact-family guardian\naccess. Neither method offers arbitrary cross-family education discovery.\n\nShared work includes an opaque `commentRevisionId` even when assessment feedback\nis withheld. Bind the comment form to that exact viewed revision and submit it\nunchanged; never resolve the latest assessment again when saving a comment.\nThe identifier grants no assessment access. Feedback and child comment visibility\nstill pass their independent current policy checks on every read.\n\nActivate `education.supervisor` through the host cookbook, rebuild registration\nand apply the host's normal manifest migrations before serving group routes.\nThe six additive tables use generated native UUID references and unique keys.\nDo not alter existing workbook rows or remove family data when a group leaves.\nA missing table is a migration error, never permission to create schema during\na request. Test schema generation uses the same structured manifest on SQLite\nand PostgreSQL; deployments retain their normal migration backup/rollback policy.\n\nHosts refresh the stored session and effective group permissions/guardian terms\non the callback's exact executor. Action strings above are capability names,\nnot a promise that any ordinary users role receives them automatically. Seed\nonly the desired group supervisor/admin roles and never grant family guardian\npermissions. Invitation delivery is host-owned; an invitation identifier alone\nis not a bearer credential. Parents can use only existing currently authorized\nlearners named by the immutable invitation.\n\nServe original bytes through `readSharedMedia` on every authenticated HTTP\nrequest, including direct bookmarks. The result carries `private, no-store`;\nhosts must also set safe MIME/disposition, sandbox CSP and `nosniff`, and never\ncache responses in a service worker or expose underlying asset paths. Uploaded\noriginals can contain marks physically present on paper even when generated\nassessment feedback sharing is disabled.\n\nHost navigation uses `listMyGroups(actor)` for the actor's current users memberships\nand `listLearnerMemberships({ ..., access: 'child' })` for an authenticated child's\nown active group edges. Child navigation uses `education.group.child-comments`\nand never grants guardian access to consent or policy history. Group discovery\nkeeps the original authenticated session context and derives exact group scopes\nfrom stored memberships; inactive groups require current management authority.\nStaff role assignment/removal uses the existing public users collections under\nhost authorization on the same executor. Education sharing never substitutes\nfor those users permission checks or gives staff family authority.\n\n`getSharingPolicyOptions({ actorUserId, sessionId, familyTenantId, learnerId })`\nreturns current course labels/subjects for a currently authorized guardian before\nconsent, without requiring a group or accepted invitation. It uses the same\nactive executor and exact learner ownership checks; it creates no grants or\npolicy history. Host guardian decisions must validate the supplied exact current\nrelationships/terms separately from a group's `education.group.review` role.\n\n## Trusted workspace-kind metadata\n\n`isGroupTenant(db, tenantId): Promise<boolean>` is a trusted host-only metadata\nlookup for an exact server-selected resource tenant. It uses the supplied current\nexecutor, verifies that the Tenant exists freshly, and checks the owning\n`education_groups` table for that exact tenant. Blank, malformed, missing or\nambiguous scope fails closed. The result is independent of group activation,\nTenant status, memberships and staff roles: disabling a group or removing a staff\nmembership never turns it into a family. The result contains no name, roster,\npermission or grant and creates no session or tenant context. It has no generated\nREST, MCP or CLI surface.\n\nOn PostgreSQL, the exact bounded group count and `row_security_active` check\nshare one statement on the caller's executor. One visible row establishes group\nkind; an ambiguous result fails closed. Zero rows establishes family kind only\nwhen PostgreSQL reports row security inactive for that relation and caller.\nUnder active RLS, zero rows is indeterminate and throws `Tenant kind is unavailable`,\nincluding for an actual family tenant. The host needs an already trusted metadata\nexecutor with provable unrestricted visibility to classify families. Policy-level\nbypass settings alone do not prove that visibility. The helper never changes\nroles, permissions, session settings or tenant context to obtain visibility.\n\nThis result is not authorization. Hosts must separately require a freshly ACTIVE\nTenant plus current signed-session, background-job or independent-proof authority\non the same relevant executor. Never pass a browser-selected tenant as authority,\ninterpret a missing Tenant as family, or use absence of group membership to infer\nfamily kind. The helper provides no arbitrary cross-tenant directory.\n\n| Behavior/invariant | Trigger | Positive | Negative/failure | Actor/context | Executor/transaction | Runtime/dialect | External edge | Level | Command |\n| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n| G33 workspace kind | trusted exact resource lookup | existing family false; active/inactive group true | blank/malformed/absent tenant; ambiguous group rows; PostgreSQL RLS-hidden or indeterminate zero refuses family; database failures propagate | host-selected exact tenant, no synthetic session/context | caller-supplied executor, fresh reads; no writes | Node SQLite/PostgreSQL | status/membership/role absence never implies family or grants | integration | `pnpm --filter @happyvertical/smrt-education exec vitest run src/__tests__/group-sharing-workspace.test.ts` (same file with TEST_DB_ADAPTER=postgres and isolated DATABASE_URL) |\n\n## Authored course visibility\n\nAuthored-course `visibility` (see [course authoring](course-authoring-service.md))\nonly ever narrows group sharing; it never adds a reader, a tenant or a facet.\n\nBefore: every authored release that was not personal-use was eligible (policy\noptions, `listSharedWork`, preview) subject to the policy, edge and review rules.\nAfter: the same, except an authored release whose identity is explicitly recorded\nas `family` (including any unrecognized stored value) is `course-private`: it is\nabsent from the policy options and its work evaluates `course-private`, also when\nonly another release of that course is in the enrollment's pin lineage.\n`groups` and `public` change nothing relative to before. A course whose visibility\nwas never recorded (everything authored before visibility existed) also behaves as\nbefore, so existing contracts and tests are unchanged; hosts that want a default\nof \"family only\" call `setVisibility('family')` explicitly. `public` is a listing\nlabel only; no reviewed cross-tenant read path exists for it, so it grants nothing.\nNon-authored courses, answer keys and personal-use rules are untouched, and a\ndatabase without the visibility column or release tables reads as never recorded.\nThe gate is `authoredVisibilityPermitsGroups(db, tenantId, releaseCourseId)`.\n\nFiled loose work is attributed to its current filing placement (target lesson,\nenrollment and course, hence subject) under the same consent, offered-metadata and\npin-lineage rules as routed work; unplaced loose work stays unknown metadata.\n"
|
|
15726
|
+
"content": "# Homeschool group sharing contract\n\nArchitecture and pre-implementation test design for [SMRT #4469](https://github.com/happyvertical/smrt/issues/4469), consumed by Hearth #41. This document defines the intended contract; it is not a claim that implementation or validation has passed. Risk is high: explicit cross-tenant authorization, private child media, concurrent consent mutation and new persistent schema.\n\n## Ownership and boundary\n\nA group has an independent users `Tenant`, created with `TenantService` in the caller transaction, and ordinary users memberships/roles/permissions for its supervisors. Family tenants remain independent; do not make them descendants of the group. A supervisor never receives family membership, an inherited family role, a guardian relationship, or a family resource grant. Profiles remain canonical identities. Users `Group` is tenant-local RBAC, not the homeschool relationship.\n\nEducation owns a per-child group relationship in the child's exact family tenant. Its identity is `(familyTenantId, learnerId, groupTenantId)`, allowing several children and several groups without copying work. All work, immutable attempts/revisions, source files, releases, marks and comments stay family-owned. Revoking participation or narrowing a policy changes access, never deletes learning history or attribution.\n\n`ResourceGrantService.checkResourceOperationPermission` first requires permission in the resource's tenant. It cannot authorize these family reads without broadening supervisor authority. Reuse users permission checks in the group tenant; do not use ResourceGrant as a cache of policy matches. `TenantService` seeds roles during initialization and does not itself wrap create+ownership in a transaction; initialize/provision under the service's executor and reject partial creation.\n\nThe only cross-tenant entry is an explicit `GroupSharingService` operation. A trusted host authorizer receives the exact active executor and verifies current stored session, user, group membership and operation permission. Education then validates the persisted group, exact family/child edge and current policy before using exact family-scoped collection reads. No user-supplied SQL, cross-family list, system context, `allowCrossTenant` escape, synthesized guardian authorization, or direct collection handle is exposed. A reviewed scope switch may select only the already validated exact family and restore the caller context; it never turns a family collection into an unscoped query.\n\nGroup roster discovery uses only `GroupLearnerRosterEntry` enumerated with exact group tenant and group ID predicates. Its opaque selectors route to each exact family-owned membership and current policy, which are independently checked before any learner name or work is projected. A roster row is not an access grant: stale, revoked, corrupt or mismatched edges are denied. Never discover group participants by an unscoped query over family-owned memberships, invitations or work. Acceptance writes the roster index in the same transaction as the family edge/policy and invitation status. Revocation can retain that index for stable opaque history; it must confer no continued access. Concurrent acceptance/retry creates one index row, and rollback leaves none.\n\n## Closed persistence\n\nAll models disable API, MCP, CLI and AI mutation/discovery surfaces. Exports/manifests/recipe registration must preserve that closure. Use qualified cross-package references to users/profiles and local foreign keys inside education. Models are root-importable for generated registration. Tenant predicates are explicit on every family lookup, including foreign-key validation. Do not silently upsert immutable identities.\n\n| Model | Ownership and minimum fields | Invariants |\n| --- | --- | --- |\n| `EducationGroup` | Group tenant; name, active flag, creator user/profile | One record per group tenant. No family data. Group creation and users owner membership commit together. |\n| `GroupLearnerInvitation` | Group tenant; group, opaque familyTenantId/learnerId selectors, exact invited parent user, creator, expiry, status, accepted edge ID, accepted policy digest | Status pending/accepted/revoked/declined; expiry required; immutable scope. Group staff creates a targeted invitation without reading or confirming family/learner data. Validate the exact family/learner only at parent acceptance. ID selects an invitation, never proves parent identity. |\n| `GroupLearnerMembership` | Family tenant; group, learner, consent parent, status active/revoked, policyVersion | Unique family/learner/group tuple. Revocation is durable. A fresh invitation is required to reactivate a revoked edge; old accepted invitation cannot reactivate it. No one-child-only uniqueness. |\n| `GroupLearnerRosterEntry` | Group tenant; groupId, familyTenantId, learnerId, membershipId | Unique group/membership tuple; immutable opaque scope index, populated atomically with acceptance. Stores no names, work or policy payload and confers no access. |\n| `GroupSharingPolicy` | Family tenant; membership, monotonically increasing version, schemaVersion=1, canonical policy JSON, parent actor/time | Immutable append-only snapshots; edge points at current version. Unique membership/version. Explicit policy at acceptance; no implicit share-all. |\n| `GroupRevisionComment` | Family tenant; edge, learner, activity, attempt, exact revision, author user/profile, body, createdAt, childVisible=false, visibility parent/time/version=0 | Stable author and revision binding; cannot grade, alter assessment/evidence or silently move to a newer revision. Only parent changes child visibility. Group departure retains row. |\n\nUse guarded JSON getters/setters and runtime validation for policy documents. Enforce tuple uniqueness with database schema constraints. Validate status/version on model writes and revalidate persisted values on service reads, failing closed on corrupt or unknown values. The public model decorator does not expose SQL CHECK constraints; do not broaden core or claim database CHECK enforcement for these fields. Use normal manifest migrations; never create schema at runtime. Invitation delivery/authentication is host-owned; group invitations do not mint identity sessions, and acceptance requires an independently authenticated current parent. Initial release may use exact known parent IDs; mailbox identity onboarding is not implied by an invitation ID.\n\n## Service API and policy\n\nAll requests carry authenticated `actorUserId`, actor session/context binding and explicit resource selectors; none of those are accepted as authority merely because they are present. Proposed public operations:\n\n- `createGroup`, `getGroup`: current group administration/reading through users permissions; provision atomically.\n- `inviteLearner`: current group invitation authority creates a group-owned invitation for an exact known parent and opaque preknown family/learner selectors; it does not read family data, prove those selectors exist or require the inviter to be a guardian. `revokeInvitation` requires current group invitation authority. `declineInvitation` requires the exact currently authenticated invited parent and makes a pending invitation terminal without revealing learner data. `acceptInvitation({ invitationId, policy })`: the exact named parent must currently be guardian of the selected child in the selected family; acceptance requires explicit valid policy. Accept locks the invitation and child/group edge, rechecks active group, parent authority and expiry, inserts edge/policy/group-owned roster index and marks accepted atomically. The parent need not be a group member or supervisor.\n- `setSharingPolicy({ membershipId, expectedVersion, policy })`, `revokeMembership`: current family guardian only. An accepted retry returns the same edge only when parent and original canonical policy digest match and current edge remains active; it never resets policy changed later. Wrong-parent retries fail. Changed acceptance payload conflicts. Expired, revoked or declined pending invitations fail. Accepted historical retry may return original result after expiry only while its current edge is active and parent remains authorized.\n- `previewSharing({ membershipId, policy? })`: current parent; evaluates saved or explicitly proposed policy using exactly the evaluator and projection used for supervisor reads. Proposed preview does not persist or grant access. Return per-item allowed facets and parent-facing reasons.\n- `listSharedWork`, `getSharedWork`, `getSharedRevision`, `readSharedMedia`, `getSharedProgress`: current group supervisor, exact active edge and current policy, with bounded pagination. Reauthorize each call and each selected resource; no reusable authorization result escapes the invocation.\n- `addRevisionComment`, `listRevisionComments`: supervisor comment write requires currently shared exact work/revision and group comment permission; parent reads retained family comments independently of group revocation. Child reads require own learner identity and the current saved parent comment-visibility policy; version-zero comments inherit that policy. `setCommentChildVisibility({ commentId, expectedVersion, visible })` is parent-only.\n\nPolicy v1 has explicit booleans `shareWork`, `shareMedia`, `shareFeedback`, `shareProgress`, `parentReviewedOnly`; `historyFrom` is a required valid UTC instant; `commentVisibility` is required and accepts only `parent-only` or `learner-visible`; the host presents `parent-only` as the initial default but the service requires an explicit saved choice. `subjects` and `courseIds` are explicit selector objects (`all` or nonempty `include` values). Unknown version/keys/enums, malformed or missing required fields fail closed. Empty include selects nothing or is rejected consistently; it never means all. An explicit all selector intentionally allows unknown metadata; any restriction requires matching authoritative metadata. Subject comes from the retained activity's authorized course metadata, not a browser label or inferred assessment text. Course metadata is resolved through the same authorized self/ancestor/global catalog scope for options, preview and supervisor reads, after validating the child's exact family-owned enrollment. Catalog scope conveys no family or guardian authority to a supervisor. Synthetic routing courses for unfiled captures are excluded from selector options; unfiled capture facts retain unknown course and subject even if a technical placeholder has a label or subject. Genuine enrolled courses remain selectable before any capture. An unfiled activity or missing course/subject does not match a restricted selector. Both restrictions intersect when present.\n\nOne pure evaluator takes normalized policy and verified work/revision facts. All public reads and preview call it. History is based on immutable attempt capture time, inclusive at the cutoff; reanalysis/re-filing does not make old work new. Each correction attempt is evaluated separately. `parentReviewedOnly` requires a valid guardian revision of the selected attempt; AI analysis, child release acknowledgement or merely having some other reviewed attempt is insufficient. Feedback is projected only when enabled and the exact selected revision satisfies the review gate; work and media DTOs never incidentally contain feedback, marks or hidden historical question text. Progress may be enabled independently of feedback/work payloads: derive it only from permitted attempts/revisions, never from the whole-family summary. Media is allowed only for an allowed work attempt and the explicit media flag. New matching work appears automatically through evaluation, without per-work grants or background grant materialization.\n\nSupervisor projections contain stable activity/attempt/submission/revision IDs and authorized data only. They expose no writable models, family settings, sibling counts, source storage URLs, answer keys, personal-use catalog assets or ingestion scratch. Work identity does not authorize all revisions. Default omitted revision selects a deterministic permitted current revision; explicit unavailable revision refuses, never silently falls back. Policy flags remain independent; test every combination where one facet could leak through another.\n\n### Fixed exported contracts for implementation\n\nPut shared types and validators in `src/group-sharing-contracts.ts`; models import them, while the pure evaluator imports types only. The following names are the consumer contract, not alternate spellings for workers to invent:\n\n```ts\ntype GroupSharingSelector =\n | { mode: 'all' }\n | { mode: 'include'; values: string[] };\ninterface GroupSharingPolicyV1 {\n schemaVersion: 1;\n shareWork: boolean;\n shareMedia: boolean;\n shareFeedback: boolean;\n shareProgress: boolean;\n parentReviewedOnly: boolean;\n commentVisibility: 'parent-only' | 'learner-visible';\n historyFrom: string;\n subjects: GroupSharingSelector;\n courseIds: GroupSharingSelector;\n}\ninterface GroupSharingActor {\n actorUserId: string;\n sessionId: string;\n}\ninterface GroupSharingScope extends GroupSharingActor {\n groupId: string;\n familyTenantId: string;\n learnerId: string;\n}\ninterface GroupSharedWorkSelector extends GroupSharingScope {\n activityId: string;\n attemptId: string;\n revisionId?: string;\n}\ninterface GroupSharingWorkFacts {\n capturedAt: string;\n courseId: string | null;\n subject: string | null;\n parentReviewed: boolean;\n}\ninterface GroupSharingDecision {\n eligible: boolean;\n work: boolean;\n media: boolean;\n feedback: boolean;\n progress: boolean;\n reasons: string[];\n}\n```\n\nExport `validateGroupSharingPolicy`, `evaluateGroupSharingPolicy(policy, facts)`, `GroupSharingAuthorizationError`, and `GroupSharingConflictError`. `GroupSharingWorkFacts` is populated only by the owning reader, never request JSON. Return names are `EducationGroupView`, `GroupLearnerInvitationView`, `GroupLearnerMembershipView`, `GroupSharedWorkView`, `GroupSharedRevisionView`, `GroupSharingPreview`, `GroupSharedProgressView`, and `GroupRevisionCommentView`. Views are immutable data DTOs, with no model instances or executor. Use `familyTenantId` in requests; family-owned models store that as their required `tenantId`. Invitation and roster-index ownership are the explicit exceptions: its `tenantId` is the group tenant and `familyTenantId` is a distinct opaque scope field. Invitation group staff DTOs disclose only submitted selectors/status, never dereferenced family names, existence or child data. `groupId` references EducationGroup, whose `tenantId` is the users group tenant. Do not confuse these two tenant selectors.\n\nEligibility means course/subject/history/review gates pass; facets intersect eligibility with their explicit flag. `media` additionally requires `shareWork`, so the first implementation exposes original media only with work enabled. Progress can remain enabled while work/feedback DTOs are disabled. Assessment-derived text, answers, scores, computed answer regions and annotated renditions count as feedback. With feedback disabled but work/media enabled, the authorized original child submission bytes remain accessible: marks physically present in those original bytes are intrinsic source content, not a hidden assessment projection. Hosts must make that parent choice clear. A hidden guardian-origin reference/cover or answer-key file is never promoted to an original child submission merely by this toggle.\n\nThe authorization callback is `GroupSharingAuthorizer(request)` where request carries actor, exact group/family/learner selectors as applicable, a discriminated action and `executor: DatabaseInterface`. Actions are `education.group.create`, `education.group.manage`, `education.group.read`, `education.group.invite`, `education.group.share`, `education.group.review`, `education.group.comment`, and `education.group.child-comments`. The host verifies live identity and its effective permissions/guardian terms; the service independently verifies persisted resource scope, current edge/policy and exact selectors. Callback success never bypasses those checks. The reader accepts this callback, never a boolean token, and exposes only read/projection methods. No generic `authorizeAsGuardian` or arbitrary collection callback belongs to this API.\n\n## Owning workbook/media seams\n\nCurrent `LessonWorkService` activity/timeline APIs require learner/guardian authority; replacing the authorizer with unconditional true would create a broad guardian backdoor. Add an explicit read-only owning projection seam with a required exact-resource authorization callback, invoked on its active executor before loading private data and again at final projection/delivery where appropriate. It must not expose mutation methods or accept an externally cached authorization boolean. This seam can live in a dedicated education sharing reader that uses owned collections with exact predicates; private workbook algorithms should be shared through an owning helper rather than copied or private-state access.\n\nThe selected attempt must belong to exact family/learner/activity/submission; selected revision must belong to that attempt. Original bytes must be owned through `SubmissionAsset`, match the retained source ID/hash and belong to the learner's private asset owner. Photo covers/reference-only receipts are not work. The ordinary `signSubmissionAsset` returns a signed URL after learner authorization; it is insufficient for this sharing contract. `readSharedMedia` must run current policy/role/session/edge checks for every HTTP delivery and open the exact `withPrivateAssetAccess` scope only within that request. Return bytes or execute a scoped streaming callback; never return public/presigned storage URLs or a long-lived capability. The host route must invoke it even for a replayed/direct URL and configure private storage/cache headers. No framework can revoke bytes already delivered; successful reads linearize at their final authority check. A revocation completed before a new request must always deny that request.\n\nShared progress recomputes from the permitted subset of current guardian evidence and never calls the full guardian summary then merely redacts its citations. With `shareProgress=true` and `shareFeedback=false`, its strict field allowlist is counts of shared completed work, distinct practice episodes, and assistance categories (independent/assisted/unknown) only. Completion here means a permitted work attempt exists as completed/captured work, never a correctness threshold or private Grade-derived completion decision. Do not expose correctness, points, possible points, scores, concept labels, question identities/text/answers, feedback or outcome-derived aggregates. No question-level evidence citations appear in this counts-only shape. This restriction must hold even for a single attempt, where an aggregate would reveal the entire withheld outcome. When feedback is also enabled, authorized descriptive concept evidence may additionally be projected with permitted citations and existing episode deduplication; it still cannot include hidden subject/history/sibling evidence.\n\nComments remain outside Grades, assessment revision bodies, scoring and progress evidence. Parent-only comments can be shown to their currently authorized author/supervisors and guardians; this means hidden from children by default, not anonymous. Parent can retrieve original author/time after revocation. Child comment access always checks the current saved policy: `parent-only` denies all child comment reads immediately, including previously visible comments; `learner-visible` permits default comments whose `visibilityVersion` is zero. A parent may additionally set an individual override: when `visibilityVersion > 0`, `childVisible` must be true as well as the saved policy being `learner-visible`. Thus a saved learner-visible choice needs no per-comment opt-in, an individual false override narrows it, and an individual true override can never broaden parent-only. Policy changes apply on the next read and never rewrite the original comment or its attribution.\n\n## Transaction and race semantics\n\nUse one active executor for current users/session checks, guardian relationship terms, group state, edge/policy and owned data. Authorization hooks must not capture the outer pool. Mutations run in the education transaction/composite queue with deterministic lock ordering (learner, group/edge, invitation/comment as applicable); acquire the learner lock in the same order as workbook capture/review. PostgreSQL must arbitrate with row locks or conditional writes plus unique keys; process-local locks alone are insufficient. SQLite serialization must not overlap statements on a single native handle. Failed nested operations poison/roll back the enclosing operation even if a callback catches an error.\n\nConcurrent identical acceptance converges to one active edge, one first policy, one group-owned roster entry and one accepted invitation result. Competing policies cannot both win; one conflicts. Concurrent policy updates using one expectedVersion produce one successor. Education-owned edge/policy/invitation mutations participate in the same lock/guard protocol: acceptance versus invitation revoke and comment writes versus edge revoke/policy narrowing are serialized, so the losing mutation cannot commit on stale education-owned state. External users sessions, roles/memberships and guardian-term writers do not participate in that protocol. Their authority linearizes at the final successful live authority read on the active executor, not at transaction commit. An operation authorized before a concurrent external revocation may finish; a new request starting after that revocation committed must deny. A same-executor callback or second read alone cannot close the final-check-to-commit window, and this contract does not claim otherwise. Do not use a transaction snapshot established before the request to satisfy a new request's current-authority check. Stronger commit-time exclusion would require an actual owning users/profiles writer protocol and is outside this contract. Media reads use final-check linearization; bytes already delivered cannot be recalled. Database, authorizer or asset failures propagate as failures, never authorize on fallback. Failed group creation, acceptance and policy append leave no partial tenant/owner/edge/policy/roster/acceptance state. No service starts containers.\n\n## Behavior-to-test matrix\n\nThis is the test-design-contract matrix. Every row requires recorded execution evidence before release. Common context abbreviations: P = independently authenticated current family guardian; S = authenticated group supervisor; C = own child; X = outsider, sibling or other-group actor. TX means the same exact executor for authorization and persistence. SQ/PG means in-process SQLite and PostgreSQL; Node is the supported server runtime. Browser is intentionally not an authorization runtime. Command S: `pnpm --filter @happyvertical/smrt-education exec vitest run src/__tests__/group-sharing-lifecycle.test.ts src/__tests__/group-sharing-adversarial.test.ts src/__tests__/group-sharing-reader.test.ts src/__tests__/group-sharing-comments.test.ts`; command P: `pnpm --filter @happyvertical/smrt-education test:postgres`; command M: `pnpm --filter @happyvertical/smrt-education exec vitest run src/__tests__/group-sharing-models.test.ts src/__tests__/group-sharing-manifest.test.ts`; command B: package `typecheck`, `build`, `verify:pack`. The shared behavioral harness must be imported by both SQLite and `group-sharing.optional.test.ts`; a skipped optional PG suite is not passing PG evidence.\n\n| ID / behavior | Reachable trigger | Positive | Negative / failure | Actor/context | Executor / transaction | Runtime / dialect | External edge | Level / command |\n| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n| G01 isolated group | createGroup | owner membership and group in distinct tenant | rollback after tenant insert; no family membership/parent hierarchy | P, X | TX provision atomic | Node SQ/PG | TenantService failure, unknown permission | integration S/P |\n| G02 closed persistence | generated registration/discovery | package imports models/recipe | no REST/CLI/MCP/AI CRUD advertised | untrusted caller | manifest, no DB needed | Node; schema SQ/PG | packed root exports | contract M/B |\n| G03 edge cardinality | invite/accept multiple edges | two children × two groups coexist | duplicate tuple or rebinding learner/family | P, X | TX unique constraints | Node SQ/PG | malformed IDs | integration S/P |\n| G04 invite targeting | inviteLearner/accept | group inviter creates without family lookup; exact parent accepts with current effective guardian terms; exact parent declines | other parent, expired relationship, wrong family/group/sibling, expired/revoked/declined invite | P/X | TX current session + relationships | Node SQ/PG | absent/expired session, authorizer throw | adversarial S/P |\n| G05 explicit policy | acceptInvitation | valid explicit v1 choice | omitted policy, unknown version/key, malformed date/selector/boolean | P | TX no partial writes | Node SQ/PG | untrusted JSON | service S/P |\n| G06 retry | accept same invite | same edge/policy/result, even after later policy narrowing | changed payload/parent; revoked edge never reactivated | P/X | TX immutable digest | Node SQ/PG | request replay | integration S/P |\n| G07 acceptance race | two accepts | identical requests converge | differing policy, revoke/expiry wins; injected failure rolls all back | P | independent root connections PG, serialized SQ; unique arbiter | Node SQ/PG | failure between edge/policy/roster/accepted writes; retry leaves one index row | concurrency S/P |\n| G08 policy version | setSharingPolicy | append version and preserve previous snapshots | stale expected version, supervisor write, invalid payload | P/S | TX compare-and-set | Node SQ/PG | concurrent updates, upstream auth failure | concurrency S/P |\n| G09 automatic evaluator | new capture/list | matching new work appears without grant creation | unknown restricted subject/course; course and subject mismatch | S/P preview | TX exact family queries | Node SQ/PG | unfiled/missing metadata | unit + service S/P |\n| G10 history/review | get work/revision | inclusive cutoff and reviewed exact attempt | old attempt reanalysis, other attempt's review, provisional-only revision, malformed ancestry | S | TX immutable facts | Node SQ/PG | future/invalid dates, stale revision ID | unit + adversarial S/P |\n| G11 facet independence | every public DTO | explicit work/media/feedback/progress combinations | disabled feedback leaks through marks/status/comment or progress; disabled media via anchors | S | TX projection | Node SQ/PG | omitted optional payload fields | table-driven S/P |\n| G12 preview parity | preview and subsequent reads | identical allowed IDs/facets under same saved/proposed policy | unauthorized preview; proposal creates grant/write | P/S | same evaluator/TX | Node SQ/PG | policy parse failure | contract S/P |\n| G13 current authority | list/detail/revision/media/comment/summary | active S exact group+edge | stale session, removed role, inactive membership/group, wrong active context, sibling/group edge | S/X | current TX reads, cache:false | Node SQ/PG | every public service path | adversarial parameterized S/P |\n| G14 narrowing/revoke | reuse IDs/direct route after change | parent retains originals/history | previously allowed S denied after policy/edge/group/role/session revoke | P/S | TX; final check | Node SQ/PG | stale URL and request replay | service + host contract S/P |\n| G15 exact source ownership | readSharedMedia | exact SubmissionAsset retained hash and private owner | foreign asset/submission/revision, source cover, answer key, tampered hash, public URL | S/X | TX + exact private scope | Node SQ/PG | storage missing/failure; no leaked locator | integration S/P |\n| G16 immutable work IDs | list/get/correction/reanalysis | stable attempt/revision IDs and source citation | foreign revision, selector fallback, reanalysis counted as new practice | S | TX read-only | Node SQ/PG | workbook reader seam | integration S/P |\n| G17 scoped progress | getSharedProgress | counts-only allowlist without feedback; descriptive evidence with feedback; episodes deduped | single-attempt or multi-attempt withheld correctness/score/concept/question leakage; hidden evidence contributes counts | S | TX filtered evidence before aggregate | Node SQ/PG | nullable scores/unknown assistance | integration S/P |\n| G18 comment author/binding | add/list comments | exact visible revision, stored current author | forged author, hidden/foreign revision, supervisor grade/evidence mutation | S/P | TX immutable bind | Node SQ/PG | malformed/empty/oversize text | adversarial S/P |\n| G19 comment visibility | set visibility/child list | saved learner-visible exposes version-zero defaults; explicit false narrows; parent-only immediately hides all | missing/unknown policy field, default parent-only C read, sibling, supervisor visibility update, stale version | P/C/S/X | TX guarded visibility version | Node SQ/PG | visibilityVersion=0 inherits; >0 requires childVisible plus saved learner-visible | integration S/P |\n| G20 retained family records | revoke then family read | originals, revisions, comments/attribution remain | supervisor retains old access; cascade removes learning rows | P/S | TX family authority independent of group | Node SQ/PG | no byte cleanup on revoke | integration S/P |\n| G21 transaction affinity | host hooks in operation | all callbacks observe exact TX including nested reads | outer-pool hook usage, swallowed failure commits, closed service reuse | P/S | instrument executor; rollback injection | Node SQ/PG | callback failure | integration S/P |\n| G22 interleaving authorization | comment/media vs revoke/narrow | own edge/invite/policy mutations serialize; pre-external-revoke authorized operation may finish | stale own-edge check commits after winning revoke; new post-commit session/role/guardian-revoke request succeeds | P/S | independent PG transactions/barriers; SQ serial equivalent | Node SQ/PG | deterministic barriers for own-edge race and external final-check/new-request semantics | race S/P |\n| G23 migration compatibility | manifest upgrade + normal schema apply | six closed models migrate on empty/existing DB; old workbook history unchanged | missing schema fails without runtime DDL; duplicate edge/roster tuple blocked; corrupt status/version read denied | deploy | explicit migration TX | Node SQ/PG | native UUID FKs, migration failure | schema U/P/B |\n| G24 recipe/plugin contract | recipe discovery and packed import | group recipe registered, service/types usable | generated CRUD exposed or missing root symbol | host | N/A: static registration, no persistence | Node | downstream manifest/recipe consumer | contract M/B |\n| G25 bounded query scope | list pagination/direct service | exact group-owned roster enumeration then each exact family edge/policy check; bounded results/stable cursors | forged/stale roster grants access; caller limit hides deny; cursor reveals foreign work; raw cross-family edge query | S/X | TX group index read then exact family predicates | Node SQ/PG | invalid cursor/limit | adversarial S/P |\n| G26 staff group discovery | listMyGroups after login | own active groups; inactive group only for current manager | other user/session, removed membership, inactive nonmanager group | S/X with original session context | TX users own-membership enumeration then exact group scope | Node SQ/PG | unknown group tenant and authorizer error | integration S/P |\n| G27 family/child navigation | listLearnerMemberships access guardian/child | parent retained summaries; own child active group names | sibling, wrong actor, child guardian-policy/history escalation; revoked/disabled child edge | P/C/X | TX exact family/learner, current own-user proof | Node SQ/PG | invalid access selector | adversarial S/P |\n| G28 invitation preview/list | getInvitation/listInvitations | named guardian preview without group membership; staff opaque selectors | wrong invitee, missing guardian proof, staff family dereference | P/S/X | TX exact group invite; parent exact family proof | Node SQ/PG | parent/staff explicit access discriminator | integration S/P |\n| G29 retained policy history | getSharingPolicyHistory after leave | immutable versions/actors/time and scoped numeric pagination | supervisor/child read, malformed cursor/limit, foreign edge | P/S/C/X | TX exact family edge, guardian before/after | Node SQ/PG | unknown stored policy or version fails closed | integration S/P |\n| G30 opaque revision binding | feedback withheld; new revision before comment | work exposes immutable comment ID; comment remains on opened revision | foreign/provisional assessment under selected-review gate, hidden assessment payload | S | TX exact attempt/revision and current policy | Node SQ/PG | opaque comment selector independent of feedback | reader/comments S/P |\n\n| G31 pre-consent policy options | getSharingPolicyOptions exact family/learner before invite acceptance | current guardian receives labeled learner course/subject options without a group edge | child/supervisor/outsider, wrong family/learner, stale guardian/session, private answer/catalog data | P/S/C/X | TX exact family/learner guardian before/after; no policy mutation | Node SQ/PG | groupId omitted; current scoped metadata only | reader S/P |\n| G32 metadata/private capability isolation | ordinary member group home vs roster/work | education.group.read permits group metadata/discovery only; education.group.review permits authorized private scope | metadata-only member roster/work/revision/media/progress, role/action escalation | current stored ordinary member/S | TX role/session/group plus exact edge/policy before/after | Node SQ/PG | guardian review remains separate exact guardian proof | adversarial S/P |\n\n## Implementation ownership partitions\n\nCoordinate these partitions before editing; integrations are serial, not concurrent edits to the same file.\n\n1. Persistence/contracts worker: `src/group-sharing-models.ts`, `src/group-sharing-contracts.ts`, `src/__tests__/group-sharing-models.test.ts`. Own validation/types/closed models and unique schema; freeze exported interfaces first.\n2. Lifecycle worker: `src/group-sharing-service.ts`, `src/group-sharing-authorization.ts`, `src/__tests__/group-sharing-lifecycle-workflows.ts`. Own group/invitation/edge/policy state machine, shared transaction and current-authority boundary. Do not implement a second workbook reader.\n3. Read/projection worker: `src/group-sharing-reader.ts`, `src/group-sharing-policy.ts`, `src/__tests__/group-sharing-read-workflows.ts`. Own same evaluator for preview/reads, exact work/media projection and scoped summary. Any changes needed to `src/workbook-service.ts` or `src/submission-service.ts` belong exclusively to this worker after parent approves the owning seam. Do not widen LearnerAuthorizer.\n4. Integration owner: `src/group-sharing-comments.ts`, shared test runner `src/__tests__/group-sharing-workflows.ts`, SQLite/PG entrypoints, `src/index.ts`, `src/recipes.ts`, recipe help, package docs/AGENTS and generated artifacts. Integrate comment API after lifecycle/read interfaces stabilize, run full validation/review once. Could delegate comments as a separate non-overlapping worker after contracts freeze.\n5. Architecture owner: this document only. Record executable evidence/results through the parent session; proposed matrix rows do not substitute for executed tests.\n\n## Upstream/host contract gaps to resolve before release\n\n- Existing workbook guardian projections and signed asset API are not a sharing boundary. The new owning read seam and host authenticated media route are mandatory, not optional integration notes.\n- Host current-session/group permission and current guardian-term verification must use the provided transaction executor. No external app is permitted to supply an always-allow callback or stale role snapshot. Document exact action names/role seed in implementation.\n- Course.subject is a mutable string; define whether policy uses current authoritative metadata (recommended for immediate narrowing) or immutable metadata snapshots. This design uses current authoritative course metadata and immutable capture time. Missing/re-filed metadata is reevaluated each read.\n- PostgreSQL concurrent tests need independent connections and deterministic barriers. One connection or in-process mutex does not establish multi-process acceptance/revocation safety. Integration owner supplies the isolated existing test service; workers do not provision containers.\n- Public consumer contract must record the published SMRT version, exported types/actions, migration/recipe activation and media route obligations. Hearth consumes that release only; no local tarball or host shim.\n\n## Host integration and migrations\n\nThe public `GroupSharingService(db, authorize, options?)` facade owns lifecycle,\nreader and comment operations. Internal reader/comment classes are not root\nexports: their borrowed-executor flags are owning implementation details.\n`options` uses the normal `SubmissionServiceOptions` private storage adapter.\nThe facade supports atomic `withTransaction` composition; any failed queued\noperation poisons the complete transaction, and escaped services reject reuse.\n\n`updateGroup` changes the bounded display name or active flag under live\n`education.group.manage` authority. Management can reactivate an inactive group;\nnormal read, invitation and supervisor operations cannot use an inactive group.\nDisabling does not delete family rows. `removeLearner` is group-management\nrevocation, `leaveGroup`/`revokeMembership` are guardian revocation.\n`listMemberships` enumerates only the active group's roster index and rechecks\neach authoritative family edge under `education.group.review`. `getGroup` and\nactive `listMyGroups` use `education.group.read` for group metadata only; that\ncapability never authorizes child roster or shared work, revisions, media or\nprogress. Those private supervisor operations require `education.group.review`\nand the current exact family edge/policy. Hosts may grant ordinary members group\nmetadata reading without any private learner access. `listLearnerMemberships` is exact-family guardian\naccess. Neither method offers arbitrary cross-family education discovery.\n\nShared work includes an opaque `commentRevisionId` even when assessment feedback\nis withheld. Bind the comment form to that exact viewed revision and submit it\nunchanged; never resolve the latest assessment again when saving a comment.\nThe identifier grants no assessment access. Feedback and child comment visibility\nstill pass their independent current policy checks on every read.\n\nActivate `education.supervisor` through the host cookbook, rebuild registration\nand apply the host's normal manifest migrations before serving group routes.\nThe six additive tables use generated native UUID references and unique keys.\nDo not alter existing workbook rows or remove family data when a group leaves.\nA missing table is a migration error, never permission to create schema during\na request. Test schema generation uses the same structured manifest on SQLite\nand PostgreSQL; deployments retain their normal migration backup/rollback policy.\n\nHosts refresh the stored session and effective group permissions/guardian terms\non the callback's exact executor. Action strings above are capability names,\nnot a promise that any ordinary users role receives them automatically. Seed\nonly the desired group supervisor/admin roles and never grant family guardian\npermissions. Invitation delivery is host-owned; an invitation identifier alone\nis not a bearer credential. Parents can use only existing currently authorized\nlearners named by the immutable invitation.\n\nServe original bytes through `readSharedMedia` on every authenticated HTTP\nrequest, including direct bookmarks. The result carries `private, no-store`;\nhosts must also set safe MIME/disposition, sandbox CSP and `nosniff`, and never\ncache responses in a service worker or expose underlying asset paths. Uploaded\noriginals can contain marks physically present on paper even when generated\nassessment feedback sharing is disabled.\n\nHost navigation uses `listMyGroups(actor)` for the actor's current users memberships\nand `listLearnerMemberships({ ..., access: 'child' })` for an authenticated child's\nown active group edges. Child navigation uses `education.group.child-comments`\nand never grants guardian access to consent or policy history. Group discovery\nkeeps the original authenticated session context and derives exact group scopes\nfrom stored memberships; inactive groups require current management authority.\nStaff role assignment/removal uses the existing public users collections under\nhost authorization on the same executor. Education sharing never substitutes\nfor those users permission checks or gives staff family authority.\n\n`getSharingPolicyOptions({ actorUserId, sessionId, familyTenantId, learnerId })`\nreturns current course labels/subjects for a currently authorized guardian before\nconsent, without requiring a group or accepted invitation. It uses the same\nactive executor and exact learner ownership checks; it creates no grants or\npolicy history. Host guardian decisions must validate the supplied exact current\nrelationships/terms separately from a group's `education.group.review` role.\n\n## Trusted workspace-kind metadata\n\n`isGroupTenant(db, tenantId): Promise<boolean>` is a trusted host-only metadata\nlookup for an exact server-selected resource tenant. It uses the supplied current\nexecutor, verifies that the Tenant exists freshly, and checks the owning\n`education_groups` table for that exact tenant. Blank, malformed, missing or\nambiguous scope fails closed. The result is independent of group activation,\nTenant status, memberships and staff roles: disabling a group or removing a staff\nmembership never turns it into a family. The result contains no name, roster,\npermission or grant and creates no session or tenant context. It has no generated\nREST, MCP or CLI surface.\n\nOn PostgreSQL, the exact bounded group count and `row_security_active` check\nshare one statement on the caller's executor. One visible row establishes group\nkind; an ambiguous result fails closed. Zero rows establishes family kind only\nwhen PostgreSQL reports row security inactive for that relation and caller.\nUnder active RLS, zero rows is indeterminate and throws `Tenant kind is unavailable`,\nincluding for an actual family tenant. The host needs an already trusted metadata\nexecutor with provable unrestricted visibility to classify families. Policy-level\nbypass settings alone do not prove that visibility. The helper never changes\nroles, permissions, session settings or tenant context to obtain visibility.\n\nThis result is not authorization. Hosts must separately require a freshly ACTIVE\nTenant plus current signed-session, background-job or independent-proof authority\non the same relevant executor. Never pass a browser-selected tenant as authority,\ninterpret a missing Tenant as family, or use absence of group membership to infer\nfamily kind. The helper provides no arbitrary cross-tenant directory.\n\n| Behavior/invariant | Trigger | Positive | Negative/failure | Actor/context | Executor/transaction | Runtime/dialect | External edge | Level | Command |\n| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n| G33 workspace kind | trusted exact resource lookup | existing family false; active/inactive group true | blank/malformed/absent tenant; ambiguous group rows; PostgreSQL RLS-hidden or indeterminate zero refuses family; database failures propagate | host-selected exact tenant, no synthetic session/context | caller-supplied executor, fresh reads; no writes | Node SQLite/PostgreSQL | status/membership/role absence never implies family or grants | integration | `pnpm --filter @happyvertical/smrt-education exec vitest run src/__tests__/group-sharing-workspace.test.ts` (same file with TEST_DB_ADAPTER=postgres and isolated DATABASE_URL) |\n\n## Authored course visibility\n\nAuthored-course `visibility` (see [course authoring](course-authoring-service.md))\nonly ever narrows group sharing; it never adds a reader, a tenant or a facet.\n\nBefore: every authored release that was not personal-use was eligible (policy\noptions, `listSharedWork`, preview) subject to the policy, edge and review rules.\nAfter: the same, except an authored release whose identity is explicitly recorded\nas `family` (including any unrecognized stored value) is `course-private`: it is\nabsent from the policy options and its work evaluates `course-private`, also when\nonly another release of that course is in the enrollment's pin lineage.\n`groups` and `public` change nothing relative to before. A course whose visibility\nwas never recorded (everything authored before visibility existed) also behaves as\nbefore, so existing contracts and tests are unchanged; hosts that want a default\nof \"family only\" call `setVisibility('family')` explicitly. `public` is a listing\nlabel only; no reviewed cross-tenant read path exists for it, so it grants nothing.\nNon-authored courses, answer keys and personal-use rules are untouched, and a\ndatabase without the visibility column or release tables reads as never recorded.\nThe gate is `authoredVisibilityPermitsGroups(db, tenantId, releaseCourseId)`.\n\nFiled loose work is attributed to its current filing placement (target lesson,\nenrollment and course, hence subject) under the same consent, offered-metadata and\npin-lineage rules as routed work; unplaced loose work stays unknown metadata.\n\nShared work also carries `courseTitle`, `lessonTitle` and `pageLabel` (#4619) so a\nsupervisor can relate samples to the family's program without reading family\ncourses. They are read from the same resolved course, placement and gates as\n`courseId`/`subject`: only for items the policy shares, null where the course is\nunknown, and the lesson title only when the lesson belongs to that course. Filed\nwork names its placement's page; routed work reads the lesson's first page.\n"
|
|
15727
15727
|
},
|
|
15728
15728
|
{
|
|
15729
15729
|
"path": "agents/tutor-context.md",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-education",
|
|
3
|
-
"version": "0.59.
|
|
3
|
+
"version": "0.59.1",
|
|
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.59.
|
|
33
|
-
"@happyvertical/smrt-core": "0.59.
|
|
34
|
-
"@happyvertical/smrt-profiles": "0.59.
|
|
35
|
-
"@happyvertical/smrt-tenancy": "0.59.
|
|
36
|
-
"@happyvertical/smrt-users": "0.59.
|
|
32
|
+
"@happyvertical/smrt-assets": "0.59.1",
|
|
33
|
+
"@happyvertical/smrt-core": "0.59.1",
|
|
34
|
+
"@happyvertical/smrt-profiles": "0.59.1",
|
|
35
|
+
"@happyvertical/smrt-tenancy": "0.59.1",
|
|
36
|
+
"@happyvertical/smrt-users": "0.59.1",
|
|
37
37
|
"@happyvertical/files": "^0.111.3",
|
|
38
38
|
"@happyvertical/sql": "^0.111.3",
|
|
39
39
|
"pdf-lib": "1.17.1",
|
|
40
|
-
"@happyvertical/smrt-ingestion": "0.59.
|
|
40
|
+
"@happyvertical/smrt-ingestion": "0.59.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@happyvertical/smrt-vitest": "0.59.
|
|
43
|
+
"@happyvertical/smrt-vitest": "0.59.1",
|
|
44
44
|
"@types/node": "24.13.6",
|
|
45
45
|
"typescript": "6.0.3",
|
|
46
46
|
"vite": "8.1.6",
|