feat: add backup CLI commands, AI correction/modifier services, and timezone-aware date display

- Add `devplace backups` CLI subcommands (list, run, prune, clear) with job enqueueing and orphan cleanup
- Introduce `BACKUPS_DIR` and `BACKUP_STAGING_DIR` config paths for backup storage
- Implement `schedule_correction` and `schedule_modification` calls in content creation, comment creation, and comment editing flows
- Add `DEFAULT_CORRECTION_PROMPT` and `DEFAULT_MODIFIER_PROMPT` config constants for AI content processing
- Document timezone-aware date display using `local_dt`/`dt_ago` Jinja globals with client-side `Intl` localization
- Update README with AI content correction/modifier support in direct messages via `@ai` inline instructions
- Add `track_action(user["uid"], "vote")` call on upvote in `apply_vote`
This commit is contained in:
2026-06-16 03:32:19 +00:00
parent e59bc2d34e
commit 15bd4ad87c
115 changed files with 5839 additions and 187 deletions
+183 -2
View File
@@ -183,6 +183,58 @@
<p class="customization-hint">Disabling hides your custom code without deleting it.</p>
</div>
{% endif %}
{% if is_owner %}
<div class="customization-card" data-ai-correction data-username="{{ profile_user['username'] }}">
<div class="customization-head">
<span class="customization-title">AI content correction</span>
</div>
<div class="customization-row">
<span class="customization-label">Enable correction</span>
<label class="ai-correction-switch">
<input type="checkbox" data-ai-correction-toggle {% if ai_correction_enabled %}checked{% endif %}>
</label>
</div>
<div class="customization-row">
<span class="customization-label">Apply mode</span>
<select data-ai-correction-sync class="input-sm">
<option value="async" {% if not ai_correction_sync %}selected{% endif %}>In background (faster, applies after saving)</option>
<option value="sync" {% if ai_correction_sync %}selected{% endif %}>Synchronously (wait while saving)</option>
</select>
</div>
<textarea data-ai-correction-prompt class="input-sm ai-correction-prompt" maxlength="2000" rows="3">{{ ai_correction_prompt }}</textarea>
<div class="customization-row">
<button type="button" class="btn btn-sm btn-primary" data-ai-correction-save>Save</button>
<span class="ai-correction-status" data-ai-correction-status></span>
</div>
<p class="customization-hint">Corrections apply to new and edited content using your API key, on posts, comments, projects, gists, direct messages and your bio. Code and source files are never changed. In background mode the correction is applied just after saving; in synchronous mode the save waits for the correction to finish.</p>
</div>
<div class="customization-card" data-ai-modifier data-username="{{ profile_user['username'] }}">
<div class="customization-head">
<span class="customization-title">AI modifier</span>
</div>
<div class="customization-row">
<span class="customization-label">Enable modifier</span>
<label class="ai-correction-switch">
<input type="checkbox" data-ai-modifier-toggle {% if ai_modifier_enabled %}checked{% endif %}>
</label>
</div>
<div class="customization-row">
<span class="customization-label">Apply mode</span>
<select data-ai-modifier-sync class="input-sm">
<option value="async" {% if not ai_modifier_sync %}selected{% endif %}>In background (applies after saving)</option>
<option value="sync" {% if ai_modifier_sync %}selected{% endif %}>Synchronously (wait while saving)</option>
</select>
</div>
<textarea data-ai-modifier-prompt class="input-sm ai-correction-prompt" maxlength="2000" rows="3">{{ ai_modifier_prompt }}</textarea>
<div class="customization-row">
<button type="button" class="btn btn-sm btn-primary" data-ai-modifier-save>Save</button>
<span class="ai-correction-status" data-ai-modifier-status></span>
</div>
<p class="customization-hint">Runs only when your text contains an inline `@ai instruction` directive: it executes that instruction and removes the `@ai` marker, using your API key. Applies to posts, comments, projects, gists, direct messages and your bio. Code and source files are never touched.</p>
</div>
{% endif %}
</aside>
<div class="profile-content">
@@ -252,6 +304,135 @@
</div>
{% endif %}
{% if correction_usage and correction_usage.calls %}
<div class="ai-usage-card correction-usage-card">
<div class="ai-usage-head">
<h3 class="ai-usage-title">AI correction usage</h3>
{% if correction_usage.last_used %}<span class="ai-usage-updated">{{ format_date(correction_usage.last_used) }}</span>{% endif %}
</div>
<div class="correction-usage-stats">
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(correction_usage.calls) }}</span>
<span class="correction-usage-label">Corrections</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(correction_usage.total_tokens) }}</span>
<span class="correction-usage-label">Total tokens</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(correction_usage.prompt_tokens) }}</span>
<span class="correction-usage-label">Prompt tokens</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(correction_usage.completion_tokens) }}</span>
<span class="correction-usage-label">Completion tokens</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.0f"|format(correction_usage.avg_tokens) }}</span>
<span class="correction-usage-label">Avg tokens/call</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.0f"|format(correction_usage.avg_latency_ms) }} ms</span>
<span class="correction-usage-label">Avg latency</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.1f"|format(correction_usage.avg_tokens_per_second) }}/s</span>
<span class="correction-usage-label">Avg speed</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.1f"|format(correction_usage.total_time_s) }} s</span>
<span class="correction-usage-label">Total time</span>
</div>
{% if correction_usage.cost_usd is defined %}
<div class="correction-usage-stat correction-usage-cost">
<span class="correction-usage-value">${{ "%.4f"|format(correction_usage.cost_usd) }}</span>
<span class="correction-usage-label">Total cost</span>
</div>
<div class="correction-usage-stat correction-usage-cost">
<span class="correction-usage-value">${{ "%.5f"|format(correction_usage.avg_cost_usd) }}</span>
<span class="correction-usage-label">Avg cost/call</span>
</div>
{% endif %}
</div>
</div>
{% endif %}
{% if modifier_usage and modifier_usage.calls %}
<div class="ai-usage-card correction-usage-card">
<div class="ai-usage-head">
<h3 class="ai-usage-title">AI modifier usage</h3>
{% if modifier_usage.last_used %}<span class="ai-usage-updated">{{ format_date(modifier_usage.last_used) }}</span>{% endif %}
</div>
<div class="correction-usage-stats">
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(modifier_usage.calls) }}</span>
<span class="correction-usage-label">Modifications</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(modifier_usage.total_tokens) }}</span>
<span class="correction-usage-label">Total tokens</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(modifier_usage.prompt_tokens) }}</span>
<span class="correction-usage-label">Prompt tokens</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "{:,}".format(modifier_usage.completion_tokens) }}</span>
<span class="correction-usage-label">Completion tokens</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.0f"|format(modifier_usage.avg_tokens) }}</span>
<span class="correction-usage-label">Avg tokens/call</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.0f"|format(modifier_usage.avg_latency_ms) }} ms</span>
<span class="correction-usage-label">Avg latency</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.1f"|format(modifier_usage.avg_tokens_per_second) }}/s</span>
<span class="correction-usage-label">Avg speed</span>
</div>
<div class="correction-usage-stat">
<span class="correction-usage-value">{{ "%.1f"|format(modifier_usage.total_time_s) }} s</span>
<span class="correction-usage-label">Total time</span>
</div>
{% if modifier_usage.cost_usd is defined %}
<div class="correction-usage-stat correction-usage-cost">
<span class="correction-usage-value">${{ "%.4f"|format(modifier_usage.cost_usd) }}</span>
<span class="correction-usage-label">Total cost</span>
</div>
<div class="correction-usage-stat correction-usage-cost">
<span class="correction-usage-value">${{ "%.5f"|format(modifier_usage.avg_cost_usd) }}</span>
<span class="correction-usage-label">Avg cost/call</span>
</div>
{% endif %}
</div>
</div>
{% endif %}
<details class="profile-achievements">
<summary class="profile-achievements-summary">
<span class="profile-achievements-title"><span class="icon">&#x1F3C6;</span> Achievements</span>
<span class="profile-achievements-count">{{ badge_earned }} / {{ badge_total }}</span>
</summary>
{% for group in achievements %}
<div class="achievement-group">
<h3 class="achievement-group-title">{{ group['group'] }} <span class="achievement-group-count">{{ group['earned'] }}/{{ group['total'] }}</span></h3>
<div class="achievement-grid">
{% for item in group['items'] %}
<div class="achievement {% if item['earned'] %}earned{% else %}locked{% endif %}" title="{{ item['description'] }}">
<span class="achievement-icon">{{ item['icon'] }}</span>
<span class="achievement-body">
<span class="achievement-name">{{ item['name'] }}</span>
<span class="achievement-desc">{{ item['description'] }}</span>
</span>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</details>
<div class="profile-tabs" data-profile-tabs>
<a href="/profile/{{ profile_user['username'] }}?tab=posts" class="profile-tab {% if current_tab == 'posts' %}active{% endif %}" data-menu-icon="&#x1F4DD;" data-menu-label="Posts"><span class="icon">&#x1F4DD;</span> Posts</a>
<a href="/profile/{{ profile_user['username'] }}?tab=projects" class="profile-tab {% if current_tab == 'projects' %}active{% endif %}" data-menu-icon="&#x1F680;" data-menu-label="Projects"><span class="icon">&#x1F680;</span> Projects</a>
@@ -312,7 +493,7 @@
<div class="gist-card-desc">{{ g['description'][:200] }}{% if g['description']|length > 200 %}...{% endif %}</div>
{% endif %}
<div class="gist-card-footer">
<span>{{ entry.time_ago }}</span>
<span>{{ dt_ago(entry.gist.created_at) if entry.gist.created_at else entry.time_ago }}</span>
</div>
</a>
{% else %}
@@ -410,7 +591,7 @@
<span class="activity-type">
{% if act['type'] == 'post' %}Posted{% else %}Commented{% endif %}
</span>
<span class="activity-time">{{ act['time_ago'] }}</span>
<span class="activity-time">{{ dt_ago(act['created_at']) if act['created_at'] else act['time_ago'] }}</span>
</div>
<p class="activity-content">{{ act['content'] }}</p>
</div>