The best way to control Claude Code, Codex and more from any computer or phone
refactor(provider-core): share attachment prompts, notifications, and event loggers (#17330)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 8, 2026 at 16:34 UTC
e38b6a188fafd499df347331f8c8279ff320c207
30 files changed
+138
-84
apps/server/scripts/record-grok-acp-replay-fixture.ts
+1
-1
@@ -44,7 +44,7 @@ import { makeReplayServerConfig } from "../src/orchestration-v2/testkit/Provider
44
import * as ProviderReplayHarness from "../src/orchestration-v2/testkit/ProviderReplayHarness.ts";
45
import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace";
46
import { makeGrokAcpRuntime } from "../src/provider/acp/GrokAcpSupport.ts";
47
-import { buildRuntimeInstructions } from "../src/provider/RuntimeInstructions.ts";
47
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
48
49
const wallClock = Clock.Clock.defaultValue();
50
const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts
+5
-4
@@ -98,14 +98,14 @@ import {
98
t3AcpPromptWithInstructions,
99
type T3AcpInstructionState,
100
} from "@t3tools/provider-core/server/orchestrationInstructions";
101
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
101
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
102
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
103
import { type ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests";
104
import {
105
type BackgroundWork,
106
type BackgroundWorkReport,
107
backgroundWorkNotification,
108
-} from "../Notification.ts";
108
+} from "@t3tools/provider-core/server/notification";
109
import {
110
makeProviderFailure,
111
makeProviderRetryTurnItem,
@@ -114,7 +114,7 @@ import { acpSelectionTransition } from "@t3tools/provider-core/server/selectionT
114
import {
115
isProviderNativeImageAttachment,
116
providerMessageTextWithAttachmentPaths,
117
-} from "../AttachmentPrompt.ts";
117
+} from "@t3tools/provider-core/server/attachmentPrompt";
118
import {
119
makeSubagentChildThread,
120
makeSubagentConversationArtifacts,
@@ -6781,7 +6781,8 @@ export function makeAcpAdapterV2(
6781
const messageText = providerMessageTextWithAttachmentPaths({
6782
text: turnInput.message.text,
6783
attachments: turnInput.message.attachments,
6784
- attachmentsDir: serverConfig.attachmentsDir,
6784
+ resolveAttachmentPath: (attachment) =>
6785
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
6786
});
6787
const text = t3AcpPromptWithInstructions({
6788
prompt: messageText,
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+8
-4
@@ -112,7 +112,7 @@ import {
112
import type { ServerProviderShape } from "@t3tools/provider-core/server/snapshot";
113
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
114
import { T3_CODE_ORCHESTRATION_INSTRUCTIONS } from "@t3tools/provider-core/server/orchestrationInstructions";
115
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
115
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
116
import {
117
mcpToolPresentation,
118
normalizeMcpText,
@@ -124,14 +124,17 @@ import {
124
makeProviderRetryTurnItem,
125
} from "@t3tools/provider-core/server/failure";
126
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
127
-import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts";
127
+import { providerMessageTextWithAttachmentPaths } from "@t3tools/provider-core/server/attachmentPrompt";
128
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
129
import {
130
ProviderAdapterDriverCreateError,
131
type ProviderAdapterDriver,
132
type ProviderAdapterDriverCreateInput,
133
} from "@t3tools/provider-core/server/adapterDriver";
134
-import { type BackgroundWorkReport, backgroundWorkNotification } from "../Notification.ts";
134
+import {
135
+ type BackgroundWorkReport,
136
+ backgroundWorkNotification,
137
+} from "@t3tools/provider-core/server/notification";
138
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
139
import {
140
makeSubagentChildThread,
@@ -1344,7 +1347,8 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
1347
const textWithAttachmentPaths = providerMessageTextWithAttachmentPaths({
1348
text: input.text,
1349
attachments: input.attachments,
1347
- attachmentsDir: input.attachmentsDir,
1350
+ resolveAttachmentPath: (attachment) =>
1351
+ resolveAttachmentPath({ attachmentsDir: input.attachmentsDir, attachment }),
1352
});
1353
1354
const dispatch =
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+4
-3
@@ -126,7 +126,7 @@ import {
126
type ProviderContinuationRequest,
127
ProviderContinuationRequests,
128
} from "@t3tools/provider-core/server/continuationRequests";
129
-import { backgroundWorkNotification } from "../Notification.ts";
129
+import { backgroundWorkNotification } from "@t3tools/provider-core/server/notification";
130
import {
131
makeProviderFailure,
132
makeProviderFailureTurnItem,
@@ -136,7 +136,7 @@ import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/sel
136
import {
137
isProviderNativeImageAttachment,
138
providerMessageTextWithAttachmentPaths,
139
-} from "../AttachmentPrompt.ts";
139
+} from "@t3tools/provider-core/server/attachmentPrompt";
140
import {
141
ProviderAdapterEnsureThreadError,
142
ProviderAdapterForkThreadError,
@@ -3150,7 +3150,8 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
3150
const text = providerMessageTextWithAttachmentPaths({
3151
text: codexSkillMentionText(turnInput.message.text),
3152
attachments: turnInput.message.attachments,
3153
- attachmentsDir: serverConfig.attachmentsDir,
3153
+ resolveAttachmentPath: (attachment) =>
3154
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
3155
});
3156
if (text.length > 0) {
3157
inputItems.push({
apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.ts
+4
-3
@@ -55,14 +55,14 @@ import {
55
} from "../../provider/Drivers/CursorSkills.ts";
56
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
57
import { t3OrchestrationPromptForFirstRun } from "@t3tools/provider-core/server/orchestrationInstructions";
58
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
58
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
59
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
60
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
61
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
62
import {
63
isProviderNativeImageAttachment,
64
providerMessageTextWithAttachmentPaths,
65
-} from "../AttachmentPrompt.ts";
65
+} from "@t3tools/provider-core/server/attachmentPrompt";
66
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
67
import {
68
ProviderAdapterDriverCreateError,
@@ -2133,7 +2133,8 @@ export function makeCursorAdapterV2(
2133
? rawText
2134
: rewriteCursorSkillMentions(rawText, cursorSkillNames),
2135
attachments: turnInput.message.attachments,
2136
- attachmentsDir: serverConfig.attachmentsDir,
2136
+ resolveAttachmentPath: (attachment) =>
2137
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
2138
}),
2139
runOrdinal: turnInput.runOrdinal,
2140
hasT3Mcp: cursorMcpServers(turnInput.threadId) !== undefined,
apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.ts
+11
-4
@@ -38,7 +38,7 @@ import * as Stream from "effect/Stream";
38
import { resolveAttachmentPath } from "../../attachmentStore.ts";
39
import * as ServerConfig from "../../config.ts";
40
import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
41
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
41
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
42
import {
43
museModelCapabilities,
44
resolveMuseReasoningEffort,
@@ -71,7 +71,7 @@ import type { EventNdjsonLogger } from "../../provider/EventNdjsonLogger.ts";
71
import {
72
providerMessageTextWithAttachmentPaths,
73
isProviderNativeImageAttachment,
74
-} from "../AttachmentPrompt.ts";
74
+} from "@t3tools/provider-core/server/attachmentPrompt";
75
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
76
import {
77
ProviderAdapterEnsureThreadError,
@@ -96,7 +96,10 @@ import {
96
type ProviderAdapterV2TurnInput,
97
type ProviderAdapterV2TurnMessage,
98
} from "@t3tools/provider-core/server/ProviderAdapter";
99
-import { backgroundWorkNotification, type BackgroundWorkReport } from "../Notification.ts";
99
+import {
100
+ backgroundWorkNotification,
101
+ type BackgroundWorkReport,
102
+} from "@t3tools/provider-core/server/notification";
103
import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
104
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
105
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
@@ -1598,7 +1601,11 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
1601
const text = providerMessageTextWithAttachmentPaths({
1602
text: message.text,
1603
attachments: message.attachments,
1601
- attachmentsDir: options.serverConfig.attachmentsDir,
1604
+ resolveAttachmentPath: (attachment) =>
1605
+ resolveAttachmentPath({
1606
+ attachmentsDir: options.serverConfig.attachmentsDir,
1607
+ attachment,
1608
+ }),
1609
});
1610
if (text) parts.push({ type: "text", text });
1611
for (const attachment of message.attachments)
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.ts
+14
-5
@@ -70,6 +70,7 @@ import * as Schema from "effect/Schema";
70
import * as Semaphore from "effect/Semaphore";
71
import * as Stream from "effect/Stream";
72
73
+import { resolveAttachmentPath } from "../../attachmentStore.ts";
74
import * as ServerConfig from "../../config.ts";
75
import { paginate, type OpenCode2StreamEvent } from "../../provider/opencode2/OpenCode2Client.ts";
76
import * as OpenCode2Server from "../../provider/opencode2/OpenCode2Server.ts";
@@ -78,16 +79,19 @@ import {
79
type OpenCodeRuntimeError,
80
} from "../../provider/opencodeRuntime.ts";
81
import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
81
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
82
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
83
import { t3OrchestrationSystemPrompt } from "@t3tools/provider-core/server/orchestrationInstructions";
84
import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens";
85
import * as KeyedLock from "@t3tools/shared/KeyedLock";
86
import { getModelSelectionStringOptionValue, modelSelectionsEqual } from "@t3tools/shared/model";
87
import { causeErrorTag } from "@t3tools/shared/observability";
88
88
-import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts";
89
+import { providerMessageTextWithAttachmentPaths } from "@t3tools/provider-core/server/attachmentPrompt";
90
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
90
-import { backgroundWorkNotification, type BackgroundWorkReport } from "../Notification.ts";
91
+import {
92
+ backgroundWorkNotification,
93
+ type BackgroundWorkReport,
94
+} from "@t3tools/provider-core/server/notification";
95
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
96
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
97
import {
@@ -3212,7 +3216,8 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3216
providerMessageTextWithAttachmentPaths({
3217
text: turnInput.message.text,
3218
attachments: turnInput.message.attachments,
3215
- attachmentsDir: serverConfig.attachmentsDir,
3219
+ resolveAttachmentPath: (attachment) =>
3220
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
3221
}).trim();
3222
3223
const removeMcp = (mcp: { readonly name: string; readonly directory: string }) =>
@@ -3893,7 +3898,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3898
text: providerMessageTextWithAttachmentPaths({
3899
text: steerInput.message.text,
3900
attachments: steerInput.message.attachments,
3896
- attachmentsDir: serverConfig.attachmentsDir,
3901
+ resolveAttachmentPath: (attachment) =>
3902
+ resolveAttachmentPath({
3903
+ attachmentsDir: serverConfig.attachmentsDir,
3904
+ attachment,
3905
+ }),
3906
}).trim(),
3907
delivery: "steer",
3908
})
apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.ts
+9
-4
@@ -66,12 +66,12 @@ import {
66
} from "../../provider/NativeProtocolLogging.ts";
67
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
68
import { t3OrchestrationSystemPrompt } from "@t3tools/provider-core/server/orchestrationInstructions";
69
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
69
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
70
import * as OpenCodeRuntime from "../../provider/opencodeRuntime.ts";
71
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
72
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
73
import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition";
74
-import { providerMessageTextWithAttachmentPaths } from "../AttachmentPrompt.ts";
74
+import { providerMessageTextWithAttachmentPaths } from "@t3tools/provider-core/server/attachmentPrompt";
75
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
76
import {
77
ProviderAdapterDriverCreateError,
@@ -2853,7 +2853,8 @@ export function makeOpenCodeAdapterV2(
2853
const text = providerMessageTextWithAttachmentPaths({
2854
text: turnInput.message.text,
2855
attachments: turnInput.message.attachments,
2856
- attachmentsDir: serverConfig.attachmentsDir,
2856
+ resolveAttachmentPath: (attachment) =>
2857
+ resolveAttachmentPath({ attachmentsDir: serverConfig.attachmentsDir, attachment }),
2858
}).trim();
2859
const files = OpenCodeRuntime.toOpenCodeFileParts({
2860
attachments: turnInput.message.attachments,
@@ -3356,7 +3357,11 @@ export function makeOpenCodeAdapterV2(
3357
const text = providerMessageTextWithAttachmentPaths({
3358
text: steerInput.message.text,
3359
attachments: steerInput.message.attachments,
3359
- attachmentsDir: serverConfig.attachmentsDir,
3360
+ resolveAttachmentPath: (attachment) =>
3361
+ resolveAttachmentPath({
3362
+ attachmentsDir: serverConfig.attachmentsDir,
3363
+ attachment,
3364
+ }),
3365
}).trim();
3366
const files = OpenCodeRuntime.toOpenCodeFileParts({
3367
attachments: steerInput.message.attachments,
apps/server/src/orchestration-v2/Orchestrator.ts
+1
-1
@@ -85,7 +85,7 @@ import { CheckpointServiceV2 } from "./CheckpointService.ts";
85
import { CommandPolicyV2, resolveMessageDispatchIntent } from "./CommandPolicy.ts";
86
import { CommandReceiptStoreV2 } from "./CommandReceiptStore.ts";
87
import { ContextHandoffServiceV2 } from "./ContextHandoffService.ts";
88
-import { notificationTurnItem } from "./Notification.ts";
88
+import { notificationTurnItem } from "@t3tools/provider-core/server/notification";
89
import { isRestartNoteSource } from "./RestartBackgroundNote.ts";
90
import { isUndeliveredMailboxSteer } from "./NotificationMailbox.ts";
91
import { EventSinkV2 } from "./EventSink.ts";
apps/server/src/orchestration-v2/testkit/ReplayRuntimeInstructions.ts
+1
-1
@@ -1,6 +1,6 @@
1
import type { ProviderDriverKind, ProviderReplayTranscript } from "@t3tools/contracts";
2
3
-import { buildRuntimeInstructions } from "../../provider/RuntimeInstructions.ts";
3
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
4
5
/** Adds current runtime context to legacy prompt expectations, keeping outbound matching exact. */
6
export function materializeReplayTranscriptRuntimeInstructions(
apps/server/src/provider/CodexDeveloperInstructions.ts
+1
-1
@@ -1,6 +1,6 @@
1
import type { ProviderInteractionMode } from "@t3tools/contracts";
2
import type { V2TurnStartParams__AdditionalContextEntry } from "effect-codex-app-server/schema";
3
-import { buildRuntimeInstructions } from "./RuntimeInstructions.ts";
3
+import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
4
5
import {
6
T3_CODE_BROWSER_TOOL_INSTRUCTIONS,
apps/server/src/provider/Drivers/AntigravityDriver.ts
+1
-1
@@ -60,7 +60,7 @@ import {
60
type ProviderInstance,
61
} from "@t3tools/provider-core/server/driver";
62
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
63
-import { withInstanceIdentity } from "./instanceIdentity.ts";
63
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
64
import { discoverAntigravitySkills, resolveAntigravityUserHome } from "./AntigravitySkills.ts";
65
66
const DRIVER = ProviderDriverKind.make("antigravity");
apps/server/src/provider/Drivers/ClaudeDriver.ts
+1
-1
@@ -50,7 +50,7 @@ import {
50
type ProviderDriver,
51
type ProviderInstance,
52
} from "@t3tools/provider-core/server/driver";
53
-import { withInstanceIdentity } from "./instanceIdentity.ts";
53
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
54
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
55
import {
56
enrichProviderSnapshotWithVersionAdvisory,
apps/server/src/provider/Drivers/CodexDriver.ts
+1
-1
@@ -51,7 +51,7 @@ import { resolveCodexLaunchArgs } from "../codexLaunchArgs.ts";
51
import { makeManagedServerProvider } from "@t3tools/provider-core/server/managedProvider";
52
import * as ModelManifest from "../ModelManifest.ts";
53
import type { ProviderDriver, ProviderInstance } from "@t3tools/provider-core/server/driver";
54
-import { withInstanceIdentity } from "./instanceIdentity.ts";
54
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
55
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
56
import {
57
enrichProviderSnapshotWithVersionAdvisory,
apps/server/src/provider/Drivers/CodexManagedProvider.ts
+1
-1
@@ -21,7 +21,7 @@ import {
21
type ProviderInstance,
22
} from "@t3tools/provider-core/server/driver";
23
import { codexContinuationIdentity } from "./CodexHomeLayout.ts";
24
-import { withInstanceIdentity } from "./instanceIdentity.ts";
24
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
25
import { HttpClient } from "effect/http";
26
const DRIVER = ProviderDriverKind.make("codex");
27
apps/server/src/provider/Drivers/CursorDriver.ts
+1
-1
@@ -35,7 +35,7 @@ import {
35
type ProviderDriver,
36
type ProviderInstance,
37
} from "@t3tools/provider-core/server/driver";
38
-import { withInstanceIdentity } from "./instanceIdentity.ts";
38
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
39
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
40
import { makeManualOnlyProviderMaintenanceCapabilities } from "@t3tools/provider-core/server/maintenanceResolver";
41
import {
apps/server/src/provider/Drivers/GrokDriver.ts
+1
-1
@@ -28,7 +28,7 @@ import {
28
type ProviderDriver,
29
type ProviderInstance,
30
} from "@t3tools/provider-core/server/driver";
31
-import { withInstanceIdentity } from "./instanceIdentity.ts";
31
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
32
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
33
import { discoverGrokSkills } from "./GrokSkills.ts";
34
import {
apps/server/src/provider/Drivers/MuseDriver.ts
+1
-1
@@ -35,7 +35,7 @@ import {
35
makeProviderSnapshotSettingsSource,
36
type ProviderSnapshotSettings,
37
} from "@t3tools/provider-core/server/snapshotSettings";
38
-import { withInstanceIdentity } from "./instanceIdentity.ts";
38
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
39
40
const DRIVER_KIND = ProviderDriverKind.make("muse");
41
const decodeMuseSettings = Schema.decodeSync(MuseSettings);
apps/server/src/provider/Drivers/OpenCodeDriver.ts
+1
-1
@@ -59,7 +59,7 @@ import {
59
type ProviderDriver,
60
type ProviderInstance,
61
} from "@t3tools/provider-core/server/driver";
62
-import { withInstanceIdentity } from "./instanceIdentity.ts";
62
+import { withInstanceIdentity } from "@t3tools/provider-core/server/instanceIdentity";
63
import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
64
import {
65
enrichProviderSnapshotWithVersionAdvisory,
apps/server/src/provider/EventNdjsonLogger.ts
+2
-5
@@ -9,6 +9,7 @@ import * as NodeFS from "node:fs";
9
import * as NodePath from "node:path";
10
11
import type { ThreadId } from "@t3tools/contracts";
12
+import type { EventNdjsonLogger } from "@t3tools/provider-core/server/ProviderEventLoggers";
13
import { RotatingFileSink } from "@t3tools/shared/logging";
14
import { errorTag } from "@t3tools/shared/observability";
15
import * as Clock from "effect/Clock";
@@ -63,11 +64,7 @@ const transientAcpUpdates = new Set(["agent_message_chunk", "agent_thought_chunk
64
65
export type EventNdjsonStream = "native" | "canonical" | "orchestration";
66
66
-export interface EventNdjsonLogger {
67
- readonly filePath: string;
68
- readonly write: (event: unknown, threadId: ThreadId | null) => Effect.Effect<void>;
69
- readonly close: () => Effect.Effect<void>;
70
-}
67
+export type { EventNdjsonLogger };
68
69
export interface EventNdjsonLogStore {
70
readonly filePath: string;
apps/server/src/provider/ProviderEventLoggers.ts
+5
-26
@@ -24,39 +24,18 @@
24
*
25
* @module provider/ProviderEventLoggers
26
*/
27
-import * as Context from "effect/Context";
27
import * as Effect from "effect/Effect";
28
import * as Layer from "effect/Layer";
29
30
import * as ServerConfig from "../config.ts";
31
import * as ResourceAttribution from "../resourceTelemetry/ResourceAttribution.ts";
33
-import * as EventNdjsonLogger from "./EventNdjsonLogger.ts";
34
-
35
-/**
36
- * Shared logger pair for native + canonical provider event streams.
37
- *
38
- * Service value is intentionally a struct of two optional loggers rather
39
- * than two parallel tags. Construction site is one place
40
- * (`layer`); consumers (drivers, `ProviderService`) read one tag and pluck the
41
- * field they need.
42
- */
43
-export class ProviderEventLoggers extends Context.Service<
32
+import {
33
+ NoOpProviderEventLoggers,
34
ProviderEventLoggers,
45
- {
46
- readonly native: EventNdjsonLogger.EventNdjsonLogger | undefined;
47
- readonly canonical: EventNdjsonLogger.EventNdjsonLogger | undefined;
48
- }
49
->()("t3/provider/ProviderEventLoggers") {}
35
+} from "@t3tools/provider-core/server/ProviderEventLoggers";
36
+import * as EventNdjsonLogger from "./EventNdjsonLogger.ts";
37
51
-/**
52
- * Constant value used by tests / boot layers that want to opt out of native
53
- * + canonical logging entirely. Keeps the tag non-optional in the type
54
- * system while letting the runtime treat absence as a no-op.
55
- */
56
-export const NoOpProviderEventLoggers: ProviderEventLoggers["Service"] = {
57
- native: undefined,
58
- canonical: undefined,
59
-};
38
+export { NoOpProviderEventLoggers, ProviderEventLoggers };
39
40
/**
41
* Builds both stream views over one shared store. Setup failures are logged
packages/provider-core/package.json
+20
@@ -11,6 +11,10 @@
11
"types": "./src/server/adapterDriver.ts",
12
"import": "./src/server/adapterDriver.ts"
13
},
14
+ "./server/attachmentPrompt": {
15
+ "types": "./src/server/attachmentPrompt.ts",
16
+ "import": "./src/server/attachmentPrompt.ts"
17
+ },
18
"./server/auth": {
19
"types": "./src/server/auth.ts",
20
"import": "./src/server/auth.ts"
@@ -47,6 +51,10 @@
51
"types": "./src/server/instanceEnvironment.ts",
52
"import": "./src/server/instanceEnvironment.ts"
53
},
54
+ "./server/instanceIdentity": {
55
+ "types": "./src/server/instanceIdentity.ts",
56
+ "import": "./src/server/instanceIdentity.ts"
57
+ },
58
"./server/maintenance": {
59
"types": "./src/server/maintenance.ts",
60
"import": "./src/server/maintenance.ts"
@@ -67,6 +75,10 @@
75
"types": "./src/server/mcpToolPresentation.ts",
76
"import": "./src/server/mcpToolPresentation.ts"
77
},
78
+ "./server/notification": {
79
+ "types": "./src/server/notification.ts",
80
+ "import": "./src/server/notification.ts"
81
+ },
82
"./server/orchestrationInstructions": {
83
"types": "./src/server/orchestrationInstructions.ts",
84
"import": "./src/server/orchestrationInstructions.ts"
@@ -83,6 +95,10 @@
95
"types": "./src/server/ProviderAdapter.ts",
96
"import": "./src/server/ProviderAdapter.ts"
97
},
98
+ "./server/ProviderEventLoggers": {
99
+ "types": "./src/server/ProviderEventLoggers.ts",
100
+ "import": "./src/server/ProviderEventLoggers.ts"
101
+ },
102
"./server/ProviderHost": {
103
"types": "./src/server/ProviderHost.ts",
104
"import": "./src/server/ProviderHost.ts"
@@ -91,6 +107,10 @@
107
"types": "./src/server/randomUuid.ts",
108
"import": "./src/server/randomUuid.ts"
109
},
110
+ "./server/runtimeInstructions": {
111
+ "types": "./src/server/runtimeInstructions.ts",
112
+ "import": "./src/server/runtimeInstructions.ts"
113
+ },
114
"./server/selectionTransition": {
115
"types": "./src/server/selectionTransition.ts",
116
"import": "./src/server/selectionTransition.ts"
packages/provider-core/src/server/ProviderEventLoggers.ts
new
+30
@@ -0,0 +1,30 @@
1
+/**
2
+ * Provider event logging as the server offers it to drivers: one stream for
3
+ * the provider's native protocol frames and one for canonical orchestration
4
+ * events. Either logger is absent when diagnostics logging could not start.
5
+ *
6
+ * @module provider-core/server/ProviderEventLoggers
7
+ */
8
+import type { ThreadId } from "@t3tools/contracts";
9
+import * as Context from "effect/Context";
10
+import type * as Effect from "effect/Effect";
11
+
12
+export interface EventNdjsonLogger {
13
+ readonly filePath: string;
14
+ readonly write: (event: unknown, threadId: ThreadId | null) => Effect.Effect<void>;
15
+ readonly close: () => Effect.Effect<void>;
16
+}
17
+
18
+export class ProviderEventLoggers extends Context.Service<
19
+ ProviderEventLoggers,
20
+ {
21
+ readonly native: EventNdjsonLogger | undefined;
22
+ readonly canonical: EventNdjsonLogger | undefined;
23
+ }
24
+>()("@t3tools/provider-core/server/ProviderEventLoggers") {}
25
+
26
+/** Logging turned off: for tests and boot layers that skip diagnostics. */
27
+export const NoOpProviderEventLoggers: ProviderEventLoggers["Service"] = {
28
+ native: undefined,
29
+ canonical: undefined,
30
+};
packages/provider-core/src/server/attachmentPrompt.test.ts
renamed
+9
-5
@@ -9,7 +9,7 @@ import { assert, describe, it } from "@effect/vitest";
9
import {
10
isProviderNativeImageAttachment,
11
providerMessageTextWithAttachmentPaths,
12
-} from "./AttachmentPrompt.ts";
12
+} from "./attachmentPrompt.ts";
13
14
const document = ChatFileAttachment.make({
15
id: ChatAttachmentId.make("file-document"),
@@ -26,13 +26,17 @@ const image = ChatImageAttachment.make({
26
sizeBytes: 456,
27
});
28
29
+// Stands in for the host's resolver, which maps stored attachments to their files.
30
+const resolveAttachmentPath = (attachment: { readonly id: string; readonly name: string }) =>
31
+ `/attachments/${attachment.id}${attachment.name.slice(attachment.name.lastIndexOf("."))}`;
32
+
33
describe("provider attachment prompts", () => {
34
it("appends resolvable file paths for documents and images", () => {
35
assert.equal(
36
providerMessageTextWithAttachmentPaths({
37
text: "Review these.",
38
attachments: [document, image],
35
- attachmentsDir: "/attachments",
39
+ resolveAttachmentPath,
40
}),
41
'Review these.\n\n[Attached file "spec.pdf" is saved at: /attachments/file-document.pdf]\n' +
42
'\n[Attached image "diagram.png" is saved at: /attachments/file-image.png]',
@@ -53,7 +57,7 @@ describe("provider attachment prompts", () => {
57
const text = providerMessageTextWithAttachmentPaths({
58
text: "Fix this.",
59
attachments: [captured],
56
- attachmentsDir: "/attachments",
60
+ resolveAttachmentPath,
61
});
62
63
assert.include(
@@ -103,7 +107,7 @@ describe("provider attachment prompts", () => {
107
const text = providerMessageTextWithAttachmentPaths({
108
text: "Describe this.",
109
attachments: [captured],
106
- attachmentsDir: "/attachments",
110
+ resolveAttachmentPath,
111
});
112
113
assert.include(
@@ -133,7 +137,7 @@ describe("provider attachment prompts", () => {
137
const text = providerMessageTextWithAttachmentPaths({
138
text: "Fix this.",
139
attachments,
136
- attachmentsDir: "/attachments",
140
+ resolveAttachmentPath,
141
});
142
143
assert.isAtMost(text.length, PROVIDER_SEND_TURN_MAX_INPUT_CHARS);
packages/provider-core/src/server/attachmentPrompt.ts
renamed
+3
-7
@@ -8,8 +8,6 @@ import {
8
} from "@t3tools/contracts";
9
import * as Schema from "effect/Schema";
10
11
-import { resolveAttachmentPath } from "../attachmentStore.ts";
12
-
11
const encodePromptJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
12
13
interface SnapShotPromptAccessibilityNode {
@@ -161,7 +159,8 @@ export function isProviderNativeImageAttachment(attachment: ChatAttachment): boo
159
export function providerMessageTextWithAttachmentPaths(input: {
160
readonly text: string;
161
readonly attachments: ReadonlyArray<ChatAttachment>;
164
- readonly attachmentsDir: string;
162
+ /** Absolute path of a stored attachment, such as `ProviderHost.resolveAttachmentPath`. */
163
+ readonly resolveAttachmentPath: (attachment: ChatAttachment) => string | null;
164
}): string {
165
let text = input.text;
166
const appendContext = (context: string | undefined) => {
@@ -171,10 +170,7 @@ export function providerMessageTextWithAttachmentPaths(input: {
170
};
171
172
for (const attachment of input.attachments) {
174
- const path = resolveAttachmentPath({
175
- attachmentsDir: input.attachmentsDir,
176
- attachment,
177
- });
173
+ const path = input.resolveAttachmentPath(attachment);
174
appendContext(
175
path === null
176
? undefined
packages/provider-core/src/server/instanceIdentity.ts
renamed
packages/provider-core/src/server/notification.test.ts
renamed
+1
-1
@@ -10,7 +10,7 @@ import {
10
} from "@t3tools/contracts";
11
import * as DateTime from "effect/DateTime";
12
13
-import { backgroundWorkNotification, notificationTurnItem } from "./Notification.ts";
13
+import { backgroundWorkNotification, notificationTurnItem } from "./notification.ts";
14
15
const childThreadId = ThreadId.make("thread:child");
16
packages/provider-core/src/server/notification.ts
renamed
packages/provider-core/src/server/runtimeInstructions.test.ts
renamed
+1
-1
@@ -1,5 +1,5 @@
1
import { describe, expect, it } from "vite-plus/test";
2
-import { buildRuntimeInstructions } from "./RuntimeInstructions.ts";
2
+import { buildRuntimeInstructions } from "./runtimeInstructions.ts";
3
4
describe("buildRuntimeInstructions", () => {
5
it("requires explicit registration of every PR and stack layer", () => {