Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c072888
refactor(context): extract context runtime package
ScriptedAlchemy Aug 13, 2026
9e6ccd8
docs(context): use official Rstack agent plugin
ScriptedAlchemy Aug 13, 2026
ca0661c
Merge remote-tracking branch 'origin/main' into codex/rstack-mcp-obse…
ScriptedAlchemy Aug 13, 2026
b5d8c70
fix(context): keep MCP protocol output clean
ScriptedAlchemy Aug 13, 2026
f0608ee
test(context): canonicalize temporary roots
ScriptedAlchemy Aug 13, 2026
59465fe
test: support context checks on Windows
ScriptedAlchemy Aug 13, 2026
e5fe903
test: allow Windows coverage fixture time
ScriptedAlchemy Aug 13, 2026
8201b62
fix(context): compare complete snapshot evidence
ScriptedAlchemy Aug 13, 2026
5f550a4
fix(context): qualify lint snapshot freshness
ScriptedAlchemy Aug 13, 2026
a05db19
fix(context): normalize Rsdoctor module relations
ScriptedAlchemy Aug 14, 2026
8b3be60
feat(context): capture related Rstest evidence
ScriptedAlchemy Aug 14, 2026
518e89c
chore: prepare context extraction
ScriptedAlchemy Aug 14, 2026
08d8c37
refactor: import context package history
ScriptedAlchemy Aug 14, 2026
e12e172
feat: establish standalone context repository
ScriptedAlchemy Aug 14, 2026
3571e69
build: support source dependency installs
ScriptedAlchemy Aug 14, 2026
993e4f2
fix: make source installs portable
ScriptedAlchemy Aug 14, 2026
7f58090
test: assert portable coverage dependency
ScriptedAlchemy Aug 14, 2026
6c992fa
build: pin integrated Rstack tool versions
ScriptedAlchemy Aug 14, 2026
f2408b0
fix: harden context dogfood workflows
ScriptedAlchemy Aug 14, 2026
cf93f7b
test: dogfood Rsdoctor agent canary
ScriptedAlchemy Aug 14, 2026
7b24854
feat: expose focused context entry points
ScriptedAlchemy Aug 14, 2026
4dab4ab
feat: add structural Rstack context plugin
ScriptedAlchemy Aug 14, 2026
88c35a4
fix: improve degraded evidence capture
ScriptedAlchemy Aug 14, 2026
2f5062e
fix: surface Rstest capture errors
ScriptedAlchemy Aug 14, 2026
8dbb426
docs: clarify code evidence artifact inputs
ScriptedAlchemy Aug 14, 2026
a384ebc
feat: explain related test outcomes
ScriptedAlchemy Aug 14, 2026
2f30659
refactor: simplify context internals
ScriptedAlchemy Aug 14, 2026
0b89c75
feat: improve context evidence fidelity
ScriptedAlchemy Aug 14, 2026
e921c34
fix: collapse nested entry roots
ScriptedAlchemy Aug 14, 2026
c01fd3b
build: pin the Rsdoctor agent CLI canary as the dependency
ScriptedAlchemy Aug 15, 2026
50bce81
build: keep the Rsdoctor canary override root-only
ScriptedAlchemy Aug 15, 2026
291a442
build: make Rsdoctor runtime host-provided
ScriptedAlchemy Aug 15, 2026
2e7c506
fix: ignore test duration jitter in snapshot diffs
ScriptedAlchemy Aug 15, 2026
dfec1ff
fix: bind diagnostics cursors to query filters
ScriptedAlchemy Aug 15, 2026
2dba313
fix: bind lint evidence to captured paths
ScriptedAlchemy Aug 15, 2026
eba8a34
fix: reject unrelated report HTML
ScriptedAlchemy Aug 15, 2026
ff4dbfe
fix: expose truncated build counts
ScriptedAlchemy Aug 15, 2026
c4b9bff
fix: reject unreadable test snapshot inputs
ScriptedAlchemy Aug 15, 2026
d48e151
fix: preserve complete project status evidence
ScriptedAlchemy Aug 15, 2026
711b987
build: validate stacked Rsdoctor preview
ScriptedAlchemy Aug 15, 2026
b52259e
fix: keep optimizer bounds out of product roots
ScriptedAlchemy Aug 17, 2026
619cc51
refactor: externalize Context from Rstack CLI
ScriptedAlchemy Sep 24, 2026
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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
pull_request:
push:
branches: [main]

permissions: {}

jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Enable Corepack
run: corepack enable

- name: Setup Node.js
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: 24.15.0
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check
run: pnpm check

- name: Build
run: pnpm build

- name: Test
run: pnpm test

- name: Pack
run: |
mkdir -p .artifacts
pnpm pack --pack-destination .artifacts
50 changes: 50 additions & 0 deletions .github/workflows/pkg-pr-new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Publish Package Previews

on:
pull_request:
branches: [main]

permissions: {}

jobs:
publish:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Enable Corepack
run: corepack enable

- name: Setup Node.js
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: 24.15.0
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Publish package preview
shell: bash
run: |
set +e
output=$(pnpm exec pkg-pr-new publish --pnpm --previewVersion --no-template '.' 2>&1)
status=$?
set -e
printf '%s\n' "$output"

if [ "$status" -eq 0 ]; then
exit 0
fi

if [[ "$output" == *'There is no workflow defined'* ]]; then
echo '::warning title=pkg.pr.new is not enabled::Grant the pkg.pr.new GitHub App access to rstackjs/context to publish preview packages.'
exit 0
fi

exit "$status"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.artifacts
coverage
dist
dist-tests
node_modules
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage
dist
dist-tests
pnpm-lock.yaml
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 100,
"singleQuote": true
}
37 changes: 37 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# AGENTS.md

## Stack

- Use the Node.js and pnpm versions declared in `package.json`.
- TypeScript package built with Rslib.
- Rsbuild APIs power build-context observation.
- Rstest runs tests and coverage.
- Rslint performs lint and type-aware checks.

## Commands

```bash
corepack enable
pnpm install
pnpm check
pnpm build
pnpm test
pnpm test:coverage
```

## Architecture

- Keep the context runtime independent of the `rstack` CLI package.
- Do not add a Context-specific CLI command, plugin SPI, or generated lint/test wrapper configs.
- Integrate passive builds only through the public Rstack shared-config API from RFC #504.
- Run MCP directly through the programmatic `@rstackjs/context/mcp` stdio entry point.
- Keep Codex and Claude plugin packaging and skills in `rstackjs/agent-skills`.
- Preserve freshness, completeness, provenance, and evidence axes independently.
- Missing Rstack producers must degrade to unavailable evidence rather than prevent other tools from
working.

## Changes

- Add tests for public API, store-schema, MCP-schema, or evidence-semantic changes.
- Keep the package API and MCP tool schemas backward compatible unless a breaking change is explicit.
- Use pkg.pr.new previews for cross-repository shared-config and Agent Skills validation.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Rstack contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
92 changes: 90 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,90 @@
# context
Rstack project context, evidence storage, and MCP runtime.
# Rstack Context

`@rstackjs/context` records and queries checkout-local build, lint, test, coverage, and Rsdoctor
evidence while keeping freshness, completeness, and provenance explicit. The package is independent
of Rstack CLI. Its MCP server runs directly, while passive build capture integrates through ordinary
Rstack shared configuration.

## Add build context

> [!IMPORTANT]
> This integration requires the public `define.extends()` API proposed in
> [Rstack RFC #504](https://github.com/rstackjs/rstack-cli/discussions/504). The lower-level
> implementation is still landing in Rstack, so keep this setup gated until a released Rstack
> version exports that API.

After that API is released, install `@rstackjs/context` and add its shared configuration to
`rstack.config.ts`:

```ts
import { createRstackContextConfig } from '@rstackjs/context/shared-config';
import { define } from 'rstack';

define.extends([
createRstackContextConfig({
products: 'application',
}),
]);

define.app({
// Project-specific settings have the normal highest precedence.
});
```

Use `products: 'library'` for a library-only project, or
`products: ['application', 'library']` when the same Rstack configuration intentionally defines
both. Product selection is explicit so adding Context does not change Rstack's automatic Rstest
App-versus-Lib inheritance.

The factory enables metadata capture by default. Set `capture: 'off'`, or set
`RSTACK_CONTEXT=0`, to disable it. `RSTACK_CONTEXT=1` enables metadata capture for an invocation.

## Run the MCP server

The package exports a programmatic stdio entry point rather than adding a custom CLI command.

For an MCP host configuration:

```json
{
"mcpServers": {
"rstack-context": {
"command": "node",
"args": [
"--input-type=module",
"--eval",
"import('@rstackjs/context/mcp').then(({ runContextMcpServer }) => runContextMcpServer())"
]
}
}
}
```

The server reads completed build observations from `.rstack/cache/context-v1`. Explicit
`lint_snapshot` and `test_snapshot` requests use the selected package's native
`rslint.config.*` and `rstest.config.*` files. `related_tests` lists the Rstest files related to
one or more source files without executing test cases or writing a snapshot. Both Rstest tools
reject a package that has no native `rstest.config.*` instead of falling back to default workspace
discovery. None of these tools requires a custom command, a Rstack CLI plugin SPI, or generated
wrapper configs.

Codex and Claude Code workflow guidance is distributed separately by
[`rstackjs/agent-skills`](https://github.com/rstackjs/agent-skills).

## Development

```bash
corepack enable
pnpm install
pnpm check
pnpm build
pnpm test
```

The package uses Rslib for builds, Rstest for tests, and Rslint for lint and type-aware checks.
Rsbuild remains a public integration surface for build-context observers. See the
[context engine RFC](./docs/rfc.md) for the evidence model.

Execution coverage evidence is optional and resolved against the package under test, not against
`@rstackjs/context` itself. Install `@rstest/coverage-istanbul` or another supported Rstest
coverage provider in the checkout being analyzed.
87 changes: 87 additions & 0 deletions docs/repository-extraction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Rstack Context ownership

## Status

Revised on 2026-09-23 after
[Rstack RFC #504](https://github.com/rstackjs/rstack-cli/discussions/504) replaced the proposed
Context-specific CLI plugin system.

## Decision

`rstackjs/context` owns the complete Context runtime:

- the evidence model and checkout-local store;
- Rsbuild and Rslib observers;
- native Rslint and Rstest capture;
- related-test discovery through Rstest's public reusable instance API;
- Rsdoctor artifact analysis;
- queries and diffs; and
- the programmatic stdio MCP server.

`rstackjs/agent-skills` owns installation manifests and agent workflows. Rstack CLI owns only its
general shared-configuration feature. It does not host Context, add `rs mcp`, generate lint/test
wrapper configs, or provide a Context plugin SPI.

## Runtime architecture

```mermaid
flowchart LR
Host["Codex or Claude"] -->|"stdio"| MCP["@rstackjs/context/mcp"]
Shared["Rstack define.extends()"] --> Observer["Context build observer"]
Observer --> Store[("checkout-local evidence store")]
MCP --> Store
MCP -->|"explicit capture"| Lint["native Rslint config"]
MCP -->|"explicit preflight/capture"| Test["native Rstest config"]
MCP -->|"explicit file"| Doctor["Rsdoctor artifact"]
```

The stdio process is started by importing `runContextMcpServer()`. It is not a package binary or a
custom Rstack command.

## Shared-config gate

Passive build integration uses `@rstackjs/context/shared-config`, but it remains release-gated until
Rstack publishes the complete RFC #504 contract:

- public `RstackConfig`;
- public `define.extends()`;
- shared-layer loading;
- App and Lib native merges; and
- merged Test configuration before automatic App-versus-Lib inheritance.

The package can still ship and run its MCP, lint, test, Rsdoctor, store, and query features without
that Rstack release. Documentation must not present passive build setup as currently available until
the gate is satisfied.

## Native test boundary

Context uses `@rstest/core`'s public `loadConfig()` and reusable `createRstest()` API. It trusts
Rstest's native config discovery order and extensions. If discovery returns no config file,
`related_tests` and `test_snapshot` fail before constructing Rstest or writing a run manifest.

`related_tests` calls `listTests({ filesOnly: true, filters: sources, related: true })`.
`test_snapshot` runs the original source filters with `related: true`; it does not substitute the
preflight's test paths into execution.

## Compatibility

- Preserve the `@rstackjs/context` package name.
- Preserve `.rstack/cache/context-v1` reads and evidence semantics.
- Keep producer failures independent.
- Keep freshness, completeness, provenance, and evidence axes separate.
- Avoid runtime or peer dependencies on `rstack`.
- Do not preserve the abandoned CLI host APIs as compatibility shims.

## Verification

The repository must pass:

- frozen install;
- Rslint type-aware checks and formatting;
- Rslib build and declaration generation;
- the full Rstest suite;
- real stdio MCP initialization;
- native Rstest related preflight and execution;
- missing-config rejection before `createRstest`;
- packed-package import from a clean consumer; and
- pkg.pr.new preview publication.
Loading
Loading