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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 136 additions & 104 deletions apps/server/src/environmentTheme.test.ts

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions apps/server/src/feedback/FeedbackReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const T3_CLI_COMMANDS: ReadonlyArray<string> = [
"t3 help",
"t3 serve",
"t3 app",
"t3 app network-access",
"t3 pair",
"t3 auth",
"t3 auth connect-device",
Expand Down Expand Up @@ -158,6 +159,65 @@ export const T3_CLI_COMMANDS: ReadonlyArray<string> = [
"t3 thread start",
"t3 thread send",
"t3 thread show",
"t3 thread answer",
"t3 thread archive",
"t3 thread delete",
"t3 thread export",
"t3 thread fork",
"t3 thread hide",
"t3 thread move",
"t3 thread rename",
"t3 thread resume",
"t3 thread rollback",
"t3 thread search",
"t3 thread settle",
"t3 thread stop",
"t3 thread unarchive",
"t3 thread unhide",
"t3 thread unsettle",
"t3 draft",
"t3 draft create",
"t3 draft delete",
"t3 draft list",
"t3 draft send",
"t3 import",
"t3 import list",
"t3 integration",
"t3 integration discord",
"t3 integration discord connect",
"t3 integration discord leave",
"t3 integration discord servers",
"t3 integration login",
"t3 integration logout",
"t3 integration status",
"t3 provider",
"t3 provider disable",
"t3 provider enable",
"t3 provider list",
"t3 provider refresh",
"t3 schedule",
"t3 schedule create",
"t3 schedule delete",
"t3 schedule disable",
"t3 schedule enable",
"t3 schedule list",
"t3 schedule run",
"t3 schedule show",
"t3 schedule update",
"t3 schedule webhook",
"t3 schedule webhook deliveries",
"t3 schedule webhook rotate",
"t3 settings",
"t3 settings set",
"t3 settings show",
"t3 settings unset",
"t3 usage",
"t3 usage cost",
"t3 usage tokens",
"t3 worktree",
"t3 worktree cleanup",
"t3 worktree list",
"t3 worktree remove",
"t3 feedback",
"t3 feedback list",
"t3 workflow",
Expand Down
32 changes: 16 additions & 16 deletions apps/server/src/keybindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ const writeKeybindingsConfig = (configPath: string, rules: readonly KeybindingRu
yield* fileSystem.writeFileString(configPath, encoded);
});

const fillerRulesToKeepDefault = (target: KeybindingRule) => {
const defaults = SharedKeybindings.DEFAULT_KEYBINDINGS;
const index = defaults.findIndex(
(rule) =>
rule.command === target.command && rule.key === target.key && rule.when === target.when,
);
assert.isAtLeast(index, 0);
const visibleDefaults = SharedKeybindings.compileResolvedKeybindingsConfig(defaults.slice(index));
return Array.from({ length: MAX_KEYBINDINGS_COUNT - visibleDefaults.length }, (_, index) => ({
key: "mod+alt+f1",
command: `script.filler-${index}.run` as const,
}));
};

const readKeybindingsConfig = (configPath: string) =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
Expand Down Expand Up @@ -533,15 +547,8 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
Effect.gen(function* () {
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
const keybindings = yield* Keybindings.Keybindings;
yield* writeKeybindingsConfig(
keybindingsConfigPath,
Array.from({ length: 210 }, (_, index) => ({
key: "mod+alt+f1",
command: `script.filler-${index}.run` as const,
})),
);

const target = { key: "mod+shift+o", command: "chat.new", when: "!terminalFocus" } as const;
yield* writeKeybindingsConfig(keybindingsConfigPath, fillerRulesToKeepDefault(target));
const local = { ...target, key: "mod+shift+n", command: "chat.newLocal" } as const;
const relevant = (rule: { readonly command: KeybindingCommand }) =>
rule.command === target.command || rule.command === local.command;
Expand All @@ -566,15 +573,8 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
Effect.gen(function* () {
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
const keybindings = yield* Keybindings.Keybindings;
yield* writeKeybindingsConfig(
keybindingsConfigPath,
Array.from({ length: 209 }, (_, index) => ({
key: "mod+alt+f1",
command: `script.filler-${index}.run` as const,
})),
);

const target = { key: "mod+n", command: "chat.new", when: "!terminalFocus" } as const;
yield* writeKeybindingsConfig(keybindingsConfigPath, fillerRulesToKeepDefault(target));
const sibling = { ...target, key: "mod+shift+o" };
const isChatNew = (binding: { readonly command: KeybindingCommand }) =>
binding.command === target.command;
Expand Down
39 changes: 35 additions & 4 deletions apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.testkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ function withRequestId(expected: unknown, actual: unknown): unknown {
: expected;
}

// Runtime instructions occupy their own input part and change independently of the protocol.
function normalizeTurnStartInstructions(frame: unknown): unknown {
if (!isRecord(frame) || frame.method !== "turn/start" || !isRecord(frame.params)) {
return frame;
}
const input = frame.params.input;
if (!Array.isArray(input)) return frame;
const [instructions, ...messageParts] = input;
if (
!isRecord(instructions) ||
instructions.type !== "text" ||
typeof instructions.text !== "string" ||
!instructions.text.startsWith("<runtime_info>") ||
!instructions.text.includes("</runtime_info>")
) {
return frame;
}
return {
...frame,
params: {
...frame.params,
input: [{ ...instructions, text: "<runtime_info></runtime_info>" }, ...messageParts],
},
};
}

function replayFrameMatches(expected: unknown, actual: unknown): boolean {
return replayValueMatches(
normalizeTurnStartInstructions(withRequestId(expected, actual)),
normalizeTurnStartInstructions(actual),
);
}

/** A write may not match past one of these: it would be a turn early. */
function startsTurn(entry: ProviderReplayEntryType): boolean {
if (entry.type !== "expect_outbound" || !isRecord(entry.frame)) return false;
Expand Down Expand Up @@ -250,9 +283,7 @@ class MuseReplayController {
const entry = entries[index]!;
const pending = entry.type === "expect_outbound" && !this.consumed.has(index);
possible =
pending &&
entryHost(entry) === host.ordinal &&
replayValueMatches(withRequestId(entry.frame, actual), actual);
pending && entryHost(entry) === host.ordinal && replayFrameMatches(entry.frame, actual);
if (!possible && pending && startsTurn(entry)) break;
}
if (!possible) {
Expand Down Expand Up @@ -310,7 +341,7 @@ class MuseReplayController {
const entry = entries[index]!;
if (entry.type !== "expect_outbound") return false;
if (this.consumed.has(index) || entryHost(entry) !== host.ordinal) continue;
if (!replayValueMatches(withRequestId(entry.frame, actual), actual)) continue;
if (!replayFrameMatches(entry.frame, actual)) continue;
const recordedId = clientRequestId(entry.frame);
const actualId = clientRequestId(actual);
if (recordedId !== undefined && actualId !== undefined) host.ids.set(recordedId, actualId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import {
ProviderTurnId,
ThreadId,
TurnItemId,
type OrchestrationV2DomainEvent,
} from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as ProviderInstanceRegistry from "../provider/ProviderInstanceRegistry.ts";
import * as WorkspaceFolders from "../workspace/WorkspaceFolders.ts";
import * as RuntimePolicy from "./RuntimePolicy.ts";
import * as Fiber from "effect/Fiber";
import * as Result from "effect/Result";
import { planProjectCommand } from "./ProjectCommands.ts";
import * as Queue from "effect/Queue";
Expand Down Expand Up @@ -141,15 +139,14 @@ it.effect.each([
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
const sink = yield* EventSink.EventSinkV2;
const threadId = ThreadId.make("thread:workspace-change-detach");
const providerTurnRunning = () =>
orchestrator.streamDomainEvents.pipe(
const awaitRunningTurn = (afterSequence: number) =>
sink.stream({ threadId, afterSequence, eventType: "provider-turn.updated" }).pipe(
Stream.filter(
(event: OrchestrationV2DomainEvent) =>
({ event }) =>
event.type === "provider-turn.updated" && event.payload.status === "running",
),
Stream.take(1),
Stream.runDrain,
Effect.forkScoped,
);
yield* orchestrator.dispatch({
type: "thread.create",
Expand All @@ -165,7 +162,7 @@ it.effect.each([
createdBy: "user",
creationSource: "web",
});
const firstRunning = yield* providerTurnRunning();
const beforeFirstTurn = yield* sink.latestSequence({ threadId });
yield* orchestrator.dispatch({
type: "message.dispatch",
commandId: CommandId.make("investigate"),
Expand All @@ -178,7 +175,7 @@ it.effect.each([
creationSource: "web",
});
yield* worker.drain();
yield* Fiber.join(firstRunning);
yield* awaitRunningTurn(beforeFirstTurn);
const first = started[0]!;
const providerTurn = (yield* orchestrator.getThreadProjection(threadId))
.providerTurns[0]!;
Expand Down Expand Up @@ -271,7 +268,7 @@ it.effect.each([
),
});
}
const continuationRunning = yield* providerTurnRunning();
const beforeMove = yield* sink.latestSequence({ threadId });
const move = {
type: "thread.project.move" as const,
commandId: CommandId.make("handoff"),
Expand Down Expand Up @@ -308,7 +305,19 @@ it.effect.each([
creationSource: "mcp",
});
yield* worker.drain();
yield* Fiber.join(continuationRunning);
// The checkpoint can schedule queue promotion after the outbox drain returns.
yield* sink.stream({ threadId, afterSequence: beforeMove }).pipe(
Stream.filter(
({ event }) =>
(event.type === "run.updated" || event.type === "run.created") &&
event.payload.id !== first.runId &&
event.payload.status === "starting",
),
Stream.take(1),
Stream.runDrain,
);
yield* worker.drain();
yield* awaitRunningTurn(beforeMove);

const after = yield* orchestrator.getThreadProjection(threadId);
assert.deepEqual(
Expand Down
2 changes: 1 addition & 1 deletion packages/client-runtime/src/state/sharedSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe("findSharedSettingsMismatches", () => {
environmentId: boxId,
label: "Remote Box",
syncEligible: true,
settings: DEFAULT_SERVER_SETTINGS,
settings: { ...primarySettings, sidebarAutoSettleAfterDays: 14 },
},
],
});
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/t3ProjectFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ describe("buildT3ProjectFileJsonSchema", () => {
"$schema",
"defaultThreadEnvMode",
"iconPath",
"ignoreRepositories",
"pythonInterpreterPath",
"scripts",
"worktreeLayout",
"worktreeSparsePatternsPath",
"worktreeSubmodules",
]);
expect(schema.required).toBeUndefined();
Expand Down