codexmate 0.1.31 → 0.1.33

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 (92) hide show
  1. package/README.md +8 -3
  2. package/README.vi.md +8 -3
  3. package/README.zh.md +8 -3
  4. package/cli/agents-files.js +18 -4
  5. package/cli/claude-proxy.js +2 -2
  6. package/cli/plugin-config.js +64 -0
  7. package/cli/prompt-history.js +19 -4
  8. package/cli/system-prompt-files.js +7 -2
  9. package/cli.js +200 -214
  10. package/lib/cli-config-engine.js +15 -4
  11. package/lib/cli-file-utils.js +6 -1
  12. package/lib/config-change-fs.js +132 -0
  13. package/lib/config-changes.js +293 -0
  14. package/lib/handoff-mcp.js +18 -2
  15. package/lib/local-feature-store.js +39 -0
  16. package/lib/session-bookmarks.js +72 -0
  17. package/lib/session-context-health.js +102 -0
  18. package/lib/session-context-records.js +153 -0
  19. package/lib/session-diagnostics.js +75 -0
  20. package/lib/session-feature-settings.js +21 -0
  21. package/lib/session-features.js +63 -0
  22. package/lib/session-handoff-draft.js +43 -0
  23. package/lib/session-projects.js +76 -0
  24. package/lib/session-search-index.js +188 -0
  25. package/lib/thread-handoff.js +8 -0
  26. package/lib/web-server.js +216 -0
  27. package/lib/web-startup-auth.js +5 -1
  28. package/package.json +1 -1
  29. package/plugins/prompt-templates/computed.mjs +3 -3
  30. package/plugins/prompt-templates/invocation.mjs +73 -0
  31. package/plugins/prompt-templates/methods.mjs +48 -3
  32. package/plugins/prompt-templates/overview.mjs +2 -0
  33. package/web-ui/app.js +32 -1
  34. package/web-ui/index.html +2 -0
  35. package/web-ui/logic.context-health.mjs +144 -0
  36. package/web-ui/logic.context-window.mjs +15 -0
  37. package/web-ui/modules/api.mjs +72 -39
  38. package/web-ui/modules/app.computed.prompts.mjs +11 -0
  39. package/web-ui/modules/app.methods.agents.mjs +25 -3
  40. package/web-ui/modules/app.methods.claude-config.mjs +2 -0
  41. package/web-ui/modules/app.methods.codex-config.mjs +9 -0
  42. package/web-ui/modules/app.methods.config-changes.mjs +124 -0
  43. package/web-ui/modules/app.methods.index.mjs +4 -0
  44. package/web-ui/modules/app.methods.kilocode-config.mjs +2 -0
  45. package/web-ui/modules/app.methods.openclaw-persist.mjs +2 -0
  46. package/web-ui/modules/app.methods.opencode-config.mjs +2 -0
  47. package/web-ui/modules/app.methods.pi-config.mjs +12 -3
  48. package/web-ui/modules/app.methods.provider-cache.mjs +9 -3
  49. package/web-ui/modules/app.methods.providers.mjs +6 -0
  50. package/web-ui/modules/app.methods.startup-claude.mjs +8 -47
  51. package/web-ui/modules/app.methods.system-prompt.mjs +17 -2
  52. package/web-ui/modules/config-change-actions.mjs +9 -0
  53. package/web-ui/modules/context-health.methods.mjs +70 -0
  54. package/web-ui/modules/i18n/locales/en.mjs +164 -4
  55. package/web-ui/modules/i18n/locales/ja.mjs +164 -4
  56. package/web-ui/modules/i18n/locales/vi.mjs +164 -4
  57. package/web-ui/modules/i18n/locales/zh-tw.mjs +164 -4
  58. package/web-ui/modules/i18n/locales/zh.mjs +164 -4
  59. package/web-ui/modules/plugins.methods.mjs +2 -0
  60. package/web-ui/modules/prompt-ecosystem.methods.mjs +136 -0
  61. package/web-ui/modules/request-deadline.mjs +33 -0
  62. package/web-ui/modules/session-features.mjs +279 -0
  63. package/web-ui/modules/thread-handoff.mjs +1 -1
  64. package/web-ui/partials/index/config-changes.html +25 -0
  65. package/web-ui/partials/index/context-health.html +45 -0
  66. package/web-ui/partials/index/context-window-reference.html +17 -0
  67. package/web-ui/partials/index/layout-header.html +7 -30
  68. package/web-ui/partials/index/modal-openclaw-config.html +0 -2
  69. package/web-ui/partials/index/modal-prompt-invocation.html +17 -0
  70. package/web-ui/partials/index/modal-skills.html +0 -1
  71. package/web-ui/partials/index/modals-basic.html +0 -8
  72. package/web-ui/partials/index/modals-pi-provider.html +0 -1
  73. package/web-ui/partials/index/panel-config-codex.html +0 -3
  74. package/web-ui/partials/index/panel-config-openclaw.html +16 -13
  75. package/web-ui/partials/index/panel-dashboard.html +0 -2
  76. package/web-ui/partials/index/panel-plugins.html +37 -10
  77. package/web-ui/partials/index/panel-prompts.html +18 -3
  78. package/web-ui/partials/index/panel-sessions.html +23 -11
  79. package/web-ui/partials/index/panel-settings.html +1 -12
  80. package/web-ui/partials/index/panel-trash.html +0 -1
  81. package/web-ui/partials/index/session-diagnostics.html +29 -0
  82. package/web-ui/partials/index/session-features.html +107 -0
  83. package/web-ui/partials/index/thread-handoff.html +6 -3
  84. package/web-ui/res/web-ui-render.precompiled.js +1863 -271
  85. package/web-ui/styles/config-changes.css +30 -0
  86. package/web-ui/styles/context-health.css +107 -0
  87. package/web-ui/styles/openclaw-structured.css +205 -189
  88. package/web-ui/styles/prompts-editor.css +23 -0
  89. package/web-ui/styles/session-features.css +148 -0
  90. package/web-ui/styles/sessions-preview.css +21 -0
  91. package/web-ui/styles/sub-tabs.css +181 -0
  92. package/web-ui/styles.css +5 -1
@@ -0,0 +1,124 @@
1
+ import { CONFIG_CHANGE_ACTIONS } from './config-change-actions.mjs';
2
+ import { api, setConfigChangeHandler, getConfigChangeBaseline } from './api.mjs';
3
+
4
+ export const configChangeMixin = {
5
+ methods: createConfigChangeMethods(),
6
+ data() {
7
+ return { configChangePreview: null, configChangeBusy: false, configChangeApplying: false, configChangeError: '', lastConfigChange: null };
8
+ }
9
+ };
10
+
11
+ export function createConfigChangeMethods() {
12
+ return {
13
+ installConfigChangePreview() {
14
+ this._configChangeApiHandler = (action, params) => this.requestConfigChange(action, params);
15
+ setConfigChangeHandler(this._configChangeApiHandler);
16
+ this.refreshLastConfigChange();
17
+ },
18
+ uninstallConfigChangePreview() {
19
+ setConfigChangeHandler(null, this._configChangeApiHandler);
20
+ this.closeConfigChangePreview({ force: true });
21
+ },
22
+ async requestConfigChange(action, params) {
23
+ if (this.configChangePreview || this.configChangeBusy) return { error: this.t('changes.busy'), success: false };
24
+ this.configChangeBusy = true;
25
+ try {
26
+ const preview = await api('preview-config-change', { action, params, baseline: getConfigChangeBaseline(CONFIG_CHANGE_ACTIONS[action]) });
27
+ if (preview.error) return { ...preview, error: this.configChangeErrorText(preview) };
28
+ if (!preview.hasChanges || this.configTemplateDiffConfirmEnabled === false) {
29
+ const result = await api('apply-config-change', { previewId: preview.previewId });
30
+ if (!result.error) await this.refreshLastConfigChange();
31
+ return result.error ? { ...result, error: this.configChangeErrorText(result) } : result;
32
+ }
33
+ this._configChangeReturnFocus = typeof document !== 'undefined' ? document.activeElement : null;
34
+ this.configChangePreview = preview;
35
+ this.configChangeError = '';
36
+ const pending = new Promise(resolve => { this._configChangeResolve = resolve; });
37
+ if (typeof this.$nextTick === 'function') this.$nextTick(() => this.$refs.configChangeCancel && this.$refs.configChangeCancel.focus());
38
+ return await pending;
39
+ } finally { this.configChangeBusy = false; }
40
+ },
41
+ configChangeErrorText(result) {
42
+ const key = `changes.error.${result.errorCode || ''}`;
43
+ const translated = this.t(key);
44
+ return translated === key ? this.t('changes.failed') : translated;
45
+ },
46
+ closeConfigChangePreview({ force = false } = {}) {
47
+ if (this.configChangeApplying && !force) return;
48
+ const resolve = this._configChangeResolve;
49
+ this._configChangeResolve = null;
50
+ this.configChangePreview = null;
51
+ this.configChangeError = '';
52
+ if (resolve) resolve({ canceled: true, success: false, error: this.t('changes.cancelled') });
53
+ const focus = this._configChangeReturnFocus;
54
+ this._configChangeReturnFocus = null;
55
+ if (focus && typeof focus.focus === 'function') focus.focus();
56
+ },
57
+ async confirmConfigChange() {
58
+ if (!this.configChangePreview || this.configChangeApplying) return;
59
+ this.configChangeApplying = true;
60
+ try {
61
+ const result = await api('apply-config-change', { previewId: this.configChangePreview.previewId });
62
+ if (result.error) {
63
+ this.configChangeError = this.configChangeErrorText(result);
64
+ if (result.rollbackFailed && result.rollbackFailed.length) this.configChangeError += ' ' + this.t('changes.restoreFailed', { paths: result.rollbackFailed.join(', ') });
65
+ return;
66
+ }
67
+ const resolve = this._configChangeResolve;
68
+ this._configChangeResolve = null;
69
+ this.closeConfigChangePreview({ force: true });
70
+ if (resolve) resolve(result);
71
+ await this.refreshLastConfigChange();
72
+ } catch (_) {
73
+ this.configChangeError = this.t('changes.failed');
74
+ } finally { this.configChangeApplying = false; }
75
+ },
76
+ async refreshLastConfigChange() {
77
+ const target = this.configMode;
78
+ try {
79
+ const result = await api('get-last-config-change', { target });
80
+ if (this.configMode === target) this.lastConfigChange = result.change || null;
81
+ } catch (_) {
82
+ if (this.configMode === target) this.lastConfigChange = null;
83
+ }
84
+ },
85
+ async undoLastConfigChange() {
86
+ const change = this.lastConfigChange;
87
+ if (!change || this.configChangeBusy || this.configChangeApplying || !this.isToolConfigWriteAllowed(change.target)) return;
88
+ const confirmed = await this.requestConfirmDialog({
89
+ title: this.t('changes.undo'), message: this.t('changes.undoConfirm', { paths: change.files.map(file => file.path).join('\n') }),
90
+ confirmText: this.t('changes.undo'), cancelText: this.t('common.cancel'), danger: true
91
+ });
92
+ if (!confirmed) return;
93
+ this.configChangeBusy = true;
94
+ try {
95
+ const result = await api('undo-config-change', { target: change.target, changeId: change.id });
96
+ if (result.error) {
97
+ let message = this.configChangeErrorText(result);
98
+ if (result.rollbackFailed && result.rollbackFailed.length) message += ' ' + this.t('changes.restoreFailed', { paths: result.rollbackFailed.join(', ') });
99
+ this.showMessage(message, 'error');
100
+ return;
101
+ }
102
+ this.showMessage(this.t('changes.undone'), 'success');
103
+ await this.refreshLastConfigChange();
104
+ if (change.target === 'codex' || change.target === 'claude') await this.loadAll();
105
+ if (change.target === 'claude') this._lastAppliedClaudeKey = '';
106
+ if (change.target === 'openclaw') await this.syncDefaultOpenclawConfigEntry();
107
+ if (change.target === 'opencode') await this.loadOpencodeConfig();
108
+ if (change.target === 'kilocode') await this.loadKilocodeConfig();
109
+ if (change.target === 'pi') await this.loadPiSources();
110
+ } catch (_) { this.showMessage(this.t('changes.refreshFailed'), 'error'); }
111
+ finally { this.configChangeBusy = false; }
112
+ },
113
+ handleConfigChangeKeydown(event) {
114
+ if (event.key === 'Escape') { event.stopPropagation(); this.closeConfigChangePreview(); return; }
115
+ if (event.key !== 'Tab') return;
116
+ event.stopPropagation();
117
+ const items = [...event.currentTarget.querySelectorAll('button:not(:disabled), [tabindex="0"]')];
118
+ const first = items[0];
119
+ const last = items[items.length - 1];
120
+ if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
121
+ else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
122
+ }
123
+ };
124
+ }
@@ -36,6 +36,8 @@ import { createSessionTrashMethods } from './app.methods.session-trash.mjs';
36
36
  import { createStartupClaudeMethods } from './app.methods.startup-claude.mjs';
37
37
  import { createSkillsMethods } from './skills.methods.mjs';
38
38
  import { createPluginsMethods } from './plugins.methods.mjs';
39
+ import { createPromptEcosystemMethods } from './prompt-ecosystem.methods.mjs';
40
+ import { createContextHealthMethods } from './context-health.methods.mjs';
39
41
  import { createI18nMethods } from './i18n.mjs';
40
42
  import { createWebhookMethods } from './app.methods.webhook.mjs';
41
43
  import { createWebUiPreferencesMethods } from './app.methods.web-ui-preferences.mjs';
@@ -90,6 +92,8 @@ export function createAppMethods() {
90
92
  }),
91
93
  ...createSkillsMethods({ api }),
92
94
  ...createPluginsMethods(),
95
+ ...createPromptEcosystemMethods({ api }),
96
+ ...createContextHealthMethods({ api }),
93
97
  ...createAgentsMethods({ api, apiWithMeta }),
94
98
  ...createSystemPromptMethods({ api, apiWithMeta }),
95
99
  ...createProvidersMethods({ api }),
@@ -109,6 +109,7 @@ export function createKilocodeConfigMethods(options = {}) {
109
109
  this.kilocodeError = '';
110
110
  try {
111
111
  const res = await api('apply-kilocode-config', { provider, url, model, apiKey });
112
+ if (res && res.canceled) return;
112
113
  if (res && res.error) {
113
114
  this.kilocodeError = res.error;
114
115
  this.showMessage(res.error, 'error');
@@ -145,6 +146,7 @@ export function createKilocodeConfigMethods(options = {}) {
145
146
  apiKey: this.kilocodeApiKey
146
147
  } : {};
147
148
  const res = await api('start-kilocode', payload);
149
+ if (res && res.canceled) return;
148
150
  if (res && res.error) {
149
151
  this.kilocodeError = res.error;
150
152
  this.showMessage(res.error, 'error');
@@ -294,6 +294,7 @@ export function createOpenclawPersistMethods(options = {}) {
294
294
  lineEnding: this.openclawLineEnding,
295
295
  authProfileUpdates: Object.values(this.openclawPendingAuthProfileUpdates || {})
296
296
  });
297
+ if (res && res.canceled) return;
297
298
  if (res.error || res.success === false) {
298
299
  this.showMessage(res.error || '应用配置失败', 'error');
299
300
  return;
@@ -352,6 +353,7 @@ export function createOpenclawPersistMethods(options = {}) {
352
353
  lineEnding: this.openclawLineEnding,
353
354
  authProfileUpdates: Object.values(this.openclawPendingAuthProfileUpdates || {})
354
355
  });
356
+ if (res && res.canceled) return;
355
357
  if (res.error || res.success === false) {
356
358
  this.showMessage(res.error || '应用配置失败', 'error');
357
359
  } else {
@@ -160,6 +160,7 @@ export function createOpencodeConfigMethods(options = {}) {
160
160
  this.opencodeError = '';
161
161
  try {
162
162
  const res = await api('apply-opencode-config', { content: this.opencodeContent });
163
+ if (res && res.canceled) return;
163
164
  if (res && res.error) {
164
165
  this.opencodeError = res.error;
165
166
  this.showMessage(res.error, 'error');
@@ -205,6 +206,7 @@ export function createOpencodeConfigMethods(options = {}) {
205
206
  maxTokens: this.opencodeMaxTokens,
206
207
  reasoningEffort: this.opencodeReasoningEffort
207
208
  });
209
+ if (res && res.canceled) return;
208
210
  if (res && res.error) {
209
211
  this.opencodeError = res.error;
210
212
  this.showMessage(res.error, 'error');
@@ -58,6 +58,7 @@ export function createPiConfigMethods({ api: apiClient }) {
58
58
  else updates.defaultModel = '';
59
59
  try {
60
60
  const result = await apiClient('write-pi-settings', updates);
61
+ if (result && result.canceled) return;
61
62
  if (result && result.error) throw new Error(result.error);
62
63
  await this.loadPiSettings();
63
64
  this.message = '已切换为使用该供应商';
@@ -75,7 +76,8 @@ export function createPiConfigMethods({ api: apiClient }) {
75
76
  const existing = providers[providerId] || {};
76
77
  const updated = { ...providers };
77
78
  delete updated[providerId];
78
- await this.savePiProviders(updated);
79
+ const result = await this.savePiProviders(updated);
80
+ if (result && (result.canceled || result.error)) return result;
79
81
  return { success: true, provider: existing };
80
82
  },
81
83
  async persistPiProvider(providerId, values) {
@@ -137,7 +139,9 @@ export function createPiConfigMethods({ api: apiClient }) {
137
139
  merged.id = providerId;
138
140
  if (merged.name === undefined) merged.name = providerId;
139
141
  }
140
- await this.persistPiProvider(providerId, merged);
142
+ const result = await this.persistPiProvider(providerId, merged);
143
+ if (result && result.canceled) return;
144
+ if (result && result.error) throw new Error(result.error);
141
145
  this.piProviders = { ...this.piProviders, [providerId]: merged };
142
146
  this.piProviderIds = Object.keys(this.piProviders).sort();
143
147
  this.resetPiProviderEditing();
@@ -421,7 +425,9 @@ export function createPiConfigMethods({ api: apiClient }) {
421
425
  danger: true
422
426
  });
423
427
  if (!confirmed) return;
424
- await this.removePiProvider(providerId);
428
+ const result = await this.removePiProvider(providerId);
429
+ if (result && result.canceled) return;
430
+ if (result && result.error) { this.message = result.error; this.messageType = 'error'; return; }
425
431
  const updated = { ...this.piProviders };
426
432
  delete updated[providerId];
427
433
  this.piProviders = updated;
@@ -486,6 +492,7 @@ export function createPiConfigMethods({ api: apiClient }) {
486
492
  this.piFileJsonSaving = true;
487
493
  try {
488
494
  const result = await apiClient('write-pi-settings', { settings: parsed.value });
495
+ if (result && result.canceled) return;
489
496
  if (result && result.error) throw new Error(result.error);
490
497
  this.piSettingsJsonError = '';
491
498
  this.piSettingsJsonDraft = JSON.stringify(parsed.value, null, 2);
@@ -511,6 +518,7 @@ export function createPiConfigMethods({ api: apiClient }) {
511
518
  this.piFileJsonSaving = true;
512
519
  try {
513
520
  const result = await apiClient('write-pi-models', { file: parsed.value });
521
+ if (result && result.canceled) return;
514
522
  if (result && result.error) throw new Error(result.error);
515
523
  await this.loadPiSources();
516
524
  this.message = 'models.json 已保存';
@@ -640,6 +648,7 @@ export function createPiConfigMethods({ api: apiClient }) {
640
648
  this.piHistoryApplying = true;
641
649
  try {
642
650
  const res = await api('apply-pi-config-history', { target: this.piHistoryTarget, id: this.piHistoryPreviewId });
651
+ if (res && res.canceled) return;
643
652
  if (res && res.error) {
644
653
  this.showMessage(res.error, 'error');
645
654
  return;
@@ -1,5 +1,7 @@
1
+ import { withRequestDeadline } from './request-deadline.mjs';
2
+
1
3
  export function createProviderCacheMethods(options = {}) {
2
- const { api } = options;
4
+ const { api, cacheLoadTimeoutMs = 6000 } = options;
3
5
 
4
6
  return {
5
7
  async openProviderCacheModal(options = {}) {
@@ -41,7 +43,10 @@ export function createProviderCacheMethods(options = {}) {
41
43
  }
42
44
  this.providerCacheError = '';
43
45
  try {
44
- const res = await api('get-provider-cache-records');
46
+ const res = await withRequestDeadline(
47
+ signal => api('get-provider-cache-records', {}, { signal }),
48
+ { timeoutMs: cacheLoadTimeoutMs }
49
+ );
45
50
  if (!isLatestRequest()) return;
46
51
  if (res && res.error) {
47
52
  this.providerCacheError = res.error;
@@ -52,7 +57,8 @@ export function createProviderCacheMethods(options = {}) {
52
57
  this.providerCacheLoadedAt = this.providerCacheRecords.generatedAt || new Date().toISOString();
53
58
  } catch (e) {
54
59
  if (!isLatestRequest()) return;
55
- this.providerCacheError = e && e.message ? e.message : this.t('modal.providerCache.loadFailed');
60
+ this.providerCacheError = e && e.message && e.name !== 'TimeoutError'
61
+ ? e.message : this.t('modal.providerCache.loadFailed');
56
62
  } finally {
57
63
  if (isLatestRequest() && !background) {
58
64
  this.providerCacheLoading = false;
@@ -189,6 +189,7 @@ export function createProvidersMethods(options = {}) {
189
189
  }
190
190
  const suggestedModel = validation.model;
191
191
  const res = await api('add-provider', payload);
192
+ if (res && res.canceled) return;
192
193
  if (res.error) {
193
194
  this.showMessage(res.error, 'error');
194
195
  return;
@@ -284,6 +285,7 @@ export function createProvidersMethods(options = {}) {
284
285
  }
285
286
  try {
286
287
  const res = await api('delete-provider', { name });
288
+ if (res && res.canceled) return;
287
289
  if (res.error) {
288
290
  this.showMessage(res.error, 'error');
289
291
  return;
@@ -438,6 +440,7 @@ export function createProvidersMethods(options = {}) {
438
440
  }
439
441
  try {
440
442
  const res = await api('update-provider', params);
443
+ if (res && res.canceled) return;
441
444
  if (res.error) {
442
445
  this.showMessage(res.error, 'error');
443
446
  return;
@@ -490,6 +493,7 @@ export function createProvidersMethods(options = {}) {
490
493
  this.resetConfigLoading = true;
491
494
  try {
492
495
  const res = await api('reset-config');
496
+ if (res && res.canceled) return;
493
497
  if (res.error) {
494
498
  this.showMessage(res.error, 'error');
495
499
  return;
@@ -511,6 +515,7 @@ export function createProvidersMethods(options = {}) {
511
515
  try {
512
516
  const modelName = this.newModelName.trim();
513
517
  const res = await api('add-model', { model: modelName });
518
+ if (res && res.canceled) return;
514
519
  if (res.error) {
515
520
  this.showMessage(res.error, 'error');
516
521
  } else {
@@ -538,6 +543,7 @@ export function createProvidersMethods(options = {}) {
538
543
  async removeModel(model) {
539
544
  try {
540
545
  const res = await api('delete-model', { model });
546
+ if (res && res.canceled) return;
541
547
  if (res.error) {
542
548
  this.showMessage(res.error, 'error');
543
549
  } else {
@@ -1,3 +1,4 @@
1
+ import { withRequestDeadline } from './request-deadline.mjs';
1
2
  import {
2
3
  findDuplicateClaudeConfigName,
3
4
  getClaudeModelCatalogForBaseUrl,
@@ -29,6 +30,7 @@ function shouldSuppressDeletedClaudeSettingsImport(env = {}, deletedEntries = []
29
30
  export function createStartupClaudeMethods(options = {}) {
30
31
  const {
31
32
  api,
33
+ configLoadTimeoutMs = 6000,
32
34
  defaultModelContextWindow = 190000,
33
35
  defaultModelAutoCompactTokenLimit = 185000
34
36
  } = options;
@@ -41,26 +43,6 @@ export function createStartupClaudeMethods(options = {}) {
41
43
  }
42
44
  const preserveLoading = !!options.preserveLoading;
43
45
  const run = async () => {
44
- const configLoadTimeoutMs = 6000;
45
- const withTimeout = async (promise, ms) => {
46
- const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
47
- if (!timeoutMs) {
48
- return promise;
49
- }
50
- let timer = null;
51
- try {
52
- return await Promise.race([
53
- promise,
54
- new Promise((_, reject) => {
55
- timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
56
- })
57
- ]);
58
- } finally {
59
- if (timer) {
60
- clearTimeout(timer);
61
- }
62
- }
63
- };
64
46
  if (!preserveLoading) {
65
47
  this.loading = true;
66
48
  }
@@ -68,12 +50,12 @@ export function createStartupClaudeMethods(options = {}) {
68
50
  const startedAt = Date.now();
69
51
  const timeLeftMs = () => configLoadTimeoutMs - (Date.now() - startedAt);
70
52
  try {
71
- const statusRes = await withTimeout(api('status'), timeLeftMs());
53
+ const statusRes = await withRequestDeadline(signal => api('status', {}, { signal }), { timeoutMs: Math.max(0, timeLeftMs()) });
72
54
  if (statusRes && statusRes.error) {
73
55
  this.initError = statusRes.error;
74
56
  return false;
75
57
  }
76
- const listRes = await withTimeout(api('list'), timeLeftMs());
58
+ const listRes = await withRequestDeadline(signal => api('list', {}, { signal }), { timeoutMs: Math.max(0, timeLeftMs()) });
77
59
  if (listRes && listRes.error) {
78
60
  this.initError = listRes.error;
79
61
  return false;
@@ -91,7 +73,7 @@ export function createStartupClaudeMethods(options = {}) {
91
73
  : '';
92
74
  this.currentModel = dictModelForCurrent || statusRes.model;
93
75
  try {
94
- const installRes = await withTimeout(api('install-status'), Math.max(0, Math.min(1200, timeLeftMs())));
76
+ const installRes = await withRequestDeadline(signal => api('install-status', {}, { signal }), { timeoutMs: Math.max(0, Math.min(1200, timeLeftMs())) });
95
77
  if (installRes && !installRes.error) {
96
78
  const targets = Array.isArray(installRes.targets) ? installRes.targets : null;
97
79
  if (targets) {
@@ -162,9 +144,8 @@ export function createStartupClaudeMethods(options = {}) {
162
144
  this.maybeShowStarPrompt();
163
145
  return true;
164
146
  } catch (e) {
165
- if (e && e.message !== 'timeout') {
166
- this.initError = '连接失败: ' + (e.message || '');
167
- }
147
+ this.initError = e && e.message === 'timeout'
148
+ ? '读取配置超时' : '连接失败: ' + (e && e.message || '');
168
149
  return false;
169
150
  } finally {
170
151
  if (!preserveLoading) {
@@ -340,28 +321,8 @@ export function createStartupClaudeMethods(options = {}) {
340
321
  const silent = !!options.silent;
341
322
  const silentModelError = !!options.silentModelError || silent;
342
323
  const run = async () => {
343
- const configLoadTimeoutMs = 6000;
344
- const withTimeout = async (promise, ms) => {
345
- const timeoutMs = Number.isFinite(Number(ms)) ? Math.max(0, Number(ms)) : 0;
346
- if (!timeoutMs) {
347
- return promise;
348
- }
349
- let timer = null;
350
- try {
351
- return await Promise.race([
352
- promise,
353
- new Promise((_, reject) => {
354
- timer = setTimeout(() => reject(new Error('timeout')), timeoutMs);
355
- })
356
- ]);
357
- } finally {
358
- if (timer) {
359
- clearTimeout(timer);
360
- }
361
- }
362
- };
363
324
  try {
364
- const res = await withTimeout(api('get-claude-settings'), configLoadTimeoutMs);
325
+ const res = await withRequestDeadline(signal => api('get-claude-settings', {}, { signal }), { timeoutMs: configLoadTimeoutMs });
365
326
  if (res && res.error) {
366
327
  if (!silent) {
367
328
  this.showMessage('读取配置失败', 'error');
@@ -76,6 +76,7 @@ export function createSystemPromptMethods(options = {}) {
76
76
  this.sysPromptPath = res.path || '';
77
77
  this.sysPromptExists = !!res.exists;
78
78
  this.sysPromptHash = res.hash || '';
79
+ this.sysHistoryBucket = res.historyBucket || '';
79
80
  } catch (e) {
80
81
  if (!isLatestRequestToken(this, '_sysPromptOpenRequestToken', requestToken)) return;
81
82
  this.showMessage(this.t('toast.load.fail'), 'error');
@@ -309,6 +310,8 @@ export function createSystemPromptMethods(options = {}) {
309
310
  ? bucketArg.trim()
310
311
  : this.resolveSysHistoryBucket();
311
312
  this.sysHistoryBucket = bucket;
313
+ const requestToken = Symbol('history-list');
314
+ this._sysHistoryRequestToken = requestToken;
312
315
  this.sysHistoryLoading = true;
313
316
  this.sysHistoryError = '';
314
317
  this.sysHistoryItems = [];
@@ -316,20 +319,24 @@ export function createSystemPromptMethods(options = {}) {
316
319
  this.sysHistoryPreviewContent = '';
317
320
  try {
318
321
  const res = await api('list-prompt-history', { bucket });
322
+ if (this._sysHistoryRequestToken !== requestToken || !this.sysHistoryVisible || this.sysHistoryBucket !== bucket) return;
319
323
  if (res && res.error) {
320
324
  this.sysHistoryError = res.error;
321
325
  return;
322
326
  }
323
327
  this.sysHistoryItems = Array.isArray(res) ? res : [];
324
328
  } catch (e) {
329
+ if (this._sysHistoryRequestToken !== requestToken) return;
325
330
  this.sysHistoryError = this.t('toast.load.fail');
326
331
  } finally {
327
- this.sysHistoryLoading = false;
332
+ if (this._sysHistoryRequestToken === requestToken) this.sysHistoryLoading = false;
328
333
  }
329
334
  },
330
335
 
331
336
  closeSysHistory() {
332
337
  this.sysHistoryVisible = false;
338
+ this._sysHistoryRequestToken = null;
339
+ this.sysHistoryLoading = false;
333
340
  this.sysHistoryPreviewId = '';
334
341
  this.sysHistoryPreviewContent = '';
335
342
  this.sysHistoryError = '';
@@ -339,10 +346,15 @@ export function createSystemPromptMethods(options = {}) {
339
346
  if (!item || !item.id) return;
340
347
  if (this.sysHistoryLoading) return;
341
348
  if (this.sysHistoryPreviewId === item.id && this.sysHistoryPreviewContent) return;
349
+ const bucket = this.sysHistoryBucket;
350
+ const requestToken = Symbol('history-preview');
351
+ this._sysHistoryRequestToken = requestToken;
352
+ this.sysHistoryLoading = true;
342
353
  this.sysHistoryPreviewId = item.id;
343
354
  this.sysHistoryPreviewContent = '';
344
355
  try {
345
- const res = await api('get-prompt-history', { bucket: this.sysHistoryBucket, id: item.id });
356
+ const res = await api('get-prompt-history', { bucket, id: item.id });
357
+ if (this._sysHistoryRequestToken !== requestToken || !this.sysHistoryVisible || this.sysHistoryBucket !== bucket) return;
346
358
  if (res && res.error) {
347
359
  this.sysHistoryError = res.error;
348
360
  this.sysHistoryPreviewId = '';
@@ -350,8 +362,11 @@ export function createSystemPromptMethods(options = {}) {
350
362
  }
351
363
  this.sysHistoryPreviewContent = typeof res.content === 'string' ? res.content : '';
352
364
  } catch (e) {
365
+ if (this._sysHistoryRequestToken !== requestToken) return;
353
366
  this.sysHistoryError = this.t('toast.load.fail');
354
367
  this.sysHistoryPreviewId = '';
368
+ } finally {
369
+ if (this._sysHistoryRequestToken === requestToken) this.sysHistoryLoading = false;
355
370
  }
356
371
  },
357
372
 
@@ -0,0 +1,9 @@
1
+ // Keep this contract aligned with CONFIG_CHANGE_ACTIONS in cli.js.
2
+ export const CONFIG_CHANGE_ACTIONS = Object.freeze({
3
+ 'apply-config-template': 'codex', 'add-provider': 'codex', 'update-provider': 'codex',
4
+ 'delete-provider': 'codex', 'reset-config': 'codex', 'add-model': 'codex', 'delete-model': 'codex',
5
+ 'apply-claude-settings-raw': 'claude', 'apply-claude-config': 'claude',
6
+ 'apply-opencode-config': 'opencode', 'update-opencode-selection': 'opencode',
7
+ 'apply-kilocode-config': 'kilocode', 'apply-openclaw-config': 'openclaw',
8
+ 'write-pi-models': 'pi', 'write-pi-settings': 'pi', 'apply-pi-config-history': 'pi'
9
+ });
@@ -0,0 +1,70 @@
1
+ export function createContextHealthMethods({ api }) {
2
+ return {
3
+ async loadSessionContextHealth(force = false) {
4
+ if (!this.activeSession || (this.mainTab !== 'sessions' && !this.sessionStandalone)) return;
5
+ const session = this.activeSession;
6
+ const stamp = `${this.getSessionExportKey(session)}:${this.sessionDetailRequestSeq}`;
7
+ if (force !== true && this.sessionContextHealthStamp === stamp) return;
8
+ this.sessionContextHealthStamp = stamp;
9
+ this.sessionContextHealth = null;
10
+ this.sessionContextHealthError = '';
11
+ this.sessionContextHealthFocusedNode = null;
12
+ this.sessionContextHealthLoading = true;
13
+ try {
14
+ const result = await api('session-context-health', { source: session.source,
15
+ sessionId: session.sessionId, filePath: session.filePath, cwd: session.cwd });
16
+ if (this.activeSession !== session || this.sessionContextHealthStamp !== stamp) return;
17
+ if (result.error) throw new Error(result.error);
18
+ this.sessionContextHealth = Object.freeze(result);
19
+ } catch (error) {
20
+ if (this.activeSession === session && this.sessionContextHealthStamp === stamp) {
21
+ this.sessionContextHealthError = error.message || this.t('toast.load.fail');
22
+ }
23
+ } finally {
24
+ if (this.sessionContextHealthStamp === stamp) this.sessionContextHealthLoading = false;
25
+ }
26
+ },
27
+ toggleContextHealthDetails() {
28
+ this.sessionContextHealthPinned = !this.sessionContextHealthPinned;
29
+ this.sessionContextHealthExpanded = this.sessionContextHealthPinned;
30
+ },
31
+ leaveContextHealthDetails() {
32
+ if (!this.sessionContextHealthPinned) this.sessionContextHealthExpanded = false;
33
+ },
34
+ contextHealthReasonLabel(reason) {
35
+ return this.t(`contextHealth.reason.${reason}`);
36
+ },
37
+ async jumpToContextHealthNode(node) {
38
+ if (!this.activeSession || this.sessionContextHealthNodeLoading) return;
39
+ const session = this.activeSession;
40
+ const stamp = this.sessionContextHealthStamp;
41
+ this.sessionContextHealthNodeLoading = true;
42
+ this.sessionContextHealthError = '';
43
+ try {
44
+ const result = await api('session-context-node', { source: session.source,
45
+ sessionId: session.sessionId, filePath: session.filePath, cwd: session.cwd, nodeId: node.id });
46
+ if (this.activeSession !== session || this.sessionContextHealthStamp !== stamp) return;
47
+ if (result.error) throw new Error(result.error);
48
+ this.sessionContextHealthFocusedNode = Object.freeze({ ...result.node,
49
+ estimatedTokens: node.estimatedTokens, percentage: node.percentage });
50
+ const matching = node.id.includes('.') ? -1
51
+ : this.activeSessionMessages.findIndex((message) => message.recordLineIndex === result.node.recordLineIndex
52
+ && typeof message.text === 'string' && message.text.trim() === result.node.text.trim());
53
+ if (matching >= 0 && this.sessionPreviewRenderEnabled) {
54
+ this.sessionPreviewVisibleCount = Math.max(this.sessionPreviewVisibleCount, matching + 1);
55
+ }
56
+ await this.$nextTick();
57
+ const message = matching >= 0 ? this.activeSessionMessages[matching] : null;
58
+ const key = message ? this.getRecordRenderKey(message, matching) : '';
59
+ const original = key && this.sessionMessageRefMap[key];
60
+ const target = original || this.$refs.contextHealthFocusedMessage;
61
+ if (target) {
62
+ target.scrollIntoView({ block: 'start', behavior: 'auto' });
63
+ if (target === this.$refs.contextHealthFocusedMessage) target.focus();
64
+ }
65
+ } catch (error) {
66
+ if (this.activeSession === session) this.sessionContextHealthError = error.message || this.t('toast.load.fail');
67
+ } finally { this.sessionContextHealthNodeLoading = false; }
68
+ }
69
+ };
70
+ }