Skip to content

Commit d469089

Browse files
8bitAlexCopilot
andauthored
New Context command (#55)
* add context command * refactor: enhance task schema with shared properties and update documentation * feat: implement recent command logging and enhance context output * feat: enhance context output with agent-readable header and recent command statuses * feat: add tools section to context output for agent discovery * version bump * feat: refactor context structure to align with Model Context Protocol and enhance JSON output * feat: enhance command output to include named task steps in context Co-authored-by: Copilot <copilot@github.com> * code review fixes --------- Co-authored-by: Copilot <copilot@github.com>
1 parent f9c4b09 commit d469089

22 files changed

Lines changed: 2620 additions & 163 deletions

profile.raid.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ commands:
1818
message: "==> Building raid app"
1919
color: cyan
2020
- type: Shell
21+
name: Build raid app
2122
cmd: go build ./...
2223
path: ~/Developer/raid
2324
- type: Print

schemas/raid-defs.schema.json

Lines changed: 385 additions & 157 deletions
Large diffs are not rendered by default.

site/docs/features/tasks.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ These fields apply to all task types.
1313
| Field | Description |
1414
|---|---|
1515
| `type` | Task type (required) |
16+
| `name` | Optional human-readable label, surfaced in logs and agent output. Does not affect execution. |
1617
| `concurrent` | Run this task in parallel with adjacent concurrent tasks |
1718
| `condition` | Only run this task if the condition passes |
1819

site/docs/references/commands.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ For more details, see [Doctor](/docs/usage/doctor).
9292

9393
---
9494

95+
## raid context
96+
97+
Print a condensed snapshot of the active workspace — profile, environment, and per-repository git state.
98+
99+
```bash
100+
raid context # pretty-printed
101+
raid context --json # machine-readable JSON
102+
```
103+
104+
| Flag | Description |
105+
|---|---|
106+
| `--json` | Emit machine-readable JSON instead of the human-readable table |
107+
108+
Output is intentionally token-efficient and bounded — useful for piping into a chat agent or another tool.
109+
110+
For more details, see [Context](/docs/usage/context).
111+
112+
---
113+
95114
## raid \<command\>
96115

97116
Run a custom command defined in the active profile or any of its repositories.

site/docs/references/schema.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ All tasks share these common fields:
183183
| Field | Type | Required | Description |
184184
|---|---|---|---|
185185
| [`type`](#task-types) | string | Yes | Task type (case-sensitive, Title Case) |
186+
| `name` | string | No | Human-readable label, surfaced in logs and agent output. Does not affect execution. |
186187
| `concurrent` | bool | No | Run in parallel with adjacent concurrent tasks |
187188
| [`condition`](#condition) | object | No | Conditions that must all pass for the task to run |
188189

site/docs/usage/context.mdx

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
# Context
6+
7+
Print a condensed snapshot of the active workspace — the profile, environment, and per-repository git state. Designed to be terse enough to paste into a chat agent or pipe into another tool.
8+
9+
```bash
10+
raid context # pretty-printed for humans
11+
raid context --json # machine-readable JSON
12+
```
13+
14+
## What it emits
15+
16+
Every snapshot is **self-describing** so an agent that picks it up out of context can identify the producer:
17+
18+
- **Name** — always `raid`
19+
- **Title** — the human-readable display name, `Raid`
20+
- **Version** — the raid binary version, useful for feature/schema detection
21+
- **Website URL** — canonical GitHub URL the agent can follow for additional documentation, source code search, or issue reporting
22+
- **Generated at** — UTC timestamp of when the snapshot was produced
23+
24+
Followed by the workspace data:
25+
26+
- **Tools** — name and short description of every built-in `raid` subcommand (`install`, `env`, `doctor`, `profile`, `context`). Lets an agent discover what raid itself can do without having to invoke `raid --help`.
27+
- **Active profile name**
28+
- **Active environment** (if one is set)
29+
- **Repositories** — name, configured path, current git branch, dirty status (uncommitted changes), and whether the repo has been cloned to disk
30+
- **Commands** — name and short description of every user-defined `raid <cmd>` available in the active profile. Script bodies are intentionally excluded so the snapshot stays token-efficient and free of inlined secrets. If any of a command's tasks have a `name` field set, those names also surface as a `steps` array — letting an agent see the outline of what the command does without exposing the underlying scripts. Built-in subcommands are listed under **Tools** above and are not duplicated here.
31+
- **Recent runs** — exit status, duration, and relative time of the most recent `raid <cmd>` invocations (capped at 10, persisted in `~/.raid/recent.json`). A run that was killed mid-execution (Ctrl+C, SIGTERM, etc.) is recorded as `interrupted` so you don't lose visibility into terminated commands.
32+
33+
JSON keys use camelCase and the workspace data is grouped under a single `workspace` object. This shape aligns with the [Model Context Protocol](https://modelcontextprotocol.io) so a future `raid context serve` mode (a stdio MCP server) can lift these structures directly into JSON-RPC responses without translation.
34+
35+
Output is intentionally bounded — task script bodies are excluded so the snapshot stays token-efficient for AI agents.
36+
37+
## Pretty output
38+
39+
Default invocation produces a fixed-width table for human reading:
40+
41+
```
42+
# raid v1.2.3 workspace context (2026-04-27T18:00:00Z)
43+
# https://github.com/8bitalex/raid
44+
45+
Profile: my-project
46+
Env: dev
47+
48+
Repos (3):
49+
api ~/dev/my-project/api main clean
50+
frontend ~/dev/my-project/frontend develop dirty
51+
worker ~/dev/my-project/worker not cloned
52+
53+
Tools (5):
54+
context Print a condensed summary of the active workspace
55+
doctor Check the raid configuration and report any issues
56+
env Execute an environment
57+
install Install the active profile
58+
profile Manage raid profiles
59+
60+
Commands (3):
61+
deploy Deploy to production
62+
1. Build artifact
63+
2. Push to registry
64+
3. Apply migrations
65+
test Run tests
66+
reset-db Reset local database
67+
68+
Recent (3):
69+
✓ deploy ok 12.3s 2m ago
70+
✗ test failed 4.5s 5m ago
71+
⊘ migrate interrupted — 18m ago
72+
```
73+
74+
Each row shows a status glyph, the command name, a status word, the duration, and a relative timestamp.
75+
76+
| Glyph | Status word | Meaning |
77+
|---|---|---|
78+
| `` | `ok` | Command completed with exit code 0 |
79+
| `` | `failed` | Command completed with a non-zero exit code |
80+
| `` | `interrupted` | Command was killed before completing (SIGINT, SIGTERM, etc.). Duration is unknown and shown as ``. |
81+
82+
Status values:
83+
84+
| Status | Meaning |
85+
|---|---|
86+
| `clean` | Repository is cloned and has no uncommitted changes |
87+
| `dirty` | Repository is cloned and has uncommitted changes (per `git status --porcelain`) |
88+
| `not cloned` | Path from the profile does not exist on disk, or is not a git repository |
89+
90+
## JSON output
91+
92+
`raid context --json` emits a stable, agent-friendly schema:
93+
94+
```json
95+
{
96+
"name": "raid",
97+
"title": "Raid",
98+
"version": "1.2.3",
99+
"websiteUrl": "https://github.com/8bitalex/raid",
100+
"generatedAt": "2026-04-27T18:00:00Z",
101+
"tools": [
102+
{ "name": "context", "description": "Print a condensed summary of the active workspace" },
103+
{ "name": "doctor", "description": "Check the raid configuration and report any issues" },
104+
{ "name": "env", "description": "Execute an environment" },
105+
{ "name": "install", "description": "Install the active profile" },
106+
{ "name": "profile", "description": "Manage raid profiles" }
107+
],
108+
"workspace": {
109+
"profile": "my-project",
110+
"env": "dev",
111+
"repos": [
112+
{
113+
"name": "api",
114+
"path": "~/dev/my-project/api",
115+
"cloned": true,
116+
"branch": "main",
117+
"dirty": false
118+
},
119+
{
120+
"name": "worker",
121+
"path": "~/dev/my-project/worker",
122+
"cloned": false
123+
}
124+
],
125+
"commands": [
126+
{
127+
"name": "deploy",
128+
"description": "Deploy to production",
129+
"steps": [
130+
{ "name": "Build artifact" },
131+
{ "name": "Push to registry" },
132+
{ "name": "Apply migrations" }
133+
]
134+
},
135+
{ "name": "test", "description": "Run tests" }
136+
],
137+
"recent": [
138+
{
139+
"command": "deploy",
140+
"status": "completed",
141+
"exitCode": 0,
142+
"startedAt": "2026-04-27T12:00:00Z",
143+
"durationMs": 12300
144+
},
145+
{
146+
"command": "migrate",
147+
"status": "interrupted",
148+
"exitCode": 0,
149+
"startedAt": "2026-04-27T11:42:00Z"
150+
}
151+
]
152+
}
153+
}
154+
```
155+
156+
When a repository is not cloned, `branch` and `dirty` are omitted. The `workspace.recent` array is omitted entirely when no commands have been run yet.
157+
158+
## Common uses
159+
160+
```bash
161+
# Drop the current workspace state into a chat agent
162+
raid context | pbcopy
163+
164+
# Feed JSON into another tool
165+
raid context --json | jq '.workspace.repos[] | select(.dirty)'
166+
```

0 commit comments

Comments
 (0)