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,367 @@
1
+ // `seance sync`: finds what changed since the last sync (with git), updates the auto section of PROJECT.md and saves a pending
2
+ // structural quiz in `.seance/state.json`. No AI, no questions asked, safe to run from a hook. Pure decisions are in @seance/core;
3
+ // this file runs git, reads the changed files and writes the two output files.
4
+ import { lstat, stat } from "node:fs/promises";
5
+ import { join, resolve } from "node:path";
6
+ import { AUTO_END, AUTO_START, DECISIONS_PATH, DECISION_LIMITS, MAP_LIMITS, QuizItemSchema, STATE_LIMITS, STATE_PATH, SeanceStateSchema, buildSnapshot, buildStructureMap, changeFingerprint, decisionCheck, emptyState, findBlock, generateStructuralQuestions, isExcludedPath, mergeAutoSections, mergeChangeLists, parseChangelog, parseNulPaths, parseNumstatZ, pickMapFiles, renderAutoBody, selectNewChanges, serializeState, } from "@seance/core";
7
+ import { createGitRunner } from "../git.js";
8
+ import { REAL_WRITE_OPS, checkParents, errorCode, readExisting, resolveRoot, writeAtomic } from "../init-fs.js";
9
+ const PROJECT_PATH = "PROJECT.md";
10
+ const MAX_PROJECT_BYTES = 1_000_000;
11
+ const MAX_MAP_FILE_BYTES = 102_400;
12
+ const HASH_BATCH = 50;
13
+ const QUESTION_COUNT = 5;
14
+ // A git object hash (SHA-1 or SHA-256), used for commits and for blobs.
15
+ const GIT_HASH = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
16
+ /** Thrown after a line was printed, to leave the flow with an exit code (from helpers that never return, such as `gitFailed`). */
17
+ class Stop extends Error {
18
+ exitCode;
19
+ constructor(exitCode) {
20
+ super("stop");
21
+ this.exitCode = exitCode;
22
+ }
23
+ }
24
+ /** Runs `seance sync`. Returns the exit code and never calls `process.exit`. */
25
+ export async function runSync(options, deps) {
26
+ try {
27
+ return await syncFlow(options, deps);
28
+ }
29
+ catch (error) {
30
+ if (error instanceof Stop)
31
+ return error.exitCode;
32
+ throw error;
33
+ }
34
+ }
35
+ function say(deps, text) {
36
+ deps.out(`seance sync: ${text}`);
37
+ }
38
+ /** Prints the "git failed" line of design "Output" and leaves with exit code 0. */
39
+ function gitFailed(deps, subCommand, reason) {
40
+ say(deps, reason === "not-found" ? "git not found; nothing synced" : `git ${subCommand} failed (${reason}); nothing synced`);
41
+ throw new Stop(0);
42
+ }
43
+ /** Runs git and returns stdout; any failure prints a line and stops the sync. */
44
+ async function gitText(deps, git, subCommand, args) {
45
+ const result = await git(args);
46
+ if (!result.ok)
47
+ gitFailed(deps, subCommand, result.reason);
48
+ return result.stdout;
49
+ }
50
+ function pad(value) {
51
+ return String(value).padStart(2, "0");
52
+ }
53
+ async function isDirectory(path) {
54
+ try {
55
+ return (await stat(path)).isDirectory();
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
61
+ async function readState(root) {
62
+ const found = await readExisting(root, STATE_PATH, STATE_LIMITS.maxBytes);
63
+ if (found === undefined)
64
+ return { state: emptyState(), text: undefined, usable: true };
65
+ const unusable = { state: emptyState(), text: undefined, usable: false };
66
+ if (found.type !== "file")
67
+ return unusable;
68
+ try {
69
+ const parsed = SeanceStateSchema.safeParse(JSON.parse(found.content));
70
+ return parsed.success ? { state: parsed.data, text: found.content, usable: true } : unusable;
71
+ }
72
+ catch {
73
+ return unusable;
74
+ }
75
+ }
76
+ /** Reads DECISIONS.md for the decision check: missing, not a regular UTF-8 file under 256 KB (`other`), or its text. */
77
+ async function readDecisionFile(root) {
78
+ const found = await readExisting(root, DECISIONS_PATH, DECISION_LIMITS.maxFileBytes);
79
+ if (found === undefined)
80
+ return { type: "missing" };
81
+ return found.type === "file" ? { type: "file", text: found.content } : { type: "other" };
82
+ }
83
+ /** The git hash of HEAD, or null when the repo has no commit. Stops the sync when git itself fails. */
84
+ async function readHead(deps, git) {
85
+ const inside = await git(["rev-parse", "--is-inside-work-tree"]);
86
+ if (!inside.ok) {
87
+ if (inside.reason === "failed") {
88
+ say(deps, "not a git repository; nothing synced");
89
+ throw new Stop(0);
90
+ }
91
+ gitFailed(deps, "rev-parse", inside.reason);
92
+ }
93
+ if (inside.stdout.trim() !== "true") {
94
+ say(deps, "not a git repository; nothing synced");
95
+ throw new Stop(0);
96
+ }
97
+ const head = await git(["rev-parse", "--verify", "-q", "HEAD^{commit}"]);
98
+ if (head.ok) {
99
+ const hash = head.stdout.trim();
100
+ return GIT_HASH.test(hash) ? hash : null;
101
+ }
102
+ if (head.reason === "failed")
103
+ return null; // no commit yet
104
+ return gitFailed(deps, "rev-parse", head.reason);
105
+ }
106
+ /** The commit to compare with: the last synced commit when git still has it, else HEAD. */
107
+ async function chooseBase(deps, git, head, lastCommit) {
108
+ if (lastCommit === null || lastCommit === undefined || lastCommit === head || !GIT_HASH.test(lastCommit))
109
+ return head;
110
+ const exists = await git(["cat-file", "-e", `${lastCommit}^{commit}`]);
111
+ if (exists.ok)
112
+ return lastCommit;
113
+ if (exists.reason !== "failed")
114
+ gitFailed(deps, "cat-file", exists.reason);
115
+ say(deps, "last synced commit not found, comparing with HEAD");
116
+ return head;
117
+ }
118
+ /** The snapshot value of one changed path: `deleted`, `other` or (set later from hash-object) a blob; undefined means "hash it". */
119
+ async function quickSnapshot(root, path) {
120
+ const parents = await checkParents(root, path);
121
+ if (parents === "absent")
122
+ return "deleted";
123
+ if (parents === "unsafe")
124
+ return "other";
125
+ try {
126
+ const info = await lstat(join(root, ...path.split("/")));
127
+ return info.isFile() ? undefined : "other";
128
+ }
129
+ catch (error) {
130
+ return errorCode(error) === "ENOENT" ? "deleted" : "other";
131
+ }
132
+ }
133
+ /** Adds the snapshot value and kind to every change; regular files are hashed by git in batches of 50. */
134
+ async function addSnapshots(deps, git, root, changes) {
135
+ const values = new Map();
136
+ const toHash = [];
137
+ for (const change of changes) {
138
+ const quick = await quickSnapshot(root, change.path);
139
+ if (quick === undefined)
140
+ toHash.push(change.path);
141
+ else
142
+ values.set(change.path, quick);
143
+ }
144
+ for (let from = 0; from < toHash.length; from += HASH_BATCH) {
145
+ const batch = toHash.slice(from, from + HASH_BATCH);
146
+ const lines = (await gitText(deps, git, "hash-object", ["hash-object", "--no-filters", "--", ...batch])).split("\n").filter((line) => line !== "");
147
+ if (lines.length !== batch.length || lines.some((line) => !GIT_HASH.test(line)))
148
+ gitFailed(deps, "hash-object", "failed");
149
+ batch.forEach((path, index) => values.set(path, `blob:${lines[index]}`));
150
+ }
151
+ return changes.map((change) => {
152
+ const snapshot = values.get(change.path) ?? "other";
153
+ const kind = snapshot === "deleted" ? "deleted" : change.untracked ? "new" : "modified";
154
+ return { ...change, kind, snapshot };
155
+ });
156
+ }
157
+ /** Reads the changed JS/TS files (100 KB each and in total), builds the structure map and the structural questions. */
158
+ async function buildQuiz(root, fresh, fingerprint, buildMap) {
159
+ const sources = [];
160
+ let total = 0;
161
+ for (const path of pickMapFiles(fresh)) {
162
+ const read = await readExisting(root, path, MAX_MAP_FILE_BYTES);
163
+ if (read?.type !== "file")
164
+ continue; // too large, not UTF-8 or unreadable: skipped, the sync goes on
165
+ total += Buffer.byteLength(read.content);
166
+ if (total > MAP_LIMITS.maxTotalBytes)
167
+ break;
168
+ sources.push({ path, content: read.content });
169
+ }
170
+ let map;
171
+ try {
172
+ map = buildMap(sources);
173
+ }
174
+ catch {
175
+ return { files: [], exportsByPath: {}, questions: [] }; // for example two paths that normalise to the same path: no quiz, the sync goes on
176
+ }
177
+ const seed = Number.parseInt(fingerprint.slice(8), 16);
178
+ const questions = [];
179
+ for (const question of generateStructuralQuestions(map, { count: QUESTION_COUNT, seed })) {
180
+ const item = QuizItemSchema.safeParse({ ...question, origin: "structural" });
181
+ if (item.success)
182
+ questions.push(item.data);
183
+ }
184
+ const exportsByPath = {};
185
+ for (const file of map.files) {
186
+ const names = file.exports.map((entry) => entry.name).filter((name) => name !== "*");
187
+ exportsByPath[file.path] = [...new Set([...names, ...file.commonjsExports])];
188
+ }
189
+ return { files: map.files.map((file) => file.path), exportsByPath, questions };
190
+ }
191
+ /** The `Uncommitted` flag: the working tree under the target folder differs from HEAD. */
192
+ async function isUncommitted(deps, git, base, head, changes, untracked) {
193
+ if (head === null || base === head)
194
+ return changes.length > 0;
195
+ if (untracked.some((path) => !isExcludedPath(path)))
196
+ return true;
197
+ const names = parseNulPaths(await gitText(deps, git, "diff", ["diff", "--name-only", "-z", "--no-ext-diff", "--relative", head, "--"]));
198
+ return names.some((path) => !isExcludedPath(path));
199
+ }
200
+ async function syncFlow(options, deps) {
201
+ // 1. The folder.
202
+ const dir = resolve(deps.cwd, options.dir ?? ".");
203
+ if (!(await isDirectory(dir))) {
204
+ say(deps, "--dir is not a folder");
205
+ return 1;
206
+ }
207
+ const root = await resolveRoot(dir);
208
+ const git = deps.git ?? createGitRunner(root);
209
+ // 2-3. The repo, HEAD and the state file.
210
+ const head = await readHead(deps, git);
211
+ const { state, text: stateText, usable } = await readState(root);
212
+ const last = usable ? state.lastSync : undefined;
213
+ // 4. The base commit and the change lists.
214
+ const base = head === null ? null : await chooseBase(deps, git, head, last?.commit);
215
+ let tracked = [];
216
+ let untracked;
217
+ if (head === null || base === null) {
218
+ untracked = parseNulPaths(await gitText(deps, git, "ls-files", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"]));
219
+ }
220
+ else {
221
+ tracked = parseNumstatZ(await gitText(deps, git, "diff", ["diff", "--numstat", "-z", "--no-renames", "--no-ext-diff", "--no-textconv", "--relative", base, "--"]));
222
+ untracked = parseNulPaths(await gitText(deps, git, "ls-files", ["ls-files", "-z", "--others", "--exclude-standard"]));
223
+ }
224
+ const { changes, omitted } = mergeChangeLists(tracked, untracked);
225
+ const uncommitted = await isUncommitted(deps, git, base, head, changes, untracked);
226
+ // 5. Snapshot values, then keep what is new.
227
+ const all = await addSnapshots(deps, git, root, changes);
228
+ const fresh = selectNewChanges(all, last?.files);
229
+ if (fresh.length === 0) {
230
+ // First sync and nothing to report: record the current commit as the base, so a later commit is compared with it.
231
+ if (last === undefined && usable && options.dryRun !== true) {
232
+ const baselineDecisions = decisionCheck(await readDecisionFile(root), state.decisionLog);
233
+ return recordBaseline(deps, root, { state, text: stateText, usable }, head, baselineDecisions.next);
234
+ }
235
+ say(deps, "no new changes since the last sync");
236
+ return 0;
237
+ }
238
+ // 6. The map and the questions.
239
+ const fingerprint = changeFingerprint(fresh);
240
+ const quiz = await buildQuiz(root, fresh, fingerprint, deps.buildMap ?? buildStructureMap);
241
+ // The decision check (Task 13): only with new changes and a usable state. The line is printed last.
242
+ const decisions = usable ? decisionCheck(await readDecisionFile(root), state.decisionLog) : undefined;
243
+ // 7. The auto section.
244
+ const now = deps.now();
245
+ const at = now.toISOString();
246
+ const summary = {
247
+ date: `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`,
248
+ time: `${pad(now.getHours())}:${pad(now.getMinutes())}`,
249
+ commit: head,
250
+ uncommitted,
251
+ files: fresh,
252
+ omitted,
253
+ exportsByPath: quiz.exportsByPath,
254
+ questionCount: quiz.questions.length,
255
+ };
256
+ const project = await readExisting(root, PROJECT_PATH, MAX_PROJECT_BYTES);
257
+ let previous = [];
258
+ if (project?.type === "file") {
259
+ const block = findBlock(project.content, AUTO_START, AUTO_END);
260
+ if (block.state === "ok")
261
+ previous = parseChangelog(block.body);
262
+ }
263
+ const body = renderAutoBody(summary, previous);
264
+ if (options.dryRun === true) {
265
+ deps.out(body.trimEnd());
266
+ if (decisions?.line !== undefined)
267
+ say(deps, decisions.line);
268
+ say(deps, `dry run, ${quiz.questions.length} quiz ${quiz.questions.length === 1 ? "question" : "questions"}, nothing written`);
269
+ return 0;
270
+ }
271
+ let added = 0;
272
+ let removed = 0;
273
+ for (const file of fresh) {
274
+ if (!file.binary) {
275
+ added += file.added;
276
+ removed += file.deleted;
277
+ }
278
+ }
279
+ const count = fresh.length + omitted;
280
+ say(deps, `${count} changed ${count === 1 ? "file" : "files"} since the last sync (+${added} -${removed})`);
281
+ // 8-9. Write PROJECT.md, then the state file.
282
+ const ops = { ...REAL_WRITE_OPS, ...deps.fs };
283
+ let writing = PROJECT_PATH;
284
+ try {
285
+ await updateProject(deps, root, project, body, ops);
286
+ writing = STATE_PATH;
287
+ await saveState(deps, root, ops, { read: { state, text: stateText, usable }, all, head, quiz, uncommitted, at, fingerprint, decisionLog: decisions?.next });
288
+ }
289
+ catch (error) {
290
+ say(deps, `could not write ${writing}: ${errorCode(error)}`);
291
+ return 1;
292
+ }
293
+ if (decisions?.line !== undefined)
294
+ say(deps, decisions.line);
295
+ return 0;
296
+ }
297
+ /** Writes the merged PROJECT.md, or prints why it was left alone. */
298
+ async function updateProject(deps, root, project, body, ops) {
299
+ if (project === undefined)
300
+ return say(deps, "PROJECT.md not found; run seance init");
301
+ if (project.type !== "file")
302
+ return say(deps, "PROJECT.md skipped (not a regular UTF-8 file under 1 MB)");
303
+ const merged = mergeAutoSections(project.content, body);
304
+ if (merged.status === "missing")
305
+ return say(deps, "PROJECT.md has no seance:auto section; run seance init");
306
+ if (merged.status === "malformed")
307
+ return say(deps, "PROJECT.md has a broken seance:auto section; fix the markers by hand");
308
+ if (!merged.changed)
309
+ return say(deps, "PROJECT.md unchanged");
310
+ const outcome = await writeAtomic(root, PROJECT_PATH, merged.text, project.content, ops);
311
+ say(deps, outcome === "written" ? "PROJECT.md updated" : "PROJECT.md skipped (changed during sync)");
312
+ }
313
+ /** Checks the new state against the schema and writes it; returns false when the file changed since it was read. */
314
+ async function writeState(root, read, next, ops) {
315
+ if (!SeanceStateSchema.safeParse(next).success)
316
+ throw Object.assign(new Error("new state is not valid"), { code: "INVALID_STATE" });
317
+ return (await writeAtomic(root, STATE_PATH, serializeState(next), read.text, ops)) === "written";
318
+ }
319
+ /** Writes only `.seance/state.json`, with `lastSync` set to the current commit and no files (req 3.6). */
320
+ async function recordBaseline(deps, root, read, head, decisionLog) {
321
+ const next = { ...read.state, lastSync: { at: deps.now().toISOString(), commit: head, files: {} } };
322
+ if (decisionLog !== undefined)
323
+ next.decisionLog = decisionLog;
324
+ try {
325
+ const written = await writeState(root, read, next, { ...REAL_WRITE_OPS, ...deps.fs });
326
+ say(deps, written ? "no changes yet; baseline recorded for the next sync" : `${STATE_PATH} skipped (changed during sync)`);
327
+ return 0;
328
+ }
329
+ catch (error) {
330
+ say(deps, `could not write ${STATE_PATH}: ${errorCode(error)}`);
331
+ return 1;
332
+ }
333
+ }
334
+ /** Writes `.seance/state.json` with the new last sync and, when there are questions, the new pending quiz. */
335
+ async function saveState(deps, root, ops, input) {
336
+ const { read, quiz } = input;
337
+ if (!read.usable) {
338
+ say(deps, `${STATE_PATH} is invalid; fix or delete it (quiz not saved)`);
339
+ if (quiz.questions.length === 0)
340
+ say(deps, "no JS or TS changes to quiz on");
341
+ return;
342
+ }
343
+ const next = { ...read.state, lastSync: { at: input.at, commit: input.head, files: buildSnapshot(input.all) } };
344
+ if (input.decisionLog !== undefined)
345
+ next.decisionLog = input.decisionLog;
346
+ if (quiz.questions.length > 0) {
347
+ const pending = {
348
+ id: `sync-${input.fingerprint.slice(8)}`,
349
+ createdAt: input.at,
350
+ commit: input.head,
351
+ uncommitted: input.uncommitted,
352
+ files: quiz.files,
353
+ questions: quiz.questions,
354
+ };
355
+ next.pendingQuiz = pending;
356
+ }
357
+ if (!(await writeState(root, read, next, ops))) {
358
+ say(deps, `${STATE_PATH} skipped (changed during sync)`);
359
+ }
360
+ else if (quiz.questions.length > 0) {
361
+ say(deps, `${quiz.questions.length} quiz ${quiz.questions.length === 1 ? "question" : "questions"} saved; run seance quiz`);
362
+ }
363
+ else {
364
+ say(deps, "no JS or TS changes to quiz on");
365
+ }
366
+ }
367
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA,+HAA+H;AAC/H,mIAAmI;AACnI,+EAA+E;AAC/E,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,QAAQ,EACR,UAAU,EACV,cAAc,EACd,eAAe,EACf,UAAU,EACV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,SAAS,EACT,2BAA2B,EAC3B,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,eAAe,EAAkC,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAkC,MAAM,eAAe,CAAC;AAahJ,MAAM,YAAY,GAAG,YAAY,CAAC;AAClC,MAAM,iBAAiB,GAAG,SAAS,C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QAAQ,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACxC,SAAS,EAAE,KAAK,CAAC,EAAE;YACnB,MAAM,EAAE,KAAK,CAAC,IAAI;YAClB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;IAC7B,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/C,GAAG,CAAC,IAAI,EAAE,GAAG,UAAU,gCAAgC,CAAC,CAAC;IAC3D,CAAC;SAAM,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,SAAS,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,yBAAyB,CAAC,CAAC;IAC9H,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,IAAI,EAAE,gCAAgC,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
package/dist/git.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export type GitResult = {
2
+ ok: true;
3
+ stdout: string;
4
+ } | {
5
+ ok: false;
6
+ reason: "not-found" | "failed" | "timeout" | "too-large";
7
+ };
8
+ /** Runs one git sub-command with its arguments (without the leading `-c core.fsmonitor=false`, the runner adds it). */
9
+ export type GitRunner = (args: readonly string[]) => Promise<GitResult>;
10
+ export interface GitRunnerOptions {
11
+ gitPath?: string;
12
+ prefixArgs?: string[];
13
+ env?: NodeJS.ProcessEnv;
14
+ platform?: NodeJS.Platform;
15
+ timeoutMs?: number;
16
+ }
17
+ export interface FindGitOptions {
18
+ env?: NodeJS.ProcessEnv;
19
+ platform?: NodeJS.Platform;
20
+ name?: string;
21
+ isProgram?: (fullPath: string) => Promise<boolean>;
22
+ }
23
+ /**
24
+ * Finds a program on PATH and returns its absolute path. Entries that are empty or not absolute are skipped on every platform,
25
+ * so a `.` entry can never make the target folder's own `git` run. On Windows only `<name>.exe` counts (a `.cmd` needs a shell).
26
+ */
27
+ export declare function findGit(options?: FindGitOptions): Promise<string | undefined>;
28
+ /**
29
+ * Makes a git runner for one folder. git is looked up once (on the first call) as an absolute path, because on Windows a bare
30
+ * `git` is also searched for in the working folder. `core.fsmonitor` is turned off because it can start a program from the
31
+ * repo's config, and `GIT_OPTIONAL_LOCKS=0` stops git from writing to the index while it only reads.
32
+ */
33
+ export declare function createGitRunner(cwd: string, options?: GitRunnerOptions): GitRunner;
package/dist/git.js ADDED
@@ -0,0 +1,103 @@
1
+ // Finds `git` and runs it for `seance sync`: an absolute program path, execFile with an argument array (never a shell),
2
+ // a timeout and an output cap. The runner never throws; it returns a result that says why a call failed.
3
+ import { execFile } from "node:child_process";
4
+ import { constants } from "node:fs";
5
+ import { access, stat } from "node:fs/promises";
6
+ import path from "node:path";
7
+ const DEFAULT_TIMEOUT_MS = 10_000;
8
+ const MAX_OUTPUT_BYTES = 1_048_576;
9
+ /** What went wrong, from the error `execFile` reports. */
10
+ function reasonOf(error) {
11
+ if (error.code === "ENOENT")
12
+ return "not-found";
13
+ if (error.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER")
14
+ return "too-large";
15
+ if (error.killed === true)
16
+ return "timeout";
17
+ return "failed";
18
+ }
19
+ /** True for a regular file; on POSIX it must also be executable. */
20
+ async function isRealProgram(fullPath, platform) {
21
+ try {
22
+ if (!(await stat(fullPath)).isFile())
23
+ return false;
24
+ if (platform !== "win32")
25
+ await access(fullPath, constants.X_OK);
26
+ return true;
27
+ }
28
+ catch {
29
+ return false;
30
+ }
31
+ }
32
+ /** The value of PATH; on Windows the key may be written `Path`. */
33
+ function pathValue(env, platform) {
34
+ if (platform !== "win32")
35
+ return env["PATH"] ?? "";
36
+ const key = Object.keys(env).find((name) => name.toUpperCase() === "PATH");
37
+ return key === undefined ? "" : (env[key] ?? "");
38
+ }
39
+ /**
40
+ * Finds a program on PATH and returns its absolute path. Entries that are empty or not absolute are skipped on every platform,
41
+ * so a `.` entry can never make the target folder's own `git` run. On Windows only `<name>.exe` counts (a `.cmd` needs a shell).
42
+ */
43
+ export async function findGit(options = {}) {
44
+ const platform = options.platform ?? process.platform;
45
+ const win = platform === "win32";
46
+ const flavour = win ? path.win32 : path.posix;
47
+ const fileName = `${options.name ?? "git"}${win ? ".exe" : ""}`;
48
+ const isProgram = options.isProgram ?? ((fullPath) => isRealProgram(fullPath, platform));
49
+ for (const rawEntry of pathValue(options.env ?? process.env, platform).split(flavour.delimiter)) {
50
+ const entry = win ? rawEntry.trim().replace(/^"(.*)"$/s, "$1") : rawEntry;
51
+ if (entry === "" || !flavour.isAbsolute(entry))
52
+ continue;
53
+ const candidate = flavour.join(entry, fileName);
54
+ if (await isProgram(candidate))
55
+ return candidate;
56
+ }
57
+ return undefined;
58
+ }
59
+ /** The program to run: an absolute `gitPath` as given, a relative one or the default looked up on PATH. */
60
+ function resolveProgram(options) {
61
+ const platform = options.platform ?? process.platform;
62
+ const given = options.gitPath;
63
+ if (given !== undefined && (path.win32.isAbsolute(given) || path.posix.isAbsolute(given)))
64
+ return Promise.resolve(given);
65
+ return findGit({ env: { ...process.env, ...options.env }, platform, ...(given === undefined ? {} : { name: given }) });
66
+ }
67
+ /**
68
+ * Makes a git runner for one folder. git is looked up once (on the first call) as an absolute path, because on Windows a bare
69
+ * `git` is also searched for in the working folder. `core.fsmonitor` is turned off because it can start a program from the
70
+ * repo's config, and `GIT_OPTIONAL_LOCKS=0` stops git from writing to the index while it only reads.
71
+ */
72
+ export function createGitRunner(cwd, options = {}) {
73
+ const prefix = options.prefixArgs ?? [];
74
+ const timeout = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
75
+ let program;
76
+ return async (args) => {
77
+ program ??= resolveProgram(options);
78
+ const gitPath = await program;
79
+ if (gitPath === undefined)
80
+ return { ok: false, reason: "not-found" };
81
+ return new Promise((resolve) => {
82
+ try {
83
+ execFile(gitPath, [...prefix, "-c", "core.fsmonitor=false", ...args], {
84
+ cwd,
85
+ timeout,
86
+ maxBuffer: MAX_OUTPUT_BYTES,
87
+ windowsHide: true,
88
+ encoding: "utf8",
89
+ env: { ...process.env, ...options.env, GIT_OPTIONAL_LOCKS: "0" },
90
+ }, (error, stdout) => {
91
+ if (error === null)
92
+ resolve({ ok: true, stdout });
93
+ else
94
+ resolve({ ok: false, reason: reasonOf(error) });
95
+ });
96
+ }
97
+ catch {
98
+ resolve({ ok: false, reason: "failed" }); // execFile throws for a bad argument such as a NUL in a path
99
+ }
100
+ });
101
+ };
102
+ }
103
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,yGAAyG;AACzG,OAAO,EAAE,QAAQ,EAA0B,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,IAAI,MAAM,WAAW,CAAC;AAiB7B,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACnC,0DAA0D;AAC1D,SAAS,QAAQ,CAAC,KAAwB;IACxC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,WAAW,CAAC;IAChD,IAAI,KAAK,CAAC,IAAI,KAAK,mCAAmC;QAAE,OAAO,WAAW,CAAC;IAC3E,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5C,OAAO,QAAQ,CAAC;AA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M,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACvD,CAAC,CACF,CAAC;YACJ,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,6DAA6D;YACzG,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,24 @@
1
+ /** The deployed API address (the live Seance site, an origin with no path). `SEANCE_API_URL` in the shell overrides it. */
2
+ export declare const DEFAULT_API_URL = "https://seance-kiroween.netlify.app";
3
+ export declare const HOSTED_CLIENT_TIMEOUT_MS = 30000;
4
+ /**
5
+ * The API address to try: `SEANCE_API_URL` from the shell (an empty value turns the hosted API off), else `defaultApiUrl`, else `DEFAULT_API_URL`.
6
+ * `defaultApiUrl: null` means no default; tests use it so they never depend on the real URL.
7
+ */
8
+ export declare function apiUrlSetting(env: Readonly<Record<string, string | undefined>>, defaultApiUrl?: string | null): string | undefined;
9
+ export type HostedReply = {
10
+ ok: true;
11
+ json: unknown;
12
+ } | {
13
+ ok: false;
14
+ reason: "timeout" | "network" | "rate limited" | "invalid reply" | `HTTP ${number}`;
15
+ };
16
+ export interface HostedApi {
17
+ /** The host (with port) shown to the user, for example `seance.netlify.app`. */
18
+ host: string;
19
+ post(path: "/api/quiz" | "/api/grade", body: unknown): Promise<HostedReply>;
20
+ }
21
+ export declare function createHostedApi(url: URL, deps?: {
22
+ fetch?: typeof fetch;
23
+ timeoutMs?: number;
24
+ }): HostedApi;
@@ -0,0 +1,85 @@
1
+ // The CLI's HTTP client for the Seance hosted API (Task 8). One POST with a timeout, no redirects and a cap on the reply size.
2
+ // It never throws: every failure becomes a `reason` the caller prints. Tests pass a fake `fetch`.
3
+ import { API_LIMITS } from "@seance/core";
4
+ /** The deployed API address (the live Seance site, an origin with no path). `SEANCE_API_URL` in the shell overrides it. */
5
+ export const DEFAULT_API_URL = "https://seance-kiroween.netlify.app";
6
+ export const HOSTED_CLIENT_TIMEOUT_MS = 30_000;
7
+ /**
8
+ * The API address to try: `SEANCE_API_URL` from the shell (an empty value turns the hosted API off), else `defaultApiUrl`, else `DEFAULT_API_URL`.
9
+ * `defaultApiUrl: null` means no default; tests use it so they never depend on the real URL.
10
+ */
11
+ export function apiUrlSetting(env, defaultApiUrl) {
12
+ if (env.SEANCE_API_URL !== undefined)
13
+ return env.SEANCE_API_URL;
14
+ return defaultApiUrl === undefined ? DEFAULT_API_URL : (defaultApiUrl ?? undefined);
15
+ }
16
+ /** An abort or a timeout of `AbortSignal.timeout` (the name depends on where it was thrown). */
17
+ function isTimeout(error) {
18
+ return typeof error === "object" && error !== null && ["TimeoutError", "AbortError"].includes(error.name);
19
+ }
20
+ /** Reads at most `maxBytes` of the reply body as UTF-8 text; returns undefined when the body is bigger or not text. */
21
+ async function readCapped(response, maxBytes) {
22
+ if (response.body === null)
23
+ return "";
24
+ const reader = response.body.getReader();
25
+ const chunks = [];
26
+ let total = 0;
27
+ for (;;) {
28
+ const { done, value } = await reader.read();
29
+ if (done)
30
+ break;
31
+ total += value.byteLength;
32
+ if (total > maxBytes) {
33
+ await reader.cancel().catch(() => undefined);
34
+ return undefined;
35
+ }
36
+ chunks.push(value);
37
+ }
38
+ const bytes = new Uint8Array(total);
39
+ let offset = 0;
40
+ for (const chunk of chunks) {
41
+ bytes.set(chunk, offset);
42
+ offset += chunk.byteLength;
43
+ }
44
+ try {
45
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
46
+ }
47
+ catch {
48
+ return undefined;
49
+ }
50
+ }
51
+ export function createHostedApi(url, deps = {}) {
52
+ const doFetch = deps.fetch ?? fetch;
53
+ const timeoutMs = deps.timeoutMs ?? HOSTED_CLIENT_TIMEOUT_MS;
54
+ return {
55
+ host: url.host,
56
+ async post(path, body) {
57
+ try {
58
+ const response = await doFetch(new URL(path, url), {
59
+ method: "POST",
60
+ headers: { "content-type": "application/json" },
61
+ body: JSON.stringify(body),
62
+ redirect: "error", // a redirect could send the code to another server
63
+ signal: AbortSignal.timeout(timeoutMs),
64
+ });
65
+ if (response.status !== 200) {
66
+ await response.body?.cancel().catch(() => undefined);
67
+ return { ok: false, reason: response.status === 429 ? "rate limited" : `HTTP ${response.status}` };
68
+ }
69
+ const text = await readCapped(response, API_LIMITS.maxResponseBytes);
70
+ if (text === undefined)
71
+ return { ok: false, reason: "invalid reply" };
72
+ try {
73
+ return { ok: true, json: JSON.parse(text) };
74
+ }
75
+ catch {
76
+ return { ok: false, reason: "invalid reply" };
77
+ }
78
+ }
79
+ catch (error) {
80
+ return { ok: false, reason: isTimeout(error) ? "timeout" : "network" };
81
+ }
82
+ },
83
+ };
84
+ }
85
+ //# sourceMappingURL=hosted-api.js.map