Projects: shareable, registry-backed, container-mounted; drop ticket board
Nightly Build / build (push) Successful in 6m27s

Rework projects from single-user leftovers into shareable endeavours.

- DB: move `projects` from the owner bucket to the registry (system.db,
  not encrypted); add `owner_user_id` + `slug` (drop free `path`); new
  `project_members(project_id, user_id, can_write)` mirroring
  `shared_folder_members`. Drop `project_tickets` entirely. Only user↔agent
  conversations stay encrypted (per-user DB) — each member keeps a private
  project chat. Registry home dissolves the cross-DB-FK problem.
- Filesystem/container: on disk `{WD}/projects/{owner_userid}/{slug}`,
  agent/container path `projects/{owner_username}/{slug}`. Two-segment routing
  in UserFs (ProjectMount + host_base_and_tail arm) and a second loop in
  build_user_fs; read-only members get a :ro mount. Reuse the shared-folder
  remount machinery (refresh_user_shared_folders -> refresh_user_mounts).
- Remove the ticket system: ProjectTicketManager, UserContext.tickets, its
  wiring, and the project_tickets references in scheduled_jobs/cron.
- API: repoint handlers to the registry pool + membership scoping. Sharing is
  self-service — owner or any write-member may add/remove members and set
  read/write; only the owner deletes; the owner cannot be removed. New
  POST/DELETE /api/projects/{id}/members[/{user_id}]. Seed `@fs_any allow
  projects/*`; build_runtime_run_context sets working_directory to the agent
  path and drops the host-path allow_fs_writes.
- Frontend: create form without the free path field, owner/read-write badges;
  the detail page becomes header + description + sharing panel + Open chat + a
  file-explorer placeholder (the future primary surface). i18n en/it/fr.
This commit is contained in:
2026-07-20 22:21:10 +01:00
parent bd88f02226
commit 2ec394c17c
26 changed files with 963 additions and 1245 deletions
+21 -93
View File
@@ -1,106 +1,34 @@
pub mod tickets;
use std::sync::Arc;
use anyhow::Result;
use sqlx::SqlitePool;
use crate::db::projects::{self, Project};
use crate::db::projects::Project;
use crate::run_context::RunContext;
pub struct ProjectManager {
db: Arc<SqlitePool>,
}
impl ProjectManager {
pub fn new(db: Arc<SqlitePool>) -> Self {
Self { db }
}
pub async fn list(&self) -> Result<Vec<Project>> {
projects::list(&self.db).await
}
pub async fn get(&self, id: i64) -> Result<Option<Project>> {
projects::get(&self.db, id).await
}
pub async fn create(
&self,
name: &str,
path: &str,
description: &str,
run_context: Option<&RunContext>,
) -> Result<Project> {
let rc_json = run_context.map(|rc| rc.to_db());
projects::create(&self.db, name, path, description, rc_json.as_deref()).await
}
pub async fn update(
&self,
id: i64,
name: &str,
path: &str,
description: &str,
run_context: Option<&RunContext>,
) -> Result<bool> {
let rc_json = run_context.map(|rc| rc.to_db());
projects::update(&self.db, id, name, path, description, rc_json.as_deref()).await
}
pub async fn delete(&self, id: i64) -> Result<bool> {
projects::delete(&self.db, id).await
}
}
/// Builds the runtime `RunContext` for working on `project`, layering project-runtime
/// fields over an optional pre-resolved `base` RC (which carries static config set at
/// creation time, e.g. `security_group`).
/// Builds the runtime `RunContext` for working on `project`, layering the project's
/// working directory + a context header over an optional pre-resolved `base` RC (which
/// carries static config set at creation time, e.g. `security_group`).
///
/// Runtime fields computed here:
/// - `working_directory` — always set to `project.path`.
/// - `allow_fs_writes` — project tree + Skald's own `data/` directory.
/// - `system_prompt` — project-context fragments prepended before any stored ones.
///
/// Shared by `ProjectTicketManager::start` (background ticket jobs) and the interactive
/// project-chat session provisioning, so both work with identical context.
pub fn build_runtime_run_context(project: &Project, base: Option<RunContext>) -> RunContext {
/// `working_directory` is the **agent path** `projects/{owner_username}/{slug}` — the
/// same namespace the fs-tools and `execute_cmd` route through (the host/container
/// mapping is handled by `UserFs`). Writes there are auto-allowed by the seeded
/// `projects/*` approval rule and physically gated by the per-member read-only mount,
/// so no host-path `allow_fs_writes` grant is needed (that was the old single-user
/// model, which predated per-user containers).
pub fn build_runtime_run_context(
project: &Project,
owner_username: &str,
base: Option<RunContext>,
) -> RunContext {
let mut rc = base.unwrap_or_default();
// Working directory is always the project path, overwritten at build time.
rc.working_directory = Some(project.path.clone());
rc.working_directory = Some(format!("projects/{owner_username}/{}", project.slug));
// Absolute path to Skald's own data directory (user personal data store).
let skald_data = std::env::current_dir()
.unwrap_or_default()
.join("data")
.to_string_lossy()
.into_owned();
// Grant write access to the project tree and Skald's data directory.
if !rc.allow_fs_writes.contains(&project.path) {
rc.allow_fs_writes.push(project.path.clone());
}
if !rc.allow_fs_writes.contains(&skald_data) {
rc.allow_fs_writes.push(skald_data.clone());
}
// Build runtime context fragments and prepend before any stored ones.
// Note: working directory is intentionally omitted here — the date/time/OS/WD
// tail block in MessageBuilder already reflects the effective WD from RunContext.
let project_header = if project.description.is_empty() {
format!("You are working on project \"{}\".", project.name)
} else {
format!("You are working on project \"{}\". Description: {}", project.name, project.description)
};
let mut injected = vec![
project_header,
format!(
"Personal user data is available at: {}. \
Consult it when the task requires knowledge about the user.",
skald_data
),
];
"You are working on project \"{}\". Description: {}",
project.name, project.description
)
};
let mut injected = vec![project_header];
injected.extend(std::mem::take(&mut rc.system_prompt));
rc.system_prompt = injected;