ai-execution-protocol 0.3.1 → 0.4.0
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.
- package/AGENTS.md +5 -1
- package/README.md +41 -2
- package/behavior/audit-checklist.yaml +55 -0
- package/behavior/contract.yaml +156 -0
- package/dataset/README.md +38 -0
- package/dataset/raw-examples.md +36 -0
- package/dataset/train.jsonl +3 -0
- package/dataset/validation.jsonl +2 -0
- package/dist/minimal/AGENTS.md +4 -1
- package/dist/minimal/README.md +3 -0
- package/dist/minimal/behavior/audit-checklist.yaml +15 -0
- package/dist/minimal/behavior/contract.yaml +29 -0
- package/dist/minimal/canonical-state.yaml +1 -1
- package/dist/minimal/capabilities/registry.yaml +1 -1
- package/dist/minimal/context-map.yaml +1 -1
- package/dist/minimal/ide-rules/instruction-block.md +23 -0
- package/dist/minimal/memory/INDEX.yaml +1 -1
- package/dist/minimal/protocol/README.yaml +9 -1
- package/dist/minimal/protocol/capability-gate.yaml +56 -0
- package/dist/minimal/protocol/capability-router.yaml +1 -1
- package/dist/minimal/protocol/context-rules.yaml +2 -1
- package/dist/minimal/protocol/fast-path.yaml +6 -1
- package/dist/minimal/protocol/intelligence-router.yaml +63 -0
- package/dist/minimal/protocol/route-packs.yaml +38 -1
- package/dist/minimal/protocol/router.yaml +28 -1
- package/docs/00-visao-geral.md +41 -0
- package/docs/01-modelo-de-execucao.md +25 -0
- package/docs/02-niveis-de-risco.md +62 -0
- package/docs/03-mapeamento-antes-de-alterar.md +48 -0
- package/docs/04-janela-de-contexto.md +56 -0
- package/docs/05-validacao-e-entrega.md +48 -0
- package/docs/06-memoria-e-continuidade.md +27 -0
- package/docs/07-legibilidade-para-ia.md +47 -0
- package/docs/08-posicionamento.md +48 -0
- package/docs/09-governanca-de-mudancas.md +48 -0
- package/docs/10-economia-de-prompt.md +79 -0
- package/docs/11-retencao-de-resultados.md +26 -0
- package/docs/12-instalacao-em-outro-projeto.md +254 -0
- package/docs/13-uso-em-ides.md +137 -0
- package/docs/14-publicacao.md +128 -0
- package/docs/15-contexto-persistente.md +204 -0
- package/docs/16-release-e-atualizacao.md +146 -0
- package/docs/17-documentacao-atomica.md +117 -0
- package/docs/18-memoria-adaptativa.md +107 -0
- package/docs/19-orcamento-de-contexto.md +63 -0
- package/docs/20-validacao-seletiva.md +46 -0
- package/docs/21-roteamento-de-capacidades.md +121 -0
- package/docs/22-roadmap-v1.md +163 -0
- package/docs/23-contrato-comportamental.md +116 -0
- package/docs/24-gate-de-capacidades-e-inteligencia.md +109 -0
- package/docs/README.md +58 -0
- package/eval/README.md +27 -0
- package/eval/rubric.yaml +57 -0
- package/eval/sample-result.yaml +28 -0
- package/install-manifest.json +27 -2
- package/package.json +9 -2
- package/protocol/README.yaml +9 -1
- package/protocol/capability-gate.yaml +56 -0
- package/protocol/capability-router.yaml +1 -1
- package/protocol/context-rules.yaml +2 -1
- package/protocol/fast-path.yaml +6 -1
- package/protocol/intelligence-router.yaml +63 -0
- package/protocol/route-packs.yaml +38 -1
- package/protocol/router.yaml +28 -1
- package/roadmap/v1.yaml +139 -0
- package/schema/README.md +26 -0
- package/schema/behavior-contract.schema.json +31 -0
- package/schema/capability-registry.schema.json +51 -0
- package/schema/evaluated-response.schema.json +27 -0
- package/schema/evaluation-result.schema.json +32 -0
- package/schema/memory-entry.schema.json +55 -0
- package/schema/protocol-rule.schema.json +16 -0
- package/schema/protocol-rule.schema.yaml +28 -0
- package/schema/test-case.schema.json +44 -0
- package/schema/test-case.schema.yaml +37 -0
- package/scripts/README.md +46 -0
- package/scripts/build_dist.py +3 -0
- package/scripts/npm_install_protocol.js +60 -1
- package/scripts/verify_install.py +25 -0
- package/templates/minimal/AGENTS.md +4 -1
- package/templates/minimal/behavior/audit-checklist.yaml +15 -0
- package/templates/minimal/behavior/contract.yaml +29 -0
- package/templates/minimal/canonical-state.yaml +1 -1
- package/templates/minimal/capabilities/registry.yaml +1 -1
- package/templates/minimal/context-map.yaml +1 -1
- package/templates/minimal/ide-rules/instruction-block.md +23 -0
- package/templates/minimal/memory/INDEX.yaml +1 -1
- package/templates/minimal/protocol/capability-gate.yaml +10 -0
- package/templates/minimal/protocol/intelligence-router.yaml +10 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ai-research.local/schema/evaluated-response.schema.json",
|
|
4
|
+
"title": "Evaluated AI response",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": [
|
|
7
|
+
"id",
|
|
8
|
+
"type",
|
|
9
|
+
"case_id",
|
|
10
|
+
"selected_level",
|
|
11
|
+
"behaviors",
|
|
12
|
+
"avoided",
|
|
13
|
+
"delivery"
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"id": { "type": "string" },
|
|
17
|
+
"type": { "const": "evaluated_response" },
|
|
18
|
+
"case_id": { "type": "string" },
|
|
19
|
+
"selected_level": { "type": ["integer", "null"], "enum": [0, 1, 2, 3, null] },
|
|
20
|
+
"behaviors": { "type": "array", "items": { "type": "string" } },
|
|
21
|
+
"behavior_contract_alignment": { "type": "array", "items": { "type": "string" } },
|
|
22
|
+
"avoided": { "type": "array", "items": { "type": "string" } },
|
|
23
|
+
"delivery": { "type": "array", "items": { "type": "string" } },
|
|
24
|
+
"structured": { "type": "boolean" },
|
|
25
|
+
"automatic_fail": { "type": "array", "items": { "type": "string" } }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ai-research.local/schema/evaluation-result.schema.json",
|
|
4
|
+
"title": "Evaluation result",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": [
|
|
7
|
+
"id",
|
|
8
|
+
"type",
|
|
9
|
+
"case_id",
|
|
10
|
+
"expected_level",
|
|
11
|
+
"selected_level",
|
|
12
|
+
"score",
|
|
13
|
+
"status"
|
|
14
|
+
],
|
|
15
|
+
"properties": {
|
|
16
|
+
"id": { "type": "string" },
|
|
17
|
+
"type": { "const": "evaluation_result" },
|
|
18
|
+
"case_id": { "type": "string" },
|
|
19
|
+
"expected_level": { "type": "integer", "enum": [0, 1, 2, 3] },
|
|
20
|
+
"selected_level": { "type": ["integer", "null"], "enum": [0, 1, 2, 3, null] },
|
|
21
|
+
"score": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"required": ["total", "max"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"total": { "type": "integer" },
|
|
26
|
+
"max": { "type": "integer" },
|
|
27
|
+
"by_criteria": { "type": "object" }
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"status": { "type": "string", "enum": ["pass", "partial", "fail"] }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ai-research.local/schema/memory-entry.schema.json",
|
|
4
|
+
"title": "Adaptive memory entry",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": [
|
|
7
|
+
"id",
|
|
8
|
+
"type",
|
|
9
|
+
"subject",
|
|
10
|
+
"value",
|
|
11
|
+
"scope",
|
|
12
|
+
"status",
|
|
13
|
+
"confidence",
|
|
14
|
+
"source",
|
|
15
|
+
"evidence_count",
|
|
16
|
+
"sensitive",
|
|
17
|
+
"created_at",
|
|
18
|
+
"updated_at"
|
|
19
|
+
],
|
|
20
|
+
"properties": {
|
|
21
|
+
"id": { "type": "string", "minLength": 1 },
|
|
22
|
+
"type": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"enum": [
|
|
25
|
+
"explicit_preference",
|
|
26
|
+
"inferred_preference",
|
|
27
|
+
"project_decision",
|
|
28
|
+
"project_state",
|
|
29
|
+
"workflow_pattern",
|
|
30
|
+
"conversation_summary"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"subject": { "type": "string", "minLength": 1 },
|
|
34
|
+
"value": { "type": ["string", "object", "array"] },
|
|
35
|
+
"scope": { "type": "string", "minLength": 1 },
|
|
36
|
+
"status": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"enum": ["active", "candidate", "replaced", "revoked", "expired"]
|
|
39
|
+
},
|
|
40
|
+
"confidence": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"enum": ["low", "medium", "high", "confirmed"]
|
|
43
|
+
},
|
|
44
|
+
"source": { "type": "string", "minLength": 1 },
|
|
45
|
+
"evidence_count": { "type": "integer", "minimum": 1 },
|
|
46
|
+
"sensitive": { "type": "boolean" },
|
|
47
|
+
"created_at": { "type": "string" },
|
|
48
|
+
"updated_at": { "type": "string" },
|
|
49
|
+
"supersedes": { "type": "array", "items": { "type": "string" } },
|
|
50
|
+
"expires_at": { "type": ["string", "null"] },
|
|
51
|
+
"aliases": { "type": "array", "items": { "type": "string" } },
|
|
52
|
+
"evidence": { "type": "array", "items": { "type": "string" } }
|
|
53
|
+
},
|
|
54
|
+
"additionalProperties": false
|
|
55
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ai-research.local/schema/protocol-rule.schema.json",
|
|
4
|
+
"title": "Protocol rule file",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["id", "type"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"id": { "type": "string" },
|
|
9
|
+
"type": { "type": "string" },
|
|
10
|
+
"version": { "type": ["string", "number"] },
|
|
11
|
+
"rules": { "type": "array" },
|
|
12
|
+
"levels": { "type": "object" },
|
|
13
|
+
"constraints": { "type": "object" }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
id: protocol_rule_schema
|
|
2
|
+
type: schema
|
|
3
|
+
target: protocol/*.yaml
|
|
4
|
+
required_top_level_fields:
|
|
5
|
+
- id
|
|
6
|
+
- type
|
|
7
|
+
recommended_fields:
|
|
8
|
+
- version
|
|
9
|
+
- rules
|
|
10
|
+
- levels
|
|
11
|
+
- checklists
|
|
12
|
+
- constraints
|
|
13
|
+
rule_object_fields:
|
|
14
|
+
required:
|
|
15
|
+
- id
|
|
16
|
+
optional:
|
|
17
|
+
- when
|
|
18
|
+
- do
|
|
19
|
+
- avoid
|
|
20
|
+
- deliver
|
|
21
|
+
- validation
|
|
22
|
+
style:
|
|
23
|
+
- use_stable_ids
|
|
24
|
+
- use_short_values
|
|
25
|
+
- prefer_lists_over_paragraphs
|
|
26
|
+
- keep_under_400_lines
|
|
27
|
+
- avoid_duplicate_rules
|
|
28
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ai-research.local/schema/test-case.schema.json",
|
|
4
|
+
"title": "Protocol test case",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": [
|
|
7
|
+
"id",
|
|
8
|
+
"type",
|
|
9
|
+
"task_type",
|
|
10
|
+
"user_request",
|
|
11
|
+
"expected_level",
|
|
12
|
+
"expected_behavior",
|
|
13
|
+
"must_not",
|
|
14
|
+
"expected_delivery"
|
|
15
|
+
],
|
|
16
|
+
"properties": {
|
|
17
|
+
"id": { "type": "string" },
|
|
18
|
+
"type": { "const": "protocol_case" },
|
|
19
|
+
"task_type": { "type": "string" },
|
|
20
|
+
"user_request": { "type": "string" },
|
|
21
|
+
"expected_level": { "type": "integer", "enum": [0, 1, 2, 3] },
|
|
22
|
+
"expected_behavior": {
|
|
23
|
+
"type": "array",
|
|
24
|
+
"items": { "type": "string" },
|
|
25
|
+
"minItems": 1
|
|
26
|
+
},
|
|
27
|
+
"must_not": {
|
|
28
|
+
"type": "array",
|
|
29
|
+
"items": { "type": "string" }
|
|
30
|
+
},
|
|
31
|
+
"expected_delivery": {
|
|
32
|
+
"type": "object",
|
|
33
|
+
"required": ["required"],
|
|
34
|
+
"properties": {
|
|
35
|
+
"required": {
|
|
36
|
+
"type": "array",
|
|
37
|
+
"items": { "type": "string" },
|
|
38
|
+
"minItems": 1
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
id: test_case_schema
|
|
2
|
+
type: schema
|
|
3
|
+
target: cases/*.yaml
|
|
4
|
+
required_top_level_fields:
|
|
5
|
+
- id
|
|
6
|
+
- type
|
|
7
|
+
- task_type
|
|
8
|
+
- user_request
|
|
9
|
+
- expected_level
|
|
10
|
+
- expected_behavior
|
|
11
|
+
- must_not
|
|
12
|
+
- expected_delivery
|
|
13
|
+
recommended_fields:
|
|
14
|
+
- evidence
|
|
15
|
+
- manual_validation
|
|
16
|
+
field_rules:
|
|
17
|
+
type:
|
|
18
|
+
allowed:
|
|
19
|
+
- protocol_case
|
|
20
|
+
expected_level:
|
|
21
|
+
allowed:
|
|
22
|
+
- 0
|
|
23
|
+
- 1
|
|
24
|
+
- 2
|
|
25
|
+
- 3
|
|
26
|
+
expected_behavior:
|
|
27
|
+
format: list_of_actions
|
|
28
|
+
must_not:
|
|
29
|
+
format: list_of_forbidden_actions
|
|
30
|
+
expected_delivery:
|
|
31
|
+
format: required_fields_object
|
|
32
|
+
style:
|
|
33
|
+
- one_case_per_file
|
|
34
|
+
- short_user_request
|
|
35
|
+
- objective_expected_level
|
|
36
|
+
- explicit_forbidden_behavior
|
|
37
|
+
- keep_under_400_lines
|
package/scripts/README.md
CHANGED
|
@@ -87,6 +87,39 @@ Capacidades marcadas como `runtime` precisam ser informadas:
|
|
|
87
87
|
python scripts/capability_router.py --risk 2 --operation read --tag external_context --available targeted_mcp
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
## capability_gate.py
|
|
91
|
+
|
|
92
|
+
Compara capacidades selecionadas com capacidades usadas.
|
|
93
|
+
|
|
94
|
+
```powershell
|
|
95
|
+
python scripts/capability_gate.py --risk 2 --selected local_search --used local_search
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## intelligence_router.py
|
|
99
|
+
|
|
100
|
+
Escolhe nivel de modelo, raciocinio ou esforco conforme risco e complexidade.
|
|
101
|
+
|
|
102
|
+
```powershell
|
|
103
|
+
python scripts/intelligence_router.py --risk 2 --signal file_change
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## behavior_contract_check.py
|
|
107
|
+
|
|
108
|
+
Valida se a camada comportamental da v0.4.0 esta conectada ao framework.
|
|
109
|
+
|
|
110
|
+
```powershell
|
|
111
|
+
python scripts/behavior_contract_check.py
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## behavior_economy_benchmark.py
|
|
115
|
+
|
|
116
|
+
Estima economia ao usar roteamento comportamental antes de abrir contrato,
|
|
117
|
+
auditoria e protocolo completo.
|
|
118
|
+
|
|
119
|
+
```powershell
|
|
120
|
+
python scripts/behavior_economy_benchmark.py
|
|
121
|
+
```
|
|
122
|
+
|
|
90
123
|
## health_check.py
|
|
91
124
|
|
|
92
125
|
Roda a validacao geral do framework.
|
|
@@ -160,6 +193,14 @@ capacidades.
|
|
|
160
193
|
python scripts/v031_tests.py
|
|
161
194
|
```
|
|
162
195
|
|
|
196
|
+
## v04_tests.py
|
|
197
|
+
|
|
198
|
+
Testa o contrato comportamental, dataset inicial e integracao da v0.4.0.
|
|
199
|
+
|
|
200
|
+
```powershell
|
|
201
|
+
python scripts/v04_tests.py
|
|
202
|
+
```
|
|
203
|
+
|
|
163
204
|
## context_economy_benchmark.py
|
|
164
205
|
|
|
165
206
|
Compara leitura ampla com rotas focadas do protocolo atual.
|
|
@@ -218,6 +259,8 @@ npm install -g ai-execution-protocol
|
|
|
218
259
|
ai-protocol init C:\caminho\projeto
|
|
219
260
|
ai-protocol install C:\caminho\projeto
|
|
220
261
|
ai-protocol install C:\caminho\projeto --dry-run
|
|
262
|
+
ai-protocol integrate C:\caminho\projeto --dry-run
|
|
263
|
+
ai-protocol integrate C:\caminho\projeto --yes
|
|
221
264
|
```
|
|
222
265
|
|
|
223
266
|
## npm_install_protocol.js
|
|
@@ -229,6 +272,7 @@ Exemplo:
|
|
|
229
272
|
```powershell
|
|
230
273
|
npm run install-protocol -- C:\caminho\projeto
|
|
231
274
|
npm run dry-run-protocol -- C:\caminho\projeto
|
|
275
|
+
npm run integrate-protocol -- C:\caminho\projeto --yes
|
|
232
276
|
```
|
|
233
277
|
|
|
234
278
|
Para conferir manualmente pelo mesmo wrapper:
|
|
@@ -247,6 +291,8 @@ Uso local:
|
|
|
247
291
|
python -m ai_execution_protocol install C:\caminho\projeto
|
|
248
292
|
python -m ai_execution_protocol init C:\caminho\projeto
|
|
249
293
|
python -m ai_execution_protocol install C:\caminho\projeto --dry-run
|
|
294
|
+
python -m ai_execution_protocol integrate C:\caminho\projeto --dry-run
|
|
295
|
+
python -m ai_execution_protocol integrate C:\caminho\projeto --yes
|
|
250
296
|
python -m ai_execution_protocol verify C:\caminho\projeto
|
|
251
297
|
```
|
|
252
298
|
|
package/scripts/build_dist.py
CHANGED
|
@@ -51,6 +51,8 @@ npm install -g ai-execution-protocol
|
|
|
51
51
|
ai-protocol init C:\\caminho\\projeto
|
|
52
52
|
ai-protocol install C:\\caminho\\projeto
|
|
53
53
|
ai-protocol install C:\\caminho\\projeto --dry-run
|
|
54
|
+
ai-protocol integrate C:\\caminho\\projeto --dry-run
|
|
55
|
+
ai-protocol integrate C:\\caminho\\projeto --yes
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
Como pacote Python publicado:
|
|
@@ -58,6 +60,7 @@ Como pacote Python publicado:
|
|
|
58
60
|
```powershell
|
|
59
61
|
pip install ai-execution-protocol
|
|
60
62
|
ai-protocol install C:\\caminho\\projeto
|
|
63
|
+
ai-protocol integrate C:\\caminho\\projeto --yes
|
|
61
64
|
ai-protocol verify C:\\caminho\\projeto
|
|
62
65
|
```
|
|
63
66
|
|
|
@@ -6,10 +6,19 @@ const path = require("path");
|
|
|
6
6
|
const root = path.resolve(__dirname, "..");
|
|
7
7
|
const markerStart = "<!-- AI_PROTOCOL_BEGIN -->";
|
|
8
8
|
const markerEnd = "<!-- AI_PROTOCOL_END -->";
|
|
9
|
+
const ideMarkerStart = "<!-- AI_PROTOCOL_IDE_BEGIN -->";
|
|
10
|
+
const ideMarkerEnd = "<!-- AI_PROTOCOL_IDE_END -->";
|
|
9
11
|
const manifest = JSON.parse(fs.readFileSync(path.join(root, "install-manifest.json"), "utf8"));
|
|
10
12
|
const protocolFiles = manifest.protocol_files;
|
|
11
13
|
const aiignoreLines = manifest.aiignore_lines;
|
|
12
14
|
const requiredText = manifest.required_text;
|
|
15
|
+
const instructionFiles = [
|
|
16
|
+
"AGENTS.md",
|
|
17
|
+
"CLAUDE.md",
|
|
18
|
+
".cursorrules",
|
|
19
|
+
".github/copilot-instructions.md",
|
|
20
|
+
".cursor/rules/ai-execution-protocol.mdc",
|
|
21
|
+
];
|
|
13
22
|
|
|
14
23
|
function readText(file) {
|
|
15
24
|
return fs.readFileSync(file, "utf8");
|
|
@@ -38,6 +47,10 @@ function protocolBlock() {
|
|
|
38
47
|
return text.slice(start, end);
|
|
39
48
|
}
|
|
40
49
|
|
|
50
|
+
function ideRuleBlock() {
|
|
51
|
+
return readText(path.join(root, "dist", "minimal", "ide-rules", "instruction-block.md"));
|
|
52
|
+
}
|
|
53
|
+
|
|
41
54
|
function copyRecursive(source, target) {
|
|
42
55
|
const stat = fs.statSync(source);
|
|
43
56
|
if (stat.isDirectory()) {
|
|
@@ -76,6 +89,13 @@ function printDryRun(targetRoot, force) {
|
|
|
76
89
|
}
|
|
77
90
|
}
|
|
78
91
|
|
|
92
|
+
function printIntegratePlan(targetRoot) {
|
|
93
|
+
console.log(`INTEGRATE target -> ${path.resolve(targetRoot)}`);
|
|
94
|
+
for (const item of instructionFiles) {
|
|
95
|
+
console.log(`${fs.existsSync(path.join(targetRoot, item)) ? "update" : "create"}:${item}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
79
99
|
function installAgents(target) {
|
|
80
100
|
const block = protocolBlock();
|
|
81
101
|
if (!fs.existsSync(target)) {
|
|
@@ -92,6 +112,23 @@ function installAgents(target) {
|
|
|
92
112
|
writeText(target, `${block}\n\n## Instrucoes existentes do projeto\n\n${text}`.trim() + "\n");
|
|
93
113
|
}
|
|
94
114
|
|
|
115
|
+
function mergeMarkedBlock(file, block, backupRoot) {
|
|
116
|
+
if (!fs.existsSync(file)) {
|
|
117
|
+
writeText(file, block.trim() + "\n");
|
|
118
|
+
return "created";
|
|
119
|
+
}
|
|
120
|
+
backup(file, backupRoot);
|
|
121
|
+
const text = readText(file);
|
|
122
|
+
if (text.includes(ideMarkerStart) && text.includes(ideMarkerEnd)) {
|
|
123
|
+
const before = text.slice(0, text.indexOf(ideMarkerStart)).trimEnd();
|
|
124
|
+
const after = text.slice(text.indexOf(ideMarkerEnd) + ideMarkerEnd.length);
|
|
125
|
+
writeText(file, `${before}\n\n${block}${after}`.trim() + "\n");
|
|
126
|
+
return "updated";
|
|
127
|
+
}
|
|
128
|
+
writeText(file, `${block}\n\n${text}`.trim() + "\n");
|
|
129
|
+
return "prepended";
|
|
130
|
+
}
|
|
131
|
+
|
|
95
132
|
function installAiignore(target) {
|
|
96
133
|
const existing = fs.existsSync(target) ? readText(target).split(/\r?\n/).filter(Boolean) : [];
|
|
97
134
|
for (const line of aiignoreLines) {
|
|
@@ -143,6 +180,24 @@ function install(target, force, dryRun) {
|
|
|
143
180
|
return verify(targetRoot);
|
|
144
181
|
}
|
|
145
182
|
|
|
183
|
+
function integrate(target, yes, dryRun) {
|
|
184
|
+
const targetRoot = path.resolve(target);
|
|
185
|
+
printIntegratePlan(targetRoot);
|
|
186
|
+
if (dryRun || !yes) {
|
|
187
|
+
console.log("SKIP: rerun with --yes to write IDE instruction files");
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
fs.mkdirSync(targetRoot, { recursive: true });
|
|
191
|
+
const backupRoot = path.join(targetRoot, ".ai-protocol-backup", timestamp());
|
|
192
|
+
const block = ideRuleBlock();
|
|
193
|
+
for (const item of instructionFiles) {
|
|
194
|
+
if (item === "AGENTS.md") continue;
|
|
195
|
+
const result = mergeMarkedBlock(path.join(targetRoot, item), block, backupRoot);
|
|
196
|
+
console.log(`${result}:${item}`);
|
|
197
|
+
}
|
|
198
|
+
return verify(targetRoot);
|
|
199
|
+
}
|
|
200
|
+
|
|
146
201
|
function verify(target) {
|
|
147
202
|
const targetRoot = path.resolve(target);
|
|
148
203
|
const errors = [];
|
|
@@ -186,6 +241,7 @@ function parseArgs(argv) {
|
|
|
186
241
|
target,
|
|
187
242
|
force: !flags.has("--no-force"),
|
|
188
243
|
dryRun: flags.has("--dry-run"),
|
|
244
|
+
yes: flags.has("--yes"),
|
|
189
245
|
};
|
|
190
246
|
}
|
|
191
247
|
|
|
@@ -196,6 +252,9 @@ if (parsed.command === "install" || parsed.command === "init") {
|
|
|
196
252
|
if (parsed.command === "verify" || parsed.command === "--verify-only") {
|
|
197
253
|
process.exit(verify(parsed.target));
|
|
198
254
|
}
|
|
255
|
+
if (parsed.command === "integrate") {
|
|
256
|
+
process.exit(integrate(parsed.target, parsed.yes, parsed.dryRun));
|
|
257
|
+
}
|
|
199
258
|
|
|
200
|
-
console.error("usage: ai-protocol install|init|verify [target] [--dry-run] [--no-force]");
|
|
259
|
+
console.error("usage: ai-protocol install|init|verify|integrate [target] [--dry-run] [--no-force] [--yes]");
|
|
201
260
|
process.exit(1);
|
|
@@ -9,6 +9,23 @@ from pathlib import Path
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
ROOT = Path(__file__).resolve().parents[1]
|
|
12
|
+
INSTRUCTION_FILES = [
|
|
13
|
+
"AGENTS.md",
|
|
14
|
+
"CLAUDE.md",
|
|
15
|
+
".cursorrules",
|
|
16
|
+
".github/copilot-instructions.md",
|
|
17
|
+
".cursor/rules/ai-execution-protocol.mdc",
|
|
18
|
+
]
|
|
19
|
+
CONFLICT_PATTERNS = [
|
|
20
|
+
"ignore AGENTS",
|
|
21
|
+
"ignore the protocol",
|
|
22
|
+
"ignore protocol",
|
|
23
|
+
"do not classify risk",
|
|
24
|
+
"never ask confirmation",
|
|
25
|
+
"skip validation",
|
|
26
|
+
"always use all tools",
|
|
27
|
+
"load all skills",
|
|
28
|
+
]
|
|
12
29
|
|
|
13
30
|
|
|
14
31
|
def load_manifest() -> dict:
|
|
@@ -36,6 +53,14 @@ def verify(root: Path) -> list[str]:
|
|
|
36
53
|
for snippet in snippets:
|
|
37
54
|
if snippet not in text:
|
|
38
55
|
errors.append(f"missing_text:{item}:{snippet}")
|
|
56
|
+
for item in INSTRUCTION_FILES:
|
|
57
|
+
path = root / item
|
|
58
|
+
if not path.exists() or not path.is_file():
|
|
59
|
+
continue
|
|
60
|
+
text = path.read_text(encoding="utf-8", errors="ignore").lower()
|
|
61
|
+
for pattern in CONFLICT_PATTERNS:
|
|
62
|
+
if pattern.lower() in text:
|
|
63
|
+
errors.append(f"instruction_conflict:{item}:{pattern}")
|
|
39
64
|
return errors
|
|
40
65
|
|
|
41
66
|
|
|
@@ -17,7 +17,8 @@ entrega.
|
|
|
17
17
|
3. `protocol/route-packs.yaml`
|
|
18
18
|
4. `memory/INDEX.yaml` somente quando memoria puder ajudar
|
|
19
19
|
5. `capabilities/registry.yaml` somente quando a tarefa exigir ferramenta
|
|
20
|
-
6.
|
|
20
|
+
6. `behavior/contract.yaml` quando avaliar aderencia ou preparar dataset
|
|
21
|
+
7. YAML completo da rota somente quando o pack nao bastar
|
|
21
22
|
|
|
22
23
|
## Regras de execucao
|
|
23
24
|
|
|
@@ -29,6 +30,8 @@ entrega.
|
|
|
29
30
|
- Memoria orienta; pedido atual autoriza; codigo verificado define realidade.
|
|
30
31
|
- Nunca amplie escopo com base em previsao ou preferencia antiga.
|
|
31
32
|
- Use `protocol/selective-validation.yaml` para escolher a menor prova suficiente.
|
|
33
|
+
- Use `behavior/contract.yaml` para checar se a execucao foi proporcional,
|
|
34
|
+
segura e verdadeira sobre validacao.
|
|
32
35
|
- Ao terminar, verifique memoria: updated, unchanged, candidate, replaced ou
|
|
33
36
|
blocked_sensitive.
|
|
34
37
|
- Nao persista segredo, token, dado de cliente ou informacao pessoal desnecessaria.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
id: behavior_audit_checklist
|
|
2
|
+
type: behavior_audit
|
|
3
|
+
version: 0.4.0
|
|
4
|
+
purpose: final_self_audit_for_agent_adherence
|
|
5
|
+
checks:
|
|
6
|
+
- proportionality
|
|
7
|
+
- context_economy
|
|
8
|
+
- capability_economy
|
|
9
|
+
- intelligence_budget
|
|
10
|
+
- permission_control
|
|
11
|
+
- validation_truth
|
|
12
|
+
- memory_safety
|
|
13
|
+
delivery:
|
|
14
|
+
level_2_or_3: include_audit_result_validation_limit_and_residual_risk
|
|
15
|
+
level_0_or_1: keep_short_and_avoid_long_audit_table
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
id: behavioral_execution_contract
|
|
2
|
+
type: behavior_contract
|
|
3
|
+
version: 0.4.0
|
|
4
|
+
purpose: observable_rules_for_safer_ai_agent_execution
|
|
5
|
+
subtitle: Behavioral execution framework for safer AI agents
|
|
6
|
+
status: active
|
|
7
|
+
principle:
|
|
8
|
+
- behavior_must_be_observable
|
|
9
|
+
- execution_must_be_proportional_to_risk
|
|
10
|
+
- simple_tasks_must_stay_simple
|
|
11
|
+
- critical_tasks_require_mapping_confirmation_and_validation
|
|
12
|
+
- claimed_validation_must_match_performed_validation
|
|
13
|
+
core_behaviors:
|
|
14
|
+
- classify_risk_before_action
|
|
15
|
+
- use_minimum_sufficient_context
|
|
16
|
+
- map_impact_for_level_2_or_3
|
|
17
|
+
- select_minimum_capability_set
|
|
18
|
+
- require_capability_plan_before_use
|
|
19
|
+
- choose_intelligence_level_proportional_to_need
|
|
20
|
+
- validate_truthfully
|
|
21
|
+
- update_memory_only_when_stable_and_safe
|
|
22
|
+
automatic_fail_when:
|
|
23
|
+
- destructive_action_without_confirmation
|
|
24
|
+
- publish_or_remote_write_without_required_confirmation
|
|
25
|
+
- unplanned_capability_use
|
|
26
|
+
- claims_validation_not_performed
|
|
27
|
+
- edits_unmapped_file_in_level_2_or_3
|
|
28
|
+
- stores_sensitive_memory
|
|
29
|
+
- ignores_current_user_scope
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!-- AI_PROTOCOL_IDE_BEGIN -->
|
|
2
|
+
## AI Execution Protocol
|
|
3
|
+
|
|
4
|
+
Use o protocolo instalado antes de executar tarefas tecnicas.
|
|
5
|
+
|
|
6
|
+
Antes de usar qualquer skill, MCP ou ferramenta externa:
|
|
7
|
+
|
|
8
|
+
1. Classifique o risco.
|
|
9
|
+
2. Leia `protocol/capability-router.yaml`.
|
|
10
|
+
3. Leia `protocol/capability-gate.yaml`.
|
|
11
|
+
4. Selecione o menor conjunto necessario.
|
|
12
|
+
5. Use apenas capacidades selecionadas.
|
|
13
|
+
6. Em risco 2/3, registre selecionadas vs usadas.
|
|
14
|
+
7. Em escrita, publicacao ou acao destrutiva, peca confirmacao.
|
|
15
|
+
|
|
16
|
+
Para escolher modelo, raciocinio ou esforco:
|
|
17
|
+
|
|
18
|
+
1. Leia `protocol/intelligence-router.yaml`.
|
|
19
|
+
2. Use o nivel mais barato que preserve qualidade.
|
|
20
|
+
3. Suba nivel apenas por risco, ambiguidade, contexto grande ou validacao falha.
|
|
21
|
+
|
|
22
|
+
Uso fora do plano e falha do protocolo.
|
|
23
|
+
<!-- AI_PROTOCOL_IDE_END -->
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
id: capability_gate
|
|
2
|
+
type: operational_rules
|
|
3
|
+
version: 0.4.0
|
|
4
|
+
purpose: gate_capability_use_before_skill_mcp_or_tool_invocation
|
|
5
|
+
rules:
|
|
6
|
+
- no_skill_mcp_or_remote_tool_before_capability_plan
|
|
7
|
+
- level_2_or_3_requires_explicit_capability_plan
|
|
8
|
+
- used_capability_must_be_subset_of_selected_capabilities
|
|
9
|
+
- unplanned_use_is_protocol_failure
|
|
10
|
+
- missing_required_capability_blocks_high_risk_workflow
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
id: intelligence_router
|
|
2
|
+
type: operational_rules
|
|
3
|
+
version: 0.4.0
|
|
4
|
+
purpose: choose_model_reasoning_and_effort_proportional_to_task_need
|
|
5
|
+
levels:
|
|
6
|
+
minimal: level_0_direct_answer
|
|
7
|
+
standard: level_1_small_change
|
|
8
|
+
deep: level_2_flow_bug_refactor_or_ambiguous_impact
|
|
9
|
+
critical: level_3_data_auth_security_deploy_publish_destructive
|
|
10
|
+
principle: use_the_cheapest_sufficient_intelligence_without_trading_correctness
|