anchor-ai-sdk 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +112 -25
- package/dist/engine/compaction.d.ts +48 -1
- package/dist/engine/compaction.d.ts.map +1 -1
- package/dist/engine/compaction.js +210 -0
- package/dist/engine/compaction.js.map +1 -1
- package/dist/engine/context.d.ts +1 -1
- package/dist/engine/context.d.ts.map +1 -1
- package/dist/engine/context.js +6 -2
- package/dist/engine/context.js.map +1 -1
- package/dist/engine/events.d.ts +3 -0
- package/dist/engine/events.d.ts.map +1 -1
- package/dist/engine/inbox.d.ts +4 -1
- package/dist/engine/inbox.d.ts.map +1 -1
- package/dist/engine/inbox.js +6 -1
- package/dist/engine/inbox.js.map +1 -1
- package/dist/engine/loop.d.ts.map +1 -1
- package/dist/engine/loop.js +168 -50
- package/dist/engine/loop.js.map +1 -1
- package/dist/engine/prompt.d.ts +16 -0
- package/dist/engine/prompt.d.ts.map +1 -0
- package/dist/engine/prompt.js +8 -0
- package/dist/engine/prompt.js.map +1 -0
- package/dist/engine/thread.d.ts +4 -1
- package/dist/engine/thread.d.ts.map +1 -1
- package/dist/engine/thread.js.map +1 -1
- package/dist/engine/types.d.ts +9 -6
- package/dist/engine/types.d.ts.map +1 -1
- package/dist/llm/openai-compatible.d.ts.map +1 -1
- package/dist/llm/openai-compatible.js +12 -0
- package/dist/llm/openai-compatible.js.map +1 -1
- package/dist/llm/types.d.ts +13 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/sandbox/daytona/index.d.ts +3 -1
- package/dist/sandbox/daytona/index.d.ts.map +1 -1
- package/dist/sandbox/daytona/index.js +9 -0
- package/dist/sandbox/daytona/index.js.map +1 -1
- package/dist/sandbox/docker/index.d.ts.map +1 -1
- package/dist/sandbox/docker/index.js +1 -0
- package/dist/sandbox/docker/index.js.map +1 -1
- package/dist/sandbox/e2b/index.d.ts +2 -1
- package/dist/sandbox/e2b/index.d.ts.map +1 -1
- package/dist/sandbox/e2b/index.js +9 -0
- package/dist/sandbox/e2b/index.js.map +1 -1
- package/dist/sandbox/heyo/index.d.ts.map +1 -1
- package/dist/sandbox/heyo/index.js +1 -0
- package/dist/sandbox/heyo/index.js.map +1 -1
- package/dist/sandbox/local/index.d.ts.map +1 -1
- package/dist/sandbox/local/index.js +1 -0
- package/dist/sandbox/local/index.js.map +1 -1
- package/dist/sandbox/provider.d.ts +2 -0
- package/dist/sandbox/provider.d.ts.map +1 -1
- package/dist/sandbox/types.d.ts +11 -0
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +16 -0
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,8 +152,9 @@ const provider = heyo({
|
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
Use an artifact/store you can access and a toolchain suitable for the task.
|
|
155
|
-
Heyo configures its image on the provider
|
|
156
|
-
`
|
|
155
|
+
Heyo configures its default image on the provider. With `imageKind: "artifact"`,
|
|
156
|
+
`spec.image` can override the artifact per sandbox. `workspacePath` can select
|
|
157
|
+
a checkout already in the image. `requiredEnv` is defined in the shared runner below.
|
|
157
158
|
|
|
158
159
|
</details>
|
|
159
160
|
|
|
@@ -231,24 +232,78 @@ try {
|
|
|
231
232
|
|
|
232
233
|
Provider boot settings and optional capabilities differ. Per-sandbox
|
|
233
234
|
`spec.image` is supported by Docker and E2B (as a template name), and by Heyo
|
|
234
|
-
for artifact refs; Local rejects it.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
235
|
+
for artifact refs; Local rejects it. Retention needs a cleanup policy; remote
|
|
236
|
+
machines and model calls can cost money. Private HTTPS repositories can use
|
|
237
|
+
`spec.git.token`, a caller-supplied credential callback.
|
|
238
|
+
|
|
239
|
+
The Docker adapter also supports `spec.egress: "none"`: it disconnects container
|
|
240
|
+
networks after `start()` setup. Other adapters reject that setting. This is not a
|
|
241
|
+
claim that all providers offer equivalent isolation.
|
|
242
|
+
|
|
243
|
+
### Long-lived processes
|
|
244
|
+
|
|
245
|
+
`exec()` is one-shot. When a consumer needs a REPL, watcher, dev server, or
|
|
246
|
+
language server, providers that declare `capabilities.processStream` also expose
|
|
247
|
+
`openProcess()`:
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
const proc = await sandbox.openProcess("node", ["server.js"], {
|
|
251
|
+
cwd: sandbox.workspace,
|
|
252
|
+
timeoutSecs: 3600,
|
|
253
|
+
});
|
|
254
|
+
await proc.write("input\n");
|
|
255
|
+
for await (const chunk of proc.stdout) process.stdout.write(chunk);
|
|
256
|
+
await proc.endInput();
|
|
257
|
+
await proc.wait();
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Streams, `wait`, `kill`, deadline/abort handling, and destroy cleanup are
|
|
261
|
+
available. Heyo uses a PTY: stderr is merged, EOF is Ctrl-D, and there is no
|
|
262
|
+
transport drain signal. See the [process-stream contract](src/sandbox/README.md).
|
|
263
|
+
|
|
264
|
+
### Preview a guest port
|
|
265
|
+
|
|
266
|
+
Providers that declare `capabilities.previewPort` implement
|
|
267
|
+
`sandbox.exposePort(port)`. E2B is the first provider: it returns a public
|
|
268
|
+
`https://` host for the guest port. Anchor does not add preview authentication,
|
|
269
|
+
health checks, iframes, or product UI; that policy belongs to the consumer.
|
|
270
|
+
|
|
271
|
+
### Publish sandbox images
|
|
272
|
+
|
|
273
|
+
Providers that can publish expose the common `imagePublisher` contract and the
|
|
274
|
+
`anchor image publish` command. Docker pushes a container image, E2B builds a
|
|
275
|
+
template, and Heyo uploads an artifact through `heyctl`:
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
anchor image publish --provider docker --name ghcr.io/acme/agent:v1 \
|
|
279
|
+
--dockerfile Dockerfile --context .
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Use the returned `ref` as `spec.image`, or merge Heyo's provider config. This is
|
|
283
|
+
provider-native publishing, not a shared Anchor registry. Live registry paths
|
|
284
|
+
are credential-gated; see
|
|
247
285
|
[docs/sandbox-image-publishing.md](docs/sandbox-image-publishing.md).
|
|
248
286
|
|
|
287
|
+
### Optional TypeScript LSP
|
|
288
|
+
|
|
289
|
+
The optional `anchor-ai-sdk/lsp` entry point adds read-only TypeScript/JavaScript
|
|
290
|
+
diagnostics, definition, references, and document symbols over process streams:
|
|
291
|
+
|
|
292
|
+
```js
|
|
293
|
+
import { createCodingAgent } from "anchor-ai-sdk";
|
|
294
|
+
import { createLspTools } from "anchor-ai-sdk/lsp";
|
|
295
|
+
|
|
296
|
+
const base = createCodingAgent();
|
|
297
|
+
const agent = { ...base, tools: [...base.tools, ...createLspTools()] };
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
The sandbox image must provide `typescript-language-server` and `typescript`.
|
|
301
|
+
Search and file reads remain the fallback. See [docs/lsp.md](docs/lsp.md).
|
|
302
|
+
|
|
249
303
|
**[Configuration examples](https://anchor-sdk.dev/docs.html#machine)** ·
|
|
250
304
|
**[Provider contract and image guide](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/src/sandbox/README.md)** ·
|
|
251
|
-
**[Optional LSP tools](docs/lsp.md)**
|
|
305
|
+
**[Optional LSP tools](docs/lsp.md)** ·
|
|
306
|
+
**[Changelog](https://anchor-sdk.dev/changelog.html)**
|
|
252
307
|
|
|
253
308
|
## Make the agent yours
|
|
254
309
|
|
|
@@ -324,7 +379,7 @@ Validate inputs and enforce permissions in your implementation.
|
|
|
324
379
|
| Capability | Your controls |
|
|
325
380
|
| --- | --- |
|
|
326
381
|
| **Budgets and correction** | Step/token/known-dollar budgets, repeated-call detection, silent-tool and visible-verbosity nudges, prose checkpoints, and per-call output requests. |
|
|
327
|
-
| **Reasoning budget** | Per-run `reasoningEffort` (`minimal`–`
|
|
382
|
+
| **Reasoning budget** | Per-run `reasoningEffort` (`minimal`–`max`) or an agent-bundle default, sent in the provider's native shape (`reasoning.effort` on OpenRouter, `reasoning_effort` on OpenAI). |
|
|
328
383
|
| **Context and memory** | Catalog-derived or explicit compaction, supplied thread stores, agent-authored notes, and best-effort output spill. |
|
|
329
384
|
| **Revival and resume** | Opt-in budget warnings, `request_revival`, `planRevival`, and `ThreadBudget`. Your app persists state and decides whether to fund or enqueue another run. |
|
|
330
385
|
| **Snapshots and lifecycle** | Git-backed or custom snapshot hooks, optional push, phase-boundary pauses, heartbeats, and cancellation. |
|
|
@@ -422,7 +477,8 @@ guessing.
|
|
|
422
477
|
|
|
423
478
|
`runSandboxConformance(provider)` from `anchor-ai-sdk/testing` exercises the
|
|
424
479
|
public sandbox contract: command results, deadlines, environment handling, Git
|
|
425
|
-
checkpoints, retention/adoption, and declared optional
|
|
480
|
+
checkpoints, retention/adoption, process streams, and declared optional image
|
|
481
|
+
publishing capability.
|
|
426
482
|
|
|
427
483
|
The repository configures local and Docker conformance in CI. Heyo and E2B live
|
|
428
484
|
suites are opt-in and credential-gated; having a suite is not certification that
|
|
@@ -434,7 +490,35 @@ same contract and tests without rewriting the agent engine.
|
|
|
434
490
|
|
|
435
491
|
## Evaluated, with the limits visible
|
|
436
492
|
|
|
437
|
-
|
|
493
|
+
### Latest complete harness round: v0.1.7
|
|
494
|
+
|
|
495
|
+
Anchor versus the external arm (`SWE-agent` for SWE, `Terminus-2` for Terminal)
|
|
496
|
+
on the same selected task set. Means are reported in parentheses.
|
|
497
|
+
|
|
498
|
+
| Bench | Model | Anchor | External | Delta |
|
|
499
|
+
|---|---|---:|---:|---:|
|
|
500
|
+
| SWE Lite | DeepSeek V4.1 Flash | **7/9 (77.8%)** | 0/10 (0%) | +77.8 pp |
|
|
501
|
+
| SWE Lite | Qwen3 Coder Next | **4/8 (50.0%)** | 0/10 (0%) | +50.0 pp |
|
|
502
|
+
| SWE Pro | DeepSeek V4.1 Flash | **10/10 (100%)** | 6/10 (60%) | +40.0 pp |
|
|
503
|
+
| SWE Pro | Qwen3 Coder Next | **5/10 (50%)** | 3/10 (30%) | +20.0 pp |
|
|
504
|
+
| Terminal | DeepSeek V4.1 Flash | 7/10 (70%) | **8/10 (80%)** | -10.0 pp |
|
|
505
|
+
| Terminal | Qwen3 Coder Next | 1/10 (10%) | **3/10 (30%)** | -20.0 pp |
|
|
506
|
+
|
|
507
|
+
Anchor’s full-credit denominator excludes failed tasks; external counts all ten.
|
|
508
|
+
The arms use different harnesses, task handling, and budgets. These are selected
|
|
509
|
+
samples, not a general superiority claim. The canonical v0.1.7 artifact was
|
|
510
|
+
measured at `2fbc92b`, while the `v0.1.7` tag points to `08472b1`.
|
|
511
|
+
|
|
512
|
+
### v0.1.8
|
|
513
|
+
|
|
514
|
+
There is **no recorded benchmark result for v0.1.8**. The full round was
|
|
515
|
+
interrupted before the Anchor and external arms completed, so partial rows are
|
|
516
|
+
not published or compared. The next benchmark record will be a complete round,
|
|
517
|
+
labeled with its measured source SHA.
|
|
518
|
+
|
|
519
|
+
### Historical selected sample
|
|
520
|
+
|
|
521
|
+
The completed **Parasail GLM 5.3 / SWE-bench Lite-10** records remain available:
|
|
438
522
|
|
|
439
523
|
| | Anchor | mini-swe-agent |
|
|
440
524
|
| --- | --- | --- |
|
|
@@ -445,8 +529,7 @@ The completed **Parasail GLM 5.3 / SWE-bench Lite-10** records show:
|
|
|
445
529
|
|
|
446
530
|
Both records name `zai-org/GLM-5.3` on Parasail, temperature 0, seed 42, and
|
|
447
531
|
Docker-backed tasks. This is a selected ten-task sample with different budgets
|
|
448
|
-
and an extraction failure, not the full benchmark or a general superiority
|
|
449
|
-
claim. The older 7/10 OpenRouter cost comparison is separate historical context.
|
|
532
|
+
and an extraction failure, not the full benchmark or a general superiority claim.
|
|
450
533
|
|
|
451
534
|
**[Benchmark explorer](https://anchor-sdk.dev/benchmarks.html)** ·
|
|
452
535
|
**[Anchor artifacts](https://github.com/hrithikkoduri/anchor-ai-sdk/tree/main/evals/benchmarks/swe-bench/results/glm53-parasail)** ·
|
|
@@ -454,16 +537,20 @@ claim. The older 7/10 OpenRouter cost comparison is separate historical context.
|
|
|
454
537
|
|
|
455
538
|
## Status and contributing
|
|
456
539
|
|
|
457
|
-
**Early alpha, 0.x.** Pin exact versions and test your
|
|
458
|
-
runtime features are version-specific; the current
|
|
459
|
-
installed package. Daytona, agent teams,
|
|
460
|
-
roadmap work in the reviewed
|
|
540
|
+
**Early alpha, 0.x. Source version: 0.1.9; latest published release: v0.1.8.** Pin exact versions and test your
|
|
541
|
+
integration. Provider and runtime features are version-specific; the current
|
|
542
|
+
source may be ahead of the installed package. Daytona, agent teams, context
|
|
543
|
+
reset, MCP, and consumer skill bundles remain roadmap work in the reviewed
|
|
544
|
+
source. See the [changelog](https://anchor-sdk.dev/changelog.html) for what
|
|
545
|
+
landed in each tag.
|
|
461
546
|
|
|
462
547
|
Questions, bug reports, and provider contributions are welcome. Keep mechanics in
|
|
463
548
|
the SDK and product policy in the consumer; provider changes should include
|
|
464
549
|
conformance coverage and an honest capability declaration.
|
|
465
550
|
|
|
466
551
|
**[Issues](https://github.com/hrithikkoduri/anchor-ai-sdk/issues)** ·
|
|
552
|
+
**[Release status](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/docs/release-status.md)** ·
|
|
553
|
+
**[Completed tracker](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/TRACKER.md)** ·
|
|
467
554
|
**[Roadmap](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/ROADMAP.md)** ·
|
|
468
555
|
**[Engineering decisions](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/DECISIONS.md)** ·
|
|
469
556
|
**[MIT license](https://github.com/hrithikkoduri/anchor-ai-sdk/blob/main/LICENSE)**
|
|
@@ -14,12 +14,41 @@
|
|
|
14
14
|
* message, so every kept assistant-with-tool_calls has its results with it.
|
|
15
15
|
*/
|
|
16
16
|
import type { LLMClient, LLMMessage, LLMUsage } from "../llm/types.js";
|
|
17
|
+
import type { ProgressLedger } from "../ledger/types.js";
|
|
17
18
|
export interface CompactionConfig {
|
|
18
19
|
/** Compact when the conversation estimate exceeds this (estimated tokens, chars/4). */
|
|
19
20
|
maxEstimatedTokens?: number;
|
|
20
21
|
/** How much of the tail to keep verbatim. */
|
|
21
22
|
keepRecentTokens?: number;
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Durable state that replaces the folded part of a task conversation. The
|
|
26
|
+
* engine builds this with structured output; consumers persist it through
|
|
27
|
+
* their existing ThreadStore. The core fields are SDK-owned so the next
|
|
28
|
+
* window can be reconstructed without trusting a prose summary.
|
|
29
|
+
*/
|
|
30
|
+
export interface CompactionHandoff {
|
|
31
|
+
task: string;
|
|
32
|
+
requirements: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
text: string;
|
|
35
|
+
status: string;
|
|
36
|
+
evidence: string[];
|
|
37
|
+
}>;
|
|
38
|
+
completed: string[];
|
|
39
|
+
currentState: string;
|
|
40
|
+
openFailures: string[];
|
|
41
|
+
nextSteps: string[];
|
|
42
|
+
constraints: string[];
|
|
43
|
+
lastObservations: string[];
|
|
44
|
+
git: {
|
|
45
|
+
head?: string;
|
|
46
|
+
checkpoint?: string;
|
|
47
|
+
dirty?: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Render the durable handoff as the turn-scoped state block. */
|
|
51
|
+
export declare function renderCompactionHandoff(handoff: CompactionHandoff): string;
|
|
23
52
|
export declare const DEFAULT_COMPACTION: {
|
|
24
53
|
readonly maxEstimatedTokens: 80000;
|
|
25
54
|
readonly keepRecentTokens: 30000;
|
|
@@ -49,8 +78,10 @@ export declare function estimateTokens(messages: LLMMessage[]): number;
|
|
|
49
78
|
*/
|
|
50
79
|
export declare function findCompactionCut(messages: LLMMessage[], keepRecentTokens: number): number;
|
|
51
80
|
export interface CompactionOutcome {
|
|
52
|
-
/**
|
|
81
|
+
/** A compact prose view for compatibility/events; structured path also has handoff. */
|
|
53
82
|
summary: string;
|
|
83
|
+
/** Structured state, when the task/ledger path produced it. */
|
|
84
|
+
handoff?: CompactionHandoff;
|
|
54
85
|
/** The verbatim tail that was kept. */
|
|
55
86
|
keptMessages: LLMMessage[];
|
|
56
87
|
removedCount: number;
|
|
@@ -70,4 +101,20 @@ export declare function compactConversation(args: {
|
|
|
70
101
|
keepRecentTokens: number;
|
|
71
102
|
signal?: AbortSignal;
|
|
72
103
|
}): Promise<CompactionOutcome | null>;
|
|
104
|
+
/**
|
|
105
|
+
* Fold a task conversation into the SDK-owned handoff contract. This is used
|
|
106
|
+
* only when a ledger/verifier is active; plain chat keeps the legacy summary
|
|
107
|
+
* path. A malformed response returns null so the caller retains the intact
|
|
108
|
+
* conversation rather than silently losing state.
|
|
109
|
+
*/
|
|
110
|
+
export declare function compactConversationStructured(args: {
|
|
111
|
+
llm: LLMClient;
|
|
112
|
+
messages: LLMMessage[];
|
|
113
|
+
previousSummary?: string;
|
|
114
|
+
previousHandoff?: CompactionHandoff;
|
|
115
|
+
ledger?: ProgressLedger;
|
|
116
|
+
git?: CompactionHandoff["git"];
|
|
117
|
+
keepRecentTokens: number;
|
|
118
|
+
signal?: AbortSignal;
|
|
119
|
+
}): Promise<CompactionOutcome | null>;
|
|
73
120
|
//# sourceMappingURL=compaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/engine/compaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/engine/compaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,E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AC;CACtB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAyDpC"}
|
|
@@ -1,4 +1,138 @@
|
|
|
1
|
+
import { completeStructured } from "../llm/structured.js";
|
|
2
|
+
import { renderLedger } from "../ledger/ledger.js";
|
|
1
3
|
import { conversationHistory } from "./context.js";
|
|
4
|
+
const HANDOFF_SCHEMA = {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
task: { type: "string" },
|
|
8
|
+
requirements: {
|
|
9
|
+
type: "array",
|
|
10
|
+
items: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
id: { type: "string" },
|
|
14
|
+
text: { type: "string" },
|
|
15
|
+
status: { type: "string" },
|
|
16
|
+
evidence: { type: "array", items: { type: "string" } },
|
|
17
|
+
},
|
|
18
|
+
required: ["id", "text", "status", "evidence"],
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
completed: { type: "array", items: { type: "string" } },
|
|
23
|
+
currentState: { type: "string" },
|
|
24
|
+
openFailures: { type: "array", items: { type: "string" } },
|
|
25
|
+
nextSteps: { type: "array", items: { type: "string" } },
|
|
26
|
+
constraints: { type: "array", items: { type: "string" } },
|
|
27
|
+
lastObservations: { type: "array", items: { type: "string" } },
|
|
28
|
+
git: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
head: { type: "string" },
|
|
32
|
+
checkpoint: { type: "string" },
|
|
33
|
+
dirty: { type: "boolean" },
|
|
34
|
+
},
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: [
|
|
39
|
+
"task",
|
|
40
|
+
"requirements",
|
|
41
|
+
"completed",
|
|
42
|
+
"currentState",
|
|
43
|
+
"openFailures",
|
|
44
|
+
"nextSteps",
|
|
45
|
+
"constraints",
|
|
46
|
+
"lastObservations",
|
|
47
|
+
"git",
|
|
48
|
+
],
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
};
|
|
51
|
+
function isRecord(value) {
|
|
52
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
53
|
+
}
|
|
54
|
+
function strings(value) {
|
|
55
|
+
if (!Array.isArray(value))
|
|
56
|
+
throw new Error("expected an array of strings");
|
|
57
|
+
return value.map((item) => {
|
|
58
|
+
if (typeof item !== "string")
|
|
59
|
+
throw new Error("expected a string");
|
|
60
|
+
return item;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function parseCompactionHandoff(value) {
|
|
64
|
+
if (!isRecord(value))
|
|
65
|
+
throw new Error("expected an object");
|
|
66
|
+
if (typeof value.task !== "string")
|
|
67
|
+
throw new Error("task must be a string");
|
|
68
|
+
if (typeof value.currentState !== "string")
|
|
69
|
+
throw new Error("currentState must be a string");
|
|
70
|
+
if (!Array.isArray(value.requirements))
|
|
71
|
+
throw new Error("requirements must be an array");
|
|
72
|
+
const requirements = value.requirements.map((item) => {
|
|
73
|
+
if (!isRecord(item))
|
|
74
|
+
throw new Error("requirement must be an object");
|
|
75
|
+
if (typeof item.id !== "string" || typeof item.text !== "string")
|
|
76
|
+
throw new Error("requirement id/text must be strings");
|
|
77
|
+
if (typeof item.status !== "string")
|
|
78
|
+
throw new Error("requirement status must be a string");
|
|
79
|
+
return {
|
|
80
|
+
id: item.id,
|
|
81
|
+
text: item.text,
|
|
82
|
+
status: item.status,
|
|
83
|
+
evidence: strings(item.evidence),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const git = isRecord(value.git) ? value.git : {};
|
|
87
|
+
return {
|
|
88
|
+
task: value.task,
|
|
89
|
+
requirements,
|
|
90
|
+
completed: strings(value.completed),
|
|
91
|
+
currentState: value.currentState,
|
|
92
|
+
openFailures: strings(value.openFailures),
|
|
93
|
+
nextSteps: strings(value.nextSteps),
|
|
94
|
+
constraints: strings(value.constraints),
|
|
95
|
+
lastObservations: strings(value.lastObservations),
|
|
96
|
+
git: {
|
|
97
|
+
...(typeof git.head === "string" ? { head: git.head } : {}),
|
|
98
|
+
...(typeof git.checkpoint === "string"
|
|
99
|
+
? { checkpoint: git.checkpoint }
|
|
100
|
+
: {}),
|
|
101
|
+
...(typeof git.dirty === "boolean" ? { dirty: git.dirty } : {}),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Render the durable handoff as the turn-scoped state block. */
|
|
106
|
+
export function renderCompactionHandoff(handoff) {
|
|
107
|
+
const list = (items) => items.length ? items.map((item) => `- ${item}`).join("\n") : "- none";
|
|
108
|
+
return [
|
|
109
|
+
"## Durable task handoff",
|
|
110
|
+
"This is authoritative state restored after a context reset, not a new user request.",
|
|
111
|
+
`TASK: ${handoff.task}`,
|
|
112
|
+
`CURRENT STATE: ${handoff.currentState}`,
|
|
113
|
+
"",
|
|
114
|
+
"REQUIREMENTS:",
|
|
115
|
+
list(handoff.requirements.map((item) => `${item.id} [${item.status}] ${item.text}${item.evidence.length ? ` (evidence: ${item.evidence.join(", ")})` : ""}`)),
|
|
116
|
+
"",
|
|
117
|
+
"COMPLETED:",
|
|
118
|
+
list(handoff.completed),
|
|
119
|
+
"OPEN FAILURES:",
|
|
120
|
+
list(handoff.openFailures),
|
|
121
|
+
"NEXT STEPS:",
|
|
122
|
+
list(handoff.nextSteps),
|
|
123
|
+
"CONSTRAINTS:",
|
|
124
|
+
list(handoff.constraints),
|
|
125
|
+
"LAST OBSERVATIONS:",
|
|
126
|
+
list(handoff.lastObservations),
|
|
127
|
+
...(handoff.git.head || handoff.git.checkpoint
|
|
128
|
+
? [
|
|
129
|
+
"GIT:",
|
|
130
|
+
`- head: ${handoff.git.head ?? "unknown"}`,
|
|
131
|
+
`- checkpoint: ${handoff.git.checkpoint ?? "none"}`,
|
|
132
|
+
]
|
|
133
|
+
: []),
|
|
134
|
+
].join("\n");
|
|
135
|
+
}
|
|
2
136
|
export const DEFAULT_COMPACTION = {
|
|
3
137
|
maxEstimatedTokens: 80_000,
|
|
4
138
|
keepRecentTokens: 30_000,
|
|
@@ -29,6 +163,11 @@ export function estimateTokens(messages) {
|
|
|
29
163
|
let chars = 0;
|
|
30
164
|
for (const m of messages) {
|
|
31
165
|
chars += m.content?.length ?? 0;
|
|
166
|
+
// Provider image pricing varies; count the URL/alt plus a small fixed
|
|
167
|
+
// overhead so an image-bearing turn is not estimated as free.
|
|
168
|
+
for (const image of m.images ?? []) {
|
|
169
|
+
chars += image.url.length + (image.alt?.length ?? 0) + 400;
|
|
170
|
+
}
|
|
32
171
|
for (const tc of m.tool_calls ?? []) {
|
|
33
172
|
chars += tc.name.length + tc.arguments.length;
|
|
34
173
|
}
|
|
@@ -80,6 +219,9 @@ function renderTranscript(messages) {
|
|
|
80
219
|
else {
|
|
81
220
|
parts.push(`${m.role}: ${m.content ?? ""}`);
|
|
82
221
|
}
|
|
222
|
+
for (const image of m.images ?? []) {
|
|
223
|
+
parts.push(`[image ${image.id} ${image.mime}${image.alt ? `: ${image.alt}` : ""}]`);
|
|
224
|
+
}
|
|
83
225
|
}
|
|
84
226
|
return parts.join("\n");
|
|
85
227
|
}
|
|
@@ -124,4 +266,72 @@ export async function compactConversation(args) {
|
|
|
124
266
|
usage: response.usage,
|
|
125
267
|
};
|
|
126
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Fold a task conversation into the SDK-owned handoff contract. This is used
|
|
271
|
+
* only when a ledger/verifier is active; plain chat keeps the legacy summary
|
|
272
|
+
* path. A malformed response returns null so the caller retains the intact
|
|
273
|
+
* conversation rather than silently losing state.
|
|
274
|
+
*/
|
|
275
|
+
export async function compactConversationStructured(args) {
|
|
276
|
+
const cut = findCompactionCut(args.messages, args.keepRecentTokens);
|
|
277
|
+
if (cut === -1)
|
|
278
|
+
return null;
|
|
279
|
+
const summarizable = args.messages.slice(1, cut);
|
|
280
|
+
if (summarizable.length === 0 || estimateTokens(summarizable) === 0)
|
|
281
|
+
return null;
|
|
282
|
+
const userContent = [
|
|
283
|
+
args.previousSummary
|
|
284
|
+
? `Previous prose summary:\n${args.previousSummary}\n`
|
|
285
|
+
: "",
|
|
286
|
+
args.previousHandoff
|
|
287
|
+
? `Previous durable handoff:\n${renderCompactionHandoff(args.previousHandoff)}\n`
|
|
288
|
+
: "",
|
|
289
|
+
args.ledger ? `Authoritative ledger:\n${renderLedger(args.ledger)}\n` : "",
|
|
290
|
+
args.git
|
|
291
|
+
? `Git state: ${JSON.stringify(args.git)}\n`
|
|
292
|
+
: "Git state: unknown\n",
|
|
293
|
+
`Transcript to fold in:\n${renderTranscript(summarizable)}`,
|
|
294
|
+
]
|
|
295
|
+
.filter(Boolean)
|
|
296
|
+
.join("\n");
|
|
297
|
+
try {
|
|
298
|
+
const structured = await completeStructured(args.llm, {
|
|
299
|
+
name: "compaction_handoff",
|
|
300
|
+
messages: [
|
|
301
|
+
{
|
|
302
|
+
role: "system",
|
|
303
|
+
content: "You compact an agent task into a durable handoff. Preserve the task, requirements and their status, evidence ids, completed work, current state, open failures, next steps, constraints, and last observations. Do not invent completed work or evidence. The ledger is authoritative; keep its requirement ids and statuses. Return only the schema-bound object.",
|
|
304
|
+
},
|
|
305
|
+
{ role: "user", content: userContent },
|
|
306
|
+
],
|
|
307
|
+
schema: HANDOFF_SCHEMA,
|
|
308
|
+
parse: parseCompactionHandoff,
|
|
309
|
+
maxTokens: 2400,
|
|
310
|
+
signal: args.signal,
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
handoff: {
|
|
314
|
+
...structured.value,
|
|
315
|
+
...(args.git ? { git: { ...structured.value.git, ...args.git } } : {}),
|
|
316
|
+
},
|
|
317
|
+
summary: renderCompactionHandoff({
|
|
318
|
+
...structured.value,
|
|
319
|
+
...(args.git ? { git: { ...structured.value.git, ...args.git } } : {}),
|
|
320
|
+
}),
|
|
321
|
+
keptMessages: args.messages.slice(cut),
|
|
322
|
+
removedCount: summarizable.length,
|
|
323
|
+
foldingPreview: previewFold(summarizable),
|
|
324
|
+
usage: structured.response.usage,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
catch {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function previewFold(messages) {
|
|
332
|
+
const folded = renderTranscript(messages);
|
|
333
|
+
return folded.length > FOLDING_PREVIEW_CHARS
|
|
334
|
+
? `${folded.slice(0, FOLDING_PREVIEW_CHARS)}\n[... folded transcript truncated for the record — ${folded.length} chars total ...]`
|
|
335
|
+
: folded;
|
|
336
|
+
}
|
|
127
337
|
//# sourceMappingURL=compaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/engine/compaction.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AASnD,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,kBAAkB,EAAE,MAAM;IAC1B,gBAAgB,EAAE,MAAM;CAChB,CAAC;AAEX;6DAC6D;AAC7D,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAC9C,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAC3C,gFAAgF;AAChF,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,aAAqB,EACrB,IAAI,GAAyC,EAAE;IAE/C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,sBAAsB,CAAC;IACvD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CACpB,IAAI,CAAC,KAAK,IAAI,oBAAoB,EAClC,aAAa,GAAG,GAAG,CACpB,CAAC;IACF,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CACjC,KAAK,EACL,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,0BAA0B,CAAC,CAC9D,CAAC;IACF,OAAO;QACL,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAAC,kBAAkB,C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C,MAAM,CAAC;AACb,CAAC"}
|
package/dist/engine/context.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import type { LLMMessage, LLMResponse } from "../llm/types.js";
|
|
10
10
|
export declare function assistantMessage(response: LLMResponse): LLMMessage;
|
|
11
11
|
export declare function toolResultMessage(toolCallId: string, content: string): LLMMessage;
|
|
12
|
-
export declare function userMessage(content: string): LLMMessage;
|
|
12
|
+
export declare function userMessage(content: string, images?: LLMMessage["images"]): LLMMessage;
|
|
13
13
|
/** Working memory contains real conversation and observations, not system
|
|
14
14
|
* prompts or internal orchestration messages. No prefix guessing: a user's
|
|
15
15
|
* text is still their text even if it happens to start with "PHASE:". */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,GAAG,UAAU,CASlE;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,UAAU,CAEZ;AAED,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE/D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,GAAG,UAAU,CASlE;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,UAAU,CAEZ;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,GAC5B,UAAU,CAMZ;AAED;;yEAEyE;AACzE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAIxE"}
|
package/dist/engine/context.js
CHANGED
|
@@ -10,8 +10,12 @@ export function assistantMessage(response) {
|
|
|
10
10
|
export function toolResultMessage(toolCallId, content) {
|
|
11
11
|
return { role: "tool", tool_call_id: toolCallId, content };
|
|
12
12
|
}
|
|
13
|
-
export function userMessage(content) {
|
|
14
|
-
return {
|
|
13
|
+
export function userMessage(content, images) {
|
|
14
|
+
return {
|
|
15
|
+
role: "user",
|
|
16
|
+
content,
|
|
17
|
+
...(images && images.length ? { images } : {}),
|
|
18
|
+
};
|
|
15
19
|
}
|
|
16
20
|
/** Working memory contains real conversation and observations, not system
|
|
17
21
|
* prompts or internal orchestration messages. No prefix guessing: a user's
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,gBAAgB,CAAC,QAAqB;IACpD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EACL,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;YACnD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,QAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;KAC3E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,OAAe;IAEf,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,WAAW,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/engine/context.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,gBAAgB,CAAC,QAAqB;IACpD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EACL,QAAQ,CAAC,IAAI,KAAK,EAAE,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;YACnD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,QAAQ,CAAC,IAAI;QACnB,UAAU,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;KAC3E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,UAAkB,EAClB,OAAe;IAEf,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,OAAe,EACf,MAA6B;IAE7B,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,OAAO;QACP,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/C,CAAC;AACJ,CAAC;AAED;;yEAEyE;AACzE,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CACtE,CAAC;AACJ,CAAC"}
|
package/dist/engine/events.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* itself never formats anything — it only emits.
|
|
8
8
|
*/
|
|
9
9
|
import type { LLMToolCall, LLMUsage } from "../llm/types.js";
|
|
10
|
+
import type { CompactionHandoff } from "./compaction.js";
|
|
10
11
|
/** What a budget-limited run says it still needs — see EngineOptions.revival. */
|
|
11
12
|
export interface RevivalRequest {
|
|
12
13
|
/** Plain language: the work that remains. */
|
|
@@ -155,6 +156,8 @@ export type AgentEvent = {
|
|
|
155
156
|
summaryChars: number;
|
|
156
157
|
/** The summary that replaced the folded span — the compaction's output. */
|
|
157
158
|
summary?: string;
|
|
159
|
+
/** Structured handoff used by a task/ledger reset. */
|
|
160
|
+
compaction?: CompactionHandoff;
|
|
158
161
|
/** Truncated transcript of the folded span — the compaction's input. */
|
|
159
162
|
folding?: string;
|
|
160
163
|
usage: LLMUsage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/engine/events.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/engine/events.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GACvD;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,oGAAoG;IACpG,GAAG,CAAC,EAAE,SAAS,GAAG,oBAAoB,GAAG,gBAAgB,CAAC;CAC3D,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE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