Repository navigation
feat(elos): agent practice in the app and sentence questions per chapter #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /** | ||
| * Practice done with a local agent (Hermes through the ELOS MCP server), handed back to | ||
| * the app as a per-chapter summary next to the learner snapshot. | ||
| * | ||
| * DERIVED_PRACTICE by design: questions answered through an agent are assisted and | ||
| * generated, so this summary is shown as practice and never changes a mastery state. | ||
| * It holds counts only: no question text, answer or course passage. | ||
| */ | ||
|
|
||
| export const AGENT_PRACTICE_FORMAT = "engineer-learning-os/agent-practice"; | ||
| export const AGENT_PRACTICE_VERSION = 1; | ||
| export const AGENT_PRACTICE_FILE = "elos-practice.json"; | ||
|
|
||
| export type PracticeAttempt = Readonly<{ at: string; chapterId: string; questionId: string; correct: boolean }>; | ||
| export type ChapterLabel = Readonly<{ id: string; title: string; subject: string }>; | ||
|
|
||
| export type AgentPracticeChapter = Readonly<{ | ||
| chapterId: string; | ||
| title: string; | ||
| subject: string; | ||
| answered: number; | ||
| correct: number; | ||
| /** Questions whose latest answer was wrong: what the agent will ask again first. */ | ||
| toRetry: number; | ||
| lastAt: string; | ||
| }>; | ||
|
|
||
| export type AgentPractice = Readonly<{ | ||
| format: typeof AGENT_PRACTICE_FORMAT; | ||
| version: typeof AGENT_PRACTICE_VERSION; | ||
| generatedAt: string; | ||
| evidence: "DERIVED_PRACTICE"; | ||
| chapters: readonly AgentPracticeChapter[]; | ||
| }>; | ||
|
|
||
| export function buildAgentPractice(attempts: readonly PracticeAttempt[], chapters: readonly ChapterLabel[], now: Date): AgentPractice { | ||
| const labels = new Map(chapters.map((chapter) => [chapter.id, chapter])); | ||
| const byChapter = new Map<string, PracticeAttempt[]>(); | ||
| for (const attempt of [...attempts].sort((a, b) => a.at.localeCompare(b.at))) { | ||
| byChapter.set(attempt.chapterId, [...(byChapter.get(attempt.chapterId) ?? []), attempt]); | ||
| } | ||
| return { | ||
| format: AGENT_PRACTICE_FORMAT, version: AGENT_PRACTICE_VERSION, generatedAt: now.toISOString(), evidence: "DERIVED_PRACTICE", | ||
| chapters: [...byChapter].map(([chapterId, list]) => { | ||
| const latest = new Map(list.map((attempt) => [attempt.questionId, attempt.correct])); | ||
| return { | ||
| chapterId, title: labels.get(chapterId)?.title ?? chapterId, subject: labels.get(chapterId)?.subject ?? "", | ||
| answered: list.length, correct: list.filter((attempt) => attempt.correct).length, | ||
| toRetry: [...latest.values()].filter((correct) => !correct).length, lastAt: list[list.length - 1].at, | ||
| }; | ||
| }).sort((a, b) => b.lastAt.localeCompare(a.lastAt)), | ||
| }; | ||
| } | ||
|
|
||
| const count = (value: unknown) => typeof value === "number" && Number.isInteger(value) && value >= 0; | ||
|
|
||
| /** Strict validation for the app: an unknown or damaged file is rejected, never partially trusted. */ | ||
| export function parseAgentPractice(text: string): AgentPractice { | ||
| const value = JSON.parse(text) as Partial<AgentPractice>; | ||
| const valid = value?.format === AGENT_PRACTICE_FORMAT && value.version === AGENT_PRACTICE_VERSION && value.evidence === "DERIVED_PRACTICE" | ||
| && typeof value.generatedAt === "string" && Array.isArray(value.chapters) | ||
| && value.chapters.every((chapter) => typeof chapter?.chapterId === "string" && typeof chapter.title === "string" && typeof chapter.subject === "string" | ||
| && count(chapter.answered) && count(chapter.correct) && count(chapter.toRetry) && chapter.correct <= chapter.answered && typeof chapter.lastAt === "string"); | ||
| if (!valid) throw new Error("INVALID_AGENT_PRACTICE"); | ||
| return value as AgentPractice; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Hermes records an answer while the Data page remains mounted, only
elos-practice.jsonchanges; neitherfoldernorstatuschanges, so this effect never reads the new counts.AgentAutoSyncalso only writes the snapshot and does not notify this panel, leaving the displayed practice stale until navigation/remount or a status transition. Polling while visible or reacting to visibility/focus would make the new hand-back behavior observable.Useful? React with 👍 / 👎.