Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869export interface SkillMention { start: number; end: number; prefix: string;}
const nameCharacter = (char: string) => /^[a-zA-Z0-9_-]$/.test(char);
// The $name the caret is in or just after, where the daemon reads it as a skill// mention (src/albedo/harness/extensions/skills/mentions.gleam).export function skillMentionAt( text: string, cursor: number,): SkillMention | null { cursor = Math.max(0, Math.min(cursor, text.length)); let start = cursor; while (start > 0 && nameCharacter(text[start - 1])) start--; if (start === 0 || text[start - 1] !== '$') return null; start--; // A dollar attached to a word, a dollar or a backslash is not a mention. if (start > 0 && /[\w$\\-]/.test(text[start - 1])) return null; if (!prose(text.slice(0, start))) return null; let end = cursor; while (end < text.length && nameCharacter(text[end])) end++; return { start, end, prefix: text.slice(start + 1, cursor) };}
// Whether text after prefix is prose: outside fenced code, indented code and// inline code spans.function prose(prefix: string): boolean { let fence = ''; let ticks = 0; let indented = false; for (const line of prefix.split('\n')) { const content = line.replace(/^ +/, ''); indented = line.length - content.length >= 4 || content.startsWith('\t'); const [marks, info] = indented ? ['', ''] : fenceMarker(content); if (fence) { if (marks[0] === fence[0] && marks.length >= fence.length && !info) fence = ''; continue; } if (marks && !ticks) { fence = marks; continue; } if (indented) continue; for (let index = 0; index < line.length; index++) { if (line[index] === '\\' && !ticks) { index++; continue; } if (line[index] !== '`') continue; let size = 1; while (line[index + size] === '`') size++; if (!ticks) ticks = size; else if (ticks === size) ticks = 0; index += size - 1; } } return !fence && !ticks && !indented;}
// A line's run of three or more backticks or tildes and the trimmed text after it.function fenceMarker(content: string): [string, string] { const match = /^(`{3,}|~{3,})(.*)$/s.exec(content); return match ? [match[1], match[2].trim()] : ['', ''];}