diff --git a/CHANGELOG.md b/CHANGELOG.md index deaf154..b735745 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Fixed +- Format the current time in Claude response prompts in UTC regardless of the host timezone. - Bound recent live Discord context passed to Claude so deep-context requests cannot contribute unbounded live-message input. - Support announcement and other guild text-based channels in MCP channel tools. - Reject symbolic-link attachment destinations instead of following them when saving downloads. diff --git a/src/askClaude.ts b/src/askClaude.ts index 41ad01d..5d28b26 100644 --- a/src/askClaude.ts +++ b/src/askClaude.ts @@ -46,6 +46,7 @@ export async function askClaude( const now = new Date(); promptParts.push( `=== Current time: ${now.toLocaleString("en-US", { + timeZone: "UTC", weekday: "long", year: "numeric", month: "long", diff --git a/tests/promptTime.test.mjs b/tests/promptTime.test.mjs new file mode 100644 index 0000000..e5adc4e --- /dev/null +++ b/tests/promptTime.test.mjs @@ -0,0 +1,48 @@ +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { spawnSync } from "node:child_process"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +const repoDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); + +test("formats Claude response prompt times in UTC", () => { + const messagesDir = fs.mkdtempSync( + path.join(os.tmpdir(), "claudify-prompt-time-"), + ); + try { + const script = ` + import { askClaude } from "./build/askClaude.js"; + let prompt = ""; + await askClaude( + "Question", "User", "user-1", "general", "channel-1", + "Guild", "guild-1", [], "", + async (_args, input) => { + prompt = input; + return { stdout: "Answer", stderr: "" }; + }, + ); + process.stdout.write(prompt.split("\\n", 1)[0]); + `; + const result = spawnSync( + process.execPath, + ["--input-type=module", "--eval", script], + { + cwd: repoDir, + encoding: "utf8", + env: { + ...process.env, + MESSAGES_DIR: messagesDir, + TZ: "America/Los_Angeles", + }, + }, + ); + + assert.equal(result.status, 0, result.stderr); + assert.match(result.stdout, /^=== Current time: .* UTC ===$/); + } finally { + fs.rmSync(messagesDir, { recursive: true, force: true }); + } +}); \ No newline at end of file