Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Inject current datetime into prompts
wyt7b4779d5f140
diff --git a/src/main/features/agents.ts b/src/main/features/agents.tsindex c39ea6ae..501ca112 100644--- a/src/main/features/agents.ts+++ b/src/main/features/agents.ts@@ -38,6 +38,7 @@ const log = createLogger('agents');function CUSTOM_AGENTS_DIR(): string { return userAgentsDir(getActiveUserId()); }function CUSTOM_SKILLS_DIR(): string { return userSkillsDir(getActiveUserId()); }import { prompts } from '../prompts/loader';+import { buildRuntimeDatetimeBlock } from '../prompts/runtime_context';import { findOuterTagRanges } from '../util/markdown-prose-code';import {nowIso, genAgentId, safeId,@@ -1709,7 +1710,7 @@ export function buildAgentEditSystemPrompt(agent: {interactive: agent.interactive === true ? 'true' : 'false',});const tail = buildLanguageDirective();- return `${body}\n\n---\n\n${tail}`;+ return `${body}\n\n---\n\n${tail}\n\n---\n\n${buildRuntimeDatetimeBlock()}`;}export interface AgentEditResult {diff --git a/src/main/features/group_chat/bus.ts b/src/main/features/group_chat/bus.tsindex 632b6b6f..0eaf01b1 100644--- a/src/main/features/group_chat/bus.ts+++ b/src/main/features/group_chat/bus.ts@@ -62,6 +62,7 @@ import {resolveSkillAllowlistRefs,type SkillAllowlistRef,} from '../../model/core-agent/skill-registry';+import { buildRuntimeDatetimeBlock } from '../../prompts/runtime_context';const log = createLogger('group_chat.bus');@@ -1977,11 +1978,11 @@ function concatSharedRules(main: string, shared: string): string {return `${main.slice(0, idx)}---\n\n${shared}\n\n${main.slice(idx)}`;}-/** Append the user-language directive at the very tail. Kept last (after- * runtime injection) because it is the most volatile per-user variable;- * putting it last keeps the cached prefix stable. */+/** Append volatile prompt tail after the runtime injection block. Current+ * datetime stays last because it changes every turn; keeping it at the tail+ * preserves the largest cacheable prefix. */function appendLanguageDirective(prompt: string): string {- return `${prompt}\n\n---\n\n${buildLanguageDirective()}`;+ return `${prompt}\n\n---\n\n${buildLanguageDirective()}\n\n---\n\n${buildRuntimeDatetimeBlock()}`;}// Render the agents-index block injected into commander's system prompt.@@ -3310,6 +3311,7 @@ async function _buildCliPrompt(attachments_block: filesBlock,conversation_block: conversationBlock,task_body: taskBody,+ runtime_datetime_block: buildRuntimeDatetimeBlock(),});if (!bridgeHistory) return render('');diff --git a/src/main/features/skills.ts b/src/main/features/skills.tsindex ed76a657..6a4c988b 100644--- a/src/main/features/skills.ts+++ b/src/main/features/skills.ts@@ -40,6 +40,7 @@ function CUSTOM_SKILLS_DIR(): string {const log = createLogger('skills');import { prompts } from '../prompts/loader';+import { buildRuntimeDatetimeBlock } from '../prompts/runtime_context';import {nowIso, readJson, writeJson, writeTextAtomicSync,appendJsonlAtomic, invalidateLineCount, readJsonl,@@ -1869,7 +1870,7 @@ export async function buildSkillEditSystemPrompt(skill: {skill_files: skillFilesBlock(files),});const tail = buildLanguageDirective();- return `${body}\n\n---\n\n${tail}`;+ return `${body}\n\n---\n\n${tail}\n\n---\n\n${buildRuntimeDatetimeBlock()}`;}export interface SkillChatResult {diff --git a/src/main/i18n.ts b/src/main/i18n.tsindex 9dfcc1bd..eab83ae3 100644--- a/src/main/i18n.ts+++ b/src/main/i18n.ts@@ -191,10 +191,9 @@ export function getCurrentLang(): Lang {}// ── LLM language directive ───────────────────────────────────────────────-// Appended at the tail of every conversational system prompt so the model-// replies in the user's chosen UI language. Lives at the very end (after-// runtime injection) — this is the most volatile part of the prompt, so-// keeping it last avoids invalidating the KV-cache prefix.+// Appended near the tail of every conversational system prompt so the model+// replies in the user's chosen UI language. Callers may append per-turn+// context after this block when it changes more often than language.export function buildLanguageDirective(lang: Lang = _current): string {const name = getLocaleMeta(lang).llmName;diff --git a/src/main/prompts/chat_cli_agent.md b/src/main/prompts/chat_cli_agent.mdindex dccbd27d..24ca168a 100644--- a/src/main/prompts/chat_cli_agent.md+++ b/src/main/prompts/chat_cli_agent.md@@ -15,3 +15,5 @@ $conversation_block## Your task$task_body++$runtime_datetime_blockdiff --git a/src/main/prompts/runtime_context.ts b/src/main/prompts/runtime_context.tsnew file mode 100644index 00000000..b6bd9efb--- /dev/null+++ b/src/main/prompts/runtime_context.ts@@ -0,0 +1,37 @@+function pad2(n: number): string {+ return String(n).padStart(2, '0');+}++function formatOffset(minutesBehindUtc: number): string {+ const total = -minutesBehindUtc;+ const sign = total >= 0 ? '+' : '-';+ const abs = Math.abs(total);+ const hours = Math.floor(abs / 60);+ const minutes = abs % 60;+ return `${sign}${pad2(hours)}:${pad2(minutes)}`;+}++export function formatCurrentDatetime(date = new Date()): string {+ const yyyy = date.getFullYear();+ const mm = pad2(date.getMonth() + 1);+ const dd = pad2(date.getDate());+ const hh = pad2(date.getHours());+ const mi = pad2(date.getMinutes());+ const ss = pad2(date.getSeconds());+ return `${yyyy}-${mm}-${dd}T${hh}:${mi}:${ss}${formatOffset(date.getTimezoneOffset())}`;+}++export function getRuntimeTimezone(): string {+ const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;+ return tz || `UTC${formatOffset(new Date().getTimezoneOffset())}`;+}++export function buildRuntimeDatetimeBlock(date = new Date()): string {+ const currentDatetime = formatCurrentDatetime(date);+ return [+ '## Current datetime',+ '',+ `Current datetime: ${currentDatetime}`,+ `Timezone: ${getRuntimeTimezone()}`,+ ].join('\n');+}diff --git a/test/main/features/group_chat/output-format.test.ts b/test/main/features/group_chat/output-format.test.tsindex fe3b735c..5da0eb82 100644--- a/test/main/features/group_chat/output-format.test.ts+++ b/test/main/features/group_chat/output-format.test.ts@@ -63,6 +63,7 @@ describe('group_chat CLI output_format prompt hints', () => {attachments_block: '',conversation_block: '',task_body: 'Summarize status.',+ runtime_datetime_block: '## Current datetime\n\nCurrent datetime: 2026-06-05T14:30:00+08:00\nTimezone: Asia/Shanghai',});expect(rendered).not.toContain('Use plain text or Markdown');diff --git a/test/main/prompts/contract.test.ts b/test/main/prompts/contract.test.tsindex 2a4f7c9c..c550a963 100644--- a/test/main/prompts/contract.test.ts+++ b/test/main/prompts/contract.test.ts@@ -227,4 +227,16 @@ describe('prompts ↔ code contract', () => {expect(cliSetupPrompt).toMatch(/zero\/few inputs/i);expect(cliSetupPrompt).toMatch(/one task field plus one optional context field/i);});++ it('runtime datetime context is appended after language directives', () => {+ const bus = readFile('src/main/features/group_chat/bus.ts');+ const agents = readFile('src/main/features/agents.ts');+ const skills = readFile('src/main/features/skills.ts');+ const cliPrompt = fs.readFileSync(path.join(PROMPTS_DIR, 'chat_cli_agent.md'), 'utf-8');++ expect(bus).toMatch(/buildLanguageDirective\(\)\}\\n\\n---\\n\\n\$\{buildRuntimeDatetimeBlock\(\)\}/);+ expect(agents).toMatch(/buildLanguageDirective\(\)[\s\S]+buildRuntimeDatetimeBlock\(\)/);+ expect(skills).toMatch(/buildLanguageDirective\(\)[\s\S]+buildRuntimeDatetimeBlock\(\)/);+ expect(cliPrompt).toMatch(/\$task_body\n\n\$runtime_datetime_block\s*$/);+ });});diff --git a/test/main/prompts/loader.test.ts b/test/main/prompts/loader.test.tsindex 7793cda6..3d7dbfa0 100644--- a/test/main/prompts/loader.test.ts+++ b/test/main/prompts/loader.test.ts@@ -3,6 +3,7 @@ import * as fs from 'node:fs';import * as os from 'node:os';import * as path from 'node:path';import { PromptManager, safeSubstitute, prompts } from '../../../src/main/prompts/loader';+import { buildRuntimeDatetimeBlock, formatCurrentDatetime } from '../../../src/main/prompts/runtime_context';describe('prompts › safeSubstitute', () => {it('substitutes $identifier', () => {@@ -47,6 +48,21 @@ describe('prompts › safeSubstitute', () => {});});+describe('prompts › runtime datetime context', () => {+ it('formats local datetime as ISO with seconds and numeric offset', () => {+ const block = buildRuntimeDatetimeBlock(new Date(2026, 5, 5, 14, 30, 0));++ expect(formatCurrentDatetime(new Date(2026, 5, 5, 14, 30, 0))).toMatch(+ /^2026-06-05T14:30:00[+-]\d{2}:\d{2}$/,+ );+ expect(block).toContain('## Current datetime');+ expect(block).toMatch(/Current datetime: 2026-06-05T14:30:00[+-]\d{2}:\d{2}/);+ expect(block).toMatch(/Timezone: .+/);+ expect(block).not.toContain('This datetime is authoritative');+ expect(block).not.toContain('Current year:');+ });+});+describe('prompts › PromptManager (custom root)', () => {let tmpDir: string;let mgr: PromptManager;