Skip to content

Commit 9fca8c0

Browse files
arul28claude
andauthored
ship: orchestrator smoke cleanup — simplify code, update docs, add work session tests (#362)
Simplify nested ternaries, inline one-use helpers, consolidate duplicated guards, restore precise types, and update feature docs after the large missions-removal and Cursor SDK cleanup merges. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5962526 commit 9fca8c0

28 files changed

Lines changed: 759 additions & 401 deletions

apps/ade-cli/src/adeRpcServer.ts

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,9 +2410,7 @@ function buildAdeInlineGuidanceForLane(laneWorktreePath: string | null | undefin
24102410
return buildAdeCliInlineGuidance(getAdeAgentSkillRootsForPrompt({ cwd: laneWorktreePath ?? undefined }));
24112411
}
24122412

2413-
function resolveRunContextLaneId(runtime: AdeRuntime, callerCtx: CallerContext): string | null {
2414-
void runtime;
2415-
void callerCtx;
2413+
function resolveRunContextLaneId(_runtime: AdeRuntime, _callerCtx: CallerContext): string | null {
24162414
return null;
24172415
}
24182416

@@ -2864,12 +2862,8 @@ async function resolveEffectiveCallerContext(
28642862
return callerCtx;
28652863
}
28662864

2867-
function isStandaloneChatCaller(callerCtx: CallerContext): boolean {
2868-
return callerCtx.standaloneChatSession;
2869-
}
2870-
28712865
function isToolHiddenForStandaloneChat(name: string, callerCtx: CallerContext): boolean {
2872-
return isStandaloneChatCaller(callerCtx) && STANDALONE_CHAT_HIDDEN_TOOL_NAMES.has(name);
2866+
return callerCtx.standaloneChatSession && STANDALONE_CHAT_HIDDEN_TOOL_NAMES.has(name);
28732867
}
28742868

28752869
function isLocalComputerUseAllowed(callerCtx: CallerContext): boolean {
@@ -2922,8 +2916,7 @@ async function listToolSpecsForSession(runtime: AdeRuntime, session: SessionStat
29222916
return allVisibleTools.filter((tool) => !isToolHiddenForStandaloneChat(tool.name, callerCtx));
29232917
}
29242918

2925-
function parseInitializeIdentity(runtime: AdeRuntime, params: unknown): SessionIdentity {
2926-
void runtime;
2919+
function parseInitializeIdentity(_runtime: AdeRuntime, params: unknown): SessionIdentity {
29272920
const data = safeObject(params);
29282921
const identity = safeObject(data.identity);
29292922
const envContext = resolveEnvCallerContext();
@@ -3094,7 +3087,6 @@ async function buildLaneStatus(runtime: AdeRuntime, laneId: string): Promise<Rec
30943087
};
30953088
}
30963089

3097-
30983090
// Global ask_user rate limit shared across all sessions to prevent
30993091
// bypass via session recycling. Limits to 20 calls per 60s globally.
31003092
const GLOBAL_ASK_USER_RATE_LIMIT = {
@@ -3217,9 +3209,7 @@ async function runTool(args: {
32173209
title: args.title,
32183210
path: args.artifactPath,
32193211
mimeType: args.mimeType,
3220-
metadata: {
3221-
...args.metadata,
3222-
},
3212+
metadata: args.metadata,
32233213
},
32243214
],
32253215
owners: resolveComputerUseOwners(args.sessionState, args.toolArgs),
@@ -3602,14 +3592,17 @@ async function runTool(args: {
36023592
const argsList = Array.isArray(toolArgs.argsList) ? toolArgs.argsList : null;
36033593
const hasScalarArg = Object.prototype.hasOwnProperty.call(toolArgs, "arg");
36043594
const rawObjectArgs = safeObject(toolArgs.args);
3605-
const result = argsList
3606-
? await (callable as (...params: unknown[]) => Promise<unknown>).apply(service, argsList)
3607-
: hasScalarArg
3608-
? await (callable as (arg: unknown) => Promise<unknown>).call(service, toolArgs.arg)
3609-
: await (callable as (args?: Record<string, unknown>) => Promise<unknown>).call(
3610-
service,
3611-
Object.keys(rawObjectArgs).length > 0 ? rawObjectArgs : undefined
3612-
);
3595+
let result: unknown;
3596+
if (argsList) {
3597+
result = await (callable as (...params: unknown[]) => Promise<unknown>).apply(service, argsList);
3598+
} else if (hasScalarArg) {
3599+
result = await (callable as (arg: unknown) => Promise<unknown>).call(service, toolArgs.arg);
3600+
} else {
3601+
result = await (callable as (args?: Record<string, unknown>) => Promise<unknown>).call(
3602+
service,
3603+
Object.keys(rawObjectArgs).length > 0 ? rawObjectArgs : undefined,
3604+
);
3605+
}
36133606
const record = isRecord(result) ? result : null;
36143607
const statusHints = {
36153608
operationId: typeof record?.operationId === "string" ? record.operationId : null,
@@ -4076,11 +4069,10 @@ async function runTool(args: {
40764069
});
40774070
}
40784071
const answered = result.decision !== "decline" && result.decision !== "cancel";
4079-
const outcome = result.decision === "decline"
4080-
? "declined"
4081-
: result.decision === "cancel"
4082-
? "cancelled"
4083-
: "answered";
4072+
let outcome: "answered" | "declined" | "cancelled";
4073+
if (result.decision === "decline") outcome = "declined";
4074+
else if (result.decision === "cancel") outcome = "cancelled";
4075+
else outcome = "answered";
40844076
return buildAskUserResult({
40854077
awaitingUserResponse: false,
40864078
blocking: false,

apps/ade-cli/src/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ export async function createAdeRuntime(args: {
718718
projectRoot,
719719
logger,
720720
onEvent: (event) => pushEvent("runtime", { type: "computer_use_event", event }),
721-
} as Parameters<typeof createComputerUseArtifactBrokerService>[0]);
721+
});
722722
const iosSimulatorService = chatOnlyRuntime
723723
? null
724724
: createIosSimulatorService({

apps/ade-cli/src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10127,10 +10127,10 @@ function readMachineRuntimeInfo(value: unknown): MachineRuntimeInfo {
1012710127
}
1012810128
const pid = value.runtimeInfo.pid;
1012910129
return {
10130-
version: asString(value.runtimeInfo.version)?.trim() || null,
10131-
buildHash: asString(value.runtimeInfo.buildHash)?.trim() || null,
10130+
version: asString(value.runtimeInfo.version),
10131+
buildHash: asString(value.runtimeInfo.buildHash),
1013210132
defaultRole: normalizeAdeRuntimeRole(value.runtimeInfo.defaultRole),
10133-
projectRoot: asString(value.runtimeInfo.projectRoot)?.trim() || null,
10133+
projectRoot: asString(value.runtimeInfo.projectRoot),
1013410134
pid:
1013510135
typeof pid === "number" && Number.isFinite(pid) && pid > 0
1013610136
? Math.floor(pid)

apps/ade-cli/src/headlessLinearServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ export function createHeadlessLinearServices(
16471647
outboundService,
16481648
prService,
16491649
computerUseArtifactBrokerService: args.computerUseArtifactBrokerService,
1650-
} as Parameters<typeof createLinearCloseoutServiceImpl>[0]);
1650+
});
16511651
const dispatcherService = createLinearDispatcherServiceImpl({
16521652
db: args.db,
16531653
projectId: args.projectId,
@@ -1662,7 +1662,7 @@ export function createHeadlessLinearServices(
16621662
workerTaskSessionService,
16631663
prService,
16641664
onEvent: args.onLinearWorkflowEvent ?? (() => {}),
1665-
} as Parameters<typeof createLinearDispatcherServiceImpl>[0]);
1665+
});
16661666
const syncService = createLinearSyncServiceImpl({
16671667
db: args.db,
16681668
logger: args.logger,

apps/ade-cli/src/multiProjectRpcServer.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,19 @@ export function createMultiProjectRpcRequestHandler(
378378
return syncService;
379379
};
380380

381-
const resolveRuntimeEnvInfo = () => ({
382-
buildHash:
383-
typeof process.env.ADE_RUNTIME_BUILD_HASH === "string" &&
384-
process.env.ADE_RUNTIME_BUILD_HASH.trim()
385-
? process.env.ADE_RUNTIME_BUILD_HASH.trim()
386-
: null,
387-
defaultRole: normalizeAdeRuntimeRole(process.env.ADE_DEFAULT_ROLE),
388-
projectRoot:
389-
typeof process.env.ADE_PROJECT_ROOT === "string" &&
390-
process.env.ADE_PROJECT_ROOT.trim()
391-
? path.resolve(process.env.ADE_PROJECT_ROOT.trim())
392-
: null,
393-
});
381+
const trimmedEnvOrNull = (key: string): string | null => {
382+
const value = process.env[key];
383+
return typeof value === "string" && value.trim() ? value.trim() : null;
384+
};
385+
386+
const resolveRuntimeEnvInfo = () => {
387+
const projectRoot = trimmedEnvOrNull("ADE_PROJECT_ROOT");
388+
return {
389+
buildHash: trimmedEnvOrNull("ADE_RUNTIME_BUILD_HASH"),
390+
defaultRole: normalizeAdeRuntimeRole(process.env.ADE_DEFAULT_ROLE),
391+
projectRoot: projectRoot ? path.resolve(projectRoot) : null,
392+
};
393+
};
394394

395395
const handler = (async (request: JsonRpcRequest): Promise<unknown | null> => {
396396
const method = typeof request.method === "string" ? request.method : "";

apps/ade-cli/src/tuiClient/connection.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,22 +384,20 @@ class StaleAdeSocketError extends Error {
384384
}
385385
}
386386

387+
function trimmedStringOrNull(value: unknown): string | null {
388+
if (typeof value !== "string") return null;
389+
const trimmed = value.trim();
390+
return trimmed || null;
391+
}
392+
387393
function readAttachedRuntimeInfo(result: InitializeResult): AttachedRuntimeInfo {
388394
const runtimeInfo = result.runtimeInfo;
389395
const pid = runtimeInfo?.pid;
396+
const projectRoot = trimmedStringOrNull(runtimeInfo?.projectRoot);
390397
return {
391-
buildHash:
392-
typeof runtimeInfo?.buildHash === "string" && runtimeInfo.buildHash.trim()
393-
? runtimeInfo.buildHash.trim()
394-
: null,
395-
defaultRole:
396-
typeof runtimeInfo?.defaultRole === "string" && runtimeInfo.defaultRole.trim()
397-
? runtimeInfo.defaultRole.trim()
398-
: null,
399-
projectRoot:
400-
typeof runtimeInfo?.projectRoot === "string" && runtimeInfo.projectRoot.trim()
401-
? path.resolve(runtimeInfo.projectRoot.trim())
402-
: null,
398+
buildHash: trimmedStringOrNull(runtimeInfo?.buildHash),
399+
defaultRole: trimmedStringOrNull(runtimeInfo?.defaultRole),
400+
projectRoot: projectRoot ? path.resolve(projectRoot) : null,
403401
pid:
404402
typeof pid === "number" && Number.isFinite(pid) && pid > 0
405403
? Math.floor(pid)

apps/desktop/src/main/services/config/projectConfigService.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -594,21 +594,18 @@ function coerceAutomationExecution(value: unknown): AutomationExecution | undefi
594594

595595
if (kind === "agent-session") {
596596
const legacyTitle = kindRaw === "mission" ? legacyMissionPrompt(value) : undefined;
597-
const session = isRecord(value.session)
597+
const sessionTitle = isRecord(value.session)
598+
? firstNonEmptyString(value.session.title, legacyTitle)
599+
: legacyTitle;
600+
const sessionReasoningEffort = isRecord(value.session) ? asString(value.session.reasoningEffort)?.trim() : undefined;
601+
const sessionCodexFastMode = isRecord(value.session) ? asBool(value.session.codexFastMode) : undefined;
602+
const session = sessionTitle || sessionReasoningEffort || sessionCodexFastMode != null
598603
? {
599-
...(asString(value.session.title)?.trim()
600-
? { title: asString(value.session.title)!.trim() }
601-
: legacyTitle
602-
? { title: legacyTitle }
603-
: {}),
604-
...(asString(value.session.reasoningEffort)?.trim()
605-
? { reasoningEffort: asString(value.session.reasoningEffort)!.trim() }
606-
: {}),
607-
...(asBool(value.session.codexFastMode) != null ? { codexFastMode: asBool(value.session.codexFastMode) } : {}),
604+
...(sessionTitle ? { title: sessionTitle } : {}),
605+
...(sessionReasoningEffort ? { reasoningEffort: sessionReasoningEffort } : {}),
606+
...(sessionCodexFastMode != null ? { codexFastMode: sessionCodexFastMode } : {}),
608607
}
609-
: legacyTitle
610-
? { title: legacyTitle }
611-
: undefined;
608+
: undefined;
612609
return {
613610
kind,
614611
...sharedLaneFields,

apps/desktop/src/renderer/components/chat/AgentChatComposer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,9 +2608,7 @@ export function AgentChatComposer({
26082608
captureRichSelection();
26092609
}, [captureRichSelection, getRichCursorTextOffset, onDraftChange, serializeRichEditor]);
26102610

2611-
const singleModelBlockedMessage = (modelUnavailableMessage?.trim() ?? "").length > 0
2612-
? modelUnavailableMessage
2613-
: null;
2611+
const singleModelBlockedMessage = modelUnavailableMessage?.trim() ? modelUnavailableMessage : null;
26142612
const singleModelReady = Boolean(modelId) && !singleModelBlockedMessage;
26152613

26162614
const submitComposerDraft = useCallback(() => {

0 commit comments

Comments
 (0)