Skip to content
Merged
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
3 changes: 0 additions & 3 deletions apps/server/src/cli/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ import { mcpToolSession, type McpToolSession } from "../mcp/AcpMcpStdioBridge.ts
import { expandHomePath } from "../os-jank.ts";
import * as ProcessRunner from "../processRunner.ts";
import { readLiveServerRuntimeState } from "../serverRuntimeState.ts";
<<<<<<< origin/main
import { userViewCommand } from "../fork/userView/userViewCommand.ts";
=======
import { unsetInheritedRepositoryEnv } from "../vcs/VcsProcess.ts";
>>>>>>> upstream/main
import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,5 @@ export const withAntigravityAccountEmail =
return email ? { credentialFingerprint, credentialEmail: email } : { credentialFingerprint };
});

export const antigravityAccountFields = (
account: AntigravityAccount,
): AntigravityAccountIdentity =>
export const antigravityAccountFields = (account: AntigravityAccount): AntigravityAccountIdentity =>
typeof account === "string" ? { credentialFingerprint: account } : account;
57 changes: 57 additions & 0 deletions apps/server/src/fork/codexAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as Effect from "effect/Effect";
import * as Base64Url from "effect/encoding/Base64Url";
import * as FileSystem from "effect/FileSystem";
import * as Option from "effect/Option";
import * as Result from "effect/Result";
import * as Schema from "effect/Schema";

/**
* Codex writes `tokens` only for ChatGPT logins and omits the key for API-key,
* agent-identity, and personal-access-token logins, so its absence is a
* supported install and not a malformed file. `account_id` is the ChatGPT
* workspace, which a whole Team shares; the `id_token` names the person.
*/
const CodexAuthJsonSchema = Schema.Struct({
tokens: Schema.optionalKey(
Schema.Struct({
account_id: Schema.String,
id_token: Schema.optionalKey(Schema.String),
}),
),
});
const decodeCodexAuthJson = Schema.decodeUnknownOption(Schema.fromJsonString(CodexAuthJsonSchema));

// `sub` names the login method (`google-oauth2|…`), so one person can have several.
// `user_id` (`user-…`) is the OpenAI account and is the same for every login.
const IdTokenClaims = Schema.Struct({
"https://api.openai.com/auth": Schema.Struct({ user_id: Schema.NonEmptyString }),
});
const decodeIdTokenClaims = Schema.decodeUnknownOption(Schema.fromJsonString(IdTokenClaims));

const openAiUserId = (idToken: string) => {
const payload = Base64Url.decodeString(idToken.split(".")[1] ?? "");
return Result.isSuccess(payload)
? Option.map(
decodeIdTokenClaims(payload.success),
(claims) => claims["https://api.openai.com/auth"].user_id,
)
: Option.none<string>();
};

// A Team shares `account_id`; the id_token's user id tells its seats apart.
export const readCodexAccount = Effect.fn("CodexAdapterV2.readAccount")(function* (
fileSystem: FileSystem.FileSystem,
authPath: string,
) {
const text = yield* fileSystem.readFileString(authPath).pipe(Effect.option);
const tokens = Option.flatMap(Option.flatMap(text, decodeCodexAuthJson), (auth) =>
Option.fromUndefinedOr(auth.tokens),
);
return Option.map(tokens, (tokens) => {
const userId = Option.fromUndefinedOr(tokens.id_token).pipe(
Option.flatMap(openAiUserId),
Option.getOrElse(() => ""),
);
return `${tokens.account_id}\n${userId}`;
});
});
55 changes: 55 additions & 0 deletions apps/server/src/fork/fyi/FyiSettle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import {
type OrchestrationV2ThreadProjection,
} from "@t3tools/contracts";
import * as Deferred from "effect/Deferred";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import * as Queue from "effect/Queue";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";

import * as CommandReceiptStore from "../../orchestration-v2/CommandReceiptStore.ts";
import * as Orchestrator from "../../orchestration-v2/Orchestrator.ts";
Expand Down Expand Up @@ -59,6 +61,7 @@ it.effect("settleAfterRun settles after a notification run that carried an FYI",
({
thread: { id: threadId, projectId, deletedAt: null },
runs: raced ? [...runs, nextRun] : runs,
turnItems: [],
messages: [
{ id: MessageId.make("original"), runId, role: "user" as const },
{
Expand Down Expand Up @@ -120,3 +123,55 @@ it.effect("settleAfterRun settles after a notification run that carried an FYI",
expect(dispatched).toEqual(["thread.settle"]);
}),
);

it.effect("settleAfterRun settles after an FYI read once the settle was requested", () =>
Effect.gen(function* () {
const projectId = ProjectId.make("project:thread-management:settle-after-fyi");
const threadId = ThreadId.make("thread:thread-management:settle-after-fyi");
const runId = RunId.make("run:thread-management:settle-after-fyi");
yield* TestClock.adjust(Duration.millis(60_000));
const dispatched: Array<string> = [];
const layerTest = ThreadManagementService.layer.pipe(
Layer.provide(Layer.mock(ProviderSessionManager.ProviderSessionManagerV2)({})),
Layer.provide(
Layer.mock(Orchestrator.OrchestratorV2)({
getThreadEventSequence: () => Effect.succeed(0),
restartContinuationPending: () => Effect.succeed(false),
streamStoredEventsFrom: () => Stream.empty,
getThreadRecords: () =>
Effect.succeed({
thread: { id: threadId, projectId, deletedAt: null },
runs: [{ id: runId, ordinal: 1, status: "completed", userMessageId: "original" }],
messages: [
{ id: "original", runId, role: "user" },
{ id: "fyi", runId, role: "user", fyi: true },
],
turnItems: [
{
runId,
type: "user_message",
inputIntent: "steer",
fyi: true,
status: "completed",
createdAt: "1970-01-01T00:01:30.000Z",
completedAt: "1970-01-01T00:01:30.000Z",
},
],
} as unknown as OrchestrationV2ThreadProjection),
dispatch: (command) =>
Effect.sync(() => {
dispatched.push(command.type);
return { sequence: 1, storedEvents: [] } as never;
}),
}),
),
Layer.provide(ServerSettings.layerTest()),
Layer.provide(CommandReceiptStore.layer.pipe(Layer.provide(SqlitePersistence.layerMemory))),
);
const service = yield* ThreadManagementService.ThreadManagementService.pipe(
Effect.provide(layerTest),
);
yield* service.settleAfterRun({ projectId, threadId, runId });
expect(dispatched).toEqual(["thread.settle"]);
}),
);
18 changes: 9 additions & 9 deletions apps/server/src/fork/previewChrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import type { PreviewBrowserRelease } from "../preview/PreviewBrowser.ts";
// macOS keeps the shell: the Chrome app bundle holds symlinks the installer will not unpack.
// Pin from each chrome zip in known-good-versions-with-downloads.json, at PreviewBrowser.VERSION:
// the browser's --user-agent names that version in both modes.
const VERSION = "158.0.8127.36";
const VERSION = "158.0.8127.88";
const ARCHIVES: Partial<Record<string, { readonly bytes: number; readonly sha256: string }>> = {
linux64: {
bytes: 208_062_943,
sha256: "dba9cc838e1ce269c33ea68170881127bd15d078fc3ca5891c90802819a4d7c7",
bytes: 208_082_347,
sha256: "59e3b43f8b3aaa292238fbdcfb36a93127debd53e212510dcdc2cc8812b4b57e",
},
"linux-arm64": {
bytes: 205_790_900,
sha256: "f811b64a50cbc73f94fda7b3f3b3bf62be5d9409b3207e6ead9b61e6706afffe",
bytes: 205_794_810,
sha256: "91669b5de79af808d498037dd974e4b09461776a1b5240b3bb656abd17e5d3ab",
},
win32: {
bytes: 196_218_437,
sha256: "427a02beb8887ceca6a1847dc67445580741c8c40bd15af334993d3a59863943",
bytes: 196_213_788,
sha256: "b994ff42d7b4b6c90bf66e13d7f4653ee4bb88dd5677e08241c2f3f01a61e877",
},
win64: {
bytes: 214_927_656,
sha256: "6a8ad290952cc612c7777ffb3eb62f345539a2a1a8d440cfac190c6d36b34d2c",
bytes: 214_931_627,
sha256: "fda73ca9ffc7f02c5c85165cb472152540a76a7cecd8ec11314ea781e4454109",
},
};

Expand Down
21 changes: 9 additions & 12 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5985,7 +5985,15 @@ describe("AcpAdapterV2", () => {
);
assert.equal(runtimeOrdinalSeen, 2);
assert.lengthOf(runtimeInputs, 2);
<<<<<<< origin/main
// Loading the thread into the replacement agent is reported, and cleared before the turn runs.
assert.deepEqual(
Array.from(startup, (event) =>
event.type === "provider_session.updated"
? (event.providerSession.startupPhase ?? null)
: "turn running",
).slice(0, 3),
["resume", null, "turn running"],
);
assert.isFalse(yield* accountChanged!, "restarted process read the new account");

account = Option.some("account-c");
Expand All @@ -6000,17 +6008,6 @@ describe("AcpAdapterV2", () => {
assert.isFalse(yield* accountChanged!, "replacement process read the new account");
account = Option.none();
assert.isFalse(yield* accountChanged!, "unreadable");
=======
// Loading the thread into the replacement agent is reported, and cleared before the turn runs.
assert.deepEqual(
Array.from(startup, (event) =>
event.type === "provider_session.updated"
? (event.providerSession.startupPhase ?? null)
: "turn running",
).slice(0, 3),
["resume", null, "turn running"],
);
>>>>>>> upstream/main
}).pipe(Effect.provide(layerTest)),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,7 @@ describe("AntigravityAdapterV2 update_steps checklist", () => {
const adapter = yield* makeAntigravityAdapterV2({
instanceId,
selfInvocation: yield* resolveSelfInvocation(),
profileDirectory: unusedProfileDirectory,
makeRuntime: (input) =>
makeAntigravityAcpRuntime({
...input,
Expand Down
21 changes: 1 addition & 20 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import type { ManagedServerProvider } from "@t3tools/provider-core/server/snapshot";
import type { CodexEffectiveRuntime } from "../../provider/CodexManagedRuntime.ts";
import { classifyCodexManagedError } from "../../provider/CodexManagedErrors.ts";
import { CodexAuthJsonSchema, openAiUserId } from "../../telemetry/Identify.ts";
import {
buildCodexInitializeParams,
codexAppServerEnvironment,
Expand Down Expand Up @@ -117,6 +116,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/process";
import { resolveAttachmentPath, resolveAttachmentPathById } from "../../attachmentStore.ts";
import * as PortScanner from "../../preview/PortScanner.ts";
import { getCodexServiceTierOptionValue } from "../../codexModelOptions.ts";
import { readCodexAccount } from "../../fork/codexAccount.ts";
import { resolveCodexTurnServiceTier } from "../../fork/codexServiceTier.ts";
import {
codexCompactionNoteItems,
Expand Down Expand Up @@ -345,25 +345,6 @@ const decodeCodexBackgroundTerminalTerminateResponse = Schema.decodeUnknownEffec
const decodeCodexBackgroundTerminalsListResponse = Schema.decodeUnknownEffect(
CodexBackgroundTerminalsListResponse,
);
const decodeCodexAuthJson = Schema.decodeUnknownOption(Schema.fromJsonString(CodexAuthJsonSchema));

// A Team shares `account_id`; the id_token's user id tells its seats apart.
const readCodexAccount = Effect.fn("CodexAdapterV2.readAccount")(function* (
fileSystem: FileSystem.FileSystem,
authPath: string,
) {
const text = yield* fileSystem.readFileString(authPath).pipe(Effect.option);
const tokens = Option.flatMap(Option.flatMap(text, decodeCodexAuthJson), (auth) =>
Option.fromUndefinedOr(auth.tokens),
);
return Option.map(tokens, (tokens) => {
const userId = Option.fromUndefinedOr(tokens.id_token).pipe(
Option.flatMap(openAiUserId),
Option.getOrElse(() => ""),
);
return `${tokens.account_id}\n${userId}`;
});
});
// Initialize normally answers in under a second; leave room for a slow first launch.
const CODEX_INITIALIZE_TIMEOUT = "30 seconds";
const CodexThreadSampleResponse = Schema.Struct({ text: Schema.NullOr(Schema.String) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ const make = Effect.gen(function* () {
turnItems.some(
(item) =>
item.type === "user_message" &&
item.fyi !== true &&
(item.inputIntent === "steer" || item.inputIntent === "promoted_queued_to_steer") &&
item.completedAt !== null &&
!DateTime.isLessThan(DateTime.makeUnsafe(item.completedAt), requestedAt),
Expand Down
16 changes: 3 additions & 13 deletions apps/server/src/project/AgentSessionScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,11 +925,6 @@ export const make = Effect.gen(function* () {
const serverSettings = yield* ServerSettings.ServerSettingsService;
const projectStore = yield* ProjectStore.ProjectStoreV2;
const runtimes = yield* ProviderSessionRuntime.ProviderSessionRuntimeRepository;
<<<<<<< origin/main
const baseDir = path.resolve(serverConfig.baseDir);
const worktreesDir = path.resolve(serverConfig.worktreesDir);
const homeCacheDir = yield* homeCheckoutCacheDir;
=======
const configuredT3Dirs = {
baseDir: path.resolve(serverConfig.baseDir),
worktreesDir: path.resolve(serverConfig.worktreesDir),
Expand All @@ -941,7 +936,7 @@ export const make = Effect.gen(function* () {
baseDir: yield* realPathOf(configuredT3Dirs.baseDir),
worktreesDir: yield* realPathOf(configuredT3Dirs.worktreesDir),
};
>>>>>>> upstream/main
const homeCacheDir = yield* homeCheckoutCacheDir;
const platform = yield* HostProcess.Platform;
const isWindows = platform === "win32";
const foldWorktreeCase = isWindows;
Expand All @@ -967,17 +962,12 @@ export const make = Effect.gen(function* () {
);
const isT3OwnedPath = (candidatePath: string, t3Dirs = configuredT3Dirs) =>
normalizeForWorktreeMatch(candidatePath, foldWorktreeCase).startsWith(
<<<<<<< origin/main
normalizeForWorktreeMatch(baseDir, foldWorktreeCase),
normalizeForWorktreeMatch(t3Dirs.baseDir, foldWorktreeCase),
) ||
isT3ManagedWorktree(candidatePath, worktreesDir, foldWorktreeCase) ||
isT3ManagedWorktree(candidatePath, t3Dirs.worktreesDir, foldWorktreeCase) ||
isCheckoutCachePath(candidatePath, { homeCacheDir, caseFold: foldWorktreeCase });
=======
normalizeForWorktreeMatch(t3Dirs.baseDir, foldWorktreeCase),
) || isT3ManagedWorktree(candidatePath, t3Dirs.worktreesDir, foldWorktreeCase);
const isExcludedProjectPath = (candidatePath: string, t3Dirs = configuredT3Dirs) =>
isScratchPath(candidatePath) || isT3OwnedPath(candidatePath, t3Dirs);
>>>>>>> upstream/main

const listDirectory = (directory: string) =>
fileSystem.readDirectory(directory).pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));
Expand Down
8 changes: 1 addition & 7 deletions apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
<<<<<<< origin/main
"claudeSystemAppendBytes": 5945,
"codexAdditionalContextBytes": 7339,
"mcpToolListJsonBytes": 67345
=======
"claudeSystemAppendBytes": 6245,
"codexAdditionalContextBytes": 7639,
"mcpToolListJsonBytes": 61914
>>>>>>> upstream/main
"mcpToolListJsonBytes": 67550
}
3 changes: 0 additions & 3 deletions apps/server/src/storageCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ import { forkParked } from "./serverActivation.ts";
import * as Settings from "./serverSettings.ts";
import * as TerminalManager from "./terminal/Manager.ts";
import { isFilesystemRoot, managedWorktreesDirectories } from "./worktreesDirectory.ts";
<<<<<<< origin/main
import {
homeCheckoutCacheDir,
isCheckoutCachePath,
} from "./fork/reflinkWorktrees/checkoutCacheSites.ts";
=======
import * as CheckpointCaptureIndex from "./vcs/checkpointCaptureIndex.ts";
>>>>>>> upstream/main
import * as GitVcsDriver from "./vcs/GitVcsDriver.ts";
import { isNonRepositoryGitStderr } from "./vcs/GitVcsDriverCore.ts";
import { isLinkedWorktree, removeLinkedWorktree } from "./vcs/worktreeRemoval.ts";
Expand Down
35 changes: 0 additions & 35 deletions apps/server/src/telemetry/Identify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,6 @@ import { CLOUD_LINKED_USER_ID } from "../cloud/config.ts";
import * as ServerConfig from "../config.ts";

/**
<<<<<<< origin/main
* Codex writes `tokens` only for ChatGPT logins and omits the key for API-key,
* agent-identity, and personal-access-token logins, so its absence is a
* supported install and not a malformed file. `account_id` is the ChatGPT
* workspace, which a whole Team shares; the `id_token` names the person.
*/
export const CodexAuthJsonSchema = Schema.Struct({
tokens: Schema.optionalKey(
Schema.Struct({
account_id: Schema.String,
id_token: Schema.optionalKey(Schema.String),
}),
),
});

/** `userID` is random per machine. `oauthAccount` is present only while Claude Code is logged in. */
const ClaudeJsonSchema = Schema.Struct({
userID: Schema.optionalKey(Schema.String),
oauthAccount: Schema.optionalKey(
Schema.Struct({
accountUuid: Schema.optionalKey(Schema.String),
}),
),
});

// `sub` names the login method (`google-oauth2|…`), so one person can have several.
// `user_id` (`user-…`) is the OpenAI account and is the same for every login.
const IdTokenClaims = Schema.Struct({
"https://api.openai.com/auth": Schema.Struct({ user_id: Schema.NonEmptyString }),
});
const decodeIdTokenClaims = Schema.decodeUnknownOption(Schema.fromJsonString(IdTokenClaims));

/**
=======
>>>>>>> upstream/main
* Who an install belongs to, from strongest to weakest. `connect` is the T3
* Connect account. `device` is a client device that connected.
*/
Expand Down
Loading
Loading