AgentSkillsCN

project-detection

检测项目类型、包管理器和monorepo结构。返回正确的测试/构建/lint/开发命令。在项目初始化时运行并缓存结果到状态。在运行任何构建/测试命令之前使用。

SKILL.md
--- frontmatter
name: project-detection
description: Detects project type, package manager, and monorepo structure. Returns correct commands for test/build/lint/dev. Run at project initialization and cache results in state. Use before running any build/test commands.

Project Detection

Detects project configuration and provides standardized commands. Run once at init, cache in state file.

Usage

Run the detection script from the project root:

bash
./marathon-ralph/skills/project-detection/scripts/detect.sh /path/to/project

Returns JSON:

json
{
  "language": "node",
  "packageManager": "bun",
  "monorepo": {
    "type": "turbo",
    "workspaces": ["apps/web", "apps/api", "packages/shared"]
  },
  "commands": {
    "install": "bun install",
    "dev": "bun run dev",
    "build": "bun run build",
    "test": "bun run test",
    "testWorkspace": "bun run --filter={workspace} test",
    "lint": "bun run lint",
    "typecheck": "bun run check-types"
  }
}

Caching Results

After detection, store in marathon state file under project key:

json
{
  "project": {
    "language": "node",
    "packageManager": "bun",
    "monorepo": { "type": "turbo", "workspaces": [...] },
    "commands": { ... },
    "detectedAt": "2024-01-03T12:00:00Z"
  }
}

Using Cached Commands

When running commands, always check state first:

  1. Read project.commands from state
  2. If not present, run detection script
  3. Use the appropriate command from the cache

For Monorepos

When tests/builds need to target a specific workspace:

bash
# Use testWorkspace with the workspace name
bun run --filter=web test

# Or for all workspaces
turbo run test

Command Selection Priority

  1. Use cached command from state
  2. If no cache, run detection
  3. If detection fails, fall back to reference patterns

Detection Logic

Package Manager Detection (by lock file)

Lock FilePackage ManagerInstallRun
bun.lock or bun.lockbbunbun installbun run
pnpm-lock.yamlpnpmpnpm installpnpm run
yarn.lockyarnyarn installyarn
package-lock.jsonnpmnpm installnpm run

Monorepo Detection

Config FileMonorepo Type
turbo.jsonTurborepo
nx.jsonNx
lerna.jsonLerna
pnpm-workspace.yamlpnpm workspaces
package.json with workspacesnpm/yarn workspaces

Language Detection

IndicatorLanguage
package.jsonNode.js
pyproject.toml, setup.pyPython
go.modGo
Cargo.tomlRust
build.gradle, pom.xmlJava

Python Project Commands

For Python projects:

ToolInstallRun ScriptTest
poetrypoetry installpoetry run {script}poetry run pytest
poetry+poepoetry installpoe {task}poe test
pip + venvpip install -r requirements.txtpython -m {module}pytest
uvuv pip install -r requirements.txtuv run {script}uv run pytest
pipenvpipenv installpipenv run {script}pipenv run pytest

Note: If [tool.poe.tasks] exists in pyproject.toml, poe commands are preferred.

Reference Files