seance-cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/commands/init.d.ts +29 -0
  4. package/dist/commands/init.js +310 -0
  5. package/dist/commands/init.js.map +1 -0
  6. package/dist/commands/mcp.d.ts +19 -0
  7. package/dist/commands/mcp.js +38 -0
  8. package/dist/commands/mcp.js.map +1 -0
  9. package/dist/commands/quiz.d.ts +23 -0
  10. package/dist/commands/quiz.js +187 -0
  11. package/dist/commands/quiz.js.map +1 -0
  12. package/dist/commands/review.d.ts +4 -0
  13. package/dist/commands/review.js +115 -0
  14. package/dist/commands/review.js.map +1 -0
  15. package/dist/commands/sync.d.ts +17 -0
  16. package/dist/commands/sync.js +367 -0
  17. package/dist/commands/sync.js.map +1 -0
  18. package/dist/git.d.ts +33 -0
  19. package/dist/git.js +103 -0
  20. package/dist/git.js.map +1 -0
  21. package/dist/hosted-api.d.ts +24 -0
  22. package/dist/hosted-api.js +85 -0
  23. package/dist/hosted-api.js.map +1 -0
  24. package/dist/hosted-consent.d.ts +8 -0
  25. package/dist/hosted-consent.js +37 -0
  26. package/dist/hosted-consent.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +108 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/init-fs.d.ts +51 -0
  31. package/dist/init-fs.js +220 -0
  32. package/dist/init-fs.js.map +1 -0
  33. package/dist/init-questions.d.ts +21 -0
  34. package/dist/init-questions.js +161 -0
  35. package/dist/init-questions.js.map +1 -0
  36. package/dist/mcp-handlers.d.ts +22 -0
  37. package/dist/mcp-handlers.js +185 -0
  38. package/dist/mcp-handlers.js.map +1 -0
  39. package/dist/mcp-server.d.ts +4 -0
  40. package/dist/mcp-server.js +39 -0
  41. package/dist/mcp-server.js.map +1 -0
  42. package/dist/prompter.d.ts +29 -0
  43. package/dist/prompter.js +42 -0
  44. package/dist/prompter.js.map +1 -0
  45. package/dist/quiz-backend.d.ts +40 -0
  46. package/dist/quiz-backend.js +116 -0
  47. package/dist/quiz-backend.js.map +1 -0
  48. package/dist/quiz-input.d.ts +12 -0
  49. package/dist/quiz-input.js +52 -0
  50. package/dist/quiz-input.js.map +1 -0
  51. package/dist/quiz-io.d.ts +30 -0
  52. package/dist/quiz-io.js +83 -0
  53. package/dist/quiz-io.js.map +1 -0
  54. package/dist/quiz-ui.d.ts +18 -0
  55. package/dist/quiz-ui.js +51 -0
  56. package/dist/quiz-ui.js.map +1 -0
  57. package/node_modules/@seance/ai/LICENSE +21 -0
  58. package/node_modules/@seance/ai/dist/chain.d.ts +31 -0
  59. package/node_modules/@seance/ai/dist/chain.js +114 -0
  60. package/node_modules/@seance/ai/dist/chain.js.map +1 -0
  61. package/node_modules/@seance/ai/dist/grade.d.ts +14 -0
  62. package/node_modules/@seance/ai/dist/grade.js +44 -0
  63. package/node_modules/@seance/ai/dist/grade.js.map +1 -0
  64. package/node_modules/@seance/ai/dist/hosted-config.d.ts +9 -0
  65. package/node_modules/@seance/ai/dist/hosted-config.js +27 -0
  66. package/node_modules/@seance/ai/dist/hosted-config.js.map +1 -0
  67. package/node_modules/@seance/ai/dist/index.d.ts +9 -0
  68. package/node_modules/@seance/ai/dist/index.js +9 -0
  69. package/node_modules/@seance/ai/dist/index.js.map +1 -0
  70. package/node_modules/@seance/ai/dist/providers.d.ts +54 -0
  71. package/node_modules/@seance/ai/dist/providers.js +149 -0
  72. package/node_modules/@seance/ai/dist/providers.js.map +1 -0
  73. package/node_modules/@seance/ai/dist/quiz.d.ts +26 -0
  74. package/node_modules/@seance/ai/dist/quiz.js +41 -0
  75. package/node_modules/@seance/ai/dist/quiz.js.map +1 -0
  76. package/node_modules/@seance/ai/package.json +25 -0
  77. package/node_modules/@seance/core/LICENSE +21 -0
  78. package/node_modules/@seance/core/dist/ai-check.d.ts +58 -0
  79. package/node_modules/@seance/core/dist/ai-check.js +460 -0
  80. package/node_modules/@seance/core/dist/ai-check.js.map +1 -0
  81. package/node_modules/@seance/core/dist/ai-prompts.d.ts +29 -0
  82. package/node_modules/@seance/core/dist/ai-prompts.js +221 -0
  83. package/node_modules/@seance/core/dist/ai-prompts.js.map +1 -0
  84. package/node_modules/@seance/core/dist/ai-schemas.d.ts +155 -0
  85. package/node_modules/@seance/core/dist/ai-schemas.js +92 -0
  86. package/node_modules/@seance/core/dist/ai-schemas.js.map +1 -0
  87. package/node_modules/@seance/core/dist/api-client.d.ts +26 -0
  88. package/node_modules/@seance/core/dist/api-client.js +71 -0
  89. package/node_modules/@seance/core/dist/api-client.js.map +1 -0
  90. package/node_modules/@seance/core/dist/api-errors.d.ts +37 -0
  91. package/node_modules/@seance/core/dist/api-errors.js +66 -0
  92. package/node_modules/@seance/core/dist/api-errors.js.map +1 -0
  93. package/node_modules/@seance/core/dist/api-schemas.d.ts +284 -0
  94. package/node_modules/@seance/core/dist/api-schemas.js +67 -0
  95. package/node_modules/@seance/core/dist/api-schemas.js.map +1 -0
  96. package/node_modules/@seance/core/dist/decision-log.d.ts +73 -0
  97. package/node_modules/@seance/core/dist/decision-log.js +239 -0
  98. package/node_modules/@seance/core/dist/decision-log.js.map +1 -0
  99. package/node_modules/@seance/core/dist/dependency-guard.d.ts +20 -0
  100. package/node_modules/@seance/core/dist/dependency-guard.js +732 -0
  101. package/node_modules/@seance/core/dist/dependency-guard.js.map +1 -0
  102. package/node_modules/@seance/core/dist/gate.d.ts +11 -0
  103. package/node_modules/@seance/core/dist/gate.js +26 -0
  104. package/node_modules/@seance/core/dist/gate.js.map +1 -0
  105. package/node_modules/@seance/core/dist/git-parse.d.ts +11 -0
  106. package/node_modules/@seance/core/dist/git-parse.js +23 -0
  107. package/node_modules/@seance/core/dist/git-parse.js.map +1 -0
  108. package/node_modules/@seance/core/dist/index.d.ts +65 -0
  109. package/node_modules/@seance/core/dist/index.js +47 -0
  110. package/node_modules/@seance/core/dist/index.js.map +1 -0
  111. package/node_modules/@seance/core/dist/init-checklist.d.ts +153 -0
  112. package/node_modules/@seance/core/dist/init-checklist.js +200 -0
  113. package/node_modules/@seance/core/dist/init-checklist.js.map +1 -0
  114. package/node_modules/@seance/core/dist/init-detect.d.ts +9 -0
  115. package/node_modules/@seance/core/dist/init-detect.js +84 -0
  116. package/node_modules/@seance/core/dist/init-detect.js.map +1 -0
  117. package/node_modules/@seance/core/dist/init-templates.d.ts +36 -0
  118. package/node_modules/@seance/core/dist/init-templates.js +257 -0
  119. package/node_modules/@seance/core/dist/init-templates.js.map +1 -0
  120. package/node_modules/@seance/core/dist/map-basics.d.ts +13 -0
  121. package/node_modules/@seance/core/dist/map-basics.js +19 -0
  122. package/node_modules/@seance/core/dist/map-basics.js.map +1 -0
  123. package/node_modules/@seance/core/dist/map-summary.d.ts +5 -0
  124. package/node_modules/@seance/core/dist/map-summary.js +50 -0
  125. package/node_modules/@seance/core/dist/map-summary.js.map +1 -0
  126. package/node_modules/@seance/core/dist/markers.d.ts +51 -0
  127. package/node_modules/@seance/core/dist/markers.js +84 -0
  128. package/node_modules/@seance/core/dist/markers.js.map +1 -0
  129. package/node_modules/@seance/core/dist/mcp-quiz.d.ts +94 -0
  130. package/node_modules/@seance/core/dist/mcp-quiz.js +130 -0
  131. package/node_modules/@seance/core/dist/mcp-quiz.js.map +1 -0
  132. package/node_modules/@seance/core/dist/mcp-tools.d.ts +82 -0
  133. package/node_modules/@seance/core/dist/mcp-tools.js +136 -0
  134. package/node_modules/@seance/core/dist/mcp-tools.js.map +1 -0
  135. package/node_modules/@seance/core/dist/mcp-views.d.ts +21 -0
  136. package/node_modules/@seance/core/dist/mcp-views.js +83 -0
  137. package/node_modules/@seance/core/dist/mcp-views.js.map +1 -0
  138. package/node_modules/@seance/core/dist/quiz-assembly.d.ts +21 -0
  139. package/node_modules/@seance/core/dist/quiz-assembly.js +43 -0
  140. package/node_modules/@seance/core/dist/quiz-assembly.js.map +1 -0
  141. package/node_modules/@seance/core/dist/quiz-cards.d.ts +183 -0
  142. package/node_modules/@seance/core/dist/quiz-cards.js +215 -0
  143. package/node_modules/@seance/core/dist/quiz-cards.js.map +1 -0
  144. package/node_modules/@seance/core/dist/quiz-session.d.ts +67 -0
  145. package/node_modules/@seance/core/dist/quiz-session.js +141 -0
  146. package/node_modules/@seance/core/dist/quiz-session.js.map +1 -0
  147. package/node_modules/@seance/core/dist/quiz-subjects.d.ts +13 -0
  148. package/node_modules/@seance/core/dist/quiz-subjects.js +63 -0
  149. package/node_modules/@seance/core/dist/quiz-subjects.js.map +1 -0
  150. package/node_modules/@seance/core/dist/rate-limit.d.ts +33 -0
  151. package/node_modules/@seance/core/dist/rate-limit.js +114 -0
  152. package/node_modules/@seance/core/dist/rate-limit.js.map +1 -0
  153. package/node_modules/@seance/core/dist/scoring.d.ts +48 -0
  154. package/node_modules/@seance/core/dist/scoring.js +95 -0
  155. package/node_modules/@seance/core/dist/scoring.js.map +1 -0
  156. package/node_modules/@seance/core/dist/seance-config.d.ts +177 -0
  157. package/node_modules/@seance/core/dist/seance-config.js +43 -0
  158. package/node_modules/@seance/core/dist/seance-config.js.map +1 -0
  159. package/node_modules/@seance/core/dist/seance-state.d.ts +125 -0
  160. package/node_modules/@seance/core/dist/seance-state.js +61 -0
  161. package/node_modules/@seance/core/dist/seance-state.js.map +1 -0
  162. package/node_modules/@seance/core/dist/sm2.d.ts +18 -0
  163. package/node_modules/@seance/core/dist/sm2.js +87 -0
  164. package/node_modules/@seance/core/dist/sm2.js.map +1 -0
  165. package/node_modules/@seance/core/dist/stored-schemas.d.ts +29 -0
  166. package/node_modules/@seance/core/dist/stored-schemas.js +29 -0
  167. package/node_modules/@seance/core/dist/stored-schemas.js.map +1 -0
  168. package/node_modules/@seance/core/dist/structural-questions.d.ts +31 -0
  169. package/node_modules/@seance/core/dist/structural-questions.js +575 -0
  170. package/node_modules/@seance/core/dist/structural-questions.js.map +1 -0
  171. package/node_modules/@seance/core/dist/structure-map-schema.d.ts +84 -0
  172. package/node_modules/@seance/core/dist/structure-map-schema.js +73 -0
  173. package/node_modules/@seance/core/dist/structure-map-schema.js.map +1 -0
  174. package/node_modules/@seance/core/dist/structure-map.d.ts +78 -0
  175. package/node_modules/@seance/core/dist/structure-map.js +750 -0
  176. package/node_modules/@seance/core/dist/structure-map.js.map +1 -0
  177. package/node_modules/@seance/core/dist/sync-changes.d.ts +38 -0
  178. package/node_modules/@seance/core/dist/sync-changes.js +89 -0
  179. package/node_modules/@seance/core/dist/sync-changes.js.map +1 -0
  180. package/node_modules/@seance/core/dist/sync-render.d.ts +28 -0
  181. package/node_modules/@seance/core/dist/sync-render.js +113 -0
  182. package/node_modules/@seance/core/dist/sync-render.js.map +1 -0
  183. package/node_modules/@seance/core/dist/terminal-text.d.ts +8 -0
  184. package/node_modules/@seance/core/dist/terminal-text.js +33 -0
  185. package/node_modules/@seance/core/dist/terminal-text.js.map +1 -0
  186. package/node_modules/@seance/core/dist/write-plan.d.ts +51 -0
  187. package/node_modules/@seance/core/dist/write-plan.js +173 -0
  188. package/node_modules/@seance/core/dist/write-plan.js.map +1 -0
  189. package/node_modules/@seance/core/package.json +26 -0
  190. package/package.json +42 -6
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vedant Hande
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
1
+ # seance-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `seance` command. It quizzes you on the code your AI agent just built, using a real structure map of the changed files, and brings the concepts you miss back with SM-2 spaced repetition. It also writes rules for AI agents and a PROJECT.md that updates itself after each task.
4
+
5
+ Part of Seance, built for Kiroween 2026. Source and full docs: https://github.com/Vedant224/Kiroween
6
+
7
+ ## Install
8
+
9
+ ```
10
+ npm install --save-dev seance-cli
11
+ npx seance init
12
+ ```
13
+
14
+ Or run it once without installing: `npx seance-cli init`. Needs Node >= 22.13 and git.
15
+
16
+ ## Commands
17
+
18
+ Run `seance <command> --help` for all flags.
19
+
20
+ | Command | What it does |
21
+ |---|---|
22
+ | `seance init` | Asks a short checklist, then writes Kiro steering and `AGENTS.md` rules, `PROJECT.md`, `DECISIONS.md`, a sync hook, a dependency guard hook, a `seance-tutor` agent and `.seance/config.json`. It never overwrites a file you edited. To get a quiz in Kiro, pick `seance-tutor` in the agent selector before asking for a quiz: as a sub-agent it cannot continue a conversation. |
23
+ | `seance sync` | Updates the auto section of `PROJECT.md` from the git diff and saves a quiz on the changed files. Run it by hand or from the Kiro hook that `init` writes. |
24
+ | `seance quiz` | Prints a structure map summary, then asks 5 questions about the latest change. Missed questions become review cards. `--offline` makes questions from the code structure only. |
25
+ | `seance review` | Walks the review cards that are due today and reschedules them with SM-2. `--offline` grades by keywords. |
26
+ | `seance mcp` | An MCP server over stdio with five tools (`get_project_context`, `get_due_reviews`, `get_decisions`, `start_quiz`, `submit_answer`). |
27
+
28
+ Keep `node_modules` in your project's `.gitignore`, or `seance sync` can stop on git output that is too large.
29
+
30
+ ## Privacy
31
+
32
+ - `--offline` sends nothing. `init`, `sync` and `mcp` make no network calls.
33
+ - With your own provider keys in the shell (`GEMINI_API_KEY` and `GEMINI_MODEL`, or the NVIDIA or OpenRouter variables), `quiz` sends excerpts of the changed JS/TS files, your written answers and the latest `DECISIONS.md` entry to those providers. It prints a notice first.
34
+ - With no provider keys, `quiz` offers the hosted Seance API by default (`https://seance-kiroween.netlify.app`, or the address in `SEANCE_API_URL`) and asks Yes or No once per run before sending code to it. No keeps everything local, and nothing is sent before you answer. `--offline` never asks and never sends; `SEANCE_API_URL=` (empty) turns the hosted API off.
35
+ - `seance review`: with your own keys and no `--offline`, it sends your explain answers to those providers. With the hosted API it asks "Send your answers to the Seance API (<host>) for grading?" only when an explain card is due.
36
+ - Secrets inside source code or in `DECISIONS.md` are not removed before sending.
37
+ - The CLI does not read `.env` files. No accounts, no database: state lives in `.seance/state.json` in your project.
38
+
39
+ ## License
40
+
41
+ MIT
@@ -0,0 +1,29 @@
1
+ import { type WriteOps } from "../init-fs.js";
2
+ import { type Prompter } from "../prompter.js";
3
+ export interface InitOptions {
4
+ dir?: string;
5
+ yes?: boolean;
6
+ dryRun?: boolean;
7
+ targets?: string;
8
+ gate?: string;
9
+ name?: string;
10
+ description?: string;
11
+ audience?: string;
12
+ language?: string;
13
+ framework?: string;
14
+ packageManager?: string;
15
+ testRunner?: string;
16
+ experience?: string;
17
+ outOfScope?: string;
18
+ conventions?: string;
19
+ }
20
+ export interface InitDeps {
21
+ cwd: string;
22
+ prompter: Prompter;
23
+ isTTY: boolean;
24
+ out: (line: string) => void;
25
+ version: string;
26
+ fs?: Partial<WriteOps>;
27
+ }
28
+ /** Runs `seance init`. Returns the exit code and never calls `process.exit`. */
29
+ export declare function runInit(options: InitOptions, deps: InitDeps): Promise<number>;
@@ -0,0 +1,310 @@
1
+ // `seance init`: reads the target folder, asks the checklist questions, plans the files with @seance/core and writes them.
2
+ // All decisions are made by pure functions in core; the disk work is in ../init-fs.ts and the questions in ../init-questions.ts.
3
+ import { readdir, stat } from "node:fs/promises";
4
+ import { basename, resolve } from "node:path";
5
+ import { CHECKLIST, InitAnswersSchema, MANIFEST_PATH, ManifestSchema, SeanceConfigSchema, cleanAnswerText, detectProject, evaluateChecklist, firstIssuePath, planInit, renderInitFiles, } from "@seance/core";
6
+ import { applyPlan, readExisting, resolveRoot } from "../init-fs.js";
7
+ import { answersWithoutQuestions, askEverything, withUndecided } from "../init-questions.js";
8
+ import { PromptCancelled } from "../prompter.js";
9
+ const ALL_TARGETS = ["kiro", "agents-md"];
10
+ const GATE_MODES = ["off", "soft", "strict"];
11
+ const MAX_PACKAGE_JSON_BYTES = 1_000_000;
12
+ const MAX_SEANCE_FILE_BYTES = 256 * 1024;
13
+ const MAX_MANAGED_FILE_BYTES = 1_000_000;
14
+ // The command line flag of each checklist item, and the property commander puts its value in.
15
+ const FLAGS = {
16
+ projectName: { flag: "--name", option: "name" },
17
+ description: { flag: "--description", option: "description" },
18
+ audience: { flag: "--audience", option: "audience" },
19
+ language: { flag: "--language", option: "language" },
20
+ framework: { flag: "--framework", option: "framework" },
21
+ packageManager: { flag: "--package-manager", option: "packageManager" },
22
+ testRunner: { flag: "--test-runner", option: "testRunner" },
23
+ experience: { flag: "--experience", option: "experience" },
24
+ outOfScope: { flag: "--out-of-scope", option: "outOfScope" },
25
+ conventions: { flag: "--conventions", option: "conventions" },
26
+ };
27
+ const ACTION_LABELS = {
28
+ create: "created",
29
+ update: "updated",
30
+ unchanged: "unchanged",
31
+ "append-markers": "appended markers",
32
+ "append-rules": "appended rules",
33
+ "skip-edited": "skipped (edited)",
34
+ "skip-foreign": "skipped (not Seance's)",
35
+ "skip-broken-markers": "skipped (broken markers)",
36
+ };
37
+ /** A mistake in the options or in a file the user must fix. Printed as one line, exit code 1. */
38
+ class UsageError extends Error {
39
+ }
40
+ /** Runs `seance init`. Returns the exit code and never calls `process.exit`. */
41
+ export async function runInit(options, deps) {
42
+ try {
43
+ return await initFlow(options, deps);
44
+ }
45
+ catch (error) {
46
+ if (error instanceof UsageError) {
47
+ deps.out(error.message);
48
+ return 1;
49
+ }
50
+ if (error instanceof PromptCancelled) {
51
+ deps.out("init cancelled, nothing written");
52
+ return 130;
53
+ }
54
+ throw error;
55
+ }
56
+ }
57
+ /** The whole command: check options, read the folder, collect answers, plan, then print the plan or write it. */
58
+ async function initFlow(options, deps) {
59
+ // 1. Check the options before anything else.
60
+ const targetsFlag = parseTargets(options.targets);
61
+ const gateFlag = parseGate(options.gate);
62
+ const flagAnswers = parseFlagAnswers(options);
63
+ const root = resolve(deps.cwd, options.dir ?? ".");
64
+ if (!(await isDirectory(root)))
65
+ throw new UsageError(`--dir ${options.dir ?? "."} does not exist or is not a folder`);
66
+ if (!deps.isTTY && options.yes !== true) {
67
+ throw new UsageError("seance init needs a terminal; run it with --yes to use defaults");
68
+ }
69
+ // 2. Read what is in the folder. Every path is built under the real path of the root (open question 42).
70
+ const fsRoot = await resolveRoot(root);
71
+ const warnings = [];
72
+ const config = await readConfig(fsRoot);
73
+ const manifest = await readManifest(fsRoot, warnings);
74
+ const rootNames = (await readdir(fsRoot)).sort();
75
+ const packageJson = await readExisting(fsRoot, "package.json", MAX_PACKAGE_JSON_BYTES);
76
+ const detected = detectProject({
77
+ folderName: basename(root),
78
+ packageJson: packageJson?.type === "file" ? packageJson.content : undefined,
79
+ rootNames,
80
+ });
81
+ const targets = targetsFlag ?? config?.targets ?? ALL_TARGETS;
82
+ const gateDefault = gateFlag ?? config?.gate.mode ?? "strict";
83
+ // 3. Collect the answers. Nothing is written until every question is answered (9.1).
84
+ const known = { flags: flagAnswers, stored: config?.answers ?? {}, detected, prompter: deps.prompter };
85
+ let collected;
86
+ let gateMode = gateDefault;
87
+ if (options.yes === true) {
88
+ collected = answersWithoutQuestions(known);
89
+ }
90
+ else {
91
+ const asked = await askEverything(known, gateFlag, gateDefault, deps.out);
92
+ collected = asked.answers;
93
+ gateMode = asked.gateMode;
94
+ }
95
+ const answers = withUndecided(collected);
96
+ // 4. Check, render and plan.
97
+ const checked = InitAnswersSchema.safeParse(answers);
98
+ if (!checked.success)
99
+ throw new UsageError(`the answers are not valid: ${firstIssuePath(checked.error)}`);
100
+ const settings = { targets: [...targets], gateMode, version: deps.version };
101
+ const units = renderInitFiles(answers, settings, config);
102
+ const existing = new Map();
103
+ for (const path of [...units.map((unit) => unit.path), MANIFEST_PATH]) {
104
+ const found = await readExisting(fsRoot, path, MAX_MANAGED_FILE_BYTES);
105
+ if (found !== undefined)
106
+ existing.set(path, found);
107
+ }
108
+ const plan = planInit(units, existing, manifest);
109
+ warnings.push(...plan.warnings);
110
+ const checklist = evaluateChecklist(answers);
111
+ const detectedLine = options.yes === true ? describeDetected(detected, descriptionSource(flagAnswers, known.stored)) : undefined;
112
+ // 5. Dry run: show the plan and stop.
113
+ if (options.dryRun === true) {
114
+ deps.out(`Dry run in ${root}: nothing is written.`);
115
+ if (detectedLine !== undefined)
116
+ deps.out(detectedLine);
117
+ printWarnings(deps, warnings);
118
+ printWrites(deps, plan.writes, new Map());
119
+ deps.out(`Checklist ${checklist.percent}%`);
120
+ return 0;
121
+ }
122
+ // 6. Write, manifest last.
123
+ const result = await applyPlan(fsRoot, plan, existing, manifest, deps.out, deps.fs);
124
+ if (result.failed)
125
+ return 1;
126
+ // 7. Summary.
127
+ deps.out(`Seance init in ${root}`);
128
+ if (detectedLine !== undefined)
129
+ deps.out(detectedLine);
130
+ printWarnings(deps, warnings);
131
+ printWrites(deps, plan.writes, result.labels);
132
+ deps.out(`Checklist ${checklist.percent}%` + (checklist.undecided.length > 0 ? ` (undecided: ${checklist.undecided.join(", ")})` : ""));
133
+ const descriptionSkipped = options.yes === true && detected.description !== undefined && answers.description?.source === "undecided";
134
+ printTips(deps, targets, plan.writes, checklist.undecided, descriptionSkipped);
135
+ return 0;
136
+ }
137
+ // ---------------------------------------------------------------------------------------------------------------
138
+ // Options
139
+ /** `--targets kiro,agents-md` as a list; undefined when the flag is absent. A bad entry is a usage error (1.6). */
140
+ function parseTargets(raw) {
141
+ if (raw === undefined)
142
+ return undefined;
143
+ const parts = raw.split(",").map((part) => part.trim().toLowerCase());
144
+ const valid = parts.length > 0 && parts.every((part) => part === "kiro" || part === "agents-md");
145
+ if (!valid)
146
+ throw new UsageError("--targets must be a comma-separated list of: kiro, agents-md");
147
+ return ALL_TARGETS.filter((target) => parts.includes(target));
148
+ }
149
+ /** `--gate off|soft|strict`; undefined when the flag is absent. */
150
+ function parseGate(raw) {
151
+ if (raw === undefined)
152
+ return undefined;
153
+ const mode = GATE_MODES.find((candidate) => candidate === raw.trim().toLowerCase());
154
+ if (mode === undefined)
155
+ throw new UsageError("--gate must be one of: off, soft, strict");
156
+ return mode;
157
+ }
158
+ /** The answers given with flags (source `user`). A bad value is a usage error (1.6). */
159
+ function parseFlagAnswers(options) {
160
+ const answers = {};
161
+ for (const item of CHECKLIST) {
162
+ const { flag, option } = FLAGS[item.id];
163
+ const raw = options[option];
164
+ if (typeof raw !== "string")
165
+ continue;
166
+ const match = item.choices?.find((choice) => choice.toLowerCase() === raw.trim().toLowerCase());
167
+ if (match !== undefined) {
168
+ answers[item.id] = { value: match, source: "user" };
169
+ }
170
+ else if (item.kind === "choice" && item.allowOther !== true) {
171
+ throw new UsageError(`${flag} must be one of: ${(item.choices ?? []).join(", ")}`);
172
+ }
173
+ else {
174
+ const value = cleanAnswerText(raw, item.maxLength);
175
+ if (value === "")
176
+ throw new UsageError(`${flag} must not be empty`);
177
+ answers[item.id] = { value, source: "user" };
178
+ }
179
+ }
180
+ return answers;
181
+ }
182
+ // ---------------------------------------------------------------------------------------------------------------
183
+ // Reading the folder
184
+ /** True when `path` is an existing folder. */
185
+ async function isDirectory(path) {
186
+ try {
187
+ return (await stat(path)).isDirectory();
188
+ }
189
+ catch {
190
+ return false;
191
+ }
192
+ }
193
+ /** The parsed JSON of a text (a leading BOM is ignored), or `ok: false`. */
194
+ function parseJson(text) {
195
+ try {
196
+ return { ok: true, value: JSON.parse(text.replace(/^\uFEFF+/, "")) };
197
+ }
198
+ catch {
199
+ return { ok: false };
200
+ }
201
+ }
202
+ /** The words for a config that is not a regular readable file (3.5, open questions 41 and 42). */
203
+ function otherReason(why) {
204
+ if (why === "not-utf8")
205
+ return "not valid UTF-8";
206
+ if (why === "unsafe-path")
207
+ return "a parent folder is a symlink or not a folder";
208
+ return "not a regular file under 256 KB";
209
+ }
210
+ /** `.seance/config.json`, or undefined when absent. An invalid file stops the run before anything is written (3.5). */
211
+ async function readConfig(fsRoot) {
212
+ const file = await readExisting(fsRoot, ".seance/config.json", MAX_SEANCE_FILE_BYTES);
213
+ if (file === undefined)
214
+ return undefined;
215
+ const invalid = (why) => new UsageError(`.seance/config.json is invalid: ${why}; fix or delete it`);
216
+ if (file.type === "other")
217
+ throw invalid(otherReason(file.why));
218
+ const json = parseJson(file.content);
219
+ if (!json.ok)
220
+ throw invalid("not valid JSON");
221
+ const parsed = SeanceConfigSchema.safeParse(json.value);
222
+ if (!parsed.success)
223
+ throw invalid(firstIssuePath(parsed.error));
224
+ return parsed.data;
225
+ }
226
+ /**
227
+ * `.seance/manifest.json`. An invalid one counts as empty, with a warning, and is replaced (5.9). One that is not a
228
+ * regular UTF-8 file counts as empty too, with a different warning, and is left as it is (the plan will not write it).
229
+ */
230
+ async function readManifest(fsRoot, warnings) {
231
+ const empty = { schemaVersion: 1, records: {} };
232
+ const file = await readExisting(fsRoot, MANIFEST_PATH, MAX_MANAGED_FILE_BYTES);
233
+ if (file === undefined)
234
+ return empty;
235
+ const skipped = "so every existing Seance file is treated as not Seance's and skipped";
236
+ if (file.type === "other") {
237
+ warnings.push(`.seance/manifest.json is not a regular UTF-8 file, ${skipped}, and the manifest is left as it is`);
238
+ return empty;
239
+ }
240
+ const tooBig = Buffer.byteLength(file.content) > MAX_SEANCE_FILE_BYTES; // over 256 KB counts as invalid (3.6)
241
+ const json = tooBig ? { ok: false } : parseJson(file.content);
242
+ const parsed = json.ok ? ManifestSchema.safeParse(json.value) : undefined;
243
+ if (parsed === undefined || !parsed.success) {
244
+ warnings.push(`.seance/manifest.json is invalid, ${skipped}`);
245
+ return empty;
246
+ }
247
+ return parsed.data;
248
+ }
249
+ function descriptionSource(flags, stored) {
250
+ if (flags.description !== undefined)
251
+ return "flag";
252
+ // A stored answer counts only when it is not `undecided` (open question 36c), the same rule `--yes` uses.
253
+ if (stored.description !== undefined && stored.description.source !== "undecided")
254
+ return "stored";
255
+ return "none";
256
+ }
257
+ /** The note after the detected description: the real reason it is not used (1.8). */
258
+ const DESCRIPTION_NOTES = {
259
+ flag: "not used: --description was given",
260
+ stored: "not used: the description stored in .seance/config.json is used",
261
+ none: "not used with --yes; pass --description to use it",
262
+ };
263
+ /** The `--yes` line that lists everything `detectProject` found; undefined when it found nothing (1.8). */
264
+ function describeDetected(detected, source) {
265
+ const parts = [];
266
+ if (detected.projectName !== undefined)
267
+ parts.push(`name "${detected.projectName}"`);
268
+ if (detected.description !== undefined)
269
+ parts.push(`description "${detected.description}" (${DESCRIPTION_NOTES[source]})`);
270
+ if (detected.language !== undefined)
271
+ parts.push(`language ${detected.language}`);
272
+ if (detected.framework !== undefined)
273
+ parts.push(`framework ${detected.framework}`);
274
+ if (detected.packageManager !== undefined)
275
+ parts.push(`package manager ${detected.packageManager}`);
276
+ if (detected.testRunner !== undefined)
277
+ parts.push(`test runner ${detected.testRunner}`);
278
+ return parts.length === 0 ? undefined : `detected: ${parts.join(", ")}`;
279
+ }
280
+ /** One `warning: ...` line per warning. */
281
+ function printWarnings(deps, warnings) {
282
+ for (const warning of warnings)
283
+ deps.out(`warning: ${warning}`);
284
+ }
285
+ /** One line per planned file: the label (a write that was skipped at the last moment has its own) and the path. */
286
+ function printWrites(deps, writes, labels) {
287
+ for (const write of writes)
288
+ deps.out(` ${(labels.get(write) ?? ACTION_LABELS[write.action]).padEnd(25)} ${write.path}`);
289
+ }
290
+ /** The "Tips:" block of the summary. */
291
+ function printTips(deps, targets, writes, undecidedIds, descriptionSkipped) {
292
+ deps.out("Tips:");
293
+ deps.out(" Commit `.kiro/`, `AGENTS.md`, `PROJECT.md`, `DECISIONS.md`, `.seance/config.json` and `.seance/manifest.json`. Do not commit `.seance/state.json`.");
294
+ if (targets.includes("kiro")) {
295
+ deps.out(" The sync hook calls `seance sync`; install it in this project with `npm install --save-dev seance-cli` so `npx --no-install seance` finds it.");
296
+ }
297
+ if (targets.includes("kiro")) {
298
+ deps.out(` For the tutor's tools, install the Seance power or add "seance mcp" to .kiro/settings/mcp.json.`);
299
+ deps.out(" To get a quiz in Kiro, pick `seance-tutor` in the agent selector first, then ask for a quiz: as a sub-agent it cannot continue a conversation.");
300
+ }
301
+ if (writes.some((write) => write.action === "skip-edited")) {
302
+ deps.out(" Delete a skipped file and re-run `seance init` to get the new version.");
303
+ }
304
+ if (descriptionSkipped) {
305
+ deps.out(' The description was not taken from package.json with --yes. Set it with `--description "..."` or run `seance init` without --yes.');
306
+ }
307
+ if (undecidedIds.length > 0)
308
+ deps.out(` Run \`seance init\` again to answer: ${undecidedIds.join(", ")}.`);
309
+ }
310
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,2HAA2H;AAC3H,iIAAiI;AACjI,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,eAAe,GAChB,MAAM,cAAc,CAAC;AActB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAmC,MAAM,eAAe,CAAC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C,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3H,CAAC;AAED,wCAAwC;AACxC,SAAS,SAAS,CAAC,IAAc,EAAE,OAA0B,EAAE,MAAsB,EAAE,YAAsB,EAAE,kBAA2B;IACxI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClB,IAAI,CAAC,GAAG,CAAC,sJAAsJ,CAAC,CAAC;IACjK,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,iJAAiJ,CAAC,CAAC;IAC9J,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,mGAAmG,CAAC,CAAC;QAC9G,IAAI,CAAC,GAAG,CAAC,kJAAkJ,CAAC,CAAC;IAC/J,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,aAAa,CAAC,EAAE,CAAC;QAC3D,IAAI,CAAC,GAAG,CAAC,0EAA0E,CAAC,CAAC;IACvF,CAAC;IACD,IAAI,kBAAkB,EAAE,CAAC;QACvB,IAAI,CAAC,GAAG,CAAC,qIAAqI,CAAC,CAAC;IAClJ,CAAC;IACD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;QAAE,IAAI,CAAC,GAAG,CAAC,0CAA0C,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9G,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Readable, Writable } from "node:stream";
2
+ import { type WriteOps } from "../init-fs.js";
3
+ import type { GitRunner } from "../git.js";
4
+ export interface McpOptions {
5
+ dir?: string;
6
+ }
7
+ export interface McpCommandDeps {
8
+ cwd: string;
9
+ err: (line: string) => void;
10
+ now: () => Date;
11
+ randomId: () => string;
12
+ version: string;
13
+ stdin?: Readable;
14
+ stdout?: Writable;
15
+ git?: GitRunner;
16
+ fs?: Partial<WriteOps>;
17
+ }
18
+ /** Runs `seance mcp`. Returns the exit code when the client closes the connection; never calls `process.exit`. */
19
+ export declare function runMcp(options: McpOptions, deps: McpCommandDeps): Promise<number>;
@@ -0,0 +1,38 @@
1
+ // `seance mcp`: serves the five Seance tools to an MCP client (Kiro) over stdio. The only thing written to stdout is the
2
+ // protocol; diagnostics go to stderr. Resolves the project folder once, then runs until the client closes stdin.
3
+ import { resolve } from "node:path";
4
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
+ import { resolveRoot } from "../init-fs.js";
6
+ import { createMcpHandlers } from "../mcp-handlers.js";
7
+ import { createSeanceMcpServer } from "../mcp-server.js";
8
+ import { isDirectory } from "../quiz-ui.js";
9
+ /** Runs `seance mcp`. Returns the exit code when the client closes the connection; never calls `process.exit`. */
10
+ export async function runMcp(options, deps) {
11
+ const dir = resolve(deps.cwd, options.dir ?? ".");
12
+ if (!(await isDirectory(dir))) {
13
+ deps.err("seance mcp: --dir is not a folder");
14
+ return 1;
15
+ }
16
+ const root = await resolveRoot(dir);
17
+ const handlers = createMcpHandlers(root, {
18
+ cwd: root,
19
+ err: deps.err,
20
+ now: deps.now,
21
+ randomId: deps.randomId,
22
+ ...(deps.git === undefined ? {} : { git: deps.git }),
23
+ ...(deps.fs === undefined ? {} : { fs: deps.fs }),
24
+ });
25
+ const server = createSeanceMcpServer(handlers, deps.version);
26
+ const stdin = deps.stdin ?? process.stdin;
27
+ const closed = new Promise((done) => {
28
+ server.server.onclose = () => done();
29
+ });
30
+ // The SDK transport does not watch for the end of stdin, so close the server ourselves (requirement 1.7).
31
+ stdin.once("end", () => {
32
+ void server.close();
33
+ });
34
+ await server.connect(new StdioServerTransport(stdin, deps.stdout ?? process.stdout));
35
+ await closed;
36
+ return 0;
37
+ }
38
+ //# sourceMappingURL=mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.js","sourceRoot":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C;KAClD,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,qBAAqB,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,OAAO,CAAO,CAAC,IAAI,EAAE,EAAE;QACxC,MAAM,CAAC,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,0GAA0G;IAC1G,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;QACrB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACrF,MAAM,MAAM,CAAC;IACb,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type ClientFactory } from "@seance/ai";
2
+ import { type GitRunner } from "../git.js";
3
+ import { type WriteOps } from "../init-fs.js";
4
+ import { type Prompter } from "../prompter.js";
5
+ export interface QuizOptions {
6
+ dir?: string;
7
+ offline?: boolean;
8
+ }
9
+ export interface QuizDeps {
10
+ cwd: string;
11
+ out: (line: string) => void;
12
+ prompter: Prompter;
13
+ isTTY: boolean;
14
+ now: () => Date;
15
+ env: Readonly<Record<string, string | undefined>>;
16
+ defaultApiUrl?: string | null;
17
+ clientFactory?: ClientFactory;
18
+ fetch?: typeof fetch;
19
+ git?: GitRunner;
20
+ fs?: Partial<WriteOps>;
21
+ }
22
+ /** Runs `seance quiz`. Returns the exit code and never calls `process.exit`. */
23
+ export declare function runQuiz(options: QuizOptions, deps: QuizDeps): Promise<number>;