@codelia/runtime 0.1.91 → 0.1.93
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/{chunk-X4222JDX.js → chunk-K42SQONI.js} +265 -36
- package/dist/{chunk-EC2N4PCP.js → chunk-OQGZHVYU.js} +781 -627
- package/dist/index.cjs +1036 -661
- package/dist/index.js +2 -2
- package/dist/sdk.cjs +1036 -661
- package/dist/sdk.d.cts +2 -0
- package/dist/sdk.d.ts +2 -0
- package/dist/sdk.js +2 -2
- package/dist/subagents/child-entry.cjs +273 -20
- package/dist/subagents/child-entry.js +1 -1
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -91,25 +91,6 @@ var toTrimmed = (value) => {
|
|
|
91
91
|
const trimmed = value.trim();
|
|
92
92
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
93
93
|
};
|
|
94
|
-
var parseBoolean = (value) => {
|
|
95
|
-
const normalized = toTrimmed(value)?.toLowerCase();
|
|
96
|
-
if (!normalized) return void 0;
|
|
97
|
-
if (normalized === "1" || normalized === "true") return true;
|
|
98
|
-
if (normalized === "0" || normalized === "false") return false;
|
|
99
|
-
return void 0;
|
|
100
|
-
};
|
|
101
|
-
var parsePositiveInt = (value) => {
|
|
102
|
-
const normalized = toTrimmed(value);
|
|
103
|
-
if (!normalized) return void 0;
|
|
104
|
-
const parsed = Number.parseInt(normalized, 10);
|
|
105
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
|
|
106
|
-
};
|
|
107
|
-
var parseMarkers = (value) => {
|
|
108
|
-
const normalized = toTrimmed(value);
|
|
109
|
-
if (!normalized) return void 0;
|
|
110
|
-
const markers = normalized.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
111
|
-
return markers.length > 0 ? markers : void 0;
|
|
112
|
-
};
|
|
113
94
|
var exists = async (targetPath) => {
|
|
114
95
|
try {
|
|
115
96
|
await import_node_fs.promises.access(targetPath);
|
|
@@ -180,37 +161,12 @@ var findRootByMarkers = async (workingDir, markers, stopAtFsRoot, reader) => {
|
|
|
180
161
|
}
|
|
181
162
|
};
|
|
182
163
|
var mergeConfig = (config, env = process.env) => {
|
|
183
|
-
const
|
|
184
|
-
enabled: parseBoolean(env.CODELIA_AGENTS_ENABLED),
|
|
185
|
-
root: {
|
|
186
|
-
projectRootOverride: toTrimmed(env.CODELIA_AGENTS_ROOT),
|
|
187
|
-
markers: parseMarkers(env.CODELIA_AGENTS_MARKERS)
|
|
188
|
-
},
|
|
189
|
-
initial: {
|
|
190
|
-
maxFiles: parsePositiveInt(env.CODELIA_AGENTS_INITIAL_MAX_FILES),
|
|
191
|
-
maxBytes: parsePositiveInt(env.CODELIA_AGENTS_INITIAL_MAX_BYTES)
|
|
192
|
-
},
|
|
193
|
-
resolver: {
|
|
194
|
-
enabled: parseBoolean(env.CODELIA_AGENTS_RESOLVER_ENABLED),
|
|
195
|
-
maxFilesPerResolve: parsePositiveInt(
|
|
196
|
-
env.CODELIA_AGENTS_MAX_FILES_PER_RESOLVE
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
|
-
});
|
|
164
|
+
const rootOverride = toTrimmed(env.CODELIA_AGENTS_ROOT);
|
|
200
165
|
const merged = AgentsConfigSchema.parse({
|
|
201
166
|
...config ?? {},
|
|
202
|
-
...envConfig,
|
|
203
167
|
root: {
|
|
204
168
|
...config?.root ?? {},
|
|
205
|
-
...
|
|
206
|
-
},
|
|
207
|
-
initial: {
|
|
208
|
-
...config?.initial ?? {},
|
|
209
|
-
...envConfig.initial ?? {}
|
|
210
|
-
},
|
|
211
|
-
resolver: {
|
|
212
|
-
...config?.resolver ?? {},
|
|
213
|
-
...envConfig.resolver ?? {}
|
|
169
|
+
...rootOverride ? { projectRootOverride: rootOverride } : {}
|
|
214
170
|
}
|
|
215
171
|
});
|
|
216
172
|
return {
|
|
@@ -427,14 +383,14 @@ var readBrowserMode = (value) => {
|
|
|
427
383
|
return null;
|
|
428
384
|
};
|
|
429
385
|
var hasSshSession = (env) => !!env.SSH_CONNECTION || !!env.SSH_CLIENT || !!env.SSH_TTY;
|
|
430
|
-
var resolveOAuthBrowserMode = (env = process.env) => {
|
|
431
|
-
const configured = readBrowserMode(
|
|
386
|
+
var resolveOAuthBrowserMode = (configuredMode, env = process.env) => {
|
|
387
|
+
const configured = readBrowserMode(configuredMode);
|
|
432
388
|
if (configured) {
|
|
433
389
|
return configured;
|
|
434
390
|
}
|
|
435
391
|
return hasSshSession(env) ? "manual" : "auto";
|
|
436
392
|
};
|
|
437
|
-
var shouldAutoOpenOAuthBrowser = (env = process.env) => resolveOAuthBrowserMode(env) === "auto";
|
|
393
|
+
var shouldAutoOpenOAuthBrowser = (configuredMode, env = process.env) => resolveOAuthBrowserMode(configuredMode, env) === "auto";
|
|
438
394
|
var parseCallbackParams = (input) => {
|
|
439
395
|
const trimmed = input.trim();
|
|
440
396
|
if (!trimmed) {
|
|
@@ -612,7 +568,7 @@ var OPENAI_OAUTH_ORIGINATOR = "codelia";
|
|
|
612
568
|
var OPENAI_OAUTH_USER_AGENT = "codelia-cli";
|
|
613
569
|
var HTML_SUCCESS = "<!doctype html><html><head><title>codelia - Authorization successful</title></head><body><h2>Authorization successful</h2><p>You can close this window.</p></body></html>";
|
|
614
570
|
var HTML_ERROR = (message) => `<!doctype html><html><head><title>codelia - Authorization failed</title></head><body><h2>Authorization failed</h2><pre>${message}</pre></body></html>`;
|
|
615
|
-
var clientId = () =>
|
|
571
|
+
var clientId = () => DEFAULT_CLIENT_ID;
|
|
616
572
|
var oauthPort = () => readPositiveIntEnv("CODELIA_OPENAI_OAUTH_PORT", DEFAULT_PORT);
|
|
617
573
|
var buildAuthorizeUrl = (redirectUri, pkce, state) => {
|
|
618
574
|
const params = new URLSearchParams({
|
|
@@ -929,9 +885,21 @@ var resolveTuiConfig = async (workingDir) => {
|
|
|
929
885
|
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
930
886
|
const effective = import_config.configRegistry.resolve([globalConfig, projectConfig]);
|
|
931
887
|
return {
|
|
932
|
-
theme: effective.tui
|
|
888
|
+
...effective.tui?.theme ? { theme: effective.tui.theme } : {},
|
|
889
|
+
...effective.tui?.color_scheme ? { color_scheme: effective.tui.color_scheme } : {},
|
|
890
|
+
...effective.tui?.image_protocol ? { image_protocol: effective.tui.image_protocol } : {}
|
|
933
891
|
};
|
|
934
892
|
};
|
|
893
|
+
var resolveAgentsEnabled = async (workingDir) => {
|
|
894
|
+
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
895
|
+
const effective = import_config.configRegistry.resolve([globalConfig, projectConfig]);
|
|
896
|
+
return effective.agents?.enabled ?? true;
|
|
897
|
+
};
|
|
898
|
+
var resolveAuthOAuthBrowser = async (workingDir) => {
|
|
899
|
+
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
900
|
+
const effective = import_config.configRegistry.resolve([globalConfig, projectConfig]);
|
|
901
|
+
return effective.auth?.oauth_browser;
|
|
902
|
+
};
|
|
935
903
|
var resolvePermissionsConfig = async (workingDir) => {
|
|
936
904
|
const { globalConfig, projectConfig } = await loadConfigLayers(workingDir);
|
|
937
905
|
const effective = import_config.configRegistry.resolve([globalConfig, projectConfig]);
|
|
@@ -1112,7 +1080,7 @@ var hasDefinedGroup = (group, value) => {
|
|
|
1112
1080
|
case "permissions":
|
|
1113
1081
|
return Array.isArray(value?.permissions?.allow) || Array.isArray(value?.permissions?.deny);
|
|
1114
1082
|
case "tui":
|
|
1115
|
-
return typeof value?.tui?.theme === "string" && value.tui.theme.trim().length > 0;
|
|
1083
|
+
return typeof value?.tui?.theme === "string" && value.tui.theme.trim().length > 0 || value?.tui?.color_scheme !== void 0 || value?.tui?.image_protocol !== void 0;
|
|
1116
1084
|
default:
|
|
1117
1085
|
return false;
|
|
1118
1086
|
}
|
|
@@ -1919,6 +1887,8 @@ var sendNotificationAsync = async (state, notify) => {
|
|
|
1919
1887
|
}
|
|
1920
1888
|
await sendAsync(notify);
|
|
1921
1889
|
};
|
|
1890
|
+
var transportBackpressureEvents = 0;
|
|
1891
|
+
var getTransportBackpressureEvents = () => transportBackpressureEvents;
|
|
1922
1892
|
var send = (msg) => {
|
|
1923
1893
|
const { payload, label } = serializeMessage(msg);
|
|
1924
1894
|
const writable = process.stdout.write(payload, (error) => {
|
|
@@ -1927,6 +1897,7 @@ var send = (msg) => {
|
|
|
1927
1897
|
}
|
|
1928
1898
|
});
|
|
1929
1899
|
if (!writable) {
|
|
1900
|
+
transportBackpressureEvents += 1;
|
|
1930
1901
|
(0, import_logger.debugLog)(`transport.backpressure label=${label} bytes=${payload.length}`);
|
|
1931
1902
|
}
|
|
1932
1903
|
};
|
|
@@ -1941,6 +1912,7 @@ var sendAsync = async (msg) => new Promise((resolve) => {
|
|
|
1941
1912
|
resolve();
|
|
1942
1913
|
});
|
|
1943
1914
|
if (!writable) {
|
|
1915
|
+
transportBackpressureEvents += 1;
|
|
1944
1916
|
(0, import_logger.debugLog)(`transport.backpressure label=${label} bytes=${payload.length}`);
|
|
1945
1917
|
}
|
|
1946
1918
|
});
|
|
@@ -1990,12 +1962,12 @@ var sendRunContext = (state, runId, contextLeftPercent) => {
|
|
|
1990
1962
|
})
|
|
1991
1963
|
);
|
|
1992
1964
|
};
|
|
1993
|
-
var sendRunDiagnostics = (state, params) => {
|
|
1994
|
-
sendNotification(state, notificationMessage("run.diagnostics", params));
|
|
1995
|
-
};
|
|
1996
1965
|
var sendRunMetrics = (state, params) => {
|
|
1997
1966
|
sendNotification(state, notificationMessage("run.metrics", params));
|
|
1998
1967
|
};
|
|
1968
|
+
var sendRunSummary = (state, params) => {
|
|
1969
|
+
sendNotification(state, notificationMessage("run.summary", params));
|
|
1970
|
+
};
|
|
1999
1971
|
|
|
2000
1972
|
// src/rpc/protocol.ts
|
|
2001
1973
|
var MAX_ISSUES = 10;
|
|
@@ -2011,8 +1983,18 @@ var schemaFor = (method, slot) => {
|
|
|
2011
1983
|
throw new Error(`${method} is a notification without a result`);
|
|
2012
1984
|
return spec.result;
|
|
2013
1985
|
};
|
|
1986
|
+
var cachedProtocolAssertRaw;
|
|
1987
|
+
var cachedProtocolAssertEnabled = false;
|
|
1988
|
+
var isProtocolAssertEnabled = () => {
|
|
1989
|
+
const raw = process.env.CODELIA_TEST_PROTOCOL_ASSERT;
|
|
1990
|
+
if (raw !== cachedProtocolAssertRaw) {
|
|
1991
|
+
cachedProtocolAssertRaw = raw;
|
|
1992
|
+
cachedProtocolAssertEnabled = raw === "1";
|
|
1993
|
+
}
|
|
1994
|
+
return cachedProtocolAssertEnabled;
|
|
1995
|
+
};
|
|
2014
1996
|
var assertOutgoing = (method, slot, value) => {
|
|
2015
|
-
if (
|
|
1997
|
+
if (!isProtocolAssertEnabled()) return;
|
|
2016
1998
|
const result = schemaFor(method, slot).safeParse(value);
|
|
2017
1999
|
if (!result.success)
|
|
2018
2000
|
throw new Error(
|
|
@@ -2131,11 +2113,8 @@ var DEFAULT_CLIENT_ID2 = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
|
2131
2113
|
var ISSUER2 = "https://auth.openai.com";
|
|
2132
2114
|
var DEFAULT_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
2133
2115
|
var DEFAULT_INTERVAL_SECONDS = 5;
|
|
2134
|
-
var clientId2 = () =>
|
|
2135
|
-
var deviceCodeTimeoutMs = () =>
|
|
2136
|
-
"CODELIA_OPENAI_DEVICE_CODE_TIMEOUT_MS",
|
|
2137
|
-
DEFAULT_TIMEOUT_MS
|
|
2138
|
-
);
|
|
2116
|
+
var clientId2 = () => DEFAULT_CLIENT_ID2;
|
|
2117
|
+
var deviceCodeTimeoutMs = () => DEFAULT_TIMEOUT_MS;
|
|
2139
2118
|
var cancelledError = () => new Error("device code login cancelled");
|
|
2140
2119
|
var sleep = (ms, signal) => new Promise((resolve, reject2) => {
|
|
2141
2120
|
if (signal?.aborted) {
|
|
@@ -2788,7 +2767,10 @@ var AuthResolver = class _AuthResolver {
|
|
|
2788
2767
|
if (!supportsPick || !supportsPrompt) {
|
|
2789
2768
|
throw new Error("UI does not support auth prompts");
|
|
2790
2769
|
}
|
|
2791
|
-
const
|
|
2770
|
+
const configuredBrowser = await resolveAuthOAuthBrowser(
|
|
2771
|
+
this.state.runtimeWorkingDir ?? void 0
|
|
2772
|
+
).catch(() => void 0);
|
|
2773
|
+
const prefersDeviceCode = resolveOAuthBrowserMode(configuredBrowser) === "manual";
|
|
2792
2774
|
const pick = await requestUiPick(this.state, {
|
|
2793
2775
|
title: "How would you like to connect OpenAI?",
|
|
2794
2776
|
items: prefersDeviceCode ? [
|
|
@@ -2847,7 +2829,10 @@ var AuthResolver = class _AuthResolver {
|
|
|
2847
2829
|
throw new Error("UI does not support device code confirmation");
|
|
2848
2830
|
}
|
|
2849
2831
|
const session = await createOpenAiDeviceCodeSession();
|
|
2850
|
-
const
|
|
2832
|
+
const configuredBrowser = await resolveAuthOAuthBrowser(
|
|
2833
|
+
this.state.runtimeWorkingDir ?? void 0
|
|
2834
|
+
).catch(() => void 0);
|
|
2835
|
+
const shouldAutoOpen = shouldAutoOpenOAuthBrowser(configuredBrowser);
|
|
2851
2836
|
const confirm = await requestUiConfirm(this.state, {
|
|
2852
2837
|
title: "OpenAI device code",
|
|
2853
2838
|
message: [
|
|
@@ -2890,7 +2875,10 @@ var AuthResolver = class _AuthResolver {
|
|
|
2890
2875
|
if (!supportsConfirm) {
|
|
2891
2876
|
throw new Error("UI does not support OAuth confirmation");
|
|
2892
2877
|
}
|
|
2893
|
-
const
|
|
2878
|
+
const configuredBrowser = await resolveAuthOAuthBrowser(
|
|
2879
|
+
this.state.runtimeWorkingDir ?? void 0
|
|
2880
|
+
).catch(() => void 0);
|
|
2881
|
+
const shouldAutoOpen = shouldAutoOpenOAuthBrowser(configuredBrowser);
|
|
2894
2882
|
const canPasteCallback = !shouldAutoOpen && supportsPrompt;
|
|
2895
2883
|
const session = await createOAuthSession({
|
|
2896
2884
|
callbackMode: canPasteCallback ? "paste" : "server"
|
|
@@ -4762,6 +4750,14 @@ var ApprovalDispatcher = class {
|
|
|
4762
4750
|
return failure2?.outcome;
|
|
4763
4751
|
}
|
|
4764
4752
|
dispatch(options) {
|
|
4753
|
+
const nowMs = this.options.monotonicNow ?? (() => performance.now());
|
|
4754
|
+
const approvalStartedAt = options.onApprovalWaitMs ? nowMs() : 0;
|
|
4755
|
+
let approvalRecorded = false;
|
|
4756
|
+
const recordApprovalWait = () => {
|
|
4757
|
+
if (approvalRecorded || !options.onApprovalWaitMs) return;
|
|
4758
|
+
approvalRecorded = true;
|
|
4759
|
+
options.onApprovalWaitMs(Math.max(0, nowMs() - approvalStartedAt));
|
|
4760
|
+
};
|
|
4765
4761
|
const request = Object.freeze({ ...options.request });
|
|
4766
4762
|
const { id: id2, ...binding } = request;
|
|
4767
4763
|
const receiptBinding = options.deduplicate ? digest(binding) : void 0;
|
|
@@ -4772,286 +4768,292 @@ var ApprovalDispatcher = class {
|
|
|
4772
4768
|
...options.signal ? [options.signal] : []
|
|
4773
4769
|
]) : options.signal;
|
|
4774
4770
|
const dispatch = async () => {
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4771
|
+
try {
|
|
4772
|
+
const facts = options.evaluate();
|
|
4773
|
+
const route = freezeRoute(routeApproval(facts));
|
|
4774
|
+
let actor = facts.confinedAutoLaunch && route.kind === "immediate" ? "sandbox" : "rule";
|
|
4775
|
+
const audit = (state, reason, taskId, diagnostic) => this.options.audit?.({
|
|
4776
|
+
requestId: id2,
|
|
4777
|
+
origin: request.origin,
|
|
4778
|
+
subject: request.subject,
|
|
4779
|
+
route: route.kind,
|
|
4780
|
+
profile: route.profile,
|
|
4781
|
+
actor,
|
|
4782
|
+
state,
|
|
4783
|
+
reason,
|
|
4784
|
+
...diagnostic ? { reviewDiagnostic: diagnostic } : {},
|
|
4785
|
+
at: Date.now(),
|
|
4786
|
+
...taskId ? { taskId } : {},
|
|
4787
|
+
...request.runId ? { runId: request.runId } : {}
|
|
4788
|
+
});
|
|
4789
|
+
if (route.kind === "deny") {
|
|
4790
|
+
audit("denied", route.reason);
|
|
4791
|
+
return reject(route.reason);
|
|
4792
|
+
}
|
|
4793
|
+
const expire = (reason, diagnostic) => {
|
|
4794
|
+
audit("expired", reason, void 0, diagnostic);
|
|
4795
|
+
return reject(
|
|
4796
|
+
diagnostic ? `${reason}: ${reviewDiagnosticText(diagnostic)}` : reason
|
|
4797
|
+
);
|
|
4798
|
+
};
|
|
4799
|
+
const checkCurrent = (reviewing = false) => {
|
|
4800
|
+
if (requestSignal?.aborted || !options.stillCurrent()) {
|
|
4801
|
+
expire(
|
|
4802
|
+
"approval_expired",
|
|
4803
|
+
reviewing ? reviewDiagnostic(
|
|
4804
|
+
requestSignal?.aborted ? "review_cancelled" : "review_authority_changed"
|
|
4805
|
+
) : void 0
|
|
4806
|
+
);
|
|
4807
|
+
}
|
|
4808
|
+
};
|
|
4809
|
+
checkCurrent();
|
|
4810
|
+
const unsandboxedEscalation = route.profile === "full-access" && route.additional.length === 1 && isUnsandboxedShellResource(route.additional[0]);
|
|
4811
|
+
const interactive = options.interactiveShell && request.subject === "shell" && (request.origin === "parent_agent" || request.origin === "operator") && ((route.profile === "development" || route.profile === "investigation") && !route.additional.length || unsandboxedEscalation) && this.options.confirmation?.confirm && this.options.confirmation.available?.() !== false ? options.interactiveShell : void 0;
|
|
4812
|
+
if (route.kind === "defer" && !interactive) {
|
|
4813
|
+
const diagnostic = options.reviewCoverageDiagnostic ?? reviewDiagnostic("review_evidence_unavailable");
|
|
4814
|
+
audit("denied", "review_evidence_unavailable", void 0, diagnostic);
|
|
4815
|
+
return rejectLocalReview(
|
|
4816
|
+
"review_evidence_unavailable",
|
|
4817
|
+
void 0,
|
|
4818
|
+
diagnostic
|
|
4809
4819
|
);
|
|
4810
4820
|
}
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
request.authorityVersion,
|
|
4821
|
+
let save = options.save;
|
|
4822
|
+
let saveScope;
|
|
4823
|
+
let sessionGrant;
|
|
4824
|
+
const version = route.kind === "review" ? this.options.review?.reviewVersion?.(request) : void 0;
|
|
4825
|
+
if (route.kind !== "immediate") {
|
|
4826
|
+
const retryKey = facts.autoReview && route.kind === "review" ? (0, import_node_crypto4.createHash)("sha256").update(
|
|
4827
|
+
JSON.stringify([
|
|
4828
|
+
request.owner,
|
|
4829
|
+
request.intentVersion,
|
|
4830
|
+
request.authorityVersion,
|
|
4831
|
+
version,
|
|
4832
|
+
options.reviewRetryKey ?? digest(binding)
|
|
4833
|
+
])
|
|
4834
|
+
).digest("hex") : void 0;
|
|
4835
|
+
const evidenceKey = retryKey === void 0 ? void 0 : `${retryKey}/${options.reviewRetryEvidenceKey ?? ""}`;
|
|
4836
|
+
const now = this.options.monotonicNow ?? (() => performance.now());
|
|
4837
|
+
const cachedFailure = retryKey === void 0 || evidenceKey === void 0 ? void 0 : this.reviewFailure(retryKey, now()) ?? this.reviewFailure(evidenceKey, now());
|
|
4838
|
+
let reviewReason;
|
|
4839
|
+
const reviewResult = cachedFailure ?? (route.kind === "review" ? await this.review(
|
|
4840
|
+
request,
|
|
4841
|
+
retryKey ?? receiptBinding ?? digest(binding),
|
|
4842
|
+
facts.reviewCategory,
|
|
4834
4843
|
version,
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
const decision = typeof outcome === "object" ? outcome.fallback : outcome;
|
|
4857
|
-
const failureDetails = typeof outcome === "object" && outcome.fallback !== "ask_user" ? outcome : void 0;
|
|
4858
|
-
const diagnostic = failureDetails?.diagnostic;
|
|
4859
|
-
const confirmationCause = failureDetails?.oneTimeConfirmation;
|
|
4860
|
-
const manualPrivacyFallback = confirmationCause === "private_evidence";
|
|
4861
|
-
const manualInconclusiveFallback = facts.autoReview === true && confirmationCause === "inconclusive";
|
|
4862
|
-
const oneTimeConfirmation = manualPrivacyFallback || manualInconclusiveFallback;
|
|
4863
|
-
if (confirmationCause === "inconclusive" || decision === "allow_once" || decision === "deny" || diagnostic && decision !== "review_evidence_unavailable" && diagnostic.code !== "review_preparation_failed")
|
|
4864
|
-
actor = "review";
|
|
4865
|
-
checkCurrent(route.kind === "review");
|
|
4866
|
-
if (interactive && diagnostic && (diagnostic.code === "review_cancelled" || diagnostic.code === "review_authority_changed")) {
|
|
4867
|
-
return expire("approval_expired", diagnostic);
|
|
4868
|
-
}
|
|
4869
|
-
if (decision === "deny" && !interactive) {
|
|
4870
|
-
audit("denied", "review_denied");
|
|
4871
|
-
return facts.autoReview ? rejectLocalReview("deny") : reject("review_denied");
|
|
4872
|
-
}
|
|
4873
|
-
if (retryKey !== void 0 && evidenceKey !== void 0 && outcome !== "allow_once" && outcome !== "deny" && !manualPrivacyFallback) {
|
|
4874
|
-
if (!cachedFailure) {
|
|
4875
|
-
if (this.localReviewFailures.size >= 256) {
|
|
4876
|
-
const oldest = this.localReviewFailures.keys().next().value;
|
|
4877
|
-
if (oldest !== void 0) this.localReviewFailures.delete(oldest);
|
|
4878
|
-
}
|
|
4879
|
-
const failureKey = decision === "review_unavailable" || decision === "review_not_delegated" ? retryKey : evidenceKey;
|
|
4880
|
-
this.localReviewFailures.set(failureKey, {
|
|
4881
|
-
outcome,
|
|
4882
|
-
...decision === "review_unavailable" ? { expiresAt: now() + 15e3 } : {}
|
|
4883
|
-
});
|
|
4844
|
+
requestSignal,
|
|
4845
|
+
interactive ? (reason) => {
|
|
4846
|
+
reviewReason = reason;
|
|
4847
|
+
} : void 0
|
|
4848
|
+
) : route.kind === "defer" ? failure(
|
|
4849
|
+
"review_evidence_unavailable",
|
|
4850
|
+
options.reviewCoverageDiagnostic ?? reviewDiagnostic("review_evidence_unavailable")
|
|
4851
|
+
) : { fallback: "ask_user", missing: "unspecified" });
|
|
4852
|
+
const outcome = facts.autoReview && route.kind === "review" && typeof reviewResult === "object" && reviewResult.fallback === "ask_user" && reviewResult.missing === "unspecified" ? failure("review_inconclusive") : reviewResult;
|
|
4853
|
+
const decision = typeof outcome === "object" ? outcome.fallback : outcome;
|
|
4854
|
+
const failureDetails = typeof outcome === "object" && outcome.fallback !== "ask_user" ? outcome : void 0;
|
|
4855
|
+
const diagnostic = failureDetails?.diagnostic;
|
|
4856
|
+
const confirmationCause = failureDetails?.oneTimeConfirmation;
|
|
4857
|
+
const manualPrivacyFallback = confirmationCause === "private_evidence";
|
|
4858
|
+
const manualInconclusiveFallback = facts.autoReview === true && confirmationCause === "inconclusive";
|
|
4859
|
+
const oneTimeConfirmation = manualPrivacyFallback || manualInconclusiveFallback;
|
|
4860
|
+
if (confirmationCause === "inconclusive" || decision === "allow_once" || decision === "deny" || diagnostic && decision !== "review_evidence_unavailable" && diagnostic.code !== "review_preparation_failed")
|
|
4861
|
+
actor = "review";
|
|
4862
|
+
checkCurrent(route.kind === "review");
|
|
4863
|
+
if (interactive && diagnostic && (diagnostic.code === "review_cancelled" || diagnostic.code === "review_authority_changed")) {
|
|
4864
|
+
return expire("approval_expired", diagnostic);
|
|
4884
4865
|
}
|
|
4885
|
-
if (
|
|
4886
|
-
audit(
|
|
4887
|
-
|
|
4888
|
-
decision === "ask_user" ? "review_user_decision_required" : decision,
|
|
4889
|
-
void 0,
|
|
4890
|
-
diagnostic
|
|
4891
|
-
);
|
|
4892
|
-
return outcome.fallback === "ask_user" ? rejectLocalReview("ask_user", outcome.missing) : rejectLocalReview(outcome.fallback, void 0, diagnostic);
|
|
4866
|
+
if (decision === "deny" && !interactive) {
|
|
4867
|
+
audit("denied", "review_denied");
|
|
4868
|
+
return facts.autoReview ? rejectLocalReview("deny") : reject("review_denied");
|
|
4893
4869
|
}
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
);
|
|
4870
|
+
if (retryKey !== void 0 && evidenceKey !== void 0 && outcome !== "allow_once" && outcome !== "deny" && !manualPrivacyFallback) {
|
|
4871
|
+
if (!cachedFailure) {
|
|
4872
|
+
if (this.localReviewFailures.size >= 256) {
|
|
4873
|
+
const oldest = this.localReviewFailures.keys().next().value;
|
|
4874
|
+
if (oldest !== void 0)
|
|
4875
|
+
this.localReviewFailures.delete(oldest);
|
|
4876
|
+
}
|
|
4877
|
+
const failureKey = decision === "review_unavailable" || decision === "review_not_delegated" ? retryKey : evidenceKey;
|
|
4878
|
+
this.localReviewFailures.set(failureKey, {
|
|
4879
|
+
outcome,
|
|
4880
|
+
...decision === "review_unavailable" ? { expiresAt: now() + 15e3 } : {}
|
|
4881
|
+
});
|
|
4906
4882
|
}
|
|
4907
|
-
if (
|
|
4908
|
-
|
|
4909
|
-
"
|
|
4883
|
+
if (!manualInconclusiveFallback && !interactive) {
|
|
4884
|
+
audit(
|
|
4885
|
+
"denied",
|
|
4886
|
+
decision === "ask_user" ? "review_user_decision_required" : decision,
|
|
4910
4887
|
void 0,
|
|
4911
4888
|
diagnostic
|
|
4912
4889
|
);
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
);
|
|
4890
|
+
return outcome.fallback === "ask_user" ? rejectLocalReview("ask_user", outcome.missing) : rejectLocalReview(outcome.fallback, void 0, diagnostic);
|
|
4891
|
+
}
|
|
4916
4892
|
}
|
|
4917
|
-
if (
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
options.
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
preview,
|
|
4945
|
-
route,
|
|
4946
|
-
...route.kind === "review" || route.kind === "defer" ? {
|
|
4947
|
-
reviewFallback: decision === "deny" ? "review_denied" : decision,
|
|
4948
|
-
...reviewReason ? { reviewReason } : {},
|
|
4949
|
-
...diagnostic ? { reviewDiagnostic: diagnostic } : {},
|
|
4950
|
-
...manualPrivacyFallback ? { reviewWithheldForPrivacy: true } : {}
|
|
4951
|
-
} : {},
|
|
4952
|
-
expiresAt: Date.now() + 12e4,
|
|
4953
|
-
choices: choices2,
|
|
4954
|
-
...options.escalation === "unsandboxed" ? {
|
|
4955
|
-
escalation: "unsandboxed",
|
|
4956
|
-
...options.protectedPathsEnforced === false ? { protectedPathsEnforced: false } : {}
|
|
4957
|
-
} : {},
|
|
4958
|
-
...details
|
|
4959
|
-
},
|
|
4960
|
-
signal
|
|
4961
|
-
)
|
|
4962
|
-
)
|
|
4963
|
-
);
|
|
4964
|
-
if (signal.aborted) return expire("approval_expired");
|
|
4965
|
-
checkCurrent();
|
|
4966
|
-
if (reply?.requestId !== requestId || !choices2.includes(reply.choice))
|
|
4967
|
-
return reject("confirmation_required");
|
|
4968
|
-
return reply.choice;
|
|
4969
|
-
};
|
|
4970
|
-
let choice2;
|
|
4971
|
-
if (interactive) {
|
|
4972
|
-
const propose = !withheld && !facts.opaque && !facts.humanOnly ? interactive.propose : void 0;
|
|
4973
|
-
const selected = await selectShellAllowance({
|
|
4893
|
+
if (decision !== "allow_once") {
|
|
4894
|
+
if (decision === "deny") audit("review_failed", "review_denied");
|
|
4895
|
+
else if (diagnostic)
|
|
4896
|
+
audit("review_failed", decision, void 0, diagnostic);
|
|
4897
|
+
const confirm = this.options.confirmation?.confirm;
|
|
4898
|
+
if (!confirm || this.options.confirmation?.available?.() === false) {
|
|
4899
|
+
if (manualInconclusiveFallback) {
|
|
4900
|
+
audit("denied", "review_inconclusive");
|
|
4901
|
+
return reject(
|
|
4902
|
+
`${agentReviewReasons.review_inconclusive} Interactive confirmation is unavailable on this connection.`
|
|
4903
|
+
);
|
|
4904
|
+
}
|
|
4905
|
+
if (manualPrivacyFallback)
|
|
4906
|
+
return rejectLocalReview(
|
|
4907
|
+
"review_evidence_unavailable",
|
|
4908
|
+
void 0,
|
|
4909
|
+
diagnostic
|
|
4910
|
+
);
|
|
4911
|
+
return reject(
|
|
4912
|
+
diagnostic ? `confirmation_required: ${reviewDiagnosticText(diagnostic)}` : "confirmation_required"
|
|
4913
|
+
);
|
|
4914
|
+
}
|
|
4915
|
+
if (manualInconclusiveFallback) audit("review_failed", decision);
|
|
4916
|
+
actor = "user";
|
|
4917
|
+
const withheld = manualPrivacyFallback || !!(interactive && diagnostic && isReviewPrivacyFailure(diagnostic.code));
|
|
4918
|
+
const preview = withheld && diagnostic ? this.options.review?.privacyConfirmationPreview?.(
|
|
4919
|
+
options.preview(),
|
|
4974
4920
|
request,
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4921
|
+
diagnostic
|
|
4922
|
+
) ?? "Command details are hidden here. Inspect the original shell proposal before choosing Run once." : options.preview();
|
|
4923
|
+
const checkRouteCurrent = () => {
|
|
4924
|
+
checkCurrent();
|
|
4925
|
+
if (JSON.stringify(routeApproval(options.evaluate())) !== JSON.stringify(route))
|
|
4926
|
+
return expire("authority_changed");
|
|
4927
|
+
};
|
|
4928
|
+
const ask = async (requestId, choices2, details = {}) => {
|
|
4929
|
+
checkRouteCurrent();
|
|
4930
|
+
const deadline = (this.options.deadline ?? AbortSignal.timeout)(
|
|
4931
|
+
12e4
|
|
4932
|
+
);
|
|
4933
|
+
const signal = requestSignal ? AbortSignal.any([deadline, requestSignal]) : deadline;
|
|
4934
|
+
const reply = responseRecord(
|
|
4935
|
+
await awaitAbortable(
|
|
4936
|
+
signal,
|
|
4937
|
+
() => confirm(
|
|
4938
|
+
{
|
|
4939
|
+
requestId,
|
|
4940
|
+
subject: request.subject,
|
|
4941
|
+
origin: request.origin,
|
|
4942
|
+
preview,
|
|
4943
|
+
route,
|
|
4944
|
+
...route.kind === "review" || route.kind === "defer" ? {
|
|
4945
|
+
reviewFallback: decision === "deny" ? "review_denied" : decision,
|
|
4946
|
+
...reviewReason ? { reviewReason } : {},
|
|
4947
|
+
...diagnostic ? { reviewDiagnostic: diagnostic } : {},
|
|
4948
|
+
...manualPrivacyFallback ? { reviewWithheldForPrivacy: true } : {}
|
|
4949
|
+
} : {},
|
|
4950
|
+
expiresAt: Date.now() + 12e4,
|
|
4951
|
+
choices: choices2,
|
|
4952
|
+
...options.escalation === "unsandboxed" ? {
|
|
4953
|
+
escalation: "unsandboxed",
|
|
4954
|
+
...options.protectedPathsEnforced === false ? { protectedPathsEnforced: false } : {}
|
|
4955
|
+
} : {},
|
|
4956
|
+
...details
|
|
4957
|
+
},
|
|
4958
|
+
signal
|
|
4959
|
+
)
|
|
4960
|
+
)
|
|
4961
|
+
);
|
|
4962
|
+
if (signal.aborted) return expire("approval_expired");
|
|
4963
|
+
checkCurrent();
|
|
4964
|
+
if (reply?.requestId !== requestId || !choices2.includes(reply.choice))
|
|
4965
|
+
return reject("confirmation_required");
|
|
4966
|
+
return reply.choice;
|
|
4967
|
+
};
|
|
4968
|
+
let choice2;
|
|
4969
|
+
if (interactive) {
|
|
4970
|
+
const propose = !withheld && !facts.opaque && !facts.humanOnly ? interactive.propose : void 0;
|
|
4971
|
+
const selected = await selectShellAllowance({
|
|
4972
|
+
request,
|
|
4973
|
+
propose,
|
|
4974
|
+
ask,
|
|
4975
|
+
checkCurrent: checkRouteCurrent,
|
|
4976
|
+
signal: requestSignal
|
|
4977
|
+
});
|
|
4978
|
+
choice2 = selected.choice;
|
|
4979
|
+
save = selected.proposal;
|
|
4980
|
+
} else {
|
|
4981
|
+
const choices2 = [
|
|
4982
|
+
"allow_once",
|
|
4983
|
+
"deny_continue",
|
|
4984
|
+
"deny_stop"
|
|
4985
|
+
];
|
|
4986
|
+
if (!oneTimeConfirmation && save && !facts.opaque && !facts.humanOnly) {
|
|
4987
|
+
if ("commit" in save) choices2.push("save_session");
|
|
4988
|
+
choices2.push("save_project");
|
|
4989
|
+
}
|
|
4990
|
+
if (!oneTimeConfirmation && options.grantSession)
|
|
4991
|
+
choices2.push("grant_session");
|
|
4992
|
+
choice2 = await ask(
|
|
4993
|
+
id2,
|
|
4994
|
+
choices2,
|
|
4995
|
+
!oneTimeConfirmation ? {
|
|
4996
|
+
saveDescription: save?.description,
|
|
4997
|
+
grantDescription: options.grantSession?.description
|
|
4998
|
+
} : {}
|
|
4999
|
+
);
|
|
5000
|
+
}
|
|
5001
|
+
if (choice2 === "grant_session") sessionGrant = options.grantSession;
|
|
5002
|
+
if (choice2 === "save_session") saveScope = "session";
|
|
5003
|
+
if (choice2 === "save_project") saveScope = "project";
|
|
5004
|
+
if (choice2 === "deny_continue" || choice2 === "deny_stop") {
|
|
5005
|
+
audit("denied", "user_denied");
|
|
5006
|
+
return reject("user_denied", choice2 === "deny_stop");
|
|
4991
5007
|
}
|
|
4992
|
-
if (!oneTimeConfirmation && options.grantSession)
|
|
4993
|
-
choices2.push("grant_session");
|
|
4994
|
-
choice2 = await ask(
|
|
4995
|
-
id2,
|
|
4996
|
-
choices2,
|
|
4997
|
-
!oneTimeConfirmation ? {
|
|
4998
|
-
saveDescription: save?.description,
|
|
4999
|
-
grantDescription: options.grantSession?.description
|
|
5000
|
-
} : {}
|
|
5001
|
-
);
|
|
5002
5008
|
}
|
|
5003
|
-
|
|
5004
|
-
if (
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
+
checkCurrent(actor === "review");
|
|
5010
|
+
if (JSON.stringify(routeApproval(options.evaluate())) !== JSON.stringify(route)) {
|
|
5011
|
+
return expire(
|
|
5012
|
+
"authority_changed",
|
|
5013
|
+
actor === "review" ? reviewDiagnostic("review_authority_changed") : void 0
|
|
5014
|
+
);
|
|
5009
5015
|
}
|
|
5010
5016
|
}
|
|
5011
|
-
|
|
5012
|
-
if (
|
|
5013
|
-
return expire(
|
|
5014
|
-
"authority_changed",
|
|
5015
|
-
actor === "review" ? reviewDiagnostic("review_authority_changed") : void 0
|
|
5016
|
-
);
|
|
5017
|
-
}
|
|
5018
|
-
}
|
|
5019
|
-
sessionGrant?.commit();
|
|
5020
|
-
if (saveScope === "project" && save && "rememberProject" in save) {
|
|
5021
|
-
try {
|
|
5022
|
-
await save.rememberProject();
|
|
5023
|
-
} catch (error) {
|
|
5024
|
-
if (error instanceof Error && error.message === "approval_expired")
|
|
5025
|
-
return expire("approval_expired");
|
|
5026
|
-
audit("save_failed", "project_tool_rule_save_failed");
|
|
5027
|
-
return reject(
|
|
5028
|
-
"project_tool_rule_save_failed: Could not save this workspace permission to the personal policy store. The tool did not run."
|
|
5029
|
-
);
|
|
5030
|
-
}
|
|
5031
|
-
}
|
|
5032
|
-
let consumed = false;
|
|
5033
|
-
const consume = (details) => {
|
|
5034
|
-
if (consumed) reject("approval_already_consumed");
|
|
5035
|
-
checkCurrent(actor === "review");
|
|
5036
|
-
if (actor === "review" && (this.options.review?.stillApproved?.(request) === false || this.options.review?.reviewVersion && this.options.review.reviewVersion(request) !== version)) {
|
|
5037
|
-
const diagnostic = reviewDiagnostic("review_authority_changed");
|
|
5038
|
-
audit("expired", "review_authority_changed", void 0, diagnostic);
|
|
5039
|
-
return reject(
|
|
5040
|
-
`approval_expired: ${reviewDiagnosticText(diagnostic)}`
|
|
5041
|
-
);
|
|
5042
|
-
}
|
|
5043
|
-
consumed = true;
|
|
5044
|
-
if (saveScope && save && "commit" in save) {
|
|
5017
|
+
sessionGrant?.commit();
|
|
5018
|
+
if (saveScope === "project" && save && "rememberProject" in save) {
|
|
5045
5019
|
try {
|
|
5046
|
-
save.
|
|
5047
|
-
} catch {
|
|
5048
|
-
|
|
5020
|
+
await save.rememberProject();
|
|
5021
|
+
} catch (error) {
|
|
5022
|
+
if (error instanceof Error && error.message === "approval_expired")
|
|
5023
|
+
return expire("approval_expired");
|
|
5024
|
+
audit("save_failed", "project_tool_rule_save_failed");
|
|
5025
|
+
return reject(
|
|
5026
|
+
"project_tool_rule_save_failed: Could not save this workspace permission to the personal policy store. The tool did not run."
|
|
5027
|
+
);
|
|
5049
5028
|
}
|
|
5050
5029
|
}
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5030
|
+
let consumed = false;
|
|
5031
|
+
const consume = (details) => {
|
|
5032
|
+
if (consumed) reject("approval_already_consumed");
|
|
5033
|
+
checkCurrent(actor === "review");
|
|
5034
|
+
if (actor === "review" && (this.options.review?.stillApproved?.(request) === false || this.options.review?.reviewVersion && this.options.review.reviewVersion(request) !== version)) {
|
|
5035
|
+
const diagnostic = reviewDiagnostic("review_authority_changed");
|
|
5036
|
+
audit("expired", "review_authority_changed", void 0, diagnostic);
|
|
5037
|
+
return reject(
|
|
5038
|
+
`approval_expired: ${reviewDiagnosticText(diagnostic)}`
|
|
5039
|
+
);
|
|
5040
|
+
}
|
|
5041
|
+
consumed = true;
|
|
5042
|
+
if (saveScope && save && "commit" in save) {
|
|
5043
|
+
try {
|
|
5044
|
+
save.commit(saveScope);
|
|
5045
|
+
} catch {
|
|
5046
|
+
audit("save_failed", "launch_rule_save_failed");
|
|
5047
|
+
}
|
|
5048
|
+
}
|
|
5049
|
+
audit("dispatch", route.reason, details?.taskId);
|
|
5050
|
+
};
|
|
5051
|
+
if (!options.deferConsumption) consume();
|
|
5052
|
+
recordApprovalWait();
|
|
5053
|
+
return options.execute(consume, saveScope);
|
|
5054
|
+
} finally {
|
|
5055
|
+
recordApprovalWait();
|
|
5056
|
+
}
|
|
5055
5057
|
};
|
|
5056
5058
|
return receiptBinding !== void 0 ? this.requests.run(scope, id2, receiptBinding, dispatch) : Promise.resolve().then(dispatch);
|
|
5057
5059
|
}
|
|
@@ -10029,6 +10031,7 @@ MCP environment keys: ${serviceLaunch.names.join(", ")}` : ""}`,
|
|
|
10029
10031
|
} : {},
|
|
10030
10032
|
...confirmationOptions,
|
|
10031
10033
|
deferConsumption: true,
|
|
10034
|
+
...input.onApprovalWaitMs ? { onApprovalWaitMs: input.onApprovalWaitMs } : {},
|
|
10032
10035
|
execute: (consume, saveScope) => execute((taskId) => {
|
|
10033
10036
|
const boundLaunch = candidate && (saveScope || reliedOnRule);
|
|
10034
10037
|
if (boundLaunch && backend.supportsExactLaunchBinding?.(candidate, protection) !== true)
|
|
@@ -11473,10 +11476,7 @@ var HTML_SUCCESS2 = "<!doctype html><html><head><title>codelia - MCP authorizati
|
|
|
11473
11476
|
var HTML_ERROR2 = (message) => `<!doctype html><html><head><title>codelia - MCP authorization failed</title></head><body><h2>Authorization failed</h2><pre>${message}</pre></body></html>`;
|
|
11474
11477
|
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11475
11478
|
var oauthPort2 = () => readPositiveIntEnv("CODELIA_MCP_OAUTH_PORT", DEFAULT_MCP_OAUTH_PORT);
|
|
11476
|
-
var oauthWaitTimeoutMs = () =>
|
|
11477
|
-
"CODELIA_MCP_OAUTH_TIMEOUT_MS",
|
|
11478
|
-
DEFAULT_MCP_OAUTH_WAIT_TIMEOUT_MS
|
|
11479
|
-
);
|
|
11479
|
+
var oauthWaitTimeoutMs = () => DEFAULT_MCP_OAUTH_WAIT_TIMEOUT_MS;
|
|
11480
11480
|
var buildAuthorizeUrl2 = (authorizationUrl, redirectUri, clientId3, pkce, state, scope, resource) => {
|
|
11481
11481
|
const url = new URL(authorizationUrl);
|
|
11482
11482
|
url.searchParams.set("response_type", "code");
|
|
@@ -11788,6 +11788,7 @@ var requestMcpOAuthTokens = async (gateway, serverId, oauth2, errorMessage, sign
|
|
|
11788
11788
|
|
|
11789
11789
|
// src/model-factory.ts
|
|
11790
11790
|
var import_core9 = require("@codelia/core");
|
|
11791
|
+
var import_logger6 = require("@codelia/logger");
|
|
11791
11792
|
var import_model_metadata = require("@codelia/model-metadata");
|
|
11792
11793
|
var import_storage12 = require("@codelia/storage");
|
|
11793
11794
|
|
|
@@ -12313,17 +12314,12 @@ var requireApiKeyAuth = (provider, auth) => {
|
|
|
12313
12314
|
}
|
|
12314
12315
|
return auth.api_key;
|
|
12315
12316
|
};
|
|
12316
|
-
var envTruthy = (value) => {
|
|
12317
|
-
if (!value) return false;
|
|
12318
|
-
const normalized = value.trim().toLowerCase();
|
|
12319
|
-
return normalized === "1" || normalized === "true";
|
|
12320
|
-
};
|
|
12321
12317
|
var buildOpenAiClientOptions = (getOpenAiAccessToken, auth, log2) => {
|
|
12322
12318
|
if (auth.method === "api_key") {
|
|
12323
12319
|
return { apiKey: auth.api_key };
|
|
12324
12320
|
}
|
|
12325
12321
|
let accountId = auth.oauth.account_id;
|
|
12326
|
-
const enableDebugHttp =
|
|
12322
|
+
const enableDebugHttp = (0, import_logger6.isDebugEnabled)();
|
|
12327
12323
|
const apiKey = async () => {
|
|
12328
12324
|
if (!getOpenAiAccessToken) {
|
|
12329
12325
|
throw new Error("OpenAI OAuth token refresh is unavailable");
|
|
@@ -12785,6 +12781,7 @@ var withOpenRouterDynamicModel = (registry, llm, entry) => {
|
|
|
12785
12781
|
...contextWindow ? { contextWindow } : {},
|
|
12786
12782
|
...maxInputTokens ? { maxInputTokens } : {},
|
|
12787
12783
|
...maxOutputTokens ? { maxOutputTokens } : {},
|
|
12784
|
+
...entry.cost ? { cost: entry.cost } : {},
|
|
12788
12785
|
...entry.capabilities?.supportsVision !== void 0 ? { supportsVision: entry.capabilities.supportsVision } : {},
|
|
12789
12786
|
...entry.capabilities?.supportsTools !== void 0 ? { supportsTools: entry.capabilities.supportsTools } : {}
|
|
12790
12787
|
}
|
|
@@ -17988,7 +17985,8 @@ var createRuntimeToolApproval = ({
|
|
|
17988
17985
|
...workspaceGrant ? { grantSession: workspaceGrant } : {},
|
|
17989
17986
|
signal: state.approvalSignal(ctx.signal),
|
|
17990
17987
|
execute,
|
|
17991
|
-
deferConsumption: files?.deferConsumption
|
|
17988
|
+
deferConsumption: files?.deferConsumption,
|
|
17989
|
+
...ctx.recordApprovalWaitMs ? { onApprovalWaitMs: ctx.recordApprovalWaitMs } : {}
|
|
17992
17990
|
});
|
|
17993
17991
|
};
|
|
17994
17992
|
const authorize = async (origin, call, raw, ctx) => {
|
|
@@ -18256,12 +18254,6 @@ var toTrimmed2 = (value) => {
|
|
|
18256
18254
|
const trimmed = value.trim();
|
|
18257
18255
|
return trimmed ? trimmed : void 0;
|
|
18258
18256
|
};
|
|
18259
|
-
var parseMarkers2 = (value) => {
|
|
18260
|
-
const normalized = toTrimmed2(value);
|
|
18261
|
-
if (!normalized) return void 0;
|
|
18262
|
-
const markers = normalized.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
18263
|
-
return markers.length > 0 ? markers : void 0;
|
|
18264
|
-
};
|
|
18265
18257
|
var exists2 = async (targetPath) => {
|
|
18266
18258
|
try {
|
|
18267
18259
|
await import_node_fs33.promises.access(targetPath);
|
|
@@ -18360,7 +18352,7 @@ var SkillsResolver = class _SkillsResolver {
|
|
|
18360
18352
|
const env = options.env ?? process.env;
|
|
18361
18353
|
const workingDir = import_node_path37.default.resolve(options.workingDir);
|
|
18362
18354
|
const rootOverride = toTrimmed2(env.CODELIA_AGENTS_ROOT);
|
|
18363
|
-
const markers =
|
|
18355
|
+
const markers = options.markers?.length ? options.markers : DEFAULT_MARKERS2;
|
|
18364
18356
|
const rootDir = rootOverride ? import_node_path37.default.resolve(rootOverride) : await findRootByMarkers2(workingDir, markers, options.reader);
|
|
18365
18357
|
const homeDir = toTrimmed2(env.HOME) ?? import_node_os9.default.homedir();
|
|
18366
18358
|
const userSkillsDir = import_node_path37.default.join(import_node_path37.default.resolve(homeDir), ".agents", "skills");
|
|
@@ -20582,6 +20574,12 @@ var AgentTreeCoordinator = class {
|
|
|
20582
20574
|
isAvailable() {
|
|
20583
20575
|
return this.factory.isAvailable();
|
|
20584
20576
|
}
|
|
20577
|
+
getPerfStats() {
|
|
20578
|
+
return {
|
|
20579
|
+
active: this.active.size,
|
|
20580
|
+
maxConcurrent: this.parent?.subagent?.max_concurrent ?? DEFAULT_MAX_CONCURRENT
|
|
20581
|
+
};
|
|
20582
|
+
}
|
|
20585
20583
|
serialize(fn) {
|
|
20586
20584
|
const next = this.queue.then(fn, fn);
|
|
20587
20585
|
this.queue = next.then(
|
|
@@ -22046,23 +22044,8 @@ var import_node_fs39 = require("fs");
|
|
|
22046
22044
|
var import_core23 = require("@codelia/core");
|
|
22047
22045
|
var import_zod33 = require("zod");
|
|
22048
22046
|
var DEFAULT_READ_LIMIT = 2e3;
|
|
22049
|
-
var
|
|
22050
|
-
var
|
|
22051
|
-
var parsePositiveIntEnv = (key, fallback) => {
|
|
22052
|
-
const raw = process.env[key];
|
|
22053
|
-
if (!raw) return fallback;
|
|
22054
|
-
const parsed = Number.parseInt(raw, 10);
|
|
22055
|
-
if (!Number.isFinite(parsed) || parsed <= 0) return fallback;
|
|
22056
|
-
return parsed;
|
|
22057
|
-
};
|
|
22058
|
-
var MAX_LINE_LENGTH = parsePositiveIntEnv(
|
|
22059
|
-
"CODELIA_READ_MAX_LINE_LENGTH",
|
|
22060
|
-
DEFAULT_MAX_LINE_LENGTH
|
|
22061
|
-
);
|
|
22062
|
-
var MAX_BYTES = parsePositiveIntEnv(
|
|
22063
|
-
"CODELIA_READ_MAX_BYTES",
|
|
22064
|
-
DEFAULT_MAX_BYTES
|
|
22065
|
-
);
|
|
22047
|
+
var MAX_LINE_LENGTH = 1e3;
|
|
22048
|
+
var MAX_BYTES = 64 * 1024;
|
|
22066
22049
|
var clipLongLine = (line) => {
|
|
22067
22050
|
if (line.length <= MAX_LINE_LENGTH) {
|
|
22068
22051
|
return line;
|
|
@@ -22847,7 +22830,8 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
22847
22830
|
origin: getOperatorContext(ctx) ? "operator" : "parent_agent",
|
|
22848
22831
|
signal: ctx.signal,
|
|
22849
22832
|
owner: sessionContext?.sessionId ?? void 0,
|
|
22850
|
-
reviewHistory: input.approval_context
|
|
22833
|
+
reviewHistory: input.approval_context,
|
|
22834
|
+
...ctx.recordApprovalWaitMs ? { onApprovalWaitMs: ctx.recordApprovalWaitMs } : {}
|
|
22851
22835
|
},
|
|
22852
22836
|
async (admission) => {
|
|
22853
22837
|
try {
|
|
@@ -23605,7 +23589,7 @@ var import_node_fs41 = require("fs");
|
|
|
23605
23589
|
var import_node_path43 = __toESM(require("path"), 1);
|
|
23606
23590
|
var import_core31 = require("@codelia/core");
|
|
23607
23591
|
var import_zod41 = require("zod");
|
|
23608
|
-
var
|
|
23592
|
+
var DEFAULT_MAX_BYTES = 5 * 1024 * 1024;
|
|
23609
23593
|
var MAX_MAX_BYTES = 10 * 1024 * 1024;
|
|
23610
23594
|
var MIME_BY_EXTENSION = {
|
|
23611
23595
|
".png": "image/png",
|
|
@@ -23676,7 +23660,7 @@ var createViewImageTool = (sandboxKey) => (0, import_core31.defineTool)({
|
|
|
23676
23660
|
if (stat2.isDirectory()) {
|
|
23677
23661
|
return `Path is a directory: ${input.file_path}`;
|
|
23678
23662
|
}
|
|
23679
|
-
const maxBytes = input.max_bytes ??
|
|
23663
|
+
const maxBytes = input.max_bytes ?? DEFAULT_MAX_BYTES;
|
|
23680
23664
|
if (stat2.size > maxBytes) {
|
|
23681
23665
|
return `Image too large: ${input.file_path} (${stat2.size} bytes > ${maxBytes} bytes)`;
|
|
23682
23666
|
}
|
|
@@ -23713,7 +23697,7 @@ var import_core32 = require("@codelia/core");
|
|
|
23713
23697
|
var import_zod42 = require("zod");
|
|
23714
23698
|
var DEFAULT_TIMEOUT_MS4 = 1e4;
|
|
23715
23699
|
var MAX_TIMEOUT_MS = 3e4;
|
|
23716
|
-
var
|
|
23700
|
+
var DEFAULT_MAX_BYTES2 = 2e5;
|
|
23717
23701
|
var MAX_MAX_BYTES2 = 1e6;
|
|
23718
23702
|
var TLS_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
23719
23703
|
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
@@ -23973,7 +23957,7 @@ var createWebfetchTool = () => (0, import_core32.defineTool)({
|
|
|
23973
23957
|
`Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS4}, Max ${MAX_TIMEOUT_MS}.`
|
|
23974
23958
|
),
|
|
23975
23959
|
max_bytes: import_zod42.z.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
|
|
23976
|
-
`Max response bytes to keep. Default ${
|
|
23960
|
+
`Max response bytes to keep. Default ${DEFAULT_MAX_BYTES2}, Max ${MAX_MAX_BYTES2}.`
|
|
23977
23961
|
)
|
|
23978
23962
|
}),
|
|
23979
23963
|
execute: async (input) => {
|
|
@@ -23987,7 +23971,7 @@ var createWebfetchTool = () => (0, import_core32.defineTool)({
|
|
|
23987
23971
|
return `Unsupported URL protocol: ${url.protocol}`;
|
|
23988
23972
|
}
|
|
23989
23973
|
const timeoutMs = input.timeout_ms ?? DEFAULT_TIMEOUT_MS4;
|
|
23990
|
-
const maxBytes = input.max_bytes ??
|
|
23974
|
+
const maxBytes = input.max_bytes ?? DEFAULT_MAX_BYTES2;
|
|
23991
23975
|
const outputFormat = input.output_format ?? "markdown";
|
|
23992
23976
|
const startedAt = Date.now();
|
|
23993
23977
|
const controller = new AbortController();
|
|
@@ -24384,11 +24368,6 @@ var createSubagentTaskTools = (coordinator, ownerSession, spawn8) => {
|
|
|
24384
24368
|
};
|
|
24385
24369
|
|
|
24386
24370
|
// src/agent-factory.ts
|
|
24387
|
-
var envTruthy2 = (value) => {
|
|
24388
|
-
if (!value) return false;
|
|
24389
|
-
const normalized = value.trim().toLowerCase();
|
|
24390
|
-
return normalized === "1" || normalized === "true";
|
|
24391
|
-
};
|
|
24392
24371
|
var sleep2 = (ms) => new Promise((resolve) => {
|
|
24393
24372
|
setTimeout(resolve, ms);
|
|
24394
24373
|
});
|
|
@@ -24404,13 +24383,16 @@ var waitForUiConfirmSupport = async (state, timeoutMs = 5e3, signal) => {
|
|
|
24404
24383
|
return !signal?.aborted && !!state.uiCapabilities?.supports_confirm;
|
|
24405
24384
|
};
|
|
24406
24385
|
var requestMcpOAuthTokens2 = async (state, serverId, oauth2, errorMessage, signal) => {
|
|
24386
|
+
const configuredBrowser = state.effectiveEnvironment.config.source === "disabled" ? void 0 : await resolveAuthOAuthBrowser(
|
|
24387
|
+
state.runtimeWorkingDir ?? void 0
|
|
24388
|
+
).catch(() => void 0);
|
|
24407
24389
|
const gateway = {
|
|
24408
24390
|
runId: state.activeRunId ?? void 0,
|
|
24409
24391
|
supportsPrompt: !!state.uiCapabilities?.supports_prompt,
|
|
24410
24392
|
waitForConfirmSupport: () => waitForUiConfirmSupport(state, 5e3, signal),
|
|
24411
24393
|
confirm: (params) => requestUiConfirm(state, params, signal),
|
|
24412
24394
|
prompt: (params) => requestUiPrompt(state, params, signal),
|
|
24413
|
-
shouldAutoOpenBrowser: shouldAutoOpenOAuthBrowser,
|
|
24395
|
+
shouldAutoOpenBrowser: () => shouldAutoOpenOAuthBrowser(configuredBrowser),
|
|
24414
24396
|
openBrowser,
|
|
24415
24397
|
log: import_logger.log
|
|
24416
24398
|
};
|
|
@@ -24474,13 +24456,28 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
24474
24456
|
sandboxKey = createSandboxKey(ctx);
|
|
24475
24457
|
}
|
|
24476
24458
|
const reader = workspaceRoot && (environment.context.projectInstructions === "from-workspace" || environment.context.skills === "from-config") ? await runtimeResourceReader(state, workspaceRoot, ctx) : void 0;
|
|
24459
|
+
const initPhases = [];
|
|
24460
|
+
const measurePhase = async (name2, fn) => {
|
|
24461
|
+
const started = performance.now();
|
|
24462
|
+
try {
|
|
24463
|
+
return await fn();
|
|
24464
|
+
} finally {
|
|
24465
|
+
initPhases.push({
|
|
24466
|
+
name: name2,
|
|
24467
|
+
duration_ms: Math.max(0, Math.round(performance.now() - started))
|
|
24468
|
+
});
|
|
24469
|
+
}
|
|
24470
|
+
};
|
|
24477
24471
|
if (environment.context.projectInstructions === "from-workspace" && workspaceRoot) {
|
|
24478
|
-
agentsResolver =
|
|
24479
|
-
workspaceRoot
|
|
24480
|
-
|
|
24481
|
-
|
|
24482
|
-
|
|
24483
|
-
|
|
24472
|
+
agentsResolver = await measurePhase("agents_resolver", async () => {
|
|
24473
|
+
const agentsEnabled = environment.config.source === "disabled" ? true : await resolveAgentsEnabled(workspaceRoot).catch(() => true);
|
|
24474
|
+
return state.agentsResolver ?? await AgentsResolver.create(
|
|
24475
|
+
workspaceRoot,
|
|
24476
|
+
{ enabled: agentsEnabled },
|
|
24477
|
+
void 0,
|
|
24478
|
+
reader
|
|
24479
|
+
);
|
|
24480
|
+
});
|
|
24484
24481
|
state.agentsResolver = agentsResolver;
|
|
24485
24482
|
}
|
|
24486
24483
|
if (environment.context.skills === "from-config" && workspaceRoot) {
|
|
@@ -24494,11 +24491,14 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
24494
24491
|
const message = error instanceof Error ? error.message : String(error);
|
|
24495
24492
|
throw new Error(message);
|
|
24496
24493
|
}
|
|
24497
|
-
skillsResolver =
|
|
24498
|
-
|
|
24499
|
-
|
|
24500
|
-
|
|
24501
|
-
|
|
24494
|
+
skillsResolver = await measurePhase(
|
|
24495
|
+
"skills_resolver",
|
|
24496
|
+
async () => state.skillsResolver ?? await SkillsResolver.create({
|
|
24497
|
+
workingDir: workspaceRoot,
|
|
24498
|
+
config: skillsConfig,
|
|
24499
|
+
reader
|
|
24500
|
+
})
|
|
24501
|
+
);
|
|
24502
24502
|
state.skillsResolver = skillsResolver;
|
|
24503
24503
|
state.updateSkillsSnapshot(workspaceRoot, skillsResolver.getSnapshot());
|
|
24504
24504
|
}
|
|
@@ -24557,24 +24557,32 @@ var createAgentFactory = (state, options = {}) => {
|
|
|
24557
24557
|
}
|
|
24558
24558
|
let mcpTools = [];
|
|
24559
24559
|
if (environment.tools.mcp === "from-config" && options.mcpManager) {
|
|
24560
|
-
|
|
24561
|
-
|
|
24562
|
-
|
|
24563
|
-
(
|
|
24564
|
-
|
|
24565
|
-
|
|
24566
|
-
|
|
24567
|
-
state,
|
|
24560
|
+
mcpTools = await measurePhase("mcp_tools", async () => {
|
|
24561
|
+
try {
|
|
24562
|
+
return await options.mcpManager.getTools({
|
|
24563
|
+
onStatus: (message) => {
|
|
24564
|
+
(0, import_logger.log)(`mcp: ${message}`);
|
|
24565
|
+
},
|
|
24566
|
+
requestOAuthTokens: async ({
|
|
24568
24567
|
server_id,
|
|
24569
|
-
oauth2,
|
|
24568
|
+
oauth: oauth2,
|
|
24570
24569
|
error,
|
|
24571
24570
|
signal
|
|
24572
|
-
)
|
|
24573
|
-
|
|
24574
|
-
|
|
24575
|
-
|
|
24576
|
-
|
|
24577
|
-
|
|
24571
|
+
}) => {
|
|
24572
|
+
return requestMcpOAuthTokensWithRunStatus(
|
|
24573
|
+
state,
|
|
24574
|
+
server_id,
|
|
24575
|
+
oauth2,
|
|
24576
|
+
error,
|
|
24577
|
+
signal
|
|
24578
|
+
);
|
|
24579
|
+
}
|
|
24580
|
+
});
|
|
24581
|
+
} catch (error) {
|
|
24582
|
+
(0, import_logger.log)(`failed to load mcp tools: ${String(error)}`);
|
|
24583
|
+
return [];
|
|
24584
|
+
}
|
|
24585
|
+
});
|
|
24578
24586
|
}
|
|
24579
24587
|
const hostTools = environment.tools.host === "enabled" ? await loadRuntimeHostTools(environment.adapters.toolProviders ?? []) : [];
|
|
24580
24588
|
const subagentConfig = options.subagents?.isAvailable() && workspaceRoot ? await resolveEnvironmentSubagentConfig(state, workspaceRoot) : void 0;
|
|
@@ -24596,13 +24604,16 @@ ${JSON.stringify(subagentConfig)}
|
|
|
24596
24604
|
state,
|
|
24597
24605
|
workspaceRoot
|
|
24598
24606
|
);
|
|
24599
|
-
executionEnvironmentContext = await
|
|
24600
|
-
|
|
24601
|
-
|
|
24602
|
-
|
|
24603
|
-
|
|
24604
|
-
|
|
24605
|
-
|
|
24607
|
+
executionEnvironmentContext = await measurePhase(
|
|
24608
|
+
"exec_env",
|
|
24609
|
+
() => buildExecutionEnvironmentContext({
|
|
24610
|
+
workingDir: workspaceRoot,
|
|
24611
|
+
sandboxRoot: ctx.rootDir,
|
|
24612
|
+
config: executionEnvironmentConfig,
|
|
24613
|
+
hostInfo: describeExecutionEnvironmentHost(state.sandboxMode.value),
|
|
24614
|
+
probeOptions: { authorize: authorizeRuntimeShell(state) }
|
|
24615
|
+
})
|
|
24616
|
+
);
|
|
24606
24617
|
}
|
|
24607
24618
|
state.executionEnvironmentContext = executionEnvironmentContext;
|
|
24608
24619
|
if (logInitialExecutionEnvironmentDebug(executionEnvironmentContext, {
|
|
@@ -24748,12 +24759,12 @@ ${JSON.stringify(subagentConfig)}
|
|
|
24748
24759
|
state.currentModelProvider = provider;
|
|
24749
24760
|
state.currentModelName = resolvedModelName;
|
|
24750
24761
|
state.currentModelSource = modelConfig.source;
|
|
24751
|
-
const modelRegistry =
|
|
24752
|
-
|
|
24753
|
-
|
|
24754
|
-
|
|
24755
|
-
|
|
24756
|
-
|
|
24762
|
+
const modelRegistry = await measurePhase(
|
|
24763
|
+
"model_registry",
|
|
24764
|
+
async () => environment.persistence.mode === "runtime" || getResponsesProvider(modelConfig, provider) ? await buildModelRegistry(llm, {
|
|
24765
|
+
strict: provider !== "openrouter",
|
|
24766
|
+
providers: modelConfig.providers
|
|
24767
|
+
}) : buildConfiguredModelRegistry(modelConfig.providers)
|
|
24757
24768
|
);
|
|
24758
24769
|
const builtinTools = /* @__PURE__ */ new Set([...baseLocalTools, ...imageTools]);
|
|
24759
24770
|
if (localSearchTool && environment.sourcePreset === "tui-local" && !environment.adapters.approvalToolAuthority && !environment.adapters.approvalToolEffect)
|
|
@@ -24888,7 +24899,7 @@ Original conversation messages remain available after compaction. When a summary
|
|
|
24888
24899
|
systemPrompt: effectiveSystemPrompt,
|
|
24889
24900
|
modelRegistry: modelRegistry ?? import_core37.DEFAULT_MODEL_REGISTRY,
|
|
24890
24901
|
toolOutputCache: {
|
|
24891
|
-
totalBudgetTrim:
|
|
24902
|
+
totalBudgetTrim: false
|
|
24892
24903
|
},
|
|
24893
24904
|
services: {
|
|
24894
24905
|
toolOutputCacheStore,
|
|
@@ -24897,11 +24908,13 @@ Original conversation messages remain available after compaction. When a summary
|
|
|
24897
24908
|
}
|
|
24898
24909
|
});
|
|
24899
24910
|
state.canReadAttachment = canReadAttachment;
|
|
24911
|
+
state.telemetry.setAgentInitPhases(initPhases);
|
|
24900
24912
|
state.recordAgentChatRoute(
|
|
24901
24913
|
agent,
|
|
24902
|
-
getResponsesProvider(modelConfig, provider) ? { kind: "named" } : {
|
|
24914
|
+
getResponsesProvider(modelConfig, provider) ? { kind: "named", metered: false } : {
|
|
24903
24915
|
kind: "builtin",
|
|
24904
24916
|
provider,
|
|
24917
|
+
metered: providerAuth.method === "api_key",
|
|
24905
24918
|
apiBase: providerAuth.method === "api_key" ? builtinApiKeyBase(provider) : void 0
|
|
24906
24919
|
}
|
|
24907
24920
|
);
|
|
@@ -26930,9 +26943,6 @@ var resolveRuntimeSandboxMode = async (environment, input = {}) => {
|
|
|
26930
26943
|
const modeFlag = readFlag(args, "--sandbox-mode");
|
|
26931
26944
|
if (modeFlag !== void 0)
|
|
26932
26945
|
return parseMode(modeFlag, "--sandbox-mode", "cli", false);
|
|
26933
|
-
const legacyFlag = readFlag(args, "--approval-mode");
|
|
26934
|
-
if (legacyFlag !== void 0)
|
|
26935
|
-
return parseMode(legacyFlag, "--approval-mode", "cli", true);
|
|
26936
26946
|
if (env.CODELIA_SANDBOX_MODE !== void 0)
|
|
26937
26947
|
return parseMode(
|
|
26938
26948
|
env.CODELIA_SANDBOX_MODE,
|
|
@@ -26940,13 +26950,6 @@ var resolveRuntimeSandboxMode = async (environment, input = {}) => {
|
|
|
26940
26950
|
"env",
|
|
26941
26951
|
false
|
|
26942
26952
|
);
|
|
26943
|
-
if (env.CODELIA_APPROVAL_MODE !== void 0)
|
|
26944
|
-
return parseMode(
|
|
26945
|
-
env.CODELIA_APPROVAL_MODE,
|
|
26946
|
-
"CODELIA_APPROVAL_MODE",
|
|
26947
|
-
"env",
|
|
26948
|
-
true
|
|
26949
|
-
);
|
|
26950
26953
|
const store = input.store ?? new import_storage26.ProjectsPolicyStore();
|
|
26951
26954
|
const projectKey = await import_node_fs43.promises.realpath(root).catch((error) => {
|
|
26952
26955
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -26968,6 +26971,213 @@ var resolveRuntimeSandboxMode = async (environment, input = {}) => {
|
|
|
26968
26971
|
return defaultSandboxMode;
|
|
26969
26972
|
};
|
|
26970
26973
|
|
|
26974
|
+
// src/telemetry.ts
|
|
26975
|
+
var MAX_RECENT_CALLS = 64;
|
|
26976
|
+
var MAX_RECENT_TOOLS = 64;
|
|
26977
|
+
var cloneModelUsage = (entry) => ({
|
|
26978
|
+
...entry
|
|
26979
|
+
});
|
|
26980
|
+
var createEmptyTelemetrySummary = () => ({
|
|
26981
|
+
total_calls: 0,
|
|
26982
|
+
total_tokens: 0,
|
|
26983
|
+
total_input_tokens: 0,
|
|
26984
|
+
total_output_tokens: 0,
|
|
26985
|
+
total_output_reasoning_tokens: 0,
|
|
26986
|
+
total_cached_input_tokens: 0,
|
|
26987
|
+
total_cache_creation_tokens: 0,
|
|
26988
|
+
total_input_image_tokens: 0,
|
|
26989
|
+
cache_hit_calls: 0,
|
|
26990
|
+
cache_miss_calls: 0,
|
|
26991
|
+
cache_unknown_calls: 0,
|
|
26992
|
+
total_cost_usd: null,
|
|
26993
|
+
retry_count: 0,
|
|
26994
|
+
retry_wait_ms: 0,
|
|
26995
|
+
tool_calls: 0,
|
|
26996
|
+
tool_errors: 0,
|
|
26997
|
+
tool_exec_ms: 0,
|
|
26998
|
+
tool_approval_wait_ms: 0,
|
|
26999
|
+
compaction_count: 0,
|
|
27000
|
+
compaction_duration_ms: 0,
|
|
27001
|
+
by_model: {}
|
|
27002
|
+
});
|
|
27003
|
+
var cloneTelemetrySummary = (summary) => ({
|
|
27004
|
+
...summary,
|
|
27005
|
+
by_model: Object.fromEntries(
|
|
27006
|
+
Object.entries(summary.by_model).map(([model, entry]) => [
|
|
27007
|
+
model,
|
|
27008
|
+
cloneModelUsage(entry)
|
|
27009
|
+
])
|
|
27010
|
+
)
|
|
27011
|
+
});
|
|
27012
|
+
var applyCallToSummary = (summary, call) => {
|
|
27013
|
+
const usage = call.usage ?? null;
|
|
27014
|
+
const inputTokens = usage?.input_tokens ?? 0;
|
|
27015
|
+
const outputTokens = usage?.output_tokens ?? 0;
|
|
27016
|
+
const reasoningTokens = usage?.output_reasoning_tokens ?? 0;
|
|
27017
|
+
const cachedTokens = usage?.input_cached_tokens ?? 0;
|
|
27018
|
+
const cacheCreationTokens = usage?.input_cache_creation_tokens ?? 0;
|
|
27019
|
+
const imageTokens = usage?.input_image_tokens ?? 0;
|
|
27020
|
+
const totalTokens = usage?.total_tokens ?? 0;
|
|
27021
|
+
const hitState = call.cache?.hit_state ?? (typeof usage?.input_cached_tokens === "number" ? cachedTokens > 0 ? "hit" : "miss" : "unknown");
|
|
27022
|
+
const validCost = typeof call.cost_usd === "number" && Number.isFinite(call.cost_usd) && call.cost_usd >= 0 ? call.cost_usd : null;
|
|
27023
|
+
summary.total_calls += 1;
|
|
27024
|
+
summary.total_tokens += totalTokens;
|
|
27025
|
+
summary.total_input_tokens += inputTokens;
|
|
27026
|
+
summary.total_output_tokens += outputTokens;
|
|
27027
|
+
summary.total_output_reasoning_tokens += reasoningTokens;
|
|
27028
|
+
summary.total_cached_input_tokens += cachedTokens;
|
|
27029
|
+
summary.total_cache_creation_tokens += cacheCreationTokens;
|
|
27030
|
+
summary.total_input_image_tokens += imageTokens;
|
|
27031
|
+
if (hitState === "hit") summary.cache_hit_calls += 1;
|
|
27032
|
+
else if (hitState === "miss") summary.cache_miss_calls += 1;
|
|
27033
|
+
else summary.cache_unknown_calls += 1;
|
|
27034
|
+
if (validCost !== null) {
|
|
27035
|
+
summary.total_cost_usd = (summary.total_cost_usd ?? 0) + validCost;
|
|
27036
|
+
}
|
|
27037
|
+
const modelKey = call.model ?? "unknown";
|
|
27038
|
+
const existing = summary.by_model[modelKey];
|
|
27039
|
+
if (!existing) {
|
|
27040
|
+
summary.by_model[modelKey] = {
|
|
27041
|
+
calls: 1,
|
|
27042
|
+
input_tokens: inputTokens,
|
|
27043
|
+
output_tokens: outputTokens,
|
|
27044
|
+
output_reasoning_tokens: reasoningTokens,
|
|
27045
|
+
cached_input_tokens: cachedTokens,
|
|
27046
|
+
cache_creation_tokens: cacheCreationTokens,
|
|
27047
|
+
input_image_tokens: imageTokens,
|
|
27048
|
+
cache_hit_calls: hitState === "hit" ? 1 : 0,
|
|
27049
|
+
cache_miss_calls: hitState === "miss" ? 1 : 0,
|
|
27050
|
+
cache_unknown_calls: hitState === "unknown" ? 1 : 0,
|
|
27051
|
+
total_tokens: totalTokens,
|
|
27052
|
+
cost_usd: validCost
|
|
27053
|
+
};
|
|
27054
|
+
} else {
|
|
27055
|
+
existing.calls += 1;
|
|
27056
|
+
existing.input_tokens += inputTokens;
|
|
27057
|
+
existing.output_tokens += outputTokens;
|
|
27058
|
+
existing.output_reasoning_tokens += reasoningTokens;
|
|
27059
|
+
existing.cached_input_tokens += cachedTokens;
|
|
27060
|
+
existing.cache_creation_tokens += cacheCreationTokens;
|
|
27061
|
+
existing.input_image_tokens += imageTokens;
|
|
27062
|
+
if (hitState === "hit") existing.cache_hit_calls += 1;
|
|
27063
|
+
else if (hitState === "miss") existing.cache_miss_calls += 1;
|
|
27064
|
+
else existing.cache_unknown_calls += 1;
|
|
27065
|
+
existing.total_tokens += totalTokens;
|
|
27066
|
+
if (validCost !== null) {
|
|
27067
|
+
existing.cost_usd = (existing.cost_usd ?? 0) + validCost;
|
|
27068
|
+
}
|
|
27069
|
+
}
|
|
27070
|
+
};
|
|
27071
|
+
var applyToolToSummary = (summary, record) => {
|
|
27072
|
+
summary.tool_calls += 1;
|
|
27073
|
+
if (record.status === "error") {
|
|
27074
|
+
summary.tool_errors += 1;
|
|
27075
|
+
}
|
|
27076
|
+
summary.tool_exec_ms += Math.max(
|
|
27077
|
+
0,
|
|
27078
|
+
record.exec_duration_ms ?? record.duration_ms
|
|
27079
|
+
);
|
|
27080
|
+
summary.tool_approval_wait_ms += Math.max(0, record.approval_wait_ms ?? 0);
|
|
27081
|
+
};
|
|
27082
|
+
var applyRetryToSummary = (summary, delayMs) => {
|
|
27083
|
+
summary.retry_count += 1;
|
|
27084
|
+
summary.retry_wait_ms += Math.max(0, Math.round(delayMs));
|
|
27085
|
+
};
|
|
27086
|
+
var applyCompactionToSummary = (summary, durationMs) => {
|
|
27087
|
+
summary.compaction_count += 1;
|
|
27088
|
+
summary.compaction_duration_ms += Math.max(0, durationMs);
|
|
27089
|
+
};
|
|
27090
|
+
var RuntimeTelemetryStore = class {
|
|
27091
|
+
sessionSummary = createEmptyTelemetrySummary();
|
|
27092
|
+
currentRunId = null;
|
|
27093
|
+
currentRunSummary = null;
|
|
27094
|
+
recentCalls = [];
|
|
27095
|
+
recentTools = [];
|
|
27096
|
+
startupPhases = [];
|
|
27097
|
+
agentInitPhases = [];
|
|
27098
|
+
resetSession() {
|
|
27099
|
+
this.sessionSummary = createEmptyTelemetrySummary();
|
|
27100
|
+
this.currentRunId = null;
|
|
27101
|
+
this.currentRunSummary = null;
|
|
27102
|
+
this.recentCalls.length = 0;
|
|
27103
|
+
this.recentTools.length = 0;
|
|
27104
|
+
}
|
|
27105
|
+
beginRun(runId) {
|
|
27106
|
+
this.currentRunId = runId;
|
|
27107
|
+
this.currentRunSummary = createEmptyTelemetrySummary();
|
|
27108
|
+
}
|
|
27109
|
+
recordLlmCall(call) {
|
|
27110
|
+
applyCallToSummary(this.sessionSummary, call);
|
|
27111
|
+
if (this.currentRunId === call.run_id && this.currentRunSummary) {
|
|
27112
|
+
applyCallToSummary(this.currentRunSummary, call);
|
|
27113
|
+
}
|
|
27114
|
+
const { session: _session, ...callRecord } = call;
|
|
27115
|
+
this.recentCalls.push(callRecord);
|
|
27116
|
+
if (this.recentCalls.length > MAX_RECENT_CALLS) {
|
|
27117
|
+
this.recentCalls.shift();
|
|
27118
|
+
}
|
|
27119
|
+
}
|
|
27120
|
+
recordToolComplete(record) {
|
|
27121
|
+
applyToolToSummary(this.sessionSummary, record);
|
|
27122
|
+
if (this.currentRunId === record.run_id && this.currentRunSummary) {
|
|
27123
|
+
applyToolToSummary(this.currentRunSummary, record);
|
|
27124
|
+
}
|
|
27125
|
+
this.recentTools.push(record);
|
|
27126
|
+
if (this.recentTools.length > MAX_RECENT_TOOLS) {
|
|
27127
|
+
this.recentTools.shift();
|
|
27128
|
+
}
|
|
27129
|
+
}
|
|
27130
|
+
recordRetry(runId, delayMs) {
|
|
27131
|
+
applyRetryToSummary(this.sessionSummary, delayMs);
|
|
27132
|
+
if (this.currentRunId === runId && this.currentRunSummary) {
|
|
27133
|
+
applyRetryToSummary(this.currentRunSummary, delayMs);
|
|
27134
|
+
}
|
|
27135
|
+
}
|
|
27136
|
+
recordRetryWait(runId, waitMs) {
|
|
27137
|
+
const rounded = Math.max(0, Math.round(waitMs));
|
|
27138
|
+
this.sessionSummary.retry_wait_ms += rounded;
|
|
27139
|
+
if (this.currentRunId === runId && this.currentRunSummary) {
|
|
27140
|
+
this.currentRunSummary.retry_wait_ms += rounded;
|
|
27141
|
+
}
|
|
27142
|
+
}
|
|
27143
|
+
recordCompaction(runId, durationMs) {
|
|
27144
|
+
applyCompactionToSummary(this.sessionSummary, durationMs);
|
|
27145
|
+
if (this.currentRunId === runId && this.currentRunSummary) {
|
|
27146
|
+
applyCompactionToSummary(this.currentRunSummary, durationMs);
|
|
27147
|
+
}
|
|
27148
|
+
}
|
|
27149
|
+
recordStartupPhase(name2, durationMs) {
|
|
27150
|
+
this.startupPhases.push({
|
|
27151
|
+
name: name2,
|
|
27152
|
+
duration_ms: Math.max(0, Math.round(durationMs))
|
|
27153
|
+
});
|
|
27154
|
+
}
|
|
27155
|
+
setAgentInitPhases(phases) {
|
|
27156
|
+
this.agentInitPhases = phases.map((phase) => ({
|
|
27157
|
+
name: phase.name,
|
|
27158
|
+
duration_ms: Math.max(0, Math.round(phase.duration_ms))
|
|
27159
|
+
}));
|
|
27160
|
+
}
|
|
27161
|
+
getSessionSummary() {
|
|
27162
|
+
return cloneTelemetrySummary(this.sessionSummary);
|
|
27163
|
+
}
|
|
27164
|
+
getRunSummary() {
|
|
27165
|
+
return this.currentRunSummary ? cloneTelemetrySummary(this.currentRunSummary) : null;
|
|
27166
|
+
}
|
|
27167
|
+
getRecentCalls() {
|
|
27168
|
+
return this.recentCalls.slice();
|
|
27169
|
+
}
|
|
27170
|
+
getRecentTools() {
|
|
27171
|
+
return this.recentTools.slice();
|
|
27172
|
+
}
|
|
27173
|
+
getStartupPhases() {
|
|
27174
|
+
return this.startupPhases.slice();
|
|
27175
|
+
}
|
|
27176
|
+
getAgentInitPhases() {
|
|
27177
|
+
return this.agentInitPhases.slice();
|
|
27178
|
+
}
|
|
27179
|
+
};
|
|
27180
|
+
|
|
26971
27181
|
// src/runtime-state.ts
|
|
26972
27182
|
var RuntimeState = class {
|
|
26973
27183
|
attachments;
|
|
@@ -27100,6 +27310,7 @@ var RuntimeState = class {
|
|
|
27100
27310
|
set sessionId(value) {
|
|
27101
27311
|
if (value === this.boundSessionId) return;
|
|
27102
27312
|
this.boundSessionId = value;
|
|
27313
|
+
this.telemetry.resetSession();
|
|
27103
27314
|
this.receiptOwner.abort();
|
|
27104
27315
|
this.receiptOwner = new AbortController();
|
|
27105
27316
|
this.signalApprovalChange();
|
|
@@ -27163,7 +27374,7 @@ var RuntimeState = class {
|
|
|
27163
27374
|
currentModelName = null;
|
|
27164
27375
|
currentModelSource = null;
|
|
27165
27376
|
sessionModelOverride = null;
|
|
27166
|
-
|
|
27377
|
+
telemetry = new RuntimeTelemetryStore();
|
|
27167
27378
|
setRuntimeEnvironment(options) {
|
|
27168
27379
|
this.effectiveEnvironment = resolveRuntimeEnvironment(options);
|
|
27169
27380
|
const value = this.effectiveEnvironment.workspace.sandboxMode;
|
|
@@ -27384,7 +27595,7 @@ function spawnRuntimeMcpStdio(state, workingDir, config, trustedService, signal)
|
|
|
27384
27595
|
}
|
|
27385
27596
|
|
|
27386
27597
|
// src/rpc/handlers.ts
|
|
27387
|
-
var
|
|
27598
|
+
var import_protocol48 = require("@codelia/protocol");
|
|
27388
27599
|
var import_storage35 = require("@codelia/storage");
|
|
27389
27600
|
|
|
27390
27601
|
// src/constants.ts
|
|
@@ -28321,6 +28532,25 @@ var CONFIG_KEYS = [
|
|
|
28321
28532
|
writeVia: "model.set"
|
|
28322
28533
|
},
|
|
28323
28534
|
{ key: "tui.theme", type: "string", fallback: null, writeVia: "theme.set" },
|
|
28535
|
+
{
|
|
28536
|
+
key: "tui.color_scheme",
|
|
28537
|
+
type: "enum",
|
|
28538
|
+
enum: ["dark", "light"],
|
|
28539
|
+
fallback: "dark"
|
|
28540
|
+
},
|
|
28541
|
+
{
|
|
28542
|
+
key: "tui.image_protocol",
|
|
28543
|
+
type: "enum",
|
|
28544
|
+
enum: ["halfblocks", "kitty"],
|
|
28545
|
+
fallback: "halfblocks"
|
|
28546
|
+
},
|
|
28547
|
+
{
|
|
28548
|
+
key: "auth.oauth_browser",
|
|
28549
|
+
type: "enum",
|
|
28550
|
+
enum: ["auto", "manual"],
|
|
28551
|
+
fallback: null
|
|
28552
|
+
},
|
|
28553
|
+
{ key: "agents.enabled", type: "boolean", fallback: true },
|
|
28324
28554
|
{
|
|
28325
28555
|
key: "subagent.max_concurrent",
|
|
28326
28556
|
type: "integer",
|
|
@@ -28573,8 +28803,68 @@ var createConfigHandlers = ({
|
|
|
28573
28803
|
return { handleConfigGet, handleConfigSet };
|
|
28574
28804
|
};
|
|
28575
28805
|
|
|
28576
|
-
// src/rpc/
|
|
28806
|
+
// src/rpc/telemetry.ts
|
|
28577
28807
|
var import_protocol19 = require("@codelia/protocol");
|
|
28808
|
+
var emptyUsage = (state) => ({
|
|
28809
|
+
provider: state.currentModelProvider,
|
|
28810
|
+
model: state.currentModelName,
|
|
28811
|
+
limit_tokens: null,
|
|
28812
|
+
used_tokens: null,
|
|
28813
|
+
input_tokens: null,
|
|
28814
|
+
left_percent: null,
|
|
28815
|
+
basis: "none",
|
|
28816
|
+
breakdown: []
|
|
28817
|
+
});
|
|
28818
|
+
var createTelemetryHandlers = ({
|
|
28819
|
+
state,
|
|
28820
|
+
subagents,
|
|
28821
|
+
log: log2
|
|
28822
|
+
}) => {
|
|
28823
|
+
const handleTelemetryGet = async (id2) => {
|
|
28824
|
+
try {
|
|
28825
|
+
const context = state.agent ? state.agent.getContextUsage() : emptyUsage(state);
|
|
28826
|
+
const mem = process.memoryUsage();
|
|
28827
|
+
const subagentStats = subagents?.getPerfStats() ?? {
|
|
28828
|
+
active: 0,
|
|
28829
|
+
maxConcurrent: 0
|
|
28830
|
+
};
|
|
28831
|
+
const result = {
|
|
28832
|
+
...state.sessionId ? { session_id: state.sessionId } : {},
|
|
28833
|
+
active_run_id: state.activeRunId,
|
|
28834
|
+
context,
|
|
28835
|
+
session_summary: state.telemetry.getSessionSummary(),
|
|
28836
|
+
run_summary: state.telemetry.getRunSummary(),
|
|
28837
|
+
recent_calls: state.telemetry.getRecentCalls(),
|
|
28838
|
+
recent_tools: state.telemetry.getRecentTools(),
|
|
28839
|
+
runtime: {
|
|
28840
|
+
startup_phases: state.telemetry.getStartupPhases(),
|
|
28841
|
+
agent_init_phases: state.telemetry.getAgentInitPhases(),
|
|
28842
|
+
active_subagents: subagentStats.active,
|
|
28843
|
+
max_concurrent_subagents: subagentStats.maxConcurrent,
|
|
28844
|
+
backpressure_events: getTransportBackpressureEvents(),
|
|
28845
|
+
memory: {
|
|
28846
|
+
rss_bytes: mem.rss,
|
|
28847
|
+
heap_used_bytes: mem.heapUsed,
|
|
28848
|
+
heap_total_bytes: mem.heapTotal,
|
|
28849
|
+
external_bytes: mem.external,
|
|
28850
|
+
array_buffers_bytes: mem.arrayBuffers
|
|
28851
|
+
}
|
|
28852
|
+
}
|
|
28853
|
+
};
|
|
28854
|
+
sendRequestResult("telemetry.get", id2, result);
|
|
28855
|
+
} catch (error) {
|
|
28856
|
+
log2(`telemetry.get failed: ${String(error)}`);
|
|
28857
|
+
sendError(id2, {
|
|
28858
|
+
code: import_protocol19.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28859
|
+
message: "telemetry unavailable"
|
|
28860
|
+
});
|
|
28861
|
+
}
|
|
28862
|
+
};
|
|
28863
|
+
return { handleTelemetryGet };
|
|
28864
|
+
};
|
|
28865
|
+
|
|
28866
|
+
// src/rpc/context.ts
|
|
28867
|
+
var import_protocol21 = require("@codelia/protocol");
|
|
28578
28868
|
var createContextHandlers = ({
|
|
28579
28869
|
state,
|
|
28580
28870
|
log: log2
|
|
@@ -28711,7 +29001,7 @@ var createContextHandlers = ({
|
|
|
28711
29001
|
sendRequestResult("context.inspect", id2, result);
|
|
28712
29002
|
} catch (error) {
|
|
28713
29003
|
sendError(id2, {
|
|
28714
|
-
code:
|
|
29004
|
+
code: import_protocol21.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28715
29005
|
message: `context.inspect failed: ${String(error)}`
|
|
28716
29006
|
});
|
|
28717
29007
|
}
|
|
@@ -28720,8 +29010,8 @@ var createContextHandlers = ({
|
|
|
28720
29010
|
};
|
|
28721
29011
|
|
|
28722
29012
|
// src/rpc/context-usage.ts
|
|
28723
|
-
var
|
|
28724
|
-
var
|
|
29013
|
+
var import_protocol23 = require("@codelia/protocol");
|
|
29014
|
+
var emptyUsage2 = (state) => ({
|
|
28725
29015
|
provider: state.currentModelProvider,
|
|
28726
29016
|
model: state.currentModelName,
|
|
28727
29017
|
limit_tokens: null,
|
|
@@ -28737,7 +29027,7 @@ var createContextUsageHandlers = ({
|
|
|
28737
29027
|
}) => {
|
|
28738
29028
|
const handleContextUsage = async (id2) => {
|
|
28739
29029
|
try {
|
|
28740
|
-
const usage = state.agent ? state.agent.getContextUsage() :
|
|
29030
|
+
const usage = state.agent ? state.agent.getContextUsage() : emptyUsage2(state);
|
|
28741
29031
|
const result = {
|
|
28742
29032
|
...usage,
|
|
28743
29033
|
...state.sessionId ? { session_id: state.sessionId } : {}
|
|
@@ -28746,7 +29036,7 @@ var createContextUsageHandlers = ({
|
|
|
28746
29036
|
} catch (error) {
|
|
28747
29037
|
log2(`context.usage failed: ${String(error)}`);
|
|
28748
29038
|
sendError(id2, {
|
|
28749
|
-
code:
|
|
29039
|
+
code: import_protocol23.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28750
29040
|
message: "context usage unavailable"
|
|
28751
29041
|
});
|
|
28752
29042
|
}
|
|
@@ -28779,7 +29069,7 @@ var createRunContextUsageEmitter = (options) => {
|
|
|
28779
29069
|
// src/rpc/history.ts
|
|
28780
29070
|
var import_node_fs45 = require("fs");
|
|
28781
29071
|
var import_node_path47 = __toESM(require("path"), 1);
|
|
28782
|
-
var
|
|
29072
|
+
var import_protocol25 = require("@codelia/protocol");
|
|
28783
29073
|
var import_storage29 = require("@codelia/storage");
|
|
28784
29074
|
var DEFAULT_HISTORY_RUNS = 20;
|
|
28785
29075
|
var DEFAULT_HISTORY_EVENTS = 1500;
|
|
@@ -28997,7 +29287,7 @@ var createHistoryHandlers = ({
|
|
|
28997
29287
|
sessions = await sessionStateStore.list();
|
|
28998
29288
|
} catch (error) {
|
|
28999
29289
|
sendError(id2, {
|
|
29000
|
-
code:
|
|
29290
|
+
code: import_protocol25.RPC_ERROR_CODE.SESSION_LIST_FAILED,
|
|
29001
29291
|
message: `session list failed: ${String(error)}`
|
|
29002
29292
|
});
|
|
29003
29293
|
return;
|
|
@@ -29030,7 +29320,7 @@ var createHistoryHandlers = ({
|
|
|
29030
29320
|
const sessionId = params?.session_id?.trim();
|
|
29031
29321
|
if (!sessionId) {
|
|
29032
29322
|
sendError(id2, {
|
|
29033
|
-
code:
|
|
29323
|
+
code: import_protocol25.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29034
29324
|
message: "session_id is required"
|
|
29035
29325
|
});
|
|
29036
29326
|
return;
|
|
@@ -29114,7 +29404,7 @@ var createHistoryHandlers = ({
|
|
|
29114
29404
|
|
|
29115
29405
|
// src/rpc/image.ts
|
|
29116
29406
|
var import_config20 = require("@codelia/config");
|
|
29117
|
-
var
|
|
29407
|
+
var import_protocol27 = require("@codelia/protocol");
|
|
29118
29408
|
function createImageHandlers(state) {
|
|
29119
29409
|
const catalog = new ImageCatalog();
|
|
29120
29410
|
let configuring = false;
|
|
@@ -29423,7 +29713,7 @@ Saved to ${scope} settings.`
|
|
|
29423
29713
|
});
|
|
29424
29714
|
} catch (error) {
|
|
29425
29715
|
sendError(id2, {
|
|
29426
|
-
code:
|
|
29716
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29427
29717
|
message: error instanceof ImageGenerationError ? error.message : "Image operation failed; check settings, artifact and runtime storage. No credentials were changed."
|
|
29428
29718
|
});
|
|
29429
29719
|
} finally {
|
|
@@ -29436,7 +29726,7 @@ Saved to ${scope} settings.`
|
|
|
29436
29726
|
// src/rpc/model.ts
|
|
29437
29727
|
var import_core38 = require("@codelia/core");
|
|
29438
29728
|
var import_model_metadata3 = require("@codelia/model-metadata");
|
|
29439
|
-
var
|
|
29729
|
+
var import_protocol29 = require("@codelia/protocol");
|
|
29440
29730
|
var import_shared_types9 = require("@codelia/shared-types");
|
|
29441
29731
|
var isSupportedProvider = (provider, providers) => SUPPORTED_PROVIDERS.includes(provider) || Boolean(providers && Object.hasOwn(providers, provider));
|
|
29442
29732
|
var resolveProviderModelEntry2 = (providerEntries, provider, model) => {
|
|
@@ -29829,7 +30119,7 @@ var createModelHandlers = ({
|
|
|
29829
30119
|
}
|
|
29830
30120
|
} catch (error) {
|
|
29831
30121
|
sendError(id2, {
|
|
29832
|
-
code:
|
|
30122
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29833
30123
|
message: String(error)
|
|
29834
30124
|
});
|
|
29835
30125
|
return;
|
|
@@ -29837,7 +30127,7 @@ var createModelHandlers = ({
|
|
|
29837
30127
|
const provider = requestedProvider ?? configuredProvider ?? "openai";
|
|
29838
30128
|
if (!isSupportedProvider(provider, providers)) {
|
|
29839
30129
|
sendError(id2, {
|
|
29840
|
-
code:
|
|
30130
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29841
30131
|
message: `unsupported provider: ${provider}`
|
|
29842
30132
|
});
|
|
29843
30133
|
return;
|
|
@@ -29856,7 +30146,7 @@ var createModelHandlers = ({
|
|
|
29856
30146
|
details = result2.details;
|
|
29857
30147
|
} catch (error) {
|
|
29858
30148
|
sendError(id2, {
|
|
29859
|
-
code:
|
|
30149
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29860
30150
|
message: String(error)
|
|
29861
30151
|
});
|
|
29862
30152
|
return;
|
|
@@ -29887,7 +30177,7 @@ var createModelHandlers = ({
|
|
|
29887
30177
|
const handleModelSet = async (id2, raw) => {
|
|
29888
30178
|
if (state.activeRunId) {
|
|
29889
30179
|
sendError(id2, {
|
|
29890
|
-
code:
|
|
30180
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
29891
30181
|
message: "runtime busy"
|
|
29892
30182
|
});
|
|
29893
30183
|
return;
|
|
@@ -29904,7 +30194,7 @@ var createModelHandlers = ({
|
|
|
29904
30194
|
const scope = params?.scope ?? "config";
|
|
29905
30195
|
if (scope !== "config" && scope !== "session") {
|
|
29906
30196
|
sendError(id2, {
|
|
29907
|
-
code:
|
|
30197
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29908
30198
|
message: `unsupported model scope: ${scope}`
|
|
29909
30199
|
});
|
|
29910
30200
|
return;
|
|
@@ -29913,7 +30203,7 @@ var createModelHandlers = ({
|
|
|
29913
30203
|
if (params?.reset) {
|
|
29914
30204
|
if (scope !== "session") {
|
|
29915
30205
|
sendError(id2, {
|
|
29916
|
-
code:
|
|
30206
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29917
30207
|
message: "model reset is only supported for session scope"
|
|
29918
30208
|
});
|
|
29919
30209
|
return;
|
|
@@ -29924,7 +30214,7 @@ var createModelHandlers = ({
|
|
|
29924
30214
|
const name3 = config.name;
|
|
29925
30215
|
if (!name3) {
|
|
29926
30216
|
sendError(id2, {
|
|
29927
|
-
code:
|
|
30217
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29928
30218
|
message: "configured model name is missing"
|
|
29929
30219
|
});
|
|
29930
30220
|
return;
|
|
@@ -29940,7 +30230,7 @@ var createModelHandlers = ({
|
|
|
29940
30230
|
);
|
|
29941
30231
|
} catch (error) {
|
|
29942
30232
|
sendError(id2, {
|
|
29943
|
-
code:
|
|
30233
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29944
30234
|
message: String(error)
|
|
29945
30235
|
});
|
|
29946
30236
|
return;
|
|
@@ -29962,7 +30252,7 @@ var createModelHandlers = ({
|
|
|
29962
30252
|
log2(`model.set reset session override -> ${provider2}/${name3}`);
|
|
29963
30253
|
} catch (error) {
|
|
29964
30254
|
sendError(id2, {
|
|
29965
|
-
code:
|
|
30255
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29966
30256
|
message: String(error)
|
|
29967
30257
|
});
|
|
29968
30258
|
}
|
|
@@ -29972,7 +30262,7 @@ var createModelHandlers = ({
|
|
|
29972
30262
|
let name2 = params?.name?.trim();
|
|
29973
30263
|
if (!name2) {
|
|
29974
30264
|
sendError(id2, {
|
|
29975
|
-
code:
|
|
30265
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29976
30266
|
message: "model name is required"
|
|
29977
30267
|
});
|
|
29978
30268
|
return;
|
|
@@ -29983,7 +30273,7 @@ var createModelHandlers = ({
|
|
|
29983
30273
|
reasoning = resolveReasoningEffort(params.reasoning);
|
|
29984
30274
|
} catch (error) {
|
|
29985
30275
|
sendError(id2, {
|
|
29986
|
-
code:
|
|
30276
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29987
30277
|
message: String(error)
|
|
29988
30278
|
});
|
|
29989
30279
|
return;
|
|
@@ -29993,7 +30283,7 @@ var createModelHandlers = ({
|
|
|
29993
30283
|
const endpoint = getResponsesProvider(configured, provider);
|
|
29994
30284
|
if (!isSupportedProvider(provider, configured.providers)) {
|
|
29995
30285
|
sendError(id2, {
|
|
29996
|
-
code:
|
|
30286
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29997
30287
|
message: `unsupported provider: ${provider}`
|
|
29998
30288
|
});
|
|
29999
30289
|
return;
|
|
@@ -30006,7 +30296,7 @@ var createModelHandlers = ({
|
|
|
30006
30296
|
);
|
|
30007
30297
|
if (!spec) {
|
|
30008
30298
|
sendError(id2, {
|
|
30009
|
-
code:
|
|
30299
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30010
30300
|
message: `unknown model: ${name2}`
|
|
30011
30301
|
});
|
|
30012
30302
|
return;
|
|
@@ -30039,7 +30329,7 @@ var createModelHandlers = ({
|
|
|
30039
30329
|
await validateFastSelection(provider, name2, candidate.fast);
|
|
30040
30330
|
} catch (error) {
|
|
30041
30331
|
sendError(id2, {
|
|
30042
|
-
code:
|
|
30332
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30043
30333
|
message: String(error)
|
|
30044
30334
|
});
|
|
30045
30335
|
return;
|
|
@@ -30094,7 +30384,7 @@ var createModelHandlers = ({
|
|
|
30094
30384
|
);
|
|
30095
30385
|
} catch (error) {
|
|
30096
30386
|
sendError(id2, {
|
|
30097
|
-
code:
|
|
30387
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
30098
30388
|
message: String(error)
|
|
30099
30389
|
});
|
|
30100
30390
|
}
|
|
@@ -30105,7 +30395,7 @@ var createModelHandlers = ({
|
|
|
30105
30395
|
// src/rpc/permissions.ts
|
|
30106
30396
|
var import_node_fs46 = require("fs");
|
|
30107
30397
|
var import_config_loader3 = require("@codelia/config-loader");
|
|
30108
|
-
var
|
|
30398
|
+
var import_protocol31 = require("@codelia/protocol");
|
|
30109
30399
|
var import_storage30 = require("@codelia/storage");
|
|
30110
30400
|
var MAX_RULE_FIELD_LENGTH = 4096;
|
|
30111
30401
|
var RULE_FIELDS = ["tool", "command", "command_glob", "skill_name"];
|
|
@@ -30142,7 +30432,7 @@ var createPermissionsHandlers = ({
|
|
|
30142
30432
|
const rejectUnsupported = (id2) => {
|
|
30143
30433
|
if (supportsConfigReadWrite(state)) return false;
|
|
30144
30434
|
sendError(id2, {
|
|
30145
|
-
code:
|
|
30435
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30146
30436
|
message: "permission rules are not available for this runtime"
|
|
30147
30437
|
});
|
|
30148
30438
|
return true;
|
|
@@ -30154,7 +30444,7 @@ var createPermissionsHandlers = ({
|
|
|
30154
30444
|
const params = parsed.params;
|
|
30155
30445
|
if (params?.include_system !== void 0 && typeof params.include_system !== "boolean") {
|
|
30156
30446
|
sendError(id2, {
|
|
30157
|
-
code:
|
|
30447
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30158
30448
|
message: "include_system must be a boolean"
|
|
30159
30449
|
});
|
|
30160
30450
|
return;
|
|
@@ -30256,7 +30546,7 @@ var createPermissionsHandlers = ({
|
|
|
30256
30546
|
const root = resolveConfigWorkspaceDir(state);
|
|
30257
30547
|
if (!root || !localProjectAllows(state) || params.scope !== "project" || !configurableToolInvocations.has(params.remembered_tool)) {
|
|
30258
30548
|
sendError(id2, {
|
|
30259
|
-
code:
|
|
30549
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30260
30550
|
message: "Invalid remembered tool"
|
|
30261
30551
|
});
|
|
30262
30552
|
return;
|
|
@@ -30277,7 +30567,7 @@ var createPermissionsHandlers = ({
|
|
|
30277
30567
|
});
|
|
30278
30568
|
if (removed === "busy") {
|
|
30279
30569
|
sendError(id2, {
|
|
30280
|
-
code:
|
|
30570
|
+
code: import_protocol31.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30281
30571
|
message: "runtime busy"
|
|
30282
30572
|
});
|
|
30283
30573
|
return;
|
|
@@ -30289,7 +30579,7 @@ var createPermissionsHandlers = ({
|
|
|
30289
30579
|
});
|
|
30290
30580
|
} catch {
|
|
30291
30581
|
sendError(id2, {
|
|
30292
|
-
code:
|
|
30582
|
+
code: import_protocol31.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
30293
30583
|
message: "Remembered tool removal failed"
|
|
30294
30584
|
});
|
|
30295
30585
|
}
|
|
@@ -30298,7 +30588,7 @@ var createPermissionsHandlers = ({
|
|
|
30298
30588
|
const workspaceDir = resolveConfigWorkspaceDir(state);
|
|
30299
30589
|
if (!workspaceDir || params.resource !== "workspace_write" || params.scope !== "session") {
|
|
30300
30590
|
sendError(id2, {
|
|
30301
|
-
code:
|
|
30591
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30302
30592
|
message: "Invalid workspace grant reference"
|
|
30303
30593
|
});
|
|
30304
30594
|
return;
|
|
@@ -30314,7 +30604,7 @@ var createPermissionsHandlers = ({
|
|
|
30314
30604
|
const workspaceDir = resolveConfigWorkspaceDir(state);
|
|
30315
30605
|
if (!workspaceDir || !/^[a-f0-9]{64}$/u.test(params.launch_rule_id) || params.scope !== "session" && params.scope !== "project" || state.effectiveEnvironment.sourcePreset !== "tui-local") {
|
|
30316
30606
|
sendError(id2, {
|
|
30317
|
-
code:
|
|
30607
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30318
30608
|
message: "Invalid launch rule reference"
|
|
30319
30609
|
});
|
|
30320
30610
|
return;
|
|
@@ -30334,7 +30624,7 @@ var createPermissionsHandlers = ({
|
|
|
30334
30624
|
sendRequestResult("permissions.remove", id2, result);
|
|
30335
30625
|
} catch {
|
|
30336
30626
|
sendError(id2, {
|
|
30337
|
-
code:
|
|
30627
|
+
code: import_protocol31.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
30338
30628
|
message: "Launch rule removal failed"
|
|
30339
30629
|
});
|
|
30340
30630
|
}
|
|
@@ -30351,12 +30641,12 @@ var createPermissionsHandlers = ({
|
|
|
30351
30641
|
return removeLaunchRule(id2, params);
|
|
30352
30642
|
if (state.activeRunId) {
|
|
30353
30643
|
sendError(id2, {
|
|
30354
|
-
code:
|
|
30644
|
+
code: import_protocol31.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30355
30645
|
message: "runtime busy"
|
|
30356
30646
|
});
|
|
30357
30647
|
return;
|
|
30358
30648
|
}
|
|
30359
|
-
const invalid = (message) => sendError(id2, { code:
|
|
30649
|
+
const invalid = (message) => sendError(id2, { code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS, message });
|
|
30360
30650
|
const scope = params?.scope;
|
|
30361
30651
|
const kind = params?.kind;
|
|
30362
30652
|
if (scope !== "global" && scope !== "project") {
|
|
@@ -30392,14 +30682,14 @@ var createPermissionsHandlers = ({
|
|
|
30392
30682
|
});
|
|
30393
30683
|
} catch {
|
|
30394
30684
|
sendError(id2, {
|
|
30395
|
-
code:
|
|
30685
|
+
code: import_protocol31.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
30396
30686
|
message: `${scope} config write failed`
|
|
30397
30687
|
});
|
|
30398
30688
|
return;
|
|
30399
30689
|
}
|
|
30400
30690
|
if (removed === "busy") {
|
|
30401
30691
|
sendError(id2, {
|
|
30402
|
-
code:
|
|
30692
|
+
code: import_protocol31.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30403
30693
|
message: "runtime busy"
|
|
30404
30694
|
});
|
|
30405
30695
|
return;
|
|
@@ -30411,7 +30701,7 @@ var createPermissionsHandlers = ({
|
|
|
30411
30701
|
const handleProjectAllowTrustSet = async (id2, raw) => {
|
|
30412
30702
|
if (!supportsProjectAllowTrust(state)) {
|
|
30413
30703
|
sendError(id2, {
|
|
30414
|
-
code:
|
|
30704
|
+
code: import_protocol31.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
30415
30705
|
message: "Project allow trust changes are unavailable for this runtime."
|
|
30416
30706
|
});
|
|
30417
30707
|
return;
|
|
@@ -30421,7 +30711,7 @@ var createPermissionsHandlers = ({
|
|
|
30421
30711
|
const params = parsed.params;
|
|
30422
30712
|
if (typeof params?.workspace !== "string" || typeof params.trusted !== "boolean" || typeof params.expected_revision !== "string" || !params.expected_revision) {
|
|
30423
30713
|
sendError(id2, {
|
|
30424
|
-
code:
|
|
30714
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30425
30715
|
message: "Expected a reviewed project allow list for this local workspace"
|
|
30426
30716
|
});
|
|
30427
30717
|
return;
|
|
@@ -30430,7 +30720,7 @@ var createPermissionsHandlers = ({
|
|
|
30430
30720
|
await state.withAdmissionLock(async () => {
|
|
30431
30721
|
if (state.activeRunId) {
|
|
30432
30722
|
sendError(id2, {
|
|
30433
|
-
code:
|
|
30723
|
+
code: import_protocol31.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30434
30724
|
message: "runtime busy"
|
|
30435
30725
|
});
|
|
30436
30726
|
return;
|
|
@@ -30438,7 +30728,7 @@ var createPermissionsHandlers = ({
|
|
|
30438
30728
|
const root = resolveConfigWorkspaceDir(state);
|
|
30439
30729
|
if (!root || (0, import_node_fs46.realpathSync)(root) !== params.workspace) {
|
|
30440
30730
|
sendError(id2, {
|
|
30441
|
-
code:
|
|
30731
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30442
30732
|
message: "Workspace changed. Review the current project allow list again."
|
|
30443
30733
|
});
|
|
30444
30734
|
return;
|
|
@@ -30458,7 +30748,7 @@ var createPermissionsHandlers = ({
|
|
|
30458
30748
|
} catch (error) {
|
|
30459
30749
|
const changed = error instanceof Error && error.message === "project_allow_trust_changed";
|
|
30460
30750
|
sendError(id2, {
|
|
30461
|
-
code: changed ?
|
|
30751
|
+
code: changed ? import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol31.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
30462
30752
|
message: changed ? "The project allow list or its trust state changed. Review it again." : "Project allow trust is unavailable."
|
|
30463
30753
|
});
|
|
30464
30754
|
}
|
|
@@ -30843,7 +31133,7 @@ var buildResumeDiff = async (meta, state, options = {}) => {
|
|
|
30843
31133
|
};
|
|
30844
31134
|
|
|
30845
31135
|
// src/rpc/run.ts
|
|
30846
|
-
var
|
|
31136
|
+
var import_protocol35 = require("@codelia/protocol");
|
|
30847
31137
|
|
|
30848
31138
|
// src/provider-errors.ts
|
|
30849
31139
|
var import_core39 = require("@codelia/core");
|
|
@@ -30913,7 +31203,7 @@ var normalizeRunFailure = (error) => {
|
|
|
30913
31203
|
|
|
30914
31204
|
// src/rpc/goals.ts
|
|
30915
31205
|
var import_core40 = require("@codelia/core");
|
|
30916
|
-
var
|
|
31206
|
+
var import_protocol33 = require("@codelia/protocol");
|
|
30917
31207
|
var import_storage31 = require("@codelia/storage");
|
|
30918
31208
|
var import_zod47 = require("zod");
|
|
30919
31209
|
var id = import_zod47.z.string().min(1).max(200);
|
|
@@ -31066,7 +31356,7 @@ var GoalController = class {
|
|
|
31066
31356
|
handle(requestId, method, raw, serialize, interrupt, onError) {
|
|
31067
31357
|
if (!this.enabled) {
|
|
31068
31358
|
sendError(requestId, {
|
|
31069
|
-
code:
|
|
31359
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31070
31360
|
message: "Goals are unavailable on this connection."
|
|
31071
31361
|
});
|
|
31072
31362
|
return Promise.resolve();
|
|
@@ -31259,7 +31549,7 @@ var GoalController = class {
|
|
|
31259
31549
|
reject(requestId, error) {
|
|
31260
31550
|
const conflict = error instanceof GoalConflict ? error : null;
|
|
31261
31551
|
sendError(requestId, {
|
|
31262
|
-
code: conflict?.reason === "busy" ?
|
|
31552
|
+
code: conflict?.reason === "busy" ? import_protocol33.RPC_ERROR_CODE.RUNTIME_BUSY : conflict || error instanceof import_zod47.z.ZodError ? import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol33.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31263
31553
|
message: conflict?.message ?? (error instanceof import_zod47.z.ZodError ? "Invalid goal parameters." : "Goal operation failed.")
|
|
31264
31554
|
});
|
|
31265
31555
|
}
|
|
@@ -31950,6 +32240,13 @@ var runInputLengthForDebug = (input) => {
|
|
|
31950
32240
|
};
|
|
31951
32241
|
|
|
31952
32242
|
// src/rpc/run-metrics.ts
|
|
32243
|
+
var import_core42 = require("@codelia/core");
|
|
32244
|
+
var nonEmpty = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
32245
|
+
var extractActualModel = (providerMeta) => {
|
|
32246
|
+
const meta = providerMeta;
|
|
32247
|
+
const rawServerModel = meta?.codex_metadata?.server_model ?? meta?.server_model;
|
|
32248
|
+
return typeof rawServerModel === "string" && rawServerModel.trim().length > 0 ? rawServerModel.trim() : null;
|
|
32249
|
+
};
|
|
31953
32250
|
var buildRunMetrics = (record) => {
|
|
31954
32251
|
const timing = record.output.timing;
|
|
31955
32252
|
const tokens = record.output.usage?.output_tokens;
|
|
@@ -31966,6 +32263,45 @@ var buildRunMetrics = (record) => {
|
|
|
31966
32263
|
...validTiming ? { timing } : {}
|
|
31967
32264
|
};
|
|
31968
32265
|
};
|
|
32266
|
+
var buildCallRunMetrics = (input) => {
|
|
32267
|
+
const { record, request } = input;
|
|
32268
|
+
const usage = record.output.usage ?? null;
|
|
32269
|
+
const hasCacheMetric = typeof usage?.input_cached_tokens === "number";
|
|
32270
|
+
const cacheReadTokens = hasCacheMetric ? usage?.input_cached_tokens ?? 0 : 0;
|
|
32271
|
+
const cacheCreationTokens = usage?.input_cache_creation_tokens ?? 0;
|
|
32272
|
+
const inputTokens = usage?.input_tokens ?? 0;
|
|
32273
|
+
const hitState = hasCacheMetric ? cacheReadTokens > 0 ? "hit" : "miss" : "unknown";
|
|
32274
|
+
const requestModel = nonEmpty(request?.model);
|
|
32275
|
+
const usageModel = nonEmpty(usage?.model);
|
|
32276
|
+
const model = usageModel ?? requestModel ?? "unknown";
|
|
32277
|
+
const baseMetrics = buildRunMetrics(record);
|
|
32278
|
+
const modelCost = input.getModelCost ? (requestModel ? input.getModelCost(requestModel) : void 0) ?? input.getModelCost(model) : void 0;
|
|
32279
|
+
const costUsd = input.metered ? (0, import_core42.estimateUsageCostUsd)(usage, modelCost) : null;
|
|
32280
|
+
const actualModel = extractActualModel(record.output.provider_meta);
|
|
32281
|
+
return {
|
|
32282
|
+
...baseMetrics,
|
|
32283
|
+
...request?.provider ? { provider: request.provider } : {},
|
|
32284
|
+
model,
|
|
32285
|
+
...actualModel ? { actual_model: actualModel } : {},
|
|
32286
|
+
request_ts: request?.ts ?? record.ts,
|
|
32287
|
+
response_ts: record.ts,
|
|
32288
|
+
latency_ms: Math.max(0, Math.round(input.latencyMs)),
|
|
32289
|
+
stop_reason: record.output.stop_reason ?? null,
|
|
32290
|
+
usage,
|
|
32291
|
+
cache: {
|
|
32292
|
+
hit_state: hitState,
|
|
32293
|
+
cache_read_tokens: cacheReadTokens,
|
|
32294
|
+
cache_creation_tokens: cacheCreationTokens,
|
|
32295
|
+
cache_read_ratio: hasCacheMetric && inputTokens > 0 ? Math.min(1, Math.max(0, cacheReadTokens / inputTokens)) : null
|
|
32296
|
+
},
|
|
32297
|
+
cost_usd: costUsd,
|
|
32298
|
+
cost_basis: costUsd !== null ? "api_list" : "unavailable",
|
|
32299
|
+
retry_count: Math.max(0, input.retryCount),
|
|
32300
|
+
retry_wait_ms: Math.max(0, input.retryWaitMs),
|
|
32301
|
+
provider_meta_summary: summarizeProviderMeta(record.output.provider_meta),
|
|
32302
|
+
...input.context ? { context: input.context } : {}
|
|
32303
|
+
};
|
|
32304
|
+
};
|
|
31969
32305
|
|
|
31970
32306
|
// src/rpc/text-delta-coalescer.ts
|
|
31971
32307
|
var DEFAULT_TEXT_DELTA_FLUSH_MS = 40;
|
|
@@ -32100,10 +32436,6 @@ var mergeWorkspaceRootIntoSessionMeta = (meta, workspaceRoot) => {
|
|
|
32100
32436
|
return Object.keys(nextMeta).length > 0 ? nextMeta : void 0;
|
|
32101
32437
|
};
|
|
32102
32438
|
var resolveSessionWorkspaceRoot = (state) => state.lastUiContext?.workspace_root ?? state.agentsResolver?.getRootDir() ?? state.runtimeSandboxRoot ?? state.runtimeWorkingDir ?? void 0;
|
|
32103
|
-
var toTimestampMs = (value) => {
|
|
32104
|
-
const ms = Date.parse(value);
|
|
32105
|
-
return Number.isFinite(ms) ? ms : null;
|
|
32106
|
-
};
|
|
32107
32439
|
var OPENAI_AUTO_WS_FALLBACK_WARNING = "Warning: OpenAI websocket auto mode fell back to HTTP. Continuing this run over HTTP.";
|
|
32108
32440
|
var shouldEmitOpenAiWsFallbackWarning = (providerMeta) => {
|
|
32109
32441
|
if (!providerMeta || typeof providerMeta !== "object" || Array.isArray(providerMeta)) {
|
|
@@ -32221,7 +32553,7 @@ var createRunHandlers = ({
|
|
|
32221
32553
|
initialInput = normalizeRunInput(params.input);
|
|
32222
32554
|
} catch (error) {
|
|
32223
32555
|
sendError(id2, {
|
|
32224
|
-
code:
|
|
32556
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32225
32557
|
message: String(error)
|
|
32226
32558
|
});
|
|
32227
32559
|
return;
|
|
@@ -32229,7 +32561,7 @@ var createRunHandlers = ({
|
|
|
32229
32561
|
const attachmentIds = runAttachmentIds(initialInput);
|
|
32230
32562
|
if (params.force_compaction && attachmentIds.length > 0) {
|
|
32231
32563
|
sendError(id2, {
|
|
32232
|
-
code:
|
|
32564
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32233
32565
|
message: "A compaction run cannot admit new attachments"
|
|
32234
32566
|
});
|
|
32235
32567
|
return;
|
|
@@ -32239,7 +32571,7 @@ var createRunHandlers = ({
|
|
|
32239
32571
|
await beforeRunStart();
|
|
32240
32572
|
} catch (error) {
|
|
32241
32573
|
sendError(id2, {
|
|
32242
|
-
code:
|
|
32574
|
+
code: import_protocol35.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
32243
32575
|
message: `startup onboarding failed: ${String(error)}`
|
|
32244
32576
|
});
|
|
32245
32577
|
return;
|
|
@@ -32247,7 +32579,7 @@ var createRunHandlers = ({
|
|
|
32247
32579
|
}
|
|
32248
32580
|
if (state.activeRunId) {
|
|
32249
32581
|
sendError(id2, {
|
|
32250
|
-
code:
|
|
32582
|
+
code: import_protocol35.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
32251
32583
|
message: "runtime busy"
|
|
32252
32584
|
});
|
|
32253
32585
|
return;
|
|
@@ -32264,14 +32596,14 @@ var createRunHandlers = ({
|
|
|
32264
32596
|
resumeState = await sessionStateStore.load(requestedSessionId);
|
|
32265
32597
|
} catch (error) {
|
|
32266
32598
|
sendError(id2, {
|
|
32267
|
-
code:
|
|
32599
|
+
code: import_protocol35.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
32268
32600
|
message: `session load failed: ${String(error)}`
|
|
32269
32601
|
});
|
|
32270
32602
|
return;
|
|
32271
32603
|
}
|
|
32272
32604
|
if (!resumeState) {
|
|
32273
32605
|
sendError(id2, {
|
|
32274
|
-
code:
|
|
32606
|
+
code: import_protocol35.RPC_ERROR_CODE.SESSION_NOT_FOUND,
|
|
32275
32607
|
message: "session not found"
|
|
32276
32608
|
});
|
|
32277
32609
|
return;
|
|
@@ -32282,7 +32614,7 @@ var createRunHandlers = ({
|
|
|
32282
32614
|
resumeState = await sessionStateStore.load(state.sessionId);
|
|
32283
32615
|
} catch (error) {
|
|
32284
32616
|
sendError(id2, {
|
|
32285
|
-
code:
|
|
32617
|
+
code: import_protocol35.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
32286
32618
|
message: `session reload failed: ${String(error)}`
|
|
32287
32619
|
});
|
|
32288
32620
|
return;
|
|
@@ -32299,7 +32631,7 @@ var createRunHandlers = ({
|
|
|
32299
32631
|
if (resumeState?.meta?.codelia_subagent) {
|
|
32300
32632
|
restorePreviousModel();
|
|
32301
32633
|
sendError(id2, {
|
|
32302
|
-
code:
|
|
32634
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32303
32635
|
message: "Delegated sessions cannot be resumed as a root run"
|
|
32304
32636
|
});
|
|
32305
32637
|
return;
|
|
@@ -32324,7 +32656,7 @@ var createRunHandlers = ({
|
|
|
32324
32656
|
} catch (error) {
|
|
32325
32657
|
restorePreviousModel();
|
|
32326
32658
|
sendError(id2, {
|
|
32327
|
-
code: error instanceof AttachmentAdmissionError ?
|
|
32659
|
+
code: error instanceof AttachmentAdmissionError ? import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol35.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
32328
32660
|
message: error instanceof Error ? error.message : String(error)
|
|
32329
32661
|
});
|
|
32330
32662
|
return;
|
|
@@ -32341,7 +32673,7 @@ var createRunHandlers = ({
|
|
|
32341
32673
|
} catch (error) {
|
|
32342
32674
|
restorePreviousModel();
|
|
32343
32675
|
sendError(id2, {
|
|
32344
|
-
code:
|
|
32676
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32345
32677
|
message: String(error)
|
|
32346
32678
|
});
|
|
32347
32679
|
return;
|
|
@@ -32360,7 +32692,7 @@ var createRunHandlers = ({
|
|
|
32360
32692
|
} catch {
|
|
32361
32693
|
restorePreviousModel();
|
|
32362
32694
|
sendError(id2, {
|
|
32363
|
-
code:
|
|
32695
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32364
32696
|
message: "Could not claim the attachments for this conversation. Upload them again."
|
|
32365
32697
|
});
|
|
32366
32698
|
return;
|
|
@@ -32480,22 +32812,30 @@ var createRunHandlers = ({
|
|
|
32480
32812
|
}
|
|
32481
32813
|
);
|
|
32482
32814
|
const pendingLlmRequests = /* @__PURE__ */ new Map();
|
|
32815
|
+
const toolNamesByCallId = /* @__PURE__ */ new Map();
|
|
32816
|
+
let pendingRetryCount = 0;
|
|
32817
|
+
let pendingRetryWaitMs = 0;
|
|
32818
|
+
let activeRetry = null;
|
|
32819
|
+
const settleActiveRetryWait = (interrupted) => {
|
|
32820
|
+
if (!activeRetry) return;
|
|
32821
|
+
const { startedAtMs, plannedMs } = activeRetry;
|
|
32822
|
+
activeRetry = null;
|
|
32823
|
+
const waitMs = interrupted ? Math.min(
|
|
32824
|
+
plannedMs,
|
|
32825
|
+
Math.max(0, Math.round(performance.now() - startedAtMs))
|
|
32826
|
+
) : plannedMs;
|
|
32827
|
+
pendingRetryWaitMs += waitMs;
|
|
32828
|
+
state.telemetry.recordRetryWait(runId, waitMs);
|
|
32829
|
+
};
|
|
32830
|
+
const runStartedAtMs = performance.now();
|
|
32831
|
+
state.telemetry.beginRun(runId);
|
|
32483
32832
|
let openAiWsFallbackWarningShown = false;
|
|
32484
32833
|
const streamDeltas = state.uiCapabilities?.supports_text_delta === true;
|
|
32485
|
-
const diagnosticsActive = state.diagnosticsEnabled || state.uiCapabilities?.supports_run_diagnostics === true;
|
|
32486
32834
|
const deltaCoalescer = streamDeltas ? createTextDeltaCoalescer({
|
|
32487
32835
|
send: (event) => {
|
|
32488
32836
|
if (!state.cancelRequested) sendAgentEvent(state, runId, event);
|
|
32489
32837
|
}
|
|
32490
32838
|
}) : null;
|
|
32491
|
-
const emitRunDiagnostics = (params2) => {
|
|
32492
|
-
if (!diagnosticsActive) return;
|
|
32493
|
-
try {
|
|
32494
|
-
sendRunDiagnostics(state, params2);
|
|
32495
|
-
} catch (error) {
|
|
32496
|
-
log2(`run diagnostics emit failed: ${String(error)}`);
|
|
32497
|
-
}
|
|
32498
|
-
};
|
|
32499
32839
|
const emitOpenAiWsFallbackWarning = () => {
|
|
32500
32840
|
if (openAiWsFallbackWarningShown) {
|
|
32501
32841
|
return;
|
|
@@ -32524,68 +32864,44 @@ var createRunHandlers = ({
|
|
|
32524
32864
|
}
|
|
32525
32865
|
};
|
|
32526
32866
|
const sessionAppend = (record) => {
|
|
32527
|
-
|
|
32528
|
-
|
|
32529
|
-
|
|
32530
|
-
|
|
32531
|
-
|
|
32867
|
+
try {
|
|
32868
|
+
if (record.type === "llm.request") {
|
|
32869
|
+
const modelName = record.model?.name ?? record.input.model ?? "unknown";
|
|
32870
|
+
pendingLlmRequests.set(record.seq, {
|
|
32871
|
+
ts: record.ts,
|
|
32872
|
+
startedAtMs: performance.now(),
|
|
32873
|
+
provider: record.model?.provider,
|
|
32874
|
+
model: modelName
|
|
32875
|
+
});
|
|
32532
32876
|
}
|
|
32533
|
-
|
|
32534
|
-
|
|
32535
|
-
|
|
32536
|
-
|
|
32537
|
-
|
|
32538
|
-
|
|
32539
|
-
|
|
32540
|
-
|
|
32541
|
-
|
|
32542
|
-
|
|
32543
|
-
|
|
32544
|
-
|
|
32545
|
-
|
|
32546
|
-
|
|
32547
|
-
|
|
32548
|
-
|
|
32549
|
-
|
|
32550
|
-
|
|
32551
|
-
|
|
32552
|
-
|
|
32553
|
-
|
|
32554
|
-
|
|
32555
|
-
|
|
32556
|
-
|
|
32557
|
-
|
|
32558
|
-
run_id: runId,
|
|
32559
|
-
seq: record.seq,
|
|
32560
|
-
...request?.provider ? { provider: request.provider } : {},
|
|
32561
|
-
model,
|
|
32562
|
-
request_ts: request?.ts ?? record.ts,
|
|
32563
|
-
response_ts: record.ts,
|
|
32564
|
-
latency_ms: latencyMs,
|
|
32565
|
-
...metrics.timing ? { timing: metrics.timing } : {},
|
|
32566
|
-
output_tokens_per_second: metrics.output_tokens_per_second,
|
|
32567
|
-
stop_reason: record.output.stop_reason ?? null,
|
|
32568
|
-
usage,
|
|
32569
|
-
cache: {
|
|
32570
|
-
hit_state: hitState,
|
|
32571
|
-
cache_read_tokens: cacheReadTokens,
|
|
32572
|
-
cache_creation_tokens: cacheCreationTokens,
|
|
32573
|
-
cache_read_ratio: usage ? cacheReadTokens / Math.max(inputTokens, 1) : null
|
|
32574
|
-
},
|
|
32575
|
-
cost_usd: null,
|
|
32576
|
-
provider_meta_summary: summarizeProviderMeta(
|
|
32577
|
-
record.output.provider_meta
|
|
32578
|
-
)
|
|
32579
|
-
};
|
|
32580
|
-
emitRunDiagnostics({
|
|
32581
|
-
run_id: runId,
|
|
32582
|
-
kind: "llm_call",
|
|
32583
|
-
call: diagnostics
|
|
32584
|
-
});
|
|
32585
|
-
}
|
|
32586
|
-
} catch (error) {
|
|
32587
|
-
log2(`run diagnostics build failed: ${String(error)}`);
|
|
32877
|
+
if (record.type === "llm.response") {
|
|
32878
|
+
settleActiveRetryWait(false);
|
|
32879
|
+
const request = pendingLlmRequests.get(record.seq);
|
|
32880
|
+
pendingLlmRequests.delete(record.seq);
|
|
32881
|
+
const latencyMs = request ? Math.max(0, Math.round(performance.now() - request.startedAtMs)) : 0;
|
|
32882
|
+
const route = state.reviewChatRoute;
|
|
32883
|
+
const retryCount = pendingRetryCount;
|
|
32884
|
+
const retryWaitMs = pendingRetryWaitMs;
|
|
32885
|
+
pendingRetryCount = 0;
|
|
32886
|
+
pendingRetryWaitMs = 0;
|
|
32887
|
+
const metrics = buildCallRunMetrics({
|
|
32888
|
+
record,
|
|
32889
|
+
request,
|
|
32890
|
+
latencyMs,
|
|
32891
|
+
metered: route?.kind === "builtin" && route.metered === true,
|
|
32892
|
+
getModelCost: (modelName) => runtimeAgent.getModelCost(modelName),
|
|
32893
|
+
retryCount,
|
|
32894
|
+
retryWaitMs,
|
|
32895
|
+
context: runtimeAgent.getContextSnapshot()
|
|
32896
|
+
});
|
|
32897
|
+
state.telemetry.recordLlmCall(metrics);
|
|
32898
|
+
sendRunMetrics(state, {
|
|
32899
|
+
...metrics,
|
|
32900
|
+
session: state.telemetry.getSessionSummary()
|
|
32901
|
+
});
|
|
32588
32902
|
}
|
|
32903
|
+
} catch (error) {
|
|
32904
|
+
log2(`run metrics build/emit failed: ${String(error)}`);
|
|
32589
32905
|
}
|
|
32590
32906
|
if (record.type === "llm.response" && shouldEmitOpenAiWsFallbackWarning(record.output.provider_meta)) {
|
|
32591
32907
|
emitOpenAiWsFallbackWarning();
|
|
@@ -32698,12 +33014,23 @@ var createRunHandlers = ({
|
|
|
32698
33014
|
let sessionSaveChain = Promise.resolve(true);
|
|
32699
33015
|
let lastSessionSaveAt = 0;
|
|
32700
33016
|
const polledUnconfirmedSteers = [];
|
|
32701
|
-
const
|
|
32702
|
-
|
|
32703
|
-
|
|
32704
|
-
|
|
32705
|
-
|
|
32706
|
-
|
|
33017
|
+
const emitRunSummary = () => {
|
|
33018
|
+
try {
|
|
33019
|
+
settleActiveRetryWait(true);
|
|
33020
|
+
const runSummary = state.telemetry.getRunSummary();
|
|
33021
|
+
if (!runSummary) return;
|
|
33022
|
+
sendRunSummary(state, {
|
|
33023
|
+
run_id: runId,
|
|
33024
|
+
duration_ms: Math.max(
|
|
33025
|
+
0,
|
|
33026
|
+
Math.round(performance.now() - runStartedAtMs)
|
|
33027
|
+
),
|
|
33028
|
+
run: runSummary,
|
|
33029
|
+
session: state.telemetry.getSessionSummary()
|
|
33030
|
+
});
|
|
33031
|
+
} catch (error) {
|
|
33032
|
+
log2(`run summary emit failed: ${String(error)}`);
|
|
33033
|
+
}
|
|
32707
33034
|
};
|
|
32708
33035
|
const buildTerminalStatusExtras = () => {
|
|
32709
33036
|
state.closeRunSteers(runId);
|
|
@@ -32854,11 +33181,41 @@ var createRunHandlers = ({
|
|
|
32854
33181
|
continue;
|
|
32855
33182
|
}
|
|
32856
33183
|
deltaCoalescer?.flush();
|
|
33184
|
+
if (event.type === "llm.retry") {
|
|
33185
|
+
settleActiveRetryWait(false);
|
|
33186
|
+
const delayMs = Math.max(0, event.delay_ms);
|
|
33187
|
+
pendingRetryCount += 1;
|
|
33188
|
+
state.telemetry.recordRetry(runId, 0);
|
|
33189
|
+
activeRetry = {
|
|
33190
|
+
startedAtMs: performance.now(),
|
|
33191
|
+
plannedMs: delayMs
|
|
33192
|
+
};
|
|
33193
|
+
}
|
|
33194
|
+
if (event.type === "tool_call") {
|
|
33195
|
+
toolNamesByCallId.set(event.tool_call_id, event.tool);
|
|
33196
|
+
}
|
|
33197
|
+
if (event.type === "step_complete") {
|
|
33198
|
+
const toolName = toolNamesByCallId.get(event.step_id) ?? "unknown";
|
|
33199
|
+
toolNamesByCallId.delete(event.step_id);
|
|
33200
|
+
state.telemetry.recordToolComplete({
|
|
33201
|
+
run_id: runId,
|
|
33202
|
+
tool_call_id: event.step_id,
|
|
33203
|
+
tool: toolName,
|
|
33204
|
+
status: event.status,
|
|
33205
|
+
duration_ms: event.duration_ms,
|
|
33206
|
+
...event.exec_duration_ms !== void 0 ? { exec_duration_ms: event.exec_duration_ms } : {},
|
|
33207
|
+
...event.approval_wait_ms !== void 0 ? { approval_wait_ms: event.approval_wait_ms } : {},
|
|
33208
|
+
finished_at: nowIso5()
|
|
33209
|
+
});
|
|
33210
|
+
}
|
|
32857
33211
|
if (event.type === "final") {
|
|
32858
33212
|
finalResponse = event.content;
|
|
32859
33213
|
await queueSessionSave("final");
|
|
32860
33214
|
}
|
|
32861
33215
|
if (event.type === "compaction_complete") {
|
|
33216
|
+
if (event.compacted) {
|
|
33217
|
+
state.telemetry.recordCompaction(runId, event.duration_ms ?? 0);
|
|
33218
|
+
}
|
|
32862
33219
|
logCompactionSnapshot(log2, runId, runtimeAgent, event.compacted);
|
|
32863
33220
|
if (event.compacted) await queueSessionSave("compaction");
|
|
32864
33221
|
}
|
|
@@ -32932,7 +33289,7 @@ var createRunHandlers = ({
|
|
|
32932
33289
|
normalizeRuntimeAgentHistory(`run.cancel ${runId}`, runtimeAgent);
|
|
32933
33290
|
}
|
|
32934
33291
|
await queueSessionSave("terminal");
|
|
32935
|
-
|
|
33292
|
+
emitRunSummary();
|
|
32936
33293
|
const status2 = state.cancelRequested ? "cancelled" : "completed";
|
|
32937
33294
|
outcome = status2;
|
|
32938
33295
|
const terminalExtras = buildTerminalStatusExtras();
|
|
@@ -32950,7 +33307,7 @@ var createRunHandlers = ({
|
|
|
32950
33307
|
outcome = "cancelled";
|
|
32951
33308
|
normalizeRuntimeAgentHistory(`run.cancel ${runId}`, runtimeAgent);
|
|
32952
33309
|
await queueSessionSave("cancelled");
|
|
32953
|
-
|
|
33310
|
+
emitRunSummary();
|
|
32954
33311
|
const terminalExtras2 = buildTerminalStatusExtras();
|
|
32955
33312
|
emitRunStatus(
|
|
32956
33313
|
runId,
|
|
@@ -32965,7 +33322,7 @@ var createRunHandlers = ({
|
|
|
32965
33322
|
const safeFailure = normalizeRunFailure(err);
|
|
32966
33323
|
logRunDebug(log2, runId, `stream.error ${safeFailure.debugMessage}`);
|
|
32967
33324
|
await queueSessionSave("error");
|
|
32968
|
-
|
|
33325
|
+
emitRunSummary();
|
|
32969
33326
|
const terminalExtras = buildTerminalStatusExtras();
|
|
32970
33327
|
emitRunStatus(
|
|
32971
33328
|
runId,
|
|
@@ -33034,7 +33391,7 @@ var createRunHandlers = ({
|
|
|
33034
33391
|
const runId = typeof params?.run_id === "string" ? params.run_id.trim() : "";
|
|
33035
33392
|
if (!runId) {
|
|
33036
33393
|
sendError(id2, {
|
|
33037
|
-
code:
|
|
33394
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33038
33395
|
message: "run_id is required"
|
|
33039
33396
|
});
|
|
33040
33397
|
return Promise.resolve();
|
|
@@ -33054,7 +33411,7 @@ var createRunHandlers = ({
|
|
|
33054
33411
|
const input = parseSteerInput(params.input);
|
|
33055
33412
|
if ("error" in input) {
|
|
33056
33413
|
sendError(id2, {
|
|
33057
|
-
code:
|
|
33414
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33058
33415
|
message: input.error
|
|
33059
33416
|
});
|
|
33060
33417
|
return;
|
|
@@ -33062,7 +33419,7 @@ var createRunHandlers = ({
|
|
|
33062
33419
|
const initialInput = input.value;
|
|
33063
33420
|
if (!state.canSteerRun(runId)) {
|
|
33064
33421
|
sendError(id2, {
|
|
33065
|
-
code:
|
|
33422
|
+
code: import_protocol35.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
33066
33423
|
message: "active run not found"
|
|
33067
33424
|
});
|
|
33068
33425
|
return;
|
|
@@ -33088,7 +33445,7 @@ var createRunHandlers = ({
|
|
|
33088
33445
|
normalizedInput = await state.prepareRunImages(normalizedInput);
|
|
33089
33446
|
} catch (error) {
|
|
33090
33447
|
sendError(id2, {
|
|
33091
|
-
code: error instanceof AttachmentAdmissionError ?
|
|
33448
|
+
code: error instanceof AttachmentAdmissionError ? import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol35.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
33092
33449
|
message: error instanceof Error ? error.message : String(error)
|
|
33093
33450
|
});
|
|
33094
33451
|
return;
|
|
@@ -33102,7 +33459,7 @@ var createRunHandlers = ({
|
|
|
33102
33459
|
);
|
|
33103
33460
|
} catch {
|
|
33104
33461
|
sendError(id2, {
|
|
33105
|
-
code:
|
|
33462
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33106
33463
|
message: "Could not retain the attachments for this conversation. Upload them again."
|
|
33107
33464
|
});
|
|
33108
33465
|
return;
|
|
@@ -33111,7 +33468,7 @@ var createRunHandlers = ({
|
|
|
33111
33468
|
if (!state.canSteerRun(runId)) {
|
|
33112
33469
|
releaseAttachments?.();
|
|
33113
33470
|
sendError(id2, {
|
|
33114
|
-
code:
|
|
33471
|
+
code: import_protocol35.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
33115
33472
|
message: "active run ended before steer could be queued"
|
|
33116
33473
|
});
|
|
33117
33474
|
return;
|
|
@@ -33146,7 +33503,7 @@ var createRunHandlers = ({
|
|
|
33146
33503
|
const handleGoal = (id2, method, raw) => {
|
|
33147
33504
|
if (!goals?.enabled) {
|
|
33148
33505
|
sendError(id2, {
|
|
33149
|
-
code:
|
|
33506
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33150
33507
|
message: "Goals are unavailable on this connection."
|
|
33151
33508
|
});
|
|
33152
33509
|
return Promise.resolve();
|
|
@@ -33185,7 +33542,7 @@ var createRunHandlers = ({
|
|
|
33185
33542
|
return;
|
|
33186
33543
|
}
|
|
33187
33544
|
sendError(id2, {
|
|
33188
|
-
code:
|
|
33545
|
+
code: import_protocol35.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
33189
33546
|
message: "run not found"
|
|
33190
33547
|
});
|
|
33191
33548
|
};
|
|
@@ -33196,14 +33553,14 @@ var createRunHandlers = ({
|
|
|
33196
33553
|
const open3 = async () => {
|
|
33197
33554
|
if (!sessionId) {
|
|
33198
33555
|
sendError(id2, {
|
|
33199
|
-
code:
|
|
33556
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33200
33557
|
message: "session_id is required"
|
|
33201
33558
|
});
|
|
33202
33559
|
return;
|
|
33203
33560
|
}
|
|
33204
33561
|
if (state.activeRunId) {
|
|
33205
33562
|
sendError(id2, {
|
|
33206
|
-
code:
|
|
33563
|
+
code: import_protocol35.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
33207
33564
|
message: "runtime busy"
|
|
33208
33565
|
});
|
|
33209
33566
|
return;
|
|
@@ -33219,21 +33576,21 @@ var createRunHandlers = ({
|
|
|
33219
33576
|
opened = await sessionStateStore.load(sessionId);
|
|
33220
33577
|
} catch (error) {
|
|
33221
33578
|
sendError(id2, {
|
|
33222
|
-
code:
|
|
33579
|
+
code: import_protocol35.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
33223
33580
|
message: `session load failed: ${String(error)}`
|
|
33224
33581
|
});
|
|
33225
33582
|
return;
|
|
33226
33583
|
}
|
|
33227
33584
|
if (!opened) {
|
|
33228
33585
|
sendError(id2, {
|
|
33229
|
-
code:
|
|
33586
|
+
code: import_protocol35.RPC_ERROR_CODE.SESSION_NOT_FOUND,
|
|
33230
33587
|
message: "session not found"
|
|
33231
33588
|
});
|
|
33232
33589
|
return;
|
|
33233
33590
|
}
|
|
33234
33591
|
if (opened.meta?.codelia_subagent) {
|
|
33235
33592
|
sendError(id2, {
|
|
33236
|
-
code:
|
|
33593
|
+
code: import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33237
33594
|
message: "Delegated sessions cannot be opened as a root session"
|
|
33238
33595
|
});
|
|
33239
33596
|
return;
|
|
@@ -33271,7 +33628,7 @@ var createRunHandlers = ({
|
|
|
33271
33628
|
|
|
33272
33629
|
// src/rpc/sandbox.ts
|
|
33273
33630
|
var import_promises5 = require("fs/promises");
|
|
33274
|
-
var
|
|
33631
|
+
var import_protocol37 = require("@codelia/protocol");
|
|
33275
33632
|
var import_storage32 = require("@codelia/storage");
|
|
33276
33633
|
var choices = [
|
|
33277
33634
|
{
|
|
@@ -33339,7 +33696,7 @@ var status = async (state, store) => {
|
|
|
33339
33696
|
var handleSandbox = async (state, id2, method, params) => {
|
|
33340
33697
|
if (!supportsSandboxModeManagement(state))
|
|
33341
33698
|
return sendError(id2, {
|
|
33342
|
-
code:
|
|
33699
|
+
code: import_protocol37.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
33343
33700
|
message: "Sandbox management is unavailable."
|
|
33344
33701
|
});
|
|
33345
33702
|
if (method === "sandbox.get") {
|
|
@@ -33357,7 +33714,7 @@ var handleSandbox = async (state, id2, method, params) => {
|
|
|
33357
33714
|
const { mode } = parsed.params;
|
|
33358
33715
|
const store = new import_storage32.ProjectsPolicyStore();
|
|
33359
33716
|
const fail = (reason) => sendError(id2, {
|
|
33360
|
-
code: reason === "runtime_busy" || reason === "policy_store_busy" ?
|
|
33717
|
+
code: reason === "runtime_busy" || reason === "policy_store_busy" ? import_protocol37.RPC_ERROR_CODE.RUNTIME_BUSY : import_protocol37.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33361
33718
|
message: `Project sandbox mode could not be changed (${reason}).`,
|
|
33362
33719
|
data: { reason }
|
|
33363
33720
|
});
|
|
@@ -33383,11 +33740,11 @@ var handleSandbox = async (state, id2, method, params) => {
|
|
|
33383
33740
|
};
|
|
33384
33741
|
|
|
33385
33742
|
// src/rpc/session-lifecycle.ts
|
|
33386
|
-
var
|
|
33743
|
+
var import_protocol39 = require("@codelia/protocol");
|
|
33387
33744
|
var createSessionUpdateHandler = (options) => async (id2, raw) => {
|
|
33388
33745
|
if (!options.sessions.updateMetadata) {
|
|
33389
33746
|
sendError(id2, {
|
|
33390
|
-
code:
|
|
33747
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33391
33748
|
message: "Session lifecycle updates are unavailable"
|
|
33392
33749
|
});
|
|
33393
33750
|
return;
|
|
@@ -33397,14 +33754,14 @@ var createSessionUpdateHandler = (options) => async (id2, raw) => {
|
|
|
33397
33754
|
const params = parsed.params;
|
|
33398
33755
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(params.session_id) || params.pinned === void 0 && params.archived === void 0) {
|
|
33399
33756
|
sendError(id2, {
|
|
33400
|
-
code:
|
|
33757
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33401
33758
|
message: "Expected session_id and a boolean pinned or archived update"
|
|
33402
33759
|
});
|
|
33403
33760
|
return;
|
|
33404
33761
|
}
|
|
33405
33762
|
if (params.archived && options.state.activeRunId && options.state.sessionId === params.session_id) {
|
|
33406
33763
|
sendError(id2, {
|
|
33407
|
-
code:
|
|
33764
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
33408
33765
|
message: "Wait for the active run before archiving this session"
|
|
33409
33766
|
});
|
|
33410
33767
|
return;
|
|
@@ -33425,7 +33782,7 @@ var createSessionUpdateHandler = (options) => async (id2, raw) => {
|
|
|
33425
33782
|
sendRequestResult("session.update", id2, result);
|
|
33426
33783
|
} catch (error) {
|
|
33427
33784
|
sendError(id2, {
|
|
33428
|
-
code:
|
|
33785
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33429
33786
|
message: `Session update failed: ${String(error)}`
|
|
33430
33787
|
});
|
|
33431
33788
|
}
|
|
@@ -33433,17 +33790,17 @@ var createSessionUpdateHandler = (options) => async (id2, raw) => {
|
|
|
33433
33790
|
|
|
33434
33791
|
// src/rpc/shell.ts
|
|
33435
33792
|
var import_node_path49 = __toESM(require("path"), 1);
|
|
33436
|
-
var
|
|
33793
|
+
var import_protocol42 = require("@codelia/protocol");
|
|
33437
33794
|
var import_storage33 = require("@codelia/storage");
|
|
33438
33795
|
|
|
33439
33796
|
// src/rpc/shell-timeout.ts
|
|
33440
|
-
var
|
|
33797
|
+
var import_protocol41 = require("@codelia/protocol");
|
|
33441
33798
|
var resolveRpcShellTimeoutSeconds = (requestedTimeout, background) => {
|
|
33442
33799
|
if (requestedTimeout !== void 0) {
|
|
33443
33800
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
33444
33801
|
return {
|
|
33445
33802
|
error: {
|
|
33446
|
-
code:
|
|
33803
|
+
code: import_protocol41.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33447
33804
|
message: "timeout_seconds must be a positive number"
|
|
33448
33805
|
}
|
|
33449
33806
|
};
|
|
@@ -33457,7 +33814,7 @@ var resolveRpcShellTimeoutSeconds = (requestedTimeout, background) => {
|
|
|
33457
33814
|
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
33458
33815
|
return {
|
|
33459
33816
|
error: {
|
|
33460
|
-
code:
|
|
33817
|
+
code: import_protocol41.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33461
33818
|
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
33462
33819
|
}
|
|
33463
33820
|
};
|
|
@@ -33518,7 +33875,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33518
33875
|
if (!taskId) {
|
|
33519
33876
|
return {
|
|
33520
33877
|
error: {
|
|
33521
|
-
code:
|
|
33878
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33522
33879
|
message: "task_id is required"
|
|
33523
33880
|
}
|
|
33524
33881
|
};
|
|
@@ -33526,7 +33883,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33526
33883
|
if (params?.stream !== "stdout" && params?.stream !== "stderr") {
|
|
33527
33884
|
return {
|
|
33528
33885
|
error: {
|
|
33529
|
-
code:
|
|
33886
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33530
33887
|
message: "stream must be stdout or stderr"
|
|
33531
33888
|
}
|
|
33532
33889
|
};
|
|
@@ -33534,7 +33891,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33534
33891
|
if (params.line_number !== void 0 && (params.offset !== void 0 || params.limit !== void 0)) {
|
|
33535
33892
|
return {
|
|
33536
33893
|
error: {
|
|
33537
|
-
code:
|
|
33894
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33538
33895
|
message: "line_number cannot be combined with offset or limit"
|
|
33539
33896
|
}
|
|
33540
33897
|
};
|
|
@@ -33542,7 +33899,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33542
33899
|
if (params.line_number === void 0 && (params.char_offset !== void 0 || params.char_limit !== void 0)) {
|
|
33543
33900
|
return {
|
|
33544
33901
|
error: {
|
|
33545
|
-
code:
|
|
33902
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33546
33903
|
message: "char_offset/char_limit require line_number"
|
|
33547
33904
|
}
|
|
33548
33905
|
};
|
|
@@ -33550,7 +33907,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33550
33907
|
if (params.offset !== void 0 && (!Number.isFinite(params.offset) || params.offset < 0)) {
|
|
33551
33908
|
return {
|
|
33552
33909
|
error: {
|
|
33553
|
-
code:
|
|
33910
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33554
33911
|
message: "offset must be a non-negative number"
|
|
33555
33912
|
}
|
|
33556
33913
|
};
|
|
@@ -33558,7 +33915,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33558
33915
|
if (params.limit !== void 0 && (!Number.isFinite(params.limit) || params.limit <= 0)) {
|
|
33559
33916
|
return {
|
|
33560
33917
|
error: {
|
|
33561
|
-
code:
|
|
33918
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33562
33919
|
message: "limit must be a positive number"
|
|
33563
33920
|
}
|
|
33564
33921
|
};
|
|
@@ -33566,7 +33923,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33566
33923
|
if (params.line_number !== void 0 && (!Number.isFinite(params.line_number) || params.line_number <= 0)) {
|
|
33567
33924
|
return {
|
|
33568
33925
|
error: {
|
|
33569
|
-
code:
|
|
33926
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33570
33927
|
message: "line_number must be a positive number"
|
|
33571
33928
|
}
|
|
33572
33929
|
};
|
|
@@ -33574,7 +33931,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33574
33931
|
if (params.char_offset !== void 0 && (!Number.isFinite(params.char_offset) || params.char_offset < 0)) {
|
|
33575
33932
|
return {
|
|
33576
33933
|
error: {
|
|
33577
|
-
code:
|
|
33934
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33578
33935
|
message: "char_offset must be a non-negative number"
|
|
33579
33936
|
}
|
|
33580
33937
|
};
|
|
@@ -33582,7 +33939,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
33582
33939
|
if (params.char_limit !== void 0 && (!Number.isFinite(params.char_limit) || params.char_limit <= 0)) {
|
|
33583
33940
|
return {
|
|
33584
33941
|
error: {
|
|
33585
|
-
code:
|
|
33942
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33586
33943
|
message: "char_limit must be a positive number"
|
|
33587
33944
|
}
|
|
33588
33945
|
};
|
|
@@ -33636,7 +33993,7 @@ var parseTaskId = (value) => {
|
|
|
33636
33993
|
var toTaskRpcError = (error) => {
|
|
33637
33994
|
if (!(error instanceof TaskManagerError)) {
|
|
33638
33995
|
return {
|
|
33639
|
-
code:
|
|
33996
|
+
code: import_protocol42.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
33640
33997
|
message: String(error)
|
|
33641
33998
|
};
|
|
33642
33999
|
}
|
|
@@ -33645,17 +34002,17 @@ var toTaskRpcError = (error) => {
|
|
|
33645
34002
|
case "invalid_task_id":
|
|
33646
34003
|
case "unsupported_workspace_mode":
|
|
33647
34004
|
return {
|
|
33648
|
-
code:
|
|
34005
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33649
34006
|
message: error.message
|
|
33650
34007
|
};
|
|
33651
34008
|
case "manager_shutting_down":
|
|
33652
34009
|
return {
|
|
33653
|
-
code:
|
|
34010
|
+
code: import_protocol42.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
33654
34011
|
message: error.message
|
|
33655
34012
|
};
|
|
33656
34013
|
default:
|
|
33657
34014
|
return {
|
|
33658
|
-
code:
|
|
34015
|
+
code: import_protocol42.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
33659
34016
|
message: error.message
|
|
33660
34017
|
};
|
|
33661
34018
|
}
|
|
@@ -33679,7 +34036,7 @@ var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
|
33679
34036
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
33680
34037
|
return {
|
|
33681
34038
|
error: {
|
|
33682
|
-
code:
|
|
34039
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33683
34040
|
message: "wait_timeout_seconds must be a positive number"
|
|
33684
34041
|
}
|
|
33685
34042
|
};
|
|
@@ -33687,7 +34044,7 @@ var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
|
33687
34044
|
if (requestedTimeout > MAX_TIMEOUT_SECONDS) {
|
|
33688
34045
|
return {
|
|
33689
34046
|
error: {
|
|
33690
|
-
code:
|
|
34047
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33691
34048
|
message: `wait_timeout_seconds must be ${MAX_TIMEOUT_SECONDS} seconds or less`
|
|
33692
34049
|
}
|
|
33693
34050
|
};
|
|
@@ -33702,7 +34059,7 @@ var parseShellStartRequest = (state, params, options) => {
|
|
|
33702
34059
|
if (!command.trim()) {
|
|
33703
34060
|
return {
|
|
33704
34061
|
error: {
|
|
33705
|
-
code:
|
|
34062
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33706
34063
|
message: "command is required"
|
|
33707
34064
|
}
|
|
33708
34065
|
};
|
|
@@ -33718,7 +34075,7 @@ var parseShellStartRequest = (state, params, options) => {
|
|
|
33718
34075
|
if (!cwd) {
|
|
33719
34076
|
return {
|
|
33720
34077
|
error: {
|
|
33721
|
-
code:
|
|
34078
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33722
34079
|
message: "cwd is outside sandbox root"
|
|
33723
34080
|
}
|
|
33724
34081
|
};
|
|
@@ -33844,7 +34201,7 @@ var createShellHandlers = ({
|
|
|
33844
34201
|
const requestedLimit = params?.limit;
|
|
33845
34202
|
if (requestedLimit !== void 0 && (!Number.isFinite(requestedLimit) || requestedLimit <= 0)) {
|
|
33846
34203
|
sendError(id2, {
|
|
33847
|
-
code:
|
|
34204
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33848
34205
|
message: "limit must be a positive number"
|
|
33849
34206
|
});
|
|
33850
34207
|
return;
|
|
@@ -33862,7 +34219,7 @@ var createShellHandlers = ({
|
|
|
33862
34219
|
const taskId = parseTaskId(params?.task_id);
|
|
33863
34220
|
if (!taskId) {
|
|
33864
34221
|
sendError(id2, {
|
|
33865
|
-
code:
|
|
34222
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33866
34223
|
message: "task_id is required"
|
|
33867
34224
|
});
|
|
33868
34225
|
return;
|
|
@@ -33898,7 +34255,7 @@ var createShellHandlers = ({
|
|
|
33898
34255
|
);
|
|
33899
34256
|
if (!cacheId && liveContent === null && !isTerminalTaskState(task.state)) {
|
|
33900
34257
|
sendError(id2, {
|
|
33901
|
-
code:
|
|
34258
|
+
code: import_protocol42.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
33902
34259
|
message: `shell output is not retained yet for running task: ${parsed.taskId}`
|
|
33903
34260
|
});
|
|
33904
34261
|
return;
|
|
@@ -33935,7 +34292,7 @@ var createShellHandlers = ({
|
|
|
33935
34292
|
const taskId = parseTaskId(params?.task_id);
|
|
33936
34293
|
if (!taskId) {
|
|
33937
34294
|
sendError(id2, {
|
|
33938
|
-
code:
|
|
34295
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
33939
34296
|
message: "task_id is required"
|
|
33940
34297
|
});
|
|
33941
34298
|
return;
|
|
@@ -34027,7 +34384,7 @@ var createShellHandlers = ({
|
|
|
34027
34384
|
const taskId = parseTaskId(params?.task_id);
|
|
34028
34385
|
if (!taskId) {
|
|
34029
34386
|
sendError(id2, {
|
|
34030
|
-
code:
|
|
34387
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34031
34388
|
message: "task_id is required"
|
|
34032
34389
|
});
|
|
34033
34390
|
return;
|
|
@@ -34041,7 +34398,7 @@ var createShellHandlers = ({
|
|
|
34041
34398
|
const waits = activeShellWaits.get(taskId);
|
|
34042
34399
|
if (!waits || waits.size === 0) {
|
|
34043
34400
|
sendError(id2, {
|
|
34044
|
-
code:
|
|
34401
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34045
34402
|
message: `no active shell.wait to detach for task: ${taskId}`
|
|
34046
34403
|
});
|
|
34047
34404
|
return;
|
|
@@ -34063,7 +34420,7 @@ var createShellHandlers = ({
|
|
|
34063
34420
|
const taskId = parseTaskId(params?.task_id);
|
|
34064
34421
|
if (!taskId) {
|
|
34065
34422
|
sendError(id2, {
|
|
34066
|
-
code:
|
|
34423
|
+
code: import_protocol42.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34067
34424
|
message: "task_id is required"
|
|
34068
34425
|
});
|
|
34069
34426
|
return;
|
|
@@ -34092,7 +34449,7 @@ var createShellHandlers = ({
|
|
|
34092
34449
|
|
|
34093
34450
|
// src/rpc/skills.ts
|
|
34094
34451
|
var import_node_path50 = __toESM(require("path"), 1);
|
|
34095
|
-
var
|
|
34452
|
+
var import_protocol44 = require("@codelia/protocol");
|
|
34096
34453
|
var createSkillsHandlers = ({
|
|
34097
34454
|
state,
|
|
34098
34455
|
log: log2
|
|
@@ -34123,7 +34480,7 @@ var createSkillsHandlers = ({
|
|
|
34123
34480
|
});
|
|
34124
34481
|
} catch (error) {
|
|
34125
34482
|
sendError(id2, {
|
|
34126
|
-
code:
|
|
34483
|
+
code: import_protocol44.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
34127
34484
|
message: `skills resolver init failed: ${String(error)}`
|
|
34128
34485
|
});
|
|
34129
34486
|
return;
|
|
@@ -34145,7 +34502,7 @@ var createSkillsHandlers = ({
|
|
|
34145
34502
|
} catch (error) {
|
|
34146
34503
|
log2(`skills.list error: ${String(error)}`);
|
|
34147
34504
|
sendError(id2, {
|
|
34148
|
-
code:
|
|
34505
|
+
code: import_protocol44.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
34149
34506
|
message: `skills list failed: ${String(error)}`
|
|
34150
34507
|
});
|
|
34151
34508
|
}
|
|
@@ -34155,7 +34512,7 @@ var createSkillsHandlers = ({
|
|
|
34155
34512
|
|
|
34156
34513
|
// src/rpc/task.ts
|
|
34157
34514
|
var import_node_path51 = __toESM(require("path"), 1);
|
|
34158
|
-
var
|
|
34515
|
+
var import_protocol46 = require("@codelia/protocol");
|
|
34159
34516
|
var import_storage34 = require("@codelia/storage");
|
|
34160
34517
|
var DEFAULT_TRUNCATED2 = {
|
|
34161
34518
|
stdout: false,
|
|
@@ -34205,7 +34562,7 @@ var parseTaskId2 = (value) => {
|
|
|
34205
34562
|
var toTaskRpcError2 = (error) => {
|
|
34206
34563
|
if (!(error instanceof TaskManagerError)) {
|
|
34207
34564
|
return {
|
|
34208
|
-
code:
|
|
34565
|
+
code: import_protocol46.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
34209
34566
|
message: String(error)
|
|
34210
34567
|
};
|
|
34211
34568
|
}
|
|
@@ -34214,17 +34571,17 @@ var toTaskRpcError2 = (error) => {
|
|
|
34214
34571
|
case "invalid_task_id":
|
|
34215
34572
|
case "unsupported_workspace_mode":
|
|
34216
34573
|
return {
|
|
34217
|
-
code:
|
|
34574
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34218
34575
|
message: error.message
|
|
34219
34576
|
};
|
|
34220
34577
|
case "manager_shutting_down":
|
|
34221
34578
|
return {
|
|
34222
|
-
code:
|
|
34579
|
+
code: import_protocol46.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
34223
34580
|
message: error.message
|
|
34224
34581
|
};
|
|
34225
34582
|
default:
|
|
34226
34583
|
return {
|
|
34227
|
-
code:
|
|
34584
|
+
code: import_protocol46.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
34228
34585
|
message: error.message
|
|
34229
34586
|
};
|
|
34230
34587
|
}
|
|
@@ -34277,7 +34634,7 @@ var parseShellSpawnRequest = (state, params, options) => {
|
|
|
34277
34634
|
if (!command.trim()) {
|
|
34278
34635
|
return {
|
|
34279
34636
|
error: {
|
|
34280
|
-
code:
|
|
34637
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34281
34638
|
message: "command is required for shell tasks"
|
|
34282
34639
|
}
|
|
34283
34640
|
};
|
|
@@ -34293,7 +34650,7 @@ var parseShellSpawnRequest = (state, params, options) => {
|
|
|
34293
34650
|
if (!cwd) {
|
|
34294
34651
|
return {
|
|
34295
34652
|
error: {
|
|
34296
|
-
code:
|
|
34653
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34297
34654
|
message: "cwd is outside sandbox root"
|
|
34298
34655
|
}
|
|
34299
34656
|
};
|
|
@@ -34373,7 +34730,7 @@ var createTaskHandlers = ({
|
|
|
34373
34730
|
const handleTaskSpawn = async (id2, params) => {
|
|
34374
34731
|
if (!params || !isTaskKind(params.kind)) {
|
|
34375
34732
|
sendError(id2, {
|
|
34376
|
-
code:
|
|
34733
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34377
34734
|
message: "kind must be shell or subagent"
|
|
34378
34735
|
});
|
|
34379
34736
|
return;
|
|
@@ -34381,7 +34738,7 @@ var createTaskHandlers = ({
|
|
|
34381
34738
|
if (params.kind !== "shell") {
|
|
34382
34739
|
if (params.kind !== "subagent" || !subagents?.isAvailable() || !getAgent) {
|
|
34383
34740
|
sendError(id2, {
|
|
34384
|
-
code:
|
|
34741
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34385
34742
|
message: `task kind ${params.kind} is not supported yet.`
|
|
34386
34743
|
});
|
|
34387
34744
|
return;
|
|
@@ -34465,21 +34822,21 @@ var createTaskHandlers = ({
|
|
|
34465
34822
|
const requestedLimit = params?.limit;
|
|
34466
34823
|
if (requestedLimit !== void 0 && (!Number.isFinite(requestedLimit) || requestedLimit <= 0)) {
|
|
34467
34824
|
sendError(id2, {
|
|
34468
|
-
code:
|
|
34825
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34469
34826
|
message: "limit must be a positive number"
|
|
34470
34827
|
});
|
|
34471
34828
|
return;
|
|
34472
34829
|
}
|
|
34473
34830
|
if (params?.kind !== void 0 && !isTaskKind(params.kind)) {
|
|
34474
34831
|
sendError(id2, {
|
|
34475
|
-
code:
|
|
34832
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34476
34833
|
message: "kind must be shell or subagent"
|
|
34477
34834
|
});
|
|
34478
34835
|
return;
|
|
34479
34836
|
}
|
|
34480
34837
|
if (params?.state !== void 0 && !isTaskState(params.state)) {
|
|
34481
34838
|
sendError(id2, {
|
|
34482
|
-
code:
|
|
34839
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34483
34840
|
message: "invalid task state"
|
|
34484
34841
|
});
|
|
34485
34842
|
return;
|
|
@@ -34497,7 +34854,7 @@ var createTaskHandlers = ({
|
|
|
34497
34854
|
const taskId = parseTaskId2(params?.task_id);
|
|
34498
34855
|
if (!taskId) {
|
|
34499
34856
|
sendError(id2, {
|
|
34500
|
-
code:
|
|
34857
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34501
34858
|
message: "task_id is required"
|
|
34502
34859
|
});
|
|
34503
34860
|
return;
|
|
@@ -34517,7 +34874,7 @@ var createTaskHandlers = ({
|
|
|
34517
34874
|
const taskId = parseTaskId2(params?.task_id);
|
|
34518
34875
|
if (!taskId) {
|
|
34519
34876
|
sendError(id2, {
|
|
34520
|
-
code:
|
|
34877
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34521
34878
|
message: "task_id is required"
|
|
34522
34879
|
});
|
|
34523
34880
|
return;
|
|
@@ -34538,7 +34895,7 @@ var createTaskHandlers = ({
|
|
|
34538
34895
|
const taskId = parseTaskId2(params?.task_id);
|
|
34539
34896
|
if (!taskId) {
|
|
34540
34897
|
sendError(id2, {
|
|
34541
|
-
code:
|
|
34898
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34542
34899
|
message: "task_id is required"
|
|
34543
34900
|
});
|
|
34544
34901
|
return;
|
|
@@ -34561,7 +34918,7 @@ var createTaskHandlers = ({
|
|
|
34561
34918
|
const taskId = parseTaskId2(params?.task_id);
|
|
34562
34919
|
if (!taskId) {
|
|
34563
34920
|
sendError(id2, {
|
|
34564
|
-
code:
|
|
34921
|
+
code: import_protocol46.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34565
34922
|
message: "task_id is required"
|
|
34566
34923
|
});
|
|
34567
34924
|
return;
|
|
@@ -34826,6 +35183,11 @@ var createRuntimeHandlers = ({
|
|
|
34826
35183
|
state,
|
|
34827
35184
|
log: log2
|
|
34828
35185
|
});
|
|
35186
|
+
const telemetryHandlers = createTelemetryHandlers({
|
|
35187
|
+
state,
|
|
35188
|
+
subagents,
|
|
35189
|
+
log: log2
|
|
35190
|
+
});
|
|
34829
35191
|
const { handleSkillsList } = createSkillsHandlers({
|
|
34830
35192
|
state,
|
|
34831
35193
|
log: log2
|
|
@@ -34853,12 +35215,15 @@ var createRuntimeHandlers = ({
|
|
|
34853
35215
|
const parsed = parseRequestParams("initialize", raw);
|
|
34854
35216
|
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
34855
35217
|
const params = parsed.params;
|
|
34856
|
-
let
|
|
35218
|
+
let resolvedTui;
|
|
34857
35219
|
const environment2 = state.effectiveEnvironment;
|
|
34858
35220
|
if (isTuiLocalEnvironment(environment2)) {
|
|
34859
35221
|
try {
|
|
34860
35222
|
const workingDir = state.lastUiContext?.cwd ?? state.runtimeWorkingDir ?? process.cwd();
|
|
34861
|
-
|
|
35223
|
+
const loaded = await resolveEnvironmentTuiConfig(state, workingDir);
|
|
35224
|
+
if (loaded.theme || loaded.color_scheme || loaded.image_protocol) {
|
|
35225
|
+
resolvedTui = loaded;
|
|
35226
|
+
}
|
|
34862
35227
|
} catch (error) {
|
|
34863
35228
|
log2(`initialize tui config load failed: ${String(error)}`);
|
|
34864
35229
|
}
|
|
@@ -34897,7 +35262,7 @@ var createRuntimeHandlers = ({
|
|
|
34897
35262
|
supports_run_cancel: true,
|
|
34898
35263
|
supports_run_steer: true,
|
|
34899
35264
|
supports_goals: Boolean(goalStore),
|
|
34900
|
-
|
|
35265
|
+
supports_telemetry: true,
|
|
34901
35266
|
supports_session_lifecycle: !!sessionStateStore.updateMetadata,
|
|
34902
35267
|
supports_shell_exec: !!shellBackend,
|
|
34903
35268
|
supports_shell_tasks: processEnabled,
|
|
@@ -34928,7 +35293,7 @@ var createRuntimeHandlers = ({
|
|
|
34928
35293
|
supports_text_delta: true
|
|
34929
35294
|
},
|
|
34930
35295
|
...localHost ? { local_host: localHost } : {},
|
|
34931
|
-
...localHost ||
|
|
35296
|
+
...localHost || resolvedTui ? { tui: { ...resolvedTui, ...localHost } } : {}
|
|
34932
35297
|
};
|
|
34933
35298
|
sendRequestResult("initialize", id2, result);
|
|
34934
35299
|
log2(`initialize from ${params.client?.name ?? "unknown"}`);
|
|
@@ -34946,7 +35311,7 @@ var createRuntimeHandlers = ({
|
|
|
34946
35311
|
const handleThemeSet = async (id2, raw) => {
|
|
34947
35312
|
if (state.activeRunId) {
|
|
34948
35313
|
sendError(id2, {
|
|
34949
|
-
code:
|
|
35314
|
+
code: import_protocol48.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
34950
35315
|
message: "runtime busy"
|
|
34951
35316
|
});
|
|
34952
35317
|
return;
|
|
@@ -34956,14 +35321,14 @@ var createRuntimeHandlers = ({
|
|
|
34956
35321
|
const name2 = parsed.params.name.trim().toLowerCase();
|
|
34957
35322
|
if (!name2) {
|
|
34958
35323
|
sendError(id2, {
|
|
34959
|
-
code:
|
|
35324
|
+
code: import_protocol48.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34960
35325
|
message: "theme name is required"
|
|
34961
35326
|
});
|
|
34962
35327
|
return;
|
|
34963
35328
|
}
|
|
34964
35329
|
if (!SUPPORTED_TUI_THEMES.has(name2)) {
|
|
34965
35330
|
sendError(id2, {
|
|
34966
|
-
code:
|
|
35331
|
+
code: import_protocol48.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
34967
35332
|
message: `unsupported theme: ${name2}`
|
|
34968
35333
|
});
|
|
34969
35334
|
return;
|
|
@@ -34979,7 +35344,7 @@ var createRuntimeHandlers = ({
|
|
|
34979
35344
|
log2(`theme.set ${name2} scope=${target2.scope} path=${target2.path}`);
|
|
34980
35345
|
} catch (error) {
|
|
34981
35346
|
sendError(id2, {
|
|
34982
|
-
code:
|
|
35347
|
+
code: import_protocol48.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
34983
35348
|
message: String(error)
|
|
34984
35349
|
});
|
|
34985
35350
|
}
|
|
@@ -35000,7 +35365,7 @@ var createRuntimeHandlers = ({
|
|
|
35000
35365
|
const skillsEnabled = state.effectiveEnvironment.context.skills === "from-config";
|
|
35001
35366
|
const themeSetEnabled = isTuiLocalEnvironment(state.effectiveEnvironment) && state.effectiveEnvironment.config.source !== "disabled";
|
|
35002
35367
|
const rejectDisabled = (message) => sendError(req.id, {
|
|
35003
|
-
code:
|
|
35368
|
+
code: import_protocol48.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
35004
35369
|
message
|
|
35005
35370
|
});
|
|
35006
35371
|
switch (req.method) {
|
|
@@ -35225,13 +35590,18 @@ var createRuntimeHandlers = ({
|
|
|
35225
35590
|
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
35226
35591
|
return contextUsageHandlers.handleContextUsage(req.id);
|
|
35227
35592
|
}
|
|
35593
|
+
case "telemetry.get": {
|
|
35594
|
+
const parsed = parseRequestParams("telemetry.get", req.params);
|
|
35595
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
35596
|
+
return telemetryHandlers.handleTelemetryGet(req.id);
|
|
35597
|
+
}
|
|
35228
35598
|
case "theme.set":
|
|
35229
35599
|
if (!themeSetEnabled)
|
|
35230
35600
|
return rejectDisabled("theme setting is disabled");
|
|
35231
35601
|
return handleThemeSet(req.id, req.params);
|
|
35232
35602
|
default:
|
|
35233
35603
|
return sendError(req.id, {
|
|
35234
|
-
code:
|
|
35604
|
+
code: import_protocol48.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
35235
35605
|
message: "method not found"
|
|
35236
35606
|
});
|
|
35237
35607
|
}
|
|
@@ -35259,7 +35629,7 @@ var createRuntimeHandlers = ({
|
|
|
35259
35629
|
if (msg.jsonrpc !== "2.0" || "method" in msg && typeof msg.method !== "string") {
|
|
35260
35630
|
if (id2 !== void 0) {
|
|
35261
35631
|
sendError(id2, {
|
|
35262
|
-
code:
|
|
35632
|
+
code: import_protocol48.RPC_ERROR_CODE.INVALID_REQUEST,
|
|
35263
35633
|
message: "invalid request"
|
|
35264
35634
|
});
|
|
35265
35635
|
} else {
|
|
@@ -35276,7 +35646,7 @@ var createRuntimeHandlers = ({
|
|
|
35276
35646
|
if (invalid) {
|
|
35277
35647
|
if (id2 !== void 0)
|
|
35278
35648
|
sendError(id2, {
|
|
35279
|
-
code:
|
|
35649
|
+
code: import_protocol48.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
35280
35650
|
message: invalid
|
|
35281
35651
|
});
|
|
35282
35652
|
else log2(`invalid rpc notification: ${msg.method}`);
|
|
@@ -35290,7 +35660,7 @@ var createRuntimeHandlers = ({
|
|
|
35290
35660
|
if (!hasRpcResponse(id2)) {
|
|
35291
35661
|
try {
|
|
35292
35662
|
sendError(id2, {
|
|
35293
|
-
code:
|
|
35663
|
+
code: import_protocol48.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
35294
35664
|
message: "internal runtime error"
|
|
35295
35665
|
});
|
|
35296
35666
|
} catch {
|
|
@@ -35315,7 +35685,7 @@ var createRuntimeHandlers = ({
|
|
|
35315
35685
|
handleResponse(msg);
|
|
35316
35686
|
} else if (id2 !== void 0) {
|
|
35317
35687
|
sendError(id2, {
|
|
35318
|
-
code:
|
|
35688
|
+
code: import_protocol48.RPC_ERROR_CODE.INVALID_REQUEST,
|
|
35319
35689
|
message: "invalid request"
|
|
35320
35690
|
});
|
|
35321
35691
|
} else {
|
|
@@ -35527,12 +35897,11 @@ var prepareProcess = (input, options, channel) => {
|
|
|
35527
35897
|
cwd: input.workspace_root,
|
|
35528
35898
|
detached: process.platform !== "win32",
|
|
35529
35899
|
stdio: ["pipe", "pipe", "pipe", "pipe"],
|
|
35530
|
-
//
|
|
35900
|
+
// Debug/provider logging can write raw credentials/payloads outside the child contract.
|
|
35531
35901
|
env: {
|
|
35532
35902
|
...process.env,
|
|
35533
|
-
|
|
35534
|
-
|
|
35535
|
-
CODELIA_DIAGNOSTICS: "0"
|
|
35903
|
+
CODELIA_DEBUG: "",
|
|
35904
|
+
CODELIA_DEBUG_DIR: ""
|
|
35536
35905
|
}
|
|
35537
35906
|
}
|
|
35538
35907
|
);
|
|
@@ -35728,21 +36097,20 @@ function normalizeChildResult(result) {
|
|
|
35728
36097
|
}
|
|
35729
36098
|
|
|
35730
36099
|
// src/runtime.ts
|
|
35731
|
-
var envTruthy3 = (value) => {
|
|
35732
|
-
if (!value) return false;
|
|
35733
|
-
const normalized = value.trim().toLowerCase();
|
|
35734
|
-
return normalized === "1" || normalized === "true";
|
|
35735
|
-
};
|
|
35736
36100
|
var startRuntime = async (options = {}) => {
|
|
35737
36101
|
const state = new RuntimeState();
|
|
35738
36102
|
state.setRuntimeEnvironment(options);
|
|
35739
36103
|
const environment = state.effectiveEnvironment;
|
|
36104
|
+
const sandboxModeStart = performance.now();
|
|
35740
36105
|
state.sandboxMode = await resolveRuntimeSandboxMode(environment);
|
|
36106
|
+
state.telemetry.recordStartupPhase(
|
|
36107
|
+
"sandbox_mode",
|
|
36108
|
+
performance.now() - sandboxModeStart
|
|
36109
|
+
);
|
|
35741
36110
|
if (state.sandboxMode.legacy === "full-access")
|
|
35742
36111
|
(0, import_logger.log)(
|
|
35743
36112
|
"Legacy approval_mode full-access uses workspace-write. Specify --sandbox-mode full-access to disable OS isolation and keep command approval."
|
|
35744
36113
|
);
|
|
35745
|
-
state.diagnosticsEnabled = envTruthy3(process.env.CODELIA_DIAGNOSTICS);
|
|
35746
36114
|
const workingDir = environment.workspace.root;
|
|
35747
36115
|
if (workingDir) {
|
|
35748
36116
|
state.runtimeWorkingDir = workingDir;
|
|
@@ -35752,15 +36120,22 @@ var startRuntime = async (options = {}) => {
|
|
|
35752
36120
|
}
|
|
35753
36121
|
state.attachments = createRuntimeAttachmentService(state);
|
|
35754
36122
|
if (environment.context.projectInstructions === "from-workspace" && workingDir) {
|
|
36123
|
+
const agentsStart = performance.now();
|
|
35755
36124
|
try {
|
|
36125
|
+
const agentsEnabled = environment.config.source === "disabled" ? true : await resolveAgentsEnabled(workingDir).catch(() => true);
|
|
35756
36126
|
state.agentsResolver = await AgentsResolver.create(
|
|
35757
36127
|
workingDir,
|
|
35758
|
-
|
|
36128
|
+
{ enabled: agentsEnabled },
|
|
35759
36129
|
void 0,
|
|
35760
36130
|
await runtimeResourceReader(state, workingDir)
|
|
35761
36131
|
);
|
|
35762
36132
|
} catch (error) {
|
|
35763
36133
|
(0, import_logger.log)(`agents resolver startup init failed: ${String(error)}`);
|
|
36134
|
+
} finally {
|
|
36135
|
+
state.telemetry.recordStartupPhase(
|
|
36136
|
+
"agents_resolver",
|
|
36137
|
+
performance.now() - agentsStart
|
|
36138
|
+
);
|
|
35764
36139
|
}
|
|
35765
36140
|
}
|
|
35766
36141
|
const sessionStateStore = environment.adapters.stores?.sessionStateStore ?? (environment.persistence.mode === "volatile" ? new VolatileSessionStateStore() : new import_storage36.SessionStateStoreImpl({
|