codelocal 1.5.0-beta.1 → 1.5.0-beta.2
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/client-v2.js +13 -7
- package/dist/log.js +16 -3
- package/package.json +1 -1
package/dist/client-v2.js
CHANGED
|
@@ -875,19 +875,25 @@ async function connect() {
|
|
|
875
875
|
return;
|
|
876
876
|
const requestId = String(message.requestId ?? message.id ?? "");
|
|
877
877
|
const startedAt = Date.now();
|
|
878
|
-
|
|
879
|
-
|
|
878
|
+
const trace = {
|
|
879
|
+
mcpSessionId: typeof message.sessionId === "string" ? message.sessionId : undefined,
|
|
880
|
+
workspaceKey: WORKSPACE_KEY,
|
|
881
|
+
workspaceId: WORKSPACE_ID,
|
|
882
|
+
workspaceName: WORKSPACE_NAME,
|
|
883
|
+
};
|
|
884
|
+
log("info", "tool.received", { requestId, ...trace, tool: message.tool, args: summarizeToolArgs(message.tool, message.args) });
|
|
885
|
+
await audit({ event: "tool.received", requestId, mcpSessionId: trace.mcpSessionId, workspaceKey: WORKSPACE_KEY, tool: message.tool });
|
|
880
886
|
try {
|
|
881
887
|
const result = await executeRequest(message);
|
|
882
888
|
ws.send(JSON.stringify({ type: "tool_result", protocolVersion: PROTOCOL_VERSION, requestId, id: requestId, ok: true, result, metadata: { durationMs: Date.now() - startedAt } }));
|
|
883
|
-
log("info", "tool.completed", { requestId, tool: message.tool, durationMs: Date.now() - startedAt });
|
|
884
|
-
await audit({ event: "tool.completed", requestId, workspaceKey: WORKSPACE_KEY, tool: message.tool, status: "ok" });
|
|
889
|
+
log("info", "tool.completed", { requestId, ...trace, tool: message.tool, durationMs: Date.now() - startedAt });
|
|
890
|
+
await audit({ event: "tool.completed", requestId, mcpSessionId: trace.mcpSessionId, workspaceKey: WORKSPACE_KEY, tool: message.tool, status: "ok" });
|
|
885
891
|
}
|
|
886
892
|
catch (error) {
|
|
887
893
|
const normalized = normalizeError(error);
|
|
888
894
|
ws.send(JSON.stringify({ type: "tool_result", protocolVersion: PROTOCOL_VERSION, requestId, id: requestId, ok: false, ...normalized, error: normalized.errorMessage, metadata: { durationMs: Date.now() - startedAt } }));
|
|
889
|
-
log("error", "tool.failed", { requestId, tool: message.tool, durationMs: Date.now() - startedAt, error });
|
|
890
|
-
await audit({ event: "tool.failed", requestId, workspaceKey: WORKSPACE_KEY, tool: message.tool, status: normalized.errorCode, detail: normalized.errorMessage });
|
|
895
|
+
log("error", "tool.failed", { requestId, ...trace, tool: message.tool, durationMs: Date.now() - startedAt, error });
|
|
896
|
+
await audit({ event: "tool.failed", requestId, mcpSessionId: trace.mcpSessionId, workspaceKey: WORKSPACE_KEY, tool: message.tool, status: normalized.errorCode, detail: normalized.errorMessage });
|
|
891
897
|
}
|
|
892
898
|
});
|
|
893
899
|
ws.on("close", (code, reason) => {
|
|
@@ -906,5 +912,5 @@ async function shutdown() {
|
|
|
906
912
|
}
|
|
907
913
|
process.on("SIGINT", async () => { await shutdown(); process.exit(0); });
|
|
908
914
|
process.on("SIGTERM", async () => { await shutdown(); process.exit(0); });
|
|
909
|
-
log("info", "client.started", { version: "1.5.0-beta.
|
|
915
|
+
log("info", "client.started", { version: "1.5.0-beta.2", protocolVersion: PROTOCOL_VERSION, deviceId: DEVICE_ID, workspaceId: WORKSPACE_ID, projectRoot: root, shell: ALLOW_SHELL, approvalMode: APPROVAL_MODE, terminalApproval: "chat-mediated", networkPolicy: NETWORK_POLICY, hostname: os.hostname() });
|
|
910
916
|
void connect();
|
package/dist/log.js
CHANGED
|
@@ -63,6 +63,16 @@ function compact(value, max = 76) {
|
|
|
63
63
|
const text = redactText(String(value ?? "")).replace(/\s+/g, " ").trim();
|
|
64
64
|
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
65
65
|
}
|
|
66
|
+
export function formatToolTraceContext(fields) {
|
|
67
|
+
const rawSessionId = String(fields.mcpSessionId ?? fields.sessionId ?? "").trim();
|
|
68
|
+
const sessionId = rawSessionId ? rawSessionId.slice(0, 8) : "legacy";
|
|
69
|
+
const workspaceName = String(fields.workspaceName ?? "").trim();
|
|
70
|
+
const workspaceId = String(fields.workspaceId ?? "").trim();
|
|
71
|
+
const workspace = compact(workspaceName && workspaceId && workspaceName !== workspaceId
|
|
72
|
+
? `${workspaceName} · ${workspaceId}`
|
|
73
|
+
: workspaceName || workspaceId || fields.workspaceKey || "workspace", 48);
|
|
74
|
+
return `MCP ${sessionId} › ${workspace}`;
|
|
75
|
+
}
|
|
66
76
|
function toolDetail(args) {
|
|
67
77
|
if (!args || typeof args !== "object")
|
|
68
78
|
return "";
|
|
@@ -170,16 +180,19 @@ function prettyLog(level, event, fields) {
|
|
|
170
180
|
}
|
|
171
181
|
if (event === "tool.received") {
|
|
172
182
|
const detail = toolDetail(fields.args);
|
|
173
|
-
|
|
183
|
+
const context = formatToolTraceContext(fields);
|
|
184
|
+
console.log(` ${paint(ansi.magenta, "◆")} ${dim(context)} ${dim("›")} ${paint(ansi.cyan, bold(tool || "tool"))}${detail ? ` ${dim(detail)}` : ""}`);
|
|
174
185
|
return;
|
|
175
186
|
}
|
|
176
187
|
if (event === "tool.completed") {
|
|
177
|
-
|
|
188
|
+
const context = formatToolTraceContext(fields);
|
|
189
|
+
console.log(` ${paint(ansi.green, "✓")} ${dim(context)} ${dim("›")} ${bold(tool || "tool")} ${dim(elapsed || "done")}`);
|
|
178
190
|
return;
|
|
179
191
|
}
|
|
180
192
|
if (event === "tool.failed") {
|
|
181
193
|
const error = fields.error;
|
|
182
|
-
|
|
194
|
+
const context = formatToolTraceContext(fields);
|
|
195
|
+
console.error(` ${paint(ansi.red, "✕")} ${dim(context)} ${dim("›")} ${bold(tool || "tool")} ${dim(elapsed)}${error?.message ? ` ${paint(ansi.red, compact(error.message, 72))}` : ""}`);
|
|
183
196
|
return;
|
|
184
197
|
}
|
|
185
198
|
const detail = Object.entries(fields)
|