@yu_robotics/remote-cli 1.6.176 → 1.6.177

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.
Files changed (34) hide show
  1. package/README.md +19 -2
  2. package/dist/client/MessageHandler.d.ts +1 -0
  3. package/dist/client/MessageHandler.d.ts.map +1 -1
  4. package/dist/client/MessageHandler.js +54 -15
  5. package/dist/client/MessageHandler.js.map +1 -1
  6. package/dist/delegation/DelegatedWorkerSessionStore.d.ts +11 -1
  7. package/dist/delegation/DelegatedWorkerSessionStore.d.ts.map +1 -1
  8. package/dist/delegation/DelegatedWorkerSessionStore.js +98 -51
  9. package/dist/delegation/DelegatedWorkerSessionStore.js.map +1 -1
  10. package/dist/delegation/DelegationManager.d.ts +2 -0
  11. package/dist/delegation/DelegationManager.d.ts.map +1 -1
  12. package/dist/delegation/DelegationManager.js +11 -0
  13. package/dist/delegation/DelegationManager.js.map +1 -1
  14. package/dist/executor/CodexAppServerClient.d.ts +2 -1
  15. package/dist/executor/CodexAppServerClient.d.ts.map +1 -1
  16. package/dist/executor/CodexAppServerClient.js +15 -11
  17. package/dist/executor/CodexAppServerClient.js.map +1 -1
  18. package/dist/executor/PiExecutor.d.ts.map +1 -1
  19. package/dist/executor/PiExecutor.js +2 -1
  20. package/dist/executor/PiExecutor.js.map +1 -1
  21. package/dist/maintenance/release-notes.json +1 -1
  22. package/dist/thread/ThreadContextReset.d.ts +12 -0
  23. package/dist/thread/ThreadContextReset.d.ts.map +1 -0
  24. package/dist/thread/ThreadContextReset.js +59 -0
  25. package/dist/thread/ThreadContextReset.js.map +1 -0
  26. package/dist/thread/ThreadExecutorPool.d.ts +8 -1
  27. package/dist/thread/ThreadExecutorPool.d.ts.map +1 -1
  28. package/dist/thread/ThreadExecutorPool.js +84 -1
  29. package/dist/thread/ThreadExecutorPool.js.map +1 -1
  30. package/dist/thread/ThreadManager.d.ts +2 -0
  31. package/dist/thread/ThreadManager.d.ts.map +1 -1
  32. package/dist/thread/ThreadManager.js +3 -0
  33. package/dist/thread/ThreadManager.js.map +1 -1
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Remote control Claude Code, AGY CLI, Codex CLI, OpenCode CLI, Kimi Code CLI, ZCode, or Pi from anywhere using your mobile phone through Feishu (Lark) messaging.
4
4
 
5
+ ![Remote CLI architecture](../../docs/images/remote-cli-architecture.png)
6
+
5
7
  ## Features
6
8
 
7
9
  - **Remote Control**: Control your local development environment from anywhere via mobile
@@ -179,8 +181,8 @@ Linux users upgrading from version 1.6.23 or earlier should run `remote-cli serv
179
181
  | `/skills` | List available skills for the active backend |
180
182
  | `/abort` | Abort executing task in current thread |
181
183
  | `/queue` | Inspect or manage confirmed messages waiting in thread queues |
182
- | `/clear` | Clear context for this thread |
183
- | `/new` | Alias for `/clear`; start a fresh conversation in this thread |
184
+ | `/clear` | Reset all direct backend and managed worker conversations for this thread |
185
+ | `/new` | Alias for `/clear`; start fresh across this thread's backends and workers |
184
186
  | `/compact` | Compress history to save tokens |
185
187
  | `/cd [dir]` | Browse directories as a card, or change directory directly with a path |
186
188
  | `/model [name]` | Open native model settings, or set the active backend model with a text argument |
@@ -490,6 +492,21 @@ Claude Code also supports opt-in `/sandbox` policies. Workspace-write mode autom
490
492
  - **Device authentication**: Each device has a unique hardware-based ID
491
493
  - **Binding codes**: Expire after 5 minutes
492
494
 
495
+ From CLI 1.6.177, `/clear` and its `/new` alias reset the entire current
496
+ thread's conversation context: all direct backend session bindings and every
497
+ managed worker conversation, across backends and parallel worker lanes. The
498
+ working directory, files, Git artifacts, archived native transcripts, login,
499
+ backend/model/effort selections, delegation preference, and sandbox grants are
500
+ preserved. Other threads are unaffected. A later backend switch starts fresh
501
+ instead of restoring a pre-clear binding. Busy tasks, queued work, and workers
502
+ with unconfirmed shutdowns must settle before clearing. Reset intent is saved
503
+ before any session binding changes. A persisted reset intent blocks old
504
+ conversations until clearing succeeds, including after a CLI restart. If
505
+ clearing fails, resolve the reported problem and retry `/clear` or `/new`.
506
+ Service shutdown waits for retained cleanup and reports unconfirmed native exits
507
+ before acknowledging completion.
508
+ Single-worker **Clear context** controls still reset only the selected worker.
509
+
493
510
  ## Session Resume
494
511
 
495
512
  CLI 1.6.164 supports confirmed Pi native session connections and read-only Pi/Codex/Claude Code discovery. Adopted Pi history reloads before every remote turn; `/session detach` preserves it and `/session release` is removed. Foreground Pi `/new` and `/clear` also preserve old history and start independent IDs; new default names use native session IDs and persisted names are not overwritten on reopen. Worker/metadata cleanup is unchanged. Resume drafts keep ordinary messages in the current conversation until confirmation succeeds. Use only one side at a time. Local Pi windows may stay open but must use native `/resume` before their next local turn; automatic local refresh and writer locking are not provided. Existing Router command/response envelopes support the text workflow without a new wire capability. See the [session resume specification](../../SESSION_RESUME_SPEC.md).
@@ -80,6 +80,7 @@ export declare class MessageHandler {
80
80
  private handleStatusQuery;
81
81
  private isValidMessage;
82
82
  private handleWorkerContextReset;
83
+ private clearThreadConversation;
83
84
  /**
84
85
  * Handle built-in commands (thread-scoped).
85
86
  * Returns true if handled.
@@ -1 +1 @@
1
- {"version":3,"file":"MessageHandler.d.ts","sourceRoot":"","sources":["../../src/client/MessageHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAQpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAgK,MAAM,UAAU,CAAC;AACzM,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAOxD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAyHxD;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,E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O,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,sBAAsB;IAuB9B,iFAAiF;IACjF,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,eAAe;IAiBvB,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,sBAAsB;IAyB9B,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,YAAY;IAgBpB,OAAO,CAAC,SAAS;IAiBjB,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,YAAY;IAsDpB,OAAO,CAAC,qBAAqB;IAI7B,8EAA8E;YAChE,sBAAsB;IAgBpC,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,gBAAgB;IAYxB,uFAAuF;YACzE,sBAAsB;IAsBpC,mFAAmF;YACrE,eAAe;YAuDf,mBAAmB;IA0BjC,OAAO,CAAC,YAAY;YAUN,cAAc;YAuBd,oBAAoB;IAgHlC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB/B"}
@@ -29,6 +29,7 @@ const uuid_1 = require("uuid");
29
29
  const ZCodeCommand_1 = require("../executor/zcode/ZCodeCommand");
30
30
  const DelegationManager_1 = require("../delegation/DelegationManager");
31
31
  const DelegationBridge_1 = require("../delegation/DelegationBridge");
32
+ const DelegatedWorkerSessionStore_1 = require("../delegation/DelegatedWorkerSessionStore");
32
33
  const contract_1 = require("../delegation/contract");
33
34
  const DelegationStatusFormatter_1 = require("../delegation/DelegationStatusFormatter");
34
35
  const WorkerPolicy_1 = require("../delegation/WorkerPolicy");
@@ -205,7 +206,7 @@ class MessageHandler {
205
206
  for (const delivery of this.imageDeliveries.values())
206
207
  delivery.invalidatePending();
207
208
  });
208
- this.delegation = new DelegationManager_1.DelegationManager(directoryGuard);
209
+ this.delegation = new DelegationManager_1.DelegationManager(directoryGuard, undefined, undefined, undefined, undefined, undefined, new DelegatedWorkerSessionStore_1.DelegatedWorkerSessionStore(undefined, threadManager.contextResets));
209
210
  this.settingsCatalogReader = new SettingsCatalog_1.SettingsCatalogReader(directoryGuard);
210
211
  this.settingsService = new SettingsService_1.SettingsService({
211
212
  state: id => this.settingsState(id),
@@ -410,7 +411,12 @@ class MessageHandler {
410
411
  async handleCommandMessage(message, fileOrder) {
411
412
  const threadId = message.threadId ?? this.threadManager.getDefaultThread().id;
412
413
  const content = message.content?.trim() ?? '';
413
- const body = () => this.handleAdmittedCommandMessage(message, fileOrder);
414
+ const clearing = content === '/clear' || content === '/new';
415
+ const body = () => {
416
+ if (!clearing)
417
+ this.threadManager.contextResets.assertReady(threadId);
418
+ return this.handleAdmittedCommandMessage(message, fileOrder);
419
+ };
414
420
  this.messageOpenIds.set(message.messageId, message.openId);
415
421
  if ((0, SessionResumeService_1.isSessionControl)(content)) {
416
422
  if (!this.threadManager.getThread(threadId)) {
@@ -419,11 +425,13 @@ class MessageHandler {
419
425
  }
420
426
  let response;
421
427
  try {
428
+ this.threadManager.contextResets.assertReady(threadId);
422
429
  const control = () => this.sessionControl.handle(content, { openId: message.openId, threadId });
423
430
  // Only Pi confirmations mutate native context. Other catalogs remain read-only.
424
431
  if (this.threadPool.getBackendKey(threadId) === 'pi' && /^\/(?:resume|r|session)\s+confirm(?:\s|$)/i.test(content)) {
425
432
  try {
426
433
  response = await this.settingsAdmission.mutation(threadId, async () => {
434
+ this.threadManager.contextResets.assertReady(threadId);
427
435
  this.settingsService.invalidate(threadId);
428
436
  try {
429
437
  return await control();
@@ -451,7 +459,7 @@ class MessageHandler {
451
459
  // Abort and addressed human replies must remain available during native work.
452
460
  if (content === '/abort' || /^(?:yes|no)(?:\s|$)/.test(content) || content.startsWith('/input '))
453
461
  return await body();
454
- if (/^\/(?:backend|model|effort|cd)\s+\S/.test(content)) {
462
+ if (clearing || /^\/(?:backend|model|effort|cd)\s+\S/.test(content)) {
455
463
  const global = /^\/backend\s/.test(content) && !/\s@$/.test(content);
456
464
  await this.settingsAdmission.mutation(global ? '*' : threadId, async () => {
457
465
  this.settingsService.invalidate(global ? undefined : threadId);
@@ -469,7 +477,7 @@ class MessageHandler {
469
477
  }
470
478
  }
471
479
  catch (error) {
472
- this.sendResponse(message.messageId, threadId, { success: false, error: error instanceof Error ? error.message : 'Command admission failed.' });
480
+ this.sendResponse(message.messageId, threadId, { success: false, error: error instanceof Error ? error.message : 'Command admission failed.' }, clearing);
473
481
  }
474
482
  }
475
483
  async handleAdmittedCommandMessage(message, fileOrder) {
@@ -497,6 +505,10 @@ class MessageHandler {
497
505
  return;
498
506
  }
499
507
  const settingsCommand = content?.trim() ?? '';
508
+ if (settingsCommand === '/clear' || settingsCommand === '/new') {
509
+ await this.clearThreadConversation(messageId, resolvedThreadId);
510
+ return;
511
+ }
500
512
  if (this.directoryCardsSupported && openId && settingsCommand === '/cd') {
501
513
  try {
502
514
  const menu = await this.directoryBrowser.open(resolvedThreadId, openId, messageId);
@@ -932,6 +944,30 @@ class MessageHandler {
932
944
  this.wsClient.send({ type: 'worker_context_reset_result', messageId: request.messageId,
933
945
  success: !error, ...(error ? { error } : {}), timestamp: Date.now() });
934
946
  }
947
+ async clearThreadConversation(messageId, threadId) {
948
+ if (this.threadPool.isThreadBusy(threadId) || this.hasThreadQueueState(threadId)
949
+ || this.abortOperations.has(threadId) || this.activeThreadOperations.has(threadId)) {
950
+ throw new Error('This thread is busy or has queued messages. Wait for it to finish and clear its queue before retrying /clear.');
951
+ }
952
+ this.threadPool.assertContextResettable(threadId);
953
+ const token = this.beginThreadOperation(threadId);
954
+ try {
955
+ await this.delegation.assertThreadContextResettable(threadId);
956
+ await this.threadManager.contextResets.begin(threadId);
957
+ await this.threadPool.clearThreadContext(threadId);
958
+ await this.delegation.clearThreadContexts(threadId);
959
+ await this.threadManager.contextResets.complete(threadId);
960
+ this.sendResponse(messageId, threadId, { success: true,
961
+ output: 'Conversation context cleared for all direct backends and managed workers in this thread.' }, true);
962
+ }
963
+ catch (error) {
964
+ const detail = error instanceof Error ? error.message : 'Local context storage is unavailable';
965
+ throw new Error(`Could not clear thread conversation: ${detail}. Check local CLI storage and retry /clear or /new.`);
966
+ }
967
+ finally {
968
+ this.finishThreadOperation(threadId, token);
969
+ }
970
+ }
935
971
  /**
936
972
  * Handle built-in commands (thread-scoped).
937
973
  * Returns true if handled.
@@ -1165,14 +1201,6 @@ You can also use natural language commands to control Claude Code CLI.`,
1165
1201
  });
1166
1202
  return true;
1167
1203
  }
1168
- if (trimmed === '/clear' || trimmed === '/new') {
1169
- executor.resetContext();
1170
- this.sendResponse(messageId, threadId, {
1171
- success: true,
1172
- output: '✅ Conversation context cleared',
1173
- });
1174
- return true;
1175
- }
1176
1204
  if (trimmed === '/compact') {
1177
1205
  if (!('compactWhenFull' in executor && typeof executor.compactWhenFull === 'function')) {
1178
1206
  this.sendResponse(messageId, threadId, {
@@ -2837,6 +2865,7 @@ You can also use natural language commands to control Claude Code CLI.`,
2837
2865
  return { success: true, output: `✅ Changed working directory to: ${cwd}${changed ? '\nConversation context cleared for all direct and delegated backends in this thread.' : ''}${cleanup.failed ? `\n⚠️ ${cleanup.failed} delegated worker lane(s) could not be cleaned up. Retry with /delegation reset after checking filesystem permissions.` : ''}` };
2838
2866
  }
2839
2867
  settingsState(threadId) {
2868
+ this.threadManager.contextResets.assertReady(threadId);
2840
2869
  const thread = this.threadManager.getThread(threadId);
2841
2870
  if (!thread)
2842
2871
  return undefined;
@@ -2902,6 +2931,7 @@ You can also use natural language commands to control Claude Code CLI.`,
2902
2931
  }
2903
2932
  /** Shared native/persistent mutation for cards and parameterized text commands. */
2904
2933
  async applyPreference(threadId, backend, kind, value, onStream) {
2934
+ this.threadManager.contextResets.assertReady(threadId);
2905
2935
  const thread = this.threadManager.getThread(threadId);
2906
2936
  if (!thread)
2907
2937
  return { success: false, error: 'This thread no longer exists.' };
@@ -2975,6 +3005,9 @@ You can also use natural language commands to control Claude Code CLI.`,
2975
3005
  }
2976
3006
  async applyBackendSetting(threadId, backend, scope, followGlobal = false) {
2977
3007
  try {
3008
+ for (const thread of scope === 'all' ? this.threadManager.listThreads() : [{ id: threadId }]) {
3009
+ this.threadManager.contextResets.assertReady(thread.id);
3010
+ }
2978
3011
  if (followGlobal) {
2979
3012
  await this.threadPool.destroyThread(threadId, { deleteData: false });
2980
3013
  await this.threadManager.updateThread(threadId, { backend: undefined });
@@ -3140,14 +3173,20 @@ You can also use natural language commands to control Claude Code CLI.`,
3140
3173
  await this.fileInbox?.destroy();
3141
3174
  this.notificationAdapter.unregister();
3142
3175
  try {
3143
- await this.delegation.destroy();
3144
- await Promise.all([...this.delegationBridges.values()].map(bridge => bridge.close()));
3176
+ const results = await Promise.allSettled([
3177
+ this.delegation.destroy(),
3178
+ ...[...this.delegationBridges.values()].map(bridge => bridge.close()),
3179
+ this.threadPool.destroyAll({ deleteData: false, shutdown: true }),
3180
+ ]);
3181
+ const failure = results.find((result) => result.status === 'rejected');
3182
+ if (failure)
3183
+ throw failure.reason;
3145
3184
  this.delegationBridges.clear();
3146
- await this.threadPool.destroyAll({ deleteData: false });
3147
3185
  this.pendingApprovalCards.clear();
3148
3186
  }
3149
3187
  catch (err) {
3150
3188
  console.error('Error destroying thread executors:', err);
3189
+ throw err;
3151
3190
  }
3152
3191
  }
3153
3192
  }