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,177 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type GateMode } from "./gate.js";
|
|
3
|
+
import { type InitAnswers } from "./init-checklist.js";
|
|
4
|
+
/** Bumped when a generated file's template changes in a way users should get on a re-run. */
|
|
5
|
+
export declare const TEMPLATE_VERSION = 1;
|
|
6
|
+
/** Most records a manifest may hold; a manifest with more is not ours (`planInit` never writes more). */
|
|
7
|
+
export declare const MAX_MANIFEST_RECORDS = 50;
|
|
8
|
+
/** One tracked file (or the AGENTS.md rules block): the hash of the content Seance last wrote. */
|
|
9
|
+
export interface ManifestRecord {
|
|
10
|
+
kind: "file" | "block";
|
|
11
|
+
hash: string;
|
|
12
|
+
template: string;
|
|
13
|
+
templateVersion: number;
|
|
14
|
+
}
|
|
15
|
+
/** `.seance/manifest.json`. Keys are POSIX paths; the AGENTS.md block uses the key "AGENTS.md#rules". */
|
|
16
|
+
export interface Manifest {
|
|
17
|
+
schemaVersion: 1;
|
|
18
|
+
records: Record<string, ManifestRecord>;
|
|
19
|
+
}
|
|
20
|
+
/** Checks a parsed `.seance/manifest.json`: version 1, at most 50 records, short keys, well-formed hashes. */
|
|
21
|
+
export declare const ManifestSchema: z.ZodObject<{
|
|
22
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
23
|
+
records: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
24
|
+
kind: z.ZodEnum<{
|
|
25
|
+
block: "block";
|
|
26
|
+
file: "file";
|
|
27
|
+
}>;
|
|
28
|
+
hash: z.ZodString;
|
|
29
|
+
template: z.ZodString;
|
|
30
|
+
templateVersion: z.ZodInt;
|
|
31
|
+
}, z.core.$strip>>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
/** Which rule files `init` writes: Kiro files (`.kiro/`) and/or a rules block in AGENTS.md. */
|
|
34
|
+
export type Target = "kiro" | "agents-md";
|
|
35
|
+
/** What the user chose besides the answers. `version` is the `seance-cli` version, kept in `createdWith`. */
|
|
36
|
+
export interface InitSettings {
|
|
37
|
+
targets: Target[];
|
|
38
|
+
gateMode: GateMode;
|
|
39
|
+
version: string;
|
|
40
|
+
}
|
|
41
|
+
/** `.seance/config.json`. Keys this version does not know are kept when the file is read and written again. */
|
|
42
|
+
export interface SeanceConfig {
|
|
43
|
+
schemaVersion: 1;
|
|
44
|
+
answers: InitAnswers;
|
|
45
|
+
targets: Target[];
|
|
46
|
+
gate: {
|
|
47
|
+
mode: GateMode;
|
|
48
|
+
passMark: number;
|
|
49
|
+
};
|
|
50
|
+
dependencyGuard: {
|
|
51
|
+
allow: string[];
|
|
52
|
+
};
|
|
53
|
+
createdWith: string;
|
|
54
|
+
}
|
|
55
|
+
export declare const SeanceConfigSchema: z.ZodObject<{
|
|
56
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
57
|
+
answers: z.ZodObject<{
|
|
58
|
+
audience: z.ZodOptional<z.ZodObject<{
|
|
59
|
+
value: z.ZodString;
|
|
60
|
+
source: z.ZodEnum<{
|
|
61
|
+
default: "default";
|
|
62
|
+
detected: "detected";
|
|
63
|
+
suggested: "suggested";
|
|
64
|
+
undecided: "undecided";
|
|
65
|
+
user: "user";
|
|
66
|
+
}>;
|
|
67
|
+
}, z.core.$strip>>;
|
|
68
|
+
conventions: z.ZodOptional<z.ZodObject<{
|
|
69
|
+
value: z.ZodString;
|
|
70
|
+
source: z.ZodEnum<{
|
|
71
|
+
default: "default";
|
|
72
|
+
detected: "detected";
|
|
73
|
+
suggested: "suggested";
|
|
74
|
+
undecided: "undecided";
|
|
75
|
+
user: "user";
|
|
76
|
+
}>;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
description: z.ZodOptional<z.ZodObject<{
|
|
79
|
+
value: z.ZodString;
|
|
80
|
+
source: z.ZodEnum<{
|
|
81
|
+
default: "default";
|
|
82
|
+
detected: "detected";
|
|
83
|
+
suggested: "suggested";
|
|
84
|
+
undecided: "undecided";
|
|
85
|
+
user: "user";
|
|
86
|
+
}>;
|
|
87
|
+
}, z.core.$strip>>;
|
|
88
|
+
experience: z.ZodOptional<z.ZodObject<{
|
|
89
|
+
value: z.ZodString;
|
|
90
|
+
source: z.ZodEnum<{
|
|
91
|
+
default: "default";
|
|
92
|
+
detected: "detected";
|
|
93
|
+
suggested: "suggested";
|
|
94
|
+
undecided: "undecided";
|
|
95
|
+
user: "user";
|
|
96
|
+
}>;
|
|
97
|
+
}, z.core.$strip>>;
|
|
98
|
+
framework: z.ZodOptional<z.ZodObject<{
|
|
99
|
+
value: z.ZodString;
|
|
100
|
+
source: z.ZodEnum<{
|
|
101
|
+
default: "default";
|
|
102
|
+
detected: "detected";
|
|
103
|
+
suggested: "suggested";
|
|
104
|
+
undecided: "undecided";
|
|
105
|
+
user: "user";
|
|
106
|
+
}>;
|
|
107
|
+
}, z.core.$strip>>;
|
|
108
|
+
language: z.ZodOptional<z.ZodObject<{
|
|
109
|
+
value: z.ZodString;
|
|
110
|
+
source: z.ZodEnum<{
|
|
111
|
+
default: "default";
|
|
112
|
+
detected: "detected";
|
|
113
|
+
suggested: "suggested";
|
|
114
|
+
undecided: "undecided";
|
|
115
|
+
user: "user";
|
|
116
|
+
}>;
|
|
117
|
+
}, z.core.$strip>>;
|
|
118
|
+
outOfScope: z.ZodOptional<z.ZodObject<{
|
|
119
|
+
value: z.ZodString;
|
|
120
|
+
source: z.ZodEnum<{
|
|
121
|
+
default: "default";
|
|
122
|
+
detected: "detected";
|
|
123
|
+
suggested: "suggested";
|
|
124
|
+
undecided: "undecided";
|
|
125
|
+
user: "user";
|
|
126
|
+
}>;
|
|
127
|
+
}, z.core.$strip>>;
|
|
128
|
+
packageManager: z.ZodOptional<z.ZodObject<{
|
|
129
|
+
value: z.ZodString;
|
|
130
|
+
source: z.ZodEnum<{
|
|
131
|
+
default: "default";
|
|
132
|
+
detected: "detected";
|
|
133
|
+
suggested: "suggested";
|
|
134
|
+
undecided: "undecided";
|
|
135
|
+
user: "user";
|
|
136
|
+
}>;
|
|
137
|
+
}, z.core.$strip>>;
|
|
138
|
+
projectName: z.ZodOptional<z.ZodObject<{
|
|
139
|
+
value: z.ZodString;
|
|
140
|
+
source: z.ZodEnum<{
|
|
141
|
+
default: "default";
|
|
142
|
+
detected: "detected";
|
|
143
|
+
suggested: "suggested";
|
|
144
|
+
undecided: "undecided";
|
|
145
|
+
user: "user";
|
|
146
|
+
}>;
|
|
147
|
+
}, z.core.$strip>>;
|
|
148
|
+
testRunner: z.ZodOptional<z.ZodObject<{
|
|
149
|
+
value: z.ZodString;
|
|
150
|
+
source: z.ZodEnum<{
|
|
151
|
+
default: "default";
|
|
152
|
+
detected: "detected";
|
|
153
|
+
suggested: "suggested";
|
|
154
|
+
undecided: "undecided";
|
|
155
|
+
user: "user";
|
|
156
|
+
}>;
|
|
157
|
+
}, z.core.$strip>>;
|
|
158
|
+
}, z.core.$strip>;
|
|
159
|
+
targets: z.ZodArray<z.ZodEnum<{
|
|
160
|
+
"agents-md": "agents-md";
|
|
161
|
+
kiro: "kiro";
|
|
162
|
+
}>>;
|
|
163
|
+
gate: z.ZodObject<{
|
|
164
|
+
mode: z.ZodEnum<{
|
|
165
|
+
off: "off";
|
|
166
|
+
soft: "soft";
|
|
167
|
+
strict: "strict";
|
|
168
|
+
}>;
|
|
169
|
+
passMark: z.ZodDefault<z.ZodNumber>;
|
|
170
|
+
}, z.core.$loose>;
|
|
171
|
+
dependencyGuard: z.ZodDefault<z.ZodObject<{
|
|
172
|
+
allow: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
173
|
+
}, z.core.$loose>>;
|
|
174
|
+
createdWith: z.ZodString;
|
|
175
|
+
}, z.core.$loose>;
|
|
176
|
+
/** Where the first problem of a failed parse is, like `gate.mode`, for the `.seance/config.json is invalid: <path>` message. */
|
|
177
|
+
export declare function firstIssuePath(error: z.ZodError): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Types and zod schemas for the files `seance init` keeps in `.seance/`: the manifest (what Seance wrote)
|
|
2
|
+
// and the config (the answers and settings). Pure: no file access.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { DEFAULT_PASS_MARK } from "./gate.js";
|
|
5
|
+
import { InitAnswersSchema } from "./init-checklist.js";
|
|
6
|
+
/** Bumped when a generated file's template changes in a way users should get on a re-run. */
|
|
7
|
+
export const TEMPLATE_VERSION = 1;
|
|
8
|
+
/** Most records a manifest may hold; a manifest with more is not ours (`planInit` never writes more). */
|
|
9
|
+
export const MAX_MANIFEST_RECORDS = 50;
|
|
10
|
+
const recordSchema = z.object({
|
|
11
|
+
kind: z.enum(["file", "block"]),
|
|
12
|
+
hash: z.string().regex(/^fnv1a32:[0-9a-f]{8}$/),
|
|
13
|
+
template: z.string().min(1).max(60),
|
|
14
|
+
templateVersion: z.int().min(1).max(1_000_000),
|
|
15
|
+
});
|
|
16
|
+
/** Checks a parsed `.seance/manifest.json`: version 1, at most 50 records, short keys, well-formed hashes. */
|
|
17
|
+
export const ManifestSchema = z.object({
|
|
18
|
+
schemaVersion: z.literal(1),
|
|
19
|
+
records: z.record(z.string().min(1).max(200), recordSchema).refine((records) => Object.keys(records).length <= MAX_MANIFEST_RECORDS, { message: `at most ${MAX_MANIFEST_RECORDS} records` }),
|
|
20
|
+
});
|
|
21
|
+
/** Most package names a user can allow, and the longest npm package name. */
|
|
22
|
+
const MAX_ALLOWED_PACKAGES = 200;
|
|
23
|
+
const MAX_PACKAGE_NAME_LENGTH = 214;
|
|
24
|
+
// `looseObject` keeps unknown keys instead of dropping them, so a hand-edited file survives a re-run (req 3.4).
|
|
25
|
+
export const SeanceConfigSchema = z.looseObject({
|
|
26
|
+
schemaVersion: z.literal(1),
|
|
27
|
+
answers: InitAnswersSchema,
|
|
28
|
+
targets: z.array(z.enum(["kiro", "agents-md"])).min(1).max(2),
|
|
29
|
+
gate: z.looseObject({
|
|
30
|
+
mode: z.enum(["off", "soft", "strict"]),
|
|
31
|
+
passMark: z.number().min(0).max(1).default(DEFAULT_PASS_MARK),
|
|
32
|
+
}),
|
|
33
|
+
dependencyGuard: z
|
|
34
|
+
.looseObject({ allow: z.array(z.string().min(1).max(MAX_PACKAGE_NAME_LENGTH)).max(MAX_ALLOWED_PACKAGES).default([]) })
|
|
35
|
+
.default({ allow: [] }),
|
|
36
|
+
createdWith: z.string().min(1).max(60),
|
|
37
|
+
});
|
|
38
|
+
/** Where the first problem of a failed parse is, like `gate.mode`, for the `.seance/config.json is invalid: <path>` message. */
|
|
39
|
+
export function firstIssuePath(error) {
|
|
40
|
+
const path = error.issues[0]?.path ?? [];
|
|
41
|
+
return path.length === 0 ? "(root)" : path.map(String).join(".");
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=seance-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seance-config.js","sourceRoot":"","sources":["../src/seance-config.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,mEAAmE;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAiB,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAoB,MAAM,qBAAqB,CAAC;AAE1E,6FAA6F;AAC7F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,yGAAyG;AACzG,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAgBvC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,I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,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;QACvC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;KAC9D,CAAC;IACF,eAAe,EAAE,CAAC;SACf,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;SACrH,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IACzB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;CACvC,CAAC,CAAC;AAEH,gIAAgI;AAChI,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;IACzC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type QuizItem } from "./ai-schemas.js";
|
|
3
|
+
import type { Card } from "./sm2.js";
|
|
4
|
+
export declare const STATE_PATH = ".seance/state.json";
|
|
5
|
+
/** Size caps of the state file (bytes unless the name says chars or counts). */
|
|
6
|
+
export declare const STATE_LIMITS: {
|
|
7
|
+
readonly maxBytes: 262144;
|
|
8
|
+
readonly maxSnapshotFiles: 200;
|
|
9
|
+
readonly maxPathChars: 500;
|
|
10
|
+
readonly maxPendingFiles: 50;
|
|
11
|
+
readonly maxQuestions: 10;
|
|
12
|
+
readonly maxCards: 200;
|
|
13
|
+
readonly maxCardKeyChars: 100;
|
|
14
|
+
};
|
|
15
|
+
/** `blob:<hex hash>`, `deleted` or `other` (not a regular file). */
|
|
16
|
+
export type SnapshotValue = string;
|
|
17
|
+
/** What the last sync saw: when (ISO UTC), the HEAD commit (null when there was none) and a snapshot value per changed path. */
|
|
18
|
+
export interface LastSync {
|
|
19
|
+
at: string;
|
|
20
|
+
commit: string | null;
|
|
21
|
+
files: Record<string, SnapshotValue>;
|
|
22
|
+
}
|
|
23
|
+
/** The quiz sync saved for the latest change. `files` are the map files, so `seance quiz` can ask the AI about them. */
|
|
24
|
+
export interface PendingQuiz {
|
|
25
|
+
id: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
commit: string | null;
|
|
28
|
+
uncommitted: boolean;
|
|
29
|
+
files: string[];
|
|
30
|
+
questions: QuizItem[];
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
export interface SeanceState {
|
|
34
|
+
schemaVersion: 1;
|
|
35
|
+
lastSync?: LastSync;
|
|
36
|
+
pendingQuiz?: PendingQuiz;
|
|
37
|
+
cards: Record<string, Card>;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
/** Checks a parsed state file. Unknown keys survive at the top level, in the pending quiz and in each card. */
|
|
41
|
+
export declare const SeanceStateSchema: z.ZodObject<{
|
|
42
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
43
|
+
lastSync: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
at: z.ZodISODateTime;
|
|
45
|
+
commit: z.ZodNullable<z.ZodString>;
|
|
46
|
+
files: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
pendingQuiz: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
id: z.ZodString;
|
|
50
|
+
createdAt: z.ZodISODateTime;
|
|
51
|
+
commit: z.ZodNullable<z.ZodString>;
|
|
52
|
+
uncommitted: z.ZodBoolean;
|
|
53
|
+
files: z.ZodArray<z.ZodString>;
|
|
54
|
+
questions: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
55
|
+
id: z.ZodString;
|
|
56
|
+
concept: z.ZodEnum<{
|
|
57
|
+
"async-functions": "async-functions";
|
|
58
|
+
"call-graph": "call-graph";
|
|
59
|
+
classes: "classes";
|
|
60
|
+
"data-flow": "data-flow";
|
|
61
|
+
decision: "decision";
|
|
62
|
+
"error-handling": "error-handling";
|
|
63
|
+
exports: "exports";
|
|
64
|
+
imports: "imports";
|
|
65
|
+
parameters: "parameters";
|
|
66
|
+
"side-effects": "side-effects";
|
|
67
|
+
state: "state";
|
|
68
|
+
}>;
|
|
69
|
+
prompt: z.ZodString;
|
|
70
|
+
source: z.ZodObject<{
|
|
71
|
+
path: z.ZodString;
|
|
72
|
+
line: z.ZodOptional<z.ZodInt>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
origin: z.ZodEnum<{
|
|
75
|
+
ai: "ai";
|
|
76
|
+
structural: "structural";
|
|
77
|
+
}>;
|
|
78
|
+
kind: z.ZodEnum<{
|
|
79
|
+
mcq: "mcq";
|
|
80
|
+
"what-if": "what-if";
|
|
81
|
+
}>;
|
|
82
|
+
choices: z.ZodArray<z.ZodString>;
|
|
83
|
+
answerIndex: z.ZodInt;
|
|
84
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
85
|
+
id: z.ZodString;
|
|
86
|
+
concept: z.ZodEnum<{
|
|
87
|
+
"async-functions": "async-functions";
|
|
88
|
+
"call-graph": "call-graph";
|
|
89
|
+
classes: "classes";
|
|
90
|
+
"data-flow": "data-flow";
|
|
91
|
+
decision: "decision";
|
|
92
|
+
"error-handling": "error-handling";
|
|
93
|
+
exports: "exports";
|
|
94
|
+
imports: "imports";
|
|
95
|
+
parameters: "parameters";
|
|
96
|
+
"side-effects": "side-effects";
|
|
97
|
+
state: "state";
|
|
98
|
+
}>;
|
|
99
|
+
prompt: z.ZodString;
|
|
100
|
+
source: z.ZodObject<{
|
|
101
|
+
path: z.ZodString;
|
|
102
|
+
line: z.ZodOptional<z.ZodInt>;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
origin: z.ZodEnum<{
|
|
105
|
+
ai: "ai";
|
|
106
|
+
structural: "structural";
|
|
107
|
+
}>;
|
|
108
|
+
kind: z.ZodLiteral<"explain">;
|
|
109
|
+
rubric: z.ZodObject<{
|
|
110
|
+
keyPoints: z.ZodArray<z.ZodString>;
|
|
111
|
+
modelAnswer: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
}, z.core.$strip>]>>;
|
|
114
|
+
}, z.core.$loose>>;
|
|
115
|
+
cards: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
116
|
+
ease: z.ZodNumber;
|
|
117
|
+
interval: z.ZodInt;
|
|
118
|
+
repetitions: z.ZodInt;
|
|
119
|
+
dueAt: z.ZodString;
|
|
120
|
+
}, z.core.$loose>>>;
|
|
121
|
+
}, z.core.$loose>;
|
|
122
|
+
/** A state with nothing in it. */
|
|
123
|
+
export declare function emptyState(): SeanceState;
|
|
124
|
+
/** Two-space JSON with a final newline, as written to disk. */
|
|
125
|
+
export declare function serializeState(state: SeanceState): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// The shape of `.seance/state.json`: what the last `seance sync` saw, the pending quiz, and the SM-2 cards (Task 7).
|
|
2
|
+
// Pure: a zod schema with size caps, an empty state and a serializer. Unknown keys are kept so later tasks can add fields.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { QuizItemSchema } from "./ai-schemas.js";
|
|
5
|
+
export const STATE_PATH = ".seance/state.json";
|
|
6
|
+
/** Size caps of the state file (bytes unless the name says chars or counts). */
|
|
7
|
+
export const STATE_LIMITS = {
|
|
8
|
+
maxBytes: 262_144,
|
|
9
|
+
maxSnapshotFiles: 200,
|
|
10
|
+
maxPathChars: 500,
|
|
11
|
+
maxPendingFiles: 50,
|
|
12
|
+
maxQuestions: 10,
|
|
13
|
+
maxCards: 200,
|
|
14
|
+
maxCardKeyChars: 100,
|
|
15
|
+
};
|
|
16
|
+
const HASH = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
17
|
+
const SNAPSHOT_VALUE = /^(blob:[0-9a-f]{40}([0-9a-f]{24})?|deleted|other)$/;
|
|
18
|
+
const pathSchema = z.string().min(1).max(STATE_LIMITS.maxPathChars);
|
|
19
|
+
const hashSchema = z.string().regex(HASH);
|
|
20
|
+
const lastSyncSchema = z.object({
|
|
21
|
+
at: z.iso.datetime(),
|
|
22
|
+
commit: hashSchema.nullable(),
|
|
23
|
+
files: z
|
|
24
|
+
.record(pathSchema, z.string().regex(SNAPSHOT_VALUE))
|
|
25
|
+
.refine((files) => Object.keys(files).length <= STATE_LIMITS.maxSnapshotFiles, {
|
|
26
|
+
message: `at most ${STATE_LIMITS.maxSnapshotFiles} snapshot files`,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
const pendingSchema = z.looseObject({
|
|
30
|
+
id: z.string().regex(/^sync-[0-9a-f]{8}$/),
|
|
31
|
+
createdAt: z.iso.datetime(),
|
|
32
|
+
commit: hashSchema.nullable(),
|
|
33
|
+
uncommitted: z.boolean(),
|
|
34
|
+
files: z.array(pathSchema).max(STATE_LIMITS.maxPendingFiles),
|
|
35
|
+
questions: z.array(QuizItemSchema).max(STATE_LIMITS.maxQuestions),
|
|
36
|
+
});
|
|
37
|
+
const cardSchema = z.looseObject({
|
|
38
|
+
ease: z.number().min(1.3),
|
|
39
|
+
interval: z.int().min(0).max(365),
|
|
40
|
+
repetitions: z.int().min(0),
|
|
41
|
+
dueAt: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
42
|
+
});
|
|
43
|
+
/** Checks a parsed state file. Unknown keys survive at the top level, in the pending quiz and in each card. */
|
|
44
|
+
export const SeanceStateSchema = z.looseObject({
|
|
45
|
+
schemaVersion: z.literal(1),
|
|
46
|
+
lastSync: lastSyncSchema.optional(),
|
|
47
|
+
pendingQuiz: pendingSchema.optional(),
|
|
48
|
+
cards: z
|
|
49
|
+
.record(z.string().min(1).max(STATE_LIMITS.maxCardKeyChars), cardSchema)
|
|
50
|
+
.refine((cards) => Object.keys(cards).length <= STATE_LIMITS.maxCards, { message: `at most ${STATE_LIMITS.maxCards} cards` })
|
|
51
|
+
.default({}),
|
|
52
|
+
});
|
|
53
|
+
/** A state with nothing in it. */
|
|
54
|
+
export function emptyState() {
|
|
55
|
+
return { schemaVersion: 1, cards: {} };
|
|
56
|
+
}
|
|
57
|
+
/** Two-space JSON with a final newline, as written to disk. */
|
|
58
|
+
export function serializeState(state) {
|
|
59
|
+
return JSON.stringify(state, null, 2) + "\n";
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=seance-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seance-state.js","sourceRoot":"","sources":["../src/seance-state.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,2HAA2H;AAC3H,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAiB,MAAM,iBAAiB,CAAC;AAEhE,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAC/C,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,QAAQ,EAAE,OAAO;IACjB,gBAAgB,EAAE,GAAG;IACrB,YAAY,EAAE,GAAG;IACjB,eAAe,EAAE,EAAE;IACnB,YAAY,EAAE,EAAE;IAChB,QAAQ,EAAE,GAAG;IACb,eAAe,EAAE,GAAG;CACZ,CAAC;AA0BX,MAAM,IAAI,GAAG,+BAA+B,CAAC;AAC7C,MAAM,cAAc,GAA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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** How well you remembered: 0 = blackout ... 5 = perfect. */
|
|
2
|
+
export type Quality = 0 | 1 | 2 | 3 | 4 | 5;
|
|
3
|
+
/** One concept's review state. `dueAt` is a calendar date written YYYY-MM-DD. */
|
|
4
|
+
export interface Card {
|
|
5
|
+
ease: number;
|
|
6
|
+
interval: number;
|
|
7
|
+
repetitions: number;
|
|
8
|
+
dueAt: string;
|
|
9
|
+
}
|
|
10
|
+
/** Longest wait between two reviews, so every card returns at least once a year. */
|
|
11
|
+
export declare const MAX_INTERVAL_DAYS = 365;
|
|
12
|
+
/** A brand-new card: default ease, no history, due today. */
|
|
13
|
+
export declare function newCard(today: string): Card;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the card after one review. The input card is never changed.
|
|
16
|
+
* `quality` is typed `number` on purpose so bad values from untyped callers are caught.
|
|
17
|
+
*/
|
|
18
|
+
export declare function nextReview(card: Card, quality: number, today: string): Card;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SM-2 spaced repetition: decides when a missed concept comes back for review.
|
|
2
|
+
// Pure functions only. The caller passes "today" in, so nothing here reads the clock.
|
|
3
|
+
/** Longest wait between two reviews, so every card returns at least once a year. */
|
|
4
|
+
export const MAX_INTERVAL_DAYS = 365;
|
|
5
|
+
const MIN_EASE = 1.3;
|
|
6
|
+
const MS_PER_DAY = 86_400_000;
|
|
7
|
+
/** Reads "YYYY-MM-DD" into a UTC timestamp. Throws RangeError for fake dates like 2026-02-30. */
|
|
8
|
+
function parseIsoDate(value, field) {
|
|
9
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
10
|
+
throw new RangeError(`${field} must be an ISO date (YYYY-MM-DD), got ${String(value)}`);
|
|
11
|
+
}
|
|
12
|
+
const [year, month, day] = value.split("-").map(Number);
|
|
13
|
+
const time = Date.UTC(year, month - 1, day);
|
|
14
|
+
// Round trip: a date like 2026-02-30 rolls over to March, so it will not match.
|
|
15
|
+
if (new Date(time).toISOString().slice(0, 10) !== value) {
|
|
16
|
+
throw new RangeError(`${field} must be a real calendar date, got ${value}`);
|
|
17
|
+
}
|
|
18
|
+
return time;
|
|
19
|
+
}
|
|
20
|
+
/** Adds whole days to an ISO date. UTC avoids daylight-saving bugs. Years above 9999 are out of range (unreachable in practice). */
|
|
21
|
+
function addDays(isoDate, days) {
|
|
22
|
+
const time = parseIsoDate(isoDate, "date") + days * MS_PER_DAY;
|
|
23
|
+
return new Date(time).toISOString().slice(0, 10);
|
|
24
|
+
}
|
|
25
|
+
/** A brand-new card: default ease, no history, due today. */
|
|
26
|
+
export function newCard(today) {
|
|
27
|
+
parseIsoDate(today, "today");
|
|
28
|
+
return { ease: 2.5, interval: 0, repetitions: 0, dueAt: today };
|
|
29
|
+
}
|
|
30
|
+
/** Rounds to 2 decimals so saved files show 2.38 and not 2.3800000000000003. */
|
|
31
|
+
function round2(x) {
|
|
32
|
+
return Math.round(x * 100) / 100;
|
|
33
|
+
}
|
|
34
|
+
function isNonNegativeInteger(x) {
|
|
35
|
+
return typeof x === "number" && Number.isInteger(x) && x >= 0;
|
|
36
|
+
}
|
|
37
|
+
/** Throws RangeError when any card field is out of range. */
|
|
38
|
+
function validateCard(card) {
|
|
39
|
+
if (typeof card.ease !== "number" || !Number.isFinite(card.ease) || card.ease < MIN_EASE) {
|
|
40
|
+
throw new RangeError(`ease must be a finite number >= ${MIN_EASE}, got ${String(card.ease)}`);
|
|
41
|
+
}
|
|
42
|
+
if (!isNonNegativeInteger(card.interval)) {
|
|
43
|
+
throw new RangeError(`interval must be a non-negative integer, got ${String(card.interval)}`);
|
|
44
|
+
}
|
|
45
|
+
if (!isNonNegativeInteger(card.repetitions)) {
|
|
46
|
+
throw new RangeError(`repetitions must be a non-negative integer, got ${String(card.repetitions)}`);
|
|
47
|
+
}
|
|
48
|
+
parseIsoDate(card.dueAt, "card.dueAt");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the card after one review. The input card is never changed.
|
|
52
|
+
* `quality` is typed `number` on purpose so bad values from untyped callers are caught.
|
|
53
|
+
*/
|
|
54
|
+
export function nextReview(card, quality, today) {
|
|
55
|
+
if (!Number.isInteger(quality) || quality < 0 || quality > 5) {
|
|
56
|
+
throw new RangeError(`quality must be an integer 0..5, got ${String(quality)}`);
|
|
57
|
+
}
|
|
58
|
+
validateCard(card);
|
|
59
|
+
parseIsoDate(today, "today");
|
|
60
|
+
// How far from a perfect answer (0 for q = 5, 5 for q = 0).
|
|
61
|
+
const d = 5 - quality;
|
|
62
|
+
// SM-2 ease formula; ease never drops below 1.3.
|
|
63
|
+
const ease = round2(Math.max(MIN_EASE, card.ease + 0.1 - d * (0.08 + d * 0.02)));
|
|
64
|
+
let repetitions;
|
|
65
|
+
let interval;
|
|
66
|
+
if (quality < 3) {
|
|
67
|
+
// Failed: start the learning steps over and see the card again tomorrow.
|
|
68
|
+
repetitions = 0;
|
|
69
|
+
interval = 1;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
repetitions = card.repetitions + 1;
|
|
73
|
+
if (repetitions === 1) {
|
|
74
|
+
interval = 1; // first success: tomorrow
|
|
75
|
+
}
|
|
76
|
+
else if (repetitions === 2) {
|
|
77
|
+
interval = 6; // second success: in 6 days
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Later successes: grow by the OLD ease (the rating judges the last interval).
|
|
81
|
+
// At least 1 day, so a card with interval 0 is never due again on the same day.
|
|
82
|
+
interval = Math.max(1, Math.min(MAX_INTERVAL_DAYS, Math.round(card.interval * card.ease)));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { ease, interval, repetitions, dueAt: addDays(today, interval) };
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=sm2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sm2.js","sourceRoot":"","sources":["../src/sm2.ts"],"names":[],"mappings":"AAAA,+EAA+E;AA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GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7F,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const STORED_LIMITS: {
|
|
3
|
+
readonly maxLastResultBytes: 2048;
|
|
4
|
+
readonly maxConsentBytes: 1024;
|
|
5
|
+
};
|
|
6
|
+
export declare const LastResultSchema: z.ZodObject<{
|
|
7
|
+
at: z.ZodString;
|
|
8
|
+
score: z.ZodNumber;
|
|
9
|
+
understood: z.ZodBoolean;
|
|
10
|
+
servedBy: z.ZodEnum<{
|
|
11
|
+
gemini: "gemini";
|
|
12
|
+
nvidia: "nvidia";
|
|
13
|
+
openrouter: "openrouter";
|
|
14
|
+
structural: "structural";
|
|
15
|
+
}>;
|
|
16
|
+
model: z.ZodOptional<z.ZodString>;
|
|
17
|
+
local: z.ZodBoolean;
|
|
18
|
+
questions: z.ZodNumber;
|
|
19
|
+
missed: z.ZodNumber;
|
|
20
|
+
source: z.ZodEnum<{
|
|
21
|
+
demo: "demo";
|
|
22
|
+
paste: "paste";
|
|
23
|
+
}>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
export type LastResult = z.infer<typeof LastResultSchema>;
|
|
26
|
+
export declare const ConsentSchema: z.ZodObject<{
|
|
27
|
+
pastedCode: z.ZodLiteral<"dont-ask">;
|
|
28
|
+
at: z.ZodString;
|
|
29
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Zod schemas for the two small values the web app keeps in localStorage: the last quiz result and the consent flag.
|
|
2
|
+
// Strict (unknown keys fail). The byte caps apply to the raw text, so the reader checks them before it parses.
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { SERVED_BY_QUIZ } from "./api-schemas.js";
|
|
5
|
+
export const STORED_LIMITS = { maxLastResultBytes: 2_048, maxConsentBytes: 1_024 };
|
|
6
|
+
/** ISO UTC date-time such as `2026-11-30T10:00:00.000Z` that `Date.parse` accepts. */
|
|
7
|
+
const IsoUtcSchema = z
|
|
8
|
+
.string()
|
|
9
|
+
.regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/)
|
|
10
|
+
.refine((value) => !Number.isNaN(Date.parse(value)));
|
|
11
|
+
export const LastResultSchema = z.strictObject({
|
|
12
|
+
/** ISO UTC time of the run. */
|
|
13
|
+
at: IsoUtcSchema,
|
|
14
|
+
/** 0 to 1. */
|
|
15
|
+
score: z.number().min(0).max(1),
|
|
16
|
+
understood: z.boolean(),
|
|
17
|
+
servedBy: z.enum(SERVED_BY_QUIZ),
|
|
18
|
+
model: z.string().min(1).max(200).optional(),
|
|
19
|
+
/** True when the questions were built in the browser. */
|
|
20
|
+
local: z.boolean(),
|
|
21
|
+
questions: z.number().int().min(1).max(10),
|
|
22
|
+
missed: z.number().int().min(0).max(10),
|
|
23
|
+
source: z.enum(["demo", "paste"]),
|
|
24
|
+
});
|
|
25
|
+
export const ConsentSchema = z.strictObject({
|
|
26
|
+
pastedCode: z.literal("dont-ask"),
|
|
27
|
+
at: IsoUtcSchema,
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=stored-schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-schemas.js","sourceRoot":"","sources":["../src/stored-schemas.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,+GAA+G;AAC/G,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAW,CAAC;AAE5F,sFAA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@
|
|
|
1
|
+
import type { StructureMap } from "./structure-map.js";
|
|
2
|
+
/** The skill a question tests. These tags become SM-2 card names, so do not rename them. */
|
|
3
|
+
export type StructuralConcept = "exports" | "imports" | "call-graph" | "classes" | "async-functions" | "parameters";
|
|
4
|
+
/** A multiple-choice question. It fits Task 2's `QuizQuestion` (kind "mcq") and adds a prompt and a source. */
|
|
5
|
+
export interface StructuralQuestion {
|
|
6
|
+
id: string;
|
|
7
|
+
concept: StructuralConcept;
|
|
8
|
+
kind: "mcq";
|
|
9
|
+
choices: string[];
|
|
10
|
+
answerIndex: number;
|
|
11
|
+
prompt: string;
|
|
12
|
+
source: {
|
|
13
|
+
path: string;
|
|
14
|
+
line: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface StructuralQuestionOptions {
|
|
18
|
+
/** How many questions to return, 0 to 50. Default 5. */
|
|
19
|
+
count?: number;
|
|
20
|
+
/** Picks which questions and wrong answers appear. Default 0. One per sync. */
|
|
21
|
+
seed?: number;
|
|
22
|
+
/** Only changes the order of the choices, so a retake cannot be passed by remembering positions. Default 0. */
|
|
23
|
+
attempt?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* FNV-1a, a tiny 32-bit hash. It gives the same number for the same text on every machine,
|
|
27
|
+
* which is what we need instead of Math.random: order and picks stay repeatable.
|
|
28
|
+
*/
|
|
29
|
+
export declare function fnv1a32(text: string): number;
|
|
30
|
+
/** Makes up to `count` multiple-choice questions from the map. Throws RangeError for bad options. */
|
|
31
|
+
export declare function generateStructuralQuestions(map: StructureMap, options?: StructuralQuestionOptions): StructuralQuestion[];
|