Skip to content

Commit dea6a9d

Browse files
committed
feat: show the services a thread is running in its details card
Thread details get a Services section listing the listening servers a thread's agent or terminals started, plus servers running in its folder. Each row has a short name, the port, and a hover card with owner, uptime, CPU, memory, URLs and the command. Clicking copies the URL that works from the current client; hover actions open or stop the service. The server attributes listeners to threads through the terminal shells, the Claude CLI process, and the thread's workspace for shared providers such as Codex. Stop signals only the dev-server job: the climb from a listener stays in its process group and goes only through known launchers, so agent CLIs, shells, editors and T3 itself are never signaled. Names come from a new generateServiceName text-generation operation, after redacting secrets.
1 parent 1451e7c commit dea6a9d

56 files changed

Lines changed: 6322 additions & 179 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/server/src/auth/RpcAuthorization.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AuthFilesystemReadScope,
55
AuthProvidersManageScope,
66
AuthSettingsWriteScope,
7+
AuthStandardClientScopes,
78
DEFAULT_SERVER_SETTINGS,
89
ProviderInstanceId,
910
ThreadId,
@@ -18,6 +19,7 @@ import {
1819
AuthTerminalOperateScope,
1920
WS_METHODS,
2021
WsRpcGroup,
22+
sessionGrantsScope,
2123
} from "@t3tools/contracts";
2224
import { describe, expect, it } from "@effect/vitest";
2325
import * as Effect from "effect/Effect";
@@ -170,6 +172,32 @@ describe("RPC authorization scopes", () => {
170172
}
171173
});
172174

175+
it("keeps thread service command lines at diagnostics scope and stopping at terminal operate", () => {
176+
expect(requiredScopeForRpcMethod(WS_METHODS.subscribeThreadServices)).toBe(
177+
AuthDiagnosticsReadScope,
178+
);
179+
expect(requiredScopeForRpcMethod(WS_METHODS.threadServicesStop)).toBe(AuthTerminalOperateScope);
180+
// Normal clients keep the panel: standard grants include the scope, and legacy grants imply it
181+
// through orchestration:read. A grant narrowed to orchestration:read does not.
182+
expect(AuthStandardClientScopes).toContain(AuthDiagnosticsReadScope);
183+
expect(
184+
sessionGrantsScope(
185+
{ authenticated: true, scopes: [AuthOrchestrationReadScope] },
186+
AuthDiagnosticsReadScope,
187+
),
188+
).toBe(true);
189+
expect(
190+
sessionGrantsScope(
191+
{
192+
authenticated: true,
193+
scopes: [AuthOrchestrationReadScope],
194+
permissions: [AuthOrchestrationReadScope],
195+
},
196+
AuthDiagnosticsReadScope,
197+
),
198+
).toBe(false);
199+
});
200+
173201
it("separates passive terminal observation from operations that can change a shell", () => {
174202
for (const method of [
175203
WS_METHODS.terminalObserve,

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ export const RPC_REQUIRED_SCOPES = {
192192
[WS_METHODS.previewReportStatus]: AuthPreviewOperateScope,
193193
[WS_METHODS.subscribePreviewEvents]: AuthOrchestrationReadScope,
194194
[WS_METHODS.subscribeDiscoveredLocalServers]: AuthOrchestrationReadScope,
195+
// Streams full argv and cwd of terminal and non-T3 processes, like process diagnostics.
196+
[WS_METHODS.subscribeThreadServices]: AuthDiagnosticsReadScope,
195197
[WS_METHODS.deviceConfigure]: AuthSettingsWriteScope,
196198
[WS_METHODS.deviceTestHost]: AuthSettingsWriteScope,
197199
[WS_METHODS.deviceList]: AuthOrchestrationReadScope,

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ function createTextGeneration(
347347
title: "Update workflow",
348348
}),
349349
generateReviewGuide: () => Effect.succeed({ stops: [] }),
350+
generateServiceName: () => Effect.succeed({ name: "Web app" }),
350351
...overrides,
351352
};
352353

@@ -396,6 +397,7 @@ function createTextGeneration(
396397
),
397398
),
398399
generateReviewGuide: (input) => implementation.generateReviewGuide(input),
400+
generateServiceName: (input) => implementation.generateServiceName(input),
399401
};
400402
}
401403

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ const RPC_AGGREGATES = {
196196
[WS_METHODS.previewReportStatus]: "preview",
197197
[WS_METHODS.subscribePreviewEvents]: "preview",
198198
[WS_METHODS.subscribeDiscoveredLocalServers]: "preview",
199+
[WS_METHODS.subscribeThreadServices]: "threadServices",
200+
[WS_METHODS.threadServicesStop]: "threadServices",
199201
[WS_METHODS.deviceConfigure]: "device",
200202
[WS_METHODS.deviceTestHost]: "device",
201203
[WS_METHODS.deviceList]: "device",

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import {
120120
type CompiledClaudeModelSelection,
121121
} from "../../claudeModelOptions.ts";
122122
import * as ServerConfig from "../../config.ts";
123+
import * as ThreadProcessRoots from "../../threadServices/ThreadProcessRoots.ts";
123124
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
124125
import { signalProcessGroup } from "@t3tools/provider-core/server/processGroup";
125126
import {
@@ -279,15 +280,25 @@ const WORKFLOW_MEMBER_TRANSCRIPT_FLUSH_MS = 500;
279280
* reads (#3089). Those stay in the CLI's group, so the rest of the group gets SIGKILL once the
280281
* CLI exits for any reason.
281282
*/
282-
function spawnClaudeProcessGroup(options: ClaudeSpawnOptions): ClaudeSpawnedProcess {
283+
function spawnClaudeProcessGroup(
284+
options: ClaudeSpawnOptions,
285+
root?: {
286+
readonly threadId: ThreadId;
287+
readonly roots: ThreadProcessRoots.ThreadProcessRoots["Service"];
288+
},
289+
): ClaudeSpawnedProcess {
283290
const child = NodeChildProcess.spawn(options.command, options.args, {
284291
cwd: options.cwd,
285292
env: options.env,
286293
signal: options.signal,
287294
stdio: ["pipe", "pipe", "ignore"],
288295
detached: true,
289296
});
297+
const pid = child.pid;
298+
// One CLI serves one thread, so anything the agent starts under it belongs to that thread.
299+
if (root !== undefined && pid !== undefined) root.roots.register(root.threadId, pid);
290300
child.once("exit", () => {
301+
if (root !== undefined && pid !== undefined) root.roots.unregister(pid);
291302
try {
292303
signalProcessGroup(child.pid ?? 0, "SIGKILL");
293304
} catch {}
@@ -751,6 +762,11 @@ export const layerQueryRunner: Layer.Layer<
751762
const { native: nativeEventLogger } = yield* ProviderEventLoggers.ProviderEventLoggers;
752763
const agentScope = yield* AgentScope;
753764
const platform = yield* HostProcess.Platform;
765+
// Optional so harnesses that build the runner alone need not provide it; the server shares
766+
// one registry with ThreadServices.
767+
const processRoots = Option.getOrUndefined(
768+
yield* Effect.serviceOption(ThreadProcessRoots.ThreadProcessRoots),
769+
);
754770

755771
return ClaudeAgentSdkQueryRunner.of({
756772
allocateSessionId: crypto
@@ -804,7 +820,15 @@ export const layerQueryRunner: Layer.Layer<
804820
// Windows has no process groups, so there the SDK spawns the CLI itself.
805821
const spawnClaudeCodeProcess =
806822
options.spawnClaudeCodeProcess ??
807-
(platform === "win32" ? undefined : spawnClaudeProcessGroup);
823+
(platform === "win32"
824+
? undefined
825+
: (spawnOptions: ClaudeSpawnOptions) =>
826+
spawnClaudeProcessGroup(
827+
spawnOptions,
828+
processRoots === undefined
829+
? undefined
830+
: { threadId: input.threadId, roots: processRoots },
831+
));
808832
const queryRuntime = yield* Effect.uninterruptibleMask((restore) =>
809833
Effect.try({
810834
try: () =>

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,24 @@ const threadWorktreePathsReadActiveThreads = Effect.gen(function* () {
565565
assert.deepEqual(yield* store.getThreadWorktreePaths(), [
566566
{ threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" },
567567
]);
568+
assert.deepEqual(
569+
// The SQL store is shared with other tests' threads.
570+
(yield* store.getThreadWorkspaces())
571+
.filter(({ projectId }) => projectId === ProjectId.make("project:worktree-paths"))
572+
.toSorted((left, right) => left.threadId.localeCompare(right.threadId)),
573+
[
574+
{
575+
threadId: ThreadId.make("thread:active"),
576+
projectId: ProjectId.make("project:worktree-paths"),
577+
worktreePath: "/worktrees/active",
578+
},
579+
{
580+
threadId: ThreadId.make("thread:local"),
581+
projectId: ProjectId.make("project:worktree-paths"),
582+
worktreePath: null,
583+
},
584+
],
585+
);
568586
});
569587

570588
const commandReadsSkipSettledLeafNodes = Effect.gen(function* () {
@@ -650,7 +668,7 @@ it.effect("memory command reads skip finished leaf nodes of finished runs", () =
650668
commandReadsSkipSettledLeafNodes.pipe(Effect.provide(ProjectionStore.layerMemory)),
651669
);
652670

653-
it.effect("memory worktree path lookup reads only active threads", () =>
671+
it.effect("memory worktree path and workspace lookups read only active threads", () =>
654672
threadWorktreePathsReadActiveThreads.pipe(Effect.provide(ProjectionStore.layerMemory)),
655673
);
656674

@@ -878,7 +896,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
878896
() => runlessNativeSubagentNeedsRecovery,
879897
);
880898
it.effect(
881-
"worktree path lookup reads only active threads",
899+
"worktree path and workspace lookups read only active threads",
882900
() => threadWorktreePathsReadActiveThreads,
883901
);
884902

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import type {
3232
OrchestrationV2ThreadShell,
3333
OrchestrationV2ThreadProjection,
3434
OrchestrationV2TurnItem,
35-
ProjectId,
3635
ProviderSessionId,
3736
ProviderThreadId,
3837
ProviderTurnId,
@@ -63,6 +62,7 @@ import {
6362
ThreadId,
6463
TurnItemId,
6564
NodeId,
65+
ProjectId,
6666
ProviderInstanceId,
6767
} from "@t3tools/contracts";
6868
import {
@@ -426,6 +426,15 @@ export interface ProjectionStoreV2Shape {
426426
ReadonlyArray<{ readonly threadId: ThreadId; readonly worktreePath: string }>,
427427
ProjectionStoreV2Error
428428
>;
429+
/** Where each non-archived thread works, without decoding thread payloads. */
430+
readonly getThreadWorkspaces: () => Effect.Effect<
431+
ReadonlyArray<{
432+
readonly threadId: ThreadId;
433+
readonly projectId: ProjectId;
434+
readonly worktreePath: string | null;
435+
}>,
436+
ProjectionStoreV2Error
437+
>;
429438
readonly getTurnStartContext: (
430439
threadId: ThreadId,
431440
runId: RunId,
@@ -5756,6 +5765,30 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
57565765
Effect.mapError((cause) => new ProjectionStoreSetupError({ cause })),
57575766
);
57585767

5768+
const getThreadWorkspaces: ProjectionStoreV2Shape["getThreadWorkspaces"] = () =>
5769+
sql<{
5770+
readonly thread_id: string;
5771+
readonly project_id: string;
5772+
readonly worktree_path: string | null;
5773+
}>`
5774+
SELECT
5775+
thread_id,
5776+
project_id,
5777+
json_extract(payload_json, '$.worktreePath') AS worktree_path
5778+
FROM orchestration_v2_projection_threads
5779+
WHERE deleted_at IS NULL
5780+
AND json_extract(payload_json, '$.archivedAt') IS NULL
5781+
`.pipe(
5782+
Effect.map((rows) =>
5783+
rows.map((row) => ({
5784+
threadId: ThreadId.make(row.thread_id),
5785+
projectId: ProjectId.make(row.project_id),
5786+
worktreePath: row.worktree_path,
5787+
})),
5788+
),
5789+
Effect.mapError((cause) => new ProjectionStoreSetupError({ cause })),
5790+
);
5791+
57595792
const shellThreadStateFromRow = (input: {
57605793
readonly row: ShellThreadRow;
57615794
readonly runOrdinalsByThreadId: ReadonlyMap<ThreadId, Map<RunId, number>>;
@@ -6090,6 +6123,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60906123
getSettlementCandidates,
60916124
getThreadsWithPullRequests,
60926125
getThreadWorktreePaths,
6126+
getThreadWorkspaces,
60936127
getThreadProjection,
60946128
getTurnStartContext,
60956129
getTurnStartHistory,
@@ -6252,6 +6286,22 @@ export const layerMemory: Layer.Layer<ProjectionStoreV2> = Layer.effect(
62526286
),
62536287
),
62546288
),
6289+
getThreadWorkspaces: () =>
6290+
Ref.get(replayState).pipe(
6291+
Effect.map((state) =>
6292+
[...state.projections.values()].flatMap(({ thread }) =>
6293+
thread.deletedAt === null && thread.archivedAt === null
6294+
? [
6295+
{
6296+
threadId: thread.id,
6297+
projectId: thread.projectId,
6298+
worktreePath: thread.worktreePath,
6299+
},
6300+
]
6301+
: [],
6302+
),
6303+
),
6304+
),
62556305
getThreadsWithPullRequests: (threadId) =>
62566306
Ref.get(replayState).pipe(
62576307
Effect.map((state) =>

‎apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ it.effect(
217217
getSettlementCandidates: () => Effect.die("unused getSettlementCandidates"),
218218
getThreadsWithPullRequests: () => Effect.die("unused getThreadsWithPullRequests"),
219219
getThreadWorktreePaths: () => Effect.die("unused getThreadWorktreePaths"),
220+
getThreadWorkspaces: () => Effect.die("unused getThreadWorkspaces"),
220221
getThreadProjection: () => Effect.die("control effects must not load transcript"),
221222
getTurnStartContext: () => Effect.die("unused"),
222223
getTurnStartHistory: () => Effect.die("unused"),

0 commit comments

Comments
 (0)