codexmate 0.1.34 → 0.1.35

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 (47) hide show
  1. package/README.md +15 -1
  2. package/README.vi.md +15 -1
  3. package/README.zh.md +15 -1
  4. package/cli/analytics-export-args.js +7 -0
  5. package/cli/session-usage.js +4 -1
  6. package/cli.js +29 -5
  7. package/lib/data/model-prices.json +1868 -0
  8. package/lib/session-context-health.js +5 -1
  9. package/lib/session-evidence-collections.js +85 -0
  10. package/lib/session-features.js +15 -0
  11. package/lib/session-project-git.js +65 -0
  12. package/lib/session-projects.js +12 -1
  13. package/lib/session-stories.js +67 -0
  14. package/lib/session-usage-ledger.js +77 -0
  15. package/lib/session-usage-pricing.js +42 -0
  16. package/lib/session-usage-report.js +101 -0
  17. package/package.json +4 -1
  18. package/plugins/prompt-templates/computed.mjs +9 -0
  19. package/web-ui/app.js +10 -0
  20. package/web-ui/logic.session-artifacts.mjs +39 -0
  21. package/web-ui/modules/app.methods.agents.mjs +3 -2
  22. package/web-ui/modules/app.methods.session-browser.mjs +35 -0
  23. package/web-ui/modules/app.methods.system-prompt.mjs +16 -7
  24. package/web-ui/modules/app.methods.web-ui-preferences.mjs +5 -0
  25. package/web-ui/modules/i18n/locales/en.mjs +116 -1
  26. package/web-ui/modules/i18n/locales/ja.mjs +116 -1
  27. package/web-ui/modules/i18n/locales/vi.mjs +116 -1
  28. package/web-ui/modules/i18n/locales/zh-tw.mjs +116 -1
  29. package/web-ui/modules/i18n/locales/zh.mjs +116 -1
  30. package/web-ui/modules/session-collections.mjs +65 -0
  31. package/web-ui/modules/session-evidence.mjs +81 -0
  32. package/web-ui/modules/session-features.mjs +15 -1
  33. package/web-ui/modules/session-git.mjs +39 -0
  34. package/web-ui/modules/session-stories.mjs +64 -0
  35. package/web-ui/modules/usage-pricing.mjs +30 -0
  36. package/web-ui/partials/index/layout-footer.html +1 -1
  37. package/web-ui/partials/index/panel-sessions.html +20 -20
  38. package/web-ui/partials/index/panel-usage.html +2 -0
  39. package/web-ui/partials/index/session-features.html +82 -2
  40. package/web-ui/partials/index/thread-handoff.html +73 -62
  41. package/web-ui/partials/index/usage-records.html +41 -0
  42. package/web-ui/res/web-ui-render.precompiled.js +772 -125
  43. package/web-ui/styles/session-features.css +63 -0
  44. package/web-ui/styles/sessions-list.css +74 -0
  45. package/web-ui/styles/sessions-preview.css +106 -68
  46. package/web-ui/styles/sessions-usage.css +8 -0
  47. package/web-ui/styles/theme-violet.css +9 -3
@@ -190,14 +190,6 @@
190
190
  {{ parseSessionTitleInfo(session).location }}
191
191
  </div>
192
192
  </div>
193
- <span class="session-count-badge">{{ session.messageCount == null ? '...' : session.messageCount }}</span>
194
- <span v-if="session.match && session.match.hit" class="session-match-badge">{{ session.match.count }}</span>
195
- <span
196
- v-if="sessionContextUtilization[getSessionExportKey(session)] && sessionContextUtilization[getSessionExportKey(session)].percent > 0"
197
- :class="['session-context-badge', 'session-context-' + sessionContextUtilization[getSessionExportKey(session)].level]"
198
- :title="'Context: ' + sessionContextUtilization[getSessionExportKey(session)].percent + '%'">
199
- {{ sessionContextUtilization[getSessionExportKey(session)].percent }}%
200
- </span>
201
193
  </div>
202
194
  <div class="session-item-actions">
203
195
  <button
@@ -231,6 +223,14 @@
231
223
  <div class="session-item-meta">
232
224
  <span class="session-source" :data-source="session.source">{{ session.sourceLabel }}</span>
233
225
  <span class="session-item-time">{{ session.updatedAtLabel || session.updatedAt || t('sessions.unknownTime') }}</span>
226
+ <span class="session-count-badge">{{ session.messageCount == null ? '...' : session.messageCount }}</span>
227
+ <span v-if="session.match && session.match.hit" class="session-match-badge">{{ session.match.count }}</span>
228
+ <span
229
+ v-if="sessionContextUtilization[getSessionExportKey(session)] && sessionContextUtilization[getSessionExportKey(session)].percent > 0"
230
+ :class="['session-context-badge', 'session-context-' + sessionContextUtilization[getSessionExportKey(session)].level]"
231
+ :title="'Context: ' + sessionContextUtilization[getSessionExportKey(session)].percent + '%'">
232
+ {{ sessionContextUtilization[getSessionExportKey(session)].percent }}%
233
+ </span>
234
234
  <span v-if="getSessionHotLabel(session)" class="session-item-hot">{{ getSessionHotLabel(session) }}</span>
235
235
  <div v-if="session.match && session.match.snippets && session.match.snippets.length" class="session-match-snippets">
236
236
  <div v-for="(snip, si) in session.match.snippets.slice(0, 2)" :key="si" class="session-match-snippet">{{ snip }}</div>
@@ -428,20 +428,20 @@
428
428
  <span class="session-msg-role">{{ msg.roleLabel || (msg.normalizedRole === 'user' ? t('sessions.roleLabel.user') : (msg.normalizedRole === 'system' ? t('sessions.roleLabel.system') : t('sessions.roleLabel.assistant'))) }}</span>
429
429
  <span class="session-msg-time">{{ msg.timestamp || '' }}</span>
430
430
  </div>
431
+ <button
432
+ v-if="msg.normalizedRole === 'user'"
433
+ type="button"
434
+ class="session-msg-copy"
435
+ @click="copySessionMessage(msg)"
436
+ :aria-label="t('sessions.preview.copyMessage')"
437
+ :title="t('sessions.preview.copyMessage')">
438
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
439
+ <rect x="8" y="8" width="12" height="12" rx="2"></rect>
440
+ <path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"></path>
441
+ </svg>
442
+ </button>
431
443
  </div>
432
444
  <div class="session-msg-content" v-html="msg.text || ''"></div>
433
- <button
434
- v-if="msg.normalizedRole === 'user'"
435
- type="button"
436
- class="session-msg-copy"
437
- @click="copySessionMessage(msg)"
438
- :aria-label="t('sessions.preview.copyMessage')"
439
- :title="t('sessions.preview.copyMessage')">
440
- <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
441
- <rect x="8" y="8" width="12" height="12" rx="2"></rect>
442
- <path d="M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"></path>
443
- </svg>
444
- </button>
445
445
  </div>
446
446
  <div v-if="canLoadMoreSessionMessages" class="session-preview-load-more">
447
447
  <span>{{ t('sessions.preview.shownCount', { shown: activeSessionVisibleMessages.length, total: activeSessionMessages.length }) }}</span>
@@ -17,6 +17,8 @@
17
17
  </div>
18
18
  </div>
19
19
 
20
+ <!-- @include ./usage-records.html -->
21
+
20
22
  <div v-if="sessionsUsageLoading && !sessionsUsageList.length" class="usage-empty-state">
21
23
  <div class="usage-empty-illustration">
22
24
  <svg viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -20,12 +20,18 @@
20
20
  <div v-if="indexReport" class="feature-meta" role="status">
21
21
  <span class="feature-status" :data-status="indexReport.job.status">{{ t('features.status.' + indexReport.job.status) }}</span>
22
22
  <span>{{ t('features.indexStatus', { count: indexReport.indexed, processed: indexReport.job.processed, total: indexReport.job.candidates }) }}</span>
23
+ <span class="feature-index-time">{{ t('features.indexCatalogTime', { time: indexCatalogTime }) }}</span>
23
24
  </div>
24
25
  <form class="feature-actions feature-search-form" @submit.prevent="searchSessionIndex">
25
26
  <input v-model="indexQuery" :aria-label="t('features.search')" :placeholder="t('features.search')">
26
27
  <button class="btn-mini feature-primary" :disabled="featureBusy || !indexQuery.trim() || !indexReport?.updatedAt">{{ t('features.search') }}</button>
27
28
  </form>
28
- <details class="feature-disclosure"><summary>{{ t('features.searchScope') }}</summary><p class="feature-hint">{{ t('features.indexScope') }}</p></details>
29
+ <details class="feature-disclosure feature-index-scope">
30
+ <summary>{{ t('features.searchScope') }}</summary>
31
+ <p class="feature-hint">{{ t('features.indexScope') }}</p>
32
+ <p v-for="entry in indexSourceCoverage" :key="entry.source" class="feature-hint feature-index-coverage">{{ t('features.indexSourceCoverage', { source: t('sessions.source.' + entry.source), count: entry.candidates ?? t('features.indexUnknown'), limit: entry.discoveryLimit ?? t('features.indexUnknown') }) }}</p>
33
+ <p v-if="!indexSourceCoverage.length" class="feature-hint feature-index-unknown">{{ t('features.indexCoverageUnknown') }}</p>
34
+ </details>
29
35
  <p v-if="indexReport?.failures.length" class="form-error" role="alert">{{ t('features.indexFailures', { count: indexReport.failures.length }) }}</p>
30
36
  <p v-if="featureBusy" class="feature-loading" role="status">{{ t('features.loading') }}</p>
31
37
  <template v-if="indexResults">
@@ -36,11 +42,48 @@
36
42
  <header class="feature-record-heading"><h4>{{ result.session.title || result.session.sessionId }}</h4><span class="feature-source">{{ result.session.source }}</span></header>
37
43
  <small class="feature-path" :title="result.session.cwd">{{ result.session.cwd }}</small>
38
44
  <pre class="feature-excerpt">{{ result.snippet }}</pre>
39
- <div class="feature-record-actions"><button type="button" class="btn-mini" @click="openIndexedMessage(result)">{{ t('features.source') }}</button></div>
45
+ <div class="feature-record-actions"><button type="button" class="btn-mini" @click="openIndexedMessage(result)">{{ t('features.source') }}</button><label class="evidence-select"><input type="checkbox" :checked="isEvidenceSelected(result)" @change="toggleEvidence(result)">{{ t('evidence.select') }}</label></div>
40
46
  <details class="feature-disclosure"><summary>{{ t('features.context') }}</summary><pre>{{ result.before }}</pre><pre>{{ result.after }}</pre></details>
41
47
  </article>
42
48
  </template>
43
49
  </div>
50
+ <details class="feature-disclosure evidence-collections" :open="collectionsOpen" @toggle="toggleCollections($event)">
51
+ <summary>{{ t('collections.title') }}</summary>
52
+ <p class="feature-hint">{{ t('collections.scope') }}</p>
53
+ <p v-if="collectionError" class="form-error" role="alert">{{ collectionError }}</p>
54
+ <p v-if="collectionBusy" role="status">{{ t('features.loading') }}</p>
55
+ <ol class="collection-list"><li v-for="item in collections" :key="item.id">
56
+ <button type="button" class="btn-mini" @click="openEvidenceCollection(item)" :disabled="collectionBusy || evidenceBusy" :aria-pressed="collectionId === item.id">{{ item.name }}</button>
57
+ <span class="feature-count">{{ item.references.length }}/100</span>
58
+ <button type="button" class="btn-mini feature-quiet" @click="removeEvidenceCollection(item)" :disabled="collectionBusy">{{ t('collections.remove') }}</button>
59
+ </li></ol>
60
+ <p v-if="!collectionBusy && !collections.length" class="feature-hint">{{ t('collections.empty') }}</p>
61
+ <form v-if="evidenceSelections.length" class="feature-editor collection-editor" @submit.prevent="saveEvidenceCollection(false)">
62
+ <label>{{ t('collections.name') }}<input v-model="collectionName" maxlength="160" required></label>
63
+ <div class="feature-actions">
64
+ <button class="btn-mini" :disabled="collectionBusy || evidenceBusy || !collectionName.trim()">{{ t('collections.save') }}</button>
65
+ <button v-if="collectionId" type="button" class="btn-mini feature-quiet" @click="saveEvidenceCollection(true)" :disabled="collectionBusy || evidenceBusy || !collectionName.trim()">{{ t('collections.saveAs') }}</button>
66
+ </div>
67
+ </form>
68
+ <button type="button" class="btn-mini feature-quiet" @click="loadEvidenceCollections" :disabled="collectionBusy">{{ t('collections.refresh') }}</button>
69
+ </details>
70
+ <section v-if="evidenceSelections.length" class="evidence-basket" :aria-label="t('evidence.title')">
71
+ <div class="feature-section-heading"><h3>{{ t('evidence.title') }}</h3><span class="feature-count">{{ evidenceSelections.length }}/100</span></div>
72
+ <p class="feature-hint">{{ t('evidence.memory') }}</p>
73
+ <ol class="evidence-list"><li v-for="item in evidenceSelections" :key="evidenceKey(item)"><span><strong>{{ item.session.title || item.session.sessionId }}</strong><small class="feature-meta">{{ item.session.source }} · {{ item.nodeId }}</small><small v-if="item.state" class="collection-source-state" :data-state="item.state">{{ t('collections.state.' + item.state) }}</small></span><button type="button" class="btn-mini feature-quiet" @click="openIndexedMessage(item)">{{ t('features.source') }}</button><button type="button" class="btn-mini" @click="toggleEvidence(item)">{{ t('evidence.remove') }}</button></li></ol>
74
+ <form class="feature-actions feature-search-form evidence-generator" @submit.prevent="generateEvidencePack">
75
+ <input v-model="evidenceGoal" :aria-label="t('evidence.goal')" :placeholder="t('evidence.goal')">
76
+ <select v-model="evidenceFormat" :aria-label="t('artifacts.format')">
77
+ <option value="evidence">{{ t('evidence.title') }}</option>
78
+ <option value="receipt">{{ t('artifacts.receipt') }}</option>
79
+ <option value="relay">{{ t('artifacts.relay') }}</option>
80
+ </select>
81
+ <textarea v-if="evidenceFormat !== 'evidence'" v-model="evidenceNote" class="evidence-generator-note" rows="3" maxlength="4000" :aria-label="t('artifacts.note')" :placeholder="t('artifacts.notePlaceholder')"></textarea>
82
+ <button class="btn-mini feature-primary" :disabled="evidenceBusy">{{ evidenceBusy ? t('features.loading') : evidenceFormat === 'evidence' ? t('evidence.generate') : t('artifacts.generate.' + evidenceFormat) }}</button>
83
+ </form>
84
+ <p v-if="evidenceError" class="form-error" role="alert">{{ evidenceError }}</p>
85
+ <details v-if="evidencePack" class="feature-disclosure evidence-preview" open><summary>{{ t('evidence.preview', { count: evidencePack.length }) }}</summary><pre>{{ evidencePack }}</pre><button type="button" class="btn-mini" @click="downloadEvidencePack">{{ t('evidence.download') }}</button></details>
86
+ </section>
44
87
  <div v-if="featureView === 'projects'" class="feature-content">
45
88
  <div class="feature-section-heading"><h3>{{ t('features.projects') }}</h3><small v-if="projectReport" class="feature-meta">{{ t('features.readAt', { time: projectReport.readAt }) }}</small></div>
46
89
  <p class="feature-hint">{{ t('features.projectHistory') }}</p>
@@ -56,6 +99,43 @@
56
99
  <template v-if="projectReport.detail">
57
100
  <div class="feature-section-heading feature-project-heading"><h4 class="feature-path" :title="projectReport.detail.cwd">{{ projectReport.detail.cwd || t('features.unassigned') }}</h4></div>
58
101
  <p v-if="projectReport.detail.truncated" class="feature-hint">{{ t('features.partial') }}</p>
102
+ <details v-if="projectSelected" class="feature-disclosure project-git" @toggle="toggleProjectGit($event)">
103
+ <summary>{{ t('git.title') }}</summary>
104
+ <p class="feature-hint">{{ t('git.scope') }}</p>
105
+ <p v-if="projectGitError" class="form-error" role="alert">{{ projectGitError }}</p>
106
+ <p v-if="projectGitBusy" role="status">{{ t('features.loading') }}</p>
107
+ <template v-if="projectGit">
108
+ <p class="feature-meta">{{ t('git.status.' + projectGit.status) }} · {{ t('features.readAt', { time: projectGit.readAt }) }}</p>
109
+ <template v-if="projectGit.root">
110
+ <p class="feature-path">{{ projectGit.root }}</p>
111
+ <p class="feature-meta">{{ projectGit.branch || t('git.detached') }} · <code>{{ projectGit.head || t('git.noHead') }}</code> · {{ t('git.changes', { count: projectGit.changedFiles }) }}</p>
112
+ <ul class="git-change-list"><li v-for="change in projectGit.changes" :key="change.path"><code>{{ change.status }}</code> {{ change.path }}</li></ul>
113
+ <p v-if="projectGit.changesTruncated || projectGit.commitsTruncated" class="feature-hint">{{ t('git.truncated') }}</p>
114
+ <ol class="git-commit-list"><li v-for="commit in projectGit.commits" :key="commit.sha"><button type="button" class="btn-mini" @click="loadProjectGitCommit(commit.sha)" :disabled="projectGitBusy"><code>{{ commit.sha.slice(0, 8) }}</code> {{ commit.subject }}</button><small class="feature-meta">{{ commit.timestamp }}</small><div class="feature-link-list"><button v-for="session in commit.candidates" :key="session.source + session.sessionId" type="button" @click="selectSession(session)">{{ t('git.candidate') }}: {{ session.source }} · {{ session.title || session.sessionId }}</button></div></li></ol>
115
+ <pre v-if="projectGitCommit" class="feature-code git-commit-stat">{{ projectGitCommit.sha }}
116
+ {{ projectGitCommit.stat }}</pre>
117
+ <section v-if="projectGitCommit" class="project-stories" :aria-label="t('stories.title')">
118
+ <h4>{{ t('stories.title') }}</h4>
119
+ <p class="feature-hint">{{ t('stories.scope') }}</p>
120
+ <p v-if="storyError" class="form-error" role="alert">{{ storyError }}</p>
121
+ <p v-if="storyBusy" role="status">{{ t('features.loading') }}</p>
122
+ <article v-for="item in commitStories" :key="item.id" class="story-record">
123
+ <p class="feature-meta">{{ t('stories.linked') }} · {{ item.session.source }}</p>
124
+ <button v-if="item.available" type="button" class="btn-mini" @click="selectSession(item.session)">{{ item.session.title || item.session.sessionId }}</button>
125
+ <p v-else class="feature-hint">{{ item.session.title || item.session.sessionId }} · {{ t('stories.unavailable') }}</p>
126
+ <p class="feature-note">{{ item.note }}</p>
127
+ <button type="button" class="btn-mini feature-quiet" @click="removeProjectStory(item)" :disabled="storyBusy">{{ t('stories.remove') }}</button>
128
+ </article>
129
+ <form class="feature-editor story-editor" @submit.prevent="saveProjectStory">
130
+ <label>{{ t('stories.session') }}<select v-model="storySession" :disabled="storyBusy"><option value="">{{ t('stories.choose') }}</option><option v-for="session in storySessions" :key="storySessionKey(session)" :value="storySessionKey(session)">{{ session.source }} · {{ session.title || session.sessionId }}</option></select></label>
131
+ <label>{{ t('stories.note') }}<textarea v-model="storyNote" maxlength="4000"></textarea></label>
132
+ <div class="feature-actions"><button class="btn-mini" :disabled="storyBusy || !storySession">{{ t('stories.save') }}</button><button type="button" class="btn-mini feature-quiet" @click="loadProjectStories" :disabled="storyBusy">{{ t('stories.refresh') }}</button></div>
133
+ </form>
134
+ </section>
135
+ </template>
136
+ </template>
137
+ <button type="button" class="btn-mini" @click="loadProjectGit" :disabled="projectGitBusy">{{ t('git.refresh') }}</button>
138
+ </details>
59
139
  <div class="feature-project-sessions">
60
140
  <article v-for="session in projectReport.detail.sessions" :key="session.source + session.sessionId" class="feature-session-row">
61
141
  <button type="button" @click="selectSession(session)">{{ session.title || session.sessionId }}</button>
@@ -1,62 +1,73 @@
1
- <details v-if="activeSession" :key="handoffSessionKey" class="session-workspace thread-handoff" :open="handoffExpanded" @toggle="toggleThreadHandoff" aria-label="会话交接">
2
- <summary class="thread-handoff-summary"><span>会话交接</span><span class="thread-handoff-summary-hint">{{ handoffExpanded ? '收起' : '填写交接 · 查看历史' }}</span></summary>
3
- <div v-if="handoffExpanded" class="thread-handoff-body">
4
- <div class="session-workspace-header session-workspace-card-wide">
5
- <p class="session-workspace-subtitle">草稿在切换会话后保留,刷新后清空。</p>
6
- <button class="btn-mini" type="button" @click="loadThreadHandoffs" :disabled="handoffLoading || handoffBusy">{{ handoffLoading ? '刷新中…' : '刷新历史' }}</button>
7
- </div>
8
- <form @submit.prevent="createThreadHandoff" class="thread-handoff-form">
9
- <label class="thread-handoff-field">
10
- <span class="session-workspace-card-title">交给谁 <small>必填</small></span>
11
- <input v-model="handoffDraft.target" class="session-query-input" required :disabled="handoffBusy" placeholder="目标代理标识,例如 claude">
12
- </label>
13
- <label class="thread-handoff-field">
14
- <span class="session-workspace-card-title">接下来做什么 <small>必填</small></span>
15
- <textarea v-model="handoffDraft.goal" class="session-query-input" rows="3" required :disabled="handoffBusy" placeholder="描述下一步任务、预期结果或验收标准"></textarea>
16
- </label>
17
- <details class="thread-handoff-optional">
18
- <summary class="thread-handoff-optional-summary">补充上下文</summary>
19
- <div class="session-workspace-grid">
20
- <label v-for="field in handoffFields" :key="field.key" class="thread-handoff-field">
21
- <span class="session-workspace-card-title">{{ field.label }}(可选)</span>
22
- <textarea v-model="handoffDraft[field.key]" class="session-query-input" rows="3" :disabled="handoffBusy" placeholder="每行填写一项"></textarea>
23
- </label>
24
- </div>
25
- </details>
26
- <div class="thread-handoff-actions">
27
- <button class="btn-mini thread-handoff-submit" type="submit" :disabled="handoffBusy || handoffLoading || !handoffDraft.target.trim() || !handoffDraft.goal.trim()">{{ handoffBusy ? '处理中…' : '生成交接' }}</button>
28
- </div>
29
- </form>
30
- <p v-if="handoffError" class="state-message error session-workspace-card-wide" role="alert">{{ handoffError }}</p>
31
- <p v-if="handoffNotice" class="state-message session-workspace-card-wide" role="status" aria-live="polite">{{ handoffNotice }}</p>
32
- <label v-if="handoffCopyText" class="session-workspace-card session-workspace-card-wide">
33
- <span class="session-workspace-card-title">卡片文本(未发送,可手动复制)</span>
34
- <textarea class="session-query-input" rows="6" readonly :value="handoffCopyText" @focus="$event.target.select()"></textarea>
35
- </label>
36
- <p class="session-workspace-subtitle session-workspace-card-wide">复制不会自动发送。读取确认由目标代理通过 CLI ack 提交。</p>
37
- <div class="feature-actions"><button type="button" class="btn-mini" @click="generateSelectedHandoff" :disabled="featureBusy || !selectedContextIds.length">{{ t('features.generateDraft', { count: selectedContextIds.length }) }}</button></div>
38
- <p v-if="handoffDraftEvidence.length">{{ t('features.draftReview') }}</p>
39
- <details v-if="handoffUnverified.length"><summary>{{ t('features.unverified', { count: handoffUnverified.length }) }}</summary><pre v-for="(text, index) in handoffUnverified" :key="index">{{ text }}</pre></details>
40
- <ul v-if="handoffDraftEvidence.length"><li v-for="item in handoffDraftEvidence" :key="item.nodeId"><button type="button" class="btn-mini" @click="locateDraftEvidence(item)">{{ item.nodeId }} · {{ t('features.evidence.' + item.status) }}</button></li></ul>
41
- <p v-if="handoffLoading" class="session-workspace-card-wide" role="status">正在加载交接历史…</p>
42
- <p v-else-if="!handoffError && !handoffRecords.length" class="session-workspace-empty session-workspace-card-wide">暂无交接记录</p>
43
- <ol v-if="handoffRecords.length" class="session-workspace-list session-workspace-card-wide">
44
- <li v-for="record in handoffRecords" :key="record.id" class="session-workspace-card">
45
- <div class="session-workspace-card-title">{{ record.target }} · {{ handoffStatusLabel(record.status) }}</div>
46
- <div>交接标识:<code>{{ record.id }}</code></div>
47
- <div>创建时间:{{ record.createdAt }} · 投递耗时:{{ record.durationMs }} 毫秒 · 写入耗时:{{ record.writeDurationMs || 0 }} 毫秒</div>
48
- <div>交接路径:{{ record.route === 'mcp' ? 'MCP 工具' : '文件级' }} · 文件回退:{{ record.fallback ? '是' : '否' }}</div>
49
- <div v-if="record.mcp">服务:{{ record.mcp.server }} · 工具:{{ record.mcp.tool }}</div>
50
- <div>写入结果:{{ record.writeResult === 'written' ? '已写入' : (record.writeResult === 'failed_or_unconfirmed' ? '失败或结果未确认(不重试)' : '未执行写入') }}</div>
51
- <div v-if="record.filePath">文件位置:<code>{{ record.filePath }}</code></div>
52
- <div v-if="record.reason">原因:{{ record.reason }}</div>
53
- <div v-if="record.readConfirmation">
54
- <div>读取代理:{{ record.readConfirmation.agent }} · 确认时间:{{ record.readConfirmation.at }}</div>
55
- <div>读取证据:{{ record.readConfirmation.evidence }}</div>
56
- </div>
57
- <div v-for="(warning, index) in record.discoveryWarnings || []" :key="index">探测提示:{{ warning.source }} · {{ warning.reason }}</div>
58
- <button class="btn-mini" type="button" @click="copyThreadHandoff(record)" :disabled="handoffBusy || handoffLoading">{{ record.route === 'mcp' ? '回退文件并复制卡片' : '复制卡片' }}</button>
59
- </li>
60
- </ol>
61
- </div>
62
- </details>
1
+ <details v-if="activeSession" :key="handoffSessionKey" class="session-workspace thread-handoff" :open="handoffExpanded" @toggle="toggleThreadHandoff" aria-label="会话交接">
2
+ <summary class="thread-handoff-summary"><span>会话交接</span><span class="thread-handoff-summary-hint">{{ handoffExpanded ? '收起' : '填写交接 · 查看历史' }}</span></summary>
3
+ <div v-if="handoffExpanded" class="thread-handoff-body">
4
+ <div class="session-workspace-header session-workspace-card-wide">
5
+ <p class="session-workspace-subtitle">草稿在切换会话后保留,刷新后清空。</p>
6
+ <button class="btn-mini" type="button" @click="loadThreadHandoffs" :disabled="handoffLoading || handoffBusy">{{ handoffLoading ? '刷新中…' : '刷新历史' }}</button>
7
+ </div>
8
+ <form @submit.prevent="createThreadHandoff" class="thread-handoff-form">
9
+ <label class="thread-handoff-field">
10
+ <span class="session-workspace-card-title">交给谁 <small>必填</small></span>
11
+ <input v-model="handoffDraft.target" class="session-query-input" required :disabled="handoffBusy" placeholder="目标代理标识,例如 claude">
12
+ </label>
13
+ <label class="thread-handoff-field">
14
+ <span class="session-workspace-card-title">接下来做什么 <small>必填</small></span>
15
+ <textarea v-model="handoffDraft.goal" class="session-query-input" rows="3" required :disabled="handoffBusy" placeholder="描述下一步任务、预期结果或验收标准"></textarea>
16
+ </label>
17
+ <details class="thread-handoff-optional">
18
+ <summary class="thread-handoff-optional-summary">补充上下文</summary>
19
+ <div class="session-workspace-grid">
20
+ <label v-for="field in handoffFields" :key="field.key" class="thread-handoff-field">
21
+ <span class="session-workspace-card-title">{{ field.label }}(可选)</span>
22
+ <textarea v-model="handoffDraft[field.key]" class="session-query-input" rows="3" :disabled="handoffBusy" placeholder="每行填写一项"></textarea>
23
+ </label>
24
+ </div>
25
+ </details>
26
+ <div class="thread-handoff-actions">
27
+ <button class="btn-mini thread-handoff-submit" type="submit" :disabled="handoffBusy || handoffLoading || !handoffDraft.target.trim() || !handoffDraft.goal.trim()">{{ handoffBusy ? '处理中…' : '生成交接' }}</button>
28
+ </div>
29
+ </form>
30
+ <p v-if="handoffError" class="state-message error session-workspace-card-wide" role="alert">{{ handoffError }}</p>
31
+ <p v-if="handoffNotice" class="state-message session-workspace-card-wide" role="status" aria-live="polite">{{ handoffNotice }}</p>
32
+ <label v-if="handoffCopyText" class="thread-handoff-copy session-workspace-card-wide">
33
+ <span class="session-workspace-card-title">卡片文本(未发送,可手动复制)</span>
34
+ <textarea class="session-query-input" rows="6" readonly :value="handoffCopyText" @focus="$event.target.select()"></textarea>
35
+ </label>
36
+ <p class="session-workspace-subtitle session-workspace-card-wide">复制不会自动发送。读取确认由目标代理通过 CLI ack 提交。</p>
37
+ <div v-if="selectedContextIds.length" class="feature-actions"><button type="button" class="btn-mini" @click="generateSelectedHandoff" :disabled="featureBusy || !selectedContextIds.length">{{ t('features.generateDraft', { count: selectedContextIds.length }) }}</button></div>
38
+ <p v-if="handoffDraftEvidence.length">{{ t('features.draftReview') }}</p>
39
+ <details v-if="handoffUnverified.length" class="thread-handoff-audit"><summary>{{ t('features.unverified', { count: handoffUnverified.length }) }}</summary><pre v-for="(text, index) in handoffUnverified" :key="index">{{ text }}</pre></details>
40
+ <ul v-if="handoffDraftEvidence.length" class="thread-handoff-evidence"><li v-for="item in handoffDraftEvidence" :key="item.nodeId"><button type="button" class="btn-mini" @click="locateDraftEvidence(item)">{{ item.nodeId }} · {{ t('features.evidence.' + item.status) }}</button></li></ul>
41
+ <section class="thread-handoff-history session-workspace-card-wide" aria-label="交接历史">
42
+ <h3>交接历史</h3>
43
+ <p v-if="handoffLoading" class="session-workspace-card-wide" role="status">正在加载交接历史…</p>
44
+ <p v-else-if="!handoffError && !handoffRecords.length" class="session-workspace-empty session-workspace-card-wide">暂无交接记录</p>
45
+ <ol v-if="handoffRecords.length" class="session-workspace-list session-workspace-card-wide">
46
+ <li v-for="record in handoffRecords" :key="record.id" class="session-workspace-card thread-handoff-record">
47
+ <div class="thread-handoff-record-heading">
48
+ <div class="thread-handoff-record-title"><strong>{{ record.target }}</strong><span class="thread-handoff-record-status">{{ handoffStatusLabel(record.status) }}</span></div>
49
+ <button class="btn-mini" type="button" @click="copyThreadHandoff(record)" :disabled="handoffBusy || handoffLoading">{{ record.route === 'mcp' ? '回退文件并复制卡片' : '复制卡片' }}</button>
50
+ </div>
51
+ <p class="thread-handoff-record-route">{{ record.route === 'mcp' ? 'MCP 工具' : '文件级' }} · {{ record.writeResult === 'written' ? '已写入' : (record.writeResult === 'failed_or_unconfirmed' ? '失败或结果未确认(不重试)' : '未执行写入') }}</p>
52
+ <p v-if="record.reason" class="thread-handoff-record-reason">原因:{{ record.reason }}</p>
53
+ <p v-if="record.readConfirmation" class="thread-handoff-read-proof">读取证据:<span>{{ record.readConfirmation.evidence }}</span></p>
54
+ <details class="thread-handoff-audit">
55
+ <summary>投递详情</summary>
56
+ <dl>
57
+ <div><dt>交接标识</dt><dd><code>{{ record.id }}</code></dd></div>
58
+ <div><dt>创建时间</dt><dd>{{ record.createdAt }}</dd></div>
59
+ <div><dt>投递耗时</dt><dd>{{ record.durationMs }} 毫秒</dd></div>
60
+ <div><dt>写入耗时</dt><dd>{{ record.writeDurationMs || 0 }} 毫秒</dd></div>
61
+ <div><dt>文件回退</dt><dd>{{ record.fallback ? '是' : '否' }}</dd></div>
62
+ <div v-if="record.mcp"><dt>MCP 服务</dt><dd>{{ record.mcp.server }} · {{ record.mcp.tool }}</dd></div>
63
+ <div v-if="record.filePath"><dt>文件位置</dt><dd><code>{{ record.filePath }}</code></dd></div>
64
+ <div v-if="record.readConfirmation"><dt>读取代理</dt><dd>{{ record.readConfirmation.agent }}</dd></div>
65
+ <div v-if="record.readConfirmation"><dt>确认时间</dt><dd>{{ record.readConfirmation.at }}</dd></div>
66
+ <div v-for="(warning, index) in record.discoveryWarnings || []" :key="index"><dt>探测提示</dt><dd>{{ warning.source }} · {{ warning.reason }}</dd></div>
67
+ </dl>
68
+ </details>
69
+ </li>
70
+ </ol>
71
+ </section>
72
+ </div>
73
+ </details>
@@ -0,0 +1,41 @@
1
+ <details class="usage-card usage-records" id="usage-records-report" @toggle="toggleUsageRecords($event)">
2
+ <summary>{{ t('usage.records.title') }}</summary>
3
+ <p class="usage-list-meta">{{ t('usage.records.scope') }}</p>
4
+ <p v-if="usageRecordsLoading" role="status">{{ t('usage.loading') }}</p>
5
+ <p v-if="usageRecordsError" role="alert">{{ usageRecordsError }}</p>
6
+ <template v-if="usageRecords">
7
+ <p class="usage-list-meta">{{ t('usage.records.coverage', { scanned: usageRecords.summary.scannedSessions, candidates: usageRecords.summary.candidateSessions, unreported: usageRecords.summary.unreportedSessions, unsupported: usageRecords.summary.unsupportedSessions }) }}</p>
8
+ <p v-if="usageRecords.summary.failedSessions.length" role="alert">{{ t('usage.records.failed', { count: usageRecords.summary.failedSessions.length }) }}</p>
9
+ <div class="usage-kpi-grid">
10
+ <div class="usage-kpi-card"><div class="usage-kpi-label">{{ t('usage.records.total') }}</div><div class="usage-kpi-value">{{ formatUsageRecordCount(usageRecords.summary.totalTokens) }}</div></div>
11
+ <div class="usage-kpi-card"><div class="usage-kpi-label">{{ t('usage.records.estimated') }}</div><div class="usage-kpi-value">{{ formatUsageRecordCount(usageRecords.summary.estimatedTextTokens) }}</div></div>
12
+ <div class="usage-kpi-card"><div class="usage-kpi-label">{{ t('usage.records.cacheRead') }}</div><div class="usage-kpi-value">{{ formatUsageRecordCount(usageRecords.summary.cachedInputTokens) }}</div></div>
13
+ <div class="usage-kpi-card"><div class="usage-kpi-label">{{ t('usage.records.cacheWrite') }}</div><div class="usage-kpi-value">{{ formatUsageRecordCount(usageRecords.summary.cacheCreationInputTokens) }}</div></div>
14
+ </div>
15
+ <p v-if="usageRecords.summary.undatedTokens" class="usage-list-meta">{{ t('usage.records.undated', { tokens: usageRecords.summary.undatedTokens }) }}</p>
16
+ <div class="usage-records-table">
17
+ <table>
18
+ <thead><tr><th>{{ t('usage.records.date') }}</th><th>{{ t('usage.records.source') }}</th><th>{{ t('usage.records.model') }}</th><th>{{ t('usage.records.input') }}</th><th>{{ t('usage.records.cacheRead') }}</th><th>{{ t('usage.records.cacheWrite') }}</th><th>{{ t('usage.records.output') }}</th><th>{{ t('usage.records.total') }}</th></tr></thead>
19
+ <tbody><tr v-for="row in usageRecords.rows" :key="row.date + ':' + row.source + ':' + row.model"><td>{{ row.date || t('usage.records.unknown') }}</td><td>{{ row.source }}</td><td>{{ row.model }}</td><td>{{ formatUsageRecordCount(row.inputTokens) }}</td><td>{{ formatUsageRecordCount(row.cachedInputTokens) }}</td><td>{{ formatUsageRecordCount(row.cacheCreationInputTokens) }}</td><td>{{ formatUsageRecordCount(row.outputTokens) }}</td><td>{{ formatUsageRecordCount(row.totalTokens) }}</td></tr></tbody>
20
+ </table>
21
+ </div>
22
+ <p v-if="!usageRecords.rows.length">{{ t('usage.empty') }}</p>
23
+ </template>
24
+ <button v-if="!usageRecordsLoading" type="button" class="btn-mini" @click="loadUsageRecords({ forceRefresh: true })">{{ t('usage.refresh') }}</button>
25
+ </details>
26
+
27
+ <details class="usage-card usage-pricing" id="usage-price-reference" @toggle="toggleUsagePricing($event)">
28
+ <summary>{{ t('pricing.title') }}</summary>
29
+ <p class="usage-list-meta">{{ t('pricing.scope') }}</p>
30
+ <p v-if="usagePricingBusy" role="status">{{ t('usage.loading') }}</p>
31
+ <p v-if="usagePricingError" role="alert">{{ usagePricingError }}</p>
32
+ <template v-if="usagePricing">
33
+ <p class="usage-price-total">{{ t('pricing.total') }}: {{ formatPriceUsd(usagePricing.summary.estimatedUsd) }}</p>
34
+ <p class="usage-list-meta">{{ t('pricing.coverage', { known: usagePricing.summary.pricedRows, unknown: usagePricing.summary.unknownRows, failed: usagePricing.summary.failedSessions, unreported: usagePricing.summary.unreportedSessions, unsupported: usagePricing.summary.unsupportedSessions }) }} · {{ t('pricing.subtotal') }}: {{ formatPriceUsd(usagePricing.summary.knownSubtotalUsd) }}</p>
35
+ <p class="usage-list-meta"><a :href="usagePricing.priceSource.repository" target="_blank" rel="noopener noreferrer">Wei-Shaw/model-price-repo</a> · {{ usagePricing.priceSource.sourceUpdatedAt }} · <code>{{ usagePricing.priceSource.commit.slice(0, 12) }}</code></p>
36
+ <div class="usage-records-table"><table><thead><tr><th>{{ t('usage.records.date') }}</th><th>{{ t('usage.records.source') }}</th><th>{{ t('usage.records.model') }}</th><th>{{ t('pricing.total') }}</th><th>{{ t('pricing.basis') }}</th></tr></thead><tbody><tr v-for="row in usagePricing.rows" :key="row.date + ':' + row.source + ':' + row.model"><td>{{ row.date || t('usage.records.unknown') }}</td><td>{{ row.source }}</td><td>{{ row.model }}</td><td>{{ formatPriceUsd(row.estimatedUsd) }}</td><td>{{ t('pricing.reason.' + row.reason) }}<span v-if="row.rates" class="usage-price-rates">{{ t('pricing.rates', { input: formatTokenRate(row.rates.input_cost_per_token), output: formatTokenRate(row.rates.output_cost_per_token), cached: formatTokenRate(row.rates.cache_read_input_token_cost), created: formatTokenRate(row.rates.cache_creation_input_token_cost) }) }}</span></td></tr></tbody></table></div>
37
+ <p v-if="!usagePricing.rows.length">{{ t('usage.empty') }}</p>
38
+ <button type="button" class="btn-mini" @click="downloadUsagePricing">{{ t('pricing.download') }}</button>
39
+ </template>
40
+ <button type="button" class="btn-mini" @click="loadUsagePricing" :disabled="usagePricingBusy">{{ t('usage.refresh') }}</button>
41
+ </details>