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
refactor: improve terminal link detection and soft-wrap handling for URLs
0xken152c821ca50de1
diff --git a/.gitignore b/.gitignoreindex 7609c6563..0e19c9d5d 100644--- a/.gitignore+++ b/.gitignore@@ -18,3 +18,5 @@ provider/example-provider/sessions.json.env.env.*!.env.example++.secretsdiff --git a/desktop/lib/terminal/terminal_links.dart b/desktop/lib/terminal/terminal_links.dartindex 50f2a783b..be6594d34 100644--- a/desktop/lib/terminal/terminal_links.dart+++ b/desktop/lib/terminal/terminal_links.dart@@ -93,21 +93,52 @@ String? terminalLinkInText(String text, int offset) {return null;}-/// Reconstructs the clicked logical line across terminal soft wraps, mapping-/// cell columns to UTF-16 offsets (wide CJK and emoji are not one code unit).-/// The bound also keeps malformed/unbroken output cheap during mouse hover.-String? terminalLinkAt(Terminal terminal, CellOffset cell) {+/// One logical line: a run of soft-wrapped rows, as the text they spell.+class _LogicalLine {+ final int firstRow;+ final int lastRow;+ final String text;++ /// The [_styleKey] of the cell each UTF-16 unit of [text] came from.+ final List<int> styles;++ /// UTF-16 offset of the target cell in [text], when the cell is on this line.+ final int? offset;++ const _LogicalLine(+ this.firstRow,+ this.lastRow,+ this.text,+ this.styles,+ this.offset,+ );++ int get leadingBlanks => text.length - text.trimLeft().length;++ /// Offset of the last character that is not a blank, or -1 on a blank line.+ int get lastVisible => text.trimRight().length - 1;+}++/// What makes a run of cells read as one thing: its colour and whether it is+/// underlined. Claude Code paints an address bright blue and carries that+/// paint onto the row it cut the address across, while the words around it+/// are plain — the one witness to the cut that survives the newline.+int _styleKey(BufferLine line, int x) =>+ (line.getForeground(x) << 1) |+ (line.getAttributes(x) & CellAttr.underline != 0 ? 1 : 0);++bool _underlined(int styleKey) => styleKey & 1 != 0;++/// Reconstructs the logical line through row [y] across terminal soft wraps,+/// mapping cell columns to UTF-16 offsets (wide CJK and emoji are not one code+/// unit). The bound also keeps malformed/unbroken output cheap during mouse+/// hover. [cell] is the pointer, whose offset is reported when it lands here.+_LogicalLine? _logicalLine(Terminal terminal, int y, CellOffset cell) {final lines = terminal.buffer.lines;- if (cell.y < 0 ||- cell.y >= lines.length ||- cell.x < 0 ||- cell.x >= lines[cell.y].length) {- return null;- }- var start = cell.y;- var end = cell.y;+ var start = y;+ var end = y;while (start > 0 && lines[start].isWrapped) {- if (cell.y - start >= 16) return null;+ if (y - start >= 16) return null;start--;}while (end + 1 < lines.length && lines[end + 1].isWrapped) {@@ -115,13 +146,14 @@ String? terminalLinkAt(Terminal terminal, CellOffset cell) {end++;}final text = StringBuffer();+ final styles = <int>[];int? offset;- for (var y = start; y <= end; y++) {- final line = lines[y];+ for (var row = start; row <= end; row++) {+ final line = lines[row];var previousOffset = text.length;for (var x = 0; x < line.length; x++) {final continuation = x > 0 && line.getWidth(x - 1) == 2;- if (cell.y == y && cell.x == x) {+ if (cell.y == row && cell.x == x) {offset = continuation ? previousOffset : text.length;}if (continuation) continue;@@ -129,7 +161,234 @@ String? terminalLinkAt(Terminal terminal, CellOffset cell) {final codePoint = line.getCodePoint(x);text.writeCharCode(codePoint == 0 ? 0x20 : codePoint);if (text.length > 8192) return null;+ final style = _styleKey(line, x);+ while (styles.length < text.length) {+ styles.add(style);+ }+ }+ }+ return _LogicalLine(start, end, text.toString(), styles, offset);+}++/// Columns up to the last cell that is neither empty nor a space — the width+/// a row was wrapped at. Spaces after it say nothing: Claude Code pads some+/// rows (its prompt box, a list item) to the full width with them, tmux+/// repaints with them, and the cut row of a URL carries them as often as not+/// — a capture of the real thing showed both `…commandcode.ai/` at the last+/// column and `…0xkongamoto/ ` one space short of it, each followed by the+/// rest of the address on the next row.+int _visibleWidth(BufferLine line) {+ for (var x = line.length - 1; x >= 0; x--) {+ final codePoint = line.getCodePoint(x);+ if (codePoint != 0 && codePoint != 0x20) return x + line.getWidth(x);+ }+ return 0;+}++/// The widest row of the paragraph (contiguous non-blank rows) around [row].+int _paragraphWidth(Terminal terminal, int row) {+ final lines = terminal.buffer.lines;+ var widest = _visibleWidth(lines[row]);+ for (final step in [-1, 1]) {+ for (var y = row + step, seen = 0; y >= 0 && y < lines.length; y += step) {+ final width = _visibleWidth(lines[y]);+ if (width == 0 || seen++ >= _hardWrapRows * 2) break;+ if (width > widest) widest = width;}}- return offset == null ? null : terminalLinkInText(text.toString(), offset);+ return widest;+}++final _trailingWebTarget = RegExp(+ r'''https?://[^\s<>`"']+$''',+ caseSensitive: false,+);+// The rest of an address begins with a character an address can contain —+// and a lone dash or a `1.` is a list marker, not that.+final _continuationToken = RegExp(+ r'''^(?:[A-Za-z0-9]|[/._~%?#=&+-](?=[^\s<>`"']))[^\s<>`"']*''',+);+final _listMarker = RegExp(r'^\d+[.)]$');+final _webScheme = RegExp(r'^https?://', caseSensitive: false);++/// How many hard-wrapped rows one URL may span before giving up on it.+const _hardWrapRows = 8;++/// A cut row is as wide as the widest row of its paragraph — a hard cut fills+/// the box exactly, a word wrap leaves it short (measured per paragraph+/// because a full-width `────` divider is its own paragraph). The fallback+/// witness, for output that does not paint its addresses.+bool _cutAtBoxWidth(Terminal terminal, _LogicalLine line) {+ final width = _visibleWidth(terminal.buffer.lines[line.lastRow]);+ return width > 0 && width >= _paragraphWidth(terminal, line.lastRow);+}++/// Whether the paint on the last character of [a] runs on into the first+/// token of [b] — the cut address carrying its colour across the newline.+bool _paintContinues(_LogicalLine a, _LogicalLine b) =>+ a.lastVisible >= 0 &&+ b.leadingBlanks < b.text.length &&+ a.styles[a.lastVisible] == b.styles[b.leadingBlanks];++/// Length of the row's first token, after the indent.+int _tokenLength(_LogicalLine line) =>+ _continuationToken.firstMatch(line.text.trimLeft())?[0]!.length ?? 0;++/// A row that is one token from its indent to its end — what a row in the+/// middle of a cut address looks like, and what a tail row may look like.+bool _singleToken(_LogicalLine line) {+ final text = line.text.trim();+ return text.isNotEmpty && !text.contains(RegExp(r'\s'));+}++/// The next row's first token is URL characters that do not start a URL of+/// their own. Ink indents a list item's continuation deeper than its bullet,+/// so the indent is not compared.+bool _continuesUrl(_LogicalLine line) {+ final token = _continuationToken.firstMatch(line.text.trimLeft())?[0];+ return token != null &&+ !_webScheme.hasMatch(token) &&+ !_listMarker.hasMatch(token);+}++/// Where [text] (rows spliced so far) breaks off inside a web URL: the offset+/// the address starts at, or null. An address that closes a bracket it never+/// opened — `(https://a.example/)` at the end of a row — is finished, not cut.+int? _urlCutAt(String text) {+ final trimmed = text.trimRight();+ final match = _trailingWebTarget.firstMatch(trimmed);+ if (match == null || !_isTarget(match[0]!)) return null;+ final raw = match[0]!.replaceFirst(RegExp(r'[.,;:!?]+$'), '');+ for (final pair in [('(', ')'), ('[', ']')]) {+ if (raw.endsWith(pair.$2) &&+ pair.$2.allMatches(raw).length > pair.$1.allMatches(raw).length) {+ return null;+ }+ }+ return match.start;+}++/// The cut rows spliced back together without the box indent that follows+/// each break, or the blank cells that precede it, with the pointer's offset+/// in the result when [own] is given. Null when the pointer sat on blanks the+/// splice removed — not on the URL — or the run is absurdly long.+(String, int?)? _splice(List<_LogicalLine> joined, _LogicalLine? own) {+ final text = StringBuffer();+ int? offset;+ for (final line in joined) {+ final stripped = identical(line, joined.first) ? 0 : line.leadingBlanks;+ final segment = identical(line, joined.last)+ ? line.text.substring(stripped)+ : line.text.substring(stripped).trimRight();+ if (own != null && identical(line, own)) {+ final at = own.offset! - stripped;+ if (at < 0 || at >= segment.length) return null;+ offset = text.length + at;+ }+ text.write(segment);+ if (text.length > 8192) return null;+ }+ return (text.toString(), offset);+}++/// Whether every break in [joined] is a cut, judged by the witness the head+/// row offers. An address painted differently from the words before it is+/// followed by its paint: each next row must open in the same paint, and a+/// row that opens in plain text is the next sentence, however wide the row+/// above was. An address in the same paint as its sentence has only the box+/// width to go on.+bool _cutThroughout(Terminal terminal, List<_LogicalLine> joined) {+ final head = joined.first;+ final urlStart = _urlCutAt(head.text);+ if (urlStart == null) return false;+ final urlStyle = head.styles[head.lastVisible];+ var before = urlStart - 1;+ while (before >= 0 && head.text[before] == ' ') {+ before--;+ }+ final painted = before >= 0+ ? head.styles[before] != urlStyle+ : _underlined(urlStyle) || urlStyle != head.styles[0];+ for (var i = 0; i + 1 < joined.length; i++) {+ final cut = painted+ ? _paintContinues(joined[i], joined[i + 1])+ : _cutAtBoxWidth(terminal, joined[i]);+ if (!cut) return false;+ }+ return true;+}++/// Finds the target under [cell]. A web URL that the program on the other end+/// hard-wrapped across rows is read whole, from whichever row the pointer is+/// on; everything else is confined to the logical line, as separate output+/// lines are separate things (a path is never assembled from two of them).+///+/// A TUI cuts a long address at its box width and carries the rest onto the+/// next row with its own newline — what Claude Code (Ink, `wrap-ansi` with+/// `hard: true`) does. A terminal soft wrap is already joined by+/// [_logicalLine]; this is the break it cannot see, and it is inferred: from+/// the paint on the address when there is any, else from the row's width.+String? terminalLinkAt(Terminal terminal, CellOffset cell) {+ final lines = terminal.buffer.lines;+ if (cell.y < 0 ||+ cell.y >= lines.length ||+ cell.x < 0 ||+ cell.x >= lines[cell.y].length) {+ return null;+ }+ final own = _logicalLine(terminal, cell.y, cell);+ if (own == null || own.offset == null) return null;+ final single = terminalLinkInText(own.text, own.offset!);++ // Which way the rest of the address lies is read off the pointer: on the+ // row's opening token it may be a carried tail, so look above; on an+ // address the row breaks off in, look below. A row that is one token from+ // indent to end may be the middle of one, and is followed both ways.+ bool mayJoin(_LogicalLine a, _LogicalLine b) =>+ _continuesUrl(b) &&+ (_paintContinues(a, b) || _cutAtBoxWidth(terminal, a));++ final joined = [own];+ final at = own.offset!;+ final cutAt = _urlCutAt(own.text);+ final onOpeningToken =+ at >= own.leadingBlanks && at < own.leadingBlanks + _tokenLength(own);+ if (onOpeningToken && _continuesUrl(own)) {+ while (joined.first.firstRow > 0 && joined.length < _hardWrapRows) {+ final previous = _logicalLine(terminal, joined.first.firstRow - 1, cell);+ if (previous == null || !mayJoin(previous, joined.first)) break;+ // Above a carried row sits either the row the address starts on or+ // another row of nothing but address; anything else ends the search.+ final head = _urlCutAt(previous.text) != null;+ if (!head && !_singleToken(previous)) break;+ joined.insert(0, previous);+ if (head) break;+ }+ }+ if ((cutAt != null && at >= cutAt) || _singleToken(own)) {+ while (joined.last.lastRow + 1 < lines.length) {+ final next = _logicalLine(terminal, joined.last.lastRow + 1, cell);+ if (next == null ||+ !mayJoin(joined.last, next) ||+ _urlCutAt(_splice(joined, null)?.$1 ?? '') == null) {+ break;+ }+ // Past the bound the address is unknowable, and a fragment of it would+ // open the wrong page — no link is the honest answer.+ if (joined.length >= _hardWrapRows) return null;+ joined.add(next);+ // The row the address ends on has words after it; nothing follows.+ if (!_singleToken(next)) break;+ }+ }+ if (joined.length == 1 || !_cutThroughout(terminal, joined)) return single;++ final spliced = _splice(joined, own);+ if (spliced == null) return single;+ final (text, offset) = spliced;+ if (offset == null) return single;+ final target = terminalLinkInText(text, offset);+ if (target == null) return single;+ final scheme = Uri.tryParse(target)?.scheme;+ return scheme == 'http' || scheme == 'https' ? target : single;}diff --git a/desktop/test/fixtures/claude_code_44col_response.bin b/desktop/test/fixtures/claude_code_44col_response.binnew file mode 100644index 000000000..5e17b53b3--- /dev/null+++ b/desktop/test/fixtures/claude_code_44col_response.bin@@ -0,0 +1,54 @@+[?1049h[22;0;0t[?1h=[H[2J[?12l[?25h[?1000l[?1002l[?1003l[?1006l[?1005l[?2004h[?2031h[?996n(B[m[?12l[?25h[?1006l[?1000l[?1002l[?1003l[1;1H[1;30r[c[>c[>q]10;?\]11;?\[24;3H[?25l[1;11H[1K[1m[CClaude(B[m [1mCode(B[m [38;5;246mv2.1.270[39m[K[38;5;174m+ ▐[48;5;16m▛███▛█[39m[49m [38;5;246mOpus[39m [38;5;246m5[39m [38;5;246m(1M[39m [38;5;246mcontext)[39m [38;5;246mwith[39m [38;5;246mhig…[39m [38;5;174m[3;1H▝▜[48;5;16m█████[49m█▀[39m [38;5;246mClaude[39m [38;5;246mMax[39m[K+ [38;5;174m▝▝[39m [38;5;174m▝▝[39m [38;5;246m/…/scratchpad/probe[39m[K+[K[38;5;220m+⚠[39m [38;5;220mYour[39m [38;5;220mlogin[39m [38;5;220mexpires[39m [38;5;220min[39m [38;5;220m1[39m [38;5;220mday(B[m[38;5;246m ·[39m [38;5;246mrun[39m [38;5;246m/login[39m [7;1H [38;5;246mto[39m [38;5;246mrenew[39m[K+[K[38;5;239m[48;5;237m+❯ [38;5;231mReply with exactly these two lines and[39m [49m[48;5;237m[10;1H [38;5;231mnothing else, no tools: "Command Code[39m [49m[48;5;237m[11;1H [38;5;231mhere: https://commandcode.ai/0xkongamoto/[39m [49m[48;5;237m[12;1H [38;5;231msettings/billing" then "- NVIDIA[39m[K[49m[48;5;237m+ [38;5;231mIsaac-GR00T[39m[K[49m[48;5;237m+ [38;5;231m(https://github.com/NVIDIA/Isaac-GR00T)"[39m [49m[15;1H[K[38;5;231m+⏺[39m Command Code here: [94mhttps://commandcode.ai/[39m[17;1H [94m0xkongamoto/settings/billing[39m[K+ - NVIDIA Isaac-GR00T[K+ ([94mhttps://github.com/NVIDIA/Isaac-GR00T[39m) [20;1H[K[38;5;246m+✻[39m [38;5;246mBrewed for 3s · done 11:44 AM[39m[K+[K[38;5;244m+────────────────────────────────────────────[39m[24;1H❯ [K[38;5;244m+────────────────────────────────────────────[39m[26;1H [38;5;220m⏵⏵ auto mode on(B[m[38;5;246m (shift+tab to cycle) · …[39m [27;1H[K+[K+[K[30m[42m+[probe] Command Code and NV" 11:45 14-Sep-26(B[m[?12l[?25h[24;3H[18t[14t(B[m[?12l[?25h[?1006l[?1000l[?1002l[?1003l[1;1H[1;30r[24;3H[?25l[1;11H[1K[1m[CClaude(B[m [1mCode(B[m [38;5;246mv2.1.270[39m[K[38;5;174m+ ▐[48;5;16m▛███▛█[39m[49m [38;5;246mOpus[39m [38;5;246m5[39m [38;5;246m(1M[39m [38;5;246mcontext)[39m [38;5;246mwith[39m [38;5;246mhig…[39m [38;5;174m[3;1H▝▜[48;5;16m█████[49m█▀[39m [38;5;246mClaude[39m [38;5;246mMax[39m[K+ [38;5;174m▝▝[39m [38;5;174m▝▝[39m [38;5;246m/…/scratchpad/probe[39m[K+[K[38;5;220m+⚠[39m [38;5;220mYour[39m [38;5;220mlogin[39m [38;5;220mexpires[39m [38;5;220min[39m [38;5;220m1[39m [38;5;220mday(B[m[38;5;246m ·[39m [38;5;246mrun[39m [38;5;246m/login[39m [7;1H [38;5;246mto[39m [38;5;246mrenew[39m[K+[K[38;5;239m[48;5;237m+❯ [38;5;231mReply with exactly these two lines and[39m [49m[48;5;237m[10;1H [38;5;231mnothing else, no tools: "Command Code[39m [49m[48;5;237m[11;1H [38;5;231mhere: https://commandcode.ai/0xkongamoto/[39m [49m[48;5;237m[12;1H [38;5;231msettings/billing" then "- NVIDIA[39m[K[49m[48;5;237m+ [38;5;231mIsaac-GR00T[39m[K[49m[48;5;237m+ [38;5;231m(https://github.com/NVIDIA/Isaac-GR00T)"[39m [49m[15;1H[K[38;5;231m+⏺[39m Command Code here: [94mhttps://commandcode.ai/[39m[17;1H [94m0xkongamoto/settings/billing[39m[K+ - NVIDIA Isaac-GR00T[K+ ([94mhttps://github.com/NVIDIA/Isaac-GR00T[39m) [20;1H[K[38;5;246m+✻[39m [38;5;246mBrewed for 3s · done 11:44 AM[39m[K+[K[38;5;244m+────────────────────────────────────────────[39m[24;1H❯ [K[38;5;244m+────────────────────────────────────────────[39m[26;1H [38;5;220m⏵⏵ auto mode on(B[m[38;5;246m (shift+tab to cycle) · …[39m [27;1H[K+[K+[K[30m[42m+[probe] Command Code and NV" 11:45 14-Sep-26(B[m[?12l[?25h[24;3H[12d[?25l[25;40H[1;11H[1K[1m[CClaude(B[m [1mCode(B[m [38;5;246mv2.1.270[39m[K[38;5;174m+ ▐[48;5;16m▛███▛█[39m[49m [38;5;246mOpus[39m [38;5;246m5[39m [38;5;246m(1M[39m [38;5;246mcontext)[39m [38;5;246mwith[39m [38;5;246mhig…[39m [38;5;174m[3;1H▝▜[48;5;16m█████[49m█▀[39m [38;5;246mClaude[39m [38;5;246mMax[39m[K+ [38;5;174m▝▝[39m [38;5;174m▝▝[39m [38;5;246m/…/scratchpad/probe[39m[K+[K[38;5;220m+⚠[39m [38;5;220mYour[39m [38;5;220mlogin[39m [38;5;220mexpires[39m [38;5;220min[39m [38;5;220m1[39m [38;5;220mday(B[m[38;5;246m ·[39m [38;5;246mrun[39m [38;5;246m/login[39m [7;1H [38;5;246mto[39m [38;5;246mrenew[39m[K+[K[38;5;239m[48;5;237m+❯ [38;5;231mReply with exactly these two lines and[39m [49m[48;5;237m[10;1H [38;5;231mnothing else, no tools: "Command Code[39m [49m[48;5;237m[11;1H [38;5;231mhere: https://commandcode.ai/0xkongamoto/[39m [49m[48;5;237m[12;1H [38;5;231msettings/billing" then "- NVIDIA[39m[K[49m[48;5;237m+ [38;5;231mIsaac-GR00T[39m[K[49m[48;5;237m+ [38;5;231m(https://github.com/NVIDIA/Isaac-GR00T)"[39m [49m[15;1H[K[38;5;231m+⏺[39m Command Code here: [94mhttps://commandcode.ai/[39m[17;1H [94m0xkongamoto/settings/billing[39m[K+ - NVIDIA Isaac-GR00T[K+ ([94mhttps://github.com/NVIDIA/Isaac-GR00T[39m) [20;1H[K[38;5;246m+✻[39m [38;5;246mBrewed[39m [38;5;246mfor[39m [38;5;246m3s[39m [38;5;246m·[39m [38;5;246mdone[39m [38;5;246m11:44[39m [38;5;246mAM[39m[K+[K[38;5;244m+────────────────────────────────────────────[39m[24;1H❯ [K[38;5;244m+────────────────────────────────────────────[39m[26;1H [38;5;220m⏵⏵[39m [38;5;220mauto[39m [38;5;220mmode[39m [38;5;220mon(B[m[38;5;246m (shift+tab[39m [38;5;246mto[39m [38;5;246mcycle)[39m [38;5;246m·[39m [38;5;246m…[39m [27;1H[K+[K+[K[24;3H[?12l[?25h\ No newline at end of filediff --git a/desktop/test/fixtures/claude_code_44col_tool_result.bin b/desktop/test/fixtures/claude_code_44col_tool_result.binnew file mode 100644index 000000000..cc307d18d--- /dev/null+++ b/desktop/test/fixtures/claude_code_44col_tool_result.bin@@ -0,0 +1,33 @@+[?1049h[22;0;0t[?1h=[H[2J[?12l[?25h[?1000l[?1002l[?1003l[?1006l[?1005l[?2004h[?2031h[?996n(B[m[?12l[?25h[?1006l[?1000l[?1002l[?1003l[1;1H[1;30r[c[>c[>q]10;?\]11;?\[23;3H[?25l[H - NVIDIA Isaac-GR00T[K+ ([94mhttps://github.com/NVIDIA/Isaac-GR00T[39m) [3;1H[K[38;5;246m+✻[39m [38;5;246mBrewed[39m [38;5;246mfor[39m [38;5;246m3s[39m [38;5;246m·[39m [38;5;246mdone[39m [38;5;246m11:44[39m [38;5;246mAM[39m[K+[K[38;5;239m[48;5;237m+❯ [38;5;231mRun this exact bash command and then[39m [49m[48;5;237m[7;1H [38;5;231mreply "ok": echo "Command Code here:[39m [49m[48;5;237m[8;1H [38;5;231mhttps://commandcode.ai/0xkongamoto/settin[39m [49m[48;5;237m[9;1H [38;5;231mgs/billing/extra/long/path/segment"[39m [49m[10;1H[K[38;5;114m+⏺[39m [1mBash(B[m(echo "Command Code here: https://comm[12;1H andcode.ai/0xkongamoto/settings/billin[13;1H g/extra/long/path/segment")[K[38;5;246m+ ⎿ [39mCommand Code here: [94mhttps://command[39m [15;1H [94mcode.ai/0xkongamoto/settings/billi[39m [16;1H [94mng/extra/long/path/segment[39m[K+[K[38;5;231m+⏺[39m ok[K+[K[38;5;246m+✻[39m [38;5;246mBrewed for 5s · done 11:47 AM[39m[K+[K[38;5;244m+────────────────────────────────────────────[39m[23;1H❯ [2mNow run the same echo with the original b…(B[m[38;5;244m[24;1H────────────────────────────────────────────[39m[25;1H [38;5;220m⏵⏵ auto mode on(B[m[38;5;246m (shift+tab to cycle) · …[39m [26;1H[K+[K+[K+[K[30m[42m+[probe] Command Code and NV" 11:48 14-Sep-26(B[m[?12l[?25h[23;3H[18t[14t(B[m[?12l[?25h[?1006l[?1000l[?1002l[?1003l[1;1H[1;30r[23;3H[?25l[H - NVIDIA Isaac-GR00T[K+ ([94mhttps://github.com/NVIDIA/Isaac-GR00T[39m) [3;1H[K[38;5;246m+✻[39m [38;5;246mBrewed[39m [38;5;246mfor[39m [38;5;246m3s[39m [38;5;246m·[39m [38;5;246mdone[39m [38;5;246m11:44[39m [38;5;246mAM[39m[K+[K[38;5;239m[48;5;237m+❯ [38;5;231mRun this exact bash command and then[39m [49m[48;5;237m[7;1H [38;5;231mreply "ok": echo "Command Code here:[39m [49m[48;5;237m[8;1H [38;5;231mhttps://commandcode.ai/0xkongamoto/settin[39m [49m[48;5;237m[9;1H [38;5;231mgs/billing/extra/long/path/segment"[39m [49m[10;1H[K[38;5;114m+⏺[39m [1mBash(B[m(echo "Command Code here: https://comm[12;1H andcode.ai/0xkongamoto/settings/billin[13;1H g/extra/long/path/segment")[K[38;5;246m+ ⎿ [39mCommand Code here: [94mhttps://command[39m [15;1H [94mcode.ai/0xkongamoto/settings/billi[39m [16;1H [94mng/extra/long/path/segment[39m[K+[K[38;5;231m+⏺[39m ok[K+[K[38;5;246m+✻[39m [38;5;246mBrewed for 5s · done 11:47 AM[39m[K+[K[38;5;244m+────────────────────────────────────────────[39m[23;1H❯ [2mNow run the same echo with the original b…(B[m[38;5;244m[24;1H────────────────────────────────────────────[39m[25;1H [38;5;220m⏵⏵ auto mode on(B[m[38;5;246m (shift+tab to cycle) · …[39m [26;1H[K+[K+[K+[K[30m[42m+[probe] Command Code and NV" 11:48 14-Sep-26(B[m[?12l[?25h[23;3H\ No newline at end of filediff --git a/desktop/test/terminal_links_test.dart b/desktop/test/terminal_links_test.dartindex 232238c63..abeaf2d50 100644--- a/desktop/test/terminal_links_test.dart+++ b/desktop/test/terminal_links_test.dart@@ -1,3 +1,6 @@+import 'dart:convert';+import 'dart:io';+import 'package:flutter_test/flutter_test.dart';import 'package:harness/terminal/terminal_links.dart';import 'package:xterm/xterm.dart';@@ -105,4 +108,236 @@ void main() {isNull,);});++ group('hard-wrapped web URLs', () {+ // What Claude Code (Ink) writes for a long address in a narrow pane: rows+ // with their own newlines, cut at the box width, each indented by the box.+ const url = 'https://commandcode.ai/0xkongamoto/settings/billing';+ Terminal ink(List<String> rows, {int width = 44}) {+ final terminal = Terminal()..resize(width, 12);+ terminal.write(rows.join('\r\n'));+ return terminal;+ }++ test('reads the whole URL from either row', () {+ final terminal = ink([+ ' Command Code here: https://commandc',+ ' ode.ai/0xkongamoto/settings/billing',+ '',+ ' * Worked for 1s',+ ]);+ expect(terminalLinkAt(terminal, const CellOffset(25, 0)), url);+ expect(terminalLinkAt(terminal, const CellOffset(36, 0)), url);+ expect(terminalLinkAt(terminal, const CellOffset(2, 1)), url);+ expect(terminalLinkAt(terminal, const CellOffset(30, 1)), url);+ // The label before the URL and the box indent are not the link.+ expect(terminalLinkAt(terminal, const CellOffset(5, 0)), isNull);+ expect(terminalLinkAt(terminal, const CellOffset(0, 1)), isNull);+ });++ test('spans more than two rows and still trims trailing punctuation', () {+ final terminal = ink([+ ' See https://commandcode.ai/0xkon',+ ' gamoto/settings/billing?tab=invo',+ ' ices&period=2026-09.',+ ], width: 40);+ const long = '$url?tab=invoices&period=2026-09';+ expect(terminalLinkAt(terminal, const CellOffset(10, 0)), long);+ expect(terminalLinkAt(terminal, const CellOffset(10, 1)), long);+ expect(terminalLinkAt(terminal, const CellOffset(4, 2)), long);+ expect(terminalLinkAt(terminal, const CellOffset(22, 2)), isNull);+ });++ test('joins a list item whose continuation is indented deeper', () {+ final terminal = ink([+ ' • https://commandcode.ai/0xkongam',+ ' oto/settings/billing',+ ], width: 40);+ expect(terminalLinkAt(terminal, const CellOffset(6, 0)), url);+ expect(terminalLinkAt(terminal, const CellOffset(6, 1)), url);+ });++ test('does not join a word wrap that happens to end with a URL', () {+ final terminal = ink([+ ' see https://foo.com',+ ' and more words after it',+ ]);+ expect(+ terminalLinkAt(terminal, const CellOffset(8, 0)),+ 'https://foo.com',+ );+ expect(terminalLinkAt(terminal, const CellOffset(3, 1)), isNull);+ });++ test('does not join a fresh URL or across a blank row', () {+ final fresh = ink([+ ' https://a.example/one-two-three-x',+ ' https://b.example/two',+ ], width: 40);+ expect(+ terminalLinkAt(fresh, const CellOffset(4, 0)),+ 'https://a.example/one-two-three-x',+ );+ expect(+ terminalLinkAt(fresh, const CellOffset(4, 1)),+ 'https://b.example/two',+ );+ final blank = ink([' https://a.example/one-two-three-x', '', ' more']);+ expect(+ terminalLinkAt(blank, const CellOffset(4, 0)),+ 'https://a.example/one-two-three-x',+ );+ expect(terminalLinkAt(blank, const CellOffset(3, 2)), isNull);+ });++ test('ignores the spaces a row is padded with past the cut', () {+ // Claude Code's prompt box paints its rows to the full width with+ // spaces; the address still breaks at the box width underneath them.+ final terminal = ink([+ ' here: https://commandcode.ai/0xkongamoto/ ',+ ' settings/billing" then "- NVIDIA',+ ], width: 44);+ expect(terminalLinkAt(terminal, const CellOffset(12, 0)), url);+ expect(terminalLinkAt(terminal, const CellOffset(4, 1)), url);+ });++ test('does not join a row that opens with sentence punctuation', () {+ final terminal = ink([+ ' see https://a.example/one-two-x',+ ' — and then something else',+ ], width: 40);+ expect(+ terminalLinkAt(terminal, const CellOffset(8, 0)),+ 'https://a.example/one-two-x',+ );+ expect(terminalLinkAt(terminal, const CellOffset(4, 1)), isNull);+ });++ test('follows the paint of a cut address past a wider row beside it', () {+ // Claude Code paints an address bright blue (SGR 94) and carries the+ // paint onto the rows it cut it across; a tool result sits directly+ // under the wider tool-call rows, so the box width alone says no.+ final terminal = Terminal()..resize(44, 12);+ terminal.write(+ '⏺ Bash(echo "Command Code here: https://comm\r\n'+ ' andcode.ai/0xkongamoto/settings/billin\r\n'+ ' g/extra/long/path/segment")\r\n'+ ' ⎿ Command Code here: \x1b[94mhttps://command\x1b[39m\r\n'+ ' \x1b[94mcode.ai/0xkongamoto/settings/billi\x1b[39m\r\n'+ ' \x1b[94mng/extra/long/path/segment\x1b[39m',+ );+ const long = '$url/extra/long/path/segment';+ expect(terminalLinkAt(terminal, const CellOffset(30, 3)), long);+ expect(terminalLinkAt(terminal, const CellOffset(10, 4)), long);+ expect(terminalLinkAt(terminal, const CellOffset(10, 5)), long);+ expect(terminalLinkAt(terminal, const CellOffset(10, 3)), isNull);+ });++ test('a painted address is not followed into plain text', () {+ // The row is its paragraph's widest and ends with the address, but+ // the next row opens in plain paint: the sentence went on, the+ // address did not.+ final terminal = Terminal()..resize(44, 12);+ terminal.write(+ '⏺ See the docs at \x1b[94mhttps://foo.com/docs\x1b[39m\r\n'+ ' before you start.',+ );+ expect(+ terminalLinkAt(terminal, const CellOffset(20, 0)),+ 'https://foo.com/docs',+ );+ expect(terminalLinkAt(terminal, const CellOffset(3, 1)), isNull);+ });++ test('a finished address in a wide pane is not glued to the next item', () {+ // Nothing wrapped here; the first row is merely the widest, and ends+ // with the bracket that closes the address.+ final terminal = Terminal()..resize(120, 6);+ terminal.write(+ ' - Ra mắt GPT-5.2 - OpenAI (\x1b[94mhttps://openai.com/vi-VN/index/introducing-gpt-5-2/\x1b[39m)\r\n'+ ' - NVIDIA Isaac-GR00T (\x1b[94mhttps://github.com/NVIDIA/Isaac-GR00T\x1b[39m)',+ );+ expect(+ terminalLinkAt(terminal, const CellOffset(40, 0)),+ 'https://openai.com/vi-VN/index/introducing-gpt-5-2/',+ );+ expect(+ terminalLinkAt(terminal, const CellOffset(30, 1)),+ 'https://github.com/NVIDIA/Isaac-GR00T',+ );+ });++ test('a list marker is not the rest of an address', () {+ for (final marker in ['- next item', '2. next item', '2) next item']) {+ final terminal = ink([+ ' see https://a.example/one-two-x',+ ' $marker',+ ]);+ expect(+ terminalLinkAt(terminal, const CellOffset(8, 0)),+ 'https://a.example/one-two-x',+ reason: marker,+ );+ }+ });++ test('only ever assembles web URLs this way', () {+ final terminal = ink([+ ' /tmp/a-very-long-folder-name/prev',+ ' iew.png',+ ], width: 36);+ expect(terminalLinkAt(terminal, const CellOffset(6, 0)), isNull);+ expect(+ terminalLinkAt(terminal, const CellOffset(4, 1)),+ isNot('/tmp/a-very-long-folder-name/preview.png'),+ );+ });++ // Two byte streams a tmux client received from a real Claude Code+ // session on a 44-column pane (scripts: ask for the address, capture the+ // attach). They are what the pane in the app actually sees.+ for (final (name, expected) in [+ (+ 'claude_code_44col_response',+ {+ // The prompt box, one paint throughout, padded with spaces.+ const CellOffset(10, 10): url,+ const CellOffset(10, 11): url,+ // The reply, address painted, broken after the slash.+ const CellOffset(30, 15): url,+ const CellOffset(10, 16): url,+ const CellOffset(10, 18): 'https://github.com/NVIDIA/Isaac-GR00T',+ },+ ),+ (+ 'claude_code_44col_tool_result',+ {+ // The tool call, wider than the tool result right under it.+ const CellOffset(30, 11): '$url/extra/long/path/segment',+ // The tool result, three painted rows.+ const CellOffset(30, 13): '$url/extra/long/path/segment',+ const CellOffset(10, 14): '$url/extra/long/path/segment',+ const CellOffset(10, 15): '$url/extra/long/path/segment',+ },+ ),+ ]) {+ test('reads the addresses in the $name capture', () {+ final bytes = File('test/fixtures/$name.bin').readAsBytesSync();+ final terminal = Terminal()..resize(44, 30);+ terminal.write(utf8.decode(bytes, allowMalformed: true));+ for (final MapEntry(key: cell, value: target) in expected.entries) {+ expect(terminalLinkAt(terminal, cell), target, reason: '$cell');+ }+ });+ }++ test('gives up on a URL that spans too many rows', () {+ final rows = [+ ' https://a.example/${'x' * 16}',+ for (var i = 0; i < 9; i++) ' ${'y' * 34}',+ ];+ final terminal = ink(rows, width: 36);+ expect(terminalLinkAt(terminal, const CellOffset(4, 0)), isNull);+ });+ });}diff --git a/desktop/test/terminal_panel_links_test.dart b/desktop/test/terminal_panel_links_test.dartindex a9e628f5b..d46006fc9 100644--- a/desktop/test/terminal_panel_links_test.dart+++ b/desktop/test/terminal_panel_links_test.dart@@ -139,11 +139,11 @@ void main() {});}- Offset point(WidgetTester tester, [int column = 6]) {+ Offset point(WidgetTester tester, [int column = 6, int row = 0]) {final view = tester.state<TerminalViewState>(find.byType(TerminalView));final render = view.renderTerminal;return render.localToGlobal(- render.getOffset(CellOffset(column, 0)) ++ render.getOffset(CellOffset(column, row)) +Offset(render.cellSize.width / 2, render.cellSize.height / 2),);}@@ -442,4 +442,47 @@ void main() {await tester.pump(const Duration(milliseconds: 350));},);+ testOnPlatform(+ 'a URL the agent hard-wrapped across rows opens whole from either row',+ (tester) async {+ await mount(tester);+ // Claude Code (Ink) cuts a long address at its box width and writes the+ // rest on its own row, indented like the box — two rows, one link.+ session.terminal.write(+ '\r\x1b[2K Command Code here: https://commandc'+ '\r\n\x1b[2K ode.ai/0xkongamoto/settings/billing',+ );+ await tester.pump();+ const url = 'https://commandcode.ai/0xkongamoto/settings/billing';+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);+ await mouse.addPointer(location: Offset.zero);+ await mouse.moveTo(point(tester, 10, 1));+ await tester.pump();+ expect(+ tester+ .widget<Tooltip>(+ find.ancestor(+ of: find.byType(TerminalView),+ matching: find.byType(Tooltip),+ ),+ )+ .message,+ '⌘-click to open\n$url',+ );+ await tester.sendKeyDownEvent(+ LogicalKeyboardKey.metaLeft,+ platform: 'macos',+ );+ await tester.tapAt(point(tester, 10, 1), kind: PointerDeviceKind.mouse);+ await tester.sendKeyUpEvent(+ LogicalKeyboardKey.metaLeft,+ platform: 'macos',+ );+ await tester.pump(const Duration(milliseconds: 350));+ expect(launched.single.toString(), url);+ expect(outbound, isEmpty);+ await mouse.removePointer();+ await tester.pump(const Duration(milliseconds: 350));+ },+ );}diff --git a/docs/vi/autonomous-device-integration_vi.md b/docs/vi/autonomous-device-integration_vi.mddeleted file mode 100644index 172473785..000000000--- a/docs/vi/autonomous-device-integration_vi.md+++ /dev/null@@ -1,111 +0,0 @@-# Autonomous device ↔ Mac trực tiếp--Mac tự tìm Autonomous OS qua service Avahi `_autonomous._tcp` đang có, dùng bonjour-service-browse ba giây. Không nhập IP, không backend relay hoặc credential cloud trên thiết bị. Giữ-login/start của Harness Mac như cũ; daemon đang chạy vẫn pair/điều khiển khi backend offline.-Buddy không dùng và không sửa.--```sh-harness autonomous-device discover --json-harness autonomous-device pair --device '<discovery-id>' --code-stdin-harness autonomous-device status --json-harness autonomous-device list --json-harness autonomous-device revoke '<full fingerprint>'-```--Thiết bị sinh/hiển thị mã; Desktop chọn thiết bị tìm thấy rồi ghi mã vào stdin của CLI, không argv/log.-Discovery trả `{devices:[{id,name,host,port}]}`. CLI dial trực tiếp-`ws://<host>:<SRV-port>/api/harness/ws`, dùng đúng port quảng bá (có thể80), nginx chuyển Upgrade-cho route đó. Không hardcode5000, không thêm Avahi/script. Frame đầu machine_select payload-machineId/label; OS trả machine_selected và e2e_pair_intent nếu đang pair. Sau mã nhập đúng, chạy-PAKE và e2e_hello/welcome gốc; CLI chờ session đúng identity trước báo paired.--Không listener Mac mới, custom handshake/trust store, role mới hay backend onboarding. Inbound-trực tiếp chỉ nhận PAKE/cancel/hello/status cần thiết và app RPC; không setup token/remote password,-terminal/admin. Intent/PAKE chỉ được nhận trong lần pair chủ động. Backend offline không xóa-direct session hoặc cho phép pair nhầm browser slot.--Metadata `${ADAPTER_DATA_DIR}/autonomous-device-connections.json` chỉ lưu discoveryId/fingerprint;-key/pin vẫn ở E2eeManager/paired.json gốc. Mỗi15giây tìm lại thiết bị đã lưu và reconnect. Publickey-reconnect phải đúng fingerprint association; mDNS không cấp quyền. Revoke đóng socket và bỏ-association, không ảnh hưởng browser/dial khác. Sai mã đóng attempt để lần sau có socket/intent mới.-Chỉ app hello đã xác thực mới bật recap/notification.--Facade loopback có credential: GET discover; POST pair/start `{code,device}`; GET pair/status;-GET status (transport direct); GET list (id là fingerprint, khác discoveryId); POST revoke `{id}`;-GET receipt query deviceId canonical publickey và idempotencyKey. Không listen/address/replace/all.--Khi device tự revoke trust cục bộ, nó gửi application request đã xác thực-`{type:"pair.revoke",requestId}` và đợi `pair.revoke_result` trước khi đóng socket. CLI sẽ xóa đúng-identity đó cùng metadata reconnect. Socket chỉ đóng mà không có request này vẫn là `offline`, không-được hiểu là revoke, để lỗi mạng thoáng qua không unpair device.--Wire dùng nguyên e2e_* gốc role device, CI b:device. App outer autonomous_device_request/result/event-vẫn pairwise encrypted với empty dbSessionId AAD; helper relay.ts chỉ là adapter ứng dụng dùng chung-crypto, không kết nối backend. Request agents.list/status/recap/turn.send/turn.stop/question.answer/-receipt.get giữ target rõ và receipt/dedupe. Không replay mutation khi mất kết nối; unknown không-có nghĩa chưa gửi. Cache512/ring500 và schema đầy đủ ở [bản EN](../autonomous-device-integration.md).--## Focus của app cho voice--CLI quảng bá capability `focus.get`; request `{type:"focus.get",requestId}` trả-`{type:"focus.get_result",requestId,focus:null|{machineId,agentId,name?},focusRevision}`.-Event `focus.changed` có payload `{focus,focusRevision}` cùng schema. Monitor Pairing hiển thị-snapshot này; OS có thể poll để phục hồi khi bỏ lỡ event.--Nguồn focus là frame local tường minh `app_focus {agentId}` từ Desktop, không phải `terminal_open`.-Ban đầu focus là null. `app_focus {agentId:null}` hoặc đóng socket đang sở hữu focus sẽ xóa focus;-socket cũ không được xóa focus của socket mới. Mỗi thay đổi focus đổi revision, kể cả A→B→A; thông báo lại cùng target giữ nguyên revision-nhưng chuyển quyền sở hữu sang socket thông báo;-revision là chuỗi opaque có server instance ID nên khác sau restart. Khi đọc snapshot, agent local-đã bị xóa làm focus thành null và đổi revision. Focus máy remote giữ đúng machine ID remote;-facade device chỉ hỗ trợ máy đã pair, không thay bằng agent local hoặc tự relay task.--`turn.send` và `question.answer` nhận `focusRevision` tùy chọn bên cạnh target ID tường minh.-Sau bước kiểm tra receipt trùng, service kiểm tra đồng bộ revision và target trước khi reserve/gửi.-Sai revision hoặc target trả `FOCUS_CHANGED` không receipt: request đó chưa dispatch. Request trùng-đã reserve vẫn trả receipt cũ dù focus đổi. Client cũ không truyền revision vẫn dùng target tường minh-như trước. `turn.stop` không nhận trường này, tiếp tục nhắm target của lượt đang chạy.--`turn.summary` và mỗi phần tử `recap.turns[]` mang ba mức của cùng một câu trả lời; bên tiêu thụ nên-ưu tiên `turns[].fullText`, rồi `turn.summary.fullText`, rồi `text`:--| Trường | Giới hạn | Là gì |-|---|---|---|-| `recap` | 60 ký tự | câu văn xuôi đầu tiên — tiêu đề ô tile |-| `text` | 250 ký tự | câu trả lời bị làm phẳng một dòng rồi cắt — để liếc |-| `fullText` | 8192 byte UTF-8 | tin nhắn cuối của agent đúng như hiện trên màn hình, giữ markdown và xuống dòng |--`fullText` là tuỳ chọn, vắng mặt khi chưa ghi được câu trả lời nào, nên phải đọc phòng thủ. Nó chỉ chứa-phản hồi cuối hướng tới người dùng — không có transcript tool, suy luận ẩn hay output terminal — và-không tốn thêm lần gọi model: đó chính là văn bản mà bộ tóm tắt cục bộ vốn đã nhận.--Trần 8192 byte là phép tính chứ không phải khẩu vị: socket direct nhận 65536 byte, `recap` có thể trả-năm lượt một lần, và payload đã seal phình khoảng 37% qua AEAD và base64. Cắt vượt trần là cắt an toàn-UTF-8, kèm `…` ở cuối. `text` và `recap` giữ nguyên từng byte, và card `commander_event` dùng chung-không bị nới — encoder của dial USB ném lỗi khi frame vượt 8 KiB, nên trường này chỉ thêm vào event do-service này phát ra.--Typecheck/focused test đã đạt gồm chỉ chọn discovery, retry socket mới, chờ authenticated identity-và từ chối reconnect giả mạo. Real mDNS/direct Go OS ↔ CLI đã đạt khi backend chưa từng kết nối: discovery SRV, sai mã/retry,-PAKE/session, encrypted list/send/dedupe, restart/reconnect và revoke/unpair. Status chỉ đếm direct-session đã xác thực và app-ready, không đếm socket thô. Full CLI đã đạt với-`npm test -- --maxWorkers=1 --testTimeout=30000 --hookTimeout=30000`: 144 file / 1.871 test pass,-5 file / 50 test skip; `npm run typecheck` đạt. Lần chạy deadline mặc định 5 giây bị timeout ở-các test password/scrypt sẵn có khi máy chịu tải. Chỉ đổi deadline qua lệnh chạy serial, không-sửa test hoặc cấu hình để né lỗi. Không deploy hoặc pair thiết bị thật.--### Agent mặc định khi bật mode--Capability tùy chọn `focus.ensure` nhận `{type:"focus.ensure",requestId}` và trả cùng snapshot-`{focus,focusRevision}` như `focus.get`. Nếu app đã có focus thì giữ nguyên, kể cả máy remote;-OS vẫn từ chối target remote chưa được hỗ trợ. Nếu chưa có focus, CLI yêu cầu một cửa sổ Desktop-local chọn agent đầu tiên theo thứ tự `agents.list`, dùng flow chọn pane hiện có. Desktop đang có-lựa chọn sẽ gửi lại focus đó thay vì thay đổi. Chỉ xác nhận `app_focus` mới thiết lập target chính thức;-không gửi task hay tự đặt target khi không có app.-Các request đồng thời dùng chung lần chờ tối đa hai giây. Không có agent trả `NO_AGENTS`; không có-cửa sổ hoặc không nhận xác nhận trả `FOCUS_UNAVAILABLE`. Frame local `device_focus` có thời hạn để-request đến trễ không mở pane sau khi hết thời gian chờ. Chỉ gọi khi bật voice mode, không gọi giữa-utterance để tự đổi target. CLI cũ chưa có capability cần chọn agent trong app. Pairing, đọc focus,-event và dispatch task thông thường giữ nguyên.-Xác nhận focus tự động mang revision ban đầu; CLI bỏ qua nếu user đã chọn focus mới trong lúc request đang truyền.