{% extends "space-settings-base.html" %} {% from "ui.html" import action, when with context %} {% from "routine-ui.html" import schedule, outputs, last_run with context %} {% set section = "routines" %} {% set base = "/o/" ~ org.slug ~ "/" ~ space.slug ~ "/-/routines" %} {% block section %}

{{ _("AI agents that review the wiki at regular intervals. They only write to their outputs: a report page, the inbox (then handled by the tidy-up), an email or a webhook. Every run counts toward the month's AI budget.") }}

{% if not ai_configured %}

{{ _("No AI provider is configured for the organization: routines cannot run.") }}{% if manage %} {{ _("Configure AI") }}{% endif %}

{% elif spending.exhausted %}

{{ _("Monthly AI budget reached ({spent} of {budget}): routines are paused until next month.", spent=spending.spent|euros, budget=spending.budget|euros) }}{% if manage %} {{ _("Raise the budget") }}{% endif %}

{% endif %}
{% for r in routines %}{% set run = last_runs.get(r.id) %}{% set upcoming = next_run(r, space) %}

{{ r.name }}

{{ schedule(r, weekdays) }} ({{ space.tidy_timezone }}) {% if r.scope %}{{ _("Scope: {folders}", folders=r.scope|join(", ")) }}{% else %}{{ _("The whole space") }}{% endif %}

{{ _("Enabled", context="routine") if r.enabled else _("Disabled", context="routine") }}
{{ outputs(r) }}

{{ last_run(run) }}{% if r.requested %}{{ _("Requested, waiting for the worker") }}{% elif upcoming %}{{ (_("Next run: {when}")|e).format(when=when(upcoming)) }}{% endif %}

{% if run and run.status == 'done' and run.summary %}

{{ run.summary }}

{% endif %}
{{ _("Log") }} {% if manage %} {{ _("Edit") }} {% if ai_configured and not spending.exhausted %}{{ action(base ~ "/" ~ r.id ~ "/run", _("Run now"), confirm=_("Run the routine now? The run uses tokens counted in the month's budget.")) }}{% endif %} {{ action(base ~ "/" ~ r.id ~ "/toggle", _("Deactivate") if r.enabled else _("Enable"), kind="quiet" if r.enabled else "primary") }} {% endif %}
{% else %}

{{ _("No routines yet.") }}{% if manage %} {{ _("Start from a template below.") }}{% endif %}

{% endfor %}
{% if manage %}

{{ _("Add a routine") }}

{% for t in templates %}

{{ _(t.name) }}

{{ _(t.description) }}

{{ schedule(t, weekdays) }}

{{ outputs(t) }}
{% if t.key in used_templates %}{{ _("Already added") }} {% else %}{{ action(base ~ "/from/" ~ t.key, _("Enable"), kind="primary") }} {{ _("Customize first") }}{% endif %}
{% endfor %}

{{ _("Blank routine") }}

{{ _("Your own instructions: review of a folder, Monday briefing, regenerated FAQ…") }}

{% else %}

{{ _("Only organization administrators create and edit routines.") }}

{% endif %}
{% endblock %}