@meistrari/tela-cli 0.7.41 → 0.7.43
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/index.js +299 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -274,7 +274,7 @@ var require_defaults = __commonJS({
|
|
|
274
274
|
services: {
|
|
275
275
|
pantry: "https://pantry-api.tela.tools",
|
|
276
276
|
workflow: "https://workflow-api.tela.tools",
|
|
277
|
-
agent: "https://agent-
|
|
277
|
+
agent: "https://agent-api-production-81c9.up.railway.app"
|
|
278
278
|
}
|
|
279
279
|
},
|
|
280
280
|
staging: {
|
|
@@ -366,6 +366,7 @@ var require_config = __commonJS({
|
|
|
366
366
|
var paths_1 = require_paths();
|
|
367
367
|
var LEGACY_STAGING_AUTH_API_URL = "https://auth.staging.tela.com";
|
|
368
368
|
var LEGACY_STAGING_DEFAULT_API_URL = "https://api.staging.tela.com";
|
|
369
|
+
var LEGACY_PRODUCTION_AGENT_GATEWAY_URL = "https://agent-gateway-api.tela.tools";
|
|
369
370
|
var CREDENTIAL_MATERIAL_KEYS = /* @__PURE__ */ new Set([
|
|
370
371
|
"accessToken",
|
|
371
372
|
"refreshToken",
|
|
@@ -523,6 +524,13 @@ var require_config = __commonJS({
|
|
|
523
524
|
};
|
|
524
525
|
}
|
|
525
526
|
function applyDefaultEnvironmentValues(id, currentEnvironment, defaultEnvironment) {
|
|
527
|
+
const services = {
|
|
528
|
+
...defaultEnvironment.services,
|
|
529
|
+
...currentEnvironment.services
|
|
530
|
+
};
|
|
531
|
+
if (id === "production" && services.agent === LEGACY_PRODUCTION_AGENT_GATEWAY_URL) {
|
|
532
|
+
services.agent = defaultEnvironment.services.agent;
|
|
533
|
+
}
|
|
526
534
|
return {
|
|
527
535
|
...currentEnvironment,
|
|
528
536
|
authApiUrl: id === "staging" && currentEnvironment.authApiUrl === LEGACY_STAGING_AUTH_API_URL ? defaultEnvironment.authApiUrl : currentEnvironment.authApiUrl,
|
|
@@ -530,10 +538,7 @@ var require_config = __commonJS({
|
|
|
530
538
|
// staging moved to the telastaging.com domain.
|
|
531
539
|
defaultApiUrl: id === "staging" && currentEnvironment.defaultApiUrl === LEGACY_STAGING_DEFAULT_API_URL ? defaultEnvironment.defaultApiUrl : currentEnvironment.defaultApiUrl,
|
|
532
540
|
authApplication: currentEnvironment.authApplication ?? defaultEnvironment.authApplication,
|
|
533
|
-
services
|
|
534
|
-
...defaultEnvironment.services,
|
|
535
|
-
...currentEnvironment.services
|
|
536
|
-
}
|
|
541
|
+
services
|
|
537
542
|
};
|
|
538
543
|
}
|
|
539
544
|
function assertNoCredentialMaterial(value) {
|
|
@@ -2186,7 +2191,6 @@ var require_config2 = __commonJS({
|
|
|
2186
2191
|
"use strict";
|
|
2187
2192
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2188
2193
|
exports2.getDefaultAgentCloneRoot = getDefaultAgentCloneRoot;
|
|
2189
|
-
exports2.isDirectAgentApiUrl = isDirectAgentApiUrl;
|
|
2190
2194
|
exports2.resolveAgentConfig = resolveAgentConfig;
|
|
2191
2195
|
exports2.ensureConfigInteractive = ensureConfigInteractive;
|
|
2192
2196
|
var node_os_1 = require("node:os");
|
|
@@ -2194,23 +2198,10 @@ var require_config2 = __commonJS({
|
|
|
2194
2198
|
var tela_local_config_1 = require_dist();
|
|
2195
2199
|
var credentials_1 = require_credentials2();
|
|
2196
2200
|
var errors_1 = require_errors();
|
|
2197
|
-
var AGENT_GATEWAY_HOSTS = /* @__PURE__ */ new Set([
|
|
2198
|
-
"agent-gateway-api.tela.tools"
|
|
2199
|
-
]);
|
|
2200
2201
|
function getDefaultAgentCloneRoot(env = process.env) {
|
|
2201
2202
|
const configured = env.TELA_AGENT_CLONE_ROOT?.trim();
|
|
2202
2203
|
return configured ? (0, node_path_1.resolve)(configured.replace(/^~(?=$|\/)/, (0, node_os_1.homedir)())) : (0, node_path_1.join)((0, node_os_1.homedir)(), "tela-agents");
|
|
2203
2204
|
}
|
|
2204
|
-
function isDirectAgentApiUrl(value) {
|
|
2205
|
-
if (!value)
|
|
2206
|
-
return false;
|
|
2207
|
-
try {
|
|
2208
|
-
const url = new URL(value);
|
|
2209
|
-
return !AGENT_GATEWAY_HOSTS.has(url.hostname);
|
|
2210
|
-
} catch {
|
|
2211
|
-
return false;
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
2205
|
async function resolveAgentConfig(options = {}) {
|
|
2215
2206
|
const env = options.env ?? process.env;
|
|
2216
2207
|
const localConfig = await (0, tela_local_config_1.loadConfig)();
|
|
@@ -2220,22 +2211,13 @@ var require_config2 = __commonJS({
|
|
|
2220
2211
|
workspace: options.workspace,
|
|
2221
2212
|
env
|
|
2222
2213
|
});
|
|
2223
|
-
|
|
2224
|
-
if (shouldRequireAgentService && !Object.prototype.hasOwnProperty.call(resolved.environment.services, "agent")) {
|
|
2214
|
+
if (options.requireAgentService !== false && !Object.prototype.hasOwnProperty.call(resolved.environment.services, "agent")) {
|
|
2225
2215
|
throw (0, errors_1.createUserFacingError)({
|
|
2226
2216
|
code: "agent_service_missing",
|
|
2227
2217
|
summary: `Context ${resolved.id} does not define an agent service URL.`,
|
|
2228
2218
|
fixes: ["Add services.agent to the selected Tela environment in Dock before running agent commands."]
|
|
2229
2219
|
});
|
|
2230
2220
|
}
|
|
2231
|
-
const configuredAgentServiceUrl = resolved.environment.services.agent;
|
|
2232
|
-
if (options.requireDirectAgentService === true && !isDirectAgentApiUrl(configuredAgentServiceUrl)) {
|
|
2233
|
-
throw (0, errors_1.createUserFacingError)({
|
|
2234
|
-
code: "agent_service_gateway_unsupported",
|
|
2235
|
-
summary: `Context ${resolved.id} points Agent API to an Agent Gateway URL, which cannot be used for tela agent setup.`,
|
|
2236
|
-
fixes: ["Connect an environment with a direct Agent API URL, such as Staging, before running agent setup."]
|
|
2237
|
-
});
|
|
2238
|
-
}
|
|
2239
2221
|
const credentials = options.credentials ?? (0, credentials_1.createAgentCredentialAdapter)(env);
|
|
2240
2222
|
const credential = await credentials.get(resolved.context.credentialRef);
|
|
2241
2223
|
if (!credential) {
|
|
@@ -3464,6 +3446,7 @@ var require_run = __commonJS({
|
|
|
3464
3446
|
exports2.addLocalAgentRunInputs = addLocalAgentRunInputs;
|
|
3465
3447
|
exports2.removeLocalAgentRunInput = removeLocalAgentRunInput;
|
|
3466
3448
|
exports2.createInitialRunSnapshot = createInitialRunSnapshot;
|
|
3449
|
+
exports2.getDefaultAgentRunsRoot = getDefaultAgentRunsRoot;
|
|
3467
3450
|
exports2.runLocalAgentCommand = runLocalAgentCommand;
|
|
3468
3451
|
exports2.renderRunExecutionRecap = renderRunExecutionRecap;
|
|
3469
3452
|
exports2.renderRunArtifactCard = renderRunArtifactCard;
|
|
@@ -3491,6 +3474,7 @@ var require_run = __commonJS({
|
|
|
3491
3474
|
];
|
|
3492
3475
|
var TOOL_PROGRESS_MILESTONES = [0, 5, 15, 30];
|
|
3493
3476
|
var RUN_ARCHIVE_SCHEMA_VERSION = 1;
|
|
3477
|
+
var LIVE_DEBUG_SNAPSHOT_INTERVAL_MS = 1e3;
|
|
3494
3478
|
function writeLine2(writer, line) {
|
|
3495
3479
|
const message = `${line}
|
|
3496
3480
|
`;
|
|
@@ -3644,7 +3628,7 @@ var require_run = __commonJS({
|
|
|
3644
3628
|
const detail = summarizeToolInput(name, input);
|
|
3645
3629
|
return detail ? { summary: truncate(`${name} ${detail}`), detail: `${name}: ${detail}` } : { summary: name };
|
|
3646
3630
|
}
|
|
3647
|
-
function
|
|
3631
|
+
function extractMessageUsage(message) {
|
|
3648
3632
|
if (!message || typeof message !== "object")
|
|
3649
3633
|
return void 0;
|
|
3650
3634
|
const usage = message.usage;
|
|
@@ -3653,6 +3637,21 @@ var require_run = __commonJS({
|
|
|
3653
3637
|
const usageRecord = usage;
|
|
3654
3638
|
const input = safeNumber(usageRecord.input_tokens) ?? 0;
|
|
3655
3639
|
const output = safeNumber(usageRecord.output_tokens) ?? 0;
|
|
3640
|
+
const cached = safeNumber(usageRecord.cache_read_input_tokens) ?? safeNumber(usageRecord.cache_read_tokens) ?? 0;
|
|
3641
|
+
if (input <= 0 && output <= 0 && cached <= 0)
|
|
3642
|
+
return void 0;
|
|
3643
|
+
return {
|
|
3644
|
+
inputTokens: input,
|
|
3645
|
+
outputTokens: output,
|
|
3646
|
+
cachedTokens: cached
|
|
3647
|
+
};
|
|
3648
|
+
}
|
|
3649
|
+
function extractMessageTokens(message) {
|
|
3650
|
+
const usage = extractMessageUsage(message);
|
|
3651
|
+
if (!usage)
|
|
3652
|
+
return void 0;
|
|
3653
|
+
const input = usage.inputTokens;
|
|
3654
|
+
const output = usage.outputTokens;
|
|
3656
3655
|
const total = input + output;
|
|
3657
3656
|
return total > 0 ? total : void 0;
|
|
3658
3657
|
}
|
|
@@ -3781,6 +3780,7 @@ var require_run = __commonJS({
|
|
|
3781
3780
|
summary: "Claude session started.",
|
|
3782
3781
|
detail: safeString(event.cwd),
|
|
3783
3782
|
model: safeString(event.model),
|
|
3783
|
+
claudeSessionId: safeString(event.session_id),
|
|
3784
3784
|
recordStep: true
|
|
3785
3785
|
}];
|
|
3786
3786
|
case "status": {
|
|
@@ -3863,6 +3863,7 @@ var require_run = __commonJS({
|
|
|
3863
3863
|
const normalized = [];
|
|
3864
3864
|
const parentToolUseId = safeString(event.parent_tool_use_id);
|
|
3865
3865
|
const tokens = extractMessageTokens(event.message);
|
|
3866
|
+
const usage = extractMessageUsage(event.message);
|
|
3866
3867
|
const text = extractAssistantText(event.message);
|
|
3867
3868
|
if (text.trim()) {
|
|
3868
3869
|
const summary = summarizeLines(text);
|
|
@@ -3873,7 +3874,9 @@ var require_run = __commonJS({
|
|
|
3873
3874
|
detail: summary.detail,
|
|
3874
3875
|
recordStep: true,
|
|
3875
3876
|
parentToolUseId,
|
|
3876
|
-
tokens
|
|
3877
|
+
tokens,
|
|
3878
|
+
usage,
|
|
3879
|
+
startsTurn: !parentToolUseId
|
|
3877
3880
|
});
|
|
3878
3881
|
}
|
|
3879
3882
|
const toolUses = extractAssistantToolUses(event.message);
|
|
@@ -3881,8 +3884,11 @@ var require_run = __commonJS({
|
|
|
3881
3884
|
const batch = buildToolBatchEvent(buildDerivedToolSummary(toolUses), toolUses);
|
|
3882
3885
|
if (batch.kind === "tool_batch") {
|
|
3883
3886
|
batch.parentToolUseId = parentToolUseId;
|
|
3887
|
+
batch.startsTurn = !parentToolUseId && normalized.length === 0;
|
|
3884
3888
|
if (tokens != null && normalized.length === 0)
|
|
3885
3889
|
batch.tokens = tokens;
|
|
3890
|
+
if (usage && normalized.length === 0)
|
|
3891
|
+
batch.usage = usage;
|
|
3886
3892
|
}
|
|
3887
3893
|
normalized.push(batch);
|
|
3888
3894
|
}
|
|
@@ -3938,7 +3944,8 @@ var require_run = __commonJS({
|
|
|
3938
3944
|
text,
|
|
3939
3945
|
summary: summary.summary,
|
|
3940
3946
|
detail: summary.detail,
|
|
3941
|
-
recordStep: true
|
|
3947
|
+
recordStep: true,
|
|
3948
|
+
startsTurn: true
|
|
3942
3949
|
}];
|
|
3943
3950
|
}
|
|
3944
3951
|
case "tool_use_summary": {
|
|
@@ -4001,6 +4008,38 @@ var require_run = __commonJS({
|
|
|
4001
4008
|
const elapsed = timeElapsed != null && Number.isFinite(timeElapsed) ? ` timeElapsed="${String(timeElapsed).replace(/"/g, """)}"` : "";
|
|
4002
4009
|
return `<step${elapsed}>${escapeReasoningStepContent(content)}</step>`;
|
|
4003
4010
|
}
|
|
4011
|
+
function mapRunStatusToDebugTimelineStatus(status) {
|
|
4012
|
+
switch (status) {
|
|
4013
|
+
case "success":
|
|
4014
|
+
return "completed";
|
|
4015
|
+
case "failed":
|
|
4016
|
+
return "failed";
|
|
4017
|
+
case "cancelled":
|
|
4018
|
+
return "cancelled";
|
|
4019
|
+
case "running":
|
|
4020
|
+
return "running";
|
|
4021
|
+
case "starting":
|
|
4022
|
+
default:
|
|
4023
|
+
return "pending";
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
function getTimelineToolCategory(toolName) {
|
|
4027
|
+
const normalized = toolName?.toLowerCase() ?? "";
|
|
4028
|
+
if (includesAny(normalized, ["bash", "shell", "exec", "command", "terminal"]))
|
|
4029
|
+
return "shell";
|
|
4030
|
+
if (includesAny(normalized, ["grep", "glob", "search", "find", "lsp"]))
|
|
4031
|
+
return "search";
|
|
4032
|
+
if (includesAny(normalized, ["read", "fetch", "get", "open", "view"]))
|
|
4033
|
+
return "file";
|
|
4034
|
+
if (includesAny(normalized, ["write", "edit", "patch", "replace", "update", "insert", "delete", "move", "apply"]))
|
|
4035
|
+
return "edit";
|
|
4036
|
+
if (includesAny(normalized, ["web", "url", "browser"]))
|
|
4037
|
+
return "web";
|
|
4038
|
+
return "other";
|
|
4039
|
+
}
|
|
4040
|
+
function includesAny(value, needles) {
|
|
4041
|
+
return needles.some((needle) => value.includes(needle));
|
|
4042
|
+
}
|
|
4004
4043
|
function normalizeToolInput(input) {
|
|
4005
4044
|
if (isRecord2(input)) {
|
|
4006
4045
|
return input;
|
|
@@ -4018,11 +4057,19 @@ var require_run = __commonJS({
|
|
|
4018
4057
|
reasoningSteps = [];
|
|
4019
4058
|
activeTools = /* @__PURE__ */ new Map();
|
|
4020
4059
|
subagentBuckets = /* @__PURE__ */ new Map();
|
|
4060
|
+
timelineEvents = [];
|
|
4061
|
+
timelineToolEventIndexes = /* @__PURE__ */ new Map();
|
|
4062
|
+
runTurns = [];
|
|
4063
|
+
debugSessionId = (0, node_crypto_1.randomUUID)();
|
|
4021
4064
|
execution;
|
|
4022
4065
|
stepIndex = 0;
|
|
4066
|
+
sequenceIndex = 0;
|
|
4067
|
+
runTurnIndex = 0;
|
|
4023
4068
|
status = "starting";
|
|
4024
4069
|
currentActivity = "Preparing Claude run\u2026";
|
|
4025
4070
|
model;
|
|
4071
|
+
claudeSessionId = null;
|
|
4072
|
+
currentRunTurnId = null;
|
|
4026
4073
|
constructor(prepared, mode, startedAtMs = Date.now()) {
|
|
4027
4074
|
this.prepared = prepared;
|
|
4028
4075
|
this.mode = mode;
|
|
@@ -4045,6 +4092,163 @@ var require_run = __commonJS({
|
|
|
4045
4092
|
notable
|
|
4046
4093
|
});
|
|
4047
4094
|
}
|
|
4095
|
+
elapsedMs() {
|
|
4096
|
+
return Math.max(0, Date.now() - this.startedAtMs);
|
|
4097
|
+
}
|
|
4098
|
+
eventClock() {
|
|
4099
|
+
const relativeTimeMs = this.elapsedMs();
|
|
4100
|
+
return {
|
|
4101
|
+
relativeTimeMs,
|
|
4102
|
+
timestamp: this.startedAtMs + relativeTimeMs
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
4105
|
+
startRunTurn(startMs = this.elapsedMs()) {
|
|
4106
|
+
const lastTurn = this.runTurns.at(-1);
|
|
4107
|
+
if (lastTurn && lastTurn.endMs == null) {
|
|
4108
|
+
lastTurn.endMs = Math.max(lastTurn.startMs, startMs);
|
|
4109
|
+
}
|
|
4110
|
+
const id = `run-turn-${++this.runTurnIndex}`;
|
|
4111
|
+
this.runTurns.push({
|
|
4112
|
+
id,
|
|
4113
|
+
startMs
|
|
4114
|
+
});
|
|
4115
|
+
this.currentRunTurnId = id;
|
|
4116
|
+
return id;
|
|
4117
|
+
}
|
|
4118
|
+
ensureRunTurn() {
|
|
4119
|
+
return this.currentRunTurnId ?? this.startRunTurn();
|
|
4120
|
+
}
|
|
4121
|
+
finishRunTurn(endMs = this.elapsedMs()) {
|
|
4122
|
+
const turn = this.currentRunTurnId ? this.runTurns.find((candidate) => candidate.id === this.currentRunTurnId) : this.runTurns.at(-1);
|
|
4123
|
+
if (turn) {
|
|
4124
|
+
turn.endMs = Math.max(turn.startMs, endMs);
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
addTimelineTextEvent(event) {
|
|
4128
|
+
if (event.startsTurn) {
|
|
4129
|
+
this.startRunTurn();
|
|
4130
|
+
}
|
|
4131
|
+
const { relativeTimeMs, timestamp } = this.eventClock();
|
|
4132
|
+
this.timelineEvents.push({
|
|
4133
|
+
type: "text",
|
|
4134
|
+
relativeTimeMs,
|
|
4135
|
+
timestamp,
|
|
4136
|
+
sequenceIndex: ++this.sequenceIndex,
|
|
4137
|
+
runTurnId: this.ensureRunTurn(),
|
|
4138
|
+
tokensIn: event.usage?.inputTokens,
|
|
4139
|
+
tokensOut: event.usage?.outputTokens,
|
|
4140
|
+
cachedTokens: event.usage?.cachedTokens,
|
|
4141
|
+
text: event.text,
|
|
4142
|
+
displaySummary: event.summary
|
|
4143
|
+
});
|
|
4144
|
+
}
|
|
4145
|
+
addTimelineToolEvents(event) {
|
|
4146
|
+
if (event.startsTurn) {
|
|
4147
|
+
this.startRunTurn();
|
|
4148
|
+
}
|
|
4149
|
+
for (let index = 0; index < event.tools.length; index += 1) {
|
|
4150
|
+
const tool = event.tools[index];
|
|
4151
|
+
const includeUsage = index === 0;
|
|
4152
|
+
const { relativeTimeMs, timestamp } = this.eventClock();
|
|
4153
|
+
const timelineEvent = {
|
|
4154
|
+
type: "tool_call",
|
|
4155
|
+
relativeTimeMs,
|
|
4156
|
+
timestamp,
|
|
4157
|
+
sequenceIndex: ++this.sequenceIndex,
|
|
4158
|
+
runTurnId: this.ensureRunTurn(),
|
|
4159
|
+
...includeUsage && event.usage ? {
|
|
4160
|
+
tokensIn: event.usage.inputTokens,
|
|
4161
|
+
tokensOut: event.usage.outputTokens,
|
|
4162
|
+
cachedTokens: event.usage.cachedTokens
|
|
4163
|
+
} : {},
|
|
4164
|
+
toolName: tool.name,
|
|
4165
|
+
callId: tool.id,
|
|
4166
|
+
arguments: normalizeToolInput(tool.input),
|
|
4167
|
+
displaySummary: tool.detail ?? tool.summary,
|
|
4168
|
+
category: getTimelineToolCategory(tool.name)
|
|
4169
|
+
};
|
|
4170
|
+
this.timelineToolEventIndexes.set(tool.id, this.timelineEvents.length);
|
|
4171
|
+
this.timelineEvents.push(timelineEvent);
|
|
4172
|
+
}
|
|
4173
|
+
}
|
|
4174
|
+
completeTimelineToolEvent(event) {
|
|
4175
|
+
const index = this.timelineToolEventIndexes.get(event.toolUseId);
|
|
4176
|
+
if (index == null)
|
|
4177
|
+
return;
|
|
4178
|
+
const existing = this.timelineEvents[index];
|
|
4179
|
+
if (!existing || existing.type !== "tool_call")
|
|
4180
|
+
return;
|
|
4181
|
+
const endMs = this.elapsedMs();
|
|
4182
|
+
existing.status = event.isError ? "failed" : "success";
|
|
4183
|
+
existing.result = {
|
|
4184
|
+
output: event.output,
|
|
4185
|
+
isError: event.isError,
|
|
4186
|
+
durationMs: Math.max(0, endMs - existing.relativeTimeMs)
|
|
4187
|
+
};
|
|
4188
|
+
}
|
|
4189
|
+
buildDebugTimeline() {
|
|
4190
|
+
const events = this.timelineEvents.map((event) => ({
|
|
4191
|
+
...event,
|
|
4192
|
+
result: event.result ? { ...event.result } : void 0,
|
|
4193
|
+
arguments: event.arguments ? { ...event.arguments } : void 0
|
|
4194
|
+
}));
|
|
4195
|
+
const fallbackEndMs = this.execution.durationMs ?? this.elapsedMs();
|
|
4196
|
+
const turns = this.runTurns.length > 0 ? this.runTurns : [{ id: "run-turn-1", startMs: 0, endMs: fallbackEndMs }];
|
|
4197
|
+
const timelineStatus = mapRunStatusToDebugTimelineStatus(this.status);
|
|
4198
|
+
const spans = turns.map((turn) => {
|
|
4199
|
+
const turnEvents = events.filter((event) => event.runTurnId === turn.id);
|
|
4200
|
+
const isOpenTurn = turn.endMs == null && (timelineStatus === "running" || timelineStatus === "pending");
|
|
4201
|
+
const endCandidates = [
|
|
4202
|
+
turn.endMs,
|
|
4203
|
+
isOpenTurn ? fallbackEndMs : void 0,
|
|
4204
|
+
...turnEvents.map((event) => {
|
|
4205
|
+
const duration = event.type === "tool_call" ? event.result?.durationMs ?? 0 : 0;
|
|
4206
|
+
return event.relativeTimeMs + duration;
|
|
4207
|
+
})
|
|
4208
|
+
].filter((value) => typeof value === "number" && Number.isFinite(value));
|
|
4209
|
+
const endMs = Math.max(turn.startMs, endCandidates.length > 0 ? Math.max(...endCandidates) : fallbackEndMs);
|
|
4210
|
+
return {
|
|
4211
|
+
id: turn.id,
|
|
4212
|
+
type: "run_turn",
|
|
4213
|
+
parentId: null,
|
|
4214
|
+
startMs: turn.startMs,
|
|
4215
|
+
endMs,
|
|
4216
|
+
metrics: {
|
|
4217
|
+
tokensIn: turnEvents.reduce((sum, event) => sum + (event.tokensIn ?? 0), 0),
|
|
4218
|
+
tokensOut: turnEvents.reduce((sum, event) => sum + (event.tokensOut ?? 0), 0),
|
|
4219
|
+
cachedTokens: turnEvents.reduce((sum, event) => sum + (event.cachedTokens ?? 0), 0),
|
|
4220
|
+
costUsd: turnEvents.reduce((sum, event) => sum + (event.costUsd ?? 0), 0),
|
|
4221
|
+
toolCallCount: turnEvents.filter((event) => event.type === "tool_call").length,
|
|
4222
|
+
apiCallCount: 1
|
|
4223
|
+
}
|
|
4224
|
+
};
|
|
4225
|
+
});
|
|
4226
|
+
const tokensIn = events.reduce((sum, event) => sum + (event.tokensIn ?? 0), 0);
|
|
4227
|
+
const tokensOut = events.reduce((sum, event) => sum + (event.tokensOut ?? 0), 0);
|
|
4228
|
+
const cachedTokens = events.reduce((sum, event) => sum + (event.cachedTokens ?? 0), 0);
|
|
4229
|
+
return {
|
|
4230
|
+
sessionId: this.debugSessionId,
|
|
4231
|
+
status: timelineStatus,
|
|
4232
|
+
metrics: {
|
|
4233
|
+
durationMs: fallbackEndMs,
|
|
4234
|
+
toolCalls: events.filter((event) => event.type === "tool_call").length,
|
|
4235
|
+
apiCalls: this.execution.numTurns ?? spans.length,
|
|
4236
|
+
tokensIn,
|
|
4237
|
+
tokensOut,
|
|
4238
|
+
cachedTokens,
|
|
4239
|
+
totalCostUsd: this.execution.totalCostUsd ?? events.reduce((sum, event) => sum + (event.costUsd ?? 0), 0),
|
|
4240
|
+
cacheSavingsUsd: 0
|
|
4241
|
+
},
|
|
4242
|
+
prompt: {
|
|
4243
|
+
model: this.model ?? null,
|
|
4244
|
+
claudeSessionId: this.claudeSessionId,
|
|
4245
|
+
timestamp: this.startedAtMs,
|
|
4246
|
+
text: INITIAL_PROMPT
|
|
4247
|
+
},
|
|
4248
|
+
events,
|
|
4249
|
+
spans
|
|
4250
|
+
};
|
|
4251
|
+
}
|
|
4048
4252
|
pushReasoningStep(parentToolUseId, step) {
|
|
4049
4253
|
if (parentToolUseId && this.subagentBuckets.has(parentToolUseId)) {
|
|
4050
4254
|
this.subagentBuckets.get(parentToolUseId).reasoningSteps.push(step);
|
|
@@ -4136,6 +4340,7 @@ var require_run = __commonJS({
|
|
|
4136
4340
|
this.execution.status = "running";
|
|
4137
4341
|
this.currentActivity = event.summary;
|
|
4138
4342
|
this.model = event.model ?? this.model;
|
|
4343
|
+
this.claudeSessionId = event.claudeSessionId ?? this.claudeSessionId;
|
|
4139
4344
|
if (event.recordStep) {
|
|
4140
4345
|
this.addStep("status", event.summary, event.detail);
|
|
4141
4346
|
this.addReasoningText(event.detail ? `${event.summary}
|
|
@@ -4152,6 +4357,9 @@ ${event.detail}` : event.summary);
|
|
|
4152
4357
|
this.execution.status = "running";
|
|
4153
4358
|
this.currentActivity = event.summary;
|
|
4154
4359
|
this.addReasoningText(event.text, event.parentToolUseId);
|
|
4360
|
+
if (!event.parentToolUseId) {
|
|
4361
|
+
this.addTimelineTextEvent(event);
|
|
4362
|
+
}
|
|
4155
4363
|
if (isSubagent && event.tokens != null) {
|
|
4156
4364
|
this.subagentBuckets.get(event.parentToolUseId).totalTokens += event.tokens;
|
|
4157
4365
|
}
|
|
@@ -4179,6 +4387,9 @@ ${event.detail}` : event.summary);
|
|
|
4179
4387
|
this.subagentBuckets.get(event.parentToolUseId).totalToolUseCount += 1;
|
|
4180
4388
|
}
|
|
4181
4389
|
}
|
|
4390
|
+
if (!event.parentToolUseId) {
|
|
4391
|
+
this.addTimelineToolEvents(event);
|
|
4392
|
+
}
|
|
4182
4393
|
if (isSubagent && event.tokens != null) {
|
|
4183
4394
|
this.subagentBuckets.get(event.parentToolUseId).totalTokens += event.tokens;
|
|
4184
4395
|
}
|
|
@@ -4200,6 +4411,9 @@ ${event.detail}` : event.summary);
|
|
|
4200
4411
|
}
|
|
4201
4412
|
case "tool_result":
|
|
4202
4413
|
this.addReasoningToolResult(event.toolUseId, event.output, event.isError, event.parentToolUseId);
|
|
4414
|
+
if (!event.parentToolUseId) {
|
|
4415
|
+
this.completeTimelineToolEvent(event);
|
|
4416
|
+
}
|
|
4203
4417
|
break;
|
|
4204
4418
|
case "status_notice":
|
|
4205
4419
|
this.status = "running";
|
|
@@ -4276,6 +4490,7 @@ ${event.detail}` : event.summary);
|
|
|
4276
4490
|
this.addStep("result", event.summary, event.detail, event.execution.status !== "success");
|
|
4277
4491
|
this.addReasoningText(event.detail ? `${event.summary}
|
|
4278
4492
|
${event.detail}` : event.summary);
|
|
4493
|
+
this.finishRunTurn();
|
|
4279
4494
|
break;
|
|
4280
4495
|
}
|
|
4281
4496
|
return this.snapshot();
|
|
@@ -4300,7 +4515,8 @@ ${event.detail}` : event.summary);
|
|
|
4300
4515
|
this.addReasoningText(detail?.errors?.length ? `${summary}
|
|
4301
4516
|
${detail.errors.join("\n")}` : summary);
|
|
4302
4517
|
}
|
|
4303
|
-
|
|
4518
|
+
this.finishRunTurn();
|
|
4519
|
+
return this.snapshot(true);
|
|
4304
4520
|
}
|
|
4305
4521
|
buildSubagentReasoningById() {
|
|
4306
4522
|
if (this.subagentBuckets.size === 0)
|
|
@@ -4311,19 +4527,23 @@ ${detail.errors.join("\n")}` : summary);
|
|
|
4311
4527
|
}
|
|
4312
4528
|
return result;
|
|
4313
4529
|
}
|
|
4314
|
-
snapshot() {
|
|
4530
|
+
snapshot(includeDebugTimeline = false) {
|
|
4315
4531
|
return {
|
|
4316
4532
|
repoRoot: this.prepared.repoRoot,
|
|
4317
4533
|
mode: this.mode,
|
|
4318
4534
|
model: this.model,
|
|
4319
4535
|
artifactPath: this.prepared.resultPath,
|
|
4320
4536
|
sourceResultPath: this.prepared.resultPath,
|
|
4537
|
+
runDirectory: this.prepared.repoRoot,
|
|
4538
|
+
inputDirectory: (0, node_path_1.join)(this.prepared.repoRoot, "input"),
|
|
4539
|
+
outputDirectory: (0, node_path_1.join)(this.prepared.repoRoot, "output"),
|
|
4321
4540
|
startedAtMs: this.startedAtMs,
|
|
4322
4541
|
status: this.status,
|
|
4323
4542
|
currentActivity: this.currentActivity,
|
|
4324
4543
|
steps: this.steps.map((step) => ({ ...step })),
|
|
4325
4544
|
reasoningMarkup: this.reasoningSteps.join(""),
|
|
4326
4545
|
subagentReasoningById: this.buildSubagentReasoningById(),
|
|
4546
|
+
debugTimeline: includeDebugTimeline ? this.buildDebugTimeline() : void 0,
|
|
4327
4547
|
outputSchema: this.prepared.outputSchema,
|
|
4328
4548
|
activeTools: Array.from(this.activeTools.values()).map((tool) => ({ ...tool })),
|
|
4329
4549
|
execution: {
|
|
@@ -4968,17 +5188,40 @@ Input folder: ${comparableInputRoot}`,
|
|
|
4968
5188
|
return { stagedPath };
|
|
4969
5189
|
}
|
|
4970
5190
|
function createInitialRunSnapshot(prepared, mode = prepared.config.isMultiturn ? "chat" : "one-shot") {
|
|
5191
|
+
const startedAtMs = Date.now();
|
|
4971
5192
|
return {
|
|
4972
5193
|
repoRoot: prepared.repoRoot,
|
|
4973
5194
|
mode,
|
|
4974
5195
|
model: prepared.config.model,
|
|
4975
5196
|
artifactPath: prepared.resultPath,
|
|
4976
5197
|
sourceResultPath: prepared.resultPath,
|
|
4977
|
-
startedAtMs
|
|
5198
|
+
startedAtMs,
|
|
4978
5199
|
status: "starting",
|
|
4979
5200
|
currentActivity: mode === "chat" ? "Preparing Claude chat handoff\u2026" : "Validating repository contract\u2026",
|
|
4980
5201
|
steps: [],
|
|
4981
5202
|
reasoningMarkup: "",
|
|
5203
|
+
debugTimeline: {
|
|
5204
|
+
sessionId: (0, node_crypto_1.randomUUID)(),
|
|
5205
|
+
status: "pending",
|
|
5206
|
+
metrics: {
|
|
5207
|
+
durationMs: 0,
|
|
5208
|
+
toolCalls: 0,
|
|
5209
|
+
apiCalls: 0,
|
|
5210
|
+
tokensIn: 0,
|
|
5211
|
+
tokensOut: 0,
|
|
5212
|
+
cachedTokens: 0,
|
|
5213
|
+
totalCostUsd: 0,
|
|
5214
|
+
cacheSavingsUsd: 0
|
|
5215
|
+
},
|
|
5216
|
+
prompt: {
|
|
5217
|
+
model: prepared.config.model ?? null,
|
|
5218
|
+
claudeSessionId: null,
|
|
5219
|
+
timestamp: startedAtMs,
|
|
5220
|
+
text: INITIAL_PROMPT
|
|
5221
|
+
},
|
|
5222
|
+
events: [],
|
|
5223
|
+
spans: []
|
|
5224
|
+
},
|
|
4982
5225
|
outputSchema: prepared.outputSchema,
|
|
4983
5226
|
activeTools: [],
|
|
4984
5227
|
execution: {
|
|
@@ -5143,6 +5386,8 @@ Input folder: ${comparableInputRoot}`,
|
|
|
5143
5386
|
execution: input.execution,
|
|
5144
5387
|
steps: input.snapshot.steps,
|
|
5145
5388
|
reasoningMarkup: input.snapshot.reasoningMarkup,
|
|
5389
|
+
subagentReasoningById: input.snapshot.subagentReasoningById,
|
|
5390
|
+
debugTimeline: input.snapshot.debugTimeline,
|
|
5146
5391
|
inputs: input.inputs
|
|
5147
5392
|
}), "utf-8");
|
|
5148
5393
|
} catch (error) {
|
|
@@ -5299,6 +5544,7 @@ Input folder: ${comparableInputRoot}`,
|
|
|
5299
5544
|
steps: snapshot.steps,
|
|
5300
5545
|
reasoningMarkup: snapshot.reasoningMarkup,
|
|
5301
5546
|
subagentReasoningById: snapshot.subagentReasoningById,
|
|
5547
|
+
debugTimeline: snapshot.debugTimeline,
|
|
5302
5548
|
outputSchema: prepared.outputSchema,
|
|
5303
5549
|
artifact: {
|
|
5304
5550
|
path: archived.resultPath,
|
|
@@ -5362,7 +5608,7 @@ Input folder: ${comparableInputRoot}`,
|
|
|
5362
5608
|
const notifySnapshot = (snapshot2) => {
|
|
5363
5609
|
options.onSnapshot?.(snapshot2);
|
|
5364
5610
|
};
|
|
5365
|
-
notifySnapshot(tracker.snapshot());
|
|
5611
|
+
notifySnapshot(tracker.snapshot(true));
|
|
5366
5612
|
if (options.surface === "plain") {
|
|
5367
5613
|
writeLine2(options.writeStdout, "Streaming Claude execution in one-shot mode.");
|
|
5368
5614
|
}
|
|
@@ -5405,6 +5651,12 @@ Input folder: ${comparableInputRoot}`,
|
|
|
5405
5651
|
}
|
|
5406
5652
|
}
|
|
5407
5653
|
});
|
|
5654
|
+
const liveDebugSnapshotTimer = setInterval(() => {
|
|
5655
|
+
const snapshot2 = tracker.snapshot(true);
|
|
5656
|
+
if (snapshot2.status === "running" || snapshot2.status === "starting") {
|
|
5657
|
+
notifySnapshot(snapshot2);
|
|
5658
|
+
}
|
|
5659
|
+
}, LIVE_DEBUG_SNAPSHOT_INTERVAL_MS);
|
|
5408
5660
|
options.onControl?.({
|
|
5409
5661
|
interrupt() {
|
|
5410
5662
|
cancelled = true;
|
|
@@ -5415,8 +5667,13 @@ Input folder: ${comparableInputRoot}`,
|
|
|
5415
5667
|
handle.kill();
|
|
5416
5668
|
}
|
|
5417
5669
|
});
|
|
5418
|
-
|
|
5419
|
-
|
|
5670
|
+
let result;
|
|
5671
|
+
try {
|
|
5672
|
+
result = await handle.result;
|
|
5673
|
+
} finally {
|
|
5674
|
+
clearInterval(liveDebugSnapshotTimer);
|
|
5675
|
+
}
|
|
5676
|
+
let snapshot = tracker.snapshot(true);
|
|
5420
5677
|
if (result.exitCode !== 0) {
|
|
5421
5678
|
if (cancelled) {
|
|
5422
5679
|
snapshot = tracker.finalize("cancelled", {
|
|
@@ -5485,7 +5742,7 @@ Input folder: ${comparableInputRoot}`,
|
|
|
5485
5742
|
snapshot = await runOneShotAgent(prepared, effectiveOptions, tracker, claudeLaunch);
|
|
5486
5743
|
}
|
|
5487
5744
|
} catch (error) {
|
|
5488
|
-
let terminalSnapshot = tracker.snapshot();
|
|
5745
|
+
let terminalSnapshot = tracker.snapshot(true);
|
|
5489
5746
|
let archiveFailureWarning;
|
|
5490
5747
|
if (error instanceof process_1.CommandError && terminalSnapshot.execution.status !== "failed" && terminalSnapshot.execution.status !== "cancelled") {
|
|
5491
5748
|
terminalSnapshot = tracker.finalize("failed", {
|
|
@@ -5913,8 +6170,7 @@ var require_setup = __commonJS({
|
|
|
5913
6170
|
environmentId: options.environmentId,
|
|
5914
6171
|
workspace: options.workspace,
|
|
5915
6172
|
credentials: options.credentials,
|
|
5916
|
-
env: options.env
|
|
5917
|
-
requireDirectAgentService: true
|
|
6173
|
+
env: options.env
|
|
5918
6174
|
});
|
|
5919
6175
|
if (!config.contextId) {
|
|
5920
6176
|
throw new Error("Agent setup requires a resolved Tela context.");
|
|
@@ -6028,8 +6284,7 @@ var require_setup = __commonJS({
|
|
|
6028
6284
|
const config = await (0, config_1.resolveAgentConfig)({
|
|
6029
6285
|
contextId: input.contextId,
|
|
6030
6286
|
credentials,
|
|
6031
|
-
env: options.env
|
|
6032
|
-
requireDirectAgentService: true
|
|
6287
|
+
env: options.env
|
|
6033
6288
|
});
|
|
6034
6289
|
const organizations = await (0, agent_api_1.listOrganizations)(config, options.fetchFn);
|
|
6035
6290
|
const organization = organizations.find((item) => item.id === input.organizationId);
|
|
@@ -6965,7 +7220,7 @@ var require_dist2 = __commonJS({
|
|
|
6965
7220
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
6966
7221
|
};
|
|
6967
7222
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6968
|
-
exports2.ensureConfigInteractive = exports2.resolveAgentConfig = exports2.
|
|
7223
|
+
exports2.ensureConfigInteractive = exports2.resolveAgentConfig = exports2.getDefaultAgentCloneRoot = void 0;
|
|
6969
7224
|
__exportStar(require_agent_api(), exports2);
|
|
6970
7225
|
__exportStar(require_auth2(), exports2);
|
|
6971
7226
|
__exportStar(require_claude(), exports2);
|
|
@@ -6978,9 +7233,6 @@ var require_dist2 = __commonJS({
|
|
|
6978
7233
|
Object.defineProperty(exports2, "getDefaultAgentCloneRoot", { enumerable: true, get: function() {
|
|
6979
7234
|
return config_1.getDefaultAgentCloneRoot;
|
|
6980
7235
|
} });
|
|
6981
|
-
Object.defineProperty(exports2, "isDirectAgentApiUrl", { enumerable: true, get: function() {
|
|
6982
|
-
return config_1.isDirectAgentApiUrl;
|
|
6983
|
-
} });
|
|
6984
7236
|
Object.defineProperty(exports2, "resolveAgentConfig", { enumerable: true, get: function() {
|
|
6985
7237
|
return config_1.resolveAgentConfig;
|
|
6986
7238
|
} });
|