agent-things 1.3.1 → 1.3.3

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.
@@ -6,6 +6,7 @@ const os = require('node:os');
6
6
  const crypto = require('node:crypto');
7
7
  const { readConfiguredLang, getUi } = require('./i18n.cjs');
8
8
  const { createPresentation } = require('./ui-foundation.cjs');
9
+ const PACKAGE_VERSION = require('../package.json').version;
9
10
 
10
11
  const presentationHelper = createPresentation('zh');
11
12
 
@@ -87,7 +88,7 @@ function renderAntigravityCardHtml({
87
88
  lang = readConfiguredLang(),
88
89
  } = {}) {
89
90
  const ui = getUi(lang);
90
- const { t, labels: uiLabels, taskLabels: uiTaskLabels, strings: uiStrings } = ui;
91
+ const { t, labels: uiLabels, taskLabels: uiTaskLabels, strings: uiStrings, updateBannerState } = ui;
91
92
  const clientI18n = { ...uiStrings };
92
93
  delete clientI18n.defaultDocTitle;
93
94
  const resolvedTitle = title || t('defaultSessionTitle');
@@ -115,6 +116,7 @@ function renderAntigravityCardHtml({
115
116
  title: resolvedTitle,
116
117
  lang: ui.lang,
117
118
  loadToken: connection?.loadToken || null,
119
+ packageVersion: PACKAGE_VERSION,
118
120
  });
119
121
 
120
122
  const lightAccentPalette = presentationHelper.resolveAccentPalette(readAntigravityConfiguredAccent({ isDark: false }), { isDark: false, fallback: '#2F75C3' });
@@ -744,6 +746,72 @@ function renderAntigravityCardHtml({
744
746
  margin-top: 8px;
745
747
  }
746
748
 
749
+ .app-update {
750
+ margin-top: 3px;
751
+ padding: 10px 11px;
752
+ background: var(--hover);
753
+ border: 1px solid var(--line);
754
+ border-radius: 10px;
755
+ }
756
+ .app-update-row {
757
+ display: flex;
758
+ align-items: center;
759
+ justify-content: space-between;
760
+ gap: 10px;
761
+ }
762
+ .app-update-label {
763
+ font-size: 12px;
764
+ line-height: 18px;
765
+ color: var(--ink);
766
+ min-width: 0;
767
+ overflow-wrap: anywhere;
768
+ }
769
+ .app-update-button {
770
+ flex: none;
771
+ padding: 5px 10px;
772
+ min-height: 28px;
773
+ border-radius: 7px;
774
+ font-size: 11px;
775
+ }
776
+ .app-update-detail {
777
+ margin-top: 7px;
778
+ font-size: 11px;
779
+ line-height: 1.6;
780
+ color: var(--secondary);
781
+ white-space: pre-wrap;
782
+ overflow-wrap: anywhere;
783
+ user-select: text;
784
+ }
785
+ .app-update[data-failed=true] .app-update-detail {
786
+ color: var(--error);
787
+ }
788
+
789
+ .version-bar {
790
+ display: flex;
791
+ align-items: center;
792
+ justify-content: space-between;
793
+ gap: 10px;
794
+ padding: 10px 0 2px;
795
+ font-size: 11px;
796
+ line-height: 16px;
797
+ color: var(--muted);
798
+ }
799
+ .version-bar-text {
800
+ min-width: 0;
801
+ overflow-wrap: anywhere;
802
+ }
803
+ .version-bar[data-failed=true] .version-bar-text {
804
+ color: var(--error);
805
+ }
806
+ .version-check-button {
807
+ flex: none;
808
+ font-size: 11px;
809
+ color: var(--muted);
810
+ }
811
+ .version-check-button:hover:not(:disabled) {
812
+ color: inherit;
813
+ }
814
+
747
815
  /* Views */
748
816
  .view-heading {
749
817
  position: sticky;
@@ -1207,6 +1275,17 @@ function renderAntigravityCardHtml({
1207
1275
  <span>${escapeHtml(t('notesLabel'))}</span>
1208
1276
  <span class="row-detail" id="noteOpenLabel">${escapeHtml(note ? t('editLabel') : t('addLabel'))}</span>
1209
1277
  </button>
1278
+ <div class="app-update" id="appUpdateBox" hidden>
1279
+ <div class="app-update-row">
1280
+ <span class="app-update-label" id="appUpdateLabel" role="status"></span>
1281
+ <button type="button" class="primary app-update-button" id="btnAppUpdate" onclick="onUpgradeClick()">${escapeHtml(t('upgradeBtn'))}</button>
1282
+ </div>
1283
+ <div class="app-update-detail" id="appUpdateDetail" hidden></div>
1284
+ </div>
1285
+ </div>
1286
+ <div class="version-bar" id="versionBar">
1287
+ <span class="version-bar-text" id="versionBarText" role="status">${escapeHtml(t('versionTagPattern', { version: PACKAGE_VERSION }))}</span>
1288
+ <button type="button" class="text-button version-check-button" id="btnCheckUpdate" onclick="onCheckUpdateClick()">${escapeHtml(t('checkUpdateBtn'))}</button>
1210
1289
  </div>
1211
1290
  </div>
1212
1291
 
@@ -1317,12 +1396,23 @@ function renderAntigravityCardHtml({
1317
1396
  }
1318
1397
  const conversationId = ${JSON.stringify(conversationId)};
1319
1398
  const connection = ${configJson};
1399
+ const computeUpdateBannerState = ${updateBannerState.toString()};
1320
1400
  let currentRevision = ${Number(revision) || 0};
1321
1401
  let savedRevision = ${Number(revision) || 0};
1322
1402
  let draftBaseRevision = savedRevision;
1323
1403
  let isFormDirty = false;
1324
1404
  let pendingRemoteSnapshot = null;
1325
1405
  let saveSwitchTimer = null;
1406
+ let currentUpdateInfo = null;
1407
+ let updateTimer = null;
1408
+ let manualCheckTimer = null;
1409
+ let updateChecking = false;
1410
+ let upgradeStarting = false;
1411
+ let updateConnectionError = '';
1412
+ let manualCheckStatus = '';
1413
+ let manualCheckError = '';
1414
+ let updatePollingStarted = false;
1415
+ let isSessionAnalyzing = false;
1326
1416
  let currentState = ${JSON.stringify(state)};
1327
1417
  let currentProgress = ${progress != null ? Number(progress) : 'null'};
1328
1418
  let isDraggingSlider = false;
@@ -1959,6 +2049,7 @@ function renderAntigravityCardHtml({
1959
2049
  }
1960
2050
 
1961
2051
  const analyzing = Boolean(s.analyzing || s.analysisStatus?.status === 'pending');
2052
+ isSessionAnalyzing = analyzing;
1962
2053
  const analysisStatus = s.analysisStatus;
1963
2054
  const btnAnalyze = document.getElementById('btnAnalyze');
1964
2055
  if (btnAnalyze) {
@@ -1966,7 +2057,7 @@ function renderAntigravityCardHtml({
1966
2057
  btnAnalyze.disabled = true;
1967
2058
  btnAnalyze.textContent = i18n.btnUpdating;
1968
2059
  } else {
1969
- btnAnalyze.disabled = false;
2060
+ btnAnalyze.disabled = ['waiting', 'installing'].includes(currentUpdateInfo?.update?.stage);
1970
2061
  btnAnalyze.textContent = i18n.btnUpdate;
1971
2062
  if (analysisStatus?.status === 'failed') {
1972
2063
  showFeedback(i18n.analysisNotDonePrefix + (analysisStatus.error || i18n.analysisAbnormal), true);
@@ -2180,6 +2271,146 @@ function renderAntigravityCardHtml({
2180
2271
  }
2181
2272
  }
2182
2273
 
2274
+ function renderUpdateUi(info) {
2275
+ if (info !== undefined) currentUpdateInfo = info;
2276
+ const effectiveInfo = currentUpdateInfo || {
2277
+ currentVersion: connection?.packageVersion || '',
2278
+ available: false,
2279
+ command: 'npx agent-things@latest',
2280
+ update: null,
2281
+ };
2282
+ const banner = computeUpdateBannerState(effectiveInfo, i18n, {
2283
+ starting: upgradeStarting,
2284
+ checking: updateChecking,
2285
+ connectionError: updateConnectionError,
2286
+ manualCheckStatus: manualCheckStatus,
2287
+ checkError: manualCheckError,
2288
+ });
2289
+ const box = document.getElementById('appUpdateBox');
2290
+ const labelEl = document.getElementById('appUpdateLabel');
2291
+ const upgradeEl = document.getElementById('btnAppUpdate');
2292
+ const detailEl = document.getElementById('appUpdateDetail');
2293
+ const versionBarEl = document.getElementById('versionBar');
2294
+ const versionTextEl = document.getElementById('versionBarText');
2295
+ const checkBtnEl = document.getElementById('btnCheckUpdate');
2296
+ if (box) {
2297
+ box.hidden = !banner.visible;
2298
+ box.setAttribute('data-failed', String(banner.failed));
2299
+ }
2300
+ if (labelEl) labelEl.textContent = banner.label;
2301
+ if (upgradeEl) {
2302
+ upgradeEl.textContent = banner.buttonText;
2303
+ upgradeEl.disabled = banner.buttonDisabled;
2304
+ }
2305
+ if (detailEl) {
2306
+ detailEl.textContent = banner.detail;
2307
+ detailEl.hidden = !banner.detail;
2308
+ }
2309
+ if (versionBarEl) {
2310
+ versionBarEl.hidden = !(banner.showVersionBar && (effectiveInfo.currentVersion || banner.checking || banner.checkFailed));
2311
+ versionBarEl.setAttribute('data-failed', String(banner.checkFailed));
2312
+ }
2313
+ if (versionTextEl) versionTextEl.textContent = banner.versionText;
2314
+ if (checkBtnEl) {
2315
+ checkBtnEl.textContent = banner.checkButtonText;
2316
+ checkBtnEl.disabled = banner.checkDisabled;
2317
+ }
2318
+ const btnAnalyze = document.getElementById('btnAnalyze');
2319
+ if (btnAnalyze) {
2320
+ btnAnalyze.disabled = isSessionAnalyzing || ['waiting', 'installing'].includes(currentUpdateInfo?.update?.stage);
2321
+ }
2322
+ return banner.active;
2323
+ }
2324
+
2325
+ async function pollAppUpdate() {
2326
+ if (updateTimer) {
2327
+ clearTimeout(updateTimer);
2328
+ updateTimer = null;
2329
+ }
2330
+ try {
2331
+ const reply = await sendProxyAction('app-update-info', {});
2332
+ const info = reply?.updateInfo ?? null;
2333
+ updateConnectionError = '';
2334
+ if (info?.available) {
2335
+ manualCheckStatus = '';
2336
+ manualCheckError = '';
2337
+ }
2338
+ const active = renderUpdateUi(info);
2339
+ updateTimer = setTimeout(pollAppUpdate, active ? 2000 : 60000);
2340
+ } catch (err) {
2341
+ updateConnectionError = err?.message || i18n.cardOpFailed;
2342
+ if (currentUpdateInfo) renderUpdateUi(currentUpdateInfo);
2343
+ updateTimer = setTimeout(pollAppUpdate, 5000);
2344
+ }
2345
+ }
2346
+
2347
+ async function onCheckUpdateClick() {
2348
+ if (updateChecking) return;
2349
+ if (updateTimer) {
2350
+ clearTimeout(updateTimer);
2351
+ updateTimer = null;
2352
+ }
2353
+ if (manualCheckTimer) {
2354
+ clearTimeout(manualCheckTimer);
2355
+ manualCheckTimer = null;
2356
+ }
2357
+ updateChecking = true;
2358
+ manualCheckStatus = '';
2359
+ manualCheckError = '';
2360
+ renderUpdateUi();
2361
+ try {
2362
+ const reply = await sendProxyAction('app-update-info', { force: true });
2363
+ const info = reply?.updateInfo ?? null;
2364
+ updateChecking = false;
2365
+ updateConnectionError = '';
2366
+ if (info?.checkError && !info?.available) {
2367
+ manualCheckStatus = 'failed';
2368
+ manualCheckError = info.checkError;
2369
+ } else if (!info?.available) {
2370
+ manualCheckStatus = 'latest';
2371
+ manualCheckTimer = setTimeout(function() {
2372
+ manualCheckTimer = null;
2373
+ if (manualCheckStatus === 'latest') {
2374
+ manualCheckStatus = '';
2375
+ renderUpdateUi();
2376
+ }
2377
+ }, 5000);
2378
+ }
2379
+ const active = renderUpdateUi(info);
2380
+ updateTimer = setTimeout(pollAppUpdate, active ? 2000 : 60000);
2381
+ } catch (err) {
2382
+ updateChecking = false;
2383
+ manualCheckStatus = 'failed';
2384
+ manualCheckError = err?.message || i18n.cardOpFailed;
2385
+ renderUpdateUi();
2386
+ updateTimer = setTimeout(pollAppUpdate, 60000);
2387
+ }
2388
+ }
2389
+
2390
+ async function onUpgradeClick() {
2391
+ const upgradeEl = document.getElementById('btnAppUpdate');
2392
+ if (upgradeEl?.disabled || upgradeStarting) return;
2393
+ if (updateTimer) {
2394
+ clearTimeout(updateTimer);
2395
+ updateTimer = null;
2396
+ }
2397
+ upgradeStarting = true;
2398
+ manualCheckStatus = '';
2399
+ manualCheckError = '';
2400
+ renderUpdateUi();
2401
+ try {
2402
+ const reply = await sendProxyAction('app-update-start', {});
2403
+ upgradeStarting = false;
2404
+ updateConnectionError = '';
2405
+ renderUpdateUi(reply?.updateInfo ?? null);
2406
+ } catch (err) {
2407
+ upgradeStarting = false;
2408
+ updateConnectionError = err?.message || i18n.cardOpFailed;
2409
+ renderUpdateUi();
2410
+ }
2411
+ updateTimer = setTimeout(pollAppUpdate, 1000);
2412
+ }
2413
+
2183
2414
  async function initEventStream() {
2184
2415
  if (sseReconnectTimer) {
2185
2416
  clearTimeout(sseReconnectTimer);
@@ -2198,6 +2429,10 @@ function renderAntigravityCardHtml({
2198
2429
  }
2199
2430
  authTicket = auth.ticket;
2200
2431
  serviceOrigin = auth.origin;
2432
+ if (!updatePollingStarted && hostChannelPort) {
2433
+ updatePollingStarted = true;
2434
+ void pollAppUpdate();
2435
+ }
2201
2436
 
2202
2437
  const sseUrl = auth.origin + '/session/events?id=' + encodeURIComponent(conversationId) + '&ticket=' + encodeURIComponent(auth.ticket);
2203
2438
  const es = new EventSource(sseUrl);
@@ -1039,12 +1039,13 @@
1039
1039
  return;
1040
1040
  }
1041
1041
 
1042
- // 宿主桥代发写操作(保存、清除、分析)
1042
+ // 宿主桥代发写操作(保存、清除、分析、版本更新)
1043
1043
  if (data.type === 'AGENT_THINGS_ACTION_PROXY') {
1044
1044
  const { nonce, action, payload } = data;
1045
1045
  if (!nonce) return;
1046
1046
  try {
1047
1047
  const key = JSON.stringify(['local', boundConvId]);
1048
+ const isUpdateAction = action === 'app-update-info' || action === 'app-update-start';
1048
1049
  let rpcMsg = null;
1049
1050
  if (action === 'update') {
1050
1051
  rpcMsg = { type: 'update', key, record: payload.record, expectedRevision: payload.expectedRevision, requestId: 'proxy-update-' + Date.now() };
@@ -1052,6 +1053,15 @@
1052
1053
  rpcMsg = { type: 'clear', key, expectedRevision: payload.expectedRevision, requestId: 'proxy-clear-' + Date.now() };
1053
1054
  } else if (action === 'analyze') {
1054
1055
  rpcMsg = { type: 'analyze', key, requestId: 'proxy-analyze-' + Date.now() };
1056
+ } else if (action === 'app-update-info') {
1057
+ rpcMsg = {
1058
+ type: 'app-update-info',
1059
+ key,
1060
+ ...(typeof payload?.force === 'boolean' ? { force: payload.force } : {}),
1061
+ requestId: 'proxy-update-info-' + Date.now(),
1062
+ };
1063
+ } else if (action === 'app-update-start') {
1064
+ rpcMsg = { type: 'app-update-start', key, requestId: 'proxy-update-start-' + Date.now() };
1055
1065
  }
1056
1066
  if (rpcMsg) {
1057
1067
  const res = await fetch(`${getServiceOrigin()}/rpc`, {
@@ -1060,6 +1070,18 @@
1060
1070
  body: JSON.stringify(rpcMsg),
1061
1071
  });
1062
1072
  const reply = await res.json();
1073
+ if (isUpdateAction) {
1074
+ sendReplyToCard(binding, targetPort, {
1075
+ type: 'AGENT_THINGS_ACTION_RESULT',
1076
+ nonce,
1077
+ action,
1078
+ success: !reply.error,
1079
+ error: reply.error || null,
1080
+ updateInfo: reply.updateInfo || null,
1081
+ data: { updateInfo: reply.updateInfo || null, lang: reply.lang },
1082
+ });
1083
+ return;
1084
+ }
1063
1085
  if (reply.snapshot) {
1064
1086
  window.__codexSessionStatus?.receive?.(reply.snapshot);
1065
1087
  }
@@ -368,6 +368,11 @@ if (typeof globalThis !== 'undefined' && !globalThis.__agentThingsPresentation)
368
368
  updateFailedLabel: '升级失败',
369
369
  upgradeBtn: '立即升级',
370
370
  upgradingShort: '正在升级…',
371
+ checkUpdateBtn: '检查更新',
372
+ checkingUpdateShort: '正在检查…',
373
+ alreadyLatestPattern: '当前已是最新版 v{version}',
374
+ versionTagPattern: 'v{version}',
375
+ checkUpdateFailedLabel: '检查更新失败',
371
376
  pleaseWait: '请稍候',
372
377
  completedShort: '已完成',
373
378
  retryBtn: '重试',
@@ -557,6 +562,11 @@ if (typeof globalThis !== 'undefined' && !globalThis.__agentThingsPresentation)
557
562
  updateFailedLabel: 'Upgrade failed',
558
563
  upgradeBtn: 'Upgrade',
559
564
  upgradingShort: 'Upgrading...',
565
+ checkUpdateBtn: 'Check updates',
566
+ checkingUpdateShort: 'Checking...',
567
+ alreadyLatestPattern: 'Up to date (v{version})',
568
+ versionTagPattern: 'v{version}',
569
+ checkUpdateFailedLabel: 'Update check failed',
560
570
  pleaseWait: 'Please wait',
561
571
  completedShort: 'Done',
562
572
  retryBtn: 'Retry',
@@ -646,6 +656,72 @@ if (typeof globalThis !== 'undefined' && !globalThis.__agentThingsPresentation)
646
656
  function analysisDisabled(busy, analyzing, upgradeStage) {
647
657
  return Boolean(busy || analyzing || ['waiting', 'installing'].includes(upgradeStage));
648
658
  }
659
+ function updateBannerState(info, dict, options = {}) {
660
+ const textDict = dict || {};
661
+ const fmtText = (template, vars = {}) => String(template || '').replace(/\{(\w+)\}/g, (_, k) => (vars[k] !== undefined ? String(vars[k]) : ''));
662
+ const update = info?.update;
663
+ const stage = update?.stage;
664
+ const stages = textDict.updateStages || {
665
+ queued: 'Preparing upgrade',
666
+ checking: 'Checking version',
667
+ downloading: 'Downloading update',
668
+ waiting: 'Waiting for analysis to finish',
669
+ installing: 'Upgrading',
670
+ };
671
+ const activeStage = Boolean(stages[stage]) || Boolean(options.starting);
672
+ const updatedAtMs = update?.updatedAt ? Date.parse(update.updatedAt) : NaN;
673
+ const now = options.now ?? Date.now();
674
+ const completed = stage === 'completed' && Number.isFinite(updatedAtMs) && now - updatedAtMs < 60000;
675
+ const failed = stage === 'failed';
676
+ const visible = Boolean(info?.available || activeStage || failed || completed);
677
+ const command = info?.command || 'npx agent-things@latest';
678
+ const label = activeStage
679
+ ? (stages[stage] || stages.queued)
680
+ : failed
681
+ ? fmtText(textDict.updateFailedLabel || 'Upgrade failed')
682
+ : completed
683
+ ? fmtText(textDict.upgradedToPattern || 'Upgraded to v{version}', { version: update?.currentVersion || '' })
684
+ : fmtText(textDict.updateAvailablePattern || 'Update available v{version}', { version: info?.latestVersion || '' });
685
+ const buttonText = activeStage
686
+ ? (textDict.pleaseWait || 'Please wait')
687
+ : completed
688
+ ? (textDict.completedShort || 'Done')
689
+ : failed
690
+ ? (textDict.retryBtn || 'Retry')
691
+ : (textDict.upgradeBtn || 'Upgrade');
692
+ const detail = options.connectionError
693
+ ? `${textDict.reconnectHint || ''}\n${textDict.terminalUpgradePrefix || ''}${command}`
694
+ : failed
695
+ ? `${update?.error || ''}\n${textDict.terminalUpgradePrefix || ''}${command}`
696
+ : (completed && update?.reconnectMcp ? (textDict.reconnectMcpHint || '') : '');
697
+ const currentVersion = info?.currentVersion || '';
698
+ const checkFailed = !visible && options.manualCheckStatus === 'failed';
699
+ let versionText = currentVersion ? fmtText(textDict.versionTagPattern || 'v{version}', { version: currentVersion }) : '';
700
+ if (checkFailed) {
701
+ const errText = options.checkError || info?.checkError || '';
702
+ versionText = errText ? `${textDict.checkUpdateFailedLabel || 'Update check failed'}: ${errText}` : (textDict.checkUpdateFailedLabel || 'Update check failed');
703
+ } else if (!visible && options.manualCheckStatus === 'latest' && currentVersion) {
704
+ versionText = fmtText(textDict.alreadyLatestPattern || 'Up to date (v{version})', { version: currentVersion });
705
+ }
706
+ const checking = Boolean(options.checking);
707
+ return {
708
+ visible,
709
+ active: activeStage,
710
+ completed,
711
+ failed,
712
+ buttonDisabled: activeStage || completed,
713
+ label,
714
+ buttonText,
715
+ detail,
716
+ currentVersion,
717
+ versionText,
718
+ showVersionBar: !visible,
719
+ checking,
720
+ checkDisabled: checking,
721
+ checkFailed,
722
+ checkButtonText: checking ? (textDict.checkingUpdateShort || 'Checking...') : (textDict.checkUpdateBtn || 'Check updates'),
723
+ };
724
+ }
649
725
 
650
726
  const active = forLang(currentLang);
651
727
  return {
@@ -668,6 +744,7 @@ if (typeof globalThis !== 'undefined' && !globalThis.__agentThingsPresentation)
668
744
  progressState,
669
745
  draftTransition,
670
746
  analysisDisabled,
747
+ updateBannerState,
671
748
  };
672
749
  })(globalThis.__agentThingsLang);
673
750
  }
@@ -233,7 +233,11 @@ class ClaudeService {
233
233
  const reply = await this.rpc({ type: 'analyze', key, requestId: message.requestId });
234
234
  if (reply.error) throw Object.assign(new Error(reply.error), reply.errorInfo || {});
235
235
  } else if (message.action === 'update-info' || message.action === 'upgrade') {
236
- const reply = await this.rpc({ type: message.action === 'upgrade' ? 'app-update-start' : 'app-update-info', requestId: message.requestId });
236
+ const reply = await this.rpc({
237
+ type: message.action === 'upgrade' ? 'app-update-start' : 'app-update-info',
238
+ ...(message.action === 'update-info' && message.force === true ? { force: true } : {}),
239
+ requestId: message.requestId,
240
+ });
237
241
  if (reply.error) throw Object.assign(new Error(reply.error), reply.errorInfo || {});
238
242
  return { updateInfo: reply.updateInfo, lang };
239
243
  } else if (message.action !== 'read') throw new Error(en ? 'Unknown card action' : '未知卡片操作');
@@ -1,9 +1,21 @@
1
1
  'use strict';
2
2
  const crypto = require('node:crypto');
3
+ const { stripLeadingEnvelopes } = require('../../analysis-history.cjs');
3
4
 
4
- function textContent(content) {
5
- if (typeof content === 'string') return content;
6
- return Array.isArray(content) ? content.filter(part => part.type === 'text').map(part => part.text || '').join('\n') : '';
5
+ function textContent(content, { stripEnvelopes = false } = {}) {
6
+ const cleanPart = text => (stripEnvelopes ? stripLeadingEnvelopes(text) : String(text || ''));
7
+ if (typeof content === 'string') return cleanPart(content);
8
+ return Array.isArray(content)
9
+ ? content.filter(part => part?.type === 'text').map(part => cleanPart(part.text || '')).filter(Boolean).join('\n')
10
+ : '';
11
+ }
12
+
13
+ function cleanCompactSummary(text) {
14
+ let value = String(text || '').trim();
15
+ value = value.replace(/^This session is being continued from a previous conversation[\s\S]*?(?=<system-reminder>|\bSummary:)/i, '');
16
+ value = stripLeadingEnvelopes(value);
17
+ value = value.replace(/\n+(?:If you need specific details from before compaction|Continue the conversation from where it left off|Please continue the conversation|If you are working with the user|The messages after this summary are the most recent messages from before compaction)[\s\S]*$/i, '').trim();
18
+ return value ? `[前情摘要]\n${value}` : '';
7
19
  }
8
20
 
9
21
  function transcriptTurns(result) {
@@ -21,9 +33,10 @@ function appendTranscriptEntry(turns, entry) {
21
33
  function cleanTranscriptMessage(entry) {
22
34
  const message = entry.message || entry;
23
35
  const role = message.role || entry.type;
24
- if (!['user', 'assistant'].includes(role) || entry.isSidechain) return null;
36
+ if (!['user', 'assistant'].includes(role) || entry.isSidechain || entry.isMeta) return null;
25
37
  if (role === 'assistant' && message.stop_reason && message.stop_reason !== 'end_turn') return null;
26
- const original = textContent(message.content);
38
+ let original = textContent(message.content, { stripEnvelopes: true });
39
+ if (role === 'user' && entry.isCompactSummary) original = cleanCompactSummary(original);
27
40
  const text = original.length > 24000 ? `${original.slice(0, 12000)}\n[内容已精简]\n${original.slice(-12000)}` : original;
28
41
  if (!text.trim()) return null;
29
42
  const id = entry.uuid || entry.id;
@@ -70,7 +70,7 @@
70
70
  installCodexSessionStatus('codex-mcp-app', null, {
71
71
  container, key, title, snapshot, analysisState, session, theme, lang: initial.lang || snapshot?.lang,
72
72
  async send(payload) {
73
- const { type, requestId, expectedRevision, record, source, cancelRequestId } = JSON.parse(payload);
73
+ const { type, requestId, expectedRevision, record, source, cancelRequestId, force } = JSON.parse(payload);
74
74
  if (type === 'panel-event') return;
75
75
  if (type === 'cancel-request') {
76
76
  for (const [id, entry] of pending) if (entry.uiRequestId === cancelRequestId) {
@@ -82,6 +82,7 @@
82
82
  const name = readActions.has(type) ? 'read_session_card' : 'change_session_card';
83
83
  try {
84
84
  const result = await request('tools/call', { name, arguments: { conversation_id: conversationId, card_token: cardToken, action: type,
85
+ ...(typeof force === 'boolean' ? { force } : {}),
85
86
  ...(expectedRevision == null ? {} : { expectedRevision }), ...(record === undefined ? {} : { record }), ...(source ? { source } : {}) } }, 18000, requestId);
86
87
  const errorInfo = result.structuredContent?.errorInfo;
87
88
  const error = result.isError || !result.structuredContent ? result.content?.[0]?.text || uiText('cardOpFailed', '卡片操作失败') : undefined;
@@ -121,7 +122,7 @@
121
122
  }
122
123
  });
123
124
 
124
- request('ui/initialize', { appInfo: { name: 'agent-things', version: window.__agentThingsVersion || '1.3.1' }, appCapabilities: {}, protocolVersion: '2026-01-26' }, 5000)
125
+ request('ui/initialize', { appInfo: { name: 'agent-things', version: window.__agentThingsVersion || '1.3.3' }, appCapabilities: {}, protocolVersion: '2026-01-26' }, 5000)
125
126
  .then(result => {
126
127
  theme = result?.hostContext?.theme;
127
128
  if (theme === 'light' || theme === 'dark') {
@@ -31,7 +31,7 @@ function getCardTools(lang = readConfiguredLang()) {
31
31
  description: en
32
32
  ? 'Read card status, Git info, version updates, or wait for session changes'
33
33
  : '读取卡片状态、Git 信息、版本或等待会话变更',
34
- inputSchema: { type: 'object', properties: { ...cardProperties, action: { enum: ['analysis-state', 'project-git', 'app-update-info', 'watch-state'] }, cursor: { type: 'string', pattern: '^[a-f0-9]{64}$' } }, required: ['conversation_id', 'card_token', 'action'], additionalProperties: false },
34
+ inputSchema: { type: 'object', properties: { ...cardProperties, action: { enum: ['analysis-state', 'project-git', 'app-update-info', 'watch-state'] }, cursor: { type: 'string', pattern: '^[a-f0-9]{64}$' }, force: { type: 'boolean' } }, required: ['conversation_id', 'card_token', 'action'], additionalProperties: false },
35
35
  annotations: { readOnlyHint: true }, _meta: { ui: { visibility: ['app'] } } },
36
36
  { name: 'change_session_card',
37
37
  description: en
@@ -148,6 +148,7 @@ function createCodexCard({ store, request = (message, options) => requestProgres
148
148
  }
149
149
  let result;
150
150
  try { result = await request({ protocolVersion: PROTOCOL_VERSION, type: action, key, expectedRevision: args.expectedRevision, record: args.record,
151
+ ...(action === 'app-update-info' && typeof args.force === 'boolean' ? { force: args.force } : {}),
151
152
  ...(action === 'locate-source' ? { source: { turnId: args.source?.turnId, itemId: args.source?.itemId } } : {}) }, options); }
152
153
  catch (error) { result = { error: error.message, errorInfo: errorDetails(error, undefined, lang) }; }
153
154
  if (result.error) {
@@ -17,6 +17,7 @@ const CHECK_FILE = path.join(DATA_DIR, 'npm-version-check.json');
17
17
  const PLIST = path.join(DATA_DIR, 'npm-update.plist');
18
18
  const PACKAGE = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
19
19
  const ACTIVE = new Set(['queued', 'checking', 'downloading', 'waiting', 'installing']);
20
+ const CHECK_INTERVAL_MS = 3600000;
20
21
  const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
21
22
  let checking;
22
23
 
@@ -67,7 +68,7 @@ async function getUpdateInfo({ force = false } = {}) {
67
68
  if (!currentVersion) return { currentVersion: null, available: false, command: `npx ${PACKAGE.name}@latest`, update };
68
69
  let cached = fs.existsSync(CHECK_FILE) ? JSON.parse(fs.readFileSync(CHECK_FILE, 'utf8')) : null;
69
70
  if (cached?.currentVersion !== currentVersion) cached = null;
70
- if (!ACTIVE.has(update?.stage) && (force || !cached || Date.now() - Date.parse(cached.attemptedAt) >= 86400000)) {
71
+ if (!ACTIVE.has(update?.stage) && (force || !cached || Date.now() - Date.parse(cached.attemptedAt) >= CHECK_INTERVAL_MS)) {
71
72
  if (!checking) checking = (async () => {
72
73
  const attemptedAt = new Date().toISOString();
73
74
  let result;
@@ -225,4 +226,4 @@ async function startUpdateUnlocked() {
225
226
  const startUpdate = () => require('./lifecycle-lock.cjs').withLifecycleLock(DATA_DIR, startUpdateUnlocked);
226
227
 
227
228
  if (require.main === module && process.argv[2] === '--worker') void runUpdate(process.argv[3]);
228
- module.exports = { newerVersion, checkForUpdate, getUpdateInfo, downloadRelease, readUpdateStatus, startUpdate, assertUpdateIdle, assertSetupIdle, verifyServices, runUpdate };
229
+ module.exports = { CHECK_INTERVAL_MS, newerVersion, checkForUpdate, getUpdateInfo, downloadRelease, readUpdateStatus, startUpdate, assertUpdateIdle, assertSetupIdle, verifyServices, runUpdate };