-
Notifications
You must be signed in to change notification settings - Fork 71
Scope agent context: extract conventions, enforce git restrictions via hooks #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7ea73dc
7a0614a
533a6f1
87b3261
7db86c9
9e460aa
a1befc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "hooks": { | ||
| "PreToolUse": [ | ||
| { | ||
| "matcher": "Bash", | ||
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "uv run python scripts/block_git_mutations.py", | ||
| "timeout": 5 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| When generating Python code (e.g. when translating TypeScript to Python), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like hiding things under .github either. If we want to go through with this (I'm still skeptical) we should collect all the agent instructions in a single top-level directory (not hidden) and explain in AGENTS.md how to use them. |
||
| follow these guidelines: | ||
|
|
||
| * When creating a new file, add a copyright header to the top: | ||
| ``` | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| ``` | ||
|
|
||
| * Assume Python 3.12 | ||
|
|
||
| * Always strip trailing spaces | ||
|
|
||
| * Keep class and type names in `PascalCase` | ||
| * Use `python_case` for variable/field and function/method names | ||
|
|
||
| * Use `Literal` for unions of string literals | ||
| * Keep union notation (`X | Y`) for other unions | ||
| * Use `Protocol` for interfaces whose name starts with `I` followed by a capital letter | ||
| * Use `dataclass` for other classes and structured types | ||
| * Use `type` for type aliases (`PascalCase` again) | ||
| * Use `list`, `tuple`, `dict`, `set` etc., not `List` etc. | ||
|
|
||
| * Translate `foo?: string` to `foo: str | None = None` | ||
|
|
||
| * When writing tests: | ||
| - don't mock; use the regular implementation (maybe introduce a fixture to create it) | ||
| - assume `pytest`; use `assert` statements | ||
| - match the type annotations of the tested functions | ||
| - read the code of the tested functions to understand their behavior | ||
| - When using fixtures: | ||
| - Fully type-annotate the fixture definitions (including return type) | ||
| - Fully type-annotate fixture usages | ||
|
|
||
| * Don't put imports inside functions. | ||
| Put them at the top of the file with the other imports. | ||
| Exception: imports in a `if __name__ == "__main__":` block or a `main()` function. | ||
| Another exception: pydantic and logfire. | ||
| Final exception: to avoid circular import errors. | ||
|
|
||
| * **Import Architecture Rules**: | ||
| - **Never import a symbol from a module that just re-exports it** | ||
| - **Always import directly from the module that defines the symbol** | ||
| - **Exception**: Package `__init__.py` files that explicitly re-export with `__all__` | ||
| - **Exception**: Explicit re-export patterns like `from ... import X as X` or marked with "# For export" | ||
| - This prevents circular imports and makes dependencies clear | ||
|
|
||
| * Order imports alphabetically after lowercasing; group them as follows | ||
| (with a blank line between groups): | ||
| 1. standard library imports | ||
| 2. established third-party libraries | ||
| 3. experimental third-party libraries (e.g. `typechat`) | ||
| 4. local imports (e.g. `from typeagent.knowpro import ...`) | ||
|
|
||
| * **Error Handling**: Don't use `try/except Exception` to catch errors broadly. | ||
| Let errors bubble up naturally for proper error handling and debugging at higher levels. | ||
|
|
||
| * **Code Validation**: Don't use `py_compile` for syntax checking. | ||
| Use `pyright` or `make check` instead for proper type checking and validation. | ||
|
|
||
| * **Deprecations**: Don't deprecate things -- just delete them and fix the usage sites. | ||
| Don't create backward compatibility APIs or exports or whatever. Fix the usage sites. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| Get your instructions from AGENTS.md in the repo root. | ||
|
|
||
| For code generation and style conventions, see [code-conventions.md](code-conventions.md). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this into AGENTS.md |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # Editor settings | ||
| .vscode | ||
| # Editor settings (but .vscode/settings.json is tracked for Copilot hooks) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I would be against this. |
||
| .vscode/* | ||
| !.vscode/settings.json | ||
|
|
||
| # Python | ||
| __pycache__ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "github.copilot.chat.agent.hooks": { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file varies per user. We can't replace it with this. At best we could move this to README.md for humans to manually add there. (Or possibly we can add it to AGENTS.md. :-) |
||
| "PreToolUse": [ | ||
| { | ||
| "type": "command", | ||
| "command": "uv run python scripts/block_git_mutations.py", | ||
| "windows": "uv run python scripts\\block_git_mutations.py", | ||
| "timeout": 5 | ||
| } | ||
| ] | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same objection as for .vscode