tinker-agent 2.8.0 → 2.9.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/README.md +64 -10
  3. package/package.json +4 -3
  4. package/src/agent/runtime-context-capabilities.ts +19 -0
  5. package/src/agent/runtime-context-events.ts +127 -0
  6. package/src/agent/runtime-context-maintenance.ts +780 -0
  7. package/src/agent/runtime-interactions.ts +291 -0
  8. package/src/agent/runtime-prompt-scheduler.ts +182 -0
  9. package/src/agent/runtime-session-contracts.ts +317 -0
  10. package/src/agent/runtime-session.ts +250 -2130
  11. package/src/agent/runtime-skills.ts +544 -0
  12. package/src/cli/runner-dependencies.ts +6 -5
  13. package/src/context/context-automation-policy.ts +12 -118
  14. package/src/events/types.ts +12 -0
  15. package/src/memory/memory-get-tool.ts +1 -1
  16. package/src/observation/observation-builder.ts +41 -11
  17. package/src/session/resume-projection.ts +47 -21
  18. package/src/session/session-history-access.ts +238 -0
  19. package/src/session/session-store-context-readers.ts +183 -0
  20. package/src/session/session-store-ledger-writer.ts +315 -0
  21. package/src/session/session-store-record-writer.ts +318 -0
  22. package/src/session/session-store-recovery.ts +225 -0
  23. package/src/session/session-store-revisions.ts +1004 -0
  24. package/src/session/session-store-sql.ts +40 -0
  25. package/src/session/session-store-validation.ts +657 -0
  26. package/src/session/session-store.ts +756 -3186
  27. package/src/tools/bash-task.ts +20 -2
  28. package/src/tools/recall.ts +106 -50
  29. package/src/tools/registry.ts +4 -6
  30. package/src/tools/task-output-range.ts +146 -0
  31. package/src/tools/task-output-tool.ts +35 -5
  32. package/src/tools/task-output.ts +35 -0
  33. package/src/tools/task-tool-args.ts +34 -0
  34. package/src/tools/types.ts +9 -0
  35. package/src/tui/event-store.ts +8 -3
@@ -0,0 +1,317 @@
1
+ import type { PublicToolingConfig } from "../cli/public-config-contract";
2
+ import type { ContextAutomationPolicy } from "../context/context-automation-policy";
3
+ import type {
4
+ ContextCompactionResult,
5
+ ContextCompactionTrigger,
6
+ ContextRetirementResult,
7
+ ContextRetirementTrigger,
8
+ } from "../context/context-manager";
9
+ import type { BuiltContextRequest } from "../context/context-revision";
10
+ import type { ContextSurfaceComponent } from "../context/context-surface";
11
+ import type { ToolCompletionInput } from "../context/protocol-frame";
12
+ import type { EventSink } from "../events/event-sink";
13
+ import type { AgentEventInput, AgentEventType } from "../events/types";
14
+ import type { RuntimeIdFactory, SessionId, TurnId } from "../ids/runtime-id";
15
+ import type { ImportedImageAsset } from "../image/image-asset-store";
16
+ import type { ImageAssetRef, UserMessage } from "../image/image-types";
17
+ import type { ProjectInstructionManifest } from "../instructions/project-instructions";
18
+ import type { loadMcpConfig } from "../mcp/mcp-config";
19
+ import type { createMcpManager, McpInventorySnapshot } from "../mcp/mcp-manager";
20
+ import type { ModelClient } from "../model/model-client";
21
+ import type {
22
+ ModelContextBudget,
23
+ ModelContextProfile,
24
+ } from "../model/model-context-profile";
25
+ import type { ReasoningEffortSnapshot } from "../model/reasoning-effort";
26
+ import type { ObservationBuilder } from "../observation/observation-builder";
27
+ import type {
28
+ CompletedTurnSnapshot,
29
+ SessionRecoveryResult,
30
+ SessionStore,
31
+ } from "../session/session-store";
32
+ import type { SkillCatalogSnapshot } from "../skills/skill-loader";
33
+ import type { createDefaultTooling } from "../tools/registry";
34
+ import type { TurnUndoResult } from "../tools/turn-undo-manager";
35
+ import type {
36
+ AskUserRequest,
37
+ ContextMaintenanceHandle,
38
+ ToolExecutor,
39
+ } from "../tools/types";
40
+ import type { Refiner } from "../tools/web-fetch/refiner";
41
+ import type {
42
+ AssistantTextDeltaSink,
43
+ AssistantTextDeltaUpdate,
44
+ } from "./assistant-text-delta";
45
+ import type { RunAgentInput } from "./loop";
46
+ import type {
47
+ AgentTurnLedger,
48
+ CommittedToolCompletion,
49
+ SessionLedger,
50
+ } from "./session-ledger";
51
+ import type {
52
+ IterationIdentity,
53
+ RunAgentResult,
54
+ ToolCallIdentity,
55
+ TurnIdentity,
56
+ } from "./types";
57
+
58
+ export type ExecuteTurnInput = {
59
+ userMessage: UserMessage;
60
+ signal: AbortSignal;
61
+ };
62
+
63
+ export type AcceptedTurn = {
64
+ readonly turnId: TurnIdentity["turnId"];
65
+ readonly userMessage: UserMessage;
66
+ readonly completion: Promise<RunAgentResult>;
67
+ };
68
+
69
+ export type PromptSchedulerSnapshot = {
70
+ readonly state: "idle" | "running";
71
+ readonly activeTurnId?: TurnIdentity["turnId"];
72
+ readonly pendingCount: number;
73
+ };
74
+
75
+ export type QueueFollowUpResult = {
76
+ readonly kind: "queued";
77
+ readonly pendingCount: number;
78
+ readonly activeTurnId?: TurnIdentity["turnId"];
79
+ };
80
+
81
+ export type SessionDisposeReason =
82
+ | { type: "oneshot_complete" }
83
+ | { type: "tui_exit" }
84
+ | { type: "session_switch" }
85
+ | { type: "runner_failed"; error: string }
86
+ | { type: "initialization_failed"; error: string };
87
+
88
+ export type RuntimeSession = {
89
+ readonly sessionId: SessionId;
90
+ readonly resumed: boolean;
91
+ readonly recovery: SessionRecoveryResult;
92
+ skills(): RuntimeSkillsSnapshot;
93
+ mcp(): McpInventorySnapshot;
94
+ supportsImageInput(): boolean;
95
+ reasoningEffort(): ReasoningEffortSnapshot | undefined;
96
+ setReasoningEffort(effort: string): ReasoningEffortSnapshot;
97
+ resetReasoningEffort(): ReasoningEffortSnapshot;
98
+ importImage(
99
+ sourcePath: string,
100
+ signal: AbortSignal,
101
+ prospectiveMessageImageCount: number,
102
+ ): Promise<ImportedImageAsset>;
103
+ verifyImageAssets(
104
+ assets: readonly ImageAssetRef[],
105
+ signal: AbortSignal,
106
+ ): Promise<void>;
107
+ admitTurn(input: ExecuteTurnInput): Promise<AcceptedTurn>;
108
+ executeTurn(input: ExecuteTurnInput): Promise<RunAgentResult>;
109
+ promptScheduler(): PromptSchedulerSnapshot;
110
+ subscribePromptScheduler(listener: () => void): () => void;
111
+ queueFollowUp(userMessage: UserMessage): QueueFollowUpResult;
112
+ compactContext(): Promise<ContextCompactionResult>;
113
+ retireContext(): Promise<ContextRetirementResult>;
114
+ undoLatestFileMutationTurn(): Promise<TurnUndoResult>;
115
+ cloneSession(targetSessionId: SessionId): Promise<void>;
116
+ canSwitchSession(): boolean;
117
+ bashGuard(): BashGuardSnapshot;
118
+ subscribeBashGuard(listener: () => void): () => void;
119
+ setYoloMode(enabled: boolean): void;
120
+ resolveBashConfirmation(decision: "allow" | "deny"): Promise<void>;
121
+ askUser(): AskUserSnapshot;
122
+ subscribeAskUser(listener: () => void): () => void;
123
+ resolveAskUser(response: AskUserResolution): Promise<void>;
124
+ dispose(reason: SessionDisposeReason): Promise<void>;
125
+ };
126
+
127
+ export type AskUserSnapshot = {
128
+ readonly pending?: AskUserRequest;
129
+ };
130
+
131
+ export type AskUserResolution =
132
+ | { readonly outcome: "selected"; readonly selectedIndex: number }
133
+ | { readonly outcome: "dismissed" };
134
+
135
+ export type BashGuardSource = "default" | "environment" | "cli" | "session";
136
+
137
+ export type BashGuardSnapshot = {
138
+ readonly mode: "guard" | "yolo";
139
+ readonly source: BashGuardSource;
140
+ readonly pending?: {
141
+ readonly command: string;
142
+ readonly reason: string;
143
+ };
144
+ };
145
+
146
+ export type RuntimeSkillsSnapshot = {
147
+ readonly skills: readonly {
148
+ readonly name: string;
149
+ readonly description: string;
150
+ readonly scope: "project" | "user";
151
+ readonly active: boolean;
152
+ }[];
153
+ readonly shadowedNames: readonly string[];
154
+ };
155
+
156
+ export type RuntimeSessionContext = {
157
+ readonly sessionId: SessionId;
158
+ readonly contextMaintenance: ContextMaintenanceHandle;
159
+ createIteration(turn: TurnIdentity, iterationNumber: number): IterationIdentity;
160
+ createToolCall(
161
+ iteration: IterationIdentity,
162
+ toolCallNumber: number,
163
+ ): ToolCallIdentity;
164
+ finishIterationForContinuation(iteration: IterationIdentity): void;
165
+ append(input: AgentEventInput): Promise<void>;
166
+ updateAssistantTextDelta?(update: AssistantTextDeltaUpdate): void;
167
+ onToolCompletionsCommitted?(input: {
168
+ completions: readonly ToolCompletionInput[];
169
+ committed: readonly CommittedToolCompletion[];
170
+ }): void;
171
+ prepareModelDispatch?(input: {
172
+ iteration: IterationIdentity;
173
+ built: BuiltContextRequest;
174
+ }): void;
175
+ maintainContextAfterIteration?(input: {
176
+ turn: TurnIdentity;
177
+ consumedThroughOrdinal: number;
178
+ ledger: AgentTurnLedger;
179
+ }): Promise<void>;
180
+ applyQueuedSteering?(input: {
181
+ turn: TurnIdentity;
182
+ ledger: AgentTurnLedger;
183
+ }): Promise<number>;
184
+ };
185
+
186
+ export type ContextSurfaceRefreshSummary = {
187
+ readonly previousRevisionNumber: number;
188
+ readonly revisionNumber: number;
189
+ readonly changed: readonly ContextSurfaceComponent[];
190
+ readonly toolCountBefore: number;
191
+ readonly toolCountAfter: number;
192
+ };
193
+
194
+ export type SkillsUpdateSummary = {
195
+ readonly previousRevisionNumber: number;
196
+ readonly revisionNumber: number;
197
+ readonly activated: readonly string[];
198
+ readonly refreshed: readonly string[];
199
+ readonly deactivated: readonly string[];
200
+ readonly unavailable: readonly string[];
201
+ readonly addedOverrideCount: number;
202
+ };
203
+
204
+ export type CompletedTurnHookInput = {
205
+ readonly workspaceRoot: string;
206
+ readonly sessionId: SessionId;
207
+ readonly turnId: TurnId;
208
+ readonly snapshot: CompletedTurnSnapshot;
209
+ };
210
+
211
+ export type CompletedTurnHookFailure = {
212
+ readonly workspaceRoot: string;
213
+ readonly sessionId: SessionId;
214
+ readonly turnId: TurnId;
215
+ readonly reason: "completed_turn_snapshot_failed" | "completed_turn_enqueue_failed";
216
+ };
217
+
218
+ export type CompletedTurnHook = {
219
+ enqueue(input: CompletedTurnHookInput): void;
220
+ recordFailure(input: CompletedTurnHookFailure): void;
221
+ };
222
+
223
+ export type CommonRuntimeSessionInput = {
224
+ workspaceRoot: string;
225
+ homeRoot?: string;
226
+ modelName: string;
227
+ profileName?: string;
228
+ maxIterations: number;
229
+ includeReasoningContent: boolean;
230
+ contextProfile: ModelContextProfile;
231
+ contextBudget: ModelContextBudget;
232
+ modelClient: ModelClient;
233
+ systemPrompt: string;
234
+ projectInstruction?: ProjectInstructionManifest;
235
+ skillCatalog?: SkillCatalogSnapshot;
236
+ presentationSinks?: EventSink[];
237
+ assistantTextDeltaSink?: AssistantTextDeltaSink;
238
+ persistence?:
239
+ | false
240
+ | {
241
+ eventLogPath?: string;
242
+ observationLogPath?: string;
243
+ };
244
+ webFetchRefiner?: Refiner;
245
+ toolingConfig?: PublicToolingConfig;
246
+ memorySearch?: ToolExecutor;
247
+ memoryGet?: ToolExecutor;
248
+ memoryCreate?: ToolExecutor;
249
+ memoryUpdate?: ToolExecutor;
250
+ memoryDelete?: ToolExecutor;
251
+ completedTurnHook?: CompletedTurnHook;
252
+ enableTurnUndo?: boolean;
253
+ enableAskUser?: boolean;
254
+ bashGuard?: {
255
+ readonly mode: "guard" | "yolo";
256
+ readonly source: Exclude<BashGuardSource, "session">;
257
+ readonly surface: "tui" | "one-shot";
258
+ };
259
+ };
260
+
261
+ export type CreateNewRuntimeSessionInput = CommonRuntimeSessionInput & {
262
+ selection: { mode: "new"; sessionId: SessionId };
263
+ };
264
+
265
+ export type ResumeRuntimeSessionInput = CommonRuntimeSessionInput & {
266
+ selection: { mode: "resume"; sessionId: SessionId };
267
+ };
268
+
269
+ export type CreateRuntimeSessionInput =
270
+ | CreateNewRuntimeSessionInput
271
+ | ResumeRuntimeSessionInput;
272
+
273
+ export type RuntimeSessionFactoryDependencies = {
274
+ idFactory: RuntimeIdFactory;
275
+ createTooling: typeof createDefaultTooling;
276
+ loadMcpConfig: typeof loadMcpConfig;
277
+ createMcpManager: typeof createMcpManager;
278
+ createObservationBuilder: () => ObservationBuilder;
279
+ openStore: (
280
+ input: CreateRuntimeSessionInput,
281
+ idFactory: RuntimeIdFactory,
282
+ ) => Promise<SessionStore>;
283
+ createLedger: (store: SessionStore, idFactory: RuntimeIdFactory) => SessionLedger;
284
+ createEventSink: (
285
+ input: CreateRuntimeSessionInput,
286
+ sessionDirectory: string,
287
+ ) => EventSink;
288
+ selectShadowPlanning: NonNullable<RunAgentInput["shadowPlanning"]>["select"];
289
+ onShadowPlanningResult?: NonNullable<RunAgentInput["shadowPlanning"]>["onResult"];
290
+ contextAutomationPolicy: ContextAutomationPolicy;
291
+ automaticCompactionTrigger: () => ContextCompactionTrigger;
292
+ automaticRetirementTrigger: () => ContextRetirementTrigger;
293
+ manualCompactionTrigger: () => ContextCompactionTrigger;
294
+ manualRetirementTrigger: () => ContextRetirementTrigger;
295
+ };
296
+
297
+ export type RuntimeSessionState =
298
+ | "initializing"
299
+ | "admitting"
300
+ | "ready"
301
+ | "executing"
302
+ | "compacting"
303
+ | "maintaining_context"
304
+ | "undoing"
305
+ | "faulted"
306
+ | "disposing"
307
+ | "disposed";
308
+
309
+ export class RuntimeEventAppendError extends Error {
310
+ readonly eventType: AgentEventType;
311
+
312
+ constructor(eventType: AgentEventType, options?: ErrorOptions) {
313
+ super(`Failed to append runtime event ${eventType}.`, options);
314
+ this.name = "RuntimeEventAppendError";
315
+ this.eventType = eventType;
316
+ }
317
+ }