flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/web/app/lib/mention.ts

16 lines605 bytesCodeBlame
1/** How g1t's agent is mentioned. The same as `AGENT_HANDLE` in the contracts. */
2export const AGENT_MENTION = "@g1t-agent";
3
4const NAME = AGENT_MENTION.slice(1);
5
6/**
7 * The `@…` being typed just before the caret, if it could become
8 * `@g1t-agent`: where it starts. Null otherwise.
9 */
10export function partialMention(text: string, caret: number): number | null {
11 const match = /(?:^|[\s(])@([\w-]{0,9})$/.exec(text.slice(0, caret));
12 if (!match) return null;
13 const typed = match[1].toLowerCase();
14 if (typed === NAME || !NAME.startsWith(typed)) return null;
15 return caret - typed.length - 1;
16}