Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/skill-project-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/intent': patch
---

Add project options for skills. A skill can ship an `options.json` file beside its `SKILL.md` that declares choices, each with a question, the allowed values, and a default. A project records its answers under `intent.options` in `package.json`, and `intent load` appends a `## Project options` section with the recorded choices and the defaults for the rest. `intent validate` checks the file. Skills without `options.json` load unchanged.
1 change: 1 addition & 0 deletions docs/cli/intent-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ id: intent-load
### Output

- Prints raw `SKILL.md` content by default
- Appends a `## Project options` section when the skill ships an `options.json` file; see [Configuration](../concepts/configuration)
- Prints the scanner-reported path when `--path` is passed
- Prints debug details to stderr when `--debug` is passed

Expand Down
19 changes: 19 additions & 0 deletions docs/cli/intent-validate.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ A skill without reference files needs no `references` key. A skill without a tre

Upgrade impact: a repository that already has reference files fails validation when a reference file is not linked directly from its `SKILL.md`, begins with frontmatter, or contains a code example that does not typecheck, or when a matching `skill_tree.yaml` entry does not list the skill's reference files.

### Options file

A skill can ship an `options.json` file beside its `SKILL.md` to declare choices that a consuming project records in [`intent.options`](../concepts/configuration). When the file exists, it is checked with its skill.

```json
{
"framework": {
"question": "Which framework does this app use?",
"choices": ["nextjs", "tanstack-start", "other"],
"default": "other"
}
}
```

- The file is a JSON object; each key is an option name
- `question` is a non-empty string
- `choices` is a non-empty array of non-empty strings
- `default` is one of `choices`; it applies when a project has not recorded a choice

### Artifacts

When `<dir>/_artifacts` exists, Intent also checks:
Expand Down
45 changes: 45 additions & 0 deletions docs/concepts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Configure Intent in the `intent` object in `package.json`:

- **`skills`** permits packages or individual skills.
- **`exclude`** blocks packages or skills after permissions are evaluated.
- **`options`** records this project's choices for skills that declare options.

```json
{
Expand All @@ -28,6 +29,7 @@ Configure Intent in the `intent` object in `package.json`:
| --- | --- |
| `intent.skills` | Uses the nearest non-null declaration between the current directory and the workspace or project root. A nearer declaration replaces its parent; omitted or null values inherit. |
| `intent.exclude` | Combines arrays from the root through the current directory, then adds excludes passed by the caller. |
| `intent.options` | Merges each skill's choices from the root through the current directory. A nearer package replaces a single choice and inherits the rest. |

## `intent.skills`

Expand Down Expand Up @@ -164,3 +166,46 @@ Use `intent exclude` to manage this list from the CLI:
| `@scope/pkg#*` | The whole package, using the `#*` shortcut. |

Each segment supports exact names and `*` wildcards only. Excludes apply to both npm and workspace sources with matching names, regardless of source kind.

## `intent.options`

Some skills give different guidance depending on choices your project has made, such as which framework it uses. A skill declares those choices in an `options.json` file beside its `SKILL.md`. `intent.options` records your project's answers, so every agent session loads the skill with the same choices.

```json
{
"intent": {
"options": {
"@acme/client#setup": {
"framework": "tanstack-start"
}
}
}
}
```

Each key is a skill in `<package>#<skill>` form. Each value maps an option name to one of the choices the skill declares.

When a skill has an `options.json` file, `intent load` appends a `## Project options` section to its content. The section lists each recorded choice. For an option you have not recorded, it lists the skill's default with the question and the available choices:

```text
## Project options

Choices this project made for `@acme/client#setup`, from `intent.options` in `package.json`. Follow the guidance that matches them.

- framework: tanstack-start
- fragmentColocation: yes (default, not recorded). Set up fragment colocation? Choices: yes, no.
```

Intent reads `options.json` as data. It does not run code from the package. A skill without `options.json` loads unchanged, even when `intent.options` has an entry for it.

### Option warnings

`intent load` prints a warning on stderr and continues in these cases:

| Situation | Result |
| --- | --- |
| A recorded value is not one of the declared choices | The skill's default applies. |
| A recorded option is not declared by the skill | The entry is ignored. |
| The skill's `options.json` is invalid or links outside its package | The skill loads without the section. |

Maintainers can find the file format under [Options file](../cli/intent-validate#options-file).
10 changes: 10 additions & 0 deletions packages/intent/src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { parseDocument, parse as parseYaml } from 'yaml'
import { fail, isCliFailure } from '../shared/cli-error.js'
import { readScalarField } from '../shared/utils.js'
import { resolveProjectContext } from '../core/project-context.js'
import { SKILL_OPTIONS_FILE, parseSkillOptions } from '../core/skill-options.js'
import { findWorkspacePackages } from '../setup/workspace-patterns.js'
import { createIntentFsCache } from '../discovery/fs-cache.js'
import {
Expand Down Expand Up @@ -629,6 +630,15 @@ async function runValidateCommandInternal(

const skillDir = dirname(filePath)
const skillName = basename(skillDir)
const optionsPath = join(skillDir, SKILL_OPTIONS_FILE)
if (existsSync(optionsPath)) {
const file = relative(process.cwd(), optionsPath)
for (const message of parseSkillOptions(
readFileSync(optionsPath, 'utf8'),
).errors) {
errors.push({ file, message })
}
}
const referenceFiles = findReferenceFiles(skillDir)
const linked = new Set(
referenceFiles.length
Expand Down
4 changes: 2 additions & 2 deletions packages/intent/src/core/excludes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export function isPackageExcluded(
)
}

// A prefixed skill is loadable by its short alias too; an exclude must match either form.
function skillNameVariants(
// A prefixed skill is loadable by its short alias too; config keyed by skill must match either form.
export function skillNameVariants(
packageName: string,
skillName: string,
): Array<string> {
Expand Down
118 changes: 84 additions & 34 deletions packages/intent/src/core/intent-core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAbsolute, relative, resolve } from 'node:path'
import { dirname, isAbsolute, join, relative, resolve } from 'node:path'
import { createIntentFsCache } from '../discovery/fs-cache.js'
import { ResolveSkillUseError, resolveSkillUse } from '../skills/resolver.js'
import { formatSkillUse, parseSkillUse } from '../skills/use.js'
Expand All @@ -9,6 +9,11 @@ import {
import { rewriteLoadedSkillMarkdownDestinations } from './markdown.js'
import { resolveSkillUseFastPath } from './load-resolution.js'
import { resolveProjectContext } from './project-context.js'
import {
SKILL_OPTIONS_FILE,
appendProjectOptions,
readRecordedOptions,
} from './skill-options.js'
import {
checkLoadAllowed,
isSourcePermitted,
Expand All @@ -20,6 +25,7 @@ import type { ResolveSkillResult } from '../skills/resolver.js'
import type { IntentFsCache } from '../discovery/fs-cache.js'
import type { ReadFs } from '../shared/utils.js'
import type { ScanOptions, ScanScope } from '../shared/types.js'
import type { ProjectContext } from './project-context.js'
import type {
IntentCoreErrorCode,
IntentCoreOptions,
Expand Down Expand Up @@ -267,6 +273,8 @@ function resolveIntentSkillInCwd(
use: string,
options: IntentCoreOptions = {},
): {
fsCache: IntentFsCache
projectContext: ProjectContext
realPackageRoot: string
realResolvedPath: string
readFs: ReadFs
Expand Down Expand Up @@ -318,22 +326,26 @@ function resolveIntentSkillInCwd(
const lateRefusal = packageNotListedRefusal(use, parsedUse.packageName)
throw new IntentCoreError(lateRefusal.code, lateRefusal.message)
}
return toResolvedIntentSkill(
cwd,
use,
fastPathResolved,
fsCache.getReadFs(),
options.debug
? createLoadedSkillDebug({
cwd,
excludes: excludePatterns,
resolution: 'fast-path',
resolved: fastPathResolved,
scan: fsCache.getStats(),
scope,
})
: undefined,
)
return {
fsCache,
projectContext,
...toResolvedIntentSkill(
cwd,
use,
fastPathResolved,
fsCache.getReadFs(),
options.debug
? createLoadedSkillDebug({
cwd,
excludes: excludePatterns,
resolution: 'fast-path',
resolved: fastPathResolved,
scan: fsCache.getStats(),
scope,
})
: undefined,
),
}
}

const { scan: scanResult, droppedNames } = scanForPolicedIntents({
Expand All @@ -358,22 +370,26 @@ function resolveIntentSkillInCwd(
throw err
}

return toResolvedIntentSkill(
cwd,
use,
resolved,
fsCache.getReadFs(),
options.debug
? createLoadedSkillDebug({
cwd,
excludes: excludePatterns,
resolution: 'full-scan',
resolved,
scan: scanResult.stats,
scope,
})
: undefined,
)
return {
fsCache,
projectContext,
...toResolvedIntentSkill(
cwd,
use,
resolved,
fsCache.getReadFs(),
options.debug
? createLoadedSkillDebug({
cwd,
excludes: excludePatterns,
resolution: 'full-scan',
resolved,
scan: scanResult.stats,
scope,
})
: undefined,
),
}
}

export function resolveIntentSkill(
Expand All @@ -395,9 +411,43 @@ export function loadIntentSkill(
packageRoot: resolved.realPackageRoot,
skillFilePath: resolved.realResolvedPath,
})
const optionsFile = join(
dirname(resolved.realResolvedPath),
SKILL_OPTIONS_FILE,
)
if (!resolved.readFs.existsSync(optionsFile)) {
return { ...resolved.result, content }
}

const optionsPath = resolved.readFs.realpathSync.native(optionsFile)
const { packageName, skillName } = resolved.result
const skillUse = formatSkillUse(packageName, skillName)
const projectOptions = isResolvedPathInsidePackageRoot(
optionsPath,
resolved.realPackageRoot,
)
? appendProjectOptions(
content,
resolved.readFs.readFileSync(optionsPath, 'utf8'),
skillUse,
readRecordedOptions(
cwd,
resolved.projectContext,
resolved.fsCache,
packageName,
skillName,
),
)
: {
content,
warnings: [
`Ignored ${SKILL_OPTIONS_FILE} for "${skillUse}": the file is outside the package`,
],
}

return {
...resolved.result,
content,
content: projectOptions.content,
warnings: [...resolved.result.warnings, ...projectOptions.warnings],
}
}
Loading
Loading