mirror of
https://github.com/nightly-labs/openbot.git
synced 2026-11-25 15:45:30 +08:00
* Remove code comments and add the no-comments rule Remove the comments from first-party code and configuration files: TS/JS, JSX, CSS, SQL migrations, Swift, Kotlin, Gradle, shell, Docker, systemd, Nix, YAML, TOML, JSONC and GritQL. Keep only what a tool reads: license headers, shebangs, compiler and lint directives, JSDoc types in plain .js files, generated file headers, GritQL scope lines, the install-server.sh help text and the openbot-boat-pre-stop marker. Vendored code, fixtures and released schemas keep their comments. Add the rule to AGENTS.md, and change the docs that asked for comments. Add two i18n keys that only comments named to RELEASED_SOURCE_KEYS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep comments that are data in strings The benchmark task files in opencode-free-models-bench.ts tell the model what each function must do. The sample file and HTML page in the two stories are display content. Put their comments back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep released migrations and mobile native inputs unchanged check:migrations compares each released migration with v0.73.0 byte for byte, so restore src/backend/migrations. A change to a native build input of apps/mobile makes a new runtime version, so restore those files and the extra fingerprint sources. List these files and the comment markers that a tool reads in AGENTS.md. Remove the last requests for comments in src/renderer/AGENTS.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
3.6 KiB
TypeScript
106 lines
3.6 KiB
TypeScript
import { lstat, rm } from "node:fs/promises";
|
|
import { homedir } from "node:os";
|
|
import { dirname, parse, resolve } from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import { createOpenBotLogger, toLogValue } from "@openbot/logging";
|
|
import { isMissingFileError } from "../src/backend/file-errors";
|
|
import { type DevelopmentProfile, developmentUserDataName } from "../src/main/development-profile";
|
|
import { resolveDevelopmentAppDataRoot } from "./development-state-paths";
|
|
import { readScriptArguments } from "./script-arguments";
|
|
import { cleanupSeedOwnedTransfers, isDevelopmentProfileActive } from "./seed-dev-state";
|
|
|
|
export { resolveDevelopmentAppDataRoot } from "./development-state-paths";
|
|
|
|
const logger = createOpenBotLogger("reset-dev-state");
|
|
|
|
const developmentProfiles = ["app", "test-client"] as const satisfies readonly DevelopmentProfile[];
|
|
const legacyDevelopmentStateNames = ["OpenBot Dev Host"] as const;
|
|
|
|
const USAGE = [
|
|
"Usage: bun run dev:reset",
|
|
"",
|
|
"Deletes the app, test-client, and legacy host development profiles. It refuses while a",
|
|
"dev app has one of them open. It takes no options.",
|
|
].join("\n");
|
|
|
|
export function developmentStatePaths(appDataRoot: string): string[] {
|
|
const safeRoot = resolve(appDataRoot);
|
|
if (safeRoot === parse(safeRoot).root) {
|
|
throw new Error("The application data root cannot be a filesystem root.");
|
|
}
|
|
|
|
return [
|
|
...developmentProfiles.map((profile) => developmentUserDataName(profile)),
|
|
...legacyDevelopmentStateNames,
|
|
].map((name) => {
|
|
const target = resolve(safeRoot, name);
|
|
if (dirname(target) !== safeRoot) {
|
|
throw new Error(`Unsafe OpenBot dev state path: ${target}`);
|
|
}
|
|
return target;
|
|
});
|
|
}
|
|
|
|
export async function resetDevelopmentState(
|
|
appDataRoot: string,
|
|
homeDirectory = homedir(),
|
|
beforeDelete: (statePath: string) => void = () => {},
|
|
): Promise<string[]> {
|
|
const existingPaths: string[] = [];
|
|
for (const statePath of developmentStatePaths(appDataRoot)) {
|
|
try {
|
|
await lstat(statePath);
|
|
} catch (error) {
|
|
if (isMissingFileError(error)) {
|
|
continue;
|
|
}
|
|
throw error;
|
|
}
|
|
existingPaths.push(statePath);
|
|
}
|
|
|
|
for (const statePath of existingPaths) {
|
|
if (await isDevelopmentProfileActive(statePath)) {
|
|
throw new Error(`Quit the OpenBot dev app before you reset its state. ${statePath} is open.`);
|
|
}
|
|
}
|
|
|
|
for (const statePath of existingPaths) {
|
|
beforeDelete(statePath);
|
|
await cleanupSeedOwnedTransfers(statePath, homeDirectory);
|
|
await rm(statePath, { force: true, maxRetries: 3, recursive: true, retryDelay: 100 });
|
|
}
|
|
|
|
return existingPaths;
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
if (readScriptArguments({ usage: USAGE, options: {} }) === null) return;
|
|
const appDataRoot = resolveDevelopmentAppDataRoot();
|
|
const deletedPaths = await resetDevelopmentState(appDataRoot, homedir(), (statePath) => {
|
|
logger.info(`Deleting ${statePath}`);
|
|
});
|
|
|
|
if (deletedPaths.length === 0) {
|
|
logger.info("No OpenBot development state was found.");
|
|
} else {
|
|
logger.info("OpenBot development state reset.");
|
|
}
|
|
|
|
logger.info("Seed-owned transfer files were removed. Other shared files were not changed.");
|
|
logger.info("Agent workspaces, ~/.codex, and ~/.claude were not changed.");
|
|
logger.info("Downloaded provider CLIs were not changed.");
|
|
}
|
|
|
|
function isMainModule(): boolean {
|
|
const entryPath = process.argv[1];
|
|
return entryPath !== undefined && import.meta.url === pathToFileURL(resolve(entryPath)).href;
|
|
}
|
|
|
|
if (isMainModule()) {
|
|
main().catch((error: unknown) => {
|
|
logger.error(toLogValue(error));
|
|
process.exitCode = 1;
|
|
});
|
|
}
|