Skip to content

Commit df0832c

Browse files
committed
feat: enhance documentation with detailed file attachment parameters and session shutdown methods
1 parent 25e4913 commit df0832c

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

src/site/markdown/advanced.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ var session = client.createSession(
110110

111111
## File Attachments
112112

113-
Include files as context for the AI to analyze.
113+
Include files as context for the AI to analyze. The `Attachment` record takes three parameters:
114+
115+
| Parameter | Type | Description |
116+
|-----------|------|-------------|
117+
| `type` | String | The attachment type — use `"file"` for filesystem files |
118+
| `path` | String | The absolute path to the file on disk |
119+
| `displayName` | String | A human-readable label shown to the AI (e.g., the filename or a description) |
114120

115121
```java
116122
session.send(new MessageOptions()
@@ -121,6 +127,18 @@ session.send(new MessageOptions()
121127
).get();
122128
```
123129

130+
You can attach multiple files in a single message:
131+
132+
```java
133+
session.send(new MessageOptions()
134+
.setPrompt("Compare these two implementations")
135+
.setAttachments(List.of(
136+
new Attachment("file", "/src/main/OldImpl.java", "Old Implementation"),
137+
new Attachment("file", "/src/main/NewImpl.java", "New Implementation")
138+
))
139+
).get();
140+
```
141+
124142
---
125143

126144
## Bring Your Own Key (BYOK)
@@ -454,6 +472,31 @@ client.start().get(); // Start manually
454472
client.stop().get(); // Stop manually
455473
```
456474

475+
### Graceful Stop vs Force Stop
476+
477+
The SDK provides two shutdown methods:
478+
479+
| Method | Behavior |
480+
|--------|----------|
481+
| `stop()` | Gracefully closes all open sessions, then shuts down the connection |
482+
| `forceStop()` | Immediately clears sessions and shuts down — no graceful session cleanup |
483+
484+
Use `stop()` for normal shutdown — it ensures each session is properly closed (flushing pending operations) before terminating the connection:
485+
486+
```java
487+
// Graceful: closes all sessions, then disconnects
488+
client.stop().get();
489+
```
490+
491+
Use `forceStop()` when you need to terminate immediately, such as during error recovery or when the server is unresponsive:
492+
493+
```java
494+
// Immediate: skips session cleanup, kills connection
495+
client.forceStop().get();
496+
```
497+
498+
> **Tip:** In `try-with-resources` blocks, `close()` delegates to `stop()`, so graceful cleanup happens automatically.
499+
457500
---
458501

459502
## Session Lifecycle Events

src/site/markdown/documentation.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,33 @@ The four states are:
425425
| `CONNECTED` | Client is connected and ready |
426426
| `ERROR` | Connection failed (check logs for details) |
427427

428+
### State Transitions
429+
430+
```
431+
start()
432+
DISCONNECTED ──────────► CONNECTING
433+
434+
┌──────────┼──────────┐
435+
│ success │ │ failure
436+
▼ │ ▼
437+
CONNECTED │ ERROR
438+
│ │
439+
stop() / │ │
440+
forceStop() │ │
441+
▼ │
442+
DISCONNECTED ◄───┘
443+
444+
│ start() (retry)
445+
446+
CONNECTING
447+
```
448+
449+
- **DISCONNECTED → CONNECTING:** `start()` was called
450+
- **CONNECTING → CONNECTED:** Server connection and protocol handshake succeeded
451+
- **CONNECTING → ERROR:** Connection or protocol verification failed
452+
- **CONNECTED → DISCONNECTED:** `stop()` or `forceStop()` was called, or `close()` via try-with-resources
453+
- **DISCONNECTED → CONNECTING:** `start()` can be called again to retry
454+
428455
### Server Status
429456

430457
Get CLI version and protocol information:

src/site/markdown/setup.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,39 @@ Complete list of `CopilotClientOptions` settings:
350350
| `environment` | Map | Environment variables | inherited |
351351
| `cwd` | String | Working directory | current dir |
352352

353+
### Extra CLI Arguments
354+
355+
Pass additional command-line arguments to the CLI process:
356+
357+
```java
358+
var options = new CopilotClientOptions()
359+
.setCliArgs(new String[]{"--verbose", "--no-telemetry"});
360+
361+
try (var client = new CopilotClient(options)) {
362+
client.start().get();
363+
// CLI process receives the extra flags
364+
}
365+
```
366+
367+
### Custom Environment Variables
368+
369+
Set environment variables for the CLI process (merged with the inherited system environment):
370+
371+
```java
372+
var options = new CopilotClientOptions()
373+
.setEnvironment(Map.of(
374+
"HTTPS_PROXY", "http://proxy.example.com:8080",
375+
"NO_PROXY", "localhost,127.0.0.1"
376+
));
377+
378+
try (var client = new CopilotClient(options)) {
379+
client.start().get();
380+
// CLI process uses the proxy settings
381+
}
382+
```
383+
384+
This is useful for configuring proxy servers, custom CA certificates, or any environment-specific settings the CLI needs.
385+
353386
## Best Practices
354387

355388
### Development

0 commit comments

Comments
 (0)