seance-cli 0.0.0-stage → 0.1.0

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.
Files changed (190) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/commands/init.d.ts +29 -0
  4. package/dist/commands/init.js +310 -0
  5. package/dist/commands/init.js.map +1 -0
  6. package/dist/commands/mcp.d.ts +19 -0
  7. package/dist/commands/mcp.js +38 -0
  8. package/dist/commands/mcp.js.map +1 -0
  9. package/dist/commands/quiz.d.ts +23 -0
  10. package/dist/commands/quiz.js +187 -0
  11. package/dist/commands/quiz.js.map +1 -0
  12. package/dist/commands/review.d.ts +4 -0
  13. package/dist/commands/review.js +115 -0
  14. package/dist/commands/review.js.map +1 -0
  15. package/dist/commands/sync.d.ts +17 -0
  16. package/dist/commands/sync.js +367 -0
  17. package/dist/commands/sync.js.map +1 -0
  18. package/dist/git.d.ts +33 -0
  19. package/dist/git.js +103 -0
  20. package/dist/git.js.map +1 -0
  21. package/dist/hosted-api.d.ts +24 -0
  22. package/dist/hosted-api.js +85 -0
  23. package/dist/hosted-api.js.map +1 -0
  24. package/dist/hosted-consent.d.ts +8 -0
  25. package/dist/hosted-consent.js +37 -0
  26. package/dist/hosted-consent.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +108 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/init-fs.d.ts +51 -0
  31. package/dist/init-fs.js +220 -0
  32. package/dist/init-fs.js.map +1 -0
  33. package/dist/init-questions.d.ts +21 -0
  34. package/dist/init-questions.js +161 -0
  35. package/dist/init-questions.js.map +1 -0
  36. package/dist/mcp-handlers.d.ts +22 -0
  37. package/dist/mcp-handlers.js +185 -0
  38. package/dist/mcp-handlers.js.map +1 -0
  39. package/dist/mcp-server.d.ts +4 -0
  40. package/dist/mcp-server.js +39 -0
  41. package/dist/mcp-server.js.map +1 -0
  42. package/dist/prompter.d.ts +29 -0
  43. package/dist/prompter.js +42 -0
  44. package/dist/prompter.js.map +1 -0
  45. package/dist/quiz-backend.d.ts +40 -0
  46. package/dist/quiz-backend.js +116 -0
  47. package/dist/quiz-backend.js.map +1 -0
  48. package/dist/quiz-input.d.ts +12 -0
  49. package/dist/quiz-input.js +52 -0
  50. package/dist/quiz-input.js.map +1 -0
  51. package/dist/quiz-io.d.ts +30 -0
  52. package/dist/quiz-io.js +83 -0
  53. package/dist/quiz-io.js.map +1 -0
  54. package/dist/quiz-ui.d.ts +18 -0
  55. package/dist/quiz-ui.js +51 -0
  56. package/dist/quiz-ui.js.map +1 -0
  57. package/node_modules/@seance/ai/LICENSE +21 -0
  58. package/node_modules/@seance/ai/dist/chain.d.ts +31 -0
  59. package/node_modules/@seance/ai/dist/chain.js +114 -0
  60. package/node_modules/@seance/ai/dist/chain.js.map +1 -0
  61. package/node_modules/@seance/ai/dist/grade.d.ts +14 -0
  62. package/node_modules/@seance/ai/dist/grade.js +44 -0
  63. package/node_modules/@seance/ai/dist/grade.js.map +1 -0
  64. package/node_modules/@seance/ai/dist/hosted-config.d.ts +9 -0
  65. package/node_modules/@seance/ai/dist/hosted-config.js +27 -0
  66. package/node_modules/@seance/ai/dist/hosted-config.js.map +1 -0
  67. package/node_modules/@seance/ai/dist/index.d.ts +9 -0
  68. package/node_modules/@seance/ai/dist/index.js +9 -0
  69. package/node_modules/@seance/ai/dist/index.js.map +1 -0
  70. package/node_modules/@seance/ai/dist/providers.d.ts +54 -0
  71. package/node_modules/@seance/ai/dist/providers.js +149 -0
  72. package/node_modules/@seance/ai/dist/providers.js.map +1 -0
  73. package/node_modules/@seance/ai/dist/quiz.d.ts +26 -0
  74. package/node_modules/@seance/ai/dist/quiz.js +41 -0
  75. package/node_modules/@seance/ai/dist/quiz.js.map +1 -0
  76. package/node_modules/@seance/ai/package.json +25 -0
  77. package/node_modules/@seance/core/LICENSE +21 -0
  78. package/node_modules/@seance/core/dist/ai-check.d.ts +58 -0
  79. package/node_modules/@seance/core/dist/ai-check.js +460 -0
  80. package/node_modules/@seance/core/dist/ai-check.js.map +1 -0
  81. package/node_modules/@seance/core/dist/ai-prompts.d.ts +29 -0
  82. package/node_modules/@seance/core/dist/ai-prompts.js +221 -0
  83. package/node_modules/@seance/core/dist/ai-prompts.js.map +1 -0
  84. package/node_modules/@seance/core/dist/ai-schemas.d.ts +155 -0
  85. package/node_modules/@seance/core/dist/ai-schemas.js +92 -0
  86. package/node_modules/@seance/core/dist/ai-schemas.js.map +1 -0
  87. package/node_modules/@seance/core/dist/api-client.d.ts +26 -0
  88. package/node_modules/@seance/core/dist/api-client.js +71 -0
  89. package/node_modules/@seance/core/dist/api-client.js.map +1 -0
  90. package/node_modules/@seance/core/dist/api-errors.d.ts +37 -0
  91. package/node_modules/@seance/core/dist/api-errors.js +66 -0
  92. package/node_modules/@seance/core/dist/api-errors.js.map +1 -0
  93. package/node_modules/@seance/core/dist/api-schemas.d.ts +284 -0
  94. package/node_modules/@seance/core/dist/api-schemas.js +67 -0
  95. package/node_modules/@seance/core/dist/api-schemas.js.map +1 -0
  96. package/node_modules/@seance/core/dist/decision-log.d.ts +73 -0
  97. package/node_modules/@seance/core/dist/decision-log.js +239 -0
  98. package/node_modules/@seance/core/dist/decision-log.js.map +1 -0
  99. package/node_modules/@seance/core/dist/dependency-guard.d.ts +20 -0
  100. package/node_modules/@seance/core/dist/dependency-guard.js +732 -0
  101. package/node_modules/@seance/core/dist/dependency-guard.js.map +1 -0
  102. package/node_modules/@seance/core/dist/gate.d.ts +11 -0
  103. package/node_modules/@seance/core/dist/gate.js +26 -0
  104. package/node_modules/@seance/core/dist/gate.js.map +1 -0
  105. package/node_modules/@seance/core/dist/git-parse.d.ts +11 -0
  106. package/node_modules/@seance/core/dist/git-parse.js +23 -0
  107. package/node_modules/@seance/core/dist/git-parse.js.map +1 -0
  108. package/node_modules/@seance/core/dist/index.d.ts +65 -0
  109. package/node_modules/@seance/core/dist/index.js +47 -0
  110. package/node_modules/@seance/core/dist/index.js.map +1 -0
  111. package/node_modules/@seance/core/dist/init-checklist.d.ts +153 -0
  112. package/node_modules/@seance/core/dist/init-checklist.js +200 -0
  113. package/node_modules/@seance/core/dist/init-checklist.js.map +1 -0
  114. package/node_modules/@seance/core/dist/init-detect.d.ts +9 -0
  115. package/node_modules/@seance/core/dist/init-detect.js +84 -0
  116. package/node_modules/@seance/core/dist/init-detect.js.map +1 -0
  117. package/node_modules/@seance/core/dist/init-templates.d.ts +36 -0
  118. package/node_modules/@seance/core/dist/init-templates.js +257 -0
  119. package/node_modules/@seance/core/dist/init-templates.js.map +1 -0
  120. package/node_modules/@seance/core/dist/map-basics.d.ts +13 -0
  121. package/node_modules/@seance/core/dist/map-basics.js +19 -0
  122. package/node_modules/@seance/core/dist/map-basics.js.map +1 -0
  123. package/node_modules/@seance/core/dist/map-summary.d.ts +5 -0
  124. package/node_modules/@seance/core/dist/map-summary.js +50 -0
  125. package/node_modules/@seance/core/dist/map-summary.js.map +1 -0
  126. package/node_modules/@seance/core/dist/markers.d.ts +51 -0
  127. package/node_modules/@seance/core/dist/markers.js +84 -0
  128. package/node_modules/@seance/core/dist/markers.js.map +1 -0
  129. package/node_modules/@seance/core/dist/mcp-quiz.d.ts +94 -0
  130. package/node_modules/@seance/core/dist/mcp-quiz.js +130 -0
  131. package/node_modules/@seance/core/dist/mcp-quiz.js.map +1 -0
  132. package/node_modules/@seance/core/dist/mcp-tools.d.ts +82 -0
  133. package/node_modules/@seance/core/dist/mcp-tools.js +136 -0
  134. package/node_modules/@seance/core/dist/mcp-tools.js.map +1 -0
  135. package/node_modules/@seance/core/dist/mcp-views.d.ts +21 -0
  136. package/node_modules/@seance/core/dist/mcp-views.js +83 -0
  137. package/node_modules/@seance/core/dist/mcp-views.js.map +1 -0
  138. package/node_modules/@seance/core/dist/quiz-assembly.d.ts +21 -0
  139. package/node_modules/@seance/core/dist/quiz-assembly.js +43 -0
  140. package/node_modules/@seance/core/dist/quiz-assembly.js.map +1 -0
  141. package/node_modules/@seance/core/dist/quiz-cards.d.ts +183 -0
  142. package/node_modules/@seance/core/dist/quiz-cards.js +215 -0
  143. package/node_modules/@seance/core/dist/quiz-cards.js.map +1 -0
  144. package/node_modules/@seance/core/dist/quiz-session.d.ts +67 -0
  145. package/node_modules/@seance/core/dist/quiz-session.js +141 -0
  146. package/node_modules/@seance/core/dist/quiz-session.js.map +1 -0
  147. package/node_modules/@seance/core/dist/quiz-subjects.d.ts +13 -0
  148. package/node_modules/@seance/core/dist/quiz-subjects.js +63 -0
  149. package/node_modules/@seance/core/dist/quiz-subjects.js.map +1 -0
  150. package/node_modules/@seance/core/dist/rate-limit.d.ts +33 -0
  151. package/node_modules/@seance/core/dist/rate-limit.js +114 -0
  152. package/node_modules/@seance/core/dist/rate-limit.js.map +1 -0
  153. package/node_modules/@seance/core/dist/scoring.d.ts +48 -0
  154. package/node_modules/@seance/core/dist/scoring.js +95 -0
  155. package/node_modules/@seance/core/dist/scoring.js.map +1 -0
  156. package/node_modules/@seance/core/dist/seance-config.d.ts +177 -0
  157. package/node_modules/@seance/core/dist/seance-config.js +43 -0
  158. package/node_modules/@seance/core/dist/seance-config.js.map +1 -0
  159. package/node_modules/@seance/core/dist/seance-state.d.ts +125 -0
  160. package/node_modules/@seance/core/dist/seance-state.js +61 -0
  161. package/node_modules/@seance/core/dist/seance-state.js.map +1 -0
  162. package/node_modules/@seance/core/dist/sm2.d.ts +18 -0
  163. package/node_modules/@seance/core/dist/sm2.js +87 -0
  164. package/node_modules/@seance/core/dist/sm2.js.map +1 -0
  165. package/node_modules/@seance/core/dist/stored-schemas.d.ts +29 -0
  166. package/node_modules/@seance/core/dist/stored-schemas.js +29 -0
  167. package/node_modules/@seance/core/dist/stored-schemas.js.map +1 -0
  168. package/node_modules/@seance/core/dist/structural-questions.d.ts +31 -0
  169. package/node_modules/@seance/core/dist/structural-questions.js +575 -0
  170. package/node_modules/@seance/core/dist/structural-questions.js.map +1 -0
  171. package/node_modules/@seance/core/dist/structure-map-schema.d.ts +84 -0
  172. package/node_modules/@seance/core/dist/structure-map-schema.js +73 -0
  173. package/node_modules/@seance/core/dist/structure-map-schema.js.map +1 -0
  174. package/node_modules/@seance/core/dist/structure-map.d.ts +78 -0
  175. package/node_modules/@seance/core/dist/structure-map.js +750 -0
  176. package/node_modules/@seance/core/dist/structure-map.js.map +1 -0
  177. package/node_modules/@seance/core/dist/sync-changes.d.ts +38 -0
  178. package/node_modules/@seance/core/dist/sync-changes.js +89 -0
  179. package/node_modules/@seance/core/dist/sync-changes.js.map +1 -0
  180. package/node_modules/@seance/core/dist/sync-render.d.ts +28 -0
  181. package/node_modules/@seance/core/dist/sync-render.js +113 -0
  182. package/node_modules/@seance/core/dist/sync-render.js.map +1 -0
  183. package/node_modules/@seance/core/dist/terminal-text.d.ts +8 -0
  184. package/node_modules/@seance/core/dist/terminal-text.js +33 -0
  185. package/node_modules/@seance/core/dist/terminal-text.js.map +1 -0
  186. package/node_modules/@seance/core/dist/write-plan.d.ts +51 -0
  187. package/node_modules/@seance/core/dist/write-plan.js +173 -0
  188. package/node_modules/@seance/core/dist/write-plan.js.map +1 -0
  189. package/node_modules/@seance/core/package.json +26 -0
  190. package/package.json +42 -6
@@ -0,0 +1,43 @@
1
+ // Quiz assembly (Task 9): turns the hosted API's quiz reply, or no reply at all, into the questions the web app asks.
2
+ // Pure: same rule as the CLI's hosted backend (cut to 5, top up 1-4 with structural questions, structural only without a reply).
3
+ import { QuizItemSchema } from "./ai-schemas.js";
4
+ import { fillQuiz } from "./ai-check.js";
5
+ import { generateStructuralQuestions } from "./structural-questions.js";
6
+ /** How many questions a quiz has. */
7
+ export const QUIZ_SIZE = 5;
8
+ /** Valid items only, first one wins for a repeated id. */
9
+ function validUnique(items) {
10
+ const seen = new Set();
11
+ const result = [];
12
+ for (const item of items) {
13
+ const parsed = QuizItemSchema.safeParse(item);
14
+ if (!parsed.success || seen.has(parsed.data.id))
15
+ continue;
16
+ seen.add(parsed.data.id);
17
+ result.push(parsed.data);
18
+ }
19
+ return result;
20
+ }
21
+ /** Structural questions of the map as quiz items. */
22
+ function structuralItems(map, seed, attempt) {
23
+ const questions = generateStructuralQuestions(map, { count: QUIZ_SIZE, seed, attempt });
24
+ return validUnique(questions.map((question) => ({ ...question, origin: "structural" })));
25
+ }
26
+ /**
27
+ * `reply` is the parsed `/api/quiz` reply, or `null` when the request failed or had no valid question.
28
+ * No reply: structural questions only. 5 or more questions: the first 5. 1 to 4: topped up with structural questions.
29
+ */
30
+ export function assembleQuiz(reply, map, options) {
31
+ if (reply === null) {
32
+ return { questions: structuralItems(map, options.seed, options.attempt), servedBy: "structural", local: true };
33
+ }
34
+ const fromReply = validUnique(reply.questions);
35
+ const questions = fromReply.length >= QUIZ_SIZE
36
+ ? fromReply.slice(0, QUIZ_SIZE)
37
+ : validUnique(fillQuiz(fromReply, generateStructuralQuestions(map, { count: QUIZ_SIZE * 2, seed: options.seed, attempt: options.attempt }))).slice(0, QUIZ_SIZE);
38
+ const assembled = { questions, servedBy: reply.servedBy, local: false };
39
+ if (reply.model !== undefined)
40
+ assembled.model = reply.model;
41
+ return assembled;
42
+ }
43
+ //# sourceMappingURL=quiz-assembly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quiz-assembly.js","sourceRoot":"","sources":["../src/quiz-assembly.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,iIAAiI;AACjI,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAGxE,qCAAqC;AACrC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAW3B,0DAA0D;AAC1D,SAAS,WAAW,CAAC,KAAyB;IAC5C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE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,CAAC,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IACrK,MAAM,SAAS,GAAkB,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACvF,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;QAAE,SAAS,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC7D,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,183 @@
1
+ import { z } from "zod";
2
+ import { type QuizConcept, type QuizItem } from "./ai-schemas.js";
3
+ import { type AnswerOutcome, type QuizSession, type QuizSource, type QuizSummary } from "./quiz-session.js";
4
+ import { type PendingQuiz, type SeanceState } from "./seance-state.js";
5
+ import { type Card } from "./sm2.js";
6
+ /** Most cards one `seance review` run asks about. */
7
+ export declare const MAX_REVIEW_PER_SESSION = 20;
8
+ /** Most files `seance quiz` reads when there is no pending quiz. */
9
+ export declare const MAX_QUIZ_FILES = 50;
10
+ /** An SM-2 card plus what Task 7 stores with it: the concept, the question as asked, when it was added and how often it was reviewed. */
11
+ export interface ReviewCard extends Card {
12
+ concept: QuizConcept;
13
+ question: QuizItem;
14
+ addedAt: string;
15
+ reviews: number;
16
+ [key: string]: unknown;
17
+ }
18
+ /** Checks a stored card: the SM-2 fields as in `seance-state.ts`, plus the Task 7 fields. Unknown keys survive. */
19
+ export declare const ReviewCardSchema: z.ZodObject<{
20
+ ease: z.ZodNumber;
21
+ interval: z.ZodInt;
22
+ repetitions: z.ZodInt;
23
+ dueAt: z.ZodString;
24
+ concept: z.ZodEnum<{
25
+ "async-functions": "async-functions";
26
+ "call-graph": "call-graph";
27
+ classes: "classes";
28
+ "data-flow": "data-flow";
29
+ decision: "decision";
30
+ "error-handling": "error-handling";
31
+ exports: "exports";
32
+ imports: "imports";
33
+ parameters: "parameters";
34
+ "side-effects": "side-effects";
35
+ state: "state";
36
+ }>;
37
+ question: z.ZodUnion<readonly [z.ZodObject<{
38
+ id: z.ZodString;
39
+ concept: z.ZodEnum<{
40
+ "async-functions": "async-functions";
41
+ "call-graph": "call-graph";
42
+ classes: "classes";
43
+ "data-flow": "data-flow";
44
+ decision: "decision";
45
+ "error-handling": "error-handling";
46
+ exports: "exports";
47
+ imports: "imports";
48
+ parameters: "parameters";
49
+ "side-effects": "side-effects";
50
+ state: "state";
51
+ }>;
52
+ prompt: z.ZodString;
53
+ source: z.ZodObject<{
54
+ path: z.ZodString;
55
+ line: z.ZodOptional<z.ZodInt>;
56
+ }, z.core.$strip>;
57
+ origin: z.ZodEnum<{
58
+ ai: "ai";
59
+ structural: "structural";
60
+ }>;
61
+ kind: z.ZodEnum<{
62
+ mcq: "mcq";
63
+ "what-if": "what-if";
64
+ }>;
65
+ choices: z.ZodArray<z.ZodString>;
66
+ answerIndex: z.ZodInt;
67
+ }, z.core.$strip>, z.ZodObject<{
68
+ id: z.ZodString;
69
+ concept: z.ZodEnum<{
70
+ "async-functions": "async-functions";
71
+ "call-graph": "call-graph";
72
+ classes: "classes";
73
+ "data-flow": "data-flow";
74
+ decision: "decision";
75
+ "error-handling": "error-handling";
76
+ exports: "exports";
77
+ imports: "imports";
78
+ parameters: "parameters";
79
+ "side-effects": "side-effects";
80
+ state: "state";
81
+ }>;
82
+ prompt: z.ZodString;
83
+ source: z.ZodObject<{
84
+ path: z.ZodString;
85
+ line: z.ZodOptional<z.ZodInt>;
86
+ }, z.core.$strip>;
87
+ origin: z.ZodEnum<{
88
+ ai: "ai";
89
+ structural: "structural";
90
+ }>;
91
+ kind: z.ZodLiteral<"explain">;
92
+ rubric: z.ZodObject<{
93
+ keyPoints: z.ZodArray<z.ZodString>;
94
+ modelAnswer: z.ZodOptional<z.ZodString>;
95
+ }, z.core.$strip>;
96
+ }, z.core.$strip>]>;
97
+ addedAt: z.ZodString;
98
+ reviews: z.ZodInt;
99
+ }, z.core.$loose>;
100
+ /** What the pending quiz remembers about runs of `seance quiz`. */
101
+ export interface QuizProgress {
102
+ attempts: number;
103
+ lastResult?: {
104
+ at: string;
105
+ score: number;
106
+ understood: boolean;
107
+ source: QuizSource;
108
+ };
109
+ }
110
+ export declare const QuizProgressSchema: z.ZodObject<{
111
+ attempts: z.ZodDefault<z.ZodInt>;
112
+ lastResult: z.ZodOptional<z.ZodObject<{
113
+ at: z.ZodISODateTime;
114
+ score: z.ZodNumber;
115
+ understood: z.ZodBoolean;
116
+ source: z.ZodEnum<{
117
+ hosted: "hosted";
118
+ "local-ai": "local-ai";
119
+ offline: "offline";
120
+ structural: "structural";
121
+ }>;
122
+ }, z.core.$strip>>;
123
+ }, z.core.$loose>;
124
+ /** The progress of a pending quiz; `{ attempts: 0 }` when there is none or its progress fields are invalid. */
125
+ export declare function readProgress(pending: PendingQuiz | undefined): QuizProgress;
126
+ /**
127
+ * `{concept}:{8 hex}` from the path, kind, prompt and correct answer text (not the id, which repeats across AI quizzes, and
128
+ * not the choice order). The answer is part of the key since Dec 2 (changed after review): the same prompt with another
129
+ * correct answer is another question. An explain question has no answer text, so its key is the same as before.
130
+ */
131
+ export declare function cardKey(item: QuizItem): string;
132
+ /**
133
+ * `{concept}|{prompt with whitespace collapsed}|{correct answer text}`: two questions with the same value are the same
134
+ * question for review (changed Dec 2 after manual test: the same prompt came back as a second card because its source
135
+ * line or kind differed). The correct answer is part of the key (changed Dec 2 after review): "Which function calls
136
+ * `save`?" asked about two different files has two answers and needs two cards. An explain question has no choice, so its
137
+ * answer part is empty. The text is the trimmed choice, so a reshuffled choice order gives the same key.
138
+ */
139
+ export declare function promptKey(item: Pick<QuizItem, "concept" | "prompt"> & {
140
+ choices?: readonly string[];
141
+ answerIndex?: number;
142
+ }): string;
143
+ /** The seed of a quiz: from the pending quiz id, else from the picked paths. */
144
+ export declare function quizSeed(pending: PendingQuiz | undefined, paths: readonly string[]): number;
145
+ /** JS and TS paths that are not excluded, unique, sorted by UTF-16 and cut to 50. */
146
+ export declare function pickQuizFiles(paths: readonly string[]): string[];
147
+ /** Everything `applyQuizResult` needs about a finished quiz. `today` is the local date, `at` an ISO UTC time. */
148
+ export interface QuizRecord {
149
+ quizId: string | null;
150
+ summary: QuizSummary;
151
+ session: QuizSession;
152
+ today: string;
153
+ at: string;
154
+ source: QuizSource;
155
+ }
156
+ export interface QuizApply {
157
+ state: SeanceState;
158
+ added: string[];
159
+ updated: string[];
160
+ notAdded: number;
161
+ }
162
+ /**
163
+ * The state after a quiz. Missed questions without a card become new cards (rated from the answer); a question whose
164
+ * key has a valid card updates it; correct answers never add a card. The input state is not changed.
165
+ */
166
+ export declare function applyQuizResult(state: SeanceState, record: QuizRecord): QuizApply;
167
+ export interface DueCard {
168
+ key: string;
169
+ card: ReviewCard;
170
+ }
171
+ /** Valid cards due on or before `today`, oldest first (then by key), at most `limit`. `invalid` counts every entry that fails `ReviewCardSchema`. */
172
+ export declare function dueCards(cards: Readonly<Record<string, Card>>, today: string, limit?: number): {
173
+ due: DueCard[];
174
+ invalid: number;
175
+ };
176
+ /** The earliest `dueAt` of a valid card, or undefined when there is none. */
177
+ export declare function nextDueDate(cards: Readonly<Record<string, Card>>): string | undefined;
178
+ export interface ReviewOutcome {
179
+ key: string;
180
+ outcome: AnswerOutcome;
181
+ }
182
+ /** The state after a review: each reviewed card moves on by its quality. A key that is missing or invalid is ignored. */
183
+ export declare function applyReviewResult(state: SeanceState, reviews: readonly ReviewOutcome[], today: string): SeanceState;
@@ -0,0 +1,215 @@
1
+ // Review cards and state updates for `seance quiz` and `seance review` (Task 7): card keys, schemas for the fields
2
+ // this task adds to `.seance/state.json`, which cards are due, and how a quiz or a review changes the state. Pure.
3
+ import { z } from "zod";
4
+ import { QUIZ_CONCEPTS, QuizItemSchema } from "./ai-schemas.js";
5
+ import { isComplete, qualityFor } from "./quiz-session.js";
6
+ import { STATE_LIMITS, serializeState } from "./seance-state.js";
7
+ import { newCard, nextReview } from "./sm2.js";
8
+ import { fnv1a32 } from "./structural-questions.js";
9
+ import { isExcludedPath } from "./sync-changes.js";
10
+ /** Most cards one `seance review` run asks about. */
11
+ export const MAX_REVIEW_PER_SESSION = 20;
12
+ /** Most files `seance quiz` reads when there is no pending quiz. */
13
+ export const MAX_QUIZ_FILES = 50;
14
+ const MAX_COUNT = 100_000;
15
+ const DATE = /^\d{4}-\d{2}-\d{2}$/;
16
+ /** True for a real calendar date written YYYY-MM-DD (2026-02-30 is not). */
17
+ function isRealDate(value) {
18
+ if (!DATE.test(value))
19
+ return false;
20
+ const [year = 0, month = 1, day = 1] = value.split("-").map(Number);
21
+ return new Date(Date.UTC(year, month - 1, day)).toISOString().slice(0, 10) === value;
22
+ }
23
+ const dateSchema = z.string().refine(isRealDate, { message: "not a calendar date" });
24
+ /** Checks a stored card: the SM-2 fields as in `seance-state.ts`, plus the Task 7 fields. Unknown keys survive. */
25
+ export const ReviewCardSchema = z.looseObject({
26
+ ease: z.number().min(1.3),
27
+ interval: z.int().min(0).max(365),
28
+ repetitions: z.int().min(0),
29
+ dueAt: dateSchema,
30
+ concept: z.enum(QUIZ_CONCEPTS),
31
+ question: QuizItemSchema,
32
+ addedAt: dateSchema,
33
+ reviews: z.int().min(0).max(MAX_COUNT),
34
+ });
35
+ export const QuizProgressSchema = z.looseObject({
36
+ attempts: z.int().min(0).max(MAX_COUNT).default(0),
37
+ lastResult: z
38
+ .object({
39
+ at: z.iso.datetime(),
40
+ score: z.number().min(0).max(1),
41
+ understood: z.boolean(),
42
+ source: z.enum(["offline", "local-ai", "hosted", "structural"]),
43
+ })
44
+ .optional(),
45
+ });
46
+ /** The progress of a pending quiz; `{ attempts: 0 }` when there is none or its progress fields are invalid. */
47
+ export function readProgress(pending) {
48
+ if (pending === undefined)
49
+ return { attempts: 0 };
50
+ const parsed = QuizProgressSchema.safeParse(pending);
51
+ if (!parsed.success)
52
+ return { attempts: 0 };
53
+ const { attempts, lastResult } = parsed.data;
54
+ return lastResult === undefined ? { attempts } : { attempts, lastResult };
55
+ }
56
+ /** The trimmed text of the correct choice, or "" for an explain question. Not the index, so a reshuffle does not change it. */
57
+ function correctAnswerText(item) {
58
+ const { choices, answerIndex } = item; // an explain question has neither
59
+ if (choices === undefined || answerIndex === undefined)
60
+ return "";
61
+ return (choices[answerIndex] ?? "").replace(/\s+/g, " ").trim();
62
+ }
63
+ /**
64
+ * `{concept}:{8 hex}` from the path, kind, prompt and correct answer text (not the id, which repeats across AI quizzes, and
65
+ * not the choice order). The answer is part of the key since Dec 2 (changed after review): the same prompt with another
66
+ * correct answer is another question. An explain question has no answer text, so its key is the same as before.
67
+ */
68
+ export function cardKey(item) {
69
+ const answer = correctAnswerText(item);
70
+ const text = `${item.source?.path ?? ""}\n${item.kind}\n${item.prompt}${answer === "" ? "" : `\n${answer}`}`;
71
+ return `${item.concept}:${fnv1a32(text).toString(16).padStart(8, "0")}`;
72
+ }
73
+ /**
74
+ * `{concept}|{prompt with whitespace collapsed}|{correct answer text}`: two questions with the same value are the same
75
+ * question for review (changed Dec 2 after manual test: the same prompt came back as a second card because its source
76
+ * line or kind differed). The correct answer is part of the key (changed Dec 2 after review): "Which function calls
77
+ * `save`?" asked about two different files has two answers and needs two cards. An explain question has no choice, so its
78
+ * answer part is empty. The text is the trimmed choice, so a reshuffled choice order gives the same key.
79
+ */
80
+ export function promptKey(item) {
81
+ return `${item.concept}|${item.prompt.replace(/\s+/g, " ").trim()}|${correctAnswerText(item)}`;
82
+ }
83
+ /** The seed of a quiz: from the pending quiz id, else from the picked paths. */
84
+ export function quizSeed(pending, paths) {
85
+ if (pending !== undefined) {
86
+ const seed = Number.parseInt(pending.id.slice(5), 16);
87
+ if (Number.isFinite(seed))
88
+ return seed;
89
+ }
90
+ return fnv1a32(paths.join("\n"));
91
+ }
92
+ const QUIZ_EXTENSIONS = new Set([".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts"]);
93
+ function extensionOf(path) {
94
+ const base = path.slice(path.lastIndexOf("/") + 1);
95
+ const dot = base.lastIndexOf(".");
96
+ return dot > 0 ? base.slice(dot).toLowerCase() : "";
97
+ }
98
+ /** JS and TS paths that are not excluded, unique, sorted by UTF-16 and cut to 50. */
99
+ export function pickQuizFiles(paths) {
100
+ const kept = [...new Set(paths)].filter((path) => QUIZ_EXTENSIONS.has(extensionOf(path)) && !isExcludedPath(path));
101
+ kept.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
102
+ return kept.slice(0, MAX_QUIZ_FILES);
103
+ }
104
+ function utf8Bytes(text) {
105
+ return new TextEncoder().encode(text).length;
106
+ }
107
+ /** The card stored under a key, when it passes `ReviewCardSchema`. */
108
+ function validCard(cards, key) {
109
+ if (!Object.hasOwn(cards, key))
110
+ return undefined;
111
+ const parsed = ReviewCardSchema.safeParse(cards[key]);
112
+ return parsed.success ? parsed.data : undefined;
113
+ }
114
+ /**
115
+ * The state after a quiz. Missed questions without a card become new cards (rated from the answer); a question whose
116
+ * key has a valid card updates it; correct answers never add a card. The input state is not changed.
117
+ */
118
+ export function applyQuizResult(state, record) {
119
+ if (!isComplete(record.session))
120
+ throw new RangeError("the quiz is not complete");
121
+ const cards = { ...state.cards };
122
+ const next = { ...state, cards };
123
+ const pending = state.pendingQuiz;
124
+ if (pending !== undefined && record.quizId !== null && pending.id === record.quizId) {
125
+ next.pendingQuiz = {
126
+ ...pending,
127
+ attempts: Math.min(MAX_COUNT, readProgress(pending).attempts + 1),
128
+ lastResult: { at: record.at, score: record.summary.result.score, understood: record.summary.gate.understood, source: record.source },
129
+ };
130
+ }
131
+ const added = [];
132
+ const updated = [];
133
+ let notAdded = 0;
134
+ const handled = new Set();
135
+ // The card each question text already has. A new card is never added for such a question: the existing card is updated instead.
136
+ const keyByPrompt = new Map();
137
+ for (const existing of Object.keys(cards)) {
138
+ const card = validCard(cards, existing);
139
+ if (card !== undefined && !keyByPrompt.has(promptKey(card.question)))
140
+ keyByPrompt.set(promptKey(card.question), existing);
141
+ }
142
+ record.session.questions.forEach((item, index) => {
143
+ const outcome = record.session.outcomes[index];
144
+ const key = keyByPrompt.get(promptKey(item)) ?? cardKey(item);
145
+ if (outcome === undefined || handled.has(key))
146
+ return;
147
+ handled.add(key);
148
+ const quality = qualityFor(outcome);
149
+ if (Object.hasOwn(cards, key)) {
150
+ const card = validCard(cards, key);
151
+ if (card === undefined)
152
+ return; // an invalid card is left alone
153
+ const moved = { ...card, ...nextReview(card, quality, record.today), reviews: card.reviews + 1 };
154
+ cards[key] = moved;
155
+ updated.push(key);
156
+ return;
157
+ }
158
+ if (quality >= 3)
159
+ return;
160
+ const candidate = { ...nextReview(newCard(record.today), quality, record.today), concept: item.concept, question: item, addedAt: record.today, reviews: 0 };
161
+ if (Object.keys(cards).length >= STATE_LIMITS.maxCards) {
162
+ notAdded += 1;
163
+ return;
164
+ }
165
+ cards[key] = candidate;
166
+ if (utf8Bytes(serializeState(next)) > STATE_LIMITS.maxBytes) {
167
+ delete cards[key];
168
+ notAdded += 1;
169
+ return;
170
+ }
171
+ keyByPrompt.set(promptKey(item), key);
172
+ added.push(key);
173
+ });
174
+ return { state: next, added, updated, notAdded };
175
+ }
176
+ function compareText(a, b) {
177
+ return a < b ? -1 : a > b ? 1 : 0;
178
+ }
179
+ /** Valid cards due on or before `today`, oldest first (then by key), at most `limit`. `invalid` counts every entry that fails `ReviewCardSchema`. */
180
+ export function dueCards(cards, today, limit = MAX_REVIEW_PER_SESSION) {
181
+ const due = [];
182
+ let invalid = 0;
183
+ for (const key of Object.keys(cards)) {
184
+ const card = validCard(cards, key);
185
+ if (card === undefined)
186
+ invalid += 1;
187
+ else if (card.dueAt <= today)
188
+ due.push({ key, card });
189
+ }
190
+ due.sort((a, b) => compareText(a.card.dueAt, b.card.dueAt) || compareText(a.key, b.key));
191
+ return { due: due.slice(0, Math.max(0, limit)), invalid };
192
+ }
193
+ /** The earliest `dueAt` of a valid card, or undefined when there is none. */
194
+ export function nextDueDate(cards) {
195
+ let earliest;
196
+ for (const key of Object.keys(cards)) {
197
+ const card = validCard(cards, key);
198
+ if (card !== undefined && (earliest === undefined || card.dueAt < earliest))
199
+ earliest = card.dueAt;
200
+ }
201
+ return earliest;
202
+ }
203
+ /** The state after a review: each reviewed card moves on by its quality. A key that is missing or invalid is ignored. */
204
+ export function applyReviewResult(state, reviews, today) {
205
+ const cards = { ...state.cards };
206
+ for (const { key, outcome } of reviews) {
207
+ const card = validCard(cards, key);
208
+ if (card === undefined)
209
+ continue;
210
+ const moved = { ...card, ...nextReview(card, qualityFor(outcome), today), reviews: card.reviews + 1 };
211
+ cards[key] = moved;
212
+ }
213
+ return { ...state, cards };
214
+ }
215
+ //# sourceMappingURL=quiz-cards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quiz-cards.js","sourceRoot":"","sources":["../src/quiz-cards.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,mHAAmH;AACnH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAmC,MAAM,iBAAiB,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,UAAU,EAA2E,MAAM,mBAAmB,CAAC;AACpI,OAAO,EAAE,YAAY,EAAE,cAAc,EAAsC,MAAM,mBAAmB,CAAC;AACrG,OAAO,EAAE,OAAO,EAAE,UAAU,EAAa,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qDAAqD;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AACjC,MAAM,SAAS,GAAG,OAAO,CAAC;AAC1B,MAA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KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC;YAAE,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC;IACrG,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAOD,yHAAyH;AACzH,MAAM,UAAU,iBAAiB,CAAC,KAAkB,EAAE,OAAiC,EAAE,KAAa;IACpG,MAAM,KAAK,GAAyB,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IACvD,KAAK,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,OAAO,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,SAAS;YAAE,SAAS;QACjC,MAAM,KAAK,GAAe,EAAE,GAAG,IAAI,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;QAClH,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { type QuizItem } from "./ai-schemas.js";
2
+ import { type GateMode, type GateResult } from "./gate.js";
3
+ import { type QuizResult } from "./scoring.js";
4
+ import type { Quality } from "./sm2.js";
5
+ /** Where a quiz comes from. `hosted` (Task 8) is the Seance API. */
6
+ export type QuizSource = "offline" | "local-ai" | "hosted" | "structural";
7
+ /** `--offline` wins; else the user's own provider keys; else the hosted API when its URL is set; else structural questions only. */
8
+ export declare function pickQuizSource(input: {
9
+ offline: boolean;
10
+ providerCount: number;
11
+ hostedUrl?: URL;
12
+ }): QuizSource;
13
+ /** One answered question. `rough` marks a keyword grade. */
14
+ export type AnswerOutcome = {
15
+ questionId: string;
16
+ kind: "choice";
17
+ choiceIndex: number;
18
+ correct: boolean;
19
+ } | {
20
+ questionId: string;
21
+ kind: "graded";
22
+ score: number;
23
+ rough: boolean;
24
+ };
25
+ export interface QuizSession {
26
+ readonly questions: readonly QuizItem[];
27
+ readonly outcomes: readonly AnswerOutcome[];
28
+ }
29
+ /** Starts a session. Throws RangeError for 0 or more than 10 questions, a repeated id or an item that fails `QuizItemSchema`. */
30
+ export declare function startSession(questions: readonly QuizItem[]): QuizSession;
31
+ export declare function isComplete(session: QuizSession): boolean;
32
+ /** The question to ask next, or undefined when every question has an answer. */
33
+ export declare function currentQuestion(session: QuizSession): QuizItem | undefined;
34
+ /** Records the answer to the current choice question. Throws RangeError when complete, for an explain question or an index outside the choices. */
35
+ export declare function answerChoice(session: QuizSession, choiceIndex: number): {
36
+ session: QuizSession;
37
+ correct: boolean;
38
+ correctIndex: number;
39
+ };
40
+ /** Records the grade of the current explain question. Throws RangeError when complete, for a choice question or a score outside [0, 1]. */
41
+ export declare function answerGraded(session: QuizSession, score: number, rough: boolean): QuizSession;
42
+ /** SM-2 quality of one answer: choice right 4, wrong 1; explain by score. Below 3 means the question was missed. */
43
+ export declare function qualityFor(outcome: AnswerOutcome): Quality;
44
+ export interface QuizSummary {
45
+ result: QuizResult;
46
+ gate: GateResult;
47
+ passMark: number;
48
+ mode: GateMode;
49
+ /** Missed questions in question order (quality below 3). */
50
+ missed: QuizItem[];
51
+ }
52
+ /** Scores a finished session and applies the gate. Throws RangeError when a question has no answer yet. */
53
+ export declare function finishSession(session: QuizSession, gate: {
54
+ mode: GateMode;
55
+ passMark: number;
56
+ }): QuizSummary;
57
+ /**
58
+ * The same question with its choices in another order for each `attempt`, so a retake cannot be passed by position.
59
+ * Attempt 0 and explain questions are returned unchanged. Indexes are tracked, so equal choice texts are safe.
60
+ */
61
+ export declare function reorderChoices(item: QuizItem, attempt: number): QuizItem;
62
+ /** The result lines printed after a quiz (design "Output"). `cards` says what `applyQuizResult` did. */
63
+ export declare function formatQuizResult(summary: QuizSummary, cards: {
64
+ added: number;
65
+ notAdded: number;
66
+ firstReview?: string;
67
+ }): string[];