fix: filter codex subthreads during auto import
This commit is contained in:
@@ -33,6 +33,15 @@ function fallbackDisplayName(thread, folderName) {
|
||||
return `${folderName} · ${suffix}`;
|
||||
}
|
||||
|
||||
function trimToDefined(value) {
|
||||
const trimmed = typeof value === "string" ? value.trim() : "";
|
||||
return trimmed ? trimmed : null;
|
||||
}
|
||||
|
||||
function isPrimaryWorkspaceThread(thread) {
|
||||
return !trimToDefined(thread.agentRole) && !trimToDefined(thread.agentNickname);
|
||||
}
|
||||
|
||||
function loadThreadWorkspaceHints(globalStatePath) {
|
||||
if (!globalStatePath) return new Map();
|
||||
try {
|
||||
@@ -193,7 +202,7 @@ export async function discoverCodexProjectCandidates(options = {}) {
|
||||
}
|
||||
|
||||
const seenThreadIds = new Set();
|
||||
const candidates = [];
|
||||
const groupedCandidates = new Map();
|
||||
for (const thread of threads) {
|
||||
if (!thread?.id || seenThreadIds.has(thread.id)) continue;
|
||||
const latestActivitySeconds = latestLogByThread.get(thread.id) ?? thread.updatedAtSeconds;
|
||||
@@ -213,7 +222,7 @@ export async function discoverCodexProjectCandidates(options = {}) {
|
||||
sanitizeDisplayName(thread.title, fallbackDisplayName(thread, folderName)),
|
||||
);
|
||||
|
||||
candidates.push({
|
||||
const candidate = {
|
||||
folderName,
|
||||
folderRef: folderPath,
|
||||
threadId: thread.id,
|
||||
@@ -222,7 +231,23 @@ export async function discoverCodexProjectCandidates(options = {}) {
|
||||
codexThreadRef: thread.id,
|
||||
lastActiveAt: toIsoFromUnixSeconds(latestActivitySeconds) ?? now.toISOString(),
|
||||
suggestedImport: true,
|
||||
};
|
||||
const folderKey = folderPath || folderName;
|
||||
const bucket = groupedCandidates.get(folderKey) ?? [];
|
||||
bucket.push({
|
||||
candidate,
|
||||
latestActivitySeconds,
|
||||
primary: isPrimaryWorkspaceThread(thread),
|
||||
});
|
||||
groupedCandidates.set(folderKey, bucket);
|
||||
}
|
||||
|
||||
const candidates = [];
|
||||
for (const entries of groupedCandidates.values()) {
|
||||
entries.sort((left, right) => right.latestActivitySeconds - left.latestActivitySeconds);
|
||||
const primaryEntries = entries.filter((entry) => entry.primary);
|
||||
const chosenEntries = primaryEntries.length > 0 ? primaryEntries : entries.slice(0, 1);
|
||||
candidates.push(...chosenEntries.map((entry) => entry.candidate));
|
||||
}
|
||||
|
||||
candidates.sort((a, b) => b.lastActiveAt.localeCompare(a.lastActiveAt));
|
||||
|
||||
Reference in New Issue
Block a user