Skip to content
Merged
2 changes: 1 addition & 1 deletion apps/mobile/src/features/threads/thread-command-output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function ThreadCommandOutput(props: {
}}
>
{data?.output.truncated ? (
<Text className="pb-0.5 text-3xs text-foreground-subtle">
<Text className="pb-0.5 text-3xs text-foreground-muted">
<T>Earlier output not shown</T>
</Text>
) : null}
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/features/threads/thread-work-log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
) : null}
<Text
accessibilityLabel={timestamp.toLocaleString()}
className="shrink-0 text-xs text-foreground-subtle"
className="shrink-0 text-xs text-foreground-muted"
>
{timestamp.toLocaleString(undefined, {
month: "short",
Expand Down Expand Up @@ -1185,7 +1185,7 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
row.workEntry.questionAnswer &&
hasQuestionAnswer(row.workEntry.questionAnswer)
? "text-foreground"
: "text-foreground-subtle"
: "text-foreground-muted"
}
>{` ${answerPreview}`}</Text>
) : null}
Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/project/ProjectSetupScriptRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ describe("ProjectSetupScriptRunner", () => {
}),
);

it.effect("keeps emoji whole when capping a long output line or partial-line buffer", () =>
Effect.gen(function* () {
const { outputLines, emit } = yield* setup();
yield* emit({ ...event, type: "output", data: `x${"🙂".repeat(250)}\r\n` });
yield* emit({ ...event, type: "output", data: `${"🙂".repeat(2_100)}x` });
yield* emit({ ...event, type: "output", data: "\r\n" });
expect(yield* Queue.takeAll(outputLines)).toEqual([`x${"🙂".repeat(199)}`, "🙂".repeat(200)]);
}),
);

it.effect("types into a quiet shell that has no line editor", () =>
Effect.gen(function* () {
const { writes } = yield* setup();
Expand Down
15 changes: 13 additions & 2 deletions apps/server/src/project/ProjectSetupScriptRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { linkOriginIsFenced, ProjectId, type ProjectScript, ThreadId } from "@t3tools/contracts";
import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
import {
projectScriptRuntimeEnv,
projectScriptTerminalInput,
Expand Down Expand Up @@ -310,7 +311,14 @@ export const make = Effect.gen(function* () {
) {
return Effect.void;
}
return input.onOutputLine(cleaned.slice(0, OUTPUT_LINE_MAX_LENGTH));
return input.onOutputLine(
cleaned.slice(
0,
splitsSurrogatePair(cleaned, OUTPUT_LINE_MAX_LENGTH)
? OUTPUT_LINE_MAX_LENGTH - 1
: OUTPUT_LINE_MAX_LENGTH,
),
);
});

const unsubscribe = yield* terminalManager.subscribe((event) => {
Expand All @@ -324,7 +332,10 @@ export const make = Effect.gen(function* () {
lineBuffer = lines.pop() ?? "";
// Bound newline-free output; the sentinel has its own line, so retaining the tail is safe.
if (lineBuffer.length > PARTIAL_LINE_MAX_LENGTH) {
lineBuffer = lineBuffer.slice(-PARTIAL_LINE_MAX_LENGTH);
const start = lineBuffer.length - PARTIAL_LINE_MAX_LENGTH;
lineBuffer = lineBuffer.slice(
splitsSurrogatePair(lineBuffer, start) ? start + 1 : start,
);
}
return Effect.forEach(lines, handleLine, { discard: true }).pipe(
Effect.andThen(
Expand Down
50 changes: 42 additions & 8 deletions apps/server/src/provider/ProviderRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ const layerTestNodeServices = Layer.mergeAll(
Layer.succeed(ServerEnvironment.ServerEnvironmentIdentity, {
getEnvironmentId: Effect.succeed(EnvironmentId.make("00000000-0000-4000-8000-000000000001")),
}),
// A login shell that prints nothing, so refreshes never take PATH from the developer's profile.
Layer.effect(
HostProcess.Environment,
Effect.sync(() => ({ ...process.env, SHELL: "/usr/bin/true" })),
),
// An empty home, so the developer's own Claude settings never reach provider probes.
Layer.effect(
HostProcess.HomeDirectory,
Expand Down Expand Up @@ -2563,10 +2568,37 @@ it.layer(
}),
);

it.effect(
"rebuilds only instances missing their CLI when a refresh finds a new Windows PATH",
() => {
const env: NodeJS.ProcessEnv = { PATH: "C:\\Windows" };
// A login shell stand-in that prints the capture with one more PATH entry, as a profile edited
// after launch would.
const withLateLoginShell = <A, E, R>(effect: (shell: string) => Effect.Effect<A, E, R>) =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-login-shell-" });
const shell = `${dir}/sh`;
yield* fs.writeFileString(
shell,
'#!/bin/sh\nPATH=/opt/late:/usr/bin exec /bin/sh -c "$2"\n',
);
yield* fs.chmod(shell, 0o755);
return yield* effect(shell);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer));

it.effect.each([
{
name: "Windows PATH",
platform: "win32" as const,
path: "C:\\Windows",
expectedPath: "C:\\Windows;C:\\Tools",
},
{
name: "login-shell PATH",
platform: "linux" as const,
path: "/usr/bin",
expectedPath: "/opt/late:/usr/bin",
},
])("rebuilds only instances missing their CLI when a refresh finds a new $name", (host) =>
withLateLoginShell((shell) => {
const env: NodeJS.ProcessEnv = { PATH: host.path, SHELL: shell };
return Effect.gen(function* () {
const driver = ProviderDriverKind.make("codex");
const makeInstance = (id: string, installed: boolean): ProviderInstance => {
Expand Down Expand Up @@ -2628,7 +2660,9 @@ it.layer(
}),
),
Layer.provideMerge(
ServerConfig.layerTest(process.cwd(), { prefix: "t3-provider-registry-path-" }),
ServerConfig.layerTest(process.cwd(), {
prefix: "t3-provider-registry-path-",
}),
),
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
),
Expand All @@ -2637,16 +2671,16 @@ it.layer(

yield* registry.refresh();

assert.strictEqual(env.PATH, "C:\\Windows;C:\\Tools");
assert.strictEqual(env.PATH, host.expectedPath);
assert.deepStrictEqual(rebuilt, [[ProviderInstanceId.make("missing")]]);
}).pipe(
Effect.provideService(HostProcess.Platform, "win32"),
Effect.provideService(HostProcess.Platform, host.platform),
Effect.provideService(HostProcess.Environment, env),
Effect.provideService(WindowsShellEnvironment, () =>
Effect.succeed({ PATH: "C:\\Windows;C:\\Tools" }),
),
);
},
}),
);

it.effect("rescans a requested cwd whose snapshot is still current", () =>
Expand Down
17 changes: 16 additions & 1 deletion apps/server/src/provider/ProviderRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import * as Ref from "effect/Ref";
import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";
import * as Semaphore from "effect/Semaphore";
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
import * as HostProcess from "@t3tools/shared/HostProcess";

import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
import * as ModelManifest from "./ModelManifest.ts";
import { applyProviderCompatibility } from "./providerCompatibility.ts";
import * as ServerConfig from "../config.ts";
import { refreshWindowsPath } from "../os-jank.ts";
import { refreshPathFromLoginShell, refreshWindowsPath } from "../os-jank.ts";
import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
import * as ProviderInstanceRegistryMutator from "./ProviderInstanceRegistryMutator.ts";
import {
Expand Down Expand Up @@ -747,7 +749,20 @@ export const layer = Layer.effect(
// A refresh is how a user asks T3 to see a CLI installed since launch; a burst shares one probe.
// Drivers copy the environment when built, so instances still missing their CLI are rebuilt
// on the new PATH. They cannot have live sessions, and installed ones keep theirs.
// Compared with the last PATH seen here, since other features re-read the login shell too.
const hostEnvironment = yield* HostProcess.Environment;
const readHostPath = () => hostEnvironment.PATH ?? hostEnvironment.Path ?? hostEnvironment.path;
const lastHostPathRef = yield* Ref.make(readHostPath());
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const refreshHostPath = yield* refreshWindowsPath().pipe(
Effect.andThen(refreshPathFromLoginShell()),
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.andThen(
Effect.suspend(() => {
const path = readHostPath();
return Ref.getAndSet(lastHostPathRef, path).pipe(Effect.map((last) => last !== path));
}),
),
Effect.flatMap((changed) =>
changed
? Ref.get(providersRef).pipe(
Expand Down
24 changes: 21 additions & 3 deletions apps/server/src/provider/acp/AntigravityProtocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,24 +535,42 @@ describe("Antigravity tool results", () => {
);
});

it("keeps the start of a long command line, where the program and target are", () => {
const head = "cat > notes.md <<'EOF'";
const commandLine = `${head}\n${"note line\n".repeat(1_000)}EOF`;
const toolCall = normalizeAntigravityToolCall(
parseToolUpdate({
...commandStarted,
update: { ...commandStarted.update, rawInput: { CommandLine: commandLine } },
}).toolCall,
);
expect(toolCall.command?.startsWith(head)).toBe(true);
expect(toolCall.command).not.toContain("[Earlier output truncated]");
expect((toolCall.data.rawInput as { CommandLine: string }).CommandLine.startsWith(head)).toBe(
true,
);
});

it("keeps 1.5 command input and output valid Unicode when cut", () => {
const tail = `${"x".repeat(7_982)}build completed\r\n`;
const output = `Command output:\nprefix\r\n🚀${tail}`;
const expected = `[Earlier output truncated]\n\n${tail}`;
const head = "x".repeat(7_999);
const expectedCommand = `${head}\n\n[Command truncated]`;
const toolCall = normalizeAntigravityToolCall(
parseToolUpdate({
...commandCompleted,
update: {
...commandCompleted.update,
rawInput: { CommandLine: output },
rawInput: { CommandLine: `${head}🚀 --flag` },
rawOutput: { output, exit_code: 0 },
content: [{ type: "content", content: { type: "text", text: output } }],
},
}).toolCall,
);
expect(toolCall.command).toBe(expected.trimEnd());
expect(toolCall.command).toBe(expectedCommand);
expect(toolCall.data).toMatchObject({
rawInput: { CommandLine: expected },
rawInput: { CommandLine: expectedCommand },
rawOutput: { output: expected },
content: [{ content: { text: expected.trimEnd() } }],
});
Expand Down
29 changes: 23 additions & 6 deletions apps/server/src/provider/acp/AntigravityProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

const TOOL_TEXT_LIMIT = 8_000;
const TOOL_TEXT_TRUNCATED = "[Earlier output truncated]\n\n";
const COMMAND_LINE_TRUNCATED = "\n\n[Command truncated]";
const QUESTION_LABEL_LIMIT = 512;

const NativeToolFields = Schema.Struct({
Expand Down Expand Up @@ -194,11 +195,21 @@ function boundCommandText(text: string, limit = TOOL_TEXT_LIMIT): string {
return copyBoundedText(`${TOOL_TEXT_TRUNCATED}${tail}`);
}

// A command line's program and target are at its start, so it keeps its head.
function boundCommandLine(text: string, limit = TOOL_TEXT_LIMIT): string {
if (
text.length <= limit ||
(text.length <= limit + COMMAND_LINE_TRUNCATED.length && text.endsWith(COMMAND_LINE_TRUNCATED))
) {
return text;
}
const head = text.slice(0, limit).replace(/[\uD800-\uDBFF]$/u, "");
return copyBoundedText(`${head}${COMMAND_LINE_TRUNCATED}`);
}

const COMMAND_LINE_FIELDS = new Set(["CommandLine", "command_line", "commandLine", "command"]);

const COMMAND_TEXT_FIELDS = new Set([
"CommandLine",
"command_line",
"commandLine",
"command",
"aggregatedOutput",
"combinedOutput",
"combined_output",
Expand Down Expand Up @@ -231,7 +242,13 @@ function sanitizeToolValue(
return undefined;
}
const bound =
field !== undefined && COMMAND_TEXT_FIELDS.has(field) ? boundCommandText : boundText;
field === undefined
? boundText
: COMMAND_LINE_FIELDS.has(field)
? boundCommandLine
: COMMAND_TEXT_FIELDS.has(field)
? boundCommandText
: boundText;
const text = bound(value, Math.min(TOOL_TEXT_LIMIT, budget.text));
budget.text -= text.length;
return text;
Expand Down Expand Up @@ -468,7 +485,7 @@ export function normalizeAntigravityToolCall(
output?.commandLine ??
output?.command_line ??
toolCall.command;
const command = nativeCommand?.trim() ? boundCommandText(nativeCommand.trim()) : undefined;
const command = nativeCommand?.trim() ? boundCommandLine(nativeCommand.trim()) : undefined;
const nativeCwd =
input?.Cwd ??
input?.WorkingDirectory ??
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/provider/providerCompatibility.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert, describe, it } from "@effect/vitest";
import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Deferred from "effect/Deferred";
import * as Fiber from "effect/Fiber";
import * as Effect from "effect/Effect";
Expand Down Expand Up @@ -329,6 +330,8 @@ it.effect("a remote policy refresh preserves a newer health result on the regist
),
),
),
// A login shell that prints nothing, so the refresh never takes PATH from the developer's profile.
Effect.provideService(HostProcess.Environment, { ...process.env, SHELL: "/usr/bin/true" }),
);
}),
);
32 changes: 30 additions & 2 deletions apps/server/src/textGeneration/CodexTextGeneration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER,
ProjectId,
ProviderDriverKind,
type ModelSelection,
Expand Down Expand Up @@ -660,11 +661,13 @@ const PREFLIGHT_PRIMARY_STATES = [
"exhausted",
"not installed",
"not installed, fallback disabled for project",
"not installed, fallback model cannot generate text",
"signed out",
"signed out, fallback failed",
"cannot generate text",
"model cannot generate text",
"disabled",
"disabled, thread default model cannot generate text",
"disabled, fallback disabled for project",
] as const;

Expand Down Expand Up @@ -726,6 +729,21 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
],
}
: {}),
...((primaryState === "not installed, fallback model cannot generate text" ||
primaryState === "disabled, thread default model cannot generate text") &&
instanceId === fallback
? {
models: [
{
slug: threadDefault.model,
name: threadDefault.model,
isCustom: true,
supportsTextGeneration: false,
capabilities: null,
},
],
}
: {}),
...(primaryState.startsWith("disabled") && instanceId === primary
? { enabled: false, status: "disabled" }
: {}),
Expand Down Expand Up @@ -797,7 +815,10 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
cwd: "/tmp",
message: "hello",
linkedContext: "",
modelSelection: selection,
modelSelection:
primaryState === "disabled, thread default model cannot generate text"
? threadDefault
: selection,
projectId,
})
.pipe(Effect.exit);
Expand All @@ -813,7 +834,14 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima
primaryState === "not installed, fallback disabled for project" ||
primaryState === "signed out, fallback failed"
? selection
: threadDefault,
: primaryState === "not installed, fallback model cannot generate text" ||
primaryState === "disabled, thread default model cannot generate text"
? {
instanceId: fallback,
model:
DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")],
}
: threadDefault,
]);
}),
);
Expand Down
Loading
Loading