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,161 @@
1
+ // The questions of `seance init`: which answer each checklist item gets with `--yes`, and how a person is asked.
2
+ // Everything goes through a Prompter, so tests script the answers and nothing here needs a terminal.
3
+ import { CHECKLIST, cleanAnswerText, evaluateChecklist } from "@seance/core";
4
+ const GATE_CHOICES = [
5
+ { value: "strict", name: "strict", description: "block the next task until the last quiz is passed (recommended)" },
6
+ { value: "soft", name: "soft", description: "show a warning when the quiz is failed, but let you continue" },
7
+ { value: "off", name: "off", description: "no gate" },
8
+ ];
9
+ // Values of menu entries that are not answers.
10
+ const ASK_SUGGESTIONS = "__suggest__";
11
+ const ASK_OTHER = "__other__";
12
+ const DECIDE_LATER = "__later__";
13
+ const undecided = () => ({ value: "", source: "undecided" });
14
+ /** Stores an answer; an item that was left empty (undefined) is not stored. */
15
+ function setAnswer(answers, id, answer) {
16
+ if (answer !== undefined)
17
+ answers[id] = answer;
18
+ }
19
+ /** A stored answer counts only when it is not `undecided`. */
20
+ function answeredOnly(answer) {
21
+ return answer === undefined || answer.source === "undecided" ? undefined : answer;
22
+ }
23
+ /** The value `detectProject` found for a checklist item, if any. */
24
+ function detectedValue(detected, id) {
25
+ switch (id) {
26
+ case "projectName":
27
+ return detected.projectName;
28
+ case "description":
29
+ return detected.description;
30
+ case "language":
31
+ return detected.language;
32
+ case "framework":
33
+ return detected.framework;
34
+ case "packageManager":
35
+ return detected.packageManager;
36
+ case "testRunner":
37
+ return detected.testRunner;
38
+ default:
39
+ return undefined;
40
+ }
41
+ }
42
+ /** The value offered as the default: stored answer, else detected (if allowed), else the item's fixed default. */
43
+ function defaultAnswer(item, known, useDetected = true) {
44
+ const stored = answeredOnly(known.stored[item.id]);
45
+ if (stored !== undefined)
46
+ return stored;
47
+ const found = useDetected ? detectedValue(known.detected, item.id) : undefined;
48
+ if (found !== undefined && found !== "")
49
+ return { value: found, source: "detected" };
50
+ if (item.default !== undefined)
51
+ return { value: item.default, source: "default" };
52
+ return undefined;
53
+ }
54
+ /**
55
+ * `--yes`: per item the flag, else the stored answer, else the detected value, else the default, else nothing (1.3).
56
+ * The detected description is never used (open question 46): it stays undecided unless `--description` is given.
57
+ */
58
+ export function answersWithoutQuestions(known) {
59
+ const answers = {};
60
+ for (const item of CHECKLIST) {
61
+ setAnswer(answers, item.id, known.flags[item.id] ?? defaultAnswer(item, known, item.id !== "description"));
62
+ }
63
+ return answers;
64
+ }
65
+ /** Items nobody answered: a required one is recorded as undecided (so the generated files list it), an optional one is left out. */
66
+ export function withUndecided(answers) {
67
+ const complete = {};
68
+ for (const item of CHECKLIST)
69
+ setAnswer(complete, item.id, answers[item.id] ?? (item.required ? undecided() : undefined));
70
+ return complete;
71
+ }
72
+ /** Asks every item (a flag answers its own item), then the gate mode, then the missing required items once more (2.5). */
73
+ export async function askEverything(known, gateFlag, gateDefault, out) {
74
+ const answers = {};
75
+ for (const item of CHECKLIST)
76
+ setAnswer(answers, item.id, known.flags[item.id] ?? (await askItem(item, known)));
77
+ const gateMode = gateFlag ?? (await known.prompter.select({ id: "gate", message: "Learning gate mode?", choices: GATE_CHOICES, default: gateDefault }));
78
+ const first = evaluateChecklist(answers);
79
+ if (!first.complete) {
80
+ out(`Checklist ${first.percent}%: missing ${first.missingRequired.join(", ")}`);
81
+ for (const id of first.missingRequired) {
82
+ const item = CHECKLIST.find((candidate) => candidate.id === id);
83
+ if (item !== undefined)
84
+ setAnswer(answers, id, await askItem(item, known));
85
+ }
86
+ }
87
+ return { answers, gateMode };
88
+ }
89
+ /** Keeps the source of the default when the user accepts it unchanged, so a re-run does not change the config. */
90
+ function answerFor(fallback, value) {
91
+ return { value, source: fallback !== undefined && fallback.value === value ? fallback.source : "user" };
92
+ }
93
+ /** Asks one checklist item. Returns undefined for an optional item the user left empty. */
94
+ function askItem(item, known) {
95
+ return item.kind === "text" ? askText(item, known) : askChoice(item, known);
96
+ }
97
+ /** The hint after a text question: how to ask for suggestions or decide later. */
98
+ function textHint(item) {
99
+ if (item.suggestions !== undefined)
100
+ return " (type ? if you don't know)";
101
+ return item.decideLater ? " (type ? to decide later)" : "";
102
+ }
103
+ /** A text question. `?` opens the suggestions or means "decide later", when the item offers it. */
104
+ async function askText(item, known) {
105
+ const fallback = defaultAnswer(item, known);
106
+ const raw = await known.prompter.text({ id: item.id, message: item.question + textHint(item), default: fallback?.value, maxLength: item.maxLength });
107
+ if ((item.suggestions !== undefined || item.decideLater) && raw.trim() === "?") {
108
+ return item.suggestions !== undefined ? askSuggestions(item, known) : undecided();
109
+ }
110
+ const value = cleanAnswerText(raw, item.maxLength);
111
+ if (value === "")
112
+ return item.required ? undecided() : undefined;
113
+ return answerFor(fallback, value);
114
+ }
115
+ /** The menu of a choice question: its values, then "Other" and "I don't know" when the item offers them. */
116
+ function choiceMenu(item) {
117
+ const choices = (item.choices ?? []).map((value) => ({ value, name: value }));
118
+ if (item.allowOther === true)
119
+ choices.push({ value: ASK_OTHER, name: "Other (type your own)" });
120
+ if (item.suggestions !== undefined)
121
+ choices.push({ value: ASK_SUGGESTIONS, name: "I don't know, suggest options" });
122
+ return choices;
123
+ }
124
+ /** A choice question (a menu). "Other" opens a second text prompt; "I don't know" opens the suggestions. */
125
+ async function askChoice(item, known) {
126
+ const fallback = defaultAnswer(item, known);
127
+ const inMenu = fallback !== undefined && (item.choices ?? []).includes(fallback.value);
128
+ // Which menu entry is pre-selected: the default itself, "Other" when the default is a free-text value, else none.
129
+ let menuDefault;
130
+ if (inMenu)
131
+ menuDefault = fallback.value;
132
+ else if (item.allowOther === true && fallback !== undefined)
133
+ menuDefault = ASK_OTHER;
134
+ const picked = await known.prompter.select({ id: item.id, message: item.question, choices: choiceMenu(item), default: menuDefault });
135
+ if (picked === ASK_SUGGESTIONS)
136
+ return askSuggestions(item, known);
137
+ if (picked !== ASK_OTHER)
138
+ return answerFor(fallback, picked);
139
+ const raw = await known.prompter.text({
140
+ id: `${item.id}-other`,
141
+ message: `${item.question} (your own)`,
142
+ default: fallback !== undefined && !inMenu ? fallback.value : undefined,
143
+ maxLength: item.maxLength,
144
+ });
145
+ const value = cleanAnswerText(raw, item.maxLength);
146
+ return value === "" ? undecided() : answerFor(fallback, value);
147
+ }
148
+ /** The "I don't know" screen: the item's suggestions with their reasons, then "Decide later". */
149
+ async function askSuggestions(item, known) {
150
+ const suggestions = item.suggestions ?? [];
151
+ const choices = suggestions.map((suggestion, index) => ({
152
+ value: String(index),
153
+ name: index === 0 ? `${suggestion.label} (recommended)` : suggestion.label,
154
+ description: suggestion.reason,
155
+ }));
156
+ choices.push({ value: DECIDE_LATER, name: "Decide later" });
157
+ const picked = await known.prompter.select({ id: `${item.id}-suggestions`, message: `${item.question} Suggestions:`, choices });
158
+ const chosen = picked === DECIDE_LATER ? undefined : suggestions[Number(picked)];
159
+ return chosen === undefined ? undecided() : { value: chosen.value, source: "suggested" };
160
+ }
161
+ //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AO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { ToolReply } from "@seance/core";
2
+ import { type GitRunner } from "./git.js";
3
+ import { type WriteOps } from "./init-fs.js";
4
+ export interface McpDeps {
5
+ cwd: string;
6
+ err: (line: string) => void;
7
+ now: () => Date;
8
+ randomId: () => string;
9
+ git?: GitRunner;
10
+ fs?: Partial<WriteOps>;
11
+ }
12
+ export interface McpHandlers {
13
+ getProjectContext(): Promise<ToolReply>;
14
+ getDueReviews(): Promise<ToolReply>;
15
+ getDecisions(input: {
16
+ count?: number;
17
+ }): Promise<ToolReply>;
18
+ startQuiz(): Promise<ToolReply>;
19
+ submitAnswer(input: unknown): Promise<ToolReply>;
20
+ }
21
+ /** Creates the handlers for one project folder. `root` is already resolved (`resolveRoot`). */
22
+ export declare function createMcpHandlers(root: string, deps: McpDeps): McpHandlers;
@@ -0,0 +1,185 @@
1
+ // The five tools of `seance mcp` as plain async functions (Task 11): they read files in the project folder, keep quiz sessions
2
+ // in memory and save one `.seance/state.json` write per finished quiz. They never touch the MCP SDK, never use the network
3
+ // and never write to stdout. Pure decisions are in @seance/core (mcp-quiz, mcp-views, mcp-tools).
4
+ import { readChainConfig } from "@seance/ai";
5
+ import { BLANK_ANSWER_FEEDBACK, DECISIONS_PATH, DECISION_LIMITS, MCP_LIMITS, QUIZ_ID_PATTERN, STATE_PATH, SubmitAnswerInputSchema, applyQuizResult, currentQuestion, decisionsView, dueReviewsView, emptyStore, finishSession, findQuiz, formatMapSummary, formatQuizResult, isBlankAnswer, mcpError, openQuiz, parseDecisionLog, pickQuizFiles, projectContextView, pruneStore, quizSeed, readProgress, reorderChoices, shownQuestionId, submitAnswer, toPlainText, toolText, } from "@seance/core";
6
+ import { createGitRunner } from "./git.js";
7
+ import { errorCode, readExisting } from "./init-fs.js";
8
+ import { createBackend } from "./quiz-backend.js";
9
+ import { choosePaths, readMap, usable } from "./quiz-input.js";
10
+ import { readGate, readState, saveWithRetry } from "./quiz-io.js";
11
+ import { isSafeRelativePath, localDate } from "./quiz-ui.js";
12
+ const HOW = "Ask the user this question and show its choices with the numbers from the choices list. Then call submit_answer with choiceNumber (the number the user picked, as shown, starting at 1) or choiceText (the exact text of the choice), or with text for an explain question. Never subtract 1.";
13
+ const NO_PENDING = "no pending quiz; run seance sync after a change";
14
+ const NOTHING_TO_QUIZ = "nothing to quiz on (no readable JS or TS files)";
15
+ /** Creates the handlers for one project folder. `root` is already resolved (`resolveRoot`). */
16
+ export function createMcpHandlers(root, deps) {
17
+ let store = emptyStore();
18
+ // Quiz calls run one after another, so two answers to the same quiz cannot interleave and each finished quiz is saved alone.
19
+ let queue = Promise.resolve();
20
+ const serial = (task) => {
21
+ const run = queue.then(task, task);
22
+ queue = run.catch(() => undefined);
23
+ return run;
24
+ };
25
+ const nowMs = () => deps.now().getTime();
26
+ const backend = createBackend("offline", { config: readChainConfig({}) }); // no providers: keyword grading and structural questions only
27
+ /** Runs a tool, turns a throw into the `internal` error and writes the one stderr line (tool, ok or error code, ms). */
28
+ async function run(tool, task) {
29
+ const started = nowMs();
30
+ let reply;
31
+ let errorName = "";
32
+ try {
33
+ reply = await task();
34
+ }
35
+ catch (error) {
36
+ reply = mcpError("internal");
37
+ errorName = ` (${error instanceof Error ? toPlainText(error.name, { maxChars: 40 }) : "Error"})`;
38
+ }
39
+ deps.err(`seance mcp: ${tool} ${reply.ok ? "ok" : reply.code} ${Math.max(0, nowMs() - started)}ms${errorName}`);
40
+ return reply;
41
+ }
42
+ async function readProject() {
43
+ const found = await readExisting(root, "PROJECT.md", MCP_LIMITS.maxProjectReadBytes);
44
+ return found?.type === "file" ? found.content : undefined;
45
+ }
46
+ const getProjectContext = () => run("get_project_context", async () => {
47
+ const read = await readState(root);
48
+ const projectText = await readProject();
49
+ let summary = [];
50
+ const pending = read.ok ? read.state.pendingQuiz : undefined;
51
+ if (pending !== undefined) {
52
+ const paths = pickQuizFiles(pending.files.filter(isSafeRelativePath));
53
+ summary = formatMapSummary((await readMap(root, paths)).map);
54
+ }
55
+ return projectContextView({ projectText, state: read.ok ? read.state : undefined, summary, today: localDate(deps.now()) });
56
+ });
57
+ const getDueReviews = () => run("get_due_reviews", async () => {
58
+ const read = await readState(root);
59
+ if (!read.ok)
60
+ return mcpError("state-invalid");
61
+ return dueReviewsView(read.state.cards, localDate(deps.now()));
62
+ });
63
+ const getDecisions = (input) => run("get_decisions", async () => {
64
+ const found = await readExisting(root, DECISIONS_PATH, DECISION_LIMITS.maxFileBytes);
65
+ const log = found?.type === "file" ? parseDecisionLog(found.content) : undefined;
66
+ return decisionsView(log, input.count);
67
+ });
68
+ const startQuiz = () => serial(() => run("start_quiz", async () => {
69
+ const read = await readState(root);
70
+ if (!read.ok)
71
+ return mcpError("state-invalid");
72
+ const pending = read.state.pendingQuiz;
73
+ const paths = await choosePaths(deps.git ?? createGitRunner(root), pending?.files);
74
+ if (paths === undefined)
75
+ return toolText({ quizId: null, note: NO_PENDING });
76
+ const { map, files } = await readMap(root, paths);
77
+ const parsed = map.files.filter((file) => file.parsed).length;
78
+ const seed = quizSeed(pending, paths);
79
+ const attempt = readProgress(pending).attempts;
80
+ let questions = [];
81
+ if (parsed > 0)
82
+ questions = usable((await backend.makeQuiz({ map, files, seed, attempt })).questions);
83
+ if (questions.length === 0)
84
+ questions = usable((pending?.questions ?? []).map((item) => reorderChoices(item, attempt)));
85
+ if (questions.length === 0)
86
+ return toolText({ quizId: null, note: NOTHING_TO_QUIZ });
87
+ const id = deps.randomId();
88
+ if (!QUIZ_ID_PATTERN.test(id))
89
+ throw new RangeError("bad quiz id");
90
+ const opened = openQuiz(store, { id, nowMs: nowMs(), questions, pendingId: pending?.id ?? null, attempt });
91
+ store = opened.store;
92
+ return toolText({
93
+ quizId: id,
94
+ questionCount: questions.length,
95
+ summary: parsed > 0 ? formatMapSummary(map) : [],
96
+ question: opened.first,
97
+ how: HOW,
98
+ });
99
+ }));
100
+ /** Scores a finished quiz and saves it once. Never throws for a save problem: `saved: false` and a fixed note. */
101
+ async function finish(finished) {
102
+ const gate = await readGate(root);
103
+ const summary = finishSession(finished.session, { mode: gate.mode, passMark: gate.passMark });
104
+ const now = deps.now();
105
+ const record = {
106
+ quizId: finished.pendingId,
107
+ summary,
108
+ session: finished.session,
109
+ today: localDate(now),
110
+ at: now.toISOString(),
111
+ source: "offline",
112
+ };
113
+ const holder = {};
114
+ let saved = false;
115
+ let note;
116
+ const read = await readState(root);
117
+ if (!read.ok) {
118
+ note = "state-invalid";
119
+ }
120
+ else {
121
+ try {
122
+ const outcome = await saveWithRetry(root, read, (state) => {
123
+ holder.applied = applyQuizResult(state, record);
124
+ return holder.applied.state;
125
+ }, deps.fs);
126
+ if (outcome === "written")
127
+ saved = true;
128
+ else
129
+ note = "changed during the quiz";
130
+ }
131
+ catch (error) {
132
+ note = `could not write ${STATE_PATH}: ${toPlainText(errorCode(error), { maxChars: 40 })}`;
133
+ }
134
+ }
135
+ const applied = saved ? holder.applied : undefined;
136
+ const dates = (applied?.added ?? []).map((key) => applied?.state.cards[key]?.dueAt).filter((date) => date !== undefined);
137
+ const firstReview = dates.length === 0 ? null : dates.reduce((a, b) => (a < b ? a : b));
138
+ const cards = { added: applied?.added.length ?? 0, notAdded: applied?.notAdded ?? 0 };
139
+ return {
140
+ score: Math.round(summary.result.score * 100),
141
+ passMark: Math.round(summary.passMark * 100),
142
+ gateLine: formatQuizResult(summary, cards)[1] ?? "",
143
+ missedConcepts: summary.result.missedConcepts.map((concept) => toPlainText(concept)),
144
+ cardsAdded: cards.added,
145
+ cardsNotAdded: cards.notAdded,
146
+ firstReview,
147
+ saved,
148
+ ...(note === undefined ? {} : { note }),
149
+ };
150
+ }
151
+ /** The keyword grade for an explain answer to the current question; undefined when the call needs none (the pure function then checks it). */
152
+ async function gradeIfExplain(quiz, input) {
153
+ const current = quiz === undefined ? undefined : currentQuestion(quiz.session);
154
+ if (quiz === undefined || current?.kind !== "explain")
155
+ return undefined;
156
+ if (input.questionId !== shownQuestionId(quiz.session.outcomes.length + 1))
157
+ return undefined;
158
+ if (input.text === undefined || input.choiceNumber !== undefined || input.choiceText !== undefined)
159
+ return undefined;
160
+ // A blank answer scores 0 without a backend call (changed Dec 2 after manual test).
161
+ if (isBlankAnswer(input.text))
162
+ return { score: 0, feedback: BLANK_ANSWER_FEEDBACK };
163
+ const graded = await backend.grade(current, input.text);
164
+ return { score: graded.score, feedback: graded.feedback };
165
+ }
166
+ const submit = (rawInput) => serial(() => run("submit_answer", async () => {
167
+ const parsedInput = SubmitAnswerInputSchema.safeParse(rawInput);
168
+ if (!parsedInput.success)
169
+ return mcpError("invalid-input");
170
+ const input = parsedInput.data;
171
+ const at = nowMs();
172
+ store = pruneStore(store, at);
173
+ const grade = await gradeIfExplain(findQuiz(store, input.quizId), input);
174
+ const result = submitAnswer(store, { ...input, ...(grade === undefined ? {} : { grade }) }, at);
175
+ if (result.type === "error")
176
+ return mcpError(result.code, result.currentId);
177
+ // The store changes only after the finish step returned, so a throw there leaves the quiz at its last question for a retry.
178
+ const final = result.finished === undefined ? undefined : await finish(result.finished);
179
+ store = result.store;
180
+ const shown = { quizId: input.quizId, questionId: input.questionId, result: result.reveal, next: result.next };
181
+ return toolText(final === undefined ? shown : { ...shown, final });
182
+ }));
183
+ return { getProjectContext, getDueReviews, getDecisions, startQuiz, submitAnswer: submit };
184
+ }
185
+ //# sourceMappingURL=mcp-handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-handlers.js","sourceRoot":"","sources":["../src/mcp-handlers.ts"],"names":[],"mappings":"AAAA,+HAA+H;AAC/H,2HAA2H;AAC3H,kGAAkG;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,UAAU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E,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC/G,OAAO,QAAQ,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACrE,CAAC,CAAC,CACH,CAAC;IACJ,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;AAC7F,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { McpHandlers } from "./mcp-handlers.js";
3
+ /** Builds the server (not connected). `version` is the CLI's version. */
4
+ export declare function createSeanceMcpServer(handlers: McpHandlers, version: string): McpServer;
@@ -0,0 +1,39 @@
1
+ // The MCP server of `seance mcp` (Task 11): registers the five tools with their strict input schemas and maps each handler's
2
+ // ToolReply to an MCP tool result. The handlers hold all the logic; this file only knows the SDK. It writes nothing itself.
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { EmptyInputSchema, GetDecisionsInputSchema, MCP_LIMITS, SubmitAnswerInputSchema } from "@seance/core";
5
+ /** An MCP tool result: one text item, and `isError` for an error reply (its text is one of the fixed messages). */
6
+ function toResult(reply) {
7
+ return reply.ok ? { content: [{ type: "text", text: reply.text }] } : { content: [{ type: "text", text: reply.text }], isError: true };
8
+ }
9
+ /** Builds the server (not connected). `version` is the CLI's version. */
10
+ export function createSeanceMcpServer(handlers, version) {
11
+ const server = new McpServer({ name: "seance", version }, { maxToolInputElements: MCP_LIMITS.maxToolInputElements });
12
+ server.registerTool("get_project_context", {
13
+ description: "Returns the project's PROJECT.md, the last sync time, the files of the pending quiz with a structure summary, and how many review cards are due.",
14
+ inputSchema: EmptyInputSchema,
15
+ annotations: { readOnlyHint: true },
16
+ }, async () => toResult(await handlers.getProjectContext()));
17
+ server.registerTool("get_due_reviews", {
18
+ description: "Lists the review cards due today (concepts the developer missed before). Read-only; the developer reviews them with `seance review` in a terminal.",
19
+ inputSchema: EmptyInputSchema,
20
+ annotations: { readOnlyHint: true },
21
+ }, async () => toResult(await handlers.getDueReviews()));
22
+ server.registerTool("get_decisions", {
23
+ description: "Returns the latest entries of DECISIONS.md (what was built, what was chosen and why), newest first. `count` is 1 to 10, default 3.",
24
+ inputSchema: GetDecisionsInputSchema,
25
+ annotations: { readOnlyHint: true },
26
+ }, async (input) => toResult(await handlers.getDecisions(input)));
27
+ server.registerTool("start_quiz", {
28
+ description: "Starts a quiz on the latest change and returns the first question. Questions come from the code structure; answers stay on the server until you submit one.",
29
+ inputSchema: EmptyInputSchema,
30
+ }, async () => toResult(await handlers.startQuiz()));
31
+ server.registerTool("submit_answer", {
32
+ description: "Submits the user's answer to the current question: choiceNumber (1-based, the number shown next to the choice) or choiceText (the exact choice text) for a choice question, text for an explain question. Do not send a 0-based index. Returns the result, the next question and, after the last answer, the score.",
33
+ // Loose on purpose (changed Dec 2 after review): the SDK would answer an unknown key such as `choiceIndex` with its own text.
34
+ // The handler parses with the strict schema and returns the fixed `invalid-input` text, which names `choiceNumber`.
35
+ inputSchema: SubmitAnswerInputSchema.loose(),
36
+ }, async (input) => toResult(await handlers.submitAnswer(input)));
37
+ return server;
38
+ }
39
+ //# sourceMappingURL=mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA,6HAA6H;AAC7H,4HAA4H;AAC5H,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAI9G,mHAAmH;AACnH,S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,QAAQ,CAAC,MAAM,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAC9D,CAAC;IACF,MAAM,CAAC,YAAY,CACjB,YAAY,EACZ;QACE,WAAW,EAAE,6JAA6J;QAC1K,WAAW,EAAE,gBAAgB;KAC9B,EACD,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC,CACjD,CAAC;IACF,MAAM,CAAC,YAAY,CACjB,eAAe,EACf;QACE,WAAW,EAAE,qTAAqT;QAClU,8HAA8H;QAC9H,oHAAoH;QACpH,WAAW,EAAE,uBAAuB,CAAC,KAAK,EAAE;KAC7C,EACD,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAC9D,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,29 @@
1
+ export interface Choice<T extends string> {
2
+ value: T;
3
+ name: string;
4
+ description?: string;
5
+ }
6
+ export interface Prompter {
7
+ text(q: {
8
+ id: string;
9
+ message: string;
10
+ default?: string;
11
+ maxLength: number;
12
+ }): Promise<string>;
13
+ select<T extends string>(q: {
14
+ id: string;
15
+ message: string;
16
+ choices: Choice<T>[];
17
+ default?: T;
18
+ }): Promise<T>;
19
+ }
20
+ /** Thrown by a prompter when the user cancels (Ctrl+C). `runInit` turns it into exit code 130. */
21
+ export declare class PromptCancelled extends Error {
22
+ constructor();
23
+ }
24
+ /**
25
+ * Inquirer rejects with an error named `ExitPromptError` on Ctrl+C. Its classes are not exported by
26
+ * `@inquirer/prompts`, so we match the name (requirements open question 23). Anything else is passed on.
27
+ */
28
+ export declare function mapPromptError(error: unknown): unknown;
29
+ export declare function createInquirerPrompter(): Prompter;
@@ -0,0 +1,42 @@
1
+ // The only place that talks to @inquirer/prompts. `runInit` asks its questions through the `Prompter` interface,
2
+ // so tests pass a scripted prompter and never need a terminal.
3
+ import { input, select } from "@inquirer/prompts";
4
+ /** Thrown by a prompter when the user cancels (Ctrl+C). `runInit` turns it into exit code 130. */
5
+ export class PromptCancelled extends Error {
6
+ constructor() {
7
+ super("prompt cancelled");
8
+ this.name = "PromptCancelled";
9
+ }
10
+ }
11
+ /**
12
+ * Inquirer rejects with an error named `ExitPromptError` on Ctrl+C. Its classes are not exported by
13
+ * `@inquirer/prompts`, so we match the name (requirements open question 23). Anything else is passed on.
14
+ */
15
+ export function mapPromptError(error) {
16
+ return error instanceof Error && error.name === "ExitPromptError" ? new PromptCancelled() : error;
17
+ }
18
+ export function createInquirerPrompter() {
19
+ return {
20
+ async text(q) {
21
+ try {
22
+ return await input({
23
+ message: q.message,
24
+ default: q.default,
25
+ validate: (value) => Array.from(value).length <= q.maxLength || `Please use at most ${q.maxLength} characters.`,
26
+ });
27
+ }
28
+ catch (error) {
29
+ throw mapPromptError(error);
30
+ }
31
+ },
32
+ async select(q) {
33
+ try {
34
+ return await select({ message: q.message, choices: q.choices, default: q.default });
35
+ }
36
+ catch (error) {
37
+ throw mapPromptError(error);
38
+ }
39
+ },
40
+ };
41
+ }
42
+ //# sourceMappingURL=prompter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompter.js","sourceRoot":"","sources":["../src/prompter.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,+DAA+D;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAalD,kGAAkG;AAClG,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC;QACE,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,CAAC,CAAC,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AACpG,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,CAAC;YACV,IAAI,CAAC;gBACH,OAAO,MAAM,KAAK,CAAC;oBACjB,OAAO,EAAE,CAAC,CAAC,OAAO;oBAClB,OAAO,EAAE,CAAC,CAAC,OAAO;oBAClB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,SAAS,IAAI,sBAAsB,CAAC,CAAC,SAAS,cAAc;iBAChH,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,CAAC;YACZ,IAAI,CAAC;gBACH,OAAO,MAAM,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACtF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { type ChainConfig, type ClientFactory } from "@seance/ai";
2
+ import type { DecisionEntry, QuizItem, QuizSource, SourceFile, StructureMap } from "@seance/core";
3
+ import type { HostedApi } from "./hosted-api.js";
4
+ export interface QuizInput {
5
+ map: StructureMap;
6
+ files: SourceFile[];
7
+ seed: number;
8
+ attempt: number;
9
+ /** The latest DECISIONS.md entry (with Chose and Why). Only the backends that send code use it; the structural one ignores it. */
10
+ decision?: DecisionEntry;
11
+ }
12
+ export interface QuizBackend {
13
+ source: QuizSource;
14
+ /** True when making a quiz or grading sends code or answers to another machine. */
15
+ sendsCode: boolean;
16
+ /** The configured provider names (`gemini, nvidia`), or `none`. Never keys or URLs. */
17
+ label: string;
18
+ /** Where code and answers go, for the notice lines: `your AI providers (gemini)` or `the Seance API (host)`; `this computer` when nothing is sent. */
19
+ destination: string;
20
+ makeQuiz(input: QuizInput): Promise<{
21
+ questions: QuizItem[];
22
+ servedBy: string;
23
+ model?: string;
24
+ }>;
25
+ grade(item: QuizItem, answer: string): Promise<{
26
+ score: number;
27
+ feedback: string;
28
+ rough: boolean;
29
+ }>;
30
+ }
31
+ /**
32
+ * Makes the backend for a source. `local-ai` calls `generateQuiz` and `gradeExplanation`, which fall back on their own.
33
+ * `hosted` needs `deps.hosted`; `deps.warn` receives the "API unavailable" lines.
34
+ */
35
+ export declare function createBackend(source: QuizSource, deps: {
36
+ config: ChainConfig;
37
+ clientFactory?: ClientFactory;
38
+ hosted?: HostedApi;
39
+ warn?: (line: string) => void;
40
+ }): QuizBackend;