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.
- package/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/commands/init.d.ts +29 -0
- package/dist/commands/init.js +310 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +19 -0
- package/dist/commands/mcp.js +38 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/quiz.d.ts +23 -0
- package/dist/commands/quiz.js +187 -0
- package/dist/commands/quiz.js.map +1 -0
- package/dist/commands/review.d.ts +4 -0
- package/dist/commands/review.js +115 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/sync.d.ts +17 -0
- package/dist/commands/sync.js +367 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/git.d.ts +33 -0
- package/dist/git.js +103 -0
- package/dist/git.js.map +1 -0
- package/dist/hosted-api.d.ts +24 -0
- package/dist/hosted-api.js +85 -0
- package/dist/hosted-api.js.map +1 -0
- package/dist/hosted-consent.d.ts +8 -0
- package/dist/hosted-consent.js +37 -0
- package/dist/hosted-consent.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/init-fs.d.ts +51 -0
- package/dist/init-fs.js +220 -0
- package/dist/init-fs.js.map +1 -0
- package/dist/init-questions.d.ts +21 -0
- package/dist/init-questions.js +161 -0
- package/dist/init-questions.js.map +1 -0
- package/dist/mcp-handlers.d.ts +22 -0
- package/dist/mcp-handlers.js +185 -0
- package/dist/mcp-handlers.js.map +1 -0
- package/dist/mcp-server.d.ts +4 -0
- package/dist/mcp-server.js +39 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/prompter.d.ts +29 -0
- package/dist/prompter.js +42 -0
- package/dist/prompter.js.map +1 -0
- package/dist/quiz-backend.d.ts +40 -0
- package/dist/quiz-backend.js +116 -0
- package/dist/quiz-backend.js.map +1 -0
- package/dist/quiz-input.d.ts +12 -0
- package/dist/quiz-input.js +52 -0
- package/dist/quiz-input.js.map +1 -0
- package/dist/quiz-io.d.ts +30 -0
- package/dist/quiz-io.js +83 -0
- package/dist/quiz-io.js.map +1 -0
- package/dist/quiz-ui.d.ts +18 -0
- package/dist/quiz-ui.js +51 -0
- package/dist/quiz-ui.js.map +1 -0
- package/node_modules/@seance/ai/LICENSE +21 -0
- package/node_modules/@seance/ai/dist/chain.d.ts +31 -0
- package/node_modules/@seance/ai/dist/chain.js +114 -0
- package/node_modules/@seance/ai/dist/chain.js.map +1 -0
- package/node_modules/@seance/ai/dist/grade.d.ts +14 -0
- package/node_modules/@seance/ai/dist/grade.js +44 -0
- package/node_modules/@seance/ai/dist/grade.js.map +1 -0
- package/node_modules/@seance/ai/dist/hosted-config.d.ts +9 -0
- package/node_modules/@seance/ai/dist/hosted-config.js +27 -0
- package/node_modules/@seance/ai/dist/hosted-config.js.map +1 -0
- package/node_modules/@seance/ai/dist/index.d.ts +9 -0
- package/node_modules/@seance/ai/dist/index.js +9 -0
- package/node_modules/@seance/ai/dist/index.js.map +1 -0
- package/node_modules/@seance/ai/dist/providers.d.ts +54 -0
- package/node_modules/@seance/ai/dist/providers.js +149 -0
- package/node_modules/@seance/ai/dist/providers.js.map +1 -0
- package/node_modules/@seance/ai/dist/quiz.d.ts +26 -0
- package/node_modules/@seance/ai/dist/quiz.js +41 -0
- package/node_modules/@seance/ai/dist/quiz.js.map +1 -0
- package/node_modules/@seance/ai/package.json +25 -0
- package/node_modules/@seance/core/LICENSE +21 -0
- package/node_modules/@seance/core/dist/ai-check.d.ts +58 -0
- package/node_modules/@seance/core/dist/ai-check.js +460 -0
- package/node_modules/@seance/core/dist/ai-check.js.map +1 -0
- package/node_modules/@seance/core/dist/ai-prompts.d.ts +29 -0
- package/node_modules/@seance/core/dist/ai-prompts.js +221 -0
- package/node_modules/@seance/core/dist/ai-prompts.js.map +1 -0
- package/node_modules/@seance/core/dist/ai-schemas.d.ts +155 -0
- package/node_modules/@seance/core/dist/ai-schemas.js +92 -0
- package/node_modules/@seance/core/dist/ai-schemas.js.map +1 -0
- package/node_modules/@seance/core/dist/api-client.d.ts +26 -0
- package/node_modules/@seance/core/dist/api-client.js +71 -0
- package/node_modules/@seance/core/dist/api-client.js.map +1 -0
- package/node_modules/@seance/core/dist/api-errors.d.ts +37 -0
- package/node_modules/@seance/core/dist/api-errors.js +66 -0
- package/node_modules/@seance/core/dist/api-errors.js.map +1 -0
- package/node_modules/@seance/core/dist/api-schemas.d.ts +284 -0
- package/node_modules/@seance/core/dist/api-schemas.js +67 -0
- package/node_modules/@seance/core/dist/api-schemas.js.map +1 -0
- package/node_modules/@seance/core/dist/decision-log.d.ts +73 -0
- package/node_modules/@seance/core/dist/decision-log.js +239 -0
- package/node_modules/@seance/core/dist/decision-log.js.map +1 -0
- package/node_modules/@seance/core/dist/dependency-guard.d.ts +20 -0
- package/node_modules/@seance/core/dist/dependency-guard.js +732 -0
- package/node_modules/@seance/core/dist/dependency-guard.js.map +1 -0
- package/node_modules/@seance/core/dist/gate.d.ts +11 -0
- package/node_modules/@seance/core/dist/gate.js +26 -0
- package/node_modules/@seance/core/dist/gate.js.map +1 -0
- package/node_modules/@seance/core/dist/git-parse.d.ts +11 -0
- package/node_modules/@seance/core/dist/git-parse.js +23 -0
- package/node_modules/@seance/core/dist/git-parse.js.map +1 -0
- package/node_modules/@seance/core/dist/index.d.ts +65 -0
- package/node_modules/@seance/core/dist/index.js +47 -0
- package/node_modules/@seance/core/dist/index.js.map +1 -0
- package/node_modules/@seance/core/dist/init-checklist.d.ts +153 -0
- package/node_modules/@seance/core/dist/init-checklist.js +200 -0
- package/node_modules/@seance/core/dist/init-checklist.js.map +1 -0
- package/node_modules/@seance/core/dist/init-detect.d.ts +9 -0
- package/node_modules/@seance/core/dist/init-detect.js +84 -0
- package/node_modules/@seance/core/dist/init-detect.js.map +1 -0
- package/node_modules/@seance/core/dist/init-templates.d.ts +36 -0
- package/node_modules/@seance/core/dist/init-templates.js +257 -0
- package/node_modules/@seance/core/dist/init-templates.js.map +1 -0
- package/node_modules/@seance/core/dist/map-basics.d.ts +13 -0
- package/node_modules/@seance/core/dist/map-basics.js +19 -0
- package/node_modules/@seance/core/dist/map-basics.js.map +1 -0
- package/node_modules/@seance/core/dist/map-summary.d.ts +5 -0
- package/node_modules/@seance/core/dist/map-summary.js +50 -0
- package/node_modules/@seance/core/dist/map-summary.js.map +1 -0
- package/node_modules/@seance/core/dist/markers.d.ts +51 -0
- package/node_modules/@seance/core/dist/markers.js +84 -0
- package/node_modules/@seance/core/dist/markers.js.map +1 -0
- package/node_modules/@seance/core/dist/mcp-quiz.d.ts +94 -0
- package/node_modules/@seance/core/dist/mcp-quiz.js +130 -0
- package/node_modules/@seance/core/dist/mcp-quiz.js.map +1 -0
- package/node_modules/@seance/core/dist/mcp-tools.d.ts +82 -0
- package/node_modules/@seance/core/dist/mcp-tools.js +136 -0
- package/node_modules/@seance/core/dist/mcp-tools.js.map +1 -0
- package/node_modules/@seance/core/dist/mcp-views.d.ts +21 -0
- package/node_modules/@seance/core/dist/mcp-views.js +83 -0
- package/node_modules/@seance/core/dist/mcp-views.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-assembly.d.ts +21 -0
- package/node_modules/@seance/core/dist/quiz-assembly.js +43 -0
- package/node_modules/@seance/core/dist/quiz-assembly.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-cards.d.ts +183 -0
- package/node_modules/@seance/core/dist/quiz-cards.js +215 -0
- package/node_modules/@seance/core/dist/quiz-cards.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-session.d.ts +67 -0
- package/node_modules/@seance/core/dist/quiz-session.js +141 -0
- package/node_modules/@seance/core/dist/quiz-session.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-subjects.d.ts +13 -0
- package/node_modules/@seance/core/dist/quiz-subjects.js +63 -0
- package/node_modules/@seance/core/dist/quiz-subjects.js.map +1 -0
- package/node_modules/@seance/core/dist/rate-limit.d.ts +33 -0
- package/node_modules/@seance/core/dist/rate-limit.js +114 -0
- package/node_modules/@seance/core/dist/rate-limit.js.map +1 -0
- package/node_modules/@seance/core/dist/scoring.d.ts +48 -0
- package/node_modules/@seance/core/dist/scoring.js +95 -0
- package/node_modules/@seance/core/dist/scoring.js.map +1 -0
- package/node_modules/@seance/core/dist/seance-config.d.ts +177 -0
- package/node_modules/@seance/core/dist/seance-config.js +43 -0
- package/node_modules/@seance/core/dist/seance-config.js.map +1 -0
- package/node_modules/@seance/core/dist/seance-state.d.ts +125 -0
- package/node_modules/@seance/core/dist/seance-state.js +61 -0
- package/node_modules/@seance/core/dist/seance-state.js.map +1 -0
- package/node_modules/@seance/core/dist/sm2.d.ts +18 -0
- package/node_modules/@seance/core/dist/sm2.js +87 -0
- package/node_modules/@seance/core/dist/sm2.js.map +1 -0
- package/node_modules/@seance/core/dist/stored-schemas.d.ts +29 -0
- package/node_modules/@seance/core/dist/stored-schemas.js +29 -0
- package/node_modules/@seance/core/dist/stored-schemas.js.map +1 -0
- package/node_modules/@seance/core/dist/structural-questions.d.ts +31 -0
- package/node_modules/@seance/core/dist/structural-questions.js +575 -0
- package/node_modules/@seance/core/dist/structural-questions.js.map +1 -0
- package/node_modules/@seance/core/dist/structure-map-schema.d.ts +84 -0
- package/node_modules/@seance/core/dist/structure-map-schema.js +73 -0
- package/node_modules/@seance/core/dist/structure-map-schema.js.map +1 -0
- package/node_modules/@seance/core/dist/structure-map.d.ts +78 -0
- package/node_modules/@seance/core/dist/structure-map.js +750 -0
- package/node_modules/@seance/core/dist/structure-map.js.map +1 -0
- package/node_modules/@seance/core/dist/sync-changes.d.ts +38 -0
- package/node_modules/@seance/core/dist/sync-changes.js +89 -0
- package/node_modules/@seance/core/dist/sync-changes.js.map +1 -0
- package/node_modules/@seance/core/dist/sync-render.d.ts +28 -0
- package/node_modules/@seance/core/dist/sync-render.js +113 -0
- package/node_modules/@seance/core/dist/sync-render.js.map +1 -0
- package/node_modules/@seance/core/dist/terminal-text.d.ts +8 -0
- package/node_modules/@seance/core/dist/terminal-text.js +33 -0
- package/node_modules/@seance/core/dist/terminal-text.js.map +1 -0
- package/node_modules/@seance/core/dist/write-plan.d.ts +51 -0
- package/node_modules/@seance/core/dist/write-plan.js +173 -0
- package/node_modules/@seance/core/dist/write-plan.js.map +1 -0
- package/node_modules/@seance/core/package.json +26 -0
- package/package.json +42 -6
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// `seance quiz`: quizzes the developer on the latest change. Questions come from the pending quiz files (or git), through a
|
|
2
|
+
// QuizBackend (structural questions, or the user's own AI providers). The result is scored, gated, and missed questions become
|
|
3
|
+
// SM-2 review cards in `.seance/state.json`. Pure decisions are in @seance/core; this file reads files, prompts and writes once.
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { readChainConfig } from "@seance/ai";
|
|
6
|
+
import { STATE_PATH, answerChoice, answerGraded, applyQuizResult, buildStructureMap, currentQuestion, decisionPromptText, fitQuizFiles, finishSession, formatMapSummary, formatQuizResult, isComplete, parseApiUrl, pickQuizSource, quizSeed, readProgress, reorderChoices, startSession, toPlainText, } from "@seance/core";
|
|
7
|
+
import { createGitRunner } from "../git.js";
|
|
8
|
+
import { apiUrlSetting, createHostedApi } from "../hosted-api.js";
|
|
9
|
+
import { askSendCode } from "../hosted-consent.js";
|
|
10
|
+
import { errorCode, resolveRoot } from "../init-fs.js";
|
|
11
|
+
import { PromptCancelled } from "../prompter.js";
|
|
12
|
+
import { createBackend } from "../quiz-backend.js";
|
|
13
|
+
import { readDecision, readGate, readState, saveWithRetry } from "../quiz-io.js";
|
|
14
|
+
import { choosePaths, readMap, usable } from "../quiz-input.js";
|
|
15
|
+
import { askQuestion, isDirectory, localDate, plural } from "../quiz-ui.js";
|
|
16
|
+
/** Runs `seance quiz`. Returns the exit code and never calls `process.exit`. */
|
|
17
|
+
export async function runQuiz(options, deps) {
|
|
18
|
+
try {
|
|
19
|
+
return await quizFlow(options, deps);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error instanceof PromptCancelled) {
|
|
23
|
+
deps.out("quiz cancelled, nothing saved");
|
|
24
|
+
return 130;
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function say(deps, text) {
|
|
30
|
+
deps.out(`seance quiz: ${text}`);
|
|
31
|
+
}
|
|
32
|
+
async function quizFlow(options, deps) {
|
|
33
|
+
// 1. The folder.
|
|
34
|
+
const dir = resolve(deps.cwd, options.dir ?? ".");
|
|
35
|
+
if (!(await isDirectory(dir))) {
|
|
36
|
+
say(deps, "--dir is not a folder");
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
const root = await resolveRoot(dir);
|
|
40
|
+
// 2. The state and the gate.
|
|
41
|
+
const read = await readState(root);
|
|
42
|
+
if (!read.ok) {
|
|
43
|
+
say(deps, `${STATE_PATH} is invalid; fix or delete it`);
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
const gate = await readGate(root);
|
|
47
|
+
if (gate.warning !== undefined)
|
|
48
|
+
say(deps, gate.warning);
|
|
49
|
+
// 3. A terminal is needed to ask questions.
|
|
50
|
+
if (!deps.isTTY) {
|
|
51
|
+
deps.out("seance quiz needs a terminal (it asks questions)");
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
// 4-5. The files and the map.
|
|
55
|
+
const pending = read.state.pendingQuiz;
|
|
56
|
+
const paths = await choosePaths(deps.git ?? createGitRunner(root), pending?.files);
|
|
57
|
+
if (paths === undefined) {
|
|
58
|
+
say(deps, "no pending quiz; run seance sync after a change");
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
const { map, files, bytes } = await readMap(root, paths);
|
|
62
|
+
const parsed = map.files.filter((file) => file.parsed).length;
|
|
63
|
+
const stored = usable(pending?.questions ?? []);
|
|
64
|
+
if (parsed === 0 && stored.length === 0) {
|
|
65
|
+
say(deps, "nothing to quiz on (no readable JS or TS files)");
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
for (const line of formatMapSummary(map))
|
|
69
|
+
deps.out(line);
|
|
70
|
+
// 6. The source and the backend. The hosted API (Task 8) is used only when there are no own keys, SEANCE_API_URL (or the default) is set,
|
|
71
|
+
// and the user says yes to sending the code (D1); only the files that fit the API's 100 KB are sent, and the summary above shows them all.
|
|
72
|
+
const config = readChainConfig(deps.env);
|
|
73
|
+
const apiUrl = parseApiUrl(apiUrlSetting(deps.env, deps.defaultApiUrl));
|
|
74
|
+
let source = pickQuizSource({ offline: options.offline === true, providerCount: config.providers.length, ...(apiUrl === undefined ? {} : { hostedUrl: apiUrl }) });
|
|
75
|
+
const seed = quizSeed(pending, paths);
|
|
76
|
+
const attempt = readProgress(pending).attempts;
|
|
77
|
+
let sendFiles = files;
|
|
78
|
+
let sendMap = map;
|
|
79
|
+
let sendBytes = bytes;
|
|
80
|
+
let hosted;
|
|
81
|
+
// The latest DECISIONS.md entry is read only when code would leave the machine, before the question or the notice (Task 13, req 11.1, 11.4).
|
|
82
|
+
let decision;
|
|
83
|
+
if (parsed > 0 && (source === "hosted" || source === "local-ai"))
|
|
84
|
+
decision = await readDecision(root);
|
|
85
|
+
if (source === "hosted" && apiUrl !== undefined) {
|
|
86
|
+
hosted = createHostedApi(apiUrl, deps.fetch === undefined ? {} : { fetch: deps.fetch });
|
|
87
|
+
const fit = fitQuizFiles(files, { seed, attempt, ...(decision === undefined ? {} : { decision: decisionPromptText(decision) }) });
|
|
88
|
+
if (parsed === 0) {
|
|
89
|
+
source = "structural"; // no code to send: nothing goes to the API
|
|
90
|
+
}
|
|
91
|
+
else if (fit.files.length === 0) {
|
|
92
|
+
say(deps, "no file fits the API's 100 KB limit; questions from the code structure");
|
|
93
|
+
source = "structural";
|
|
94
|
+
decision = undefined;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// The consent question shows what would be sent; the narrowed files and map are used only after a Yes (changed after review).
|
|
98
|
+
const fitBytes = fit.files.reduce((sum, file) => sum + Buffer.byteLength(file.content), 0);
|
|
99
|
+
if (await askSendCode(deps.prompter, hosted.host, fit.files.length, (fitBytes / 1024).toFixed(1), decision !== undefined)) {
|
|
100
|
+
if (fit.dropped > 0)
|
|
101
|
+
say(deps, `${fit.dropped} ${plural(fit.dropped, "file", "files")} left out (the API takes 100 KB)`);
|
|
102
|
+
sendFiles = fit.files;
|
|
103
|
+
sendMap = buildStructureMap(fit.files);
|
|
104
|
+
sendBytes = fitBytes;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
source = "structural"; // sends nothing; the structural quiz uses the full map and files
|
|
108
|
+
decision = undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const backend = createBackend(source, {
|
|
113
|
+
config,
|
|
114
|
+
...(deps.clientFactory === undefined ? {} : { clientFactory: deps.clientFactory }),
|
|
115
|
+
...(hosted === undefined ? {} : { hosted }),
|
|
116
|
+
warn: (line) => say(deps, toPlainText(line)),
|
|
117
|
+
});
|
|
118
|
+
// 7. The questions.
|
|
119
|
+
// The answer-grading notice (changed after review): printed once before the first network grade call, unless the line below was printed.
|
|
120
|
+
let noticePrinted = false;
|
|
121
|
+
const notice = () => {
|
|
122
|
+
if (!backend.sendsCode || noticePrinted)
|
|
123
|
+
return;
|
|
124
|
+
noticePrinted = true;
|
|
125
|
+
say(deps, toPlainText(`sending your answers to ${backend.destination} for grading; use --offline to grade by keywords`));
|
|
126
|
+
};
|
|
127
|
+
let questions = [];
|
|
128
|
+
if (parsed > 0) {
|
|
129
|
+
if (backend.sendsCode) {
|
|
130
|
+
const kb = (sendBytes / 1024).toFixed(1);
|
|
131
|
+
noticePrinted = true; // this line also covers grading (open question 18)
|
|
132
|
+
say(deps, toPlainText(`sending code from ${sendFiles.length} ${plural(sendFiles.length, "file", "files")} (${kb} KB)${decision === undefined ? "" : " and the latest DECISIONS.md entry"} to ${backend.destination}; use --offline to keep it local`));
|
|
133
|
+
}
|
|
134
|
+
const made = await backend.makeQuiz({ map: sendMap, files: sendFiles, seed, attempt, ...(decision === undefined ? {} : { decision }) });
|
|
135
|
+
questions = usable(made.questions);
|
|
136
|
+
if (backend.sendsCode && made.servedBy !== "structural") {
|
|
137
|
+
deps.out(toPlainText(`Questions by ${made.servedBy}${made.model === undefined ? "" : ` (${made.model})`}`));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
deps.out(`Questions from the code structure (${source === "offline" ? "offline" : "AI unavailable"})`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (questions.length === 0)
|
|
144
|
+
questions = usable(stored.map((item) => reorderChoices(item, attempt)));
|
|
145
|
+
if (questions.length === 0) {
|
|
146
|
+
say(deps, "nothing to quiz on (no readable JS or TS files)");
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
// 8. Ask.
|
|
150
|
+
let session = startSession(questions);
|
|
151
|
+
const ask = { prompter: deps.prompter, out: deps.out, backend };
|
|
152
|
+
for (let item = currentQuestion(session); item !== undefined; item = currentQuestion(session)) {
|
|
153
|
+
const outcome = await askQuestion(ask, item, `Question ${session.outcomes.length + 1}/${session.questions.length}`, notice);
|
|
154
|
+
session = outcome.kind === "choice" ? answerChoice(session, outcome.choiceIndex).session : answerGraded(session, outcome.score, outcome.rough);
|
|
155
|
+
}
|
|
156
|
+
if (!isComplete(session))
|
|
157
|
+
throw new RangeError("the quiz did not finish");
|
|
158
|
+
// 9. Score, gate and cards; one write. saveWithRetry may call the callback twice (on a retry); the last call is the one that is written, so `holder` keeps the last result.
|
|
159
|
+
const summary = finishSession(session, { mode: gate.mode, passMark: gate.passMark });
|
|
160
|
+
const now = deps.now();
|
|
161
|
+
const record = { quizId: pending?.id ?? null, summary, session, today: localDate(now), at: now.toISOString(), source };
|
|
162
|
+
const holder = {};
|
|
163
|
+
try {
|
|
164
|
+
const outcome = await saveWithRetry(root, read, (state) => {
|
|
165
|
+
const result = applyQuizResult(state, record);
|
|
166
|
+
holder.applied = result;
|
|
167
|
+
return result.state;
|
|
168
|
+
}, deps.fs);
|
|
169
|
+
if (outcome === "conflict") {
|
|
170
|
+
say(deps, `${STATE_PATH} changed during the quiz; results not saved`);
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
say(deps, `could not write ${STATE_PATH}: ${errorCode(error)}`);
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
// 10. The result.
|
|
179
|
+
const applied = holder.applied;
|
|
180
|
+
const dates = (applied?.added ?? []).map((key) => applied?.state.cards[key]?.dueAt).filter((date) => date !== undefined);
|
|
181
|
+
const firstReview = dates.length === 0 ? undefined : dates.reduce((a, b) => (a < b ? a : b));
|
|
182
|
+
const cards = { added: applied?.added.length ?? 0, notAdded: applied?.notAdded ?? 0, ...(firstReview === undefined ? {} : { firstReview }) };
|
|
183
|
+
for (const line of formatQuizResult(summary, cards))
|
|
184
|
+
deps.out(line);
|
|
185
|
+
return summary.gate.reason === "strict-below" ? 1 : 0;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=quiz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quiz.js","sourceRoot":"","sources":["../../src/commands/quiz.ts"],"names":[],"mappings":"AAAA,4HAA4H;AAC5H,+HAA+H;AAC/H,iIAAiI;AACjI,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAsB,MAAM,YAAY,CAAC;AACjE,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,GACZ,MAAM,cAAc,CAAC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CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IACzI,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,MAAM,KAAK,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAC,EAAE,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;IAC7I,KAAK,MAAM,IAAI,IAAI,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpE,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { QuizDeps, QuizOptions } from "./quiz.js";
|
|
2
|
+
export type ReviewOptions = QuizOptions;
|
|
3
|
+
/** Runs `seance review`. Returns the exit code and never calls `process.exit`. */
|
|
4
|
+
export declare function runReview(options: ReviewOptions, deps: QuizDeps): Promise<number>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// `seance review`: asks the review cards that are due again (the stored question with reshuffled choices), grades explain cards
|
|
2
|
+
// (AI when the user has keys and no --offline, else keywords) and moves each card on with SM-2. Writes `.seance/state.json` once.
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { readChainConfig } from "@seance/ai";
|
|
5
|
+
import { STATE_PATH, applyReviewResult, dueCards, nextDueDate, parseApiUrl, pickQuizSource, qualityFor, reorderChoices, toPlainText } from "@seance/core";
|
|
6
|
+
import { apiUrlSetting, createHostedApi } from "../hosted-api.js";
|
|
7
|
+
import { askSendAnswers } from "../hosted-consent.js";
|
|
8
|
+
import { errorCode, resolveRoot } from "../init-fs.js";
|
|
9
|
+
import { PromptCancelled } from "../prompter.js";
|
|
10
|
+
import { createBackend } from "../quiz-backend.js";
|
|
11
|
+
import { readState, saveWithRetry } from "../quiz-io.js";
|
|
12
|
+
import { askQuestion, isDirectory, localDate, plural } from "../quiz-ui.js";
|
|
13
|
+
/** Runs `seance review`. Returns the exit code and never calls `process.exit`. */
|
|
14
|
+
export async function runReview(options, deps) {
|
|
15
|
+
try {
|
|
16
|
+
return await reviewFlow(options, deps);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error instanceof PromptCancelled) {
|
|
20
|
+
deps.out("review cancelled, nothing saved");
|
|
21
|
+
return 130;
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function say(deps, text) {
|
|
27
|
+
deps.out(`seance review: ${text}`);
|
|
28
|
+
}
|
|
29
|
+
async function reviewFlow(options, deps) {
|
|
30
|
+
// 1. The folder and the state.
|
|
31
|
+
const dir = resolve(deps.cwd, options.dir ?? ".");
|
|
32
|
+
if (!(await isDirectory(dir))) {
|
|
33
|
+
say(deps, "--dir is not a folder");
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
const root = await resolveRoot(dir);
|
|
37
|
+
const read = await readState(root);
|
|
38
|
+
if (!read.ok) {
|
|
39
|
+
say(deps, `${STATE_PATH} is invalid; fix or delete it`);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
// 2. What is due.
|
|
43
|
+
const today = localDate(deps.now());
|
|
44
|
+
const { due, invalid } = dueCards(read.state.cards, today);
|
|
45
|
+
const skipped = `${invalid} ${plural(invalid, "card", "cards")} skipped (invalid in ${STATE_PATH})`;
|
|
46
|
+
if (due.length === 0) {
|
|
47
|
+
const next = nextDueDate(read.state.cards);
|
|
48
|
+
say(deps, next === undefined ? "no review cards yet; run seance quiz" : `nothing due today; next review ${next}`);
|
|
49
|
+
if (invalid > 0)
|
|
50
|
+
say(deps, skipped);
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
if (!deps.isTTY) {
|
|
54
|
+
deps.out(`seance review needs a terminal; ${due.length} ${plural(due.length, "card is", "cards are")} due`);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
// 3. The backend (grading only).
|
|
58
|
+
const config = readChainConfig(deps.env);
|
|
59
|
+
const apiUrl = parseApiUrl(apiUrlSetting(deps.env, deps.defaultApiUrl));
|
|
60
|
+
let source = pickQuizSource({ offline: options.offline === true, providerCount: config.providers.length, ...(apiUrl === undefined ? {} : { hostedUrl: apiUrl }) });
|
|
61
|
+
let hosted;
|
|
62
|
+
if (source === "hosted" && apiUrl !== undefined) {
|
|
63
|
+
hosted = createHostedApi(apiUrl, deps.fetch === undefined ? {} : { fetch: deps.fetch });
|
|
64
|
+
// Only explain cards are graded by the API. The question is asked once, and only when there is something to grade (D1).
|
|
65
|
+
const needsGrading = due.some((entry) => entry.card.question.kind === "explain");
|
|
66
|
+
if (!needsGrading || !(await askSendAnswers(deps.prompter, hosted.host)))
|
|
67
|
+
source = "structural";
|
|
68
|
+
}
|
|
69
|
+
const backend = createBackend(source, {
|
|
70
|
+
config,
|
|
71
|
+
...(deps.clientFactory === undefined ? {} : { clientFactory: deps.clientFactory }),
|
|
72
|
+
...(hosted === undefined ? {} : { hosted }),
|
|
73
|
+
warn: (line) => say(deps, toPlainText(line)),
|
|
74
|
+
});
|
|
75
|
+
let noticePrinted = false;
|
|
76
|
+
const notice = () => {
|
|
77
|
+
if (!backend.sendsCode || noticePrinted)
|
|
78
|
+
return;
|
|
79
|
+
noticePrinted = true;
|
|
80
|
+
say(deps, toPlainText(`sending your answers to ${backend.destination} for grading; use --offline to grade by keywords`));
|
|
81
|
+
};
|
|
82
|
+
// 4. Ask.
|
|
83
|
+
const ask = { prompter: deps.prompter, out: deps.out, backend };
|
|
84
|
+
const reviews = [];
|
|
85
|
+
for (const [index, entry] of due.entries()) {
|
|
86
|
+
const question = reorderChoices(entry.card.question, entry.card.reviews + 1);
|
|
87
|
+
const label = `Card ${index + 1}/${due.length} (added ${entry.card.addedAt})`;
|
|
88
|
+
reviews.push({ key: entry.key, outcome: await askQuestion(ask, question, label, notice) });
|
|
89
|
+
}
|
|
90
|
+
// 5. One write. saveWithRetry may call the callback twice (on a retry); the last call is the one that is written, so `holder` keeps the last result.
|
|
91
|
+
const holder = {};
|
|
92
|
+
try {
|
|
93
|
+
const outcome = await saveWithRetry(root, read, (state) => {
|
|
94
|
+
holder.state = applyReviewResult(state, reviews, today);
|
|
95
|
+
return holder.state;
|
|
96
|
+
}, deps.fs);
|
|
97
|
+
if (outcome === "conflict") {
|
|
98
|
+
say(deps, `${STATE_PATH} changed during the review; results not saved`);
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
say(deps, `could not write ${STATE_PATH}: ${errorCode(error)}`);
|
|
104
|
+
return 1;
|
|
105
|
+
}
|
|
106
|
+
const after = holder.state;
|
|
107
|
+
const remembered = reviews.filter((review) => qualityFor(review.outcome) >= 3).length;
|
|
108
|
+
const again = reviews.length - remembered;
|
|
109
|
+
const next = after === undefined ? undefined : nextDueDate(after.cards);
|
|
110
|
+
deps.out(`Reviewed ${reviews.length} ${plural(reviews.length, "card", "cards")}: ${remembered} remembered, ${again} again tomorrow. Next review ${next ?? "not scheduled"}.`);
|
|
111
|
+
if (invalid > 0)
|
|
112
|
+
say(deps, skipped);
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.js","sourceRoot":"","sources":["../../src/commands/review.ts"],"names":[],"mappings":"AAAA,gIAAgI;AAChI,kIAAkI;AAClI,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE1J,OAAO,EAAE,aAAa,EAAE,eAAe,EAAkB,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAK5E,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAsB,EAAE,IAAc;IACpE,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;YACrC,IAAI,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;YAC5C,OAAO,GAAG,CAAC;QACb,CAAC;QACD,MAAM,KAAK,CAA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AAO,CAAC,MAAM,GAAG,UAAU,CAAC;IAC1C,MAAM,IAAI,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACxE,IAAI,CAAC,GAAG,CAAC,YAAY,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,KAAK,UAAU,gBAAgB,KAAK,gCAAgC,IAAI,IAAI,eAAe,GAAG,CAAC,CAAC;IAC9K,IAAI,OAAO,GAAG,CAAC;QAAE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { buildStructureMap } from "@seance/core";
|
|
2
|
+
import { type GitRunner } from "../git.js";
|
|
3
|
+
import { type WriteOps } from "../init-fs.js";
|
|
4
|
+
export interface SyncOptions {
|
|
5
|
+
dir?: string;
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SyncDeps {
|
|
9
|
+
cwd: string;
|
|
10
|
+
out: (line: string) => void;
|
|
11
|
+
now: () => Date;
|
|
12
|
+
git?: GitRunner;
|
|
13
|
+
fs?: Partial<WriteOps>;
|
|
14
|
+
buildMap?: typeof buildStructureMap;
|
|
15
|
+
}
|
|
16
|
+
/** Runs `seance sync`. Returns the exit code and never calls `process.exit`. */
|
|
17
|
+
export declare function runSync(options: SyncOptions, deps: SyncDeps): Promise<number>;
|