recess-cli 3.50.2 → 3.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +13 -9
- package/dist/auth.js +3 -0
- package/dist/cli.js +484 -37
- package/dist/command-schema.js +17 -1
- package/dist/commands/admissions.js +1 -1
- package/dist/commands/apps.js +2 -1
- package/dist/commands/changelog.js +1 -1
- package/dist/commands/channels.js +1 -1
- package/dist/commands/db.js +1 -1
- package/dist/commands/onboarding.js +1 -1
- package/dist/commands/reading-checks.js +1 -1
- package/dist/commands/reports.js +1 -1
- package/dist/commands/safe-staff-operations.js +1 -1
- package/dist/commands/school.js +1 -1
- package/dist/commands/shared.js +1 -1
- package/dist/commands/tuition-plans.js +2 -1
- package/dist/config.js +1 -1
- package/dist/delivery.js +1 -1
- package/dist/feedback.js +1 -1
- package/dist/help.js +26 -1
- package/dist/in-app.js +511 -0
- package/dist/jobs.js +1 -1
- package/dist/setup.js +1 -1
- package/dist/skill-update.js +1 -1
- package/dist/skills-cache.js +1 -1
- package/dist/update-notice.js +2 -1
- package/package.json +1 -1
package/dist/in-app.js
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
3
|
+
import nodeFs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { CliError } from "./errors.js";
|
|
6
|
+
const context = new AsyncLocalStorage();
|
|
7
|
+
/** Inline input files of one command, all together. */
|
|
8
|
+
export const IN_APP_FILES_MAX_BYTES = 2 * 1024 * 1024;
|
|
9
|
+
/** What one command may write to the store. */
|
|
10
|
+
const IN_APP_COMMIT_MAX_BYTES = 64 * 1024 * 1024;
|
|
11
|
+
/** `.git` cannot be a path inside the store's own repository. */
|
|
12
|
+
const GIT_DIR = ".git";
|
|
13
|
+
const STORED_GIT_DIR = ".recess-checkout";
|
|
14
|
+
export async function runInApp(run, input = {}) {
|
|
15
|
+
const state = {
|
|
16
|
+
root: process.cwd(),
|
|
17
|
+
store: input.store,
|
|
18
|
+
files: new Map(),
|
|
19
|
+
dirs: new Set(),
|
|
20
|
+
dirty: new Set(),
|
|
21
|
+
};
|
|
22
|
+
let total = 0;
|
|
23
|
+
for (const [name, text] of Object.entries(input.files ?? {})) {
|
|
24
|
+
if (!name ||
|
|
25
|
+
path.isAbsolute(name) ||
|
|
26
|
+
name.split(/[\\/]/).includes("..") ||
|
|
27
|
+
typeof text !== "string") {
|
|
28
|
+
throw new CliError("invalid_arguments", `Input file names are plain relative names such as patch.json; got ${JSON.stringify(name)}.`);
|
|
29
|
+
}
|
|
30
|
+
const bytes = Buffer.from(text, "utf8");
|
|
31
|
+
total += bytes.byteLength;
|
|
32
|
+
const stored = storedPath(state, name);
|
|
33
|
+
state.files.set(stored, bytes);
|
|
34
|
+
// With a store the file stays for the confirm; without one it lives only
|
|
35
|
+
// for this command.
|
|
36
|
+
if (state.store)
|
|
37
|
+
state.dirty.add(stored);
|
|
38
|
+
}
|
|
39
|
+
if (total > IN_APP_FILES_MAX_BYTES) {
|
|
40
|
+
throw new CliError("invalid_arguments", "The input files are too large for the Recess app chat (2 MB in total).");
|
|
41
|
+
}
|
|
42
|
+
return context.run(state, async () => {
|
|
43
|
+
let result;
|
|
44
|
+
try {
|
|
45
|
+
result = await run();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
// The command's own failure is the one to report.
|
|
49
|
+
await flush(state).catch(() => undefined);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
await flush(state);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new CliError("files_not_saved", `The command finished, but its files could not be saved to this chat's files folder: ${error instanceof Error ? error.message : String(error)}`);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export function isInApp() {
|
|
62
|
+
return context.getStore() !== undefined;
|
|
63
|
+
}
|
|
64
|
+
/** This in-app command's own state, or undefined everywhere else. */
|
|
65
|
+
export function inAppState() {
|
|
66
|
+
return context.getStore();
|
|
67
|
+
}
|
|
68
|
+
/** Refuse anything that needs the caller's own computer. */
|
|
69
|
+
export function assertLocalMachine() {
|
|
70
|
+
if (!isInApp())
|
|
71
|
+
return;
|
|
72
|
+
throw unavailable();
|
|
73
|
+
}
|
|
74
|
+
function unavailable() {
|
|
75
|
+
return new CliError("files_unavailable", "This needs a program or a place on a computer that the Recess app chat does not have. Run it with the Recess CLI on a computer.");
|
|
76
|
+
}
|
|
77
|
+
function fsError(code, target) {
|
|
78
|
+
const error = new Error(`${code}: ${typeof target === "string" ? path.basename(target) : "path"}`);
|
|
79
|
+
error.code = code;
|
|
80
|
+
return error;
|
|
81
|
+
}
|
|
82
|
+
/** The store path for a file-system path, or null when outside the root. */
|
|
83
|
+
function storedPath(state, target) {
|
|
84
|
+
if (typeof target !== "string")
|
|
85
|
+
return null;
|
|
86
|
+
const relative = path.relative(state.root, path.resolve(state.root, target));
|
|
87
|
+
if (relative.startsWith("..") || path.isAbsolute(relative))
|
|
88
|
+
return null;
|
|
89
|
+
return relative
|
|
90
|
+
.split(path.sep)
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.map((segment) => (segment === GIT_DIR ? STORED_GIT_DIR : segment))
|
|
93
|
+
.join("/");
|
|
94
|
+
}
|
|
95
|
+
function index(state) {
|
|
96
|
+
state.index ??= (async () => new Set(state.store ? await state.store.list() : []))();
|
|
97
|
+
return state.index;
|
|
98
|
+
}
|
|
99
|
+
/** Every live file path: the store's, plus this command's, minus deletions. */
|
|
100
|
+
async function livePaths(state) {
|
|
101
|
+
const paths = new Set(await index(state));
|
|
102
|
+
for (const [file, bytes] of state.files) {
|
|
103
|
+
if (bytes)
|
|
104
|
+
paths.add(file);
|
|
105
|
+
else
|
|
106
|
+
paths.delete(file);
|
|
107
|
+
}
|
|
108
|
+
return Array.from(paths);
|
|
109
|
+
}
|
|
110
|
+
async function fileBytes(state, stored) {
|
|
111
|
+
if (stored === null)
|
|
112
|
+
return null;
|
|
113
|
+
const seen = state.files.get(stored);
|
|
114
|
+
if (seen !== undefined)
|
|
115
|
+
return seen;
|
|
116
|
+
if (!state.store || !(await index(state)).has(stored))
|
|
117
|
+
return null;
|
|
118
|
+
const bytes = await state.store.read(stored);
|
|
119
|
+
const buffer = bytes ? Buffer.from(bytes) : null;
|
|
120
|
+
state.files.set(stored, buffer);
|
|
121
|
+
return buffer;
|
|
122
|
+
}
|
|
123
|
+
async function isDirectory(state, stored) {
|
|
124
|
+
if (stored === null)
|
|
125
|
+
return false;
|
|
126
|
+
if (stored === "" || state.dirs.has(stored))
|
|
127
|
+
return true;
|
|
128
|
+
const prefix = `${stored}/`;
|
|
129
|
+
return (await livePaths(state)).some((file) => file.startsWith(prefix));
|
|
130
|
+
}
|
|
131
|
+
function requireStore(state, stored) {
|
|
132
|
+
if (!state.store || stored === null)
|
|
133
|
+
throw unavailable();
|
|
134
|
+
return stored;
|
|
135
|
+
}
|
|
136
|
+
function put(state, stored, bytes) {
|
|
137
|
+
state.files.set(stored, bytes);
|
|
138
|
+
state.dirty.add(stored);
|
|
139
|
+
}
|
|
140
|
+
function addDirectory(state, stored) {
|
|
141
|
+
const segments = stored.split("/").filter(Boolean);
|
|
142
|
+
for (let depth = 1; depth <= segments.length; depth += 1) {
|
|
143
|
+
state.dirs.add(segments.slice(0, depth).join("/"));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function stats(bytes) {
|
|
147
|
+
return {
|
|
148
|
+
size: bytes?.byteLength ?? 0,
|
|
149
|
+
mode: bytes ? 0o600 : 0o700,
|
|
150
|
+
mtimeMs: 0,
|
|
151
|
+
isFile: () => bytes !== null,
|
|
152
|
+
isDirectory: () => bytes === null,
|
|
153
|
+
isSymbolicLink: () => false,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async function statOf(state, target) {
|
|
157
|
+
const stored = storedPath(state, target);
|
|
158
|
+
const bytes = await fileBytes(state, stored);
|
|
159
|
+
if (bytes)
|
|
160
|
+
return stats(bytes);
|
|
161
|
+
if (await isDirectory(state, stored))
|
|
162
|
+
return stats(null);
|
|
163
|
+
throw fsError("ENOENT", target);
|
|
164
|
+
}
|
|
165
|
+
/** Files and folders directly under `stored`, by name. */
|
|
166
|
+
async function children(state, stored) {
|
|
167
|
+
const prefix = stored ? `${stored}/` : "";
|
|
168
|
+
const found = new Map();
|
|
169
|
+
for (const file of await livePaths(state)) {
|
|
170
|
+
if (!file.startsWith(prefix))
|
|
171
|
+
continue;
|
|
172
|
+
const [name, ...rest] = file.slice(prefix.length).split("/");
|
|
173
|
+
if (name)
|
|
174
|
+
found.set(name, rest.length > 0 ? "dir" : "file");
|
|
175
|
+
}
|
|
176
|
+
for (const dir of state.dirs) {
|
|
177
|
+
if (!dir.startsWith(prefix) || dir === stored)
|
|
178
|
+
continue;
|
|
179
|
+
const name = dir.slice(prefix.length).split("/")[0];
|
|
180
|
+
if (name && !found.has(name))
|
|
181
|
+
found.set(name, "dir");
|
|
182
|
+
}
|
|
183
|
+
return found;
|
|
184
|
+
}
|
|
185
|
+
async function moveTree(state, from, to, keepSource) {
|
|
186
|
+
const bytes = await fileBytes(state, from);
|
|
187
|
+
if (bytes) {
|
|
188
|
+
put(state, to, bytes);
|
|
189
|
+
if (!keepSource)
|
|
190
|
+
put(state, from, null);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const prefix = `${from}/`;
|
|
194
|
+
for (const file of await livePaths(state)) {
|
|
195
|
+
if (!file.startsWith(prefix))
|
|
196
|
+
continue;
|
|
197
|
+
const content = await fileBytes(state, file);
|
|
198
|
+
if (!content)
|
|
199
|
+
continue;
|
|
200
|
+
put(state, `${to}/${file.slice(prefix.length)}`, content);
|
|
201
|
+
if (!keepSource)
|
|
202
|
+
put(state, file, null);
|
|
203
|
+
}
|
|
204
|
+
for (const dir of Array.from(state.dirs)) {
|
|
205
|
+
if (dir !== from && !dir.startsWith(prefix))
|
|
206
|
+
continue;
|
|
207
|
+
addDirectory(state, `${to}${dir.slice(from.length)}`);
|
|
208
|
+
if (!keepSource)
|
|
209
|
+
state.dirs.delete(dir);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function encodingOf(options) {
|
|
213
|
+
const encoding = typeof options === "string"
|
|
214
|
+
? options
|
|
215
|
+
: options?.encoding;
|
|
216
|
+
return (encoding ?? undefined);
|
|
217
|
+
}
|
|
218
|
+
function toBuffer(data, options) {
|
|
219
|
+
if (typeof data === "string") {
|
|
220
|
+
return Buffer.from(data, encodingOf(options) ?? "utf8");
|
|
221
|
+
}
|
|
222
|
+
if (data instanceof Uint8Array)
|
|
223
|
+
return Buffer.from(data);
|
|
224
|
+
throw unavailable();
|
|
225
|
+
}
|
|
226
|
+
const OPS = {
|
|
227
|
+
async readFile(state, [target, options]) {
|
|
228
|
+
const stored = storedPath(state, target);
|
|
229
|
+
const bytes = await fileBytes(state, stored);
|
|
230
|
+
if (!bytes) {
|
|
231
|
+
throw fsError((await isDirectory(state, stored)) ? "EISDIR" : "ENOENT", target);
|
|
232
|
+
}
|
|
233
|
+
const encoding = encodingOf(options);
|
|
234
|
+
return encoding ? bytes.toString(encoding) : bytes;
|
|
235
|
+
},
|
|
236
|
+
async writeFile(state, [target, data, options]) {
|
|
237
|
+
const stored = requireStore(state, storedPath(state, target));
|
|
238
|
+
if (options?.flag === "wx" &&
|
|
239
|
+
(await fileBytes(state, stored))) {
|
|
240
|
+
throw fsError("EEXIST", target);
|
|
241
|
+
}
|
|
242
|
+
put(state, stored, toBuffer(data, options));
|
|
243
|
+
},
|
|
244
|
+
async appendFile(state, [target, data, options]) {
|
|
245
|
+
const stored = requireStore(state, storedPath(state, target));
|
|
246
|
+
const before = (await fileBytes(state, stored)) ?? Buffer.alloc(0);
|
|
247
|
+
put(state, stored, Buffer.concat([before, toBuffer(data, options)]));
|
|
248
|
+
},
|
|
249
|
+
async mkdir(state, [target]) {
|
|
250
|
+
addDirectory(state, requireStore(state, storedPath(state, target)));
|
|
251
|
+
return undefined;
|
|
252
|
+
},
|
|
253
|
+
async mkdtemp(state, [prefix]) {
|
|
254
|
+
const directory = `${String(prefix)}${randomBytes(4).toString("hex")}`;
|
|
255
|
+
addDirectory(state, requireStore(state, storedPath(state, directory)));
|
|
256
|
+
return directory;
|
|
257
|
+
},
|
|
258
|
+
async readdir(state, [target, options]) {
|
|
259
|
+
const stored = storedPath(state, target);
|
|
260
|
+
if (stored === null || !(await isDirectory(state, stored))) {
|
|
261
|
+
throw fsError("ENOENT", target);
|
|
262
|
+
}
|
|
263
|
+
const entries = Array.from(await children(state, stored)).sort(([left], [right]) => left.localeCompare(right));
|
|
264
|
+
if (!options?.withFileTypes) {
|
|
265
|
+
return entries.map(([name]) => name);
|
|
266
|
+
}
|
|
267
|
+
return entries.map(([name, kind]) => ({
|
|
268
|
+
name,
|
|
269
|
+
isFile: () => kind === "file",
|
|
270
|
+
isDirectory: () => kind === "dir",
|
|
271
|
+
isSymbolicLink: () => false,
|
|
272
|
+
}));
|
|
273
|
+
},
|
|
274
|
+
stat: (state, [target]) => statOf(state, target),
|
|
275
|
+
lstat: (state, [target]) => statOf(state, target),
|
|
276
|
+
async realpath(state, [target]) {
|
|
277
|
+
await statOf(state, target);
|
|
278
|
+
return path.resolve(state.root, target);
|
|
279
|
+
},
|
|
280
|
+
async access(state, [target]) {
|
|
281
|
+
await statOf(state, target);
|
|
282
|
+
},
|
|
283
|
+
async chmod(state, [target]) {
|
|
284
|
+
await statOf(state, target);
|
|
285
|
+
},
|
|
286
|
+
async rm(state, [target, options]) {
|
|
287
|
+
const stored = storedPath(state, target);
|
|
288
|
+
const settings = (options ?? {});
|
|
289
|
+
if (stored !== null && (await fileBytes(state, stored))) {
|
|
290
|
+
put(state, requireStore(state, stored), null);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (stored !== null && (await isDirectory(state, stored))) {
|
|
294
|
+
requireStore(state, stored);
|
|
295
|
+
const prefix = `${stored}/`;
|
|
296
|
+
for (const file of await livePaths(state)) {
|
|
297
|
+
if (file.startsWith(prefix))
|
|
298
|
+
put(state, file, null);
|
|
299
|
+
}
|
|
300
|
+
for (const dir of Array.from(state.dirs)) {
|
|
301
|
+
if (dir === stored || dir.startsWith(prefix))
|
|
302
|
+
state.dirs.delete(dir);
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (!settings.force)
|
|
307
|
+
throw fsError("ENOENT", target);
|
|
308
|
+
},
|
|
309
|
+
async rename(state, [from, to]) {
|
|
310
|
+
await statOf(state, from);
|
|
311
|
+
await moveTree(state, requireStore(state, storedPath(state, from)), requireStore(state, storedPath(state, to)), false);
|
|
312
|
+
},
|
|
313
|
+
async cp(state, [from, to]) {
|
|
314
|
+
await statOf(state, from);
|
|
315
|
+
await moveTree(state, requireStore(state, storedPath(state, from)), requireStore(state, storedPath(state, to)), true);
|
|
316
|
+
},
|
|
317
|
+
async open(state, [target, flags]) {
|
|
318
|
+
if (flags !== undefined && flags !== "r")
|
|
319
|
+
throw unavailable();
|
|
320
|
+
const bytes = await fileBytes(state, storedPath(state, target));
|
|
321
|
+
if (!bytes)
|
|
322
|
+
throw fsError("ENOENT", target);
|
|
323
|
+
return {
|
|
324
|
+
async read(buffer, offset, length, position) {
|
|
325
|
+
const bytesRead = bytes.copy(buffer, offset, position, Math.min(bytes.byteLength, position + length));
|
|
326
|
+
return { bytesRead, buffer };
|
|
327
|
+
},
|
|
328
|
+
stat: async () => stats(bytes),
|
|
329
|
+
readFile: async (options) => {
|
|
330
|
+
const encoding = encodingOf(options);
|
|
331
|
+
return encoding ? bytes.toString(encoding) : bytes;
|
|
332
|
+
},
|
|
333
|
+
close: async () => undefined,
|
|
334
|
+
};
|
|
335
|
+
},
|
|
336
|
+
};
|
|
337
|
+
OPS.unlink = (state, [target]) => OPS.rm(state, [target]);
|
|
338
|
+
async function flush(state) {
|
|
339
|
+
if (!state.store || state.dirty.size === 0)
|
|
340
|
+
return;
|
|
341
|
+
const stored = await index(state);
|
|
342
|
+
const changes = [];
|
|
343
|
+
let total = 0;
|
|
344
|
+
for (const file of state.dirty) {
|
|
345
|
+
const content = state.files.get(file) ?? null;
|
|
346
|
+
// Deleting what the store never held is nothing to write.
|
|
347
|
+
if (!content && !stored.has(file))
|
|
348
|
+
continue;
|
|
349
|
+
total += content?.byteLength ?? 0;
|
|
350
|
+
changes.push({ path: file, content });
|
|
351
|
+
}
|
|
352
|
+
if (changes.length === 0)
|
|
353
|
+
return;
|
|
354
|
+
if (total > IN_APP_COMMIT_MAX_BYTES) {
|
|
355
|
+
throw new CliError("files_too_large", "This command's files are too large for the Recess app chat (64 MB). Run it with the Recess CLI on a computer.");
|
|
356
|
+
}
|
|
357
|
+
await state.store.commit(changes);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* `node:fs/promises` everywhere but in-app, where every call answers from the
|
|
361
|
+
* command's virtual files and anything else is refused.
|
|
362
|
+
*/
|
|
363
|
+
export const fs = new Proxy(nodeFs, {
|
|
364
|
+
get(target, property, receiver) {
|
|
365
|
+
const value = Reflect.get(target, property, receiver);
|
|
366
|
+
if (typeof value !== "function")
|
|
367
|
+
return value;
|
|
368
|
+
return (...args) => {
|
|
369
|
+
const state = context.getStore();
|
|
370
|
+
if (!state) {
|
|
371
|
+
return value.apply(target, args);
|
|
372
|
+
}
|
|
373
|
+
const operation = typeof property === "string" ? OPS[property] : undefined;
|
|
374
|
+
// Async like the real one, so `.catch()` chains still see the failure.
|
|
375
|
+
return (async () => {
|
|
376
|
+
if (!operation)
|
|
377
|
+
throw unavailable();
|
|
378
|
+
return operation(state, args);
|
|
379
|
+
})();
|
|
380
|
+
};
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
const LEDGER = `${GIT_DIR}/recess-in-app.json`;
|
|
384
|
+
async function readLedger(cwd) {
|
|
385
|
+
const raw = await fs
|
|
386
|
+
.readFile(path.join(cwd, LEDGER), "utf8")
|
|
387
|
+
.catch(() => null);
|
|
388
|
+
return raw ? JSON.parse(raw) : null;
|
|
389
|
+
}
|
|
390
|
+
async function workingTree(state, cwd) {
|
|
391
|
+
const root = storedPath(state, cwd);
|
|
392
|
+
if (root === null)
|
|
393
|
+
throw unavailable();
|
|
394
|
+
const prefix = root ? `${root}/` : "";
|
|
395
|
+
const tree = {};
|
|
396
|
+
for (const file of (await livePaths(state)).sort()) {
|
|
397
|
+
if (!file.startsWith(prefix))
|
|
398
|
+
continue;
|
|
399
|
+
const relative = file.slice(prefix.length);
|
|
400
|
+
if (relative.startsWith(`${STORED_GIT_DIR}/`))
|
|
401
|
+
continue;
|
|
402
|
+
const bytes = await fileBytes(state, file);
|
|
403
|
+
if (bytes) {
|
|
404
|
+
tree[relative] = createHash("sha256").update(bytes).digest("hex");
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return tree;
|
|
408
|
+
}
|
|
409
|
+
function sameTree(left, right) {
|
|
410
|
+
const names = Object.keys(left);
|
|
411
|
+
return (names.length === Object.keys(right).length &&
|
|
412
|
+
names.every((name) => left[name] === right[name]));
|
|
413
|
+
}
|
|
414
|
+
async function commitTree(state, cwd, ledger, subject) {
|
|
415
|
+
const commit = {
|
|
416
|
+
parent: ledger.head,
|
|
417
|
+
subject,
|
|
418
|
+
tree: await workingTree(state, cwd),
|
|
419
|
+
};
|
|
420
|
+
const id = createHash("sha1").update(JSON.stringify(commit)).digest("hex");
|
|
421
|
+
ledger.commits[id] = commit;
|
|
422
|
+
ledger.head = id;
|
|
423
|
+
await fs.writeFile(path.join(cwd, LEDGER), JSON.stringify(ledger), "utf8");
|
|
424
|
+
return id;
|
|
425
|
+
}
|
|
426
|
+
/** `base..head`, oldest first; throws when `base` is not an ancestor. */
|
|
427
|
+
function commitsAfter(ledger, base, head) {
|
|
428
|
+
const chain = [];
|
|
429
|
+
for (let id = head; id && id !== base; id = ledger.commits[id]?.parent ?? null) {
|
|
430
|
+
if (!ledger.commits[id])
|
|
431
|
+
break;
|
|
432
|
+
chain.unshift(id);
|
|
433
|
+
}
|
|
434
|
+
const oldest = chain[0] ? ledger.commits[chain[0]] : undefined;
|
|
435
|
+
if (head !== base && oldest?.parent !== base) {
|
|
436
|
+
throw new CliError("git_failed", "This checkout does not continue from the workspace it was checked out of. Check it out again.");
|
|
437
|
+
}
|
|
438
|
+
return chain;
|
|
439
|
+
}
|
|
440
|
+
/** The git commands the workspace flows run, answered from the ledger. */
|
|
441
|
+
export async function inAppGit(cwd, args) {
|
|
442
|
+
const state = context.getStore();
|
|
443
|
+
if (!state)
|
|
444
|
+
throw unavailable();
|
|
445
|
+
const [command, ...rest] = args;
|
|
446
|
+
if (command === "config")
|
|
447
|
+
return rest[0] === "--get" ? "Recess CLI\n" : "";
|
|
448
|
+
if (command === "add")
|
|
449
|
+
return "";
|
|
450
|
+
if (command === "init") {
|
|
451
|
+
await fs.mkdir(path.join(cwd, GIT_DIR), { recursive: true });
|
|
452
|
+
await fs.writeFile(path.join(cwd, LEDGER), JSON.stringify({ head: null, commits: {} }), "utf8");
|
|
453
|
+
return "";
|
|
454
|
+
}
|
|
455
|
+
const ledger = await readLedger(cwd);
|
|
456
|
+
if (!ledger) {
|
|
457
|
+
throw new CliError("invalid_checkout", "That folder is not a Recess checkout. Check the workspace out first.");
|
|
458
|
+
}
|
|
459
|
+
if (command === "rev-parse" && rest[0] === "--show-toplevel") {
|
|
460
|
+
return `${path.resolve(cwd)}\n`;
|
|
461
|
+
}
|
|
462
|
+
// Nothing is ever "uncommitted": edits fold into HEAD when it is asked for.
|
|
463
|
+
if (command === "status")
|
|
464
|
+
return "";
|
|
465
|
+
if (command === "ls-files") {
|
|
466
|
+
return Object.keys(await workingTree(state, cwd))
|
|
467
|
+
.map((file) => `${file}\0`)
|
|
468
|
+
.join("");
|
|
469
|
+
}
|
|
470
|
+
if (command === "commit") {
|
|
471
|
+
const subject = rest[rest.indexOf("-m") + 1] ?? "Update workspace";
|
|
472
|
+
await commitTree(state, cwd, ledger, subject);
|
|
473
|
+
return "";
|
|
474
|
+
}
|
|
475
|
+
if (command === "rev-parse" && rest[0] === "HEAD") {
|
|
476
|
+
const head = ledger.head ? ledger.commits[ledger.head] : undefined;
|
|
477
|
+
if (!head || !sameTree(head.tree, await workingTree(state, cwd))) {
|
|
478
|
+
return `${await commitTree(state, cwd, ledger, "Edit workspace files")}\n`;
|
|
479
|
+
}
|
|
480
|
+
return `${ledger.head}\n`;
|
|
481
|
+
}
|
|
482
|
+
const range = rest.at(-1)?.split("..") ?? [];
|
|
483
|
+
if (command === "merge-base" && rest[0] === "--is-ancestor") {
|
|
484
|
+
commitsAfter(ledger, rest[1], rest[2]);
|
|
485
|
+
return "";
|
|
486
|
+
}
|
|
487
|
+
if (command === "log" && range.length === 2) {
|
|
488
|
+
return commitsAfter(ledger, range[0], range[1])
|
|
489
|
+
.map((id) => `${id}\t${ledger.commits[id].subject}\n`)
|
|
490
|
+
.join("");
|
|
491
|
+
}
|
|
492
|
+
if (command === "diff" && range.length === 2) {
|
|
493
|
+
const before = ledger.commits[range[0]]?.tree;
|
|
494
|
+
const after = ledger.commits[range[1]]?.tree;
|
|
495
|
+
if (!before || !after) {
|
|
496
|
+
throw new CliError("git_failed", "This checkout has lost its history.");
|
|
497
|
+
}
|
|
498
|
+
const fields = [];
|
|
499
|
+
for (const file of new Set([
|
|
500
|
+
...Object.keys(before),
|
|
501
|
+
...Object.keys(after),
|
|
502
|
+
])) {
|
|
503
|
+
if (before[file] === after[file])
|
|
504
|
+
continue;
|
|
505
|
+
fields.push(!before[file] ? "A" : !after[file] ? "D" : "M", file);
|
|
506
|
+
}
|
|
507
|
+
return fields.map((field) => `${field}\0`).join("");
|
|
508
|
+
}
|
|
509
|
+
throw unavailable();
|
|
510
|
+
}
|
|
511
|
+
//# sourceMappingURL=in-app.js.map
|
package/dist/jobs.js
CHANGED
package/dist/setup.js
CHANGED
package/dist/skill-update.js
CHANGED
package/dist/skills-cache.js
CHANGED
package/dist/update-notice.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import fs from "
|
|
2
|
+
import { assertLocalMachine, fs } from "./in-app.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { defaultConfigPath } from "./config.js";
|
|
5
5
|
import { CliError } from "./errors.js";
|
|
@@ -66,6 +66,7 @@ export async function printUpdateNotice(cliVersion, write = (text) => process.st
|
|
|
66
66
|
write(`\n${text}\n`);
|
|
67
67
|
}
|
|
68
68
|
export async function runSelfUpdate() {
|
|
69
|
+
assertLocalMachine();
|
|
69
70
|
const [bin, ...args] = UPGRADE_COMMAND.split(" ");
|
|
70
71
|
const exitCode = await new Promise((resolve, reject) => {
|
|
71
72
|
const child = spawn(bin, args, {
|