Skip to content

Commit 49c1155

Browse files
authored
Add repo agent guidance and sync test config (#3)
1 parent c374a31 commit 49c1155

5 files changed

Lines changed: 112 additions & 1 deletion

File tree

AGENTS.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# AGENTS.md
2+
3+
Guidance for coding agents working in this repository.
4+
5+
## Purpose
6+
7+
This repo contains small, self-contained [glance.sh](https://glance.sh) integrations for different coding agents. Each plugin should be easy to read, easy to install, and easy to test locally.
8+
9+
## Repository shape
10+
11+
- Each agent integration lives in its own top-level directory such as `pi/` or `opencode/`.
12+
- Each plugin directory should contain:
13+
- `glance.ts`: the plugin implementation
14+
- `glance.test.ts`: the Vitest suite for that plugin
15+
- `README.md`: install and usage instructions for that plugin
16+
- Shared test-only helpers and runtime stubs belong under `test/`.
17+
18+
## Plugin expectations
19+
20+
- Keep plugins self-contained inside their own directory.
21+
- Prefer platform-native APIs such as `fetch`, `AbortController`, and `ReadableStream` over adding new dependencies.
22+
- Preserve the style already used in the plugin you are editing instead of forcing a repo-wide formatting style.
23+
- Match the repo's writing style: concise, direct, and low on filler in code comments, README copy, and PR text.
24+
- Keep runtime-specific code minimal and explicit. Document runtime assumptions in the plugin `README.md`.
25+
- Update the plugin `README.md` whenever install steps, behavior, supported commands/tools, or runtime requirements change.
26+
- If a plugin has internal async/session logic that is hard to verify from the public API alone, expose a small `__testing` surface rather than making production code more coupled.
27+
28+
## Behavior requirements
29+
30+
Every plugin should cover the same core lifecycle:
31+
32+
- create a glance session
33+
- surface the session URL to the agent or user
34+
- listen for image events over SSE
35+
- handle reconnects, timeouts, expiry, and cancellation
36+
- return or inject the received image URL in the host agent's expected format
37+
38+
If you fix a behavior bug in one plugin, check the other plugins for the same pattern before stopping.
39+
40+
## Testing requirements
41+
42+
- Every plugin must have a Vitest suite in the same directory as the plugin file.
43+
- Tests should cover both the happy path and failure modes, not just basic registration.
44+
- At minimum, cover:
45+
- session creation
46+
- reuse or refresh of persistent sessions
47+
- SSE image delivery
48+
- timeout or expiry handling
49+
- cancellation or shutdown behavior
50+
- user-facing command/tool responses
51+
- Prefer deterministic tests with mocked `fetch`, streams, timers, and runtime APIs.
52+
- Keep tests local to the plugin. Put only reusable stubs or fixtures in `test/`.
53+
54+
## Tooling and config
55+
56+
When adding a new plugin directory or new test-only runtime stub, update the root tooling so it stays in sync:
57+
58+
- `vitest.config.ts`
59+
- `tsconfig.json`
60+
- `package.json` if new scripts are genuinely needed
61+
- `.github/workflows/test.yml` if CI inputs change
62+
63+
Do not add a build step unless the repository actually needs one.
64+
65+
## Validation
66+
67+
Before opening or updating a PR, run:
68+
69+
```bash
70+
npm test
71+
npm run test:coverage
72+
npm exec -- tsc --noEmit
73+
```
74+
75+
If a command cannot be run, say so explicitly and explain why.
76+
77+
## PR checklist
78+
79+
- The plugin implementation, tests, and README are all updated together.
80+
- New behavior is covered by tests.
81+
- Root test/typecheck config includes any new plugin or stub paths.
82+
- CI still runs the repo validation commands on pull requests.
83+
- The PR description calls out user-visible behavior changes and any runtime-specific caveats in concise language.

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

test/stubs/opencode-plugin.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export interface ToolContext {
2+
abort?: AbortSignal;
3+
metadata(input: {
4+
metadata: Record<string, unknown>;
5+
title: string;
6+
}): void;
7+
}
8+
9+
export interface ToolDefinition {
10+
args: Record<string, unknown>;
11+
description: string;
12+
execute(...args: any[]): Promise<string> | string;
13+
}
14+
15+
export type Plugin = (input: {
16+
client: unknown;
17+
}) => Promise<{
18+
event?: (input: { event: { type: string } }) => Promise<void> | void;
19+
tool: Record<string, ToolDefinition>;
20+
}>;
21+
22+
export function tool<T extends ToolDefinition>(definition: T): T {
23+
return definition;
24+
}

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
"noEmit": true,
1111
"baseUrl": ".",
1212
"paths": {
13+
"@opencode-ai/plugin": ["test/stubs/opencode-plugin.ts"],
1314
"@mariozechner/pi-ai": ["test/stubs/pi-ai.ts"],
1415
"@mariozechner/pi-coding-agent": ["test/stubs/pi-coding-agent.ts"],
1516
"@mariozechner/pi-tui": ["test/stubs/pi-tui.ts"]
1617
}
1718
},
1819
"include": [
20+
"opencode/**/*.ts",
1921
"pi/**/*.ts",
2022
"test/**/*.ts",
2123
"vitest.config.ts"

vitest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const resolveFromRoot = (path: string) =>
77
export default defineConfig({
88
resolve: {
99
alias: {
10+
"@opencode-ai/plugin": resolveFromRoot("./test/stubs/opencode-plugin.ts"),
1011
"@mariozechner/pi-ai": resolveFromRoot("./test/stubs/pi-ai.ts"),
1112
"@mariozechner/pi-coding-agent": resolveFromRoot(
1213
"./test/stubs/pi-coding-agent.ts",
@@ -18,7 +19,7 @@ export default defineConfig({
1819
clearMocks: true,
1920
coverage: {
2021
all: true,
21-
include: ["pi/**/*.ts"],
22+
include: ["opencode/**/*.ts", "pi/**/*.ts"],
2223
provider: "v8",
2324
reporter: ["text", "lcov"],
2425
},

0 commit comments

Comments
 (0)