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/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
# already uses OIDC (`id-token: write`); this flag is what changesets
# / pnpm honor (they do not accept `--provenance`).
# publishConfig.provenance is true on every public package.
NPM_CONFIG_PROVENANCE: "true"
NPM_CONFIG_PROVENANCE: 'true'

- name: Detect @truefoundry/trueforge publish
id: trueforge
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export default defineConfig(
'packages/trueforge-sdk/**',
],
},
{
// Require braces on every control statement, including single-line and multi-line.
rules: {
curly: ['error', 'all'],
},
},
{
files: ['**/*.{js,mjs,cjs,ts}'],
ignores: ['packages/frontend/**'],
Expand Down
12 changes: 9 additions & 3 deletions packages/frontend/src/LogoutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export function LogoutButton() {
const state = { cancelled: false };
void isOidcConnectedSession()
.then(ok => {
if (!state.cancelled) setVisible(ok);
if (!state.cancelled) {
setVisible(ok);
}
})
.catch(() => {
// Failed refetch must not clear a known-good session (e.g. transient network).
Expand All @@ -35,7 +37,9 @@ export function LogoutButton() {
}

const handleConfirm = () => {
if (busy) return;
if (busy) {
return;
}
setBusy(true);
void logout()
.then(() => {
Expand Down Expand Up @@ -64,7 +68,9 @@ export function LogoutButton() {
<CenteredModal
open={confirmOpen}
onOpenChange={next => {
if (!busy) setConfirmOpen(next);
if (!busy) {
setConfirmOpen(next);
}
}}
title="Log out"
description="Sure to logout?"
Expand Down
11 changes: 8 additions & 3 deletions packages/local-sandbox/scripts/probe-loopback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ async function listenHost(): Promise<{ port: number; close: () => Promise<void>
close: () =>
new Promise((resolve, reject) => {
server.close(err => {
if (err) reject(err);
else resolve();
if (err) {
reject(err);
} else {
resolve();
}
});
}),
};
Expand All @@ -85,7 +88,9 @@ async function runSandboxed(params: { label: string; command: string; allowedDom
{ commandId: randomUUID(), commandText: params.command },
);
const [argv0, ...argvRest] = wrap.argv;
if (argv0 === undefined) throw new Error('empty argv');
if (argv0 === undefined) {
throw new Error('empty argv');
}

const result = await new Promise<{ code: number | null; out: string }>((resolve, reject) => {
const child = spawn(argv0, argvRest, {
Expand Down
8 changes: 6 additions & 2 deletions packages/local-sandbox/src/core/CodeModeUdsTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export class CodeModeUdsTransport implements CodeModeTransport {
// Oversized / malformed frames only tear down this connection (and notify
// onProtocolError). Transport is handle-scoped and does not kill the process group.
const fail = (message: string): void => {
if (settled) return;
if (settled) {
return;
}
settled = true;
this.onProtocolError?.(message);
socket.destroy();
Expand All @@ -190,7 +192,9 @@ export class CodeModeUdsTransport implements CodeModeTransport {
});

socket.on('end', () => {
if (settled) return;
if (settled) {
return;
}
settled = true;
void this.dispatchConnection(socket, reader).catch((error: unknown) => {
this.onProtocolError?.(error instanceof Error ? error.message : String(error));
Expand Down
34 changes: 25 additions & 9 deletions packages/local-sandbox/src/core/hostRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,13 @@ function darwinUnixSocketPaths(): string[] {

function syncDarwinUnixSockets(): void {
// No-op until initSrt: register/unregister may run from transport-only tests.
if (SandboxManager.getConfig() === undefined) return;
if (SandboxManager.getConfig() === undefined) {
return;
}
const platform = requireActivePlatform();
if (platform !== 'darwin') return;
if (platform !== 'darwin') {
return;
}
SandboxManager.updateConfig(buildSessionConfig(platform));
}

Expand Down Expand Up @@ -327,7 +331,9 @@ export function isSrtInitialized(): boolean {
* Child is spawned as a process-group leader (`detached: true` on Unix).
*/
export function killExecTree(child: ChildProcess | undefined): void {
if (!child) return;
if (!child) {
return;
}
const pid = child.pid;
if (pid !== undefined && process.platform !== 'win32') {
try {
Expand Down Expand Up @@ -421,8 +427,11 @@ export async function runSupervisorSession(params: {
stdinStream.on('error', () => undefined);
await new Promise<void>((resolve, reject) => {
stdinStream.end(stdin, (error?: Error | null) => {
if (error) reject(error);
else resolve();
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
Expand Down Expand Up @@ -453,8 +462,11 @@ export async function runSupervisorSession(params: {
return;
}
const text = chunk.toString('utf8');
if (stream === 'stdout') stdoutText += text;
else stderrText += text;
if (stream === 'stdout') {
stdoutText += text;
} else {
stderrText += text;
}
};

ignoreStreamError(child.stdout);
Expand All @@ -473,15 +485,19 @@ export async function runSupervisorSession(params: {
}, timeoutMs);

child.on('error', error => {
if (closed) return;
if (closed) {
return;
}
closed = true;
clearTimeout(timer);
SandboxManager.cleanupAfterCommand();
reject(error);
});

child.on('close', code => {
if (closed) return;
if (closed) {
return;
}
closed = true;
clearTimeout(timer);
SandboxManager.cleanupAfterCommand();
Expand Down
12 changes: 9 additions & 3 deletions packages/local-sandbox/src/provider/LocalSandboxProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ export class LocalSandboxProvider implements SandboxProvider {
let shell: string | undefined;
for (const name of SHELL_CANDIDATES) {
const resolved = await resolveCommandOnHost({ platform, name });
if (resolved === undefined) continue;
if (resolved === undefined) {
continue;
}
const probe = await runSupervisorSession({
sandboxRootPath: probeRoot,
platform,
Expand All @@ -132,7 +134,9 @@ export class LocalSandboxProvider implements SandboxProvider {
let python: string | undefined;
for (const name of PYTHON_CANDIDATES) {
const resolved = await resolveCommandOnHost({ platform, name });
if (resolved === undefined) continue;
if (resolved === undefined) {
continue;
}
const probe = await runSupervisorSession({
sandboxRootPath: probeRoot,
platform,
Expand Down Expand Up @@ -216,7 +220,9 @@ export class LocalSandboxProvider implements SandboxProvider {
}

private async ensureSrt(): Promise<void> {
if (this.srtInitialized) return;
if (this.srtInitialized) {
return;
}
await initSrt({ platform: this.support.platform });
this.srtInitialized = true;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/trueforge-core/scripts/check-dist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ for (const modulePath of modulePaths) {
try {
require(`${base}.js`);
await import(pathToFileURL(`${base}.mjs`).href);
if (!fs.existsSync(`${base}.d.ts`)) throw new Error('missing .d.ts');
if (!fs.existsSync(`${base}.d.ts`)) {
throw new Error('missing .d.ts');
}
console.log(`ok ${modulePath}.{js,mjs,d.ts}`);
} catch (error) {
failures += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export class TurnResourceResolver<
signal: AbortSignal;
tracing: AgentTracing;
}): Promise<Sandbox | undefined> {
if (!this.deps.sandboxProvider || !specWantsSandbox(input.spec)) return undefined;
if (!this.deps.sandboxProvider || !specWantsSandbox(input.spec)) {
return undefined;
}
this.#sandbox = await this.deps.sandboxProvider({
spec: input.spec,
existingSandboxId: input.existing?.sandbox_id,
Expand Down Expand Up @@ -234,7 +236,9 @@ export class TurnResourceResolver<
*/
protected getOrCreateToolSource(input: { id: string; create: () => Promise<ToolSource> }): Promise<ToolSource> {
const cached = this.#sources.get(input.id);
if (cached) return cached;
if (cached) {
return cached;
}
const made = input.create();
this.#sources.set(input.id, made);
return made;
Expand Down
4 changes: 3 additions & 1 deletion packages/trueforge-core/src/agent-session/schemas/turn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ export const CreateTurnRequestSchema = z
.describe('When true (default), stream turn events as SSE. When false, return the running turn immediately.'),
})
.superRefine((data, ctx) => {
if (!data.input) return;
if (!data.input) {
return;
}
const hasUser = data.input.some(msg => 'type' in msg && msg.type === 'user.message');
const hasApprovalOrToolResponse = data.input.some(
msg => 'type' in msg && (msg.type === 'user.tool_approval' || msg.type === 'user.tool_response'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ function turnKey({ session_id, turn_id }: { session_id: string; turn_id: string

/** Lexicographic session_id order — shared by listSessions sort and keyset filter. */
function compareSessionId(a: string, b: string): number {
if (a < b) return -1;
if (a > b) return 1;
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}

Expand Down Expand Up @@ -231,7 +235,9 @@ export class InMemorySessionStore<
): Promise<{ data: SessionRecord<TSessionCustom>[]; pagination: TokenPagination }> {
const records: SessionRecord<TSessionCustom>[] = [];
for (const stored of this.sessions.values()) {
if (stored.record.tenant_id !== input.tenant_id) continue;
if (stored.record.tenant_id !== input.tenant_id) {
continue;
}
if (
input.agent_id !== undefined &&
(stored.record.agent.type !== 'reference' || stored.record.agent.id !== input.agent_id)
Expand All @@ -242,8 +248,12 @@ export class InMemorySessionStore<
continue;
}
const createdAt = stored.record.created_at.getTime();
if (input.start_timestamp !== undefined && createdAt < input.start_timestamp.getTime()) continue;
if (input.end_timestamp !== undefined && createdAt > input.end_timestamp.getTime()) continue;
if (input.start_timestamp !== undefined && createdAt < input.start_timestamp.getTime()) {
continue;
}
if (input.end_timestamp !== undefined && createdAt > input.end_timestamp.getTime()) {
continue;
}
records.push(stored.record);
}
records.sort((a, b) => {
Expand Down Expand Up @@ -569,11 +579,17 @@ export class InMemorySessionStore<
let oldestId = chain[0];
while (oldestId && oldestId !== anchor.turn_id) {
const oldest = this.turns.get(turnKey({ session_id: sessionId, turn_id: oldestId }));
if (!oldest) break;
if (!oldest) {
break;
}
const older = oldest.ancestor_ids.filter(id => !seen.has(id));
if (older.length === 0) break;
if (older.length === 0) {
break;
}
chain.unshift(...older);
for (const id of older) seen.add(id);
for (const id of older) {
seen.add(id);
}
oldestId = older[0];
}
return chain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function encodeOffsetPageToken(offset: number): string {
}

export function decodeOffsetPageToken(token: string | undefined): number {
if (token === undefined || token === '') return 0;
if (token === undefined || token === '') {
return 0;
}
return decodePageToken(OffsetPageCursorSchema, token).offset;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export function encodeSessionListPageToken(cursor: SessionListPageCursor): strin
}

export function decodeSessionListPageToken(token: string | undefined): SessionListPageCursor | undefined {
if (token === undefined) return undefined;
if (token === undefined) {
return undefined;
}
return decodePageToken(SessionListPageCursorSchema, token);
}

Expand Down
16 changes: 12 additions & 4 deletions packages/trueforge-core/src/core/InstructionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export class InstructionBuilder {
/** Adds raw text (no wrapping tag) to this section. Empty strings are ignored. */
addContent(content: string): this {
const trimmed = content.trim();
if (trimmed) this.children.push(trimmed);
if (trimmed) {
this.children.push(trimmed);
}
return this;
}

Expand All @@ -82,7 +84,9 @@ export class InstructionBuilder {
*/
addSection(tag: string, content: string, escapeContent = false): this {
const trimmed = content.trim();
if (!trimmed) return this;
if (!trimmed) {
return this;
}
const child = new InstructionBuilder(tag, escapeContent);
child.children.push(trimmed);
this.children.push(child);
Expand All @@ -104,11 +108,15 @@ export class InstructionBuilder {
inner.push(child);
} else {
const output = child.build();
if (output) inner.push(output);
if (output) {
inner.push(output);
}
}
}

if (inner.length === 0) return '';
if (inner.length === 0) {
return '';
}

const body = inner.join('\n\n');
if (this.escapeContent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ interface ToolResultWithInfo {
}

function categorize(result: ToolCallResult, sandbox: Sandbox | undefined): ResultCategory {
if (result.failure) return 'failure';
if (result.failure) {
return 'failure';
}
if (!result.info) {
throw new Error(`Unreachable`);
}
if (sandbox && result.info.toolSet === sandbox) return 'sandbox';
if (sandbox && result.info.toolSet === sandbox) {
return 'sandbox';
}
return 'mcp';
}

Expand Down
Loading
Loading