Skip to content

Commit 5948641

Browse files
committed
Substantial changes to agent mechanism
1 parent 01a886f commit 5948641

File tree

210 files changed

+11086
-992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+11086
-992
lines changed

.beads/issues.jsonl

Lines changed: 26 additions & 1 deletion
Large diffs are not rendered by default.

AGENTS.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,29 @@ Each package in `packages/` may contain:
5151
- Use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format
5252
- Include a brief description of the change, its motivation, and any relevant issue references
5353
- Never mention CLAUDE in commit messages or code comments
54+
55+
## Landing the Plane (Session Completion)
56+
57+
**When ending a work session**, you MUST complete ALL steps below. Work is NOT complete until `git push` succeeds.
58+
59+
**MANDATORY WORKFLOW:**
60+
61+
1. **File issues for remaining work** - Create issues for anything that needs follow-up
62+
2. **Run quality gates** (if code changed) - Tests, linters, builds
63+
3. **Update issue status** - Close finished work, update in-progress items
64+
4. **PUSH TO REMOTE** - This is MANDATORY:
65+
```bash
66+
git pull --rebase
67+
bd sync
68+
git push
69+
git status # MUST show "up to date with origin"
70+
```
71+
5. **Clean up** - Clear stashes, prune remote branches
72+
6. **Verify** - All changes committed AND pushed
73+
7. **Hand off** - Provide context for next session
74+
75+
**CRITICAL RULES:**
76+
- Work is NOT complete until `git push` succeeds
77+
- NEVER stop before pushing - that leaves work stranded locally
78+
- NEVER say "ready to push when you are" - YOU must push
79+
- If push fails, resolve and retry until it succeeds

docs-build/http/1-overview.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ HttpClient
9494
└── withRequest() - Create pending request for execution
9595
└── pool() - Execute multiple requests concurrently
9696
└── withPool() - Create pending pool for deferred execution
97-
// @doctest id="0309"
97+
// @doctest id="cc10"
9898
```
9999

100100
### Middleware Layer
@@ -105,7 +105,7 @@ The middleware system allows for processing requests and responses through a cha
105105
Request -> Middleware 1 -> Middleware 2 -> ... -> Driver -> External API
106106
107107
Response <- Middleware 1 <- Middleware 2 <- ... <- Driver <- HTTP Response
108-
// @doctest id="55c0"
108+
// @doctest id="e0e6"
109109
```
110110

111111
Key components:
@@ -123,7 +123,7 @@ CanHandleHttpRequest (interface)
123123
├── SymfonyDriver
124124
├── LaravelDriver
125125
└── MockHttpDriver (for testing)
126-
// @doctest id="0c52"
126+
// @doctest id="90bd"
127127
```
128128

129129
### Adapter Layer
@@ -136,7 +136,7 @@ HttpResponse (interface)
136136
├── SymfonyHttpResponse
137137
├── LaravelHttpResponse
138138
└── MockHttpResponse
139-
// @doctest id="b411"
139+
// @doctest id="6066"
140140
```
141141

142142
## Supported HTTP Clients

docs-build/http/10-middleware.mdx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface HttpMiddleware
3434
{
3535
public function handle(HttpClientRequest $request, CanHandleHttpRequest $next): HttpResponse;
3636
}
37-
// @doctest id="54d3"
37+
// @doctest id="cb13"
3838
```
3939

4040
The `handle` method takes two parameters:
@@ -85,7 +85,7 @@ abstract class BaseMiddleware implements HttpMiddleware
8585
return $response;
8686
}
8787
}
88-
// @doctest id="f4e1"
88+
// @doctest id="98cf"
8989
```
9090

9191
By extending `BaseMiddleware`, you only need to override the methods relevant to your middleware's functionality, making the code more focused and maintainable.
@@ -120,7 +120,7 @@ $client->withMiddleware(
120120
new RetryMiddleware(),
121121
new TimeoutMiddleware()
122122
);
123-
// @doctest id="a28f"
123+
// @doctest id="dd2b"
124124
```
125125

126126
Named middleware are useful when you need to reference them later, for example, to remove or replace them.
@@ -132,7 +132,7 @@ You can remove middleware from the stack by name:
132132
```php
133133
// Remove a middleware by name
134134
$client->middleware()->remove('cache');
135-
// @doctest id="bb21"
135+
// @doctest id="9d07"
136136
```
137137

138138
### Replacing Middleware
@@ -142,7 +142,7 @@ You can replace a middleware with another one:
142142
```php
143143
// Replace a middleware with a new one
144144
$client->middleware()->replace('cache', new ImprovedCachingMiddleware());
145-
// @doctest id="4f1a"
145+
// @doctest id="9103"
146146
```
147147

148148
### Clearing Middleware
@@ -152,7 +152,7 @@ You can remove all middleware from the stack:
152152
```php
153153
// Clear all middleware
154154
$client->middleware()->clear();
155-
// @doctest id="9a14"
155+
// @doctest id="bbb5"
156156
```
157157

158158
### Checking Middleware
@@ -164,7 +164,7 @@ You can check if a middleware exists in the stack:
164164
if ($client->middleware()->has('rate-limit')) {
165165
// The 'rate-limit' middleware exists
166166
}
167-
// @doctest id="8c1b"
167+
// @doctest id="a83c"
168168
```
169169

170170
### Getting Middleware
@@ -177,7 +177,7 @@ $rateLimitMiddleware = $client->middleware()->get('rate-limit');
177177

178178
// Get a middleware by index
179179
$firstMiddleware = $client->middleware()->get(0);
180-
// @doctest id="6ca6"
180+
// @doctest id="f3c2"
181181
```
182182

183183
### Middleware Order
@@ -229,7 +229,7 @@ $request = new HttpRequest(
229229
// 6. RetryMiddleware processes the response (may retry on certain status codes)
230230
// 7. LoggingMiddleware processes the response (logs incoming response)
231231
$response = $client->withRequest($request)->get();
232-
// @doctest id="c048"
232+
// @doctest id="996c"
233233
```
234234

235235
## Built-in Middleware
@@ -248,7 +248,7 @@ $client->withMiddleware(new DebugMiddleware());
248248

249249
// Or use the convenience method
250250
$client->withDebugPreset('on');
251-
// @doctest id="33bc"
251+
// @doctest id="bd75"
252252
```
253253

254254
The debug middleware logs:
@@ -275,7 +275,7 @@ return [
275275
'responseStreamByLine' => true, // Dump stream as full lines or raw chunks
276276
],
277277
];
278-
// @doctest id="c2ed"
278+
// @doctest id="c182"
279279
```
280280

281281
### StreamByLine Middleware
@@ -287,7 +287,7 @@ use Cognesy\Http\Middleware\ServerSideEvents\StreamSSEsMiddleware;
287287

288288
// Add stream by line middleware
289289
$client->withMiddleware(new StreamSSEsMiddleware());
290-
// @doctest id="9a55"
290+
// @doctest id="b46d"
291291
```
292292

293293
You can customize how lines are processed by providing a parser function:
@@ -302,7 +302,7 @@ $lineParser = function (string $line) {
302302
};
303303

304304
$client->withMiddleware(new StreamByLineMiddleware($lineParser));
305-
// @doctest id="3097"
305+
// @doctest id="688f"
306306
```
307307

308308

@@ -318,7 +318,7 @@ $client->withMiddleware(
318318
new BufferResponseMiddleware(), // Buffer responses for reuse
319319
new DebugMiddleware() // Log requests and responses
320320
);
321-
// @doctest id="6a4e"
321+
// @doctest id="d637"
322322
```
323323

324324
#### API Client Setup
@@ -331,7 +331,7 @@ $client->withMiddleware(
331331
new RateLimitingMiddleware(maxRequests: 100), // Respect rate limits
332332
new LoggingMiddleware() // Log API interactions
333333
);
334-
// @doctest id="8d3a"
334+
// @doctest id="7dd5"
335335
```
336336

337337
#### Testing Setup
@@ -341,7 +341,7 @@ $client = new HttpClient();
341341
$client->withMiddleware(
342342
new RecordReplayMiddleware(RecordReplayMiddleware::MODE_REPLAY) // Replay recorded responses
343343
);
344-
// @doctest id="6d90"
344+
// @doctest id="30b6"
345345
```
346346

347347
#### Streaming Setup
@@ -352,7 +352,7 @@ $client->withMiddleware(
352352
new StreamByLineMiddleware(), // Process streaming responses line by line
353353
new BufferResponseMiddleware() // Buffer responses for reuse
354354
);
355-
// @doctest id="2780"
355+
// @doctest id="5355"
356356
```
357357

358358
By combining middleware components, you can create a highly customized HTTP client that handles complex requirements while keeping your application code clean and focused.

docs-build/http/11-processing-with-middleware.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ $client->withMiddleware(new class implements HttpMiddleware {
7070
return $response;
7171
}
7272
});
73-
// @doctest id="9417"
73+
// @doctest id="32bb"
7474
```
7575

7676
This approach is concise but less reusable than defining a named class.
@@ -131,7 +131,7 @@ Then add the middleware to your client:
131131
```php
132132
$client = new HttpClient();
133133
$client->withMiddleware(new JsonStreamMiddleware());
134-
// @doctest id="9f1c"
134+
// @doctest id="6dd4"
135135
```
136136

137137
### Response Decoration for Transforming Content
@@ -169,7 +169,7 @@ class XmlToJsonDecorator extends BaseResponseDecorator
169169
return $headers;
170170
}
171171
}
172-
// @doctest id="9a27"
172+
// @doctest id="5764"
173173
```
174174

175175
And the corresponding middleware:
@@ -199,7 +199,7 @@ class XmlToJsonMiddleware extends BaseMiddleware
199199
return new XmlToJsonDecorator($request, $response);
200200
}
201201
}
202-
// @doctest id="4eb6"
202+
// @doctest id="109f"
203203
```
204204

205205
## Advanced Middleware Examples
@@ -257,7 +257,7 @@ class AnalyticsMiddleware extends BaseMiddleware
257257
return $response;
258258
}
259259
}
260-
// @doctest id="1f1e"
260+
// @doctest id="4f26"
261261
```
262262

263263
### Circuit Breaker Middleware
@@ -347,7 +347,7 @@ class CircuitBreakerMiddleware extends BaseMiddleware
347347
}
348348
}
349349
}
350-
// @doctest id="0976"
350+
// @doctest id="90ec"
351351
```
352352

353353
### Conditional Middleware
@@ -387,7 +387,7 @@ class ConditionalMiddleware implements HttpMiddleware
387387
return $next->handle($request);
388388
}
389389
}
390-
// @doctest id="c2f7"
390+
// @doctest id="77f2"
391391
```
392392

393393
Usage example:
@@ -401,7 +401,7 @@ $conditionalCaching = new ConditionalMiddleware(
401401
);
402402

403403
$client->withMiddleware($conditionalCaching);
404-
// @doctest id="aabd"
404+
// @doctest id="816a"
405405
```
406406

407407
### Request ID Middleware
@@ -454,7 +454,7 @@ class RequestIdMiddleware extends BaseMiddleware
454454
return $response;
455455
}
456456
}
457-
// @doctest id="8d86"
457+
// @doctest id="3f48"
458458
```
459459

460460
### OpenTelemetry Tracing Middleware
@@ -537,7 +537,7 @@ class TracingMiddleware extends BaseMiddleware
537537
}
538538
}
539539
}
540-
// @doctest id="dabe"
540+
// @doctest id="12e8"
541541
```
542542

543543
### Customizing Middleware for LLM APIs
@@ -643,7 +643,7 @@ class LlmStreamingMiddleware extends BaseMiddleware
643643
};
644644
}
645645
}
646-
// @doctest id="84db"
646+
// @doctest id="e9b5"
647647
```
648648

649649
### Combining Multiple Middleware Components
@@ -687,7 +687,7 @@ $client->withMiddleware(
687687

688688
// Now the client is ready to use with a complete middleware pipeline
689689
$response = $client->withRequest($request)->get();
690-
// @doctest id="a5a9"
690+
// @doctest id="c34e"
691691
```
692692

693693
With this setup, requests and responses flow through the middleware in the following order:

0 commit comments

Comments
 (0)