feat: add 3-letter DOW prefix to injected timestamps

Changes [2026-01-28 20:30 EST] to [Wed 2026-01-28 20:30 EST].
Costs ~1 extra token but provides day-of-week for smaller models
that can't derive DOW from a date. Frontier models already handle
it, but this is cheap insurance for 7B-class models.
This commit is contained in:
Conroy Whitney
2026-01-28 22:07:26 -05:00
committed by Shakker
parent ff713a41e0
commit a007ba7b1b
3 changed files with 20 additions and 13 deletions

View File

@@ -18,16 +18,17 @@ describe("injectTimestamp", () => {
timezone: "America/New_York",
});
expect(result).toMatch(/^\[2026-01-28 20:30 EST\] Is it the weekend\?$/);
expect(result).toMatch(/^\[Wed 2026-01-28 20:30 EST\] Is it the weekend\?$/);
});
it("uses the same format as channel envelope timestamps", () => {
it("uses channel envelope format with DOW prefix", () => {
const now = new Date();
const expected = formatZonedTimestamp(now, "America/New_York");
const result = injectTimestamp("hello", { timezone: "America/New_York" });
expect(result).toBe(`[${expected}] hello`);
// DOW prefix + formatZonedTimestamp format
expect(result).toBe(`[Wed ${expected}] hello`);
});
it("always uses 24-hour format", () => {
@@ -42,14 +43,14 @@ describe("injectTimestamp", () => {
const result = injectTimestamp("hello", { timezone: "America/Chicago" });
// 8:30 PM EST = 7:30 PM CST = 19:30
expect(result).toMatch(/^\[2026-01-28 19:30 CST\]/);
expect(result).toMatch(/^\[Wed 2026-01-28 19:30 CST\]/);
});
it("defaults to UTC when no timezone specified", () => {
const result = injectTimestamp("hello", {});
// 2026-01-29T01:30:00Z
expect(result).toMatch(/^\[2026-01-29 01:30/);
expect(result).toMatch(/^\[Thu 2026-01-29 01:30/);
});
it("returns empty/whitespace messages unchanged", () => {
@@ -65,7 +66,7 @@ describe("injectTimestamp", () => {
});
it("does NOT double-stamp messages already injected by us", () => {
const alreadyStamped = "[2026-01-28 20:30 EST] hello there";
const alreadyStamped = "[Wed 2026-01-28 20:30 EST] hello there";
const result = injectTimestamp(alreadyStamped, { timezone: "America/New_York" });
expect(result).toBe(alreadyStamped);
@@ -84,7 +85,7 @@ describe("injectTimestamp", () => {
const result = injectTimestamp("hello", { timezone: "America/New_York" });
expect(result).toMatch(/^\[2026-02-01 00:00 EST\]/);
expect(result).toMatch(/^\[Sun 2026-02-01 00:00 EST\]/);
});
it("handles date boundaries (just before midnight)", () => {
@@ -92,19 +93,19 @@ describe("injectTimestamp", () => {
const result = injectTimestamp("hello", { timezone: "America/New_York" });
expect(result).toMatch(/^\[2026-01-31 23:59 EST\]/);
expect(result).toMatch(/^\[Sat 2026-01-31 23:59 EST\]/);
});
it("handles DST correctly (same UTC hour, different local time)", () => {
// EST (winter): UTC-5 → 2026-01-15T05:00Z = midnight Jan 15
vi.setSystemTime(new Date("2026-01-15T05:00:00.000Z"));
const winter = injectTimestamp("winter", { timezone: "America/New_York" });
expect(winter).toMatch(/^\[2026-01-15 00:00 EST\]/);
expect(winter).toMatch(/^\[Thu 2026-01-15 00:00 EST\]/);
// EDT (summer): UTC-4 → 2026-07-15T04:00Z = midnight Jul 15
vi.setSystemTime(new Date("2026-07-15T04:00:00.000Z"));
const summer = injectTimestamp("summer", { timezone: "America/New_York" });
expect(summer).toMatch(/^\[2026-07-15 00:00 EDT\]/);
expect(summer).toMatch(/^\[Wed 2026-07-15 00:00 EDT\]/);
});
it("accepts a custom now date", () => {
@@ -115,7 +116,7 @@ describe("injectTimestamp", () => {
now: customDate,
});
expect(result).toMatch(/^\[2025-07-04 12:00 EDT\]/);
expect(result).toMatch(/^\[Fri 2025-07-04 12:00 EDT\]/);
});
});

View File

@@ -53,7 +53,13 @@ export function injectTimestamp(message: string, opts?: TimestampInjectionOption
const formatted = formatZonedTimestamp(now, timezone);
if (!formatted) return message;
return `[${formatted}] ${message}`;
// Add 3-letter day-of-week for smaller models that can't derive DOW
// from a date. Costs ~1 token, cheap insurance.
const dow = new Intl.DateTimeFormat("en-US", { timeZone: timezone, weekday: "short" }).format(
now,
);
return `[${dow} ${formatted}] ${message}`;
}
/**

View File

@@ -163,7 +163,7 @@ describe("gateway agent handler", () => {
await vi.waitFor(() => expect(mocks.agentCommand).toHaveBeenCalled());
const callArgs = mocks.agentCommand.mock.calls[0][0];
expect(callArgs.message).toBe("[2026-01-28 20:30 EST] Is it the weekend?");
expect(callArgs.message).toBe("[Wed 2026-01-28 20:30 EST] Is it the weekend?");
mocks.loadConfigReturn = {};
vi.useRealTimers();