@markusylisiurunen/tau 0.3.98 → 0.3.100
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/dist/core/code_mode/agents.js +2 -0
- package/dist/core/code_mode/agents.js.map +1 -1
- package/dist/core/code_mode/history.js +7 -0
- package/dist/core/code_mode/history.js.map +1 -1
- package/dist/core/code_mode/models.js.map +1 -1
- package/dist/core/code_mode/web.js.map +1 -1
- package/dist/core/config/content_loader.js.map +1 -1
- package/dist/core/config/index.js +2 -1
- package/dist/core/config/index.js.map +1 -1
- package/dist/core/config/ownership.js +71 -0
- package/dist/core/config/ownership.js.map +1 -0
- package/dist/core/config/runtime.js +22 -10
- package/dist/core/config/runtime.js.map +1 -1
- package/dist/core/config/runtime_config_snapshot.js +2 -2
- package/dist/core/config/runtime_config_snapshot.js.map +1 -1
- package/dist/core/config/schema.js +3 -2
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/history/agent_history_recorder.js +64 -0
- package/dist/core/history/agent_history_recorder.js.map +1 -0
- package/dist/core/history/cli.js +2 -2
- package/dist/core/history/cli.js.map +1 -1
- package/dist/core/history/config.js.map +1 -1
- package/dist/core/history/history_manager.js +14 -29
- package/dist/core/history/history_manager.js.map +1 -1
- package/dist/core/history/local_history_store.js +43 -10
- package/dist/core/history/local_history_store.js.map +1 -1
- package/dist/core/history/migrations.js +1 -1
- package/dist/core/history/migrations.js.map +1 -1
- package/dist/core/history/remote_history_client.js +2 -0
- package/dist/core/history/remote_history_client.js.map +1 -1
- package/dist/core/history/setup.js +10 -8
- package/dist/core/history/setup.js.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/persona_selection.js +38 -0
- package/dist/core/persona_selection.js.map +1 -0
- package/dist/core/runtime/agent_model.js.map +1 -1
- package/dist/core/runtime/chat_runtime.js +1 -5
- package/dist/core/runtime/chat_runtime.js.map +1 -1
- package/dist/core/session/auto_compaction_threshold.js.map +1 -1
- package/dist/core/static/code_mode/history/documentation.md +22 -4
- package/dist/core/static/tau_docs/code-mode.md +1 -1
- package/dist/core/static/tau_docs/config-reference.md +22 -8
- package/dist/core/static/tau_docs/configuration.md +13 -2
- package/dist/core/static/tau_docs/credentials.md +1 -1
- package/dist/core/static/tau_docs/history.md +48 -5
- package/dist/core/static/tau_docs/models.md +1 -1
- package/dist/core/static/tau_docs/node-sdk.md +9 -9
- package/dist/core/static/tau_docs/ownership-and-scope.md +7 -5
- package/dist/core/static/tau_docs/personas.md +5 -5
- package/dist/core/static/tau_docs/remote-sessions.md +3 -2
- package/dist/core/static/tau_docs/security.md +11 -3
- package/dist/core/static/tau_docs/session-protocol-methods.md +15 -6
- package/dist/core/static/tau_docs/session-protocol.md +21 -11
- package/dist/core/static/tau_docs/sessions.md +9 -5
- package/dist/core/static/tau_docs/subagents.md +13 -13
- package/dist/core/static/tau_docs/telegram-projects.md +65 -10
- package/dist/core/static/tau_docs/telegram.md +60 -41
- package/dist/core/static/tau_docs/troubleshooting.md +7 -3
- package/dist/core/static/tau_docs/tui.md +24 -5
- package/dist/core/subagents/agent_supervisor.js +5 -1
- package/dist/core/subagents/agent_supervisor.js.map +1 -1
- package/dist/core/subagents/claude_code_runner.mjs +49 -49
- package/dist/core/subagents/native_subagent_runtime.js +6 -1
- package/dist/core/subagents/native_subagent_runtime.js.map +1 -1
- package/dist/core/subagents/runtime.js.map +1 -1
- package/dist/core/telegram/adapter.js +41 -59
- package/dist/core/telegram/adapter.js.map +1 -1
- package/dist/core/telegram/cli.js +24 -12
- package/dist/core/telegram/cli.js.map +1 -1
- package/dist/core/telegram/config.js +43 -58
- package/dist/core/telegram/config.js.map +1 -1
- package/dist/core/telegram/local_session_client.js +3 -3
- package/dist/core/telegram/local_session_client.js.map +1 -1
- package/dist/core/telegram/runtime.js +19 -5
- package/dist/core/telegram/runtime.js.map +1 -1
- package/dist/core/telegram/session_manager.js +18 -7
- package/dist/core/telegram/session_manager.js.map +1 -1
- package/dist/core/telegram/workspace.js +21 -0
- package/dist/core/telegram/workspace.js.map +1 -1
- package/dist/core/tools/catalog.js.map +1 -1
- package/dist/core/utils/model_notices.js.map +1 -1
- package/dist/core/utils/speech_to_text_keywords.js +10 -4
- package/dist/core/utils/speech_to_text_keywords.js.map +1 -1
- package/dist/core/version.js +2 -2
- package/dist/core/version.js.map +1 -1
- package/dist/diff_tool/app/dist/assets/{core-D8lOlLN2.js → core-3PFMkRLP.js} +1 -1
- package/dist/diff_tool/app/dist/assets/engine-oniguruma-C5P09Ghe.js +1 -0
- package/dist/diff_tool/app/dist/assets/{highlights-B80gocb2.js → highlights-Bi-VwGCO.js} +2 -2
- package/dist/diff_tool/app/dist/assets/index-DhaXI7F3.js +221 -0
- package/dist/diff_tool/app/dist/assets/langs-CDbZNx2R.js +1 -0
- package/dist/diff_tool/app/dist/assets/lib-BKZ5ZaMU.js +1 -0
- package/dist/diff_tool/app/dist/assets/shiki-BArE1NVK.js +2 -0
- package/dist/diff_tool/app/dist/assets/{stream-tokenizer-BkuDYA48.js → stream-tokenizer-DFTZfQ1S.js} +4 -4
- package/dist/diff_tool/app/dist/assets/{themes-BaMgiyFz.js → themes-Dzo-2cM5.js} +2 -2
- package/dist/diff_tool/app/dist/assets/wasm-4KdTHw0F.js +1 -0
- package/dist/diff_tool/app/dist/index.html +2 -2
- package/dist/history/worker/index.js +140 -15
- package/dist/history/worker/index.js.map +1 -1
- package/dist/history/worker/migrations/0002_parent_session.sql +3 -0
- package/dist/history/worker/viewer.css +10 -1
- package/dist/host/local_session_host.js +134 -75
- package/dist/host/local_session_host.js.map +1 -1
- package/dist/host/session_bootstrap.js +53 -0
- package/dist/host/session_bootstrap.js.map +1 -0
- package/dist/host/session_host.js.map +1 -1
- package/dist/host/session_protocol_handler.js +9 -1
- package/dist/host/session_protocol_handler.js.map +1 -1
- package/dist/main.js +48 -95
- package/dist/main.js.map +1 -1
- package/dist/protocol/environment_variables.d.ts +2 -0
- package/dist/protocol/environment_variables.js +7 -0
- package/dist/protocol/environment_variables.js.map +1 -0
- package/dist/protocol/session_protocol.d.ts +16 -4
- package/dist/protocol/session_protocol.js +35 -15
- package/dist/protocol/session_protocol.js.map +1 -1
- package/dist/sdk/client.js +2 -2
- package/dist/sdk/client.js.map +1 -1
- package/dist/sdk/local_client.d.ts +6 -2
- package/dist/sdk/local_client.js +11 -59
- package/dist/sdk/local_client.js.map +1 -1
- package/dist/sdk/session.js +4 -3
- package/dist/sdk/session.js.map +1 -1
- package/dist/sdk/types.d.ts +6 -2
- package/dist/store/session_snapshot_migrations.js +19 -1
- package/dist/store/session_snapshot_migrations.js.map +1 -1
- package/dist/tui/chat_view.js +5 -0
- package/dist/tui/chat_view.js.map +1 -1
- package/dist/tui/host_diagnostic_relay.js +44 -0
- package/dist/tui/host_diagnostic_relay.js.map +1 -0
- package/dist/tui/index.js +1 -0
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/listen_capture.js +7 -9
- package/dist/tui/listen_capture.js.map +1 -1
- package/dist/tui/session_chat_app.js +2 -2
- package/dist/tui/session_chat_app.js.map +1 -1
- package/dist/tui/session_chat_controller.js +89 -13
- package/dist/tui/session_chat_controller.js.map +1 -1
- package/dist/tui/terminal.js +13 -2
- package/dist/tui/terminal.js.map +1 -1
- package/package.json +9 -9
- package/dist/diff_tool/app/dist/assets/index-DSKn9aHV.js +0 -205
- package/dist/diff_tool/app/dist/assets/langs-Cb6u03GG.js +0 -1
- package/dist/diff_tool/app/dist/assets/lib-BFrBoEqQ.js +0 -9
- package/dist/diff_tool/app/dist/assets/shiki-DaptjTao.js +0 -2
- package/dist/diff_tool/app/dist/assets/wasm-BnjxR4X6.js +0 -1
|
@@ -2,14 +2,15 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { isDeepStrictEqual } from "node:util";
|
|
4
4
|
import { resolvePromptTemplateWithBackend } from "../core/config/index.js";
|
|
5
|
-
import {
|
|
5
|
+
import { AgentHistoryRecorder } from "../core/history/agent_history_recorder.js";
|
|
6
6
|
import { McpManager } from "../core/mcp/manager.js";
|
|
7
|
+
import { resolvePersonaSelection } from "../core/persona_selection.js";
|
|
7
8
|
import { ChatRuntime } from "../core/runtime/chat_runtime.js";
|
|
8
9
|
import { getEffectiveAutoCompactThresholdTokens, } from "../core/session/auto_compaction_threshold.js";
|
|
9
10
|
import { buildToolRunPresentation, TOOL_UI_FACET_VERSION } from "../core/tools/presentation.js";
|
|
10
11
|
import { appendUsageLogEntry, getUsageCostTotal, getUsageTotals, } from "../core/usage/logs.js";
|
|
11
12
|
import { filterProjectPathAutocompleteEntries, loadProjectPathAutocompleteEntriesWithBackend, } from "../core/utils/project_files.js";
|
|
12
|
-
import { applySessionProtocolDelta, createSessionProtocolDeltaMessage, createSessionProtocolEphemeralMessage, createSessionProtocolSubagentActivitiesMessage, parseAutoCompactThresholdTokens, projectSessionProtocolNoticePresentation, projectSessionProtocolSubagentActivity, SESSION_PROTOCOL_MAX_SUBAGENT_ACTIVITIES, } from "../protocol/session_protocol.js";
|
|
13
|
+
import { applySessionProtocolDelta, createSessionProtocolDeltaMessage, createSessionProtocolEphemeralMessage, createSessionProtocolSubagentActivitiesMessage, parseAutoCompactThresholdTokens, parseSessionAttributes, projectSessionProtocolNoticePresentation, projectSessionProtocolSubagentActivity, SESSION_PROTOCOL_MAX_SUBAGENT_ACTIVITIES, } from "../protocol/session_protocol.js";
|
|
13
14
|
import { isIntermediateSystemMessage, } from "../protocol/system_message.js";
|
|
14
15
|
import { LEGACY_SESSION_MODEL_CONTEXT_KEY } from "../store/session_snapshot_migrations.js";
|
|
15
16
|
import { ClientToolBroker } from "./client_tool_broker.js";
|
|
@@ -28,13 +29,11 @@ export class LocalSessionHost {
|
|
|
28
29
|
historyRemote;
|
|
29
30
|
onShutdown;
|
|
30
31
|
clientToolBroker = new ClientToolBroker();
|
|
31
|
-
mcp;
|
|
32
32
|
sessionOptions;
|
|
33
33
|
shutdownPromise;
|
|
34
34
|
shuttingDown = false;
|
|
35
35
|
constructor(options) {
|
|
36
|
-
const { store, history, historyRemote,
|
|
37
|
-
this.mcp = new McpManager(mcpServers);
|
|
36
|
+
const { store, history, historyRemote, onShutdown, ...sessionOptions } = options;
|
|
38
37
|
this.store = store;
|
|
39
38
|
this.history = history;
|
|
40
39
|
this.historyRemote = historyRemote;
|
|
@@ -60,7 +59,38 @@ export class LocalSessionHost {
|
|
|
60
59
|
}
|
|
61
60
|
let hostedSession;
|
|
62
61
|
try {
|
|
63
|
-
|
|
62
|
+
const result = await executionEnvironment
|
|
63
|
+
.getToolExecutionBackend()
|
|
64
|
+
.runNodeScript('process.stdout.write(require("node:os").hostname())', [], {
|
|
65
|
+
timeoutMs: 30_000,
|
|
66
|
+
maxCaptureBytes: 4_096,
|
|
67
|
+
});
|
|
68
|
+
if (result.exitCode !== 0 ||
|
|
69
|
+
result.truncated ||
|
|
70
|
+
result.timedOut ||
|
|
71
|
+
result.aborted ||
|
|
72
|
+
!result.stdout.trim()) {
|
|
73
|
+
const reason = result.timedOut
|
|
74
|
+
? "probe timed out"
|
|
75
|
+
: result.aborted
|
|
76
|
+
? "probe aborted"
|
|
77
|
+
: result.truncated
|
|
78
|
+
? "probe exceeded the capture limit"
|
|
79
|
+
: result.exitCode !== 0
|
|
80
|
+
? `probe exited with code ${result.exitCode}`
|
|
81
|
+
: "probe returned an empty hostname";
|
|
82
|
+
const output = result.output.trim();
|
|
83
|
+
throw new Error(`failed to determine execution machine hostname: ${reason}${output ? `: ${output}` : ""}`);
|
|
84
|
+
}
|
|
85
|
+
const attributes = parseSessionAttributes({
|
|
86
|
+
...input.attributes,
|
|
87
|
+
machine: result.stdout.trim(),
|
|
88
|
+
cwd: executionEnvironment.snapshot().cwd,
|
|
89
|
+
});
|
|
90
|
+
hostedSession = await this.createLocalSessionHandle(executionEnvironment, undefined, {
|
|
91
|
+
...input,
|
|
92
|
+
attributes,
|
|
93
|
+
});
|
|
64
94
|
}
|
|
65
95
|
catch (error) {
|
|
66
96
|
if (!this.sessionsHasExecutionEnvironment(executionEnvironment)) {
|
|
@@ -106,7 +136,7 @@ export class LocalSessionHost {
|
|
|
106
136
|
}
|
|
107
137
|
async createLocalSessionHandle(executionEnvironment, committedSnapshot, createParams, forceNextSnapshotRevision = false) {
|
|
108
138
|
const remoteCatalog = this.sessionOptions.getRemoteModelCatalog();
|
|
109
|
-
const bootstrap = await this.
|
|
139
|
+
const bootstrap = await this.resolveSessionBootstrap(executionEnvironment, remoteCatalog, committedSnapshot !== undefined);
|
|
110
140
|
if (committedSnapshot) {
|
|
111
141
|
this.applySnapshotSettingsToBootstrap(bootstrap, committedSnapshot);
|
|
112
142
|
}
|
|
@@ -118,16 +148,27 @@ export class LocalSessionHost {
|
|
|
118
148
|
discoveredSkills: bootstrap.discoveredSkills,
|
|
119
149
|
includeAgentContext: this.sessionOptions.includeAgentContext,
|
|
120
150
|
});
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
151
|
+
const mcp = new McpManager(executionEnvironment.snapshot().kind === "local" ? bootstrap.config.mcpServers : {});
|
|
152
|
+
const mcpState = executionEnvironment.snapshot().kind === "local"
|
|
153
|
+
? {
|
|
154
|
+
status: "available",
|
|
155
|
+
servers: mcp
|
|
156
|
+
.listServers()
|
|
157
|
+
.map(({ name }) => name)
|
|
158
|
+
.sort(),
|
|
159
|
+
}
|
|
160
|
+
: { status: "unavailable", reason: "remote-execution" };
|
|
161
|
+
const catalog = createContentCatalogSnapshot(bootstrap, mcpState);
|
|
162
|
+
return this.createLocalSessionHandleFromRuntimeContext(executionEnvironment, runtimeContext, bootstrap, catalog, mcp, remoteCatalog, committedSnapshot, createParams, forceNextSnapshotRevision);
|
|
163
|
+
}
|
|
164
|
+
async createLocalSessionHandleFromRuntimeContext(executionEnvironment, runtimeContext, bootstrap, catalog, mcp, remoteCatalog, committedSnapshot, createParams, forceNextSnapshotRevision = false) {
|
|
128
165
|
let hostedSession;
|
|
129
166
|
const sessionId = committedSnapshot?.sessionId ?? randomUUID();
|
|
130
167
|
const createdAt = committedSnapshot?.createdAt ?? this.sessionOptions.environment.now();
|
|
168
|
+
const attributes = committedSnapshot?.attributes ?? createParams?.attributes;
|
|
169
|
+
if (!attributes) {
|
|
170
|
+
throw new Error("session attributes are required");
|
|
171
|
+
}
|
|
131
172
|
const runtime = ChatRuntime.create({
|
|
132
173
|
sessionId,
|
|
133
174
|
createdAt,
|
|
@@ -146,41 +187,46 @@ export class LocalSessionHost {
|
|
|
146
187
|
eventSink: async (event) => await hostedSession.enqueueRuntimeEvent(event),
|
|
147
188
|
subagentEventSink: async (event) => await hostedSession.recordSubagentEvent(event),
|
|
148
189
|
history: this.history.query(this.historyRemote),
|
|
149
|
-
|
|
190
|
+
openSubagentHistory: (child) => {
|
|
191
|
+
const recorder = new AgentHistoryRecorder(this.history.openSession({
|
|
192
|
+
sessionId: child.sessionId,
|
|
193
|
+
parentSessionId: sessionId,
|
|
194
|
+
attributes: { ...attributes, cwd: child.workingDirectory },
|
|
195
|
+
createdAt: child.createdAt,
|
|
196
|
+
}, this.historyRemote));
|
|
197
|
+
return async (event) => {
|
|
198
|
+
const failure = recorder.record(event);
|
|
199
|
+
if (failure)
|
|
200
|
+
await hostedSession.recordSubagentHistoryFailure(failure);
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
mcp,
|
|
150
204
|
initialPromptComposition: committedSnapshot
|
|
151
205
|
? promptCompositionFromSnapshot(committedSnapshot)
|
|
152
206
|
: undefined,
|
|
153
|
-
config: bootstrap.config
|
|
207
|
+
config: bootstrap.config,
|
|
154
208
|
recordUsage: this.sessionOptions.recordUsage,
|
|
155
209
|
deps: this.sessionOptions.deps,
|
|
156
210
|
});
|
|
157
211
|
runtime.setAutoCompactThreshold(committedSnapshot
|
|
158
212
|
? committedSnapshot.settings.autoCompactThresholdTokens
|
|
159
|
-
:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
hostedSession = new LocalHostedSessionHandle(runtime, runtimeContext.promptBootstrap, catalog, bootstrap, remoteCatalog, this.sessionOptions.getRemoteModelCatalog, this.sessionOptions.includeAgentContext, executionEnvironment, this.store, this.history, this.historyRemote, attributes, createdAt, committedSnapshot, forceNextSnapshotRevision, this.sessionOptions.recordUsage ?? appendUsageLogEntry, (session) => {
|
|
213
|
+
: createParams?.autoCompactThresholdTokens !== undefined
|
|
214
|
+
? createParams.autoCompactThresholdTokens
|
|
215
|
+
: (bootstrap.initialAutoCompactThresholdTokens ?? null));
|
|
216
|
+
const historyWriter = this.history.openSession({ sessionId, attributes, createdAt }, this.historyRemote);
|
|
217
|
+
hostedSession = new LocalHostedSessionHandle(runtime, runtimeContext.promptBootstrap, catalog, mcp, bootstrap, remoteCatalog, this.sessionOptions.getRemoteModelCatalog, this.sessionOptions.includeAgentContext, executionEnvironment, this.store, new AgentHistoryRecorder(historyWriter), attributes, createdAt, committedSnapshot, forceNextSnapshotRevision, this.sessionOptions.recordUsage ?? appendUsageLogEntry, (session) => {
|
|
165
218
|
this.sessions.delete(session);
|
|
166
219
|
this.sessionReferences.delete(session);
|
|
167
|
-
this.history.forgetSession(session.sessionId);
|
|
168
220
|
});
|
|
169
|
-
const historyFailure = this.history.registerSession({
|
|
170
|
-
sessionId: committedSnapshot?.sessionId ?? hostedSession.sessionId,
|
|
171
|
-
attributes,
|
|
172
|
-
createdAt,
|
|
173
|
-
}, this.historyRemote);
|
|
174
|
-
await hostedSession.recordHistoryFailure(historyFailure);
|
|
175
221
|
this.sessions.add(hostedSession);
|
|
176
222
|
return hostedSession;
|
|
177
223
|
}
|
|
178
|
-
async
|
|
224
|
+
async resolveSessionBootstrap(executionEnvironment, remoteCatalog, recovering) {
|
|
179
225
|
const resolver = this.sessionOptions.resolveSessionBootstrap;
|
|
180
226
|
if (!resolver) {
|
|
181
227
|
return this.defaultSessionBootstrap();
|
|
182
228
|
}
|
|
183
|
-
const bootstrap = await resolver({ executionEnvironment, remoteCatalog });
|
|
229
|
+
const bootstrap = await resolver({ executionEnvironment, remoteCatalog, recovering });
|
|
184
230
|
return cloneResolvedBootstrap(bootstrap);
|
|
185
231
|
}
|
|
186
232
|
applySnapshotSettingsToBootstrap(bootstrap, snapshot) {
|
|
@@ -383,12 +429,6 @@ export class LocalSessionHost {
|
|
|
383
429
|
}
|
|
384
430
|
}
|
|
385
431
|
this.sessionEvictions.clear();
|
|
386
|
-
try {
|
|
387
|
-
await this.mcp.close();
|
|
388
|
-
}
|
|
389
|
-
catch (error) {
|
|
390
|
-
errors.push(error);
|
|
391
|
-
}
|
|
392
432
|
try {
|
|
393
433
|
await this.history.flush();
|
|
394
434
|
}
|
|
@@ -432,14 +472,14 @@ class LocalHostedSessionHandle {
|
|
|
432
472
|
runtime;
|
|
433
473
|
promptBootstrap;
|
|
434
474
|
catalog;
|
|
475
|
+
mcp;
|
|
435
476
|
bootstrap;
|
|
436
477
|
remoteCatalog;
|
|
437
478
|
getLatestRemoteModelCatalog;
|
|
438
479
|
includeAgentContext;
|
|
439
480
|
executionEnvironment;
|
|
440
481
|
store;
|
|
441
|
-
|
|
442
|
-
historyRemote;
|
|
482
|
+
historyRecorder;
|
|
443
483
|
attributes;
|
|
444
484
|
createdAt;
|
|
445
485
|
recordUsage;
|
|
@@ -474,26 +514,28 @@ class LocalHostedSessionHandle {
|
|
|
474
514
|
disposePromise;
|
|
475
515
|
disposing = false;
|
|
476
516
|
costTotal = 0;
|
|
517
|
+
boundMcpServers;
|
|
477
518
|
forceNextSnapshotRevision;
|
|
478
519
|
projectionFailure;
|
|
479
520
|
disposed = false;
|
|
480
|
-
constructor(runtime, promptBootstrap, catalog, bootstrap, remoteCatalog, getLatestRemoteModelCatalog, includeAgentContext, executionEnvironment, store,
|
|
521
|
+
constructor(runtime, promptBootstrap, catalog, mcp, bootstrap, remoteCatalog, getLatestRemoteModelCatalog, includeAgentContext, executionEnvironment, store, historyRecorder, attributes, createdAt, committedSnapshot, forceNextSnapshotRevision, recordUsage, removeFromHost = () => { }) {
|
|
481
522
|
this.runtime = runtime;
|
|
482
523
|
this.promptBootstrap = promptBootstrap;
|
|
483
524
|
this.catalog = catalog;
|
|
525
|
+
this.mcp = mcp;
|
|
484
526
|
this.bootstrap = bootstrap;
|
|
485
527
|
this.remoteCatalog = remoteCatalog;
|
|
486
528
|
this.getLatestRemoteModelCatalog = getLatestRemoteModelCatalog;
|
|
487
529
|
this.includeAgentContext = includeAgentContext;
|
|
488
530
|
this.executionEnvironment = executionEnvironment;
|
|
489
531
|
this.store = store;
|
|
490
|
-
this.
|
|
491
|
-
this.historyRemote = historyRemote;
|
|
532
|
+
this.historyRecorder = historyRecorder;
|
|
492
533
|
this.attributes = attributes;
|
|
493
534
|
this.createdAt = createdAt;
|
|
494
535
|
this.recordUsage = recordUsage;
|
|
495
536
|
this.removeFromHost = removeFromHost;
|
|
496
537
|
this.session = runtime;
|
|
538
|
+
this.boundMcpServers = structuredClone(catalog.mcp.status === "available" ? bootstrap.config.mcpServers : {});
|
|
497
539
|
this.persistedSnapshot = committedSnapshot
|
|
498
540
|
? cloneSessionProtocolSnapshot(committedSnapshot)
|
|
499
541
|
: undefined;
|
|
@@ -818,15 +860,11 @@ class LocalHostedSessionHandle {
|
|
|
818
860
|
return { revision: snapshot.revision, settings: snapshot.settings };
|
|
819
861
|
});
|
|
820
862
|
}
|
|
821
|
-
async setPersona(personaId) {
|
|
863
|
+
async setPersona(personaId, overrides) {
|
|
822
864
|
this.assertActive();
|
|
823
865
|
const runtimeConfig = await this.executionEnvironment.resolveRuntimeConfig(this.executionEnvironment.snapshot().cwd, { remoteCatalog: this.remoteCatalog });
|
|
824
866
|
const personas = runtimeConfig.personas.map(clonePersona);
|
|
825
|
-
const
|
|
826
|
-
if (!persona) {
|
|
827
|
-
throw new Error(`unknown persona '${personaId}'`);
|
|
828
|
-
}
|
|
829
|
-
const selectedPersona = clonePersona(persona);
|
|
867
|
+
const selectedPersona = resolvePersonaSelection(personas, runtimeConfig.config.defaultPersona, personaId, overrides);
|
|
830
868
|
const runtimeContext = await this.executionEnvironment.resolveRuntimeContext({
|
|
831
869
|
cwd: this.executionEnvironment.snapshot().cwd,
|
|
832
870
|
discoveredSkills: runtimeConfig.skills,
|
|
@@ -836,6 +874,7 @@ class LocalHostedSessionHandle {
|
|
|
836
874
|
this.runtime.setRuntimeConfig(runtimeConfig.config, runtimeConfig.bootstrap.modelResolver.resolveModel);
|
|
837
875
|
this.runtime.updatePromptContext(runtimeContext.promptBootstrap.promptContext);
|
|
838
876
|
this.runtime.setPersona(selectedPersona);
|
|
877
|
+
this.runtime.setAutoCompactThreshold(overrides?.autoCompactThresholdTokens ?? null);
|
|
839
878
|
this.bootstrap = {
|
|
840
879
|
persona: clonePersona(selectedPersona),
|
|
841
880
|
discoveredSkills: structuredClone(runtimeConfig.skills),
|
|
@@ -844,7 +883,7 @@ class LocalHostedSessionHandle {
|
|
|
844
883
|
modelResolver: runtimeConfig.bootstrap.modelResolver.resolveModel,
|
|
845
884
|
config: runtimeConfig.config,
|
|
846
885
|
};
|
|
847
|
-
this.catalog = createContentCatalogSnapshot(this.bootstrap, this.catalog.
|
|
886
|
+
this.catalog = createContentCatalogSnapshot(this.bootstrap, this.catalog.mcp);
|
|
848
887
|
const snapshot = await this.commitSnapshot();
|
|
849
888
|
this.emitSnapshotReset("configuration", snapshot);
|
|
850
889
|
return snapshot;
|
|
@@ -859,7 +898,10 @@ class LocalHostedSessionHandle {
|
|
|
859
898
|
}
|
|
860
899
|
const personas = runtimeConfig.personas.map(clonePersona);
|
|
861
900
|
const currentPersonaId = this.runtime.persona.id.toLowerCase();
|
|
862
|
-
const nextPersona = personas.find((persona) => persona.id.toLowerCase() === currentPersonaId) ?? personas[0];
|
|
901
|
+
const nextPersona = clonePersona(personas.find((persona) => persona.id.toLowerCase() === currentPersonaId) ?? personas[0]);
|
|
902
|
+
if (nextPersona.id.toLowerCase() === currentPersonaId) {
|
|
903
|
+
nextPersona.settings = structuredClone(this.runtime.persona.settings);
|
|
904
|
+
}
|
|
863
905
|
const runtimeContext = await this.executionEnvironment.resolveRuntimeContext({
|
|
864
906
|
cwd: this.executionEnvironment.snapshot().cwd,
|
|
865
907
|
discoveredSkills: runtimeConfig.skills,
|
|
@@ -878,12 +920,20 @@ class LocalHostedSessionHandle {
|
|
|
878
920
|
modelResolver: runtimeConfig.bootstrap.modelResolver.resolveModel,
|
|
879
921
|
config: runtimeConfig.config,
|
|
880
922
|
};
|
|
881
|
-
this.catalog = createContentCatalogSnapshot(this.bootstrap, this.catalog.
|
|
923
|
+
this.catalog = createContentCatalogSnapshot(this.bootstrap, this.catalog.mcp);
|
|
882
924
|
const snapshot = await this.commitSnapshot();
|
|
883
925
|
this.emitSnapshotReset("configuration", snapshot);
|
|
884
926
|
return {
|
|
885
927
|
snapshot,
|
|
886
|
-
warnings:
|
|
928
|
+
warnings: [
|
|
929
|
+
...runtimeConfig.warnings,
|
|
930
|
+
...(this.catalog.mcp.status === "available" &&
|
|
931
|
+
!isDeepStrictEqual(this.boundMcpServers, runtimeConfig.config.mcpServers)
|
|
932
|
+
? [
|
|
933
|
+
"MCP configuration changed; new definitions take effect after this session unloads and is opened again.",
|
|
934
|
+
]
|
|
935
|
+
: []),
|
|
936
|
+
],
|
|
887
937
|
counts: {
|
|
888
938
|
personas: runtimeConfig.personas.length,
|
|
889
939
|
prompts: runtimeConfig.prompts.length,
|
|
@@ -1132,6 +1182,12 @@ class LocalHostedSessionHandle {
|
|
|
1132
1182
|
catch (error) {
|
|
1133
1183
|
errors.push(error);
|
|
1134
1184
|
}
|
|
1185
|
+
try {
|
|
1186
|
+
await this.mcp.close();
|
|
1187
|
+
}
|
|
1188
|
+
catch (error) {
|
|
1189
|
+
errors.push(error);
|
|
1190
|
+
}
|
|
1135
1191
|
try {
|
|
1136
1192
|
await this.executionEnvironment.dispose();
|
|
1137
1193
|
}
|
|
@@ -1495,7 +1551,10 @@ class LocalHostedSessionHandle {
|
|
|
1495
1551
|
await this.enqueueMutation(() => this.applySubagentEvent(event));
|
|
1496
1552
|
}
|
|
1497
1553
|
async enqueueRuntimeEvent(event) {
|
|
1498
|
-
await this.enqueueMutation(() =>
|
|
1554
|
+
await this.enqueueMutation(async () => {
|
|
1555
|
+
await this.recordRuntimeEvent(event);
|
|
1556
|
+
await this.recordHistoryFailure(this.historyRecorder.record(event));
|
|
1557
|
+
});
|
|
1499
1558
|
}
|
|
1500
1559
|
removeToolRun(tool, changes) {
|
|
1501
1560
|
this.tools.delete(tool.id);
|
|
@@ -1507,6 +1566,16 @@ class LocalHostedSessionHandle {
|
|
|
1507
1566
|
}
|
|
1508
1567
|
changes.push({ type: "tool.remove", id: tool.id }, { type: "timeline.remove", id: timelineItemId });
|
|
1509
1568
|
}
|
|
1569
|
+
async recordSubagentHistoryFailure(reason) {
|
|
1570
|
+
if (this.disposing || this.disposed)
|
|
1571
|
+
return;
|
|
1572
|
+
try {
|
|
1573
|
+
await this.enqueueMutation(() => this.recordHistoryFailure(reason));
|
|
1574
|
+
}
|
|
1575
|
+
catch {
|
|
1576
|
+
// A history diagnostic must not fail a worker when its parent is unavailable.
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1510
1579
|
async recordHistoryFailure(reason) {
|
|
1511
1580
|
if (!reason || this.timeline.items.some((item) => item.id === HISTORY_UNAVAILABLE_NOTICE_ID)) {
|
|
1512
1581
|
return;
|
|
@@ -1537,15 +1606,13 @@ class LocalHostedSessionHandle {
|
|
|
1537
1606
|
if (tool.status === "queued" || tool.status === "running") {
|
|
1538
1607
|
throw new Error(`transcript tool call '${tool.toolCallId}' is not terminal`);
|
|
1539
1608
|
}
|
|
1540
|
-
await this.recordHistoryFailure(this.
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
}),
|
|
1548
|
-
], this.historyRemote));
|
|
1609
|
+
await this.recordHistoryFailure(this.historyRecorder.recordTool({
|
|
1610
|
+
callHistoryEntryId: tool.call.messageId,
|
|
1611
|
+
resultHistoryEntryId,
|
|
1612
|
+
call,
|
|
1613
|
+
result,
|
|
1614
|
+
outcome: tool.status,
|
|
1615
|
+
}));
|
|
1549
1616
|
}
|
|
1550
1617
|
agentStateChange() {
|
|
1551
1618
|
const state = this.session.snapshot();
|
|
@@ -1688,7 +1755,6 @@ class LocalHostedSessionHandle {
|
|
|
1688
1755
|
},
|
|
1689
1756
|
},
|
|
1690
1757
|
], { persist: true });
|
|
1691
|
-
await this.recordHistoryFailure(this.history.append(this.sessionId, [systemHistoryEntry(event.historyEntryId, event.message)], this.historyRemote));
|
|
1692
1758
|
return;
|
|
1693
1759
|
}
|
|
1694
1760
|
case "user_message": {
|
|
@@ -1721,7 +1787,6 @@ class LocalHostedSessionHandle {
|
|
|
1721
1787
|
if (turn) {
|
|
1722
1788
|
this.pendingAcceptedTurnHistoryEntryIds.delete(event.historyEntryId);
|
|
1723
1789
|
}
|
|
1724
|
-
await this.recordHistoryFailure(this.history.append(this.sessionId, [userHistoryEntry(event.historyEntryId, event.message)], this.historyRemote));
|
|
1725
1790
|
return;
|
|
1726
1791
|
}
|
|
1727
1792
|
case "history_rewound": {
|
|
@@ -1733,7 +1798,6 @@ class LocalHostedSessionHandle {
|
|
|
1733
1798
|
this.timeline.items = this.timeline.items.filter((item) => item.sequence <= cutoffSequence);
|
|
1734
1799
|
const snapshot = await this.commitSnapshot({ removeMissingAgents: true });
|
|
1735
1800
|
this.emitSnapshotReset({ type: "rewind", epoch: this.timeline.epoch, cutoffSequence }, snapshot);
|
|
1736
|
-
await this.recordHistoryFailure(this.history.truncateFromSources(this.sessionId, event.removedEntryIds, this.historyRemote));
|
|
1737
1801
|
return;
|
|
1738
1802
|
}
|
|
1739
1803
|
case "assistant_final": {
|
|
@@ -1781,7 +1845,6 @@ class LocalHostedSessionHandle {
|
|
|
1781
1845
|
: []),
|
|
1782
1846
|
...toolChanges,
|
|
1783
1847
|
]);
|
|
1784
|
-
await this.recordHistoryFailure(this.history.append(this.sessionId, assistantHistoryEntries(event.historyEntryId, event.message), this.historyRemote));
|
|
1785
1848
|
return;
|
|
1786
1849
|
}
|
|
1787
1850
|
case "tool_run_queued":
|
|
@@ -1839,7 +1902,6 @@ class LocalHostedSessionHandle {
|
|
|
1839
1902
|
},
|
|
1840
1903
|
{ type: "tool.set", tool: structuredClone(nextTool) },
|
|
1841
1904
|
]);
|
|
1842
|
-
await this.appendToolHistory(existing, event.historyEntryId, event.message);
|
|
1843
1905
|
return;
|
|
1844
1906
|
}
|
|
1845
1907
|
await this.emitPatch("tool-result", [
|
|
@@ -1869,7 +1931,6 @@ class LocalHostedSessionHandle {
|
|
|
1869
1931
|
},
|
|
1870
1932
|
},
|
|
1871
1933
|
];
|
|
1872
|
-
const historyTools = [];
|
|
1873
1934
|
for (const toolResult of event.toolResults) {
|
|
1874
1935
|
const existing = this.tools.get(toolResult.toolCallId);
|
|
1875
1936
|
if (!existing || existing.status === "streaming") {
|
|
@@ -1883,12 +1944,8 @@ class LocalHostedSessionHandle {
|
|
|
1883
1944
|
};
|
|
1884
1945
|
this.tools.set(nextTool.id, nextTool);
|
|
1885
1946
|
changes.push({ type: "tool.set", tool: structuredClone(nextTool) });
|
|
1886
|
-
historyTools.push({ tool: existing, result: toolResult });
|
|
1887
1947
|
}
|
|
1888
1948
|
await this.emitPatch({ type: "resync" }, changes);
|
|
1889
|
-
for (const { tool, result } of historyTools) {
|
|
1890
|
-
await this.appendToolHistory(tool, event.historyEntryId, result);
|
|
1891
|
-
}
|
|
1892
1949
|
return;
|
|
1893
1950
|
}
|
|
1894
1951
|
case "feedback": {
|
|
@@ -2527,15 +2584,16 @@ function agentRunFromSubagentEvent(event) {
|
|
|
2527
2584
|
}
|
|
2528
2585
|
function cloneResolvedBootstrap(bootstrap) {
|
|
2529
2586
|
return {
|
|
2587
|
+
initialAutoCompactThresholdTokens: bootstrap.initialAutoCompactThresholdTokens,
|
|
2530
2588
|
persona: clonePersona(bootstrap.persona),
|
|
2531
2589
|
discoveredSkills: structuredClone(bootstrap.discoveredSkills),
|
|
2532
2590
|
personas: bootstrap.personas.map(clonePersona),
|
|
2533
2591
|
prompts: structuredClone(bootstrap.prompts),
|
|
2534
2592
|
modelResolver: bootstrap.modelResolver,
|
|
2535
|
-
|
|
2593
|
+
config: structuredClone(bootstrap.config),
|
|
2536
2594
|
};
|
|
2537
2595
|
}
|
|
2538
|
-
function createContentCatalogSnapshot(bootstrap,
|
|
2596
|
+
function createContentCatalogSnapshot(bootstrap, mcp) {
|
|
2539
2597
|
return {
|
|
2540
2598
|
personas: bootstrap.personas.map(personaSnapshotFromPersona),
|
|
2541
2599
|
prompts: bootstrap.prompts.map((prompt) => ({
|
|
@@ -2547,7 +2605,8 @@ function createContentCatalogSnapshot(bootstrap, mcpServers) {
|
|
|
2547
2605
|
description: skill.description,
|
|
2548
2606
|
path: skill.path,
|
|
2549
2607
|
})),
|
|
2550
|
-
|
|
2608
|
+
mcp: structuredClone(mcp),
|
|
2609
|
+
speechVocabulary: [...bootstrap.config.speechVocabulary],
|
|
2551
2610
|
};
|
|
2552
2611
|
}
|
|
2553
2612
|
function clonePersona(persona) {
|