agent-things 0.0.0-stage → 1.2.2

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 (124) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +5 -0
  3. package/README.md +221 -2
  4. package/bin/agent-things.cjs +8 -0
  5. package/bin/antigravity-session-status.cjs +96 -0
  6. package/bin/claude-session-status.cjs +55 -0
  7. package/bin/codex-session-status.cjs +287 -0
  8. package/mods/agent-things-ui/.claude-plugin/plugin.json +12 -0
  9. package/mods/agent-things-ui/SKILL.md +10 -0
  10. package/mods/agent-things-ui/hooks/controls.js +112 -0
  11. package/mods/agent-things-ui/hooks/foundation.js +431 -0
  12. package/mods/agent-things-ui/hooks/hooks.json +1 -0
  13. package/mods/agent-things-ui/hooks/presentation.js +223 -0
  14. package/mods/agent-things-ui/hooks/progress.js +1 -0
  15. package/mods/agent-things-ui/hooks/register.js +382 -0
  16. package/native/bin/bridge +0 -0
  17. package/native/bin/bridge.json +20 -0
  18. package/native/session-status-bridge.swift +280 -0
  19. package/outputs/antigravity-session-status.js +2476 -0
  20. package/outputs/codex-session-status.js +1761 -0
  21. package/package.json +75 -4
  22. package/scripts/build-antigravity-bundle.cjs +35 -0
  23. package/scripts/build-codex-bundle.cjs +31 -0
  24. package/scripts/build-native-bridge.cjs +55 -0
  25. package/scripts/build-shared-ui.cjs +16 -0
  26. package/scripts/setup-antigravity-service.cjs +71 -0
  27. package/scripts/setup-claude-service.cjs +21 -0
  28. package/skills/agent-things/SKILL.en.md +95 -0
  29. package/skills/agent-things/SKILL.md +99 -0
  30. package/skills/codex/things/SKILL.en.md +10 -0
  31. package/skills/codex/things/SKILL.md +10 -0
  32. package/skills/things/SKILL.en.md +10 -0
  33. package/skills/things/SKILL.md +10 -0
  34. package/skills/things/checklist.en.md +91 -0
  35. package/skills/things/checklist.md +95 -0
  36. package/src/analysis-app-server.cjs +74 -0
  37. package/src/analysis-assets/output.en.schema.json +93 -0
  38. package/src/analysis-assets/output.schema.json +93 -0
  39. package/src/analysis-assets/prompt.en.txt +17 -0
  40. package/src/analysis-assets/prompt.zh-CN.txt +18 -0
  41. package/src/analysis-budget.cjs +105 -0
  42. package/src/analysis-git.cjs +38 -0
  43. package/src/analysis-history.cjs +150 -0
  44. package/src/analysis-ledger.cjs +82 -0
  45. package/src/analysis-log.cjs +62 -0
  46. package/src/analysis-runner.cjs +203 -0
  47. package/src/analysis-service.cjs +197 -0
  48. package/src/analysis-source.cjs +72 -0
  49. package/src/antigravity-card.cjs +2063 -0
  50. package/src/antigravity-hook.cjs +138 -0
  51. package/src/antigravity-mcp-config.cjs +36 -0
  52. package/src/app-server.cjs +96 -0
  53. package/src/cdp.cjs +115 -0
  54. package/src/claude-inline-install.cjs +38 -0
  55. package/src/claude-mcp-config.cjs +29 -0
  56. package/src/cli/arguments.cjs +30 -0
  57. package/src/cli/environment-probe.cjs +130 -0
  58. package/src/cli/integration-state.cjs +15 -0
  59. package/src/cli/interactive-cli.cjs +236 -0
  60. package/src/cli/prompt-tui.cjs +420 -0
  61. package/src/cli/setup-orchestrator.cjs +449 -0
  62. package/src/codex-mcp-config.cjs +67 -0
  63. package/src/harnesses/antigravity/analysis-profile.cjs +41 -0
  64. package/src/harnesses/antigravity/antigravity-git.cjs +89 -0
  65. package/src/harnesses/antigravity/antigravity-harness.js +1477 -0
  66. package/src/harnesses/antigravity/antigravity-injector.cjs +104 -0
  67. package/src/harnesses/antigravity/antigravity-migration.cjs +235 -0
  68. package/src/harnesses/antigravity/antigravity-service.cjs +357 -0
  69. package/src/harnesses/antigravity/antigravity-title.cjs +155 -0
  70. package/src/harnesses/antigravity/gemini-runner.cjs +304 -0
  71. package/src/harnesses/antigravity/transcript-cleaner.cjs +129 -0
  72. package/src/harnesses/antigravity/transcript-source.cjs +100 -0
  73. package/src/harnesses/claude/claude-harness.js +93 -0
  74. package/src/harnesses/claude/claude-host-helper.cjs +176 -0
  75. package/src/harnesses/claude/claude-injector.cjs +95 -0
  76. package/src/harnesses/claude/claude-local-source.cjs +106 -0
  77. package/src/harnesses/claude/claude-navigation.cjs +99 -0
  78. package/src/harnesses/claude/claude-runner.cjs +74 -0
  79. package/src/harnesses/claude/claude-service.cjs +313 -0
  80. package/src/harnesses/claude/claude-source.cjs +70 -0
  81. package/src/harnesses/codex/codex-analysis.cjs +10 -0
  82. package/src/harnesses/codex/codex-card-bridge.js +123 -0
  83. package/src/harnesses/codex/codex-card-events.cjs +76 -0
  84. package/src/harnesses/codex/codex-card.cjs +169 -0
  85. package/src/harnesses/codex/codex-git.cjs +24 -0
  86. package/src/harnesses/codex/codex-harness.js +229 -0
  87. package/src/harnesses/codex/codex-local-card.js +97 -0
  88. package/src/harnesses/codex/codex-progress-context.cjs +84 -0
  89. package/src/harnesses/codex/codex-service.cjs +502 -0
  90. package/src/i18n.cjs +174 -0
  91. package/src/launchd.cjs +105 -0
  92. package/src/lifecycle-lock.cjs +13 -0
  93. package/src/local-progress-http.cjs +267 -0
  94. package/src/manual-status-agent.cjs +12 -0
  95. package/src/manual-status-startup.cjs +66 -0
  96. package/src/manual-status-store.cjs +466 -0
  97. package/src/mcp-stdio.cjs +67 -0
  98. package/src/model-router.cjs +63 -0
  99. package/src/native-bridge.cjs +17 -0
  100. package/src/npm-updates.cjs +228 -0
  101. package/src/plugins/things/assets/logo.svg +13 -0
  102. package/src/plugins/things/plugin.json +6 -0
  103. package/src/plugins/things/sidecars/things_board/app.js +447 -0
  104. package/src/plugins/things/sidecars/things_board/index.html +2141 -0
  105. package/src/plugins/things/sidecars/things_board/main.mjs +652 -0
  106. package/src/plugins/things/sidecars/things_board/package.json +6 -0
  107. package/src/plugins/things/sidecars/things_board/sidecar.json +21 -0
  108. package/src/plugins/things/sidecars/things_board/styles.css +560 -0
  109. package/src/plugins/things/sidecars/things_board/ui-i18n.mjs +434 -0
  110. package/src/progress-error.cjs +54 -0
  111. package/src/progress-tools.cjs +145 -0
  112. package/src/project-path.cjs +15 -0
  113. package/src/renderer-resource.cjs +17 -0
  114. package/src/request-budget.cjs +24 -0
  115. package/src/resolve.cjs +51 -0
  116. package/src/runtime-install.cjs +635 -0
  117. package/src/session-status-filter.cjs +136 -0
  118. package/src/session-status.js +992 -0
  119. package/src/session-view.cjs +34 -0
  120. package/src/startup/controller.cjs +354 -0
  121. package/src/startup/watch.cjs +126 -0
  122. package/src/state-file-lock.cjs +31 -0
  123. package/src/task-provenance.cjs +42 -0
  124. package/src/ui-foundation.cjs +435 -0
@@ -0,0 +1,2063 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const os = require('node:os');
6
+ const crypto = require('node:crypto');
7
+ const { readConfiguredLang, getUi } = require('./i18n.cjs');
8
+
9
+ const colors = {
10
+ unstarted: '#9098a2',
11
+ unfinished: '#c89b38',
12
+ completed: '#548eea',
13
+ pushed: '#a17be3',
14
+ };
15
+
16
+ const defaultUi = getUi('zh');
17
+ const labels = defaultUi.labels;
18
+ const taskLabels = defaultUi.taskLabels;
19
+
20
+ function escapeHtml(str) {
21
+ return String(str ?? '').replace(/[&<>"']/g, c => ({
22
+ '&': '&amp;',
23
+ '<': '&lt;',
24
+ '>': '&gt;',
25
+ '"': '&quot;',
26
+ "'": '&#39;',
27
+ }[c]));
28
+ }
29
+
30
+ function renderSvgRing(progress, state, loading = false) {
31
+ const color = colors[state] || colors.unstarted;
32
+ const radius = 10;
33
+ const strokeWidth = 1.6;
34
+ const hasProgress = progress !== null && progress !== undefined && Number.isFinite(progress);
35
+ const progVal = hasProgress ? Math.max(0, Math.min(100, progress)) : 0;
36
+
37
+ let piePath = '';
38
+ if (hasProgress && progVal > 0) {
39
+ const angle = (progVal / 100) * Math.PI * 2;
40
+ const x = (12 + 7.4 * Math.sin(angle)).toFixed(2);
41
+ const y = (12 - 7.4 * Math.cos(angle)).toFixed(2);
42
+ piePath = progVal === 100
43
+ ? `<path d="M12 4.6a7.4 7.4 0 1 1 0 14.8a7.4 7.4 0 1 1 0-14.8" fill="${color}" class="progress-pie"/>`
44
+ : `<path d="M12 12L12 4.6A7.4 7.4 0 ${progVal > 50 ? 1 : 0} 1 ${x} ${y}Z" fill="${color}" class="progress-pie"/>`;
45
+ }
46
+
47
+ const isHundred = progVal === 100;
48
+ const fontSize = isHundred ? '5.8px' : '6.4px';
49
+ const letterSpacing = isHundred ? '-0.3px' : '-0.2px';
50
+ const textVal = hasProgress ? `${progVal}%` : '—';
51
+
52
+ return `
53
+ <svg viewBox="0 0 24 24" width="32" height="32" aria-hidden="true" style="overflow:visible">
54
+ <circle cx="12" cy="12" r="${radius}" fill="none" stroke="${color}" stroke-width="${strokeWidth}" opacity="${hasProgress ? '1' : '0.85'}"/>
55
+ ${piePath}
56
+ <text x="12" y="12.4" text-anchor="middle" dominant-baseline="middle" fill="${color}" class="${hasProgress ? '' : 'progress-unknown'}" style="font:600 ${fontSize} -apple-system,BlinkMacSystemFont,sans-serif;letter-spacing:${letterSpacing};font-variant-numeric:tabular-nums">${textVal}</text>
57
+ </svg>
58
+ `.trim();
59
+ }
60
+
61
+ function renderAntigravityCardHtml({
62
+ title,
63
+ conversationId = '',
64
+ record = null,
65
+ tasks = [],
66
+ summary = '',
67
+ revision = 0,
68
+ connection = null,
69
+ lang = readConfiguredLang(),
70
+ } = {}) {
71
+ const ui = getUi(lang);
72
+ const { t, labels: uiLabels, taskLabels: uiTaskLabels, strings: uiStrings } = ui;
73
+ const clientI18n = { ...uiStrings };
74
+ delete clientI18n.defaultDocTitle;
75
+ const resolvedTitle = title || t('defaultSessionTitle');
76
+ const htmlLang = ui.lang === 'en' ? 'en' : 'zh-CN';
77
+ const state = record?.state || (record?.progress === 100 ? 'completed' : record?.progress > 0 ? 'unfinished' : 'unstarted');
78
+ const progress = record?.progress ?? null;
79
+ const note = record?.note || '';
80
+ const stateColor = colors[state] || colors.unstarted;
81
+ const stateLabel = uiLabels[state] || uiLabels.unstarted;
82
+ const sourceLabel = record?.source === 'analysis' ? t('sourceAuto') : t('sourceManual');
83
+ const updatedDate = record?.updatedAt ? new Date(record.updatedAt) : new Date();
84
+ const timestampStr = `${updatedDate.getMonth() + 1}/${updatedDate.getDate()} ${String(updatedDate.getHours()).padStart(2, '0')}:${String(updatedDate.getMinutes()).padStart(2, '0')}`;
85
+
86
+ const allTasks = Array.isArray(tasks) ? tasks : [];
87
+ const uncompletedTasks = allTasks.filter(task => task.status !== 'done');
88
+ const completedTasks = allTasks.filter(task => task.status === 'done');
89
+ const totalCount = allTasks.length;
90
+ const doneCount = completedTasks.length;
91
+ const totalsText = totalCount > 0 ? t('totalsPattern', { done: doneCount, total: totalCount }) : t('noTasksYet');
92
+ const summaryText = summary || record?.note || '';
93
+
94
+ const configJson = JSON.stringify({
95
+ origin: connection?.origin || 'http://127.0.0.1:29888',
96
+ conversationId,
97
+ title: resolvedTitle,
98
+ lang: ui.lang,
99
+ loadToken: connection?.loadToken || null,
100
+ });
101
+
102
+ return `<!DOCTYPE html>
103
+ <html lang="${htmlLang}">
104
+ <head>
105
+ <meta charset="utf-8">
106
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
107
+ <title>${escapeHtml(resolvedTitle)} · ${escapeHtml(t('docTitleSuffix'))}</title>
108
+ <style>
109
+ :root {
110
+ --accent: #0169cc;
111
+ --accent-hover: #005bb3;
112
+ --ink: #e6edf3;
113
+ --secondary: #a0a6ad;
114
+ --muted: #828c96;
115
+ --note: #bbc3ca;
116
+ --track: #ffffff12;
117
+ --line: #ffffff14;
118
+ --input-border: #ffffff18;
119
+ --input-bg: #ffffff03;
120
+ --hover: #ffffff09;
121
+ --selected: #ffffff10;
122
+ --source-bg: #ffffff0a;
123
+ --number-line: #ffffff25;
124
+ --thumb: #e6edf3;
125
+ --thumb-edge: #ffffff30;
126
+ --danger: #ef7777;
127
+ --error: #f7ad86;
128
+ --panel-bg: #0e1318;
129
+ font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
130
+ color: var(--ink);
131
+ color-scheme: dark;
132
+ }
133
+ * {
134
+ box-sizing: border-box;
135
+ scrollbar-width: none;
136
+ -ms-overflow-style: none;
137
+ }
138
+ *::-webkit-scrollbar {
139
+ display: none;
140
+ width: 0;
141
+ height: 0;
142
+ }
143
+ button, input, textarea {
144
+ font: inherit;
145
+ color: inherit;
146
+ }
147
+ button {
148
+ cursor: pointer;
149
+ }
150
+ [hidden] {
151
+ display: none !important;
152
+ }
153
+
154
+ body {
155
+ margin: 0;
156
+ padding: 0;
157
+ background: transparent;
158
+ display: flex;
159
+ justify-content: flex-start;
160
+ color: var(--ink);
161
+ font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
162
+ }
163
+
164
+ .shell {
165
+ position: relative;
166
+ width: 340px;
167
+ max-width: 100%;
168
+ max-height: none;
169
+ display: flex;
170
+ flex-direction: column;
171
+ overflow: hidden;
172
+ background: var(--panel-bg);
173
+ border: 1px solid #ffffff1c;
174
+ border-radius: 20px;
175
+ box-shadow: 0 16px 54px rgba(0, 0, 0, 0.35);
176
+ padding: 16px 20px 14px;
177
+ }
178
+ .shell:hover {
179
+ --panel-bg: #1f242a;
180
+ }
181
+
182
+ .title-heading {
183
+ display: flex;
184
+ flex: none;
185
+ align-items: flex-start;
186
+ gap: 10px;
187
+ margin-right: 34px;
188
+ border-radius: 5px;
189
+ outline-offset: 4px;
190
+ cursor: default;
191
+ transition: max-height 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.18s ease, transform 0.22s ease, margin 0.22s ease;
192
+ max-height: 60px;
193
+ opacity: 1;
194
+ transform: translateY(0);
195
+ overflow: visible;
196
+ }
197
+ .shell.is-scrolled .title-heading {
198
+ height: 0;
199
+ min-height: 0;
200
+ max-height: 0;
201
+ opacity: 0;
202
+ visibility: hidden;
203
+ margin: 0;
204
+ padding: 0;
205
+ transform: translateY(-20px);
206
+ overflow: hidden;
207
+ pointer-events: none;
208
+ }
209
+ .open-pane {
210
+ position: absolute;
211
+ right: 13px;
212
+ top: 14px;
213
+ display: inline-flex;
214
+ align-items: center;
215
+ justify-content: center;
216
+ width: 28px;
217
+ height: 28px;
218
+ padding: 0;
219
+ border: 0;
220
+ border-radius: 6px;
221
+ background: none;
222
+ color: var(--secondary);
223
+ transition: color 0.12s, background 0.12s, opacity 0.18s ease, transform 0.22s ease;
224
+ z-index: 5;
225
+ }
226
+ .open-pane:hover,
227
+ .open-pane:focus-visible {
228
+ color: var(--ink);
229
+ background: var(--hover);
230
+ }
231
+ .open-pane:focus-visible {
232
+ outline: 2px solid var(--accent);
233
+ outline-offset: 1px;
234
+ }
235
+ .open-pane:disabled {
236
+ opacity: 0.55;
237
+ cursor: wait;
238
+ }
239
+ .open-pane-tip {
240
+ position: absolute;
241
+ right: calc(100% + 6px);
242
+ top: 50%;
243
+ transform: translateY(-50%);
244
+ padding: 4px 8px;
245
+ border-radius: 6px;
246
+ background: var(--panel-bg);
247
+ color: var(--ink);
248
+ border: 1px solid var(--line);
249
+ box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
250
+ font-size: 11px;
251
+ line-height: 1.4;
252
+ white-space: nowrap;
253
+ pointer-events: none;
254
+ opacity: 0;
255
+ visibility: hidden;
256
+ transition: opacity 0.08s, visibility 0s;
257
+ z-index: 20;
258
+ }
259
+ .open-pane:is(:hover, :focus-visible) .open-pane-tip {
260
+ opacity: 1;
261
+ visibility: visible;
262
+ transition-delay: 0.15s;
263
+ }
264
+ .shell.is-scrolled .open-pane {
265
+ opacity: 0;
266
+ visibility: hidden;
267
+ pointer-events: none;
268
+ transform: translateY(-20px);
269
+ }
270
+ h2.title {
271
+ font-size: 24px;
272
+ font-weight: 650;
273
+ line-height: 1.3;
274
+ letter-spacing: -0.5px;
275
+ margin: 0;
276
+ min-width: 0;
277
+ overflow-wrap: anywhere;
278
+ display: -webkit-box;
279
+ -webkit-box-orient: vertical;
280
+ -webkit-line-clamp: 2;
281
+ overflow: hidden;
282
+ color: var(--ink);
283
+ }
284
+
285
+ .title-progress {
286
+ display: flex;
287
+ flex: none;
288
+ width: 32px;
289
+ height: 32px;
290
+ margin-top: 1px;
291
+ }
292
+ .title-progress svg {
293
+ width: 32px;
294
+ height: 32px;
295
+ display: block;
296
+ }
297
+ .title-progress text {
298
+ opacity: 0;
299
+ transition: opacity 0.15s ease;
300
+ pointer-events: none;
301
+ }
302
+ .title-progress text.progress-unknown {
303
+ opacity: 1;
304
+ }
305
+ .title-heading:hover .progress-pie,
306
+ .title-heading:focus-visible .progress-pie {
307
+ opacity: 0;
308
+ }
309
+ .title-heading:hover text,
310
+ .title-heading:focus-visible text {
311
+ opacity: 1;
312
+ }
313
+
314
+ .panel-body {
315
+ flex: 1;
316
+ overflow-y: auto;
317
+ overflow-x: hidden;
318
+ min-height: 0;
319
+ margin-top: 14px;
320
+ scrollbar-width: none;
321
+ -ms-overflow-style: none;
322
+ transition: margin-top 0.22s ease;
323
+ }
324
+ .shell.is-scrolled .panel-body {
325
+ margin-top: 0;
326
+ }
327
+ .panel-body::-webkit-scrollbar {
328
+ display: none;
329
+ width: 0;
330
+ height: 0;
331
+ }
332
+
333
+ .view {
334
+ padding-bottom: 4px;
335
+ }
336
+
337
+ .status-line {
338
+ display: flex;
339
+ align-items: center;
340
+ justify-content: space-between;
341
+ gap: 16px;
342
+ }
343
+ .status-block {
344
+ transform: translateY(2px);
345
+ min-width: 0;
346
+ flex: 1;
347
+ }
348
+ .status-name {
349
+ display: flex;
350
+ align-items: center;
351
+ gap: 7px;
352
+ line-height: 18px;
353
+ font-size: 13px;
354
+ min-width: 0;
355
+ }
356
+ .status-name > span:last-child {
357
+ min-width: 0;
358
+ overflow: hidden;
359
+ text-overflow: ellipsis;
360
+ white-space: nowrap;
361
+ }
362
+ .state-dot {
363
+ width: 10px;
364
+ height: 10px;
365
+ border: 1.5px solid;
366
+ border-radius: 50%;
367
+ flex: none;
368
+ background: transparent !important;
369
+ }
370
+ .timestamp {
371
+ font-size: 11px;
372
+ line-height: 16px;
373
+ color: var(--secondary);
374
+ margin-top: 2px;
375
+ margin-left: 17px;
376
+ overflow: hidden;
377
+ text-overflow: ellipsis;
378
+ white-space: nowrap;
379
+ }
380
+ .score {
381
+ display: flex;
382
+ align-items: baseline;
383
+ line-height: 1;
384
+ font-variant-numeric: tabular-nums;
385
+ flex: none;
386
+ }
387
+ .score-number {
388
+ font-size: 39px;
389
+ font-weight: 550;
390
+ letter-spacing: -1px;
391
+ color: var(--ink);
392
+ }
393
+ .score-unit {
394
+ font-size: 15px;
395
+ color: var(--secondary);
396
+ margin-left: 3px;
397
+ }
398
+
399
+ .meter {
400
+ height: 4px;
401
+ background: var(--track);
402
+ border-radius: 3px;
403
+ margin: 10px 0 8px;
404
+ overflow: hidden;
405
+ }
406
+ .meter::after {
407
+ content: "";
408
+ display: block;
409
+ height: 100%;
410
+ width: ${progress != null ? Math.max(0, Math.min(100, progress)) : 0}%;
411
+ background: ${stateColor};
412
+ border-radius: inherit;
413
+ }
414
+
415
+ .totals-row {
416
+ display: flex;
417
+ justify-content: space-between;
418
+ align-items: center;
419
+ gap: 8px;
420
+ color: var(--secondary);
421
+ }
422
+ .totals, .source-label {
423
+ font-size: 11px;
424
+ font-weight: 400;
425
+ line-height: 16px;
426
+ }
427
+ .source-label {
428
+ margin-left: auto;
429
+ text-align: right;
430
+ white-space: nowrap;
431
+ }
432
+
433
+ .summary-block {
434
+ position: relative;
435
+ margin: 10px 0;
436
+ outline: none;
437
+ }
438
+ .overview-summary {
439
+ font-size: 13px;
440
+ line-height: 1.65;
441
+ color: var(--note);
442
+ display: -webkit-box;
443
+ -webkit-line-clamp: 3;
444
+ -webkit-box-orient: vertical;
445
+ overflow: hidden;
446
+ white-space: pre-wrap;
447
+ overflow-wrap: anywhere;
448
+ }
449
+ .summary-expand {
450
+ position: absolute;
451
+ right: 0;
452
+ bottom: 0;
453
+ border: 0;
454
+ background: linear-gradient(to right, transparent, var(--panel-bg) 18px);
455
+ padding: 0 0 0 22px;
456
+ color: var(--secondary);
457
+ font-size: 12px;
458
+ line-height: 21.45px;
459
+ white-space: nowrap;
460
+ cursor: pointer;
461
+ }
462
+ .summary-expand:hover {
463
+ color: inherit;
464
+ }
465
+ .summary-block.expanded .overview-summary {
466
+ display: block;
467
+ -webkit-line-clamp: unset;
468
+ }
469
+ .summary-block.expanded .summary-expand {
470
+ position: static;
471
+ display: block;
472
+ margin-left: auto;
473
+ padding-left: 0;
474
+ background: none;
475
+ }
476
+
477
+ .actions {
478
+ display: flex;
479
+ align-items: center;
480
+ gap: 14px;
481
+ margin: 12px 0 14px;
482
+ }
483
+ .primary {
484
+ border: 0;
485
+ background: var(--accent);
486
+ color: #fff;
487
+ border-radius: 9px;
488
+ padding: 9px 14px;
489
+ font-weight: 550;
490
+ min-height: 36px;
491
+ font-size: 13px;
492
+ white-space: nowrap;
493
+ flex-shrink: 0;
494
+ transition: background 0.15s ease;
495
+ }
496
+ .primary:hover {
497
+ background: var(--accent-hover);
498
+ color: #fff;
499
+ }
500
+ .text-button, .clear, .back {
501
+ border: 0;
502
+ background: none;
503
+ padding: 0;
504
+ color: var(--secondary);
505
+ font-size: 12px;
506
+ white-space: nowrap;
507
+ cursor: pointer;
508
+ transition: color 0.12s ease;
509
+ }
510
+ .text-button:hover, .back:hover {
511
+ color: inherit;
512
+ }
513
+ .actions .clear {
514
+ margin-left: auto;
515
+ font-size: 11px;
516
+ color: var(--muted);
517
+ white-space: nowrap;
518
+ position: relative;
519
+ }
520
+ .actions .clear:hover {
521
+ color: var(--danger);
522
+ }
523
+ .clear-tooltip {
524
+ position: absolute;
525
+ right: 0;
526
+ bottom: calc(100% + 8px);
527
+ padding: 6px 9px;
528
+ border-radius: 6px;
529
+ background: var(--panel-bg);
530
+ color: var(--secondary);
531
+ border: 1px solid var(--line);
532
+ font-size: 11px;
533
+ pointer-events: none;
534
+ opacity: 0;
535
+ visibility: hidden;
536
+ transition: opacity 0.08s, visibility 0s;
537
+ white-space: nowrap;
538
+ box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
539
+ z-index: 10;
540
+ }
541
+ .clear:is(:hover, :focus-visible) .clear-tooltip {
542
+ opacity: 1;
543
+ visibility: visible;
544
+ transition-delay: 0.1s;
545
+ }
546
+
547
+ .section-head {
548
+ border-top: 1px solid var(--line);
549
+ padding-top: 10px;
550
+ display: flex;
551
+ align-items: center;
552
+ justify-content: space-between;
553
+ margin-bottom: 4px;
554
+ }
555
+ .section-head h3 {
556
+ font-size: 12px;
557
+ font-weight: 550;
558
+ margin: 0;
559
+ color: var(--ink);
560
+ }
561
+ .remaining-toggle {
562
+ border: 0;
563
+ background: none;
564
+ padding: 0;
565
+ }
566
+ .row-detail {
567
+ font-size: 12px;
568
+ font-weight: 400;
569
+ line-height: 18px;
570
+ color: var(--secondary);
571
+ white-space: nowrap;
572
+ }
573
+
574
+ .task-row {
575
+ position: relative;
576
+ display: flex;
577
+ gap: 9px;
578
+ align-items: flex-start;
579
+ padding: 9px 0;
580
+ overflow: hidden;
581
+ isolation: isolate;
582
+ }
583
+ .task-row:focus-visible {
584
+ outline: 1px solid var(--accent);
585
+ outline-offset: -1px;
586
+ }
587
+ .task-dot {
588
+ width: 12px;
589
+ height: 12px;
590
+ border: 1.3px solid #c89b38;
591
+ border-radius: 50%;
592
+ margin-top: 4px;
593
+ flex: none;
594
+ }
595
+ .task-row[data-status="done"] .task-dot {
596
+ border-color: #548eea;
597
+ background: rgba(84, 142, 234, 0.22);
598
+ }
599
+ .task-content {
600
+ min-width: 0;
601
+ flex: 1;
602
+ }
603
+ .task-title {
604
+ font-size: 13px;
605
+ line-height: 1.4;
606
+ color: var(--ink);
607
+ word-break: break-word;
608
+ }
609
+ .task-meta {
610
+ font-size: 10px;
611
+ color: var(--secondary);
612
+ margin-top: 3px;
613
+ }
614
+ .task-source {
615
+ position: absolute;
616
+ right: 0;
617
+ top: 0;
618
+ bottom: 0;
619
+ display: flex;
620
+ align-items: center;
621
+ justify-content: flex-end;
622
+ padding-left: 28px;
623
+ background: linear-gradient(to right, transparent, var(--panel-bg) 25px);
624
+ opacity: 0;
625
+ pointer-events: none;
626
+ transform: translateX(4px);
627
+ transition: opacity 0.13s ease, transform 0.13s ease;
628
+ }
629
+ .task-source button {
630
+ border: 0;
631
+ border-radius: 6px;
632
+ background: var(--source-bg);
633
+ color: var(--ink);
634
+ padding: 5px 7px;
635
+ font-size: 11px;
636
+ line-height: 1;
637
+ white-space: nowrap;
638
+ cursor: pointer;
639
+ transition: background 0.15s ease;
640
+ }
641
+ .task-source button:hover {
642
+ background: var(--hover);
643
+ }
644
+ .task-row:hover .task-source,
645
+ .task-row:focus-within .task-source {
646
+ opacity: 1;
647
+ pointer-events: auto;
648
+ transform: none;
649
+ }
650
+ @media (hover: none) {
651
+ .task-source {
652
+ opacity: 1;
653
+ pointer-events: auto;
654
+ transform: none;
655
+ }
656
+ }
657
+
658
+ .empty {
659
+ font-size: 12px;
660
+ color: var(--secondary);
661
+ padding: 8px 0;
662
+ text-align: left;
663
+ }
664
+
665
+ .quiet-row {
666
+ border: 0;
667
+ border-top: 1px solid var(--line);
668
+ display: flex;
669
+ justify-content: space-between;
670
+ align-items: center;
671
+ width: 100%;
672
+ background: none;
673
+ color: inherit;
674
+ padding: 10px 0;
675
+ text-align: left;
676
+ font-size: 12px;
677
+ cursor: pointer;
678
+ transition: color 0.15s ease;
679
+ }
680
+ .quiet-row span:last-child {
681
+ color: var(--secondary);
682
+ }
683
+ .quiet-row:hover {
684
+ color: var(--ink);
685
+ }
686
+
687
+ .overview-bottom {
688
+ margin-top: 8px;
689
+ }
690
+
691
+ /* Views */
692
+ .view-heading {
693
+ position: sticky;
694
+ top: 0;
695
+ z-index: 10;
696
+ background: var(--panel-bg);
697
+ display: flex;
698
+ justify-content: space-between;
699
+ align-items: center;
700
+ padding: 4px 0 10px;
701
+ margin-bottom: 6px;
702
+ }
703
+ .view-heading h3 {
704
+ font-size: 14px;
705
+ font-weight: 600;
706
+ margin: 0;
707
+ color: var(--ink);
708
+ }
709
+ .view-heading .back {
710
+ font-size: 13px;
711
+ font-weight: 500;
712
+ color: var(--secondary);
713
+ padding: 4px 8px;
714
+ margin-right: -6px;
715
+ border-radius: 6px;
716
+ cursor: pointer;
717
+ transition: color 0.12s, background 0.12s;
718
+ }
719
+ .view-heading .back:hover {
720
+ color: var(--ink);
721
+ background: var(--hover);
722
+ }
723
+ .view-heading::after {
724
+ content: "";
725
+ position: absolute;
726
+ left: -20px;
727
+ right: -20px;
728
+ top: 100%;
729
+ height: 20px;
730
+ background: linear-gradient(to bottom, var(--panel-bg), transparent);
731
+ pointer-events: none;
732
+ opacity: 0;
733
+ transition: opacity 0.2s ease-out, background 0.15s ease-out;
734
+ }
735
+ .shell.is-scrolled .view-heading::after {
736
+ opacity: 1;
737
+ }
738
+
739
+ /* Edit View */
740
+ .choices-list {
741
+ display: flex;
742
+ flex-direction: column;
743
+ gap: 4px;
744
+ margin-bottom: 12px;
745
+ }
746
+ .choice {
747
+ display: flex;
748
+ align-items: center;
749
+ gap: 10px;
750
+ width: 100%;
751
+ padding: 8px 9px;
752
+ border: 0;
753
+ border-radius: 7px;
754
+ background: none;
755
+ color: inherit;
756
+ text-align: left;
757
+ font-size: 13px;
758
+ cursor: pointer;
759
+ transition: background 0.12s ease;
760
+ }
761
+ .choice:hover {
762
+ background: var(--hover);
763
+ }
764
+ .choice[aria-pressed="true"] {
765
+ background: var(--selected);
766
+ }
767
+ .dot {
768
+ width: 12px;
769
+ height: 12px;
770
+ border: 1.6px solid var(--mark);
771
+ border-radius: 50%;
772
+ flex: none;
773
+ }
774
+ .choice[aria-pressed="true"] .dot {
775
+ background: var(--mark);
776
+ box-shadow: inset 0 0 0 2px var(--panel-bg);
777
+ }
778
+
779
+ .progress-section {
780
+ margin-top: 20px;
781
+ }
782
+ .progress-head {
783
+ display: flex;
784
+ justify-content: space-between;
785
+ align-items: center;
786
+ margin-bottom: 12px;
787
+ }
788
+ .label {
789
+ font-size: 11px;
790
+ color: var(--secondary);
791
+ }
792
+ .number-wrap {
793
+ display: flex;
794
+ align-items: center;
795
+ gap: 5px;
796
+ color: var(--secondary);
797
+ }
798
+ .progress-number {
799
+ appearance: textfield;
800
+ color: var(--ink);
801
+ width: 65px;
802
+ padding: 2px 3px 4px;
803
+ background: none;
804
+ border: 0;
805
+ border-bottom: 1px solid var(--number-line);
806
+ font-size: 27px;
807
+ font-weight: 550;
808
+ text-align: right;
809
+ font-variant-numeric: tabular-nums;
810
+ }
811
+ .progress-number::-webkit-inner-spin-button {
812
+ appearance: none;
813
+ }
814
+ .range {
815
+ position: relative;
816
+ height: 51px;
817
+ margin-top: 2px;
818
+ --mark: ${stateColor};
819
+ }
820
+ .range-track {
821
+ position: absolute;
822
+ left: 7px;
823
+ right: 7px;
824
+ top: 10px;
825
+ height: 4px;
826
+ border-radius: 3px;
827
+ background: linear-gradient(to right, var(--mark) var(--fill), var(--track) var(--fill));
828
+ pointer-events: none;
829
+ }
830
+ .range-input {
831
+ position: relative;
832
+ appearance: none;
833
+ width: 100%;
834
+ height: 24px;
835
+ background: transparent;
836
+ margin: 0;
837
+ display: block;
838
+ padding: 0;
839
+ cursor: pointer;
840
+ }
841
+ .range-input::-webkit-slider-runnable-track {
842
+ height: 4px;
843
+ background: transparent;
844
+ }
845
+ .range-input::-webkit-slider-thumb {
846
+ appearance: none;
847
+ width: 14px;
848
+ height: 14px;
849
+ margin-top: -5px;
850
+ background: var(--thumb);
851
+ border: 2px solid var(--panel-bg);
852
+ border-radius: 50%;
853
+ box-shadow: 0 0 0 1px var(--thumb-edge);
854
+ }
855
+ .range-nodes {
856
+ position: absolute;
857
+ left: 7px;
858
+ right: 7px;
859
+ top: 0;
860
+ pointer-events: none;
861
+ }
862
+ .range-node {
863
+ position: absolute;
864
+ left: var(--at);
865
+ top: 8px;
866
+ width: 0;
867
+ font-size: 10px;
868
+ color: var(--secondary);
869
+ font-variant-numeric: tabular-nums;
870
+ }
871
+ .range-node::before {
872
+ content: "";
873
+ display: block;
874
+ width: 7px;
875
+ height: 7px;
876
+ transform: translateX(-50%);
877
+ border-radius: 50%;
878
+ background: var(--panel-bg);
879
+ border: 1px solid var(--secondary);
880
+ box-shadow: 0 0 0 1px var(--panel-bg);
881
+ }
882
+ .range-node-label {
883
+ position: absolute;
884
+ top: 19px;
885
+ left: 0;
886
+ transform: translateX(-50%);
887
+ }
888
+ .range-node:first-child .range-node-label {
889
+ transform: none;
890
+ }
891
+ .range-node:last-child .range-node-label {
892
+ transform: translateX(-100%);
893
+ }
894
+ .unknown-row {
895
+ display: flex;
896
+ justify-content: flex-end;
897
+ margin: 2px 0 18px;
898
+ }
899
+ .unknown {
900
+ font-size: 11px;
901
+ color: var(--secondary);
902
+ border: 0;
903
+ background: none;
904
+ padding: 0;
905
+ cursor: pointer;
906
+ }
907
+ .unknown:hover {
908
+ color: var(--ink);
909
+ }
910
+
911
+ .note-label {
912
+ display: block;
913
+ font-size: 11px;
914
+ color: var(--secondary);
915
+ margin-bottom: 8px;
916
+ }
917
+ textarea.note-input {
918
+ display: block;
919
+ width: 100%;
920
+ resize: vertical;
921
+ min-height: 66px;
922
+ max-height: 140px;
923
+ background: var(--input-bg);
924
+ color: inherit;
925
+ border: 1px solid var(--input-border);
926
+ border-radius: 8px;
927
+ padding: 9px;
928
+ line-height: 1.6;
929
+ font-size: 12px;
930
+ }
931
+ textarea.note-input:focus-visible {
932
+ outline: none;
933
+ }
934
+
935
+ .edit-actions {
936
+ display: flex;
937
+ justify-content: flex-end;
938
+ gap: 18px;
939
+ align-items: center;
940
+ padding: 21px 0 16px;
941
+ }
942
+
943
+ .feedback-msg {
944
+ font-size: 11px;
945
+ color: var(--secondary);
946
+ margin-top: 10px;
947
+ text-align: right;
948
+ }
949
+ .feedback-msg.error {
950
+ color: var(--error);
951
+ }
952
+ .feedback-msg.success {
953
+ color: #548eea;
954
+ }
955
+
956
+ @media (prefers-color-scheme: light) {
957
+ :root {
958
+ --ink: #22272e;
959
+ --secondary: #576374;
960
+ --muted: #667383;
961
+ --note: #46515f;
962
+ --track: #c3ccd6;
963
+ --line: #dfe4ea;
964
+ --input-border: #c7d0da;
965
+ --input-bg: #f7f9fb;
966
+ --hover: #f0f3f6;
967
+ --selected: #e9edf2;
968
+ --source-bg: #e9eef4;
969
+ --number-line: #b6c1ce;
970
+ --thumb: var(--accent);
971
+ --thumb-edge: var(--accent);
972
+ --danger: #bf2f3a;
973
+ --error: #b13a2d;
974
+ --panel-bg: #fff;
975
+ color: var(--ink);
976
+ color-scheme: light;
977
+ }
978
+ .shell {
979
+ --panel-bg: #fff;
980
+ border-color: #dfe4ea;
981
+ box-shadow: none;
982
+ }
983
+ .shell:hover {
984
+ --panel-bg: #f5f6f7;
985
+ }
986
+ }
987
+ </style>
988
+ </head>
989
+ <body>
990
+ <div class="shell" id="agentThingsCard">
991
+ <button type="button" class="open-pane" id="btnOpenPane" aria-label="${escapeHtml(t('openInSidebar'))}" onclick="onOpenPaneClick()">
992
+ <svg width="28" height="28" viewBox="0 0 28 28" fill="none" aria-hidden="true">
993
+ <rect x="6.65" y="8.15" width="14.7" height="11.7" rx="3" stroke="currentColor" stroke-width="1.3"></rect>
994
+ <path d="M16.3 8.2V19.8" stroke="currentColor" stroke-width="1.3"></path>
995
+ </svg>
996
+ <span class="open-pane-tip" role="tooltip">${escapeHtml(t('openInSidebar'))}</span>
997
+ </button>
998
+ <div class="title-heading" tabindex="0">
999
+ <span class="title-progress" id="titleProgress">
1000
+ ${renderSvgRing(progress, state)}
1001
+ </span>
1002
+ <h2 class="title" id="cardTitle" title="${escapeHtml(resolvedTitle)}">${escapeHtml(resolvedTitle)}</h2>
1003
+ </div>
1004
+
1005
+ <div class="panel-body" id="panelBody">
1006
+ <!-- Overview View -->
1007
+ <div id="overviewView" class="view overview">
1008
+ <div class="status-line">
1009
+ <div class="status-block">
1010
+ <div class="status-name">
1011
+ <span class="state-dot" id="overviewDot" style="border-color:${stateColor};"></span>
1012
+ <span id="overviewStatusLabel">${escapeHtml(stateLabel)}</span>
1013
+ </div>
1014
+ <div class="timestamp" id="overviewTimestamp">${escapeHtml(timestampStr)}</div>
1015
+ </div>
1016
+ <div class="score">
1017
+ <span class="score-number" id="overviewScoreNumber">${progress != null ? progress : '—'}</span>
1018
+ <span class="score-unit" ${progress == null ? 'hidden' : ''}>%</span>
1019
+ </div>
1020
+ </div>
1021
+
1022
+ <div class="meter" id="overviewMeter" style="--fill:${progress != null ? Math.max(0, Math.min(100, progress)) : 0}%; --mark:${stateColor};"></div>
1023
+
1024
+ <div class="totals-row">
1025
+ <span class="totals" id="overviewTotals">${escapeHtml(totalsText)}</span>
1026
+ <span class="source-label">${escapeHtml(sourceLabel)}</span>
1027
+ </div>
1028
+
1029
+ ${summaryText ? `
1030
+ <div class="summary-block" id="summaryBlock" tabindex="0">
1031
+ <div class="overview-summary" id="overviewSummary">${escapeHtml(summaryText)}</div>
1032
+ <button class="summary-expand" id="summaryExpand" onclick="toggleSummaryExpand()" hidden>${escapeHtml(t('expandAll'))}</button>
1033
+ </div>
1034
+ ` : ''}
1035
+
1036
+ <div class="actions">
1037
+ <button class="primary" id="btnAnalyze" onclick="onAnalyzeClick()">${escapeHtml(t('btnUpdate'))}</button>
1038
+ <button class="text-button" onclick="switchToEdit()">${escapeHtml(t('btnAdjust'))}</button>
1039
+ <button class="clear" aria-label="${escapeHtml(t('btnClear'))}" onclick="onClearClick()">
1040
+ <span class="clear-tooltip" role="tooltip">${escapeHtml(t('clearTooltip'))}</span>
1041
+ ${escapeHtml(t('btnClear'))}
1042
+ </button>
1043
+ </div>
1044
+
1045
+ <!-- Section Head -->
1046
+ <div class="section-head">
1047
+ <h3 id="remainingTasksHeading">${escapeHtml(t('remainingHeadingPattern', { count: uncompletedTasks.length }))}</h3>
1048
+ ${uncompletedTasks.length > 3 ? `
1049
+ <button class="text-button row-detail" id="btnToggleAllRemaining" onclick="toggleAllRemaining()">${escapeHtml(t('showAllCountPattern', { count: uncompletedTasks.length }))}</button>
1050
+ ` : ''}
1051
+ </div>
1052
+
1053
+ <!-- Tasks list -->
1054
+ <div class="tasks-list" id="uncompletedTasksList">
1055
+ ${allTasks.length === 0 ? `<div class="empty">${escapeHtml(t('emptyNoTasks'))}</div>`
1056
+ : uncompletedTasks.length === 0 ? `<div class="empty">${escapeHtml(t('emptyNoRemaining'))}</div>` : ''}
1057
+ ${uncompletedTasks.map((task, idx) => {
1058
+ const hasSource = Boolean(task.source?.locator || task.source?.turnId);
1059
+ const taskTitle = task.title || task.summary || t('untitledTask');
1060
+ return `
1061
+ <div class="task-row ${idx >= 3 ? 'remaining-hidden' : ''}" data-status="${escapeHtml(task.status)}" tabindex="0" ${idx >= 3 ? 'hidden' : ''}>
1062
+ <span class="task-dot"></span>
1063
+ <div class="task-content">
1064
+ <div class="task-title">${escapeHtml(taskTitle)}</div>
1065
+ <div class="task-meta">${escapeHtml(uiTaskLabels[task.status] || task.status)}</div>
1066
+ </div>
1067
+ ${hasSource ? `
1068
+ <div class="task-source">
1069
+ <button type="button" aria-label="${escapeHtml(t('viewSourceAriaPrefix') + taskTitle)}" data-source="${escapeHtml(JSON.stringify(task.source))}" onclick="onSourceClick(this)">${escapeHtml(t('viewSource'))}</button>
1070
+ </div>
1071
+ ` : ''}
1072
+ </div>
1073
+ `;
1074
+ }).join('')}
1075
+ </div>
1076
+
1077
+ <!-- Bottom Rows (1:1 identical to sidebar) -->
1078
+ <div class="overview-bottom">
1079
+ <button class="quiet-row history-open" onclick="switchToHistory()">
1080
+ <span>${escapeHtml(t('completedHeading'))}</span>
1081
+ <span class="row-detail" id="historyCount">${escapeHtml(t('countArrowPattern', { count: completedTasks.length }))}</span>
1082
+ </button>
1083
+ <button class="quiet-row note-open" onclick="switchToEditNote()">
1084
+ <span>${escapeHtml(t('notesLabel'))}</span>
1085
+ <span class="row-detail" id="noteOpenLabel">${escapeHtml(note ? t('editLabel') : t('addLabel'))}</span>
1086
+ </button>
1087
+ </div>
1088
+ </div>
1089
+
1090
+ <!-- History View -->
1091
+ <div id="historyView" class="view history-view" hidden>
1092
+ <div class="view-heading">
1093
+ <h3>${escapeHtml(t('completedHeading'))}</h3>
1094
+ <button class="back" onclick="switchToOverview()">${escapeHtml(t('backLabel'))}</button>
1095
+ </div>
1096
+ <div class="history-list" id="historyList">
1097
+ ${completedTasks.length === 0 ? `<div class="empty">${escapeHtml(t('emptyCompleted'))}</div>` : ''}
1098
+ ${completedTasks.map((task) => {
1099
+ const hasSource = Boolean(task.source?.locator || task.source?.turnId);
1100
+ const taskTitle = task.title || task.summary || t('completedTaskFallback');
1101
+ return `
1102
+ <div class="task-row" data-status="done" tabindex="0">
1103
+ <span class="task-dot"></span>
1104
+ <div class="task-content">
1105
+ <div class="task-title">${escapeHtml(taskTitle)}</div>
1106
+ <div class="task-meta">${escapeHtml(uiTaskLabels.done)}</div>
1107
+ </div>
1108
+ ${hasSource ? `
1109
+ <div class="task-source">
1110
+ <button type="button" aria-label="${escapeHtml(t('viewSourceAriaPrefix') + taskTitle)}" data-source="${escapeHtml(JSON.stringify(task.source))}" onclick="onSourceClick(this)">${escapeHtml(t('viewSource'))}</button>
1111
+ </div>
1112
+ ` : ''}
1113
+ </div>
1114
+ `;
1115
+ }).join('')}
1116
+ </div>
1117
+ </div>
1118
+
1119
+ <!-- Edit View -->
1120
+ <div id="editView" class="view edit-view" hidden>
1121
+ <div class="view-heading">
1122
+ <h3>${escapeHtml(t('editHeading'))}</h3>
1123
+ <button class="back" onclick="switchToOverview()">${escapeHtml(t('backLabel'))}</button>
1124
+ </div>
1125
+ <div class="choices-list">
1126
+ ${Object.entries(uiLabels).map(([key, label]) => `
1127
+ <button class="choice" id="choice-${key}" ${key === 'pushed' ? 'hidden' : ''} aria-pressed="${state === key ? 'true' : 'false'}" style="--mark:${colors[key]}" onclick="selectState('${key}')">
1128
+ <span class="dot"></span>
1129
+ <span>${escapeHtml(label)}</span>
1130
+ </button>
1131
+ `).join('')}
1132
+ </div>
1133
+
1134
+ <div class="progress-section">
1135
+ <div class="progress-head">
1136
+ <label class="label" for="inputProgressNumber">${escapeHtml(t('progressLabel'))}</label>
1137
+ <div class="number-wrap">
1138
+ <input type="number" id="inputProgressNumber" class="progress-number" min="0" max="100" step="1" value="${progress != null ? progress : ''}" placeholder="—" aria-label="${escapeHtml(t('progressLabel'))}" oninput="onNumberInput(this.value)" onkeydown="onProgressKeyDown(event)">
1139
+ <span>%</span>
1140
+ </div>
1141
+ </div>
1142
+
1143
+ <div class="range" id="rangeBox" style="--mark:${stateColor}; --fill:${progress != null ? Math.max(0, Math.min(100, progress)) : 0}%;">
1144
+ <div class="range-track"></div>
1145
+ <div class="range-nodes" aria-hidden="true">
1146
+ ${[0, 25, 50, 75, 100].map(val => `
1147
+ <span class="range-node" style="--at:${val}%;">
1148
+ <span class="range-node-label">${val}</span>
1149
+ </span>
1150
+ `).join('')}
1151
+ </div>
1152
+ <input type="range" id="inputSlider" class="range-input" min="0" max="100" step="1" value="${progress != null ? progress : 0}" aria-label="${escapeHtml(t('sliderAriaLabel'))}" onpointerdown="onSliderPointerDown()" onpointerup="onSliderPointerUp()" onpointercancel="onSliderPointerUp()" oninput="onSliderInput(this.value)">
1153
+ </div>
1154
+
1155
+ <div class="unknown-row">
1156
+ <button type="button" class="unknown" onclick="onClearProgressClick()">${escapeHtml(t('clearValueBtn'))}</button>
1157
+ </div>
1158
+ </div>
1159
+
1160
+ <label class="note-label" for="txtNote">${escapeHtml(t('notesLabel'))}</label>
1161
+ <textarea id="txtNote" class="note-input" maxlength="4000" placeholder="${escapeHtml(t('notePlaceholder'))}" aria-label="${escapeHtml(t('noteAriaLabel'))}" oninput="markFormDirty()">${escapeHtml(note)}</textarea>
1162
+
1163
+ <div id="conflictBox" class="conflict-box" style="display:none; margin: 10px 0; padding: 8px 12px; background: rgba(230, 80, 80, 0.12); border: 1px solid rgba(230, 80, 80, 0.35); border-radius: 6px; font-size: 12px; line-height: 1.5; color: var(--ink);">
1164
+ <div id="conflictMsg">${escapeHtml(t('conflictBanner'))}</div>
1165
+ <div style="margin-top: 6px;">
1166
+ <button type="button" class="text-button" id="btnResolveConflict" style="color: var(--mark); text-decoration: underline; padding: 0;" onclick="resolveConflictKeepDraft()">${escapeHtml(t('resolveConflictBtn'))}</button>
1167
+ </div>
1168
+ </div>
1169
+
1170
+ <div class="edit-actions">
1171
+ <button class="text-button" onclick="switchToOverview()">${escapeHtml(t('cancelBtn'))}</button>
1172
+ <button class="primary" id="btnSaveRecord" onclick="onSaveRecord()">${escapeHtml(t('saveBtn'))}</button>
1173
+ </div>
1174
+ </div>
1175
+ </div>
1176
+
1177
+ <div class="feedback-msg" id="feedbackMsg" role="status"></div>
1178
+ </div>
1179
+
1180
+ <script>
1181
+ const colors = ${JSON.stringify(colors)};
1182
+ const i18n = ${JSON.stringify(clientI18n)};
1183
+ const labels = i18n.labels || {};
1184
+ const taskLabels = i18n.taskLabels || {};
1185
+ const fmt = (key, vars = {}) => String(i18n[key] ?? key).replace(/\\{(\\w+)\\}/g, (_, k) => (vars[k] !== undefined ? String(vars[k]) : ''));
1186
+ function escapeHtml(value) {
1187
+ return String(value ?? '').replace(/[&<>"']/g, c => ({
1188
+ '&': '&amp;',
1189
+ '<': '&lt;',
1190
+ '>': '&gt;',
1191
+ '"': '&quot;',
1192
+ "'": '&#39;',
1193
+ }[c]));
1194
+ }
1195
+ const conversationId = ${JSON.stringify(conversationId)};
1196
+ const connection = ${configJson};
1197
+ let currentRevision = ${Number(revision) || 0};
1198
+ let savedRevision = ${Number(revision) || 0};
1199
+ let draftBaseRevision = savedRevision;
1200
+ let isFormDirty = false;
1201
+ let currentState = ${JSON.stringify(state)};
1202
+ let currentProgress = ${progress != null ? Number(progress) : 'null'};
1203
+ let isDraggingSlider = false;
1204
+ let hostChannelPort = null;
1205
+
1206
+ function resetScroll() {
1207
+ const panel = document.getElementById('panelBody');
1208
+ const shell = document.getElementById('agentThingsCard');
1209
+ if (panel) panel.scrollTop = 0;
1210
+ if (shell) shell.classList.remove('is-scrolled');
1211
+ }
1212
+
1213
+ function showConflictNotice(msg) {
1214
+ const box = document.getElementById('conflictBox');
1215
+ const text = document.getElementById('conflictMsg');
1216
+ if (box && text) {
1217
+ text.textContent = msg || i18n.conflictBanner;
1218
+ box.style.display = 'block';
1219
+ }
1220
+ showFeedback(i18n.conflictDetectedFeedback, true);
1221
+ }
1222
+
1223
+ function hideConflictNotice() {
1224
+ const box = document.getElementById('conflictBox');
1225
+ if (box) box.style.display = 'none';
1226
+ }
1227
+
1228
+ function resolveConflictKeepDraft() {
1229
+ draftBaseRevision = savedRevision;
1230
+ hideConflictNotice();
1231
+ showFeedback(i18n.conflictRebasedFeedback);
1232
+ }
1233
+
1234
+ function switchToEdit() {
1235
+ resetScroll();
1236
+ draftBaseRevision = savedRevision;
1237
+ isFormDirty = false;
1238
+ hideConflictNotice();
1239
+ document.getElementById('overviewView').hidden = true;
1240
+ document.getElementById('historyView').hidden = true;
1241
+ document.getElementById('editView').hidden = false;
1242
+ clearFeedback();
1243
+ }
1244
+
1245
+ function switchToEditNote() {
1246
+ switchToEdit();
1247
+ setTimeout(function() {
1248
+ const txt = document.getElementById('txtNote');
1249
+ if (txt) txt.focus();
1250
+ }, 50);
1251
+ }
1252
+
1253
+ function switchToHistory() {
1254
+ resetScroll();
1255
+ document.getElementById('overviewView').hidden = true;
1256
+ document.getElementById('editView').hidden = true;
1257
+ document.getElementById('historyView').hidden = false;
1258
+ clearFeedback();
1259
+ }
1260
+
1261
+ function switchToOverview() {
1262
+ resetScroll();
1263
+ document.getElementById('editView').hidden = true;
1264
+ document.getElementById('historyView').hidden = true;
1265
+ document.getElementById('overviewView').hidden = false;
1266
+ isFormDirty = false;
1267
+ hideConflictNotice();
1268
+ clearFeedback();
1269
+ checkSummaryOverflow();
1270
+ }
1271
+
1272
+ function markFormDirty() {
1273
+ isFormDirty = true;
1274
+ }
1275
+
1276
+ function selectState(stateKey, isRemoteSync = false) {
1277
+ if (!isRemoteSync) markFormDirty();
1278
+ currentState = stateKey;
1279
+ for (const key of Object.keys(labels)) {
1280
+ const btn = document.getElementById('choice-' + key);
1281
+ if (btn) btn.setAttribute('aria-pressed', String(key === stateKey));
1282
+ }
1283
+ if (!isRemoteSync) {
1284
+ if (stateKey === 'unstarted') {
1285
+ updateProgressVal(0);
1286
+ } else if (stateKey === 'completed' || stateKey === 'pushed') {
1287
+ updateProgressVal(100);
1288
+ }
1289
+ }
1290
+ updateRangeMark(colors[stateKey] || colors.unfinished);
1291
+ }
1292
+
1293
+ function onNumberInput(val) {
1294
+ markFormDirty();
1295
+ const num = val === '' ? null : Number(val);
1296
+ if (num !== null && !isNaN(num)) {
1297
+ const clamped = Math.max(0, Math.min(100, Math.round(num)));
1298
+ updateProgressVal(clamped);
1299
+ const nextState = clamped === 100 ? (currentState === 'pushed' ? 'pushed' : 'completed')
1300
+ : (clamped === 0 && currentState === 'unstarted' ? 'unstarted' : 'unfinished');
1301
+ selectState(nextState);
1302
+ } else {
1303
+ updateProgressVal(null);
1304
+ }
1305
+ }
1306
+
1307
+ function onProgressKeyDown(event) {
1308
+ if (event.key === 'Enter') {
1309
+ event.preventDefault();
1310
+ onSaveRecord();
1311
+ }
1312
+ }
1313
+
1314
+ function onSliderPointerDown() {
1315
+ isDraggingSlider = true;
1316
+ }
1317
+
1318
+ function onSliderPointerUp() {
1319
+ isDraggingSlider = false;
1320
+ }
1321
+
1322
+ function onSliderInput(val) {
1323
+ markFormDirty();
1324
+ const value = Number(val);
1325
+ const nearest = Math.round(value / 25) * 25;
1326
+ const snapped = (isDraggingSlider && Math.abs(value - nearest) <= 2) ? nearest : value;
1327
+ updateProgressVal(snapped);
1328
+ const nextState = snapped === 100 ? (currentState === 'pushed' ? 'pushed' : 'completed')
1329
+ : (snapped === 0 && currentState === 'unstarted' ? 'unstarted' : 'unfinished');
1330
+ selectState(nextState);
1331
+ }
1332
+
1333
+ function onClearProgressClick() {
1334
+ updateProgressVal(null);
1335
+ }
1336
+
1337
+ function updateProgressVal(val) {
1338
+ currentProgress = val;
1339
+ const slider = document.getElementById('inputSlider');
1340
+ const numberInput = document.getElementById('inputProgressNumber');
1341
+ const rangeBox = document.getElementById('rangeBox');
1342
+ if (slider) slider.value = val !== null ? val : 0;
1343
+ if (numberInput) numberInput.value = val !== null ? val : '';
1344
+ if (rangeBox) rangeBox.style.setProperty('--fill', (val !== null ? val : 0) + '%');
1345
+ }
1346
+
1347
+ function updateRangeMark(markColor) {
1348
+ const rangeBox = document.getElementById('rangeBox');
1349
+ if (rangeBox) rangeBox.style.setProperty('--mark', markColor);
1350
+ }
1351
+
1352
+ function toggleAllRemaining() {
1353
+ const hiddenRows = document.querySelectorAll('.remaining-hidden');
1354
+ const btn = document.getElementById('btnToggleAllRemaining');
1355
+ const isExpanded = btn?.getAttribute('data-expanded') === 'true';
1356
+ hiddenRows.forEach(function(row) { row.hidden = isExpanded; });
1357
+ if (btn) {
1358
+ btn.setAttribute('data-expanded', String(!isExpanded));
1359
+ const total = hiddenRows.length + 3;
1360
+ btn.textContent = isExpanded ? fmt('showAllCountPattern', { count: total }) : i18n.collapseArrow;
1361
+ }
1362
+ }
1363
+
1364
+ function toggleSummaryExpand() {
1365
+ const block = document.getElementById('summaryBlock');
1366
+ const btn = document.getElementById('summaryExpand');
1367
+ if (!block || !btn) return;
1368
+ const isExpanded = block.classList.toggle('expanded');
1369
+ btn.textContent = isExpanded ? i18n.collapse : i18n.expandAll;
1370
+ }
1371
+
1372
+ function checkSummaryOverflow() {
1373
+ const summaryEl = document.getElementById('overviewSummary');
1374
+ const btn = document.getElementById('summaryExpand');
1375
+ if (summaryEl && btn) {
1376
+ btn.hidden = summaryEl.scrollHeight <= summaryEl.clientHeight + 2;
1377
+ }
1378
+ }
1379
+
1380
+ function postWindowLocateRequest(source, { timeoutMs = 15000 } = {}) {
1381
+ return new Promise((resolve, reject) => {
1382
+ if (!window.parent || window.parent === window) {
1383
+ reject(new Error(i18n.locateUnsupported));
1384
+ return;
1385
+ }
1386
+ const nonce = 'loc-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 7);
1387
+ const timer = setTimeout(() => {
1388
+ pendingActions.delete(nonce);
1389
+ reject(new Error(i18n.locateTimeout));
1390
+ }, timeoutMs);
1391
+ pendingActions.set(nonce, { resolve, reject, timer });
1392
+ try {
1393
+ window.parent.postMessage({
1394
+ type: 'AGENT_THINGS_LOCATE',
1395
+ conversationId,
1396
+ nonce,
1397
+ source,
1398
+ }, '*');
1399
+ } catch (err) {
1400
+ clearTimeout(timer);
1401
+ pendingActions.delete(nonce);
1402
+ reject(err);
1403
+ }
1404
+ });
1405
+ }
1406
+
1407
+ async function onSourceClick(button) {
1408
+ if (button) button.disabled = true;
1409
+ try {
1410
+ const sourceJson = button.getAttribute('data-source');
1411
+ if (!sourceJson) return;
1412
+ const source = JSON.parse(sourceJson);
1413
+ showFeedback(i18n.locatingSourceMessage);
1414
+
1415
+ const result = hostChannelPort
1416
+ ? await postHostChannelRequest({
1417
+ type: 'AGENT_THINGS_LOCATE',
1418
+ source,
1419
+ }, { timeoutMs: 18000, errorLabel: i18n.locateTimeout })
1420
+ : await postWindowLocateRequest(source);
1421
+
1422
+ showFeedback(result?.message || i18n.locatedJumpMessage);
1423
+ } catch (err) {
1424
+ showFeedback(i18n.locateCommandErrorPrefix + (err.message || i18n.unknownActionError), true);
1425
+ } finally {
1426
+ if (button) button.disabled = false;
1427
+ }
1428
+ }
1429
+
1430
+ function showFeedback(msg, isError = false) {
1431
+ const el = document.getElementById('feedbackMsg');
1432
+ if (!el) return;
1433
+ el.textContent = msg;
1434
+ el.className = 'feedback-msg ' + (isError ? 'error' : 'success');
1435
+ setTimeout(function() { if (el.textContent === msg) el.textContent = ''; }, 4000);
1436
+ }
1437
+
1438
+ function clearFeedback() {
1439
+ const el = document.getElementById('feedbackMsg');
1440
+ if (el) el.textContent = '';
1441
+ }
1442
+
1443
+ let sseSource = null;
1444
+ let sseReconnectTimer = null;
1445
+ let authTicket = null;
1446
+ let serviceOrigin = connection?.origin || null;
1447
+ const pendingActions = new Map();
1448
+
1449
+ function postHostChannelRequest(message, { timeoutMs = 12000, errorLabel = i18n.cardTimeout } = {}) {
1450
+ return new Promise((resolve, reject) => {
1451
+ if (!hostChannelPort) {
1452
+ reject(new Error(i18n.locateHostDisconnected));
1453
+ return;
1454
+ }
1455
+ const nonce = 'req-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 7);
1456
+ const timer = setTimeout(() => {
1457
+ pendingActions.delete(nonce);
1458
+ reject(new Error(errorLabel));
1459
+ }, timeoutMs);
1460
+
1461
+ pendingActions.set(nonce, { resolve, reject, timer });
1462
+
1463
+ try {
1464
+ hostChannelPort.postMessage(Object.assign({}, message, {
1465
+ conversationId: conversationId,
1466
+ nonce: nonce,
1467
+ }));
1468
+ } catch (err) {
1469
+ clearTimeout(timer);
1470
+ pendingActions.delete(nonce);
1471
+ reject(err);
1472
+ }
1473
+ });
1474
+ }
1475
+
1476
+ async function sendProxyAction(action, payload = {}) {
1477
+ if (!hostChannelPort) {
1478
+ try { await requestHostAuth(); } catch (_) {}
1479
+ }
1480
+ return postHostChannelRequest({
1481
+ type: 'AGENT_THINGS_ACTION_PROXY',
1482
+ action: action,
1483
+ payload: payload,
1484
+ });
1485
+ }
1486
+
1487
+ function sendOpenPaneViaEmbedNative() {
1488
+ if (window.parent && window.parent !== window) {
1489
+ try {
1490
+ window.parent.postMessage({
1491
+ type: 'OPEN_SIDECAR',
1492
+ target: 'things/things_board',
1493
+ }, '*');
1494
+ return true;
1495
+ } catch (_) {}
1496
+ }
1497
+ return false;
1498
+ }
1499
+
1500
+ async function onOpenPaneClick() {
1501
+ const btn = document.getElementById('btnOpenPane');
1502
+ if (btn && btn.disabled) return;
1503
+ try {
1504
+ if (btn) btn.disabled = true;
1505
+ clearFeedback();
1506
+ if (hostChannelPort) {
1507
+ try {
1508
+ await postHostChannelRequest({
1509
+ type: 'AGENT_THINGS_OPEN_PANE',
1510
+ }, { timeoutMs: 4500, errorLabel: i18n.cardRequestTimeout });
1511
+ return;
1512
+ } catch (err) {
1513
+ if (err && err.isHostBusinessError) {
1514
+ throw err;
1515
+ }
1516
+ if (sendOpenPaneViaEmbedNative()) {
1517
+ return;
1518
+ }
1519
+ throw err;
1520
+ }
1521
+ }
1522
+ if (sendOpenPaneViaEmbedNative()) {
1523
+ return;
1524
+ }
1525
+ try { await requestHostAuth(); } catch (_) {}
1526
+ if (hostChannelPort) {
1527
+ await postHostChannelRequest({
1528
+ type: 'AGENT_THINGS_OPEN_PANE',
1529
+ }, { timeoutMs: 4500, errorLabel: i18n.cardRequestTimeout });
1530
+ return;
1531
+ }
1532
+ throw new Error(i18n.locateUnsupported);
1533
+ } catch (err) {
1534
+ showFeedback(i18n.openPaneFailedPrefix + (err?.message || i18n.unknownActionError), true);
1535
+ } finally {
1536
+ if (btn) btn.disabled = false;
1537
+ }
1538
+ }
1539
+
1540
+ function onIncomingHostMessage(data) {
1541
+ if (!data || typeof data !== 'object') return;
1542
+
1543
+ if (data.type === 'AGENT_THINGS_AUTH_RESPONSE' && data.nonce) {
1544
+ const req = pendingActions.get(data.nonce);
1545
+ if (req) {
1546
+ clearTimeout(req.timer);
1547
+ pendingActions.delete(data.nonce);
1548
+ if (data.origin) serviceOrigin = data.origin;
1549
+ if (data.ticket) authTicket = data.ticket;
1550
+ req.resolve(data);
1551
+ }
1552
+ return;
1553
+ }
1554
+
1555
+ if ((data.type === 'AGENT_THINGS_ACTION_RESULT' || data.type === 'AGENT_THINGS_LOCATE_RESULT') && data.nonce) {
1556
+ const req = pendingActions.get(data.nonce);
1557
+ if (req) {
1558
+ clearTimeout(req.timer);
1559
+ pendingActions.delete(data.nonce);
1560
+ const actionOk = data.success !== undefined ? Boolean(data.success) : Boolean(data.located);
1561
+ if (actionOk) {
1562
+ req.resolve(data.data || (data.message ? { message: data.message } : {}));
1563
+ } else {
1564
+ const err = new Error(data.error || data.message || i18n.cardOpFailed);
1565
+ err.isHostBusinessError = true;
1566
+ req.reject(err);
1567
+ }
1568
+ }
1569
+ return;
1570
+ }
1571
+ }
1572
+
1573
+ function requestHostAuth() {
1574
+ return new Promise((resolve, reject) => {
1575
+ const nonce = 'auth-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 7);
1576
+ const timer = setTimeout(() => {
1577
+ pendingActions.delete(nonce);
1578
+ if (hostChannelPort && !authTicket) {
1579
+ try { hostChannelPort.close(); } catch (_) {}
1580
+ hostChannelPort = null;
1581
+ }
1582
+ reject(new Error(i18n.cardTimeout));
1583
+ }, 8000);
1584
+
1585
+ pendingActions.set(nonce, { resolve, reject, timer });
1586
+
1587
+ try {
1588
+ // 若已有绑定的专属端口(后台重启换票场景),直接通过原端口原路发送换票请求,不重新广播替换端口
1589
+ if (hostChannelPort) {
1590
+ try {
1591
+ hostChannelPort.postMessage({
1592
+ type: 'AGENT_THINGS_AUTH_REQUEST',
1593
+ conversationId: conversationId,
1594
+ nonce: nonce,
1595
+ });
1596
+ return;
1597
+ } catch (_) {
1598
+ try { hostChannelPort.close(); } catch (_) {}
1599
+ hostChannelPort = null;
1600
+ }
1601
+ }
1602
+
1603
+ // 首次握手:创建 MessageChannel 并在窗口上携带 loadToken 转移 port2
1604
+ if (typeof MessageChannel !== 'undefined') {
1605
+ const channel = new MessageChannel();
1606
+ hostChannelPort = channel.port1;
1607
+ hostChannelPort.onmessage = (event) => onIncomingHostMessage(event.data);
1608
+ window.parent.postMessage({
1609
+ type: 'AGENT_THINGS_AUTH_REQUEST',
1610
+ conversationId: conversationId,
1611
+ nonce: nonce,
1612
+ loadToken: (typeof window !== 'undefined' && window.__agentThingsLoadToken) ? window.__agentThingsLoadToken : (connection?.loadToken || null),
1613
+ }, '*', [channel.port2]);
1614
+ } else {
1615
+ clearTimeout(timer);
1616
+ pendingActions.delete(nonce);
1617
+ reject(new Error(i18n.cardAuthUnavailable));
1618
+ return;
1619
+ }
1620
+ } catch (err) {
1621
+ clearTimeout(timer);
1622
+ pendingActions.delete(nonce);
1623
+ reject(err);
1624
+ }
1625
+ });
1626
+ }
1627
+
1628
+ window.addEventListener('message', (event) => {
1629
+ try {
1630
+ onIncomingHostMessage(event.data);
1631
+ } catch (_) {}
1632
+ });
1633
+
1634
+ async function onSaveRecord() {
1635
+ const btn = document.getElementById('btnSaveRecord');
1636
+ const noteVal = document.getElementById('txtNote')?.value ?? '';
1637
+ try {
1638
+ if (btn) btn.disabled = true;
1639
+ showFeedback(i18n.savingFeedback);
1640
+ const reply = await sendProxyAction('update', {
1641
+ expectedRevision: draftBaseRevision,
1642
+ record: {
1643
+ state: currentState,
1644
+ progress: currentProgress,
1645
+ note: noteVal
1646
+ }
1647
+ });
1648
+ // 修复:sendProxyAction 已解包 data,调用方应读 reply.session.recordRevision
1649
+ const newRev = reply?.session?.recordRevision;
1650
+ if (typeof newRev === 'number') {
1651
+ savedRevision = newRev;
1652
+ draftBaseRevision = newRev;
1653
+ currentRevision = newRev;
1654
+ }
1655
+ isFormDirty = false;
1656
+ hideConflictNotice();
1657
+ showFeedback(i18n.savedFeedback);
1658
+ setTimeout(switchToOverview, 600);
1659
+ } catch (err) {
1660
+ const isConflict = err.message && (err.message.includes('其他窗口更新') || err.message.includes('another window') || err.message.includes('版本已被') || err.message.includes('409') || err.message.includes('conflict') || err.message.includes('revision mismatch'));
1661
+ if (isConflict) {
1662
+ showConflictNotice(i18n.conflictBanner);
1663
+ } else {
1664
+ showFeedback(i18n.saveFailedPrefix + err.message, true);
1665
+ }
1666
+ } finally {
1667
+ if (btn) btn.disabled = false;
1668
+ }
1669
+ }
1670
+
1671
+ async function onClearClick() {
1672
+ if (!confirm(i18n.clearConfirm)) return;
1673
+ try {
1674
+ showFeedback(i18n.clearingFeedback);
1675
+ const reply = await sendProxyAction('clear', {
1676
+ expectedRevision: draftBaseRevision,
1677
+ });
1678
+ const newRev = reply?.session?.recordRevision;
1679
+ if (typeof newRev === 'number') {
1680
+ savedRevision = newRev;
1681
+ draftBaseRevision = newRev;
1682
+ currentRevision = newRev;
1683
+ }
1684
+ isFormDirty = false;
1685
+ hideConflictNotice();
1686
+ showFeedback(i18n.clearedFeedback);
1687
+ } catch (err) {
1688
+ showFeedback(i18n.clearFailedPrefix + err.message, true);
1689
+ }
1690
+ }
1691
+
1692
+ function handleRemoteSessionUpdate(payload) {
1693
+ if (!payload) return;
1694
+ const s = payload.session || payload;
1695
+ const effectiveProgress = typeof s.progress === 'number' ? s.progress : typeof s.progress?.progress === 'number' ? s.progress.progress : (typeof s === 'number' ? s : null);
1696
+ const effectiveState = s.state || s.progress?.state || (effectiveProgress === 100 ? 'completed' : (effectiveProgress > 0 ? 'unfinished' : 'unstarted'));
1697
+ const effectiveTasks = Array.isArray(s.tasks) ? s.tasks : (Array.isArray(s.progress?.tasks) ? s.progress.tasks : (s.analysis?.ledger?.tasks || []));
1698
+ const effectiveNote = s.note || s.progress?.note || '';
1699
+ const effectiveSummary = s.summary || s.progress?.summary || s.analysis?.ledger?.summary || '';
1700
+ const effectiveTitle = s.title || s.progress?.title || '';
1701
+
1702
+ if (typeof s.recordRevision === 'number') savedRevision = Math.max(savedRevision, s.recordRevision);
1703
+ else if (typeof s.progress?.revision === 'number') savedRevision = Math.max(savedRevision, s.progress.revision);
1704
+ else if (typeof s.revision === 'number') savedRevision = Math.max(savedRevision, s.revision);
1705
+
1706
+ // 若未处于草稿编辑中,基准版本与当前展示版本同步更新
1707
+ if (!isFormDirty) {
1708
+ currentRevision = savedRevision;
1709
+ draftBaseRevision = savedRevision;
1710
+ }
1711
+
1712
+ const analyzing = Boolean(s.analyzing || s.analysisStatus?.status === 'pending');
1713
+ const analysisStatus = s.analysisStatus;
1714
+ const btnAnalyze = document.getElementById('btnAnalyze');
1715
+ if (btnAnalyze) {
1716
+ if (analyzing) {
1717
+ btnAnalyze.disabled = true;
1718
+ btnAnalyze.textContent = i18n.btnUpdating;
1719
+ } else {
1720
+ btnAnalyze.disabled = false;
1721
+ btnAnalyze.textContent = i18n.btnUpdate;
1722
+ if (analysisStatus?.status === 'failed') {
1723
+ showFeedback(i18n.analysisNotDonePrefix + (analysisStatus.error || i18n.analysisAbnormal), true);
1724
+ }
1725
+ }
1726
+ }
1727
+
1728
+ // 仅在非 dirty 编辑态下将远端状态刷入表单与展示
1729
+ if (!isFormDirty) {
1730
+ applyFullProgressToUI({
1731
+ state: effectiveState,
1732
+ progress: effectiveProgress,
1733
+ tasks: effectiveTasks,
1734
+ note: effectiveNote,
1735
+ summary: effectiveSummary,
1736
+ title: effectiveTitle,
1737
+ revision: currentRevision,
1738
+ });
1739
+ }
1740
+ }
1741
+
1742
+ function applyFullProgressToUI(data) {
1743
+ if (!data) return;
1744
+ currentRevision = data.revision ?? currentRevision;
1745
+ const nextState = data.state || (data.progress === 100 ? 'completed' : data.progress > 0 ? 'unfinished' : 'unstarted');
1746
+ const nextProgress = data.progress ?? null;
1747
+
1748
+ if (!isFormDirty) {
1749
+ currentState = nextState;
1750
+ currentProgress = nextProgress;
1751
+ updateProgressVal(currentProgress);
1752
+ selectState(currentState, true);
1753
+ const noteInput = document.getElementById('txtNote');
1754
+ if (noteInput) noteInput.value = data.note || '';
1755
+ const noteOpenLabel = document.getElementById('noteOpenLabel');
1756
+ if (noteOpenLabel) noteOpenLabel.textContent = data.note ? i18n.editLabel : i18n.addLabel;
1757
+ }
1758
+
1759
+ if (data.title && data.title !== '当前会话' && data.title !== 'Current session') {
1760
+ const titleEl = document.getElementById('cardTitle');
1761
+ if (titleEl) {
1762
+ titleEl.textContent = data.title;
1763
+ titleEl.title = data.title;
1764
+ }
1765
+ }
1766
+
1767
+ const scoreEl = document.getElementById('overviewScoreNumber');
1768
+ if (scoreEl) scoreEl.textContent = currentProgress !== null ? currentProgress : '—';
1769
+ const scoreUnit = document.querySelector('.score-unit');
1770
+ if (scoreUnit) scoreUnit.hidden = currentProgress === null;
1771
+
1772
+ const labelEl = document.getElementById('overviewStatusLabel');
1773
+ if (labelEl) labelEl.textContent = labels[currentState] || currentState;
1774
+ const dotEl = document.getElementById('overviewDot');
1775
+ if (dotEl) {
1776
+ dotEl.style.borderColor = colors[currentState] || colors.unstarted;
1777
+ dotEl.style.background = 'transparent';
1778
+ }
1779
+
1780
+ const meterEl = document.getElementById('overviewMeter');
1781
+ if (meterEl) {
1782
+ const prog = currentProgress != null ? Math.max(0, Math.min(100, currentProgress)) : 0;
1783
+ meterEl.style.setProperty('--fill', prog + '%');
1784
+ meterEl.style.setProperty('--mark', colors[currentState] || colors.unstarted);
1785
+ }
1786
+
1787
+ const totalCount = data.totalTasks ?? data.tasks?.length ?? 0;
1788
+ const doneCount = data.completedTasks ?? data.tasks?.filter(function(t) { return t.status === 'done'; }).length ?? 0;
1789
+ const totalsEl = document.getElementById('overviewTotals');
1790
+ if (totalsEl) {
1791
+ totalsEl.textContent = totalCount > 0 ? fmt('totalsPattern', { done: doneCount, total: totalCount }) : i18n.noTasksYet;
1792
+ }
1793
+
1794
+ const summaryText = data.summary || data.note || '';
1795
+ const summaryEl = document.getElementById('overviewSummary');
1796
+ if (summaryEl && summaryText) {
1797
+ summaryEl.textContent = summaryText;
1798
+ }
1799
+ checkSummaryOverflow();
1800
+
1801
+ const titleProgress = document.getElementById('titleProgress');
1802
+ if (titleProgress) {
1803
+ const color = colors[currentState] || colors.unstarted;
1804
+ const hasProgress = currentProgress !== null && currentProgress !== undefined && Number.isFinite(currentProgress);
1805
+ const progVal = hasProgress ? Math.max(0, Math.min(100, currentProgress)) : 0;
1806
+
1807
+ let piePath = '';
1808
+ if (hasProgress && progVal > 0) {
1809
+ const angle = (progVal / 100) * Math.PI * 2;
1810
+ const x = (12 + 7.4 * Math.sin(angle)).toFixed(2);
1811
+ const y = (12 - 7.4 * Math.cos(angle)).toFixed(2);
1812
+ piePath = progVal === 100
1813
+ ? '<path d="M12 4.6a7.4 7.4 0 1 1 0 14.8a7.4 7.4 0 1 1 0-14.8" fill="' + color + '" class="progress-pie"/>'
1814
+ : '<path d="M12 12L12 4.6A7.4 7.4 0 ' + (progVal > 50 ? 1 : 0) + ' 1 ' + x + ' ' + y + 'Z" fill="' + color + '" class="progress-pie"/>';
1815
+ }
1816
+
1817
+ const isHundred = progVal === 100;
1818
+ const fontSize = isHundred ? '5.8px' : '6.4px';
1819
+ const letterSpacing = isHundred ? '-0.3px' : '-0.2px';
1820
+
1821
+ titleProgress.innerHTML = '<svg viewBox="0 0 24 24" width="32" height="32" aria-hidden="true" style="overflow:visible">' +
1822
+ '<circle cx="12" cy="12" r="10" fill="none" stroke="' + color + '" stroke-width="1.6" opacity="' + (hasProgress ? '1' : '0.85') + '"/>' +
1823
+ piePath +
1824
+ '<text x="12" y="12.4" text-anchor="middle" dominant-baseline="middle" fill="' + color + '" class="' + (hasProgress ? '' : 'progress-unknown') + '" style="font:600 ' + fontSize + ' -apple-system,BlinkMacSystemFont,sans-serif;letter-spacing:' + letterSpacing + ';font-variant-numeric:tabular-nums">' + (hasProgress ? (progVal + '%') : '—') + '</text>' +
1825
+ '</svg>';
1826
+ }
1827
+
1828
+ if (Array.isArray(data.tasks)) {
1829
+ const remaining = data.tasks.filter(function(t) { return t.status !== 'done'; });
1830
+ const completed = data.tasks.filter(function(t) { return t.status === 'done'; });
1831
+
1832
+ const remainingHeading = document.getElementById('remainingTasksHeading');
1833
+ if (remainingHeading) remainingHeading.textContent = fmt('remainingHeadingPattern', { count: remaining.length });
1834
+
1835
+ const toggleBtn = document.getElementById('btnToggleAllRemaining');
1836
+ if (toggleBtn) {
1837
+ toggleBtn.hidden = remaining.length <= 3;
1838
+ toggleBtn.textContent = fmt('showAllCountPattern', { count: remaining.length });
1839
+ toggleBtn.setAttribute('data-expanded', 'false');
1840
+ }
1841
+
1842
+ const historyCount = document.getElementById('historyCount');
1843
+ if (historyCount) historyCount.textContent = fmt('countArrowPattern', { count: completed.length });
1844
+
1845
+ const uncompletedList = document.getElementById('uncompletedTasksList');
1846
+ if (uncompletedList) {
1847
+ let html = '';
1848
+ if (data.tasks.length === 0) {
1849
+ html = '<div class="empty">' + escapeHtml(i18n.emptyNoTasks) + '</div>';
1850
+ } else if (remaining.length === 0) {
1851
+ html = '<div class="empty">' + escapeHtml(i18n.emptyNoRemaining) + '</div>';
1852
+ }
1853
+ html += remaining.map(function(task, idx) {
1854
+ const hasSource = Boolean(task.source && (task.source.locator || task.source.turnId));
1855
+ const badge = taskLabels[task.status] || task.status;
1856
+ const titleText = task.title || task.summary || i18n.untitledTask;
1857
+ return '<div class="task-row ' + (idx >= 3 ? 'remaining-hidden' : '') + '" data-status="' + escapeHtml(task.status) + '" tabindex="0" ' + (idx >= 3 ? 'hidden' : '') + '>' +
1858
+ '<span class="task-dot"></span>' +
1859
+ '<div class="task-content">' +
1860
+ '<div class="task-title">' + escapeHtml(titleText) + '</div>' +
1861
+ '<div class="task-meta">' + escapeHtml(badge) + '</div>' +
1862
+ '</div>' +
1863
+ (hasSource ? '<div class="task-source"><button type="button" aria-label="' + escapeHtml(i18n.viewSourceAriaPrefix + titleText) + '" data-source="' + escapeHtml(JSON.stringify(task.source)) + '" onclick="onSourceClick(this)">' + escapeHtml(i18n.viewSource) + '</button></div>' : '') +
1864
+ '</div>';
1865
+ }).join('');
1866
+ uncompletedList.innerHTML = html;
1867
+ }
1868
+
1869
+ const historyList = document.getElementById('historyList');
1870
+ if (historyList) {
1871
+ let html = '';
1872
+ if (completed.length === 0) {
1873
+ html = '<div class="empty">' + escapeHtml(i18n.emptyCompleted) + '</div>';
1874
+ }
1875
+ html += completed.map(function(task) {
1876
+ const hasSource = Boolean(task.source && (task.source.locator || task.source.turnId));
1877
+ const titleText = task.title || task.summary || i18n.completedTaskFallback;
1878
+ return '<div class="task-row" data-status="done" tabindex="0">' +
1879
+ '<span class="task-dot"></span>' +
1880
+ '<div class="task-content">' +
1881
+ '<div class="task-title">' + escapeHtml(titleText) + '</div>' +
1882
+ '<div class="task-meta">' + escapeHtml(taskLabels.done || 'done') + '</div>' +
1883
+ '</div>' +
1884
+ (hasSource ? '<div class="task-source"><button type="button" aria-label="' + escapeHtml(i18n.viewSourceAriaPrefix + titleText) + '" data-source="' + escapeHtml(JSON.stringify(task.source)) + '" onclick="onSourceClick(this)">' + escapeHtml(i18n.viewSource) + '</button></div>' : '') +
1885
+ '</div>';
1886
+ }).join('');
1887
+ historyList.innerHTML = html;
1888
+ }
1889
+ }
1890
+
1891
+ if (hostChannelPort) {
1892
+ try {
1893
+ hostChannelPort.postMessage({
1894
+ type: 'AGENT_THINGS_CARD_UPDATED',
1895
+ conversationId: conversationId,
1896
+ progress: currentProgress,
1897
+ revision: currentRevision,
1898
+ state: currentState,
1899
+ });
1900
+ } catch (_) {}
1901
+ }
1902
+ }
1903
+
1904
+ async function onAnalyzeClick() {
1905
+ const btn = document.getElementById('btnAnalyze');
1906
+ try {
1907
+ if (btn) {
1908
+ btn.disabled = true;
1909
+ btn.textContent = i18n.btnUpdating;
1910
+ }
1911
+ showFeedback(i18n.startingAnalysisFeedback);
1912
+ await sendProxyAction('analyze', {});
1913
+ } catch (err) {
1914
+ showFeedback(i18n.updateFailedPrefix + err.message, true);
1915
+ if (btn) {
1916
+ btn.disabled = false;
1917
+ btn.textContent = i18n.btnUpdate;
1918
+ }
1919
+ }
1920
+ }
1921
+
1922
+ async function initEventStream() {
1923
+ if (sseReconnectTimer) {
1924
+ clearTimeout(sseReconnectTimer);
1925
+ sseReconnectTimer = null;
1926
+ }
1927
+ if (sseSource) {
1928
+ try { sseSource.close(); } catch (_) {}
1929
+ sseSource = null;
1930
+ }
1931
+
1932
+ try {
1933
+ const auth = await requestHostAuth();
1934
+ if (!auth?.ticket || !auth?.origin) {
1935
+ scheduleReconnect();
1936
+ return;
1937
+ }
1938
+ authTicket = auth.ticket;
1939
+ serviceOrigin = auth.origin;
1940
+
1941
+ const sseUrl = auth.origin + '/session/events?id=' + encodeURIComponent(conversationId) + '&ticket=' + encodeURIComponent(auth.ticket);
1942
+ const es = new EventSource(sseUrl);
1943
+ sseSource = es;
1944
+
1945
+ es.addEventListener('snapshot', function(ev) {
1946
+ try {
1947
+ const data = JSON.parse(ev.data);
1948
+ handleRemoteSessionUpdate(data);
1949
+ } catch (_) {}
1950
+ });
1951
+
1952
+ es.addEventListener('change', function(ev) {
1953
+ try {
1954
+ const data = JSON.parse(ev.data);
1955
+ handleRemoteSessionUpdate(data);
1956
+ } catch (_) {}
1957
+ });
1958
+
1959
+ es.onerror = function() {
1960
+ try { es.close(); } catch (_) {}
1961
+ sseSource = null;
1962
+ scheduleReconnect();
1963
+ };
1964
+ } catch (_) {
1965
+ scheduleReconnect();
1966
+ }
1967
+ }
1968
+
1969
+ function scheduleReconnect() {
1970
+ if (sseReconnectTimer) return;
1971
+ sseReconnectTimer = setTimeout(function() {
1972
+ sseReconnectTimer = null;
1973
+ initEventStream();
1974
+ }, 2000);
1975
+ }
1976
+
1977
+ function setupScrollListener() {
1978
+ const panel = document.getElementById('panelBody');
1979
+ const shell = document.getElementById('agentThingsCard');
1980
+ if (!panel || !shell) return;
1981
+ panel.addEventListener('scroll', function() {
1982
+ const isScrolled = panel.scrollTop > 8;
1983
+ shell.classList.toggle('is-scrolled', isScrolled);
1984
+ }, { passive: true });
1985
+ }
1986
+
1987
+ function initCard() {
1988
+ checkSummaryOverflow();
1989
+ setupScrollListener();
1990
+ initEventStream();
1991
+ }
1992
+
1993
+ if (document.readyState === 'loading') {
1994
+ document.addEventListener('DOMContentLoaded', initCard);
1995
+ } else {
1996
+ initCard();
1997
+ }
1998
+ </script>
1999
+ </body>
2000
+ </html>`;
2001
+ }
2002
+
2003
+ function getAntigravityHttpConnection(stateFile) {
2004
+ const file = stateFile || path.join(os.homedir(), '.gemini', 'antigravity', 'session-status', 'manual-state.json');
2005
+ const credsFile = `${file}.http.json`;
2006
+ if (!fs.existsSync(credsFile)) return null;
2007
+ try {
2008
+ const creds = JSON.parse(fs.readFileSync(credsFile, 'utf8'));
2009
+ return {
2010
+ origin: `http://127.0.0.1:${creds.port}`,
2011
+ };
2012
+ } catch {
2013
+ return null;
2014
+ }
2015
+ }
2016
+
2017
+ function generateCardArtifact({
2018
+ conversationId,
2019
+ title,
2020
+ record,
2021
+ tasks,
2022
+ summary,
2023
+ revision,
2024
+ brainDir,
2025
+ artifactDir,
2026
+ stateFile,
2027
+ loadToken = null,
2028
+ connection: passedConnection = null,
2029
+ lang,
2030
+ }) {
2031
+ const resolvedLang = lang || readConfiguredLang({ dataDir: stateFile ? path.dirname(stateFile) : undefined });
2032
+ const dir = brainDir || artifactDir || path.join(os.homedir(), '.gemini', 'antigravity', 'brain', conversationId);
2033
+ fs.mkdirSync(dir, { recursive: true });
2034
+ const htmlPath = path.join(dir, 'things-card.html');
2035
+ const connection = passedConnection || getAntigravityHttpConnection(stateFile) || {};
2036
+ const token = loadToken || passedConnection?.loadToken || connection.loadToken || ('token-' + crypto.randomBytes(16).toString('hex'));
2037
+ connection.loadToken = token;
2038
+ const html = renderAntigravityCardHtml({
2039
+ title,
2040
+ conversationId,
2041
+ record,
2042
+ tasks,
2043
+ summary,
2044
+ revision,
2045
+ connection,
2046
+ lang: resolvedLang,
2047
+ });
2048
+ fs.writeFileSync(htmlPath, html, 'utf8');
2049
+ return {
2050
+ path: htmlPath,
2051
+ embedTag: `<agent-embed src="file://${htmlPath}"></agent-embed>`,
2052
+ loadToken: token,
2053
+ };
2054
+ }
2055
+
2056
+ module.exports = {
2057
+ renderAntigravityCardHtml,
2058
+ generateCardArtifact,
2059
+ getAntigravityHttpConnection,
2060
+ colors,
2061
+ labels,
2062
+ taskLabels,
2063
+ };