Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
feat(agent-tui): /init writes AGENTS.md by default; JAN.md stays as legacy
thinhlpg6808b9ec7f84
diff --git a/docs/src/pages/docs/agent/context.mdx b/docs/src/pages/docs/agent/context.mdxindex 76714c7f0..e95016585 100644--- a/docs/src/pages/docs/agent/context.mdx+++ b/docs/src/pages/docs/agent/context.mdx@@ -44,9 +44,9 @@ Inside is a rail that shows the fill as a percentage of the window, a visual bartoken scale, and a headroom line (`N tokens available before auto-compact`), theprompt-cache lines when the route reports any, followed by a per-category breakdown:System prompt, System tools, Project context, Skills, and Messages. Below it, **Project-instructions** lists each instructions file the project context loaded, and marks an `AGENTS.md`-or `CLAUDE.md` read because its folder has no `JAN.md` (see-[Project Config](/docs/agent/project-config#agentsmd-and-claudemd)).+instructions** lists each instructions file the project context loaded, and labels a legacy+`JAN.md` or an opt-in `CLAUDE.md` (see+[Project Config](/docs/agent/project-config#janmd-and-claudemd)).Press <kbd>Esc</kbd>, <kbd>q</kbd>, or <kbd>Ctrl</kbd>+<kbd>C</kbd> to close; closing nevercancels the turn.diff --git a/docs/src/pages/docs/agent/memory.mdx b/docs/src/pages/docs/agent/memory.mdxindex 696224658..71e01998e 100644--- a/docs/src/pages/docs/agent/memory.mdx+++ b/docs/src/pages/docs/agent/memory.mdx@@ -91,14 +91,14 @@ README is noise; a note about the thing that surprised someone is worth keeping.If the agent has stored something wrong, delete the file. There's no special command for it - theyare just files.-## Memory and JAN.md+## Memory and AGENTS.mdThey overlap, and the distinction is who writes them:| | Written by | Best for || --- | --- | --- |-| `JAN.md` | You | Rules you want followed every time |+| `AGENTS.md` | You | Rules you want followed every time || Memory | The agent | Facts it discovered and shouldn't have to rediscover |If you find yourself correcting the same thing repeatedly, promote it into-[`JAN.md`](/docs/agent/project-config#janmd) where it's guaranteed to be in the prompt.+[`AGENTS.md`](/docs/agent/project-config#agentsmd) where it's guaranteed to be in the prompt.diff --git a/docs/src/pages/docs/agent/project-config.mdx b/docs/src/pages/docs/agent/project-config.mdxindex ab8175aa4..2deb0631c 100644--- a/docs/src/pages/docs/agent/project-config.mdx+++ b/docs/src/pages/docs/agent/project-config.mdx@@ -1,7 +1,7 @@---title: Project Config-description: JAN.md and agent.toml - per-project instructions, model, budget, and tool policy.-keywords: [Jan, Jan Agent, agent.toml, JAN.md, project config, instructions, budget]+description: AGENTS.md and agent.toml - per-project instructions, model, budget, and tool policy.+keywords: [Jan, Jan Agent, agent.toml, AGENTS.md, JAN.md, project config, instructions, budget]---import { Callout } from 'nextra/components'@@ -9,11 +9,11 @@ import { Callout } from 'nextra/components'# Project ConfigEach project gets a store under `~/.jan/projects/` holding how the agent should behave there. The-project directory itself holds only `JAN.md`.+project directory itself holds only `AGENTS.md`.```your-project/-`-- JAN.md # instructions for the agent+`-- AGENTS.md # instructions for the agent~/.jan/projects/<name>-<hash>/|-- project.json # which directory this store belongs to@@ -37,7 +37,7 @@ jan cli agent status --project .```<Callout type="tip">-Commit `JAN.md` so the whole team gets the same instructions. It is the only file Jan keeps in the+Commit `AGENTS.md` so the whole team gets the same instructions. It is the only file Jan keeps in theproject; everything in the store is per user and stays out of your repository.</Callout>@@ -49,7 +49,7 @@ so. It never merges: if the store already has content, the old folder is left alfor you to merge or delete by hand. Any other files in `.jan/` are left in place and listed. Aworkspace that is your home directory is skipped, since its `.jan` is the user-wide `~/.jan`.-## JAN.md+## AGENTS.mdPlain markdown, injected into the system prompt on every run. The highest-leverage file here.@@ -67,23 +67,25 @@ This is a Rust workspace. `cargo test` must pass before you call anything done.Write it as rules, not prose. Things that are true every time belong here; a procedure for one kindof task belongs in a [skill](/docs/agent/skills).-Jan reads `JAN.md` from the project root and each of its ancestors; the nearest file wins. Write one-by hand or with `/init`.+Jan reads it from the project root and each of its ancestors; the nearest file wins. Write one by+hand or with `/init`, which writes `AGENTS.md`. Other coding agents read `AGENTS.md` too, so one file+serves them all.-### AGENTS.md and CLAUDE.md+### JAN.md and CLAUDE.md-Many repositories already keep instructions for other coding agents in `AGENTS.md`. Jan reads one-file per directory on that same walk:+Jan reads one file per directory on that same walk:-1. `JAN.md`, if it is there and not empty. It always wins, so a repo with both files loads only- `JAN.md`.+1. `JAN.md`, if it is there and not empty. This is Jan's legacy name. It still wins, so a project+ that already has one loads exactly what it did before, and `/init` keeps editing it. Rename it to+ `AGENTS.md` whenever you like.2. Otherwise `AGENTS.md`.3. Otherwise `CLAUDE.md`, but only if you opt in to it.-A file already loaded under another name is skipped, so the common `ln -s AGENTS.md JAN.md` loads-once. Each file keeps its path in the prompt, so the model can see which one it got. When a-fallback is used, the startup note says so and `/context` lists it under **Project instructions**.-In a project that has `AGENTS.md` but no `JAN.md`, `/init` uses it as the starting point.+A file already loaded under another name is skipped, so a `JAN.md -> AGENTS.md` symlink loads once.+Each file keeps its path in the prompt, so the model can see which one it got. When a legacy+`JAN.md` or a `CLAUDE.md` is used, the startup note says so and `/context` labels it under+**Project instructions**. In a project with only `CLAUDE.md`, `/init` uses it as the starting point+for `AGENTS.md`.Configure it in `agent.toml`, or in `~/.jan/config.toml` for every project (the project wins):@@ -91,7 +93,7 @@ Configure it in `agent.toml`, or in `~/.jan/config.toml` for every project (the[context]fallback_files = ["AGENTS.md"] # the default# fallback_files = ["AGENTS.md", "CLAUDE.md"] # also read CLAUDE.md-# fallback_files = [] # JAN.md only+# fallback_files = [] # JAN.md only; /init then writes JAN.md```Only `AGENTS.md` and `CLAUDE.md` are recognised. The files are re-read at the start of every run;@@ -99,8 +101,8 @@ Only `AGENTS.md` and `CLAUDE.md` are recognised. The files are re-read at the st<Callout type="warning">A file written for another agent can mention that agent's own tools or commands. If Jan follows-something meant for another tool, write a `JAN.md` (it shadows the other file) or set-`fallback_files = []`.+something meant for another tool, edit the file, write a `JAN.md` (it shadows the other file), or+set `fallback_files = []`.</Callout>## agent.tomldiff --git a/docs/src/pages/docs/agent/sessions.mdx b/docs/src/pages/docs/agent/sessions.mdxindex e004d82a8..35a2ddbaf 100644--- a/docs/src/pages/docs/agent/sessions.mdx+++ b/docs/src/pages/docs/agent/sessions.mdx@@ -187,4 +187,4 @@ Under the project's store, `~/.jan/projects/<slug>/` (see| `skills/` | Reusable procedures, see [Skills](/docs/agent/skills) |None of it lives in your repository, so there is nothing to gitignore. The only file Jan keeps in-the project is `JAN.md`.+the project is `AGENTS.md` (or a legacy `JAN.md`).diff --git a/docs/src/pages/docs/agent/skills.mdx b/docs/src/pages/docs/agent/skills.mdxindex a1805c5f6..5fcae8040 100644--- a/docs/src/pages/docs/agent/skills.mdx+++ b/docs/src/pages/docs/agent/skills.mdx@@ -99,15 +99,15 @@ the `nightly` channel only - the same project files, through the same directory.in one shows up in the other.</Callout>-## Skills, JAN.md, and memory+## Skills, AGENTS.md, and memoryThree places that shape behaviour, easily confused:| | Scope | Loaded || --- | --- | --- |-| [`JAN.md`](/docs/agent/project-config#janmd) | Rules for everything the agent does here | Always |+| [`AGENTS.md`](/docs/agent/project-config#agentsmd) | Rules for everything the agent does here | Always || Skills | A specific procedure | On demand, when relevant || [Memory](/docs/agent/memory) | Facts the agent learned | Recalled as needed |-Rule of thumb: if it applies to every task, it belongs in `JAN.md`. If it applies to one kind of+Rule of thumb: if it applies to every task, it belongs in `AGENTS.md`. If it applies to one kind oftask, make it a skill.diff --git a/docs/src/pages/docs/agent/slash-commands.mdx b/docs/src/pages/docs/agent/slash-commands.mdxindex 7af790bca..8412f3864 100644--- a/docs/src/pages/docs/agent/slash-commands.mdx+++ b/docs/src/pages/docs/agent/slash-commands.mdx@@ -69,7 +69,7 @@ See [Run modes](/docs/agent/run-modes), [Goals and todos](/docs/agent/goals-and-| `/effort [low\|medium\|high]` | Set reasoning effort. Bare: show current; `low` is faster, `high` thinks deeper || `/mcp` | List, toggle, add, edit, and remove MCP servers; Enter opens a server's detail screen, where you can list its tools and sign in to it || `/plugin [list\|install <spec>\|remove <name>\|search [query]]` | Manage plugins: install from a git URL or the marketplace, list/remove installed, search the marketplace |-| `/reload [config\|plugin\|skills\|system-prompt]` | Re-read on-disk state into the running session without a restart (bare: all). `config` re-applies the project's `agent.toml` limits - `context_window`, `compaction_ratio`, `compaction_reserve_tokens`, `max_tokens`, `send_reasoning`, `[budget].max_tokens` - to the next run and lists what changed; the model, `[tools]`, `[provider]` and `[budget].max_usd` still need a restart. `plugin`/`skills` re-scan and rebuild the catalog, reporting added/removed/changed entries. `system-prompt` re-reads the project instructions (`JAN.md`, or a `[context].fallback_files` entry such as `AGENTS.md` where a directory has none), which apply on the next run |+| `/reload [config\|plugin\|skills\|system-prompt]` | Re-read on-disk state into the running session without a restart (bare: all). `config` re-applies the project's `agent.toml` limits - `context_window`, `compaction_ratio`, `compaction_reserve_tokens`, `max_tokens`, `send_reasoning`, `[budget].max_tokens` - to the next run and lists what changed; the model, `[tools]`, `[provider]` and `[budget].max_usd` still need a restart. `plugin`/`skills` re-scan and rebuild the catalog, reporting added/removed/changed entries. `system-prompt` re-reads the project instructions (`AGENTS.md`, or a legacy `JAN.md` where a directory has one), which apply on the next run || `/login` | Sign in to Tokamak and save the API key || `/config [what you want]` | View provider config (`~/.jan/config.toml`). With words, it is `/vibe-setting` || `/terminal-setup` | Configure this terminal so <kbd>Shift</kbd>+<kbd>Enter</kbd> inserts a newline and, on macOS, <kbd>Option</kbd>+<kbd>Delete</kbd> deletes a word. Writes the terminal's own config where it can (VS Code, kitty, Ghostty, tmux) and prints the manual step where it cannot. Idempotent |diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.md b/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.mdindex f3171e472..8af7c2597 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.md+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/default_jan_skill.md@@ -11,8 +11,10 @@ Run `jan` in a folder. That CWD is the project root; `--project DIR` selects ano## Project files-Jan reads non-empty `JAN.md` files from the project root and its ancestors. The nearest file wins.-`JAN.md` is the only file Jan keeps in the project; commit it to share instructions.+Jan reads one non-empty instructions file per folder, from the project root and its ancestors. The+nearest file wins. `AGENTS.md` is the default and what `/init` writes; a legacy `JAN.md` still loads+and wins over `AGENTS.md` in the same folder. It is the only file Jan keeps in the project; commit it+to share instructions.Everything else is per-user state under `~/.jan/`, created on first use.## User filesdiff --git a/src-tauri/src/core/agent/context.rs b/src-tauri/src/core/agent/context.rsindex 1f8b2802d..50750b99d 100644--- a/src-tauri/src/core/agent/context.rs+++ b/src-tauri/src/core/agent/context.rs@@ -37,12 +37,29 @@ get on with unrelated work or finish the turn.";/// the project root up to the filesystem root. When a directory has a/// non-empty one it wins outright: nothing else in that directory is read.///-/// #8642 made `JAN.md` the only file ingested, so another agent's file never-/// became authoritative behind the user's back. #9079 keeps `JAN.md` primary-/// and adds a *fallback* for directories without one: the names in-/// `[context].fallback_files` (default `AGENTS.md`; `CLAUDE.md` is opt-in),-/// tried in order, one file per directory. `[]` restores JAN.md-only exactly.-const CONTEXT_FILE_NAME: &str = "JAN.md";+/// `JAN.md` is the *legacy* name: `/init` now writes `AGENTS.md` (#9083), but a+/// `JAN.md` the user already has keeps winning, so an existing project loads+/// exactly the bytes it loaded before and its prompt cache stays warm. Other+/// directories fall back to the names in `[context].fallback_files` (default+/// `AGENTS.md`; `CLAUDE.md` is opt-in), tried in order, one file per directory.+/// `[]` restores JAN.md-only exactly.+pub(crate) const CONTEXT_FILE_NAME: &str = "JAN.md";++/// The instructions file `/init` writes for a new project (#9083).+#[cfg(feature = "cli")]+pub(crate) const DEFAULT_INSTRUCTIONS_FILE: &str = "AGENTS.md";++/// How a surface labels a loaded instructions file by its name: `JAN.md` is+/// the legacy name, `CLAUDE.md` an opt-in fallback, and `AGENTS.md` -- the+/// default -- needs no label.+#[cfg(feature = "cli")]+pub(crate) fn instructions_file_label(path: &Path) -> Option<&'static str> {+ match path.file_name().and_then(|name| name.to_str()) {+ Some(CONTEXT_FILE_NAME) => Some("legacy JAN.md"),+ Some(DEFAULT_INSTRUCTIONS_FILE) | None => None,+ Some(_) => Some("fallback"),+ }+}/// One instructions file the walk picked: where it is, what it says, and/// whether it is a fallback (not `JAN.md`), so a surface can say so.@@ -147,13 +164,11 @@ pub(crate) fn has_context_file(project_root: &Path) -> bool {!project_context_files(project_root).is_empty()}-/// Whether the project root itself has a non-empty `JAN.md`. `/init` uses it to-/// decide between writing one and reviewing one, since a fallback file (or an-/// ancestor's) is not the project's own.+/// Whether `project_root` itself (not an ancestor) has a non-empty `name`.+/// `/init` uses it to decide between writing a file and reviewing one.#[cfg(feature = "cli")]-pub(crate) fn has_own_jan_md(project_root: &Path) -> bool {- std::fs::read_to_string(project_root.join(CONTEXT_FILE_NAME))- .is_ok_and(|content| !content.trim().is_empty())+pub(crate) fn has_own_file(project_root: &Path, name: &str) -> bool {+ std::fs::read_to_string(project_root.join(name)).is_ok_and(|content| !content.trim().is_empty())}/// Built-in guide teaching the model the skills/memory file conventions. Alwaysdiff --git a/src-tauri/src/core/agent/prompt.rs b/src-tauri/src/core/agent/prompt.rsindex c4a5ebbfb..04f15af36 100644--- a/src-tauri/src/core/agent/prompt.rs+++ b/src-tauri/src/core/agent/prompt.rs@@ -154,7 +154,7 @@ impl Composer {Composer::SkillGuide => "the skills and memory file conventions",Composer::WebToolsGuide => "the native web tools and when to reach for them",Composer::ProjectContext => {- "JAN.md (or its AGENTS.md fallback), from the project and its ancestors"+ "AGENTS.md (or a legacy JAN.md), from the project and its ancestors"},Composer::Skills => "the installed skill catalog",Composer::MemoryCatalog => "the curated memory note catalog",diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rsindex 8e20ec284..361606dc8 100644--- a/src-tauri/src/core/cli/tui.rs+++ b/src-tauri/src/core/cli/tui.rs@@ -6766,8 +6766,8 @@ struct ContextReport {session_cached_tokens: u64,session_cache_write_tokens: u64,/// The instructions files the project context loaded, farthest first, each- /// with whether it is a fallback (`AGENTS.md`, `CLAUDE.md`) read because its- /// directory has no `JAN.md` (#9079). Listed so a fallback is never silent.+ /// with whether it is not a `JAN.md` (#9079). `/context` labels each by+ /// name (legacy `JAN.md`, `CLAUDE.md` fallback), so the choice is never silent.instruction_files: Vec<(String, bool)>,}@@ -6993,18 +6993,20 @@ fn cost_summary_line(report: &ContextReport) -> Option<String> {}/// Which instructions files the project context holds, for `/context`: a blank-/// separator, a heading, then one path per file, a fallback marked as such.+/// separator, a heading, then one path per file, a legacy JAN.md or a CLAUDE.md+/// fallback labelled as such./// Empty when none loaded, so a project without instructions shows nothing.fn instruction_file_lines(report: &ContextReport) -> Vec<String> {if report.instruction_files.is_empty() {return Vec::new();}let mut lines = vec![String::new(), "Project instructions".to_string()];- for (path, fallback) in &report.instruction_files {- lines.push(if *fallback {- format!(" {path} (fallback: no JAN.md in that folder)")- } else {- format!(" {path}")+ for (path, _) in &report.instruction_files {+ let label =+ crate::core::agent::context::instructions_file_label(std::path::Path::new(path));+ lines.push(match label {+ Some(label) => format!(" {path} ({label})"),+ None => format!(" {path}"),});}lines@@ -9572,8 +9574,8 @@ pub async fn run(// middle of a run.app.note(&warning);}- // Only when there is nothing to load: a project that already has JAN.md needs- // no invitation, and the splash hint covers re-running /init deliberately.+ // An invitation when there is nothing to load, a label when a legacy JAN.md+ // or a CLAUDE.md is what loaded; an AGENTS.md project hears nothing.if let Some(note) = project_instructions_note(&app.project_root) {app.note(¬e);}@@ -12148,7 +12150,7 @@ const SLASH_COMMANDS: &[SlashCommand] = &[SlashCommand {name: "/init",hint: "",- description: "Study the project, then write JAN.md, skills, and memory",+ description: "Study the project, then write AGENTS.md, skills, and memory",alias_of: None,},SlashCommand {@@ -12280,7 +12282,7 @@ const SLASH_COMMANDS: &[SlashCommand] = &[SlashCommand {name: "/reload",hint: "[config|plugin|skills|system-prompt]",- description: "Re-read agent.toml, skills, plugins and JAN.md without restarting (bare: all)",+ description: "Re-read agent.toml, skills, plugins and AGENTS.md without restarting (bare: all)",alias_of: None,},SlashCommand {@@ -12739,47 +12741,97 @@ fn parse_usage_mode(arg: &str) -> UsageMode {/// The `/init` prompt. Onboarding a project means producing the three things a-/// later session reads back: the root `JAN.md` (ingested as project context),-/// skills for repeatable workflows, and memory for durable facts. Phrased as a-/// task for the model rather than executed here -- only the model can read the-/// project and judge what is worth writing down.-const INIT_PROMPT: &str = "Onboard yourself to this project so future sessions start informed.\n\n\+/// later session reads back: the root instructions file (ingested as project+/// context), skills for repeatable workflows, and memory for durable facts.+/// Phrased as a task for the model rather than executed here -- only the model+/// can read the project and judge what is worth writing down. `{file}` is the+/// file [`init_plan`] chose.+fn init_prompt(file: &str) -> String {+ format!(+ "Onboard yourself to this project so future sessions start informed.\n\n\1. Study the project first. Read the README and any contributor docs, map the directory layout, and \find the real build, test, lint, and type-check commands (from the manifests and CI config, not from \guesswork). Note the conventions the code actually follows.\n\n\-2. Write `JAN.md` in the project root. It is the only instructions file loaded into your system \-prompt, and it is loaded every session, so it must earn its tokens: the commands to build/test/lint, \-the architecture a newcomer cannot infer from the tree, and the conventions worth enforcing. Skip \-anything obvious from a directory listing, and do not pad it. If `JAN.md` already exists, read it and \-correct what has drifted instead of rewriting it wholesale.\n\n\+2. Write `{file}` in the project root. It is loaded into your system prompt every session, so it \+must earn its tokens: the commands to build/test/lint, the architecture a newcomer cannot infer from \+the tree, and the conventions worth enforcing. Skip anything obvious from a directory listing, and \+do not pad it. If `{file}` already exists, read it and correct what has drifted instead of rewriting \+it wholesale.\n\n\3. Write skills with `skill_write` for the project's repeatable procedures -- releasing, running \migrations, adding a module, debugging a subsystem -- one skill per procedure, only where a real \multi-step recipe exists. Do not invent skills to fill space.\n\n\4. Record durable project facts with `memory_write`: decisions, constraints, and gotchas that are \true beyond this session and not already stated in the code.\n\n\-Then report what you wrote and why, briefly.";+Then report what you wrote and why, briefly."+ )+}/// The startup note about project instructions: an invitation to `/init` when-/// there are none, and a plain statement when the context came from a fallback-/// file (`AGENTS.md`) rather than `JAN.md`, so that choice is never silent-/// (#9079). `None` when every loaded file is a `JAN.md`: nothing to say.+/// there are none, and a plain statement when a loaded file is not the default+/// `AGENTS.md` -- a legacy `JAN.md` or an opt-in `CLAUDE.md` -- so which file+/// the prompt holds is never silent (#9079). `None` when every loaded file is+/// an `AGENTS.md`: nothing to say.fn project_instructions_note(project_root: &std::path::Path) -> Option<String> {- let files = crate::core::agent::context::project_context_files(project_root);+ use crate::core::agent::context::{instructions_file_label, project_context_files};+ let files = project_context_files(project_root);if files.is_empty() {- return Some("no JAN.md here — run /init to study this project and write one".to_string());+ return Some(+ "no AGENTS.md here — run /init to study this project and write one".to_string(),+ );}- let fallbacks: Vec<String> = files+ let labelled: Vec<String> = files.iter()- .filter(|file| file.fallback)- .map(|file| file.path.display().to_string())+ .filter_map(|file| {+ instructions_file_label(&file.path)+ .map(|label| format!("{} ({label})", file.path.display()))+ }).collect();- if fallbacks.is_empty() {+ if labelled.is_empty() {return None;}- Some(format!(- "project instructions from {} (no JAN.md there) · [context].fallback_files in agent.toml controls this",- fallbacks.join(", ")- ))+ Some(format!("project instructions from {}", labelled.join(", ")))+}++/// What `/init` does in this project root: which file it writes or reviews,+/// whether that file already exists, and which other agent's file (if any) it+/// starts from.+#[derive(Debug, PartialEq, Eq)]+struct InitPlan {+ file: &'static str,+ existing: bool,+ seed: Option<&'static str>,+}++/// Choose `/init`'s target (#9083). `AGENTS.md` is the default. A root that+/// already has a legacy `JAN.md` keeps it: `JAN.md` wins over `AGENTS.md` in the+/// same folder, so an `AGENTS.md` written next to it would never load. A project+/// whose `[context].fallback_files` leaves `AGENTS.md` out gets `JAN.md`, the+/// one name that is always read. A `CLAUDE.md` seeds a new file.+fn init_plan(project_root: &std::path::Path) -> InitPlan {+ use crate::core::agent::context::{+ has_own_file, CONTEXT_FILE_NAME, DEFAULT_INSTRUCTIONS_FILE,+ };+ let agents_read = crate::core::agent::project::context_fallback_files(project_root)+ .iter()+ .any(|name| name == DEFAULT_INSTRUCTIONS_FILE);+ let file = if has_own_file(project_root, CONTEXT_FILE_NAME) || !agents_read {+ CONTEXT_FILE_NAME+ } else {+ DEFAULT_INSTRUCTIONS_FILE+ };+ let existing = has_own_file(project_root, file);+ let seed = (!existing)+ .then(|| {+ [DEFAULT_INSTRUCTIONS_FILE, "CLAUDE.md"]+ .into_iter()+ .find(|name| *name != file && has_own_file(project_root, name))+ })+ .flatten();+ InitPlan {+ file,+ existing,+ seed,+ }}/// `/init`: hand the model the onboarding task as a user turn, so it runs with@@ -12793,50 +12845,47 @@ fn init_command(app: &mut App) {app.note("/init is only available once the run has finished");return;}- let existing = crate::core::agent::context::has_own_jan_md(&app.project_root);- let seed = (!existing)- .then(|| init_seed_file(&app.project_root))- .flatten();- match (&seed, existing) {- (_, true) => app.note("◈ init · reviewing JAN.md, skills, and memory for this project"),- (Some(name), false) => app.note(&format!(- "◈ init · writing JAN.md from this project's {name}, plus skills and memory"+ let plan = init_plan(&app.project_root);+ let file = plan.file;+ match (plan.seed, plan.existing) {+ (_, true) => app.note(&format!(+ "◈ init · reviewing {file}, skills, and memory for this project"+ )),+ (Some(seed), false) => app.note(&format!(+ "◈ init · writing {file} from this project's {seed}, plus skills and memory"+ )),+ (None, false) => app.note(&format!(+ "◈ init · studying the project to write {file}, skills, and memory")),- (None, false) => {- app.note("◈ init · studying the project to write JAN.md, skills, and memory")- }}- let prompt = match seed {- Some(name) => format!("{INIT_PROMPT}\n\n{}", init_seed_paragraph(&name)),- None => INIT_PROMPT.to_string(),- };+ let mut prompt = init_prompt(file);+ if let Some(seed) = plan.seed {+ prompt.push_str("\n\n");+ prompt.push_str(&init_seed_paragraph(file, seed));+ }+ if file == crate::core::agent::context::CONTEXT_FILE_NAME && plan.existing {+ prompt.push_str("\n\n");+ prompt.push_str(INIT_LEGACY_PARAGRAPH);+ }app.submit_user_hidden(prompt);}-/// The other agent's instructions file `/init` should start from, when the-/// project root has one and no `JAN.md` (#9079): `AGENTS.md`, else `CLAUDE.md`.-/// Both are offered regardless of `[context].fallback_files`, because this only-/// seeds a file the user then owns -- nothing is loaded from it by this choice.-fn init_seed_file(project_root: &std::path::Path) -> Option<String> {- ["AGENTS.md", "CLAUDE.md"]- .into_iter()- .find(|name| {- std::fs::read_to_string(project_root.join(name))- .is_ok_and(|content| !content.trim().is_empty())- })- .map(str::to_string)-}+/// The `/init` addendum for a project whose own file is the legacy `JAN.md`:+/// keep editing it in place, and leave the rename to the user.+const INIT_LEGACY_PARAGRAPH: &str = "`JAN.md` is Jan's legacy instructions file; new projects use \+`AGENTS.md`, which other coding agents read too. Keep editing `JAN.md` in place -- it wins over an \+`AGENTS.md` in the same folder -- and do not rename it yourself. In your report, mention that the \+user can rename it to `AGENTS.md` if they want one file shared by every agent.";/// The `/init` addendum for a project that already keeps instructions for/// another agent: build on them rather than writing from scratch, and drop what/// was aimed at that agent -- the concern #8642 raised about ingesting it as is.-fn init_seed_paragraph(name: &str) -> String {+fn init_seed_paragraph(file: &str, seed: &str) -> String {format!(- "This project has no `JAN.md` but has `{name}`, written for another coding agent. Read it \-first and use it as the starting point for `JAN.md`: keep the commands, architecture, and \+ "This project has no `{file}` but has `{seed}`, written for another coding agent. Read it \+first and use it as the starting point for `{file}`: keep the commands, architecture, and \conventions that hold for any agent, and drop or rewrite anything aimed at that specific agent (its \-tool names, its CLI commands, its config files). Leave `{name}` itself unchanged. If the user would \-rather keep one file, mention that `ln -s {name} JAN.md` makes Jan read it directly."+tool names, its CLI commands, its config files). Leave `{seed}` itself unchanged.")}@@ -14767,13 +14816,15 @@ fn reload_system_prompt(app: &mut App) {let files = crate::core::agent::context::project_context_files(&app.project_root);if files.is_empty() {app.note(- "◈ reload · system-prompt · no JAN.md or [context].fallback_files match in this project or its ancestors",+ "◈ reload · system-prompt · no AGENTS.md or JAN.md in this project or its ancestors",);return;}app.note("◈ reload · system-prompt · re-read project instructions (applies next run)");for file in &files {- let tag = if file.fallback { ", fallback" } else { "" };+ let tag = crate::core::agent::context::instructions_file_label(&file.path)+ .map(|label| format!(", {label}"))+ .unwrap_or_default();app.system_detail_text(&format!(" {} ({} bytes{tag})",file.path.display(),@@ -25500,7 +25551,8 @@ mod tests {super::init_command(&mut app);assert!(app.want_start, "/init must start a turn");let sent = app.history.last().expect("user message").to_string();- assert!(sent.contains("JAN.md"), "{sent}");+ assert!(sent.contains("Write `AGENTS.md`"), "{sent}");+ assert!(!sent.contains("JAN.md"), "a new project never hears of JAN.md: {sent}");assert!(sent.contains("skill_write"), "{sent}");assert!(sent.contains("memory_write"), "{sent}");let _ = std::fs::remove_dir_all(&app.agent_dir);@@ -37657,7 +37709,7 @@ mod tests {let (mut app, root) = skill_test_app("deploy", "How to deploy.");run_command(&mut app, "reload system-prompt", &no_mcp()).await;assert!(- transcript_text(&app).contains("no JAN.md or [context].fallback_files match"),+ transcript_text(&app).contains("no AGENTS.md or JAN.md"),"empty project: {}",transcript_text(&app));@@ -37670,23 +37722,23 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}- /// #9079 x #9077: `/reload system-prompt` goes through the fallback- /// discovery, so a project with only AGENTS.md reports it (tagged), and a- /// JAN.md added later shadows it.+ /// #9079 x #9077: `/reload system-prompt` goes through the same discovery,+ /// so a project with only AGENTS.md reports it, and a legacy JAN.md added+ /// later shadows it and is labelled.#[tokio::test]async fn reload_system_prompt_reads_agents_md_fallback() {let (mut app, root) = skill_test_app("deploy", "How to deploy.");std::fs::write(root.join("AGENTS.md"), "# Agents\n\nUse make.\n").unwrap();run_command(&mut app, "reload system-prompt", &no_mcp()).await;let out = transcript_text(&app);- assert!(out.contains("AGENTS.md") && out.contains("fallback"), "{out}");+ assert!(out.contains("AGENTS.md (") && !out.contains("fallback"), "{out}");std::fs::write(root.join("JAN.md"), "# Rules\n").unwrap();let before = transcript_text(&app).len();run_command(&mut app, "reload system-prompt", &no_mcp()).await;let out = transcript_text(&app);let tail = &out[before..];- assert!(tail.contains("JAN.md") && !tail.contains("AGENTS.md"), "{tail}");+ assert!(tail.contains("legacy JAN.md") && !tail.contains("AGENTS.md"), "{tail}");let _ = std::fs::remove_dir_all(&root);}@@ -38960,8 +39012,8 @@ mod tests {let _ = std::fs::remove_dir_all(&root);}- /// #9079: a fallback is never silent. No instructions invites `/init`; a- /// JAN.md says nothing; an AGENTS.md fallback names the file it loaded.+ /// #9079/#9083: no instructions invites `/init`; an AGENTS.md says nothing;+ /// a legacy JAN.md (which shadows it) is named as such.#[test]fn startup_note_names_an_agents_md_fallback() {crate::core::agent::global_config::with_temp_home(|_| {@@ -38970,18 +39022,22 @@ mod tests {let _ = std::fs::remove_dir_all(&root);std::fs::create_dir_all(&root).unwrap();let none = super::project_instructions_note(&root).expect("an invitation");- assert!(none.contains("/init"), "{none}");+ assert!(none.contains("/init") && none.contains("AGENTS.md"), "{none}");std::fs::write(root.join("AGENTS.md"), "AGENTS_RULES").unwrap();- let fallback = super::project_instructions_note(&root).expect("a fallback note");- assert!(fallback.contains("AGENTS.md"), "{fallback}");- assert!(fallback.contains("no JAN.md"), "{fallback}");+ assert_eq!(+ super::project_instructions_note(&root),+ None,+ "AGENTS.md is the default: nothing to say"+ );std::fs::write(root.join("JAN.md"), "JAN_RULES").unwrap();- assert_eq!(super::project_instructions_note(&root), None);+ let legacy = super::project_instructions_note(&root).expect("a legacy note");+ assert!(legacy.contains("JAN.md (legacy JAN.md)"), "{legacy}");let _ = std::fs::remove_dir_all(&root);});}- /// `/context` lists the files the project context holds, marking a fallback.+ /// `/context` lists the files the project context holds, labelling a legacy+ /// JAN.md and a CLAUDE.md fallback.#[test]fn context_view_lists_instruction_files_and_marks_a_fallback() {let mut report = context_report(128_000, 16_000, [100, 100, 100, 100, 100]);@@ -39000,36 +39056,83 @@ mod tests {assert!(text.contains("/repo/JAN.md"), "{text}");assert!(text.contains("AGENTS.md"), "{text}");}- assert!(context_text(&report).contains("AGENTS.md (fallback"));+ let text = context_text(&report);+ assert!(text.contains("/repo/JAN.md (legacy JAN.md)"), "{text}");+ assert!(!text.contains("AGENTS.md ("), "AGENTS.md is unlabelled: {text}");+ report.instruction_files = vec![("/repo/CLAUDE.md".into(), true)];+ assert!(context_text(&report).contains("CLAUDE.md (fallback)"));}- /// #9079: `/init` in a project with AGENTS.md and no JAN.md builds on it- /// rather than writing from scratch, and offers the symlink.+ /// #9083: `/init` writes AGENTS.md by default, reviews one that exists,+ /// starts from a CLAUDE.md, keeps a legacy JAN.md, and falls back to JAN.md+ /// when `[context].fallback_files` would not read AGENTS.md.#[test]- fn init_starts_from_an_existing_agents_md() {- let root = std::env::temp_dir().join(format!("jan_init_seed_{}", std::process::id()));- let _ = std::fs::remove_dir_all(&root);- std::fs::create_dir_all(&root).unwrap();- assert_eq!(super::init_seed_file(&root), None);- std::fs::write(root.join("CLAUDE.md"), "CLAUDE_RULES").unwrap();- assert_eq!(super::init_seed_file(&root).as_deref(), Some("CLAUDE.md"));- std::fs::write(root.join("AGENTS.md"), "AGENTS_RULES").unwrap();- assert_eq!(super::init_seed_file(&root).as_deref(), Some("AGENTS.md"));+ fn init_plan_defaults_to_agents_md_and_keeps_a_legacy_jan_md() {+ crate::core::agent::global_config::with_temp_home(|_| {+ let root =+ std::env::temp_dir().join(format!("jan_init_plan_{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&root);+ std::fs::create_dir_all(&root).unwrap();+ let plan = |file, existing, seed| super::InitPlan {+ file,+ existing,+ seed,+ };+ assert_eq!(super::init_plan(&root), plan("AGENTS.md", false, None));+ std::fs::write(root.join("CLAUDE.md"), "CLAUDE_RULES").unwrap();+ assert_eq!(+ super::init_plan(&root),+ plan("AGENTS.md", false, Some("CLAUDE.md"))+ );+ std::fs::write(root.join("AGENTS.md"), "AGENTS_RULES").unwrap();+ assert_eq!(super::init_plan(&root), plan("AGENTS.md", true, None));+ // A legacy JAN.md shadows AGENTS.md, so /init edits it, not AGENTS.md.+ std::fs::write(root.join("JAN.md"), "JAN_RULES").unwrap();+ assert_eq!(super::init_plan(&root), plan("JAN.md", true, None));+ // `fallback_files = []` reads JAN.md only: /init writes that.+ std::fs::remove_file(root.join("JAN.md")).unwrap();+ let store = crate::core::agent::project::store_root(&root);+ std::fs::create_dir_all(&store).unwrap();+ std::fs::write(store.join("agent.toml"), "[context]\nfallback_files = []\n").unwrap();+ assert_eq!(+ super::init_plan(&root),+ plan("JAN.md", false, Some("AGENTS.md"))+ );+ let _ = std::fs::remove_dir_all(&store);+ let _ = std::fs::remove_dir_all(&root);+ });+ }- let mut app = test_app();- app.project_root = root.clone();- super::init_command(&mut app);- let sent = app.history.last().expect("user message").to_string();- assert!(sent.contains("has `AGENTS.md`"), "{sent}");- assert!(sent.contains("ln -s AGENTS.md JAN.md"), "{sent}");- let text: String = row_lines(&app.transcript)- .iter()- .flat_map(|l| l.spans.clone())- .map(|s| s.content.to_string())- .collect();- assert!(text.contains("from this project's AGENTS.md"), "{text}");- let _ = std::fs::remove_dir_all(&app.agent_dir);- let _ = std::fs::remove_dir_all(&root);+ /// `/init` in a project with CLAUDE.md builds AGENTS.md on it; one with a+ /// legacy JAN.md keeps editing it and is told about the rename.+ #[test]+ fn init_prompt_names_the_planned_file() {+ crate::core::agent::global_config::with_temp_home(|_| {+ let root =+ std::env::temp_dir().join(format!("jan_init_seed_{}", std::process::id()));+ let _ = std::fs::remove_dir_all(&root);+ std::fs::create_dir_all(&root).unwrap();+ std::fs::write(root.join("CLAUDE.md"), "CLAUDE_RULES").unwrap();+ let mut app = test_app();+ app.project_root = root.clone();+ super::init_command(&mut app);+ let sent = app.history.last().expect("user message").to_string();+ assert!(sent.contains("Write `AGENTS.md`"), "{sent}");+ assert!(sent.contains("has `CLAUDE.md`"), "{sent}");+ assert!(transcript_text(&app).contains("writing AGENTS.md from this project's CLAUDE.md"));+ let _ = std::fs::remove_dir_all(&app.agent_dir);++ std::fs::write(root.join("JAN.md"), "JAN_RULES").unwrap();+ let mut app = test_app();+ app.project_root = root.clone();+ super::init_command(&mut app);+ let sent = app.history.last().expect("user message").to_string();+ assert!(sent.contains("Write `JAN.md`"), "{sent}");+ assert!(sent.contains("legacy instructions file"), "{sent}");+ assert!(transcript_text(&app).contains("reviewing JAN.md"));+ let _ = std::fs::remove_dir_all(&app.agent_dir);+ let _ = std::fs::remove_dir_all(&root);+ });}#[test]