ai-execution-protocol 0.3.0 → 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 +12 -1
- package/README.md +54 -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 +8 -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 +48 -0
- package/dist/minimal/context-map.yaml +2 -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 +11 -1
- package/dist/minimal/protocol/capability-gate.yaml +56 -0
- package/dist/minimal/protocol/capability-router.yaml +123 -0
- package/dist/minimal/protocol/context-rules.yaml +2 -1
- package/dist/minimal/protocol/fast-path.yaml +8 -1
- package/dist/minimal/protocol/intelligence-router.yaml +63 -0
- package/dist/minimal/protocol/route-packs.yaml +49 -1
- package/dist/minimal/protocol/router.yaml +35 -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 +38 -2
- package/package.json +9 -2
- package/protocol/README.yaml +11 -1
- package/protocol/capability-gate.yaml +56 -0
- package/protocol/capability-router.yaml +123 -0
- package/protocol/context-rules.yaml +2 -1
- package/protocol/fast-path.yaml +8 -1
- package/protocol/intelligence-router.yaml +63 -0
- package/protocol/route-packs.yaml +49 -1
- package/protocol/router.yaml +35 -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 +79 -1
- 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 +8 -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 +48 -0
- package/templates/minimal/context-map.yaml +2 -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,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
|
@@ -73,6 +73,53 @@ python scripts/selective_validation.py
|
|
|
73
73
|
python scripts/selective_validation.py --release
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
## capability_router.py
|
|
77
|
+
|
|
78
|
+
Seleciona o menor conjunto de skills, MCPs e ferramentas que cobre a tarefa.
|
|
79
|
+
|
|
80
|
+
```powershell
|
|
81
|
+
python scripts/capability_router.py --risk 1 --operation read --tag code_search
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Capacidades marcadas como `runtime` precisam ser informadas:
|
|
85
|
+
|
|
86
|
+
```powershell
|
|
87
|
+
python scripts/capability_router.py --risk 2 --operation read --tag external_context --available targeted_mcp
|
|
88
|
+
```
|
|
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
|
+
|
|
76
123
|
## health_check.py
|
|
77
124
|
|
|
78
125
|
Roda a validacao geral do framework.
|
|
@@ -137,14 +184,40 @@ instalacao.
|
|
|
137
184
|
python scripts/v03_tests.py
|
|
138
185
|
```
|
|
139
186
|
|
|
187
|
+
## v031_tests.py
|
|
188
|
+
|
|
189
|
+
Testa cobertura, custo, disponibilidade e confirmacao do roteador de
|
|
190
|
+
capacidades.
|
|
191
|
+
|
|
192
|
+
```powershell
|
|
193
|
+
python scripts/v031_tests.py
|
|
194
|
+
```
|
|
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
|
+
|
|
140
204
|
## context_economy_benchmark.py
|
|
141
205
|
|
|
142
|
-
Compara leitura ampla com rotas focadas
|
|
206
|
+
Compara leitura ampla com rotas focadas do protocolo atual.
|
|
143
207
|
|
|
144
208
|
```powershell
|
|
145
209
|
python scripts/context_economy_benchmark.py
|
|
146
210
|
```
|
|
147
211
|
|
|
212
|
+
## capability_economy_benchmark.py
|
|
213
|
+
|
|
214
|
+
Compara carregar o catalogo inteiro com selecionar apenas capacidades
|
|
215
|
+
necessarias.
|
|
216
|
+
|
|
217
|
+
```powershell
|
|
218
|
+
python scripts/capability_economy_benchmark.py
|
|
219
|
+
```
|
|
220
|
+
|
|
148
221
|
## build_dist.py
|
|
149
222
|
|
|
150
223
|
Gera `dist/minimal/` a partir de `AGENTS.md` minimo e `protocol/`.
|
|
@@ -186,6 +259,8 @@ npm install -g ai-execution-protocol
|
|
|
186
259
|
ai-protocol init C:\caminho\projeto
|
|
187
260
|
ai-protocol install C:\caminho\projeto
|
|
188
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
|
|
189
264
|
```
|
|
190
265
|
|
|
191
266
|
## npm_install_protocol.js
|
|
@@ -197,6 +272,7 @@ Exemplo:
|
|
|
197
272
|
```powershell
|
|
198
273
|
npm run install-protocol -- C:\caminho\projeto
|
|
199
274
|
npm run dry-run-protocol -- C:\caminho\projeto
|
|
275
|
+
npm run integrate-protocol -- C:\caminho\projeto --yes
|
|
200
276
|
```
|
|
201
277
|
|
|
202
278
|
Para conferir manualmente pelo mesmo wrapper:
|
|
@@ -215,6 +291,8 @@ Uso local:
|
|
|
215
291
|
python -m ai_execution_protocol install C:\caminho\projeto
|
|
216
292
|
python -m ai_execution_protocol init C:\caminho\projeto
|
|
217
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
|
|
218
296
|
python -m ai_execution_protocol verify C:\caminho\projeto
|
|
219
297
|
```
|
|
220
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
|
|
|
@@ -16,15 +16,22 @@ entrega.
|
|
|
16
16
|
2. `protocol/router.yaml`
|
|
17
17
|
3. `protocol/route-packs.yaml`
|
|
18
18
|
4. `memory/INDEX.yaml` somente quando memoria puder ajudar
|
|
19
|
-
5.
|
|
19
|
+
5. `capabilities/registry.yaml` somente quando a tarefa exigir ferramenta
|
|
20
|
+
6. `behavior/contract.yaml` quando avaliar aderencia ou preparar dataset
|
|
21
|
+
7. YAML completo da rota somente quando o pack nao bastar
|
|
20
22
|
|
|
21
23
|
## Regras de execucao
|
|
22
24
|
|
|
23
25
|
- Classifique o risco antes de agir.
|
|
24
26
|
- Use o menor contexto suficiente e respeite `protocol/context-budget.yaml`.
|
|
27
|
+
- Use `protocol/capability-router.yaml` para carregar somente skills, MCPs e
|
|
28
|
+
ferramentas necessarias.
|
|
29
|
+
- Risco maior restringe permissao; nao aumenta a quantidade por padrao.
|
|
25
30
|
- Memoria orienta; pedido atual autoriza; codigo verificado define realidade.
|
|
26
31
|
- Nunca amplie escopo com base em previsao ou preferencia antiga.
|
|
27
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.
|
|
28
35
|
- Ao terminar, verifique memoria: updated, unchanged, candidate, replaced ou
|
|
29
36
|
blocked_sensitive.
|
|
30
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,48 @@
|
|
|
1
|
+
id: capability_registry
|
|
2
|
+
type: capability_registry
|
|
3
|
+
version: 0.4.0
|
|
4
|
+
purpose: project_capabilities_available_to_the_agent
|
|
5
|
+
policy:
|
|
6
|
+
default_available: false
|
|
7
|
+
runtime_availability_must_be_verified: true
|
|
8
|
+
capabilities:
|
|
9
|
+
- id: local_search
|
|
10
|
+
type: local_tool
|
|
11
|
+
available: true
|
|
12
|
+
tags: [code_search, file_discovery]
|
|
13
|
+
operations: [read]
|
|
14
|
+
cost: {tokens: low, latency: low}
|
|
15
|
+
side_effect: none
|
|
16
|
+
confirmation: never
|
|
17
|
+
- id: local_files
|
|
18
|
+
type: local_tool
|
|
19
|
+
available: true
|
|
20
|
+
tags: [file_read, file_write]
|
|
21
|
+
operations: [read, write]
|
|
22
|
+
cost: {tokens: low, latency: low}
|
|
23
|
+
side_effect: local_write
|
|
24
|
+
confirmation: risk_based
|
|
25
|
+
- id: focused_skill
|
|
26
|
+
type: skill
|
|
27
|
+
available: runtime
|
|
28
|
+
tags: [domain_guidance]
|
|
29
|
+
operations: [read]
|
|
30
|
+
cost: {tokens: medium, latency: low}
|
|
31
|
+
side_effect: none
|
|
32
|
+
confirmation: never
|
|
33
|
+
- id: targeted_mcp
|
|
34
|
+
type: mcp
|
|
35
|
+
available: runtime
|
|
36
|
+
tags: [external_context, remote_operation]
|
|
37
|
+
operations: [read, write]
|
|
38
|
+
cost: {tokens: medium, latency: medium}
|
|
39
|
+
side_effect: remote_write
|
|
40
|
+
confirmation: operation_based
|
|
41
|
+
- id: publish_service
|
|
42
|
+
type: remote_service
|
|
43
|
+
available: runtime
|
|
44
|
+
tags: [publish]
|
|
45
|
+
operations: [publish]
|
|
46
|
+
cost: {tokens: low, latency: medium}
|
|
47
|
+
side_effect: publish
|
|
48
|
+
confirmation: always
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
id: project_context_map
|
|
2
2
|
type: context_map
|
|
3
|
-
version: 0.
|
|
3
|
+
version: 0.4.0
|
|
4
4
|
purpose: small_index_for_progressive_context_retrieval
|
|
5
5
|
maintenance:
|
|
6
6
|
current_mode: manual_bootstrap
|
|
@@ -11,6 +11,7 @@ read_first:
|
|
|
11
11
|
- protocol/router.yaml
|
|
12
12
|
- protocol/route-packs.yaml
|
|
13
13
|
- memory/INDEX.yaml
|
|
14
|
+
- capabilities/registry.yaml
|
|
14
15
|
domains: {}
|
|
15
16
|
retrieval_policy:
|
|
16
17
|
order:
|
|
@@ -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
|