fix: use getDiagnostics for cascade IDs + summary fallback + stop poll spam
This commit is contained in:
Binary file not shown.
@@ -281,73 +281,85 @@ function activate(context) {
|
|||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
let pollFailCount = 0;
|
||||||
async function pollConversations() {
|
async function pollConversations() {
|
||||||
if (!lsPort) {
|
if (!lsPort) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (pollFailCount > 3) {
|
||||||
|
return;
|
||||||
|
} // stop after repeated failures
|
||||||
try {
|
try {
|
||||||
// Get trajectory list — returns {trajectories:[{trajectoryId, trajectoryScope, current}]}
|
// Use getDiagnostics to get cascade-level conversation IDs
|
||||||
const result = await lsRPC('GetUserTrajectoryDescriptions');
|
const diag = await vscode.commands.executeCommand('antigravity.getDiagnostics');
|
||||||
if (!result || !result.trajectories) {
|
if (!diag) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parsed = typeof diag === 'string' ? JSON.parse(diag) : diag;
|
||||||
|
const trajectories = parsed.recentTrajectories || [];
|
||||||
|
if (!Array.isArray(trajectories) || trajectories.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Debug: log structure on first call
|
|
||||||
const isFirstPoll = Object.keys(lastStepIndex).length === 0;
|
const isFirstPoll = Object.keys(lastStepIndex).length === 0;
|
||||||
if (isFirstPoll) {
|
if (isFirstPoll) {
|
||||||
console.log(`Gravity Bridge: [LS] trajectories response keys: ${Object.keys(result).join(', ')}`);
|
console.log(`Gravity Bridge: [LS] ${trajectories.length} recent trajectories from getDiagnostics`);
|
||||||
console.log(`Gravity Bridge: [LS] trajectories sample: ${JSON.stringify(result).substring(0, 600)}`);
|
const latest = trajectories[trajectories.length - 1];
|
||||||
|
console.log(`Gravity Bridge: [LS] latest: ${JSON.stringify(latest).substring(0, 400)}`);
|
||||||
}
|
}
|
||||||
// Find current (active) trajectory
|
// Check the most recent trajectory for step count changes
|
||||||
const trajectories = result.trajectories;
|
const latest = trajectories[trajectories.length - 1];
|
||||||
const current = trajectories.find((t) => t.current === true) || trajectories[0];
|
const agentId = latest.googleAgentId || '';
|
||||||
if (!current?.trajectoryId) {
|
const trajId = latest.trajectoryId || '';
|
||||||
|
const stepIdx = latest.lastStepIndex ?? 0;
|
||||||
|
if (!agentId && !trajId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const trajId = current.trajectoryId;
|
const key = agentId || trajId;
|
||||||
// Try multiple RPC methods and field name variants
|
const prev = lastStepIndex[key];
|
||||||
const attempts = [
|
if (prev === undefined) {
|
||||||
{ method: 'GetCascadeTrajectorySteps', params: { trajectoryId: trajId } },
|
// First poll — initialize
|
||||||
{ method: 'GetCascadeTrajectory', params: { trajectoryId: trajId } },
|
lastStepIndex[key] = stepIdx;
|
||||||
{ method: 'GetCascadeTrajectorySteps', params: { cascadeId: trajId } },
|
console.log(`Gravity Bridge: [LS] initialized ${key.substring(0, 8)} at step ${stepIdx}`);
|
||||||
{ method: 'GetCascadeTrajectory', params: { cascadeId: trajId } },
|
return;
|
||||||
{ method: 'GetUserTrajectory', params: { trajectoryId: trajId } },
|
}
|
||||||
];
|
if (stepIdx > prev) {
|
||||||
let stepsResult = null;
|
// New steps detected! Try to fetch them
|
||||||
for (const attempt of attempts) {
|
console.log(`Gravity Bridge: [LS] ${key.substring(0, 8)} new steps: ${prev} → ${stepIdx}`);
|
||||||
const res = await lsRPC(attempt.method, attempt.params);
|
const attempts = [
|
||||||
if (res && !res.code && !res.message?.includes('not found')) {
|
{ method: 'GetCascadeTrajectorySteps', params: { googleAgentId: agentId, trajectoryId: trajId, startStepIndex: prev } },
|
||||||
stepsResult = res;
|
{ method: 'GetCascadeTrajectory', params: { googleAgentId: agentId, trajectoryId: trajId } },
|
||||||
if (isFirstPoll) {
|
{ method: 'GetCascadeTrajectorySteps', params: { conversationId: agentId, trajectoryId: trajId } },
|
||||||
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method}(${JSON.stringify(attempt.params).substring(0, 50)}) worked!`);
|
];
|
||||||
console.log(`Gravity Bridge: [LS] steps response keys: ${Object.keys(res).join(', ')}`);
|
let stepsResult = null;
|
||||||
console.log(`Gravity Bridge: [LS] steps sample: ${JSON.stringify(res).substring(0, 800)}`);
|
for (const attempt of attempts) {
|
||||||
|
const res = await lsRPC(attempt.method, attempt.params);
|
||||||
|
if (res && !res.code && !res.message?.includes('not found')) {
|
||||||
|
stepsResult = res;
|
||||||
|
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method} worked!`);
|
||||||
|
console.log(`Gravity Bridge: [LS] keys: ${Object.keys(res).join(', ')}`);
|
||||||
|
console.log(`Gravity Bridge: [LS] sample: ${JSON.stringify(res).substring(0, 800)}`);
|
||||||
|
pollFailCount = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (isFirstPoll) {
|
if (stepsResult) {
|
||||||
const errMsg = res?.message || res?.code || 'null/empty';
|
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
|
||||||
console.log(`Gravity Bridge: [LS] ❌ ${attempt.method}(${Object.keys(attempt.params)[0]}): ${errMsg}`);
|
if (Array.isArray(steps) && steps.length > 0) {
|
||||||
|
const newSteps = steps.slice(-(stepIdx - prev));
|
||||||
|
extractAndRelaySteps(newSteps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
if (!stepsResult) {
|
// All attempts failed — try writing the summary as a fallback
|
||||||
return;
|
const summary = latest.summary || '';
|
||||||
}
|
if (summary && summary !== lastStepIndex[key + '_summary']) {
|
||||||
// Count steps — detect new ones
|
writeChatSnapshot(`[AI 대화 요약]\n\n${summary}\n\n(step ${prev} → ${stepIdx})`);
|
||||||
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
|
lastStepIndex[key + '_summary'] = summary;
|
||||||
const stepCount = Array.isArray(steps) ? steps.length : 0;
|
console.log(`Gravity Bridge: [LS] relayed summary fallback: ${summary.substring(0, 100)}`);
|
||||||
const prevCount = lastStepIndex[trajId] ?? -1;
|
}
|
||||||
if (prevCount === -1) {
|
pollFailCount++;
|
||||||
// First poll — just record count, don't relay old messages
|
}
|
||||||
lastStepIndex[trajId] = stepCount;
|
lastStepIndex[key] = stepIdx;
|
||||||
console.log(`Gravity Bridge: [LS] trajectory ${trajId.substring(0, 8)} initialized with ${stepCount} steps`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (stepCount > prevCount) {
|
|
||||||
console.log(`Gravity Bridge: [LS] ${trajId.substring(0, 8)} new steps: ${prevCount} → ${stepCount}`);
|
|
||||||
// Extract AI text from new steps
|
|
||||||
const newSteps = steps.slice(prevCount);
|
|
||||||
extractAndRelaySteps(newSteps);
|
|
||||||
lastStepIndex[trajId] = stepCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -263,75 +263,86 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pollFailCount = 0;
|
||||||
|
|
||||||
async function pollConversations() {
|
async function pollConversations() {
|
||||||
if (!lsPort) { return; }
|
if (!lsPort) { return; }
|
||||||
|
if (pollFailCount > 3) { return; } // stop after repeated failures
|
||||||
try {
|
try {
|
||||||
// Get trajectory list — returns {trajectories:[{trajectoryId, trajectoryScope, current}]}
|
// Use getDiagnostics to get cascade-level conversation IDs
|
||||||
const result = await lsRPC('GetUserTrajectoryDescriptions');
|
const diag: any = await vscode.commands.executeCommand('antigravity.getDiagnostics');
|
||||||
if (!result || !result.trajectories) { return; }
|
if (!diag) { return; }
|
||||||
|
|
||||||
|
const parsed = typeof diag === 'string' ? JSON.parse(diag) : diag;
|
||||||
|
const trajectories = parsed.recentTrajectories || [];
|
||||||
|
if (!Array.isArray(trajectories) || trajectories.length === 0) { return; }
|
||||||
|
|
||||||
// Debug: log structure on first call
|
|
||||||
const isFirstPoll = Object.keys(lastStepIndex).length === 0;
|
const isFirstPoll = Object.keys(lastStepIndex).length === 0;
|
||||||
if (isFirstPoll) {
|
if (isFirstPoll) {
|
||||||
console.log(`Gravity Bridge: [LS] trajectories response keys: ${Object.keys(result).join(', ')}`);
|
console.log(`Gravity Bridge: [LS] ${trajectories.length} recent trajectories from getDiagnostics`);
|
||||||
console.log(`Gravity Bridge: [LS] trajectories sample: ${JSON.stringify(result).substring(0, 600)}`);
|
const latest = trajectories[trajectories.length - 1];
|
||||||
|
console.log(`Gravity Bridge: [LS] latest: ${JSON.stringify(latest).substring(0, 400)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find current (active) trajectory
|
// Check the most recent trajectory for step count changes
|
||||||
const trajectories = result.trajectories as any[];
|
const latest = trajectories[trajectories.length - 1];
|
||||||
const current = trajectories.find((t: any) => t.current === true) || trajectories[0];
|
const agentId = latest.googleAgentId || '';
|
||||||
if (!current?.trajectoryId) { return; }
|
const trajId = latest.trajectoryId || '';
|
||||||
|
const stepIdx = latest.lastStepIndex ?? 0;
|
||||||
|
|
||||||
const trajId = current.trajectoryId;
|
if (!agentId && !trajId) { return; }
|
||||||
|
|
||||||
// Try multiple RPC methods and field name variants
|
const key = agentId || trajId;
|
||||||
const attempts = [
|
const prev = lastStepIndex[key];
|
||||||
{ method: 'GetCascadeTrajectorySteps', params: { trajectoryId: trajId } },
|
|
||||||
{ method: 'GetCascadeTrajectory', params: { trajectoryId: trajId } },
|
|
||||||
{ method: 'GetCascadeTrajectorySteps', params: { cascadeId: trajId } },
|
|
||||||
{ method: 'GetCascadeTrajectory', params: { cascadeId: trajId } },
|
|
||||||
{ method: 'GetUserTrajectory', params: { trajectoryId: trajId } },
|
|
||||||
];
|
|
||||||
|
|
||||||
let stepsResult: any = null;
|
if (prev === undefined) {
|
||||||
for (const attempt of attempts) {
|
// First poll — initialize
|
||||||
const res = await lsRPC(attempt.method, attempt.params);
|
lastStepIndex[key] = stepIdx;
|
||||||
if (res && !res.code && !res.message?.includes('not found')) {
|
console.log(`Gravity Bridge: [LS] initialized ${key.substring(0, 8)} at step ${stepIdx}`);
|
||||||
stepsResult = res;
|
|
||||||
if (isFirstPoll) {
|
|
||||||
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method}(${JSON.stringify(attempt.params).substring(0, 50)}) worked!`);
|
|
||||||
console.log(`Gravity Bridge: [LS] steps response keys: ${Object.keys(res).join(', ')}`);
|
|
||||||
console.log(`Gravity Bridge: [LS] steps sample: ${JSON.stringify(res).substring(0, 800)}`);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (isFirstPoll) {
|
|
||||||
const errMsg = res?.message || res?.code || 'null/empty';
|
|
||||||
console.log(`Gravity Bridge: [LS] ❌ ${attempt.method}(${Object.keys(attempt.params)[0]}): ${errMsg}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!stepsResult) { return; }
|
|
||||||
|
|
||||||
// Count steps — detect new ones
|
|
||||||
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
|
|
||||||
const stepCount = Array.isArray(steps) ? steps.length : 0;
|
|
||||||
const prevCount = lastStepIndex[trajId] ?? -1;
|
|
||||||
|
|
||||||
if (prevCount === -1) {
|
|
||||||
// First poll — just record count, don't relay old messages
|
|
||||||
lastStepIndex[trajId] = stepCount;
|
|
||||||
console.log(`Gravity Bridge: [LS] trajectory ${trajId.substring(0, 8)} initialized with ${stepCount} steps`);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stepCount > prevCount) {
|
if (stepIdx > prev) {
|
||||||
console.log(`Gravity Bridge: [LS] ${trajId.substring(0, 8)} new steps: ${prevCount} → ${stepCount}`);
|
// New steps detected! Try to fetch them
|
||||||
// Extract AI text from new steps
|
console.log(`Gravity Bridge: [LS] ${key.substring(0, 8)} new steps: ${prev} → ${stepIdx}`);
|
||||||
const newSteps = steps.slice(prevCount);
|
|
||||||
extractAndRelaySteps(newSteps);
|
const attempts = [
|
||||||
lastStepIndex[trajId] = stepCount;
|
{ method: 'GetCascadeTrajectorySteps', params: { googleAgentId: agentId, trajectoryId: trajId, startStepIndex: prev } },
|
||||||
|
{ method: 'GetCascadeTrajectory', params: { googleAgentId: agentId, trajectoryId: trajId } },
|
||||||
|
{ method: 'GetCascadeTrajectorySteps', params: { conversationId: agentId, trajectoryId: trajId } },
|
||||||
|
];
|
||||||
|
|
||||||
|
let stepsResult: any = null;
|
||||||
|
for (const attempt of attempts) {
|
||||||
|
const res = await lsRPC(attempt.method, attempt.params);
|
||||||
|
if (res && !res.code && !res.message?.includes('not found')) {
|
||||||
|
stepsResult = res;
|
||||||
|
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method} worked!`);
|
||||||
|
console.log(`Gravity Bridge: [LS] keys: ${Object.keys(res).join(', ')}`);
|
||||||
|
console.log(`Gravity Bridge: [LS] sample: ${JSON.stringify(res).substring(0, 800)}`);
|
||||||
|
pollFailCount = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stepsResult) {
|
||||||
|
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
|
||||||
|
if (Array.isArray(steps) && steps.length > 0) {
|
||||||
|
const newSteps = steps.slice(-(stepIdx - prev));
|
||||||
|
extractAndRelaySteps(newSteps);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// All attempts failed — try writing the summary as a fallback
|
||||||
|
const summary = latest.summary || '';
|
||||||
|
if (summary && summary !== lastStepIndex[key + '_summary']) {
|
||||||
|
writeChatSnapshot(`[AI 대화 요약]\n\n${summary}\n\n(step ${prev} → ${stepIdx})`);
|
||||||
|
lastStepIndex[key + '_summary'] = summary;
|
||||||
|
console.log(`Gravity Bridge: [LS] relayed summary fallback: ${summary.substring(0, 100)}`);
|
||||||
|
}
|
||||||
|
pollFailCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStepIndex[key] = stepIdx;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Gravity Bridge: [LS poll] error: ${e}`);
|
console.log(`Gravity Bridge: [LS poll] error: ${e}`);
|
||||||
@@ -339,6 +350,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function extractAndRelaySteps(steps: any[]) {
|
function extractAndRelaySteps(steps: any[]) {
|
||||||
const messages: string[] = [];
|
const messages: string[] = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user