-
Notifications
You must be signed in to change notification settings - Fork 1
feat: gate verbose logs behind ZCODE_ACP_DEBUG (quiet by default) #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,7 +39,7 @@ import { | |||||||||||||
| splitAskUserQuestions, | ||||||||||||||
| zcodePermissionToAcp, | ||||||||||||||
| } from "../interaction/adapter.js"; | ||||||||||||||
| import { log } from "../utils.js"; | ||||||||||||||
| import { log, warn } from "../utils.js"; | ||||||||||||||
| import type { PendingTurn, ZcodeAcpServer } from "../server.js"; | ||||||||||||||
| import { sendSessionUpdate } from "./io.js"; | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -101,7 +101,7 @@ async function handleOne( | |||||||||||||
| const epm = isExitPlanMode(params); | ||||||||||||||
|
|
||||||||||||||
| if (!perm && !(isUserInputRequestUnchecked(method) && (epm || ask))) { | ||||||||||||||
| log(` ⚠ unhandled server→client request: ${method} (id=${zcodeReqId})`); | ||||||||||||||
| warn(` ⚠ unhandled server→client request: ${method} (id=${zcodeReqId})`); | ||||||||||||||
| sendZcodeError(backend, zcodeReqId, `bridge unsupported: ${method}`); | ||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -246,7 +246,7 @@ async function handleAskUserQuestion( | |||||||||||||
| ): Promise<ZcodeInteractionResponse> { | ||||||||||||||
| const qs = splitAskUserQuestions(params); | ||||||||||||||
| if (qs === null) { | ||||||||||||||
| log(" ⚠ AskUserQuestion: no valid questions, declining"); | ||||||||||||||
| warn(" ⚠ AskUserQuestion: no valid questions, declining"); | ||||||||||||||
| return { action: "decline", reason: "no valid questions" }; | ||||||||||||||
| } | ||||||||||||||
| const toolCallId = params.toolCallId ?? ""; | ||||||||||||||
|
|
@@ -270,7 +270,7 @@ async function handleAskUserQuestion( | |||||||||||||
| const resp = await askOnce(server, cx, acpParams, idx + 1, qs.length, q.question, turn); | ||||||||||||||
| const selected = parseAskUserResponse(resp); | ||||||||||||||
| if (selected === null) { | ||||||||||||||
| log(` ⚠ AskUserQuestion [${idx + 1}] skip/cancel/timeout, declining`); | ||||||||||||||
| warn(` ⚠ AskUserQuestion [${idx + 1}] skip/cancel/timeout, declining`); | ||||||||||||||
| return { action: "decline", reason: "skipped or cancelled" }; | ||||||||||||||
| } | ||||||||||||||
| answers[q.question] = selected; | ||||||||||||||
|
|
@@ -334,7 +334,9 @@ async function handleAskUserViaElicitation( | |||||||||||||
| _meta: { claudeCode: { toolName } }, | ||||||||||||||
| }); | ||||||||||||||
| const formParams = buildAskUserElicitationForm(params, acpSid, toolCallId || undefined); | ||||||||||||||
| log(` ⟳ AskUserQuestion forwarding elicitation/create (form, ${Object.keys(formParams.requestedSchema.properties).length} fields)`); | ||||||||||||||
| log( | ||||||||||||||
| ` ⟳ AskUserQuestion forwarding elicitation/create (form, ${Object.keys(formParams.requestedSchema.properties).length} fields)`, | ||||||||||||||
| ); | ||||||||||||||
|
Comment on lines
+337
to
+339
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent potential runtime errors, it is safer to use optional chaining when accessing
Suggested change
|
||||||||||||||
| const acpResp = await requestWithTimeout( | ||||||||||||||
| cx, | ||||||||||||||
| "elicitation/create", | ||||||||||||||
|
|
@@ -348,7 +350,7 @@ async function handleAskUserViaElicitation( | |||||||||||||
| } | ||||||||||||||
| const answers = parseAskUserElicitationResponse(acpResp, params); | ||||||||||||||
| if (answers === null) { | ||||||||||||||
| log(" ⚠ AskUserQuestion elicitation declined/cancelled"); | ||||||||||||||
| warn(" ⚠ AskUserQuestion elicitation declined/cancelled"); | ||||||||||||||
| return { action: "decline", reason: "declined or cancelled" }; | ||||||||||||||
| } | ||||||||||||||
| log(` ✓ AskUserQuestion elicitation answered (${Object.keys(answers).length})`); | ||||||||||||||
|
|
@@ -439,13 +441,13 @@ async function requestWithTimeout( | |||||||||||||
| let cancelTimer: ReturnType<typeof setInterval> | undefined; | ||||||||||||||
| const timeout = new Promise<null>((resolve) => { | ||||||||||||||
| timer = setTimeout(() => { | ||||||||||||||
| log(` ⚠ ${label} timed out after ${timeoutMs}ms`); | ||||||||||||||
| warn(` ⚠ ${label} timed out after ${timeoutMs}ms`); | ||||||||||||||
| resolve(null); | ||||||||||||||
| }, timeoutMs); | ||||||||||||||
| }); | ||||||||||||||
| const racers: Array<Promise<unknown>> = [ | ||||||||||||||
| cx.request(method, params as never).catch((e: unknown) => { | ||||||||||||||
| log(` ⚠ ${label} failed: ${e instanceof Error ? e.message : String(e)}`); | ||||||||||||||
| warn(` ⚠ ${label} failed: ${e instanceof Error ? e.message : String(e)}`); | ||||||||||||||
| return null; | ||||||||||||||
| }), | ||||||||||||||
| timeout, | ||||||||||||||
|
|
@@ -458,7 +460,7 @@ async function requestWithTimeout( | |||||||||||||
| new Promise<null>((resolve) => { | ||||||||||||||
| cancelTimer = setInterval(() => { | ||||||||||||||
| if (turn.cancelled) { | ||||||||||||||
| log(` ⚠ ${label} aborted (turn cancelled)`); | ||||||||||||||
| warn(` ⚠ ${label} aborted (turn cancelled)`); | ||||||||||||||
| resolve(null); | ||||||||||||||
| } | ||||||||||||||
| }, 100); | ||||||||||||||
|
|
||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * Tests for the logging utilities: debug-gated verbose log and warn-always. | ||
| * | ||
| * Default behavior is QUIET: verbose `log()` is suppressed unless | ||
| * `ZCODE_ACP_DEBUG=1` is set; `warn()` always emits (perceivable failures). | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, it, expect, vi } from "vitest"; | ||
|
|
||
| import { log, warn } from "../src/utils.js"; | ||
|
|
||
| describe("logging", () => { | ||
| const prevDebug = process.env.ZCODE_ACP_DEBUG; | ||
| let spy: ReturnType<typeof vi.spyOn>; | ||
|
|
||
| beforeEach(() => { | ||
| spy = vi.spyOn(process.stderr, "write").mockImplementation(() => true); | ||
| }); | ||
| afterEach(() => { | ||
| spy.mockRestore(); | ||
| if (prevDebug === undefined) delete process.env.ZCODE_ACP_DEBUG; | ||
| else process.env.ZCODE_ACP_DEBUG = prevDebug; | ||
| }); | ||
|
|
||
| it("log() is silenced by default (no ZCODE_ACP_DEBUG)", () => { | ||
| delete process.env.ZCODE_ACP_DEBUG; | ||
| log("should be silenced"); | ||
| expect(spy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("log() writes to stderr with the [zcode-acp] prefix when ZCODE_ACP_DEBUG=1", () => { | ||
| process.env.ZCODE_ACP_DEBUG = "1"; | ||
| log("hello"); | ||
| expect(spy).toHaveBeenCalledTimes(1); | ||
| expect(spy.mock.calls[0]?.[0]).toBe("[zcode-acp] hello\n"); | ||
| }); | ||
|
|
||
| it("warn() always writes, even without ZCODE_ACP_DEBUG", () => { | ||
| delete process.env.ZCODE_ACP_DEBUG; | ||
| warn("visible warning"); | ||
| expect(spy).toHaveBeenCalledTimes(1); | ||
| expect(spy.mock.calls[0]?.[0]).toBe("[zcode-acp] visible warning\n"); | ||
| }); | ||
|
|
||
| it("ZCODE_ACP_DEBUG=0 keeps log() silenced (only '1' enables verbose)", () => { | ||
| process.env.ZCODE_ACP_DEBUG = "0"; | ||
| log("still silenced"); | ||
| expect(spy).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
README.zh-CN.md中,_(未设置)缺少了结尾的下划线_,导致 Markdown 格式不一致。建议将其修改为_(未设置)_以保持与第 62 行_(自动发现)_一致的斜体格式。