src / activation.ts
/** Characters a skill name may contain if it is to be activatable with `/name`. */
export const SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
export function isValidSkillName(name: string): boolean {
return SKILL_NAME.test(name);
}
/**
* Detects an explicit skill activation at the very start of a message: `/name rest` or `$name rest`.
* A `/` or `$` anywhere else is not an activation. `/etc/hosts` is not an activation because
* `/` is not a valid name character, so the whole token fails to match.
*/
const ACTIVATION = /^\s*[/$]([A-Za-z0-9][A-Za-z0-9_-]*)(?:\s+([\s\S]*))?$/;
export function parseActivation(text: string): { name: string; rest: string } | null {
const m = ACTIVATION.exec(text);
if (!m) return null;
return { name: m[1], rest: (m[2] ?? "").trim() };
}
src / activation.ts
/** Characters a skill name may contain if it is to be activatable with `/name`. */
export const SKILL_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
export function isValidSkillName(name: string): boolean {
return SKILL_NAME.test(name);
}
/**
* Detects an explicit skill activation at the very start of a message: `/name rest` or `$name rest`.
* A `/` or `$` anywhere else is not an activation. `/etc/hosts` is not an activation because
* `/` is not a valid name character, so the whole token fails to match.
*/
const ACTIVATION = /^\s*[/$]([A-Za-z0-9][A-Za-z0-9_-]*)(?:\s+([\s\S]*))?$/;
export function parseActivation(text: string): { name: string; rest: string } | null {
const m = ACTIVATION.exec(text);
if (!m) return null;
return { name: m[1], rest: (m[2] ?? "").trim() };
}