Skip to content

Commit 27dbf15

Browse files
authored
chore(settings): simplify auto-publish threading after review
Inline the one-ternary getCloudAutoPublish helper, pass the option value through in the request body builder, take a single settings snapshot in useTaskCreation, and split the no-repo cloud prompt into per-mode blocks mirroring the repository branch. Generated-By: PostHog Code Task-Id: 49d73463-ec66-491c-b645-f6116972bd02
1 parent 2a93346 commit 27dbf15

5 files changed

Lines changed: 20 additions & 22 deletions

File tree

packages/agent/src/server/agent-server.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,28 +2729,33 @@ ${signedCommitInstructions}${prLinkInstructions}${shellEfficiencyInstructions}
27292729
}
27302730

27312731
if (!this.config.repositoryPath) {
2732-
const publishTiming = shouldAutoCreatePr
2733-
? `- After completing code changes in a cloned repository, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone without waiting to be asked.`
2734-
: `- If the user explicitly asks you to open or update a pull request, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone.`;
2735-
const publishClosing = shouldAutoCreatePr
2736-
? `- Always create the PR as a draft. Do not ask for confirmation before publishing completed code changes`
2737-
: `- Do NOT create branches, commits, push changes, or open pull requests unless the user explicitly asks for that`;
27382732
const publishInstructions =
27392733
this.config.createPr === false
27402734
? `
27412735
When the user asks for code changes:
27422736
- You may clone a repository and make local edits in that clone
27432737
- Do NOT create branches, commits, push changes, or open pull requests in this run`
2744-
: `
2745-
When the user ${shouldAutoCreatePr ? "asks" : "explicitly asks"} to clone or work in a GitHub repository:
2738+
: shouldAutoCreatePr
2739+
? `
2740+
When the user asks to clone or work in a GitHub repository:
27462741
- Clone the repository into /tmp/workspace/repos/<owner>/<repo> using \`gh repo clone <owner>/<repo> /tmp/workspace/repos/<owner>/<repo>\`
27472742
- Work from inside that cloned repository for follow-up code changes
2748-
${publishTiming} Before opening the PR, check the cloned repo for a PR template at \`.github/pull_request_template.md\` (or variants; fall back to the org's \`.github\` repo via \`gh api\`) and use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links.
2743+
- After completing code changes in a cloned repository, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone without waiting to be asked. Before opening the PR, check the cloned repo for a PR template at \`.github/pull_request_template.md\` (or variants; fall back to the org's \`.github\` repo via \`gh api\`) and use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links.
27492744
- Keep the PR description brief overall. Summarize only the most important changes — do NOT enumerate every change you made. A few sentences or bullets is plenty.
27502745
${whyContextInstruction.trimStart()}
27512746
${publicRepoSafetyInstruction.trimStart()}
27522747
- End the PR description with a horizontal rule followed by this footer line: ${prFooter}
2753-
${publishClosing}`;
2748+
- Always create the PR as a draft. Do not ask for confirmation before publishing completed code changes`
2749+
: `
2750+
When the user explicitly asks to clone or work in a GitHub repository:
2751+
- Clone the repository into /tmp/workspace/repos/<owner>/<repo> using \`gh repo clone <owner>/<repo> /tmp/workspace/repos/<owner>/<repo>\`
2752+
- Work from inside that cloned repository for follow-up code changes
2753+
- If the user explicitly asks you to open or update a pull request, create a branch, stage your changes with \`git add\` and commit them with the \`git_signed_commit\` tool (do NOT use \`git commit\`/\`git push\` — they are blocked), and open a draft pull request from inside the clone. Before opening the PR, check the cloned repo for a PR template at \`.github/pull_request_template.md\` (or variants; fall back to the org's \`.github\` repo via \`gh api\`) and use it as the body structure, and search for matching open issues with \`gh issue list --search\` to include \`Closes #<n>\` / \`Refs #<n>\` links.
2754+
- Keep the PR description brief overall. Summarize only the most important changes — do NOT enumerate every change you made. A few sentences or bullets is plenty.
2755+
${whyContextInstruction.trimStart()}
2756+
${publicRepoSafetyInstruction.trimStart()}
2757+
- End the PR description with a horizontal rule followed by this footer line: ${prFooter}
2758+
- Do NOT create branches, commits, push changes, or open pull requests unless the user explicitly asks for that`;
27542759

27552760
return `${identityInstructions}
27562761
# Cloud Task Execution — No Repository Mode

packages/api-client/src/posthog-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ function buildCloudRunRequestBody(
553553
body.pr_authorship_mode = options.prAuthorshipMode;
554554
}
555555
if (options?.autoPublish) {
556-
body.auto_publish = true;
556+
body.auto_publish = options.autoPublish;
557557
}
558558
if (options?.runSource) {
559559
body.run_source = options.runSource;

packages/core/src/sessions/cloudRunOptions.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ export function getCloudRunSource(
3131
return state.run_source === "signal_report" ? "signal_report" : "manual";
3232
}
3333

34-
export function getCloudAutoPublish(
35-
state: Record<string, unknown>,
36-
): boolean | undefined {
37-
return state.auto_publish === true ? true : undefined;
38-
}
39-
4034
export interface CloudRuntimeOptions {
4135
adapter?: Adapter;
4236
model?: string;

packages/core/src/sessions/sessionService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import { CloudLogGapReconciler } from "./cloudLogGapReconciler";
5151
import { CloudRunIdleTracker } from "./cloudRunIdleTracker";
5252
import {
5353
type CloudRuntimeOptions,
54-
getCloudAutoPublish,
5554
getCloudPrAuthorshipMode,
5655
getCloudRunSource,
5756
getCloudRuntimeOptions,
@@ -2928,7 +2927,7 @@ export class SessionService {
29282927
pendingUserArtifactIds:
29292928
artifactIds.length > 0 ? artifactIds : undefined,
29302929
prAuthorshipMode,
2931-
autoPublish: getCloudAutoPublish(previousState),
2930+
autoPublish: previousState.auto_publish === true || undefined,
29322931
runSource: getCloudRunSource(previousState),
29332932
signalReportId:
29342933
typeof previousState.signal_report_id === "string"

packages/ui/src/features/task-detail/hooks/useTaskCreation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export function useTaskCreation({
299299
}
300300
}
301301

302+
const settings = useSettingsStore.getState();
302303
const input = prepareTaskInput(serializedContent, filePaths, {
303304
// In channels chat-box mode no repo is attached up front, even if a
304305
// directory/repo is lingering in the persisted picker state.
@@ -321,9 +322,8 @@ export function useTaskCreation({
321322
channelContext,
322323
channelName,
323324
channelId,
324-
customInstructions: useSettingsStore.getState().customInstructions,
325-
autoPublishCloudRuns:
326-
useSettingsStore.getState().autoPublishCloudRuns,
325+
customInstructions: settings.customInstructions,
326+
autoPublishCloudRuns: settings.autoPublishCloudRuns,
327327
allowNoRepo,
328328
});
329329

0 commit comments

Comments
 (0)