diff --git a/packages/discord/src/binding.mjs b/packages/discord/src/binding.mjs index 68595f0a4..c2e492f72 100644 --- a/packages/discord/src/binding.mjs +++ b/packages/discord/src/binding.mjs @@ -24,12 +24,12 @@ import { loadWebConfig } from "./web.mjs"; import { loadSetsparkConfig } from "./setspark.mjs"; import { basename, isAbsolute, join, resolve, sep } from "node:path"; import { homedir } from "node:os"; -import { DiscordError, plainKey, quietRead } from "./errors.mjs"; +import { BINDING_NAME, DiscordError, plainKey, quietRead } from "./errors.mjs"; import { TOOL_DEFAULTS } from "./tools.mjs"; import { loadGitConfig } from "./git.mjs"; export const BINDING_VERSION = 1; -export const BINDING_NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/; +export { BINDING_NAME }; export const SNOWFLAKE = /^[0-9]{17,20}$/; export const CHANNEL_MODES = Object.freeze(["open", "mention"]); export const THINKING_LEVELS = Object.freeze(["off", "minimal", "low", "medium", "high", "xhigh", "max"]); diff --git a/packages/discord/src/errors.mjs b/packages/discord/src/errors.mjs index 1cb8eae62..7b5c968d3 100644 --- a/packages/discord/src/errors.mjs +++ b/packages/discord/src/errors.mjs @@ -4,6 +4,10 @@ // A refusal that names an unknown key quotes it only when it is a plain name; // a key that could carry a host path or a secret is described, never echoed (#1873). export const plainKey = (k) => (/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/.test(String(k)) ? JSON.stringify(k) : "that is not a plain name"); +// A binding (and seat) name. Defined here, not in binding.mjs, so journal.mjs can label a +// journal directory without importing binding.mjs and its config readers; copies of +// journal.mjs + errors.mjs (the queue test repo) stay self-contained. binding.mjs re-exports it. +export const BINDING_NAME = /^[a-z0-9][a-z0-9._-]{0,63}$/; // A read that fails names the file by label and the error code, never the // path Node puts in the message. The same error object is rethrown, so its diff --git a/packages/discord/src/journal.mjs b/packages/discord/src/journal.mjs index f0bce3e60..e0f5d97fa 100644 --- a/packages/discord/src/journal.mjs +++ b/packages/discord/src/journal.mjs @@ -26,8 +26,7 @@ import { unlinkSync, writeFileSync, writeSync, } from "node:fs"; import { basename, join } from "node:path"; -import { DiscordError, quietRead } from "./errors.mjs"; -import { BINDING_NAME } from "./binding.mjs"; +import { BINDING_NAME, DiscordError, quietRead } from "./errors.mjs"; // Where a refusal says a binding's journal is: its place under the data root // when the directory carries a valid binding name (bindingDataDir() makes it