Agents

One write path for people and agents

The web app and the AI assistant each had their own code for updating a task. Now both hand the write to one shared service, so they cannot disagree.

The problem

Blackhawk's platform can be driven two ways. A person clicks through the web app, or an assistant calls an MCP tool. Each had its own code for updating a task.

Two copies of one rule drift apart. The repo kept a matrix of the differences between the two, field by field and side effect by side effect. Every new rule had to be added twice and checked twice.

The decision

I moved the rules into one shared function that both surfaces call. The detail that matters: the assistant does not go through the web app's API. The web route and the MCP tool each call the same service underneath.

Both surfaces hand the write to the same function, so the behaviour is identical by construction.
A person reaches the web route and an assistant reaches the MCP tool. The MCP tool returns a preview until a person approves. Both then call one shared update service, which writes to the database and runs the side effects.
Two ways in, one function that decides what an update means.

Two callers, one function

This is the web route, after it has signed the user in and checked that the task belongs to their organization.

The web route hands the write overIllustrative
// Web route: sign in, check the organization, then hand over.
const result = await updateTask({
  taskId,
  changes: body,
  actor: user,
  organizationId,
});

And this is the MCP tool, after its own checks.

The MCP tool calls the same functionIllustrative
// Assistant tool: resolve names to ids, check the tenant, then hand over
// to the very same function.
const result = await updateTask({
  taskId: args.id,
  changes: resolved,
  actor: session.user,
  organizationId: task.organizationId,
});

Same function, same shape of arguments. The visible difference is the database client. The route passes the user's own client, where the database enforces what they can see. The MCP tool passes a full-access client, so it has to check the tenant itself before it gets this far.

What each surface keeps

Each surface keeps only the work that belongs to how it is reached.

Everything that decides what an update means lives in the shared function: recurrence, cascading a status change to subtasks, moving a task between clients, notifications. A new side effect goes there, never in one caller.

Completing or reopening a task is its own shared operation, used by the web app, bulk edits and the MCP tool. The update function refuses a completion outright, so there is no second path hiding there either.

Preview, then confirm

Every MCP write tool takes a confirm flag. Without it, the tool describes what it would do and writes nothing. For a task update that means each changed field as a from and a to, so the person approves the actual change.

A preview is just a return valueIllustrative
interface Preview<T> {
  preview: true;
  what: string;   // a plain description of the change
  would: T;       // exactly what would be written
  instruction: string;
}

function preview<T>(what: string, would: T): Preview<T> {
  return {
    preview: true,
    what,
    would,
    instruction:
      'Nothing was written. Show this to the user. If they approve, ' +
      'call again with the same arguments plus confirm: true.',
  };
}

There is no pending-write table on the server. The assistant shows the preview to the person and calls again with the same arguments plus confirm. A test reads every write tool's source and fails if the preview gate is missing or sits after a write.

The same refusals, in two dialects

Sometimes the shared function has to stop and ask. Closing a task that still has open subtasks is one case. It throws a conflict error with a stable code. The web app shows that as a dialog. The MCP tool turns the same error into data the assistant can read and act on.

One gate, translated for an assistantIllustrative
// The shared function refuses with "needs confirmation". The web app shows
// a dialog. For an assistant, the same refusal becomes a question to relay.
function asAssistantQuestion(error: unknown) {
  if (!isConfirmationRequired(error)) return null; // stays an ordinary error

  return {
    confirmationRequired: true,
    openSubtasks: error.details.openSubtasks,
    instruction:
      'Nothing was written. Ask the user whether to complete the ' +
      'subtasks too, then call again with their answer.',
  };
}

The rule itself is written once. Only the way it is presented differs.

What changed

An agent is only safe to trust with real work if it cannot do anything the product itself would refuse. Sharing the write path makes that true without anyone having to remember it.