Skip to content

Commit 2320ea8

Browse files
edburnsCopilotCopilot
authored
Rename SystemPromptSections → SystemMessageSections for cross-SDK consistency (#1683)
* Rename SystemPromptSections → SystemMessageSections for cross-SDK consistency Introduce `SystemMessageSections` as a sealed superclass containing all well-known section identifier constants. The existing `SystemPromptSections` becomes a deprecated final subclass that inherits everything unchanged, preserving backward compatibility. New files: - `SystemMessageSections.java`: Sealed class with all `public static final String` constants (IDENTITY, TONE, TOOL_EFFICIENCY, etc.) and Javadoc matching the naming convention used by Node, Python, .NET, Go, and Rust SDKs. - `SystemMessageSectionsIT.java`: Failsafe integration test that validates transform callbacks on IDENTITY and TONE sections receive non-empty content from the live CLI, plus an equivalence test ensuring the deprecated subclass inherits all constants correctly. Modified files: - `SystemPromptSections.java`: Gutted to an empty `@Deprecated(since="1.0.2", forRemoval=true)` final class extending `SystemMessageSections`. - `SystemMessageConfig.java`: Updated Javadoc references from `SystemPromptSections` to `SystemMessageSections`. - `SectionOverride.java`: Updated Javadoc references from `SystemPromptSections` to `SystemMessageSections`. Fixes #1679 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(java): address review feedback for system message sections Co-authored-by: edburns <75821+edburns@users.noreply.github.com> * Fix SystemMessageSectionsIT: remove live-auth test, add reflection-based inheritance tests The transform test required live CLI authentication which is unavailable in CI. Replace it with three tests that validate the sealed hierarchy without needing a live session: 1. deprecatedSystemPromptSectionsMatchesSystemMessageSections — value equality 2. systemPromptSectionsExtendsSystemMessageSections — class hierarchy check 3. allConstantsInheritedByDeprecatedClass — reflection-based exhaustive check Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix SystemMessageSectionsIT: use replay proxy for transform test Replace the live-auth transform test with an E2E test that uses the replay proxy and the existing system_message_transform snapshot. This works in CI without requiring authenticated CLI access. The test now has three methods: - transformOnIdentitySectionReceivesNonEmptyContent: E2E via replay proxy - deprecatedSystemPromptSectionsMatchesSystemMessageSections: value equality - allConstantsInheritedByDeprecatedClass: reflection-based inheritance check Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename SystemPromptSections → SystemMessageSections for cross-SDK consistency Fixes #1679 ## Summary Introduces `SystemMessageSections` as the canonical class for section constants in the Java SDK, aligning with the naming used in .NET, Python, and other SDKs. The previous `SystemPromptSections` class is preserved as a deprecated subclass for backward compatibility. ## Changes ### New files - `java/src/main/java/com/github/copilot/rpc/SystemMessageSections.java` Sealed superclass containing all 11 system message section constants (IDENTITY, INSTRUCTIONS, CONTEXT, TOOL_HANDLING, etc.) with full Javadoc. Permits only `SystemPromptSections` as a subclass. - `java/src/test/java/com/github/copilot/SystemMessageSectionsIT.java` Failsafe integration test with 4 test methods: 1. `transformOnIdentitySectionReceivesNonEmptyContent` — verifies that the transform callback fires with real section content using the replay proxy. 2. `deprecatedClassReferencesAreEquivalent` — confirms that constants accessed via the deprecated `SystemPromptSections` are identical to `SystemMessageSections`. 3. `allConstantsInheritedByDeprecatedClass` — reflection-based exhaustive check that all 11 constants are inherited correctly. 4. `shouldUseReplacedIdentitySectionInResponse` — E2E test proving that `SectionOverrideAction.REPLACE` on the IDENTITY section causes the assistant to adopt a custom identity (Botanica gardening assistant). - `test/snapshots/system_message_sections/should_use_replaced_identity_section_in_response.yaml` Handcrafted replay proxy snapshot for the REPLACE identity test. Contains a single conversation: user asks "Who are you?", assistant responds as Botanica. ### Modified files - `java/src/main/java/com/github/copilot/rpc/SystemPromptSections.java` Gutted to a deprecated final subclass that extends `SystemMessageSections`. All constants are now inherited from the parent. Marked `@Deprecated(since = "1.0.2", forRemoval = true)`. - `java/src/main/java/com/github/copilot/rpc/SystemMessageConfig.java` Updated Javadoc `@see` references from `SystemPromptSections` to `SystemMessageSections`. - `java/src/main/java/com/github/copilot/rpc/SectionOverride.java` Updated Javadoc `@see` references from `SystemPromptSections` to `SystemMessageSections`. * Correct bogus @SInCE values --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 1d61f7a commit 2320ea8

15 files changed

Lines changed: 316 additions & 86 deletions

java/src/main/java/com/github/copilot/CopilotSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ public CompletableFuture<Void> abort() {
18181818
* @return a future that completes when the model switch is acknowledged
18191819
* @throws IllegalStateException
18201820
* if this session has been terminated
1821-
* @since 1.2.0
1821+
* @since 1.0.0
18221822
*/
18231823
public CompletableFuture<Void> setModel(String model, String reasoningEffort) {
18241824
ensureNotTerminated();
@@ -1958,7 +1958,7 @@ public CompletableFuture<Void> setModel(String model) {
19581958
* @return a future that completes when the message is logged
19591959
* @throws IllegalStateException
19601960
* if this session has been terminated
1961-
* @since 1.2.0
1961+
* @since 1.0.0
19621962
*/
19631963
public CompletableFuture<Void> log(String message, String level, Boolean ephemeral, String url) {
19641964
ensureNotTerminated();

java/src/main/java/com/github/copilot/SystemMessageMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public enum SystemMessageMode {
4242
* default system prompt. An optional {@code content} string is appended after
4343
* all sections when provided.
4444
*
45-
* @since 1.2.0
45+
* @since 1.0.0
4646
*/
4747
CUSTOMIZE("customize");
4848

java/src/main/java/com/github/copilot/rpc/BlobAttachment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* }</pre>
2424
*
2525
* @see MessageOptions#setAttachments(java.util.List)
26-
* @since 1.2.0
26+
* @since 1.0.0
2727
*/
2828
@JsonInclude(JsonInclude.Include.NON_NULL)
2929
public final class BlobAttachment implements MessageAttachment {

java/src/main/java/com/github/copilot/rpc/CopilotClientOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public CopilotClientOptions setRemote(boolean remote) {
512512
* Gets the OpenTelemetry configuration for the CLI server.
513513
*
514514
* @return the telemetry config, or {@code null}
515-
* @since 1.2.0
515+
* @since 1.0.0
516516
*/
517517
public TelemetryConfig getTelemetry() {
518518
return telemetry;
@@ -527,7 +527,7 @@ public TelemetryConfig getTelemetry() {
527527
* @param telemetry
528528
* the telemetry configuration
529529
* @return this options instance for method chaining
530-
* @since 1.2.0
530+
* @since 1.0.0
531531
*/
532532
public CopilotClientOptions setTelemetry(TelemetryConfig telemetry) {
533533
this.telemetry = Objects.requireNonNull(telemetry, "telemetry must not be null");

java/src/main/java/com/github/copilot/rpc/MessageAttachment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @see Attachment
1717
* @see BlobAttachment
1818
* @see MessageOptions#setAttachments(java.util.List)
19-
* @since 1.2.0
19+
* @since 1.0.0
2020
*/
2121
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
2222
@JsonSubTypes({@JsonSubTypes.Type(value = Attachment.class, name = "file"),

java/src/main/java/com/github/copilot/rpc/SectionOverride.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,34 @@
1212
import com.fasterxml.jackson.annotation.JsonProperty;
1313

1414
/**
15-
* Override operation for a single system prompt section in
15+
* Override operation for a single system message section in
1616
* {@link SystemMessageMode#CUSTOMIZE} mode.
1717
* <p>
1818
* Each {@code SectionOverride} describes how one named section of the default
19-
* system prompt should be modified. The section name keys come from
20-
* {@link SystemPromptSections}.
19+
* system message should be modified. The section name keys come from
20+
* {@link SystemMessageSections}.
2121
*
2222
* <h2>Static override example</h2>
2323
*
2424
* <pre>{@code
2525
* var config = new SystemMessageConfig().setMode(SystemMessageMode.CUSTOMIZE).setSections(Map.of(
26-
* SystemPromptSections.TONE,
26+
* SystemMessageSections.TONE,
2727
* new SectionOverride().setAction(SectionOverrideAction.REPLACE).setContent("Be concise and formal."),
28-
* SystemPromptSections.CODE_CHANGE_RULES, new SectionOverride().setAction(SectionOverrideAction.REMOVE)));
28+
* SystemMessageSections.CODE_CHANGE_RULES, new SectionOverride().setAction(SectionOverrideAction.REMOVE)));
2929
* }</pre>
3030
*
3131
* <h2>Transform callback example</h2>
3232
*
3333
* <pre>{@code
3434
* var config = new SystemMessageConfig().setMode(SystemMessageMode.CUSTOMIZE)
35-
* .setSections(Map.of(SystemPromptSections.IDENTITY, new SectionOverride().setTransform(
35+
* .setSections(Map.of(SystemMessageSections.IDENTITY, new SectionOverride().setTransform(
3636
* content -> CompletableFuture.completedFuture(content + "\nAlways end replies with DONE."))));
3737
* }</pre>
3838
*
3939
* @see SystemMessageConfig
4040
* @see SectionOverrideAction
41-
* @see SystemPromptSections
42-
* @since 1.2.0
41+
* @see SystemMessageSections
42+
* @since 1.0.0
4343
*/
4444
@JsonInclude(JsonInclude.Include.NON_NULL)
4545
public class SectionOverride {

java/src/main/java/com/github/copilot/rpc/SectionOverrideAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @see SectionOverride
1414
* @see SystemMessageConfig
15-
* @since 1.2.0
15+
* @since 1.0.0
1616
*/
1717
public enum SectionOverrideAction {
1818

java/src/main/java/com/github/copilot/rpc/SystemMessageConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
* <pre>{@code
3636
* var config = new SystemMessageConfig().setMode(SystemMessageMode.CUSTOMIZE)
3737
* .setSections(
38-
* Map.of(SystemPromptSections.TONE,
38+
* Map.of(SystemMessageSections.TONE,
3939
* new SectionOverride().setAction(SectionOverrideAction.REPLACE)
4040
* .setContent("Be concise and formal."),
41-
* SystemPromptSections.CODE_CHANGE_RULES,
41+
* SystemMessageSections.CODE_CHANGE_RULES,
4242
* new SectionOverride().setAction(SectionOverrideAction.REMOVE)))
4343
* .setContent("Additional instructions appended after all sections.");
4444
* }</pre>
4545
*
4646
* @see SessionConfig#setSystemMessage(SystemMessageConfig)
4747
* @see SystemMessageMode
4848
* @see SectionOverride
49-
* @see SystemPromptSections
49+
* @see SystemMessageSections
5050
* @since 1.0.0
5151
*/
5252
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -122,7 +122,7 @@ public Map<String, SectionOverride> getSections() {
122122
/**
123123
* Sets section-level overrides for {@link SystemMessageMode#CUSTOMIZE} mode.
124124
* <p>
125-
* Keys are section identifiers from {@link SystemPromptSections}. Each value
125+
* Keys are section identifiers from {@link SystemMessageSections}. Each value
126126
* describes how that section should be modified. Sections with a
127127
* {@link SectionOverride#getTransform() transform} callback are handled locally
128128
* by the SDK via a {@code systemMessage.transform} RPC call; the rest are sent
@@ -131,7 +131,7 @@ public Map<String, SectionOverride> getSections() {
131131
* @param sections
132132
* a map of section identifier to override operation
133133
* @return this config for method chaining
134-
* @since 1.2.0
134+
* @since 1.0.0
135135
*/
136136
public SystemMessageConfig setSections(Map<String, SectionOverride> sections) {
137137
this.sections = sections;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.rpc;
6+
7+
/**
8+
* Well-known system message section identifiers for use with
9+
* {@link SystemMessageMode#CUSTOMIZE} mode.
10+
* <p>
11+
* Each constant names a section of the default Copilot system message. Pass
12+
* these as keys in the {@code sections} map of {@link SystemMessageConfig} to
13+
* override individual sections.
14+
*
15+
* <h2>Example</h2>
16+
*
17+
* <pre>{@code
18+
* var config = new SystemMessageConfig().setMode(SystemMessageMode.CUSTOMIZE).setSections(Map.of(
19+
* SystemMessageSections.TONE,
20+
* new SectionOverride().setAction(SectionOverrideAction.REPLACE).setContent("Always be concise."),
21+
* SystemMessageSections.CODE_CHANGE_RULES, new SectionOverride().setAction(SectionOverrideAction.REMOVE)));
22+
* }</pre>
23+
*
24+
* @see SystemMessageConfig
25+
* @see SectionOverride
26+
* @since 1.0.2
27+
*/
28+
public abstract sealed class SystemMessageSections permits SystemPromptSections {
29+
30+
/** Agent identity preamble and mode statement. */
31+
public static final String IDENTITY = "identity";
32+
33+
/** Response style, conciseness rules, output formatting preferences. */
34+
public static final String TONE = "tone";
35+
36+
/** Tool usage patterns, parallel calling, batching guidelines. */
37+
public static final String TOOL_EFFICIENCY = "tool_efficiency";
38+
39+
/** CWD, OS, git root, directory listing, available tools. */
40+
public static final String ENVIRONMENT_CONTEXT = "environment_context";
41+
42+
/** Coding rules, linting/testing, ecosystem tools, style. */
43+
public static final String CODE_CHANGE_RULES = "code_change_rules";
44+
45+
/** Tips, behavioral best practices, behavioral guidelines. */
46+
public static final String GUIDELINES = "guidelines";
47+
48+
/** Environment limitations, prohibited actions, security policies. */
49+
public static final String SAFETY = "safety";
50+
51+
/** Per-tool usage instructions. */
52+
public static final String TOOL_INSTRUCTIONS = "tool_instructions";
53+
54+
/** Repository and organization custom instructions. */
55+
public static final String CUSTOM_INSTRUCTIONS = "custom_instructions";
56+
57+
/**
58+
* Runtime-provided context and instructions (e.g. system notifications,
59+
* memories, workspace context, mode-specific instructions, content-exclusion
60+
* policy).
61+
*
62+
* @since 1.3.0
63+
*/
64+
public static final String RUNTIME_INSTRUCTIONS = "runtime_instructions";
65+
66+
/**
67+
* End-of-prompt instructions: parallel tool calling, persistence, task
68+
* completion.
69+
*/
70+
public static final String LAST_INSTRUCTIONS = "last_instructions";
71+
72+
/** Package-private constructor for the sealed hierarchy. */
73+
SystemMessageSections() {
74+
}
75+
}

java/src/main/java/com/github/copilot/rpc/SystemPromptSections.java

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,19 @@
55
package com.github.copilot.rpc;
66

77
/**
8-
* Well-known system prompt section identifiers for use with
9-
* {@link SystemMessageMode#CUSTOMIZE} mode.
8+
* Deprecated: use {@link SystemMessageSections} instead.
109
* <p>
11-
* Each constant names a section of the default Copilot system prompt. Pass
12-
* these as keys in the {@code sections} map of {@link SystemMessageConfig} to
13-
* override individual sections.
10+
* This class is retained for backward compatibility. All constants are
11+
* inherited from {@link SystemMessageSections}.
1412
*
15-
* <h2>Example</h2>
16-
*
17-
* <pre>{@code
18-
* var config = new SystemMessageConfig().setMode(SystemMessageMode.CUSTOMIZE).setSections(Map.of(
19-
* SystemPromptSections.TONE,
20-
* new SectionOverride().setAction(SectionOverrideAction.REPLACE).setContent("Always be concise."),
21-
* SystemPromptSections.CODE_CHANGE_RULES, new SectionOverride().setAction(SectionOverrideAction.REMOVE)));
22-
* }</pre>
23-
*
24-
* @see SystemMessageConfig
25-
* @see SectionOverride
26-
* @since 1.2.0
13+
* @deprecated Use {@link SystemMessageSections} — this class will be removed in
14+
* a future major version.
15+
* @see SystemMessageSections
16+
* @since 1.0.2
2717
*/
28-
public final class SystemPromptSections {
29-
30-
/** Agent identity preamble and mode statement. */
31-
public static final String IDENTITY = "identity";
32-
33-
/** Response style, conciseness rules, output formatting preferences. */
34-
public static final String TONE = "tone";
35-
36-
/** Tool usage patterns, parallel calling, batching guidelines. */
37-
public static final String TOOL_EFFICIENCY = "tool_efficiency";
38-
39-
/** CWD, OS, git root, directory listing, available tools. */
40-
public static final String ENVIRONMENT_CONTEXT = "environment_context";
41-
42-
/** Coding rules, linting/testing, ecosystem tools, style. */
43-
public static final String CODE_CHANGE_RULES = "code_change_rules";
44-
45-
/** Tips, behavioral best practices, behavioral guidelines. */
46-
public static final String GUIDELINES = "guidelines";
47-
48-
/** Environment limitations, prohibited actions, security policies. */
49-
public static final String SAFETY = "safety";
50-
51-
/** Per-tool usage instructions. */
52-
public static final String TOOL_INSTRUCTIONS = "tool_instructions";
53-
54-
/** Repository and organization custom instructions. */
55-
public static final String CUSTOM_INSTRUCTIONS = "custom_instructions";
56-
57-
/**
58-
* Runtime-provided context and instructions (e.g. system notifications,
59-
* memories, workspace context, mode-specific instructions, content-exclusion
60-
* policy).
61-
*
62-
* @since 1.3.0
63-
*/
64-
public static final String RUNTIME_INSTRUCTIONS = "runtime_instructions";
65-
66-
/**
67-
* End-of-prompt instructions: parallel tool calling, persistence, task
68-
* completion.
69-
*/
70-
public static final String LAST_INSTRUCTIONS = "last_instructions";
18+
@Deprecated(since = "1.0.2", forRemoval = true)
19+
public final class SystemPromptSections extends SystemMessageSections {
7120

7221
private SystemPromptSections() {
73-
// utility class
7422
}
7523
}

0 commit comments

Comments
 (0)