@codelia/runtime 0.1.89 → 0.1.90
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-NPCH2IMV.js → chunk-DSYHEFZM.js} +120 -53
- package/dist/{chunk-LNUGYGST.js → chunk-QWJ4JW4T.js} +635 -575
- package/dist/index.cjs +953 -833
- package/dist/index.js +2 -2
- package/dist/sdk.cjs +953 -833
- package/dist/sdk.js +2 -2
- package/dist/subagents/child-entry.cjs +64 -17
- package/dist/subagents/child-entry.js +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -1143,6 +1143,7 @@ var updateTuiTheme = async (workingDir, theme) => {
|
|
|
1143
1143
|
await (0, import_config_loader.updateTuiConfig)(target2.path, { theme });
|
|
1144
1144
|
return target2;
|
|
1145
1145
|
};
|
|
1146
|
+
var normalizeModelLevel = (value) => value.trim().toLowerCase();
|
|
1146
1147
|
var resolveReasoningEffort = (value) => {
|
|
1147
1148
|
return resolveModelLevelOption(value, "model.reasoning", {
|
|
1148
1149
|
allowXhigh: true
|
|
@@ -1155,7 +1156,7 @@ var resolveTextVerbosity = (value) => {
|
|
|
1155
1156
|
};
|
|
1156
1157
|
function resolveModelLevelOption(value, fieldName, options) {
|
|
1157
1158
|
if (!value) return void 0;
|
|
1158
|
-
const normalized = value
|
|
1159
|
+
const normalized = normalizeModelLevel(value);
|
|
1159
1160
|
if (normalized === "low" || normalized === "medium" || normalized === "high") {
|
|
1160
1161
|
return normalized;
|
|
1161
1162
|
}
|
|
@@ -1856,7 +1857,10 @@ var createDecisionTool = (options) => (0, import_core3.defineTool)({
|
|
|
1856
1857
|
var import_shared_types3 = require("@codelia/shared-types");
|
|
1857
1858
|
|
|
1858
1859
|
// src/rpc/ui-requests.ts
|
|
1859
|
-
var
|
|
1860
|
+
var import_protocol3 = require("@codelia/protocol");
|
|
1861
|
+
|
|
1862
|
+
// src/rpc/protocol.ts
|
|
1863
|
+
var import_protocol2 = require("@codelia/protocol");
|
|
1860
1864
|
|
|
1861
1865
|
// src/rpc/transport.ts
|
|
1862
1866
|
var import_node_async_hooks = require("async_hooks");
|
|
@@ -1960,65 +1964,107 @@ var sendResponse = (response) => {
|
|
|
1960
1964
|
var sendAgentEvent = (state, runId, event) => {
|
|
1961
1965
|
if (state.shouldSuppressEvent(runId)) return null;
|
|
1962
1966
|
const seq = state.nextSequence(runId);
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
run_id: runId,
|
|
1968
|
-
seq,
|
|
1969
|
-
event
|
|
1970
|
-
}
|
|
1971
|
-
};
|
|
1972
|
-
sendNotification(state, notify);
|
|
1967
|
+
sendNotification(
|
|
1968
|
+
state,
|
|
1969
|
+
notificationMessage("agent.event", { run_id: runId, seq, event })
|
|
1970
|
+
);
|
|
1973
1971
|
return seq;
|
|
1974
1972
|
};
|
|
1975
1973
|
var sendRunStatus = (state, runId, status2, message, error, extras) => {
|
|
1976
|
-
const notify = {
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
...extras?.unconsumed_steer_ids?.length ? { unconsumed_steer_ids: extras.unconsumed_steer_ids } : {}
|
|
1985
|
-
}
|
|
1986
|
-
};
|
|
1974
|
+
const notify = notificationMessage("run.status", {
|
|
1975
|
+
run_id: runId,
|
|
1976
|
+
status: status2,
|
|
1977
|
+
message,
|
|
1978
|
+
...error ? { error } : {},
|
|
1979
|
+
...extras?.unconsumed_steer_ids?.length ? { unconsumed_steer_ids: extras.unconsumed_steer_ids } : {},
|
|
1980
|
+
...extras?.unconsumed_client_steer_ids?.length ? { unconsumed_client_steer_ids: extras.unconsumed_client_steer_ids } : {}
|
|
1981
|
+
});
|
|
1987
1982
|
sendNotification(state, notify);
|
|
1988
1983
|
};
|
|
1989
1984
|
var sendRunContext = (state, runId, contextLeftPercent) => {
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
params: {
|
|
1985
|
+
sendNotification(
|
|
1986
|
+
state,
|
|
1987
|
+
notificationMessage("run.context", {
|
|
1994
1988
|
run_id: runId,
|
|
1995
1989
|
context_left_percent: contextLeftPercent
|
|
1996
|
-
}
|
|
1997
|
-
|
|
1998
|
-
sendNotification(state, notify);
|
|
1990
|
+
})
|
|
1991
|
+
);
|
|
1999
1992
|
};
|
|
2000
1993
|
var sendRunDiagnostics = (state, params) => {
|
|
2001
|
-
|
|
2002
|
-
jsonrpc: "2.0",
|
|
2003
|
-
method: "run.diagnostics",
|
|
2004
|
-
params
|
|
2005
|
-
};
|
|
2006
|
-
sendNotification(state, notify);
|
|
1994
|
+
sendNotification(state, notificationMessage("run.diagnostics", params));
|
|
2007
1995
|
};
|
|
2008
1996
|
var sendRunMetrics = (state, params) => {
|
|
2009
|
-
sendNotification(state,
|
|
1997
|
+
sendNotification(state, notificationMessage("run.metrics", params));
|
|
1998
|
+
};
|
|
1999
|
+
|
|
2000
|
+
// src/rpc/protocol.ts
|
|
2001
|
+
var MAX_ISSUES = 10;
|
|
2002
|
+
var describeIssues = (error) => error.issues.slice(0, MAX_ISSUES).map((issue) => ({
|
|
2003
|
+
path: issue.path.map(String).join("."),
|
|
2004
|
+
code: issue.code,
|
|
2005
|
+
message: issue.message
|
|
2006
|
+
}));
|
|
2007
|
+
var schemaFor = (method, slot) => {
|
|
2008
|
+
const spec = import_protocol2.protocolMethods[method];
|
|
2009
|
+
if (slot === "params") return spec.params;
|
|
2010
|
+
if (!("result" in spec))
|
|
2011
|
+
throw new Error(`${method} is a notification without a result`);
|
|
2012
|
+
return spec.result;
|
|
2013
|
+
};
|
|
2014
|
+
var assertOutgoing = (method, slot, value) => {
|
|
2015
|
+
if (process.env.CODELIA_PROTOCOL_ASSERT !== "1") return;
|
|
2016
|
+
const result = schemaFor(method, slot).safeParse(value);
|
|
2017
|
+
if (!result.success)
|
|
2018
|
+
throw new Error(
|
|
2019
|
+
`protocol assertion failed for ${method} ${slot}: ${JSON.stringify(describeIssues(result.error))}`
|
|
2020
|
+
);
|
|
2021
|
+
};
|
|
2022
|
+
var parseRequestParams = (method, raw) => {
|
|
2023
|
+
const result = schemaFor(method, "params").safeParse(
|
|
2024
|
+
raw === void 0 ? {} : raw
|
|
2025
|
+
);
|
|
2026
|
+
if (result.success) return { ok: true, params: result.data };
|
|
2027
|
+
const issues = describeIssues(result.error);
|
|
2028
|
+
const first = issues[0];
|
|
2029
|
+
return {
|
|
2030
|
+
ok: false,
|
|
2031
|
+
error: {
|
|
2032
|
+
code: import_protocol2.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
2033
|
+
// The first issue names the field; issue messages never echo values.
|
|
2034
|
+
message: first ? `invalid ${method} params: ${first.path || "params"}: ${first.message}` : `invalid ${method} params`,
|
|
2035
|
+
data: { issues }
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
};
|
|
2039
|
+
var parseUiNotificationParams = (method, raw) => {
|
|
2040
|
+
const result = schemaFor(method, "params").safeParse(
|
|
2041
|
+
raw === void 0 ? {} : raw
|
|
2042
|
+
);
|
|
2043
|
+
return result.success ? result.data : null;
|
|
2044
|
+
};
|
|
2045
|
+
var sendRequestResult = (method, id2, result) => {
|
|
2046
|
+
assertOutgoing(method, "result", result);
|
|
2047
|
+
sendResult(id2, result);
|
|
2048
|
+
};
|
|
2049
|
+
var notificationMessage = (method, params) => {
|
|
2050
|
+
assertOutgoing(method, "params", params);
|
|
2051
|
+
return { jsonrpc: "2.0", method, params };
|
|
2052
|
+
};
|
|
2053
|
+
var requestMessage = (method, id2, params) => {
|
|
2054
|
+
assertOutgoing(method, "params", params);
|
|
2055
|
+
return { jsonrpc: "2.0", id: id2, method, params };
|
|
2056
|
+
};
|
|
2057
|
+
var parseUiResult = (method, raw) => {
|
|
2058
|
+
const result = schemaFor(method, "result").safeParse(raw);
|
|
2059
|
+
if (result.success) return { ok: true, result: result.data };
|
|
2060
|
+
return { ok: false, issues: describeIssues(result.error) };
|
|
2010
2061
|
};
|
|
2011
2062
|
|
|
2012
2063
|
// src/rpc/ui-requests.ts
|
|
2013
2064
|
var requestUi = async (state, method, params, signal) => {
|
|
2014
2065
|
if (signal?.aborted) return null;
|
|
2015
2066
|
const id2 = state.nextUiRequestId();
|
|
2016
|
-
const request =
|
|
2017
|
-
jsonrpc: "2.0",
|
|
2018
|
-
id: id2,
|
|
2019
|
-
method,
|
|
2020
|
-
params
|
|
2021
|
-
};
|
|
2067
|
+
const request = requestMessage(method, id2, params);
|
|
2022
2068
|
const response = state.waitForUiResponse(id2);
|
|
2023
2069
|
let sent = false;
|
|
2024
2070
|
const abort = () => {
|
|
@@ -2026,13 +2072,12 @@ var requestUi = async (state, method, params, signal) => {
|
|
|
2026
2072
|
jsonrpc: "2.0",
|
|
2027
2073
|
id: id2,
|
|
2028
2074
|
error: {
|
|
2029
|
-
code:
|
|
2075
|
+
code: import_protocol3.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
2030
2076
|
message: "UI request cancelled"
|
|
2031
2077
|
}
|
|
2032
2078
|
});
|
|
2033
|
-
if (cancelled
|
|
2034
|
-
|
|
2035
|
-
}
|
|
2079
|
+
if (!cancelled || !sent || method !== "ui.pick.request") return;
|
|
2080
|
+
send(notificationMessage("ui.pick.cancelled", { id: id2 }));
|
|
2036
2081
|
};
|
|
2037
2082
|
signal?.addEventListener("abort", abort, { once: true });
|
|
2038
2083
|
try {
|
|
@@ -2041,7 +2086,12 @@ var requestUi = async (state, method, params, signal) => {
|
|
|
2041
2086
|
send(request);
|
|
2042
2087
|
sent = true;
|
|
2043
2088
|
}
|
|
2044
|
-
|
|
2089
|
+
const parsed = parseUiResult(method, await response);
|
|
2090
|
+
if (parsed.ok) return parsed.result;
|
|
2091
|
+
(0, import_logger.log)(
|
|
2092
|
+
`protocol mismatch: ${method} result: ${JSON.stringify(parsed.issues)}`
|
|
2093
|
+
);
|
|
2094
|
+
return null;
|
|
2045
2095
|
} catch {
|
|
2046
2096
|
return null;
|
|
2047
2097
|
} finally {
|
|
@@ -8796,7 +8846,7 @@ var formatExecutionEnvironmentContext = (options) => {
|
|
|
8796
8846
|
"<execution_environment>",
|
|
8797
8847
|
`os: ${options.hostInfo.osDescription}`,
|
|
8798
8848
|
`shell tool execution environment: ${options.hostInfo.shellExecution}`,
|
|
8799
|
-
`
|
|
8849
|
+
`shell uses Bash: ${options.hostInfo.bashSyntaxGuaranteed ? "yes" : "no"}`,
|
|
8800
8850
|
`sandbox root: ${options.sandboxRoot}`,
|
|
8801
8851
|
`working directory: ${options.workingDir}`
|
|
8802
8852
|
];
|
|
@@ -15079,30 +15129,26 @@ var createApplyPatchTool = (sandboxKey, outputCacheStore) => {
|
|
|
15079
15129
|
// src/rpc/client-tool-requests.ts
|
|
15080
15130
|
var requestClientToolCall = async (state, params, timeoutMs) => {
|
|
15081
15131
|
const id2 = state.nextUiRequestId();
|
|
15082
|
-
|
|
15083
|
-
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
|
|
15088
|
-
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
15096
|
-
|
|
15097
|
-
request_id: id2,
|
|
15098
|
-
run_id: params.run_id,
|
|
15099
|
-
name: params.name,
|
|
15100
|
-
reason: "timeout"
|
|
15101
|
-
}
|
|
15102
|
-
};
|
|
15103
|
-
send(notification);
|
|
15104
|
-
}
|
|
15132
|
+
send(requestMessage("client.tool.call", id2, params));
|
|
15133
|
+
const raw = await state.waitForUiResponse(id2, timeoutMs, () => {
|
|
15134
|
+
send(
|
|
15135
|
+
notificationMessage("client.tool.cancel", {
|
|
15136
|
+
request_id: id2,
|
|
15137
|
+
run_id: params.run_id,
|
|
15138
|
+
name: params.name,
|
|
15139
|
+
reason: "timeout"
|
|
15140
|
+
})
|
|
15141
|
+
);
|
|
15142
|
+
});
|
|
15143
|
+
const parsed = parseUiResult("client.tool.call", raw);
|
|
15144
|
+
if (parsed.ok) return parsed.result;
|
|
15145
|
+
(0, import_logger.log)(
|
|
15146
|
+
`protocol mismatch: client.tool.call result for ${params.name}: ${JSON.stringify(parsed.issues)}`
|
|
15105
15147
|
);
|
|
15148
|
+
return {
|
|
15149
|
+
ok: false,
|
|
15150
|
+
error: "The client returned a result that does not match the protocol."
|
|
15151
|
+
};
|
|
15106
15152
|
};
|
|
15107
15153
|
|
|
15108
15154
|
// src/tools/attachment-read.ts
|
|
@@ -15743,7 +15789,7 @@ var createRuntimeToolApproval = ({
|
|
|
15743
15789
|
// src/rpc/tool.ts
|
|
15744
15790
|
var import_node_crypto13 = require("crypto");
|
|
15745
15791
|
var import_core15 = require("@codelia/core");
|
|
15746
|
-
var
|
|
15792
|
+
var import_protocol6 = require("@codelia/protocol");
|
|
15747
15793
|
var normalizeToolResult = (result) => {
|
|
15748
15794
|
switch (result.type) {
|
|
15749
15795
|
case "json":
|
|
@@ -15780,14 +15826,14 @@ var createToolHandlers = ({
|
|
|
15780
15826
|
const toolName = params?.name;
|
|
15781
15827
|
if (!toolName) {
|
|
15782
15828
|
sendError(id2, {
|
|
15783
|
-
code:
|
|
15829
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
15784
15830
|
message: "tool name is required"
|
|
15785
15831
|
});
|
|
15786
15832
|
return;
|
|
15787
15833
|
}
|
|
15788
15834
|
if (toolName === "attachment_read" && state.attachments) {
|
|
15789
15835
|
sendError(id2, {
|
|
15790
|
-
code:
|
|
15836
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
15791
15837
|
message: "attachment_read is only available during a model run"
|
|
15792
15838
|
});
|
|
15793
15839
|
return;
|
|
@@ -15804,7 +15850,7 @@ var createToolHandlers = ({
|
|
|
15804
15850
|
const tool = state.tools?.find((entry) => entry.name === toolName);
|
|
15805
15851
|
if (!tool) {
|
|
15806
15852
|
sendError(id2, {
|
|
15807
|
-
code:
|
|
15853
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
15808
15854
|
message: `unknown tool: ${toolName}`
|
|
15809
15855
|
});
|
|
15810
15856
|
return;
|
|
@@ -15830,11 +15876,11 @@ var createToolHandlers = ({
|
|
|
15830
15876
|
};
|
|
15831
15877
|
});
|
|
15832
15878
|
assertReceiptScopeCurrent(scope);
|
|
15833
|
-
|
|
15879
|
+
sendRequestResult("tool.call", id2, result);
|
|
15834
15880
|
} catch (error) {
|
|
15835
15881
|
if (scope.connectionSignal.aborted) return;
|
|
15836
15882
|
sendError(id2, {
|
|
15837
|
-
code:
|
|
15883
|
+
code: import_protocol6.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
15838
15884
|
message: scope.ownerSignal.aborted ? "approval_expired" : error instanceof import_core15.ToolPermissionDenied ? error.decision.reason ?? "permission_denied" : `tool call failed: ${String(error)}`
|
|
15839
15885
|
});
|
|
15840
15886
|
}
|
|
@@ -19958,13 +20004,13 @@ var shellStateSchema = import_zod34.z.enum([
|
|
|
19958
20004
|
]);
|
|
19959
20005
|
var shellRunSchema = import_zod34.z.object({
|
|
19960
20006
|
command: import_zod34.z.string().describe(
|
|
19961
|
-
"
|
|
20007
|
+
"Complete shell source for the active interpreter; multiline scripts are accepted. Pass the source directly, without adding an outer layer of shell quoting or a shell wrapper."
|
|
19962
20008
|
),
|
|
19963
20009
|
cwd: import_zod34.z.string().min(1).optional().describe(
|
|
19964
|
-
"Working directory for this launch. Relative paths resolve from the workspace; omit to use its root."
|
|
20010
|
+
"Working directory for this launch; set this instead of prefixing the command with cd. Relative paths resolve from the workspace; omit to use its root."
|
|
19965
20011
|
),
|
|
19966
20012
|
label: import_zod34.z.string().max(SHELL_LABEL_MAX_CHARS).optional().describe(
|
|
19967
|
-
`Short label used to build the
|
|
20013
|
+
`Short task label, also used to build the task key. Use this for a heading instead of printing one from the command. Max ${SHELL_LABEL_MAX_CHARS} chars.`
|
|
19968
20014
|
),
|
|
19969
20015
|
timeout: import_zod34.z.number().int().positive().optional().describe(
|
|
19970
20016
|
`Execution timeout in seconds. Foreground: default ${DEFAULT_TIMEOUT_SECONDS}, max ${MAX_TIMEOUT_SECONDS}. Detached: max ${MAX_EXECUTION_TIMEOUT_SECONDS}; omit for no execution timer.`
|
|
@@ -22982,7 +23028,7 @@ function createRuntimeAttachmentService(state) {
|
|
|
22982
23028
|
var import_storage24 = require("@codelia/storage");
|
|
22983
23029
|
|
|
22984
23030
|
// src/mcp/manager.ts
|
|
22985
|
-
var
|
|
23031
|
+
var import_protocol8 = require("@codelia/protocol");
|
|
22986
23032
|
var import_storage25 = require("@codelia/storage");
|
|
22987
23033
|
|
|
22988
23034
|
// src/mcp/jsonrpc.ts
|
|
@@ -24069,7 +24115,7 @@ var McpManager = class {
|
|
|
24069
24115
|
}
|
|
24070
24116
|
this.clients.add(client);
|
|
24071
24117
|
runtime.client = client;
|
|
24072
|
-
const protocolVersion = (0,
|
|
24118
|
+
const protocolVersion = (0, import_protocol8.getMcpProtocolVersion)();
|
|
24073
24119
|
const initializeResult = await client.request(
|
|
24074
24120
|
"initialize",
|
|
24075
24121
|
{
|
|
@@ -24083,10 +24129,10 @@ var McpManager = class {
|
|
|
24083
24129
|
{ timeoutMs: runtime.config.request_timeout_ms }
|
|
24084
24130
|
);
|
|
24085
24131
|
if (this.closed) return;
|
|
24086
|
-
const negotiatedProtocol = (0,
|
|
24087
|
-
if (negotiatedProtocol && !(0,
|
|
24132
|
+
const negotiatedProtocol = (0, import_protocol8.getInitializeProtocolVersion)(initializeResult);
|
|
24133
|
+
if (negotiatedProtocol && !(0, import_protocol8.isSupportedMcpProtocolVersion)(negotiatedProtocol)) {
|
|
24088
24134
|
throw new Error(
|
|
24089
|
-
`unsupported protocol version: ${negotiatedProtocol} (supported: ${(0,
|
|
24135
|
+
`unsupported protocol version: ${negotiatedProtocol} (supported: ${(0, import_protocol8.getMcpCompatibleProtocolVersions)().join(", ")})`
|
|
24090
24136
|
);
|
|
24091
24137
|
}
|
|
24092
24138
|
if (negotiatedProtocol && negotiatedProtocol !== protocolVersion) {
|
|
@@ -24460,7 +24506,7 @@ var McpManager = class {
|
|
|
24460
24506
|
serverId: config.id,
|
|
24461
24507
|
url: config.url ?? "",
|
|
24462
24508
|
headers: config.headers,
|
|
24463
|
-
protocolVersion: (0,
|
|
24509
|
+
protocolVersion: (0, import_protocol8.getMcpProtocolVersion)(),
|
|
24464
24510
|
log: this.options.log,
|
|
24465
24511
|
getAccessToken: () => this.getServerAccessToken(config.id, config),
|
|
24466
24512
|
refreshAccessToken: (failedAccessToken) => this.refreshServerAccessToken(
|
|
@@ -24668,6 +24714,7 @@ var RuntimeState = class {
|
|
|
24668
24714
|
authority
|
|
24669
24715
|
]);
|
|
24670
24716
|
}
|
|
24717
|
+
acceptedSteerIds = /* @__PURE__ */ new Map();
|
|
24671
24718
|
pendingSteersByRun = /* @__PURE__ */ new Map();
|
|
24672
24719
|
steerClosedRuns = /* @__PURE__ */ new Set();
|
|
24673
24720
|
uiRequestCounter = 0;
|
|
@@ -24802,6 +24849,7 @@ var RuntimeState = class {
|
|
|
24802
24849
|
this.lastContextLeftPercent = null;
|
|
24803
24850
|
this.runSeq.delete(runId);
|
|
24804
24851
|
this.pendingSteersByRun.delete(runId);
|
|
24852
|
+
this.acceptedSteerIds.delete(runId);
|
|
24805
24853
|
this.steerClosedRuns.delete(runId);
|
|
24806
24854
|
if (this.activeRunId === null) {
|
|
24807
24855
|
this.sessionAppend = null;
|
|
@@ -24814,10 +24862,18 @@ var RuntimeState = class {
|
|
|
24814
24862
|
canSteerRun(runId) {
|
|
24815
24863
|
return this.activeRunId === runId && !this.cancelRequested && !this.steerClosedRuns.has(runId);
|
|
24816
24864
|
}
|
|
24865
|
+
acceptedRunSteerId(runId, clientSteerId) {
|
|
24866
|
+
return this.acceptedSteerIds.get(runId)?.get(clientSteerId);
|
|
24867
|
+
}
|
|
24817
24868
|
enqueueRunSteer(runId, content, clientSteerId, approvalUserText) {
|
|
24818
24869
|
this.signalApprovalChange();
|
|
24819
24870
|
this.runSteerCounter += 1;
|
|
24820
24871
|
const steerId = `s${this.runSteerCounter}`;
|
|
24872
|
+
if (clientSteerId !== void 0) {
|
|
24873
|
+
const accepted = this.acceptedSteerIds.get(runId) ?? /* @__PURE__ */ new Map();
|
|
24874
|
+
accepted.set(clientSteerId, steerId);
|
|
24875
|
+
this.acceptedSteerIds.set(runId, accepted);
|
|
24876
|
+
}
|
|
24821
24877
|
if (this.approvalIntent?.runId === runId) {
|
|
24822
24878
|
this.approvalIntent.steers.push({
|
|
24823
24879
|
id: steerId,
|
|
@@ -24828,7 +24884,7 @@ var RuntimeState = class {
|
|
|
24828
24884
|
const queue = this.pendingSteersByRun.get(runId) ?? [];
|
|
24829
24885
|
queue.push({
|
|
24830
24886
|
steer_id: steerId,
|
|
24831
|
-
...clientSteerId ? { client_steer_id: clientSteerId } : {},
|
|
24887
|
+
...clientSteerId !== void 0 ? { client_steer_id: clientSteerId } : {},
|
|
24832
24888
|
content
|
|
24833
24889
|
});
|
|
24834
24890
|
this.pendingSteersByRun.set(runId, queue);
|
|
@@ -24968,7 +25024,7 @@ function spawnRuntimeMcpStdio(state, workingDir, config, trustedService, signal)
|
|
|
24968
25024
|
}
|
|
24969
25025
|
|
|
24970
25026
|
// src/rpc/handlers.ts
|
|
24971
|
-
var
|
|
25027
|
+
var import_protocol45 = require("@codelia/protocol");
|
|
24972
25028
|
var import_storage35 = require("@codelia/storage");
|
|
24973
25029
|
|
|
24974
25030
|
// src/constants.ts
|
|
@@ -24977,80 +25033,77 @@ var SERVER_VERSION = "0.1.0";
|
|
|
24977
25033
|
var PROTOCOL_VERSION = "0";
|
|
24978
25034
|
|
|
24979
25035
|
// src/rpc/attachment.ts
|
|
24980
|
-
var
|
|
24981
|
-
async function handleAttachmentUpload(state, id2, method,
|
|
25036
|
+
var import_protocol9 = require("@codelia/protocol");
|
|
25037
|
+
async function handleAttachmentUpload(state, id2, method, raw) {
|
|
24982
25038
|
const attachments = state.attachments;
|
|
24983
25039
|
try {
|
|
24984
25040
|
if (!attachments)
|
|
24985
25041
|
throw new AttachmentUploadError("Attachment uploads are disabled");
|
|
24986
|
-
if (!
|
|
25042
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
24987
25043
|
throw new AttachmentUploadError(
|
|
24988
25044
|
"Attachment upload parameters are required"
|
|
24989
25045
|
);
|
|
24990
25046
|
switch (method) {
|
|
24991
|
-
case "attachment.upload.begin":
|
|
24992
|
-
|
|
25047
|
+
case "attachment.upload.begin": {
|
|
25048
|
+
const parsed = parseRequestParams(method, raw);
|
|
25049
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25050
|
+
return sendRequestResult(
|
|
25051
|
+
method,
|
|
24993
25052
|
id2,
|
|
24994
|
-
await attachments.begin(
|
|
24995
|
-
params,
|
|
24996
|
-
state.sessionId
|
|
24997
|
-
)
|
|
25053
|
+
await attachments.begin(parsed.params, state.sessionId)
|
|
24998
25054
|
);
|
|
24999
|
-
|
|
25000
|
-
|
|
25055
|
+
}
|
|
25056
|
+
case "attachment.upload.chunk": {
|
|
25057
|
+
const parsed = parseRequestParams(method, raw);
|
|
25058
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25059
|
+
return sendRequestResult(
|
|
25060
|
+
method,
|
|
25001
25061
|
id2,
|
|
25002
|
-
await attachments.chunk(
|
|
25003
|
-
params,
|
|
25004
|
-
state.sessionId
|
|
25005
|
-
)
|
|
25062
|
+
await attachments.chunk(parsed.params, state.sessionId)
|
|
25006
25063
|
);
|
|
25007
|
-
|
|
25008
|
-
|
|
25064
|
+
}
|
|
25065
|
+
case "attachment.upload.finish": {
|
|
25066
|
+
const parsed = parseRequestParams(method, raw);
|
|
25067
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25068
|
+
return sendRequestResult(
|
|
25069
|
+
method,
|
|
25009
25070
|
id2,
|
|
25010
|
-
await attachments.finish(
|
|
25011
|
-
params.upload_id,
|
|
25012
|
-
state.sessionId
|
|
25013
|
-
)
|
|
25014
|
-
);
|
|
25015
|
-
case "attachment.upload.cancel":
|
|
25016
|
-
await attachments.cancel(
|
|
25017
|
-
params.upload_id,
|
|
25018
|
-
state.sessionId
|
|
25071
|
+
await attachments.finish(parsed.params.upload_id, state.sessionId)
|
|
25019
25072
|
);
|
|
25020
|
-
|
|
25021
|
-
|
|
25022
|
-
|
|
25073
|
+
}
|
|
25074
|
+
case "attachment.upload.cancel": {
|
|
25075
|
+
const parsed = parseRequestParams(method, raw);
|
|
25076
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25077
|
+
await attachments.cancel(parsed.params.upload_id, state.sessionId);
|
|
25078
|
+
return sendRequestResult(method, id2, { ok: true });
|
|
25079
|
+
}
|
|
25023
25080
|
}
|
|
25024
25081
|
} catch (error) {
|
|
25025
25082
|
if (!(error instanceof AttachmentUploadError)) throw error;
|
|
25026
25083
|
sendError(id2, {
|
|
25027
|
-
code:
|
|
25084
|
+
code: import_protocol9.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25028
25085
|
message: error.message
|
|
25029
25086
|
});
|
|
25030
25087
|
}
|
|
25031
25088
|
}
|
|
25032
25089
|
|
|
25033
25090
|
// src/rpc/auth.ts
|
|
25034
|
-
var
|
|
25035
|
-
var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2,
|
|
25091
|
+
var import_protocol11 = require("@codelia/protocol");
|
|
25092
|
+
var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, raw) => {
|
|
25036
25093
|
if (state.activeRunId) {
|
|
25037
25094
|
sendError(id2, {
|
|
25038
|
-
code:
|
|
25095
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25039
25096
|
message: "runtime busy"
|
|
25040
25097
|
});
|
|
25041
25098
|
return;
|
|
25042
25099
|
}
|
|
25043
|
-
const
|
|
25044
|
-
if (
|
|
25100
|
+
const parsed = parseRequestParams("auth.logout", raw);
|
|
25101
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25102
|
+
const params = parsed.params;
|
|
25103
|
+
const provider = params.provider;
|
|
25104
|
+
if (provider !== void 0 && !/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(provider)) {
|
|
25045
25105
|
sendError(id2, {
|
|
25046
|
-
code:
|
|
25047
|
-
message: "confirmed must be a boolean"
|
|
25048
|
-
});
|
|
25049
|
-
return;
|
|
25050
|
-
}
|
|
25051
|
-
if (provider !== void 0 && (typeof provider !== "string" || !/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(provider))) {
|
|
25052
|
-
sendError(id2, {
|
|
25053
|
-
code: import_protocol5.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25106
|
+
code: import_protocol11.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25054
25107
|
message: "invalid logout provider name"
|
|
25055
25108
|
});
|
|
25056
25109
|
return;
|
|
@@ -25068,7 +25121,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25068
25121
|
const credentials = state.effectiveEnvironment.adapters.credentialProvider;
|
|
25069
25122
|
if (provider ? !credentials?.clearProviderAuth : !credentials?.clearAuth) {
|
|
25070
25123
|
sendError(id2, {
|
|
25071
|
-
code:
|
|
25124
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25072
25125
|
message: provider ? "host auth provider does not support scoped logout" : "host auth provider does not support logout"
|
|
25073
25126
|
});
|
|
25074
25127
|
return;
|
|
@@ -25081,7 +25134,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25081
25134
|
const auth = await store.loadV2();
|
|
25082
25135
|
if (!Object.hasOwn(auth.providers, provider) && !configuredProviders(config?.providers).includes(provider)) {
|
|
25083
25136
|
sendError(id2, {
|
|
25084
|
-
code:
|
|
25137
|
+
code: import_protocol11.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25085
25138
|
message: `unknown logout provider: ${provider}`
|
|
25086
25139
|
});
|
|
25087
25140
|
return;
|
|
@@ -25090,7 +25143,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25090
25143
|
const preconfirmed = params?.confirmed === true;
|
|
25091
25144
|
if (!preconfirmed && !state.uiCapabilities?.supports_confirm) {
|
|
25092
25145
|
sendError(id2, {
|
|
25093
|
-
code:
|
|
25146
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25094
25147
|
message: "UI confirmation is required for logout"
|
|
25095
25148
|
});
|
|
25096
25149
|
return;
|
|
@@ -25105,7 +25158,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25105
25158
|
allow_reason: false
|
|
25106
25159
|
});
|
|
25107
25160
|
if (!confirm?.ok) {
|
|
25108
|
-
|
|
25161
|
+
sendRequestResult("auth.logout", id2, {
|
|
25109
25162
|
ok: false,
|
|
25110
25163
|
auth_cleared: false,
|
|
25111
25164
|
session_cleared: false,
|
|
@@ -25131,7 +25184,7 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25131
25184
|
state.sessionAppend = null;
|
|
25132
25185
|
state.sessionModelOverride = null;
|
|
25133
25186
|
}
|
|
25134
|
-
|
|
25187
|
+
sendRequestResult("auth.logout", id2, {
|
|
25135
25188
|
ok: true,
|
|
25136
25189
|
auth_cleared: true,
|
|
25137
25190
|
session_cleared: clearSession,
|
|
@@ -25142,14 +25195,14 @@ var createAuthLogoutHandler = ({ state, log: log2 }) => async (id2, params) => {
|
|
|
25142
25195
|
);
|
|
25143
25196
|
} catch {
|
|
25144
25197
|
sendError(id2, {
|
|
25145
|
-
code:
|
|
25198
|
+
code: import_protocol11.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25146
25199
|
message: "auth logout failed"
|
|
25147
25200
|
});
|
|
25148
25201
|
}
|
|
25149
25202
|
};
|
|
25150
25203
|
|
|
25151
25204
|
// src/rpc/auth-management.ts
|
|
25152
|
-
var
|
|
25205
|
+
var import_protocol13 = require("@codelia/protocol");
|
|
25153
25206
|
var import_storage27 = require("@codelia/storage");
|
|
25154
25207
|
|
|
25155
25208
|
// src/mcp/config-secret-warnings.ts
|
|
@@ -25214,7 +25267,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25214
25267
|
const rejectUnsupported = (id2) => {
|
|
25215
25268
|
if (supportsAuthManagement(state)) return false;
|
|
25216
25269
|
sendError(id2, {
|
|
25217
|
-
code:
|
|
25270
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25218
25271
|
message: "auth is host-owned"
|
|
25219
25272
|
});
|
|
25220
25273
|
return true;
|
|
@@ -25227,11 +25280,10 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25227
25280
|
status: status2,
|
|
25228
25281
|
...message ? { message } : {}
|
|
25229
25282
|
};
|
|
25230
|
-
void sendNotificationAsync(
|
|
25231
|
-
|
|
25232
|
-
|
|
25233
|
-
|
|
25234
|
-
});
|
|
25283
|
+
void sendNotificationAsync(
|
|
25284
|
+
state,
|
|
25285
|
+
notificationMessage("auth.login.status", params)
|
|
25286
|
+
);
|
|
25235
25287
|
};
|
|
25236
25288
|
const settle = (login) => {
|
|
25237
25289
|
if (login.settled) return false;
|
|
@@ -25272,12 +25324,15 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25272
25324
|
);
|
|
25273
25325
|
return { config, providers: uniqueProviders(config.providers) };
|
|
25274
25326
|
};
|
|
25275
|
-
const handleStatus = async (id2,
|
|
25327
|
+
const handleStatus = async (id2, raw) => {
|
|
25276
25328
|
if (rejectUnsupported(id2)) return;
|
|
25329
|
+
const parsed = parseRequestParams("auth.status", raw);
|
|
25330
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25331
|
+
const params = parsed.params;
|
|
25277
25332
|
const requested = params?.provider;
|
|
25278
25333
|
if (requested !== void 0 && (typeof requested !== "string" || !PROVIDER_NAME_PATTERN.test(requested))) {
|
|
25279
25334
|
sendError(id2, {
|
|
25280
|
-
code:
|
|
25335
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25281
25336
|
message: "invalid provider name"
|
|
25282
25337
|
});
|
|
25283
25338
|
return;
|
|
@@ -25286,7 +25341,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25286
25341
|
const { config, providers } = await resolveProviders();
|
|
25287
25342
|
if (requested !== void 0 && !providers.includes(requested)) {
|
|
25288
25343
|
sendError(id2, {
|
|
25289
|
-
code:
|
|
25344
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25290
25345
|
message: `unknown provider: ${requested}`
|
|
25291
25346
|
});
|
|
25292
25347
|
return;
|
|
@@ -25389,28 +25444,31 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25389
25444
|
},
|
|
25390
25445
|
...warnings.length > 0 ? { warnings } : {}
|
|
25391
25446
|
};
|
|
25392
|
-
|
|
25447
|
+
sendRequestResult("auth.status", id2, result);
|
|
25393
25448
|
} catch {
|
|
25394
25449
|
sendError(id2, {
|
|
25395
|
-
code:
|
|
25450
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25396
25451
|
message: "auth status failed"
|
|
25397
25452
|
});
|
|
25398
25453
|
}
|
|
25399
25454
|
};
|
|
25400
|
-
const handleLogin = async (id2,
|
|
25455
|
+
const handleLogin = async (id2, raw) => {
|
|
25401
25456
|
if (rejectUnsupported(id2)) return;
|
|
25402
25457
|
if (state.activeRunId) {
|
|
25403
25458
|
sendError(id2, {
|
|
25404
|
-
code:
|
|
25459
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25405
25460
|
message: "runtime busy"
|
|
25406
25461
|
});
|
|
25407
25462
|
return;
|
|
25408
25463
|
}
|
|
25464
|
+
const parsed = parseRequestParams("auth.login", raw);
|
|
25465
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25466
|
+
const params = parsed.params;
|
|
25409
25467
|
const provider = params?.provider;
|
|
25410
25468
|
const method = params?.method;
|
|
25411
25469
|
if (typeof provider !== "string" || !PROVIDER_NAME_PATTERN.test(provider)) {
|
|
25412
25470
|
sendError(id2, {
|
|
25413
|
-
code:
|
|
25471
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25414
25472
|
message: "invalid provider name"
|
|
25415
25473
|
});
|
|
25416
25474
|
return;
|
|
@@ -25423,31 +25481,31 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25423
25481
|
providerConfigs = resolved.config.providers;
|
|
25424
25482
|
} catch {
|
|
25425
25483
|
sendError(id2, {
|
|
25426
|
-
code:
|
|
25484
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25427
25485
|
message: "auth login failed"
|
|
25428
25486
|
});
|
|
25429
25487
|
return;
|
|
25430
25488
|
}
|
|
25431
25489
|
if (!providers.includes(provider)) {
|
|
25432
25490
|
sendError(id2, {
|
|
25433
|
-
code:
|
|
25491
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25434
25492
|
message: `unknown provider: ${provider}`
|
|
25435
25493
|
});
|
|
25436
25494
|
return;
|
|
25437
25495
|
}
|
|
25438
25496
|
if (!method || !providerAuthMethods(provider, providerConfigs).includes(method)) {
|
|
25439
25497
|
sendError(id2, {
|
|
25440
|
-
code:
|
|
25498
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25441
25499
|
message: `unsupported auth method for ${provider}`
|
|
25442
25500
|
});
|
|
25443
25501
|
return;
|
|
25444
25502
|
}
|
|
25445
25503
|
if (method === "api_key") {
|
|
25446
|
-
const
|
|
25447
|
-
const apiKey = typeof
|
|
25504
|
+
const raw2 = params.api_key;
|
|
25505
|
+
const apiKey = typeof raw2 === "string" ? raw2.trim() : "";
|
|
25448
25506
|
if (!apiKey || apiKey.length > MAX_API_KEY_LENGTH || /\s/.test(apiKey)) {
|
|
25449
25507
|
sendError(id2, {
|
|
25450
|
-
code:
|
|
25508
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25451
25509
|
message: "api_key must be a non-empty single-line string"
|
|
25452
25510
|
});
|
|
25453
25511
|
return;
|
|
@@ -25465,19 +25523,19 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25465
25523
|
});
|
|
25466
25524
|
} catch {
|
|
25467
25525
|
sendError(id2, {
|
|
25468
|
-
code:
|
|
25526
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25469
25527
|
message: "saving credentials failed"
|
|
25470
25528
|
});
|
|
25471
25529
|
return;
|
|
25472
25530
|
}
|
|
25473
25531
|
if (saved === "busy") {
|
|
25474
25532
|
sendError(id2, {
|
|
25475
|
-
code:
|
|
25533
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25476
25534
|
message: "runtime busy"
|
|
25477
25535
|
});
|
|
25478
25536
|
return;
|
|
25479
25537
|
}
|
|
25480
|
-
|
|
25538
|
+
sendRequestResult("auth.login", id2, {
|
|
25481
25539
|
status: "completed",
|
|
25482
25540
|
provider,
|
|
25483
25541
|
method: "api_key"
|
|
@@ -25487,7 +25545,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25487
25545
|
}
|
|
25488
25546
|
if (pending) {
|
|
25489
25547
|
sendError(id2, {
|
|
25490
|
-
code:
|
|
25548
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25491
25549
|
message: "another login is pending"
|
|
25492
25550
|
});
|
|
25493
25551
|
return;
|
|
@@ -25495,7 +25553,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25495
25553
|
const typed = params;
|
|
25496
25554
|
if (typed.callback !== void 0 && typed.callback !== "loopback" && typed.callback !== "paste") {
|
|
25497
25555
|
sendError(id2, {
|
|
25498
|
-
code:
|
|
25556
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25499
25557
|
message: "callback must be loopback or paste"
|
|
25500
25558
|
});
|
|
25501
25559
|
return;
|
|
@@ -25518,7 +25576,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25518
25576
|
}
|
|
25519
25577
|
stop();
|
|
25520
25578
|
sendError(id2, {
|
|
25521
|
-
code:
|
|
25579
|
+
code: import_protocol13.RPC_ERROR_CODE.USER_CANCELLED,
|
|
25522
25580
|
message: "login cancelled"
|
|
25523
25581
|
});
|
|
25524
25582
|
return true;
|
|
@@ -25530,7 +25588,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25530
25588
|
});
|
|
25531
25589
|
if (cancelledDuringSetup(session.stop)) return;
|
|
25532
25590
|
login.completeFromInput = session.completeFromInput;
|
|
25533
|
-
|
|
25591
|
+
sendRequestResult("auth.login", id2, {
|
|
25534
25592
|
status: "pending",
|
|
25535
25593
|
login_id: login.id,
|
|
25536
25594
|
provider,
|
|
@@ -25548,7 +25606,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25548
25606
|
const session = await createOpenAiDeviceCodeSession();
|
|
25549
25607
|
const abort = new AbortController();
|
|
25550
25608
|
if (cancelledDuringSetup(() => abort.abort())) return;
|
|
25551
|
-
|
|
25609
|
+
sendRequestResult("auth.login", id2, {
|
|
25552
25610
|
status: "pending",
|
|
25553
25611
|
login_id: login.id,
|
|
25554
25612
|
provider,
|
|
@@ -25567,17 +25625,20 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25567
25625
|
login.settled = true;
|
|
25568
25626
|
if (pending === login) pending = null;
|
|
25569
25627
|
sendError(id2, {
|
|
25570
|
-
code:
|
|
25628
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25571
25629
|
message: `auth login failed: ${failureMessage(error)}`
|
|
25572
25630
|
});
|
|
25573
25631
|
}
|
|
25574
25632
|
};
|
|
25575
|
-
const handleLoginComplete = async (id2,
|
|
25633
|
+
const handleLoginComplete = async (id2, raw) => {
|
|
25576
25634
|
if (rejectUnsupported(id2)) return;
|
|
25635
|
+
const parsed = parseRequestParams("auth.login.complete", raw);
|
|
25636
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25637
|
+
const params = parsed.params;
|
|
25577
25638
|
const login = pending;
|
|
25578
25639
|
if (!login || login.id !== params?.login_id) {
|
|
25579
25640
|
sendError(id2, {
|
|
25580
|
-
code:
|
|
25641
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25581
25642
|
message: "no matching pending login"
|
|
25582
25643
|
});
|
|
25583
25644
|
return;
|
|
@@ -25585,7 +25646,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25585
25646
|
const input = params?.callback_input;
|
|
25586
25647
|
if (!login.completeFromInput || typeof input !== "string" || !input.trim() || input.length > MAX_CALLBACK_INPUT_LENGTH) {
|
|
25587
25648
|
sendError(id2, {
|
|
25588
|
-
code:
|
|
25649
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25589
25650
|
message: "callback_input is required for a pending OAuth login"
|
|
25590
25651
|
});
|
|
25591
25652
|
return;
|
|
@@ -25595,38 +25656,44 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25595
25656
|
completion = login.completeFromInput(input.trim());
|
|
25596
25657
|
} catch {
|
|
25597
25658
|
sendError(id2, {
|
|
25598
|
-
code:
|
|
25659
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25599
25660
|
message: "invalid OAuth callback input"
|
|
25600
25661
|
});
|
|
25601
25662
|
return;
|
|
25602
25663
|
}
|
|
25603
|
-
|
|
25664
|
+
sendRequestResult("auth.login.complete", id2, { ok: true });
|
|
25604
25665
|
completion.then(
|
|
25605
25666
|
(tokens) => finishLogin(login, tokens),
|
|
25606
25667
|
(error) => failLogin(login, error)
|
|
25607
25668
|
);
|
|
25608
25669
|
};
|
|
25609
|
-
const handleLoginCancel = async (id2,
|
|
25670
|
+
const handleLoginCancel = async (id2, raw) => {
|
|
25610
25671
|
if (rejectUnsupported(id2)) return;
|
|
25672
|
+
const parsed = parseRequestParams("auth.login.cancel", raw);
|
|
25673
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25674
|
+
const params = parsed.params;
|
|
25611
25675
|
const login = pending;
|
|
25612
25676
|
if (!login || login.id !== params?.login_id) {
|
|
25613
|
-
|
|
25677
|
+
sendRequestResult("auth.login.cancel", id2, { cancelled: false });
|
|
25614
25678
|
return;
|
|
25615
25679
|
}
|
|
25616
25680
|
settle(login);
|
|
25617
|
-
|
|
25681
|
+
sendRequestResult("auth.login.cancel", id2, { cancelled: true });
|
|
25618
25682
|
notifyLogin(login, "cancelled");
|
|
25619
25683
|
log2(`auth.login cancelled provider=${login.provider}`);
|
|
25620
25684
|
};
|
|
25621
|
-
const handleResolveConflict = async (id2,
|
|
25685
|
+
const handleResolveConflict = async (id2, raw) => {
|
|
25622
25686
|
if (rejectUnsupported(id2)) return;
|
|
25623
25687
|
if (state.activeRunId) {
|
|
25624
25688
|
sendError(id2, {
|
|
25625
|
-
code:
|
|
25689
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25626
25690
|
message: "runtime busy"
|
|
25627
25691
|
});
|
|
25628
25692
|
return;
|
|
25629
25693
|
}
|
|
25694
|
+
const parsed = parseRequestParams("auth.storage.resolve_conflict", raw);
|
|
25695
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25696
|
+
const params = parsed.params;
|
|
25630
25697
|
const strategy = params?.strategy;
|
|
25631
25698
|
const validStrategies = /* @__PURE__ */ new Set([
|
|
25632
25699
|
"keep_keyring",
|
|
@@ -25636,7 +25703,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25636
25703
|
]);
|
|
25637
25704
|
if (typeof strategy !== "string" || !validStrategies.has(strategy)) {
|
|
25638
25705
|
sendError(id2, {
|
|
25639
|
-
code:
|
|
25706
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25640
25707
|
message: "strategy must be one of keep_keyring, keep_file, keep_legacy, or clear_all"
|
|
25641
25708
|
});
|
|
25642
25709
|
return;
|
|
@@ -25645,7 +25712,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25645
25712
|
if (params?.stores !== void 0) {
|
|
25646
25713
|
if (!Array.isArray(params.stores) || params.stores.length === 0 || !params.stores.every((s) => s === "auth" || s === "mcp_auth")) {
|
|
25647
25714
|
sendError(id2, {
|
|
25648
|
-
code:
|
|
25715
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25649
25716
|
message: "stores must be a non-empty array of 'auth' or 'mcp_auth'"
|
|
25650
25717
|
});
|
|
25651
25718
|
return;
|
|
@@ -25654,7 +25721,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25654
25721
|
}
|
|
25655
25722
|
if (params?.confirmed !== void 0 && typeof params.confirmed !== "boolean") {
|
|
25656
25723
|
sendError(id2, {
|
|
25657
|
-
code:
|
|
25724
|
+
code: import_protocol13.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
25658
25725
|
message: "confirmed must be a boolean"
|
|
25659
25726
|
});
|
|
25660
25727
|
return;
|
|
@@ -25662,7 +25729,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25662
25729
|
const preconfirmed = params?.confirmed === true;
|
|
25663
25730
|
if (!preconfirmed && !state.uiCapabilities?.supports_confirm) {
|
|
25664
25731
|
sendError(id2, {
|
|
25665
|
-
code:
|
|
25732
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25666
25733
|
message: "UI confirmation is required to resolve credential conflicts"
|
|
25667
25734
|
});
|
|
25668
25735
|
return;
|
|
@@ -25678,7 +25745,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25678
25745
|
allow_reason: false
|
|
25679
25746
|
});
|
|
25680
25747
|
if (!confirm?.ok) {
|
|
25681
|
-
|
|
25748
|
+
sendRequestResult("auth.storage.resolve_conflict", id2, {
|
|
25682
25749
|
ok: false,
|
|
25683
25750
|
resolved_stores: [],
|
|
25684
25751
|
cancelled: true
|
|
@@ -25701,7 +25768,7 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25701
25768
|
});
|
|
25702
25769
|
runtimeLocalAutoReview(state).revokeAuth();
|
|
25703
25770
|
state.requestAgentInvalidation();
|
|
25704
|
-
|
|
25771
|
+
sendRequestResult("auth.storage.resolve_conflict", id2, {
|
|
25705
25772
|
ok: true,
|
|
25706
25773
|
active: resolved.active,
|
|
25707
25774
|
resolved_stores: resolved.resolvedStores
|
|
@@ -25712,13 +25779,13 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25712
25779
|
} catch (error) {
|
|
25713
25780
|
if (error instanceof Error && error.message === "runtime busy") {
|
|
25714
25781
|
sendError(id2, {
|
|
25715
|
-
code:
|
|
25782
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
25716
25783
|
message: "runtime busy"
|
|
25717
25784
|
});
|
|
25718
25785
|
return;
|
|
25719
25786
|
}
|
|
25720
25787
|
sendError(id2, {
|
|
25721
|
-
code:
|
|
25788
|
+
code: import_protocol13.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
25722
25789
|
message: `failed to resolve credential conflict: ${failureMessage(error)}`
|
|
25723
25790
|
});
|
|
25724
25791
|
}
|
|
@@ -25733,29 +25800,25 @@ var createAuthManagementHandlers = ({ state, log: log2 }) => {
|
|
|
25733
25800
|
};
|
|
25734
25801
|
|
|
25735
25802
|
// src/rpc/auto-review.ts
|
|
25736
|
-
var
|
|
25803
|
+
var import_protocol15 = require("@codelia/protocol");
|
|
25737
25804
|
var import_storage28 = require("@codelia/storage");
|
|
25738
|
-
var import_zod46 = require("zod");
|
|
25739
|
-
var paramsSchema = import_zod46.z.strictObject({
|
|
25740
|
-
action: import_zod46.z.enum(["pick", "status", "off"]).default("pick")
|
|
25741
|
-
});
|
|
25742
25805
|
var reviewerId = (reviewer) => `${reviewer.provider}/${reviewer.model}`;
|
|
25743
25806
|
var oneChoice = (result) => Array.isArray(result.ids) && result.ids.length === 1 ? result.ids[0] : void 0;
|
|
25744
25807
|
var supportsLocalAutoReviewConfiguration = (state) => state.effectiveEnvironment.sourcePreset === "tui-local" && !state.effectiveEnvironment.adapters.approvalReviewer && process.geteuid !== void 0;
|
|
25745
25808
|
var handleAutoReview = async (state, id2, raw) => {
|
|
25746
|
-
const fail = (message, code =
|
|
25809
|
+
const fail = (message, code = import_protocol15.RPC_ERROR_CODE.INVALID_PARAMS) => sendError(id2, { code, message });
|
|
25747
25810
|
if (!supportsLocalAutoReviewConfiguration(state))
|
|
25748
25811
|
return fail(
|
|
25749
25812
|
"Local Auto approve settings are unavailable.",
|
|
25750
|
-
|
|
25813
|
+
import_protocol15.RPC_ERROR_CODE.METHOD_NOT_FOUND
|
|
25751
25814
|
);
|
|
25752
|
-
const
|
|
25753
|
-
if (!
|
|
25754
|
-
|
|
25755
|
-
const { action } = params.data;
|
|
25815
|
+
const parsed = parseRequestParams("auto_review.configure", raw);
|
|
25816
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
25817
|
+
const { action = "pick" } = parsed.params;
|
|
25756
25818
|
const workspace = state.runtimeSandboxRoot ?? state.runtimeWorkingDir ?? process.cwd();
|
|
25757
25819
|
const local = runtimeLocalAutoReview(state);
|
|
25758
|
-
const status2 = async () =>
|
|
25820
|
+
const status2 = async () => sendRequestResult(
|
|
25821
|
+
"auto_review.configure",
|
|
25759
25822
|
id2,
|
|
25760
25823
|
local.status(workspace, await reviewChatRouteForStatus(state, workspace))
|
|
25761
25824
|
);
|
|
@@ -25770,7 +25833,7 @@ var handleAutoReview = async (state, id2, raw) => {
|
|
|
25770
25833
|
if (state.activeRunId)
|
|
25771
25834
|
return fail(
|
|
25772
25835
|
"Wait for the current run to finish before configuring Auto approve.",
|
|
25773
|
-
|
|
25836
|
+
import_protocol15.RPC_ERROR_CODE.RUNTIME_BUSY
|
|
25774
25837
|
);
|
|
25775
25838
|
if (!state.uiCapabilities?.supports_pick)
|
|
25776
25839
|
return fail("Auto approve setup requires a client with picker support.");
|
|
@@ -25865,7 +25928,7 @@ var handleAutoReview = async (state, id2, raw) => {
|
|
|
25865
25928
|
|
|
25866
25929
|
// src/rpc/config.ts
|
|
25867
25930
|
var import_config_loader2 = require("@codelia/config-loader");
|
|
25868
|
-
var
|
|
25931
|
+
var import_protocol17 = require("@codelia/protocol");
|
|
25869
25932
|
|
|
25870
25933
|
// src/config-keys.ts
|
|
25871
25934
|
var import_config18 = require("@codelia/config");
|
|
@@ -26028,17 +26091,20 @@ var createConfigHandlers = ({
|
|
|
26028
26091
|
const rejectUnsupported = (id2) => {
|
|
26029
26092
|
if (supportsConfigReadWrite(state)) return false;
|
|
26030
26093
|
sendError(id2, {
|
|
26031
|
-
code:
|
|
26094
|
+
code: import_protocol17.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
26032
26095
|
message: "config read/write is not available for this runtime"
|
|
26033
26096
|
});
|
|
26034
26097
|
return true;
|
|
26035
26098
|
};
|
|
26036
|
-
const handleConfigGet = async (id2,
|
|
26099
|
+
const handleConfigGet = async (id2, raw) => {
|
|
26037
26100
|
if (rejectUnsupported(id2)) return;
|
|
26101
|
+
const parsed = parseRequestParams("config.get", raw);
|
|
26102
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
26103
|
+
const params = parsed.params;
|
|
26038
26104
|
const keys = params?.keys;
|
|
26039
26105
|
if (keys !== void 0 && (!Array.isArray(keys) || keys.length > MAX_KEYS_PER_REQUEST || keys.some((key) => typeof key !== "string" || !findConfigKey(key)))) {
|
|
26040
26106
|
sendError(id2, {
|
|
26041
|
-
code:
|
|
26107
|
+
code: import_protocol17.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
26042
26108
|
message: "keys must list known config keys"
|
|
26043
26109
|
});
|
|
26044
26110
|
return;
|
|
@@ -26050,18 +26116,21 @@ var createConfigHandlers = ({
|
|
|
26050
26116
|
entries: specs.map((spec) => buildConfigEntry(spec, layers)),
|
|
26051
26117
|
...layers.errors.length ? { errors: layers.errors } : {}
|
|
26052
26118
|
};
|
|
26053
|
-
|
|
26119
|
+
sendRequestResult("config.get", id2, result);
|
|
26054
26120
|
};
|
|
26055
|
-
const handleConfigSet = async (id2,
|
|
26121
|
+
const handleConfigSet = async (id2, raw) => {
|
|
26056
26122
|
if (rejectUnsupported(id2)) return;
|
|
26057
26123
|
if (state.activeRunId) {
|
|
26058
26124
|
sendError(id2, {
|
|
26059
|
-
code:
|
|
26125
|
+
code: import_protocol17.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
26060
26126
|
message: "runtime busy"
|
|
26061
26127
|
});
|
|
26062
26128
|
return;
|
|
26063
26129
|
}
|
|
26064
|
-
const
|
|
26130
|
+
const parsed = parseRequestParams("config.set", raw);
|
|
26131
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
26132
|
+
const params = parsed.params;
|
|
26133
|
+
const invalid = (message) => sendError(id2, { code: import_protocol17.RPC_ERROR_CODE.INVALID_PARAMS, message });
|
|
26065
26134
|
const scope = params?.scope;
|
|
26066
26135
|
if (scope !== "global" && scope !== "project") {
|
|
26067
26136
|
invalid("scope must be global or project");
|
|
@@ -26116,14 +26185,14 @@ var createConfigHandlers = ({
|
|
|
26116
26185
|
});
|
|
26117
26186
|
} catch {
|
|
26118
26187
|
sendError(id2, {
|
|
26119
|
-
code:
|
|
26188
|
+
code: import_protocol17.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
26120
26189
|
message: `${scope} config write failed`
|
|
26121
26190
|
});
|
|
26122
26191
|
return;
|
|
26123
26192
|
}
|
|
26124
26193
|
if (changed === "busy") {
|
|
26125
26194
|
sendError(id2, {
|
|
26126
|
-
code:
|
|
26195
|
+
code: import_protocol17.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
26127
26196
|
message: "runtime busy"
|
|
26128
26197
|
});
|
|
26129
26198
|
return;
|
|
@@ -26136,7 +26205,7 @@ var createConfigHandlers = ({
|
|
|
26136
26205
|
entry: buildConfigEntry(spec, layers),
|
|
26137
26206
|
applies: "next_run"
|
|
26138
26207
|
};
|
|
26139
|
-
|
|
26208
|
+
sendRequestResult("config.set", id2, result);
|
|
26140
26209
|
log2(
|
|
26141
26210
|
`config.set ${spec.key} scope=${scope} ${unset ? "unset" : "set"} changed=${changed}`
|
|
26142
26211
|
);
|
|
@@ -26145,7 +26214,7 @@ var createConfigHandlers = ({
|
|
|
26145
26214
|
};
|
|
26146
26215
|
|
|
26147
26216
|
// src/rpc/context.ts
|
|
26148
|
-
var
|
|
26217
|
+
var import_protocol19 = require("@codelia/protocol");
|
|
26149
26218
|
var createContextHandlers = ({
|
|
26150
26219
|
state,
|
|
26151
26220
|
log: log2
|
|
@@ -26279,10 +26348,10 @@ var createContextHandlers = ({
|
|
|
26279
26348
|
result.skills = snapshot;
|
|
26280
26349
|
}
|
|
26281
26350
|
}
|
|
26282
|
-
|
|
26351
|
+
sendRequestResult("context.inspect", id2, result);
|
|
26283
26352
|
} catch (error) {
|
|
26284
26353
|
sendError(id2, {
|
|
26285
|
-
code:
|
|
26354
|
+
code: import_protocol19.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
26286
26355
|
message: `context.inspect failed: ${String(error)}`
|
|
26287
26356
|
});
|
|
26288
26357
|
}
|
|
@@ -26291,7 +26360,7 @@ var createContextHandlers = ({
|
|
|
26291
26360
|
};
|
|
26292
26361
|
|
|
26293
26362
|
// src/rpc/context-usage.ts
|
|
26294
|
-
var
|
|
26363
|
+
var import_protocol21 = require("@codelia/protocol");
|
|
26295
26364
|
var emptyUsage = (state) => ({
|
|
26296
26365
|
provider: state.currentModelProvider,
|
|
26297
26366
|
model: state.currentModelName,
|
|
@@ -26313,11 +26382,11 @@ var createContextUsageHandlers = ({
|
|
|
26313
26382
|
...usage,
|
|
26314
26383
|
...state.sessionId ? { session_id: state.sessionId } : {}
|
|
26315
26384
|
};
|
|
26316
|
-
|
|
26385
|
+
sendRequestResult("context.usage", id2, result);
|
|
26317
26386
|
} catch (error) {
|
|
26318
26387
|
log2(`context.usage failed: ${String(error)}`);
|
|
26319
26388
|
sendError(id2, {
|
|
26320
|
-
code:
|
|
26389
|
+
code: import_protocol21.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
26321
26390
|
message: "context usage unavailable"
|
|
26322
26391
|
});
|
|
26323
26392
|
}
|
|
@@ -26334,15 +26403,13 @@ var createRunContextUsageEmitter = (options) => {
|
|
|
26334
26403
|
if (usage === lastUsage && eventType !== "compaction_complete") return;
|
|
26335
26404
|
lastUsage = usage;
|
|
26336
26405
|
try {
|
|
26337
|
-
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
params: {
|
|
26406
|
+
void sendNotificationAsync(
|
|
26407
|
+
state,
|
|
26408
|
+
notificationMessage("run.context.usage", {
|
|
26341
26409
|
run_id: runId,
|
|
26342
26410
|
...agent.getContextUsage()
|
|
26343
|
-
}
|
|
26344
|
-
|
|
26345
|
-
void sendNotificationAsync(state, notify);
|
|
26411
|
+
})
|
|
26412
|
+
);
|
|
26346
26413
|
} catch (error) {
|
|
26347
26414
|
log2(`run.context.usage emit failed: ${String(error)}`);
|
|
26348
26415
|
}
|
|
@@ -26352,10 +26419,17 @@ var createRunContextUsageEmitter = (options) => {
|
|
|
26352
26419
|
// src/rpc/history.ts
|
|
26353
26420
|
var import_node_fs42 = require("fs");
|
|
26354
26421
|
var import_node_path45 = __toESM(require("path"), 1);
|
|
26355
|
-
var
|
|
26422
|
+
var import_protocol23 = require("@codelia/protocol");
|
|
26356
26423
|
var import_storage29 = require("@codelia/storage");
|
|
26357
26424
|
var DEFAULT_HISTORY_RUNS = 20;
|
|
26358
26425
|
var DEFAULT_HISTORY_EVENTS = 1500;
|
|
26426
|
+
var projectHistoryEvent = (event) => {
|
|
26427
|
+
if (event.type !== "tool_call") return event;
|
|
26428
|
+
const args = event.args;
|
|
26429
|
+
if (args && typeof args === "object" && !Array.isArray(args)) return event;
|
|
26430
|
+
const raw = typeof event.raw_args === "string" ? event.raw_args : JSON.stringify(args) ?? "null";
|
|
26431
|
+
return { ...event, args: { _raw: raw } };
|
|
26432
|
+
};
|
|
26359
26433
|
var runStartInputToHiddenMessage = (input) => {
|
|
26360
26434
|
if (!input) {
|
|
26361
26435
|
return "";
|
|
@@ -26563,7 +26637,7 @@ var createHistoryHandlers = ({
|
|
|
26563
26637
|
sessions = await sessionStateStore.list();
|
|
26564
26638
|
} catch (error) {
|
|
26565
26639
|
sendError(id2, {
|
|
26566
|
-
code:
|
|
26640
|
+
code: import_protocol23.RPC_ERROR_CODE.SESSION_LIST_FAILED,
|
|
26567
26641
|
message: `session list failed: ${String(error)}`
|
|
26568
26642
|
});
|
|
26569
26643
|
return;
|
|
@@ -26580,7 +26654,7 @@ var createHistoryHandlers = ({
|
|
|
26580
26654
|
sessions: filtered,
|
|
26581
26655
|
current_workspace_root: requestedWorkspaceRoot
|
|
26582
26656
|
};
|
|
26583
|
-
|
|
26657
|
+
sendRequestResult("session.list", id2, result);
|
|
26584
26658
|
};
|
|
26585
26659
|
const collectRuns = async (sessionId, maxRuns) => {
|
|
26586
26660
|
if (runIndex) {
|
|
@@ -26596,7 +26670,7 @@ var createHistoryHandlers = ({
|
|
|
26596
26670
|
const sessionId = params?.session_id?.trim();
|
|
26597
26671
|
if (!sessionId) {
|
|
26598
26672
|
sendError(id2, {
|
|
26599
|
-
code:
|
|
26673
|
+
code: import_protocol23.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
26600
26674
|
message: "session_id is required"
|
|
26601
26675
|
});
|
|
26602
26676
|
return;
|
|
@@ -26608,7 +26682,7 @@ var createHistoryHandlers = ({
|
|
|
26608
26682
|
runs: 0,
|
|
26609
26683
|
events_sent: 0
|
|
26610
26684
|
};
|
|
26611
|
-
|
|
26685
|
+
sendRequestResult("session.history", id2, result2);
|
|
26612
26686
|
return;
|
|
26613
26687
|
}
|
|
26614
26688
|
const runs = readRunLogs ? await collectRuns(sessionId, maxRuns) : [];
|
|
@@ -26650,7 +26724,11 @@ var createHistoryHandlers = ({
|
|
|
26650
26724
|
const truncated = replayEvents.length > maxEvents;
|
|
26651
26725
|
const selectedEvents = truncated ? replayEvents.slice(replayEvents.length - maxEvents) : replayEvents;
|
|
26652
26726
|
for (const event of selectedEvents) {
|
|
26653
|
-
await emitHistoryEvent(
|
|
26727
|
+
await emitHistoryEvent(
|
|
26728
|
+
event.runId,
|
|
26729
|
+
event.seq,
|
|
26730
|
+
projectHistoryEvent(event.event)
|
|
26731
|
+
);
|
|
26654
26732
|
}
|
|
26655
26733
|
let resumeDiff;
|
|
26656
26734
|
if (buildResumeDiffSummary) {
|
|
@@ -26669,25 +26747,14 @@ var createHistoryHandlers = ({
|
|
|
26669
26747
|
...truncated ? { truncated: true } : {},
|
|
26670
26748
|
...resumeDiff ? { resume_diff: resumeDiff } : {}
|
|
26671
26749
|
};
|
|
26672
|
-
|
|
26750
|
+
sendRequestResult("session.history", id2, result);
|
|
26673
26751
|
};
|
|
26674
26752
|
return { handleSessionList, handleSessionHistory };
|
|
26675
26753
|
};
|
|
26676
26754
|
|
|
26677
26755
|
// src/rpc/image.ts
|
|
26678
26756
|
var import_config20 = require("@codelia/config");
|
|
26679
|
-
var
|
|
26680
|
-
var import_zod47 = require("zod");
|
|
26681
|
-
var paramsSchema2 = import_zod47.z.object({
|
|
26682
|
-
mode: import_zod47.z.enum(["off", "builtin", "custom"]).optional(),
|
|
26683
|
-
provider: import_zod47.z.enum(["openai", "openrouter", "google"]).optional(),
|
|
26684
|
-
model: import_zod47.z.string().max(160).optional(),
|
|
26685
|
-
endpoint: import_zod47.z.string().max(160).optional(),
|
|
26686
|
-
api_key_env: import_zod47.z.string().max(128).optional(),
|
|
26687
|
-
image_size: import_zod47.z.enum(["1K", "2K", "4K"]).optional(),
|
|
26688
|
-
aspect_ratio: import_zod47.z.string().max(8).optional(),
|
|
26689
|
-
output_format: import_zod47.z.enum(["jpeg"]).optional()
|
|
26690
|
-
}).strict();
|
|
26757
|
+
var import_protocol25 = require("@codelia/protocol");
|
|
26691
26758
|
function createImageHandlers(state) {
|
|
26692
26759
|
const catalog = new ImageCatalog();
|
|
26693
26760
|
let configuring = false;
|
|
@@ -26874,23 +26941,29 @@ function createImageHandlers(state) {
|
|
|
26874
26941
|
try {
|
|
26875
26942
|
const root = workspace();
|
|
26876
26943
|
if (operation === "artifact") {
|
|
26877
|
-
const
|
|
26878
|
-
|
|
26879
|
-
}
|
|
26880
|
-
if (
|
|
26944
|
+
const parsed = parseRequestParams("image.artifact.get", params);
|
|
26945
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
26946
|
+
const { artifact_id: artifactId } = parsed.params;
|
|
26947
|
+
if (!/^codelia-image-[0-9a-f-]{36}$/.test(artifactId))
|
|
26881
26948
|
throw new ImageGenerationError("Invalid image artifact request.");
|
|
26882
26949
|
const { metadata, bytes } = await createLocalImageStore(
|
|
26883
26950
|
root,
|
|
26884
26951
|
() => state.sessionId
|
|
26885
|
-
).read(
|
|
26886
|
-
|
|
26952
|
+
).read(artifactId);
|
|
26953
|
+
sendRequestResult("image.artifact.get", id2, {
|
|
26887
26954
|
metadata,
|
|
26888
26955
|
data_url: `data:${metadata.media_type};base64,${bytes.toString("base64")}`
|
|
26889
26956
|
});
|
|
26890
26957
|
return;
|
|
26891
26958
|
}
|
|
26892
26959
|
if (operation === "get") {
|
|
26893
|
-
|
|
26960
|
+
const parsed = parseRequestParams("image.model.get", params);
|
|
26961
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
26962
|
+
sendRequestResult(
|
|
26963
|
+
"image.model.get",
|
|
26964
|
+
id2,
|
|
26965
|
+
await status2(await resolveImageGenerationConfig(root))
|
|
26966
|
+
);
|
|
26894
26967
|
return;
|
|
26895
26968
|
}
|
|
26896
26969
|
if (state.activeRunId || configuring)
|
|
@@ -26899,10 +26972,14 @@ function createImageHandlers(state) {
|
|
|
26899
26972
|
);
|
|
26900
26973
|
configuring = true;
|
|
26901
26974
|
ownsConfiguration = true;
|
|
26902
|
-
const
|
|
26903
|
-
if (!
|
|
26975
|
+
const catalogParams = parseRequestParams("image.model.configure", params);
|
|
26976
|
+
if (!catalogParams.ok) {
|
|
26977
|
+
sendError(id2, catalogParams.error);
|
|
26978
|
+
return;
|
|
26979
|
+
}
|
|
26980
|
+
const p = catalogParams.params;
|
|
26981
|
+
if ((p.model?.length ?? 0) > 160 || (p.endpoint?.length ?? 0) > 160 || (p.api_key_env?.length ?? 0) > 128 || (p.aspect_ratio?.length ?? 0) > 8)
|
|
26904
26982
|
throw new ImageGenerationError("Invalid image model settings.");
|
|
26905
|
-
const p = parsed.data;
|
|
26906
26983
|
if (p.provider === "google" && p.endpoint || p.provider !== "google" && (p.image_size || p.aspect_ratio || p.output_format))
|
|
26907
26984
|
throw new ImageGenerationError(
|
|
26908
26985
|
"Image settings do not match the selected provider."
|
|
@@ -26945,7 +27022,9 @@ function createImageHandlers(state) {
|
|
|
26945
27022
|
config = await choose();
|
|
26946
27023
|
}
|
|
26947
27024
|
if (!config) {
|
|
26948
|
-
|
|
27025
|
+
sendRequestResult("image.model.configure", id2, {
|
|
27026
|
+
message: "Image settings unchanged."
|
|
27027
|
+
});
|
|
26949
27028
|
return;
|
|
26950
27029
|
}
|
|
26951
27030
|
const next = await status2(config);
|
|
@@ -26962,7 +27041,9 @@ This saves image settings only; generation requests use the tool permission poli
|
|
|
26962
27041
|
cancel_label: "Cancel"
|
|
26963
27042
|
});
|
|
26964
27043
|
if (!confirm?.ok) {
|
|
26965
|
-
|
|
27044
|
+
sendRequestResult("image.model.configure", id2, {
|
|
27045
|
+
message: "Image settings unchanged."
|
|
27046
|
+
});
|
|
26966
27047
|
return;
|
|
26967
27048
|
}
|
|
26968
27049
|
}
|
|
@@ -26975,14 +27056,14 @@ This saves image settings only; generation requests use the tool permission poli
|
|
|
26975
27056
|
state.tools = null;
|
|
26976
27057
|
state.toolDefinitions = null;
|
|
26977
27058
|
const scope = target2.scope === "project" ? "project" : "user";
|
|
26978
|
-
|
|
27059
|
+
sendRequestResult("image.model.configure", id2, {
|
|
26979
27060
|
...next,
|
|
26980
27061
|
message: `${next.message}
|
|
26981
27062
|
Saved to ${scope} settings.`
|
|
26982
27063
|
});
|
|
26983
27064
|
} catch (error) {
|
|
26984
27065
|
sendError(id2, {
|
|
26985
|
-
code:
|
|
27066
|
+
code: import_protocol25.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
26986
27067
|
message: error instanceof ImageGenerationError ? error.message : "Image operation failed; check settings, artifact and runtime storage. No credentials were changed."
|
|
26987
27068
|
});
|
|
26988
27069
|
} finally {
|
|
@@ -26995,7 +27076,7 @@ Saved to ${scope} settings.`
|
|
|
26995
27076
|
// src/rpc/model.ts
|
|
26996
27077
|
var import_core38 = require("@codelia/core");
|
|
26997
27078
|
var import_model_metadata3 = require("@codelia/model-metadata");
|
|
26998
|
-
var
|
|
27079
|
+
var import_protocol27 = require("@codelia/protocol");
|
|
26999
27080
|
var import_shared_types9 = require("@codelia/shared-types");
|
|
27000
27081
|
var isSupportedProvider = (provider, providers) => SUPPORTED_PROVIDERS.includes(provider) || Boolean(providers && Object.hasOwn(providers, provider));
|
|
27001
27082
|
var resolveProviderModelEntry2 = (providerEntries, provider, model) => {
|
|
@@ -27357,7 +27438,10 @@ var createModelHandlers = ({
|
|
|
27357
27438
|
meta: nextMeta
|
|
27358
27439
|
});
|
|
27359
27440
|
};
|
|
27360
|
-
const handleModelList = async (id2,
|
|
27441
|
+
const handleModelList = async (id2, raw) => {
|
|
27442
|
+
const parsed = parseRequestParams("model.list", raw);
|
|
27443
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27444
|
+
const params = parsed.params;
|
|
27361
27445
|
const requestedProvider = params?.provider;
|
|
27362
27446
|
const includeDetails = params?.include_details ?? false;
|
|
27363
27447
|
let providers;
|
|
@@ -27385,7 +27469,7 @@ var createModelHandlers = ({
|
|
|
27385
27469
|
}
|
|
27386
27470
|
} catch (error) {
|
|
27387
27471
|
sendError(id2, {
|
|
27388
|
-
code:
|
|
27472
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27389
27473
|
message: String(error)
|
|
27390
27474
|
});
|
|
27391
27475
|
return;
|
|
@@ -27393,7 +27477,7 @@ var createModelHandlers = ({
|
|
|
27393
27477
|
const provider = requestedProvider ?? configuredProvider ?? "openai";
|
|
27394
27478
|
if (!isSupportedProvider(provider, providers)) {
|
|
27395
27479
|
sendError(id2, {
|
|
27396
|
-
code:
|
|
27480
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27397
27481
|
message: `unsupported provider: ${provider}`
|
|
27398
27482
|
});
|
|
27399
27483
|
return;
|
|
@@ -27412,7 +27496,7 @@ var createModelHandlers = ({
|
|
|
27412
27496
|
details = result2.details;
|
|
27413
27497
|
} catch (error) {
|
|
27414
27498
|
sendError(id2, {
|
|
27415
|
-
code:
|
|
27499
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27416
27500
|
message: String(error)
|
|
27417
27501
|
});
|
|
27418
27502
|
return;
|
|
@@ -27438,20 +27522,29 @@ var createModelHandlers = ({
|
|
|
27438
27522
|
...configuredFast !== void 0 ? { fast: configuredFast } : {},
|
|
27439
27523
|
...details ? { details } : {}
|
|
27440
27524
|
};
|
|
27441
|
-
|
|
27525
|
+
sendRequestResult("model.list", id2, result);
|
|
27442
27526
|
};
|
|
27443
|
-
const handleModelSet = async (id2,
|
|
27527
|
+
const handleModelSet = async (id2, raw) => {
|
|
27444
27528
|
if (state.activeRunId) {
|
|
27445
27529
|
sendError(id2, {
|
|
27446
|
-
code:
|
|
27530
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27447
27531
|
message: "runtime busy"
|
|
27448
27532
|
});
|
|
27449
27533
|
return;
|
|
27450
27534
|
}
|
|
27535
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw) && "reasoning" in raw && typeof raw.reasoning === "string") {
|
|
27536
|
+
raw = {
|
|
27537
|
+
...raw,
|
|
27538
|
+
reasoning: raw.reasoning ? normalizeModelLevel(raw.reasoning) : void 0
|
|
27539
|
+
};
|
|
27540
|
+
}
|
|
27541
|
+
const parsed = parseRequestParams("model.set", raw);
|
|
27542
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27543
|
+
const params = parsed.params;
|
|
27451
27544
|
const scope = params?.scope ?? "config";
|
|
27452
27545
|
if (scope !== "config" && scope !== "session") {
|
|
27453
27546
|
sendError(id2, {
|
|
27454
|
-
code:
|
|
27547
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27455
27548
|
message: `unsupported model scope: ${scope}`
|
|
27456
27549
|
});
|
|
27457
27550
|
return;
|
|
@@ -27460,7 +27553,7 @@ var createModelHandlers = ({
|
|
|
27460
27553
|
if (params?.reset) {
|
|
27461
27554
|
if (scope !== "session") {
|
|
27462
27555
|
sendError(id2, {
|
|
27463
|
-
code:
|
|
27556
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27464
27557
|
message: "model reset is only supported for session scope"
|
|
27465
27558
|
});
|
|
27466
27559
|
return;
|
|
@@ -27471,7 +27564,7 @@ var createModelHandlers = ({
|
|
|
27471
27564
|
const name3 = config.name;
|
|
27472
27565
|
if (!name3) {
|
|
27473
27566
|
sendError(id2, {
|
|
27474
|
-
code:
|
|
27567
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27475
27568
|
message: "configured model name is missing"
|
|
27476
27569
|
});
|
|
27477
27570
|
return;
|
|
@@ -27487,7 +27580,7 @@ var createModelHandlers = ({
|
|
|
27487
27580
|
);
|
|
27488
27581
|
} catch (error) {
|
|
27489
27582
|
sendError(id2, {
|
|
27490
|
-
code:
|
|
27583
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27491
27584
|
message: String(error)
|
|
27492
27585
|
});
|
|
27493
27586
|
return;
|
|
@@ -27505,11 +27598,11 @@ var createModelHandlers = ({
|
|
|
27505
27598
|
...effectiveReasoning ? { reasoning: effectiveReasoning } : {},
|
|
27506
27599
|
...config.fast !== void 0 ? { fast: effectiveFast } : {}
|
|
27507
27600
|
};
|
|
27508
|
-
|
|
27601
|
+
sendRequestResult("model.set", id2, result);
|
|
27509
27602
|
log2(`model.set reset session override -> ${provider2}/${name3}`);
|
|
27510
27603
|
} catch (error) {
|
|
27511
27604
|
sendError(id2, {
|
|
27512
|
-
code:
|
|
27605
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27513
27606
|
message: String(error)
|
|
27514
27607
|
});
|
|
27515
27608
|
}
|
|
@@ -27519,7 +27612,7 @@ var createModelHandlers = ({
|
|
|
27519
27612
|
let name2 = params?.name?.trim();
|
|
27520
27613
|
if (!name2) {
|
|
27521
27614
|
sendError(id2, {
|
|
27522
|
-
code:
|
|
27615
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27523
27616
|
message: "model name is required"
|
|
27524
27617
|
});
|
|
27525
27618
|
return;
|
|
@@ -27530,7 +27623,7 @@ var createModelHandlers = ({
|
|
|
27530
27623
|
reasoning = resolveReasoningEffort(params.reasoning);
|
|
27531
27624
|
} catch (error) {
|
|
27532
27625
|
sendError(id2, {
|
|
27533
|
-
code:
|
|
27626
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27534
27627
|
message: String(error)
|
|
27535
27628
|
});
|
|
27536
27629
|
return;
|
|
@@ -27540,7 +27633,7 @@ var createModelHandlers = ({
|
|
|
27540
27633
|
const endpoint = getResponsesProvider(configured, provider);
|
|
27541
27634
|
if (!isSupportedProvider(provider, configured.providers)) {
|
|
27542
27635
|
sendError(id2, {
|
|
27543
|
-
code:
|
|
27636
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27544
27637
|
message: `unsupported provider: ${provider}`
|
|
27545
27638
|
});
|
|
27546
27639
|
return;
|
|
@@ -27553,7 +27646,7 @@ var createModelHandlers = ({
|
|
|
27553
27646
|
);
|
|
27554
27647
|
if (!spec) {
|
|
27555
27648
|
sendError(id2, {
|
|
27556
|
-
code:
|
|
27649
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27557
27650
|
message: `unknown model: ${name2}`
|
|
27558
27651
|
});
|
|
27559
27652
|
return;
|
|
@@ -27586,7 +27679,7 @@ var createModelHandlers = ({
|
|
|
27586
27679
|
await validateFastSelection(provider, name2, candidate.fast);
|
|
27587
27680
|
} catch (error) {
|
|
27588
27681
|
sendError(id2, {
|
|
27589
|
-
code:
|
|
27682
|
+
code: import_protocol27.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27590
27683
|
message: String(error)
|
|
27591
27684
|
});
|
|
27592
27685
|
return;
|
|
@@ -27634,14 +27727,14 @@ var createModelHandlers = ({
|
|
|
27634
27727
|
...effectiveReasoning ? { reasoning: effectiveReasoning } : {},
|
|
27635
27728
|
...updatedConfig.fast !== void 0 ? { fast: effectiveFast } : {}
|
|
27636
27729
|
};
|
|
27637
|
-
|
|
27730
|
+
sendRequestResult("model.set", id2, result);
|
|
27638
27731
|
const persistence = scope === "config" && target2 ? ` scope=${target2.scope} path=${target2.path}` : " scope=session";
|
|
27639
27732
|
log2(
|
|
27640
27733
|
`model.set ${provider}/${name2}${effectiveReasoning ? ` reasoning=${effectiveReasoning}` : ""}${persistence}`
|
|
27641
27734
|
);
|
|
27642
27735
|
} catch (error) {
|
|
27643
27736
|
sendError(id2, {
|
|
27644
|
-
code:
|
|
27737
|
+
code: import_protocol27.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27645
27738
|
message: String(error)
|
|
27646
27739
|
});
|
|
27647
27740
|
}
|
|
@@ -27652,7 +27745,7 @@ var createModelHandlers = ({
|
|
|
27652
27745
|
// src/rpc/permissions.ts
|
|
27653
27746
|
var import_node_fs43 = require("fs");
|
|
27654
27747
|
var import_config_loader3 = require("@codelia/config-loader");
|
|
27655
|
-
var
|
|
27748
|
+
var import_protocol29 = require("@codelia/protocol");
|
|
27656
27749
|
var import_storage30 = require("@codelia/storage");
|
|
27657
27750
|
var MAX_RULE_FIELD_LENGTH = 4096;
|
|
27658
27751
|
var RULE_FIELDS = ["tool", "command", "command_glob", "skill_name"];
|
|
@@ -27662,23 +27755,10 @@ var toSpec = (rule) => ({
|
|
|
27662
27755
|
...rule.command_glob !== void 0 ? { command_glob: rule.command_glob } : {},
|
|
27663
27756
|
...rule.skill_name !== void 0 ? { skill_name: rule.skill_name } : {}
|
|
27664
27757
|
});
|
|
27665
|
-
var
|
|
27666
|
-
|
|
27667
|
-
|
|
27668
|
-
|
|
27669
|
-
const record = value;
|
|
27670
|
-
if (Object.keys(record).some((key) => !RULE_FIELDS.includes(key))) {
|
|
27671
|
-
return null;
|
|
27672
|
-
}
|
|
27673
|
-
for (const field of RULE_FIELDS) {
|
|
27674
|
-
const entry = record[field];
|
|
27675
|
-
if (entry === void 0 && field !== "tool") continue;
|
|
27676
|
-
if (typeof entry !== "string" || !entry.trim() || entry.length > MAX_RULE_FIELD_LENGTH) {
|
|
27677
|
-
return null;
|
|
27678
|
-
}
|
|
27679
|
-
}
|
|
27680
|
-
return toSpec(record);
|
|
27681
|
-
};
|
|
27758
|
+
var isValidRemovalRule = (rule) => RULE_FIELDS.every((field) => {
|
|
27759
|
+
const value = rule[field];
|
|
27760
|
+
return value === void 0 || value.trim().length > 0 && value.length <= MAX_RULE_FIELD_LENGTH;
|
|
27761
|
+
});
|
|
27682
27762
|
var fileRules = (config, scope) => [
|
|
27683
27763
|
...(config?.permissions?.allow ?? []).map((rule) => ({
|
|
27684
27764
|
kind: "allow",
|
|
@@ -27702,16 +27782,19 @@ var createPermissionsHandlers = ({
|
|
|
27702
27782
|
const rejectUnsupported = (id2) => {
|
|
27703
27783
|
if (supportsConfigReadWrite(state)) return false;
|
|
27704
27784
|
sendError(id2, {
|
|
27705
|
-
code:
|
|
27785
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27706
27786
|
message: "permission rules are not available for this runtime"
|
|
27707
27787
|
});
|
|
27708
27788
|
return true;
|
|
27709
27789
|
};
|
|
27710
|
-
const handlePermissionsList = async (id2,
|
|
27790
|
+
const handlePermissionsList = async (id2, raw) => {
|
|
27711
27791
|
if (rejectUnsupported(id2)) return;
|
|
27792
|
+
const parsed = parseRequestParams("permissions.list", raw);
|
|
27793
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27794
|
+
const params = parsed.params;
|
|
27712
27795
|
if (params?.include_system !== void 0 && typeof params.include_system !== "boolean") {
|
|
27713
27796
|
sendError(id2, {
|
|
27714
|
-
code:
|
|
27797
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27715
27798
|
message: "include_system must be a boolean"
|
|
27716
27799
|
});
|
|
27717
27800
|
return;
|
|
@@ -27807,108 +27890,113 @@ var createPermissionsHandlers = ({
|
|
|
27807
27890
|
rules,
|
|
27808
27891
|
...errors.length ? { errors } : {}
|
|
27809
27892
|
};
|
|
27810
|
-
|
|
27893
|
+
sendRequestResult("permissions.list", id2, result);
|
|
27811
27894
|
};
|
|
27812
|
-
const
|
|
27813
|
-
|
|
27814
|
-
if (params
|
|
27815
|
-
|
|
27816
|
-
|
|
27817
|
-
|
|
27818
|
-
|
|
27819
|
-
message: "Invalid remembered tool"
|
|
27820
|
-
});
|
|
27821
|
-
return;
|
|
27822
|
-
}
|
|
27823
|
-
try {
|
|
27824
|
-
const workspace = (0, import_node_fs43.realpathSync)(root);
|
|
27825
|
-
const removed2 = await state.withAdmissionLock(async () => {
|
|
27826
|
-
if (state.activeRunId) return "busy";
|
|
27827
|
-
return new import_storage30.ProjectsPolicyStore().updateRememberedTool(
|
|
27828
|
-
workspace,
|
|
27829
|
-
params.remembered_tool,
|
|
27830
|
-
false,
|
|
27831
|
-
() => {
|
|
27832
|
-
if (resolveConfigWorkspaceDir(state) !== root || (0, import_node_fs43.realpathSync)(root) !== workspace)
|
|
27833
|
-
throw new Error("workspace_changed");
|
|
27834
|
-
}
|
|
27835
|
-
);
|
|
27836
|
-
});
|
|
27837
|
-
if (removed2 === "busy") {
|
|
27838
|
-
sendError(id2, {
|
|
27839
|
-
code: import_protocol14.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27840
|
-
message: "runtime busy"
|
|
27841
|
-
});
|
|
27842
|
-
return;
|
|
27843
|
-
}
|
|
27844
|
-
if (removed2) state.reviseApprovalAuthority();
|
|
27845
|
-
sendResult(id2, {
|
|
27846
|
-
...params,
|
|
27847
|
-
removed: Number(removed2)
|
|
27848
|
-
});
|
|
27849
|
-
} catch {
|
|
27850
|
-
sendError(id2, {
|
|
27851
|
-
code: import_protocol14.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27852
|
-
message: "Remembered tool removal failed"
|
|
27853
|
-
});
|
|
27854
|
-
}
|
|
27895
|
+
const removeRememberedTool = async (id2, params) => {
|
|
27896
|
+
const root = resolveConfigWorkspaceDir(state);
|
|
27897
|
+
if (!root || !localProjectAllows(state) || params.scope !== "project" || !configurableToolInvocations.has(params.remembered_tool)) {
|
|
27898
|
+
sendError(id2, {
|
|
27899
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27900
|
+
message: "Invalid remembered tool"
|
|
27901
|
+
});
|
|
27855
27902
|
return;
|
|
27856
27903
|
}
|
|
27857
|
-
|
|
27858
|
-
const
|
|
27859
|
-
|
|
27904
|
+
try {
|
|
27905
|
+
const workspace = (0, import_node_fs43.realpathSync)(root);
|
|
27906
|
+
const removed = await state.withAdmissionLock(async () => {
|
|
27907
|
+
if (state.activeRunId) return "busy";
|
|
27908
|
+
return new import_storage30.ProjectsPolicyStore().updateRememberedTool(
|
|
27909
|
+
workspace,
|
|
27910
|
+
params.remembered_tool,
|
|
27911
|
+
false,
|
|
27912
|
+
() => {
|
|
27913
|
+
if (resolveConfigWorkspaceDir(state) !== root || (0, import_node_fs43.realpathSync)(root) !== workspace)
|
|
27914
|
+
throw new Error("workspace_changed");
|
|
27915
|
+
}
|
|
27916
|
+
);
|
|
27917
|
+
});
|
|
27918
|
+
if (removed === "busy") {
|
|
27860
27919
|
sendError(id2, {
|
|
27861
|
-
code:
|
|
27862
|
-
message: "
|
|
27920
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27921
|
+
message: "runtime busy"
|
|
27863
27922
|
});
|
|
27864
27923
|
return;
|
|
27865
27924
|
}
|
|
27866
|
-
|
|
27867
|
-
|
|
27868
|
-
|
|
27869
|
-
|
|
27870
|
-
|
|
27925
|
+
if (removed) state.reviseApprovalAuthority();
|
|
27926
|
+
sendRequestResult("permissions.remove", id2, {
|
|
27927
|
+
...params,
|
|
27928
|
+
removed: Number(removed)
|
|
27929
|
+
});
|
|
27930
|
+
} catch {
|
|
27931
|
+
sendError(id2, {
|
|
27932
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27933
|
+
message: "Remembered tool removal failed"
|
|
27934
|
+
});
|
|
27935
|
+
}
|
|
27936
|
+
};
|
|
27937
|
+
const removeWorkspaceGrant = (id2, params) => {
|
|
27938
|
+
const workspaceDir = resolveConfigWorkspaceDir(state);
|
|
27939
|
+
if (!workspaceDir || params.resource !== "workspace_write" || params.scope !== "session") {
|
|
27940
|
+
sendError(id2, {
|
|
27941
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27942
|
+
message: "Invalid workspace grant reference"
|
|
27871
27943
|
});
|
|
27872
27944
|
return;
|
|
27873
27945
|
}
|
|
27874
|
-
|
|
27875
|
-
|
|
27876
|
-
|
|
27877
|
-
|
|
27878
|
-
|
|
27879
|
-
|
|
27880
|
-
|
|
27881
|
-
|
|
27882
|
-
|
|
27883
|
-
|
|
27884
|
-
|
|
27885
|
-
|
|
27886
|
-
|
|
27887
|
-
|
|
27888
|
-
params.scope
|
|
27889
|
-
);
|
|
27890
|
-
if (removed2) state.reviseApprovalAuthority();
|
|
27891
|
-
const result2 = {
|
|
27892
|
-
...params,
|
|
27893
|
-
removed: removed2 ? 1 : 0
|
|
27894
|
-
};
|
|
27895
|
-
sendResult(id2, result2);
|
|
27896
|
-
} catch {
|
|
27897
|
-
sendError(id2, {
|
|
27898
|
-
code: import_protocol14.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27899
|
-
message: "Launch rule removal failed"
|
|
27900
|
-
});
|
|
27901
|
-
}
|
|
27946
|
+
const removed = removeWorkspaceWriteGrant(state, workspaceDir);
|
|
27947
|
+
sendRequestResult("permissions.remove", id2, {
|
|
27948
|
+
resource: params.resource,
|
|
27949
|
+
scope: "session",
|
|
27950
|
+
removed: removed ? 1 : 0
|
|
27951
|
+
});
|
|
27952
|
+
};
|
|
27953
|
+
const removeLaunchRule = (id2, params) => {
|
|
27954
|
+
const workspaceDir = resolveConfigWorkspaceDir(state);
|
|
27955
|
+
if (!workspaceDir || !/^[a-f0-9]{64}$/u.test(params.launch_rule_id) || params.scope !== "session" && params.scope !== "project" || state.effectiveEnvironment.sourcePreset !== "tui-local") {
|
|
27956
|
+
sendError(id2, {
|
|
27957
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27958
|
+
message: "Invalid launch rule reference"
|
|
27959
|
+
});
|
|
27902
27960
|
return;
|
|
27903
27961
|
}
|
|
27962
|
+
try {
|
|
27963
|
+
const removed = runtimeLaunchRules(state).remove(
|
|
27964
|
+
(0, import_node_fs43.realpathSync)(workspaceDir),
|
|
27965
|
+
state.sessionId ?? "operator",
|
|
27966
|
+
params.launch_rule_id,
|
|
27967
|
+
params.scope
|
|
27968
|
+
);
|
|
27969
|
+
if (removed) state.reviseApprovalAuthority();
|
|
27970
|
+
const result = {
|
|
27971
|
+
...params,
|
|
27972
|
+
removed: removed ? 1 : 0
|
|
27973
|
+
};
|
|
27974
|
+
sendRequestResult("permissions.remove", id2, result);
|
|
27975
|
+
} catch {
|
|
27976
|
+
sendError(id2, {
|
|
27977
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27978
|
+
message: "Launch rule removal failed"
|
|
27979
|
+
});
|
|
27980
|
+
}
|
|
27981
|
+
};
|
|
27982
|
+
const handlePermissionsRemove = async (id2, raw) => {
|
|
27983
|
+
if (rejectUnsupported(id2)) return;
|
|
27984
|
+
const parsed = parseRequestParams("permissions.remove", raw);
|
|
27985
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
27986
|
+
const params = parsed.params;
|
|
27987
|
+
if (params && "remembered_tool" in params)
|
|
27988
|
+
return removeRememberedTool(id2, params);
|
|
27989
|
+
if (params && "resource" in params) return removeWorkspaceGrant(id2, params);
|
|
27990
|
+
if (params && "launch_rule_id" in params)
|
|
27991
|
+
return removeLaunchRule(id2, params);
|
|
27904
27992
|
if (state.activeRunId) {
|
|
27905
27993
|
sendError(id2, {
|
|
27906
|
-
code:
|
|
27994
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27907
27995
|
message: "runtime busy"
|
|
27908
27996
|
});
|
|
27909
27997
|
return;
|
|
27910
27998
|
}
|
|
27911
|
-
const invalid = (message) => sendError(id2, { code:
|
|
27999
|
+
const invalid = (message) => sendError(id2, { code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS, message });
|
|
27912
28000
|
const scope = params?.scope;
|
|
27913
28001
|
const kind = params?.kind;
|
|
27914
28002
|
if (scope !== "global" && scope !== "project") {
|
|
@@ -27919,8 +28007,8 @@ var createPermissionsHandlers = ({
|
|
|
27919
28007
|
invalid("kind must be allow or deny");
|
|
27920
28008
|
return;
|
|
27921
28009
|
}
|
|
27922
|
-
const rule =
|
|
27923
|
-
if (!rule) {
|
|
28010
|
+
const rule = params.rule;
|
|
28011
|
+
if (!isValidRemovalRule(rule)) {
|
|
27924
28012
|
invalid("rule must have a tool and only string rule fields");
|
|
27925
28013
|
return;
|
|
27926
28014
|
}
|
|
@@ -27944,33 +28032,36 @@ var createPermissionsHandlers = ({
|
|
|
27944
28032
|
});
|
|
27945
28033
|
} catch {
|
|
27946
28034
|
sendError(id2, {
|
|
27947
|
-
code:
|
|
28035
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
27948
28036
|
message: `${scope} config write failed`
|
|
27949
28037
|
});
|
|
27950
28038
|
return;
|
|
27951
28039
|
}
|
|
27952
28040
|
if (removed === "busy") {
|
|
27953
28041
|
sendError(id2, {
|
|
27954
|
-
code:
|
|
28042
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27955
28043
|
message: "runtime busy"
|
|
27956
28044
|
});
|
|
27957
28045
|
return;
|
|
27958
28046
|
}
|
|
27959
28047
|
const result = { scope, kind, path: path51, removed };
|
|
27960
|
-
|
|
28048
|
+
sendRequestResult("permissions.remove", id2, result);
|
|
27961
28049
|
log2(`permissions.remove scope=${scope} kind=${kind} removed=${removed}`);
|
|
27962
28050
|
};
|
|
27963
|
-
const handleProjectAllowTrustSet = async (id2,
|
|
28051
|
+
const handleProjectAllowTrustSet = async (id2, raw) => {
|
|
27964
28052
|
if (!supportsProjectAllowTrust(state)) {
|
|
27965
28053
|
sendError(id2, {
|
|
27966
|
-
code:
|
|
28054
|
+
code: import_protocol29.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
27967
28055
|
message: "Project allow trust changes are unavailable for this runtime."
|
|
27968
28056
|
});
|
|
27969
28057
|
return;
|
|
27970
28058
|
}
|
|
28059
|
+
const parsed = parseRequestParams("permissions.projectTrust.set", raw);
|
|
28060
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
28061
|
+
const params = parsed.params;
|
|
27971
28062
|
if (typeof params?.workspace !== "string" || typeof params.trusted !== "boolean" || typeof params.expected_revision !== "string" || !params.expected_revision) {
|
|
27972
28063
|
sendError(id2, {
|
|
27973
|
-
code:
|
|
28064
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27974
28065
|
message: "Expected a reviewed project allow list for this local workspace"
|
|
27975
28066
|
});
|
|
27976
28067
|
return;
|
|
@@ -27979,7 +28070,7 @@ var createPermissionsHandlers = ({
|
|
|
27979
28070
|
await state.withAdmissionLock(async () => {
|
|
27980
28071
|
if (state.activeRunId) {
|
|
27981
28072
|
sendError(id2, {
|
|
27982
|
-
code:
|
|
28073
|
+
code: import_protocol29.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
27983
28074
|
message: "runtime busy"
|
|
27984
28075
|
});
|
|
27985
28076
|
return;
|
|
@@ -27987,7 +28078,7 @@ var createPermissionsHandlers = ({
|
|
|
27987
28078
|
const root = resolveConfigWorkspaceDir(state);
|
|
27988
28079
|
if (!root || (0, import_node_fs43.realpathSync)(root) !== params.workspace) {
|
|
27989
28080
|
sendError(id2, {
|
|
27990
|
-
code:
|
|
28081
|
+
code: import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
27991
28082
|
message: "Workspace changed. Review the current project allow list again."
|
|
27992
28083
|
});
|
|
27993
28084
|
return;
|
|
@@ -27999,7 +28090,7 @@ var createPermissionsHandlers = ({
|
|
|
27999
28090
|
params.expected_revision
|
|
28000
28091
|
);
|
|
28001
28092
|
state.invalidateAgentCache();
|
|
28002
|
-
|
|
28093
|
+
sendRequestResult("permissions.projectTrust.set", id2, {
|
|
28003
28094
|
workspace: params.workspace,
|
|
28004
28095
|
trusted: params.trusted
|
|
28005
28096
|
});
|
|
@@ -28007,7 +28098,7 @@ var createPermissionsHandlers = ({
|
|
|
28007
28098
|
} catch (error) {
|
|
28008
28099
|
const changed = error instanceof Error && error.message === "project_allow_trust_changed";
|
|
28009
28100
|
sendError(id2, {
|
|
28010
|
-
code: changed ?
|
|
28101
|
+
code: changed ? import_protocol29.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol29.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28011
28102
|
message: changed ? "The project allow list or its trust state changed. Review it again." : "Project allow trust is unavailable."
|
|
28012
28103
|
});
|
|
28013
28104
|
}
|
|
@@ -28392,7 +28483,7 @@ var buildResumeDiff = async (meta, state, options = {}) => {
|
|
|
28392
28483
|
};
|
|
28393
28484
|
|
|
28394
28485
|
// src/rpc/run.ts
|
|
28395
|
-
var
|
|
28486
|
+
var import_protocol33 = require("@codelia/protocol");
|
|
28396
28487
|
|
|
28397
28488
|
// src/provider-errors.ts
|
|
28398
28489
|
var import_core39 = require("@codelia/core");
|
|
@@ -28462,23 +28553,23 @@ var normalizeRunFailure = (error) => {
|
|
|
28462
28553
|
|
|
28463
28554
|
// src/rpc/goals.ts
|
|
28464
28555
|
var import_core40 = require("@codelia/core");
|
|
28465
|
-
var
|
|
28556
|
+
var import_protocol31 = require("@codelia/protocol");
|
|
28466
28557
|
var import_storage31 = require("@codelia/storage");
|
|
28467
|
-
var
|
|
28468
|
-
var id =
|
|
28469
|
-
var revision =
|
|
28470
|
-
var target =
|
|
28471
|
-
var budget =
|
|
28558
|
+
var import_zod46 = require("zod");
|
|
28559
|
+
var id = import_zod46.z.string().min(1).max(200);
|
|
28560
|
+
var revision = import_zod46.z.number().int().positive();
|
|
28561
|
+
var target = import_zod46.z.object({ session_id: id, goal_id: id, revision });
|
|
28562
|
+
var budget = import_zod46.z.number().int().positive().nullable();
|
|
28472
28563
|
var schemas = {
|
|
28473
|
-
"goal.get":
|
|
28564
|
+
"goal.get": import_zod46.z.object({
|
|
28474
28565
|
session_id: id.optional(),
|
|
28475
28566
|
continuation_id: id.optional()
|
|
28476
28567
|
}),
|
|
28477
28568
|
"goal.set": target.partial().extend({
|
|
28478
|
-
objective:
|
|
28569
|
+
objective: import_zod46.z.string().trim().min(1).max(8e3).optional(),
|
|
28479
28570
|
token_budget: budget.optional()
|
|
28480
28571
|
}),
|
|
28481
|
-
"goal.pause":
|
|
28572
|
+
"goal.pause": import_zod46.z.object({
|
|
28482
28573
|
session_id: id,
|
|
28483
28574
|
goal_id: id,
|
|
28484
28575
|
activation_id: id,
|
|
@@ -28571,11 +28662,12 @@ var GoalController = class {
|
|
|
28571
28662
|
}
|
|
28572
28663
|
publish(goal) {
|
|
28573
28664
|
if (this.enabled && this.state.sessionId === goal.session_id)
|
|
28574
|
-
send(
|
|
28575
|
-
|
|
28576
|
-
|
|
28577
|
-
|
|
28578
|
-
|
|
28665
|
+
send(
|
|
28666
|
+
notificationMessage(
|
|
28667
|
+
"goal.updated",
|
|
28668
|
+
this.snapshot(goal.session_id, goal)
|
|
28669
|
+
)
|
|
28670
|
+
);
|
|
28579
28671
|
}
|
|
28580
28672
|
ready(goal, afterRunId) {
|
|
28581
28673
|
if (!this.enabled || this.state.activeRunId || this.state.sessionId !== goal.session_id || goal.status !== "active" || !this.owns(goal) || this.offer)
|
|
@@ -28587,7 +28679,7 @@ var GoalController = class {
|
|
|
28587
28679
|
continuation_id: crypto.randomUUID(),
|
|
28588
28680
|
...afterRunId ? { after_run_id: afterRunId } : {}
|
|
28589
28681
|
};
|
|
28590
|
-
send(
|
|
28682
|
+
send(notificationMessage("goal.ready", this.offer));
|
|
28591
28683
|
}
|
|
28592
28684
|
bound(requested) {
|
|
28593
28685
|
if (requested !== void 0 && requested !== this.state.sessionId)
|
|
@@ -28614,7 +28706,7 @@ var GoalController = class {
|
|
|
28614
28706
|
handle(requestId, method, raw, serialize, interrupt, onError) {
|
|
28615
28707
|
if (!this.enabled) {
|
|
28616
28708
|
sendError(requestId, {
|
|
28617
|
-
code:
|
|
28709
|
+
code: import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
28618
28710
|
message: "Goals are unavailable on this connection."
|
|
28619
28711
|
});
|
|
28620
28712
|
return Promise.resolve();
|
|
@@ -28637,7 +28729,8 @@ var GoalController = class {
|
|
|
28637
28729
|
const params = schemas[method].parse(raw ?? {});
|
|
28638
28730
|
sessionId = this.bound(params.session_id);
|
|
28639
28731
|
const result = sessionId ? await this.store.read(sessionId, params.continuation_id) : null;
|
|
28640
|
-
|
|
28732
|
+
sendRequestResult(
|
|
28733
|
+
method,
|
|
28641
28734
|
requestId,
|
|
28642
28735
|
this.snapshot(
|
|
28643
28736
|
sessionId,
|
|
@@ -28789,15 +28882,14 @@ var GoalController = class {
|
|
|
28789
28882
|
}
|
|
28790
28883
|
}
|
|
28791
28884
|
const snapshot = this.snapshot(sessionId, goal);
|
|
28792
|
-
|
|
28793
|
-
if (cleared)
|
|
28794
|
-
send({ jsonrpc: "2.0", method: "goal.cleared", params: snapshot });
|
|
28885
|
+
sendRequestResult(method, requestId, snapshot);
|
|
28886
|
+
if (cleared) send(notificationMessage("goal.cleared", snapshot));
|
|
28795
28887
|
if (goal) {
|
|
28796
28888
|
this.publish(goal);
|
|
28797
28889
|
if (method === "goal.set" || method === "goal.resume") this.ready(goal);
|
|
28798
28890
|
}
|
|
28799
28891
|
}).catch((error) => {
|
|
28800
|
-
if (!(error instanceof GoalConflict) && !(error instanceof
|
|
28892
|
+
if (!(error instanceof GoalConflict) && !(error instanceof import_zod46.z.ZodError)) {
|
|
28801
28893
|
if (method !== "goal.get") this.disarm();
|
|
28802
28894
|
onError(error);
|
|
28803
28895
|
}
|
|
@@ -28807,8 +28899,8 @@ var GoalController = class {
|
|
|
28807
28899
|
reject(requestId, error) {
|
|
28808
28900
|
const conflict = error instanceof GoalConflict ? error : null;
|
|
28809
28901
|
sendError(requestId, {
|
|
28810
|
-
code: conflict?.reason === "busy" ?
|
|
28811
|
-
message: conflict?.message ?? (error instanceof
|
|
28902
|
+
code: conflict?.reason === "busy" ? import_protocol31.RPC_ERROR_CODE.RUNTIME_BUSY : conflict || error instanceof import_zod46.z.ZodError ? import_protocol31.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol31.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
28903
|
+
message: conflict?.message ?? (error instanceof import_zod46.z.ZodError ? "Invalid goal parameters." : "Goal operation failed.")
|
|
28812
28904
|
});
|
|
28813
28905
|
}
|
|
28814
28906
|
validateOffer(raw) {
|
|
@@ -28898,7 +28990,7 @@ var GoalController = class {
|
|
|
28898
28990
|
(0, import_core40.defineTool)({
|
|
28899
28991
|
name: "get_goal",
|
|
28900
28992
|
description: "Read this run's session goal, including its objective, status, recorded tokens, and budget, or get {goal: null} if the run no longer holds the goal reservation.",
|
|
28901
|
-
input:
|
|
28993
|
+
input: import_zod46.z.object({}),
|
|
28902
28994
|
execute: async () => {
|
|
28903
28995
|
const entry = (await this.store.read(run.goal.session_id)).entry;
|
|
28904
28996
|
const goal = entry?.claim?.run_id === run.runId ? entry.goal : null;
|
|
@@ -28913,14 +29005,14 @@ ${goal.objective}` : "This run no longer holds the goal reservation."
|
|
|
28913
29005
|
(0, import_core40.defineTool)({
|
|
28914
29006
|
name: "update_goal",
|
|
28915
29007
|
description: "Report verified goal completion or a blocker that prevents further work before giving your final answer.",
|
|
28916
|
-
input:
|
|
28917
|
-
status:
|
|
29008
|
+
input: import_zod46.z.object({
|
|
29009
|
+
status: import_zod46.z.enum(["complete", "blocked"]).describe(
|
|
28918
29010
|
"Use complete after verifying every goal requirement, or blocked when a concrete obstacle prevents further work. Omit the tool call for ordinary progress."
|
|
28919
29011
|
),
|
|
28920
|
-
evidence:
|
|
29012
|
+
evidence: import_zod46.z.string().trim().min(1).max(2e3).describe(
|
|
28921
29013
|
"For complete, state what you verified and the observed result. For blocked, state the obstacle and why it prevents further work."
|
|
28922
29014
|
),
|
|
28923
|
-
blocker_key:
|
|
29015
|
+
blocker_key: import_zod46.z.string().trim().min(1).max(200).optional().describe(
|
|
28924
29016
|
"Required for blocked. Reuse the same short key for the same obstacle across runs. Three consecutive goal runs reporting the same key stop the goal."
|
|
28925
29017
|
)
|
|
28926
29018
|
}),
|
|
@@ -29565,6 +29657,47 @@ var createTextDeltaCoalescer = (options) => {
|
|
|
29565
29657
|
var nowIso5 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
29566
29658
|
var SESSION_STATE_SAVE_DEBOUNCE_MS = 1500;
|
|
29567
29659
|
var SESSION_WORKSPACE_ROOT_META_KEY = "codelia_workspace_root";
|
|
29660
|
+
var collectUnconsumedSteers = (steers, releaseAttachments) => {
|
|
29661
|
+
const seenSteerIds = /* @__PURE__ */ new Set();
|
|
29662
|
+
const unconsumedSteerIds = [];
|
|
29663
|
+
const unconsumedClientSteerIds = [];
|
|
29664
|
+
for (const steer of steers) {
|
|
29665
|
+
if (seenSteerIds.has(steer.steer_id)) continue;
|
|
29666
|
+
seenSteerIds.add(steer.steer_id);
|
|
29667
|
+
unconsumedSteerIds.push(steer.steer_id);
|
|
29668
|
+
if (steer.client_steer_id !== void 0)
|
|
29669
|
+
unconsumedClientSteerIds.push(steer.client_steer_id);
|
|
29670
|
+
releaseAttachments(steer.steer_id);
|
|
29671
|
+
}
|
|
29672
|
+
if (unconsumedSteerIds.length === 0) {
|
|
29673
|
+
return void 0;
|
|
29674
|
+
}
|
|
29675
|
+
return {
|
|
29676
|
+
unconsumed_steer_ids: unconsumedSteerIds,
|
|
29677
|
+
...unconsumedClientSteerIds.length ? { unconsumed_client_steer_ids: unconsumedClientSteerIds } : {}
|
|
29678
|
+
};
|
|
29679
|
+
};
|
|
29680
|
+
var correlateAppliedSteer = (event, polledSteers) => {
|
|
29681
|
+
if (event.type !== "steer_applied")
|
|
29682
|
+
return { confirmedIndex: -1, forwardedEvent: event };
|
|
29683
|
+
const confirmedIndex = polledSteers.findIndex(
|
|
29684
|
+
(steer) => steer.steer_id === event.steer_id
|
|
29685
|
+
);
|
|
29686
|
+
const clientSteerId = polledSteers[confirmedIndex]?.client_steer_id;
|
|
29687
|
+
const forwardedEvent = clientSteerId === void 0 ? event : { ...event, client_steer_id: clientSteerId };
|
|
29688
|
+
return { confirmedIndex, forwardedEvent };
|
|
29689
|
+
};
|
|
29690
|
+
var parseSteerInput = (input) => {
|
|
29691
|
+
let value;
|
|
29692
|
+
try {
|
|
29693
|
+
value = normalizeRunInput(input, "run.steer");
|
|
29694
|
+
} catch (error) {
|
|
29695
|
+
return { error: String(error) };
|
|
29696
|
+
}
|
|
29697
|
+
if (isRunInputEmpty(value))
|
|
29698
|
+
return { error: "run.steer input must not be empty" };
|
|
29699
|
+
return { value };
|
|
29700
|
+
};
|
|
29568
29701
|
var registerRunTools = (tools, wrap) => tools.map((tool) => {
|
|
29569
29702
|
const registered = wrap?.(tool);
|
|
29570
29703
|
if (!registered || !isSecuredRuntimeTool(registered))
|
|
@@ -29728,7 +29861,7 @@ var createRunHandlers = ({
|
|
|
29728
29861
|
initialInput = normalizeRunInput(params.input);
|
|
29729
29862
|
} catch (error) {
|
|
29730
29863
|
sendError(id2, {
|
|
29731
|
-
code:
|
|
29864
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29732
29865
|
message: String(error)
|
|
29733
29866
|
});
|
|
29734
29867
|
return;
|
|
@@ -29736,7 +29869,7 @@ var createRunHandlers = ({
|
|
|
29736
29869
|
const attachmentIds = runAttachmentIds(initialInput);
|
|
29737
29870
|
if (params.force_compaction && attachmentIds.length > 0) {
|
|
29738
29871
|
sendError(id2, {
|
|
29739
|
-
code:
|
|
29872
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29740
29873
|
message: "A compaction run cannot admit new attachments"
|
|
29741
29874
|
});
|
|
29742
29875
|
return;
|
|
@@ -29746,7 +29879,7 @@ var createRunHandlers = ({
|
|
|
29746
29879
|
await beforeRunStart();
|
|
29747
29880
|
} catch (error) {
|
|
29748
29881
|
sendError(id2, {
|
|
29749
|
-
code:
|
|
29882
|
+
code: import_protocol33.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29750
29883
|
message: `startup onboarding failed: ${String(error)}`
|
|
29751
29884
|
});
|
|
29752
29885
|
return;
|
|
@@ -29754,7 +29887,7 @@ var createRunHandlers = ({
|
|
|
29754
29887
|
}
|
|
29755
29888
|
if (state.activeRunId) {
|
|
29756
29889
|
sendError(id2, {
|
|
29757
|
-
code:
|
|
29890
|
+
code: import_protocol33.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
29758
29891
|
message: "runtime busy"
|
|
29759
29892
|
});
|
|
29760
29893
|
return;
|
|
@@ -29771,14 +29904,14 @@ var createRunHandlers = ({
|
|
|
29771
29904
|
resumeState = await sessionStateStore.load(requestedSessionId);
|
|
29772
29905
|
} catch (error) {
|
|
29773
29906
|
sendError(id2, {
|
|
29774
|
-
code:
|
|
29907
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
29775
29908
|
message: `session load failed: ${String(error)}`
|
|
29776
29909
|
});
|
|
29777
29910
|
return;
|
|
29778
29911
|
}
|
|
29779
29912
|
if (!resumeState) {
|
|
29780
29913
|
sendError(id2, {
|
|
29781
|
-
code:
|
|
29914
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_NOT_FOUND,
|
|
29782
29915
|
message: "session not found"
|
|
29783
29916
|
});
|
|
29784
29917
|
return;
|
|
@@ -29789,7 +29922,7 @@ var createRunHandlers = ({
|
|
|
29789
29922
|
resumeState = await sessionStateStore.load(state.sessionId);
|
|
29790
29923
|
} catch (error) {
|
|
29791
29924
|
sendError(id2, {
|
|
29792
|
-
code:
|
|
29925
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
29793
29926
|
message: `session reload failed: ${String(error)}`
|
|
29794
29927
|
});
|
|
29795
29928
|
return;
|
|
@@ -29806,7 +29939,7 @@ var createRunHandlers = ({
|
|
|
29806
29939
|
if (resumeState?.meta?.codelia_subagent) {
|
|
29807
29940
|
restorePreviousModel();
|
|
29808
29941
|
sendError(id2, {
|
|
29809
|
-
code:
|
|
29942
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29810
29943
|
message: "Delegated sessions cannot be resumed as a root run"
|
|
29811
29944
|
});
|
|
29812
29945
|
return;
|
|
@@ -29831,7 +29964,7 @@ var createRunHandlers = ({
|
|
|
29831
29964
|
} catch (error) {
|
|
29832
29965
|
restorePreviousModel();
|
|
29833
29966
|
sendError(id2, {
|
|
29834
|
-
code: error instanceof AttachmentAdmissionError ?
|
|
29967
|
+
code: error instanceof AttachmentAdmissionError ? import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol33.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
29835
29968
|
message: error instanceof Error ? error.message : String(error)
|
|
29836
29969
|
});
|
|
29837
29970
|
return;
|
|
@@ -29848,7 +29981,7 @@ var createRunHandlers = ({
|
|
|
29848
29981
|
} catch (error) {
|
|
29849
29982
|
restorePreviousModel();
|
|
29850
29983
|
sendError(id2, {
|
|
29851
|
-
code:
|
|
29984
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29852
29985
|
message: String(error)
|
|
29853
29986
|
});
|
|
29854
29987
|
return;
|
|
@@ -29867,7 +30000,7 @@ var createRunHandlers = ({
|
|
|
29867
30000
|
} catch {
|
|
29868
30001
|
restorePreviousModel();
|
|
29869
30002
|
sendError(id2, {
|
|
29870
|
-
code:
|
|
30003
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
29871
30004
|
message: "Could not claim the attachments for this conversation. Upload them again."
|
|
29872
30005
|
});
|
|
29873
30006
|
return;
|
|
@@ -30194,7 +30327,7 @@ var createRunHandlers = ({
|
|
|
30194
30327
|
session_id: sessionId,
|
|
30195
30328
|
...sessionStore.filePath ? { session_log_path: sessionStore.filePath } : {}
|
|
30196
30329
|
};
|
|
30197
|
-
|
|
30330
|
+
sendRequestResult("run.start", id2, result);
|
|
30198
30331
|
responseSent = true;
|
|
30199
30332
|
log2(`run.start ${runId}`);
|
|
30200
30333
|
emitRunStatus(runId, "running");
|
|
@@ -30216,22 +30349,12 @@ var createRunHandlers = ({
|
|
|
30216
30349
|
const remainingSteers = state.drainRunSteers(runId);
|
|
30217
30350
|
if (goals && admittedGoal && polledUnconfirmedSteers.length)
|
|
30218
30351
|
goals.recordApprovalSteer(admittedGoal, void 0);
|
|
30219
|
-
const
|
|
30220
|
-
|
|
30221
|
-
|
|
30222
|
-
|
|
30223
|
-
...remainingSteers
|
|
30224
|
-
]) {
|
|
30225
|
-
if (seenSteerIds.has(steer.steer_id)) continue;
|
|
30226
|
-
seenSteerIds.add(steer.steer_id);
|
|
30227
|
-
unconsumedSteerIds.push(steer.steer_id);
|
|
30228
|
-
releaseSteerAttachments(steer.steer_id);
|
|
30229
|
-
}
|
|
30352
|
+
const extras = collectUnconsumedSteers(
|
|
30353
|
+
[...polledUnconfirmedSteers, ...remainingSteers],
|
|
30354
|
+
releaseSteerAttachments
|
|
30355
|
+
);
|
|
30230
30356
|
polledUnconfirmedSteers.length = 0;
|
|
30231
|
-
|
|
30232
|
-
return void 0;
|
|
30233
|
-
}
|
|
30234
|
-
return { unconsumed_steer_ids: unconsumedSteerIds };
|
|
30357
|
+
return extras;
|
|
30235
30358
|
};
|
|
30236
30359
|
const queueSessionSave = (reason) => {
|
|
30237
30360
|
sessionSaveChain = sessionSaveChain.then(async () => {
|
|
@@ -30385,32 +30508,31 @@ var createRunHandlers = ({
|
|
|
30385
30508
|
`event.received ${summarizeRunEvent(event)}`
|
|
30386
30509
|
);
|
|
30387
30510
|
}
|
|
30388
|
-
const
|
|
30389
|
-
|
|
30390
|
-
|
|
30391
|
-
|
|
30392
|
-
|
|
30393
|
-
|
|
30394
|
-
|
|
30395
|
-
|
|
30396
|
-
|
|
30397
|
-
|
|
30511
|
+
const { confirmedIndex, forwardedEvent } = correlateAppliedSteer(
|
|
30512
|
+
event,
|
|
30513
|
+
polledUnconfirmedSteers
|
|
30514
|
+
);
|
|
30515
|
+
const seq = sendAgentEvent(state, runId, forwardedEvent);
|
|
30516
|
+
if (seq !== null && event.type === "steer_applied" && confirmedIndex >= 0) {
|
|
30517
|
+
if (goals && admittedGoal)
|
|
30518
|
+
goals.recordApprovalSteer(
|
|
30519
|
+
admittedGoal,
|
|
30520
|
+
state.approvalSteerText(runId, event.steer_id)
|
|
30521
|
+
);
|
|
30522
|
+
state.confirmApprovalSteer(runId, event.steer_id);
|
|
30523
|
+
polledUnconfirmedSteers.splice(confirmedIndex, 1);
|
|
30524
|
+
releaseSteerAttachments(event.steer_id);
|
|
30525
|
+
if (approvalScope && sessionStateStore.confirmApprovalSteer) {
|
|
30526
|
+
try {
|
|
30527
|
+
await sessionStateStore.confirmApprovalSteer(
|
|
30528
|
+
sessionId,
|
|
30529
|
+
runId,
|
|
30530
|
+
event.steer_id
|
|
30531
|
+
);
|
|
30532
|
+
} catch (error) {
|
|
30533
|
+
log2(
|
|
30534
|
+
`Could not record applied Steer for historical approval: ${String(error)}`
|
|
30398
30535
|
);
|
|
30399
|
-
state.confirmApprovalSteer(runId, event.steer_id);
|
|
30400
|
-
polledUnconfirmedSteers.splice(confirmedIndex, 1);
|
|
30401
|
-
releaseSteerAttachments(event.steer_id);
|
|
30402
|
-
if (approvalScope && sessionStateStore.confirmApprovalSteer) {
|
|
30403
|
-
try {
|
|
30404
|
-
await sessionStateStore.confirmApprovalSteer(
|
|
30405
|
-
sessionId,
|
|
30406
|
-
runId,
|
|
30407
|
-
event.steer_id
|
|
30408
|
-
);
|
|
30409
|
-
} catch (error) {
|
|
30410
|
-
log2(
|
|
30411
|
-
`Could not record applied Steer for historical approval: ${String(error)}`
|
|
30412
|
-
);
|
|
30413
|
-
}
|
|
30414
30536
|
}
|
|
30415
30537
|
}
|
|
30416
30538
|
}
|
|
@@ -30427,7 +30549,7 @@ var createRunHandlers = ({
|
|
|
30427
30549
|
run_id: runId,
|
|
30428
30550
|
ts: nowIso5(),
|
|
30429
30551
|
seq,
|
|
30430
|
-
event
|
|
30552
|
+
event: forwardedEvent
|
|
30431
30553
|
});
|
|
30432
30554
|
}
|
|
30433
30555
|
emitContextUsage(event.type);
|
|
@@ -30551,33 +30673,35 @@ var createRunHandlers = ({
|
|
|
30551
30673
|
const runId = typeof params?.run_id === "string" ? params.run_id.trim() : "";
|
|
30552
30674
|
if (!runId) {
|
|
30553
30675
|
sendError(id2, {
|
|
30554
|
-
code:
|
|
30676
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30555
30677
|
message: "run_id is required"
|
|
30556
30678
|
});
|
|
30557
30679
|
return Promise.resolve();
|
|
30558
30680
|
}
|
|
30559
|
-
|
|
30560
|
-
|
|
30561
|
-
|
|
30562
|
-
|
|
30563
|
-
|
|
30564
|
-
|
|
30565
|
-
message: String(error)
|
|
30566
|
-
});
|
|
30567
|
-
return Promise.resolve();
|
|
30568
|
-
}
|
|
30569
|
-
if (isRunInputEmpty(initialInput)) {
|
|
30570
|
-
sendError(id2, {
|
|
30571
|
-
code: import_protocol16.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30572
|
-
message: "run.steer input must not be empty"
|
|
30573
|
-
});
|
|
30574
|
-
return Promise.resolve();
|
|
30575
|
-
}
|
|
30576
|
-
const clientSteerId = typeof params.client_steer_id === "string" && params.client_steer_id.trim() ? params.client_steer_id.trim() : void 0;
|
|
30681
|
+
const clientSteerId = params.client_steer_id;
|
|
30682
|
+
const acknowledge = (steerId) => sendRequestResult("run.steer", id2, {
|
|
30683
|
+
ok: true,
|
|
30684
|
+
steer_id: steerId,
|
|
30685
|
+
...clientSteerId !== void 0 ? { client_steer_id: clientSteerId } : {}
|
|
30686
|
+
});
|
|
30577
30687
|
const admitSteer = async () => {
|
|
30688
|
+
const acceptedId = clientSteerId === void 0 ? void 0 : state.acceptedRunSteerId(runId, clientSteerId);
|
|
30689
|
+
if (acceptedId) {
|
|
30690
|
+
acknowledge(acceptedId);
|
|
30691
|
+
return;
|
|
30692
|
+
}
|
|
30693
|
+
const input = parseSteerInput(params.input);
|
|
30694
|
+
if ("error" in input) {
|
|
30695
|
+
sendError(id2, {
|
|
30696
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30697
|
+
message: input.error
|
|
30698
|
+
});
|
|
30699
|
+
return;
|
|
30700
|
+
}
|
|
30701
|
+
const initialInput = input.value;
|
|
30578
30702
|
if (!state.canSteerRun(runId)) {
|
|
30579
30703
|
sendError(id2, {
|
|
30580
|
-
code:
|
|
30704
|
+
code: import_protocol33.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
30581
30705
|
message: "active run not found"
|
|
30582
30706
|
});
|
|
30583
30707
|
return;
|
|
@@ -30603,7 +30727,7 @@ var createRunHandlers = ({
|
|
|
30603
30727
|
normalizedInput = await state.prepareRunImages(normalizedInput);
|
|
30604
30728
|
} catch (error) {
|
|
30605
30729
|
sendError(id2, {
|
|
30606
|
-
code: error instanceof AttachmentAdmissionError ?
|
|
30730
|
+
code: error instanceof AttachmentAdmissionError ? import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS : import_protocol33.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
30607
30731
|
message: error instanceof Error ? error.message : String(error)
|
|
30608
30732
|
});
|
|
30609
30733
|
return;
|
|
@@ -30617,7 +30741,7 @@ var createRunHandlers = ({
|
|
|
30617
30741
|
);
|
|
30618
30742
|
} catch {
|
|
30619
30743
|
sendError(id2, {
|
|
30620
|
-
code:
|
|
30744
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30621
30745
|
message: "Could not retain the attachments for this conversation. Upload them again."
|
|
30622
30746
|
});
|
|
30623
30747
|
return;
|
|
@@ -30626,7 +30750,7 @@ var createRunHandlers = ({
|
|
|
30626
30750
|
if (!state.canSteerRun(runId)) {
|
|
30627
30751
|
releaseAttachments?.();
|
|
30628
30752
|
sendError(id2, {
|
|
30629
|
-
code:
|
|
30753
|
+
code: import_protocol33.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
30630
30754
|
message: "active run ended before steer could be queued"
|
|
30631
30755
|
});
|
|
30632
30756
|
return;
|
|
@@ -30642,10 +30766,7 @@ var createRunHandlers = ({
|
|
|
30642
30766
|
ids: attachmentIds,
|
|
30643
30767
|
release: releaseAttachments
|
|
30644
30768
|
});
|
|
30645
|
-
|
|
30646
|
-
ok: true,
|
|
30647
|
-
steer_id: steerId
|
|
30648
|
-
});
|
|
30769
|
+
acknowledge(steerId);
|
|
30649
30770
|
logRunDebug(log2, runId, `run.steer queued steer_id=${steerId}`);
|
|
30650
30771
|
};
|
|
30651
30772
|
const queued = runSteerQueue.then(admitSteer, admitSteer);
|
|
@@ -30664,28 +30785,33 @@ var createRunHandlers = ({
|
|
|
30664
30785
|
const handleGoal = (id2, method, raw) => {
|
|
30665
30786
|
if (!goals?.enabled) {
|
|
30666
30787
|
sendError(id2, {
|
|
30667
|
-
code:
|
|
30788
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30668
30789
|
message: "Goals are unavailable on this connection."
|
|
30669
30790
|
});
|
|
30670
30791
|
return Promise.resolve();
|
|
30671
30792
|
}
|
|
30793
|
+
const parsed = parseRequestParams(method, raw);
|
|
30794
|
+
if (!parsed.ok) {
|
|
30795
|
+
sendError(id2, parsed.error);
|
|
30796
|
+
return Promise.resolve();
|
|
30797
|
+
}
|
|
30672
30798
|
if (method === "goal.continue") {
|
|
30673
|
-
const params =
|
|
30799
|
+
const params = parsed.params;
|
|
30674
30800
|
return handleRunStart(
|
|
30675
30801
|
id2,
|
|
30676
30802
|
{
|
|
30677
30803
|
input: { type: "text", text: "" },
|
|
30678
|
-
session_id: params
|
|
30679
|
-
tools: params
|
|
30680
|
-
ui_context: params
|
|
30804
|
+
session_id: params.session_id,
|
|
30805
|
+
tools: params.tools,
|
|
30806
|
+
ui_context: params.ui_context
|
|
30681
30807
|
},
|
|
30682
|
-
|
|
30808
|
+
params
|
|
30683
30809
|
);
|
|
30684
30810
|
}
|
|
30685
30811
|
return goals.handle(
|
|
30686
30812
|
id2,
|
|
30687
30813
|
method,
|
|
30688
|
-
|
|
30814
|
+
parsed.params,
|
|
30689
30815
|
serializeAdmission,
|
|
30690
30816
|
interruptRun,
|
|
30691
30817
|
(error) => log2(`goal operation failed: ${String(error)}`)
|
|
@@ -30693,12 +30819,12 @@ var createRunHandlers = ({
|
|
|
30693
30819
|
};
|
|
30694
30820
|
const handleRunCancel = (id2, params) => {
|
|
30695
30821
|
if (interruptRun(params.run_id, params.reason)) {
|
|
30696
|
-
|
|
30822
|
+
sendRequestResult("run.cancel", id2, { ok: true });
|
|
30697
30823
|
log2(`run.cancel ${params.run_id} (${params.reason ?? "no reason"})`);
|
|
30698
30824
|
return;
|
|
30699
30825
|
}
|
|
30700
30826
|
sendError(id2, {
|
|
30701
|
-
code:
|
|
30827
|
+
code: import_protocol33.RPC_ERROR_CODE.RUN_NOT_FOUND,
|
|
30702
30828
|
message: "run not found"
|
|
30703
30829
|
});
|
|
30704
30830
|
};
|
|
@@ -30709,20 +30835,22 @@ var createRunHandlers = ({
|
|
|
30709
30835
|
const open3 = async () => {
|
|
30710
30836
|
if (!sessionId) {
|
|
30711
30837
|
sendError(id2, {
|
|
30712
|
-
code:
|
|
30838
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30713
30839
|
message: "session_id is required"
|
|
30714
30840
|
});
|
|
30715
30841
|
return;
|
|
30716
30842
|
}
|
|
30717
30843
|
if (state.activeRunId) {
|
|
30718
30844
|
sendError(id2, {
|
|
30719
|
-
code:
|
|
30845
|
+
code: import_protocol33.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30720
30846
|
message: "runtime busy"
|
|
30721
30847
|
});
|
|
30722
30848
|
return;
|
|
30723
30849
|
}
|
|
30724
30850
|
if (sessionId === state.sessionId) {
|
|
30725
|
-
|
|
30851
|
+
sendRequestResult("session.open", id2, {
|
|
30852
|
+
session_id: sessionId
|
|
30853
|
+
});
|
|
30726
30854
|
return;
|
|
30727
30855
|
}
|
|
30728
30856
|
let opened;
|
|
@@ -30730,21 +30858,21 @@ var createRunHandlers = ({
|
|
|
30730
30858
|
opened = await sessionStateStore.load(sessionId);
|
|
30731
30859
|
} catch (error) {
|
|
30732
30860
|
sendError(id2, {
|
|
30733
|
-
code:
|
|
30861
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_LOAD_FAILED,
|
|
30734
30862
|
message: `session load failed: ${String(error)}`
|
|
30735
30863
|
});
|
|
30736
30864
|
return;
|
|
30737
30865
|
}
|
|
30738
30866
|
if (!opened) {
|
|
30739
30867
|
sendError(id2, {
|
|
30740
|
-
code:
|
|
30868
|
+
code: import_protocol33.RPC_ERROR_CODE.SESSION_NOT_FOUND,
|
|
30741
30869
|
message: "session not found"
|
|
30742
30870
|
});
|
|
30743
30871
|
return;
|
|
30744
30872
|
}
|
|
30745
30873
|
if (opened.meta?.codelia_subagent) {
|
|
30746
30874
|
sendError(id2, {
|
|
30747
|
-
code:
|
|
30875
|
+
code: import_protocol33.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30748
30876
|
message: "Delegated sessions cannot be opened as a root session"
|
|
30749
30877
|
});
|
|
30750
30878
|
return;
|
|
@@ -30756,7 +30884,9 @@ var createRunHandlers = ({
|
|
|
30756
30884
|
state.sessionAppend = null;
|
|
30757
30885
|
applySessionModelOverrideFromMeta(state, opened.meta);
|
|
30758
30886
|
state.agent = null;
|
|
30759
|
-
|
|
30887
|
+
sendRequestResult("session.open", id2, {
|
|
30888
|
+
session_id: sessionId
|
|
30889
|
+
});
|
|
30760
30890
|
log2(`session.open ${sessionId}`);
|
|
30761
30891
|
};
|
|
30762
30892
|
const queued = runStartQueue.then(open3, open3);
|
|
@@ -30780,15 +30910,8 @@ var createRunHandlers = ({
|
|
|
30780
30910
|
|
|
30781
30911
|
// src/rpc/sandbox.ts
|
|
30782
30912
|
var import_promises5 = require("fs/promises");
|
|
30783
|
-
var
|
|
30784
|
-
var import_shared_types11 = require("@codelia/shared-types");
|
|
30913
|
+
var import_protocol35 = require("@codelia/protocol");
|
|
30785
30914
|
var import_storage32 = require("@codelia/storage");
|
|
30786
|
-
var import_zod49 = require("zod");
|
|
30787
|
-
var getParams = import_zod49.z.strictObject({});
|
|
30788
|
-
var setParams = import_zod49.z.strictObject({
|
|
30789
|
-
scope: import_zod49.z.literal("project"),
|
|
30790
|
-
mode: import_zod49.z.enum(import_shared_types11.sandboxModes)
|
|
30791
|
-
});
|
|
30792
30915
|
var choices = [
|
|
30793
30916
|
{
|
|
30794
30917
|
id: "readonly",
|
|
@@ -30855,30 +30978,25 @@ var status = async (state, store) => {
|
|
|
30855
30978
|
var handleSandbox = async (state, id2, method, params) => {
|
|
30856
30979
|
if (!supportsSandboxModeManagement(state))
|
|
30857
30980
|
return sendError(id2, {
|
|
30858
|
-
code:
|
|
30981
|
+
code: import_protocol35.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
30859
30982
|
message: "Sandbox management is unavailable."
|
|
30860
30983
|
});
|
|
30861
|
-
const store = new import_storage32.ProjectsPolicyStore();
|
|
30862
30984
|
if (method === "sandbox.get") {
|
|
30863
|
-
|
|
30864
|
-
|
|
30865
|
-
|
|
30866
|
-
|
|
30867
|
-
|
|
30868
|
-
return sendResult(
|
|
30985
|
+
const parsed2 = parseRequestParams(method, params);
|
|
30986
|
+
if (!parsed2.ok) return sendError(id2, parsed2.error);
|
|
30987
|
+
const store2 = new import_storage32.ProjectsPolicyStore();
|
|
30988
|
+
return sendRequestResult(
|
|
30989
|
+
method,
|
|
30869
30990
|
id2,
|
|
30870
|
-
await state.withAdmissionLock(() => status(state,
|
|
30991
|
+
await state.withAdmissionLock(() => status(state, store2))
|
|
30871
30992
|
);
|
|
30872
30993
|
}
|
|
30873
|
-
const parsed =
|
|
30874
|
-
if (!parsed.
|
|
30875
|
-
|
|
30876
|
-
|
|
30877
|
-
message: "Select a sandbox mode with project scope."
|
|
30878
|
-
});
|
|
30879
|
-
const { mode } = parsed.data;
|
|
30994
|
+
const parsed = parseRequestParams(method, params);
|
|
30995
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
30996
|
+
const { mode } = parsed.params;
|
|
30997
|
+
const store = new import_storage32.ProjectsPolicyStore();
|
|
30880
30998
|
const fail = (reason) => sendError(id2, {
|
|
30881
|
-
code: reason === "runtime_busy" || reason === "policy_store_busy" ?
|
|
30999
|
+
code: reason === "runtime_busy" || reason === "policy_store_busy" ? import_protocol35.RPC_ERROR_CODE.RUNTIME_BUSY : import_protocol35.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30882
31000
|
message: `Project sandbox mode could not be changed (${reason}).`,
|
|
30883
31001
|
data: { reason }
|
|
30884
31002
|
});
|
|
@@ -30899,30 +31017,33 @@ var handleSandbox = async (state, id2, method, params) => {
|
|
|
30899
31017
|
state.sandboxMode = { value: mode, source: "project" };
|
|
30900
31018
|
state.approvalMode = null;
|
|
30901
31019
|
state.invalidateAgentCache();
|
|
30902
|
-
return
|
|
31020
|
+
return sendRequestResult(method, id2, await status(state, store));
|
|
30903
31021
|
});
|
|
30904
31022
|
};
|
|
30905
31023
|
|
|
30906
31024
|
// src/rpc/session-lifecycle.ts
|
|
30907
|
-
var
|
|
30908
|
-
var createSessionUpdateHandler = (options) => async (id2,
|
|
31025
|
+
var import_protocol37 = require("@codelia/protocol");
|
|
31026
|
+
var createSessionUpdateHandler = (options) => async (id2, raw) => {
|
|
30909
31027
|
if (!options.sessions.updateMetadata) {
|
|
30910
31028
|
sendError(id2, {
|
|
30911
|
-
code:
|
|
31029
|
+
code: import_protocol37.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30912
31030
|
message: "Session lifecycle updates are unavailable"
|
|
30913
31031
|
});
|
|
30914
31032
|
return;
|
|
30915
31033
|
}
|
|
30916
|
-
|
|
31034
|
+
const parsed = parseRequestParams("session.update", raw);
|
|
31035
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
31036
|
+
const params = parsed.params;
|
|
31037
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(params.session_id) || params.pinned === void 0 && params.archived === void 0) {
|
|
30917
31038
|
sendError(id2, {
|
|
30918
|
-
code:
|
|
31039
|
+
code: import_protocol37.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30919
31040
|
message: "Expected session_id and a boolean pinned or archived update"
|
|
30920
31041
|
});
|
|
30921
31042
|
return;
|
|
30922
31043
|
}
|
|
30923
31044
|
if (params.archived && options.state.activeRunId && options.state.sessionId === params.session_id) {
|
|
30924
31045
|
sendError(id2, {
|
|
30925
|
-
code:
|
|
31046
|
+
code: import_protocol37.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
30926
31047
|
message: "Wait for the active run before archiving this session"
|
|
30927
31048
|
});
|
|
30928
31049
|
return;
|
|
@@ -30940,10 +31061,10 @@ var createSessionUpdateHandler = (options) => async (id2, params) => {
|
|
|
30940
31061
|
}
|
|
30941
31062
|
}
|
|
30942
31063
|
const result = { session };
|
|
30943
|
-
|
|
31064
|
+
sendRequestResult("session.update", id2, result);
|
|
30944
31065
|
} catch (error) {
|
|
30945
31066
|
sendError(id2, {
|
|
30946
|
-
code:
|
|
31067
|
+
code: import_protocol37.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
30947
31068
|
message: `Session update failed: ${String(error)}`
|
|
30948
31069
|
});
|
|
30949
31070
|
}
|
|
@@ -30951,7 +31072,7 @@ var createSessionUpdateHandler = (options) => async (id2, params) => {
|
|
|
30951
31072
|
|
|
30952
31073
|
// src/rpc/shell.ts
|
|
30953
31074
|
var import_node_path47 = __toESM(require("path"), 1);
|
|
30954
|
-
var
|
|
31075
|
+
var import_protocol39 = require("@codelia/protocol");
|
|
30955
31076
|
var import_storage33 = require("@codelia/storage");
|
|
30956
31077
|
var COMMAND_PREVIEW_CHARS = 400;
|
|
30957
31078
|
var DEFAULT_TRUNCATED = {
|
|
@@ -31003,7 +31124,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31003
31124
|
if (!taskId) {
|
|
31004
31125
|
return {
|
|
31005
31126
|
error: {
|
|
31006
|
-
code:
|
|
31127
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31007
31128
|
message: "task_id is required"
|
|
31008
31129
|
}
|
|
31009
31130
|
};
|
|
@@ -31011,7 +31132,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31011
31132
|
if (params?.stream !== "stdout" && params?.stream !== "stderr") {
|
|
31012
31133
|
return {
|
|
31013
31134
|
error: {
|
|
31014
|
-
code:
|
|
31135
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31015
31136
|
message: "stream must be stdout or stderr"
|
|
31016
31137
|
}
|
|
31017
31138
|
};
|
|
@@ -31019,7 +31140,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31019
31140
|
if (params.line_number !== void 0 && (params.offset !== void 0 || params.limit !== void 0)) {
|
|
31020
31141
|
return {
|
|
31021
31142
|
error: {
|
|
31022
|
-
code:
|
|
31143
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31023
31144
|
message: "line_number cannot be combined with offset or limit"
|
|
31024
31145
|
}
|
|
31025
31146
|
};
|
|
@@ -31027,7 +31148,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31027
31148
|
if (params.line_number === void 0 && (params.char_offset !== void 0 || params.char_limit !== void 0)) {
|
|
31028
31149
|
return {
|
|
31029
31150
|
error: {
|
|
31030
|
-
code:
|
|
31151
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31031
31152
|
message: "char_offset/char_limit require line_number"
|
|
31032
31153
|
}
|
|
31033
31154
|
};
|
|
@@ -31035,7 +31156,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31035
31156
|
if (params.offset !== void 0 && (!Number.isFinite(params.offset) || params.offset < 0)) {
|
|
31036
31157
|
return {
|
|
31037
31158
|
error: {
|
|
31038
|
-
code:
|
|
31159
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31039
31160
|
message: "offset must be a non-negative number"
|
|
31040
31161
|
}
|
|
31041
31162
|
};
|
|
@@ -31043,7 +31164,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31043
31164
|
if (params.limit !== void 0 && (!Number.isFinite(params.limit) || params.limit <= 0)) {
|
|
31044
31165
|
return {
|
|
31045
31166
|
error: {
|
|
31046
|
-
code:
|
|
31167
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31047
31168
|
message: "limit must be a positive number"
|
|
31048
31169
|
}
|
|
31049
31170
|
};
|
|
@@ -31051,7 +31172,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31051
31172
|
if (params.line_number !== void 0 && (!Number.isFinite(params.line_number) || params.line_number <= 0)) {
|
|
31052
31173
|
return {
|
|
31053
31174
|
error: {
|
|
31054
|
-
code:
|
|
31175
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31055
31176
|
message: "line_number must be a positive number"
|
|
31056
31177
|
}
|
|
31057
31178
|
};
|
|
@@ -31059,7 +31180,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31059
31180
|
if (params.char_offset !== void 0 && (!Number.isFinite(params.char_offset) || params.char_offset < 0)) {
|
|
31060
31181
|
return {
|
|
31061
31182
|
error: {
|
|
31062
|
-
code:
|
|
31183
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31063
31184
|
message: "char_offset must be a non-negative number"
|
|
31064
31185
|
}
|
|
31065
31186
|
};
|
|
@@ -31067,7 +31188,7 @@ var parseShellOutputRequest = (params) => {
|
|
|
31067
31188
|
if (params.char_limit !== void 0 && (!Number.isFinite(params.char_limit) || params.char_limit <= 0)) {
|
|
31068
31189
|
return {
|
|
31069
31190
|
error: {
|
|
31070
|
-
code:
|
|
31191
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31071
31192
|
message: "char_limit must be a positive number"
|
|
31072
31193
|
}
|
|
31073
31194
|
};
|
|
@@ -31121,7 +31242,7 @@ var parseTaskId = (value) => {
|
|
|
31121
31242
|
var toTaskRpcError = (error) => {
|
|
31122
31243
|
if (!(error instanceof TaskManagerError)) {
|
|
31123
31244
|
return {
|
|
31124
|
-
code:
|
|
31245
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31125
31246
|
message: String(error)
|
|
31126
31247
|
};
|
|
31127
31248
|
}
|
|
@@ -31130,17 +31251,17 @@ var toTaskRpcError = (error) => {
|
|
|
31130
31251
|
case "invalid_task_id":
|
|
31131
31252
|
case "unsupported_workspace_mode":
|
|
31132
31253
|
return {
|
|
31133
|
-
code:
|
|
31254
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31134
31255
|
message: error.message
|
|
31135
31256
|
};
|
|
31136
31257
|
case "manager_shutting_down":
|
|
31137
31258
|
return {
|
|
31138
|
-
code:
|
|
31259
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
31139
31260
|
message: error.message
|
|
31140
31261
|
};
|
|
31141
31262
|
default:
|
|
31142
31263
|
return {
|
|
31143
|
-
code:
|
|
31264
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31144
31265
|
message: error.message
|
|
31145
31266
|
};
|
|
31146
31267
|
}
|
|
@@ -31164,7 +31285,7 @@ var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
|
31164
31285
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
31165
31286
|
return {
|
|
31166
31287
|
error: {
|
|
31167
|
-
code:
|
|
31288
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31168
31289
|
message: "timeout_seconds must be a positive number"
|
|
31169
31290
|
}
|
|
31170
31291
|
};
|
|
@@ -31178,7 +31299,7 @@ var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
|
31178
31299
|
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
31179
31300
|
return {
|
|
31180
31301
|
error: {
|
|
31181
|
-
code:
|
|
31302
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31182
31303
|
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
31183
31304
|
}
|
|
31184
31305
|
};
|
|
@@ -31192,7 +31313,7 @@ var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
|
31192
31313
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
31193
31314
|
return {
|
|
31194
31315
|
error: {
|
|
31195
|
-
code:
|
|
31316
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31196
31317
|
message: "wait_timeout_seconds must be a positive number"
|
|
31197
31318
|
}
|
|
31198
31319
|
};
|
|
@@ -31200,7 +31321,7 @@ var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
|
31200
31321
|
if (requestedTimeout > MAX_TIMEOUT_SECONDS) {
|
|
31201
31322
|
return {
|
|
31202
31323
|
error: {
|
|
31203
|
-
code:
|
|
31324
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31204
31325
|
message: `wait_timeout_seconds must be ${MAX_TIMEOUT_SECONDS} seconds or less`
|
|
31205
31326
|
}
|
|
31206
31327
|
};
|
|
@@ -31215,7 +31336,7 @@ var parseShellStartRequest = (state, params, options) => {
|
|
|
31215
31336
|
if (!command.trim()) {
|
|
31216
31337
|
return {
|
|
31217
31338
|
error: {
|
|
31218
|
-
code:
|
|
31339
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31219
31340
|
message: "command is required"
|
|
31220
31341
|
}
|
|
31221
31342
|
};
|
|
@@ -31231,7 +31352,7 @@ var parseShellStartRequest = (state, params, options) => {
|
|
|
31231
31352
|
if (!cwd) {
|
|
31232
31353
|
return {
|
|
31233
31354
|
error: {
|
|
31234
|
-
code:
|
|
31355
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31235
31356
|
message: "cwd is outside sandbox root"
|
|
31236
31357
|
}
|
|
31237
31358
|
};
|
|
@@ -31319,7 +31440,7 @@ var createShellHandlers = ({
|
|
|
31319
31440
|
const finished = await shellTaskManager.wait(task.task_id);
|
|
31320
31441
|
assertReceiptScopeCurrent(scope);
|
|
31321
31442
|
const result = toShellExecResult(commandPreview, finished.result);
|
|
31322
|
-
|
|
31443
|
+
sendRequestResult("shell.exec", id2, result);
|
|
31323
31444
|
log2(
|
|
31324
31445
|
`shell.exec.done origin=ui_bang duration_ms=${result.duration_ms} exit_code=${String(result.exit_code)} signal=${result.signal ?? "-"}`
|
|
31325
31446
|
);
|
|
@@ -31340,7 +31461,7 @@ var createShellHandlers = ({
|
|
|
31340
31461
|
try {
|
|
31341
31462
|
const { task } = await spawnShell(id2, params, "shell.start");
|
|
31342
31463
|
assertReceiptScopeCurrent(scope);
|
|
31343
|
-
|
|
31464
|
+
sendRequestResult("shell.start", id2, toShellTaskInfo(task));
|
|
31344
31465
|
} catch (error) {
|
|
31345
31466
|
if (scope.connectionSignal.aborted) return;
|
|
31346
31467
|
if (typeof error === "object" && error !== null && "code" in error && "message" in error) {
|
|
@@ -31357,7 +31478,7 @@ var createShellHandlers = ({
|
|
|
31357
31478
|
const requestedLimit = params?.limit;
|
|
31358
31479
|
if (requestedLimit !== void 0 && (!Number.isFinite(requestedLimit) || requestedLimit <= 0)) {
|
|
31359
31480
|
sendError(id2, {
|
|
31360
|
-
code:
|
|
31481
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31361
31482
|
message: "limit must be a positive number"
|
|
31362
31483
|
});
|
|
31363
31484
|
return;
|
|
@@ -31366,7 +31487,7 @@ var createShellHandlers = ({
|
|
|
31366
31487
|
const limit = requestedLimit ? Math.trunc(requestedLimit) : void 0;
|
|
31367
31488
|
const tasks = (await shellTaskManager.list({ sessionId: state.sessionId })).filter((task) => task.kind === "shell").slice(0, limit).map(toShellTaskInfo);
|
|
31368
31489
|
const result = { tasks };
|
|
31369
|
-
|
|
31490
|
+
sendRequestResult("shell.list", id2, result);
|
|
31370
31491
|
} catch (error) {
|
|
31371
31492
|
sendTaskError(id2, error);
|
|
31372
31493
|
}
|
|
@@ -31375,7 +31496,7 @@ var createShellHandlers = ({
|
|
|
31375
31496
|
const taskId = parseTaskId(params?.task_id);
|
|
31376
31497
|
if (!taskId) {
|
|
31377
31498
|
sendError(id2, {
|
|
31378
|
-
code:
|
|
31499
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31379
31500
|
message: "task_id is required"
|
|
31380
31501
|
});
|
|
31381
31502
|
return;
|
|
@@ -31386,7 +31507,7 @@ var createShellHandlers = ({
|
|
|
31386
31507
|
taskId,
|
|
31387
31508
|
state.sessionId
|
|
31388
31509
|
);
|
|
31389
|
-
|
|
31510
|
+
sendRequestResult("shell.status", id2, toShellTaskInfo(task));
|
|
31390
31511
|
} catch (error) {
|
|
31391
31512
|
sendTaskError(id2, error);
|
|
31392
31513
|
}
|
|
@@ -31411,7 +31532,7 @@ var createShellHandlers = ({
|
|
|
31411
31532
|
);
|
|
31412
31533
|
if (!cacheId && liveContent === null && !isTerminalTaskState(task.state)) {
|
|
31413
31534
|
sendError(id2, {
|
|
31414
|
-
code:
|
|
31535
|
+
code: import_protocol39.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
31415
31536
|
message: `shell output is not retained yet for running task: ${parsed.taskId}`
|
|
31416
31537
|
});
|
|
31417
31538
|
return;
|
|
@@ -31439,7 +31560,7 @@ var createShellHandlers = ({
|
|
|
31439
31560
|
content,
|
|
31440
31561
|
...cacheId ? { ref_id: cacheId } : {}
|
|
31441
31562
|
};
|
|
31442
|
-
|
|
31563
|
+
sendRequestResult("shell.output", id2, result);
|
|
31443
31564
|
} catch (error) {
|
|
31444
31565
|
sendTaskError(id2, error);
|
|
31445
31566
|
}
|
|
@@ -31448,7 +31569,7 @@ var createShellHandlers = ({
|
|
|
31448
31569
|
const taskId = parseTaskId(params?.task_id);
|
|
31449
31570
|
if (!taskId) {
|
|
31450
31571
|
sendError(id2, {
|
|
31451
|
-
code:
|
|
31572
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31452
31573
|
message: "task_id is required"
|
|
31453
31574
|
});
|
|
31454
31575
|
return;
|
|
@@ -31467,7 +31588,7 @@ var createShellHandlers = ({
|
|
|
31467
31588
|
state.sessionId
|
|
31468
31589
|
);
|
|
31469
31590
|
if (isTerminalTaskState(existing.state)) {
|
|
31470
|
-
|
|
31591
|
+
sendRequestResult("shell.wait", id2, toShellTaskInfo(existing));
|
|
31471
31592
|
return;
|
|
31472
31593
|
}
|
|
31473
31594
|
const controller = new AbortController();
|
|
@@ -31507,7 +31628,7 @@ var createShellHandlers = ({
|
|
|
31507
31628
|
timeoutPromise
|
|
31508
31629
|
]);
|
|
31509
31630
|
if (outcome.type === "detached") {
|
|
31510
|
-
|
|
31631
|
+
sendRequestResult("shell.wait", id2, outcome.result);
|
|
31511
31632
|
return;
|
|
31512
31633
|
}
|
|
31513
31634
|
if (outcome.type === "still_running") {
|
|
@@ -31516,7 +31637,7 @@ var createShellHandlers = ({
|
|
|
31516
31637
|
taskId,
|
|
31517
31638
|
state.sessionId
|
|
31518
31639
|
);
|
|
31519
|
-
|
|
31640
|
+
sendRequestResult("shell.wait", id2, {
|
|
31520
31641
|
...toShellTaskInfo(task),
|
|
31521
31642
|
...isTerminalTaskState(task.state) ? {} : { still_running: true }
|
|
31522
31643
|
});
|
|
@@ -31525,7 +31646,7 @@ var createShellHandlers = ({
|
|
|
31525
31646
|
if (outcome.type === "aborted") {
|
|
31526
31647
|
return;
|
|
31527
31648
|
}
|
|
31528
|
-
|
|
31649
|
+
sendRequestResult("shell.wait", id2, toShellTaskInfo(outcome.task));
|
|
31529
31650
|
} finally {
|
|
31530
31651
|
if (timeoutHandle) {
|
|
31531
31652
|
clearTimeout(timeoutHandle);
|
|
@@ -31540,7 +31661,7 @@ var createShellHandlers = ({
|
|
|
31540
31661
|
const taskId = parseTaskId(params?.task_id);
|
|
31541
31662
|
if (!taskId) {
|
|
31542
31663
|
sendError(id2, {
|
|
31543
|
-
code:
|
|
31664
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31544
31665
|
message: "task_id is required"
|
|
31545
31666
|
});
|
|
31546
31667
|
return;
|
|
@@ -31554,7 +31675,7 @@ var createShellHandlers = ({
|
|
|
31554
31675
|
const waits = activeShellWaits.get(taskId);
|
|
31555
31676
|
if (!waits || waits.size === 0) {
|
|
31556
31677
|
sendError(id2, {
|
|
31557
|
-
code:
|
|
31678
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31558
31679
|
message: `no active shell.wait to detach for task: ${taskId}`
|
|
31559
31680
|
});
|
|
31560
31681
|
return;
|
|
@@ -31567,7 +31688,7 @@ var createShellHandlers = ({
|
|
|
31567
31688
|
detached: true,
|
|
31568
31689
|
state: task.state
|
|
31569
31690
|
};
|
|
31570
|
-
|
|
31691
|
+
sendRequestResult("shell.detach", id2, result);
|
|
31571
31692
|
} catch (error) {
|
|
31572
31693
|
sendTaskError(id2, error);
|
|
31573
31694
|
}
|
|
@@ -31576,7 +31697,7 @@ var createShellHandlers = ({
|
|
|
31576
31697
|
const taskId = parseTaskId(params?.task_id);
|
|
31577
31698
|
if (!taskId) {
|
|
31578
31699
|
sendError(id2, {
|
|
31579
|
-
code:
|
|
31700
|
+
code: import_protocol39.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31580
31701
|
message: "task_id is required"
|
|
31581
31702
|
});
|
|
31582
31703
|
return;
|
|
@@ -31586,7 +31707,7 @@ var createShellHandlers = ({
|
|
|
31586
31707
|
const task = await shellTaskManager.cancel(taskId, {
|
|
31587
31708
|
reason: "cancelled"
|
|
31588
31709
|
});
|
|
31589
|
-
|
|
31710
|
+
sendRequestResult("shell.cancel", id2, toShellTaskInfo(task));
|
|
31590
31711
|
} catch (error) {
|
|
31591
31712
|
sendTaskError(id2, error);
|
|
31592
31713
|
}
|
|
@@ -31605,7 +31726,7 @@ var createShellHandlers = ({
|
|
|
31605
31726
|
|
|
31606
31727
|
// src/rpc/skills.ts
|
|
31607
31728
|
var import_node_path48 = __toESM(require("path"), 1);
|
|
31608
|
-
var
|
|
31729
|
+
var import_protocol41 = require("@codelia/protocol");
|
|
31609
31730
|
var createSkillsHandlers = ({
|
|
31610
31731
|
state,
|
|
31611
31732
|
log: log2
|
|
@@ -31617,7 +31738,7 @@ var createSkillsHandlers = ({
|
|
|
31617
31738
|
if (!forceReload) {
|
|
31618
31739
|
const cachedCatalog = state.skillsCatalogByCwd.get(workingDir);
|
|
31619
31740
|
if (cachedCatalog) {
|
|
31620
|
-
|
|
31741
|
+
sendRequestResult("skills.list", id2, {
|
|
31621
31742
|
skills: cachedCatalog.skills,
|
|
31622
31743
|
errors: cachedCatalog.errors,
|
|
31623
31744
|
truncated: cachedCatalog.truncated
|
|
@@ -31636,7 +31757,7 @@ var createSkillsHandlers = ({
|
|
|
31636
31757
|
});
|
|
31637
31758
|
} catch (error) {
|
|
31638
31759
|
sendError(id2, {
|
|
31639
|
-
code:
|
|
31760
|
+
code: import_protocol41.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31640
31761
|
message: `skills resolver init failed: ${String(error)}`
|
|
31641
31762
|
});
|
|
31642
31763
|
return;
|
|
@@ -31654,11 +31775,11 @@ var createSkillsHandlers = ({
|
|
|
31654
31775
|
errors: catalog.errors,
|
|
31655
31776
|
truncated: catalog.truncated
|
|
31656
31777
|
};
|
|
31657
|
-
|
|
31778
|
+
sendRequestResult("skills.list", id2, result);
|
|
31658
31779
|
} catch (error) {
|
|
31659
31780
|
log2(`skills.list error: ${String(error)}`);
|
|
31660
31781
|
sendError(id2, {
|
|
31661
|
-
code:
|
|
31782
|
+
code: import_protocol41.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31662
31783
|
message: `skills list failed: ${String(error)}`
|
|
31663
31784
|
});
|
|
31664
31785
|
}
|
|
@@ -31668,7 +31789,7 @@ var createSkillsHandlers = ({
|
|
|
31668
31789
|
|
|
31669
31790
|
// src/rpc/task.ts
|
|
31670
31791
|
var import_node_path49 = __toESM(require("path"), 1);
|
|
31671
|
-
var
|
|
31792
|
+
var import_protocol43 = require("@codelia/protocol");
|
|
31672
31793
|
var import_storage34 = require("@codelia/storage");
|
|
31673
31794
|
var DEFAULT_TRUNCATED2 = {
|
|
31674
31795
|
stdout: false,
|
|
@@ -31718,7 +31839,7 @@ var parseTaskId2 = (value) => {
|
|
|
31718
31839
|
var toTaskRpcError2 = (error) => {
|
|
31719
31840
|
if (!(error instanceof TaskManagerError)) {
|
|
31720
31841
|
return {
|
|
31721
|
-
code:
|
|
31842
|
+
code: import_protocol43.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31722
31843
|
message: String(error)
|
|
31723
31844
|
};
|
|
31724
31845
|
}
|
|
@@ -31727,17 +31848,17 @@ var toTaskRpcError2 = (error) => {
|
|
|
31727
31848
|
case "invalid_task_id":
|
|
31728
31849
|
case "unsupported_workspace_mode":
|
|
31729
31850
|
return {
|
|
31730
|
-
code:
|
|
31851
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31731
31852
|
message: error.message
|
|
31732
31853
|
};
|
|
31733
31854
|
case "manager_shutting_down":
|
|
31734
31855
|
return {
|
|
31735
|
-
code:
|
|
31856
|
+
code: import_protocol43.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
31736
31857
|
message: error.message
|
|
31737
31858
|
};
|
|
31738
31859
|
default:
|
|
31739
31860
|
return {
|
|
31740
|
-
code:
|
|
31861
|
+
code: import_protocol43.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
31741
31862
|
message: error.message
|
|
31742
31863
|
};
|
|
31743
31864
|
}
|
|
@@ -31789,7 +31910,7 @@ var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
|
31789
31910
|
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
31790
31911
|
return {
|
|
31791
31912
|
error: {
|
|
31792
|
-
code:
|
|
31913
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31793
31914
|
message: "timeout_seconds must be a positive number"
|
|
31794
31915
|
}
|
|
31795
31916
|
};
|
|
@@ -31803,7 +31924,7 @@ var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
|
31803
31924
|
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
31804
31925
|
return {
|
|
31805
31926
|
error: {
|
|
31806
|
-
code:
|
|
31927
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31807
31928
|
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
31808
31929
|
}
|
|
31809
31930
|
};
|
|
@@ -31818,7 +31939,7 @@ var parseShellSpawnRequest = (state, params, options) => {
|
|
|
31818
31939
|
if (!command.trim()) {
|
|
31819
31940
|
return {
|
|
31820
31941
|
error: {
|
|
31821
|
-
code:
|
|
31942
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31822
31943
|
message: "command is required for shell tasks"
|
|
31823
31944
|
}
|
|
31824
31945
|
};
|
|
@@ -31834,7 +31955,7 @@ var parseShellSpawnRequest = (state, params, options) => {
|
|
|
31834
31955
|
if (!cwd) {
|
|
31835
31956
|
return {
|
|
31836
31957
|
error: {
|
|
31837
|
-
code:
|
|
31958
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31838
31959
|
message: "cwd is outside sandbox root"
|
|
31839
31960
|
}
|
|
31840
31961
|
};
|
|
@@ -31866,11 +31987,10 @@ var subscribeTaskProgress = (state, tasks) => {
|
|
|
31866
31987
|
...task.result?.usage ? { usage: task.result.usage } : {},
|
|
31867
31988
|
updated_at: progress?.updated_at ?? task.updated_at
|
|
31868
31989
|
};
|
|
31869
|
-
void sendNotificationAsync(
|
|
31870
|
-
|
|
31871
|
-
|
|
31872
|
-
|
|
31873
|
-
});
|
|
31990
|
+
void sendNotificationAsync(
|
|
31991
|
+
state,
|
|
31992
|
+
notificationMessage("task.progress", params)
|
|
31993
|
+
);
|
|
31874
31994
|
};
|
|
31875
31995
|
tasks.onTaskUpdate((task) => {
|
|
31876
31996
|
if (!visible(task)) return;
|
|
@@ -31915,12 +32035,19 @@ var createTaskHandlers = ({
|
|
|
31915
32035
|
const handleTaskSpawn = async (id2, params) => {
|
|
31916
32036
|
if (!params || !isTaskKind(params.kind)) {
|
|
31917
32037
|
sendError(id2, {
|
|
31918
|
-
code:
|
|
32038
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31919
32039
|
message: "kind must be shell or subagent"
|
|
31920
32040
|
});
|
|
31921
32041
|
return;
|
|
31922
32042
|
}
|
|
31923
|
-
if (params.kind
|
|
32043
|
+
if (params.kind !== "shell") {
|
|
32044
|
+
if (params.kind !== "subagent" || !subagents?.isAvailable() || !getAgent) {
|
|
32045
|
+
sendError(id2, {
|
|
32046
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32047
|
+
message: `task kind ${params.kind} is not supported yet.`
|
|
32048
|
+
});
|
|
32049
|
+
return;
|
|
32050
|
+
}
|
|
31924
32051
|
try {
|
|
31925
32052
|
await state.withAdmissionLock(getAgent);
|
|
31926
32053
|
if (!state.subagentSpawn)
|
|
@@ -31930,7 +32057,8 @@ var createTaskHandlers = ({
|
|
|
31930
32057
|
...createToolContext(),
|
|
31931
32058
|
signal
|
|
31932
32059
|
});
|
|
31933
|
-
|
|
32060
|
+
sendRequestResult(
|
|
32061
|
+
"task.spawn",
|
|
31934
32062
|
id2,
|
|
31935
32063
|
subagentTaskInfo(
|
|
31936
32064
|
params.background === false ? await tasks.wait(task.task_id, { signal }) : task
|
|
@@ -31941,13 +32069,6 @@ var createTaskHandlers = ({
|
|
|
31941
32069
|
}
|
|
31942
32070
|
return;
|
|
31943
32071
|
}
|
|
31944
|
-
if (params.kind !== "shell") {
|
|
31945
|
-
sendError(id2, {
|
|
31946
|
-
code: import_protocol21.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
31947
|
-
message: `task kind ${params.kind} is not supported yet.`
|
|
31948
|
-
});
|
|
31949
|
-
return;
|
|
31950
|
-
}
|
|
31951
32072
|
const background = params.background !== false;
|
|
31952
32073
|
const parsed = parseShellSpawnRequest(state, params, { background });
|
|
31953
32074
|
if ("error" in parsed) {
|
|
@@ -31993,7 +32114,7 @@ var createTaskHandlers = ({
|
|
|
31993
32114
|
await tasks.wait(task.task_id, { signal: state.activeRunSignal })
|
|
31994
32115
|
);
|
|
31995
32116
|
assertReceiptScopeCurrent(scope);
|
|
31996
|
-
|
|
32117
|
+
sendRequestResult("task.spawn", id2, result);
|
|
31997
32118
|
} catch (error) {
|
|
31998
32119
|
if (scope.connectionSignal.aborted) return;
|
|
31999
32120
|
sendTaskError2(
|
|
@@ -32006,21 +32127,21 @@ var createTaskHandlers = ({
|
|
|
32006
32127
|
const requestedLimit = params?.limit;
|
|
32007
32128
|
if (requestedLimit !== void 0 && (!Number.isFinite(requestedLimit) || requestedLimit <= 0)) {
|
|
32008
32129
|
sendError(id2, {
|
|
32009
|
-
code:
|
|
32130
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32010
32131
|
message: "limit must be a positive number"
|
|
32011
32132
|
});
|
|
32012
32133
|
return;
|
|
32013
32134
|
}
|
|
32014
32135
|
if (params?.kind !== void 0 && !isTaskKind(params.kind)) {
|
|
32015
32136
|
sendError(id2, {
|
|
32016
|
-
code:
|
|
32137
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32017
32138
|
message: "kind must be shell or subagent"
|
|
32018
32139
|
});
|
|
32019
32140
|
return;
|
|
32020
32141
|
}
|
|
32021
32142
|
if (params?.state !== void 0 && !isTaskState(params.state)) {
|
|
32022
32143
|
sendError(id2, {
|
|
32023
|
-
code:
|
|
32144
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32024
32145
|
message: "invalid task state"
|
|
32025
32146
|
});
|
|
32026
32147
|
return;
|
|
@@ -32029,7 +32150,7 @@ var createTaskHandlers = ({
|
|
|
32029
32150
|
const limit = requestedLimit ? Math.trunc(requestedLimit) : void 0;
|
|
32030
32151
|
const tasksList = (await tasks.list({ sessionId: state.sessionId })).filter((task) => params?.kind ? task.kind === params.kind : true).filter((task) => params?.state ? task.state === params.state : true).slice(0, limit).map((task) => toTaskSummary(task, tasks.getProgress(task.task_id)));
|
|
32031
32152
|
const result = { tasks: tasksList };
|
|
32032
|
-
|
|
32153
|
+
sendRequestResult("task.list", id2, result);
|
|
32033
32154
|
} catch (error) {
|
|
32034
32155
|
sendTaskError2(id2, error);
|
|
32035
32156
|
}
|
|
@@ -32038,7 +32159,7 @@ var createTaskHandlers = ({
|
|
|
32038
32159
|
const taskId = parseTaskId2(params?.task_id);
|
|
32039
32160
|
if (!taskId) {
|
|
32040
32161
|
sendError(id2, {
|
|
32041
|
-
code:
|
|
32162
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32042
32163
|
message: "task_id is required"
|
|
32043
32164
|
});
|
|
32044
32165
|
return;
|
|
@@ -32049,7 +32170,7 @@ var createTaskHandlers = ({
|
|
|
32049
32170
|
task,
|
|
32050
32171
|
tasks.getProgress(task.task_id)
|
|
32051
32172
|
);
|
|
32052
|
-
|
|
32173
|
+
sendRequestResult("task.status", id2, result);
|
|
32053
32174
|
} catch (error) {
|
|
32054
32175
|
sendTaskError2(id2, error);
|
|
32055
32176
|
}
|
|
@@ -32058,7 +32179,7 @@ var createTaskHandlers = ({
|
|
|
32058
32179
|
const taskId = parseTaskId2(params?.task_id);
|
|
32059
32180
|
if (!taskId) {
|
|
32060
32181
|
sendError(id2, {
|
|
32061
|
-
code:
|
|
32182
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32062
32183
|
message: "task_id is required"
|
|
32063
32184
|
});
|
|
32064
32185
|
return;
|
|
@@ -32070,7 +32191,7 @@ var createTaskHandlers = ({
|
|
|
32070
32191
|
task,
|
|
32071
32192
|
tasks.getProgress(task.task_id)
|
|
32072
32193
|
);
|
|
32073
|
-
|
|
32194
|
+
sendRequestResult("task.wait", id2, result);
|
|
32074
32195
|
} catch (error) {
|
|
32075
32196
|
sendTaskError2(id2, error);
|
|
32076
32197
|
}
|
|
@@ -32079,7 +32200,7 @@ var createTaskHandlers = ({
|
|
|
32079
32200
|
const taskId = parseTaskId2(params?.task_id);
|
|
32080
32201
|
if (!taskId) {
|
|
32081
32202
|
sendError(id2, {
|
|
32082
|
-
code:
|
|
32203
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32083
32204
|
message: "task_id is required"
|
|
32084
32205
|
});
|
|
32085
32206
|
return;
|
|
@@ -32093,7 +32214,7 @@ var createTaskHandlers = ({
|
|
|
32093
32214
|
task,
|
|
32094
32215
|
tasks.getProgress(task.task_id)
|
|
32095
32216
|
);
|
|
32096
|
-
|
|
32217
|
+
sendRequestResult("task.cancel", id2, result);
|
|
32097
32218
|
} catch (error) {
|
|
32098
32219
|
sendTaskError2(id2, error);
|
|
32099
32220
|
}
|
|
@@ -32102,7 +32223,7 @@ var createTaskHandlers = ({
|
|
|
32102
32223
|
const taskId = parseTaskId2(params?.task_id);
|
|
32103
32224
|
if (!taskId) {
|
|
32104
32225
|
sendError(id2, {
|
|
32105
|
-
code:
|
|
32226
|
+
code: import_protocol43.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32106
32227
|
message: "task_id is required"
|
|
32107
32228
|
});
|
|
32108
32229
|
return;
|
|
@@ -32110,7 +32231,7 @@ var createTaskHandlers = ({
|
|
|
32110
32231
|
try {
|
|
32111
32232
|
const task = await requireScope(taskId);
|
|
32112
32233
|
const result = task.state === "completed" || task.state === "failed" || task.state === "cancelled" ? toTaskInfo(task, tasks.getProgress(task.task_id)) : null;
|
|
32113
|
-
|
|
32234
|
+
sendRequestResult("task.result", id2, result);
|
|
32114
32235
|
} catch (error) {
|
|
32115
32236
|
sendTaskError2(id2, error);
|
|
32116
32237
|
}
|
|
@@ -32143,31 +32264,10 @@ var isRecord9 = (value) => typeof value === "object" && value !== null && !Array
|
|
|
32143
32264
|
var validateRequestParams = (method, params) => {
|
|
32144
32265
|
if (params !== void 0 && !isRecord9(params))
|
|
32145
32266
|
return "params must be an object";
|
|
32146
|
-
if (method === "initialize" && !isRecord9(params))
|
|
32147
|
-
return "params are required";
|
|
32148
32267
|
if (method === "run.cancel") {
|
|
32149
32268
|
if (!isRecord9(params) || typeof params.run_id !== "string" || !params.run_id.trim()) {
|
|
32150
32269
|
return "run_id is required";
|
|
32151
32270
|
}
|
|
32152
|
-
if (params.reason !== void 0 && typeof params.reason !== "string") {
|
|
32153
|
-
return "reason must be a string";
|
|
32154
|
-
}
|
|
32155
|
-
}
|
|
32156
|
-
if (method === "run.steer") {
|
|
32157
|
-
if (!isRecord9(params) || typeof params.run_id !== "string" || !params.run_id.trim()) {
|
|
32158
|
-
return "run_id is required";
|
|
32159
|
-
}
|
|
32160
|
-
if (!isRecord9(params.input)) {
|
|
32161
|
-
return "input is required";
|
|
32162
|
-
}
|
|
32163
|
-
if (params.client_steer_id !== void 0 && typeof params.client_steer_id !== "string") {
|
|
32164
|
-
return "client_steer_id must be a string";
|
|
32165
|
-
}
|
|
32166
|
-
}
|
|
32167
|
-
if (method === "run.start" && isRecord9(params)) {
|
|
32168
|
-
if (params.session_id !== void 0 && typeof params.session_id !== "string") {
|
|
32169
|
-
return "session_id must be a string";
|
|
32170
|
-
}
|
|
32171
32271
|
}
|
|
32172
32272
|
return null;
|
|
32173
32273
|
};
|
|
@@ -32411,7 +32511,10 @@ var createRuntimeHandlers = ({
|
|
|
32411
32511
|
taskManager: injectedTaskManager,
|
|
32412
32512
|
outputCache: toolOutputCacheStore ?? void 0
|
|
32413
32513
|
}) : null;
|
|
32414
|
-
const handleInitialize = async (id2,
|
|
32514
|
+
const handleInitialize = async (id2, raw) => {
|
|
32515
|
+
const parsed = parseRequestParams("initialize", raw);
|
|
32516
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
32517
|
+
const params = parsed.params;
|
|
32415
32518
|
let resolvedTheme;
|
|
32416
32519
|
const environment2 = state.effectiveEnvironment;
|
|
32417
32520
|
if (isTuiLocalEnvironment(environment2)) {
|
|
@@ -32492,7 +32595,7 @@ var createRuntimeHandlers = ({
|
|
|
32492
32595
|
}
|
|
32493
32596
|
} : resolvedTheme ? { tui: { theme: resolvedTheme } } : {}
|
|
32494
32597
|
};
|
|
32495
|
-
|
|
32598
|
+
sendRequestResult("initialize", id2, result);
|
|
32496
32599
|
log2(`initialize from ${params.client?.name ?? "unknown"}`);
|
|
32497
32600
|
state.lastClientInfo = params.client ?? null;
|
|
32498
32601
|
state.setUiCapabilities(params.ui_capabilities);
|
|
@@ -32505,25 +32608,27 @@ var createRuntimeHandlers = ({
|
|
|
32505
32608
|
`ui.context.update cwd=${params.cwd ?? "-"} file=${params.active_file?.path ?? "-"}`
|
|
32506
32609
|
);
|
|
32507
32610
|
};
|
|
32508
|
-
const handleThemeSet = async (id2,
|
|
32611
|
+
const handleThemeSet = async (id2, raw) => {
|
|
32509
32612
|
if (state.activeRunId) {
|
|
32510
32613
|
sendError(id2, {
|
|
32511
|
-
code:
|
|
32614
|
+
code: import_protocol45.RPC_ERROR_CODE.RUNTIME_BUSY,
|
|
32512
32615
|
message: "runtime busy"
|
|
32513
32616
|
});
|
|
32514
32617
|
return;
|
|
32515
32618
|
}
|
|
32516
|
-
const
|
|
32619
|
+
const parsed = parseRequestParams("theme.set", raw);
|
|
32620
|
+
if (!parsed.ok) return sendError(id2, parsed.error);
|
|
32621
|
+
const name2 = parsed.params.name.trim().toLowerCase();
|
|
32517
32622
|
if (!name2) {
|
|
32518
32623
|
sendError(id2, {
|
|
32519
|
-
code:
|
|
32624
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32520
32625
|
message: "theme name is required"
|
|
32521
32626
|
});
|
|
32522
32627
|
return;
|
|
32523
32628
|
}
|
|
32524
32629
|
if (!SUPPORTED_TUI_THEMES.has(name2)) {
|
|
32525
32630
|
sendError(id2, {
|
|
32526
|
-
code:
|
|
32631
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32527
32632
|
message: `unsupported theme: ${name2}`
|
|
32528
32633
|
});
|
|
32529
32634
|
return;
|
|
@@ -32531,16 +32636,15 @@ var createRuntimeHandlers = ({
|
|
|
32531
32636
|
const workingDir = state.lastUiContext?.cwd ?? state.runtimeWorkingDir ?? process.cwd();
|
|
32532
32637
|
try {
|
|
32533
32638
|
const target2 = await updateEnvironmentTuiTheme(state, workingDir, name2);
|
|
32534
|
-
|
|
32639
|
+
sendRequestResult("theme.set", id2, {
|
|
32535
32640
|
name: name2,
|
|
32536
32641
|
scope: target2.scope,
|
|
32537
32642
|
path: target2.path
|
|
32538
|
-
};
|
|
32539
|
-
sendResult(id2, result);
|
|
32643
|
+
});
|
|
32540
32644
|
log2(`theme.set ${name2} scope=${target2.scope} path=${target2.path}`);
|
|
32541
32645
|
} catch (error) {
|
|
32542
32646
|
sendError(id2, {
|
|
32543
|
-
code:
|
|
32647
|
+
code: import_protocol45.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
32544
32648
|
message: String(error)
|
|
32545
32649
|
});
|
|
32546
32650
|
}
|
|
@@ -32561,7 +32665,7 @@ var createRuntimeHandlers = ({
|
|
|
32561
32665
|
const skillsEnabled = state.effectiveEnvironment.context.skills === "from-config";
|
|
32562
32666
|
const themeSetEnabled = isTuiLocalEnvironment(state.effectiveEnvironment) && state.effectiveEnvironment.config.source !== "disabled";
|
|
32563
32667
|
const rejectDisabled = (message) => sendError(req.id, {
|
|
32564
|
-
code:
|
|
32668
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32565
32669
|
message
|
|
32566
32670
|
});
|
|
32567
32671
|
switch (req.method) {
|
|
@@ -32579,69 +32683,66 @@ var createRuntimeHandlers = ({
|
|
|
32579
32683
|
case "goal.clear":
|
|
32580
32684
|
case "goal.continue":
|
|
32581
32685
|
return handleGoal(req.id, req.method, req.params);
|
|
32582
|
-
case "run.start":
|
|
32583
|
-
|
|
32584
|
-
|
|
32585
|
-
return
|
|
32586
|
-
|
|
32587
|
-
|
|
32588
|
-
|
|
32589
|
-
return
|
|
32590
|
-
|
|
32591
|
-
|
|
32592
|
-
case "
|
|
32593
|
-
|
|
32686
|
+
case "run.start": {
|
|
32687
|
+
const parsed = parseRequestParams("run.start", req.params);
|
|
32688
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32689
|
+
return handleRunStart(req.id, parsed.params);
|
|
32690
|
+
}
|
|
32691
|
+
case "run.steer": {
|
|
32692
|
+
const parsed = parseRequestParams("run.steer", req.params);
|
|
32693
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32694
|
+
return handleRunSteer(req.id, parsed.params);
|
|
32695
|
+
}
|
|
32696
|
+
case "run.cancel": {
|
|
32697
|
+
const parsed = parseRequestParams("run.cancel", req.params);
|
|
32698
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32699
|
+
return handleRunCancel(req.id, parsed.params);
|
|
32700
|
+
}
|
|
32701
|
+
case "session.list": {
|
|
32702
|
+
const parsed = parseRequestParams("session.list", req.params);
|
|
32703
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32704
|
+
const params = parsed.params;
|
|
32705
|
+
return handleSessionList(req.id, params);
|
|
32706
|
+
}
|
|
32707
|
+
case "session.history": {
|
|
32708
|
+
const parsed = parseRequestParams("session.history", req.params);
|
|
32709
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32710
|
+
const params = parsed.params;
|
|
32711
|
+
return handleSessionHistory(req.id, params);
|
|
32712
|
+
}
|
|
32713
|
+
case "session.open": {
|
|
32714
|
+
const parsed = parseRequestParams("session.open", req.params);
|
|
32715
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32716
|
+
const params = parsed.params;
|
|
32717
|
+
return handleSessionOpen(req.id, params);
|
|
32718
|
+
}
|
|
32594
32719
|
case "session.update":
|
|
32595
32720
|
return handleSessionUpdate(req.id, req.params);
|
|
32596
32721
|
case "auth.logout":
|
|
32597
32722
|
return handleAuthLogout(req.id, req.params);
|
|
32598
32723
|
case "auth.status":
|
|
32599
|
-
return authHandlers.handleStatus(
|
|
32600
|
-
req.id,
|
|
32601
|
-
req.params
|
|
32602
|
-
);
|
|
32724
|
+
return authHandlers.handleStatus(req.id, req.params);
|
|
32603
32725
|
case "auth.login":
|
|
32604
32726
|
return authHandlers.handleLogin(req.id, req.params);
|
|
32605
32727
|
case "auth.login.complete":
|
|
32606
|
-
return authHandlers.handleLoginComplete(
|
|
32607
|
-
req.id,
|
|
32608
|
-
req.params
|
|
32609
|
-
);
|
|
32728
|
+
return authHandlers.handleLoginComplete(req.id, req.params);
|
|
32610
32729
|
case "auth.login.cancel":
|
|
32611
|
-
return authHandlers.handleLoginCancel(
|
|
32612
|
-
req.id,
|
|
32613
|
-
req.params
|
|
32614
|
-
);
|
|
32730
|
+
return authHandlers.handleLoginCancel(req.id, req.params);
|
|
32615
32731
|
case "auth.storage.resolve_conflict":
|
|
32616
|
-
return authHandlers.handleResolveConflict(
|
|
32617
|
-
req.id,
|
|
32618
|
-
req.params
|
|
32619
|
-
);
|
|
32732
|
+
return authHandlers.handleResolveConflict(req.id, req.params);
|
|
32620
32733
|
case "config.get":
|
|
32621
|
-
return configHandlers.handleConfigGet(
|
|
32622
|
-
req.id,
|
|
32623
|
-
req.params
|
|
32624
|
-
);
|
|
32734
|
+
return configHandlers.handleConfigGet(req.id, req.params);
|
|
32625
32735
|
case "config.set":
|
|
32626
|
-
return configHandlers.handleConfigSet(
|
|
32627
|
-
req.id,
|
|
32628
|
-
req.params
|
|
32629
|
-
);
|
|
32736
|
+
return configHandlers.handleConfigSet(req.id, req.params);
|
|
32630
32737
|
case "permissions.list":
|
|
32631
|
-
return permissionsHandlers.handlePermissionsList(
|
|
32632
|
-
req.id,
|
|
32633
|
-
req.params
|
|
32634
|
-
);
|
|
32738
|
+
return permissionsHandlers.handlePermissionsList(req.id, req.params);
|
|
32635
32739
|
case "permissions.projectTrust.set":
|
|
32636
32740
|
return permissionsHandlers.handleProjectAllowTrustSet(
|
|
32637
32741
|
req.id,
|
|
32638
32742
|
req.params
|
|
32639
32743
|
);
|
|
32640
32744
|
case "permissions.remove":
|
|
32641
|
-
return permissionsHandlers.handlePermissionsRemove(
|
|
32642
|
-
req.id,
|
|
32643
|
-
req.params
|
|
32644
|
-
);
|
|
32745
|
+
return permissionsHandlers.handlePermissionsRemove(req.id, req.params);
|
|
32645
32746
|
case "sandbox.get":
|
|
32646
32747
|
case "sandbox.set":
|
|
32647
32748
|
return handleSandbox(state, req.id, req.method, req.params);
|
|
@@ -32656,139 +32757,158 @@ var createRuntimeHandlers = ({
|
|
|
32656
32757
|
case "image.artifact.get":
|
|
32657
32758
|
return imageHandlers.handle(req.id, "artifact", req.params);
|
|
32658
32759
|
case "model.set":
|
|
32659
|
-
return afterSessionOpen(
|
|
32660
|
-
|
|
32661
|
-
);
|
|
32662
|
-
|
|
32663
|
-
return handleToolCall(req.id,
|
|
32664
|
-
|
|
32760
|
+
return afterSessionOpen(() => handleModelSet(req.id, req.params));
|
|
32761
|
+
case "tool.call": {
|
|
32762
|
+
const parsed = parseRequestParams("tool.call", req.params);
|
|
32763
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32764
|
+
return handleToolCall(req.id, parsed.params);
|
|
32765
|
+
}
|
|
32766
|
+
case "shell.exec": {
|
|
32665
32767
|
if (!shellHandlers)
|
|
32666
32768
|
return rejectDisabled("process execution is disabled");
|
|
32667
|
-
|
|
32668
|
-
|
|
32669
|
-
|
|
32670
|
-
|
|
32671
|
-
case "shell.start":
|
|
32769
|
+
const parsed = parseRequestParams("shell.exec", req.params);
|
|
32770
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32771
|
+
return shellHandlers.handleShellExec(req.id, parsed.params);
|
|
32772
|
+
}
|
|
32773
|
+
case "shell.start": {
|
|
32672
32774
|
if (!shellHandlers)
|
|
32673
32775
|
return rejectDisabled("process execution is disabled");
|
|
32674
|
-
|
|
32675
|
-
|
|
32676
|
-
|
|
32677
|
-
|
|
32678
|
-
case "shell.list":
|
|
32776
|
+
const parsed = parseRequestParams("shell.start", req.params);
|
|
32777
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32778
|
+
return shellHandlers.handleShellStart(req.id, parsed.params);
|
|
32779
|
+
}
|
|
32780
|
+
case "shell.list": {
|
|
32679
32781
|
if (!shellHandlers)
|
|
32680
32782
|
return rejectDisabled("process execution is disabled");
|
|
32681
|
-
|
|
32682
|
-
|
|
32683
|
-
|
|
32684
|
-
|
|
32685
|
-
case "shell.status":
|
|
32783
|
+
const parsed = parseRequestParams("shell.list", req.params);
|
|
32784
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32785
|
+
return shellHandlers.handleShellList(req.id, parsed.params);
|
|
32786
|
+
}
|
|
32787
|
+
case "shell.status": {
|
|
32686
32788
|
if (!shellHandlers)
|
|
32687
32789
|
return rejectDisabled("process execution is disabled");
|
|
32688
|
-
|
|
32689
|
-
|
|
32690
|
-
|
|
32691
|
-
|
|
32692
|
-
case "shell.output":
|
|
32790
|
+
const parsed = parseRequestParams("shell.status", req.params);
|
|
32791
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32792
|
+
return shellHandlers.handleShellStatus(req.id, parsed.params);
|
|
32793
|
+
}
|
|
32794
|
+
case "shell.output": {
|
|
32693
32795
|
if (!shellHandlers)
|
|
32694
32796
|
return rejectDisabled("process execution is disabled");
|
|
32695
|
-
|
|
32696
|
-
|
|
32697
|
-
|
|
32698
|
-
|
|
32699
|
-
case "shell.wait":
|
|
32797
|
+
const parsed = parseRequestParams("shell.output", req.params);
|
|
32798
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32799
|
+
return shellHandlers.handleShellOutput(req.id, parsed.params);
|
|
32800
|
+
}
|
|
32801
|
+
case "shell.wait": {
|
|
32700
32802
|
if (!shellHandlers)
|
|
32701
32803
|
return rejectDisabled("process execution is disabled");
|
|
32702
|
-
|
|
32703
|
-
|
|
32704
|
-
|
|
32705
|
-
|
|
32706
|
-
case "shell.detach":
|
|
32804
|
+
const parsed = parseRequestParams("shell.wait", req.params);
|
|
32805
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32806
|
+
return shellHandlers.handleShellWait(req.id, parsed.params);
|
|
32807
|
+
}
|
|
32808
|
+
case "shell.detach": {
|
|
32707
32809
|
if (!shellHandlers)
|
|
32708
32810
|
return rejectDisabled("process execution is disabled");
|
|
32709
|
-
|
|
32710
|
-
|
|
32711
|
-
|
|
32712
|
-
|
|
32713
|
-
case "shell.cancel":
|
|
32811
|
+
const parsed = parseRequestParams("shell.detach", req.params);
|
|
32812
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32813
|
+
return shellHandlers.handleShellDetach(req.id, parsed.params);
|
|
32814
|
+
}
|
|
32815
|
+
case "shell.cancel": {
|
|
32714
32816
|
if (!shellHandlers)
|
|
32715
32817
|
return rejectDisabled("process execution is disabled");
|
|
32716
|
-
|
|
32717
|
-
|
|
32718
|
-
|
|
32719
|
-
|
|
32720
|
-
case "task.spawn":
|
|
32818
|
+
const parsed = parseRequestParams("shell.cancel", req.params);
|
|
32819
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32820
|
+
return shellHandlers.handleShellCancel(req.id, parsed.params);
|
|
32821
|
+
}
|
|
32822
|
+
case "task.spawn": {
|
|
32721
32823
|
if (!taskHandlers)
|
|
32722
32824
|
return rejectDisabled("process execution is disabled");
|
|
32723
|
-
|
|
32724
|
-
|
|
32725
|
-
|
|
32726
|
-
|
|
32727
|
-
case "task.list":
|
|
32825
|
+
const parsed = parseRequestParams("task.spawn", req.params);
|
|
32826
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32827
|
+
return taskHandlers.handleTaskSpawn(req.id, parsed.params);
|
|
32828
|
+
}
|
|
32829
|
+
case "task.list": {
|
|
32728
32830
|
if (!taskHandlers)
|
|
32729
32831
|
return rejectDisabled("process execution is disabled");
|
|
32730
|
-
|
|
32731
|
-
|
|
32732
|
-
|
|
32733
|
-
|
|
32734
|
-
case "task.status":
|
|
32832
|
+
const parsed = parseRequestParams("task.list", req.params);
|
|
32833
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32834
|
+
return taskHandlers.handleTaskList(req.id, parsed.params);
|
|
32835
|
+
}
|
|
32836
|
+
case "task.status": {
|
|
32735
32837
|
if (!taskHandlers)
|
|
32736
32838
|
return rejectDisabled("process execution is disabled");
|
|
32737
|
-
|
|
32738
|
-
|
|
32739
|
-
|
|
32740
|
-
|
|
32741
|
-
case "task.wait":
|
|
32839
|
+
const parsed = parseRequestParams("task.status", req.params);
|
|
32840
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32841
|
+
return taskHandlers.handleTaskStatus(req.id, parsed.params);
|
|
32842
|
+
}
|
|
32843
|
+
case "task.wait": {
|
|
32742
32844
|
if (!taskHandlers)
|
|
32743
32845
|
return rejectDisabled("process execution is disabled");
|
|
32744
|
-
|
|
32745
|
-
|
|
32746
|
-
|
|
32747
|
-
|
|
32748
|
-
case "task.cancel":
|
|
32846
|
+
const parsed = parseRequestParams("task.wait", req.params);
|
|
32847
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32848
|
+
return taskHandlers.handleTaskWait(req.id, parsed.params);
|
|
32849
|
+
}
|
|
32850
|
+
case "task.cancel": {
|
|
32749
32851
|
if (!taskHandlers)
|
|
32750
32852
|
return rejectDisabled("process execution is disabled");
|
|
32751
|
-
|
|
32752
|
-
|
|
32753
|
-
|
|
32754
|
-
|
|
32755
|
-
case "task.result":
|
|
32853
|
+
const parsed = parseRequestParams("task.cancel", req.params);
|
|
32854
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32855
|
+
return taskHandlers.handleTaskCancel(req.id, parsed.params);
|
|
32856
|
+
}
|
|
32857
|
+
case "task.result": {
|
|
32756
32858
|
if (!taskHandlers)
|
|
32757
32859
|
return rejectDisabled("process execution is disabled");
|
|
32758
|
-
|
|
32759
|
-
|
|
32760
|
-
|
|
32761
|
-
|
|
32762
|
-
case "mcp.list":
|
|
32860
|
+
const parsed = parseRequestParams("task.result", req.params);
|
|
32861
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32862
|
+
return taskHandlers.handleTaskResult(req.id, parsed.params);
|
|
32863
|
+
}
|
|
32864
|
+
case "mcp.list": {
|
|
32763
32865
|
if (!mcpEnabled) {
|
|
32764
|
-
return
|
|
32866
|
+
return sendRequestResult("mcp.list", req.id, { servers: [] });
|
|
32765
32867
|
}
|
|
32868
|
+
const parsed = parseRequestParams("mcp.list", req.params);
|
|
32869
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32766
32870
|
await mcpManager.start?.();
|
|
32767
|
-
return
|
|
32871
|
+
return sendRequestResult(
|
|
32872
|
+
"mcp.list",
|
|
32768
32873
|
req.id,
|
|
32769
|
-
mcpManager.list(
|
|
32874
|
+
mcpManager.list(parsed.params.scope)
|
|
32770
32875
|
);
|
|
32771
|
-
|
|
32876
|
+
}
|
|
32877
|
+
case "skills.list": {
|
|
32772
32878
|
if (!skillsEnabled) return rejectDisabled("skills are disabled");
|
|
32773
|
-
|
|
32774
|
-
|
|
32775
|
-
return
|
|
32776
|
-
|
|
32879
|
+
const parsed = parseRequestParams("skills.list", req.params);
|
|
32880
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32881
|
+
return handleSkillsList(req.id, parsed.params);
|
|
32882
|
+
}
|
|
32883
|
+
case "context.inspect": {
|
|
32884
|
+
const parsed = parseRequestParams("context.inspect", req.params);
|
|
32885
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32886
|
+
return handleContextInspect(req.id, parsed.params);
|
|
32887
|
+
}
|
|
32888
|
+
case "context.usage": {
|
|
32889
|
+
const parsed = parseRequestParams("context.usage", req.params);
|
|
32890
|
+
if (!parsed.ok) return sendError(req.id, parsed.error);
|
|
32777
32891
|
return contextUsageHandlers.handleContextUsage(req.id);
|
|
32892
|
+
}
|
|
32778
32893
|
case "theme.set":
|
|
32779
32894
|
if (!themeSetEnabled)
|
|
32780
32895
|
return rejectDisabled("theme setting is disabled");
|
|
32781
32896
|
return handleThemeSet(req.id, req.params);
|
|
32782
32897
|
default:
|
|
32783
32898
|
return sendError(req.id, {
|
|
32784
|
-
code:
|
|
32899
|
+
code: import_protocol45.RPC_ERROR_CODE.METHOD_NOT_FOUND,
|
|
32785
32900
|
message: "method not found"
|
|
32786
32901
|
});
|
|
32787
32902
|
}
|
|
32788
32903
|
};
|
|
32789
32904
|
const handleNotification = (note) => {
|
|
32790
32905
|
if (note.method === "ui.context.update") {
|
|
32791
|
-
|
|
32906
|
+
const params = parseUiNotificationParams(
|
|
32907
|
+
"ui.context.update",
|
|
32908
|
+
note.params
|
|
32909
|
+
);
|
|
32910
|
+
if (params) handleUiContextUpdate(params);
|
|
32911
|
+
else log2("ui.context.update ignored: params do not match the protocol");
|
|
32792
32912
|
}
|
|
32793
32913
|
};
|
|
32794
32914
|
const handleResponse = (res) => {
|
|
@@ -32804,7 +32924,7 @@ var createRuntimeHandlers = ({
|
|
|
32804
32924
|
if (msg.jsonrpc !== "2.0" || "method" in msg && typeof msg.method !== "string") {
|
|
32805
32925
|
if (id2 !== void 0) {
|
|
32806
32926
|
sendError(id2, {
|
|
32807
|
-
code:
|
|
32927
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_REQUEST,
|
|
32808
32928
|
message: "invalid request"
|
|
32809
32929
|
});
|
|
32810
32930
|
} else {
|
|
@@ -32821,7 +32941,7 @@ var createRuntimeHandlers = ({
|
|
|
32821
32941
|
if (invalid) {
|
|
32822
32942
|
if (id2 !== void 0)
|
|
32823
32943
|
sendError(id2, {
|
|
32824
|
-
code:
|
|
32944
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
32825
32945
|
message: invalid
|
|
32826
32946
|
});
|
|
32827
32947
|
else log2(`invalid rpc notification: ${msg.method}`);
|
|
@@ -32835,7 +32955,7 @@ var createRuntimeHandlers = ({
|
|
|
32835
32955
|
if (!hasRpcResponse(id2)) {
|
|
32836
32956
|
try {
|
|
32837
32957
|
sendError(id2, {
|
|
32838
|
-
code:
|
|
32958
|
+
code: import_protocol45.RPC_ERROR_CODE.RUNTIME_INTERNAL,
|
|
32839
32959
|
message: "internal runtime error"
|
|
32840
32960
|
});
|
|
32841
32961
|
} catch {
|
|
@@ -32860,7 +32980,7 @@ var createRuntimeHandlers = ({
|
|
|
32860
32980
|
handleResponse(msg);
|
|
32861
32981
|
} else if (id2 !== void 0) {
|
|
32862
32982
|
sendError(id2, {
|
|
32863
|
-
code:
|
|
32983
|
+
code: import_protocol45.RPC_ERROR_CODE.INVALID_REQUEST,
|
|
32864
32984
|
message: "invalid request"
|
|
32865
32985
|
});
|
|
32866
32986
|
} else {
|
|
@@ -32878,44 +32998,44 @@ var import_node_url4 = require("url");
|
|
|
32878
32998
|
|
|
32879
32999
|
// src/subagents/bootstrap.ts
|
|
32880
33000
|
var import_node_path50 = __toESM(require("path"), 1);
|
|
32881
|
-
var
|
|
32882
|
-
var
|
|
32883
|
-
var permissionRule =
|
|
32884
|
-
tool:
|
|
32885
|
-
command:
|
|
32886
|
-
command_glob:
|
|
32887
|
-
skill_name:
|
|
33001
|
+
var import_shared_types11 = require("@codelia/shared-types");
|
|
33002
|
+
var import_zod47 = require("zod");
|
|
33003
|
+
var permissionRule = import_zod47.z.object({
|
|
33004
|
+
tool: import_zod47.z.string(),
|
|
33005
|
+
command: import_zod47.z.string().optional(),
|
|
33006
|
+
command_glob: import_zod47.z.string().optional(),
|
|
33007
|
+
skill_name: import_zod47.z.string().optional()
|
|
32888
33008
|
}).passthrough();
|
|
32889
|
-
var subagentBootstrapSchema =
|
|
32890
|
-
version:
|
|
32891
|
-
task_id:
|
|
32892
|
-
prompt:
|
|
32893
|
-
workspace_root:
|
|
32894
|
-
protected_paths:
|
|
32895
|
-
lineage:
|
|
33009
|
+
var subagentBootstrapSchema = import_zod47.z.object({
|
|
33010
|
+
version: import_zod47.z.literal(1),
|
|
33011
|
+
task_id: import_zod47.z.string().uuid(),
|
|
33012
|
+
prompt: import_zod47.z.string().min(1).max(32768),
|
|
33013
|
+
workspace_root: import_zod47.z.string().refine(import_node_path50.default.isAbsolute),
|
|
33014
|
+
protected_paths: import_zod47.z.array(import_zod47.z.string().refine(import_node_path50.default.isAbsolute)).optional(),
|
|
33015
|
+
lineage: import_zod47.z.object({
|
|
32896
33016
|
name: subagentNameSchema.optional(),
|
|
32897
|
-
tree_id:
|
|
32898
|
-
node_id:
|
|
32899
|
-
parent_node_id:
|
|
32900
|
-
owner_session_id:
|
|
32901
|
-
depth:
|
|
32902
|
-
spawn_index:
|
|
32903
|
-
context_mode:
|
|
32904
|
-
effective_policy_id:
|
|
32905
|
-
workspace_lease_id:
|
|
33017
|
+
tree_id: import_zod47.z.string().min(1),
|
|
33018
|
+
node_id: import_zod47.z.string().uuid(),
|
|
33019
|
+
parent_node_id: import_zod47.z.string().min(1),
|
|
33020
|
+
owner_session_id: import_zod47.z.string().min(1),
|
|
33021
|
+
depth: import_zod47.z.literal(1),
|
|
33022
|
+
spawn_index: import_zod47.z.number().int().positive(),
|
|
33023
|
+
context_mode: import_zod47.z.literal("fresh"),
|
|
33024
|
+
effective_policy_id: import_zod47.z.string().min(1),
|
|
33025
|
+
workspace_lease_id: import_zod47.z.string().min(1)
|
|
32906
33026
|
}).strict(),
|
|
32907
33027
|
model: subagentModelSchema,
|
|
32908
|
-
permission:
|
|
32909
|
-
tool_allowlist:
|
|
32910
|
-
workspace_access:
|
|
32911
|
-
approval_mode:
|
|
32912
|
-
sandbox_mode:
|
|
32913
|
-
parent_permissions:
|
|
32914
|
-
allow:
|
|
32915
|
-
deny:
|
|
33028
|
+
permission: import_zod47.z.object({
|
|
33029
|
+
tool_allowlist: import_zod47.z.array(import_zod47.z.enum(WRITABLE_TOOLS)).max(WRITABLE_TOOLS.length),
|
|
33030
|
+
workspace_access: import_zod47.z.enum(["read-only", "read-write"]),
|
|
33031
|
+
approval_mode: import_zod47.z.enum(["minimal", "trusted", "full-access"]).optional(),
|
|
33032
|
+
sandbox_mode: import_zod47.z.enum(import_shared_types11.sandboxModes).optional(),
|
|
33033
|
+
parent_permissions: import_zod47.z.object({
|
|
33034
|
+
allow: import_zod47.z.array(permissionRule).optional(),
|
|
33035
|
+
deny: import_zod47.z.array(permissionRule).optional()
|
|
32916
33036
|
}).strict().optional(),
|
|
32917
|
-
max_steps:
|
|
32918
|
-
timeout_seconds:
|
|
33037
|
+
max_steps: import_zod47.z.number().int().min(1).max(200),
|
|
33038
|
+
timeout_seconds: import_zod47.z.number().int().min(1).max(3600).optional()
|
|
32919
33039
|
}).strict()
|
|
32920
33040
|
}).strict().refine(
|
|
32921
33041
|
(input) => input.lineage.node_id === input.task_id && input.lineage.workspace_lease_id === input.task_id && (input.permission.workspace_access === "read-write" || input.permission.tool_allowlist.every(
|