tinker-agent 1.0.65
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 +173 -0
- package/package.json +78 -0
- package/patches/markdansi@0.3.2.patch +37 -0
- package/src/agent/context-builder.ts +43 -0
- package/src/agent/context-meter.ts +310 -0
- package/src/agent/loop.ts +525 -0
- package/src/agent/runtime-session.ts +1212 -0
- package/src/agent/session-ledger.ts +828 -0
- package/src/agent/turn-cancellation.ts +44 -0
- package/src/agent/types.ts +77 -0
- package/src/cli/config.ts +283 -0
- package/src/cli/index.ts +29 -0
- package/src/cli/model-profiles.ts +289 -0
- package/src/cli/run-runner.ts +107 -0
- package/src/cli/tui-runner.tsx +290 -0
- package/src/context/compiled-context-hash.ts +138 -0
- package/src/context/compiled-context-validator.ts +209 -0
- package/src/context/context-manager.ts +362 -0
- package/src/context/context-policy.ts +8 -0
- package/src/context/context-protocol-validator.ts +463 -0
- package/src/context/context-revision-compiler.ts +281 -0
- package/src/context/context-revision.ts +111 -0
- package/src/context/context-source.ts +30 -0
- package/src/context/context-swap-renderer.ts +272 -0
- package/src/context/protocol-frame.ts +240 -0
- package/src/context/swap-planner.ts +725 -0
- package/src/events/append-private-file.ts +16 -0
- package/src/events/bash-result-detail.ts +70 -0
- package/src/events/composite-event-sink.ts +82 -0
- package/src/events/event-sink.ts +16 -0
- package/src/events/jsonl-event-log.ts +13 -0
- package/src/events/observation-text-log.ts +195 -0
- package/src/events/stdout-event-printer.ts +396 -0
- package/src/events/types.ts +263 -0
- package/src/ids/runtime-id.ts +68 -0
- package/src/ids/uuid-v7.ts +5 -0
- package/src/instructions/project-instructions.ts +242 -0
- package/src/mcp/mcp-config.ts +144 -0
- package/src/mcp/mcp-manager.ts +216 -0
- package/src/mcp/mcp-tool-executor.ts +178 -0
- package/src/model/committed-prefix-auditor.ts +68 -0
- package/src/model/fake-model-client.ts +280 -0
- package/src/model/model-client.ts +64 -0
- package/src/model/model-context-profile.ts +134 -0
- package/src/model/model-request-preflight.ts +120 -0
- package/src/model/openai-chat-mapping.ts +444 -0
- package/src/model/openai-chat-model-client.ts +190 -0
- package/src/model/prompt-prefix-hash.ts +47 -0
- package/src/model/token-estimator.ts +148 -0
- package/src/observation/observation-builder.ts +481 -0
- package/src/session/resume-projection.ts +616 -0
- package/src/session/session-catalog.ts +270 -0
- package/src/session/session-errors.ts +121 -0
- package/src/session/session-history-reader.ts +535 -0
- package/src/session/session-lock.ts +291 -0
- package/src/session/session-schema.ts +741 -0
- package/src/session/session-store.ts +3067 -0
- package/src/session/sqlite-session-ledger.ts +153 -0
- package/src/tools/bash-task.ts +617 -0
- package/src/tools/bash.ts +450 -0
- package/src/tools/cwd-state.ts +22 -0
- package/src/tools/edit.ts +428 -0
- package/src/tools/file-diff.ts +116 -0
- package/src/tools/glob.ts +202 -0
- package/src/tools/grep.ts +550 -0
- package/src/tools/hash.ts +9 -0
- package/src/tools/path-safety.ts +33 -0
- package/src/tools/read.ts +319 -0
- package/src/tools/recall.ts +400 -0
- package/src/tools/registry.ts +213 -0
- package/src/tools/ripgrep.ts +220 -0
- package/src/tools/task-list.ts +59 -0
- package/src/tools/task-output-snapshot.ts +47 -0
- package/src/tools/task-output-tool.ts +62 -0
- package/src/tools/task-output.ts +159 -0
- package/src/tools/task-stop.ts +59 -0
- package/src/tools/task-tool-args.ts +29 -0
- package/src/tools/types.ts +330 -0
- package/src/tools/web-fetch/backend.ts +27 -0
- package/src/tools/web-fetch/browser-backend.ts +126 -0
- package/src/tools/web-fetch/exa-backend.ts +172 -0
- package/src/tools/web-fetch/index.ts +298 -0
- package/src/tools/web-fetch/local-backend.ts +267 -0
- package/src/tools/web-fetch/refiner.ts +78 -0
- package/src/tools/web-fetch/route.ts +95 -0
- package/src/tools/web-search.ts +300 -0
- package/src/tools/write.ts +244 -0
- package/src/tui/app.tsx +497 -0
- package/src/tui/components/assistant-markdown.tsx +47 -0
- package/src/tui/components/background-tasks.tsx +92 -0
- package/src/tui/components/bash-result-view.tsx +47 -0
- package/src/tui/components/context-status.tsx +127 -0
- package/src/tui/components/diff-view.tsx +151 -0
- package/src/tui/components/file-viewer.tsx +212 -0
- package/src/tui/components/footer.tsx +60 -0
- package/src/tui/components/header.tsx +21 -0
- package/src/tui/components/model-picker.tsx +142 -0
- package/src/tui/components/prompt-input.tsx +432 -0
- package/src/tui/components/resume-session-picker.tsx +273 -0
- package/src/tui/components/timeline.tsx +121 -0
- package/src/tui/context-format.ts +24 -0
- package/src/tui/event-store.ts +865 -0
- package/src/tui/git-branch.ts +23 -0
- package/src/tui/line-editor.ts +157 -0
- package/src/tui/prompt-history.ts +94 -0
- package/src/tui/slash-commands.ts +126 -0
- package/src/tui/tui-projection-policy.ts +35 -0
- package/src/tui/tui-projection-store.ts +123 -0
- package/src/tui/tui-session-controller.ts +170 -0
- package/src/tui/view-file.ts +122 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { RuntimeIdFactory } from "../ids/runtime-id";
|
|
2
|
+
import type { ToolDefinition } from "../tools/types";
|
|
3
|
+
import type { ProtocolContextView } from "../context/protocol-frame";
|
|
4
|
+
import type { BuiltContextRequest } from "../context/context-revision";
|
|
5
|
+
import {
|
|
6
|
+
InMemorySessionLedger,
|
|
7
|
+
type AgentTurnLedger,
|
|
8
|
+
type PendingLedgerTurn,
|
|
9
|
+
type SessionLedger,
|
|
10
|
+
} from "../agent/session-ledger";
|
|
11
|
+
import type { RunAgentResult, TurnIdentity } from "../agent/types";
|
|
12
|
+
import type { SessionStore } from "./session-store";
|
|
13
|
+
|
|
14
|
+
export class SqliteSessionLedger implements SessionLedger {
|
|
15
|
+
private active?: SqlitePendingLedgerTurn;
|
|
16
|
+
private faulted = false;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
private readonly store: SessionStore,
|
|
20
|
+
private readonly idFactory: RuntimeIdFactory,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
beginTurn(input: { turn: TurnIdentity; userPrompt: string }): PendingLedgerTurn {
|
|
24
|
+
this.requireAvailable("begin a turn");
|
|
25
|
+
if (this.active !== undefined) {
|
|
26
|
+
throw new Error("Cannot begin a SQLite ledger turn while another turn is open.");
|
|
27
|
+
}
|
|
28
|
+
const core = this.createCore();
|
|
29
|
+
const inner = core.beginTurn(input);
|
|
30
|
+
const pending = new SqlitePendingLedgerTurn(core, inner, (faulted) => {
|
|
31
|
+
if (this.active !== pending) {
|
|
32
|
+
throw new Error("SQLite ledger pending turn ownership was lost.");
|
|
33
|
+
}
|
|
34
|
+
this.active = undefined;
|
|
35
|
+
this.faulted ||= faulted;
|
|
36
|
+
});
|
|
37
|
+
this.active = pending;
|
|
38
|
+
return pending;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
buildCommittedModelRequest(tools: readonly ToolDefinition[]): BuiltContextRequest {
|
|
42
|
+
this.requireAvailable("build committed context");
|
|
43
|
+
if (this.active !== undefined) {
|
|
44
|
+
throw new Error("Cannot build committed context while a turn is open.");
|
|
45
|
+
}
|
|
46
|
+
return this.createCore().buildCommittedModelRequest(tools);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
buildCandidateModelRequest(
|
|
50
|
+
userPrompt: string,
|
|
51
|
+
tools: readonly ToolDefinition[],
|
|
52
|
+
): BuiltContextRequest {
|
|
53
|
+
this.requireAvailable("build candidate context");
|
|
54
|
+
if (this.active !== undefined) {
|
|
55
|
+
throw new Error("Cannot build candidate context while a turn is open.");
|
|
56
|
+
}
|
|
57
|
+
return this.createCore().buildCandidateModelRequest(userPrompt, tools);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
committedMessageCount(): number {
|
|
61
|
+
this.requireAvailable("read committed message count");
|
|
62
|
+
return this.store.loadProtocolView().messages.length;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
snapshot(
|
|
66
|
+
options: {
|
|
67
|
+
fullIntegrity?: boolean;
|
|
68
|
+
allowOpenTail?: boolean;
|
|
69
|
+
allowFaulted?: boolean;
|
|
70
|
+
} = {},
|
|
71
|
+
): ProtocolContextView {
|
|
72
|
+
if (this.active !== undefined) {
|
|
73
|
+
return this.active.snapshot(options);
|
|
74
|
+
}
|
|
75
|
+
if (this.faulted && options.allowFaulted !== true) {
|
|
76
|
+
throw new Error("Cannot read a faulted SQLite session ledger.");
|
|
77
|
+
}
|
|
78
|
+
return this.store.validateAll({
|
|
79
|
+
allowOpenTail: options.allowOpenTail === true,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fault(error: unknown): void {
|
|
84
|
+
this.faulted = true;
|
|
85
|
+
this.active?.fault(error);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private createCore(): InMemorySessionLedger {
|
|
89
|
+
return new InMemorySessionLedger({
|
|
90
|
+
sessionId: this.store.sessionId,
|
|
91
|
+
idFactory: this.idFactory,
|
|
92
|
+
initialSnapshot: this.store.loadContextSnapshot(),
|
|
93
|
+
committer: this.store,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private requireAvailable(action: string): void {
|
|
98
|
+
if (this.faulted) {
|
|
99
|
+
throw new Error(`Cannot ${action} after the SQLite session ledger faulted.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class SqlitePendingLedgerTurn implements PendingLedgerTurn {
|
|
105
|
+
readonly agent: AgentTurnLedger;
|
|
106
|
+
private settled = false;
|
|
107
|
+
|
|
108
|
+
constructor(
|
|
109
|
+
private readonly core: InMemorySessionLedger,
|
|
110
|
+
private readonly inner: PendingLedgerTurn,
|
|
111
|
+
private readonly settleOwner: (faulted: boolean) => void,
|
|
112
|
+
) {
|
|
113
|
+
this.agent = inner.agent;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
projectedMessageCount(): number {
|
|
117
|
+
return this.inner.projectedMessageCount();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
finish(result: RunAgentResult): void {
|
|
121
|
+
this.requireOpen("finish");
|
|
122
|
+
this.inner.finish(result);
|
|
123
|
+
this.settle(false);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
fault(error: unknown): void {
|
|
127
|
+
this.requireOpen("fault");
|
|
128
|
+
try {
|
|
129
|
+
this.inner.fault(error);
|
|
130
|
+
} finally {
|
|
131
|
+
this.settle(true);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
snapshot(options: {
|
|
136
|
+
fullIntegrity?: boolean;
|
|
137
|
+
allowOpenTail?: boolean;
|
|
138
|
+
allowFaulted?: boolean;
|
|
139
|
+
}): ProtocolContextView {
|
|
140
|
+
return this.core.snapshot(options);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private settle(faulted: boolean): void {
|
|
144
|
+
this.settled = true;
|
|
145
|
+
this.settleOwner(faulted);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private requireOpen(action: string): void {
|
|
149
|
+
if (this.settled) {
|
|
150
|
+
throw new Error(`Cannot ${action} after the SQLite ledger turn settled.`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|