Move thread catalog into thread feature

This commit is contained in:
murashit 2026-06-30 12:09:14 +09:00
parent 0159606b6b
commit 4daeae0cab
18 changed files with 41 additions and 37 deletions

View file

@ -1,10 +1,10 @@
import type { ThreadCatalogEvent } from "../../../../app-server/query/thread-catalog";
import {
startThread as startAppServerThread,
threadActivationSnapshotFromAppServerResponse,
} from "../../../../app-server/services/threads";
import { runtimeConfigOrDefault } from "../../../../domain/runtime/config";
import type { Thread } from "../../../../domain/threads/model";
import type { ThreadCatalogEvent } from "../../../threads/catalog/thread-catalog";
import { resumedThreadAction } from "../../application/state/actions";
import type { ChatState } from "../../application/state/root-reducer";
import type { RuntimeSnapshot } from "../../domain/runtime/snapshot";

View file

@ -1,5 +1,4 @@
import type { RequestId, ServerNotification, ServerRequest } from "../../../../app-server/connection/rpc-messages";
import type { ThreadCatalogEvent } from "../../../../app-server/query/thread-catalog";
import {
routeServerRequest,
serverRequestApprovalResponse,
@ -16,6 +15,7 @@ import {
} from "../../../../domain/pending-requests/model";
import type { ThreadConversationSummary } from "../../../../domain/threads/transcript";
import type { LocalIdSource } from "../../../../shared/id/local-id";
import type { ThreadCatalogEvent } from "../../../threads/catalog/thread-catalog";
import { activeTurnId } from "../../application/conversation/turn-state";
import type { ChatAction, ChatState } from "../../application/state/root-reducer";
import type { ChatStateStore } from "../../application/state/store";

View file

@ -1,10 +1,10 @@
import type { ServerNotification } from "../../../../app-server/connection/rpc-messages";
import type { ThreadCatalogEvent } from "../../../../app-server/query/thread-catalog";
import { threadFromAppServerRecord } from "../../../../app-server/services/threads";
import { threadTokenUsageFromRuntimeUsage } from "../../../../domain/runtime/metrics";
import { normalizeExplicitThreadName } from "../../../../domain/threads/model";
import type { ThreadConversationSummary } from "../../../../domain/threads/transcript";
import { jsonPreview } from "../../../../shared/text/preview";
import type { ThreadCatalogEvent } from "../../../threads/catalog/thread-catalog";
import { activeTurnId, pendingTurnStart as pendingTurnStartForState } from "../../application/conversation/turn-state";
import { activeThreadSettingsAppliedAction } from "../../application/state/actions";
import { messageStreamItems } from "../../application/state/message-stream";

View file

@ -28,7 +28,7 @@ export interface ThreadManagementActionsHost {
interface ThreadManagementOperations {
renameThread(threadId: string, value: string): Promise<boolean>;
archiveThread(threadId: string, options?: { saveMarkdown?: boolean; closeOpenPanels?: boolean }): Promise<boolean>;
archiveThread(threadId: string, options?: { saveMarkdown?: boolean }): Promise<boolean>;
}
export interface ThreadManagementActions {

View file

@ -2,13 +2,13 @@ import type { App, Component, EventRef } from "obsidian";
import type { AppServerClient } from "../../../app-server/connection/client";
import type { AppServerQueryContext } from "../../../app-server/query/keys";
import type { ThreadCatalogActiveReader, ThreadCatalogEventSink } from "../../../app-server/query/thread-catalog";
import type { ModelMetadata, ReasoningEffort } from "../../../domain/catalog/metadata";
import type { PendingRequestCounts } from "../../../domain/pending-requests/aggregate";
import type { SharedServerMetadata } from "../../../domain/server/metadata";
import type { ArchiveExportSettings } from "../../../domain/threads/archive-markdown";
import type { ObservedResultListener } from "../../../shared/query/observed-result";
import type { SendShortcut } from "../../../shared/ui/keyboard";
import type { ThreadCatalogActiveReader, ThreadCatalogEventSink } from "../../threads/catalog/thread-catalog";
import type { ArchiveExportDestination } from "../../threads/workflows/archive-export";
import type { TurnDiffViewState } from "../../turn-diff/model";

View file

@ -1,9 +1,9 @@
import { type App, Notice, Platform, SuggestModal } from "obsidian";
import type { ThreadCatalogActiveReader } from "../../app-server/query/thread-catalog";
import { type Thread, threadRecencyAt } from "../../domain/threads/model";
import { threadDisplayTitle } from "../../domain/threads/title";
import { shortThreadId } from "../../shared/id/thread-id";
import type { ThreadCatalogActiveReader } from "../threads/catalog/thread-catalog";
export interface ThreadPickerHost {
readonly app: App;

View file

@ -2,12 +2,12 @@ import { Notice } from "obsidian";
import type { AppServerClientAccess } from "../../app-server/connection/client-access";
import { isStaleAppServerSharedQueryContextError } from "../../app-server/query/shared-queries";
import type { ThreadCatalogActiveReader, ThreadCatalogEventSink } from "../../app-server/query/thread-catalog";
import type { ReasoningEffort } from "../../domain/catalog/metadata";
import type { ArchiveExportSettings } from "../../domain/threads/archive-markdown";
import type { Thread } from "../../domain/threads/model";
import type { ObservedResult } from "../../shared/query/observed-result";
import { observedInitialError, observedInitialLoading, observedValue } from "../../shared/query/observed-result";
import type { ThreadCatalogActiveReader, ThreadCatalogEventSink } from "../threads/catalog/thread-catalog";
import type { ArchiveExportDestination } from "../threads/workflows/archive-export";
import { createThreadOperations, type ThreadOperations } from "../threads/workflows/thread-operations";
import { createThreadTitleService, type ThreadTitleService } from "../threads/workflows/thread-title-service";
@ -36,6 +36,7 @@ export interface ThreadsViewHost {
openNewPanel(): Promise<unknown>;
openThreadInAvailableView(threadId: string): Promise<void>;
openPanelActivities(): readonly ThreadsViewPanelActivity[];
closeOpenPanelsForThread(threadId: string): void;
}
type ThreadsViewThreadCatalog = ThreadCatalogActiveReader & ThreadCatalogEventSink;
@ -328,8 +329,8 @@ export class ThreadsViewSession {
try {
await this.operations.archiveThread(threadId, {
saveMarkdown,
closeOpenPanels: true,
});
this.host.closeOpenPanelsForThread(threadId);
if (this.archiveConfirmThreadId === threadId) this.archiveConfirmThreadId = null;
this.renameStates.delete(threadId);
} catch (error) {

View file

@ -1,5 +1,5 @@
import type { Thread } from "../../domain/threads/model";
import type { ObservedResultListener } from "../../shared/query/observed-result";
import type { Thread } from "../../../domain/threads/model";
import type { ObservedResultListener } from "../../../shared/query/observed-result";
type ThreadListObserver = ObservedResultListener<readonly Thread[]>;
@ -51,7 +51,7 @@ export type ThreadCatalogEvent =
| { type: "thread-forked"; thread: Thread }
| { type: "thread-touched"; threadId: string; recencyAt?: number | null }
| { type: "thread-renamed"; threadId: string; name: string | null }
| { type: "thread-archived"; threadId: string; options?: { closeOpenPanels?: boolean } }
| { type: "thread-archived"; threadId: string }
| { type: "thread-deleted"; threadId: string }
| { type: "thread-restored"; thread: Thread }
| { type: "thread-unarchived"; threadId: string };

View file

@ -1,5 +1,4 @@
import type { AppServerClientAccess } from "../../../app-server/connection/client-access";
import type { ThreadCatalogEventSink } from "../../../app-server/query/thread-catalog";
import {
archiveThread as archiveAppServerThread,
readThreadForArchiveExport,
@ -7,6 +6,7 @@ import {
} from "../../../app-server/services/threads";
import type { ArchiveExportSettings } from "../../../domain/threads/archive-markdown";
import { normalizeExplicitThreadName } from "../../../domain/threads/model";
import type { ThreadCatalogEventSink } from "../catalog/thread-catalog";
import { type ArchiveExportDestination, exportArchivedThreadMarkdown } from "./archive-export";
export interface ThreadOperationsHost {
@ -24,7 +24,6 @@ export interface ThreadOperationsHost {
interface ArchiveThreadOptions {
saveMarkdown?: boolean;
closeOpenPanels?: boolean;
}
export interface ArchiveThreadResult {
@ -89,10 +88,6 @@ async function archiveThread(
if (exportedPath) {
host.notice(`Saved archived thread to ${exportedPath}.`);
}
host.catalog.apply(
options.closeOpenPanels === undefined
? { type: "thread-archived", threadId }
: { type: "thread-archived", threadId, options: { closeOpenPanels: options.closeOpenPanels } },
);
host.catalog.apply({ type: "thread-archived", threadId });
return { exportedPath };
}

View file

@ -5,7 +5,6 @@ import { withShortLivedAppServerClient } from "./app-server/connection/short-liv
import { AppServerQueryCache } from "./app-server/query/cache";
import { type AppServerQueryContext, appServerQueryContextIsComplete } from "./app-server/query/keys";
import { AppServerSharedQueries } from "./app-server/query/shared-queries";
import { createThreadCatalog, type ThreadCatalog, type ThreadCatalogEvent } from "./app-server/query/thread-catalog";
import { VIEW_TYPE_CODEX_THREADS, VIEW_TYPE_CODEX_TURN_DIFF } from "./constants";
import { hasPendingRequests } from "./domain/pending-requests/aggregate";
import type {
@ -17,6 +16,7 @@ import type {
CodexChatHost,
} from "./features/chat/host/contracts";
import { openThreadPicker, type ThreadPickerHost } from "./features/thread-picker/modal.obsidian";
import { createThreadCatalog, type ThreadCatalog, type ThreadCatalogEvent } from "./features/threads/catalog/thread-catalog";
import type { ThreadsViewHost, ThreadsViewSettingsAccess } from "./features/threads-view/session";
import type { ThreadsViewPanelActivity } from "./features/threads-view/state";
import { CodexThreadsView } from "./features/threads-view/view.obsidian";
@ -157,6 +157,9 @@ export class CodexPanelRuntime implements AppServerClientAccess {
openNewPanel: () => this.panels.openNewPanel(),
openThreadInAvailableView: (threadId) => this.panels.openThreadInAvailableView(threadId),
openPanelActivities: () => this.openPanelActivities(),
closeOpenPanelsForThread: (threadId) => {
this.closeOpenPanelsForThread(threadId);
},
};
}
@ -221,12 +224,15 @@ export class CodexPanelRuntime implements AppServerClientAccess {
}
}
private applyThreadArchived(threadId: string, archiveOptions: { closeOpenPanels?: boolean } = {}): void {
const leavesToClose = archiveOptions.closeOpenPanels ? this.panels.panelLeavesForThread(threadId) : [];
private applyThreadArchived(threadId: string): void {
for (const view of this.panels.panelViews()) {
const surface: ChatSharedThreadSurface = view.surface;
surface.applyThreadArchived(threadId);
}
}
private closeOpenPanelsForThread(threadId: string): void {
const leavesToClose = this.panels.panelLeavesForThread(threadId);
for (const leaf of leavesToClose) {
leaf.detach();
}
@ -242,7 +248,7 @@ export class CodexPanelRuntime implements AppServerClientAccess {
private applyThreadCatalogSurfaceEvent(event: ThreadCatalogEvent): void {
switch (event.type) {
case "thread-archived":
this.applyThreadArchived(event.threadId, event.options);
this.applyThreadArchived(event.threadId);
return;
case "thread-renamed":
this.applyThreadRenamed(event.threadId, event.name);

View file

@ -1,10 +1,10 @@
import type { AppServerClient } from "../app-server/connection/client";
import type { AppServerClientAccess } from "../app-server/connection/client-access";
import { isStaleAppServerSharedQueryContextError } from "../app-server/query/shared-queries";
import type { ThreadCatalogArchivedReader, ThreadCatalogEventSink } from "../app-server/query/thread-catalog";
import { listHookCatalog, setHookItemEnabled, trustHookItem } from "../app-server/services/catalog";
import { deleteThread, restoreArchivedThread as restoreArchivedThreadOnAppServer } from "../app-server/services/threads";
import type { ModelMetadata } from "../domain/catalog/metadata";
import type { ThreadCatalogArchivedReader, ThreadCatalogEventSink } from "../features/threads/catalog/thread-catalog";
import type { ObservedResultListener } from "../shared/query/observed-result";
import { type SettingsDynamicDataAccess, type SettingsHookCatalog, StaleSettingsDynamicDataContextError } from "./dynamic-data";

View file

@ -2,7 +2,6 @@ import { describe, expect, it, vi } from "vitest";
import type { ServerNotification, ServerRequest } from "../../../../../src/app-server/connection/rpc-messages";
import { appServerApprovalRequest, appServerUserInputRequest } from "../../../../../src/app-server/protocol/server-requests";
import type { TurnRecord } from "../../../../../src/app-server/protocol/turn";
import type { ThreadCatalogEvent } from "../../../../../src/app-server/query/thread-catalog";
import type { Thread as PanelThread } from "../../../../../src/domain/threads/model";
import {
type ChatInboundHandler,
@ -13,6 +12,7 @@ import { pendingTurnStart } from "../../../../../src/features/chat/application/c
import { type ChatAction, type ChatState, chatReducer } from "../../../../../src/features/chat/application/state/root-reducer";
import type { ChatStateStore } from "../../../../../src/features/chat/application/state/store";
import { attachHookRunsToTurn } from "../../../../../src/features/chat/domain/message-stream/updates";
import type { ThreadCatalogEvent } from "../../../../../src/features/threads/catalog/thread-catalog";
import { createLocalIdSource } from "../../../../../src/shared/id/local-id";
import { chatStateMessageStreamItems, withChatStateMessageStreamItems } from "../../support/message-stream";
import { chatStateFixture, chatStateWith } from "../../support/state";

View file

@ -4,13 +4,13 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
import type { ServerNotification } from "../../../../src/app-server/connection/rpc-messages";
import { modelMetadataFromCatalogModels } from "../../../../src/app-server/protocol/catalog";
import type { ThreadRecord } from "../../../../src/app-server/protocol/thread";
import type { ThreadCatalogEvent } from "../../../../src/app-server/query/thread-catalog";
import type { ModelMetadata } from "../../../../src/domain/catalog/metadata";
import { emptyRuntimeConfigSnapshot } from "../../../../src/domain/runtime/config";
import { createServerDiagnostics } from "../../../../src/domain/server/diagnostics";
import type { SharedServerMetadata } from "../../../../src/domain/server/metadata";
import type { Thread } from "../../../../src/domain/threads/model";
import type { CodexChatHost } from "../../../../src/features/chat/host/contracts";
import type { ThreadCatalogEvent } from "../../../../src/features/threads/catalog/thread-catalog";
import { type CodexPanelSettings, DEFAULT_SETTINGS } from "../../../../src/settings/model";
import type { ObservedResult } from "../../../../src/shared/query/observed-result";
import { notices } from "../../../mocks/obsidian";

View file

@ -296,8 +296,10 @@ describe("CodexThreadsView", () => {
"thread/archive": archiveThread,
});
const applyThreadCatalogEvent = vi.fn();
const closeOpenPanelsForThread = vi.fn();
const host = threadsHost({
threadCatalog: { apply: applyThreadCatalogEvent },
closeOpenPanelsForThread,
});
const view = await threadsView(host);
@ -310,8 +312,8 @@ describe("CodexThreadsView", () => {
expect(applyThreadCatalogEvent).toHaveBeenCalledWith({
type: "thread-archived",
threadId: "thread",
options: { closeOpenPanels: true },
});
expect(closeOpenPanelsForThread).toHaveBeenCalledWith("thread");
});
});
@ -554,6 +556,7 @@ function threadsHost(overrides: Record<string, unknown> = {}) {
openNewPanel: vi.fn().mockResolvedValue(undefined),
openThreadInAvailableView: vi.fn().mockResolvedValue(undefined),
openPanelActivities: vi.fn(() => []),
closeOpenPanelsForThread: vi.fn(),
threadCatalog: {
apply: vi.fn(),
loadActive: vi.fn(async () => []),

View file

@ -1,9 +1,9 @@
import { describe, expect, it, type Mock, vi } from "vitest";
import { AppServerQueryCache } from "../../src/app-server/query/cache";
import { AppServerSharedQueries } from "../../src/app-server/query/shared-queries";
import { createThreadCatalog, type ThreadCatalogEventObserver } from "../../src/app-server/query/thread-catalog";
import type { Thread } from "../../src/domain/threads/model";
import { AppServerQueryCache } from "../../../../src/app-server/query/cache";
import { AppServerSharedQueries } from "../../../../src/app-server/query/shared-queries";
import type { Thread } from "../../../../src/domain/threads/model";
import { createThreadCatalog, type ThreadCatalogEventObserver } from "../../../../src/features/threads/catalog/thread-catalog";
describe("ThreadCatalog", () => {
it("applies active thread snapshot replacement events through the catalog boundary", () => {
@ -79,7 +79,7 @@ describe("ThreadCatalog", () => {
catalog.apply({ type: "active-list-snapshot-received", threads: [thread("thread"), thread("other")] });
catalog.apply({ type: "archived-list-snapshot-received", threads: [thread("archived", true)] });
catalog.apply({ type: "thread-archived", threadId: "thread", options: { closeOpenPanels: true } });
catalog.apply({ type: "thread-archived", threadId: "thread" });
expect(catalog.activeSnapshot()).toEqual([thread("other")]);
expect(catalog.archivedSnapshot()).toEqual([{ ...thread("thread"), archived: true }, thread("archived", true)]);
@ -320,7 +320,7 @@ describe("ThreadCatalog", () => {
catalog.apply({ type: "thread-started", thread: thread("started") });
catalog.apply({ type: "thread-touched", threadId: "existing", recencyAt: 20 });
catalog.apply({ type: "thread-renamed", threadId: "started", name: "Started" });
catalog.apply({ type: "thread-archived", threadId: "existing", options: { closeOpenPanels: true } });
catalog.apply({ type: "thread-archived", threadId: "existing" });
expect(catalog.activeSnapshot()).toEqual([{ ...thread("started"), name: "Started" }]);
expect(catalog.archivedSnapshot()).toEqual([thread("existing", true, { recencyAt: 20 }), thread("archived", true)]);

View file

@ -31,7 +31,7 @@ describe("ThreadOperations", () => {
it("archives a thread, reports exported markdown, and notifies shared surfaces", async () => {
const { operations, catalog, notice, client, archiveDestination } = operationsFixture();
await expect(operations.archiveThread("thread", { saveMarkdown: true, closeOpenPanels: true })).resolves.toEqual({
await expect(operations.archiveThread("thread", { saveMarkdown: true })).resolves.toEqual({
exportedPath: "Archive/Archived Thread abcdef12.md",
});
@ -46,7 +46,6 @@ describe("ThreadOperations", () => {
expect(catalog.apply).toHaveBeenCalledWith({
type: "thread-archived",
threadId: "thread",
options: { closeOpenPanels: true },
});
});

View file

@ -496,7 +496,7 @@ describe("CodexPanelPlugin workspace panel reconciliation", () => {
expect(secondArchived).toHaveBeenCalledWith("thread-1");
});
it("closes matching chat panels only when archive notification requests it", async () => {
it("keeps catalog archive notifications separate from explicit panel close requests", async () => {
const { CodexChatView } = await import("../src/features/chat/host/view.obsidian");
const restoredMatchingLeaf = leaf({ state: { threadId: "thread-1", threadTitle: "Restored" } });
const matchingLeaf = leaf();
@ -515,7 +515,7 @@ describe("CodexPanelPlugin workspace panel reconciliation", () => {
expect(matchingLeaf.detach).not.toHaveBeenCalled();
expect(otherLeaf.detach).not.toHaveBeenCalled();
threadCatalog(plugin).apply({ type: "thread-archived", threadId: "thread-1", options: { closeOpenPanels: true } });
plugin.runtime.threadsHost().closeOpenPanelsForThread("thread-1");
expect(restoredMatchingLeaf.detach).toHaveBeenCalledOnce();
expect(matchingLeaf.detach).toHaveBeenCalledOnce();

View file

@ -6,9 +6,9 @@ import type { AppServerClientAccessOptions } from "../../src/app-server/connecti
import type { CatalogHookMetadata, CatalogModel } from "../../src/app-server/protocol/catalog";
import { modelMetadataFromCatalogModels } from "../../src/app-server/protocol/catalog";
import type { ThreadRecord } from "../../src/app-server/protocol/thread";
import type { ThreadCatalogEvent } from "../../src/app-server/query/thread-catalog";
import type { ModelMetadata, ReasoningEffort } from "../../src/domain/catalog/metadata";
import type { Thread } from "../../src/domain/threads/model";
import type { ThreadCatalogEvent } from "../../src/features/threads/catalog/thread-catalog";
import { createSettingsAppServerDynamicData } from "../../src/settings/app-server-dynamic-data";
import type { SettingsDynamicDataAccess } from "../../src/settings/dynamic-data";
import { SettingsDynamicSectionsController, type SettingsDynamicSectionsSnapshot } from "../../src/settings/dynamic-sections-controller";