Skip to content

/init command #976

@jsburckhardt

Description

@jsburckhardt

Describe the feature or problem you'd like to solve

/init generates a AGENTS.md

Proposed solution

expose /init command to generate a AGENTS.md. It is a well know practice and used in different environments. agents.md
e.g. opencode uses something like this link

Example prompts or workflows

steps:

  1. open copilot
  2. inside copilot execute /init
  3. create AGENTS.md or if exists enrich AGENTS.md

ste / cnl prompt sample ->

<instructions>
You MUST analyze the codebase to create a comprehensive AGENTS.md file for AI coding agents.
You MUST include build, lint, and test commands with emphasis on running single tests.
You MUST document code style guidelines covering imports, formatting, types, naming, and error handling.
You MUST search for and incorporate existing Cursor rules from .cursor/rules/ or .cursorrules.
You MUST search for and incorporate existing Copilot instructions from .github/copilot-instructions.md.
You MUST aim for approximately 150 lines of actionable content.
You MUST update the existing AGENTS.md if one is already present in the workspace.
You MUST append any user-provided instructions from CUSTOM_INSTRUCTIONS.
</instructions>

<constants>
TARGET_FILE: "AGENTS.md"
TARGET_LENGTH: 150
CURSOR_RULES_PATTERNS: JSON<<
[".cursor/rules/*.md", ".cursorrules"]
>>
COPILOT_INSTRUCTIONS: ".github/copilot-instructions.md"
REQUIRED_SECTIONS: JSON<<
{
  "commands": {
    "build": "Commands to build the project",
    "lint": "Commands to lint code",
    "test": "Commands to run all tests",
    "test_single": "Commands to run a single test file or case"
  },
  "style": {
    "imports": "Import organization and conventions",
    "formatting": "Code formatting rules",
    "types": "Type annotation requirements",
    "naming": "Naming conventions for files, variables, functions, classes",
    "errors": "Error handling patterns"
  }
}
>>
SEARCH_TARGETS: JSON<<
[
  "package.json",
  "tsconfig.json",
  "*.config.js",
  "*.config.ts",
  "Makefile",
  "justfile",
  ".eslintrc*",
  ".prettierrc*"
]
>>
</constants>

<formats>
<format id="AGENTS_OUTPUT" name="AGENTS.md Output" purpose="Return the generated AGENTS.md content with metadata.">
# AGENTS.md Generated

**Status**: <STATUS>
**Lines**: <LINE_COUNT>
**Updated existing**: <WAS_UPDATE>

```markdown
<CONTENT>
```

WHERE:
- <CONTENT> is String.
- <LINE_COUNT> is Number.
- <STATUS> is one of: created, updated.
- <WAS_UPDATE> is Boolean.
</format>
</formats>

<runtime>
CUSTOM_INSTRUCTIONS: ""
BUILD_COMMANDS: ""
LINT_COMMANDS: ""
TEST_COMMANDS: ""
SINGLE_TEST_CMD: ""
IMPORT_STYLE: ""
FORMAT_RULES: ""
TYPE_RULES: ""
NAMING_RULES: ""
ERROR_PATTERNS: ""
CURSOR_RULES: ""
COPILOT_RULES: ""
EXISTING_CONTENT: ""
FINAL_CONTENT: ""
FILE_EXISTS: false
LINE_COUNT: 0
</runtime>

<triggers>
<trigger event="user_message" target="main" />
</triggers>

<processes>
<process id="main" name="Generate AGENTS.md">
RUN `check_existing`
RUN `discover_tooling`
RUN `analyze_code_style`
RUN `gather_existing_rules`
RUN `compose_agents_file`
RUN `write_file`
RETURN: content=FINAL_CONTENT, line_count=LINE_COUNT, status=FILE_EXISTS, was_update=FILE_EXISTS
</process>

<process id="check_existing" name="Check for existing AGENTS.md">
USE `read/readFile` where: filePath=TARGET_FILE
CAPTURE EXISTING_CONTENT from `read/readFile`
IF EXISTING_CONTENT is not empty:
  SET FILE_EXISTS := true (from "Agent Inference")
</process>

<process id="discover_tooling" name="Discover build/test tooling">
USE `search/fileSearch` where: pattern="**/package.json"
USE `search/fileSearch` where: pattern="**/{tsconfig.json,*.config.js,*.config.ts,Makefile,justfile}"
USE `search/codebase` where: query="test script commands npm run build lint"
SET BUILD_COMMANDS := <BUILD_CMD_TEXT> (from "Agent Inference")
SET LINT_COMMANDS := <LINT_CMD_TEXT> (from "Agent Inference")
SET TEST_COMMANDS := <TEST_CMD_TEXT> (from "Agent Inference")
SET SINGLE_TEST_CMD := <SINGLE_TEST_TEXT> (from "Agent Inference")
</process>

<process id="analyze_code_style" name="Analyze code style patterns">
USE `search/codebase` where: query="import statements module resolution"
USE `search/codebase` where: query="type annotations interface definitions"
USE `search/codebase` where: query="error handling try catch throw"
SET IMPORT_STYLE := <IMPORT_PATTERNS> (from "Agent Inference")
SET FORMAT_RULES := <FORMAT_PATTERNS> (from "Agent Inference")
SET TYPE_RULES := <TYPE_PATTERNS> (from "Agent Inference")
SET NAMING_RULES := <NAMING_PATTERNS> (from "Agent Inference")
SET ERROR_PATTERNS := <ERROR_PATTERNS> (from "Agent Inference")
</process>

<process id="gather_existing_rules" name="Gather existing agent rules">
USE `search/fileSearch` where: pattern=".cursor/rules/*.md"
USE `search/fileSearch` where: pattern=".cursorrules"
USE `read/readFile` where: filePath=COPILOT_INSTRUCTIONS
CAPTURE COPILOT_RULES from `read/readFile`
SET CURSOR_RULES := <CURSOR_CONTENT> (from "Agent Inference")
</process>

<process id="compose_agents_file" name="Compose AGENTS.md content">
SET FINAL_CONTENT := <AGENTS_MD_TEXT> (from "Agent Inference" using BUILD_COMMANDS, LINT_COMMANDS, TEST_COMMANDS, SINGLE_TEST_CMD, IMPORT_STYLE, FORMAT_RULES, TYPE_RULES, NAMING_RULES, ERROR_PATTERNS, CURSOR_RULES, COPILOT_RULES, EXISTING_CONTENT, CUSTOM_INSTRUCTIONS, TARGET_LENGTH, REQUIRED_SECTIONS)
SET LINE_COUNT := <LINE_COUNT> (from "Agent Inference" using FINAL_CONTENT)
</process>

<process id="write_file" name="Write or update AGENTS.md">
IF FILE_EXISTS is true:
  USE `edit/editFiles` where: filePath=TARGET_FILE, edits=FINAL_CONTENT
ELSE:
  USE `edit/createFile` where: filePath=TARGET_FILE, content=FINAL_CONTENT
</process>
</processes>

<input>
CUSTOM_INSTRUCTIONS contains optional user-provided requirements or additional sections to include in AGENTS.md.
</input>

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions