ai-execution-protocol 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_execution_protocol-0.1.0/LICENSE +21 -0
- ai_execution_protocol-0.1.0/PKG-INFO +180 -0
- ai_execution_protocol-0.1.0/README.md +159 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/__init__.py +3 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/__main__.py +5 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/cli.py +283 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/README.yaml +35 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/__init__.py +0 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/context-compiler.yaml +110 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/context-rules.yaml +71 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/execution-rules.yaml +56 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/fast-path.yaml +33 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/formatting-rules.yaml +75 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/mapping-checklists.yaml +42 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/modes.yaml +42 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/prompt-economy.yaml +96 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/risk-levels.yaml +87 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/router.yaml +100 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/spec-driven.yaml +53 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol/protocol/validation-checklist.yaml +59 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol.egg-info/PKG-INFO +180 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol.egg-info/SOURCES.txt +25 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol.egg-info/dependency_links.txt +1 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol.egg-info/entry_points.txt +2 -0
- ai_execution_protocol-0.1.0/ai_execution_protocol.egg-info/top_level.txt +1 -0
- ai_execution_protocol-0.1.0/pyproject.toml +37 -0
- ai_execution_protocol-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AI Execution Protocol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai-execution-protocol
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Experimental AI execution protocol for safer agent workflows, minimal context, risk classification, validation, and evidence-based delivery.
|
|
5
|
+
Author: AI Execution Protocol
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rodneigk2/ai-execution-protocol
|
|
8
|
+
Project-URL: Repository, https://github.com/rodneigk2/ai-execution-protocol.git
|
|
9
|
+
Project-URL: Issues, https://github.com/rodneigk2/ai-execution-protocol/issues
|
|
10
|
+
Keywords: ai,agent,codex,protocol,risk,validation,prompt
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Topic :: Software Development
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# AI Execution Protocol
|
|
23
|
+
|
|
24
|
+
Framework experimental para orientar agentes de IA em tarefas tecnicas com mais
|
|
25
|
+
seguranca, contexto minimo, validacao e controle de risco.
|
|
26
|
+
|
|
27
|
+
O alvo atual e Codex. O protocolo e otimizado para Codex agora, mas foi
|
|
28
|
+
organizado para continuar portavel para outras IAs no futuro.
|
|
29
|
+
|
|
30
|
+
## Objetivo
|
|
31
|
+
|
|
32
|
+
Evitar que a IA execute pedidos de forma impulsiva, perigosa ou fora de escopo.
|
|
33
|
+
|
|
34
|
+
O framework ajuda a IA a:
|
|
35
|
+
|
|
36
|
+
- entender a intencao antes de agir;
|
|
37
|
+
- classificar o risco da tarefa;
|
|
38
|
+
- ler apenas o contexto necessario;
|
|
39
|
+
- mapear impacto antes de alterar arquivos;
|
|
40
|
+
- pedir confirmacao em acoes sensiveis;
|
|
41
|
+
- validar o resultado antes de entregar;
|
|
42
|
+
- explicar limites e risco residual.
|
|
43
|
+
|
|
44
|
+
## Ideia central
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
Entender -> classificar risco -> mapear impacto -> executar -> validar -> entregar
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
O protocolo nao tenta transformar toda tarefa em um processo pesado. A regra e
|
|
51
|
+
proporcionalidade: tarefa simples deve ser rapida; tarefa critica exige mais
|
|
52
|
+
mapa, confirmacao e evidencia.
|
|
53
|
+
|
|
54
|
+
## Status
|
|
55
|
+
|
|
56
|
+
Projeto em fase de pesquisa e evolucao.
|
|
57
|
+
|
|
58
|
+
Este repositorio contem uma proposta tecnica, nao uma garantia de seguranca nem
|
|
59
|
+
uma fonte normativa definitiva. Testes reais, revisao humana e criterio tecnico
|
|
60
|
+
continuam obrigatorios em tarefas criticas.
|
|
61
|
+
|
|
62
|
+
## Estrutura
|
|
63
|
+
|
|
64
|
+
- `AGENTS.md`: instrucao principal para agentes no projeto.
|
|
65
|
+
- `INDEX.yaml`: mapa estruturado para navegacao rapida.
|
|
66
|
+
- `config.yaml`: configuracao do alvo atual e versao do protocolo.
|
|
67
|
+
- `docs/`: explicacoes conceituais em Markdown.
|
|
68
|
+
- `protocol/`: regras operacionais curtas em YAML.
|
|
69
|
+
- `cases/`: casos estruturados para testar o comportamento da IA.
|
|
70
|
+
- `examples/`: exemplos humanos de uso do framework.
|
|
71
|
+
- `schema/`: contratos para manter os YAML padronizados.
|
|
72
|
+
- `eval/`: rubrica e exemplos de avaliacao.
|
|
73
|
+
- `scripts/`: automacoes de instalacao, validacao e avaliacao.
|
|
74
|
+
- `responses/`: exemplos de respostas para avaliacao.
|
|
75
|
+
- `benchmarks/`: comparacoes entre execucao com e sem protocolo.
|
|
76
|
+
- `model-runs/`: respostas reais por modelo para comparacao.
|
|
77
|
+
- `real-runs/`: templates ou registros de execucoes reais auditaveis.
|
|
78
|
+
- `dist/minimal/`: pacote minimo gerado para instalar em outros projetos.
|
|
79
|
+
|
|
80
|
+
## Como usar como agente
|
|
81
|
+
|
|
82
|
+
1. Leia `INDEX.yaml`.
|
|
83
|
+
2. Confirme o alvo atual em `config.yaml`.
|
|
84
|
+
3. Leia `protocol/fast-path.yaml`.
|
|
85
|
+
4. Use `protocol/router.yaml` para escolher o menor contexto suficiente.
|
|
86
|
+
5. Abra apenas os arquivos indicados pela rota.
|
|
87
|
+
6. Execute, valide e entregue com evidencia.
|
|
88
|
+
|
|
89
|
+
## Como estudar o framework
|
|
90
|
+
|
|
91
|
+
Comece por:
|
|
92
|
+
|
|
93
|
+
- `docs/00-visao-geral.md`
|
|
94
|
+
- `docs/01-modelo-de-execucao.md`
|
|
95
|
+
- `docs/02-niveis-de-risco.md`
|
|
96
|
+
- `docs/03-mapeamento-antes-de-alterar.md`
|
|
97
|
+
- `docs/05-validacao-e-entrega.md`
|
|
98
|
+
- `docs/14-publicacao.md`
|
|
99
|
+
|
|
100
|
+
Use `docs/` para entender a metodologia. Use `protocol/` quando quiser aplicar
|
|
101
|
+
as regras em uma tarefa real.
|
|
102
|
+
|
|
103
|
+
## Validacao local
|
|
104
|
+
|
|
105
|
+
Execute a validacao geral:
|
|
106
|
+
|
|
107
|
+
```powershell
|
|
108
|
+
python scripts/health_check.py
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Execute a bateria estrutural extra:
|
|
112
|
+
|
|
113
|
+
```powershell
|
|
114
|
+
python scripts/framework_tests.py
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Meca custo aproximado de leitura por rota:
|
|
118
|
+
|
|
119
|
+
```powershell
|
|
120
|
+
python scripts/token_report.py
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Instalacao em outro projeto
|
|
124
|
+
|
|
125
|
+
Projeto novo:
|
|
126
|
+
|
|
127
|
+
```powershell
|
|
128
|
+
ai-protocol init .
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Projeto existente:
|
|
132
|
+
|
|
133
|
+
```powershell
|
|
134
|
+
ai-protocol install .
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Previa sem alterar arquivos:
|
|
138
|
+
|
|
139
|
+
```powershell
|
|
140
|
+
ai-protocol install . --dry-run
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Instalacao local via PowerShell:
|
|
144
|
+
|
|
145
|
+
```powershell
|
|
146
|
+
.\install.ps1 C:\caminho\projeto -Force
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Instalacao local via npm:
|
|
150
|
+
|
|
151
|
+
```powershell
|
|
152
|
+
npm run install-protocol -- C:\caminho\projeto
|
|
153
|
+
npm run dry-run-protocol -- C:\caminho\projeto
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Instalacao local via Python:
|
|
157
|
+
|
|
158
|
+
```powershell
|
|
159
|
+
python scripts/install_protocol.py --target C:\caminho\projeto --force
|
|
160
|
+
python scripts/verify_install.py --target C:\caminho\projeto
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
O final esperado da verificacao e `PASS`.
|
|
164
|
+
|
|
165
|
+
## Publicacao
|
|
166
|
+
|
|
167
|
+
Antes de publicar, revise `docs/14-publicacao.md`.
|
|
168
|
+
|
|
169
|
+
Resumo minimo:
|
|
170
|
+
|
|
171
|
+
- nao publique `.env`, chaves, tokens, senhas, logs reais ou dados de cliente;
|
|
172
|
+
- mantenha artefatos gerados fora do Git quando nao forem necessarios;
|
|
173
|
+
- use `.gitignore`;
|
|
174
|
+
- publique com `README.md`, `LICENSE`, `docs/`, `protocol/`, `cases/`,
|
|
175
|
+
`examples/`, `schema/`, `eval/` e `scripts/` quando fizer sentido;
|
|
176
|
+
- preserve o posicionamento como pesquisa experimental e framework em evolucao.
|
|
177
|
+
|
|
178
|
+
## Licenca
|
|
179
|
+
|
|
180
|
+
Distribuido sob a licenca MIT. Veja `LICENSE`.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# AI Execution Protocol
|
|
2
|
+
|
|
3
|
+
Framework experimental para orientar agentes de IA em tarefas tecnicas com mais
|
|
4
|
+
seguranca, contexto minimo, validacao e controle de risco.
|
|
5
|
+
|
|
6
|
+
O alvo atual e Codex. O protocolo e otimizado para Codex agora, mas foi
|
|
7
|
+
organizado para continuar portavel para outras IAs no futuro.
|
|
8
|
+
|
|
9
|
+
## Objetivo
|
|
10
|
+
|
|
11
|
+
Evitar que a IA execute pedidos de forma impulsiva, perigosa ou fora de escopo.
|
|
12
|
+
|
|
13
|
+
O framework ajuda a IA a:
|
|
14
|
+
|
|
15
|
+
- entender a intencao antes de agir;
|
|
16
|
+
- classificar o risco da tarefa;
|
|
17
|
+
- ler apenas o contexto necessario;
|
|
18
|
+
- mapear impacto antes de alterar arquivos;
|
|
19
|
+
- pedir confirmacao em acoes sensiveis;
|
|
20
|
+
- validar o resultado antes de entregar;
|
|
21
|
+
- explicar limites e risco residual.
|
|
22
|
+
|
|
23
|
+
## Ideia central
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
Entender -> classificar risco -> mapear impacto -> executar -> validar -> entregar
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
O protocolo nao tenta transformar toda tarefa em um processo pesado. A regra e
|
|
30
|
+
proporcionalidade: tarefa simples deve ser rapida; tarefa critica exige mais
|
|
31
|
+
mapa, confirmacao e evidencia.
|
|
32
|
+
|
|
33
|
+
## Status
|
|
34
|
+
|
|
35
|
+
Projeto em fase de pesquisa e evolucao.
|
|
36
|
+
|
|
37
|
+
Este repositorio contem uma proposta tecnica, nao uma garantia de seguranca nem
|
|
38
|
+
uma fonte normativa definitiva. Testes reais, revisao humana e criterio tecnico
|
|
39
|
+
continuam obrigatorios em tarefas criticas.
|
|
40
|
+
|
|
41
|
+
## Estrutura
|
|
42
|
+
|
|
43
|
+
- `AGENTS.md`: instrucao principal para agentes no projeto.
|
|
44
|
+
- `INDEX.yaml`: mapa estruturado para navegacao rapida.
|
|
45
|
+
- `config.yaml`: configuracao do alvo atual e versao do protocolo.
|
|
46
|
+
- `docs/`: explicacoes conceituais em Markdown.
|
|
47
|
+
- `protocol/`: regras operacionais curtas em YAML.
|
|
48
|
+
- `cases/`: casos estruturados para testar o comportamento da IA.
|
|
49
|
+
- `examples/`: exemplos humanos de uso do framework.
|
|
50
|
+
- `schema/`: contratos para manter os YAML padronizados.
|
|
51
|
+
- `eval/`: rubrica e exemplos de avaliacao.
|
|
52
|
+
- `scripts/`: automacoes de instalacao, validacao e avaliacao.
|
|
53
|
+
- `responses/`: exemplos de respostas para avaliacao.
|
|
54
|
+
- `benchmarks/`: comparacoes entre execucao com e sem protocolo.
|
|
55
|
+
- `model-runs/`: respostas reais por modelo para comparacao.
|
|
56
|
+
- `real-runs/`: templates ou registros de execucoes reais auditaveis.
|
|
57
|
+
- `dist/minimal/`: pacote minimo gerado para instalar em outros projetos.
|
|
58
|
+
|
|
59
|
+
## Como usar como agente
|
|
60
|
+
|
|
61
|
+
1. Leia `INDEX.yaml`.
|
|
62
|
+
2. Confirme o alvo atual em `config.yaml`.
|
|
63
|
+
3. Leia `protocol/fast-path.yaml`.
|
|
64
|
+
4. Use `protocol/router.yaml` para escolher o menor contexto suficiente.
|
|
65
|
+
5. Abra apenas os arquivos indicados pela rota.
|
|
66
|
+
6. Execute, valide e entregue com evidencia.
|
|
67
|
+
|
|
68
|
+
## Como estudar o framework
|
|
69
|
+
|
|
70
|
+
Comece por:
|
|
71
|
+
|
|
72
|
+
- `docs/00-visao-geral.md`
|
|
73
|
+
- `docs/01-modelo-de-execucao.md`
|
|
74
|
+
- `docs/02-niveis-de-risco.md`
|
|
75
|
+
- `docs/03-mapeamento-antes-de-alterar.md`
|
|
76
|
+
- `docs/05-validacao-e-entrega.md`
|
|
77
|
+
- `docs/14-publicacao.md`
|
|
78
|
+
|
|
79
|
+
Use `docs/` para entender a metodologia. Use `protocol/` quando quiser aplicar
|
|
80
|
+
as regras em uma tarefa real.
|
|
81
|
+
|
|
82
|
+
## Validacao local
|
|
83
|
+
|
|
84
|
+
Execute a validacao geral:
|
|
85
|
+
|
|
86
|
+
```powershell
|
|
87
|
+
python scripts/health_check.py
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Execute a bateria estrutural extra:
|
|
91
|
+
|
|
92
|
+
```powershell
|
|
93
|
+
python scripts/framework_tests.py
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Meca custo aproximado de leitura por rota:
|
|
97
|
+
|
|
98
|
+
```powershell
|
|
99
|
+
python scripts/token_report.py
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Instalacao em outro projeto
|
|
103
|
+
|
|
104
|
+
Projeto novo:
|
|
105
|
+
|
|
106
|
+
```powershell
|
|
107
|
+
ai-protocol init .
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Projeto existente:
|
|
111
|
+
|
|
112
|
+
```powershell
|
|
113
|
+
ai-protocol install .
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Previa sem alterar arquivos:
|
|
117
|
+
|
|
118
|
+
```powershell
|
|
119
|
+
ai-protocol install . --dry-run
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Instalacao local via PowerShell:
|
|
123
|
+
|
|
124
|
+
```powershell
|
|
125
|
+
.\install.ps1 C:\caminho\projeto -Force
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Instalacao local via npm:
|
|
129
|
+
|
|
130
|
+
```powershell
|
|
131
|
+
npm run install-protocol -- C:\caminho\projeto
|
|
132
|
+
npm run dry-run-protocol -- C:\caminho\projeto
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Instalacao local via Python:
|
|
136
|
+
|
|
137
|
+
```powershell
|
|
138
|
+
python scripts/install_protocol.py --target C:\caminho\projeto --force
|
|
139
|
+
python scripts/verify_install.py --target C:\caminho\projeto
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
O final esperado da verificacao e `PASS`.
|
|
143
|
+
|
|
144
|
+
## Publicacao
|
|
145
|
+
|
|
146
|
+
Antes de publicar, revise `docs/14-publicacao.md`.
|
|
147
|
+
|
|
148
|
+
Resumo minimo:
|
|
149
|
+
|
|
150
|
+
- nao publique `.env`, chaves, tokens, senhas, logs reais ou dados de cliente;
|
|
151
|
+
- mantenha artefatos gerados fora do Git quando nao forem necessarios;
|
|
152
|
+
- use `.gitignore`;
|
|
153
|
+
- publique com `README.md`, `LICENSE`, `docs/`, `protocol/`, `cases/`,
|
|
154
|
+
`examples/`, `schema/`, `eval/` e `scripts/` quando fizer sentido;
|
|
155
|
+
- preserve o posicionamento como pesquisa experimental e framework em evolucao.
|
|
156
|
+
|
|
157
|
+
## Licenca
|
|
158
|
+
|
|
159
|
+
Distribuido sob a licenca MIT. Veja `LICENSE`.
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""CLI for installing the minimal AI protocol into a project."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import shutil
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from importlib import resources
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
MARKER_START = "<!-- AI_PROTOCOL_BEGIN -->"
|
|
14
|
+
MARKER_END = "<!-- AI_PROTOCOL_END -->"
|
|
15
|
+
AIIGNORE_LINES = [
|
|
16
|
+
"results/",
|
|
17
|
+
"benchmarks/generated/",
|
|
18
|
+
"model-runs/generated/",
|
|
19
|
+
"dist/",
|
|
20
|
+
"scripts/__pycache__/",
|
|
21
|
+
"*.pyc",
|
|
22
|
+
]
|
|
23
|
+
REQUIRED_PROTOCOL_FILES = [
|
|
24
|
+
"README.yaml",
|
|
25
|
+
"fast-path.yaml",
|
|
26
|
+
"router.yaml",
|
|
27
|
+
"modes.yaml",
|
|
28
|
+
"execution-rules.yaml",
|
|
29
|
+
"risk-levels.yaml",
|
|
30
|
+
"mapping-checklists.yaml",
|
|
31
|
+
"validation-checklist.yaml",
|
|
32
|
+
"context-rules.yaml",
|
|
33
|
+
"context-compiler.yaml",
|
|
34
|
+
"formatting-rules.yaml",
|
|
35
|
+
"prompt-economy.yaml",
|
|
36
|
+
"spec-driven.yaml",
|
|
37
|
+
]
|
|
38
|
+
REQUIRED_FILES = [
|
|
39
|
+
"AGENTS.md",
|
|
40
|
+
".aiignore",
|
|
41
|
+
*[f"protocol/{name}" for name in REQUIRED_PROTOCOL_FILES],
|
|
42
|
+
]
|
|
43
|
+
REQUIRED_TEXT = {
|
|
44
|
+
"AGENTS.md": [
|
|
45
|
+
"AI_PROTOCOL_BEGIN",
|
|
46
|
+
"protocol/fast-path.yaml",
|
|
47
|
+
"protocol/router.yaml",
|
|
48
|
+
"Classifique o risco antes de agir",
|
|
49
|
+
"Nenhum arquivo deve passar de 400 linhas.",
|
|
50
|
+
],
|
|
51
|
+
".aiignore": [
|
|
52
|
+
"results/",
|
|
53
|
+
"dist/",
|
|
54
|
+
"*.pyc",
|
|
55
|
+
],
|
|
56
|
+
"protocol/router.yaml": [
|
|
57
|
+
"feature_or_spec",
|
|
58
|
+
"spec-driven.yaml",
|
|
59
|
+
"prompt_improvement",
|
|
60
|
+
],
|
|
61
|
+
"protocol/spec-driven.yaml": [
|
|
62
|
+
"protocol_is_base_spec_is_tool",
|
|
63
|
+
"do_not_create_spec_for_low_value_tasks",
|
|
64
|
+
],
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def protocol_source() -> resources.abc.Traversable:
|
|
69
|
+
return resources.files("ai_execution_protocol").joinpath("protocol")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def minimal_agents() -> str:
|
|
73
|
+
return """# AGENTS.md
|
|
74
|
+
|
|
75
|
+
## Regra principal
|
|
76
|
+
|
|
77
|
+
<!-- AI_PROTOCOL_BEGIN -->
|
|
78
|
+
|
|
79
|
+
Use `protocol/fast-path.yaml` como entrada operacional minima.
|
|
80
|
+
|
|
81
|
+
Siga `.aiignore` antes de abrir relatorios gerados.
|
|
82
|
+
|
|
83
|
+
Este protocolo e obrigatorio para tarefas tecnicas neste projeto. Antes de
|
|
84
|
+
editar, classifique risco, escolha rota e valide a entrega.
|
|
85
|
+
|
|
86
|
+
## Ordem de leitura
|
|
87
|
+
|
|
88
|
+
1. `protocol/fast-path.yaml`
|
|
89
|
+
2. `protocol/router.yaml`
|
|
90
|
+
3. Arquivo YAML especifico em `protocol/` conforme a rota.
|
|
91
|
+
|
|
92
|
+
## Regras de execucao
|
|
93
|
+
|
|
94
|
+
- Classifique o risco antes de agir.
|
|
95
|
+
- Use o menor contexto suficiente.
|
|
96
|
+
- Leia apenas os arquivos indicados por `protocol/router.yaml`.
|
|
97
|
+
- Quando houver contexto grande, historico longo ou risco de confusao, use
|
|
98
|
+
`protocol/context-compiler.yaml` antes de abrir muitos arquivos.
|
|
99
|
+
- Use `protocol/spec-driven.yaml` para feature, refatoracao grande ou tarefa
|
|
100
|
+
critica, sem criar spec pesada para tarefa simples.
|
|
101
|
+
- Sempre entregue `Prompt original` e `Prompt melhorado da IA`; em baixo risco,
|
|
102
|
+
prefira micro formato legivel com `PO`, `PM` e `OK`.
|
|
103
|
+
- Nao edite arquivo que nao foi identificado como candidato.
|
|
104
|
+
- Preserve documentos, regras de IDE e configuracoes de framework existentes,
|
|
105
|
+
salvo pedido explicito do usuario.
|
|
106
|
+
- Se o risco subir, atualize a classificacao antes de continuar.
|
|
107
|
+
- Para nivel critico, peca confirmacao antes de acao sensivel.
|
|
108
|
+
- Quando houver risco de quebrar fluxo existente, entregue uma lista do que
|
|
109
|
+
testar.
|
|
110
|
+
- Entregue com evidencia em poucas linhas: mudanca, validacao, limite e risco
|
|
111
|
+
residual.
|
|
112
|
+
- Explique o resultado em linguagem clara para uma pessoa leiga entender.
|
|
113
|
+
|
|
114
|
+
## Convivencia com arquivos existentes
|
|
115
|
+
|
|
116
|
+
Quando houver conflito, siga esta prioridade:
|
|
117
|
+
|
|
118
|
+
1. pedido atual do usuario;
|
|
119
|
+
2. este bloco obrigatorio em `AGENTS.md`;
|
|
120
|
+
3. regras especificas da IDE ou do projeto;
|
|
121
|
+
4. docs e historico somente quando a rota pedir.
|
|
122
|
+
|
|
123
|
+
Nao sobrescreva `README.md`, `docs/`, `.cursorrules`, `CLAUDE.md`,
|
|
124
|
+
`.github/copilot-instructions.md` ou configs de framework sem pedido claro.
|
|
125
|
+
|
|
126
|
+
## Regras de organizacao
|
|
127
|
+
|
|
128
|
+
- Nenhum arquivo deve passar de 400 linhas.
|
|
129
|
+
- Organize primeiro para legibilidade por IA.
|
|
130
|
+
- Use YAML para regras operacionais.
|
|
131
|
+
- Evite duplicar a mesma regra em muitos lugares.
|
|
132
|
+
|
|
133
|
+
<!-- AI_PROTOCOL_END -->
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def protocol_block() -> str:
|
|
138
|
+
text = minimal_agents()
|
|
139
|
+
start = text.index(MARKER_START)
|
|
140
|
+
end = text.index(MARKER_END) + len(MARKER_END)
|
|
141
|
+
return text[start:end]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def backup_path(path: Path, backup_root: Path) -> None:
|
|
145
|
+
if not path.exists():
|
|
146
|
+
return
|
|
147
|
+
backup_root.mkdir(parents=True, exist_ok=True)
|
|
148
|
+
destination = backup_root / path.name
|
|
149
|
+
if path.is_dir():
|
|
150
|
+
shutil.copytree(path, destination)
|
|
151
|
+
else:
|
|
152
|
+
shutil.copy2(path, destination)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def copy_protocol(target: Path, force: bool, backup_root: Path) -> None:
|
|
156
|
+
if target.exists() and not force:
|
|
157
|
+
return
|
|
158
|
+
if target.exists():
|
|
159
|
+
backup_path(target, backup_root)
|
|
160
|
+
shutil.rmtree(target)
|
|
161
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
162
|
+
source = protocol_source()
|
|
163
|
+
for name in REQUIRED_PROTOCOL_FILES:
|
|
164
|
+
(target / name).write_text(source.joinpath(name).read_text(encoding="utf-8"), encoding="utf-8")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def install_agents(target: Path) -> None:
|
|
168
|
+
block = protocol_block()
|
|
169
|
+
if not target.exists():
|
|
170
|
+
target.write_text(minimal_agents(), encoding="utf-8")
|
|
171
|
+
return
|
|
172
|
+
|
|
173
|
+
text = target.read_text(encoding="utf-8")
|
|
174
|
+
if MARKER_START in text and MARKER_END in text:
|
|
175
|
+
before, rest = text.split(MARKER_START, 1)
|
|
176
|
+
_, after = rest.split(MARKER_END, 1)
|
|
177
|
+
merged = before.rstrip() + "\n\n" + block + after
|
|
178
|
+
else:
|
|
179
|
+
merged = block + "\n\n## Instrucoes existentes do projeto\n\n" + text
|
|
180
|
+
target.write_text(merged.strip() + "\n", encoding="utf-8")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def install_aiignore(target: Path) -> None:
|
|
184
|
+
existing = target.read_text(encoding="utf-8").splitlines() if target.exists() else []
|
|
185
|
+
lines = list(existing)
|
|
186
|
+
for item in AIIGNORE_LINES:
|
|
187
|
+
if item not in lines:
|
|
188
|
+
lines.append(item)
|
|
189
|
+
target.write_text("\n".join(lines).strip() + "\n", encoding="utf-8")
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def print_dry_run(target_root: Path, force: bool) -> None:
|
|
193
|
+
print(f"DRY-RUN target -> {target_root.resolve()}")
|
|
194
|
+
print(("update" if (target_root / "AGENTS.md").exists() else "create") + ":AGENTS.md")
|
|
195
|
+
print(("update" if (target_root / ".aiignore").exists() else "create") + ":.aiignore")
|
|
196
|
+
protocol_dir = target_root / "protocol"
|
|
197
|
+
if protocol_dir.exists() and force:
|
|
198
|
+
print("backup:protocol/")
|
|
199
|
+
print("replace:protocol/")
|
|
200
|
+
elif protocol_dir.exists():
|
|
201
|
+
print("keep:protocol/")
|
|
202
|
+
else:
|
|
203
|
+
print("create:protocol/")
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def install(target: str, force: bool, dry_run: bool = False) -> int:
|
|
207
|
+
target_root = Path(target).resolve()
|
|
208
|
+
if dry_run:
|
|
209
|
+
print_dry_run(target_root, force)
|
|
210
|
+
return 0
|
|
211
|
+
|
|
212
|
+
target_root.mkdir(parents=True, exist_ok=True)
|
|
213
|
+
backup_root = target_root / ".ai-protocol-backup" / datetime.now().strftime("%Y%m%d%H%M%S")
|
|
214
|
+
|
|
215
|
+
if (target_root / "AGENTS.md").exists():
|
|
216
|
+
backup_path(target_root / "AGENTS.md", backup_root)
|
|
217
|
+
if (target_root / ".aiignore").exists():
|
|
218
|
+
backup_path(target_root / ".aiignore", backup_root)
|
|
219
|
+
|
|
220
|
+
install_agents(target_root / "AGENTS.md")
|
|
221
|
+
install_aiignore(target_root / ".aiignore")
|
|
222
|
+
copy_protocol(target_root / "protocol", force, backup_root)
|
|
223
|
+
|
|
224
|
+
print(f"installed protocol -> {target_root}")
|
|
225
|
+
return verify(target)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def verify(target: str) -> int:
|
|
229
|
+
root = Path(target).resolve()
|
|
230
|
+
errors: list[str] = []
|
|
231
|
+
|
|
232
|
+
for item in REQUIRED_FILES:
|
|
233
|
+
path = root / item
|
|
234
|
+
if not path.exists():
|
|
235
|
+
errors.append(f"missing:{item}")
|
|
236
|
+
continue
|
|
237
|
+
if path.is_file() and len(path.read_text(encoding="utf-8").splitlines()) > 400:
|
|
238
|
+
errors.append(f"line_limit:{item}")
|
|
239
|
+
|
|
240
|
+
for item, snippets in REQUIRED_TEXT.items():
|
|
241
|
+
path = root / item
|
|
242
|
+
if not path.exists() or not path.is_file():
|
|
243
|
+
continue
|
|
244
|
+
text = path.read_text(encoding="utf-8")
|
|
245
|
+
for snippet in snippets:
|
|
246
|
+
if snippet not in text:
|
|
247
|
+
errors.append(f"missing_text:{item}:{snippet}")
|
|
248
|
+
|
|
249
|
+
if errors:
|
|
250
|
+
print("FAIL")
|
|
251
|
+
for error in errors:
|
|
252
|
+
print(error)
|
|
253
|
+
return 1
|
|
254
|
+
|
|
255
|
+
print("PASS")
|
|
256
|
+
return 0
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def main() -> int:
|
|
260
|
+
parser = argparse.ArgumentParser(prog="ai-protocol")
|
|
261
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
262
|
+
|
|
263
|
+
install_parser = subparsers.add_parser("install", help="Install protocol into a project")
|
|
264
|
+
install_parser.add_argument("target", nargs="?", default=".", help="Project root")
|
|
265
|
+
install_parser.add_argument("--no-force", action="store_true", help="Do not replace existing protocol folder")
|
|
266
|
+
install_parser.add_argument("--dry-run", action="store_true", help="Show planned changes without writing files")
|
|
267
|
+
|
|
268
|
+
init_parser = subparsers.add_parser("init", help="Initialize protocol in a new project")
|
|
269
|
+
init_parser.add_argument("target", nargs="?", default=".", help="Project root")
|
|
270
|
+
init_parser.add_argument("--no-force", action="store_true", help="Do not replace existing protocol folder")
|
|
271
|
+
init_parser.add_argument("--dry-run", action="store_true", help="Show planned changes without writing files")
|
|
272
|
+
|
|
273
|
+
verify_parser = subparsers.add_parser("verify", help="Verify protocol installation")
|
|
274
|
+
verify_parser.add_argument("target", nargs="?", default=".", help="Project root")
|
|
275
|
+
|
|
276
|
+
args = parser.parse_args()
|
|
277
|
+
if args.command in {"install", "init"}:
|
|
278
|
+
return install(args.target, force=not args.no_force, dry_run=args.dry_run)
|
|
279
|
+
if args.command == "verify":
|
|
280
|
+
return verify(args.target)
|
|
281
|
+
|
|
282
|
+
parser.print_help()
|
|
283
|
+
return 1
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
id: protocol_index
|
|
2
|
+
type: index
|
|
3
|
+
format: yaml
|
|
4
|
+
protocol_version: 0.1.0
|
|
5
|
+
purpose: ai_operational_rules
|
|
6
|
+
source_docs: ../docs
|
|
7
|
+
constraints:
|
|
8
|
+
max_lines_per_file: 400
|
|
9
|
+
ai_first_readability: true
|
|
10
|
+
compact_rules: true
|
|
11
|
+
files:
|
|
12
|
+
- path: fast-path.yaml
|
|
13
|
+
purpose: minimum_rules_to_start_any_task
|
|
14
|
+
- path: router.yaml
|
|
15
|
+
purpose: choose_minimum_files_to_read_by_task
|
|
16
|
+
- path: modes.yaml
|
|
17
|
+
purpose: choose_fast_balanced_or_strict_behavior
|
|
18
|
+
- path: execution-rules.yaml
|
|
19
|
+
purpose: execution_flow_and_core_behavior
|
|
20
|
+
- path: risk-levels.yaml
|
|
21
|
+
purpose: risk_classification_and_confirmation
|
|
22
|
+
- path: mapping-checklists.yaml
|
|
23
|
+
purpose: pre_change_maps_by_risk
|
|
24
|
+
- path: validation-checklist.yaml
|
|
25
|
+
purpose: validation_and_final_delivery
|
|
26
|
+
- path: context-rules.yaml
|
|
27
|
+
purpose: context_window_file_size_memory
|
|
28
|
+
- path: context-compiler.yaml
|
|
29
|
+
purpose: compile_minimum_context_package_and_canonical_state
|
|
30
|
+
- path: formatting-rules.yaml
|
|
31
|
+
purpose: ai_readable_file_format
|
|
32
|
+
- path: prompt-economy.yaml
|
|
33
|
+
purpose: improve_prompts_without_token_bloat
|
|
34
|
+
- path: spec-driven.yaml
|
|
35
|
+
purpose: use_light_or_full_specs_only_when_they_reduce_risk
|
|
File without changes
|