Skip to main content

session_core/
session_flags.rs

1//! The resource flags a session worker is started with (`SessionWorkerOptions` of experimental/session-worker.ts,
2//! from the command line through native-command.ts and the server's model options):
3//!
4//! - `--system-prompt <text>`: the system prompt is exactly this text (`currentSystemPrompt` returns it unrendered);
5//! - `--append-system-prompt <text or file>` (repeatable): appended to the rendered prompt in place of a discovered
6//!   APPEND_SYSTEM.md. The CLI reads a file input in its own directory and sends the text (the worker's cwd may
7//!   differ). The TS server never passed it to a worker; ultron-rs does, as `appendSystemPrompt`;
8//! - `--no-skills`: no skills in the prompt, the `skills.*` catalog or the command list (bundled ones included);
9//! - `--no-context-files`: no AGENTS.md / CLAUDE.md in the prompt;
10//! - `--skill <path>` (repeatable, `skillPaths`; absolute, the CLI resolves them in its own directory): skills loaded
11//!   after the discovered ones (resource-loader.ts `additionalSkillPaths`), the first skill of a name kept.
12//!
13//! The tool flags (`--tools`, `--no-tools`, ...) are not here: the model's tool list is exactly `[rlm]`. Neither are
14//! `-e`/`--extension` and `--no-extensions`: Pi extensions are not supported by ultron-rs (the CLI warns and ignores
15//! them), and a worker ignores `extensionPaths` and `promptPaths` options.
16
17#[derive(Clone, Debug, Default, PartialEq, Eq)]
18pub struct SessionFlags {
19    pub system_prompt: Option<String>,
20    pub append_system_prompt: Option<Vec<String>>,
21    pub no_skills: bool,
22    pub no_context_files: bool,
23    pub skill_paths: Vec<String>,
24}
25
26impl SessionFlags {
27    /// The flags of a worker's options (`systemPrompt`, `appendSystemPrompt`, `noSkills`, `noContextFiles`).
28    pub fn from_worker_options(options: &serde_json::Value) -> SessionFlags {
29        SessionFlags {
30            system_prompt: options["systemPrompt"].as_str().map(str::to_string),
31            append_system_prompt: options["appendSystemPrompt"].as_array().map(|list| {
32                list.iter()
33                    .filter_map(|text| text.as_str().map(str::to_string))
34                    .collect()
35            }),
36            no_skills: options["noSkills"] == true,
37            no_context_files: options["noContextFiles"] == true,
38            skill_paths: options["skillPaths"]
39                .as_array()
40                .map(|list| list.iter().filter_map(|p| p.as_str().map(str::to_string)).collect())
41                .unwrap_or_default(),
42        }
43    }
44
45    /// Sets the worker options keys of the flags that are set (the inverse of [`SessionFlags::from_worker_options`]).
46    pub fn write_worker_options(&self, options: &mut serde_json::Value) {
47        if let Some(prompt) = &self.system_prompt {
48            options["systemPrompt"] = prompt.as_str().into();
49        }
50        if let Some(appends) = &self.append_system_prompt {
51            options["appendSystemPrompt"] = appends.clone().into();
52        }
53        if self.no_skills {
54            options["noSkills"] = true.into();
55        }
56        if self.no_context_files {
57            options["noContextFiles"] = true.into();
58        }
59        if !self.skill_paths.is_empty() {
60            options["skillPaths"] = self.skill_paths.clone().into();
61        }
62    }
63}
64
65/// The `/` commands without the skill commands (`skill:<name>`) when `--no-skills` left the skills out.
66pub fn filter_commands(commands: Vec<serde_json::Value>, flags: &SessionFlags) -> Vec<serde_json::Value> {
67    if !flags.no_skills {
68        return commands;
69    }
70    commands.into_iter().filter(|c| c["source"] != "skill").collect()
71}