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
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Security policy

Report security vulnerabilities affecting T3 Code or T3 Tools-operated infrastructure to
[security@ping.gg](mailto:security@ping.gg). Please do not disclose them publicly until we have had
[security@t3.codes](mailto:security@t3.codes). Please do not disclose them publicly until we have had
a reasonable opportunity to investigate and remediate them.

See the [full security policy](https://t3.codes/security-policy) for reporting details, scope,
Expand Down
4 changes: 3 additions & 1 deletion .github/actions/setup-ci-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,12 @@ runs:
key: ${{ steps.pnpm_verified.outputs.cache-primary-key }}

# A filtered install that started from the current full store adds nothing
# worth a second copy of it.
# worth a second copy of it. A stacked PR, based on a branch other than the
# default, saves a ~1 GB store only its own reruns can read, so it only restores.
- name: Save pnpm store
if: >-
inputs.install == 'true' &&
(github.event_name != 'pull_request' || github.base_ref == github.event.repository.default_branch) &&
steps.pnpm_cache.outputs.cache-hit != 'true' &&
(steps.pnpm_store.outputs.namespace == 'full' ||
steps.pnpm_cache.outputs.cache-matched-key != format('pnpm-full-v1-{0}-{1}-{2}', runner.os, runner.arch, hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', 'package.json')))
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ jobs:
name: cli-${{ inputs.platform }}-${{ inputs.arch }}
path: release-cli/*
if-no-files-found: error
# The archive is already gzip or zip; deflating it again saves under 2%.
compression-level: 0

- uses: ./.github/actions/setup-apt-mirrors
if: inputs.platform == 'linux'
Expand Down Expand Up @@ -924,6 +926,8 @@ jobs:
name: desktop-${{ inputs.platform }}-${{ inputs.arch }}
path: release-publish/*
if-no-files-found: error
# Installers, zips and blockmaps are already compressed; deflating them again saves under 0.3%.
compression-level: 0

- name: Upload resource monitor
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export default defineConfig({
dependsOn: ["t3#build"],
cache: false,
},
// CI bundle jobs skip the Linux browser secret helper; packaging stages one per arch.
"build:bundle": {
command: "node scripts/build-preview-annotation-css.mjs && vp pack",
dependsOn: ["t3#build"],
cache: false,
},
dev: {
command:
"node scripts/build-browser-secret.mjs && node scripts/build-preview-annotation-css.mjs && cross-env T3CODE_DESKTOP_DEV=1 vp pack --watch",
Expand Down
2 changes: 2 additions & 0 deletions apps/marketing/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default defineConfig({
process.env.S2CODE_MARKETING_URL?.trim() ||
process.env.SHUV2CODE_MARKETING_URL?.trim() ||
undefined,
// Vercel 308s `/path/` to `/path` (see vercel.ts), so every internal link and canonical uses one form.
trailingSlash: "never",
server: {
port: Number(process.env.PORT ?? 4173),
},
Expand Down
8 changes: 4 additions & 4 deletions apps/marketing/src/pages/security-policy.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const sections = [
description="How to report security issues in T3 Code and how T3 Tools approaches product security."
heading="T3 Code Security Policy"
lede="Security is a shared responsibility. This policy explains how to report a vulnerability, how we protect T3 Tools-operated services, and how you can secure the environments and providers you connect to T3 Code."
effectiveDate="2026-07-15"
lastUpdated="2026-07-15"
effectiveDate="2026-11-06"
lastUpdated="2026-11-06"
sections={sections}
>
<section id="introduction">
Expand Down Expand Up @@ -46,7 +46,7 @@ const sections = [
<h2>Reporting Security Issues</h2>
<p>
If you believe you have found a security vulnerability affecting T3 Code or T3 Tools-operated
infrastructure, email{" "}<a href="mailto:security@ping.gg">security@ping.gg</a>. Please do not
infrastructure, email{" "}<a href="mailto:security@t3.codes">security@t3.codes</a>. Please do not
disclose the issue publicly until we have had a reasonable opportunity to investigate and
remediate it.
</p>
Expand Down Expand Up @@ -176,7 +176,7 @@ const sections = [
<h2>Contact Us</h2>
<p>
Report security issues or ask security-related questions at{" "}<a
href="mailto:security@ping.gg">security@ping.gg</a
href="mailto:security@t3.codes">security@t3.codes</a
>.
</p>
<p>
Expand Down
2 changes: 2 additions & 0 deletions apps/marketing/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const config: VercelConfig = {
installCommand: "npm install -g vite-plus && vp install --filter '@t3tools/marketing...'",
buildCommand: "vp run --filter @t3tools/marketing build",
outputDirectory: "dist",
// One URL per page: `/download/` and `/download` both served 200 before, which splits ranking signals.
trailingSlash: false,
// curl | sh requires plain, uncompressed scripts with no cache across deploys.
headers: [
{
Expand Down
55 changes: 37 additions & 18 deletions apps/server/scripts/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import rootPackageJson from "../../../package.json" with { type: "json" };
import * as HostProcess from "@t3tools/shared/HostProcess";
import { resolveSpawnCommand } from "@t3tools/shared/shell";
import {
ServerCliBootstrapTooLargeError,
ServerCliBuildAssetMissingError,
ServerCliCommandExitError,
ServerCliDevelopmentIconSourceMissingError,
Expand Down Expand Up @@ -138,30 +139,48 @@ const buildExeCmd = Command.make(
(yield* HostProcess.Platform) === "linux" &&
(yield* HostProcess.Architecture) === "arm64";
const spawnCommand = yield* resolveSpawnCommand("vp", ["pack"]);
yield* runCommand(
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
cwd: serverDir,
env: {
...process.env,
T3CODE_PACK_EXE: linuxArm64 ? "bundle" : "1",
T3CODE_PACK_EXE_TARGET: target ?? "",
},
stdout: config.verbose ? "inherit" : "ignore",
stderr: "inherit",
shell: spawnCommand.shell,
}),
);
const cliAssetDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-asset-" });
const pack = (packMode: "bundle" | "bootstrap" | "1") =>
runCommand(
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
cwd: serverDir,
env: {
...process.env,
T3CODE_PACK_EXE: packMode,
T3CODE_CLI_ASSET_DIR: cliAssetDir,
T3CODE_PACK_EXE_TARGET: target ?? "",
},
stdout: config.verbose ? "inherit" : "ignore",
stderr: "inherit",
shell: spawnCommand.shell,
}),
);

yield* pack("bundle");
const cliMainPath = path.join(cliAssetDir, "binMain.mjs");
yield* pack(linuxArm64 ? "bootstrap" : "1");

// Executables reject non-builtin imports even when bundling succeeds; inspect the emitted graph.
const bundlePath = path.join(serverDir, "dist-exe/bin.mjs");
const specifiers = findEsmImportsOfExternalPackages(yield* fs.readFileString(bundlePath));
if (specifiers.length > 0) {
return yield* new ServerCliExecutableImportError({ bundlePath, specifiers });
const bootstrapPath = path.join(serverDir, "dist-exe/bin.mjs");
for (const bundlePath of [bootstrapPath, cliMainPath]) {
const specifiers = findEsmImportsOfExternalPackages(yield* fs.readFileString(bundlePath));
if (specifiers.length > 0) {
return yield* new ServerCliExecutableImportError({ bundlePath, specifiers });
}
}
// The service launcher's memory win depends on the CLI staying out of the bootstrap.
const bootstrapBytes = (yield* fs.stat(bootstrapPath)).size;
if (bootstrapBytes > 1024 * 1024) {
return yield* new ServerCliBootstrapTooLargeError({
bootstrapPath,
bytes: Number(bootstrapBytes),
});
}
// TEMPORARY one-time Node fix. Remove when fixed: https://github.com/nodejs/node/issues/67048
if (linuxArm64) {
yield* injectLinuxArm64Sea({
bundlePath,
bundlePath: bootstrapPath,
cliAssetPath: cliMainPath,
outputPath: path.join(serverDir, "dist-exe/t3"),
nodeVersion: rootPackageJson.engines.node,
verbose: config.verbose,
Expand Down
12 changes: 12 additions & 0 deletions apps/server/scripts/cliErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ export class ServerCliExecutableImportError extends Schema.TaggedError<ServerCli
return `${this.bundlePath} imports file-backed packages that a single-executable cannot resolve: ${this.specifiers.join(", ")}. Load them through createRequire instead.`;
}
}

export class ServerCliBootstrapTooLargeError extends Schema.TaggedError<ServerCliBootstrapTooLargeError>()(
"ServerCliBootstrapTooLargeError",
{
bootstrapPath: Schema.String,
bytes: Schema.Number,
},
) {
override get message(): string {
return `${this.bootstrapPath} is ${this.bytes} bytes. The CLI was bundled into the executable bootstrap; keep ./binMain.ts external.`;
}
}
80 changes: 37 additions & 43 deletions apps/server/src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
/**
* Every ACP agent spawns `t3 acp-mcp-bridge` while opening its session, and terminal-fallback
* agents run `t3 acp-mcp-call` per tool call, so their startup sits on first-message latency.
* They and Codex's managed-token helper dispatch before the full CLI module graph (seconds
* of evaluation) loads; everything else defers to the real CLI in ./binCli.ts.
*/
// @effect-diagnostics nodeBuiltinImport:off -- The service launcher starts before the CLI runtime.
import * as NodeModule from "node:module";
import * as NodeSea from "node:sea";
import * as NodeURL from "node:url";

import { isEntrypoint } from "./entrypoint.ts";
import { applyProductEnvironment } from "@t3tools/shared/productIdentity";
import { enableCliCompileCache } from "./cliCompileCache.ts";

// Loads the CLI outside the launcher's module graph. Packaged builds embed it as a raw asset.
async function loadCliMain(): Promise<typeof import("./binMain.ts")> {
if (!NodeSea.isSea()) return import("./binMain.ts");

// Keep the executable's module URL so the CLI finds the web client and native packages beside it.
const require = NodeModule.createRequire(import.meta.url);
// require() resolves links in the executable path, such as a Windows junction.
const cliUrl = NodeURL.pathToFileURL(require.resolve(process.execPath)).href;
const hook = NodeModule.registerHooks({
load(url, context, next) {
if (url !== cliUrl) return next(url, context);
return {
format: "module",
source: new Uint8Array(NodeSea.getRawAsset("binMain.mjs")),
shortCircuit: true,
};
},
});
try {
return require(process.execPath) as typeof import("./binMain.ts");
} finally {
hook.deregister();
}
}

if (
isEntrypoint({
Expand All @@ -16,42 +39,13 @@ if (
})
) {
applyProductEnvironment(process.env);
const command = process.argv[2];
// Guard sockets before either dispatch path can load outbound-capable modules.
const { ignoreMacosTypeOfServiceEinval } = await import("./outboundHttp.ts");
ignoreMacosTypeOfServiceEinval();
if (command === "__document-text") {
const { extractDocumentText } = await import("./provider/documentTextWorker.ts");
try {
process.stdout.write(await extractDocumentText(process.argv[3]!, process.argv[4]!));
} catch (error) {
if (error instanceof Error && "code" in error && /^E[A-Z0-9]+$/.test(String(error.code))) {
throw error;
}
// Exit 2 identifies document rejections; OS and process failures remain retryable.
process.exitCode = 2;
}
} else if (command === "__managed-chatgpt-token") {
const { runManagedChatGptTokenCli } = await import("./cli/managedChatGptToken.ts");
await runManagedChatGptTokenCli(process.argv.slice(3));
} else if (command === "acp-mcp-bridge" || command === "acp-mcp-call") {
const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts");
await runAcpMcpCliFastPath(command, process.argv.slice(3));
} else if (command === "__speech-worker") {
const mode = process.argv[3];
if (mode !== "discover" && mode !== "model") throw new Error("Unknown speech worker mode.");
const { runNativeSpeechWorker } = await import("./speech/native.ts");
await runNativeSpeechWorker(mode, process.argv[4]);
// The launcher owns shutdown until its child exits, so it bypasses the Effect CLI runtime.
// The service unit passes no arguments; flags and help go through the full CLI.
if (process.argv[2] === "__service-launcher" && process.argv.length === 3) {
const { runServiceLauncherCli } = await import("./cli/serviceLauncher.ts");
await runServiceLauncherCli();
} else {
enableCliCompileCache();
// Windows desktop launches without stdin; attach before reading, except on fast paths using pipes.
const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
attachConsoleStdin();
const importStart = performance.now();
const { runCli } = await import("./binCli.ts");
if (process.env.T3CODE_STARTUP_PROFILE_DIR) {
performance.measure("server.import.binCli", { start: importStart });
}
runCli();
const { runCliCommand } = await loadCliMain();
await runCliCommand();
}
}
9 changes: 7 additions & 2 deletions apps/server/src/binCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { threadCommand } from "./cli/thread.ts";
import { runDefaultServerCommand, serveCommand, startCommand } from "./cli/server.ts";
import { updateCommand } from "./cli/update.ts";
import { uninstallCommand } from "./cli/uninstall.ts";
import { serviceLauncherCommand } from "./cli/serviceLauncher.ts";
import { runServiceLauncherCli } from "./cli/serviceLauncher.ts";
import { speechWorkerCommand } from "./cli/speechWorker.ts";
import { claudeHistoryCommand } from "./cli/claudeHistory.ts";
import { sshHelperCommand } from "./cli/sshHelper.ts";
Expand Down Expand Up @@ -92,7 +92,12 @@ export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
serviceCommand,
updateCommand,
uninstallCommand,
serviceLauncherCommand,
// bin.ts runs the bare service invocation; this keeps flags and help working like other commands.
Command.make("__service-launcher").pipe(
Command.unlisted,
// The launcher owns shutdown until its child exits; `runMain` would interrupt that shutdown.
Command.withHandler(() => Effect.sync(() => void runServiceLauncherCli())),
),
claudeHistoryCommand,
speechWorkerCommand,
sshHelperCommand,
Expand Down
45 changes: 45 additions & 0 deletions apps/server/src/binMain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { enableCliCompileCache } from "./cliCompileCache.ts";

// Packaged builds load this graph with require(esm): top-level await anywhere in it breaks them.
// ACP agents spawn `acp-mcp-bridge` per session and `acp-mcp-call` per tool call, so those fast
// paths dispatch before the full CLI module graph (seconds of evaluation) loads.
export async function runCliCommand() {
const command = process.argv[2];
// Install the socket guard before importing code that can open outbound connections.
const { ignoreMacosTypeOfServiceEinval } = await import("./outboundHttp.ts");
ignoreMacosTypeOfServiceEinval();
if (command === "__document-text") {
const { extractDocumentText } = await import("./provider/documentTextWorker.ts");
try {
process.stdout.write(await extractDocumentText(process.argv[3]!, process.argv[4]!));
} catch (error) {
if (error instanceof Error && "code" in error && /^E[A-Z0-9]+$/.test(String(error.code))) {
throw error;
}
// Exit 2 identifies document rejections; OS and process failures remain retryable.
process.exitCode = 2;
}
} else if (command === "__managed-chatgpt-token") {
const { runManagedChatGptTokenCli } = await import("./cli/managedChatGptToken.ts");
await runManagedChatGptTokenCli(process.argv.slice(3));
} else if (command === "acp-mcp-bridge" || command === "acp-mcp-call") {
const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts");
await runAcpMcpCliFastPath(command, process.argv.slice(3));
} else if (command === "__speech-worker") {
const mode = process.argv[3];
if (mode !== "discover" && mode !== "model") throw new Error("Unknown speech worker mode.");
const { runNativeSpeechWorker } = await import("./speech/native.ts");
await runNativeSpeechWorker(mode, process.argv[4]);
} else {
enableCliCompileCache();
// Windows desktop launches without stdin; attach before reading, except on fast paths using pipes.
const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
attachConsoleStdin();
const importStart = performance.now();
const { runCli } = await import("./binCli.ts");
if (process.env.T3CODE_STARTUP_PROFILE_DIR) {
performance.measure("server.import.binCli", { start: importStart });
}
runCli();
}
}
25 changes: 9 additions & 16 deletions apps/server/src/cli/serviceLauncher.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import * as Effect from "effect/Effect";
import { Command } from "effect/cli";

import { main as runServiceLauncher } from "../serviceLauncher.ts";

/** The launcher must stop its child before exiting; `runMain` would interrupt that shutdown. */
export const serviceLauncherCommand = Command.make("__service-launcher").pipe(
Command.unlisted,
Command.withHandler(() =>
Effect.sync(() => {
runServiceLauncher().catch((cause: unknown) => {
const error = cause instanceof Error ? cause : new Error(String(cause));
process.stderr.write(`[service-launcher] ${error.message}\n`);
process.exitCode = 1;
});
}),
),
);
export async function runServiceLauncherCli(): Promise<void> {
try {
await runServiceLauncher();
} catch (cause) {
const message = cause instanceof Error ? cause.message : String(cause);
process.stderr.write(`[service-launcher] ${message}\n`);
process.exitCode = 1;
}
}
Loading
Loading