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 @@
|
|
|
1
|
+
{"version":3,"file":"markers.js","sourceRoot":"","sources":["../src/markers.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,kGAAkG;AAElG,sEAAsE;AACtE,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CAAC;AACvD,MAAM,CAAC,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AAEnD,gFAAgF;AAChF,MAAM,CAAC,MAAM,WAAW,GAAG,6BAA6B,CAAC;AACzD,MAAM,CAAC,MAAM,SAAS,GAAG,2BAA2B,CAAC;AAYrD,gEAAgE;AAChE,SAAS,gBAAgB,CAAC,IAAY,EAAE,MAAc;IACpD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,SAAS,CAAC;QACR,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACtC,IAAI,EAAE,KAAK,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC5B,KAAK,IAAI,CAAC,CAAC;QACX,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,sIAAsI;AACtI,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,GAAW;IAChE,MAAM,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7C,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,IAAI,M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IAAI,KAAK,CAAC,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACzD,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IAClD,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,IAAI,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7G,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { QuizItem } from "./ai-schemas.js";
|
|
2
|
+
import { type QuizSession } from "./quiz-session.js";
|
|
3
|
+
export interface PublicQuestion {
|
|
4
|
+
id: string;
|
|
5
|
+
number: number;
|
|
6
|
+
total: number;
|
|
7
|
+
kind: "choice" | "explain";
|
|
8
|
+
concept: string;
|
|
9
|
+
path: string | null;
|
|
10
|
+
prompt: string;
|
|
11
|
+
/** Changed Dec 2 after manual test: numbered from 1, so the agent shows these numbers and sends `choiceNumber` back. */
|
|
12
|
+
choices: {
|
|
13
|
+
number: number;
|
|
14
|
+
text: string;
|
|
15
|
+
}[] | null;
|
|
16
|
+
}
|
|
17
|
+
export interface McpQuiz {
|
|
18
|
+
id: string;
|
|
19
|
+
session: QuizSession;
|
|
20
|
+
pendingId: string | null;
|
|
21
|
+
attempt: number;
|
|
22
|
+
lastUsedMs: number;
|
|
23
|
+
}
|
|
24
|
+
export interface McpQuizStore {
|
|
25
|
+
readonly quizzes: readonly McpQuiz[];
|
|
26
|
+
}
|
|
27
|
+
/** Exactly one of `choiceNumber` (1-based, as shown), `choiceText` (exact text of a shown choice) or `text` (explain). */
|
|
28
|
+
export type SubmitInput = {
|
|
29
|
+
quizId: string;
|
|
30
|
+
questionId: string;
|
|
31
|
+
choiceNumber?: number;
|
|
32
|
+
choiceText?: string;
|
|
33
|
+
text?: string;
|
|
34
|
+
grade?: {
|
|
35
|
+
score: number;
|
|
36
|
+
feedback: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/** What an accepted answer shows. An explain `score` is a whole percent (0-100). */
|
|
40
|
+
export type Reveal = {
|
|
41
|
+
kind: "choice";
|
|
42
|
+
correct: boolean;
|
|
43
|
+
answer: string;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "explain";
|
|
46
|
+
score: number;
|
|
47
|
+
feedback: string;
|
|
48
|
+
keyPoints: string[];
|
|
49
|
+
modelAnswer: string | null;
|
|
50
|
+
};
|
|
51
|
+
export type SubmitResult = {
|
|
52
|
+
type: "error";
|
|
53
|
+
code: "unknown-quiz" | "wrong-question" | "bad-answer" | "invalid-input";
|
|
54
|
+
currentId?: string;
|
|
55
|
+
} | {
|
|
56
|
+
type: "accepted";
|
|
57
|
+
store: McpQuizStore;
|
|
58
|
+
reveal: Reveal;
|
|
59
|
+
next: PublicQuestion | null;
|
|
60
|
+
finished?: McpQuiz;
|
|
61
|
+
};
|
|
62
|
+
export declare function emptyStore(): McpQuizStore;
|
|
63
|
+
/**
|
|
64
|
+
* The id the caller sees and sends back: `q1` to `qN` by position (changed after review). The internal id is never shown,
|
|
65
|
+
* because a structural id can hold the correct choice text.
|
|
66
|
+
*/
|
|
67
|
+
export declare function shownQuestionId(number: number): string;
|
|
68
|
+
/** The question as the caller may see it: a whitelist copy without the answer index, rubric or model answer. */
|
|
69
|
+
export declare function publicQuestion(item: QuizItem, number: number, total: number): PublicQuestion;
|
|
70
|
+
/** Drops sessions idle for more than 60 minutes, then the least recently used ones beyond 4. */
|
|
71
|
+
export declare function pruneStore(store: McpQuizStore, nowMs: number): McpQuizStore;
|
|
72
|
+
/** The session with this id, if the store has it. */
|
|
73
|
+
export declare function findQuiz(store: McpQuizStore, quizId: string): McpQuiz | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Opens a quiz and returns its first public question. Idle sessions go first; a fifth session pushes out the least recently
|
|
76
|
+
* used one; an existing session with the same id is replaced. Throws RangeError for 0 or more than 10 questions (from `startSession`).
|
|
77
|
+
*/
|
|
78
|
+
export declare function openQuiz(store: McpQuizStore, input: {
|
|
79
|
+
id: string;
|
|
80
|
+
nowMs: number;
|
|
81
|
+
questions: readonly QuizItem[];
|
|
82
|
+
pendingId: string | null;
|
|
83
|
+
attempt: number;
|
|
84
|
+
}): {
|
|
85
|
+
store: McpQuizStore;
|
|
86
|
+
quiz: McpQuiz;
|
|
87
|
+
first: PublicQuestion;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Accepts one answer for the current question of a live quiz. Order of checks: exactly one of choiceNumber, choiceText and text, a live quiz,
|
|
91
|
+
* the current question id, the answer form. An explain answer needs `grade`, computed by the caller (keyword grading).
|
|
92
|
+
* Never changes the store it is given; a rejected call returns an error and nothing else.
|
|
93
|
+
*/
|
|
94
|
+
export declare function submitAnswer(store: McpQuizStore, input: SubmitInput, nowMs: number): SubmitResult;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { AI_LIMITS } from "./ai-schemas.js";
|
|
2
|
+
import { MCP_LIMITS, isSafeRelativePath } from "./mcp-tools.js";
|
|
3
|
+
import { answerChoice, answerGraded, currentQuestion, isComplete, startSession } from "./quiz-session.js";
|
|
4
|
+
import { toPlainText } from "./terminal-text.js";
|
|
5
|
+
export function emptyStore() {
|
|
6
|
+
return { quizzes: [] };
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The id the caller sees and sends back: `q1` to `qN` by position (changed after review). The internal id is never shown,
|
|
10
|
+
* because a structural id can hold the correct choice text.
|
|
11
|
+
*/
|
|
12
|
+
export function shownQuestionId(number) {
|
|
13
|
+
return `q${number}`;
|
|
14
|
+
}
|
|
15
|
+
/** The question as the caller may see it: a whitelist copy without the answer index, rubric or model answer. */
|
|
16
|
+
export function publicQuestion(item, number, total) {
|
|
17
|
+
const path = item.source?.path;
|
|
18
|
+
return {
|
|
19
|
+
id: shownQuestionId(number),
|
|
20
|
+
number,
|
|
21
|
+
total,
|
|
22
|
+
kind: item.kind === "explain" ? "explain" : "choice",
|
|
23
|
+
concept: item.concept,
|
|
24
|
+
path: path !== undefined && isSafeRelativePath(path) ? toPlainText(path) : null,
|
|
25
|
+
prompt: toPlainText(item.prompt, { keepNewlines: true }),
|
|
26
|
+
choices: item.kind === "explain" ? null : item.choices.map((choice, index) => ({ number: index + 1, text: toPlainText(choice) })),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The 0-based index of the choice the caller means, or undefined when it names none. `choiceNumber` is 1-based; `choiceText`
|
|
31
|
+
* must equal one shown choice exactly (and only one: repeated texts are ambiguous).
|
|
32
|
+
*/
|
|
33
|
+
function pickedIndex(choices, input) {
|
|
34
|
+
if (input.choiceNumber !== undefined) {
|
|
35
|
+
const number = input.choiceNumber;
|
|
36
|
+
return Number.isInteger(number) && number >= 1 && number <= choices.length ? number - 1 : undefined;
|
|
37
|
+
}
|
|
38
|
+
const shown = choices.map((choice) => toPlainText(choice));
|
|
39
|
+
const matches = shown.flatMap((text, index) => (text === input.choiceText ? [index] : []));
|
|
40
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
41
|
+
}
|
|
42
|
+
/** Drops sessions idle for more than 60 minutes, then the least recently used ones beyond 4. */
|
|
43
|
+
export function pruneStore(store, nowMs) {
|
|
44
|
+
const live = store.quizzes.filter((quiz) => nowMs - quiz.lastUsedMs <= MCP_LIMITS.sessionIdleMs);
|
|
45
|
+
if (live.length <= MCP_LIMITS.maxSessions)
|
|
46
|
+
return live.length === store.quizzes.length ? store : { quizzes: live };
|
|
47
|
+
// Keep the most recently used; a tie keeps the later entry.
|
|
48
|
+
const ranked = live.map((quiz, index) => ({ quiz, index })).sort((a, b) => b.quiz.lastUsedMs - a.quiz.lastUsedMs || b.index - a.index);
|
|
49
|
+
const keep = new Set(ranked.slice(0, MCP_LIMITS.maxSessions).map((entry) => entry.index));
|
|
50
|
+
return { quizzes: live.filter((_quiz, index) => keep.has(index)) };
|
|
51
|
+
}
|
|
52
|
+
/** The session with this id, if the store has it. */
|
|
53
|
+
export function findQuiz(store, quizId) {
|
|
54
|
+
return store.quizzes.find((quiz) => quiz.id === quizId);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Opens a quiz and returns its first public question. Idle sessions go first; a fifth session pushes out the least recently
|
|
58
|
+
* used one; an existing session with the same id is replaced. Throws RangeError for 0 or more than 10 questions (from `startSession`).
|
|
59
|
+
*/
|
|
60
|
+
export function openQuiz(store, input) {
|
|
61
|
+
const session = startSession(input.questions);
|
|
62
|
+
const quiz = { id: input.id, session, pendingId: input.pendingId, attempt: input.attempt, lastUsedMs: input.nowMs };
|
|
63
|
+
const pruned = pruneStore(store, input.nowMs);
|
|
64
|
+
const others = pruned.quizzes.filter((entry) => entry.id !== input.id);
|
|
65
|
+
const next = pruneStore({ quizzes: [...others, quiz] }, input.nowMs);
|
|
66
|
+
const first = currentQuestion(session); // startSession guarantees at least one question
|
|
67
|
+
return { store: next, quiz, first: publicQuestion(first, 1, session.questions.length) };
|
|
68
|
+
}
|
|
69
|
+
function percent(score) {
|
|
70
|
+
return Math.round(score * 100);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Accepts one answer for the current question of a live quiz. Order of checks: exactly one of choiceNumber, choiceText and text, a live quiz,
|
|
74
|
+
* the current question id, the answer form. An explain answer needs `grade`, computed by the caller (keyword grading).
|
|
75
|
+
* Never changes the store it is given; a rejected call returns an error and nothing else.
|
|
76
|
+
*/
|
|
77
|
+
export function submitAnswer(store, input, nowMs) {
|
|
78
|
+
const given = [input.choiceNumber, input.choiceText, input.text].filter((value) => value !== undefined).length;
|
|
79
|
+
if (given !== 1)
|
|
80
|
+
return { type: "error", code: "invalid-input" };
|
|
81
|
+
const live = pruneStore(store, nowMs);
|
|
82
|
+
const quiz = findQuiz(live, input.quizId);
|
|
83
|
+
const question = quiz === undefined ? undefined : currentQuestion(quiz.session);
|
|
84
|
+
if (quiz === undefined || question === undefined)
|
|
85
|
+
return { type: "error", code: "unknown-quiz" };
|
|
86
|
+
const shownId = shownQuestionId(quiz.session.outcomes.length + 1);
|
|
87
|
+
if (input.questionId !== shownId)
|
|
88
|
+
return { type: "error", code: "wrong-question", currentId: shownId };
|
|
89
|
+
let session;
|
|
90
|
+
let reveal;
|
|
91
|
+
try {
|
|
92
|
+
if (question.kind === "explain") {
|
|
93
|
+
if (input.text === undefined || input.grade === undefined)
|
|
94
|
+
return { type: "error", code: "bad-answer" };
|
|
95
|
+
session = answerGraded(quiz.session, input.grade.score, true);
|
|
96
|
+
reveal = {
|
|
97
|
+
kind: "explain",
|
|
98
|
+
score: percent(input.grade.score),
|
|
99
|
+
feedback: toPlainText(input.grade.feedback, { maxChars: AI_LIMITS.maxFeedbackChars }),
|
|
100
|
+
keyPoints: (question.rubric?.keyPoints ?? []).map((point) => toPlainText(point)),
|
|
101
|
+
modelAnswer: question.rubric?.modelAnswer === undefined ? null : toPlainText(question.rubric.modelAnswer, { keepNewlines: true }),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
if (input.text !== undefined)
|
|
106
|
+
return { type: "error", code: "bad-answer" };
|
|
107
|
+
const picked = pickedIndex(question.choices, input);
|
|
108
|
+
if (picked === undefined)
|
|
109
|
+
return { type: "error", code: "bad-answer" };
|
|
110
|
+
const answered = answerChoice(quiz.session, picked);
|
|
111
|
+
session = answered.session;
|
|
112
|
+
reveal = { kind: "choice", correct: answered.correct, answer: toPlainText(question.choices[answered.correctIndex] ?? "") };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error instanceof RangeError)
|
|
117
|
+
return { type: "error", code: "bad-answer" };
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
const updated = { ...quiz, session, lastUsedMs: nowMs };
|
|
121
|
+
const others = live.quizzes.filter((entry) => entry.id !== quiz.id);
|
|
122
|
+
if (isComplete(session))
|
|
123
|
+
return { type: "accepted", store: { quizzes: others }, reveal, next: null, finished: updated };
|
|
124
|
+
const upcoming = currentQuestion(session); // not complete, so there is one
|
|
125
|
+
const position = session.outcomes.length + 1;
|
|
126
|
+
// Keep the quiz where it was in the list.
|
|
127
|
+
const quizzes = live.quizzes.map((entry) => (entry.id === quiz.id ? updated : entry));
|
|
128
|
+
return { type: "accepted", store: { quizzes }, reveal, next: publicQuestion(upcoming, position, session.questions.length) };
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=mcp-quiz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-quiz.js","sourceRoot":"","sources":["../src/mcp-quiz.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AAC5H,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAwCjD,MAAM,UAAU,UAAU;IACxB,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,OAAO,IAAI,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,CAAC,CAAC;IAC7C,0CAA0C;IAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACtF,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;AAC9H,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const MCP_LIMITS: {
|
|
3
|
+
readonly maxOutputBytes: 65536;
|
|
4
|
+
readonly maxProjectBytes: 32768;
|
|
5
|
+
readonly maxProjectReadBytes: 1048576;
|
|
6
|
+
readonly maxSessions: 4;
|
|
7
|
+
readonly sessionIdleMs: 3600000;
|
|
8
|
+
readonly maxDue: 20;
|
|
9
|
+
readonly defaultDecisions: 3;
|
|
10
|
+
readonly maxDecisions: 10;
|
|
11
|
+
readonly maxQuestionIdChars: 200;
|
|
12
|
+
readonly maxChoiceNumber: 10;
|
|
13
|
+
readonly maxChoiceTextChars: 500;
|
|
14
|
+
readonly maxToolInputElements: 64;
|
|
15
|
+
readonly maxSummaryPaths: 20;
|
|
16
|
+
};
|
|
17
|
+
export declare const MCP_TOOL_NAMES: readonly ["get_project_context", "get_due_reviews", "get_decisions", "start_quiz", "submit_answer"];
|
|
18
|
+
export type McpToolName = (typeof MCP_TOOL_NAMES)[number];
|
|
19
|
+
export type McpErrorCode = "invalid-input" | "state-invalid" | "unknown-quiz" | "wrong-question" | "bad-answer" | "output-too-large" | "internal";
|
|
20
|
+
export type ToolReply = {
|
|
21
|
+
ok: true;
|
|
22
|
+
text: string;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
code: McpErrorCode;
|
|
26
|
+
text: string;
|
|
27
|
+
};
|
|
28
|
+
/** Quiz ids are `mq_` plus 16 lowercase hex characters. */
|
|
29
|
+
export declare const QUIZ_ID_PATTERN: RegExp;
|
|
30
|
+
export declare const EmptyInputSchema: z.ZodObject<{}, z.core.$strict>;
|
|
31
|
+
export declare const GetDecisionsInputSchema: z.ZodObject<{
|
|
32
|
+
count: z.ZodOptional<z.ZodInt>;
|
|
33
|
+
}, z.core.$strict>;
|
|
34
|
+
export declare const SubmitAnswerInputSchema: z.ZodObject<{
|
|
35
|
+
quizId: z.ZodString;
|
|
36
|
+
questionId: z.ZodString;
|
|
37
|
+
choiceNumber: z.ZodOptional<z.ZodInt>;
|
|
38
|
+
choiceText: z.ZodOptional<z.ZodString>;
|
|
39
|
+
text: z.ZodOptional<z.ZodString>;
|
|
40
|
+
}, z.core.$strict>;
|
|
41
|
+
export declare const MCP_INPUT_SCHEMAS: {
|
|
42
|
+
readonly get_project_context: z.ZodObject<{}, z.core.$strict>;
|
|
43
|
+
readonly get_due_reviews: z.ZodObject<{}, z.core.$strict>;
|
|
44
|
+
readonly get_decisions: z.ZodObject<{
|
|
45
|
+
count: z.ZodOptional<z.ZodInt>;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
readonly start_quiz: z.ZodObject<{}, z.core.$strict>;
|
|
48
|
+
readonly submit_answer: z.ZodObject<{
|
|
49
|
+
quizId: z.ZodString;
|
|
50
|
+
questionId: z.ZodString;
|
|
51
|
+
choiceNumber: z.ZodOptional<z.ZodInt>;
|
|
52
|
+
choiceText: z.ZodOptional<z.ZodString>;
|
|
53
|
+
text: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, z.core.$strict>;
|
|
55
|
+
};
|
|
56
|
+
/** The fixed error texts. `<currentId>` in `wrong-question` is replaced by `mcpError`. */
|
|
57
|
+
export declare const MCP_ERRORS: Record<McpErrorCode, string>;
|
|
58
|
+
/** An error reply with its fixed text. The question id (from our own quiz, still cleaned) is only used by `wrong-question`. */
|
|
59
|
+
export declare function mcpError(code: McpErrorCode, currentId?: string): ToolReply;
|
|
60
|
+
/**
|
|
61
|
+
* True for a path that stays inside the project: POSIX separators, no `..` or `.` segment, no empty segment, not absolute,
|
|
62
|
+
* no drive letter or NUL. Paths from git, the state file or the map are checked before they reach a tool result.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isSafeRelativePath(path: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The JSON of `build(prefix, truncated)` for the longest prefix of `items` whose JSON is at most `maxBytes` (UTF-8).
|
|
67
|
+
* `truncated` is true when an item was dropped. If even the empty list does not fit, the empty-list JSON is returned
|
|
68
|
+
* and the caller (`toolText`) rejects it.
|
|
69
|
+
*/
|
|
70
|
+
export declare function fitList<T>(build: (items: T[], truncated: boolean) => unknown, items: readonly T[], maxBytes: number): string;
|
|
71
|
+
/**
|
|
72
|
+
* Cuts `text` at a code point boundary so that `JSON.stringify(result.text)` is at most `maxBytes` UTF-8 bytes
|
|
73
|
+
* (quotes and escapes counted). The result is a prefix of the input.
|
|
74
|
+
*/
|
|
75
|
+
export declare function capJsonText(text: string, maxBytes: number): {
|
|
76
|
+
text: string;
|
|
77
|
+
truncated: boolean;
|
|
78
|
+
};
|
|
79
|
+
/** A reply holding this JSON text, or `output-too-large` when it is over 64 KB. */
|
|
80
|
+
export declare function replyFromJson(text: string): ToolReply;
|
|
81
|
+
/** The JSON reply for a value, or `output-too-large` when it is over 64 KB (or cannot be written as JSON). */
|
|
82
|
+
export declare function toolText(value: unknown): ToolReply;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// The shared pieces of the Seance MCP server (Task 11): limits, tool names, strict input schemas, fixed error texts
|
|
2
|
+
// and helpers that keep every tool result within its byte cap. Pure: no I/O.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { AI_LIMITS } from "./ai-schemas.js";
|
|
5
|
+
export const MCP_LIMITS = {
|
|
6
|
+
maxOutputBytes: 65_536,
|
|
7
|
+
maxProjectBytes: 32_768,
|
|
8
|
+
maxProjectReadBytes: 1_048_576,
|
|
9
|
+
maxSessions: 4,
|
|
10
|
+
sessionIdleMs: 3_600_000,
|
|
11
|
+
maxDue: 20,
|
|
12
|
+
defaultDecisions: 3,
|
|
13
|
+
maxDecisions: 10,
|
|
14
|
+
maxQuestionIdChars: 200,
|
|
15
|
+
maxChoiceNumber: 10,
|
|
16
|
+
maxChoiceTextChars: 500,
|
|
17
|
+
maxToolInputElements: 64,
|
|
18
|
+
maxSummaryPaths: 20,
|
|
19
|
+
};
|
|
20
|
+
export const MCP_TOOL_NAMES = ["get_project_context", "get_due_reviews", "get_decisions", "start_quiz", "submit_answer"];
|
|
21
|
+
/** Quiz ids are `mq_` plus 16 lowercase hex characters. */
|
|
22
|
+
export const QUIZ_ID_PATTERN = /^mq_[0-9a-f]{16}$/;
|
|
23
|
+
// Strict objects: an unknown key fails the call.
|
|
24
|
+
export const EmptyInputSchema = z.strictObject({});
|
|
25
|
+
export const GetDecisionsInputSchema = z.strictObject({ count: z.int().min(1).max(MCP_LIMITS.maxDecisions).optional() });
|
|
26
|
+
export const SubmitAnswerInputSchema = z.strictObject({
|
|
27
|
+
quizId: z.string().regex(QUIZ_ID_PATTERN),
|
|
28
|
+
questionId: z.string().min(1).max(MCP_LIMITS.maxQuestionIdChars),
|
|
29
|
+
// `choiceNumber` is the 1-based number the user saw next to the choice (changed Dec 2 after manual test: it was a 0-based `choiceIndex`).
|
|
30
|
+
choiceNumber: z.int().min(1).max(MCP_LIMITS.maxChoiceNumber).optional(),
|
|
31
|
+
choiceText: z.string().min(1).max(MCP_LIMITS.maxChoiceTextChars).optional(),
|
|
32
|
+
text: z.string().max(AI_LIMITS.maxAnswerChars).optional(),
|
|
33
|
+
});
|
|
34
|
+
export const MCP_INPUT_SCHEMAS = {
|
|
35
|
+
get_project_context: EmptyInputSchema,
|
|
36
|
+
get_due_reviews: EmptyInputSchema,
|
|
37
|
+
get_decisions: GetDecisionsInputSchema,
|
|
38
|
+
start_quiz: EmptyInputSchema,
|
|
39
|
+
submit_answer: SubmitAnswerInputSchema,
|
|
40
|
+
};
|
|
41
|
+
/** The fixed error texts. `<currentId>` in `wrong-question` is replaced by `mcpError`. */
|
|
42
|
+
export const MCP_ERRORS = {
|
|
43
|
+
"invalid-input": "seance: invalid input; send exactly one of choiceNumber (the 1-based number the user saw), choiceText (the exact choice text) or text (explain questions); choiceIndex is no longer accepted",
|
|
44
|
+
"state-invalid": "seance: .seance/state.json is invalid; fix or delete it",
|
|
45
|
+
"unknown-quiz": "seance: quiz not found or expired; call start_quiz",
|
|
46
|
+
"wrong-question": "seance: answer question <currentId> first",
|
|
47
|
+
"bad-answer": "seance: use choiceNumber (1 to the number of choices) or choiceText (exact text of one choice) for a choice question and text for an explain question",
|
|
48
|
+
"output-too-large": "seance: result too large",
|
|
49
|
+
internal: "seance: internal error",
|
|
50
|
+
};
|
|
51
|
+
const ID_IN_ERROR_CHARS = 200;
|
|
52
|
+
/** An error reply with its fixed text. The question id (from our own quiz, still cleaned) is only used by `wrong-question`. */
|
|
53
|
+
export function mcpError(code, currentId) {
|
|
54
|
+
let text = MCP_ERRORS[code];
|
|
55
|
+
if (code === "wrong-question") {
|
|
56
|
+
const id = Array.from(String(currentId ?? "").replace(/[^\x20-\x7e]/g, " ")).slice(0, ID_IN_ERROR_CHARS).join("");
|
|
57
|
+
text = text.replace("<currentId>", id);
|
|
58
|
+
}
|
|
59
|
+
return { ok: false, code, text };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* True for a path that stays inside the project: POSIX separators, no `..` or `.` segment, no empty segment, not absolute,
|
|
63
|
+
* no drive letter or NUL. Paths from git, the state file or the map are checked before they reach a tool result.
|
|
64
|
+
*/
|
|
65
|
+
export function isSafeRelativePath(path) {
|
|
66
|
+
if (path === "" || path.includes("\\") || path.includes(":") || path.includes("\0"))
|
|
67
|
+
return false;
|
|
68
|
+
return path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
69
|
+
}
|
|
70
|
+
const encoder = new TextEncoder();
|
|
71
|
+
function utf8Bytes(text) {
|
|
72
|
+
return encoder.encode(text).length;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The JSON of `build(prefix, truncated)` for the longest prefix of `items` whose JSON is at most `maxBytes` (UTF-8).
|
|
76
|
+
* `truncated` is true when an item was dropped. If even the empty list does not fit, the empty-list JSON is returned
|
|
77
|
+
* and the caller (`toolText`) rejects it.
|
|
78
|
+
*/
|
|
79
|
+
export function fitList(build, items, maxBytes) {
|
|
80
|
+
const json = (count) => JSON.stringify(build(items.slice(0, count), count < items.length)) ?? "null";
|
|
81
|
+
for (let count = items.length; count > 0; count -= 1) {
|
|
82
|
+
const text = json(count);
|
|
83
|
+
if (utf8Bytes(text) <= maxBytes)
|
|
84
|
+
return text;
|
|
85
|
+
}
|
|
86
|
+
return json(0);
|
|
87
|
+
}
|
|
88
|
+
/** Bytes that one UTF-16 unit or code point takes inside a JSON string (without the quotes). */
|
|
89
|
+
function jsonBytes(codePoint) {
|
|
90
|
+
if (codePoint === 0x22 || codePoint === 0x5c)
|
|
91
|
+
return 2;
|
|
92
|
+
if (codePoint < 0x20)
|
|
93
|
+
return codePoint === 0x08 || codePoint === 0x09 || codePoint === 0x0a || codePoint === 0x0c || codePoint === 0x0d ? 2 : 6;
|
|
94
|
+
if (codePoint < 0x80)
|
|
95
|
+
return 1;
|
|
96
|
+
if (codePoint < 0x800)
|
|
97
|
+
return 2;
|
|
98
|
+
if (codePoint >= 0xd800 && codePoint <= 0xdfff)
|
|
99
|
+
return 6; // a lone surrogate is written as \udXXX
|
|
100
|
+
return codePoint < 0x10000 ? 3 : 4;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Cuts `text` at a code point boundary so that `JSON.stringify(result.text)` is at most `maxBytes` UTF-8 bytes
|
|
104
|
+
* (quotes and escapes counted). The result is a prefix of the input.
|
|
105
|
+
*/
|
|
106
|
+
export function capJsonText(text, maxBytes) {
|
|
107
|
+
let bytes = 2; // the two quotes
|
|
108
|
+
let end = 0;
|
|
109
|
+
while (end < text.length) {
|
|
110
|
+
const codePoint = text.codePointAt(end) ?? 0;
|
|
111
|
+
const size = jsonBytes(codePoint);
|
|
112
|
+
if (bytes + size > maxBytes)
|
|
113
|
+
return { text: text.slice(0, end), truncated: true };
|
|
114
|
+
bytes += size;
|
|
115
|
+
end += codePoint > 0xffff ? 2 : 1;
|
|
116
|
+
}
|
|
117
|
+
return { text, truncated: false };
|
|
118
|
+
}
|
|
119
|
+
/** A reply holding this JSON text, or `output-too-large` when it is over 64 KB. */
|
|
120
|
+
export function replyFromJson(text) {
|
|
121
|
+
if (utf8Bytes(text) > MCP_LIMITS.maxOutputBytes)
|
|
122
|
+
return mcpError("output-too-large");
|
|
123
|
+
return { ok: true, text };
|
|
124
|
+
}
|
|
125
|
+
/** The JSON reply for a value, or `output-too-large` when it is over 64 KB (or cannot be written as JSON). */
|
|
126
|
+
export function toolText(value) {
|
|
127
|
+
let text;
|
|
128
|
+
try {
|
|
129
|
+
text = JSON.stringify(value);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return mcpError("internal");
|
|
133
|
+
}
|
|
134
|
+
return text === undefined ? mcpError("internal") : replyFromJson(text);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=mcp-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools.js","sourceRoot":"","sources":["../src/mcp-tools.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,6EAA6E;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,cAAc,EAAE,MAAM;IACtB,eAAe,EAAE,MAAM;IACvB,mBAAmB,EAAE,S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,CAAC;AACpC,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,cAAc;QAAE,OAAO,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IACrF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED,8GAA8G;AAC9G,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,IAAI,IAAwB,CAAC;IAC7B,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DecisionLog } from "./decision-log.js";
|
|
2
|
+
import { type ToolReply } from "./mcp-tools.js";
|
|
3
|
+
import type { SeanceState } from "./seance-state.js";
|
|
4
|
+
import type { Card } from "./sm2.js";
|
|
5
|
+
/**
|
|
6
|
+
* The reply of `get_project_context`. `projectText` is undefined when PROJECT.md is missing or unreadable. `state` is undefined when
|
|
7
|
+
* `.seance/state.json` is invalid: then only the PROJECT.md text is returned. `summary` are the `formatMapSummary` lines of the pending quiz files.
|
|
8
|
+
*/
|
|
9
|
+
export declare function projectContextView(input: {
|
|
10
|
+
projectText: string | undefined;
|
|
11
|
+
state: SeanceState | undefined;
|
|
12
|
+
summary: readonly string[];
|
|
13
|
+
today: string;
|
|
14
|
+
}): ToolReply;
|
|
15
|
+
/** The reply of `get_due_reviews`: up to 20 due cards, oldest first, cut further to fit 64 KB. */
|
|
16
|
+
export declare function dueReviewsView(cards: Readonly<Record<string, Card>>, today: string): ToolReply;
|
|
17
|
+
/**
|
|
18
|
+
* The reply of `get_decisions`: the last `count` entries (default 3, 1 to 10), newest first, missing fields as null.
|
|
19
|
+
* `log` is undefined when DECISIONS.md is missing or unreadable.
|
|
20
|
+
*/
|
|
21
|
+
export declare function decisionsView(log: DecisionLog | undefined, count?: number): ToolReply;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { DECISION_FIELDS } from "./decision-log.js";
|
|
2
|
+
import { MCP_LIMITS, capJsonText, fitList, isSafeRelativePath, replyFromJson, toolText } from "./mcp-tools.js";
|
|
3
|
+
import { dueCards, nextDueDate } from "./quiz-cards.js";
|
|
4
|
+
import { toPlainText } from "./terminal-text.js";
|
|
5
|
+
const MAX_SUMMARY_LINES = 12;
|
|
6
|
+
const MAX_SUMMARY_LINE_CHARS = 300;
|
|
7
|
+
const DUE_HINT = "Run seance review in a terminal to review these cards.";
|
|
8
|
+
function safePaths(paths) {
|
|
9
|
+
return paths.filter(isSafeRelativePath).map((path) => toPlainText(path));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The reply of `get_project_context`. `projectText` is undefined when PROJECT.md is missing or unreadable. `state` is undefined when
|
|
13
|
+
* `.seance/state.json` is invalid: then only the PROJECT.md text is returned. `summary` are the `formatMapSummary` lines of the pending quiz files.
|
|
14
|
+
*/
|
|
15
|
+
export function projectContextView(input) {
|
|
16
|
+
const project = input.projectText === undefined ? null : capJsonText(toPlainText(input.projectText, { keepNewlines: true }), MCP_LIMITS.maxProjectBytes);
|
|
17
|
+
const base = {
|
|
18
|
+
project,
|
|
19
|
+
...(project === null ? { note: "PROJECT.md is missing or is not a UTF-8 text file; run seance init" } : {}),
|
|
20
|
+
};
|
|
21
|
+
if (input.state === undefined)
|
|
22
|
+
return toolText({ ...base, state: "invalid" });
|
|
23
|
+
const state = input.state;
|
|
24
|
+
const pending = state.pendingQuiz;
|
|
25
|
+
const files = pending === undefined ? [] : safePaths(pending.files);
|
|
26
|
+
const { due, invalid } = dueCards(state.cards, input.today, Infinity);
|
|
27
|
+
const next = nextDueDate(state.cards);
|
|
28
|
+
return toolText({
|
|
29
|
+
...base,
|
|
30
|
+
state: "ok",
|
|
31
|
+
lastSync: state.lastSync === undefined ? null : toPlainText(state.lastSync.at),
|
|
32
|
+
pendingQuiz: pending === undefined
|
|
33
|
+
? null
|
|
34
|
+
: { createdAt: toPlainText(pending.createdAt), files: files.slice(0, MCP_LIMITS.maxSummaryPaths), filesTruncated: files.length > MCP_LIMITS.maxSummaryPaths },
|
|
35
|
+
summary: input.summary.slice(0, MAX_SUMMARY_LINES).map((line) => toPlainText(line, { maxChars: MAX_SUMMARY_LINE_CHARS })),
|
|
36
|
+
cards: { total: Object.keys(state.cards).length - invalid, due: due.length, nextReview: next === undefined ? null : next },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** The reply of `get_due_reviews`: up to 20 due cards, oldest first, cut further to fit 64 KB. */
|
|
40
|
+
export function dueReviewsView(cards, today) {
|
|
41
|
+
const { due, invalid } = dueCards(cards, today, Infinity);
|
|
42
|
+
const next = nextDueDate(cards);
|
|
43
|
+
const shown = due.slice(0, MCP_LIMITS.maxDue).map(({ key, card }) => {
|
|
44
|
+
const question = card.question;
|
|
45
|
+
const path = question.source?.path;
|
|
46
|
+
return {
|
|
47
|
+
key: toPlainText(key),
|
|
48
|
+
concept: toPlainText(card.concept),
|
|
49
|
+
kind: question.kind === "explain" ? "explain" : "choice",
|
|
50
|
+
path: path !== undefined && isSafeRelativePath(path) ? toPlainText(path) : null,
|
|
51
|
+
prompt: toPlainText(question.prompt, { keepNewlines: true }),
|
|
52
|
+
// Numbered from 1 like the quiz tools (changed Dec 2 after manual test), so an agent never shows or counts a 0-based list.
|
|
53
|
+
choices: question.kind === "explain" ? null : question.choices.map((choice, index) => ({ number: index + 1, text: toPlainText(choice) })),
|
|
54
|
+
addedAt: toPlainText(card.addedAt),
|
|
55
|
+
dueAt: toPlainText(card.dueAt),
|
|
56
|
+
reviews: card.reviews,
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
const dropped = due.length > shown.length;
|
|
60
|
+
const text = fitList((items, cut) => ({ today: toPlainText(today), due: items, truncated: cut || dropped, invalid, nextReview: next === undefined ? null : next, hint: DUE_HINT }), shown, MCP_LIMITS.maxOutputBytes);
|
|
61
|
+
return replyFromJson(text);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The reply of `get_decisions`: the last `count` entries (default 3, 1 to 10), newest first, missing fields as null.
|
|
65
|
+
* `log` is undefined when DECISIONS.md is missing or unreadable.
|
|
66
|
+
*/
|
|
67
|
+
export function decisionsView(log, count = MCP_LIMITS.defaultDecisions) {
|
|
68
|
+
const wanted = Math.min(MCP_LIMITS.maxDecisions, Math.max(1, Math.trunc(Number.isFinite(count) ? count : MCP_LIMITS.defaultDecisions)));
|
|
69
|
+
const entries = (log?.entries ?? []).slice(-wanted).reverse();
|
|
70
|
+
const shown = entries.map((entry) => ({
|
|
71
|
+
date: toPlainText(entry.date),
|
|
72
|
+
task: toPlainText(entry.task),
|
|
73
|
+
title: toPlainText(entry.title),
|
|
74
|
+
...Object.fromEntries(DECISION_FIELDS.map((field) => {
|
|
75
|
+
const value = entry.fields[field];
|
|
76
|
+
return [field, value === undefined ? null : toPlainText(value, { keepNewlines: true })];
|
|
77
|
+
})),
|
|
78
|
+
}));
|
|
79
|
+
const note = log === undefined ? "DECISIONS.md is missing or is not a UTF-8 text file; run seance init" : shown.length === 0 ? "no decisions are logged yet" : undefined;
|
|
80
|
+
const text = fitList((items, cut) => ({ total: log?.total ?? 0, entries: items, truncated: cut, ...(note === undefined ? {} : { note }) }), shown, MCP_LIMITS.maxOutputBytes);
|
|
81
|
+
return replyFromJson(text);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=mcp-views.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-views.js","sourceRoot":"","sources":["../src/mcp-views.ts"],"names":[],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js";
|
|
3
|
+
import type { StructureMap } from "./structure-map.js";
|
|
4
|
+
/** How many questions a quiz has. */
|
|
5
|
+
export declare const QUIZ_SIZE = 5;
|
|
6
|
+
export interface AssembledQuiz {
|
|
7
|
+
/** 0 to 5 questions with unique ids; each passes `QuizItemSchema`. */
|
|
8
|
+
questions: QuizItem[];
|
|
9
|
+
servedBy: QuizResponse["servedBy"];
|
|
10
|
+
model?: string;
|
|
11
|
+
/** True when the questions were built in the browser because the API gave no usable reply. */
|
|
12
|
+
local: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `reply` is the parsed `/api/quiz` reply, or `null` when the request failed or had no valid question.
|
|
16
|
+
* No reply: structural questions only. 5 or more questions: the first 5. 1 to 4: topped up with structural questions.
|
|
17
|
+
*/
|
|
18
|
+
export declare function assembleQuiz(reply: QuizResponse | null, map: StructureMap, options: {
|
|
19
|
+
seed: number;
|
|
20
|
+
attempt: number;
|
|
21
|
+
}): AssembledQuiz;
|