tinker-agent 2.3.0 → 2.4.0
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/CHANGELOG.md +22 -1
- package/package.json +1 -1
- package/src/agent/loop.ts +1 -1
- package/src/agent/runtime-session.ts +259 -16
- package/src/agent/session-ledger.ts +10 -3
- package/src/context/context-manager.ts +185 -8
- package/src/context/context-policy.ts +1 -1
- package/src/context/context-revision-compiler.ts +7 -2
- package/src/context/context-swap-label.ts +132 -0
- package/src/context/swap-planner.ts +219 -56
- package/src/events/stdout-event-printer.ts +1 -0
- package/src/events/types.ts +3 -3
- package/src/observation/observation-builder.ts +36 -0
- package/src/session/session-store.ts +300 -0
- package/src/tools/context-maintenance.ts +266 -0
- package/src/tools/registry.ts +18 -1
- package/src/tools/types.ts +83 -1
- package/src/tui/event-store.ts +15 -0
package/src/tools/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ToolCall } from "../agent/types";
|
|
2
2
|
import type { ImageAssetRef } from "../image/image-types";
|
|
3
|
-
import type { SessionId } from "../ids/runtime-id";
|
|
3
|
+
import type { MessageId, SessionId } from "../ids/runtime-id";
|
|
4
|
+
import type { ContextUsageSource } from "../model/model-request-preflight";
|
|
4
5
|
import type {
|
|
5
6
|
RecallGetPage,
|
|
6
7
|
RecallSearchFilters,
|
|
@@ -310,6 +311,85 @@ export type RecallGetRawResult =
|
|
|
310
311
|
|
|
311
312
|
export type RecallRawResult = RecallSearchRawResult | RecallGetRawResult;
|
|
312
313
|
|
|
314
|
+
export type ContextMaintenancePressure = "normal" | "high" | "critical";
|
|
315
|
+
|
|
316
|
+
export type ContextSwapCandidate = {
|
|
317
|
+
candidateId: MessageId;
|
|
318
|
+
label: string;
|
|
319
|
+
ordinal: number;
|
|
320
|
+
savingsBytes: number;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export type ContextSwapScheduledCandidate = {
|
|
324
|
+
candidateId: MessageId;
|
|
325
|
+
savingsBytes: number;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export type ContextSwapRejectedCandidate = {
|
|
329
|
+
candidateId: MessageId;
|
|
330
|
+
reason: string;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
type ContextMaintenanceFailure<TOperation extends "status" | "candidates" | "swap"> = {
|
|
334
|
+
ok: false;
|
|
335
|
+
operation: TOperation;
|
|
336
|
+
error: string;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
export type ContextStatusRawResult =
|
|
340
|
+
| {
|
|
341
|
+
ok: true;
|
|
342
|
+
operation: "status";
|
|
343
|
+
usedInputTokens: number;
|
|
344
|
+
inputBudgetTokens: number;
|
|
345
|
+
pressure: ContextMaintenancePressure;
|
|
346
|
+
triggerTokens: number;
|
|
347
|
+
source: ContextUsageSource;
|
|
348
|
+
}
|
|
349
|
+
| ContextMaintenanceFailure<"status">;
|
|
350
|
+
|
|
351
|
+
export type ContextSwapCandidatesRawResult =
|
|
352
|
+
| {
|
|
353
|
+
ok: true;
|
|
354
|
+
operation: "candidates";
|
|
355
|
+
total: number;
|
|
356
|
+
candidates: readonly ContextSwapCandidate[];
|
|
357
|
+
}
|
|
358
|
+
| ContextMaintenanceFailure<"candidates">;
|
|
359
|
+
|
|
360
|
+
export type ContextSwapRawResult =
|
|
361
|
+
| {
|
|
362
|
+
ok: true;
|
|
363
|
+
operation: "swap";
|
|
364
|
+
scheduled: readonly ContextSwapScheduledCandidate[];
|
|
365
|
+
rejected: readonly ContextSwapRejectedCandidate[];
|
|
366
|
+
note: string;
|
|
367
|
+
}
|
|
368
|
+
| {
|
|
369
|
+
ok: false;
|
|
370
|
+
operation: "swap";
|
|
371
|
+
scheduled: readonly ContextSwapScheduledCandidate[];
|
|
372
|
+
rejected: readonly ContextSwapRejectedCandidate[];
|
|
373
|
+
error?: string;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export type ContextMaintenanceRawResult =
|
|
377
|
+
| ContextStatusRawResult
|
|
378
|
+
| ContextSwapCandidatesRawResult
|
|
379
|
+
| ContextSwapRawResult;
|
|
380
|
+
|
|
381
|
+
export type ContextMaintenanceHandle = {
|
|
382
|
+
status(call: ToolCall): Promise<ContextStatusRawResult>;
|
|
383
|
+
candidates(
|
|
384
|
+
call: ToolCall,
|
|
385
|
+
input: { readonly limit: number; readonly offset: number },
|
|
386
|
+
): Promise<ContextSwapCandidatesRawResult>;
|
|
387
|
+
swap(
|
|
388
|
+
call: ToolCall,
|
|
389
|
+
input: { readonly candidateIds: readonly MessageId[] },
|
|
390
|
+
): Promise<ContextSwapRawResult>;
|
|
391
|
+
};
|
|
392
|
+
|
|
313
393
|
export type MemorySearchRawResult =
|
|
314
394
|
| {
|
|
315
395
|
ok: true;
|
|
@@ -425,6 +505,7 @@ export type ToolRawResultByKind = {
|
|
|
425
505
|
web_search: WebSearchRawResult;
|
|
426
506
|
web_fetch: WebFetchRawResult;
|
|
427
507
|
recall: RecallRawResult;
|
|
508
|
+
context_maintenance: ContextMaintenanceRawResult;
|
|
428
509
|
memory_search: MemorySearchRawResult;
|
|
429
510
|
memory_get: MemoryGetRawResult;
|
|
430
511
|
wait: WaitRawResult;
|
|
@@ -472,6 +553,7 @@ export function defineToolExecutor<TKind extends ToolRawResultKind>(
|
|
|
472
553
|
|
|
473
554
|
export type ToolExecutionContext = {
|
|
474
555
|
signal: AbortSignal;
|
|
556
|
+
contextMaintenance?: ContextMaintenanceHandle;
|
|
475
557
|
confirmBashCommand?: (request: {
|
|
476
558
|
command: string;
|
|
477
559
|
reason: string;
|
package/src/tui/event-store.ts
CHANGED
|
@@ -883,6 +883,19 @@ function toolRawResultSummary(name: string, args: unknown, raw: ToolRawResult):
|
|
|
883
883
|
return raw.mode === "search"
|
|
884
884
|
? `${base} -> ${raw.page.hits.length} historical match${raw.page.hits.length === 1 ? "" : "es"}`
|
|
885
885
|
: `${base} -> ${raw.page.returnedBytes} historical bytes`;
|
|
886
|
+
case "context_maintenance":
|
|
887
|
+
if (!raw.ok) {
|
|
888
|
+
return raw.operation === "swap"
|
|
889
|
+
? `${base} -> 0 scheduled, ${raw.rejected.length} rejected`
|
|
890
|
+
: base;
|
|
891
|
+
}
|
|
892
|
+
if (raw.operation === "status") {
|
|
893
|
+
return `${base} -> ${raw.pressure}, ${raw.usedInputTokens}/${raw.inputBudgetTokens} tokens`;
|
|
894
|
+
}
|
|
895
|
+
if (raw.operation === "candidates") {
|
|
896
|
+
return `${base} -> ${raw.candidates.length}/${raw.total} candidates`;
|
|
897
|
+
}
|
|
898
|
+
return `${base} -> ${raw.scheduled.length} scheduled, ${raw.rejected.length} rejected`;
|
|
886
899
|
case "memory_search":
|
|
887
900
|
if (!raw.ok) {
|
|
888
901
|
return base;
|
|
@@ -980,6 +993,7 @@ function toolRawResultBashDetail(raw: ToolRawResult): Pick<TimelineItem, "bash">
|
|
|
980
993
|
case "web_search":
|
|
981
994
|
case "web_fetch":
|
|
982
995
|
case "recall":
|
|
996
|
+
case "context_maintenance":
|
|
983
997
|
case "memory_search":
|
|
984
998
|
case "memory_get":
|
|
985
999
|
case "wait":
|
|
@@ -1021,6 +1035,7 @@ function toolRawResultDiff(
|
|
|
1021
1035
|
case "web_search":
|
|
1022
1036
|
case "web_fetch":
|
|
1023
1037
|
case "recall":
|
|
1038
|
+
case "context_maintenance":
|
|
1024
1039
|
case "memory_search":
|
|
1025
1040
|
case "memory_get":
|
|
1026
1041
|
case "wait":
|