Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ const layerTest = Layer.mergeAll(
}),
request: () => Effect.void,
readRepositoryIdentity: () => Effect.succeed(null),
getAvailableRepositoryIdentity: () => Effect.succeed(null),
getAvailable: () =>
Effect.succeed({
repositoryIdentity: null,
Expand Down
33 changes: 33 additions & 0 deletions apps/server/src/orchestration-v2/ShellStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,36 @@ describe("skipUnchangedThreadShells", () => {
}),
);
});

describe("shellStreamItemFromEnrichmentRefresh", () => {
it("carries a project whose tracked folder resolved, as well as one whose own root did", () => {
const project = (
id: string,
workspaceRoot: string,
trackedFolders: ReadonlyArray<{ path: string; name: string }> = [],
) => ({
id: ProjectId.make(id),
title: id,
workspaceRoot,
repositoryIdentity: null,
defaultModelSelection: null,
scripts: [],
trackedFolders,
createdAt: "2026-09-01T00:00:00Z",
updatedAt: "2026-09-01T00:00:00Z",
});
const item = shellStreamItemFromEnrichmentRefresh({
snapshot: {
...emptyShellSnapshot,
projects: [
project("shop", "/work/shop", [{ path: "/work/shop/api", name: "api" }]),
project("api", "/work/shop/api"),
project("other", "/work/other"),
],
} as OrchestrationV2ShellSnapshot,
changes: [{ workspaceRoot: "/work/shop/api" }],
});
expect(item.snapshot.projects.map((entry) => entry.id)).toEqual(["shop", "api"]);
expect(item.resolvedRepositoryIdentityRoots).toEqual(["/work/shop/api"]);
});
});
8 changes: 6 additions & 2 deletions apps/server/src/orchestration-v2/ShellStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,12 @@ export function shellStreamItemFromEnrichmentRefresh(input: {
kind: "snapshot",
snapshot: {
...input.snapshot,
projects: input.snapshot.projects.filter((project) =>
resolvedRepositoryIdentityRoots.includes(project.workspaceRoot),
projects: input.snapshot.projects.filter(
(project) =>
resolvedRepositoryIdentityRoots.includes(project.workspaceRoot) ||
project.trackedFolders?.some((folder) =>
resolvedRepositoryIdentityRoots.includes(folder.path),
) === true,
),
threads: [],
archivedThreads: [],
Expand Down
16 changes: 10 additions & 6 deletions apps/server/src/orchestration-v2/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ export const layer = HttpApiBuilder.group(
projects,
(project) =>
// Use available enrichment only; git probes can take a minute and exceed shell-snapshot budgets.
projectEnrichment.getAvailable(project.workspaceRoot).pipe(
Effect.map((enrichment) => ({
...project,
repositoryIdentity: enrichment.repositoryIdentity,
})),
),
projectEnrichment
.getAvailable(project.workspaceRoot)
.pipe(
Effect.flatMap((enrichment) =>
ProjectEnrichmentService.withTrackedFolderIdentities(
{ ...project, repositoryIdentity: enrichment.repositoryIdentity },
(root) => projectEnrichment.getAvailableRepositoryIdentity(root),
),
),
),
{ concurrency: 16 },
),
);
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/orchestration-v2/runtimeLayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ const layerSharedApplicationDataPlaneTest = Layer.mergeAll(
}),
request: () => Effect.void,
readRepositoryIdentity: () => Effect.succeed(null),
getAvailableRepositoryIdentity: () => Effect.succeed(null),
getAvailable: () =>
Effect.succeed({
repositoryIdentity: null,
Expand Down
38 changes: 38 additions & 0 deletions apps/server/src/project/ProjectEnrichmentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,41 @@ it.effect("keeps a lookup's identity when another root is invalidated mid-flight
}).pipe(Effect.provide(layer(layerMetadata)));
}),
);

it.effect("fills in tracked folder identities once they resolve, without asking for favicons", () =>
Effect.gen(function* () {
const faviconStarts = yield* Ref.make(0);
const layerMetadata = Layer.merge(
Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
resolve: (workspaceRoot) =>
Effect.succeed(workspaceRoot === "/shop/notes" ? null : identity(workspaceRoot)),
}),
Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
invalidate: () => Effect.void,
resolvePath: () => Ref.update(faviconStarts, (count) => count + 1).pipe(Effect.as(null)),
}),
);

yield* Effect.gen(function* () {
const service = yield* ProjectEnrichment.ProjectEnrichmentService;
const project = {
trackedFolders: [
{ path: "/shop/api", name: "api" },
{ path: "/shop/notes", name: "notes" },
],
};
const read = ProjectEnrichment.withTrackedFolderIdentities(project, (root) =>
service.getAvailableRepositoryIdentity(root),
);

assert.deepStrictEqual(yield* read, project);
yield* waitForAvailable(service, "/shop/api", (value) => value.repositoryIdentity !== null);
yield* waitForAvailable(service, "/shop/notes", (value) => value.repositoryIdentityResolved);
assert.deepStrictEqual((yield* read).trackedFolders, [
{ path: "/shop/api", name: "api", repositoryIdentity: identity("/shop/api") },
{ path: "/shop/notes", name: "notes" },
]);
assert.equal(yield* Ref.get(faviconStarts), 0);
}).pipe(Effect.provide(layer(layerMetadata)));
}),
);
51 changes: 45 additions & 6 deletions apps/server/src/project/ProjectEnrichmentService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RepositoryIdentity } from "@t3tools/contracts";
import type { ProjectTrackedFolder, RepositoryIdentity } from "@t3tools/contracts";
import * as Cache from "effect/Cache";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
Expand Down Expand Up @@ -50,6 +50,10 @@ export class ProjectEnrichmentService extends Context.Service<
readonly readRepositoryIdentity: (
workspaceRoot: string,
) => Effect.Effect<RepositoryIdentity | null>;
/** The identity `peek` reports, requesting it when none is cached; favicons are left alone. */
readonly getAvailableRepositoryIdentity: (
workspaceRoot: string,
) => Effect.Effect<RepositoryIdentity | null>;
readonly invalidate: (workspaceRoots: Iterable<string>) => Effect.Effect<void>;
/** Re-resolves past both identity caches and publishes a found identity, leaving the favicon alone. */
readonly refreshRepositoryIdentity: (workspaceRoot: string) => Effect.Effect<void>;
Expand Down Expand Up @@ -267,6 +271,14 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
});

// peek/request/getAvailable run per project on every shell read, inside the caller's span; own spans were ~0ms noise.
const availableRepositoryIdentity = (
workspaceRoot: string,
cached: Option.Option<Exit.Exit<RepositoryIdentity | null, unknown>>,
) =>
isSuccessfullyResolved(cached)
? availableValue(cached)
: (lastRepositoryIdentities.get(workspaceRoot) ?? null);

const peek: ProjectEnrichmentService["Service"]["peek"] = Effect.fnUntraced(
function* (workspaceRoot) {
const [repositoryIdentity, faviconPath] = yield* Effect.all(
Expand All @@ -276,17 +288,23 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
] as const,
{ concurrency: "unbounded" },
);
const repositoryIdentityResolved = isSuccessfullyResolved(repositoryIdentity);
return {
repositoryIdentity: repositoryIdentityResolved
? availableValue(repositoryIdentity)
: (lastRepositoryIdentities.get(workspaceRoot) ?? null),
repositoryIdentity: availableRepositoryIdentity(workspaceRoot, repositoryIdentity),
faviconPath: availableValue(faviconPath),
repositoryIdentityResolved,
repositoryIdentityResolved: isSuccessfullyResolved(repositoryIdentity),
};
},
);

const getAvailableRepositoryIdentity: ProjectEnrichmentService["Service"]["getAvailableRepositoryIdentity"] =
Effect.fnUntraced(function* (workspaceRoot) {
const cached = yield* Cache.getSuccess(repositoryIdentityCache, workspaceRoot);
if (!(yield* Cache.has(repositoryIdentityCache, workspaceRoot))) {
yield* requestLane(repositoryIdentityLane, workspaceRoot, "repositoryIdentity");
}
return availableRepositoryIdentity(workspaceRoot, cached);
});

const request: ProjectEnrichmentService["Service"]["request"] = Effect.fnUntraced(
function* (workspaceRoot) {
const [hasRepositoryIdentity, hasFaviconPath] = yield* Effect.all(
Expand Down Expand Up @@ -358,10 +376,31 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* (
request,
getAvailable,
readRepositoryIdentity,
getAvailableRepositoryIdentity,
invalidate,
refreshRepositoryIdentity,
subscribeChanges: PubSub.subscribe(changes),
});
});

/**
* A project shell's tracked folders with the repository identities `identityOf` knows. A folder
* whose identity is unknown, or that is not a repository, stays as stored.
*/
export const withTrackedFolderIdentities = <
Project extends { readonly trackedFolders?: ReadonlyArray<ProjectTrackedFolder> | undefined },
>(
project: Project,
identityOf: (workspaceRoot: string) => Effect.Effect<RepositoryIdentity | null>,
): Effect.Effect<Project> =>
project.trackedFolders === undefined || project.trackedFolders.length === 0
? Effect.succeed(project)
: Effect.forEach(project.trackedFolders, (folder) =>
identityOf(folder.path).pipe(
Effect.map((repositoryIdentity) =>
repositoryIdentity === null ? folder : { ...folder, repositoryIdentity },
),
),
).pipe(Effect.map((trackedFolders) => ({ ...project, trackedFolders })));

export const layer = Layer.effect(ProjectEnrichmentService, make());
16 changes: 10 additions & 6 deletions apps/server/src/project/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,16 @@ export const make = Effect.gen(function* () {
);

const enrichShell = (shell: OrchestrationProjectShell) =>
projectEnrichment.getAvailable(shell.workspaceRoot).pipe(
Effect.map((enrichment) => ({
...shell,
repositoryIdentity: enrichment.repositoryIdentity,
})),
);
projectEnrichment
.getAvailable(shell.workspaceRoot)
.pipe(
Effect.flatMap((enrichment) =>
ProjectEnrichmentService.withTrackedFolderIdentities(
{ ...shell, repositoryIdentity: enrichment.repositoryIdentity },
(root) => projectEnrichment.getAvailableRepositoryIdentity(root),
),
),
);

const getShell: ProjectService["Service"]["getShell"] = Effect.fn("ProjectService.getShell")(
function* (projectId) {
Expand Down
42 changes: 31 additions & 11 deletions apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,13 +898,17 @@ const enrichProjectShells = Effect.fn("ws.orchestrationV2.enrichProjectShells")(
projects,
(project) =>
projectEnrichment.getAvailable(project.workspaceRoot).pipe(
Effect.map((enrichment) => ({
project: {
...project,
repositoryIdentity: enrichment.repositoryIdentity,
},
repositoryIdentityResolved: enrichment.repositoryIdentityResolved,
})),
Effect.flatMap((enrichment) =>
ProjectEnrichmentService.withTrackedFolderIdentities(
{ ...project, repositoryIdentity: enrichment.repositoryIdentity },
(root) => projectEnrichment.getAvailableRepositoryIdentity(root),
).pipe(
Effect.map((enriched) => ({
project: enriched,
repositoryIdentityResolved: enrichment.repositoryIdentityResolved,
})),
),
),
),
{ concurrency: 16 },
).pipe(
Expand Down Expand Up @@ -1308,10 +1312,26 @@ export const subscribeOrchestrationV2Shell = Effect.fn("ws.orchestrationV2.subsc
]),
);
const snapshotSequence = yield* applicationEvents.latestApplicationSequence;
const changedProjects = (yield* projects.listShells()).flatMap((project) =>
identities.has(project.workspaceRoot)
? [{ ...project, repositoryIdentity: identities.get(project.workspaceRoot) ?? null }]
: [],
// Peeks only: requesting here would re-resolve whatever expired on every refresh.
const identityOf = (root: string) =>
identities.has(root)
? Effect.succeed(identities.get(root) ?? null)
: projectEnrichment.peek(root).pipe(Effect.map((known) => known.repositoryIdentity));
const changedProjects = yield* Effect.forEach(
(yield* projects.listShells()).filter(
(project) =>
identities.has(project.workspaceRoot) ||
project.trackedFolders?.some((folder) => identities.has(folder.path)) === true,
),
(project) =>
identityOf(project.workspaceRoot).pipe(
Effect.flatMap((repositoryIdentity) =>
ProjectEnrichmentService.withTrackedFolderIdentities(
{ ...project, repositoryIdentity },
identityOf,
),
),
),
);
return shellStreamItemFromEnrichmentRefresh({
snapshot: {
Expand Down
Loading