Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4a2302607 | ||
|
|
e9f549048b | ||
|
|
f0dc3c5ac9 | ||
|
|
3dd82e21b0 | ||
|
|
06c2b010c6 | ||
|
|
b9fad2305e | ||
|
|
25b02f4ba2 |
No files matched your search
+4
-1
@@ -9,6 +9,7 @@
|
||||
"**/routeTree.gen.ts"
|
||||
],
|
||||
"plugins": ["eslint", "oxc", "react", "unicorn", "typescript"],
|
||||
"jsPlugins": ["./oxlint-plugin-t3code/index.ts"],
|
||||
"categories": {
|
||||
"correctness": "warn",
|
||||
"suspicious": "warn",
|
||||
@@ -17,6 +18,8 @@
|
||||
"rules": {
|
||||
"react-in-jsx-scope": "off",
|
||||
"eslint/no-shadow": "off",
|
||||
"eslint/no-await-in-loop": "off"
|
||||
"eslint/no-await-in-loop": "off",
|
||||
"eslint/no-underscore-dangle": "off",
|
||||
"t3code/no-inline-schema-compile": "warn"
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ const COMMIT_HASH_DISPLAY_LENGTH = 12;
|
||||
const AppPackageMetadata = Schema.Struct({
|
||||
t3codeCommitHash: Schema.optional(Schema.String),
|
||||
});
|
||||
const decodeAppPackageMetadata = Schema.decodeEffect(Schema.fromJsonString(AppPackageMetadata));
|
||||
|
||||
export interface DesktopAppIdentityShape {
|
||||
readonly resolveUserDataPath: Effect.Effect<string>;
|
||||
@@ -47,7 +48,7 @@ const make = Effect.gen(function* () {
|
||||
return yield* Option.match(raw, {
|
||||
onNone: () => Effect.succeed(Option.none<string>()),
|
||||
onSome: (value) =>
|
||||
Schema.decodeEffect(Schema.fromJsonString(AppPackageMetadata))(value).pipe(
|
||||
decodeAppPackageMetadata(value).pipe(
|
||||
Effect.map((parsed) =>
|
||||
Option.fromNullishOr(parsed.t3codeCommitHash).pipe(Option.flatMap(normalizeCommitHash)),
|
||||
),
|
||||
|
||||
@@ -15,7 +15,7 @@ import * as Schema from "effect/Schema";
|
||||
import * as Sink from "effect/Sink";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
@@ -25,6 +25,10 @@ import * as DesktopObservability from "../app/DesktopObservability.ts";
|
||||
import * as DesktopState from "../app/DesktopState.ts";
|
||||
import * as DesktopWindow from "../window/DesktopWindow.ts";
|
||||
|
||||
const decodeDesktopBackendBootstrap = Schema.decodeEffect(
|
||||
Schema.fromJsonString(DesktopBackendBootstrap),
|
||||
);
|
||||
|
||||
const baseConfig: DesktopBackendManager.DesktopBackendStartConfig = {
|
||||
executablePath: "/electron",
|
||||
entryPath: "/server/bin.mjs",
|
||||
@@ -94,7 +98,7 @@ const healthyHttpClientLayer = httpClientLayer((request) =>
|
||||
);
|
||||
|
||||
function decodeBootstrap(raw: string) {
|
||||
return Schema.decodeEffect(Schema.fromJsonString(DesktopBackendBootstrap))(raw);
|
||||
return decodeDesktopBackendBootstrap(raw);
|
||||
}
|
||||
|
||||
function makeManagerLayer(input: {
|
||||
|
||||
@@ -20,10 +20,14 @@ const ClientSettingsDocumentSchema = Schema.Struct({
|
||||
|
||||
const ClientSettingsJson = fromLenientJson(ClientSettingsSchema);
|
||||
const LegacyClientSettingsDocumentJson = fromLenientJson(ClientSettingsDocumentSchema);
|
||||
const decodeLegacyClientSettingsDocumentJson = Schema.decodeEffect(
|
||||
LegacyClientSettingsDocumentJson,
|
||||
);
|
||||
const decodeClientSettingsJsonValue = Schema.decodeEffect(ClientSettingsJson);
|
||||
const decodeClientSettingsJson = (raw: string): Effect.Effect<ClientSettings, Schema.SchemaError> =>
|
||||
Schema.decodeEffect(LegacyClientSettingsDocumentJson)(raw).pipe(
|
||||
decodeLegacyClientSettingsDocumentJson(raw).pipe(
|
||||
Effect.map((document) => document.settings),
|
||||
Effect.catch(() => Schema.decodeEffect(ClientSettingsJson)(raw)),
|
||||
Effect.catch(() => decodeClientSettingsJsonValue(raw)),
|
||||
);
|
||||
const encodeClientSettingsJson = Schema.encodeEffect(ClientSettingsJson);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
DesktopSshEnvironmentBootstrap,
|
||||
DesktopSshEnvironmentTarget,
|
||||
} from "@t3tools/contracts";
|
||||
import { type NetError, NetService } from "@t3tools/shared/Net";
|
||||
import * as NetService from "@t3tools/shared/Net";
|
||||
import {
|
||||
SshPasswordPrompt,
|
||||
type SshPasswordPromptShape,
|
||||
@@ -35,7 +35,7 @@ export type DesktopSshEnvironmentRuntimeServices =
|
||||
| FileSystem.FileSystem
|
||||
| Path.Path
|
||||
| HttpClient.HttpClient
|
||||
| NetService;
|
||||
| NetService.NetService;
|
||||
|
||||
export type DesktopSshEnvironmentOperationError =
|
||||
| SshCommandError
|
||||
@@ -44,7 +44,7 @@ export type DesktopSshEnvironmentOperationError =
|
||||
| SshPairingError
|
||||
| SshReadinessError
|
||||
| SshPasswordPromptError
|
||||
| NetError;
|
||||
| NetService.NetError;
|
||||
|
||||
export type DesktopSshEnvironmentDiscoverError = SshHostDiscoveryError;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import type * as Electron from "electron";
|
||||
|
||||
import * as ElectronWindow from "../electron/ElectronWindow.ts";
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
|
||||
import * as DesktopBackendManager from "../backend/DesktopBackendManager.ts";
|
||||
import * as DesktopConfig from "../app/DesktopConfig.ts";
|
||||
|
||||
@@ -54,6 +54,9 @@ const UpdateInfo = Schema.Struct({
|
||||
const DownloadProgressInfo = Schema.Struct({
|
||||
percent: Schema.Number,
|
||||
});
|
||||
const decodeAppUpdateYmlConfig = Schema.decodeUnknownEffect(AppUpdateYmlConfig);
|
||||
const decodeUpdateInfo = Schema.decodeUnknownEffect(UpdateInfo);
|
||||
const decodeDownloadProgressInfo = Schema.decodeUnknownEffect(DownloadProgressInfo);
|
||||
|
||||
const currentIsoTimestamp = DateTime.now.pipe(Effect.map(DateTime.formatIso));
|
||||
|
||||
@@ -115,7 +118,7 @@ function parseAppUpdateYml(raw: string): Effect.Effect<Option.Option<AppUpdateYm
|
||||
}
|
||||
}
|
||||
|
||||
return Schema.decodeUnknownEffect(AppUpdateYmlConfig)(entries).pipe(
|
||||
return decodeAppUpdateYmlConfig(entries).pipe(
|
||||
Effect.map((config) => (config.provider ? Option.some(config) : Option.none())),
|
||||
Effect.catch(() => Effect.succeed(Option.none<AppUpdateYmlConfig>())),
|
||||
);
|
||||
@@ -408,7 +411,7 @@ const make = Effect.gen(function* () {
|
||||
const handleUpdateAvailable = Effect.fn("desktop.updates.handleUpdateAvailable")(function* (
|
||||
raw: unknown,
|
||||
) {
|
||||
yield* Schema.decodeUnknownEffect(UpdateInfo)(raw).pipe(
|
||||
yield* decodeUpdateInfo(raw).pipe(
|
||||
Effect.flatMap(
|
||||
Effect.fn("desktop.updates.applyUpdateAvailable")(function* (info) {
|
||||
const state = yield* Ref.get(updateStateRef);
|
||||
@@ -479,7 +482,7 @@ const make = Effect.gen(function* () {
|
||||
const handleDownloadProgress = Effect.fn("desktop.updates.handleDownloadProgress")(function* (
|
||||
raw: unknown,
|
||||
) {
|
||||
yield* Schema.decodeUnknownEffect(DownloadProgressInfo)(raw).pipe(
|
||||
yield* decodeDownloadProgressInfo(raw).pipe(
|
||||
Effect.flatMap(
|
||||
Effect.fn("desktop.updates.applyDownloadProgress")(function* (progress) {
|
||||
const state = yield* Ref.get(updateStateRef);
|
||||
@@ -506,7 +509,7 @@ const make = Effect.gen(function* () {
|
||||
const handleUpdateDownloaded = Effect.fn("desktop.updates.handleUpdateDownloaded")(function* (
|
||||
raw: unknown,
|
||||
) {
|
||||
yield* Schema.decodeUnknownEffect(UpdateInfo)(raw).pipe(
|
||||
yield* decodeUpdateInfo(raw).pipe(
|
||||
Effect.flatMap(
|
||||
Effect.fn("desktop.updates.applyUpdateDownloaded")(function* (info) {
|
||||
const state = yield* Ref.get(updateStateRef);
|
||||
|
||||
@@ -3,19 +3,7 @@
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"types": ["node", "electron"],
|
||||
"lib": ["ESNext", "DOM", "esnext.disposable"],
|
||||
"plugins": [
|
||||
{
|
||||
"name": "@effect/language-service",
|
||||
"namespaceImportPackages": ["@effect/platform-node", "effect"],
|
||||
"diagnosticSeverity": {
|
||||
"importFromBarrel": "error",
|
||||
"anyUnknownInErrorContext": "error",
|
||||
"instanceOfSchema": "warning",
|
||||
"deterministicKeys": "warning"
|
||||
}
|
||||
}
|
||||
]
|
||||
"lib": ["ESNext", "DOM", "esnext.disposable"]
|
||||
},
|
||||
"include": ["src", "tsdown.config.ts"]
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
@@ -8,20 +9,18 @@ import {
|
||||
type OrchestrationEvent,
|
||||
type OrchestrationThread,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
Effect,
|
||||
Exit,
|
||||
FileSystem,
|
||||
Layer,
|
||||
ManagedRuntime,
|
||||
Option,
|
||||
Path,
|
||||
Ref,
|
||||
Schedule,
|
||||
Schema,
|
||||
Scope,
|
||||
Stream,
|
||||
} from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as ManagedRuntime from "effect/ManagedRuntime";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schedule from "effect/Schedule";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import { CheckpointStoreLive } from "../src/checkpointing/Layers/CheckpointStore.ts";
|
||||
import { CheckpointStore } from "../src/checkpointing/Services/CheckpointStore.ts";
|
||||
@@ -80,6 +79,8 @@ import { VcsStatusBroadcaster } from "../src/vcs/VcsStatusBroadcaster.ts";
|
||||
import { GitWorkflowService } from "../src/git/GitWorkflowService.ts";
|
||||
import * as VcsProcess from "../src/vcs/VcsProcess.ts";
|
||||
|
||||
const decodeCodexSettings = Schema.decodeEffect(CodexSettings);
|
||||
|
||||
function runGit(cwd: string, args: ReadonlyArray<string>) {
|
||||
return execFileSync("git", args, {
|
||||
cwd,
|
||||
@@ -267,7 +268,7 @@ export const makeOrchestrationIntegrationHarness = (
|
||||
const realCodexRegistry = Layer.effect(
|
||||
ProviderAdapterRegistry,
|
||||
Effect.gen(function* () {
|
||||
const codexSettings = Schema.decodeSync(CodexSettings)({});
|
||||
const codexSettings = yield* decodeCodexSettings({});
|
||||
const codexAdapter = yield* makeCodexAdapter(codexSettings);
|
||||
return makeAdapterRegistryMock({
|
||||
[ProviderDriverKind.make("codex")]: codexAdapter,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
EventId,
|
||||
@@ -12,7 +10,10 @@ import {
|
||||
TurnId,
|
||||
ProviderDriverKind,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Queue, Stream } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as Random from "effect/Random";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import {
|
||||
ProviderAdapterSessionNotFoundError,
|
||||
@@ -202,7 +203,7 @@ interface MakeTestProviderAdapterHarnessOptions {
|
||||
}
|
||||
|
||||
function nowIso(): string {
|
||||
return new Date().toISOString();
|
||||
return "2026-01-01T00:00:00.000Z";
|
||||
}
|
||||
|
||||
function sessionNotFound(
|
||||
@@ -308,10 +309,9 @@ export const makeTestProviderAdapterHarness = (options?: MakeTestProviderAdapter
|
||||
for (const fixtureEvent of response.events) {
|
||||
const rawEvent: Record<string, unknown> = {
|
||||
...(fixtureEvent as Record<string, unknown>),
|
||||
eventId: randomUUID(),
|
||||
eventId: yield* Random.nextUUIDv4,
|
||||
provider,
|
||||
sessionId: RuntimeSessionId.make(String(input.threadId)),
|
||||
createdAt: nowIso(),
|
||||
};
|
||||
rawEvent.threadId = state.snapshot.threadId;
|
||||
if (Object.hasOwn(rawEvent, "turnId")) {
|
||||
@@ -366,7 +366,7 @@ export const makeTestProviderAdapterHarness = (options?: MakeTestProviderAdapter
|
||||
if (deferredTurnCompletedEvents.length === 0) {
|
||||
yield* emit({
|
||||
type: "turn.completed",
|
||||
eventId: EventId.make(randomUUID()),
|
||||
eventId: EventId.make(yield* Random.nextUUIDv4),
|
||||
provider,
|
||||
createdAt: nowIso(),
|
||||
threadId: state.snapshot.threadId,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
@@ -17,7 +18,10 @@ import {
|
||||
ProviderInstanceId,
|
||||
} from "@t3tools/contracts";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, Option, Schema } from "effect";
|
||||
import * as Clock from "effect/Clock";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import type { TestTurnResponse } from "./TestProviderAdapter.integration.ts";
|
||||
import {
|
||||
@@ -47,7 +51,7 @@ const CODEX_PROVIDER = ProviderDriverKind.make("codex");
|
||||
const CLAUDE_AGENT_PROVIDER = ProviderDriverKind.make("claudeAgent");
|
||||
|
||||
function nowIso() {
|
||||
return new Date().toISOString();
|
||||
return "2026-05-01T00:00:00.000Z";
|
||||
}
|
||||
|
||||
class IntegrationWaitTimeoutError extends Schema.TaggedErrorClass<IntegrationWaitTimeoutError>()(
|
||||
@@ -64,14 +68,14 @@ function waitForSync<A>(
|
||||
timeoutMs = 10_000,
|
||||
): Effect.Effect<A, never> {
|
||||
return Effect.gen(function* () {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const deadline = (yield* Clock.currentTimeMillis) + timeoutMs;
|
||||
|
||||
while (true) {
|
||||
const value = read();
|
||||
if (predicate(value)) {
|
||||
return value;
|
||||
}
|
||||
if (Date.now() >= deadline) {
|
||||
if ((yield* Clock.currentTimeMillis) >= deadline) {
|
||||
return yield* Effect.die(new IntegrationWaitTimeoutError({ description }));
|
||||
}
|
||||
yield* Effect.sleep(10);
|
||||
@@ -156,6 +160,7 @@ const startTurn = (input: {
|
||||
readonly messageId: string;
|
||||
readonly text: string;
|
||||
readonly modelSelection?: ModelSelection;
|
||||
readonly createdAt?: string;
|
||||
}) =>
|
||||
input.harness.engine.dispatch({
|
||||
type: "thread.turn.start",
|
||||
@@ -174,7 +179,7 @@ const startTurn = (input: {
|
||||
: {}),
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: nowIso(),
|
||||
createdAt: input.createdAt ?? nowIso(),
|
||||
});
|
||||
|
||||
it.live("runs a single turn end-to-end and persists checkpoint state in sqlite + git", () =>
|
||||
@@ -755,6 +760,7 @@ it.live("reverts to an earlier checkpoint and trims checkpoint projections + git
|
||||
commandId: "cmd-turn-start-revert-1",
|
||||
messageId: "msg-user-revert-1",
|
||||
text: "First edit",
|
||||
createdAt: "2026-02-24T10:04:59.900Z",
|
||||
});
|
||||
|
||||
yield* harness.waitForThread(
|
||||
@@ -813,6 +819,7 @@ it.live("reverts to an earlier checkpoint and trims checkpoint projections + git
|
||||
commandId: "cmd-turn-start-revert-2",
|
||||
messageId: "msg-user-revert-2",
|
||||
text: "Second edit",
|
||||
createdAt: "2026-02-24T10:05:00.900Z",
|
||||
});
|
||||
|
||||
yield* harness.waitForThread(
|
||||
|
||||
@@ -3,7 +3,12 @@ import { ProviderDriverKind, ProviderInstanceId, ThreadId } from "@t3tools/contr
|
||||
import { DEFAULT_SERVER_SETTINGS } from "@t3tools/contracts/settings";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { it, assert } from "@effect/vitest";
|
||||
import { Effect, FileSystem, Layer, Path, Queue, Stream } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import { ProviderAdapterRegistry } from "../src/provider/Services/ProviderAdapterRegistry.ts";
|
||||
import { makeAdapterRegistryMock } from "../src/provider/testUtils/providerAdapterRegistryMock.ts";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env bun
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import { appendFileSync } from "node:fs";
|
||||
|
||||
import * as Effect from "effect/Effect";
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { Data, Effect, FileSystem, Logger, Option, Path } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Logger from "effect/Logger";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { Command, Flag } from "effect/unstable/cli";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
@@ -11,6 +16,7 @@ import {
|
||||
PUBLISH_ICON_OVERRIDES,
|
||||
} from "../../../scripts/lib/brand-assets.ts";
|
||||
import { resolveCatalogDependencies } from "../../../scripts/lib/resolve-catalog.ts";
|
||||
import { fromJsonStringPretty } from "@t3tools/shared/schemaJson";
|
||||
import rootPackageJson from "../../../package.json" with { type: "json" };
|
||||
import serverPackageJson from "../package.json" with { type: "json" };
|
||||
|
||||
@@ -30,6 +36,9 @@ interface PackageJson {
|
||||
overrides: Record<string, string>;
|
||||
}
|
||||
|
||||
const PackageJsonPrettyJson = fromJsonStringPretty(Schema.Unknown);
|
||||
const encodePackageJson = Schema.encodeEffect(PackageJsonPrettyJson);
|
||||
|
||||
class CliError extends Data.TaggedError("CliError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
@@ -227,8 +236,9 @@ const publishCmd = Command.make(
|
||||
};
|
||||
|
||||
const original = yield* fs.readFileString(packageJsonPath);
|
||||
const packageJsonString = yield* encodePackageJson(pkg);
|
||||
yield* fs.writeFileString(backupPath, original);
|
||||
yield* fs.writeFileString(packageJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
|
||||
yield* fs.writeFileString(packageJsonPath, `${packageJsonString}\n`);
|
||||
yield* Effect.log("[cli] Prepared package.json for publish");
|
||||
|
||||
const iconBackups = yield* applyPublishIconOverrides(repoRoot, serverDir);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
import process from "node:process";
|
||||
import readline from "node:readline";
|
||||
import * as NodeTimers from "node:timers";
|
||||
|
||||
type JsonPrimitive = null | boolean | number | string;
|
||||
type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };
|
||||
@@ -114,7 +116,8 @@ function matchesKeyword(option: SessionConfigOption, keyword: string): boolean {
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
// @effect-diagnostics-next-line globalTimers:off - Standalone Node probe script, not an Effect runtime test.
|
||||
NodeTimers.setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -177,7 +180,8 @@ class JsonRpcChild {
|
||||
const id = this.nextId++;
|
||||
|
||||
const responsePromise = new Promise<JsonValue | undefined>((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
// @effect-diagnostics-next-line globalTimers:off - Standalone Node probe script request timeout.
|
||||
const timeout = NodeTimers.setTimeout(() => {
|
||||
this.pending.delete(id);
|
||||
reject(new Error(`Timed out waiting for ${method} response after ${timeoutMs}ms.`));
|
||||
}, timeoutMs);
|
||||
@@ -185,11 +189,11 @@ class JsonRpcChild {
|
||||
this.pending.set(id, {
|
||||
method,
|
||||
resolve: (value) => {
|
||||
clearTimeout(timeout);
|
||||
NodeTimers.clearTimeout(timeout);
|
||||
resolve(value);
|
||||
},
|
||||
reject: (error) => {
|
||||
clearTimeout(timeout);
|
||||
NodeTimers.clearTimeout(timeout);
|
||||
reject(error);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Effect, FileSystem, Path } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Random from "effect/Random";
|
||||
|
||||
export const writeFileStringAtomically = (input: {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import path from "node:path";
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import NodePath from "node:path";
|
||||
|
||||
export const ATTACHMENTS_ROUTE_PREFIX = "/attachments";
|
||||
|
||||
export function normalizeAttachmentRelativePath(rawRelativePath: string): string | null {
|
||||
const normalized = path.normalize(rawRelativePath).replace(/^[/\\]+/, "");
|
||||
const normalized = NodePath.normalize(rawRelativePath).replace(/^[/\\]+/, "");
|
||||
if (normalized.length === 0 || normalized.startsWith("..") || normalized.includes("\0")) {
|
||||
return null;
|
||||
}
|
||||
@@ -19,9 +20,9 @@ export function resolveAttachmentRelativePath(input: {
|
||||
return null;
|
||||
}
|
||||
|
||||
const attachmentsRoot = path.resolve(input.attachmentsDir);
|
||||
const filePath = path.resolve(path.join(attachmentsRoot, normalizedRelativePath));
|
||||
if (!filePath.startsWith(`${attachmentsRoot}${path.sep}`)) {
|
||||
const attachmentsRoot = NodePath.resolve(input.attachmentsDir);
|
||||
const filePath = NodePath.resolve(NodePath.join(attachmentsRoot, normalizedRelativePath));
|
||||
if (!filePath.startsWith(`${attachmentsRoot}${NodePath.sep}`)) {
|
||||
return null;
|
||||
}
|
||||
return filePath;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { existsSync } from "node:fs";
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import type { ServerConfigShape } from "../../config.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { AuthClientSession, AuthPairingLink } from "@t3tools/contracts";
|
||||
import { DateTime, Effect, Layer } from "effect";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import { BootstrapCredentialServiceLive } from "./BootstrapCredentialService.ts";
|
||||
import { ServerSecretStoreLive } from "./ServerSecretStore.ts";
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { Duration, Effect, Layer } from "effect";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
|
||||
import type { ServerConfigShape } from "../../config.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import type { AuthPairingLink } from "@t3tools/contracts";
|
||||
import { DateTime, Duration, Effect, Layer, PubSub, Ref, Stream } from "effect";
|
||||
import { Option } from "effect";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { AuthPairingLinkRepositoryLive } from "../../persistence/Layers/AuthPairingLinks.ts";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import type { ServerConfigShape } from "../../config.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -6,7 +6,10 @@ import {
|
||||
type AuthSessionState,
|
||||
type AuthWebSocketTokenResult,
|
||||
} from "@t3tools/contracts";
|
||||
import { DateTime, Effect, Layer, Option } from "effect";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
||||
|
||||
import { AuthControlPlane } from "../Services/AuthControlPlane.ts";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import type { ServerConfigShape } from "../../config.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ServerAuthDescriptor } from "@t3tools/contracts";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { ServerAuthPolicy, type ServerAuthPolicyShape } from "../Services/ServerAuthPolicy.ts";
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { Cause, Deferred, Effect, FileSystem, Layer, Ref } from "effect";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import * as Crypto from "node:crypto";
|
||||
|
||||
import { Effect, FileSystem, Layer, Path, Predicate } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { Duration, Effect, Layer } from "effect";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
|
||||
import type { ServerConfigShape } from "../../config.ts";
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { AuthSessionId, type AuthClientMetadata, type AuthClientSession } from "@t3tools/contracts";
|
||||
import { Clock, DateTime, Duration, Effect, Layer, PubSub, Ref, Schema, Stream } from "effect";
|
||||
import { Option } from "effect";
|
||||
import * as Clock from "effect/Clock";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { AuthSessionRepositoryLive } from "../../persistence/Layers/AuthSessions.ts";
|
||||
@@ -192,6 +200,7 @@ export const makeSessionCredentialService = Effect.gen(function* () {
|
||||
),
|
||||
);
|
||||
|
||||
const encodeClaims = Schema.encodeEffect(Schema.fromJsonString(SessionClaims));
|
||||
const issue: SessionCredentialServiceShape["issue"] = (input) =>
|
||||
Effect.gen(function* () {
|
||||
const sessionId = AuthSessionId.make(crypto.randomUUID());
|
||||
@@ -209,7 +218,13 @@ export const makeSessionCredentialService = Effect.gen(function* () {
|
||||
iat: issuedAt.epochMilliseconds,
|
||||
exp: expiresAt.epochMilliseconds,
|
||||
};
|
||||
const encodedPayload = base64UrlEncode(JSON.stringify(claims));
|
||||
|
||||
const encodedPayload = yield* encodeClaims(claims).pipe(
|
||||
Effect.map(base64UrlEncode),
|
||||
Effect.mapError(
|
||||
(cause) => new SessionCredentialError({ message: "Failed to encode claims", cause }),
|
||||
),
|
||||
);
|
||||
const signature = signPayload(encodedPayload, signingSecret);
|
||||
const client = input?.client ?? createDefaultClientMetadata();
|
||||
yield* authSessions.create({
|
||||
@@ -297,12 +312,19 @@ export const makeSessionCredentialService = Effect.gen(function* () {
|
||||
});
|
||||
}
|
||||
|
||||
const expiresAt = DateTime.make(claims.exp);
|
||||
if (Option.isNone(expiresAt)) {
|
||||
return yield* new SessionCredentialError({
|
||||
message: "Invalid `exp` claim",
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
sessionId: claims.sid,
|
||||
token,
|
||||
method: claims.method,
|
||||
client: toClientMetadata(row.value.client),
|
||||
expiresAt: DateTime.makeUnsafe(claims.exp),
|
||||
expiresAt: expiresAt.value,
|
||||
subject: claims.sub,
|
||||
role: claims.role,
|
||||
} satisfies VerifiedSession;
|
||||
@@ -317,6 +339,7 @@ export const makeSessionCredentialService = Effect.gen(function* () {
|
||||
),
|
||||
);
|
||||
|
||||
const encodeWsClaims = Schema.encodeEffect(Schema.fromJsonString(WebSocketClaims));
|
||||
const issueWebSocketToken: SessionCredentialServiceShape["issueWebSocketToken"] = (
|
||||
sessionId,
|
||||
input,
|
||||
@@ -333,7 +356,12 @@ export const makeSessionCredentialService = Effect.gen(function* () {
|
||||
iat: issuedAt.epochMilliseconds,
|
||||
exp: expiresAt.epochMilliseconds,
|
||||
};
|
||||
const encodedPayload = base64UrlEncode(JSON.stringify(claims));
|
||||
const encodedPayload = yield* encodeWsClaims(claims).pipe(
|
||||
Effect.map(base64UrlEncode),
|
||||
Effect.mapError(
|
||||
(cause) => new SessionCredentialError({ message: "Failed to encode claims", cause }),
|
||||
),
|
||||
);
|
||||
const signature = signPayload(encodedPayload, signingSecret);
|
||||
return {
|
||||
token: `${encodedPayload}.${signature}`,
|
||||
|
||||
@@ -4,7 +4,11 @@ import type {
|
||||
AuthPairingLink,
|
||||
AuthSessionId,
|
||||
} from "@t3tools/contracts";
|
||||
import { Data, DateTime, Duration, Effect, Context } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Context from "effect/Context";
|
||||
import type { SessionRole } from "./SessionCredentialService.ts";
|
||||
|
||||
export const DEFAULT_SESSION_SUBJECT = "cli-issued-session";
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import type { AuthPairingLink, ServerAuthBootstrapMethod } from "@t3tools/contracts";
|
||||
import { Data, DateTime, Duration, Context } from "effect";
|
||||
import type { Effect, Stream } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
import type * as Stream from "effect/Stream";
|
||||
|
||||
export type BootstrapCredentialRole = "owner" | "client";
|
||||
|
||||
|
||||
@@ -12,8 +12,10 @@ import type {
|
||||
ServerAuthSessionMethod,
|
||||
AuthWebSocketTokenResult,
|
||||
} from "@t3tools/contracts";
|
||||
import { Data, DateTime, Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
import type * as HttpServerRequest from "effect/unstable/http/HttpServerRequest";
|
||||
import type { SessionRole } from "./SessionCredentialService.ts";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ServerAuthDescriptor } from "@t3tools/contracts";
|
||||
import { Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
|
||||
export interface ServerAuthPolicyShape {
|
||||
readonly getDescriptor: () => Effect.Effect<ServerAuthDescriptor>;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Data, Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
|
||||
export class SecretStoreError extends Data.TaggedError("SecretStoreError")<{
|
||||
readonly message: string;
|
||||
|
||||
@@ -4,8 +4,12 @@ import type {
|
||||
AuthSessionId,
|
||||
ServerAuthSessionMethod,
|
||||
} from "@t3tools/contracts";
|
||||
import { Data, DateTime, Duration, Context } from "effect";
|
||||
import type { Effect, Stream } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
import type * as Stream from "effect/Stream";
|
||||
|
||||
export type SessionRole = "owner" | "client";
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ import {
|
||||
AuthRevokePairingLinkInput,
|
||||
type AuthWebSocketTokenResult,
|
||||
} from "@t3tools/contracts";
|
||||
import { DateTime, Effect, Schema } from "effect";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
||||
|
||||
import { AuthError, ServerAuth } from "./Services/ServerAuth.ts";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics-next-line nodeBuiltinImport:off - NodeHttpServer.layer takes `NodeHttp.createServer` as arg
|
||||
import * as NodeHttp from "node:http";
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
@@ -5,7 +6,7 @@ import { join } from "node:path";
|
||||
|
||||
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { NetService } from "@t3tools/shared/Net";
|
||||
import * as NetService from "@t3tools/shared/Net";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -138,7 +139,7 @@ const withLiveProjectCliServer = <A, E, R>(baseDir: string, run: () => Effect.Ef
|
||||
}
|
||||
yield* persistServerRuntimeState({
|
||||
path: config.serverRuntimeStatePath,
|
||||
state: makePersistedServerRuntimeState({
|
||||
state: yield* makePersistedServerRuntimeState({
|
||||
config,
|
||||
port: address.port,
|
||||
}),
|
||||
@@ -179,6 +180,7 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
|
||||
const createdOutput = yield* captureStdout(
|
||||
runCli(["auth", "pairing", "create", "--base-dir", baseDir, "--json"]),
|
||||
);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
const created = JSON.parse(createdOutput.output) as {
|
||||
readonly id: string;
|
||||
readonly credential: string;
|
||||
@@ -186,6 +188,7 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
|
||||
const listedOutput = yield* captureStdout(
|
||||
runCli(["auth", "pairing", "list", "--base-dir", baseDir, "--json"]),
|
||||
);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
const listed = JSON.parse(listedOutput.output) as ReadonlyArray<{
|
||||
readonly id: string;
|
||||
readonly credential?: string;
|
||||
@@ -207,6 +210,7 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
|
||||
const issuedOutput = yield* captureStdout(
|
||||
runCli(["auth", "session", "issue", "--base-dir", baseDir, "--json"]),
|
||||
);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
const issued = JSON.parse(issuedOutput.output) as {
|
||||
readonly sessionId: string;
|
||||
readonly token: string;
|
||||
@@ -215,6 +219,7 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
|
||||
const listedOutput = yield* captureStdout(
|
||||
runCli(["auth", "session", "list", "--base-dir", baseDir, "--json"]),
|
||||
);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
const listed = JSON.parse(listedOutput.output) as ReadonlyArray<{
|
||||
readonly sessionId: string;
|
||||
readonly token?: string;
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import { Command } from "effect/unstable/cli";
|
||||
|
||||
import { NetService } from "@t3tools/shared/Net";
|
||||
import * as NetService from "@t3tools/shared/Net";
|
||||
import packageJson from "../package.json" with { type: "json" };
|
||||
import { authCommand } from "./cli/auth.ts";
|
||||
import { sharedServerCommandFlags } from "./cli/config.ts";
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as NFS from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { execFileSync, spawn } from "node:child_process";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { FileSystem, Schema } from "effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
import { vi } from "vitest";
|
||||
|
||||
import { readBootstrapEnvelope, resolveFdPath } from "./bootstrap.ts";
|
||||
@@ -36,6 +38,7 @@ vi.mock("node:fs", async (importOriginal) => {
|
||||
});
|
||||
|
||||
const TestEnvelopeSchema = Schema.Struct({ mode: Schema.String });
|
||||
const encodeTestEnvelopeSchema = Schema.encodeEffect(Schema.fromJsonString(TestEnvelopeSchema));
|
||||
|
||||
it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
it.effect("uses platform-specific fd paths", () =>
|
||||
@@ -53,9 +56,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
|
||||
yield* fs.writeFileString(
|
||||
filePath,
|
||||
`${yield* Schema.encodeEffect(Schema.fromJsonString(TestEnvelopeSchema))({
|
||||
mode: "desktop",
|
||||
})}\n`,
|
||||
`${yield* encodeTestEnvelopeSchema({ mode: "desktop" })}\n`,
|
||||
);
|
||||
|
||||
const fd = yield* Effect.acquireRelease(
|
||||
@@ -77,9 +78,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
|
||||
yield* fs.writeFileString(
|
||||
filePath,
|
||||
`${yield* Schema.encodeEffect(Schema.fromJsonString(TestEnvelopeSchema))({
|
||||
mode: "desktop",
|
||||
})}\n`,
|
||||
`${yield* encodeTestEnvelopeSchema({ mode: "desktop" })}\n`,
|
||||
);
|
||||
|
||||
// Open without acquireRelease: the direct-stream fallback uses autoClose: true,
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as NFS from "node:fs";
|
||||
import * as Net from "node:net";
|
||||
import * as readline from "node:readline";
|
||||
import type { Readable } from "node:stream";
|
||||
|
||||
import { Data, Effect, Option, Predicate, Result, Schema } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
import * as Result from "effect/Result";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { decodeJsonResult } from "@t3tools/shared/schemaJson";
|
||||
|
||||
class BootstrapError extends Data.TaggedError("BootstrapError")<{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Schema } from "effect";
|
||||
import * as Schema from "effect/Schema";
|
||||
import type { ProjectionRepositoryError } from "../persistence/Errors.ts";
|
||||
import type { VcsError } from "@t3tools/contracts";
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { CheckpointRef, ProjectId, ThreadId, TurnId } from "@t3tools/contracts";
|
||||
import { Effect, Layer, Option } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
|
||||
@@ -4,7 +4,10 @@ import {
|
||||
type OrchestrationGetFullThreadDiffResult,
|
||||
type OrchestrationGetTurnDiffResult as OrchestrationGetTurnDiffResultType,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Layer, Option, Schema } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import { ProjectionSnapshotQuery } from "../../orchestration/Services/ProjectionSnapshotQuery.ts";
|
||||
import { CheckpointInvariantError, CheckpointUnavailableError } from "../Errors.ts";
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import path from "node:path";
|
||||
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { it } from "@effect/vitest";
|
||||
import { Effect, FileSystem, Layer, PlatformError, Scope } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
import * as Scope from "effect/Scope";
|
||||
import { describe, expect } from "vitest";
|
||||
|
||||
import { checkpointRefForThreadTurn } from "../Utils.ts";
|
||||
|
||||
@@ -11,7 +11,10 @@
|
||||
*/
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import { Effect, Layer, FileSystem, Path } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
|
||||
import { CheckpointInvariantError } from "../Errors.ts";
|
||||
import { VcsProcessExitError } from "@t3tools/contracts";
|
||||
|
||||
@@ -12,8 +12,8 @@ import type {
|
||||
OrchestrationGetTurnDiffInput,
|
||||
OrchestrationGetTurnDiffResult,
|
||||
} from "@t3tools/contracts";
|
||||
import { Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
|
||||
import type { CheckpointServiceError } from "../Errors.ts";
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
*
|
||||
* @module CheckpointStore
|
||||
*/
|
||||
import { Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
|
||||
import type { CheckpointStoreError } from "../Errors.ts";
|
||||
import { CheckpointRef } from "@t3tools/contracts";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Encoding } from "effect";
|
||||
import * as Encoding from "effect/Encoding";
|
||||
import { CheckpointRef, ProjectId, type ThreadId } from "@t3tools/contracts";
|
||||
|
||||
export const CHECKPOINT_REFS_PREFIX = "refs/t3/checkpoints";
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { AuthSessionId } from "@t3tools/contracts";
|
||||
import { Console, Effect, Layer, Option, References } from "effect";
|
||||
import * as Console from "effect/Console";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as References from "effect/References";
|
||||
import { Argument, Command, Flag, GlobalFlag } from "effect/unstable/cli";
|
||||
|
||||
import { AuthControlPlaneRuntimeLive } from "../auth/Layers/AuthControlPlane.ts";
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import os from "node:os";
|
||||
import NodeOS from "node:os";
|
||||
|
||||
import { assert, expect, it } from "@effect/vitest";
|
||||
import { ConfigProvider, Effect, FileSystem, Layer, Option, Path, Schema } from "effect";
|
||||
import * as ConfigProvider from "effect/ConfigProvider";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import {
|
||||
DesktopBackendBootstrap,
|
||||
type DesktopBackendBootstrap as DesktopBackendBootstrapValue,
|
||||
} from "@t3tools/contracts";
|
||||
import { NetService } from "@t3tools/shared/Net";
|
||||
import * as NetService from "@t3tools/shared/Net";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { deriveServerPaths } from "../config.ts";
|
||||
import { resolveServerConfig } from "./config.ts";
|
||||
@@ -53,7 +59,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
|
||||
it.effect("falls back to effect/config values when flags are omitted", () =>
|
||||
Effect.gen(function* () {
|
||||
const { join } = yield* Path.Path;
|
||||
const baseDir = join(os.tmpdir(), "t3-cli-config-env-base");
|
||||
const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-env-base");
|
||||
const derivedPaths = yield* deriveServerPaths(baseDir, new URL("http://127.0.0.1:5173"));
|
||||
const resolved = yield* resolveServerConfig(
|
||||
{
|
||||
@@ -119,7 +125,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
|
||||
it.effect("uses CLI flags when provided", () =>
|
||||
Effect.gen(function* () {
|
||||
const { join } = yield* Path.Path;
|
||||
const baseDir = join(os.tmpdir(), "t3-cli-config-flags-base");
|
||||
const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-flags-base");
|
||||
const derivedPaths = yield* deriveServerPaths(baseDir, new URL("http://127.0.0.1:4173"));
|
||||
const resolved = yield* resolveServerConfig(
|
||||
{
|
||||
@@ -147,7 +153,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
|
||||
T3CODE_MODE: "desktop",
|
||||
T3CODE_PORT: "4001",
|
||||
T3CODE_HOST: "0.0.0.0",
|
||||
T3CODE_HOME: join(os.tmpdir(), "ignored-base"),
|
||||
T3CODE_HOME: join(NodeOS.tmpdir(), "ignored-base"),
|
||||
VITE_DEV_SERVER_URL: "http://127.0.0.1:5173",
|
||||
T3CODE_NO_BROWSER: "false",
|
||||
T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "false",
|
||||
@@ -185,7 +191,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
|
||||
it.effect("preserves explicit false CLI boolean flags over env and bootstrap values", () =>
|
||||
Effect.gen(function* () {
|
||||
const { join } = yield* Path.Path;
|
||||
const baseDir = join(os.tmpdir(), "t3-cli-config-false-flags");
|
||||
const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-false-flags");
|
||||
const fd = yield* openBootstrapFd(
|
||||
makeDesktopBootstrap({
|
||||
noBrowser: true,
|
||||
@@ -378,7 +384,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
|
||||
it.effect("applies flag then env precedence over bootstrap envelope values", () =>
|
||||
Effect.gen(function* () {
|
||||
const { join } = yield* Path.Path;
|
||||
const baseDir = join(os.tmpdir(), "t3-cli-config-env-wins");
|
||||
const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-env-wins");
|
||||
const fd = yield* openBootstrapFd(
|
||||
makeDesktopBootstrap({
|
||||
port: 4888,
|
||||
@@ -459,6 +465,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
|
||||
yield* fs.makeDirectory(path.dirname(derivedPaths.settingsPath), { recursive: true });
|
||||
yield* fs.writeFileString(
|
||||
derivedPaths.settingsPath,
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
`${JSON.stringify({
|
||||
observability: {
|
||||
otlpTracesUrl: "http://localhost:4318/v1/traces",
|
||||
@@ -521,7 +528,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
|
||||
it.effect("forces noBrowser and disables auto-bootstrap for headless startup presentation", () =>
|
||||
Effect.gen(function* () {
|
||||
const { join } = yield* Path.Path;
|
||||
const baseDir = join(os.tmpdir(), "t3-cli-config-headless-base");
|
||||
const baseDir = join(NodeOS.tmpdir(), "t3-cli-config-headless-base");
|
||||
const derivedPaths = yield* deriveServerPaths(baseDir, undefined);
|
||||
|
||||
const resolved = yield* resolveServerConfig(
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import { NetService } from "@t3tools/shared/Net";
|
||||
import * as NetService from "@t3tools/shared/Net";
|
||||
import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
|
||||
import { DesktopBackendBootstrap, PortSchema } from "@t3tools/contracts";
|
||||
import {
|
||||
Config,
|
||||
Duration,
|
||||
Effect,
|
||||
FileSystem,
|
||||
LogLevel,
|
||||
Option,
|
||||
Path,
|
||||
Schema,
|
||||
SchemaIssue,
|
||||
SchemaTransformation,
|
||||
} from "effect";
|
||||
import * as Config from "effect/Config";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as LogLevel from "effect/LogLevel";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as SchemaIssue from "effect/SchemaIssue";
|
||||
import * as SchemaTransformation from "effect/SchemaTransformation";
|
||||
import { Argument, Flag } from "effect/unstable/cli";
|
||||
|
||||
import { readBootstrapEnvelope } from "../bootstrap.ts";
|
||||
@@ -215,7 +213,7 @@ export const resolveServerConfig = (
|
||||
},
|
||||
) =>
|
||||
Effect.gen(function* () {
|
||||
const { findAvailablePort } = yield* NetService;
|
||||
const { findAvailablePort } = yield* NetService.NetService;
|
||||
const path = yield* Path.Path;
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
const env = yield* EnvServerConfig;
|
||||
|
||||
@@ -4,18 +4,18 @@ import {
|
||||
ProjectId,
|
||||
type ClientOrchestrationCommand,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
Console,
|
||||
Duration,
|
||||
Effect,
|
||||
Exit,
|
||||
FileSystem,
|
||||
Layer,
|
||||
Option,
|
||||
Path,
|
||||
References,
|
||||
Schema,
|
||||
} from "effect";
|
||||
import * as Console from "effect/Console";
|
||||
import * as Data from "effect/Data";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as References from "effect/References";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { Argument, Command, Flag, GlobalFlag } from "effect/unstable/cli";
|
||||
import {
|
||||
FetchHttpClient,
|
||||
@@ -54,6 +54,10 @@ type ProjectCliDispatchCommand = Extract<
|
||||
{ type: "project.create" | "project.meta.update" | "project.delete" }
|
||||
>;
|
||||
|
||||
class ProjectCommandError extends Data.TaggedError("ProjectCommandError")<{
|
||||
readonly message: string;
|
||||
}> {}
|
||||
|
||||
const ProjectCliRuntimeLive = Layer.mergeAll(
|
||||
WorkspacePathsLive,
|
||||
OrchestrationLayerLive.pipe(
|
||||
@@ -124,7 +128,7 @@ const resolveProjectTitle = Effect.fn("resolveProjectTitle")(function* (
|
||||
if (trimmed.length > 0) {
|
||||
return trimmed;
|
||||
}
|
||||
return yield* Effect.fail(new Error("Project title cannot be empty."));
|
||||
return yield* new ProjectCommandError({ message: "Project title cannot be empty." });
|
||||
}
|
||||
|
||||
const path = yield* Path.Path;
|
||||
@@ -138,7 +142,7 @@ const findActiveProjectTarget = Effect.fn("findActiveProjectTarget")(function* (
|
||||
}) {
|
||||
const trimmedIdentifier = input.identifier.trim();
|
||||
if (trimmedIdentifier.length === 0) {
|
||||
return yield* Effect.fail(new Error("Project identifier cannot be empty."));
|
||||
return yield* new ProjectCommandError({ message: "Project identifier cannot be empty." });
|
||||
}
|
||||
|
||||
const activeProjects = input.snapshot.projects.filter((project) => project.deletedAt === null);
|
||||
@@ -165,7 +169,9 @@ const findActiveProjectTarget = Effect.fn("findActiveProjectTarget")(function* (
|
||||
|
||||
const resolved = exactWorkspaceMatch;
|
||||
if (!resolved) {
|
||||
return yield* Effect.fail(new Error(`No active project found for '${trimmedIdentifier}'.`));
|
||||
return yield* new ProjectCommandError({
|
||||
message: `No active project found for '${trimmedIdentifier}'.`,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -185,7 +191,7 @@ const fetchLiveOrchestrationSnapshot = (origin: string, bearerToken: string) =>
|
||||
"2xx": decodeOrchestrationReadModelResponse,
|
||||
orElse: (response) =>
|
||||
readErrorMessageFromResponse(response).pipe(
|
||||
Effect.flatMap((message) => Effect.fail(new Error(message))),
|
||||
Effect.flatMap((message) => Effect.fail(new ProjectCommandError({ message }))),
|
||||
),
|
||||
}),
|
||||
);
|
||||
@@ -206,7 +212,7 @@ const dispatchLiveOrchestrationCommand = (
|
||||
"2xx": () => Effect.void,
|
||||
orElse: (response) =>
|
||||
readErrorMessageFromResponse(response).pipe(
|
||||
Effect.flatMap((message) => Effect.fail(new Error(message))),
|
||||
Effect.flatMap((message) => Effect.fail(new ProjectCommandError({ message }))),
|
||||
),
|
||||
}),
|
||||
),
|
||||
@@ -331,9 +337,9 @@ const projectAddCommand = Command.make("add", {
|
||||
(project) => project.deletedAt === null && project.workspaceRoot === workspaceRoot,
|
||||
);
|
||||
if (existingProject) {
|
||||
return yield* Effect.fail(
|
||||
new Error(`An active project already exists for '${workspaceRoot}'.`),
|
||||
);
|
||||
return yield* new ProjectCommandError({
|
||||
message: `An active project already exists for '${workspaceRoot}'.`,
|
||||
});
|
||||
}
|
||||
|
||||
const title = yield* resolveProjectTitle(workspaceRoot, Option.getOrUndefined(flags.title));
|
||||
@@ -345,7 +351,7 @@ const projectAddCommand = Command.make("add", {
|
||||
title,
|
||||
workspaceRoot,
|
||||
defaultModelSelection: getAutoBootstrapDefaultModelSelection(),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: DateTime.formatIso(yield* DateTime.now),
|
||||
});
|
||||
return `Added project ${projectId} (${title}) at ${workspaceRoot}.`;
|
||||
}),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Effect } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import { Command, GlobalFlag } from "effect/unstable/cli";
|
||||
|
||||
import { ServerConfig, type StartupPresentation } from "../config.ts";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { DateTime } from "effect";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
|
||||
import {
|
||||
formatIssuedPairingCredential,
|
||||
@@ -15,8 +15,8 @@ it("formats issued pairing credentials with the secret and optional pair URL", (
|
||||
credential: "secret-pairing-token",
|
||||
role: "client",
|
||||
subject: "one-time-token",
|
||||
createdAt: DateTime.fromDateUnsafe(new Date("2026-04-08T09:00:00.000Z")),
|
||||
expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
|
||||
createdAt: DateTime.makeUnsafe("2026-04-08T09:00:00.000Z"),
|
||||
expiresAt: DateTime.makeUnsafe("2026-04-08T10:00:00.000Z"),
|
||||
},
|
||||
{ baseUrl: "https://example.com", json: false },
|
||||
);
|
||||
@@ -34,8 +34,8 @@ it("formats pairing listings without exposing the secret token", () => {
|
||||
subject: "one-time-token",
|
||||
label: "Phone",
|
||||
role: "client",
|
||||
createdAt: DateTime.fromDateUnsafe(new Date("2026-04-08T09:00:00.000Z")),
|
||||
expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
|
||||
createdAt: DateTime.makeUnsafe("2026-04-08T09:00:00.000Z"),
|
||||
expiresAt: DateTime.makeUnsafe("2026-04-08T10:00:00.000Z"),
|
||||
},
|
||||
],
|
||||
{ json: false },
|
||||
@@ -57,7 +57,7 @@ it("formats issued sessions with the bearer token but omits tokens from listings
|
||||
label: "deploy-bot",
|
||||
deviceType: "bot",
|
||||
},
|
||||
expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
|
||||
expiresAt: DateTime.makeUnsafe("2026-04-08T10:00:00.000Z"),
|
||||
},
|
||||
{ json: false },
|
||||
);
|
||||
@@ -75,8 +75,8 @@ it("formats issued sessions with the bearer token but omits tokens from listings
|
||||
},
|
||||
connected: false,
|
||||
current: false,
|
||||
issuedAt: DateTime.fromDateUnsafe(new Date("2026-04-08T09:00:00.000Z")),
|
||||
expiresAt: DateTime.fromDateUnsafe(new Date("2026-04-08T10:00:00.000Z")),
|
||||
issuedAt: DateTime.makeUnsafe("2026-04-08T09:00:00.000Z"),
|
||||
expiresAt: DateTime.makeUnsafe("2026-04-08T10:00:00.000Z"),
|
||||
lastConnectedAt: null,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AuthClientMetadata, AuthClientSession, AuthPairingLink } from "@t3tools/contracts";
|
||||
import { DateTime } from "effect";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
|
||||
import type { IssuedBearerSession, IssuedPairingLink } from "./auth/Services/AuthControlPlane.ts";
|
||||
|
||||
|
||||
@@ -6,7 +6,13 @@
|
||||
*
|
||||
* @module ServerConfig
|
||||
*/
|
||||
import { Effect, FileSystem, Layer, LogLevel, Path, Schema, Context } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as LogLevel from "effect/LogLevel";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Context from "effect/Context";
|
||||
|
||||
export const DEFAULT_PORT = 3773;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ class ProcessDiagnosticsError extends Schema.TaggedErrorClass<ProcessDiagnostics
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
const isProcessDiagnosticsError = Schema.is(ProcessDiagnosticsError);
|
||||
|
||||
function toProcessDiagnosticsError(message: string, cause?: unknown): ProcessDiagnosticsError {
|
||||
return new ProcessDiagnosticsError({
|
||||
@@ -316,7 +317,7 @@ const runProcess = Effect.fn("runProcess")(
|
||||
}),
|
||||
),
|
||||
Effect.mapError((cause) =>
|
||||
Schema.is(ProcessDiagnosticsError)(cause)
|
||||
isProcessDiagnosticsError(cause)
|
||||
? cause
|
||||
: toProcessDiagnosticsError(input.errorMessage, cause),
|
||||
),
|
||||
|
||||
@@ -89,24 +89,14 @@ function toNumberValue(value: unknown): number | null {
|
||||
function unixNanoToDateTime(value: unknown): DateTime.Utc | null {
|
||||
const text = toStringValue(value);
|
||||
if (!text) return null;
|
||||
|
||||
try {
|
||||
const millis = Number(BigInt(text) / 1_000_000n);
|
||||
if (!Number.isFinite(millis)) return null;
|
||||
return DateTime.makeUnsafe(millis);
|
||||
return Option.getOrNull(DateTime.make(millis));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function isAfter(left: DateTime.Utc, right: DateTime.Utc): boolean {
|
||||
return DateTime.toEpochMillis(left) > DateTime.toEpochMillis(right);
|
||||
}
|
||||
|
||||
function isBefore(left: DateTime.Utc, right: DateTime.Utc): boolean {
|
||||
return DateTime.toEpochMillis(left) < DateTime.toEpochMillis(right);
|
||||
}
|
||||
|
||||
function readExitTag(exit: unknown): string | null {
|
||||
if (!isRecordObject(exit) || !("_tag" in exit)) return null;
|
||||
return toStringValue(exit._tag);
|
||||
@@ -254,10 +244,11 @@ export function aggregateTraceDiagnostics(
|
||||
|
||||
recordCount += 1;
|
||||
firstSpanAt =
|
||||
startedAt && (firstSpanAt === null || isBefore(startedAt, firstSpanAt))
|
||||
startedAt && (firstSpanAt === null || DateTime.isLessThan(startedAt, firstSpanAt))
|
||||
? startedAt
|
||||
: firstSpanAt;
|
||||
lastSpanAt = lastSpanAt === null || isAfter(endedAt, lastSpanAt) ? endedAt : lastSpanAt;
|
||||
lastSpanAt =
|
||||
lastSpanAt === null || DateTime.isGreaterThan(endedAt, lastSpanAt) ? endedAt : lastSpanAt;
|
||||
|
||||
const exitTag = readExitTag(parsed.exit);
|
||||
const isFailure = exitTag === "Failure";
|
||||
@@ -289,7 +280,7 @@ export function aggregateTraceDiagnostics(
|
||||
|
||||
const failureKey = `${name}\0${cause}`;
|
||||
const existing = failuresByKey.get(failureKey);
|
||||
const isLatestFailure = !existing || isAfter(endedAt, existing.lastSeenAt);
|
||||
const isLatestFailure = !existing || DateTime.isGreaterThan(endedAt, existing.lastSeenAt);
|
||||
failuresByKey.set(failureKey, {
|
||||
name,
|
||||
cause,
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import * as nodePath from "node:path";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { expect, it } from "@effect/vitest";
|
||||
import { Effect, Exit, FileSystem, Layer, PlatformError } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
|
||||
import { deriveServerPaths, ServerConfig, type ServerConfigShape } from "../../config.ts";
|
||||
import { ServerEnvironment } from "../Services/ServerEnvironment.ts";
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { EnvironmentId, type ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
|
||||
import { Effect, FileSystem, Layer, Path, Random } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Random from "effect/Random";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
import { ServerEnvironment, type ServerEnvironmentShape } from "../Services/ServerEnvironment.ts";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, describe, expect, it } from "@effect/vitest";
|
||||
import { Effect, FileSystem } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import { vi } from "vitest";
|
||||
|
||||
vi.mock("../../processRunner.ts", () => ({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as OS from "node:os";
|
||||
|
||||
import { Effect, FileSystem } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
|
||||
import { runProcess } from "../../processRunner.ts";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { EnvironmentId, ExecutionEnvironmentDescriptor } from "@t3tools/contracts";
|
||||
import { Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
|
||||
export interface ServerEnvironmentShape {
|
||||
readonly getEnvironmentId: Effect.Effect<EnvironmentId>;
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { it } from "@effect/vitest";
|
||||
import { Effect, FileSystem, Layer, PlatformError, Scope } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
import * as Scope from "effect/Scope";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
import { expect } from "vitest";
|
||||
import type {
|
||||
@@ -32,6 +37,7 @@ import { ServerConfig } from "../config.ts";
|
||||
import { ServerSettingsService } from "../serverSettings.ts";
|
||||
import {
|
||||
ProjectSetupScriptRunner,
|
||||
ProjectSetupScriptRunnerError,
|
||||
type ProjectSetupScriptRunnerInput,
|
||||
type ProjectSetupScriptRunnerShape,
|
||||
} from "../project/Services/ProjectSetupScriptRunner.ts";
|
||||
@@ -713,6 +719,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 13,
|
||||
@@ -754,6 +761,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 14,
|
||||
@@ -792,6 +800,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 0,
|
||||
@@ -843,6 +852,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 16,
|
||||
@@ -955,6 +965,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
};
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
prListSequence: [JSON.stringify([existingPr]), JSON.stringify([existingPr])],
|
||||
},
|
||||
});
|
||||
@@ -981,6 +992,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 1661,
|
||||
@@ -1034,8 +1046,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 488,
|
||||
@@ -1110,6 +1125,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListByHeadSelector: {
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1618,
|
||||
@@ -1121,6 +1137,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
updatedAt: "2026-03-01T10:00:00Z",
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"upstream/effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1518,
|
||||
@@ -1132,8 +1149,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
updatedAt: "2026-04-01T10:00:00Z",
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"pingdotgg:effect-atom": JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"my-org/upstream:effect-atom": JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"pingdotgg:upstream/effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1518,
|
||||
@@ -1145,6 +1165,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
updatedAt: "2026-04-01T10:00:00Z",
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"my-org/upstream:upstream/effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1518,
|
||||
@@ -1194,6 +1215,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 22,
|
||||
@@ -1231,6 +1253,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 23,
|
||||
@@ -1262,6 +1285,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 45,
|
||||
@@ -1612,6 +1636,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
"[]",
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 77,
|
||||
@@ -1747,6 +1772,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
"[]",
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 303,
|
||||
@@ -1793,6 +1819,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
"[]",
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 404,
|
||||
@@ -1833,6 +1860,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 42,
|
||||
@@ -1886,7 +1914,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 142,
|
||||
@@ -1963,6 +1993,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListByHeadSelector: {
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1618,
|
||||
@@ -1972,6 +2003,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
headRefName: "effect-atom",
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"upstream/effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1518,
|
||||
@@ -1981,8 +2013,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
headRefName: "upstream/effect-atom",
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"pingdotgg:effect-atom": JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"my-org/upstream:effect-atom": JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"pingdotgg:upstream/effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1518,
|
||||
@@ -1992,6 +2027,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
headRefName: "upstream/effect-atom",
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"my-org/upstream:upstream/effect-atom": JSON.stringify([
|
||||
{
|
||||
number: 1518,
|
||||
@@ -2041,7 +2077,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListByHeadSelector: {
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"t3code/pr-142/statemachine": JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
statemachine: JSON.stringify([
|
||||
{
|
||||
number: 41,
|
||||
@@ -2051,6 +2089,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
headRefName: "statemachine",
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"octocat:statemachine": JSON.stringify([
|
||||
{
|
||||
number: 142,
|
||||
@@ -2068,6 +2107,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
},
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"fork-seed:statemachine": JSON.stringify([]),
|
||||
},
|
||||
},
|
||||
@@ -2112,6 +2152,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListByHeadSelector: {
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"octocat:statemachine": JSON.stringify([
|
||||
{
|
||||
number: 142,
|
||||
@@ -2129,8 +2170,11 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
},
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"fork-seed:statemachine": JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"t3code/pr-142/statemachine": JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
statemachine: JSON.stringify([]),
|
||||
},
|
||||
},
|
||||
@@ -2170,6 +2214,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
"[]",
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 88,
|
||||
@@ -2215,6 +2260,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager, ghCalls } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 1661,
|
||||
@@ -2232,6 +2278,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
},
|
||||
},
|
||||
]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 188,
|
||||
@@ -2294,7 +2341,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
ghScenario: {
|
||||
prListSequenceByHeadSelector: {
|
||||
"octocat:statemachine": [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 188,
|
||||
@@ -2313,7 +2362,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
},
|
||||
]),
|
||||
],
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
"fork-seed:statemachine": [JSON.stringify([])],
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
statemachine: [JSON.stringify([])],
|
||||
},
|
||||
},
|
||||
@@ -2870,7 +2921,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
yield* runGit(repoDir, ["add", "existing.txt"]);
|
||||
yield* runGit(repoDir, ["commit", "-m", "Existing worktree branch"]);
|
||||
yield* runGit(repoDir, ["checkout", "main"]);
|
||||
const worktreePath = path.join(repoDir, "..", `pr-existing-${Date.now()}`);
|
||||
const worktreePath = path.join(repoDir, "..", `pr-existing-${path.basename(repoDir)}`);
|
||||
yield* runGit(repoDir, ["worktree", "add", worktreePath, "feature/pr-existing-worktree"]);
|
||||
|
||||
const setupCalls: ProjectSetupScriptRunnerInput[] = [];
|
||||
@@ -3044,7 +3095,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
yield* runGit(repoDir, ["commit", "-m", "Reused fork PR branch"]);
|
||||
yield* runGit(repoDir, ["push", "-u", "fork-seed", "feature/pr-reused-fork"]);
|
||||
yield* runGit(repoDir, ["checkout", "main"]);
|
||||
const worktreePath = path.join(repoDir, "..", `pr-reused-fork-${Date.now()}`);
|
||||
const worktreePath = path.join(repoDir, "..", `pr-reused-fork-${path.basename(repoDir)}`);
|
||||
yield* runGit(repoDir, ["worktree", "add", worktreePath, "feature/pr-reused-fork"]);
|
||||
yield* runGit(worktreePath, ["branch", "--unset-upstream"], true);
|
||||
|
||||
@@ -3112,7 +3163,8 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
},
|
||||
},
|
||||
setupScriptRunner: {
|
||||
runForThread: () => Effect.fail(new Error("terminal start failed")),
|
||||
runForThread: () =>
|
||||
Effect.fail(new ProjectSetupScriptRunnerError({ message: "terminal start failed" })),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3289,7 +3341,9 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
prListSequence: [
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([]),
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{
|
||||
number: 201,
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import {
|
||||
Array as Arr,
|
||||
Cache,
|
||||
Context,
|
||||
DateTime,
|
||||
Duration,
|
||||
Effect,
|
||||
Exit,
|
||||
FileSystem,
|
||||
Layer,
|
||||
Option,
|
||||
Order,
|
||||
Path,
|
||||
Ref,
|
||||
} from "effect";
|
||||
import * as Arr from "effect/Array";
|
||||
import * as Cache from "effect/Cache";
|
||||
import * as Context from "effect/Context";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Order from "effect/Order";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Ref from "effect/Ref";
|
||||
import {
|
||||
GitActionProgressEvent,
|
||||
GitActionProgressPhase,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { assert, describe, it, vi } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import * as GitManager from "./GitManager.ts";
|
||||
import * as GitWorkflowService from "./GitWorkflowService.ts";
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Context, Effect, Layer } from "effect";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import {
|
||||
GitManagerError,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import { existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import Mime from "@effect/platform-node/Mime";
|
||||
import { decodeOtlpTraceRecords } from "@t3tools/shared/observability";
|
||||
import { Data, Effect, FileSystem, Option, Path } from "effect";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import { cast } from "effect/Function";
|
||||
import {
|
||||
HttpBody,
|
||||
|
||||
@@ -2,7 +2,13 @@ import { KeybindingCommand, KeybindingRule, KeybindingsConfig } from "@t3tools/c
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { assertFailure } from "@effect/vitest/utils";
|
||||
import { Cause, Effect, FileSystem, Layer, Logger, Path, Schema } from "effect";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Logger from "effect/Logger";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { ServerConfig } from "./config.ts";
|
||||
|
||||
import {
|
||||
@@ -17,6 +23,12 @@ import {
|
||||
import { KeybindingsConfigError } from "@t3tools/contracts";
|
||||
|
||||
const KeybindingsConfigJson = Schema.fromJsonString(KeybindingsConfig);
|
||||
const encodeKeybindingsConfigJson = Schema.encodeEffect(KeybindingsConfigJson);
|
||||
const decodeKeybindingsConfigJson = Schema.decodeUnknownEffect(KeybindingsConfigJson);
|
||||
const encodeResolvedKeybindingFromConfig = Schema.encodeEffect(ResolvedKeybindingFromConfig);
|
||||
const decodeResolvedKeybindingFromConfigExit = Schema.decodeUnknownExit(
|
||||
ResolvedKeybindingFromConfig,
|
||||
);
|
||||
const makeKeybindingsLayer = () => {
|
||||
return KeybindingsLive.pipe(
|
||||
Layer.provideMerge(
|
||||
@@ -39,7 +51,7 @@ const writeKeybindingsConfig = (configPath: string, rules: readonly KeybindingRu
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const path = yield* Path.Path;
|
||||
const encoded = yield* Schema.encodeEffect(KeybindingsConfigJson)(rules);
|
||||
const encoded = yield* encodeKeybindingsConfigJson(rules);
|
||||
yield* fileSystem.makeDirectory(path.dirname(configPath), { recursive: true });
|
||||
yield* fileSystem.writeFileString(configPath, encoded);
|
||||
});
|
||||
@@ -48,7 +60,7 @@ const readKeybindingsConfig = (configPath: string) =>
|
||||
Effect.gen(function* () {
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const rawConfig = yield* fileSystem.readFileString(configPath);
|
||||
return yield* Schema.decodeUnknownEffect(KeybindingsConfigJson)(rawConfig);
|
||||
return yield* decodeKeybindingsConfigJson(rawConfig);
|
||||
});
|
||||
|
||||
it.layer(NodeServices.layer)("keybindings", (it) => {
|
||||
@@ -105,7 +117,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
|
||||
|
||||
it.effect("encodes resolved plus-key shortcuts", () =>
|
||||
Effect.gen(function* () {
|
||||
const encoded = yield* Schema.encodeEffect(ResolvedKeybindingFromConfig)({
|
||||
const encoded = yield* encodeResolvedKeybindingFromConfig({
|
||||
command: "terminal.toggle",
|
||||
shortcut: {
|
||||
key: "+",
|
||||
@@ -151,7 +163,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
|
||||
|
||||
it.effect("formats invalid resolved keybinding rules with the custom message", () =>
|
||||
Effect.sync(() => {
|
||||
const result = Schema.decodeUnknownExit(ResolvedKeybindingFromConfig)({
|
||||
const result = decodeResolvedKeybindingFromConfigExit({
|
||||
key: "mod+shift+d+o",
|
||||
command: "terminal.new",
|
||||
});
|
||||
@@ -229,6 +241,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
|
||||
const { keybindingsConfigPath } = yield* ServerConfig;
|
||||
yield* fs.writeFileString(
|
||||
keybindingsConfigPath,
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
JSON.stringify([
|
||||
{ key: "mod+j", command: "terminal.toggle" },
|
||||
{ key: "mod+shift+d+o", command: "terminal.new" },
|
||||
|
||||
@@ -19,33 +19,30 @@ import {
|
||||
type ServerUpsertKeybindingInput,
|
||||
type ServerConfigIssue,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
Array,
|
||||
Cache,
|
||||
Cause,
|
||||
Deferred,
|
||||
Duration,
|
||||
Effect,
|
||||
Exit,
|
||||
FileSystem,
|
||||
Path,
|
||||
Layer,
|
||||
Option,
|
||||
Predicate,
|
||||
PubSub,
|
||||
Schema,
|
||||
SchemaGetter,
|
||||
SchemaIssue,
|
||||
SchemaTransformation,
|
||||
Ref,
|
||||
Context,
|
||||
Scope,
|
||||
Stream,
|
||||
} from "effect";
|
||||
import * as Array from "effect/Array";
|
||||
import * as Cache from "effect/Cache";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as SchemaIssue from "effect/SchemaIssue";
|
||||
import * as SchemaTransformation from "effect/SchemaTransformation";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as Semaphore from "effect/Semaphore";
|
||||
import { ServerConfig } from "./config.ts";
|
||||
import { writeFileStringAtomically } from "./atomicWrite.ts";
|
||||
import { fromLenientJson } from "@t3tools/shared/schemaJson";
|
||||
import { fromJsonStringPretty, fromLenientJson } from "@t3tools/shared/schemaJson";
|
||||
import {
|
||||
DEFAULT_KEYBINDINGS,
|
||||
DEFAULT_RESOLVED_KEYBINDINGS,
|
||||
@@ -172,16 +169,11 @@ function encodeWhenAst(node: KeybindingWhenNode): string {
|
||||
}
|
||||
|
||||
const RawKeybindingsEntries = fromLenientJson(Schema.Array(Schema.Unknown));
|
||||
const KeybindingsConfigJson = Schema.fromJsonString(KeybindingsConfig);
|
||||
const PrettyJsonString = SchemaGetter.parseJson<string>().compose(
|
||||
SchemaGetter.stringifyJson({ space: 2 }),
|
||||
);
|
||||
const KeybindingsConfigPrettyJson = KeybindingsConfigJson.pipe(
|
||||
Schema.encode({
|
||||
decode: PrettyJsonString,
|
||||
encode: PrettyJsonString,
|
||||
}),
|
||||
);
|
||||
const KeybindingsConfigPrettyJson = fromJsonStringPretty(KeybindingsConfig);
|
||||
const decodeKeybindingRuleExit = Schema.decodeUnknownExit(KeybindingRule);
|
||||
const decodeResolvedKeybindingFromConfigExit = Schema.decodeExit(ResolvedKeybindingFromConfig);
|
||||
const decodeRawKeybindingsEntriesExit = Schema.decodeUnknownExit(RawKeybindingsEntries);
|
||||
const encodeKeybindingsConfigPrettyJson = Schema.encodeEffect(KeybindingsConfigPrettyJson);
|
||||
|
||||
export interface KeybindingsConfigState {
|
||||
readonly keybindings: ResolvedKeybindingsConfig;
|
||||
@@ -356,7 +348,7 @@ const makeKeybindings = Effect.gen(function* () {
|
||||
|
||||
return yield* Effect.forEach(rawConfig, (entry) =>
|
||||
Effect.gen(function* () {
|
||||
const decodedRule = Schema.decodeUnknownExit(KeybindingRule)(entry);
|
||||
const decodedRule = decodeKeybindingRuleExit(entry);
|
||||
if (decodedRule._tag === "Failure") {
|
||||
yield* Effect.logWarning("ignoring invalid keybinding entry", {
|
||||
path: keybindingsConfigPath,
|
||||
@@ -365,7 +357,7 @@ const makeKeybindings = Effect.gen(function* () {
|
||||
});
|
||||
return null;
|
||||
}
|
||||
const resolved = Schema.decodeExit(ResolvedKeybindingFromConfig)(decodedRule.value);
|
||||
const resolved = decodeResolvedKeybindingFromConfigExit(decodedRule.value);
|
||||
if (resolved._tag === "Failure") {
|
||||
yield* Effect.logWarning("ignoring invalid keybinding entry", {
|
||||
path: keybindingsConfigPath,
|
||||
@@ -391,7 +383,7 @@ const makeKeybindings = Effect.gen(function* () {
|
||||
}
|
||||
|
||||
const rawConfig = yield* readRawConfig;
|
||||
const decodedEntries = Schema.decodeUnknownExit(RawKeybindingsEntries)(rawConfig);
|
||||
const decodedEntries = decodeRawKeybindingsEntriesExit(rawConfig);
|
||||
if (decodedEntries._tag === "Failure") {
|
||||
const detail = `expected JSON array (${Cause.pretty(decodedEntries.cause)})`;
|
||||
return {
|
||||
@@ -403,7 +395,7 @@ const makeKeybindings = Effect.gen(function* () {
|
||||
const keybindings: KeybindingRule[] = [];
|
||||
const issues: ServerConfigIssue[] = [];
|
||||
for (const [index, entry] of decodedEntries.value.entries()) {
|
||||
const decodedRule = Schema.decodeUnknownExit(KeybindingRule)(entry);
|
||||
const decodedRule = decodeKeybindingRuleExit(entry);
|
||||
if (decodedRule._tag === "Failure") {
|
||||
const detail = Cause.pretty(decodedRule.cause);
|
||||
issues.push(invalidEntryIssue(index, detail));
|
||||
@@ -416,7 +408,7 @@ const makeKeybindings = Effect.gen(function* () {
|
||||
continue;
|
||||
}
|
||||
|
||||
const resolvedRule = Schema.decodeExit(ResolvedKeybindingFromConfig)(decodedRule.value);
|
||||
const resolvedRule = decodeResolvedKeybindingFromConfigExit(decodedRule.value);
|
||||
if (resolvedRule._tag === "Failure") {
|
||||
const detail = Cause.pretty(resolvedRule.cause);
|
||||
issues.push(invalidEntryIssue(index, detail));
|
||||
@@ -435,7 +427,7 @@ const makeKeybindings = Effect.gen(function* () {
|
||||
});
|
||||
|
||||
const writeConfigAtomically = (rules: readonly KeybindingRule[]) => {
|
||||
return Schema.encodeEffect(KeybindingsConfigPrettyJson)(rules).pipe(
|
||||
return encodeKeybindingsConfigPrettyJson(rules).pipe(
|
||||
Effect.map((encoded) => `${encoded}\n`),
|
||||
Effect.flatMap((encoded) =>
|
||||
writeFileStringAtomically({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Cause, Exit } from "effect";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Exit from "effect/Exit";
|
||||
|
||||
export type MetricAttributeValue = string;
|
||||
export type MetricAttributes = Readonly<Record<string, MetricAttributeValue>>;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { makeLocalFileTracer, makeTraceSink } from "@t3tools/shared/observability";
|
||||
import { Effect, Layer, References, Tracer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as References from "effect/References";
|
||||
import * as Tracer from "effect/Tracer";
|
||||
import { OtlpMetrics, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
|
||||
|
||||
import { ServerConfig } from "../../config.ts";
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import { ProviderDriverKind } from "@t3tools/contracts";
|
||||
import { Duration, Effect, Fiber, Metric } from "effect";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Metric from "effect/Metric";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
|
||||
import { withMetrics } from "./Metrics.ts";
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Clock, Duration, Effect, Exit, Metric } from "effect";
|
||||
import * as Clock from "effect/Clock";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Metric from "effect/Metric";
|
||||
import { dual } from "effect/Function";
|
||||
|
||||
import {
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
import { WS_METHODS } from "@t3tools/contracts";
|
||||
import { Duration, Effect, Exit, Fiber, Metric, Stream, Tracer } from "effect";
|
||||
import { TestClock } from "effect/testing";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Metric from "effect/Metric";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as Tracer from "effect/Tracer";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
|
||||
import {
|
||||
observeRpcEffect,
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { WS_METHODS } from "@t3tools/contracts";
|
||||
import { Clock, Duration, Effect, Exit, Metric, References, Stream } from "effect";
|
||||
import * as Clock from "effect/Clock";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Metric from "effect/Metric";
|
||||
import * as References from "effect/References";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import { outcomeFromExit } from "./Attributes.ts";
|
||||
import { metricAttributes, rpcRequestDuration, rpcRequestsTotal, withMetrics } from "./Metrics.ts";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { TraceRecord } from "@t3tools/shared/observability";
|
||||
import { Context } from "effect";
|
||||
import type { Effect } from "effect";
|
||||
import * as Context from "effect/Context";
|
||||
import type * as Effect from "effect/Effect";
|
||||
|
||||
export interface BrowserTraceCollectorShape {
|
||||
readonly record: (records: ReadonlyArray<TraceRecord>) => Effect.Effect<void>;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { assertSuccess } from "@effect/vitest/utils";
|
||||
import { FileSystem, Path, Effect } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Random from "effect/Random";
|
||||
|
||||
import {
|
||||
isCommandAvailable,
|
||||
@@ -488,7 +491,7 @@ it.layer(NodeServices.layer)("launchDetached", (it) => {
|
||||
it.effect("rejects when command does not exist", () =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* launchDetached({
|
||||
command: `t3code-no-such-command-${Date.now()}`,
|
||||
command: `t3code-no-such-command-${yield* Random.nextUUIDv4}`,
|
||||
args: [],
|
||||
}).pipe(Effect.result);
|
||||
assert.equal(result._tag, "Failure");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
/**
|
||||
* Open - Browser/editor launch service interface.
|
||||
*
|
||||
@@ -10,7 +11,9 @@ import { spawn } from "node:child_process";
|
||||
|
||||
import { EDITORS, OpenError, type EditorId } from "@t3tools/contracts";
|
||||
import { isCommandAvailable, type CommandAvailabilityOptions } from "@t3tools/shared/shell";
|
||||
import { Context, Effect, Layer } from "effect";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
// ==============================
|
||||
// Definitions
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SchemaIssue, Schema } from "effect";
|
||||
import * as SchemaIssue from "effect/SchemaIssue";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
import type { ProjectionRepositoryError } from "../persistence/Errors.ts";
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -19,7 +20,14 @@ import {
|
||||
TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { Effect, Exit, Layer, ManagedRuntime, PubSub, Scope, Stream } from "effect";
|
||||
import * as Clock from "effect/Clock";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as ManagedRuntime from "effect/ManagedRuntime";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { CheckpointStoreLive } from "../../checkpointing/Layers/CheckpointStore.ts";
|
||||
@@ -73,7 +81,7 @@ function createProviderServiceHarness(
|
||||
sessionCwd = cwd,
|
||||
providerName: ProviderSession["provider"] = ProviderDriverKind.make("codex"),
|
||||
) {
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const runtimeEventPubSub = Effect.runSync(PubSub.unbounded<ProviderRuntimeEvent>());
|
||||
const rollbackConversation = vi.fn(
|
||||
(_input: { readonly threadId: ThreadId; readonly numTurns: number }) => Effect.void,
|
||||
@@ -148,7 +156,7 @@ async function waitForThread(
|
||||
}) => boolean,
|
||||
timeoutMs = 15_000,
|
||||
) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const deadline = (await Effect.runPromise(Clock.currentTimeMillis)) + timeoutMs;
|
||||
const poll = async (): Promise<{
|
||||
latestTurn: { turnId: string } | null;
|
||||
checkpoints: ReadonlyArray<{ checkpointTurnCount: number }>;
|
||||
@@ -159,10 +167,10 @@ async function waitForThread(
|
||||
if (thread && predicate(thread)) {
|
||||
return thread;
|
||||
}
|
||||
if (Date.now() >= deadline) {
|
||||
if ((await Effect.runPromise(Clock.currentTimeMillis)) >= deadline) {
|
||||
throw new Error("Timed out waiting for thread state.");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
await Effect.runPromise(Effect.sleep("10 millis"));
|
||||
return poll();
|
||||
};
|
||||
return poll();
|
||||
@@ -173,7 +181,7 @@ async function waitForEvent(
|
||||
predicate: (event: { type: string }) => boolean,
|
||||
timeoutMs = 15_000,
|
||||
) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const deadline = (await Effect.runPromise(Clock.currentTimeMillis)) + timeoutMs;
|
||||
const poll = async () => {
|
||||
const events = await Effect.runPromise(
|
||||
Stream.runCollect(engine.readEvents(0)).pipe(Effect.map((chunk) => Array.from(chunk))),
|
||||
@@ -181,10 +189,10 @@ async function waitForEvent(
|
||||
if (events.some(predicate)) {
|
||||
return events;
|
||||
}
|
||||
if (Date.now() >= deadline) {
|
||||
if ((await Effect.runPromise(Clock.currentTimeMillis)) >= deadline) {
|
||||
throw new Error("Timed out waiting for orchestration event.");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
await Effect.runPromise(Effect.sleep("10 millis"));
|
||||
return poll();
|
||||
};
|
||||
return poll();
|
||||
@@ -223,15 +231,15 @@ function gitShowFileAtRef(cwd: string, ref: string, filePath: string): string {
|
||||
}
|
||||
|
||||
async function waitForGitRefExists(cwd: string, ref: string, timeoutMs = 15_000) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const deadline = (await Effect.runPromise(Clock.currentTimeMillis)) + timeoutMs;
|
||||
const poll = async (): Promise<void> => {
|
||||
if (gitRefExists(cwd, ref)) {
|
||||
return;
|
||||
}
|
||||
if (Date.now() >= deadline) {
|
||||
if ((await Effect.runPromise(Clock.currentTimeMillis)) >= deadline) {
|
||||
throw new Error(`Timed out waiting for git ref '${ref}'.`);
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
await Effect.runPromise(Effect.sleep("10 millis"));
|
||||
return poll();
|
||||
};
|
||||
return poll();
|
||||
@@ -342,7 +350,7 @@ describe("CheckpointReactor", () => {
|
||||
await Effect.runPromise(reactor.start().pipe(Scope.provide(scope)));
|
||||
const drain = () => Effect.runPromise(reactor.drain);
|
||||
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
await Effect.runPromise(
|
||||
engine.dispatch({
|
||||
type: "project.create",
|
||||
@@ -410,7 +418,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("captures pre-turn baseline on turn.started and post-turn checkpoint on turn.completed", async () => {
|
||||
const harness = await createHarness({ seedFilesystemCheckpoints: false });
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -435,7 +443,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-started-1"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-1"),
|
||||
});
|
||||
@@ -450,7 +458,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-completed-1"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-1"),
|
||||
payload: { state: "completed" },
|
||||
@@ -495,7 +503,7 @@ describe("CheckpointReactor", () => {
|
||||
type: "turn.completed",
|
||||
eventId: EventId.make("evt-turn-completed-refresh-local-status"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-refresh-local-status"),
|
||||
payload: { state: "completed" },
|
||||
@@ -508,7 +516,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("ignores auxiliary thread turn completion while primary turn is active", async () => {
|
||||
const harness = await createHarness({ seedFilesystemCheckpoints: false });
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -533,7 +541,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-started-main"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-main"),
|
||||
});
|
||||
@@ -549,7 +557,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-completed-aux"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-aux"),
|
||||
payload: { state: "completed" },
|
||||
@@ -565,7 +573,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-completed-main"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-main"),
|
||||
payload: { state: "completed" },
|
||||
@@ -583,7 +591,7 @@ describe("CheckpointReactor", () => {
|
||||
seedFilesystemCheckpoints: false,
|
||||
providerName: ProviderDriverKind.make("claudeAgent"),
|
||||
});
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -607,7 +615,7 @@ describe("CheckpointReactor", () => {
|
||||
type: "turn.started",
|
||||
eventId: EventId.make("evt-turn-started-claude-1"),
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-claude-1"),
|
||||
});
|
||||
@@ -621,7 +629,7 @@ describe("CheckpointReactor", () => {
|
||||
type: "turn.completed",
|
||||
eventId: EventId.make("evt-turn-completed-claude-1"),
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-claude-1"),
|
||||
payload: { state: "completed" },
|
||||
@@ -641,7 +649,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("appends capture failure activity when turn diff summary cannot be derived", async () => {
|
||||
const harness = await createHarness({ seedFilesystemCheckpoints: false });
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -666,7 +674,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-completed-missing-baseline"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-missing-baseline"),
|
||||
payload: { state: "completed" },
|
||||
@@ -706,7 +714,7 @@ describe("CheckpointReactor", () => {
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -729,7 +737,7 @@ describe("CheckpointReactor", () => {
|
||||
seedFilesystemCheckpoints: false,
|
||||
threadWorktreePath: null,
|
||||
});
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -755,7 +763,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-completed-missing-provider-cwd"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-missing-cwd"),
|
||||
payload: { state: "completed" },
|
||||
@@ -776,7 +784,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("ignores non-v2 checkpoint.captured runtime events", async () => {
|
||||
const harness = await createHarness();
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -801,7 +809,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-checkpoint-captured-3"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-3"),
|
||||
turnCount: 3,
|
||||
@@ -826,7 +834,7 @@ describe("CheckpointReactor", () => {
|
||||
seedFilesystemCheckpoints: false,
|
||||
providerSessionCwd: nonRepositorySessionCwd,
|
||||
});
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -851,7 +859,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-runtime-capture-failure"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-runtime-failure"),
|
||||
payload: { state: "completed" },
|
||||
@@ -862,7 +870,7 @@ describe("CheckpointReactor", () => {
|
||||
eventId: EventId.make("evt-turn-started-after-runtime-failure"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
turnId: asTurnId("turn-after-runtime-failure"),
|
||||
});
|
||||
@@ -878,7 +886,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("executes provider revert and emits thread.reverted for checkpoint revert requests", async () => {
|
||||
const harness = await createHarness();
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -959,7 +967,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("executes provider revert and emits thread.reverted for claude sessions", async () => {
|
||||
const harness = await createHarness({ providerName: ProviderDriverKind.make("claudeAgent") });
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1028,7 +1036,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("processes consecutive revert requests with deterministic rollback sequencing", async () => {
|
||||
const harness = await createHarness();
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1111,7 +1119,7 @@ describe("CheckpointReactor", () => {
|
||||
|
||||
it("appends an error activity when revert is requested without an active session", async () => {
|
||||
const harness = await createHarness({ hasSession: false });
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
|
||||
@@ -8,7 +8,12 @@ import {
|
||||
type OrchestrationEvent,
|
||||
type ProviderRuntimeEvent,
|
||||
} from "@t3tools/contracts";
|
||||
import { Cause, Effect, Layer, Option, Stream } from "effect";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
|
||||
|
||||
import { parseTurnDiffFilesFromUnifiedDiff } from "../../checkpointing/Diffs.ts";
|
||||
@@ -28,6 +33,8 @@ import { isGitRepository } from "../../git/Utils.ts";
|
||||
import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
|
||||
import { WorkspaceEntries } from "../../workspace/Services/WorkspaceEntries.ts";
|
||||
|
||||
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
|
||||
|
||||
type ReactorInput =
|
||||
| {
|
||||
readonly source: "runtime";
|
||||
@@ -584,7 +591,7 @@ const make = Effect.gen(function* () {
|
||||
const handleRevertRequested = Effect.fn("handleRevertRequested")(function* (
|
||||
event: Extract<OrchestrationEvent, { type: "thread.checkpoint-revert-requested" }>,
|
||||
) {
|
||||
const now = new Date().toISOString();
|
||||
const now = DateTime.formatIso(yield* DateTime.now);
|
||||
|
||||
const thread = yield* resolveThreadDetail(event.payload.threadId);
|
||||
if (!thread) {
|
||||
@@ -717,12 +724,14 @@ const make = Effect.gen(function* () {
|
||||
if (event.type === "thread.checkpoint-revert-requested") {
|
||||
yield* handleRevertRequested(event).pipe(
|
||||
Effect.catch((error) =>
|
||||
appendRevertFailureActivity({
|
||||
threadId: event.payload.threadId,
|
||||
turnCount: event.payload.turnCount,
|
||||
detail: error.message,
|
||||
createdAt: new Date().toISOString(),
|
||||
}),
|
||||
Effect.flatMap(nowIso, (createdAt) =>
|
||||
appendRevertFailureActivity({
|
||||
threadId: event.payload.threadId,
|
||||
turnCount: event.payload.turnCount,
|
||||
detail: error.message,
|
||||
createdAt,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
@@ -736,12 +745,14 @@ const make = Effect.gen(function* () {
|
||||
if (event.type === "thread.turn-diff-completed") {
|
||||
yield* captureCheckpointFromPlaceholder(event).pipe(
|
||||
Effect.catch((error) =>
|
||||
appendCaptureFailureActivity({
|
||||
threadId: event.payload.threadId,
|
||||
turnId: event.payload.turnId,
|
||||
detail: error.message,
|
||||
createdAt: new Date().toISOString(),
|
||||
}).pipe(Effect.catch(() => Effect.void)),
|
||||
Effect.flatMap(nowIso, (createdAt) =>
|
||||
appendCaptureFailureActivity({
|
||||
threadId: event.payload.threadId,
|
||||
turnId: event.payload.turnId,
|
||||
detail: error.message,
|
||||
createdAt,
|
||||
}).pipe(Effect.catch(() => Effect.void)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -760,12 +771,14 @@ const make = Effect.gen(function* () {
|
||||
yield* refreshLocalGitStatusFromTurnCompletion(event);
|
||||
yield* captureCheckpointFromTurnCompletion(event).pipe(
|
||||
Effect.catch((error) =>
|
||||
appendCaptureFailureActivity({
|
||||
threadId: event.threadId,
|
||||
turnId,
|
||||
detail: error.message,
|
||||
createdAt: new Date().toISOString(),
|
||||
}).pipe(Effect.catch(() => Effect.void)),
|
||||
Effect.flatMap(nowIso, (createdAt) =>
|
||||
appendCaptureFailureActivity({
|
||||
threadId: event.threadId,
|
||||
turnId,
|
||||
detail: error.message,
|
||||
createdAt,
|
||||
}).pipe(Effect.catch(() => Effect.void)),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
|
||||
@@ -8,9 +8,14 @@ import {
|
||||
TurnId,
|
||||
type OrchestrationEvent,
|
||||
ProviderInstanceId,
|
||||
type OrchestrationReadModel,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Layer, ManagedRuntime, Metric, Option, Queue, Stream } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as ManagedRuntime from "effect/ManagedRuntime";
|
||||
import * as Metric from "effect/Metric";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { PersistenceSqlError } from "../../persistence/Errors.ts";
|
||||
@@ -69,7 +74,7 @@ async function createOrchestrationSystem() {
|
||||
}
|
||||
|
||||
function now() {
|
||||
return new Date().toISOString();
|
||||
return "2026-01-01T00:00:00.000Z";
|
||||
}
|
||||
|
||||
const hasMetricSnapshot = (
|
||||
|
||||
@@ -5,20 +5,20 @@ import type {
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { OrchestrationCommand } from "@t3tools/contracts";
|
||||
import {
|
||||
Cause,
|
||||
Deferred,
|
||||
Duration,
|
||||
Effect,
|
||||
Exit,
|
||||
Layer,
|
||||
Metric,
|
||||
Option,
|
||||
PubSub,
|
||||
Queue,
|
||||
Schema,
|
||||
Stream,
|
||||
} from "effect";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Clock from "effect/Clock";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Metric from "effect/Metric";
|
||||
import * as Option from "effect/Option";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Queue from "effect/Queue";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import {
|
||||
@@ -44,6 +44,10 @@ import {
|
||||
OrchestrationEngineService,
|
||||
type OrchestrationEngineShape,
|
||||
} from "../Services/OrchestrationEngine.ts";
|
||||
const isOrchestrationCommandPreviouslyRejectedError = Schema.is(
|
||||
OrchestrationCommandPreviouslyRejectedError,
|
||||
);
|
||||
const isOrchestrationCommandInvariantError = Schema.is(OrchestrationCommandInvariantError);
|
||||
|
||||
interface CommandEnvelope {
|
||||
command: OrchestrationCommand;
|
||||
@@ -78,7 +82,8 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const projectionSnapshotQuery = yield* ProjectionSnapshotQuery;
|
||||
|
||||
let commandReadModel = createEmptyReadModel(new Date().toISOString());
|
||||
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
|
||||
let commandReadModel = createEmptyReadModel(yield* nowIso);
|
||||
|
||||
const commandQueue = yield* Queue.unbounded<CommandEnvelope>();
|
||||
const eventPubSub = yield* PubSub.unbounded<OrchestrationEvent>();
|
||||
@@ -97,7 +102,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
|
||||
const processEnvelope = (envelope: CommandEnvelope): Effect.Effect<void> => {
|
||||
const dispatchStartSequence = commandReadModel.snapshotSequence;
|
||||
const processingStartedAtMs = Date.now();
|
||||
let processingStartedAtMs = 0;
|
||||
const aggregateRef = commandToAggregateRef(envelope.command);
|
||||
const baseMetricAttributes = {
|
||||
commandType: envelope.command.type,
|
||||
@@ -120,6 +125,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
|
||||
return Effect.exit(
|
||||
Effect.gen(function* () {
|
||||
processingStartedAtMs = yield* Clock.currentTimeMillis;
|
||||
yield* Effect.annotateCurrentSpan({
|
||||
"orchestration.command_id": envelope.command.commandId,
|
||||
"orchestration.command_type": envelope.command.type,
|
||||
@@ -205,7 +211,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
ackEventType: event.type,
|
||||
}),
|
||||
),
|
||||
Duration.millis(Math.max(0, Date.now() - envelope.startedAtMs)),
|
||||
Duration.millis(Math.max(0, (yield* Clock.currentTimeMillis) - envelope.startedAtMs)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -224,7 +230,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
orchestrationCommandDuration,
|
||||
metricAttributes(baseMetricAttributes),
|
||||
),
|
||||
Duration.millis(Math.max(0, Date.now() - processingStartedAtMs)),
|
||||
Duration.millis(Math.max(0, (yield* Clock.currentTimeMillis) - processingStartedAtMs)),
|
||||
);
|
||||
yield* Metric.update(
|
||||
Metric.withAttributes(
|
||||
@@ -243,7 +249,7 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
}
|
||||
|
||||
const error = Cause.squash(exit.cause) as OrchestrationDispatchError;
|
||||
if (!Schema.is(OrchestrationCommandPreviouslyRejectedError)(error)) {
|
||||
if (!isOrchestrationCommandPreviouslyRejectedError(error)) {
|
||||
yield* reconcileReadModelAfterDispatchFailure.pipe(
|
||||
Effect.catch(() =>
|
||||
Effect.logWarning(
|
||||
@@ -257,13 +263,13 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
),
|
||||
);
|
||||
|
||||
if (Schema.is(OrchestrationCommandInvariantError)(error)) {
|
||||
if (isOrchestrationCommandInvariantError(error)) {
|
||||
yield* commandReceiptRepository
|
||||
.upsert({
|
||||
commandId: envelope.command.commandId,
|
||||
aggregateKind: aggregateRef.aggregateKind,
|
||||
aggregateId: aggregateRef.aggregateId,
|
||||
acceptedAt: new Date().toISOString(),
|
||||
acceptedAt: yield* nowIso,
|
||||
resultSequence: commandReadModel.snapshotSequence,
|
||||
status: "rejected",
|
||||
error: error.message,
|
||||
@@ -293,7 +299,11 @@ const makeOrchestrationEngine = Effect.gen(function* () {
|
||||
const dispatch: OrchestrationEngineShape["dispatch"] = (command) =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* Deferred.make<{ sequence: number }, OrchestrationDispatchError>();
|
||||
yield* Queue.offer(commandQueue, { command, result, startedAtMs: Date.now() });
|
||||
yield* Queue.offer(commandQueue, {
|
||||
command,
|
||||
result,
|
||||
startedAtMs: yield* Clock.currentTimeMillis,
|
||||
});
|
||||
return yield* Deferred.await(result);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Effect, Exit, Layer, ManagedRuntime, Scope } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as ManagedRuntime from "effect/ManagedRuntime";
|
||||
import * as Scope from "effect/Scope";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { CheckpointReactor } from "../Services/CheckpointReactor.ts";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
|
||||
import {
|
||||
OrchestrationReactor,
|
||||
|
||||
@@ -11,7 +11,10 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, FileSystem, Layer, Path } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
|
||||
@@ -55,7 +58,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
yield* eventStore.append({
|
||||
type: "project.created",
|
||||
@@ -180,7 +183,7 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-base-")))(
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
yield* eventStore.append({
|
||||
type: "thread.message-sent",
|
||||
@@ -224,6 +227,7 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-base-")))(
|
||||
WHERE message_id = 'message-attachments'
|
||||
`;
|
||||
assert.equal(rows.length, 1);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
assert.deepEqual(JSON.parse(rows[0]?.attachmentsJson ?? "null"), [
|
||||
{
|
||||
type: "image",
|
||||
@@ -246,7 +250,7 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-projection-atta
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
yield* eventStore.append({
|
||||
type: "thread.message-sent",
|
||||
@@ -297,6 +301,7 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-projection-atta
|
||||
WHERE message_id = 'message-attachments-safe'
|
||||
`;
|
||||
assert.equal(rows.length, 1);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
assert.deepEqual(JSON.parse(rows[0]?.attachmentsJson ?? "null"), [
|
||||
{
|
||||
type: "image",
|
||||
@@ -326,8 +331,8 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const later = new Date(Date.now() + 1_000).toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const later = "2026-01-01T00:00:01.000Z";
|
||||
|
||||
yield* eventStore.append({
|
||||
type: "project.created",
|
||||
@@ -441,6 +446,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
WHERE message_id = 'message-clear-attachments'
|
||||
`;
|
||||
assert.equal(rows.length, 1);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
assert.deepEqual(JSON.parse(rows[0]?.attachmentsJson ?? "null"), []);
|
||||
}),
|
||||
);
|
||||
@@ -454,8 +460,8 @@ it.layer(
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const later = new Date(Date.now() + 1_000).toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const later = "2026-01-01T00:00:01.000Z";
|
||||
|
||||
yield* eventStore.append({
|
||||
type: "project.created",
|
||||
@@ -576,6 +582,7 @@ it.layer(
|
||||
WHERE message_id = 'message-overwrite'
|
||||
`;
|
||||
assert.equal(rows.length, 1);
|
||||
// @effect-diagnostics-next-line preferSchemaOverJson:off
|
||||
assert.deepEqual(JSON.parse(rows[0]?.attachmentsJson ?? "null"), [
|
||||
{
|
||||
type: "image",
|
||||
@@ -598,7 +605,7 @@ it.layer(
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const path = yield* Path.Path;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
const appendAndProject = (event: Parameters<typeof eventStore.append>[0]) =>
|
||||
eventStore
|
||||
@@ -722,7 +729,7 @@ it.layer(
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const { attachmentsDir } = yield* ServerConfig;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const threadId = ThreadId.make("Thread Revert.Files");
|
||||
const keepAttachmentId = "thread-revert-files-00000000-0000-4000-8000-000000000001";
|
||||
const removeAttachmentId = "thread-revert-files-00000000-0000-4000-8000-000000000002";
|
||||
@@ -931,7 +938,7 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-projection-atta
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const { attachmentsDir } = yield* ServerConfig;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const threadId = ThreadId.make("Thread Delete.Files");
|
||||
const attachmentId = "thread-delete-files-00000000-0000-4000-8000-000000000001";
|
||||
const otherThreadAttachmentId =
|
||||
@@ -1063,7 +1070,7 @@ it.layer(Layer.fresh(makeProjectionPipelinePrefixedTestLayer("t3-projection-atta
|
||||
const path = yield* Path.Path;
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const { attachmentsDir: attachmentsRootDir, stateDir } = yield* ServerConfig;
|
||||
const attachmentsSentinelPath = path.join(attachmentsRootDir, "sentinel.txt");
|
||||
const stateDirSentinelPath = path.join(stateDir, "state-sentinel.txt");
|
||||
@@ -1103,7 +1110,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
yield* eventStore.append({
|
||||
type: "project.created",
|
||||
@@ -1230,7 +1237,7 @@ it.layer(BaseTestLayer)("OrchestrationProjectionPipeline", (it) => {
|
||||
const projectionPipeline = yield* OrchestrationProjectionPipeline;
|
||||
const eventStore = yield* OrchestrationEventStore;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
yield* eventStore.append({
|
||||
type: "project.created",
|
||||
@@ -2187,7 +2194,7 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
|
||||
Effect.gen(function* () {
|
||||
const engine = yield* OrchestrationEngineService;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
yield* engine.dispatch({
|
||||
type: "project.create",
|
||||
@@ -2225,7 +2232,7 @@ engineLayer("OrchestrationProjectionPipeline via engine dispatch", (it) => {
|
||||
Effect.gen(function* () {
|
||||
const engine = yield* OrchestrationEngineService;
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
yield* engine.dispatch({
|
||||
type: "project.create",
|
||||
|
||||
@@ -4,7 +4,12 @@ import {
|
||||
type OrchestrationEvent,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, FileSystem, Layer, Option, Path, Stream } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { toPersistenceSqlError, type ProjectionRepositoryError } from "../../persistence/Errors.ts";
|
||||
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
ProviderInstanceId,
|
||||
} from "@t3tools/contracts";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
|
||||
|
||||
@@ -23,7 +23,11 @@ import {
|
||||
ProjectId,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Layer, Option, Schema, Struct } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Struct from "effect/Struct";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
import * as SqlSchema from "effect/unstable/sql/SqlSchema";
|
||||
|
||||
@@ -1005,7 +1009,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
snapshotSequence: computeSnapshotSequence(stateRows),
|
||||
projects,
|
||||
threads,
|
||||
updatedAt: updatedAt ?? new Date(0).toISOString(),
|
||||
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
|
||||
};
|
||||
|
||||
return yield* decodeReadModel(snapshot).pipe(
|
||||
@@ -1204,7 +1208,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
snapshotSequence: computeSnapshotSequence(stateRows),
|
||||
projects,
|
||||
threads,
|
||||
updatedAt: updatedAt ?? new Date(0).toISOString(),
|
||||
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
|
||||
} satisfies OrchestrationReadModel;
|
||||
}),
|
||||
),
|
||||
@@ -1326,7 +1330,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
hasActionableProposedPlan: row.hasActionableProposedPlan > 0,
|
||||
}),
|
||||
),
|
||||
updatedAt: updatedAt ?? new Date(0).toISOString(),
|
||||
updatedAt: updatedAt ?? "1970-01-01T00:00:00.000Z",
|
||||
};
|
||||
|
||||
return yield* decodeShellSnapshot(snapshot).pipe(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -20,7 +21,13 @@ import {
|
||||
ThreadId,
|
||||
TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Exit, Layer, ManagedRuntime, PubSub, Scope, Stream } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as ManagedRuntime from "effect/ManagedRuntime";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { deriveServerPaths, ServerConfig } from "../../config.ts";
|
||||
@@ -47,6 +54,7 @@ import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
|
||||
import { ProviderCommandReactor } from "../Services/ProviderCommandReactor.ts";
|
||||
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import * as Clock from "effect/Clock";
|
||||
import { ServerSettingsService } from "../../serverSettings.ts";
|
||||
import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
|
||||
import { GitWorkflowService, type GitWorkflowServiceShape } from "../../git/GitWorkflowService.ts";
|
||||
@@ -63,15 +71,15 @@ async function waitFor(
|
||||
predicate: () => boolean | Promise<boolean>,
|
||||
timeoutMs = 2000,
|
||||
): Promise<void> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const deadline = (await Effect.runPromise(Clock.currentTimeMillis)) + timeoutMs;
|
||||
const poll = async (): Promise<void> => {
|
||||
if (await predicate()) {
|
||||
return;
|
||||
}
|
||||
if (Date.now() >= deadline) {
|
||||
if ((await Effect.runPromise(Clock.currentTimeMillis)) >= deadline) {
|
||||
throw new Error("Timed out waiting for expectation.");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
await Effect.runPromise(Effect.yieldNow);
|
||||
return poll();
|
||||
};
|
||||
|
||||
@@ -135,7 +143,7 @@ describe("ProviderCommandReactor", () => {
|
||||
readonly threadModelSelection?: ModelSelection;
|
||||
readonly sessionModelSwitch?: "unsupported" | "in-session";
|
||||
}) {
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const baseDir = input?.baseDir ?? fs.mkdtempSync(path.join(os.tmpdir(), "t3code-reactor-"));
|
||||
createdBaseDirs.add(baseDir);
|
||||
const { stateDir } = deriveServerPathsSync(baseDir, undefined);
|
||||
@@ -408,7 +416,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("reacts to thread.turn.start by ensuring session and sending provider turn", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -447,7 +455,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("generates a thread title on the first turn", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const seededTitle = "Please investigate reconnect failures after restar...";
|
||||
harness.generateThreadTitle.mockReturnValue(Effect.succeed({ title: "Generated title" }));
|
||||
|
||||
@@ -497,7 +505,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("does not overwrite an existing custom thread title on the first turn", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const seededTitle = "Please investigate reconnect failures after restar...";
|
||||
|
||||
await Effect.runPromise(
|
||||
@@ -537,7 +545,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("matches the client-seeded title even when the outgoing prompt is reformatted", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const seededTitle = "Fix reconnect spinner on resume";
|
||||
harness.generateThreadTitle.mockReturnValue(
|
||||
Effect.succeed({
|
||||
@@ -588,7 +596,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("generates a worktree branch name for the first turn", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -642,7 +650,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("forwards codex model options through session start and turn send", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -689,7 +697,7 @@ describe("ProviderCommandReactor", () => {
|
||||
model: "claude-sonnet-4-6",
|
||||
},
|
||||
});
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -739,7 +747,7 @@ describe("ProviderCommandReactor", () => {
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
});
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -784,7 +792,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("forwards plan interaction mode to the provider turn request", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -822,7 +830,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("preserves the active session model when in-session model switching is unsupported", async () => {
|
||||
const harness = await createHarness({ sessionModelSwitch: "unsupported" });
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -875,7 +883,7 @@ describe("ProviderCommandReactor", () => {
|
||||
const harness = await createHarness({
|
||||
threadModelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5-codex" },
|
||||
});
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -921,7 +929,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("reuses the same provider session when runtime mode is unchanged", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -967,7 +975,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("restarts an existing Codex thread on a compatible requested instance", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1009,7 +1017,7 @@ describe("ProviderCommandReactor", () => {
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1034,7 +1042,7 @@ describe("ProviderCommandReactor", () => {
|
||||
model: "claude-sonnet-4-6",
|
||||
},
|
||||
});
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1107,7 +1115,7 @@ describe("ProviderCommandReactor", () => {
|
||||
model: "claude-sonnet-4-6",
|
||||
},
|
||||
});
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1170,7 +1178,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("restarts the provider session when runtime mode is updated on the thread", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1260,7 +1268,7 @@ describe("ProviderCommandReactor", () => {
|
||||
model: "claude-opus-4-6",
|
||||
},
|
||||
});
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1303,7 +1311,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("does not stop the active session when restart fails before rebind", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1336,7 +1344,7 @@ describe("ProviderCommandReactor", () => {
|
||||
await waitFor(() => harness.sendTurn.mock.calls.length === 1);
|
||||
|
||||
harness.startSession.mockImplementationOnce(
|
||||
(_: unknown, __: unknown) => Effect.fail(new Error("simulated restart failure")) as never,
|
||||
(_: unknown, __: unknown) => Effect.fail("simulated restart failure") as never,
|
||||
);
|
||||
|
||||
await Effect.runPromise(
|
||||
@@ -1368,7 +1376,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("rejects provider changes after a thread is already bound to a session provider", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1440,7 +1448,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("rejects cross-driver provider changes after the existing thread session has stopped", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1506,7 +1514,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("reacts to thread.turn.interrupt-requested by calling provider interrupt", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1544,7 +1552,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("starts a fresh session when only projected session state exists", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1599,7 +1607,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("rejects active runtime sessions that are missing provider instance ids", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1670,7 +1678,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("reacts to thread.approval.respond by forwarding provider approval response", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1711,7 +1719,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("reacts to thread.user-input.respond by forwarding structured user input answers", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1756,7 +1764,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("surfaces stale provider approval request failures without faking approval resolution", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
harness.respondToRequest.mockImplementation(() =>
|
||||
Effect.fail(
|
||||
new ProviderAdapterRequestError({
|
||||
@@ -1851,7 +1859,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("surfaces stale provider user-input failures without faking user-input resolution", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
harness.respondToUserInput.mockImplementation(() =>
|
||||
Effect.fail(
|
||||
new ProviderAdapterRequestError({
|
||||
@@ -1960,7 +1968,7 @@ describe("ProviderCommandReactor", () => {
|
||||
|
||||
it("reacts to thread.session.stop by stopping provider session and clearing thread session state", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
|
||||
@@ -13,7 +13,15 @@ import {
|
||||
type TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
import { isTemporaryWorktreeBranch, WORKTREE_BRANCH_PREFIX } from "@t3tools/shared/git";
|
||||
import { Cache, Cause, Duration, Effect, Equal, Layer, Option, Schema, Stream } from "effect";
|
||||
import * as Cache from "effect/Cache";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Equal from "effect/Equal";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
|
||||
|
||||
import { resolveThreadWorkspaceCwd } from "../../checkpointing/Utils.ts";
|
||||
@@ -31,6 +39,8 @@ import {
|
||||
import { ServerSettingsService } from "../../serverSettings.ts";
|
||||
import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
|
||||
import { GitWorkflowService } from "../../git/GitWorkflowService.ts";
|
||||
const isProviderAdapterRequestError = Schema.is(ProviderAdapterRequestError);
|
||||
const isProviderDriverKind = Schema.is(ProviderDriverKind);
|
||||
|
||||
type ProviderIntentEvent = Extract<
|
||||
OrchestrationEvent,
|
||||
@@ -110,7 +120,7 @@ function findProviderAdapterRequestError(
|
||||
cause: Cause.Cause<ProviderServiceError>,
|
||||
): ProviderAdapterRequestError | undefined {
|
||||
const failReason = cause.reasons.find(Cause.isFailReason);
|
||||
return Schema.is(ProviderAdapterRequestError)(failReason?.error) ? failReason.error : undefined;
|
||||
return isProviderAdapterRequestError(failReason?.error) ? failReason.error : undefined;
|
||||
}
|
||||
|
||||
function isUnknownPendingApprovalRequestError(cause: Cause.Cause<ProviderServiceError>): boolean {
|
||||
@@ -225,7 +235,7 @@ const make = Effect.gen(function* () {
|
||||
|
||||
const formatFailureDetail = (cause: Cause.Cause<unknown>): string => {
|
||||
const failReason = cause.reasons.find(Cause.isFailReason);
|
||||
const providerError = Schema.is(ProviderAdapterRequestError)(failReason?.error)
|
||||
const providerError = isProviderAdapterRequestError(failReason?.error)
|
||||
? failReason.error
|
||||
: undefined;
|
||||
if (providerError) {
|
||||
@@ -353,7 +363,7 @@ const make = Effect.gen(function* () {
|
||||
),
|
||||
);
|
||||
const desiredDriverKind = desiredInfo.driverKind;
|
||||
if (!Schema.is(ProviderDriverKind)(desiredDriverKind)) {
|
||||
if (!isProviderDriverKind(desiredDriverKind)) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
provider: providerErrorLabel(String(desiredDriverKind)),
|
||||
method: "thread.turn.start",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -21,7 +22,14 @@ import {
|
||||
ThreadId,
|
||||
TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Exit, Layer, ManagedRuntime, PubSub, Scope, Stream } from "effect";
|
||||
import * as Clock from "effect/Clock";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as ManagedRuntime from "effect/ManagedRuntime";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Scope from "effect/Scope";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
|
||||
@@ -165,17 +173,17 @@ async function waitForThread(
|
||||
timeoutMs = 2000,
|
||||
threadId: ThreadId = asThreadId("thread-1"),
|
||||
) {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
const deadline = (await Effect.runPromise(Clock.currentTimeMillis)) + timeoutMs;
|
||||
const poll = async (): Promise<ProviderRuntimeTestThread> => {
|
||||
const snapshot = await readModel();
|
||||
const thread = snapshot.threads.find((entry) => entry.id === threadId);
|
||||
if (thread && predicate(thread)) {
|
||||
return thread;
|
||||
}
|
||||
if (Date.now() >= deadline) {
|
||||
if ((await Effect.runPromise(Clock.currentTimeMillis)) >= deadline) {
|
||||
throw new Error("Timed out waiting for thread state");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
await Effect.runPromise(Effect.yieldNow);
|
||||
return poll();
|
||||
};
|
||||
return poll();
|
||||
@@ -242,7 +250,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
await Effect.runPromise(ingestion.start().pipe(Scope.provide(scope)));
|
||||
const drain = () => Effect.runPromise(ingestion.drain);
|
||||
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
await Effect.runPromise(
|
||||
engine.dispatch({
|
||||
type: "project.create",
|
||||
@@ -312,7 +320,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("maps turn started/completed events into thread session updates", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -333,7 +341,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
eventId: asEventId("evt-turn-completed"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
turnId: asTurnId("turn-1"),
|
||||
payload: {
|
||||
state: "failed",
|
||||
@@ -354,7 +362,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("applies provider session.state.changed transitions directly", async () => {
|
||||
const harness = await createHarness();
|
||||
const waitingAt = new Date().toISOString();
|
||||
const waitingAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "session.state.changed",
|
||||
@@ -380,7 +388,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
eventId: asEventId("evt-session-state-error"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
payload: {
|
||||
state: "error",
|
||||
reason: "provider crashed",
|
||||
@@ -402,7 +410,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
eventId: asEventId("evt-session-state-stopped"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
payload: {
|
||||
state: "stopped",
|
||||
},
|
||||
@@ -423,7 +431,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
eventId: asEventId("evt-session-state-ready"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
threadId: asThreadId("thread-1"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
payload: {
|
||||
state: "ready",
|
||||
},
|
||||
@@ -442,7 +450,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("does not clear active turn when session/thread started arrives mid-turn", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -464,14 +472,14 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "thread.started",
|
||||
eventId: asEventId("evt-thread-started-midturn-lifecycle"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
});
|
||||
harness.emit({
|
||||
type: "session.started",
|
||||
eventId: asEventId("evt-session-started-midturn-lifecycle"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
});
|
||||
|
||||
@@ -485,7 +493,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.completed",
|
||||
eventId: asEventId("evt-turn-completed-midturn-lifecycle"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-midturn-lifecycle"),
|
||||
status: "completed",
|
||||
@@ -499,7 +507,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("accepts claude turn lifecycle when seeded thread id is a synthetic placeholder", async () => {
|
||||
const harness = await createHarness();
|
||||
const seededAt = new Date().toISOString();
|
||||
const seededAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -523,7 +531,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.started",
|
||||
eventId: asEventId("evt-turn-started-claude-placeholder"),
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-claude-placeholder"),
|
||||
});
|
||||
@@ -539,7 +547,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.completed",
|
||||
eventId: asEventId("evt-turn-completed-claude-placeholder"),
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-claude-placeholder"),
|
||||
status: "completed",
|
||||
@@ -553,7 +561,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("ignores auxiliary turn completions from a different provider thread", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -574,7 +582,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.completed",
|
||||
eventId: asEventId("evt-turn-completed-aux"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-aux"),
|
||||
status: "completed",
|
||||
@@ -590,7 +598,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.completed",
|
||||
eventId: asEventId("evt-turn-completed-primary"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-primary"),
|
||||
status: "completed",
|
||||
@@ -604,7 +612,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("ignores non-active turn completion when runtime omits thread id", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -626,7 +634,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.completed",
|
||||
eventId: asEventId("evt-turn-completed-guarded-other"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-guarded-other"),
|
||||
status: "completed",
|
||||
@@ -642,7 +650,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.completed",
|
||||
eventId: asEventId("evt-turn-completed-guarded-main"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-guarded-main"),
|
||||
status: "completed",
|
||||
@@ -656,7 +664,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("maps canonical content delta/item completed into finalized assistant messages", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "content.delta",
|
||||
@@ -713,7 +721,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("uses assistant item completion detail when no assistant deltas were streamed", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "item.completed",
|
||||
@@ -745,7 +753,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("preserves completed tool metadata on projected tool activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "item.completed",
|
||||
@@ -801,7 +809,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("normalizes command execution activities to ran-command summaries", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "item.completed",
|
||||
@@ -843,7 +851,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("uses structured read-file paths when available", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "item.completed",
|
||||
@@ -885,7 +893,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("projects completed plan items into first-class proposed plans", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.proposed.completed",
|
||||
@@ -919,7 +927,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
const targetThreadId = asThreadId("thread-implement");
|
||||
const sourceTurnId = asTurnId("turn-plan-source");
|
||||
const targetTurnId = asTurnId("turn-plan-implement");
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1050,7 +1058,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1075,7 +1083,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.started",
|
||||
eventId: asEventId("evt-plan-target-started"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: targetThreadId,
|
||||
turnId: targetTurnId,
|
||||
});
|
||||
@@ -1106,7 +1114,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
const sourceTurnId = asTurnId("turn-plan-source");
|
||||
const activeTurnId = asTurnId("turn-already-running");
|
||||
const staleTurnId = asTurnId("turn-stale-start");
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1219,7 +1227,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1227,7 +1235,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.started",
|
||||
eventId: asEventId("evt-turn-started-stale-plan-implementation"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: targetThreadId,
|
||||
turnId: staleTurnId,
|
||||
});
|
||||
@@ -1259,7 +1267,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
const sourceTurnId = asTurnId("turn-plan-source");
|
||||
const expectedTurnId = asTurnId("turn-plan-implement");
|
||||
const replayedTurnId = asTurnId("turn-replayed");
|
||||
const createdAt = new Date().toISOString();
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -1381,7 +1389,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1399,7 +1407,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "turn.started",
|
||||
eventId: asEventId("evt-turn-started-unrelated-plan-implementation"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: targetThreadId,
|
||||
turnId: replayedTurnId,
|
||||
});
|
||||
@@ -1420,7 +1428,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("finalizes buffered proposed-plan deltas into a first-class proposed plan on turn completion", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -1486,7 +1494,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("buffers assistant deltas by default until completion", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -1554,7 +1562,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("flushes and completes buffered assistant text when an approval request opens", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -1614,7 +1622,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("flushes and completes buffered assistant text when user input is requested", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -1980,7 +1988,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("streams assistant deltas when thread.turn.start requests streaming mode", async () => {
|
||||
const harness = await createHarness({ serverSettings: { enableAssistantStreaming: true } });
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
@@ -2072,7 +2080,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("spills oversized buffered deltas and still finalizes full assistant text", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
const oversizedText = "x".repeat(40_000);
|
||||
|
||||
harness.emit({
|
||||
@@ -2133,7 +2141,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("does not duplicate assistant completion when item.completed is followed by turn.completed", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -2219,7 +2227,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("maps canonical request events into approval activities with requestKind", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "request.opened",
|
||||
@@ -2285,7 +2293,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("maps runtime.error into errored session state", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "runtime.error",
|
||||
@@ -2312,7 +2320,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("records runtime.error activities from the typed payload message", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "runtime.error",
|
||||
@@ -2343,7 +2351,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("keeps the session running when a runtime.warning arrives during an active turn", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "turn.started",
|
||||
@@ -2387,7 +2395,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("maps session/thread lifecycle and item.started into session/activity projections", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "session.started",
|
||||
@@ -2439,7 +2447,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("consumes P1 runtime events into thread metadata, diff checkpoints, and activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "thread.metadata.updated",
|
||||
@@ -2573,7 +2581,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("projects context window updates into normalized thread activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "thread.token-usage.updated",
|
||||
@@ -2625,7 +2633,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("projects Codex camelCase token usage payloads into normalized thread activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "thread.token-usage.updated",
|
||||
@@ -2678,7 +2686,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("projects Claude usage snapshots with context window into normalized thread activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "thread.token-usage.updated",
|
||||
@@ -2722,7 +2730,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("projects compacted thread state into context compaction activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "thread.state.changed",
|
||||
@@ -2752,7 +2760,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("projects Codex task lifecycle chunks into thread activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "task.started",
|
||||
@@ -2855,7 +2863,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("projects structured user input request and resolution as thread activities", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "user-input.requested",
|
||||
@@ -2886,7 +2894,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "user-input.resolved",
|
||||
eventId: asEventId("evt-user-input-resolved"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-user-input"),
|
||||
requestId: ApprovalRequestId.make("req-user-input-1"),
|
||||
@@ -2928,7 +2936,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
|
||||
it("continues processing runtime events after a single event handler failure", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = new Date().toISOString();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
harness.emit({
|
||||
type: "content.delta",
|
||||
@@ -2948,7 +2956,7 @@ describe("ProviderRuntimeIngestion", () => {
|
||||
type: "runtime.error",
|
||||
eventId: asEventId("evt-runtime-error-after-failure"),
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
createdAt: new Date().toISOString(),
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
threadId: asThreadId("thread-1"),
|
||||
turnId: asTurnId("turn-after-failure"),
|
||||
payload: {
|
||||
|
||||
@@ -17,7 +17,13 @@ import {
|
||||
type OrchestrationThreadActivity,
|
||||
type ProviderRuntimeEvent,
|
||||
} from "@t3tools/contracts";
|
||||
import { Cache, Cause, Duration, Effect, Layer, Option, Stream } from "effect";
|
||||
import * as Cache from "effect/Cache";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Stream from "effect/Stream";
|
||||
import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
|
||||
|
||||
import { ProviderService } from "../../provider/Services/ProviderService.ts";
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
*
|
||||
* @module RuntimeReceiptBus
|
||||
*/
|
||||
import { Effect, Layer, PubSub, Stream } from "effect";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
import * as Stream from "effect/Stream";
|
||||
|
||||
import {
|
||||
RuntimeReceiptBus,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { ThreadId } from "@t3tools/contracts";
|
||||
import { Cause, Effect, Exit } from "effect";
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { logCleanupCauseUnlessInterrupted } from "./ThreadDeletionReactor.ts";
|
||||
|
||||
Loaded 100 of 437 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user