agy-bar 1.0.0 → 1.1.0
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.
- package/CHANGELOG.md +27 -0
- package/README.md +149 -55
- package/README.zh-CN.md +145 -51
- package/bin/agy-bar.mjs +625 -9
- package/llms.txt +47 -0
- package/package.json +3 -2
- package/skills/agy-bar/SKILL.md +11 -4
- package/src/account-import.mjs +435 -0
- package/src/account-quota.mjs +466 -0
- package/src/account-store.mjs +1140 -0
- package/src/agent-state.mjs +2 -1
- package/src/ansi.mjs +7 -0
- package/src/config.mjs +24 -0
- package/src/fs-atomic.mjs +16 -5
- package/src/handoff.mjs +424 -0
- package/src/installer.mjs +16 -0
- package/src/keyring.mjs +604 -0
- package/src/proxy.mjs +189 -48
- package/src/quota-sync.mjs +100 -20
- package/src/render.mjs +11 -3
- package/src/statusline.mjs +83 -12
- package/src/step-timing.mjs +129 -3
- package/src/telemetry.mjs +17 -3
- package/src/title.mjs +50 -8
package/src/statusline.mjs
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { realpathSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { computeSwapHint } from './account-quota.mjs';
|
|
5
|
+
import { readActiveAccountState } from './account-store.mjs';
|
|
4
6
|
import { classifyAgentActivity, extractNativeCostUsd } from './agent-state.mjs';
|
|
7
|
+
import { sanitizeText } from './ansi.mjs';
|
|
5
8
|
import { loadConfig } from './config.mjs';
|
|
6
9
|
import { readGitInfo } from './git.mjs';
|
|
7
10
|
import { getOrRefreshUsageSummary } from './history-scan.mjs';
|
|
8
11
|
import { maybeTriggerBackgroundPricingSync } from './pricing-sync.mjs';
|
|
9
12
|
import { extractAccountKey, syncSharedQuota } from './quota-sync.mjs';
|
|
10
13
|
import { renderFallback, renderStatusline } from './render.mjs';
|
|
11
|
-
import { readLatestStepTiming } from './step-timing.mjs';
|
|
14
|
+
import { readConversationSummaryTitle, readLatestStepTiming } from './step-timing.mjs';
|
|
12
15
|
import { syncTabTitle } from './tab-title.mjs';
|
|
13
16
|
import { deriveSessionId, maybeCaptureRedactedPayload, peekSessionState, recordTelemetry, resolveSessionTitles } from './telemetry.mjs';
|
|
14
17
|
import { isNativeTitleActive } from './title.mjs';
|
|
@@ -29,8 +32,12 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
|
|
|
29
32
|
const payload = JSON.parse(raw);
|
|
30
33
|
const now = Date.now();
|
|
31
34
|
maybeCaptureRedactedPayload(payload);
|
|
35
|
+
const activeAccountState = readActiveAccountState();
|
|
32
36
|
const syncedQuota = payload?.quota
|
|
33
|
-
? syncSharedQuota(payload.quota, {
|
|
37
|
+
? syncSharedQuota(payload.quota, {
|
|
38
|
+
now,
|
|
39
|
+
accountKey: extractAccountKey(payload, { fallbackAccountKey: activeAccountState?.activeQuotaKey ?? null }),
|
|
40
|
+
})
|
|
34
41
|
: null;
|
|
35
42
|
const effectivePayload = syncedQuota && syncedQuota !== payload.quota ? { ...payload, quota: syncedQuota } : payload;
|
|
36
43
|
const prevSession = peekSessionState(effectivePayload);
|
|
@@ -57,14 +64,35 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
|
|
|
57
64
|
})
|
|
58
65
|
: null;
|
|
59
66
|
|
|
67
|
+
const hasPayloadTitle = Boolean(sanitizeText(effectivePayload?.conversation_title || ''));
|
|
68
|
+
const summaryTitle =
|
|
69
|
+
config.tabTitle && !hasPayloadTitle && config.tabTitleSource !== 'dir' && config.dbTiming !== false
|
|
70
|
+
? readConversationSummaryTitle(effectivePayload, {
|
|
71
|
+
prevDbStamp: prevSession?.summaryDbStamp ?? null,
|
|
72
|
+
prevTitle: prevSession?.conversationTitle ?? null,
|
|
73
|
+
prevCheckedAt: prevSession?.summaryTitleCheckedAt ?? null,
|
|
74
|
+
now,
|
|
75
|
+
recheckIntervalMs: 15_000,
|
|
76
|
+
})
|
|
77
|
+
: null;
|
|
78
|
+
const { conversationTitle, customTitle } = resolveSessionTitles(effectivePayload, prevSession, {
|
|
79
|
+
dbTitle: summaryTitle?.title ?? null,
|
|
80
|
+
});
|
|
81
|
+
const payloadForTitle =
|
|
82
|
+
conversationTitle && !hasPayloadTitle
|
|
83
|
+
? { ...effectivePayload, conversation_title: conversationTitle }
|
|
84
|
+
: effectivePayload;
|
|
85
|
+
|
|
60
86
|
// Sync terminal tab title synchronously before async DB scans when AGY's native
|
|
61
|
-
// `settings.json.title` hook is not already driving this session's title
|
|
87
|
+
// `settings.json.title` hook is not already driving this session's title, OR as a
|
|
88
|
+
// one-shot push the moment a brand-new conversation's initial summary title lands.
|
|
62
89
|
let tabSync = null;
|
|
90
|
+
const sessionIdForTitle = deriveSessionId(effectivePayload);
|
|
91
|
+
const nativeActive = !plain && config.tabTitle ? isNativeTitleActive(sessionIdForTitle, { now, hostPid: process.ppid }) : false;
|
|
63
92
|
if (!plain && config.tabTitle) {
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
66
|
-
|
|
67
|
-
tabSync = syncTabTitle(effectivePayload, {
|
|
93
|
+
const newlyDiscoveredDbTitle = Boolean(!hasPayloadTitle && !prevSession?.conversationTitle && conversationTitle && !customTitle);
|
|
94
|
+
if (!nativeActive || newlyDiscoveredDbTitle) {
|
|
95
|
+
tabSync = syncTabTitle(payloadForTitle, {
|
|
68
96
|
config,
|
|
69
97
|
git,
|
|
70
98
|
customTitle,
|
|
@@ -72,25 +100,58 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
|
|
|
72
100
|
prevTabHostPid: prevSession?.lastTabHostPid ?? null,
|
|
73
101
|
prevTabTty: prevSession?.lastTabTty || null,
|
|
74
102
|
hostPidHint: process.ppid,
|
|
103
|
+
force: nativeActive && newlyDiscoveredDbTitle,
|
|
75
104
|
resolveOpts: { env },
|
|
76
105
|
});
|
|
77
106
|
}
|
|
78
107
|
}
|
|
79
108
|
|
|
80
109
|
const stepTiming = config.dbTiming
|
|
81
|
-
? await readLatestStepTiming(effectivePayload, {
|
|
110
|
+
? await readLatestStepTiming(effectivePayload, {
|
|
111
|
+
prevDbStamp: prevSession?.dbStamp ?? null,
|
|
112
|
+
prevWaitingForInput: Boolean(prevSession?.dbWaitingForInput),
|
|
113
|
+
})
|
|
82
114
|
: null;
|
|
83
|
-
|
|
115
|
+
|
|
116
|
+
// During ask_question prompts, AGY keeps agent_state="working" while steps.status=9 in local DB.
|
|
117
|
+
// Promote waiting_for_input on the live payload and push a one-shot tab update on transitions.
|
|
118
|
+
const dbWaitingNow = Boolean(stepTiming?.waitingForInput);
|
|
119
|
+
const dbWaitingPrev = Boolean(prevSession?.dbWaitingForInput);
|
|
120
|
+
const livePayload =
|
|
121
|
+
dbWaitingNow && effectivePayload.waiting_for_input !== true
|
|
122
|
+
? { ...effectivePayload, waiting_for_input: true }
|
|
123
|
+
: effectivePayload;
|
|
124
|
+
|
|
125
|
+
if (!plain && config.tabTitle && dbWaitingNow !== dbWaitingPrev) {
|
|
126
|
+
const liveTitlePayload =
|
|
127
|
+
conversationTitle && !hasPayloadTitle
|
|
128
|
+
? { ...livePayload, conversation_title: conversationTitle }
|
|
129
|
+
: livePayload;
|
|
130
|
+
tabSync = syncTabTitle(liveTitlePayload, {
|
|
131
|
+
config,
|
|
132
|
+
git,
|
|
133
|
+
customTitle,
|
|
134
|
+
prevTabTitle: tabSync?.title || prevSession?.lastTabTitle || null,
|
|
135
|
+
prevTabHostPid: tabSync?.hostPid ?? prevSession?.lastTabHostPid ?? null,
|
|
136
|
+
prevTabTty: (tabSync?.tty && tabSync.tty !== 'custom' ? tabSync.tty : null) || prevSession?.lastTabTty || null,
|
|
137
|
+
hostPidHint: process.ppid,
|
|
138
|
+
force: nativeActive,
|
|
139
|
+
resolveOpts: { env },
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const telemetry = recordTelemetry(livePayload, {
|
|
84
144
|
now,
|
|
85
145
|
git,
|
|
86
146
|
stepTiming,
|
|
147
|
+
summaryTitle,
|
|
87
148
|
prevSession,
|
|
88
149
|
tabSync,
|
|
89
150
|
cacheTtlSec: config.cacheTtlSec,
|
|
90
151
|
enableLedger: config.ledger,
|
|
91
152
|
});
|
|
92
153
|
|
|
93
|
-
const activity = classifyAgentActivity(
|
|
154
|
+
const activity = classifyAgentActivity(livePayload);
|
|
94
155
|
let usageSummary = null;
|
|
95
156
|
if (
|
|
96
157
|
config.show.todayTokens ||
|
|
@@ -110,7 +171,7 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
|
|
|
110
171
|
});
|
|
111
172
|
}
|
|
112
173
|
|
|
113
|
-
const nativeCostUsd = extractNativeCostUsd(
|
|
174
|
+
const nativeCostUsd = extractNativeCostUsd(livePayload);
|
|
114
175
|
const effectiveSessionCostUsd = Math.max(telemetry.sessionCostUsd || 0, usageSummary?.sessionCostUsd || 0, nativeCostUsd || 0);
|
|
115
176
|
const effectiveTelemetry =
|
|
116
177
|
effectiveSessionCostUsd !== telemetry.sessionCostUsd
|
|
@@ -121,13 +182,23 @@ export async function runStatusline({ stdin = process.stdin, stdout = process.st
|
|
|
121
182
|
maybeTriggerBackgroundPricingSync({ enabled: true, now, env });
|
|
122
183
|
}
|
|
123
184
|
|
|
124
|
-
const
|
|
185
|
+
const swapHint =
|
|
186
|
+
config.swapHint !== false && activeAccountState?.activeAccountId
|
|
187
|
+
? computeSwapHint({
|
|
188
|
+
payload: livePayload,
|
|
189
|
+
activeAccountId: activeAccountState.activeAccountId,
|
|
190
|
+
now,
|
|
191
|
+
})
|
|
192
|
+
: null;
|
|
193
|
+
|
|
194
|
+
const rendered = renderStatusline(livePayload, {
|
|
125
195
|
config,
|
|
126
196
|
now,
|
|
127
197
|
color,
|
|
128
198
|
git,
|
|
129
199
|
telemetry: effectiveTelemetry,
|
|
130
200
|
usageSummary,
|
|
201
|
+
swapHint,
|
|
131
202
|
env,
|
|
132
203
|
themeOptions: { env },
|
|
133
204
|
});
|
package/src/step-timing.mjs
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import { existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
4
|
import { join } from 'node:path';
|
|
4
5
|
|
|
5
6
|
const UUID_RE = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
7
|
+
export const STEP_STATUS_WAITING = 9;
|
|
8
|
+
|
|
9
|
+
let cachedDatabaseSync;
|
|
10
|
+
function loadDatabaseSync() {
|
|
11
|
+
if (cachedDatabaseSync !== undefined) return cachedDatabaseSync;
|
|
12
|
+
try {
|
|
13
|
+
const req = createRequire(import.meta.url);
|
|
14
|
+
cachedDatabaseSync = req('node:sqlite').DatabaseSync || null;
|
|
15
|
+
} catch {
|
|
16
|
+
cachedDatabaseSync = null;
|
|
17
|
+
}
|
|
18
|
+
return cachedDatabaseSync;
|
|
19
|
+
}
|
|
6
20
|
|
|
7
21
|
export function decodePbFields(buf) {
|
|
8
22
|
const b = Buffer.isBuffer(buf) ? buf : Buffer.from(buf || []);
|
|
@@ -130,7 +144,10 @@ export function getDbVersionStamp(dbPath) {
|
|
|
130
144
|
}
|
|
131
145
|
}
|
|
132
146
|
|
|
133
|
-
export async function readLatestStepTiming(
|
|
147
|
+
export async function readLatestStepTiming(
|
|
148
|
+
payload,
|
|
149
|
+
{ home = homedir(), prevDbStamp = null, prevWaitingForInput = undefined } = {},
|
|
150
|
+
) {
|
|
134
151
|
const id = payload?.conversation_id || payload?.session_id;
|
|
135
152
|
if (typeof id !== 'string' || !UUID_RE.test(id)) return null;
|
|
136
153
|
|
|
@@ -139,7 +156,9 @@ export async function readLatestStepTiming(payload, { home = homedir(), prevDbSt
|
|
|
139
156
|
|
|
140
157
|
const dbStamp = getDbVersionStamp(dbPath);
|
|
141
158
|
if (prevDbStamp && dbStamp && dbStamp === prevDbStamp) {
|
|
142
|
-
return
|
|
159
|
+
return typeof prevWaitingForInput === 'boolean'
|
|
160
|
+
? { unchanged: true, dbStamp, waitingForInput: prevWaitingForInput }
|
|
161
|
+
: { unchanged: true, dbStamp };
|
|
143
162
|
}
|
|
144
163
|
|
|
145
164
|
let db;
|
|
@@ -149,8 +168,115 @@ export async function readLatestStepTiming(payload, { home = homedir(), prevDbSt
|
|
|
149
168
|
const row = db
|
|
150
169
|
.prepare('SELECT idx, metadata FROM steps WHERE step_type = 15 AND status = 3 ORDER BY idx DESC LIMIT 1')
|
|
151
170
|
.get();
|
|
171
|
+
// Indexed numeric enum lookup (status = 9 -> WAITING for ask_question/user input); zero chat text read.
|
|
172
|
+
const waitingRow = db.prepare(`SELECT 1 AS w FROM steps WHERE status = ${STEP_STATUS_WAITING} LIMIT 1`).get();
|
|
173
|
+
const waitingForInput = Boolean(waitingRow?.w);
|
|
152
174
|
const parsed = row ? parseStepTimingMetadata(row.metadata, row.idx) : null;
|
|
153
|
-
return parsed
|
|
175
|
+
return parsed
|
|
176
|
+
? { ...parsed, dbStamp, waitingForInput }
|
|
177
|
+
: dbStamp
|
|
178
|
+
? { unchanged: false, dbStamp, waitingForInput }
|
|
179
|
+
: null;
|
|
180
|
+
} catch {
|
|
181
|
+
// Gracefully fall back on Node < 22.13, locked DBs, or schema changes.
|
|
182
|
+
return null;
|
|
183
|
+
} finally {
|
|
184
|
+
try {
|
|
185
|
+
db?.close();
|
|
186
|
+
} catch {
|
|
187
|
+
// Ignore close errors.
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Synchronous indexed lookup for native title hook: checks ONLY whether any step in the
|
|
193
|
+
// active conversation currently has numeric status = 9 (WAITING, e.g. ask_question).
|
|
194
|
+
export function readConversationWaitingForInput(
|
|
195
|
+
payload,
|
|
196
|
+
{ home = homedir(), prevDbStamp = null, prevWaitingForInput = false } = {},
|
|
197
|
+
) {
|
|
198
|
+
const id = typeof payload === 'string' ? payload : payload?.conversation_id || payload?.session_id;
|
|
199
|
+
if (typeof id !== 'string' || !UUID_RE.test(id)) return false;
|
|
200
|
+
|
|
201
|
+
const dbPath = join(home, '.gemini', 'antigravity-cli', 'conversations', `${id}.db`);
|
|
202
|
+
if (!existsSync(dbPath)) return false;
|
|
203
|
+
|
|
204
|
+
const dbStamp = getDbVersionStamp(dbPath);
|
|
205
|
+
if (prevDbStamp && dbStamp && dbStamp === prevDbStamp) {
|
|
206
|
+
return Boolean(prevWaitingForInput);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const DatabaseSync = loadDatabaseSync();
|
|
210
|
+
if (!DatabaseSync) return false;
|
|
211
|
+
|
|
212
|
+
let db;
|
|
213
|
+
try {
|
|
214
|
+
db = new DatabaseSync(dbPath, { readOnly: true });
|
|
215
|
+
const waitingRow = db.prepare(`SELECT 1 AS w FROM steps WHERE status = ${STEP_STATUS_WAITING} LIMIT 1`).get();
|
|
216
|
+
return Boolean(waitingRow?.w);
|
|
217
|
+
} catch {
|
|
218
|
+
return false;
|
|
219
|
+
} finally {
|
|
220
|
+
try {
|
|
221
|
+
db?.close();
|
|
222
|
+
} catch {
|
|
223
|
+
// Ignore close errors.
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function summaryDbPath(home = homedir()) {
|
|
229
|
+
return join(home, '.gemini', 'antigravity-cli', 'conversation_summaries.db');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Reads ONLY the generated title column for the active conversation from AGY's local
|
|
233
|
+
// conversation_summaries.db (never reads previews, prompts, or replies) when AGY CLI
|
|
234
|
+
// omits conversation_title from live payloads on brand-new conversations.
|
|
235
|
+
export function readConversationSummaryTitle(
|
|
236
|
+
payload,
|
|
237
|
+
{
|
|
238
|
+
home = homedir(),
|
|
239
|
+
dbPath = null,
|
|
240
|
+
prevDbStamp = null,
|
|
241
|
+
prevTitle = null,
|
|
242
|
+
prevCheckedAt = null,
|
|
243
|
+
now = Date.now(),
|
|
244
|
+
recheckIntervalMs = 15_000,
|
|
245
|
+
} = {},
|
|
246
|
+
) {
|
|
247
|
+
const id = typeof payload === 'string' ? payload : payload?.conversation_id || payload?.session_id;
|
|
248
|
+
if (typeof id !== 'string' || !UUID_RE.test(id)) return null;
|
|
249
|
+
|
|
250
|
+
const targetDb = dbPath || summaryDbPath(home);
|
|
251
|
+
if (!existsSync(targetDb)) return null;
|
|
252
|
+
|
|
253
|
+
const dbStamp = getDbVersionStamp(targetDb);
|
|
254
|
+
if (prevDbStamp && dbStamp && dbStamp === prevDbStamp) {
|
|
255
|
+
return { title: prevTitle || null, unchanged: true, dbStamp, checkedAt: prevCheckedAt ?? now };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Once we already have a title for this session, throttle re-checks while other chats write to the shared WAL.
|
|
259
|
+
if (
|
|
260
|
+
prevTitle &&
|
|
261
|
+
recheckIntervalMs > 0 &&
|
|
262
|
+
typeof prevCheckedAt === 'number' &&
|
|
263
|
+
now >= prevCheckedAt &&
|
|
264
|
+
now - prevCheckedAt < recheckIntervalMs
|
|
265
|
+
) {
|
|
266
|
+
return { title: prevTitle, unchanged: true, dbStamp: prevDbStamp || dbStamp, checkedAt: prevCheckedAt };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const DatabaseSync = loadDatabaseSync();
|
|
270
|
+
if (!DatabaseSync) return null;
|
|
271
|
+
|
|
272
|
+
let db;
|
|
273
|
+
try {
|
|
274
|
+
db = new DatabaseSync(targetDb, { readOnly: true });
|
|
275
|
+
const row = db
|
|
276
|
+
.prepare('SELECT title FROM conversation_summaries WHERE conversation_id = ? LIMIT 1')
|
|
277
|
+
.get(id);
|
|
278
|
+
const raw = typeof row?.title === 'string' ? row.title.trim() : '';
|
|
279
|
+
return { title: raw || null, unchanged: false, dbStamp, checkedAt: now };
|
|
154
280
|
} catch {
|
|
155
281
|
// Gracefully fall back on Node < 22.13, locked DBs, or schema changes.
|
|
156
282
|
return null;
|
package/src/telemetry.mjs
CHANGED
|
@@ -158,8 +158,10 @@ function pickQuotaSnapshot(quota) {
|
|
|
158
158
|
return Object.keys(out).length > 0 ? out : null;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
export function resolveSessionTitles(payload = {}, prev = null) {
|
|
162
|
-
const
|
|
161
|
+
export function resolveSessionTitles(payload = {}, prev = null, { dbTitle = null } = {}) {
|
|
162
|
+
const payloadTitle = sanitizeText(payload?.conversation_title || '') || null;
|
|
163
|
+
const fallbackDbTitle = sanitizeText(dbTitle || '') || null;
|
|
164
|
+
const conversationTitle = payloadTitle || fallbackDbTitle || prev?.conversationTitle || null;
|
|
163
165
|
// If user explicitly renamed the conversation via /rename (conversation_title changed),
|
|
164
166
|
// clear any older custom tab override automatically.
|
|
165
167
|
let customTitle = prev?.customTitle || null;
|
|
@@ -167,6 +169,9 @@ export function resolveSessionTitles(payload = {}, prev = null) {
|
|
|
167
169
|
if (customTitle && conversationTitle && customTitleBase && conversationTitle !== customTitleBase) {
|
|
168
170
|
customTitle = null;
|
|
169
171
|
customTitleBase = null;
|
|
172
|
+
} else if (customTitle && !customTitleBase && !payloadTitle && fallbackDbTitle) {
|
|
173
|
+
// Anchor customTitleBase once AGY's initial background summary lands so a later /rename still supersedes it.
|
|
174
|
+
customTitleBase = fallbackDbTitle;
|
|
170
175
|
}
|
|
171
176
|
return { conversationTitle, customTitle, customTitleBase };
|
|
172
177
|
}
|
|
@@ -177,6 +182,7 @@ export function recordTelemetry(
|
|
|
177
182
|
now = Date.now(),
|
|
178
183
|
git = null,
|
|
179
184
|
stepTiming = null,
|
|
185
|
+
summaryTitle = null,
|
|
180
186
|
prevSession = undefined,
|
|
181
187
|
tabSync = null,
|
|
182
188
|
baseDir = configDir(homedir()),
|
|
@@ -390,7 +396,9 @@ export function recordTelemetry(
|
|
|
390
396
|
const cacheRemainingSec =
|
|
391
397
|
lastActivityAt !== null ? Math.max(0, Math.round((cacheTtlMs - (now - lastActivityAt)) / 1000)) : null;
|
|
392
398
|
|
|
393
|
-
const { conversationTitle, customTitle, customTitleBase } = resolveSessionTitles(p, prev
|
|
399
|
+
const { conversationTitle, customTitle, customTitleBase } = resolveSessionTitles(p, prev, {
|
|
400
|
+
dbTitle: summaryTitle?.title ?? null,
|
|
401
|
+
});
|
|
394
402
|
const tabWritten = Boolean(tabSync?.written && tabSync.title);
|
|
395
403
|
const nextTabTitle = tabWritten ? tabSync.title : prev?.lastTabTitle || null;
|
|
396
404
|
const nextTabHostPid = tabWritten
|
|
@@ -418,6 +426,12 @@ export function recordTelemetry(
|
|
|
418
426
|
gitRemoved: typeof git?.removed === 'number' ? git.removed : prev?.gitRemoved ?? null,
|
|
419
427
|
gitCheckedAt: git?.dirtyChecked ? now : prev?.gitCheckedAt ?? null,
|
|
420
428
|
dbStamp: stepTiming?.dbStamp ?? prev?.dbStamp ?? null,
|
|
429
|
+
dbWaitingForInput:
|
|
430
|
+
typeof stepTiming?.waitingForInput === 'boolean'
|
|
431
|
+
? stepTiming.waitingForInput
|
|
432
|
+
: Boolean(prev?.dbWaitingForInput),
|
|
433
|
+
summaryDbStamp: summaryTitle?.dbStamp ?? prev?.summaryDbStamp ?? null,
|
|
434
|
+
summaryTitleCheckedAt: summaryTitle?.checkedAt ?? prev?.summaryTitleCheckedAt ?? null,
|
|
421
435
|
agentState: sanitizeText(p.agent_state || '') || 'idle',
|
|
422
436
|
activityKind: activity.kind,
|
|
423
437
|
needsAttention: activity.needsAttention,
|
package/src/title.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
5
5
|
import { sanitizeText } from './ansi.mjs';
|
|
6
6
|
import { configDir, loadConfig } from './config.mjs';
|
|
7
7
|
import { readGitInfo } from './git.mjs';
|
|
8
|
+
import { readConversationSummaryTitle, readConversationWaitingForInput } from './step-timing.mjs';
|
|
8
9
|
import { buildTabTitle } from './tab-title.mjs';
|
|
9
10
|
import { deriveSessionId, peekSessionState, resolveSessionTitles, sessionsDir } from './telemetry.mjs';
|
|
10
11
|
|
|
@@ -65,19 +66,41 @@ export function isNativeTitleActive(
|
|
|
65
66
|
|
|
66
67
|
export function renderNativeTitle(
|
|
67
68
|
payload = {},
|
|
68
|
-
{
|
|
69
|
+
{
|
|
70
|
+
config = loadConfig(),
|
|
71
|
+
prevSession = undefined,
|
|
72
|
+
home = homedir(),
|
|
73
|
+
baseDir = configDir(home),
|
|
74
|
+
summaryDbPath = null,
|
|
75
|
+
now = Date.now(),
|
|
76
|
+
hostPid = process.ppid,
|
|
77
|
+
touchMarker = true,
|
|
78
|
+
} = {},
|
|
69
79
|
) {
|
|
70
80
|
if (config.tabTitle === false) return '';
|
|
71
81
|
|
|
72
82
|
const p = payload && typeof payload === 'object' ? payload : {};
|
|
73
83
|
const sessionId = deriveSessionId(p);
|
|
74
84
|
const prev = prevSession !== undefined ? prevSession : peekSessionState(p, { baseDir });
|
|
75
|
-
const
|
|
85
|
+
const hasPayloadTitle = Boolean(sanitizeText(p?.conversation_title || ''));
|
|
86
|
+
const summaryLookup =
|
|
87
|
+
!hasPayloadTitle && config.tabTitleSource !== 'dir' && config.dbTiming !== false
|
|
88
|
+
? readConversationSummaryTitle(p, {
|
|
89
|
+
home,
|
|
90
|
+
dbPath: summaryDbPath,
|
|
91
|
+
prevDbStamp: prev?.summaryDbStamp ?? null,
|
|
92
|
+
prevTitle: prev?.conversationTitle ?? null,
|
|
93
|
+
prevCheckedAt: prev?.summaryTitleCheckedAt ?? null,
|
|
94
|
+
now,
|
|
95
|
+
recheckIntervalMs: 5_000,
|
|
96
|
+
})
|
|
97
|
+
: null;
|
|
98
|
+
const { conversationTitle, customTitle } = resolveSessionTitles(p, prev, {
|
|
99
|
+
dbTitle: summaryLookup?.title ?? null,
|
|
100
|
+
});
|
|
76
101
|
|
|
77
102
|
const cwd = p?.workspace?.current_dir || p?.cwd || prev?.cwd || null;
|
|
78
|
-
const needsGit =
|
|
79
|
-
config.tabTitleSource === 'dir' ||
|
|
80
|
-
(!customTitle && !sanitizeText(p?.conversation_title || ''));
|
|
103
|
+
const needsGit = config.tabTitleSource === 'dir' || (!customTitle && !conversationTitle);
|
|
81
104
|
let git = null;
|
|
82
105
|
if (needsGit && cwd) {
|
|
83
106
|
if (prev && prev.cwd === cwd && prev.branch) {
|
|
@@ -88,7 +111,24 @@ export function renderNativeTitle(
|
|
|
88
111
|
}
|
|
89
112
|
}
|
|
90
113
|
|
|
91
|
-
const
|
|
114
|
+
const rawState = String(p?.agent_state || '').trim().toLowerCase();
|
|
115
|
+
const isBusyState = rawState === 'working' || rawState === 'tool_use' || rawState === 'thinking';
|
|
116
|
+
const waitingForInput =
|
|
117
|
+
p?.waiting_for_input === true ||
|
|
118
|
+
(isBusyState &&
|
|
119
|
+
p?.tool_confirmation_pending !== true &&
|
|
120
|
+
config.dbTiming !== false &&
|
|
121
|
+
readConversationWaitingForInput(p, {
|
|
122
|
+
home,
|
|
123
|
+
prevDbStamp: prev?.dbStamp ?? null,
|
|
124
|
+
prevWaitingForInput: Boolean(prev?.dbWaitingForInput),
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
let effectivePayload = conversationTitle && !hasPayloadTitle ? { ...p, conversation_title: conversationTitle } : p;
|
|
128
|
+
if (waitingForInput && effectivePayload.waiting_for_input !== true) {
|
|
129
|
+
effectivePayload = { ...effectivePayload, waiting_for_input: true };
|
|
130
|
+
}
|
|
131
|
+
const title = buildTabTitle(effectivePayload, { config, git, customTitle });
|
|
92
132
|
if (touchMarker) {
|
|
93
133
|
touchNativeTitleMarker(sessionId, { now, hostPid, baseDir });
|
|
94
134
|
}
|
|
@@ -98,7 +138,9 @@ export function renderNativeTitle(
|
|
|
98
138
|
export async function runTitleCommand({
|
|
99
139
|
stdin = process.stdin,
|
|
100
140
|
stdout = process.stdout,
|
|
101
|
-
|
|
141
|
+
home = homedir(),
|
|
142
|
+
baseDir = configDir(home),
|
|
143
|
+
summaryDbPath = null,
|
|
102
144
|
config = undefined,
|
|
103
145
|
now = Date.now(),
|
|
104
146
|
hostPid = process.ppid,
|
|
@@ -111,7 +153,7 @@ export async function runTitleCommand({
|
|
|
111
153
|
try {
|
|
112
154
|
const payload = raw.trim() ? JSON.parse(raw) : {};
|
|
113
155
|
const cfg = config ?? loadConfig();
|
|
114
|
-
const title = renderNativeTitle(payload, { config: cfg, baseDir, now, hostPid });
|
|
156
|
+
const title = renderNativeTitle(payload, { config: cfg, home, baseDir, summaryDbPath, now, hostPid });
|
|
115
157
|
if (title) {
|
|
116
158
|
stdout.write(`${title}\n`);
|
|
117
159
|
}
|