start phase 1
This commit is contained in:
1 parent
6954d1b91c
commit
fefea0bdf6
16 files changed
+625
-4904
No files matched your search
@@ -35,7 +35,7 @@ import {
|
||||
ProviderService,
|
||||
type ProviderServiceShape,
|
||||
} from "../../provider/Services/ProviderService.ts";
|
||||
import { checkpointRefForThreadTurn } from "../../checkpointing/Refs.ts";
|
||||
import { checkpointRefForThreadTurn } from "../../checkpointing/Utils.ts";
|
||||
|
||||
const asProjectId = (value: string): ProjectId => ProjectId.makeUnsafe(value);
|
||||
const asSessionId = (value: string): ProviderSessionId => ProviderSessionId.makeUnsafe(value);
|
||||
@@ -334,7 +334,10 @@ describe("CheckpointReactor", () => {
|
||||
threadId: ProviderThreadId.makeUnsafe("provider-thread-1"),
|
||||
turnId: asTurnId("turn-1"),
|
||||
});
|
||||
await waitForGitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0));
|
||||
await waitForGitRefExists(
|
||||
harness.cwd,
|
||||
checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0),
|
||||
);
|
||||
|
||||
fs.writeFileSync(path.join(harness.cwd, "README.md"), "v2\n", "utf8");
|
||||
harness.provider.emit({
|
||||
@@ -354,12 +357,12 @@ describe("CheckpointReactor", () => {
|
||||
(entry) => entry.latestTurnId === "turn-1" && entry.checkpoints.length === 1,
|
||||
);
|
||||
expect(thread.checkpoints[0]?.checkpointTurnCount).toBe(1);
|
||||
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0)),
|
||||
).toBe(true);
|
||||
expect(
|
||||
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1)),
|
||||
).toBe(true);
|
||||
expect(
|
||||
gitShowFileAtRef(
|
||||
harness.cwd,
|
||||
@@ -398,7 +401,10 @@ describe("CheckpointReactor", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
await waitForGitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0));
|
||||
await waitForGitRefExists(
|
||||
harness.cwd,
|
||||
checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0),
|
||||
);
|
||||
expect(
|
||||
gitShowFileAtRef(
|
||||
harness.cwd,
|
||||
@@ -448,9 +454,9 @@ describe("CheckpointReactor", () => {
|
||||
});
|
||||
|
||||
await waitForEvent(harness.engine, (event) => event.type === "thread.turn-diff-completed");
|
||||
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 1)),
|
||||
).toBe(true);
|
||||
expect(
|
||||
gitShowFileAtRef(
|
||||
harness.cwd,
|
||||
@@ -556,7 +562,10 @@ describe("CheckpointReactor", () => {
|
||||
turnId: asTurnId("turn-after-runtime-failure"),
|
||||
});
|
||||
|
||||
await waitForGitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0));
|
||||
await waitForGitRefExists(
|
||||
harness.cwd,
|
||||
checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0),
|
||||
);
|
||||
expect(
|
||||
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 0)),
|
||||
).toBe(true);
|
||||
@@ -636,9 +645,9 @@ describe("CheckpointReactor", () => {
|
||||
numTurns: 1,
|
||||
});
|
||||
expect(fs.readFileSync(path.join(harness.cwd, "README.md"), "utf8")).toBe("v2\n");
|
||||
expect(gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 2))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
gitRefExists(harness.cwd, checkpointRefForThreadTurn(ThreadId.makeUnsafe("thread-1"), 2)),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("processes consecutive revert requests with deterministic rollback sequencing", async () => {
|
||||
|
||||
@@ -5,14 +5,16 @@ import {
|
||||
ProviderSessionId,
|
||||
ThreadId,
|
||||
TurnId,
|
||||
type ProjectId,
|
||||
type OrchestrationEvent,
|
||||
type ProviderRuntimeEvent,
|
||||
} from "@t3tools/contracts";
|
||||
import { Cause, Effect, Layer, Option, Queue, Stream } from "effect";
|
||||
|
||||
import { parseTurnDiffFilesFromUnifiedDiff } from "../../checkpointing/Diffs.ts";
|
||||
import { checkpointRefForThreadTurn } from "../../checkpointing/Refs.ts";
|
||||
import {
|
||||
checkpointRefForThreadTurn,
|
||||
resolveThreadWorkspaceCwd,
|
||||
} from "../../checkpointing/Utils.ts";
|
||||
import { CheckpointStore } from "../../checkpointing/Services/CheckpointStore.ts";
|
||||
import { ProviderService } from "../../provider/Services/ProviderService.ts";
|
||||
import { CheckpointReactor, type CheckpointReactorShape } from "../Services/CheckpointReactor.ts";
|
||||
@@ -40,27 +42,6 @@ function trimToNonEmpty(value: string | null | undefined): string | undefined {
|
||||
return normalized && normalized.length > 0 ? normalized : undefined;
|
||||
}
|
||||
|
||||
function resolveThreadWorkspaceCwd(input: {
|
||||
readonly thread: {
|
||||
readonly projectId: ProjectId;
|
||||
readonly worktreePath: string | null;
|
||||
};
|
||||
readonly projects: ReadonlyArray<{
|
||||
readonly id: ProjectId;
|
||||
readonly workspaceRoot: string;
|
||||
}>;
|
||||
}): string | undefined {
|
||||
const worktreeCwd = trimToNonEmpty(input.thread.worktreePath);
|
||||
if (worktreeCwd) {
|
||||
return worktreeCwd;
|
||||
}
|
||||
|
||||
const workspaceRoot = input.projects.find(
|
||||
(project) => project.id === input.thread.projectId,
|
||||
)?.workspaceRoot;
|
||||
return trimToNonEmpty(workspaceRoot);
|
||||
}
|
||||
|
||||
function checkpointStatusFromRuntime(status: string | undefined): "ready" | "missing" | "error" {
|
||||
switch (status) {
|
||||
case "failed":
|
||||
|
||||
@@ -26,7 +26,7 @@ function toTurnId(value: string | undefined): TurnId | undefined {
|
||||
}
|
||||
|
||||
function truncateDetail(value: string, limit = 180): string {
|
||||
return value.length > limit ? `${value.slice(0, limit - 1)}...` : value;
|
||||
return value.length > limit ? `${value.slice(0, limit - 3)}...` : value;
|
||||
}
|
||||
|
||||
function runtimeEventToActivities(
|
||||
@@ -130,7 +130,6 @@ const make = Effect.gen(function* () {
|
||||
const providerService = yield* ProviderService;
|
||||
|
||||
const turnMessageIdsByTurnKey = new Map<string, Set<MessageId>>();
|
||||
const latestMessageIdByTurnKey = new Map<string, MessageId>();
|
||||
|
||||
const rememberAssistantMessageId = (
|
||||
sessionId: ProviderSessionId,
|
||||
@@ -144,7 +143,6 @@ const make = Effect.gen(function* () {
|
||||
} else {
|
||||
turnMessageIdsByTurnKey.set(key, new Set([messageId]));
|
||||
}
|
||||
latestMessageIdByTurnKey.set(key, messageId);
|
||||
};
|
||||
|
||||
const getAssistantMessageIdsForTurn = (sessionId: ProviderSessionId, turnId: TurnId) => {
|
||||
@@ -162,11 +160,6 @@ const make = Effect.gen(function* () {
|
||||
turnMessageIdsByTurnKey.delete(key);
|
||||
}
|
||||
}
|
||||
for (const key of latestMessageIdByTurnKey.keys()) {
|
||||
if (key.startsWith(prefix)) {
|
||||
latestMessageIdByTurnKey.delete(key);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const processEvent = (event: ProviderRuntimeEvent) =>
|
||||
|
||||
Reference in new issue
Block a user