agent-things 0.0.0-stage → 1.2.1
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/LICENSE +21 -0
- package/NOTICE +5 -0
- package/README.md +221 -2
- package/README.zh-CN.md +222 -0
- package/bin/agent-things.cjs +8 -0
- package/bin/antigravity-session-status.cjs +96 -0
- package/bin/claude-session-status.cjs +55 -0
- package/bin/codex-session-status.cjs +287 -0
- package/mods/agent-things-ui/.claude-plugin/plugin.json +12 -0
- package/mods/agent-things-ui/SKILL.md +10 -0
- package/mods/agent-things-ui/hooks/controls.js +112 -0
- package/mods/agent-things-ui/hooks/foundation.js +431 -0
- package/mods/agent-things-ui/hooks/hooks.json +1 -0
- package/mods/agent-things-ui/hooks/presentation.js +223 -0
- package/mods/agent-things-ui/hooks/progress.js +1 -0
- package/mods/agent-things-ui/hooks/register.js +382 -0
- package/native/bin/bridge +0 -0
- package/native/bin/bridge.json +20 -0
- package/native/session-status-bridge.swift +280 -0
- package/outputs/antigravity-session-status.js +2476 -0
- package/outputs/codex-session-status.js +1761 -0
- package/package.json +75 -4
- package/scripts/build-antigravity-bundle.cjs +35 -0
- package/scripts/build-codex-bundle.cjs +31 -0
- package/scripts/build-native-bridge.cjs +55 -0
- package/scripts/build-shared-ui.cjs +16 -0
- package/scripts/setup-antigravity-service.cjs +71 -0
- package/scripts/setup-claude-service.cjs +21 -0
- package/skills/agent-things/SKILL.en.md +95 -0
- package/skills/agent-things/SKILL.md +99 -0
- package/skills/codex/things/SKILL.en.md +10 -0
- package/skills/codex/things/SKILL.md +10 -0
- package/skills/things/SKILL.en.md +10 -0
- package/skills/things/SKILL.md +10 -0
- package/skills/things/checklist.en.md +91 -0
- package/skills/things/checklist.md +95 -0
- package/src/analysis-app-server.cjs +74 -0
- package/src/analysis-assets/output.en.schema.json +93 -0
- package/src/analysis-assets/output.schema.json +93 -0
- package/src/analysis-assets/prompt.en.txt +17 -0
- package/src/analysis-assets/prompt.zh-CN.txt +18 -0
- package/src/analysis-budget.cjs +105 -0
- package/src/analysis-git.cjs +38 -0
- package/src/analysis-history.cjs +150 -0
- package/src/analysis-ledger.cjs +82 -0
- package/src/analysis-log.cjs +62 -0
- package/src/analysis-runner.cjs +203 -0
- package/src/analysis-service.cjs +197 -0
- package/src/analysis-source.cjs +72 -0
- package/src/antigravity-card.cjs +2063 -0
- package/src/antigravity-hook.cjs +138 -0
- package/src/antigravity-mcp-config.cjs +36 -0
- package/src/app-server.cjs +96 -0
- package/src/cdp.cjs +115 -0
- package/src/claude-inline-install.cjs +38 -0
- package/src/claude-mcp-config.cjs +29 -0
- package/src/cli/arguments.cjs +30 -0
- package/src/cli/environment-probe.cjs +130 -0
- package/src/cli/integration-state.cjs +15 -0
- package/src/cli/interactive-cli.cjs +236 -0
- package/src/cli/prompt-tui.cjs +420 -0
- package/src/cli/setup-orchestrator.cjs +449 -0
- package/src/codex-mcp-config.cjs +67 -0
- package/src/harnesses/antigravity/analysis-profile.cjs +41 -0
- package/src/harnesses/antigravity/antigravity-git.cjs +89 -0
- package/src/harnesses/antigravity/antigravity-harness.js +1477 -0
- package/src/harnesses/antigravity/antigravity-injector.cjs +104 -0
- package/src/harnesses/antigravity/antigravity-migration.cjs +235 -0
- package/src/harnesses/antigravity/antigravity-service.cjs +357 -0
- package/src/harnesses/antigravity/antigravity-title.cjs +155 -0
- package/src/harnesses/antigravity/gemini-runner.cjs +304 -0
- package/src/harnesses/antigravity/transcript-cleaner.cjs +129 -0
- package/src/harnesses/antigravity/transcript-source.cjs +100 -0
- package/src/harnesses/claude/claude-harness.js +93 -0
- package/src/harnesses/claude/claude-host-helper.cjs +176 -0
- package/src/harnesses/claude/claude-injector.cjs +95 -0
- package/src/harnesses/claude/claude-local-source.cjs +106 -0
- package/src/harnesses/claude/claude-navigation.cjs +99 -0
- package/src/harnesses/claude/claude-runner.cjs +74 -0
- package/src/harnesses/claude/claude-service.cjs +313 -0
- package/src/harnesses/claude/claude-source.cjs +70 -0
- package/src/harnesses/codex/codex-analysis.cjs +10 -0
- package/src/harnesses/codex/codex-card-bridge.js +123 -0
- package/src/harnesses/codex/codex-card-events.cjs +76 -0
- package/src/harnesses/codex/codex-card.cjs +169 -0
- package/src/harnesses/codex/codex-git.cjs +24 -0
- package/src/harnesses/codex/codex-harness.js +229 -0
- package/src/harnesses/codex/codex-local-card.js +97 -0
- package/src/harnesses/codex/codex-progress-context.cjs +84 -0
- package/src/harnesses/codex/codex-service.cjs +502 -0
- package/src/i18n.cjs +174 -0
- package/src/launchd.cjs +105 -0
- package/src/lifecycle-lock.cjs +13 -0
- package/src/local-progress-http.cjs +267 -0
- package/src/manual-status-agent.cjs +12 -0
- package/src/manual-status-startup.cjs +66 -0
- package/src/manual-status-store.cjs +466 -0
- package/src/mcp-stdio.cjs +67 -0
- package/src/model-router.cjs +63 -0
- package/src/native-bridge.cjs +17 -0
- package/src/npm-updates.cjs +228 -0
- package/src/plugins/things/assets/logo.svg +13 -0
- package/src/plugins/things/plugin.json +6 -0
- package/src/plugins/things/sidecars/things_board/app.js +447 -0
- package/src/plugins/things/sidecars/things_board/index.html +2141 -0
- package/src/plugins/things/sidecars/things_board/main.mjs +652 -0
- package/src/plugins/things/sidecars/things_board/package.json +6 -0
- package/src/plugins/things/sidecars/things_board/sidecar.json +21 -0
- package/src/plugins/things/sidecars/things_board/styles.css +560 -0
- package/src/plugins/things/sidecars/things_board/ui-i18n.mjs +434 -0
- package/src/progress-error.cjs +54 -0
- package/src/progress-tools.cjs +145 -0
- package/src/project-path.cjs +15 -0
- package/src/renderer-resource.cjs +17 -0
- package/src/request-budget.cjs +24 -0
- package/src/resolve.cjs +51 -0
- package/src/runtime-install.cjs +635 -0
- package/src/session-status-filter.cjs +136 -0
- package/src/session-status.js +992 -0
- package/src/session-view.cjs +34 -0
- package/src/startup/controller.cjs +354 -0
- package/src/startup/watch.cjs +126 -0
- package/src/state-file-lock.cjs +31 -0
- package/src/task-provenance.cjs +42 -0
- package/src/ui-foundation.cjs +435 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { startProgressHttp } = require('../../local-progress-http.cjs');
|
|
3
|
+
const { callProgressTool } = require('../../progress-tools.cjs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const { ManualStatusStore } = require('../../manual-status-store.cjs');
|
|
7
|
+
const { AnalysisService } = require('../../analysis-service.cjs');
|
|
8
|
+
const { createAnalysisLog, diagnosticFields } = require('../../analysis-log.cjs');
|
|
9
|
+
const { AntigravityTranscriptServer } = require('./transcript-source.cjs');
|
|
10
|
+
const { runGeminiAnalysis } = require('./gemini-runner.cjs');
|
|
11
|
+
const { detectAntigravityGit } = require('./antigravity-git.cjs');
|
|
12
|
+
const npmUpdates = require('../../npm-updates.cjs');
|
|
13
|
+
const { executeMigration } = require('./antigravity-migration.cjs');
|
|
14
|
+
const { resolveAntigravityTitle } = require('./antigravity-title.cjs');
|
|
15
|
+
const { readConfiguredLang, getUi } = require('../../i18n.cjs');
|
|
16
|
+
const { getMessage } = require('../../progress-error.cjs');
|
|
17
|
+
|
|
18
|
+
const DEFAULT_PORT = 29888;
|
|
19
|
+
const DEFAULT_STATE_FILE = path.join(os.homedir(), '.gemini', 'antigravity', 'session-status', 'manual-state.json');
|
|
20
|
+
|
|
21
|
+
class AntigravityService {
|
|
22
|
+
constructor({
|
|
23
|
+
port = DEFAULT_PORT,
|
|
24
|
+
stateFile = DEFAULT_STATE_FILE,
|
|
25
|
+
logFile = path.join(path.dirname(stateFile), 'analysis.jsonl'),
|
|
26
|
+
run = runGeminiAnalysis,
|
|
27
|
+
brainDir = path.join(os.homedir(), '.gemini', 'antigravity', 'brain'),
|
|
28
|
+
dbPath = path.join(os.homedir(), '.gemini', 'antigravity', 'conversation_summaries.db'),
|
|
29
|
+
makeServer = options => new AntigravityTranscriptServer({ brainDir, ...options }),
|
|
30
|
+
apiKey = process.env.GEMINI_API_KEY,
|
|
31
|
+
updates = npmUpdates,
|
|
32
|
+
} = {}) {
|
|
33
|
+
this.port = port;
|
|
34
|
+
this.stateFile = stateFile;
|
|
35
|
+
this.brainDir = brainDir;
|
|
36
|
+
this.dbPath = dbPath;
|
|
37
|
+
this.store = new ManualStatusStore(stateFile);
|
|
38
|
+
this.logFile = logFile;
|
|
39
|
+
this.log = createAnalysisLog(logFile);
|
|
40
|
+
this.run = (options) => run({ apiKey, ...options });
|
|
41
|
+
this.makeServer = makeServer;
|
|
42
|
+
this.server = null;
|
|
43
|
+
this.updates = updates;
|
|
44
|
+
this.analysisService = new AnalysisService({
|
|
45
|
+
store: this.store,
|
|
46
|
+
logFile: this.logFile,
|
|
47
|
+
makeServer: this.makeServer,
|
|
48
|
+
run: this.run,
|
|
49
|
+
onChange: (changedKey, statusInfo) => {
|
|
50
|
+
this.log('service.store.change', { revision: this.store.snapshot()?.revision, changedKey, status: statusInfo?.status });
|
|
51
|
+
this.broadcastState(changedKey, statusInfo);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
currentLang() {
|
|
57
|
+
if (typeof this.store?.lang === 'function') return this.store.lang();
|
|
58
|
+
return readConfiguredLang({ dataDir: this.stateFile ? path.dirname(this.stateFile) : undefined });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
canonicalKey(convIdOrKey) {
|
|
62
|
+
if (!convIdOrKey) return convIdOrKey;
|
|
63
|
+
try {
|
|
64
|
+
const parsed = JSON.parse(convIdOrKey);
|
|
65
|
+
if (Array.isArray(parsed) && parsed.length === 2 && parsed[0] === 'local') {
|
|
66
|
+
const cleanId = String(parsed[1]).replace(/^local:/, '');
|
|
67
|
+
return JSON.stringify(['local', cleanId]);
|
|
68
|
+
}
|
|
69
|
+
} catch (_) {}
|
|
70
|
+
const clean = String(convIdOrKey).trim().replace(/^local:/, '');
|
|
71
|
+
return JSON.stringify(['local', clean]);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getSessionSnapshot(cleanId, transientStatus = null) {
|
|
75
|
+
const key = this.canonicalKey(cleanId);
|
|
76
|
+
const progress = this.store.getProgress(key);
|
|
77
|
+
const analysis = this.store.analysisState(key);
|
|
78
|
+
const record = this.store.snapshot()?.records?.[key];
|
|
79
|
+
const analyzing = this.store.snapshot()?.analyzingKeys?.includes(key) || false;
|
|
80
|
+
|
|
81
|
+
let analysisStatus = transientStatus;
|
|
82
|
+
if (!analysisStatus) {
|
|
83
|
+
if (analyzing) {
|
|
84
|
+
analysisStatus = { status: 'pending', stage: 'analyzing' };
|
|
85
|
+
} else {
|
|
86
|
+
const lastEvent = (this.store.data.timeline || [])
|
|
87
|
+
.filter(e => e.key === key && e.source === 'analysis')
|
|
88
|
+
.slice(-1)[0];
|
|
89
|
+
if (lastEvent) {
|
|
90
|
+
analysisStatus = {
|
|
91
|
+
status: lastEvent.status,
|
|
92
|
+
stage: lastEvent.stage,
|
|
93
|
+
error: lastEvent.error || null,
|
|
94
|
+
finishedAt: lastEvent.finishedAt || null,
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
analysisStatus = { status: 'idle' };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const lang = this.currentLang();
|
|
103
|
+
return {
|
|
104
|
+
key,
|
|
105
|
+
conversationId: cleanId,
|
|
106
|
+
lang,
|
|
107
|
+
title: resolveAntigravityTitle(cleanId, { dbPath: this.dbPath, brainDir: this.brainDir, fallback: getUi(lang).t('defaultSessionTitle') }),
|
|
108
|
+
progress,
|
|
109
|
+
recordRevision: record?.revision ?? 0,
|
|
110
|
+
savedAnalysis: analysis?.analysis || null,
|
|
111
|
+
analysis: analysis?.analysis || null,
|
|
112
|
+
analysisStatus,
|
|
113
|
+
analyzing: Boolean(analyzing || analysisStatus?.status === 'pending'),
|
|
114
|
+
revision: this.store.snapshot()?.revision || 0,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
broadcastState(key, transientStatus = null) {
|
|
119
|
+
if (!this.http) return;
|
|
120
|
+
if (key) {
|
|
121
|
+
try {
|
|
122
|
+
const [, id] = JSON.parse(this.canonicalKey(key));
|
|
123
|
+
const cleanId = String(id).replace(/^local:/, '');
|
|
124
|
+
this.http.broadcast(cleanId, {
|
|
125
|
+
type: 'session_update',
|
|
126
|
+
session: this.getSessionSnapshot(cleanId, transientStatus),
|
|
127
|
+
snapshotRevision: this.store.snapshot()?.revision,
|
|
128
|
+
});
|
|
129
|
+
} catch (_) {}
|
|
130
|
+
} else {
|
|
131
|
+
const targetKeys = new Set(Object.keys(this.store.snapshot()?.records || {}));
|
|
132
|
+
for (const k of this.store.snapshot()?.analyzingKeys || []) targetKeys.add(k);
|
|
133
|
+
for (const recordKey of targetKeys) {
|
|
134
|
+
try {
|
|
135
|
+
const [, id] = JSON.parse(this.canonicalKey(recordKey));
|
|
136
|
+
const cleanId = String(id).replace(/^local:/, '');
|
|
137
|
+
this.http.broadcast(cleanId, {
|
|
138
|
+
type: 'session_update',
|
|
139
|
+
session: this.getSessionSnapshot(cleanId),
|
|
140
|
+
snapshotRevision: this.store.snapshot()?.revision,
|
|
141
|
+
});
|
|
142
|
+
} catch (_) {}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async handleRpc(message) {
|
|
148
|
+
const lang = this.currentLang();
|
|
149
|
+
const en = lang === 'en';
|
|
150
|
+
if (!message || typeof message.requestId !== 'string') throw new Error(en ? 'Invalid request' : '无效的请求');
|
|
151
|
+
if (message.key) message.key = this.canonicalKey(message.key);
|
|
152
|
+
let identity;
|
|
153
|
+
try { identity = JSON.parse(message.key); } catch { identity = []; }
|
|
154
|
+
const context = {
|
|
155
|
+
requestId: message.requestId,
|
|
156
|
+
requestType: message.type,
|
|
157
|
+
hostId: identity?.[0],
|
|
158
|
+
threadId: typeof identity?.[1] === 'string' ? identity[1].replace(/^local:/, '') : undefined,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
if (message.type === 'panel-event') {
|
|
162
|
+
if (this.store.validKey(message.key) && ['open', 'close', 'dispose'].includes(message.action)) {
|
|
163
|
+
this.log(`panel.${message.action}`, context);
|
|
164
|
+
}
|
|
165
|
+
return { ok: true };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.log('ui.request', context);
|
|
169
|
+
let error = null, analysisState = null, projectGit = null, updateInfo = null;
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
if (message.type === 'app-update-info') {
|
|
173
|
+
updateInfo = await this.updates.getUpdateInfo({ force: message.force === true });
|
|
174
|
+
} else if (message.type === 'app-update-start') {
|
|
175
|
+
await this.updates.startUpdate();
|
|
176
|
+
updateInfo = await this.updates.getUpdateInfo();
|
|
177
|
+
} else if (message.type === 'update') {
|
|
178
|
+
if (message.record?.state === 'pushed' && !(await this.projectGit(message.key)).hasRemote) {
|
|
179
|
+
throw new Error(en ? 'No Git remote configured for this project' : '此项目尚未配置 Git 远端');
|
|
180
|
+
}
|
|
181
|
+
this.store.update(message);
|
|
182
|
+
this.broadcastState(message.key);
|
|
183
|
+
} else if (message.type === 'clear') {
|
|
184
|
+
this.store.update({ key: message.key, expectedRevision: message.expectedRevision, record: null });
|
|
185
|
+
this.broadcastState(message.key);
|
|
186
|
+
} else if (message.type === 'project-git') {
|
|
187
|
+
const threadId = context.threadId;
|
|
188
|
+
projectGit = threadId ? await detectAntigravityGit(threadId, { brainDir: this.brainDir, dbPath: this.dbPath }) : { status: 'checked', hasRepository: false, hasRemote: false };
|
|
189
|
+
} else if (message.type === 'analysis-state') {
|
|
190
|
+
if (!this.store.validKey(message.key)) throw new Error(getMessage('INVALID_ARGUMENT', lang));
|
|
191
|
+
analysisState = this.store.analysisState(message.key);
|
|
192
|
+
} else if (message.type === 'analyze') {
|
|
193
|
+
const { promise, runId, actionSequence } = this.analysisService.start(message.key, { requestId: message.requestId });
|
|
194
|
+
Object.assign(context, { runId, actionSequence });
|
|
195
|
+
promise.catch(err => this.log('analysis.error', { ...context, ...diagnosticFields(err) }));
|
|
196
|
+
analysisState = this.store.analysisState(message.key);
|
|
197
|
+
this.broadcastState(message.key);
|
|
198
|
+
} else {
|
|
199
|
+
throw new Error(en ? `Unknown action: ${message.type}` : `未知操作:${message.type}`);
|
|
200
|
+
}
|
|
201
|
+
} catch (e) {
|
|
202
|
+
error = e.message;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const reply = {
|
|
206
|
+
requestId: message.requestId,
|
|
207
|
+
error,
|
|
208
|
+
lang,
|
|
209
|
+
snapshot: { ...this.store.snapshot(), lang },
|
|
210
|
+
analysisState,
|
|
211
|
+
projectGit,
|
|
212
|
+
updateInfo,
|
|
213
|
+
};
|
|
214
|
+
this.log('ui.reply', { ...context, ok: !error, ...(error ? diagnosticFields(error) : {}) });
|
|
215
|
+
return reply;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async projectGit(key) {
|
|
219
|
+
const [, id] = JSON.parse(key);
|
|
220
|
+
return detectAntigravityGit(id.replace(/^local:/, ''), { brainDir: this.brainDir, dbPath: this.dbPath });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async start() {
|
|
224
|
+
this.http = await startProgressHttp({ port: this.port, stateFile: this.stateFile,
|
|
225
|
+
handle: async (method, route, body) => {
|
|
226
|
+
const lang = this.currentLang();
|
|
227
|
+
const { t } = getUi(lang);
|
|
228
|
+
if (method === 'GET' && route === '/snapshot') return { snapshot: { ...this.store.snapshot(), lang } };
|
|
229
|
+
if (method === 'GET' && route === '/session/snapshot') {
|
|
230
|
+
const cleanId = (body?.conversationId || '').replace(/^local:/, '');
|
|
231
|
+
return this.getSessionSnapshot(cleanId);
|
|
232
|
+
}
|
|
233
|
+
if (method === 'POST' && route === '/rpc') return this.handleRpc(body);
|
|
234
|
+
if (method === 'POST' && route === '/tools') {
|
|
235
|
+
const rawArgs = body?.args || body?.arguments || {};
|
|
236
|
+
const normalizedArgs = { ...rawArgs };
|
|
237
|
+
let targetCleanId = null;
|
|
238
|
+
if (typeof rawArgs.conversation_id === 'string' && rawArgs.conversation_id.trim()) {
|
|
239
|
+
let id = rawArgs.conversation_id.trim();
|
|
240
|
+
try {
|
|
241
|
+
const parsed = JSON.parse(id);
|
|
242
|
+
if (Array.isArray(parsed) && parsed[0] === 'local') id = String(parsed[1]);
|
|
243
|
+
} catch (_) {}
|
|
244
|
+
targetCleanId = id.replace(/^local:/, '');
|
|
245
|
+
normalizedArgs.conversation_id = JSON.stringify(['local', targetCleanId]);
|
|
246
|
+
}
|
|
247
|
+
if (typeof rawArgs.current_session_id === 'string') {
|
|
248
|
+
normalizedArgs.current_session_id = rawArgs.current_session_id.trim().replace(/^local:/, '');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (body.name === 'render_things_card') {
|
|
252
|
+
const key = this.store.resolveKey(normalizedArgs.conversation_id || targetCleanId);
|
|
253
|
+
const progressData = this.store.getProgress(key);
|
|
254
|
+
const isEmptySession = progressData == null;
|
|
255
|
+
const stateText = isEmptySession
|
|
256
|
+
? t('unrecordedSummary')
|
|
257
|
+
: (progressData?.state === 'completed' || progressData?.progress === 100
|
|
258
|
+
? t('mdStateDone')
|
|
259
|
+
: (progressData?.progress != null ? `${progressData.progress}%` : t('mdStateUnstarted')));
|
|
260
|
+
const total = progressData?.totalTasks || 0;
|
|
261
|
+
const done = progressData?.completedTasks || 0;
|
|
262
|
+
const tasksText = total > 0 ? t('totalsPattern', { done, total }) : t('mdTasksEmpty');
|
|
263
|
+
const mdColon = lang === 'en' ? ': ' : ':';
|
|
264
|
+
const noteText = progressData?.note ? `\n- **${t('mdNotesLabel')}**${mdColon}${progressData.note}` : '';
|
|
265
|
+
const summaryText = isEmptySession ? t('unrecordedSummary') : (progressData?.summary || '');
|
|
266
|
+
|
|
267
|
+
const { generateCardArtifact } = require('../../antigravity-card.cjs');
|
|
268
|
+
const artifactDir = rawArgs.artifact_dir || path.join(os.homedir(), '.gemini/antigravity/brain', targetCleanId || 'default');
|
|
269
|
+
const sessionTitle = resolveAntigravityTitle(targetCleanId, {
|
|
270
|
+
dbPath: this.dbPath,
|
|
271
|
+
brainDir: this.brainDir,
|
|
272
|
+
fallback: t('defaultSessionTitle'),
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
const cardResult = generateCardArtifact({
|
|
276
|
+
conversationId: targetCleanId || 'default',
|
|
277
|
+
brainDir: artifactDir,
|
|
278
|
+
artifactDir,
|
|
279
|
+
record: isEmptySession ? null : {
|
|
280
|
+
state: progressData.state,
|
|
281
|
+
progress: progressData.progress,
|
|
282
|
+
note: progressData.note,
|
|
283
|
+
source: progressData.source,
|
|
284
|
+
updatedAt: progressData.updatedAt,
|
|
285
|
+
},
|
|
286
|
+
tasks: isEmptySession ? [] : (progressData?.tasks || []),
|
|
287
|
+
summary: summaryText,
|
|
288
|
+
revision: progressData?.revision || 0,
|
|
289
|
+
stateFile: this.stateFile,
|
|
290
|
+
connection: this.http?.credentials || null,
|
|
291
|
+
title: sessionTitle,
|
|
292
|
+
lang,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const userMarkdown = `${cardResult.embedTag}\n\n**${t('mdProgressHeading')}${mdColon}${stateText}**\n- **${t('mdTasksOverview')}**${mdColon}${tasksText}${noteText}\n- **${t('mdQuickActionsLabel')}**${mdColon}${t('mdQuickActionsText')}`;
|
|
296
|
+
|
|
297
|
+
const cardPayload = {
|
|
298
|
+
artifact_path: cardResult.path,
|
|
299
|
+
embed_tag: cardResult.embedTag,
|
|
300
|
+
summary: summaryText,
|
|
301
|
+
progress: isEmptySession ? null : progressData?.progress,
|
|
302
|
+
state: isEmptySession ? 'unstarted' : progressData?.state,
|
|
303
|
+
user_markdown: userMarkdown,
|
|
304
|
+
};
|
|
305
|
+
return {
|
|
306
|
+
result: {
|
|
307
|
+
content: [
|
|
308
|
+
{
|
|
309
|
+
type: 'text',
|
|
310
|
+
text: JSON.stringify(cardPayload, null, 2),
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const result = await callProgressTool(this.store, body.name, normalizedArgs, { projectGit: key => this.projectGit(key), resolveProjects: async keys => {
|
|
318
|
+
const projects = {};
|
|
319
|
+
for (const key of keys) { const git = await this.projectGit(key); if (git.projectPath || git.projectKnown) projects[key] = git.projectPath || null; }
|
|
320
|
+
return projects;
|
|
321
|
+
}, resolveSources: async (key, tasks) => {
|
|
322
|
+
const server = this.makeServer();
|
|
323
|
+
try { await server.initialize(); return await require('../../task-provenance.cjs').resolveTaskSources(server.request.bind(server), key, tasks); }
|
|
324
|
+
finally { await server.close(); }
|
|
325
|
+
}, lang });
|
|
326
|
+
this.broadcastState(targetCleanId);
|
|
327
|
+
return { result };
|
|
328
|
+
}
|
|
329
|
+
throw new Error(lang === 'en' ? 'Unknown service route' : '未知服务路径');
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
this.server = this.http.server;
|
|
333
|
+
try {
|
|
334
|
+
const migration = executeMigration(this.stateFile);
|
|
335
|
+
if (migration.migrated) {
|
|
336
|
+
this.store.reloadIfModified(true);
|
|
337
|
+
this.log('service.migration', migration.report);
|
|
338
|
+
}
|
|
339
|
+
this.store.recoverPending();
|
|
340
|
+
}
|
|
341
|
+
catch (error) { await this.http.close(); this.server = null; throw error; }
|
|
342
|
+
this.port = this.http.credentials.port;
|
|
343
|
+
return this.port;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async stop() {
|
|
347
|
+
if (this.analysisService) {
|
|
348
|
+
await this.analysisService.stop?.();
|
|
349
|
+
}
|
|
350
|
+
if (this.server) {
|
|
351
|
+
await this.http.close();
|
|
352
|
+
this.server = null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
module.exports = { AntigravityService, DEFAULT_PORT, DEFAULT_STATE_FILE };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const { execFileSync } = require('node:child_process');
|
|
7
|
+
const { cleanUserRequestText } = require('./transcript-cleaner.cjs');
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DB_PATH = path.join(os.homedir(), '.gemini', 'antigravity', 'conversation_summaries.db');
|
|
10
|
+
const DEFAULT_BRAIN_DIR = path.join(os.homedir(), '.gemini', 'antigravity', 'brain');
|
|
11
|
+
const CACHE_TTL_MS = 5000;
|
|
12
|
+
const MAX_CACHE_ENTRIES = 256;
|
|
13
|
+
const TRANSCRIPT_HEAD_BYTES = 65536;
|
|
14
|
+
|
|
15
|
+
const titleCache = new Map();
|
|
16
|
+
|
|
17
|
+
function cleanConversationId(convIdOrKey) {
|
|
18
|
+
if (typeof convIdOrKey !== 'string') return null;
|
|
19
|
+
let raw = convIdOrKey.trim();
|
|
20
|
+
if (!raw) return null;
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(raw);
|
|
23
|
+
if (Array.isArray(parsed) && parsed.length === 2 && parsed[0] === 'local') {
|
|
24
|
+
raw = String(parsed[1] || '').trim();
|
|
25
|
+
}
|
|
26
|
+
} catch (_) {}
|
|
27
|
+
const cleanId = raw.replace(/^local:/, '').trim();
|
|
28
|
+
if (!cleanId || path.basename(cleanId) !== cleanId || ['.', '..'].includes(cleanId)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return cleanId;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readTitleFromDb(cleanId, dbPath) {
|
|
35
|
+
if (!dbPath || !fs.existsSync(dbPath)) return null;
|
|
36
|
+
try {
|
|
37
|
+
const escapedId = cleanId.replace(/'/g, "''");
|
|
38
|
+
const sql = `SELECT title, preview FROM conversation_summaries WHERE conversation_id = '${escapedId}' LIMIT 1;`;
|
|
39
|
+
const stdout = execFileSync('sqlite3', ['-json', dbPath, sql], {
|
|
40
|
+
encoding: 'utf8',
|
|
41
|
+
timeout: 1000,
|
|
42
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
43
|
+
});
|
|
44
|
+
const rows = JSON.parse(stdout || '[]');
|
|
45
|
+
if (!Array.isArray(rows) || rows.length === 0) return null;
|
|
46
|
+
const candidate = String(rows[0].title || rows[0].preview || '').replace(/\s+/g, ' ').trim();
|
|
47
|
+
return candidate || null;
|
|
48
|
+
} catch (_) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function readHeadUtf8(filePath, maxBytes = TRANSCRIPT_HEAD_BYTES) {
|
|
54
|
+
const fd = fs.openSync(filePath, 'r');
|
|
55
|
+
try {
|
|
56
|
+
const buf = Buffer.allocUnsafe(maxBytes);
|
|
57
|
+
const bytesRead = fs.readSync(fd, buf, 0, maxBytes, 0);
|
|
58
|
+
return buf.toString('utf8', 0, bytesRead);
|
|
59
|
+
} finally {
|
|
60
|
+
fs.closeSync(fd);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function formatSnippetTitle(rawText, maxChars = 48) {
|
|
65
|
+
const singleLine = String(rawText || '').replace(/\s+/g, ' ').trim();
|
|
66
|
+
if (!singleLine) return null;
|
|
67
|
+
const chars = Array.from(singleLine);
|
|
68
|
+
if (chars.length <= maxChars) return singleLine;
|
|
69
|
+
return `${chars.slice(0, maxChars).join('')}...`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function readTitleFromTranscript(cleanId, brainDir) {
|
|
73
|
+
if (!brainDir) return null;
|
|
74
|
+
const logsDir = path.join(brainDir, cleanId, '.system_generated', 'logs');
|
|
75
|
+
const candidates = [
|
|
76
|
+
path.join(logsDir, 'transcript.jsonl'),
|
|
77
|
+
path.join(logsDir, 'transcript_full.jsonl'),
|
|
78
|
+
];
|
|
79
|
+
for (const filePath of candidates) {
|
|
80
|
+
if (!fs.existsSync(filePath)) continue;
|
|
81
|
+
try {
|
|
82
|
+
const head = readHeadUtf8(filePath);
|
|
83
|
+
const lines = head.split('\n');
|
|
84
|
+
for (const line of lines) {
|
|
85
|
+
if (!line.trim()) continue;
|
|
86
|
+
let step;
|
|
87
|
+
try {
|
|
88
|
+
step = JSON.parse(line);
|
|
89
|
+
} catch (_) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (step?.type !== 'USER_INPUT' || typeof step.content !== 'string') continue;
|
|
93
|
+
const cleaned = cleanUserRequestText(step.content);
|
|
94
|
+
if (!cleaned || /^\s*\/things(?:\s|$)/i.test(cleaned)) continue;
|
|
95
|
+
const title = formatSnippetTitle(cleaned);
|
|
96
|
+
if (title) return title;
|
|
97
|
+
}
|
|
98
|
+
} catch (_) {}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getCachedTitle(cacheKey, now) {
|
|
104
|
+
const hit = titleCache.get(cacheKey);
|
|
105
|
+
if (!hit) return undefined;
|
|
106
|
+
if (now - hit.ts > CACHE_TTL_MS) {
|
|
107
|
+
titleCache.delete(cacheKey);
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
return hit.value;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function setCachedTitle(cacheKey, value, now) {
|
|
114
|
+
if (titleCache.size >= MAX_CACHE_ENTRIES) {
|
|
115
|
+
const oldestKey = titleCache.keys().next().value;
|
|
116
|
+
if (oldestKey !== undefined) titleCache.delete(oldestKey);
|
|
117
|
+
}
|
|
118
|
+
titleCache.set(cacheKey, { value, ts: now });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function resolveAntigravityTitle(convIdOrKey, options = {}) {
|
|
122
|
+
const {
|
|
123
|
+
dbPath = process.env.ANTIGRAVITY_SUMMARY_DB || DEFAULT_DB_PATH,
|
|
124
|
+
brainDir = DEFAULT_BRAIN_DIR,
|
|
125
|
+
fallback = null,
|
|
126
|
+
cache = true,
|
|
127
|
+
} = options;
|
|
128
|
+
|
|
129
|
+
const cleanId = cleanConversationId(convIdOrKey);
|
|
130
|
+
if (!cleanId || cleanId === 'default') return fallback;
|
|
131
|
+
|
|
132
|
+
const cacheKey = `${dbPath || ''}\0${brainDir || ''}\0${cleanId}`;
|
|
133
|
+
const now = Date.now();
|
|
134
|
+
if (cache) {
|
|
135
|
+
const cached = getCachedTitle(cacheKey, now);
|
|
136
|
+
if (cached !== undefined) {
|
|
137
|
+
return cached || fallback;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const resolved = readTitleFromDb(cleanId, dbPath) || readTitleFromTranscript(cleanId, brainDir) || null;
|
|
142
|
+
if (cache && resolved) {
|
|
143
|
+
setCachedTitle(cacheKey, resolved, now);
|
|
144
|
+
}
|
|
145
|
+
return resolved || fallback;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = {
|
|
149
|
+
DEFAULT_DB_PATH,
|
|
150
|
+
DEFAULT_BRAIN_DIR,
|
|
151
|
+
cleanConversationId,
|
|
152
|
+
readTitleFromDb,
|
|
153
|
+
readTitleFromTranscript,
|
|
154
|
+
resolveAntigravityTitle,
|
|
155
|
+
};
|