agent\extensions\env-context.ts

import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";

export default function (pi: ExtensionAPI) {
  // Captured once at session start — keeps the system prompt stable for prompt caching.
  const now = new Date();
  const pad = (n: number) => String(n).padStart(2, "0");
  const weekday = now.toLocaleDateString("en-US", { weekday: "long" });
  const offsetMin = -now.getTimezoneOffset();
  const offset = `UTC${offsetMin >= 0 ? "+" : "-"}${Math.trunc(Math.abs(offsetMin) / 60)}`;
  const time = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())} (${weekday}, ${offset})`;

  pi.on("before_agent_start", (event) => {
    return {
      systemPrompt:
        event.systemPrompt +
        "\n\nSHELL: You are in Git Bash on Windows. CMD builtins (dir, copy, type, del, move, etc.) work directly — just type them as-is. Do NOT prefix commands with 'cmd /c'. The '/c' flag gets interpreted by bash as a path fragment, which breaks execution completely." +
        "\n\nCWD: every bash command starts in the session's working directory — 'cd' does NOT persist between tool calls. Use absolute paths, or chain within one call: cd dir && cmd." +
        `\n\nTime: ${time} — local time at session start (approximate; the session may have been running for a while). Trust it over your training data for anything date-sensitive ("latest", "recent", versions, news).`,
    };
  });
}
Edit

Pub: 03 Sep 2026 19:46 UTC

Edit: 03 Sep 2026 19:49 UTC

Views: 6