The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
A username never ends in a dot, so @name in a message tags them (#2307)
0xken15ecfb5a5542f5
diff --git a/backend/src/superTabs/commands.ts b/backend/src/superTabs/commands.tsindex 89c6dcef6..68fb787fb 100644--- a/backend/src/superTabs/commands.ts+++ b/backend/src/superTabs/commands.ts@@ -13,7 +13,7 @@ import { routeRecordSchema, routeTitle, startedAs, type RouteCandidate, type Rouimport { DEFAULT_ROUTING_POLICY, routingOverrideSaveSchema, type RoutingPolicy } from './routingPolicy.js'import { agentQuality, agentTarget, askedInSchema, broken, MAX_RULES, reviewRefusal, RULE_MESSAGE_MS, SAME_ENGINE, sameEngineReview, ruleSchema, ruleTextSchema, startTarget, unmet, type RunTarget } from './rules.js'import { MAX_ATTACHMENTS, type Attachment } from './attachments.js'-import { checkMentions, MAX_MENTIONS, namedIn, textTags, withTags, type MentionTarget } from './mentions.js'+import { checkMentions, MAX_MENTIONS, namedIn, saysName, textTags, withTags, type MentionTarget } from './mentions.js'import { answerDecision, askDecisions, checkAsker, decisionChoices, decisionQuestion, MAX_OPEN_DECISIONS, MAX_QUESTIONS, type DecisionTarget } from './decisions.js'import { TERMINAL_KEYS, terminalAlert, terminalRequest, terminalResult, toLead, type TerminalRequest } from './terminal.js'import { leadNoticeRows, loseTasks, recordTaskState, renewLease, renewOwnTask, restartQuietTime, reviewFoundProblems, waitingForReview } from './liveness.js'@@ -1992,7 +1992,8 @@ export function applyCommand(original: SuperTabState, actor: Actor, input: Comma// Every username is worked out at once, and only for a post that names or picks someone.const names = picked.length || command.text.includes('@') ? swarmUsernames(state) : new Map<string, string>()const named = namedIn(state, command.text, names)- const text = withTags(picked.filter(id => !named.includes(id)).map(id => `@${names.get(id)}`), command.text)+ const unsaid = picked.filter(id => !named.includes(id) && !saysName(command.text, names.get(id)!))+ const text = withTags(unsaid.map(id => `@${names.get(id)}`), command.text)// A tag would tell a person about an agent-only notice they cannot see.const mentions = [...new Set([...picked, ...command.agentOnly ? [] : textTags(state, actor, group, named)])].slice(0, MAX_MENTIONS)if (command.mentionsIfNoWorker && !mentions.length) fail('INVALID_MENTION', 'Hold a tag only for a message that tags someone.', 400)diff --git a/backend/src/superTabs/mentions.test.ts b/backend/src/superTabs/mentions.test.tsindex 91ab5636d..a94219e58 100644--- a/backend/src/superTabs/mentions.test.ts+++ b/backend/src/superTabs/mentions.test.ts@@ -161,6 +161,17 @@ describe('a picked tag the text does not say', () => {expect(f.say(f.group, 'run `@peer`', owner, ['peer']).text).toBe('@peer run `@peer`')})+ it('is not added again for a stored name ending in a dot that the text says', () => {+ const f = fixture()+ // Chosen before such names were refused (usernames.ts).+ f.state.people.find(p => p.id === 'peer')!.username = 'peer.'+ const sent = f.say(f.group, 'Ask @peer. today', owner, ['peer'])+ expect(sent.text).toBe('Ask @peer. today')+ expect(sent.mentions).toEqual(['peer'])+ // Said only inside code, it still opens the line.+ expect(f.say(f.group, 'run `@peer.`', owner, ['peer']).text).toBe('@peer. run `@peer.`')+ })+it('is written the same way when the command is retried', () => {const command = { type: 'message.send' as const, conversationId: '', text: 'Please look.', replyTo: null, recipientIds: [], mentions: ['peer'] }const first = fixture(), again = fixture()diff --git a/backend/src/superTabs/mentions.ts b/backend/src/superTabs/mentions.tsindex 93b28ab37..c0e170d98 100644--- a/backend/src/superTabs/mentions.ts+++ b/backend/src/superTabs/mentions.ts@@ -84,6 +84,13 @@ export function namedIn(state: SuperTabState, text: string, names: ReadonlyMap<sreturn [...new Set(ids)]}+/** Whether [text] says `@` and exactly [name] outside code and links, in any case: a stored name that ends in a dot, chosen+ * before such names were refused, reads as a shorter tag in [namedIn] but is still said. */+export function saysName(text: string, name: string): boolean {+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')+ return new RegExp(`(?<![\\w@/])@${escaped}(?![\\w+-]|\\.[\\w+-])`, 'i').test(prose(text))+}+/** [tags] on the first line of [text], as a person types them in chat. Only text that opens with a block (a list, heading,* quote, table, code, divider or link definition) keeps them on a line of their own, so that block still renders. The same* rule as Desktop's SuperTabMessageText.withTags, which shows an older message's unsaid tags. */diff --git a/backend/src/superTabs/usernames.test.ts b/backend/src/superTabs/usernames.test.tsindex c88c3b269..9518a2774 100644--- a/backend/src/superTabs/usernames.test.ts+++ b/backend/src/superTabs/usernames.test.ts@@ -55,6 +55,15 @@ describe('default usernames', () => {{ id: 'd', email: `${'a'.repeat(40)}@example.com` },])).toEqual(new Map([['a', 'pham.ngocswarm'], ['b', 'x1'], ['c', 'user'], ['d', 'a'.repeat(30)]]))})++ it('never ends a default name with a dot or puts two in a row, so @name tags them', () => {+ expect(usernames([+ { id: 'a', email: `${'a'.repeat(29)}[email protected]` },+ { id: 'b', email: '[email protected]' },+ { id: 'c', email: '[email protected]' },+ { id: 'd', email: '[email protected]' },+ ])).toEqual(new Map([['a', 'a'.repeat(29)], ['b', 'ken.nguyen'], ['c', 'dee'], ['d', 'x1']]))+ })})describe('member.username', () => {diff --git a/backend/src/superTabs/usernames.ts b/backend/src/superTabs/usernames.tsindex 37fadd33e..2e86224f6 100644--- a/backend/src/superTabs/usernames.ts+++ b/backend/src/superTabs/usernames.ts@@ -9,9 +9,11 @@ const SHAPE = /^[a-z0-9](?:[a-z0-9_-]|\.(?!\.)){0,30}[a-z0-9_-]$//** Room left in a default for its number (`ken` → `ken12`). */const DEFAULT_BASE_LENGTH = 30-/** The name a person's email prefix makes: lowercased, only the characters a username takes, never too short. */+/** The name a person's email prefix makes: lowercased, only the characters a username takes, never too short. Like a chosen+ * name (SHAPE), never a dot at its end or two in a row, so `@name` in a message tags them: trimmed after it is cut. */function base(email: string): string {- const prefix = email.split('@')[0]!.toLowerCase().replace(/[^a-z0-9._-]/g, '').replace(/^[._-]+/, '').slice(0, DEFAULT_BASE_LENGTH)+ const prefix = email.split('@')[0]!.toLowerCase().replace(/[^a-z0-9._-]/g, '').replace(/\.{2,}/g, '.').replace(/^[._-]+/, '')+ .slice(0, DEFAULT_BASE_LENGTH).replace(/\.+$/, '')if (!prefix) return 'user'return prefix.length < 2 ? `${prefix}1` : prefix}diff --git a/desktop/lib/super_tabs/model.dart b/desktop/lib/super_tabs/model.dartindex 8fa253cbf..5dacaaf1c 100644--- a/desktop/lib/super_tabs/model.dart+++ b/desktop/lib/super_tabs/model.dart@@ -78,8 +78,11 @@ String superTabDefaultUsername(String email) {.first.toLowerCase().replaceAll(RegExp(r'[^a-z0-9._-]'), '')+ .replaceAll(RegExp(r'\.{2,}'), '.').replaceFirst(RegExp(r'^[._-]+'), '');if (prefix.length > 30) prefix = prefix.substring(0, 30);+ // Never a dot at the end, so `@name` in a message tags them.+ prefix = prefix.replaceFirst(RegExp(r'\.+$'), '');if (prefix.isEmpty) return 'user';return prefix.length < 2 ? '${prefix}1' : prefix;}diff --git a/desktop/test/super_tab_usernames_test.dart b/desktop/test/super_tab_usernames_test.dartindex 81222895b..c5ef5b0c7 100644--- a/desktop/test/super_tab_usernames_test.dart+++ b/desktop/test/super_tab_usernames_test.dart@@ -70,6 +70,18 @@ void main() {);},);++ test('never ends a default name with a dot or puts two in a row', () {+ expect(+ _names([+ _person('a', '${'a' * 29}[email protected]'),+ _person('b', '[email protected]'),+ _person('c', '[email protected]'),+ _person('d', '[email protected]'),+ ]),+ {'a': 'a' * 29, 'b': 'ken.nguyen', 'c': 'dee', 'd': 'x1'},+ );+ });});test('names come from the server, whatever order members arrive in', () {