seance-cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/commands/init.d.ts +29 -0
  4. package/dist/commands/init.js +310 -0
  5. package/dist/commands/init.js.map +1 -0
  6. package/dist/commands/mcp.d.ts +19 -0
  7. package/dist/commands/mcp.js +38 -0
  8. package/dist/commands/mcp.js.map +1 -0
  9. package/dist/commands/quiz.d.ts +23 -0
  10. package/dist/commands/quiz.js +187 -0
  11. package/dist/commands/quiz.js.map +1 -0
  12. package/dist/commands/review.d.ts +4 -0
  13. package/dist/commands/review.js +115 -0
  14. package/dist/commands/review.js.map +1 -0
  15. package/dist/commands/sync.d.ts +17 -0
  16. package/dist/commands/sync.js +367 -0
  17. package/dist/commands/sync.js.map +1 -0
  18. package/dist/git.d.ts +33 -0
  19. package/dist/git.js +103 -0
  20. package/dist/git.js.map +1 -0
  21. package/dist/hosted-api.d.ts +24 -0
  22. package/dist/hosted-api.js +85 -0
  23. package/dist/hosted-api.js.map +1 -0
  24. package/dist/hosted-consent.d.ts +8 -0
  25. package/dist/hosted-consent.js +37 -0
  26. package/dist/hosted-consent.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +108 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/init-fs.d.ts +51 -0
  31. package/dist/init-fs.js +220 -0
  32. package/dist/init-fs.js.map +1 -0
  33. package/dist/init-questions.d.ts +21 -0
  34. package/dist/init-questions.js +161 -0
  35. package/dist/init-questions.js.map +1 -0
  36. package/dist/mcp-handlers.d.ts +22 -0
  37. package/dist/mcp-handlers.js +185 -0
  38. package/dist/mcp-handlers.js.map +1 -0
  39. package/dist/mcp-server.d.ts +4 -0
  40. package/dist/mcp-server.js +39 -0
  41. package/dist/mcp-server.js.map +1 -0
  42. package/dist/prompter.d.ts +29 -0
  43. package/dist/prompter.js +42 -0
  44. package/dist/prompter.js.map +1 -0
  45. package/dist/quiz-backend.d.ts +40 -0
  46. package/dist/quiz-backend.js +116 -0
  47. package/dist/quiz-backend.js.map +1 -0
  48. package/dist/quiz-input.d.ts +12 -0
  49. package/dist/quiz-input.js +52 -0
  50. package/dist/quiz-input.js.map +1 -0
  51. package/dist/quiz-io.d.ts +30 -0
  52. package/dist/quiz-io.js +83 -0
  53. package/dist/quiz-io.js.map +1 -0
  54. package/dist/quiz-ui.d.ts +18 -0
  55. package/dist/quiz-ui.js +51 -0
  56. package/dist/quiz-ui.js.map +1 -0
  57. package/node_modules/@seance/ai/LICENSE +21 -0
  58. package/node_modules/@seance/ai/dist/chain.d.ts +31 -0
  59. package/node_modules/@seance/ai/dist/chain.js +114 -0
  60. package/node_modules/@seance/ai/dist/chain.js.map +1 -0
  61. package/node_modules/@seance/ai/dist/grade.d.ts +14 -0
  62. package/node_modules/@seance/ai/dist/grade.js +44 -0
  63. package/node_modules/@seance/ai/dist/grade.js.map +1 -0
  64. package/node_modules/@seance/ai/dist/hosted-config.d.ts +9 -0
  65. package/node_modules/@seance/ai/dist/hosted-config.js +27 -0
  66. package/node_modules/@seance/ai/dist/hosted-config.js.map +1 -0
  67. package/node_modules/@seance/ai/dist/index.d.ts +9 -0
  68. package/node_modules/@seance/ai/dist/index.js +9 -0
  69. package/node_modules/@seance/ai/dist/index.js.map +1 -0
  70. package/node_modules/@seance/ai/dist/providers.d.ts +54 -0
  71. package/node_modules/@seance/ai/dist/providers.js +149 -0
  72. package/node_modules/@seance/ai/dist/providers.js.map +1 -0
  73. package/node_modules/@seance/ai/dist/quiz.d.ts +26 -0
  74. package/node_modules/@seance/ai/dist/quiz.js +41 -0
  75. package/node_modules/@seance/ai/dist/quiz.js.map +1 -0
  76. package/node_modules/@seance/ai/package.json +25 -0
  77. package/node_modules/@seance/core/LICENSE +21 -0
  78. package/node_modules/@seance/core/dist/ai-check.d.ts +58 -0
  79. package/node_modules/@seance/core/dist/ai-check.js +460 -0
  80. package/node_modules/@seance/core/dist/ai-check.js.map +1 -0
  81. package/node_modules/@seance/core/dist/ai-prompts.d.ts +29 -0
  82. package/node_modules/@seance/core/dist/ai-prompts.js +221 -0
  83. package/node_modules/@seance/core/dist/ai-prompts.js.map +1 -0
  84. package/node_modules/@seance/core/dist/ai-schemas.d.ts +155 -0
  85. package/node_modules/@seance/core/dist/ai-schemas.js +92 -0
  86. package/node_modules/@seance/core/dist/ai-schemas.js.map +1 -0
  87. package/node_modules/@seance/core/dist/api-client.d.ts +26 -0
  88. package/node_modules/@seance/core/dist/api-client.js +71 -0
  89. package/node_modules/@seance/core/dist/api-client.js.map +1 -0
  90. package/node_modules/@seance/core/dist/api-errors.d.ts +37 -0
  91. package/node_modules/@seance/core/dist/api-errors.js +66 -0
  92. package/node_modules/@seance/core/dist/api-errors.js.map +1 -0
  93. package/node_modules/@seance/core/dist/api-schemas.d.ts +284 -0
  94. package/node_modules/@seance/core/dist/api-schemas.js +67 -0
  95. package/node_modules/@seance/core/dist/api-schemas.js.map +1 -0
  96. package/node_modules/@seance/core/dist/decision-log.d.ts +73 -0
  97. package/node_modules/@seance/core/dist/decision-log.js +239 -0
  98. package/node_modules/@seance/core/dist/decision-log.js.map +1 -0
  99. package/node_modules/@seance/core/dist/dependency-guard.d.ts +20 -0
  100. package/node_modules/@seance/core/dist/dependency-guard.js +732 -0
  101. package/node_modules/@seance/core/dist/dependency-guard.js.map +1 -0
  102. package/node_modules/@seance/core/dist/gate.d.ts +11 -0
  103. package/node_modules/@seance/core/dist/gate.js +26 -0
  104. package/node_modules/@seance/core/dist/gate.js.map +1 -0
  105. package/node_modules/@seance/core/dist/git-parse.d.ts +11 -0
  106. package/node_modules/@seance/core/dist/git-parse.js +23 -0
  107. package/node_modules/@seance/core/dist/git-parse.js.map +1 -0
  108. package/node_modules/@seance/core/dist/index.d.ts +65 -0
  109. package/node_modules/@seance/core/dist/index.js +47 -0
  110. package/node_modules/@seance/core/dist/index.js.map +1 -0
  111. package/node_modules/@seance/core/dist/init-checklist.d.ts +153 -0
  112. package/node_modules/@seance/core/dist/init-checklist.js +200 -0
  113. package/node_modules/@seance/core/dist/init-checklist.js.map +1 -0
  114. package/node_modules/@seance/core/dist/init-detect.d.ts +9 -0
  115. package/node_modules/@seance/core/dist/init-detect.js +84 -0
  116. package/node_modules/@seance/core/dist/init-detect.js.map +1 -0
  117. package/node_modules/@seance/core/dist/init-templates.d.ts +36 -0
  118. package/node_modules/@seance/core/dist/init-templates.js +257 -0
  119. package/node_modules/@seance/core/dist/init-templates.js.map +1 -0
  120. package/node_modules/@seance/core/dist/map-basics.d.ts +13 -0
  121. package/node_modules/@seance/core/dist/map-basics.js +19 -0
  122. package/node_modules/@seance/core/dist/map-basics.js.map +1 -0
  123. package/node_modules/@seance/core/dist/map-summary.d.ts +5 -0
  124. package/node_modules/@seance/core/dist/map-summary.js +50 -0
  125. package/node_modules/@seance/core/dist/map-summary.js.map +1 -0
  126. package/node_modules/@seance/core/dist/markers.d.ts +51 -0
  127. package/node_modules/@seance/core/dist/markers.js +84 -0
  128. package/node_modules/@seance/core/dist/markers.js.map +1 -0
  129. package/node_modules/@seance/core/dist/mcp-quiz.d.ts +94 -0
  130. package/node_modules/@seance/core/dist/mcp-quiz.js +130 -0
  131. package/node_modules/@seance/core/dist/mcp-quiz.js.map +1 -0
  132. package/node_modules/@seance/core/dist/mcp-tools.d.ts +82 -0
  133. package/node_modules/@seance/core/dist/mcp-tools.js +136 -0
  134. package/node_modules/@seance/core/dist/mcp-tools.js.map +1 -0
  135. package/node_modules/@seance/core/dist/mcp-views.d.ts +21 -0
  136. package/node_modules/@seance/core/dist/mcp-views.js +83 -0
  137. package/node_modules/@seance/core/dist/mcp-views.js.map +1 -0
  138. package/node_modules/@seance/core/dist/quiz-assembly.d.ts +21 -0
  139. package/node_modules/@seance/core/dist/quiz-assembly.js +43 -0
  140. package/node_modules/@seance/core/dist/quiz-assembly.js.map +1 -0
  141. package/node_modules/@seance/core/dist/quiz-cards.d.ts +183 -0
  142. package/node_modules/@seance/core/dist/quiz-cards.js +215 -0
  143. package/node_modules/@seance/core/dist/quiz-cards.js.map +1 -0
  144. package/node_modules/@seance/core/dist/quiz-session.d.ts +67 -0
  145. package/node_modules/@seance/core/dist/quiz-session.js +141 -0
  146. package/node_modules/@seance/core/dist/quiz-session.js.map +1 -0
  147. package/node_modules/@seance/core/dist/quiz-subjects.d.ts +13 -0
  148. package/node_modules/@seance/core/dist/quiz-subjects.js +63 -0
  149. package/node_modules/@seance/core/dist/quiz-subjects.js.map +1 -0
  150. package/node_modules/@seance/core/dist/rate-limit.d.ts +33 -0
  151. package/node_modules/@seance/core/dist/rate-limit.js +114 -0
  152. package/node_modules/@seance/core/dist/rate-limit.js.map +1 -0
  153. package/node_modules/@seance/core/dist/scoring.d.ts +48 -0
  154. package/node_modules/@seance/core/dist/scoring.js +95 -0
  155. package/node_modules/@seance/core/dist/scoring.js.map +1 -0
  156. package/node_modules/@seance/core/dist/seance-config.d.ts +177 -0
  157. package/node_modules/@seance/core/dist/seance-config.js +43 -0
  158. package/node_modules/@seance/core/dist/seance-config.js.map +1 -0
  159. package/node_modules/@seance/core/dist/seance-state.d.ts +125 -0
  160. package/node_modules/@seance/core/dist/seance-state.js +61 -0
  161. package/node_modules/@seance/core/dist/seance-state.js.map +1 -0
  162. package/node_modules/@seance/core/dist/sm2.d.ts +18 -0
  163. package/node_modules/@seance/core/dist/sm2.js +87 -0
  164. package/node_modules/@seance/core/dist/sm2.js.map +1 -0
  165. package/node_modules/@seance/core/dist/stored-schemas.d.ts +29 -0
  166. package/node_modules/@seance/core/dist/stored-schemas.js +29 -0
  167. package/node_modules/@seance/core/dist/stored-schemas.js.map +1 -0
  168. package/node_modules/@seance/core/dist/structural-questions.d.ts +31 -0
  169. package/node_modules/@seance/core/dist/structural-questions.js +575 -0
  170. package/node_modules/@seance/core/dist/structural-questions.js.map +1 -0
  171. package/node_modules/@seance/core/dist/structure-map-schema.d.ts +84 -0
  172. package/node_modules/@seance/core/dist/structure-map-schema.js +73 -0
  173. package/node_modules/@seance/core/dist/structure-map-schema.js.map +1 -0
  174. package/node_modules/@seance/core/dist/structure-map.d.ts +78 -0
  175. package/node_modules/@seance/core/dist/structure-map.js +750 -0
  176. package/node_modules/@seance/core/dist/structure-map.js.map +1 -0
  177. package/node_modules/@seance/core/dist/sync-changes.d.ts +38 -0
  178. package/node_modules/@seance/core/dist/sync-changes.js +89 -0
  179. package/node_modules/@seance/core/dist/sync-changes.js.map +1 -0
  180. package/node_modules/@seance/core/dist/sync-render.d.ts +28 -0
  181. package/node_modules/@seance/core/dist/sync-render.js +113 -0
  182. package/node_modules/@seance/core/dist/sync-render.js.map +1 -0
  183. package/node_modules/@seance/core/dist/terminal-text.d.ts +8 -0
  184. package/node_modules/@seance/core/dist/terminal-text.js +33 -0
  185. package/node_modules/@seance/core/dist/terminal-text.js.map +1 -0
  186. package/node_modules/@seance/core/dist/write-plan.d.ts +51 -0
  187. package/node_modules/@seance/core/dist/write-plan.js +173 -0
  188. package/node_modules/@seance/core/dist/write-plan.js.map +1 -0
  189. package/node_modules/@seance/core/package.json +26 -0
  190. package/package.json +42 -6
@@ -0,0 +1,84 @@
1
+ // Guesses checklist answers from a project folder: its package.json text and the file names in its root.
2
+ // Pure and forgiving: it never throws, and a package.json it cannot read just gives fewer guesses.
3
+ import { cleanAnswerText } from "./init-checklist.js";
4
+ // The first dependency found in this order decides the framework.
5
+ const FRAMEWORKS = [
6
+ ["next", "Next.js"],
7
+ ["react", "React"],
8
+ ["vue", "Vue"],
9
+ ["svelte", "Svelte"],
10
+ ["express", "Express"],
11
+ ["fastify", "Fastify"],
12
+ ["hono", "Hono"],
13
+ ["commander", "Node.js CLI"],
14
+ ];
15
+ const TEST_RUNNERS = ["vitest", "jest", "mocha"];
16
+ // The first lockfile found in this order decides the package manager.
17
+ const LOCKFILES = [
18
+ ["package-lock.json", "npm"],
19
+ ["pnpm-lock.yaml", "pnpm"],
20
+ ["yarn.lock", "yarn"],
21
+ ["bun.lock", "bun"],
22
+ ["bun.lockb", "bun"],
23
+ ];
24
+ /** Returns the parsed package.json when it is a JSON object, else undefined (invalid JSON, an array, null, a number...). */
25
+ function parsePackageJson(text) {
26
+ if (text === undefined)
27
+ return undefined;
28
+ try {
29
+ const parsed = JSON.parse(text);
30
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed))
31
+ return parsed;
32
+ }
33
+ catch {
34
+ // not JSON: treated like a missing package.json
35
+ }
36
+ return undefined;
37
+ }
38
+ /** The names under `dependencies` and `devDependencies`, when those are plain objects. */
39
+ function dependencyNames(pkg) {
40
+ const names = new Set();
41
+ for (const key of ["dependencies", "devDependencies"]) {
42
+ const group = pkg[key];
43
+ if (typeof group === "object" && group !== null && !Array.isArray(group)) {
44
+ for (const name of Object.keys(group))
45
+ names.add(name);
46
+ }
47
+ }
48
+ return names;
49
+ }
50
+ /** A cleaned text value, or undefined when nothing is left of it. */
51
+ function cleanedText(value, maxLength) {
52
+ if (typeof value !== "string")
53
+ return undefined;
54
+ const cleaned = cleanAnswerText(value, maxLength);
55
+ return cleaned === "" ? undefined : cleaned;
56
+ }
57
+ /** Guesses project name, description, language, framework, package manager and test runner. Never throws. */
58
+ export function detectProject(snapshot) {
59
+ const detected = {};
60
+ const pkg = parsePackageJson(snapshot.packageJson);
61
+ const deps = pkg === undefined ? new Set() : dependencyNames(pkg);
62
+ const rootNames = new Set(snapshot.rootNames);
63
+ const projectName = cleanedText(pkg?.name, 80) ?? cleanedText(snapshot.folderName, 80);
64
+ if (projectName !== undefined)
65
+ detected.projectName = projectName;
66
+ const description = cleanedText(pkg?.description, 200);
67
+ if (description !== undefined)
68
+ detected.description = description;
69
+ if (rootNames.has("tsconfig.json") || deps.has("typescript"))
70
+ detected.language = "TypeScript";
71
+ else if (pkg !== undefined)
72
+ detected.language = "JavaScript";
73
+ const framework = FRAMEWORKS.find(([dependency]) => deps.has(dependency));
74
+ if (framework !== undefined)
75
+ detected.framework = framework[1];
76
+ const lockfile = LOCKFILES.find(([file]) => rootNames.has(file));
77
+ if (lockfile !== undefined)
78
+ detected.packageManager = lockfile[1];
79
+ const testRunner = TEST_RUNNERS.find((name) => deps.has(name));
80
+ if (testRunner !== undefined)
81
+ detected.testRunner = testRunner;
82
+ return detected;
83
+ }
84
+ //# sourceMappingURL=init-detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-detect.js","sourceRoot":"","sources":["../src/init-detect.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,mGAAmG;AACnG,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAatD,kEAAkE;AAClE,MAAM,UAAU,GAA6D;IAC3E,CAAC,MAAM,EAAE,SAAS,CAAC;IACnB,CAAC,OAAO,EAAE,OAAO,CAAC;IAClB,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,SAAS,EAAE,SAAS,CAAC;IACtB,CAAC,SAAS,EAAE,SAAS,CAAC;IACtB,CAAC,MAAM,EAAE,MAAM,CAAC;IAChB,CAAC,WAAW,EAAE,aAAa,CAAC;CAC7B,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAU,CAAC;AAE1D,sEAAsE;AACtE,MAAM,SAAS,GAA0D;IACvE,CAAC,mBAAmB,EAAE,KAAK,CAAC;IAC5B,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC1B,CAAC,WAAW,EAAE,MAAM,CAAC;IACrB,CAAC,UAAU,EAAE,KAAK,CAAC;IACnB,CAAC,WAAW,EAAE,KAAK,CAAC;CACrB,CAAC;AAEF,4HAA4H;AAC5H,SAAS,gBAAgB,CAAC,IAAwB;IAChD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;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AAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/D,IAAI,UAAU,KAAK,SAAS;QAAE,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IAE/D,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { type InitAnswers } from "./init-checklist.js";
2
+ import type { InitSettings, SeanceConfig } from "./seance-config.js";
3
+ /** One thing `init` may write. The kind tells `planInit` how to treat an existing file at that path. */
4
+ export type RenderedUnit = {
5
+ kind: "file";
6
+ path: string;
7
+ template: string;
8
+ content: string;
9
+ } | {
10
+ kind: "block";
11
+ path: "AGENTS.md";
12
+ template: "agents-rules";
13
+ body: string;
14
+ newFile: string;
15
+ } | {
16
+ kind: "create-only";
17
+ path: "PROJECT.md";
18
+ content: string;
19
+ autoBody: string;
20
+ } | {
21
+ kind: "create-only";
22
+ path: "DECISIONS.md";
23
+ content: string;
24
+ } | {
25
+ kind: "data";
26
+ path: ".seance/config.json";
27
+ content: string;
28
+ };
29
+ /** The DECISIONS.md `seance init` creates: a heading, the entry format and one example in a comment. It has no entry and no answer text. */
30
+ export declare const DECISIONS_TEMPLATE: string;
31
+ /**
32
+ * Renders everything `init` writes for these answers. Answers must already pass `InitAnswersSchema`.
33
+ * Text answers reach Markdown only after the CLI cleaned them and always after a fixed prefix on the same line,
34
+ * and reach JSON only through `JSON.stringify`, so an answer cannot add a marker, a front-matter line or a heading.
35
+ */
36
+ export declare function renderInitFiles(answers: InitAnswers, settings: InitSettings, config?: SeanceConfig): RenderedUnit[];
@@ -0,0 +1,257 @@
1
+ // Renders every file `seance init` writes (steering, hooks, guard script, tutor agent, AGENTS.md block,
2
+ // PROJECT.md, config) from the checked answers. Pure: same input, same output; the CLI does the writing.
3
+ import { DEFAULT_PASS_MARK } from "./gate.js";
4
+ import { DEPENDENCY_GUARD_SCRIPT } from "./dependency-guard.js";
5
+ import { evaluateChecklist } from "./init-checklist.js";
6
+ import { AUTO_END, AUTO_START, RULES_END, RULES_START } from "./markers.js";
7
+ const NOT_DECIDED = "not decided yet";
8
+ // The rule that tells an agent to keep the decision log (Task 13). It sits right after the PROJECT.md rule.
9
+ const DECISIONS_RULE = "- After every task, add an entry at the end of DECISIONS.md in the format shown at the top of that file: the task, what you built and how, where you got stuck, the options you considered, what you chose and why, and open questions for the user.";
10
+ /** The DECISIONS.md `seance init` creates: a heading, the entry format and one example in a comment. It has no entry and no answer text. */
11
+ export const DECISIONS_TEMPLATE = [
12
+ "# DECISIONS.md",
13
+ "Decision log. After every task the AI agent adds one entry at the end of this file. Seance reads it: `seance sync` warns when a task added none, and `seance quiz` can ask about the latest one.",
14
+ "Format of an entry: a heading `## YYYY-MM-DD Task <id>: <title>`, then these six bullets in this order (write `none` when there is nothing to say): `- Built:` what was built and how; `- Stuck:` where it got stuck; `- Options:` the options considered; `- Chose:` what was chosen; `- Why:` why; `- Open questions:` questions for the user.",
15
+ "<!--",
16
+ "## YYYY-MM-DD Task <id>: <short title>",
17
+ "- Built: <what was built and how>",
18
+ "- Stuck: <where it got stuck, or none>",
19
+ "- Options: <option A; option B>",
20
+ "- Chose: <the option taken>",
21
+ "- Why: <the reason>",
22
+ "- Open questions: <questions for the user, or none>",
23
+ "-->",
24
+ "",
25
+ ].join("\n");
26
+ // Words for the "Not decided yet: ..." line.
27
+ const LABELS = {
28
+ projectName: "project name",
29
+ description: "description",
30
+ audience: "audience",
31
+ language: "language",
32
+ framework: "framework",
33
+ packageManager: "package manager",
34
+ testRunner: "test runner",
35
+ experience: "experience",
36
+ outOfScope: "out of scope",
37
+ conventions: "extra rules",
38
+ };
39
+ // The commands to add an exact version and to audit, per package manager. An undecided manager means npm.
40
+ const PACKAGE_COMMANDS = {
41
+ npm: { pin: "npm install --save-exact <pkg>", audit: "npm audit" },
42
+ pnpm: { pin: "pnpm add --save-exact <pkg>", audit: "pnpm audit" },
43
+ yarn: { pin: "yarn add --exact <pkg>", audit: "yarn npm audit" },
44
+ bun: { pin: "bun add --exact <pkg>", audit: "bun audit" },
45
+ };
46
+ /** The answered value of an item, or undefined when it is missing or undecided. */
47
+ function answered(answers, id) {
48
+ const answer = answers[id];
49
+ return answer === undefined || answer.source === "undecided" ? undefined : answer.value;
50
+ }
51
+ /** The answered value, or "not decided yet". */
52
+ function shown(answers, id) {
53
+ return answered(answers, id) ?? NOT_DECIDED;
54
+ }
55
+ /** The stack on one line, for the project steering and PROJECT.md. */
56
+ function stackLine(answers) {
57
+ return [shown(answers, "language"), shown(answers, "framework"), `package manager ${shown(answers, "packageManager")}`, `tests: ${shown(answers, "testRunner")}`].join("; ");
58
+ }
59
+ /** "a beginner", "an intermediate", "an experienced". */
60
+ function withArticle(experience) {
61
+ return `${/^[aeiou]/.test(experience) ? "an" : "a"} ${experience}`;
62
+ }
63
+ function toJson(value) {
64
+ return JSON.stringify(value, null, 2) + "\n";
65
+ }
66
+ const FRONT_MATTER = ["---", "inclusion: always", "---"];
67
+ /** A steering file: front matter, a heading, a blank line, then the lines. */
68
+ function steeringFile(heading, lines) {
69
+ return [...FRONT_MATTER, `# ${heading}`, "", ...lines, ""].join("\n");
70
+ }
71
+ function projectSection(answers) {
72
+ const lines = [
73
+ `- What: ${shown(answers, "description")}`,
74
+ `- For: ${shown(answers, "audience")}`,
75
+ `- Stack: ${stackLine(answers)}`,
76
+ ];
77
+ const outOfScope = answered(answers, "outOfScope");
78
+ if (outOfScope !== undefined)
79
+ lines.push(`- Out of scope: ${outOfScope}`);
80
+ const conventions = answered(answers, "conventions");
81
+ if (conventions !== undefined)
82
+ lines.push(`- Extra rules: ${conventions}`);
83
+ lines.push("- Read PROJECT.md first instead of scanning the repo, and update it after each task.");
84
+ lines.push(DECISIONS_RULE);
85
+ const undecided = evaluateChecklist(answers).undecided.map((id) => LABELS[id]);
86
+ if (undecided.length > 0) {
87
+ lines.push(`- Not decided yet: ${undecided.join(", ")}. Ask the user before work that depends on these.`);
88
+ }
89
+ return { heading: `Project: ${shown(answers, "projectName")}`, lines };
90
+ }
91
+ function securitySection(answers) {
92
+ const manager = answered(answers, "packageManager") ?? "npm";
93
+ const commands = PACKAGE_COMMANDS[manager] ?? PACKAGE_COMMANDS["npm"];
94
+ return {
95
+ heading: "Security rules (written by Seance)",
96
+ lines: [
97
+ `- Ask before adding any dependency. Pin exact versions (\`${commands.pin}\`) and commit the lockfile.`,
98
+ `- After dependency changes, run \`${commands.audit}\`.`,
99
+ "- Avoid package versions published in the last 7 days.",
100
+ "- Validate all AI output and external input with zod, and cap its size.",
101
+ "- Never put secrets in code, logs or commits.",
102
+ "- Never add `.kiro/` to `.gitignore`.",
103
+ "- When the Seance dependency guard blocks a command, ask the user. Do not retry it another way and do not edit the allow list yourself.",
104
+ ],
105
+ };
106
+ }
107
+ function learningSection(answers) {
108
+ // An experience that is not answered gets the beginner wording: it only adds explanations.
109
+ const experience = answered(answers, "experience") ?? "beginner";
110
+ const lines = ["- Ask clarifying questions until the information the task needs is complete. State your assumptions."];
111
+ if (experience === "experienced")
112
+ lines.push("- Explain only non-obvious choices.");
113
+ else
114
+ lines.push("- Explain every change in plain words: what it does, why, and which concept it uses.");
115
+ if (experience === "beginner")
116
+ lines.push("- Define each new term the first time you use it.");
117
+ lines.push("- Prefer simple code the user can read. No unrequested refactors.");
118
+ lines.push("- After each task, suggest running `seance quiz`.");
119
+ return { heading: `Working with ${withArticle(experience)} developer (written by Seance)`, lines };
120
+ }
121
+ function agentsBlock(sections) {
122
+ const lines = ["## Rules for AI agents (written by Seance)"];
123
+ for (const section of sections)
124
+ lines.push("", `### ${section.heading}`, ...section.lines);
125
+ return lines.join("\n") + "\n";
126
+ }
127
+ function projectMd(answers, autoBody) {
128
+ return [
129
+ `# PROJECT.md: ${shown(answers, "projectName")}`,
130
+ "",
131
+ "> Agents: read this file first instead of scanning the repo. Humans: this is the one-page state of the project.",
132
+ "> The section between the `seance:auto` markers is rewritten by `seance sync`. Edit everything else freely.",
133
+ "",
134
+ "## What it is",
135
+ `- ${shown(answers, "description")}`,
136
+ "",
137
+ "## Who it is for",
138
+ `- ${shown(answers, "audience")}`,
139
+ "",
140
+ "## Tech stack",
141
+ `- ${stackLine(answers)}`,
142
+ "",
143
+ "## Tasks",
144
+ "| # | Task | Status |",
145
+ "|---|---|---|",
146
+ "",
147
+ "## Key decisions",
148
+ "- (add decisions here)",
149
+ "",
150
+ AUTO_START,
151
+ autoBody + AUTO_END,
152
+ "",
153
+ ].join("\n");
154
+ }
155
+ function hookFiles() {
156
+ return {
157
+ sync: toJson({
158
+ version: "v1",
159
+ hooks: [
160
+ {
161
+ name: "Seance sync",
162
+ trigger: "PostTaskExec",
163
+ description: "Updates the auto section of PROJECT.md and saves a quiz on the change after each spec task.",
164
+ action: { type: "command", command: "npx --no-install seance sync" },
165
+ timeout: 120,
166
+ },
167
+ ],
168
+ }),
169
+ guard: toJson({
170
+ version: "v1",
171
+ hooks: [
172
+ {
173
+ name: "Seance dependency guard",
174
+ trigger: "PreToolUse",
175
+ matcher: "shell",
176
+ description: "Blocks shell commands that add packages until the user approves them.",
177
+ action: { type: "command", command: "node .kiro/seance/dependency-guard.mjs" },
178
+ timeout: 10,
179
+ },
180
+ ],
181
+ }),
182
+ };
183
+ }
184
+ function tutorAgent(answers) {
185
+ const experience = answered(answers, "experience") ?? "beginner";
186
+ const prompt = [
187
+ `You are Seance Tutor, a tutor for ${withArticle(experience)} developer on the project "${shown(answers, "projectName")}". You never write or change code. Your job is to check that the developer understands what the AI just built.`,
188
+ "Tools from the Seance MCP server: get_project_context gives the project summary and the latest change; get_due_reviews lists concepts the developer missed before; get_decisions gives the latest entries of DECISIONS.md; start_quiz makes a quiz on the latest change and gives the first question; submit_answer checks one answer.",
189
+ "To quiz the developer: call start_quiz, then ask one question at a time and wait for the answer. Show each choice with the number the tool gives it (choices is a list of { number, text }, numbered from 1). Pass the developer's answer to submit_answer as choiceNumber (the number the developer picked, exactly as shown; never subtract 1) or choiceText (the exact choice text) for a choice question, and as text for an explain question. Never guess an answer and never reveal one before submit_answer returns it. At the end, report the score. If get_due_reviews lists cards, tell the developer to run `seance review` in a terminal.",
190
+ "If these tools are not available, read PROJECT.md and the files the user names, and ask the questions yourself. Tell the user they can also run `seance quiz` and `seance review` in a terminal.",
191
+ "Ask one question at a time and wait for the answer. Let the user try before you explain the answer.",
192
+ ].join("\n");
193
+ return toJson({
194
+ name: "seance-tutor",
195
+ description: "Quizzes you on the code the AI just built. Asks questions and never writes code. Pick it in the agent selector before asking for a quiz: as a sub-agent it cannot continue a conversation.",
196
+ prompt,
197
+ tools: ["read", "@seance", "@power-seance-seance"], // the second one is the server name when Seance is installed as a Kiro power
198
+ includeMcpJson: true,
199
+ includePowers: true,
200
+ resources: ["file://PROJECT.md"],
201
+ permissions: { rules: [{ capability: "fs_write", match: ["**"], effect: "deny" }] },
202
+ welcomeMessage: "Seance tutor. Ask me to quiz you on the latest change.",
203
+ });
204
+ }
205
+ /** `.seance/config.json`: this run's answers and settings on top of what was stored; keys we do not know stay. */
206
+ function configJson(answers, settings, stored) {
207
+ const known = {
208
+ schemaVersion: 1,
209
+ answers,
210
+ targets: settings.targets,
211
+ gate: { ...stored?.gate, mode: settings.gateMode, passMark: stored?.gate.passMark ?? DEFAULT_PASS_MARK },
212
+ dependencyGuard: { ...stored?.dependencyGuard, allow: stored?.dependencyGuard.allow ?? [] },
213
+ createdWith: stored?.createdWith ?? settings.version,
214
+ };
215
+ const extras = Object.entries(stored ?? {}).filter(([key]) => !Object.hasOwn(known, key));
216
+ return toJson(Object.fromEntries([...Object.entries(known), ...extras]));
217
+ }
218
+ /**
219
+ * Renders everything `init` writes for these answers. Answers must already pass `InitAnswersSchema`.
220
+ * Text answers reach Markdown only after the CLI cleaned them and always after a fixed prefix on the same line,
221
+ * and reach JSON only through `JSON.stringify`, so an answer cannot add a marker, a front-matter line or a heading.
222
+ */
223
+ export function renderInitFiles(answers, settings, config) {
224
+ const units = [];
225
+ const project = projectSection(answers);
226
+ const security = securitySection(answers);
227
+ const learning = learningSection(answers);
228
+ if (settings.targets.includes("kiro")) {
229
+ const file = (path, template, content) => {
230
+ units.push({ kind: "file", path, template, content });
231
+ };
232
+ const hooks = hookFiles();
233
+ file(".kiro/steering/seance-project.md", "steering-project", steeringFile(project.heading, project.lines));
234
+ file(".kiro/steering/seance-security.md", "steering-security", steeringFile(security.heading, security.lines));
235
+ file(".kiro/steering/seance-learning.md", "steering-learning", steeringFile(learning.heading, learning.lines));
236
+ file(".kiro/hooks/seance-sync.json", "hook-sync", hooks.sync);
237
+ file(".kiro/hooks/seance-dependency-guard.json", "hook-guard", hooks.guard);
238
+ file(".kiro/seance/dependency-guard.mjs", "guard-script", DEPENDENCY_GUARD_SCRIPT);
239
+ file(".kiro/agents/seance-tutor.json", "agent-tutor", tutorAgent(answers));
240
+ }
241
+ if (settings.targets.includes("agents-md")) {
242
+ const body = agentsBlock([project, security, learning]);
243
+ units.push({
244
+ kind: "block",
245
+ path: "AGENTS.md",
246
+ template: "agents-rules",
247
+ body,
248
+ newFile: `# AGENTS.md\n\n${RULES_START}\n${body}${RULES_END}\n`,
249
+ });
250
+ }
251
+ const autoBody = "_Filled by `seance sync` after each Kiro task._\n";
252
+ units.push({ kind: "create-only", path: "PROJECT.md", content: projectMd(answers, autoBody), autoBody });
253
+ units.push({ kind: "create-only", path: "DECISIONS.md", content: DECISIONS_TEMPLATE });
254
+ units.push({ kind: "data", path: ".seance/config.json", content: configJson(answers, settings, config) });
255
+ return units;
256
+ }
257
+ //# sourceMappingURL=init-templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-templates.js","sourceRoot":"","sources":["../src/init-templates.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,yGAAyG;AACzG,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAsC,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE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+1,13 @@
1
+ export declare const MAP_LIMITS: {
2
+ readonly maxFiles: 50;
3
+ readonly maxTotalBytes: 102400;
4
+ };
5
+ /** Most names kept in `mentionedNames`. A list of exactly this length may have been cut. */
6
+ export declare const MAX_MENTIONED_NAMES = 500;
7
+ /** `superClass` text for an `extends` expression that is not a name or a dotted name, for example `mixin(Base)`. */
8
+ export declare const UNKNOWN_SUPERCLASS = "(expression)";
9
+ /**
10
+ * Replaces `\` with `/`, collapses repeated slashes, drops every `.` segment (`./a`, `a/./b`),
11
+ * a leading `/` and a trailing `/`. `..` segments are kept.
12
+ */
13
+ export declare function normalisePath(path: string): string;
@@ -0,0 +1,19 @@
1
+ // Map basics: the limits, the path normaliser and two constants that Babel-free modules need.
2
+ // Kept apart from structure-map.ts so the web bundle never pulls in the Babel parser.
3
+ export const MAP_LIMITS = { maxFiles: 50, maxTotalBytes: 102_400 };
4
+ /** Most names kept in `mentionedNames`. A list of exactly this length may have been cut. */
5
+ export const MAX_MENTIONED_NAMES = 500;
6
+ /** `superClass` text for an `extends` expression that is not a name or a dotted name, for example `mixin(Base)`. */
7
+ export const UNKNOWN_SUPERCLASS = "(expression)";
8
+ /**
9
+ * Replaces `\` with `/`, collapses repeated slashes, drops every `.` segment (`./a`, `a/./b`),
10
+ * a leading `/` and a trailing `/`. `..` segments are kept.
11
+ */
12
+ export function normalisePath(path) {
13
+ return path
14
+ .replace(/\\/g, "/")
15
+ .split("/")
16
+ .filter((segment) => segment !== "" && segment !== ".")
17
+ .join("/");
18
+ }
19
+ //# sourceMappingURL=map-basics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-basics.js","sourceRoot":"","sources":["../src/map-basics.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,sFAAsF;AACtF,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,EAAW,CAAC;AAC5E,4FAA4F;AAC5F,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC,oHAAoH;AACpH,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AACjD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI;SACR,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,GAAG,CAAC;SACtD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { StructureMap } from "./structure-map.js";
2
+ /** Most file lines in the summary; the rest are counted in an `and N more files` line. */
3
+ export declare const MAX_SUMMARY_FILES = 10;
4
+ /** The summary lines: one header, at most 10 file lines (map order) and an `and N more files` line. */
5
+ export declare function formatMapSummary(map: StructureMap): string[];
@@ -0,0 +1,50 @@
1
+ import { toPlainText } from "./terminal-text.js";
2
+ /** Most file lines in the summary; the rest are counted in an `and N more files` line. */
3
+ export const MAX_SUMMARY_FILES = 10;
4
+ const MAX_LINE_CHARS = 300;
5
+ const MAX_NAMES = 6;
6
+ const MAX_SOURCES = 4;
7
+ /** The export names of a file: ES names except `*`, then CommonJS names, without duplicates. */
8
+ function exportNames(file) {
9
+ const names = file.exports.map((entry) => entry.name).filter((name) => name !== "*");
10
+ return [...new Set([...names, ...file.commonjsExports])];
11
+ }
12
+ /** `a, b, c +2 more` for a long list. */
13
+ function listWithMore(items, max) {
14
+ const shown = items.slice(0, max).join(", ");
15
+ return items.length > max ? `${shown} +${items.length - max} more` : shown;
16
+ }
17
+ function plural(count, one, many) {
18
+ return count === 1 ? one : many;
19
+ }
20
+ function fileLine(file) {
21
+ if (!file.parsed)
22
+ return ` ${file.path}: not parsed (${file.language})`;
23
+ const names = exportNames(file);
24
+ const sources = [...new Set(file.imports.map((entry) => entry.source))];
25
+ const exportsText = names.length === 0 ? "no exports" : `exports ${listWithMore(names, MAX_NAMES)}`;
26
+ return sources.length === 0 ? ` ${file.path}: ${exportsText}` : ` ${file.path}: ${exportsText}; imports ${listWithMore(sources, MAX_SOURCES)}`;
27
+ }
28
+ /** The summary lines: one header, at most 10 file lines (map order) and an `and N more files` line. */
29
+ export function formatMapSummary(map) {
30
+ const files = map.files;
31
+ let exportCount = 0;
32
+ let functionCount = 0;
33
+ let classCount = 0;
34
+ for (const file of files) {
35
+ exportCount += exportNames(file).length;
36
+ functionCount += file.functions.length + file.classes.reduce((sum, entry) => sum + entry.methods.length, 0);
37
+ classCount += file.classes.length;
38
+ }
39
+ const parsed = files.filter((file) => file.parsed).length;
40
+ const lines = [
41
+ `Structure map: ${files.length} ${plural(files.length, "file", "files")} (${parsed} parsed), ${exportCount} ${plural(exportCount, "export", "exports")}, ${functionCount} ${plural(functionCount, "function", "functions")}, ${classCount} ${plural(classCount, "class", "classes")}`,
42
+ ...files.slice(0, MAX_SUMMARY_FILES).map(fileLine),
43
+ ];
44
+ if (files.length > MAX_SUMMARY_FILES) {
45
+ const rest = files.length - MAX_SUMMARY_FILES;
46
+ lines.push(` and ${rest} more ${plural(rest, "file", "files")}`);
47
+ }
48
+ return lines.map((line) => toPlainText(line, { maxChars: MAX_LINE_CHARS }));
49
+ }
50
+ //# sourceMappingURL=map-summary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-summary.js","sourceRoot":"","sources":["../src/map-summary.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,0FAA0F;AAC1F,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,gGAAgG;AAChG,SAAS,WAAW,CAAC,IAAe;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAA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,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE;QACrR,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;KACnD,CAAC;IACF,IAAI,KAAK,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,iBAAiB,CAAC;QAC9C,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,SAAS,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;AAC9E,CAAC"}
@@ -0,0 +1,51 @@
1
+ /** Markers that delimit the auto-generated sections of PROJECT.md. */
2
+ export declare const AUTO_START = "<!-- seance:auto:start -->";
3
+ export declare const AUTO_END = "<!-- seance:auto:end -->";
4
+ /** Markers that delimit the rules block `seance init` writes into AGENTS.md. */
5
+ export declare const RULES_START = "<!-- seance:rules:start -->";
6
+ export declare const RULES_END = "<!-- seance:rules:end -->";
7
+ /**
8
+ * What a text holds for one marker pair.
9
+ * `ok` means exactly one start and one end, start first. `body` is everything between the two markers
10
+ * (including the line break after the start marker); `bodyStart` and `bodyEnd` are its string offsets.
11
+ */
12
+ export type BlockState = {
13
+ state: "missing";
14
+ } | {
15
+ state: "malformed";
16
+ } | {
17
+ state: "ok";
18
+ bodyStart: number;
19
+ bodyEnd: number;
20
+ body: string;
21
+ };
22
+ /** Looks for one marker pair: no marker at all is `missing`, exactly one start then one end is `ok`, anything else is `malformed`. */
23
+ export declare function findBlock(text: string, start: string, end: string): BlockState;
24
+ /**
25
+ * Replaces the text between the markers with `body`, exactly as given (the caller adds the line breaks
26
+ * and picks the line ending). Throws RangeError unless the markers are well formed.
27
+ */
28
+ export declare function replaceBlockBody(text: string, start: string, end: string, body: string): string;
29
+ /**
30
+ * Appends a marker block at the end of a text that has no markers. The original text stays an exact prefix.
31
+ * The block uses the text's own line ending (CRLF when the text has any CRLF). Throws RangeError unless the markers are missing.
32
+ */
33
+ export declare function appendBlock(text: string, start: string, end: string, body: string): string;
34
+ /** Returns true when the text contains a well-formed auto section (start before end). */
35
+ export declare function hasAutoSection(text: string): boolean;
36
+ /** Result of `mergeAutoSections`: the new text (and whether it differs from the old one), or why the markers cannot be used. */
37
+ export type AutoMerge = {
38
+ status: "ok";
39
+ text: string;
40
+ changed: boolean;
41
+ } | {
42
+ status: "missing";
43
+ } | {
44
+ status: "malformed";
45
+ };
46
+ /**
47
+ * Replaces the text between the auto markers of PROJECT.md with `body` and keeps every character outside them (a BOM too).
48
+ * The body gets the line ending the text already uses (CRLF when the text has any CRLF) and starts and ends on its own line.
49
+ * Throws RangeError when the body itself contains an auto marker.
50
+ */
51
+ export declare function mergeAutoSections(text: string, body: string): AutoMerge;
@@ -0,0 +1,84 @@
1
+ // Marker blocks: find, replace and append the text between a start and an end marker.
2
+ // Used for the auto section of PROJECT.md and the rules block of AGENTS.md. Pure: no file access.
3
+ /** Markers that delimit the auto-generated sections of PROJECT.md. */
4
+ export const AUTO_START = "<!-- seance:auto:start -->";
5
+ export const AUTO_END = "<!-- seance:auto:end -->";
6
+ /** Markers that delimit the rules block `seance init` writes into AGENTS.md. */
7
+ export const RULES_START = "<!-- seance:rules:start -->";
8
+ export const RULES_END = "<!-- seance:rules:end -->";
9
+ /** Counts non-overlapping occurrences of `needle` in `text`. */
10
+ function countOccurrences(text, needle) {
11
+ let count = 0;
12
+ let from = 0;
13
+ for (;;) {
14
+ const at = text.indexOf(needle, from);
15
+ if (at === -1)
16
+ return count;
17
+ count += 1;
18
+ from = at + needle.length;
19
+ }
20
+ }
21
+ /** Looks for one marker pair: no marker at all is `missing`, exactly one start then one end is `ok`, anything else is `malformed`. */
22
+ export function findBlock(text, start, end) {
23
+ const starts = countOccurrences(text, start);
24
+ const ends = countOccurrences(text, end);
25
+ if (starts === 0 && ends === 0)
26
+ return { state: "missing" };
27
+ if (starts !== 1 || ends !== 1)
28
+ return { state: "malformed" };
29
+ const startAt = text.indexOf(start);
30
+ const endAt = text.indexOf(end);
31
+ if (startAt + start.length > endAt)
32
+ return { state: "malformed" };
33
+ const bodyStart = startAt + start.length;
34
+ return { state: "ok", bodyStart, bodyEnd: endAt, body: text.slice(bodyStart, endAt) };
35
+ }
36
+ /**
37
+ * Replaces the text between the markers with `body`, exactly as given (the caller adds the line breaks
38
+ * and picks the line ending). Throws RangeError unless the markers are well formed.
39
+ */
40
+ export function replaceBlockBody(text, start, end, body) {
41
+ const block = findBlock(text, start, end);
42
+ if (block.state !== "ok")
43
+ throw new RangeError(`cannot replace: markers are ${block.state}`);
44
+ return text.slice(0, block.bodyStart) + body + text.slice(block.bodyEnd);
45
+ }
46
+ /**
47
+ * Appends a marker block at the end of a text that has no markers. The original text stays an exact prefix.
48
+ * The block uses the text's own line ending (CRLF when the text has any CRLF). Throws RangeError unless the markers are missing.
49
+ */
50
+ export function appendBlock(text, start, end, body) {
51
+ const block = findBlock(text, start, end);
52
+ if (block.state !== "missing")
53
+ throw new RangeError(`cannot append: markers are ${block.state}`);
54
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
55
+ const lead = text === "" || text.endsWith(eol) ? "" : eol;
56
+ const bodyWithEol = body.replaceAll("\r\n", "\n").replaceAll("\n", eol);
57
+ return text + lead + eol + start + eol + bodyWithEol + end + eol;
58
+ }
59
+ /** Returns true when the text contains a well-formed auto section (start before end). */
60
+ export function hasAutoSection(text) {
61
+ const start = text.indexOf(AUTO_START);
62
+ if (start === -1)
63
+ return false;
64
+ return text.indexOf(AUTO_END, start + AUTO_START.length) !== -1;
65
+ }
66
+ /**
67
+ * Replaces the text between the auto markers of PROJECT.md with `body` and keeps every character outside them (a BOM too).
68
+ * The body gets the line ending the text already uses (CRLF when the text has any CRLF) and starts and ends on its own line.
69
+ * Throws RangeError when the body itself contains an auto marker.
70
+ */
71
+ export function mergeAutoSections(text, body) {
72
+ if (body.includes(AUTO_START) || body.includes(AUTO_END))
73
+ throw new RangeError("body must not contain an auto marker");
74
+ const block = findBlock(text, AUTO_START, AUTO_END);
75
+ if (block.state !== "ok")
76
+ return { status: block.state };
77
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
78
+ let normal = body.replace(/\r\n?/g, "\n");
79
+ if (!normal.endsWith("\n"))
80
+ normal += "\n";
81
+ const next = text.slice(0, block.bodyStart) + eol + normal.replaceAll("\n", eol) + text.slice(block.bodyEnd);
82
+ return { status: "ok", text: next, changed: next !== text };
83
+ }
84
+ //# sourceMappingURL=markers.js.map