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
1 change: 1 addition & 0 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ function threadRun(
requestedAt: DateTime.formatIso(run.requestedAt),
startedAt: run.startedAt === null ? null : DateTime.formatIso(run.startedAt),
completedAt: run.completedAt === null ? null : DateTime.formatIso(run.completedAt),
...(run.delegationNudge === undefined ? {} : { delegationNudge: run.delegationNudge }),
};
}

Expand Down
38 changes: 34 additions & 4 deletions apps/server/src/mcp/ThreadMetadataMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ function metadataCommand(input: {
readonly commandId: CommandId;
readonly threadId: ThreadId;
readonly update: ThreadMetadataMcpUpdateInput;
readonly actorThreadId: ThreadId | undefined;
}): Extract<
OrchestrationV2Command,
{ readonly type: "thread.metadata.update" | "thread.standing.set" }
{ readonly type: "thread.metadata.update" | "thread.standing.set" | "thread.delegation-nudge.set" }
> {
switch (input.update.action) {
case "set_standing":
Expand All @@ -79,6 +80,20 @@ function metadataCommand(input: {
threadId: input.threadId,
standing: input.update.standing ?? null,
};
case "set_delegation_nudge":
return {
type: "thread.delegation-nudge.set",
commandId: input.commandId,
threadId: input.threadId,
enabled: input.update.delegationNudge?.enabled ?? false,
...(input.update.delegationNudge?.thresholds === undefined
? {}
: { thresholds: input.update.delegationNudge.thresholds }),
changedBy:
input.actorThreadId === undefined
? { kind: "mcp_client" }
: { kind: "agent", threadId: input.actorThreadId },
};
case "route":
return {
type: "thread.metadata.update",
Expand Down Expand Up @@ -123,12 +138,15 @@ function resultFromThread(input: {
readonly sequence: number;
readonly thread: Pick<
OrchestrationV2AppThread,
"id" | "title" | "titleRegeneration" | "linkedPullRequest" | "updatedAt" | "inbox" | "standing"
"id" | "title" | "titleRegeneration" | "linkedPullRequest" | "updatedAt" | "inbox" | "standing" | "delegationNudge"
>;
}): ThreadMetadataMcpUpdateResult {
return {
...(input.thread.inbox === undefined ? {} : { inbox: input.thread.inbox }),
...(input.thread.standing === undefined ? {} : { standing: input.thread.standing }),
...(input.thread.delegationNudge === undefined
? {}
: { delegationNudge: input.thread.delegationNudge }),
threadId: input.thread.id,
action: input.action,
commandId: input.commandId,
Expand Down Expand Up @@ -196,6 +214,15 @@ const make = Effect.gen(function* () {
input.inboxRouting,
);
if (inboxError !== null) return yield* failure("invalid_request", inboxError);
if (
input.action === "set_delegation_nudge" &&
scope.thread?.threadId === threadId
) {
return yield* failure(
"invalid_request",
"A thread cannot change its own delegation nudge. Ask from another thread or the client.",
);
}
const requestKey =
input.clientRequestId === undefined ? yield* random.uuidV4() : input.clientRequestId;
const updateCommandId = commandId({
Expand All @@ -210,6 +237,7 @@ const make = Effect.gen(function* () {
commandId: updateCommandId,
threadId,
update: input,
actorThreadId: scope.thread?.threadId,
}),
)
.pipe(
Expand All @@ -223,12 +251,14 @@ const make = Effect.gen(function* () {
const metadataEvent = dispatched.storedEvents.find(
(stored) =>
stored.event.type === "thread.metadata-updated" ||
stored.event.type === "thread.standing-updated",
stored.event.type === "thread.standing-updated" ||
stored.event.type === "thread.delegation-nudge-updated",
);
// Retries may find stored events compacted away; answer from the projection.
const thread =
metadataEvent?.event.type === "thread.metadata-updated" ||
metadataEvent?.event.type === "thread.standing-updated"
metadataEvent?.event.type === "thread.standing-updated" ||
metadataEvent?.event.type === "thread.delegation-nudge-updated"
? metadataEvent.event.payload
: yield* threadManagement
.getThreadShell(threadId)
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/mcp/toolkits/orchestrator/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const ThreadReadTool = Tool.make("t3_thread_read", {

const ThreadUpdateTool = Tool.make("t3_thread_update", {
description:
"Default: this thread. Founder must decide/review/approve: `request_decision` with `decision`; stays in their inbox until reply, `resolve_decision` or settle. `route`: `inboxRouting`, `reason` for founder/shared. `rename`: `title`; `set_standing`: `standing`. Not workspace/branch.",
"Default: this thread. Founder must decide/review/approve: `request_decision` with `decision`; stays in their inbox until reply, `resolve_decision` or settle. `route`: `inboxRouting`, `reason` for founder/shared. `rename`: `title`; `set_standing`: `standing`; `set_delegation_nudge`: `delegationNudge` {enabled, thresholds?}, not on itself. Not workspace/branch.",
// Keeps the input's action/field check, which rebuilding the struct would drop.
parameters: ThreadMetadataMcpUpdateInput.mapFields(
Struct.assign({ environmentId: OrchestratorMcpEnvironmentTarget }),
Expand Down
Loading
Loading