clawdie-ai/vitest.config.ts
Operator & Claude Code c9f9bdb63d Inherit chat_jid into agent-created controlplane tasks (Sam & Claude)
Bug: when the chat agent decides a request needs a controlplane task
(e.g. "any system updates available?" — needs root-level audit), it
calls task_create. The task is stored with context: null because the
tool's parameter schema didn't accept context and nothing in the path
auto-injected the originating chat. controlplane-heartbeat.ts:874 then
reads context.chat_jid to deliver the result back to Telegram, finds
nothing, and the task completes with no thread back to the operator.

Sam saw this on 10.maj.2026 — the queue fix from b6d72d9 stopped silent
message loss, which immediately exposed silent task-result loss.

Fix:

- src/agent-runner.ts now passes CLAWDIE_CHAT_JID=input.chatJid to the
  spawned pi process. The chat jid was already available at the call
  site, just not exported.
- .pi/extensions/clawdie-harness/controlplane-tools.ts gets a new pure
  helper buildTaskCreateBody(params, env) that auto-injects
  context.chat_jid from $CLAWDIE_CHAT_JID. The task_create tool calls
  the helper. Agent doesn't need to know about chat context — the
  harness inherits it from its parent process.

The fix is asymmetric in a deliberate way: agent-runner sets the env
var unconditionally (every chat run has a chat_jid), but the helper
only injects context when the env var is non-empty. Scheduled-task
runs that don't yet thread chat context will simply omit context, same
as today — no regression there.

Tests:

- 5 new tests in controlplane-tools.test.ts cover the helper directly:
  no env → no context, blank env → no context, set env → context with
  chat_jid, plus priority + assigned_to passthrough.
- vitest.config.ts now includes .pi/extensions/**/*.test.ts so the
  harness tests run with `npm test` and `just test` instead of needing
  a separate runner invocation. This picks up the existing
  controlplane-tools and system-tools test files (the harness rename
  commit added them but they weren't in the default include).

Out of scope deliberately: src/controlplane-runner.ts (controlplane
heartbeat path that runs subtasks) does not yet read task.context.
chat_jid to thread it forward to its own spawned agents. So if a
controlplane task itself spawns subtasks, those subtasks won't inherit
chat_jid via this commit. The original bug (chat → agent → task) is
fixed end-to-end; sub-task propagation is a follow-up if needed.
Per docs/internal/SUDO_REPLACEMENT.md, the next privileged-op gap
(sysadmin can't run pkg/freebsd-update audits) belongs in hostd, not
in a sudo replacement.

---
2251 passed locally. Pre-existing argon2/controlplane-*/cms.test
failures unchanged. Codex to validate end-to-end on host: send a
chat-driven question that triggers a controlplane task, confirm
the task lands with context.chat_jid populated and the completion
message reaches the originating Telegram thread.

---
Build: FAIL | Tests: FAIL — 16 failed
2026-05-10 08:57:27 +02:00

12 lines
245 B
TypeScript

import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: [
'src/**/*.test.ts',
'setup/**/*.test.ts',
'skills-engine/**/*.test.ts',
'.pi/extensions/**/*.test.ts',
],
},
});