@yu_robotics/remote-cli-router 1.6.169 → 1.6.172

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,8 +6,6 @@ Backend executable discovery is local-client behavior. CLI 1.6.119 supplements L
6
6
 
7
7
  ## Public Activity
8
8
 
9
- From Router 1.6.169, reply-card thread lists start collapsed. Use **Show threads** to expand the list in the same card, or **Switch to this thread** to select the thread that produced the reply. Opening or hiding the list does not change the input target; a successful switch hides the list and confirms the new target without changing the reply's source label. No separate thread-management card is sent. The recursive element budget is 180 instead of 150, with room reserved for the expanded controls; table and size thresholds are unchanged. This presentation update requires the newer Router, not a new CLI protocol capability.
10
-
11
9
  From Router 1.6.158, completion pagination keeps the final body item (or complete worker group) with the completion note, optional model metadata and thread controls when they fit together. This avoids preventable footer-only continuations, including replies without model metadata. Indivisible oversized groups still split according to node, size and table limits; thread-button refreshes preserve the final body. This does not change streaming completion timing or the wire protocol.
12
10
 
13
11
  From CLI 1.6.153, Codex shell calls no longer lose their label when native command actions are absent or unknown. Native reads, searches, and directory listings remain preferred. Other calls use fixed operation labels such as `Run npm command` or `Run Git command` for simple allowlisted programs, and `Run shell command` for compound or unrecognized commands. These are deterministic operation labels, not model-authored purpose summaries: installed Codex 0.160.0 command items have no per-call description field. Arguments, full paths, output, and execution-wide reasoning are never copied into these fallback labels. Late native action metadata can enrich a pending row before its first result; repeated results retain one row. Existing description fields, heading limits, and card-node counts are unchanged; upgrade the CLI, with no new Router capability required.
@@ -398,6 +396,21 @@ Use one Router for multiple trusted clients. Each client connects from the devel
398
396
 
399
397
  Thread switch panels show `Reply from:` with the reply's full thread name and workspace. Under `Switch thread`, a check mark (`✓`) and primary button styling identify the destination of new top-level messages when the card is finalized or clicked. Selected buttons remain clickable. Switching updates only the clicked card; other historical cards retain their last displayed selection.
400
398
 
399
+ From Router 1.6.171, completed cards keep the thread buttons and **+ New** inside a native Feishu **Switch thread** folding panel, collapsed by default. Click its header to expand or collapse the list without sending a command or changing the input target. The reply-source caption remains visible. Selecting a thread uses the existing routing behavior. Hidden buttons still count toward card limits; unrelated full-card updates can reset the panel to its default collapsed state. This uses the existing Card 2.0 client requirement (Feishu 7.20 or newer).
400
+
401
+ From CLI 1.6.172, Codex threads support native goals through `/goal` (status), `/goal <objective>` (start), `/goal pause`, `/goal resume`, and `/goal clear`. Start or resume only when the thread and queue are idle, with managed delegation explicitly disabled using `/delegation off`. This initial restriction does not disable Codex's native subagents. Optional `--budget <tokens>` on start or resume sets an explicit positive token budget; omitting it does not invent a budget. For example:
402
+
403
+ ```text
404
+ /delegation off
405
+ /goal --budget 40000 Fix the failing tests and verify the public API stays compatible
406
+ /goal
407
+ /goal pause
408
+ /goal resume
409
+ /goal clear
410
+ ```
411
+
412
+ Codex owns the persisted goal and automatic continuations; remote-cli keeps the execution card, approvals, and busy-state reservation across native turns. Status, pause, clear, and `/abort` remain available during work. Pause and clear stop current goal work; `/abort` pauses the goal, while clear removes the goal without clearing the conversation. After process loss, inspect with `/goal` and explicitly recover with `/goal resume`; status queries do not load or start the goal. Send attachments in an ordinary message before starting a goal. Use a Codex build exposing the native thread-goal APIs (verified with 0.163.0); unavailable APIs or disabled goals report an error. Other backends reject `/goal`. See [the native goal API](https://learn.chatgpt.com/docs/app-server#manage-a-thread-goal).
413
+
401
414
  When a client thread is busy, the Router sends a confirmation card before accepting another message into its queue. `/queue` shows queue state, `/queue clear` discards queued messages, and `/abort` stops the active task and clears that thread's queue. Messages received while abort cleanup is in progress wait for the client backend to become safe before execution starts.
402
415
 
403
416
  ## Expert Usage
@@ -84,8 +84,6 @@ export declare class FeishuLongConnHandler {
84
84
  * RouterServer sets this directly after construction.
85
85
  */
86
86
  onCardNewThread?: (openId: string) => Promise<void>;
87
- /** Latest device-reported inventory; missing inventory fails closed for new controls. */
88
- onCardThreadExists?: (deviceId: string, threadId: string) => boolean;
89
87
  /** Callback invoked when a user confirms or cancels a queued command. */
90
88
  onApprovalAction?: (openId: string, requestId: string, cardId: string, decision: string) => Promise<string>;
91
89
  onMaintenanceAction?: (openId: string, id: string, cardId: string, action: string, offset?: number) => Promise<string>;
@@ -229,7 +227,7 @@ export declare class FeishuLongConnHandler {
229
227
  * Split Card 2.0 elements into chunks based on Feishu limits
230
228
  *
231
229
  * Card packing budgets:
232
- * 1. Element count: Max 200 tagged nodes per card (we use 180 for safety)
230
+ * 1. Element count: Max 200 tagged nodes per card (we use 150 for safety)
233
231
  * 2. Data size: Max 3,000,000 characters in the data field (JSON.stringify result)
234
232
  * 3. Tables: A conservative budget including tables embedded in Markdown
235
233
  *
@@ -318,16 +316,10 @@ export declare class FeishuLongConnHandler {
318
316
  private _finalizeStreamingMessage;
319
317
  /**
320
318
  * Create Feishu Card 2.0 elements for thread switching buttons.
321
- * Renders one button per thread (active is highlighted) plus a "+ New" button,
322
- * split across rows so desktop clients do not compress every button into one line.
319
+ * Native expansion needs no callback or server update. Hidden button rows still
320
+ * count towards the card budget, and retain their existing switching callbacks.
323
321
  */
324
322
  private createThreadSwitchElements;
325
- /** The source action never accepts a target from the callback payload. */
326
- private createThreadSelectorElements;
327
- /** Caller owns the root message lock. Commit UI state only after a successful patch. */
328
- private patchThreadSelector;
329
- private assertThreadSelectorBudget;
330
- private handleThreadSelector;
331
323
  private threadButtonLabel;
332
324
  private createResponseHeaderElements;
333
325
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"FeishuLongConnHandler.d.ts","sourceRoot":"","sources":["../../src/feishu/FeishuLongConnHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAA4B,aAAa,EAAc,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtG,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIxE,OAAO,EAAE,SAAS,EAAE,MA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AG,OAAO,CAAC,IAAI,CAAC;IAc7E;;;OAGG;IACG,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC;QAAE,KAAK,CAAC,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI,CAAC;IAyGlE;;;OAGG;IACG,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzG,qFAAqF;IAC/E,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,mBAAmB,CAAC;IAoDnL,yEAAyE;IACnE,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAahE,OAAO,CAAC,8BAA8B;YASxB,2BAA2B;IAsBzC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4C5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B3B;;OAEG;IACH,iBAAiB,IAAI,cAAc;CAGpC"}
@@ -62,8 +62,9 @@ class FeishuLongConnHandler {
62
62
  // Feishu message size limit (4000 chars per message) - DEPRECATED for Card 2.0
63
63
  FEISHU_MESSAGE_LIMIT = 4000;
64
64
  // Feishu Card 2.0 limits (from official docs)
65
- // Keep headroom while counting nested text, icons, and container nodes.
66
- CARD_ELEMENT_LIMIT = 180;
65
+ // Note: Using conservative limits - official says 200, we use 150 with proper recursive counting
66
+ // The 150 limit leaves a 50-node safety buffer while still being practical
67
+ CARD_ELEMENT_LIMIT = 150; // Conservative: 150 tagged nodes per card (official: 200)
67
68
  CARD_DATA_SIZE_LIMIT = 3000000; // Max 3MB (3,000,000 chars) for data field
68
69
  CARD_SIZE_BUFFER = 100000; // Safety buffer: use 2.9MB instead of 3MB
69
70
  THREAD_BUTTONS_PER_ROW = 3;
@@ -139,8 +140,6 @@ class FeishuLongConnHandler {
139
140
  * RouterServer sets this directly after construction.
140
141
  */
141
142
  onCardNewThread;
142
- /** Latest device-reported inventory; missing inventory fails closed for new controls. */
143
- onCardThreadExists;
144
143
  /** Callback invoked when a user confirms or cancels a queued command. */
145
144
  onApprovalAction;
146
145
  onMaintenanceAction;
@@ -694,6 +693,7 @@ Backend and session commands (sent to active device):
694
693
  /files [clear] - List staged attachments or remove unused local copies
695
694
  /model [name] - Show models or set this thread's model
696
695
  /effort [auto|low|medium|high] - Show or set Codex/AGY reasoning effort
696
+ /goal [objective|pause|resume|clear] - Manage a native Codex goal; /goal help shows budget options
697
697
  /delegation [on|off] - Delegate between installed agent backends in the current thread
698
698
  /backend - List backends and show the current thread's effective backend
699
699
  /backend <index> - Switch all threads and clear per-thread backend overrides
@@ -990,7 +990,7 @@ Examples:
990
990
  * Split Card 2.0 elements into chunks based on Feishu limits
991
991
  *
992
992
  * Card packing budgets:
993
- * 1. Element count: Max 200 tagged nodes per card (we use 180 for safety)
993
+ * 1. Element count: Max 200 tagged nodes per card (we use 150 for safety)
994
994
  * 2. Data size: Max 3,000,000 characters in the data field (JSON.stringify result)
995
995
  * 3. Tables: A conservative budget including tables embedded in Markdown
996
996
  *
@@ -1127,8 +1127,7 @@ Examples:
1127
1127
  if (obj.tag) {
1128
1128
  count = 1;
1129
1129
  }
1130
- // WorkerContextCards.decorate can add one error row after pagination, including
1131
- // on a later reset failure. Already-decorated rows must not be counted twice.
1130
+ // Worker controls may acquire an error row after pagination or on a later refresh.
1132
1131
  const controlElements = obj.columns?.[0]?.elements;
1133
1132
  if (reserveWorkerErrors && typeof obj.element_id === 'string' && obj.element_id.startsWith('wc_')
1134
1133
  && controlElements?.[0]?.behaviors?.[0]?.value?.action === 'worker_context_clear'
@@ -1311,7 +1310,7 @@ Examples:
1311
1310
  return this._updateStreamingMessage(messageId, [...headerElements, ...elements], openId, headerElements);
1312
1311
  });
1313
1312
  }
1314
- async _updateStreamingMessage(messageId, elements, openId, continuationHeaderElements = [], trailingElements = [], keepCompletionWithBody = false, selectorRender) {
1313
+ async _updateStreamingMessage(messageId, elements, openId, continuationHeaderElements = [], trailingElements = [], keepCompletionWithBody = false) {
1315
1314
  let updatingMessageId = messageId;
1316
1315
  let updatingCardIndex = 0;
1317
1316
  try {
@@ -1324,10 +1323,7 @@ Examples:
1324
1323
  // Split elements into chunks based on Feishu Card 2.0 limits
1325
1324
  const shell = this.activityShells.get(messageId);
1326
1325
  const activityTail = shell && shell.finishedAt === undefined ? (0, ActivityProgress_1.createActivityElement)(shell.activity) : undefined;
1327
- const packed = this.splitElementsIntoChunks(elements, continuationHeaderElements, trailingElements, activityTail, keepCompletionWithBody);
1328
- // Pack the expanded controls, but initially deliver the compact footer on the same page.
1329
- const chunks = selectorRender ? packed.map(chunk => chunk.flatMap(element => element === selectorRender.expanded[0] ? selectorRender.collapsed
1330
- : selectorRender.expanded.includes(element) ? [] : [element])) : packed;
1326
+ const chunks = this.splitElementsIntoChunks(elements, continuationHeaderElements, trailingElements, activityTail, keepCompletionWithBody);
1331
1327
  const tailIndex = activityTail ? chunks.length - 1 : -1;
1332
1328
  console.log(`[FeishuHandler] Need ${chunks.length} card(s), currently have ${chain.length} card(s)`);
1333
1329
  let hashes = this.cardContentHashes.get(messageId);
@@ -1500,8 +1496,6 @@ Examples:
1500
1496
  }
1501
1497
  // Append thread switch buttons when at least one thread exists
1502
1498
  let threadSwitchElements = [];
1503
- let selector;
1504
- let selectorRender;
1505
1499
  // The reply's owner and the destination of new messages are independent.
1506
1500
  const activeThreadId = (openId ? this.onResolveActiveThread?.(openId)?.threadId : undefined)
1507
1501
  ?? threads?.find(thread => thread.name === 'default')?.id;
@@ -1512,18 +1506,14 @@ Examples:
1512
1506
  ? [replyThreadName, replyWorkspace].filter(Boolean).join(' · ')
1513
1507
  : undefined;
1514
1508
  if (!bare && threads && threads.length >= 1) {
1515
- selector = { id: (0, uuid_1.v4)(), owner: openId ?? '', deviceId: this.onResolveThread?.(messageId)?.deviceId,
1516
- rootId: messageId, replyThreadId, expanded: false };
1517
- const state = { threads, activeThreadId, replyLabel, selector };
1518
- threadSwitchElements = this.createThreadSelectorElements(state, true);
1519
- selectorRender = { expanded: threadSwitchElements, collapsed: this.createThreadSelectorElements(state, false) };
1509
+ threadSwitchElements = this.createThreadSwitchElements(threads, activeThreadId, replyLabel);
1520
1510
  finalElements.push(...threadSwitchElements);
1521
1511
  }
1522
1512
  // Reuse streaming update logic: only create cards, never delete.
1523
1513
  // Repack changed previews and clear obsolete tool copies without retracting messages.
1524
1514
  const trailingElements = !queueConfirmation ? [...footerElements, ...threadSwitchElements] : threadSwitchElements;
1525
1515
  const keepCompletionWithBody = !bare && !queueConfirmation;
1526
- const updated = await this._updateStreamingMessage(messageId, finalElements, openId, headerElements, trailingElements, keepCompletionWithBody, selectorRender);
1516
+ const updated = await this._updateStreamingMessage(messageId, finalElements, openId, headerElements, trailingElements, keepCompletionWithBody);
1527
1517
  if (!updated) {
1528
1518
  return false;
1529
1519
  }
@@ -1547,7 +1537,6 @@ Examples:
1547
1537
  threads,
1548
1538
  activeThreadId,
1549
1539
  replyLabel,
1550
- selector,
1551
1540
  createdAt: Date.now(),
1552
1541
  });
1553
1542
  }
@@ -1566,8 +1555,8 @@ Examples:
1566
1555
  }
1567
1556
  /**
1568
1557
  * Create Feishu Card 2.0 elements for thread switching buttons.
1569
- * Renders one button per thread (active is highlighted) plus a "+ New" button,
1570
- * split across rows so desktop clients do not compress every button into one line.
1558
+ * Native expansion needs no callback or server update. Hidden button rows still
1559
+ * count towards the card budget, and retain their existing switching callbacks.
1571
1560
  */
1572
1561
  createThreadSwitchElements(threads, activeThreadId, replyLabel) {
1573
1562
  const orderedThreads = this.orderThreadsForDisplay(threads);
@@ -1608,95 +1597,22 @@ Examples:
1608
1597
  columns: columns.slice(index, index + this.THREAD_BUTTONS_PER_ROW),
1609
1598
  });
1610
1599
  }
1611
- const caption = {
1612
- tag: 'markdown',
1613
- content: replyLabel ? `📍 **Reply from:** ${replyLabel}\n🗂️ **Switch thread**` : '🗂️ **Switch thread**',
1614
- };
1615
- return [{ tag: 'hr' }, caption, ...rows];
1616
- }
1617
- /** The source action never accepts a target from the callback payload. */
1618
- createThreadSelectorElements(state, expanded) {
1619
- const selector = state.selector;
1620
- const button = (text, op, disabled = false) => ({ tag: 'column', width: 'auto', elements: [{
1621
- tag: 'button', text: { tag: 'plain_text', content: text }, type: 'default', disabled,
1622
- behaviors: [{ type: 'callback', value: { action: 'thread_selector', id: selector.id, op } }],
1623
- }] });
1624
- const controls = { tag: 'column_set', flex_mode: 'stretch', columns: [
1625
- button('Switch to this thread', 'source', !selector.replyThreadId || !selector.owner || !selector.deviceId),
1626
- button(expanded ? 'Hide threads' : 'Show threads', expanded ? 'hide' : 'show'),
1627
- ] };
1628
- const full = this.createThreadSwitchElements(state.threads, state.activeThreadId, state.replyLabel);
1629
- if (!expanded)
1630
- return [...full.slice(0, 2), controls];
1631
- for (const row of full.slice(2))
1632
- for (const column of row.columns) {
1633
- const action = column.elements[0].behaviors[0].value;
1634
- column.elements[0].behaviors[0].value = action.action === 'new_thread'
1635
- ? { action: 'thread_selector', id: selector.id, op: 'new' }
1636
- : { action: 'thread_selector', id: selector.id, op: 'select', offset: state.threads.findIndex(thread => thread.id === action.threadId) };
1637
- }
1638
- return [...full.slice(0, 2), controls, ...full.slice(2)];
1639
- }
1640
- /** Caller owns the root message lock. Commit UI state only after a successful patch. */
1641
- async patchThreadSelector(cardId, state, expanded, activeThreadId = state.activeThreadId) {
1642
- const next = { ...state, activeThreadId, selector: { ...state.selector, expanded } };
1643
- const elements = [...state.baseElements, ...this.createThreadSelectorElements(next, expanded)];
1644
- if (this.checkIfElementsNeedSplitting(elements))
1645
- throw new Error('Thread controls exceed this card budget.');
1646
- await this.sendCardRequest(JSON.stringify({ schema: '2.0', body: { elements } }), async (content) => {
1647
- this.assertThreadSelectorBudget(content);
1648
- const result = await this.client.im.message.patch({ path: { message_id: cardId }, data: { content } });
1649
- if (!result?.code)
1650
- this.workerContexts?.remember(cardId, next.selector.rootId, content);
1651
- return result;
1652
- });
1653
- this.threadSwitchCardState.set(cardId, next);
1654
- }
1655
- assertThreadSelectorBudget(content) {
1656
- if (this.countTaggedNodes(JSON.parse(content)) > this.CARD_ELEMENT_LIMIT) {
1657
- throw new Error('Thread controls exceed this card budget after decoration.');
1658
- }
1659
- }
1660
- async handleThreadSelector(openId, cardId, action) {
1661
- const error = (content) => ({ toast: { type: 'error', content } });
1662
- if (typeof cardId !== 'string')
1663
- return error('This thread selector is unavailable.');
1664
- const rootId = this.threadSwitchCardState.get(cardId)?.selector?.rootId ?? cardId;
1665
- return this.withMessageLock(rootId, async () => {
1666
- const state = this.threadSwitchCardState.get(cardId);
1667
- const selector = state?.selector;
1668
- if (!state || !selector || selector.id !== action.id || selector.owner !== openId
1669
- || Date.now() - state.createdAt >= this.THREAD_SWITCH_STATE_TTL_MS)
1670
- return error('This thread selector has expired or belongs to another card.');
1671
- let switched;
1672
- try {
1673
- const device = await this.bindingManager.getActiveDevice(openId);
1674
- if (!selector.deviceId || device?.deviceId !== selector.deviceId)
1675
- return error('Select the original device before using this card.');
1676
- if (action.op === 'show' || action.op === 'hide') {
1677
- await this.patchThreadSelector(cardId, state, action.op === 'show', this.onResolveActiveThread?.(openId)?.threadId);
1678
- return { toast: { type: 'info', content: action.op === 'show' ? 'Threads shown. Input target unchanged.' : 'Threads hidden. Input target unchanged.' } };
1679
- }
1680
- if (action.op === 'new') {
1681
- if (!selector.expanded || state.threads.length >= types_1.MAX_THREADS || !this.onCardNewThread)
1682
- return error('New thread is unavailable.');
1683
- await this.onCardNewThread(openId);
1684
- return { toast: { type: 'info', content: 'Creating new thread...' } };
1685
- }
1686
- const target = action.op === 'source' ? state.threads.find(thread => thread.id === selector.replyThreadId)
1687
- : action.op === 'select' && selector.expanded && Number.isInteger(action.offset) && action.offset >= 0
1688
- ? state.threads[action.offset] : undefined;
1689
- if (!target || !this.onCardThreadExists?.(selector.deviceId, target.id) || !this.onCardSwitchThread)
1690
- return error('This thread is no longer available.');
1691
- await this.onCardSwitchThread(openId, target.id, target.name);
1692
- switched = target.name;
1693
- await this.patchThreadSelector(cardId, state, false, target.id);
1694
- return { toast: { type: 'success', content: `Input target: ${target.name}` } };
1695
- }
1696
- catch {
1697
- return error(switched ? `Input target changed to ${switched}, but the card could not refresh. Try Hide threads again.` : 'Thread action failed. Please try again.');
1698
- }
1699
- });
1600
+ return [
1601
+ { tag: 'hr' },
1602
+ ...(replyLabel ? [{ tag: 'markdown', content: `📍 **Reply from:** ${replyLabel}` }] : []),
1603
+ {
1604
+ tag: 'collapsible_panel',
1605
+ element_id: 'thread_controls',
1606
+ expanded: false,
1607
+ header: {
1608
+ title: { tag: 'plain_text', content: 'Switch thread' },
1609
+ icon: { tag: 'standard_icon', token: 'down-small-ccm_outlined', size: '16px 16px' },
1610
+ icon_position: 'right',
1611
+ icon_expanded_angle: -180,
1612
+ },
1613
+ elements: rows,
1614
+ },
1615
+ ];
1700
1616
  }
1701
1617
  threadButtonLabel(thread, active) {
1702
1618
  const details = [
@@ -1793,17 +1709,13 @@ Examples:
1793
1709
  * Re-patches the card with updated button states (new active thread highlighted).
1794
1710
  */
1795
1711
  async refreshThreadSwitchButtons(cardMessageId, newActiveThreadId) {
1796
- const rootId = this.threadSwitchCardState.get(cardMessageId)?.selector?.rootId ?? this.workerContexts?.rootFor(cardMessageId) ?? cardMessageId;
1712
+ const rootId = this.workerContexts?.rootFor(cardMessageId) ?? cardMessageId;
1797
1713
  await this.withMessageLock(rootId, async () => {
1798
1714
  const state = this.threadSwitchCardState.get(cardMessageId);
1799
1715
  if (!state) {
1800
1716
  console.warn(`[FeishuHandler] No thread switch state found for card ${cardMessageId}`);
1801
1717
  return;
1802
1718
  }
1803
- if (state.selector) {
1804
- await this.patchThreadSelector(cardMessageId, state, false, newActiveThreadId);
1805
- return;
1806
- }
1807
1719
  const updatedElements = [
1808
1720
  ...state.baseElements,
1809
1721
  ...this.createThreadSwitchElements(state.threads, newActiveThreadId, state.replyLabel),
@@ -1823,8 +1735,6 @@ Examples:
1823
1735
  if (!content)
1824
1736
  return;
1825
1737
  await this.sendCardRequest(content, async (body) => {
1826
- if (this.threadSwitchCardState.get(cardId)?.selector)
1827
- this.assertThreadSelectorBudget(body);
1828
1738
  const result = await this.client.im.message.patch({ path: { message_id: cardId }, data: { content: body } });
1829
1739
  if (!result?.code)
1830
1740
  this.workerContexts?.remember(cardId, rootId, body);
@@ -1850,15 +1760,6 @@ Examples:
1850
1760
  catch {
1851
1761
  return;
1852
1762
  }
1853
- if (!parsed || typeof parsed !== 'object' || typeof parsed.action !== 'string')
1854
- return;
1855
- if (parsed.action === 'thread_selector')
1856
- return this.handleThreadSelector(openId, data?.context?.open_message_id, parsed);
1857
- // New cards must not fall through to the legacy unbound callback contract.
1858
- if ((parsed.action === 'switch_thread' || parsed.action === 'new_thread')
1859
- && this.threadSwitchCardState.get(data?.context?.open_message_id)?.selector) {
1860
- return { toast: { type: 'error', content: 'Use this card’s thread controls.' } };
1861
- }
1862
1763
  if (parsed.action === 'settings') {
1863
1764
  const cardId = data?.context?.open_message_id;
1864
1765
  if (typeof parsed.id !== 'string' || typeof cardId !== 'string' || !this.settingsCards) {
@@ -1908,25 +1809,6 @@ Examples:
1908
1809
  return { toast: { type: 'error', content: error instanceof Error ? error.message : 'Approval failed.' } };
1909
1810
  }
1910
1811
  }
1911
- // Legacy cards remain usable while their original state is present. A new Router
1912
- // must not let expired/unknown cards bypass the bound selector via legacy actions.
1913
- if ((parsed.action === 'switch_thread' || parsed.action === 'new_thread') && this.onCardThreadExists) {
1914
- const cardId = data?.context?.open_message_id;
1915
- const state = this.threadSwitchCardState.get(cardId);
1916
- const route = typeof cardId === 'string' ? this.onResolveThread?.(cardId) : undefined;
1917
- let device;
1918
- try {
1919
- device = await this.bindingManager.getActiveDevice(openId);
1920
- }
1921
- catch {
1922
- return { toast: { type: 'error', content: 'Thread action failed. Please try again.' } };
1923
- }
1924
- if (!state || Date.now() - state.createdAt >= this.THREAD_SWITCH_STATE_TTL_MS || !route
1925
- || device?.deviceId !== route.deviceId || (parsed.action === 'switch_thread'
1926
- && (!state.threads.some(thread => thread.id === parsed.threadId) || !this.onCardThreadExists(route.deviceId, parsed.threadId)))) {
1927
- return { toast: { type: 'error', content: 'This thread card is no longer available.' } };
1928
- }
1929
- }
1930
1812
  if (parsed.action === 'switch_thread' && parsed.threadId) {
1931
1813
  const openMessageId = data?.context?.open_message_id;
1932
1814
  try {
@@ -2031,17 +1913,15 @@ Examples:
2031
1913
  /** Leave a historical queue receipt after output moves to a new card. */
2032
1914
  async markQueueCardStarted(cardMessageId) {
2033
1915
  await this.queueCardDecisions.get(cardMessageId);
2034
- const rootId = this.threadSwitchCardState.get(cardMessageId)?.selector?.rootId ?? cardMessageId;
2035
- await this.withMessageLock(rootId, async () => {
2036
- const result = await this.client.im.message.patch({
2037
- path: { message_id: cardMessageId },
2038
- data: { content: JSON.stringify({ schema: '2.0', body: { elements: [{ tag: 'markdown',
2039
- content: '▶️ **Queued task started**\n\nFollow progress in the new execution card at the bottom of the chat.' }] } }) },
2040
- });
2041
- if (result?.code)
2042
- throw result;
2043
- this.threadSwitchCardState.delete(cardMessageId);
2044
- });
1916
+ await this.withMessageLock(cardMessageId, () => this.client.im.message.patch({
1917
+ path: { message_id: cardMessageId },
1918
+ data: {
1919
+ content: JSON.stringify({
1920
+ schema: '2.0',
1921
+ body: { elements: [{ tag: 'markdown', content: '▶️ **Queued task started**\n\nFollow progress in the new execution card at the bottom of the chat.' }] },
1922
+ }),
1923
+ },
1924
+ }));
2045
1925
  }
2046
1926
  removeExpiredQueueActionStates() {
2047
1927
  const expiry = Date.now() - this.QUEUE_ACTION_STATE_TTL_MS;
@@ -2056,9 +1936,8 @@ Examples:
2056
1936
  ? '✅ **Added to queue**\n\nThis message has been accepted into the thread queue. Use /queue to check its status. If the queue is paused, use /queue continue to resume.'
2057
1937
  : '❌ **Queue request cancelled**\n\nThis message was not added to the thread queue.';
2058
1938
  try {
2059
- const rootId = this.threadSwitchCardState.get(cardMessageId)?.selector?.rootId ?? cardMessageId;
2060
- await this.withMessageLock(rootId, async () => {
2061
- const result = await this.client.im.message.patch({
1939
+ await this.withMessageLock(cardMessageId, async () => {
1940
+ await this.client.im.message.patch({
2062
1941
  path: { message_id: cardMessageId },
2063
1942
  data: {
2064
1943
  content: JSON.stringify({
@@ -2067,9 +1946,6 @@ Examples:
2067
1946
  }),
2068
1947
  },
2069
1948
  });
2070
- if (result?.code)
2071
- throw result;
2072
- this.threadSwitchCardState.delete(cardMessageId);
2073
1949
  });
2074
1950
  }
2075
1951
  catch (error) {