oxe-cc 1.16.0 → 1.21.1
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/.github/copilot-instructions.md +177 -177
- package/.github/dependabot.yml +31 -31
- package/.github/workflows/ci.yml +159 -138
- package/.github/workflows/release.yml +107 -106
- package/AGENTS.md +97 -97
- package/CHANGELOG.md +1032 -856
- package/README.md +673 -600
- package/assets/readme-banner.svg +19 -19
- package/bin/banner.txt +13 -13
- package/bin/lib/oxe-agent-install.cjs +650 -650
- package/bin/lib/oxe-artifact-catalog.cjs +376 -376
- package/bin/lib/oxe-azure.cjs +1445 -1445
- package/bin/lib/oxe-budget.cjs +117 -0
- package/bin/lib/oxe-change.cjs +230 -0
- package/bin/lib/oxe-command-registry.cjs +31 -31
- package/bin/lib/oxe-commit-convention.cjs +85 -0
- package/bin/lib/oxe-context-engine.cjs +874 -874
- package/bin/lib/oxe-core-command-handlers.cjs +82 -82
- package/bin/lib/oxe-criterion-coverage.cjs +58 -0
- package/bin/lib/oxe-dashboard.cjs +737 -737
- package/bin/lib/oxe-dossier.cjs +281 -0
- package/bin/lib/oxe-install-resolve.cjs +134 -106
- package/bin/lib/oxe-manifest.cjs +124 -124
- package/bin/lib/oxe-npm-version.cjs +66 -66
- package/bin/lib/oxe-operational.cjs +4484 -2676
- package/bin/lib/oxe-phase-gates.cjs +280 -0
- package/bin/lib/oxe-plan-json.cjs +433 -0
- package/bin/lib/oxe-plugin-cli.cjs +95 -95
- package/bin/lib/oxe-plugins.cjs +432 -432
- package/bin/lib/oxe-process.cjs +56 -56
- package/bin/lib/oxe-program.cjs +205 -0
- package/bin/lib/oxe-project-env.cjs +178 -0
- package/bin/lib/oxe-project-health.cjs +2962 -2846
- package/bin/lib/oxe-rationality.cjs +73 -49
- package/bin/lib/oxe-release.cjs +42 -0
- package/bin/lib/oxe-repo-rules.cjs +108 -0
- package/bin/lib/oxe-runtime-semantics.cjs +514 -514
- package/bin/lib/oxe-scorecard.cjs +164 -0
- package/bin/lib/oxe-security.cjs +289 -289
- package/bin/lib/oxe-spike.cjs +98 -0
- package/bin/lib/oxe-verify-dryrun.cjs +152 -0
- package/bin/lib/oxe-workflows.cjs +145 -145
- package/bin/oxe-cc.js +6281 -5829
- package/docs/INTEGRATION.md +182 -182
- package/docs/QUALITY-GATES.md +46 -46
- package/docs/RELEASE-READINESS.md +87 -86
- package/docs/RUNTIME-SMOKE-MATRIX.md +137 -137
- package/docs/oxespace-1.5/BACKLOG.md +273 -0
- package/docs/oxevoice/BACKLOG.md +244 -0
- package/lib/runtime/compiler/graph-compiler.d.ts +13 -0
- package/lib/runtime/compiler/graph-compiler.js +40 -3
- package/lib/runtime/delivery/promotion-pipeline.js +6 -2
- package/lib/runtime/events/catalog.d.ts +1 -1
- package/lib/runtime/events/catalog.js +11 -0
- package/lib/runtime/executor/adapters/claude-cli.d.ts +63 -0
- package/lib/runtime/executor/adapters/claude-cli.js +250 -0
- package/lib/runtime/executor/adapters/http-openai.d.ts +9 -0
- package/lib/runtime/executor/adapters/http-openai.js +18 -0
- package/lib/runtime/executor/adapters/registry.d.ts +13 -0
- package/lib/runtime/executor/adapters/registry.js +29 -0
- package/lib/runtime/executor/adapters/types.d.ts +21 -0
- package/lib/runtime/executor/adapters/types.js +2 -0
- package/lib/runtime/executor/built-in-tools.d.ts +8 -0
- package/lib/runtime/executor/built-in-tools.js +40 -9
- package/lib/runtime/executor/index.d.ts +12 -2
- package/lib/runtime/executor/index.js +28 -1
- package/lib/runtime/executor/llm-task-executor.d.ts +35 -2
- package/lib/runtime/executor/llm-task-executor.js +97 -21
- package/lib/runtime/executor/node-context.d.ts +83 -0
- package/lib/runtime/executor/node-context.js +116 -0
- package/lib/runtime/executor/node-prompt-builder.d.ts +2 -0
- package/lib/runtime/executor/node-prompt-builder.js +2 -0
- package/lib/runtime/executor/shell-argv.d.ts +30 -0
- package/lib/runtime/executor/shell-argv.js +57 -0
- package/lib/runtime/executor/stream-completion.d.ts +11 -0
- package/lib/runtime/executor/stream-completion.js +10 -1
- package/lib/runtime/index.d.ts +5 -2
- package/lib/runtime/index.js +8 -1
- package/lib/runtime/program/index.d.ts +1 -0
- package/lib/runtime/program/index.js +17 -0
- package/lib/runtime/program/program-model.d.ts +74 -0
- package/lib/runtime/program/program-model.js +195 -0
- package/lib/runtime/projection/projection-engine.d.ts +10 -1
- package/lib/runtime/projection/projection-engine.js +25 -1
- package/lib/runtime/reducers/run-state-reducer.js +5 -0
- package/lib/runtime/scheduler/run-journal.d.ts +19 -1
- package/lib/runtime/scheduler/run-journal.js +40 -1
- package/lib/runtime/scheduler/scheduler.d.ts +30 -0
- package/lib/runtime/scheduler/scheduler.js +195 -19
- package/lib/runtime/verification/contract-exports.d.ts +24 -0
- package/lib/runtime/verification/contract-exports.js +201 -0
- package/lib/runtime/verification/index.d.ts +1 -0
- package/lib/runtime/verification/index.js +1 -0
- package/lib/runtime/verification/test-report-parsers.d.ts +37 -0
- package/lib/runtime/verification/test-report-parsers.js +180 -0
- package/lib/runtime/verification/verification-compiler.d.ts +67 -1
- package/lib/runtime/verification/verification-compiler.js +302 -25
- package/lib/runtime/verification/verification-manifest.d.ts +10 -0
- package/lib/runtime/verification/verification-manifest.js +18 -3
- package/lib/runtime/workspace/strategies/git-worktree.d.ts +9 -0
- package/lib/runtime/workspace/strategies/git-worktree.js +81 -0
- package/lib/sdk/README.md +61 -61
- package/lib/sdk/index.cjs +815 -810
- package/lib/sdk/index.d.ts +982 -982
- package/lib/sdk/index.types.ts +933 -933
- package/oxe/schemas/plan-agents.schema.json +122 -122
- package/oxe/schemas/plan.schema.json +85 -0
- package/oxe/templates/ACTIVE-RUN.template.json +32 -32
- package/oxe/templates/CAPABILITIES.template.md +7 -7
- package/oxe/templates/CAPABILITY.template.md +45 -45
- package/oxe/templates/CHECKPOINT.template.md +37 -37
- package/oxe/templates/CHECKPOINTS.template.md +7 -7
- package/oxe/templates/CODEBASE-DELTA.template.md +33 -33
- package/oxe/templates/CONFIG.md +105 -105
- package/oxe/templates/DISCUSS.template.md +44 -44
- package/oxe/templates/DOCS_BROWNFIELD_LAYOUT.md +55 -55
- package/oxe/templates/EXECUTION-RUNTIME.template.md +68 -68
- package/oxe/templates/FIXTURE-PACK.template.json +23 -23
- package/oxe/templates/FIXTURE-PACK.template.md +11 -11
- package/oxe/templates/GIT_HOOKS_OXE.md +52 -52
- package/oxe/templates/HYPOTHESES.template.md +33 -33
- package/oxe/templates/IMPLEMENTATION-PACK.template.json +42 -42
- package/oxe/templates/IMPLEMENTATION-PACK.template.md +16 -16
- package/oxe/templates/INVESTIGATION.template.md +38 -38
- package/oxe/templates/LESSONS-METRICS.template.json +13 -13
- package/oxe/templates/LESSONS.template.md +43 -43
- package/oxe/templates/MEMORY.template.md +49 -49
- package/oxe/templates/MILESTONES.template.md +17 -17
- package/oxe/templates/NOTES.template.md +16 -16
- package/oxe/templates/OBSERVATIONS.template.md +18 -18
- package/oxe/templates/PLAN-REVIEW.template.md +31 -31
- package/oxe/templates/PLAN.template.md +66 -66
- package/oxe/templates/PLUGINS.md +108 -108
- package/oxe/templates/REFERENCE-ANCHORS.template.md +9 -9
- package/oxe/templates/RESEARCH.template.md +57 -57
- package/oxe/templates/RESUME.template.md +49 -49
- package/oxe/templates/ROADMAP.template.md +44 -44
- package/oxe/templates/SECURITY.template.md +72 -72
- package/oxe/templates/SESSION.template.md +34 -34
- package/oxe/templates/SKILL.template.md +26 -26
- package/oxe/templates/SPEC.template.md +54 -54
- package/oxe/templates/STATE-REFERENCE.md +125 -125
- package/oxe/templates/STATE.md +30 -30
- package/oxe/templates/WORKFLOW_AUTHORING.md +93 -93
- package/oxe/templates/config.template.json +38 -38
- package/oxe/templates/plan-agent-messages-README.template.md +9 -9
- package/oxe/templates/plan-agents.template.json +30 -30
- package/oxe/templates/quick-agents.template.json +24 -24
- package/oxe/workflows/ask.md +96 -96
- package/oxe/workflows/capabilities.md +25 -25
- package/oxe/workflows/checkpoint.md +37 -37
- package/oxe/workflows/compact.md +44 -44
- package/oxe/workflows/dashboard.md +33 -33
- package/oxe/workflows/debug.md +34 -34
- package/oxe/workflows/discuss.md +86 -86
- package/oxe/workflows/execute.md +255 -255
- package/oxe/workflows/forensics.md +48 -48
- package/oxe/workflows/help.md +355 -355
- package/oxe/workflows/loop.md +67 -67
- package/oxe/workflows/milestone.md +95 -95
- package/oxe/workflows/next.md +45 -45
- package/oxe/workflows/obs.md +167 -167
- package/oxe/workflows/oxe.md +150 -149
- package/oxe/workflows/plan-agent.md +143 -143
- package/oxe/workflows/plan.md +525 -523
- package/oxe/workflows/project.md +55 -55
- package/oxe/workflows/quick.md +185 -185
- package/oxe/workflows/references/adaptive-discovery.md +27 -27
- package/oxe/workflows/references/flow-robustness-contract.md +80 -80
- package/oxe/workflows/references/legacy-brownfield.md +136 -136
- package/oxe/workflows/references/plan-agent-chat-protocol.md +99 -99
- package/oxe/workflows/references/plan-json-acceptance-program.md +143 -0
- package/oxe/workflows/references/reasoning-discovery.md +28 -28
- package/oxe/workflows/references/reasoning-execution.md +29 -29
- package/oxe/workflows/references/reasoning-planning.md +32 -32
- package/oxe/workflows/references/reasoning-review.md +29 -29
- package/oxe/workflows/references/reasoning-status.md +24 -24
- package/oxe/workflows/references/robustness-elevation.md +295 -295
- package/oxe/workflows/references/session-path-resolution.md +71 -71
- package/oxe/workflows/research.md +66 -66
- package/oxe/workflows/retro.md +117 -117
- package/oxe/workflows/review-pr.md +53 -53
- package/oxe/workflows/route.md +32 -32
- package/oxe/workflows/security.md +67 -67
- package/oxe/workflows/session.md +213 -213
- package/oxe/workflows/ship.md +142 -142
- package/oxe/workflows/skill.md +44 -44
- package/oxe/workflows/spec.md +569 -566
- package/oxe/workflows/ui-review.md +32 -32
- package/oxe/workflows/ui-spec.md +25 -25
- package/oxe/workflows/update.md +35 -35
- package/oxe/workflows/validate-gaps.md +45 -45
- package/oxe/workflows/verify-audit.md +73 -73
- package/oxe/workflows/verify.md +247 -244
- package/oxe/workflows/workflow-authoring.md +34 -34
- package/oxe/workflows/workstream.md +97 -97
- package/package.json +132 -129
- package/packages/runtime/package.json +18 -18
- package/packages/runtime/src/audit/audit-trail.ts +243 -243
- package/packages/runtime/src/audit/index.ts +2 -2
- package/packages/runtime/src/audit/policy-pack.ts +62 -62
- package/packages/runtime/src/compiler/graph-compiler.ts +336 -285
- package/packages/runtime/src/compiler/index.ts +1 -1
- package/packages/runtime/src/context/context-pack-builder.ts +339 -339
- package/packages/runtime/src/context/context-pack-store.ts +197 -197
- package/packages/runtime/src/context/context-profiles.ts +60 -60
- package/packages/runtime/src/context/index.ts +3 -3
- package/packages/runtime/src/decision/decision-engine.ts +174 -174
- package/packages/runtime/src/decision/decision-memo.ts +211 -211
- package/packages/runtime/src/decision/index.ts +2 -2
- package/packages/runtime/src/delivery/branch-manager.ts +91 -91
- package/packages/runtime/src/delivery/ci-checks.ts +285 -285
- package/packages/runtime/src/delivery/delivery-records.ts +75 -75
- package/packages/runtime/src/delivery/index.ts +5 -5
- package/packages/runtime/src/delivery/pr-manager.ts +112 -112
- package/packages/runtime/src/delivery/promotion-pipeline.ts +342 -334
- package/packages/runtime/src/events/bus.ts +92 -92
- package/packages/runtime/src/events/catalog.ts +45 -34
- package/packages/runtime/src/events/envelope.ts +14 -14
- package/packages/runtime/src/events/index.ts +3 -3
- package/packages/runtime/src/evidence/evidence-store.ts +130 -130
- package/packages/runtime/src/evidence/index.ts +1 -1
- package/packages/runtime/src/executor/adapters/claude-cli.ts +285 -0
- package/packages/runtime/src/executor/adapters/http-openai.ts +16 -0
- package/packages/runtime/src/executor/adapters/registry.ts +33 -0
- package/packages/runtime/src/executor/adapters/types.ts +24 -0
- package/packages/runtime/src/executor/built-in-tools.ts +36 -8
- package/packages/runtime/src/executor/index.ts +12 -2
- package/packages/runtime/src/executor/llm-task-executor.ts +125 -25
- package/packages/runtime/src/executor/node-context.ts +210 -0
- package/packages/runtime/src/executor/node-prompt-builder.ts +5 -0
- package/packages/runtime/src/executor/shell-argv.ts +66 -0
- package/packages/runtime/src/executor/stream-completion.ts +16 -1
- package/packages/runtime/src/gate/gate-manager.ts +289 -289
- package/packages/runtime/src/gate/index.ts +1 -1
- package/packages/runtime/src/index.ts +54 -44
- package/packages/runtime/src/models/attempt.ts +19 -19
- package/packages/runtime/src/models/evidence.ts +21 -21
- package/packages/runtime/src/models/gate-decision.ts +25 -25
- package/packages/runtime/src/models/index.ts +8 -8
- package/packages/runtime/src/models/run.ts +24 -24
- package/packages/runtime/src/models/session.ts +11 -11
- package/packages/runtime/src/models/verification-result.ts +10 -10
- package/packages/runtime/src/models/work-item.ts +25 -25
- package/packages/runtime/src/models/workspace.ts +31 -31
- package/packages/runtime/src/plugins/capability-adapter.ts +313 -313
- package/packages/runtime/src/plugins/capability-matrix.ts +126 -126
- package/packages/runtime/src/plugins/index.ts +5 -5
- package/packages/runtime/src/plugins/plugin-abi.ts +106 -106
- package/packages/runtime/src/plugins/plugin-manifest.ts +118 -118
- package/packages/runtime/src/plugins/plugin-registry.ts +241 -241
- package/packages/runtime/src/policy/index.ts +1 -1
- package/packages/runtime/src/policy/policy-engine.ts +330 -330
- package/packages/runtime/src/program/index.ts +1 -0
- package/packages/runtime/src/program/program-model.ts +233 -0
- package/packages/runtime/src/projection/index.ts +1 -1
- package/packages/runtime/src/projection/projection-engine.ts +361 -328
- package/packages/runtime/src/reducers/debug-reducer.ts +36 -36
- package/packages/runtime/src/reducers/index.ts +2 -2
- package/packages/runtime/src/reducers/run-state-reducer.ts +329 -326
- package/packages/runtime/src/scheduler/agent-registry.ts +132 -132
- package/packages/runtime/src/scheduler/agent-roles.ts +109 -109
- package/packages/runtime/src/scheduler/index.ts +4 -4
- package/packages/runtime/src/scheduler/multi-agent-coordinator.ts +1017 -1017
- package/packages/runtime/src/scheduler/run-journal.ts +105 -62
- package/packages/runtime/src/scheduler/scheduler.ts +1144 -938
- package/packages/runtime/src/verification/contract-exports.ts +203 -0
- package/packages/runtime/src/verification/index.ts +3 -2
- package/packages/runtime/src/verification/test-report-parsers.ts +198 -0
- package/packages/runtime/src/verification/verification-compiler.ts +766 -438
- package/packages/runtime/src/verification/verification-manifest.ts +281 -256
- package/packages/runtime/src/workspace/index.ts +5 -5
- package/packages/runtime/src/workspace/strategies/ephemeral-container.ts +126 -126
- package/packages/runtime/src/workspace/strategies/git-worktree.ts +150 -87
- package/packages/runtime/src/workspace/strategies/inplace.ts +38 -38
- package/packages/runtime/src/workspace/workspace-manager.ts +16 -16
- package/packages/runtime/tsconfig.json +23 -23
- package/vscode-extension/.vscodeignore +9 -9
- package/vscode-extension/package.json +193 -193
- package/vscode-extension/src/extension.js +320 -320
- package/vscode-extension/src/shared/contextLoader.js +137 -137
- package/vscode-extension/src/shared/contractBuilder.js +159 -159
- package/vscode-extension/src/shared/stateReader.js +101 -101
- package/docs/oxe-artifact-map.html +0 -1172
|
@@ -1,514 +1,514 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const crypto = require('crypto');
|
|
6
|
-
|
|
7
|
-
const CONTRACTS_PATH = path.join(
|
|
8
|
-
__dirname,
|
|
9
|
-
'..',
|
|
10
|
-
'..',
|
|
11
|
-
'oxe',
|
|
12
|
-
'workflows',
|
|
13
|
-
'references',
|
|
14
|
-
'workflow-runtime-contracts.json'
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const RUNTIME_METADATA_KEYS = [
|
|
18
|
-
'oxe_workflow_slug',
|
|
19
|
-
'oxe_reasoning_mode',
|
|
20
|
-
'oxe_question_policy',
|
|
21
|
-
'oxe_output_contract',
|
|
22
|
-
'oxe_tool_profile',
|
|
23
|
-
'oxe_confidence_policy',
|
|
24
|
-
'oxe_context_tier',
|
|
25
|
-
'oxe_contract_version',
|
|
26
|
-
'oxe_semantics_hash',
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
const REQUIRED_CONTRACT_FIELDS = [
|
|
30
|
-
'reasoning_mode',
|
|
31
|
-
'question_policy',
|
|
32
|
-
'output_contract',
|
|
33
|
-
'tool_profile',
|
|
34
|
-
'confidence_policy',
|
|
35
|
-
'required_artifacts',
|
|
36
|
-
'optional_artifacts',
|
|
37
|
-
'context_tiers',
|
|
38
|
-
'freshness_policy',
|
|
39
|
-
'fallback_policy',
|
|
40
|
-
'blocking_conditions',
|
|
41
|
-
'output_sections',
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
function readContractsRegistry() {
|
|
45
|
-
try {
|
|
46
|
-
const raw = fs.readFileSync(CONTRACTS_PATH, 'utf8');
|
|
47
|
-
const parsed = JSON.parse(raw);
|
|
48
|
-
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
49
|
-
} catch {
|
|
50
|
-
return {};
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const CONTRACTS_REGISTRY = readContractsRegistry();
|
|
55
|
-
if (!CONTRACTS_REGISTRY.contract_version) {
|
|
56
|
-
process.stderr.write('[oxe] WARN: workflow-runtime-contracts.json ausente ou inválido — usando defaults.\n');
|
|
57
|
-
}
|
|
58
|
-
const CONTRACT_VERSION = String(CONTRACTS_REGISTRY.contract_version || '0.0.0');
|
|
59
|
-
const MODE_REFERENCES = CONTRACTS_REGISTRY.mode_references || {};
|
|
60
|
-
const MODE_GUIDANCE = CONTRACTS_REGISTRY.mode_guidance || {};
|
|
61
|
-
const MODE_DEFAULT_SPECS = CONTRACTS_REGISTRY.mode_defaults || {};
|
|
62
|
-
const MODE_DEFAULTS = Object.fromEntries(
|
|
63
|
-
Object.entries(MODE_DEFAULT_SPECS).map(([mode, spec]) => [
|
|
64
|
-
mode,
|
|
65
|
-
{
|
|
66
|
-
oxe_reasoning_mode: mode,
|
|
67
|
-
oxe_question_policy: spec.question_policy,
|
|
68
|
-
oxe_output_contract: spec.output_contract,
|
|
69
|
-
oxe_tool_profile: spec.tool_profile,
|
|
70
|
-
oxe_confidence_policy: spec.confidence_policy,
|
|
71
|
-
},
|
|
72
|
-
])
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
function stableJson(value) {
|
|
76
|
-
if (Array.isArray(value)) return `[${value.map((item) => stableJson(item)).join(',')}]`;
|
|
77
|
-
if (value && typeof value === 'object') {
|
|
78
|
-
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(',')}}`;
|
|
79
|
-
}
|
|
80
|
-
return JSON.stringify(value);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function uniqueStrings(items) {
|
|
84
|
-
return Array.from(new Set((items || []).map((item) => String(item || '').trim()).filter(Boolean)));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function buildContextTiers(requiredArtifacts, optionalArtifacts) {
|
|
88
|
-
const required = uniqueStrings(requiredArtifacts);
|
|
89
|
-
const optional = uniqueStrings(optionalArtifacts);
|
|
90
|
-
const minimalTail = optional.filter((item) => /(phase_summary|project_summary|session_summary)$/.test(item)).slice(0, 2);
|
|
91
|
-
const standardTail = optional.filter((item) => !minimalTail.includes(item)).slice(0, 4);
|
|
92
|
-
return {
|
|
93
|
-
minimal: uniqueStrings([...required, ...minimalTail]),
|
|
94
|
-
standard: uniqueStrings([...required, ...minimalTail, ...standardTail]),
|
|
95
|
-
full: uniqueStrings([...required, ...optional]),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function getWorkflowContract(slug) {
|
|
100
|
-
const workflow = (CONTRACTS_REGISTRY.workflows || {})[slug];
|
|
101
|
-
if (!workflow) return null;
|
|
102
|
-
const mode = String(workflow.reasoning_mode || 'status');
|
|
103
|
-
const modeDefaults = MODE_DEFAULT_SPECS[mode] || MODE_DEFAULT_SPECS.status || {};
|
|
104
|
-
const requiredArtifacts = uniqueStrings(workflow.required_artifacts);
|
|
105
|
-
const optionalArtifacts = uniqueStrings(workflow.optional_artifacts);
|
|
106
|
-
return {
|
|
107
|
-
workflow_slug: slug,
|
|
108
|
-
contract_version: CONTRACT_VERSION,
|
|
109
|
-
reasoning_mode: mode,
|
|
110
|
-
question_policy: String(workflow.question_policy || modeDefaults.question_policy || 'none'),
|
|
111
|
-
output_contract: String(workflow.output_contract || modeDefaults.output_contract || 'routing'),
|
|
112
|
-
tool_profile: String(workflow.tool_profile || modeDefaults.tool_profile || 'read_heavy'),
|
|
113
|
-
confidence_policy: String(workflow.confidence_policy || modeDefaults.confidence_policy || 'explicit'),
|
|
114
|
-
required_artifacts: requiredArtifacts,
|
|
115
|
-
optional_artifacts: optionalArtifacts,
|
|
116
|
-
context_tiers: workflow.context_tiers || buildContextTiers(requiredArtifacts, optionalArtifacts),
|
|
117
|
-
freshness_policy: workflow.freshness_policy || modeDefaults.freshness_policy || {},
|
|
118
|
-
fallback_policy: String(workflow.fallback_policy || modeDefaults.fallback_policy || 'read_direct_with_warning'),
|
|
119
|
-
blocking_conditions: uniqueStrings(workflow.blocking_conditions || modeDefaults.blocking_conditions || []),
|
|
120
|
-
output_sections: uniqueStrings(workflow.output_sections || modeDefaults.output_sections || []),
|
|
121
|
-
extraction_intent: String(workflow.extraction_intent || 'status_read'),
|
|
122
|
-
runtime_default_commands: Array.isArray(workflow.runtime_default_commands) ? workflow.runtime_default_commands.slice() : [],
|
|
123
|
-
runtime_primary_artifacts: Array.isArray(workflow.runtime_primary_artifacts) ? workflow.runtime_primary_artifacts.slice() : [],
|
|
124
|
-
runtime_fallback_note: workflow.runtime_fallback_note ? String(workflow.runtime_fallback_note) : '',
|
|
125
|
-
auditor_artifacts: Array.isArray(workflow.auditor_artifacts) ? workflow.auditor_artifacts.slice() : [],
|
|
126
|
-
auditor_excluded: Array.isArray(workflow.auditor_excluded) ? workflow.auditor_excluded.slice() : [],
|
|
127
|
-
reference: MODE_REFERENCES[mode] || null,
|
|
128
|
-
guidance: Array.isArray(MODE_GUIDANCE[mode]) ? MODE_GUIDANCE[mode].slice() : [],
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function getAllWorkflowContracts() {
|
|
133
|
-
return Object.keys(CONTRACTS_REGISTRY.workflows || {})
|
|
134
|
-
.sort()
|
|
135
|
-
.map((slug) => getWorkflowContract(slug))
|
|
136
|
-
.filter(Boolean);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function validateWorkflowContractsRegistry(registry = CONTRACTS_REGISTRY) {
|
|
140
|
-
const issues = [];
|
|
141
|
-
if (!registry || typeof registry !== 'object' || Array.isArray(registry)) {
|
|
142
|
-
return ['workflow-runtime-contracts.json deve ser um objeto'];
|
|
143
|
-
}
|
|
144
|
-
if (!registry.contract_version || typeof registry.contract_version !== 'string') {
|
|
145
|
-
issues.push('workflow-runtime-contracts.json: contract_version ausente ou inválido');
|
|
146
|
-
}
|
|
147
|
-
if (!registry.workflows || typeof registry.workflows !== 'object' || Array.isArray(registry.workflows)) {
|
|
148
|
-
issues.push('workflow-runtime-contracts.json: workflows ausente ou inválido');
|
|
149
|
-
return issues;
|
|
150
|
-
}
|
|
151
|
-
for (const slug of Object.keys(registry.workflows)) {
|
|
152
|
-
const contract = getWorkflowContract(slug);
|
|
153
|
-
if (!contract) {
|
|
154
|
-
issues.push(`workflow-runtime-contracts.json: workflow "${slug}" inválido`);
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
for (const field of REQUIRED_CONTRACT_FIELDS) {
|
|
158
|
-
const value = contract[field];
|
|
159
|
-
if (value == null) {
|
|
160
|
-
issues.push(`workflow-runtime-contracts.json: ${slug} sem "${field}"`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
for (const tier of ['minimal', 'standard', 'full']) {
|
|
164
|
-
if (!Array.isArray(contract.context_tiers[tier])) {
|
|
165
|
-
issues.push(`workflow-runtime-contracts.json: ${slug} context_tiers.${tier} deve ser array`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return issues;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function computeSemanticsHash(slug) {
|
|
173
|
-
const contract = getWorkflowContract(slug);
|
|
174
|
-
if (!contract) return null;
|
|
175
|
-
return crypto.createHash('sha256').update(stableJson(contract)).digest('hex').slice(0, 16);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function slugFromPromptFilename(name) {
|
|
179
|
-
return name.replace(/^oxe-/, '').replace(/\.prompt\.md$/i, '');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function slugFromCommandFilename(name) {
|
|
183
|
-
return name.replace(/^oxe-/i, '').replace(/\.md$/i, '');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function getRuntimeMetadataForSlug(slug, options = {}) {
|
|
187
|
-
const tier = String(options.tier || 'standard');
|
|
188
|
-
const contract = getWorkflowContract(slug);
|
|
189
|
-
if (!contract) {
|
|
190
|
-
const fallbackHash = crypto.createHash('sha256').update(`fallback:${slug}`).digest('hex').slice(0, 16);
|
|
191
|
-
return {
|
|
192
|
-
oxe_workflow_slug: slug,
|
|
193
|
-
...(MODE_DEFAULTS.status || {}),
|
|
194
|
-
oxe_context_tier: tier,
|
|
195
|
-
oxe_contract_version: CONTRACT_VERSION,
|
|
196
|
-
oxe_semantics_hash: fallbackHash,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
oxe_workflow_slug: slug,
|
|
201
|
-
oxe_reasoning_mode: contract.reasoning_mode,
|
|
202
|
-
oxe_question_policy: contract.question_policy,
|
|
203
|
-
oxe_output_contract: contract.output_contract,
|
|
204
|
-
oxe_tool_profile: contract.tool_profile,
|
|
205
|
-
oxe_confidence_policy: contract.confidence_policy,
|
|
206
|
-
oxe_context_tier: tier,
|
|
207
|
-
oxe_contract_version: CONTRACT_VERSION,
|
|
208
|
-
oxe_semantics_hash: computeSemanticsHash(slug),
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function pickRuntimeMetadata(frontmatter) {
|
|
213
|
-
const out = {};
|
|
214
|
-
for (const key of RUNTIME_METADATA_KEYS) {
|
|
215
|
-
if (frontmatter && typeof frontmatter[key] === 'string' && frontmatter[key].trim()) {
|
|
216
|
-
out[key] = frontmatter[key].trim();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return out;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function renderRuntimeMetadataLines(meta) {
|
|
223
|
-
return RUNTIME_METADATA_KEYS.map((key) => `${key}: ${meta[key] || ''}`);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function humanizeValue(value) {
|
|
227
|
-
const key = String(value || '');
|
|
228
|
-
const labels = {
|
|
229
|
-
discovery: 'descoberta',
|
|
230
|
-
planning: 'planejamento',
|
|
231
|
-
execution: 'execução',
|
|
232
|
-
review: 'revisão',
|
|
233
|
-
status: 'estado / roteamento',
|
|
234
|
-
explore_first: 'explorar primeiro',
|
|
235
|
-
ask_high_impact_only: 'perguntar só alto impacto',
|
|
236
|
-
none: 'nenhuma',
|
|
237
|
-
situational: 'situacional',
|
|
238
|
-
plan: 'plano',
|
|
239
|
-
findings: 'achados',
|
|
240
|
-
routing: 'roteamento',
|
|
241
|
-
read_heavy: 'leitura intensa',
|
|
242
|
-
write_bounded: 'mutação limitada',
|
|
243
|
-
review_heavy: 'revisão intensa',
|
|
244
|
-
mixed: 'misto',
|
|
245
|
-
explicit: 'explícita',
|
|
246
|
-
rubric: 'rubrica',
|
|
247
|
-
optional: 'opcional',
|
|
248
|
-
minimal: 'mínimo',
|
|
249
|
-
standard: 'padrão',
|
|
250
|
-
full: 'completo',
|
|
251
|
-
};
|
|
252
|
-
return labels[key] || key.replace(/_/g, ' ');
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function buildContextPackPaths(slug) {
|
|
256
|
-
return {
|
|
257
|
-
markdown: `.oxe/context/packs/${slug}.md`,
|
|
258
|
-
json: `.oxe/context/packs/${slug}.json`,
|
|
259
|
-
inspectCommand: `oxe-cc context inspect --workflow ${slug} --json`,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function buildWorkflowResolutionBlock(slug) {
|
|
264
|
-
return [
|
|
265
|
-
'<!-- oxe-workflow-resolution:start -->',
|
|
266
|
-
'',
|
|
267
|
-
`**Resolução do workflow canónico:** a partir do CWD atual, subir diretórios até encontrar .oxe/workflows/${slug}.md ou oxe/workflows/${slug}.md. Ler e aplicar integralmente o primeiro ficheiro encontrado. Não assumir que o CWD já é a raiz do repositório. Se nenhum existir, reportar os paths tentados e parar.`,
|
|
268
|
-
'',
|
|
269
|
-
'<!-- oxe-workflow-resolution:end -->',
|
|
270
|
-
].join('\n');
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function buildReasoningContractBlock(meta, options = {}) {
|
|
274
|
-
const includeReference = options.includeReference !== false;
|
|
275
|
-
const slug = String(meta.oxe_workflow_slug || options.slug || '');
|
|
276
|
-
const contract = getWorkflowContract(slug) || {};
|
|
277
|
-
const mode = meta.oxe_reasoning_mode || contract.reasoning_mode || 'status';
|
|
278
|
-
const guidance = contract.guidance || MODE_GUIDANCE[mode] || [];
|
|
279
|
-
const outputSections = contract.output_sections || [];
|
|
280
|
-
const blocking = contract.blocking_conditions || [];
|
|
281
|
-
const contextPack = buildContextPackPaths(slug);
|
|
282
|
-
const lines = [
|
|
283
|
-
'<!-- oxe-reasoning-contract:start -->',
|
|
284
|
-
'',
|
|
285
|
-
'**Contrato de raciocínio OXE deste comando**',
|
|
286
|
-
`- **Workflow:** ${slug || '—'}`,
|
|
287
|
-
`- **Modo:** ${humanizeValue(meta.oxe_reasoning_mode)}`,
|
|
288
|
-
`- **Perguntas:** ${humanizeValue(meta.oxe_question_policy)}`,
|
|
289
|
-
`- **Saída esperada:** ${humanizeValue(meta.oxe_output_contract)}`,
|
|
290
|
-
`- **Perfil de ferramentas:** ${humanizeValue(meta.oxe_tool_profile)}`,
|
|
291
|
-
`- **Política de confiança:** ${humanizeValue(meta.oxe_confidence_policy)}`,
|
|
292
|
-
`- **Tier de contexto padrão:** ${humanizeValue(meta.oxe_context_tier || 'standard')}`,
|
|
293
|
-
`- **Versão do contrato:** ${meta.oxe_contract_version || CONTRACT_VERSION}`,
|
|
294
|
-
`- **Checksum semântico:** \`${meta.oxe_semantics_hash || computeSemanticsHash(slug) || '—'}\``,
|
|
295
|
-
`- **Entrada de contexto prioritária:** \`${contextPack.markdown}\` e \`${contextPack.json}\``,
|
|
296
|
-
`- **Regra pack-first:** ler o context pack primeiro; se estiver stale, incompleto ou ausente, cair para leitura direta com fallback explícito.`,
|
|
297
|
-
`- **Inspeção estruturada:** \`${contextPack.inspectCommand}\``,
|
|
298
|
-
...guidance.map((line) => `- ${line}`),
|
|
299
|
-
];
|
|
300
|
-
if (outputSections.length) {
|
|
301
|
-
lines.push(`- **Seções esperadas:** ${outputSections.join(' · ')}`);
|
|
302
|
-
}
|
|
303
|
-
if (blocking.length) {
|
|
304
|
-
lines.push(`- **Bloqueios formais:** ${blocking.join(' · ')}`);
|
|
305
|
-
}
|
|
306
|
-
if (Array.isArray(contract.runtime_default_commands) && contract.runtime_default_commands.length) {
|
|
307
|
-
lines.push(`- **Caminho runtime padrão:** ${contract.runtime_default_commands.map((cmd) => `\`${cmd}\``).join(' → ')}`);
|
|
308
|
-
}
|
|
309
|
-
if (Array.isArray(contract.runtime_primary_artifacts) && contract.runtime_primary_artifacts.length) {
|
|
310
|
-
lines.push(`- **Artefatos canónicos primários:** ${contract.runtime_primary_artifacts.map((artifact) => `\`${artifact}\``).join(' · ')}`);
|
|
311
|
-
}
|
|
312
|
-
if (contract.runtime_fallback_note) {
|
|
313
|
-
lines.push(`- **Fallback runtime:** ${contract.runtime_fallback_note}`);
|
|
314
|
-
}
|
|
315
|
-
if (includeReference && MODE_REFERENCES[mode]) {
|
|
316
|
-
lines.push(`- **Referência canónica:** \`${MODE_REFERENCES[mode]}\``);
|
|
317
|
-
}
|
|
318
|
-
lines.push('', '<!-- oxe-reasoning-contract:end -->');
|
|
319
|
-
return lines.join('\n');
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function splitFrontmatter(raw) {
|
|
323
|
-
const normalized = String(raw || '').replace(/^\uFEFF/, '').replace(/\r\n/g, '\n');
|
|
324
|
-
if (!normalized.startsWith('---\n')) {
|
|
325
|
-
return { frontmatter: '', body: normalized.trimStart() };
|
|
326
|
-
}
|
|
327
|
-
const end = normalized.indexOf('\n---\n', 4);
|
|
328
|
-
if (end === -1) {
|
|
329
|
-
return { frontmatter: '', body: normalized.trimStart() };
|
|
330
|
-
}
|
|
331
|
-
return {
|
|
332
|
-
frontmatter: normalized.slice(4, end),
|
|
333
|
-
body: normalized.slice(end + 5).trimStart(),
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function parseFrontmatterMap(raw) {
|
|
338
|
-
const { frontmatter } = splitFrontmatter(raw);
|
|
339
|
-
const out = {};
|
|
340
|
-
if (!frontmatter) return out;
|
|
341
|
-
for (const line of frontmatter.split('\n')) {
|
|
342
|
-
const match = line.match(/^([A-Za-z0-9_-]+):\s*(.+)$/);
|
|
343
|
-
if (match) out[match[1]] = match[2].trim().replace(/^["']|["']$/g, '');
|
|
344
|
-
}
|
|
345
|
-
return out;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
function auditWrapperText(slug, raw) {
|
|
349
|
-
const frontmatter = parseFrontmatterMap(raw);
|
|
350
|
-
const expected = getRuntimeMetadataForSlug(slug);
|
|
351
|
-
const expectedPack = buildContextPackPaths(slug);
|
|
352
|
-
const workflowResolution = buildWorkflowResolutionBlock(slug);
|
|
353
|
-
const issues = [];
|
|
354
|
-
for (const key of RUNTIME_METADATA_KEYS) {
|
|
355
|
-
if ((frontmatter[key] || '') !== (expected[key] || '')) {
|
|
356
|
-
issues.push({ key, expected: expected[key] || '', actual: frontmatter[key] || '' });
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
if (!String(raw || '').includes('<!-- oxe-reasoning-contract:start -->')) {
|
|
360
|
-
issues.push({ key: 'oxe-reasoning-contract', expected: 'present', actual: 'missing' });
|
|
361
|
-
}
|
|
362
|
-
if (!String(raw || '').includes(`Checksum semântico:** \`${expected.oxe_semantics_hash}\``)) {
|
|
363
|
-
issues.push({ key: 'oxe_semantics_hash_block', expected: expected.oxe_semantics_hash, actual: 'mismatch' });
|
|
364
|
-
}
|
|
365
|
-
if (!String(raw || '').includes(expectedPack.markdown) || !String(raw || '').includes(expectedPack.json)) {
|
|
366
|
-
issues.push({ key: 'oxe_context_pack_entry', expected: `${expectedPack.markdown} + ${expectedPack.json}`, actual: 'missing' });
|
|
367
|
-
}
|
|
368
|
-
if (!String(raw || '').includes('Regra pack-first')) {
|
|
369
|
-
issues.push({ key: 'oxe_pack_first_rule', expected: 'present', actual: 'missing' });
|
|
370
|
-
}
|
|
371
|
-
if (!String(raw || '').includes('<!-- oxe-workflow-resolution:start -->')) {
|
|
372
|
-
issues.push({ key: 'oxe_workflow_resolution_block', expected: 'present', actual: 'missing' });
|
|
373
|
-
} else {
|
|
374
|
-
if (!String(raw || '').includes(`.oxe/workflows/${slug}.md`) || !String(raw || '').includes(`oxe/workflows/${slug}.md`)) {
|
|
375
|
-
issues.push({
|
|
376
|
-
key: 'oxe_workflow_resolution_paths',
|
|
377
|
-
expected: workflowResolution,
|
|
378
|
-
actual: 'missing_path_reference',
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
if (!/subir diretórios até encontrar/i.test(String(raw || ''))) {
|
|
382
|
-
issues.push({
|
|
383
|
-
key: 'oxe_workflow_resolution_walkup',
|
|
384
|
-
expected: 'subir diretórios até encontrar',
|
|
385
|
-
actual: 'missing',
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
if (/\*\*Workflow can[óôo]nic[oa]:\*\*/i.test(String(raw || ''))) {
|
|
390
|
-
issues.push({
|
|
391
|
-
key: 'legacy_workflow_anchor',
|
|
392
|
-
expected: 'absent',
|
|
393
|
-
actual: 'present',
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
if (/raiz do projeto atual \(CWD\)|na raiz do repositório em contexto|na raiz do repositório em que estás a trabalhar/i.test(String(raw || ''))) {
|
|
397
|
-
issues.push({
|
|
398
|
-
key: 'legacy_fixed_root_instruction',
|
|
399
|
-
expected: 'absent',
|
|
400
|
-
actual: 'present',
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
return {
|
|
404
|
-
slug,
|
|
405
|
-
frontmatter,
|
|
406
|
-
expected,
|
|
407
|
-
issues,
|
|
408
|
-
ok: issues.length === 0,
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
function auditRuntimeTargets(projectRoot) {
|
|
413
|
-
const targets = [
|
|
414
|
-
{
|
|
415
|
-
name: 'copilot-prompts',
|
|
416
|
-
dir: path.join(projectRoot, '.github', 'prompts'),
|
|
417
|
-
filter: (name) => (name === 'oxe.prompt.md' || name.startsWith('oxe-')) && name.endsWith('.prompt.md'),
|
|
418
|
-
slug: slugFromPromptFilename,
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
name: 'commands',
|
|
422
|
-
dir: path.join(projectRoot, 'commands', 'oxe'),
|
|
423
|
-
filter: (name) => name.endsWith('.md'),
|
|
424
|
-
slug: slugFromCommandFilename,
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
name: 'cursor',
|
|
428
|
-
dir: path.join(projectRoot, '.cursor', 'commands'),
|
|
429
|
-
filter: (name) => (name === 'oxe.md' || name.startsWith('oxe-')) && name.endsWith('.md'),
|
|
430
|
-
slug: slugFromCommandFilename,
|
|
431
|
-
},
|
|
432
|
-
];
|
|
433
|
-
const result = {
|
|
434
|
-
ok: true,
|
|
435
|
-
contractVersion: CONTRACT_VERSION,
|
|
436
|
-
registryPath: CONTRACTS_PATH,
|
|
437
|
-
registryIssues: validateWorkflowContractsRegistry(),
|
|
438
|
-
warnings: [],
|
|
439
|
-
mismatches: [],
|
|
440
|
-
targets: {},
|
|
441
|
-
};
|
|
442
|
-
for (const target of targets) {
|
|
443
|
-
const info = { path: target.dir, files: [], checked: 0, missing: false };
|
|
444
|
-
if (!fs.existsSync(target.dir)) {
|
|
445
|
-
info.missing = true;
|
|
446
|
-
result.targets[target.name] = info;
|
|
447
|
-
continue;
|
|
448
|
-
}
|
|
449
|
-
let names;
|
|
450
|
-
try {
|
|
451
|
-
names = fs.readdirSync(target.dir);
|
|
452
|
-
} catch (err) {
|
|
453
|
-
info.missing = true;
|
|
454
|
-
result.warnings.push(`${target.name}: falha ao listar diretório — ${err instanceof Error ? err.message : String(err)}`);
|
|
455
|
-
result.targets[target.name] = info;
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
for (const name of names) {
|
|
459
|
-
if (!target.filter(name)) continue;
|
|
460
|
-
const filePath = path.join(target.dir, name);
|
|
461
|
-
let raw;
|
|
462
|
-
try {
|
|
463
|
-
raw = fs.readFileSync(filePath, 'utf8');
|
|
464
|
-
} catch (err) {
|
|
465
|
-
result.warnings.push(`${target.name}/${name}: falha ao ler arquivo — ${err instanceof Error ? err.message : String(err)}`);
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
const audit = auditWrapperText(target.slug(name), raw);
|
|
469
|
-
info.checked += 1;
|
|
470
|
-
info.files.push({ file: filePath, slug: audit.slug, ok: audit.ok, issues: audit.issues });
|
|
471
|
-
if (!audit.ok) {
|
|
472
|
-
result.ok = false;
|
|
473
|
-
result.mismatches.push({ target: target.name, file: filePath, slug: audit.slug, issues: audit.issues });
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
result.targets[target.name] = info;
|
|
477
|
-
}
|
|
478
|
-
if (result.registryIssues.length) {
|
|
479
|
-
result.ok = false;
|
|
480
|
-
result.warnings.push(...result.registryIssues);
|
|
481
|
-
}
|
|
482
|
-
if (result.mismatches.length) {
|
|
483
|
-
result.warnings.push(`${result.mismatches.length} wrapper(s) com drift semântico detectado`);
|
|
484
|
-
}
|
|
485
|
-
return result;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
module.exports = {
|
|
489
|
-
CONTRACT_VERSION,
|
|
490
|
-
CONTRACTS_PATH,
|
|
491
|
-
CONTRACTS_REGISTRY,
|
|
492
|
-
MODE_DEFAULTS,
|
|
493
|
-
MODE_GUIDANCE,
|
|
494
|
-
MODE_REFERENCES,
|
|
495
|
-
REQUIRED_CONTRACT_FIELDS,
|
|
496
|
-
RUNTIME_METADATA_KEYS,
|
|
497
|
-
auditRuntimeTargets,
|
|
498
|
-
auditWrapperText,
|
|
499
|
-
buildContextPackPaths,
|
|
500
|
-
buildContextTiers,
|
|
501
|
-
buildReasoningContractBlock,
|
|
502
|
-
buildWorkflowResolutionBlock,
|
|
503
|
-
computeSemanticsHash,
|
|
504
|
-
getAllWorkflowContracts,
|
|
505
|
-
getRuntimeMetadataForSlug,
|
|
506
|
-
getWorkflowContract,
|
|
507
|
-
parseFrontmatterMap,
|
|
508
|
-
pickRuntimeMetadata,
|
|
509
|
-
renderRuntimeMetadataLines,
|
|
510
|
-
slugFromCommandFilename,
|
|
511
|
-
slugFromPromptFilename,
|
|
512
|
-
splitFrontmatter,
|
|
513
|
-
validateWorkflowContractsRegistry,
|
|
514
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const crypto = require('crypto');
|
|
6
|
+
|
|
7
|
+
const CONTRACTS_PATH = path.join(
|
|
8
|
+
__dirname,
|
|
9
|
+
'..',
|
|
10
|
+
'..',
|
|
11
|
+
'oxe',
|
|
12
|
+
'workflows',
|
|
13
|
+
'references',
|
|
14
|
+
'workflow-runtime-contracts.json'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const RUNTIME_METADATA_KEYS = [
|
|
18
|
+
'oxe_workflow_slug',
|
|
19
|
+
'oxe_reasoning_mode',
|
|
20
|
+
'oxe_question_policy',
|
|
21
|
+
'oxe_output_contract',
|
|
22
|
+
'oxe_tool_profile',
|
|
23
|
+
'oxe_confidence_policy',
|
|
24
|
+
'oxe_context_tier',
|
|
25
|
+
'oxe_contract_version',
|
|
26
|
+
'oxe_semantics_hash',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const REQUIRED_CONTRACT_FIELDS = [
|
|
30
|
+
'reasoning_mode',
|
|
31
|
+
'question_policy',
|
|
32
|
+
'output_contract',
|
|
33
|
+
'tool_profile',
|
|
34
|
+
'confidence_policy',
|
|
35
|
+
'required_artifacts',
|
|
36
|
+
'optional_artifacts',
|
|
37
|
+
'context_tiers',
|
|
38
|
+
'freshness_policy',
|
|
39
|
+
'fallback_policy',
|
|
40
|
+
'blocking_conditions',
|
|
41
|
+
'output_sections',
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
function readContractsRegistry() {
|
|
45
|
+
try {
|
|
46
|
+
const raw = fs.readFileSync(CONTRACTS_PATH, 'utf8');
|
|
47
|
+
const parsed = JSON.parse(raw);
|
|
48
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
49
|
+
} catch {
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const CONTRACTS_REGISTRY = readContractsRegistry();
|
|
55
|
+
if (!CONTRACTS_REGISTRY.contract_version) {
|
|
56
|
+
process.stderr.write('[oxe] WARN: workflow-runtime-contracts.json ausente ou inválido — usando defaults.\n');
|
|
57
|
+
}
|
|
58
|
+
const CONTRACT_VERSION = String(CONTRACTS_REGISTRY.contract_version || '0.0.0');
|
|
59
|
+
const MODE_REFERENCES = CONTRACTS_REGISTRY.mode_references || {};
|
|
60
|
+
const MODE_GUIDANCE = CONTRACTS_REGISTRY.mode_guidance || {};
|
|
61
|
+
const MODE_DEFAULT_SPECS = CONTRACTS_REGISTRY.mode_defaults || {};
|
|
62
|
+
const MODE_DEFAULTS = Object.fromEntries(
|
|
63
|
+
Object.entries(MODE_DEFAULT_SPECS).map(([mode, spec]) => [
|
|
64
|
+
mode,
|
|
65
|
+
{
|
|
66
|
+
oxe_reasoning_mode: mode,
|
|
67
|
+
oxe_question_policy: spec.question_policy,
|
|
68
|
+
oxe_output_contract: spec.output_contract,
|
|
69
|
+
oxe_tool_profile: spec.tool_profile,
|
|
70
|
+
oxe_confidence_policy: spec.confidence_policy,
|
|
71
|
+
},
|
|
72
|
+
])
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
function stableJson(value) {
|
|
76
|
+
if (Array.isArray(value)) return `[${value.map((item) => stableJson(item)).join(',')}]`;
|
|
77
|
+
if (value && typeof value === 'object') {
|
|
78
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(',')}}`;
|
|
79
|
+
}
|
|
80
|
+
return JSON.stringify(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function uniqueStrings(items) {
|
|
84
|
+
return Array.from(new Set((items || []).map((item) => String(item || '').trim()).filter(Boolean)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function buildContextTiers(requiredArtifacts, optionalArtifacts) {
|
|
88
|
+
const required = uniqueStrings(requiredArtifacts);
|
|
89
|
+
const optional = uniqueStrings(optionalArtifacts);
|
|
90
|
+
const minimalTail = optional.filter((item) => /(phase_summary|project_summary|session_summary)$/.test(item)).slice(0, 2);
|
|
91
|
+
const standardTail = optional.filter((item) => !minimalTail.includes(item)).slice(0, 4);
|
|
92
|
+
return {
|
|
93
|
+
minimal: uniqueStrings([...required, ...minimalTail]),
|
|
94
|
+
standard: uniqueStrings([...required, ...minimalTail, ...standardTail]),
|
|
95
|
+
full: uniqueStrings([...required, ...optional]),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getWorkflowContract(slug) {
|
|
100
|
+
const workflow = (CONTRACTS_REGISTRY.workflows || {})[slug];
|
|
101
|
+
if (!workflow) return null;
|
|
102
|
+
const mode = String(workflow.reasoning_mode || 'status');
|
|
103
|
+
const modeDefaults = MODE_DEFAULT_SPECS[mode] || MODE_DEFAULT_SPECS.status || {};
|
|
104
|
+
const requiredArtifacts = uniqueStrings(workflow.required_artifacts);
|
|
105
|
+
const optionalArtifacts = uniqueStrings(workflow.optional_artifacts);
|
|
106
|
+
return {
|
|
107
|
+
workflow_slug: slug,
|
|
108
|
+
contract_version: CONTRACT_VERSION,
|
|
109
|
+
reasoning_mode: mode,
|
|
110
|
+
question_policy: String(workflow.question_policy || modeDefaults.question_policy || 'none'),
|
|
111
|
+
output_contract: String(workflow.output_contract || modeDefaults.output_contract || 'routing'),
|
|
112
|
+
tool_profile: String(workflow.tool_profile || modeDefaults.tool_profile || 'read_heavy'),
|
|
113
|
+
confidence_policy: String(workflow.confidence_policy || modeDefaults.confidence_policy || 'explicit'),
|
|
114
|
+
required_artifacts: requiredArtifacts,
|
|
115
|
+
optional_artifacts: optionalArtifacts,
|
|
116
|
+
context_tiers: workflow.context_tiers || buildContextTiers(requiredArtifacts, optionalArtifacts),
|
|
117
|
+
freshness_policy: workflow.freshness_policy || modeDefaults.freshness_policy || {},
|
|
118
|
+
fallback_policy: String(workflow.fallback_policy || modeDefaults.fallback_policy || 'read_direct_with_warning'),
|
|
119
|
+
blocking_conditions: uniqueStrings(workflow.blocking_conditions || modeDefaults.blocking_conditions || []),
|
|
120
|
+
output_sections: uniqueStrings(workflow.output_sections || modeDefaults.output_sections || []),
|
|
121
|
+
extraction_intent: String(workflow.extraction_intent || 'status_read'),
|
|
122
|
+
runtime_default_commands: Array.isArray(workflow.runtime_default_commands) ? workflow.runtime_default_commands.slice() : [],
|
|
123
|
+
runtime_primary_artifacts: Array.isArray(workflow.runtime_primary_artifacts) ? workflow.runtime_primary_artifacts.slice() : [],
|
|
124
|
+
runtime_fallback_note: workflow.runtime_fallback_note ? String(workflow.runtime_fallback_note) : '',
|
|
125
|
+
auditor_artifacts: Array.isArray(workflow.auditor_artifacts) ? workflow.auditor_artifacts.slice() : [],
|
|
126
|
+
auditor_excluded: Array.isArray(workflow.auditor_excluded) ? workflow.auditor_excluded.slice() : [],
|
|
127
|
+
reference: MODE_REFERENCES[mode] || null,
|
|
128
|
+
guidance: Array.isArray(MODE_GUIDANCE[mode]) ? MODE_GUIDANCE[mode].slice() : [],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getAllWorkflowContracts() {
|
|
133
|
+
return Object.keys(CONTRACTS_REGISTRY.workflows || {})
|
|
134
|
+
.sort()
|
|
135
|
+
.map((slug) => getWorkflowContract(slug))
|
|
136
|
+
.filter(Boolean);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function validateWorkflowContractsRegistry(registry = CONTRACTS_REGISTRY) {
|
|
140
|
+
const issues = [];
|
|
141
|
+
if (!registry || typeof registry !== 'object' || Array.isArray(registry)) {
|
|
142
|
+
return ['workflow-runtime-contracts.json deve ser um objeto'];
|
|
143
|
+
}
|
|
144
|
+
if (!registry.contract_version || typeof registry.contract_version !== 'string') {
|
|
145
|
+
issues.push('workflow-runtime-contracts.json: contract_version ausente ou inválido');
|
|
146
|
+
}
|
|
147
|
+
if (!registry.workflows || typeof registry.workflows !== 'object' || Array.isArray(registry.workflows)) {
|
|
148
|
+
issues.push('workflow-runtime-contracts.json: workflows ausente ou inválido');
|
|
149
|
+
return issues;
|
|
150
|
+
}
|
|
151
|
+
for (const slug of Object.keys(registry.workflows)) {
|
|
152
|
+
const contract = getWorkflowContract(slug);
|
|
153
|
+
if (!contract) {
|
|
154
|
+
issues.push(`workflow-runtime-contracts.json: workflow "${slug}" inválido`);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
for (const field of REQUIRED_CONTRACT_FIELDS) {
|
|
158
|
+
const value = contract[field];
|
|
159
|
+
if (value == null) {
|
|
160
|
+
issues.push(`workflow-runtime-contracts.json: ${slug} sem "${field}"`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (const tier of ['minimal', 'standard', 'full']) {
|
|
164
|
+
if (!Array.isArray(contract.context_tiers[tier])) {
|
|
165
|
+
issues.push(`workflow-runtime-contracts.json: ${slug} context_tiers.${tier} deve ser array`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return issues;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function computeSemanticsHash(slug) {
|
|
173
|
+
const contract = getWorkflowContract(slug);
|
|
174
|
+
if (!contract) return null;
|
|
175
|
+
return crypto.createHash('sha256').update(stableJson(contract)).digest('hex').slice(0, 16);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function slugFromPromptFilename(name) {
|
|
179
|
+
return name.replace(/^oxe-/, '').replace(/\.prompt\.md$/i, '');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function slugFromCommandFilename(name) {
|
|
183
|
+
return name.replace(/^oxe-/i, '').replace(/\.md$/i, '');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function getRuntimeMetadataForSlug(slug, options = {}) {
|
|
187
|
+
const tier = String(options.tier || 'standard');
|
|
188
|
+
const contract = getWorkflowContract(slug);
|
|
189
|
+
if (!contract) {
|
|
190
|
+
const fallbackHash = crypto.createHash('sha256').update(`fallback:${slug}`).digest('hex').slice(0, 16);
|
|
191
|
+
return {
|
|
192
|
+
oxe_workflow_slug: slug,
|
|
193
|
+
...(MODE_DEFAULTS.status || {}),
|
|
194
|
+
oxe_context_tier: tier,
|
|
195
|
+
oxe_contract_version: CONTRACT_VERSION,
|
|
196
|
+
oxe_semantics_hash: fallbackHash,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
oxe_workflow_slug: slug,
|
|
201
|
+
oxe_reasoning_mode: contract.reasoning_mode,
|
|
202
|
+
oxe_question_policy: contract.question_policy,
|
|
203
|
+
oxe_output_contract: contract.output_contract,
|
|
204
|
+
oxe_tool_profile: contract.tool_profile,
|
|
205
|
+
oxe_confidence_policy: contract.confidence_policy,
|
|
206
|
+
oxe_context_tier: tier,
|
|
207
|
+
oxe_contract_version: CONTRACT_VERSION,
|
|
208
|
+
oxe_semantics_hash: computeSemanticsHash(slug),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function pickRuntimeMetadata(frontmatter) {
|
|
213
|
+
const out = {};
|
|
214
|
+
for (const key of RUNTIME_METADATA_KEYS) {
|
|
215
|
+
if (frontmatter && typeof frontmatter[key] === 'string' && frontmatter[key].trim()) {
|
|
216
|
+
out[key] = frontmatter[key].trim();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function renderRuntimeMetadataLines(meta) {
|
|
223
|
+
return RUNTIME_METADATA_KEYS.map((key) => `${key}: ${meta[key] || ''}`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function humanizeValue(value) {
|
|
227
|
+
const key = String(value || '');
|
|
228
|
+
const labels = {
|
|
229
|
+
discovery: 'descoberta',
|
|
230
|
+
planning: 'planejamento',
|
|
231
|
+
execution: 'execução',
|
|
232
|
+
review: 'revisão',
|
|
233
|
+
status: 'estado / roteamento',
|
|
234
|
+
explore_first: 'explorar primeiro',
|
|
235
|
+
ask_high_impact_only: 'perguntar só alto impacto',
|
|
236
|
+
none: 'nenhuma',
|
|
237
|
+
situational: 'situacional',
|
|
238
|
+
plan: 'plano',
|
|
239
|
+
findings: 'achados',
|
|
240
|
+
routing: 'roteamento',
|
|
241
|
+
read_heavy: 'leitura intensa',
|
|
242
|
+
write_bounded: 'mutação limitada',
|
|
243
|
+
review_heavy: 'revisão intensa',
|
|
244
|
+
mixed: 'misto',
|
|
245
|
+
explicit: 'explícita',
|
|
246
|
+
rubric: 'rubrica',
|
|
247
|
+
optional: 'opcional',
|
|
248
|
+
minimal: 'mínimo',
|
|
249
|
+
standard: 'padrão',
|
|
250
|
+
full: 'completo',
|
|
251
|
+
};
|
|
252
|
+
return labels[key] || key.replace(/_/g, ' ');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function buildContextPackPaths(slug) {
|
|
256
|
+
return {
|
|
257
|
+
markdown: `.oxe/context/packs/${slug}.md`,
|
|
258
|
+
json: `.oxe/context/packs/${slug}.json`,
|
|
259
|
+
inspectCommand: `oxe-cc context inspect --workflow ${slug} --json`,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function buildWorkflowResolutionBlock(slug) {
|
|
264
|
+
return [
|
|
265
|
+
'<!-- oxe-workflow-resolution:start -->',
|
|
266
|
+
'',
|
|
267
|
+
`**Resolução do workflow canónico:** a partir do CWD atual, subir diretórios até encontrar .oxe/workflows/${slug}.md ou oxe/workflows/${slug}.md. Ler e aplicar integralmente o primeiro ficheiro encontrado. Não assumir que o CWD já é a raiz do repositório. Se nenhum existir, reportar os paths tentados e parar.`,
|
|
268
|
+
'',
|
|
269
|
+
'<!-- oxe-workflow-resolution:end -->',
|
|
270
|
+
].join('\n');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function buildReasoningContractBlock(meta, options = {}) {
|
|
274
|
+
const includeReference = options.includeReference !== false;
|
|
275
|
+
const slug = String(meta.oxe_workflow_slug || options.slug || '');
|
|
276
|
+
const contract = getWorkflowContract(slug) || {};
|
|
277
|
+
const mode = meta.oxe_reasoning_mode || contract.reasoning_mode || 'status';
|
|
278
|
+
const guidance = contract.guidance || MODE_GUIDANCE[mode] || [];
|
|
279
|
+
const outputSections = contract.output_sections || [];
|
|
280
|
+
const blocking = contract.blocking_conditions || [];
|
|
281
|
+
const contextPack = buildContextPackPaths(slug);
|
|
282
|
+
const lines = [
|
|
283
|
+
'<!-- oxe-reasoning-contract:start -->',
|
|
284
|
+
'',
|
|
285
|
+
'**Contrato de raciocínio OXE deste comando**',
|
|
286
|
+
`- **Workflow:** ${slug || '—'}`,
|
|
287
|
+
`- **Modo:** ${humanizeValue(meta.oxe_reasoning_mode)}`,
|
|
288
|
+
`- **Perguntas:** ${humanizeValue(meta.oxe_question_policy)}`,
|
|
289
|
+
`- **Saída esperada:** ${humanizeValue(meta.oxe_output_contract)}`,
|
|
290
|
+
`- **Perfil de ferramentas:** ${humanizeValue(meta.oxe_tool_profile)}`,
|
|
291
|
+
`- **Política de confiança:** ${humanizeValue(meta.oxe_confidence_policy)}`,
|
|
292
|
+
`- **Tier de contexto padrão:** ${humanizeValue(meta.oxe_context_tier || 'standard')}`,
|
|
293
|
+
`- **Versão do contrato:** ${meta.oxe_contract_version || CONTRACT_VERSION}`,
|
|
294
|
+
`- **Checksum semântico:** \`${meta.oxe_semantics_hash || computeSemanticsHash(slug) || '—'}\``,
|
|
295
|
+
`- **Entrada de contexto prioritária:** \`${contextPack.markdown}\` e \`${contextPack.json}\``,
|
|
296
|
+
`- **Regra pack-first:** ler o context pack primeiro; se estiver stale, incompleto ou ausente, cair para leitura direta com fallback explícito.`,
|
|
297
|
+
`- **Inspeção estruturada:** \`${contextPack.inspectCommand}\``,
|
|
298
|
+
...guidance.map((line) => `- ${line}`),
|
|
299
|
+
];
|
|
300
|
+
if (outputSections.length) {
|
|
301
|
+
lines.push(`- **Seções esperadas:** ${outputSections.join(' · ')}`);
|
|
302
|
+
}
|
|
303
|
+
if (blocking.length) {
|
|
304
|
+
lines.push(`- **Bloqueios formais:** ${blocking.join(' · ')}`);
|
|
305
|
+
}
|
|
306
|
+
if (Array.isArray(contract.runtime_default_commands) && contract.runtime_default_commands.length) {
|
|
307
|
+
lines.push(`- **Caminho runtime padrão:** ${contract.runtime_default_commands.map((cmd) => `\`${cmd}\``).join(' → ')}`);
|
|
308
|
+
}
|
|
309
|
+
if (Array.isArray(contract.runtime_primary_artifacts) && contract.runtime_primary_artifacts.length) {
|
|
310
|
+
lines.push(`- **Artefatos canónicos primários:** ${contract.runtime_primary_artifacts.map((artifact) => `\`${artifact}\``).join(' · ')}`);
|
|
311
|
+
}
|
|
312
|
+
if (contract.runtime_fallback_note) {
|
|
313
|
+
lines.push(`- **Fallback runtime:** ${contract.runtime_fallback_note}`);
|
|
314
|
+
}
|
|
315
|
+
if (includeReference && MODE_REFERENCES[mode]) {
|
|
316
|
+
lines.push(`- **Referência canónica:** \`${MODE_REFERENCES[mode]}\``);
|
|
317
|
+
}
|
|
318
|
+
lines.push('', '<!-- oxe-reasoning-contract:end -->');
|
|
319
|
+
return lines.join('\n');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function splitFrontmatter(raw) {
|
|
323
|
+
const normalized = String(raw || '').replace(/^\uFEFF/, '').replace(/\r\n/g, '\n');
|
|
324
|
+
if (!normalized.startsWith('---\n')) {
|
|
325
|
+
return { frontmatter: '', body: normalized.trimStart() };
|
|
326
|
+
}
|
|
327
|
+
const end = normalized.indexOf('\n---\n', 4);
|
|
328
|
+
if (end === -1) {
|
|
329
|
+
return { frontmatter: '', body: normalized.trimStart() };
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
frontmatter: normalized.slice(4, end),
|
|
333
|
+
body: normalized.slice(end + 5).trimStart(),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function parseFrontmatterMap(raw) {
|
|
338
|
+
const { frontmatter } = splitFrontmatter(raw);
|
|
339
|
+
const out = {};
|
|
340
|
+
if (!frontmatter) return out;
|
|
341
|
+
for (const line of frontmatter.split('\n')) {
|
|
342
|
+
const match = line.match(/^([A-Za-z0-9_-]+):\s*(.+)$/);
|
|
343
|
+
if (match) out[match[1]] = match[2].trim().replace(/^["']|["']$/g, '');
|
|
344
|
+
}
|
|
345
|
+
return out;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function auditWrapperText(slug, raw) {
|
|
349
|
+
const frontmatter = parseFrontmatterMap(raw);
|
|
350
|
+
const expected = getRuntimeMetadataForSlug(slug);
|
|
351
|
+
const expectedPack = buildContextPackPaths(slug);
|
|
352
|
+
const workflowResolution = buildWorkflowResolutionBlock(slug);
|
|
353
|
+
const issues = [];
|
|
354
|
+
for (const key of RUNTIME_METADATA_KEYS) {
|
|
355
|
+
if ((frontmatter[key] || '') !== (expected[key] || '')) {
|
|
356
|
+
issues.push({ key, expected: expected[key] || '', actual: frontmatter[key] || '' });
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (!String(raw || '').includes('<!-- oxe-reasoning-contract:start -->')) {
|
|
360
|
+
issues.push({ key: 'oxe-reasoning-contract', expected: 'present', actual: 'missing' });
|
|
361
|
+
}
|
|
362
|
+
if (!String(raw || '').includes(`Checksum semântico:** \`${expected.oxe_semantics_hash}\``)) {
|
|
363
|
+
issues.push({ key: 'oxe_semantics_hash_block', expected: expected.oxe_semantics_hash, actual: 'mismatch' });
|
|
364
|
+
}
|
|
365
|
+
if (!String(raw || '').includes(expectedPack.markdown) || !String(raw || '').includes(expectedPack.json)) {
|
|
366
|
+
issues.push({ key: 'oxe_context_pack_entry', expected: `${expectedPack.markdown} + ${expectedPack.json}`, actual: 'missing' });
|
|
367
|
+
}
|
|
368
|
+
if (!String(raw || '').includes('Regra pack-first')) {
|
|
369
|
+
issues.push({ key: 'oxe_pack_first_rule', expected: 'present', actual: 'missing' });
|
|
370
|
+
}
|
|
371
|
+
if (!String(raw || '').includes('<!-- oxe-workflow-resolution:start -->')) {
|
|
372
|
+
issues.push({ key: 'oxe_workflow_resolution_block', expected: 'present', actual: 'missing' });
|
|
373
|
+
} else {
|
|
374
|
+
if (!String(raw || '').includes(`.oxe/workflows/${slug}.md`) || !String(raw || '').includes(`oxe/workflows/${slug}.md`)) {
|
|
375
|
+
issues.push({
|
|
376
|
+
key: 'oxe_workflow_resolution_paths',
|
|
377
|
+
expected: workflowResolution,
|
|
378
|
+
actual: 'missing_path_reference',
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
if (!/subir diretórios até encontrar/i.test(String(raw || ''))) {
|
|
382
|
+
issues.push({
|
|
383
|
+
key: 'oxe_workflow_resolution_walkup',
|
|
384
|
+
expected: 'subir diretórios até encontrar',
|
|
385
|
+
actual: 'missing',
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (/\*\*Workflow can[óôo]nic[oa]:\*\*/i.test(String(raw || ''))) {
|
|
390
|
+
issues.push({
|
|
391
|
+
key: 'legacy_workflow_anchor',
|
|
392
|
+
expected: 'absent',
|
|
393
|
+
actual: 'present',
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
if (/raiz do projeto atual \(CWD\)|na raiz do repositório em contexto|na raiz do repositório em que estás a trabalhar/i.test(String(raw || ''))) {
|
|
397
|
+
issues.push({
|
|
398
|
+
key: 'legacy_fixed_root_instruction',
|
|
399
|
+
expected: 'absent',
|
|
400
|
+
actual: 'present',
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return {
|
|
404
|
+
slug,
|
|
405
|
+
frontmatter,
|
|
406
|
+
expected,
|
|
407
|
+
issues,
|
|
408
|
+
ok: issues.length === 0,
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function auditRuntimeTargets(projectRoot) {
|
|
413
|
+
const targets = [
|
|
414
|
+
{
|
|
415
|
+
name: 'copilot-prompts',
|
|
416
|
+
dir: path.join(projectRoot, '.github', 'prompts'),
|
|
417
|
+
filter: (name) => (name === 'oxe.prompt.md' || name.startsWith('oxe-')) && name.endsWith('.prompt.md'),
|
|
418
|
+
slug: slugFromPromptFilename,
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
name: 'commands',
|
|
422
|
+
dir: path.join(projectRoot, 'commands', 'oxe'),
|
|
423
|
+
filter: (name) => name.endsWith('.md'),
|
|
424
|
+
slug: slugFromCommandFilename,
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
name: 'cursor',
|
|
428
|
+
dir: path.join(projectRoot, '.cursor', 'commands'),
|
|
429
|
+
filter: (name) => (name === 'oxe.md' || name.startsWith('oxe-')) && name.endsWith('.md'),
|
|
430
|
+
slug: slugFromCommandFilename,
|
|
431
|
+
},
|
|
432
|
+
];
|
|
433
|
+
const result = {
|
|
434
|
+
ok: true,
|
|
435
|
+
contractVersion: CONTRACT_VERSION,
|
|
436
|
+
registryPath: CONTRACTS_PATH,
|
|
437
|
+
registryIssues: validateWorkflowContractsRegistry(),
|
|
438
|
+
warnings: [],
|
|
439
|
+
mismatches: [],
|
|
440
|
+
targets: {},
|
|
441
|
+
};
|
|
442
|
+
for (const target of targets) {
|
|
443
|
+
const info = { path: target.dir, files: [], checked: 0, missing: false };
|
|
444
|
+
if (!fs.existsSync(target.dir)) {
|
|
445
|
+
info.missing = true;
|
|
446
|
+
result.targets[target.name] = info;
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
let names;
|
|
450
|
+
try {
|
|
451
|
+
names = fs.readdirSync(target.dir);
|
|
452
|
+
} catch (err) {
|
|
453
|
+
info.missing = true;
|
|
454
|
+
result.warnings.push(`${target.name}: falha ao listar diretório — ${err instanceof Error ? err.message : String(err)}`);
|
|
455
|
+
result.targets[target.name] = info;
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
for (const name of names) {
|
|
459
|
+
if (!target.filter(name)) continue;
|
|
460
|
+
const filePath = path.join(target.dir, name);
|
|
461
|
+
let raw;
|
|
462
|
+
try {
|
|
463
|
+
raw = fs.readFileSync(filePath, 'utf8');
|
|
464
|
+
} catch (err) {
|
|
465
|
+
result.warnings.push(`${target.name}/${name}: falha ao ler arquivo — ${err instanceof Error ? err.message : String(err)}`);
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
const audit = auditWrapperText(target.slug(name), raw);
|
|
469
|
+
info.checked += 1;
|
|
470
|
+
info.files.push({ file: filePath, slug: audit.slug, ok: audit.ok, issues: audit.issues });
|
|
471
|
+
if (!audit.ok) {
|
|
472
|
+
result.ok = false;
|
|
473
|
+
result.mismatches.push({ target: target.name, file: filePath, slug: audit.slug, issues: audit.issues });
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
result.targets[target.name] = info;
|
|
477
|
+
}
|
|
478
|
+
if (result.registryIssues.length) {
|
|
479
|
+
result.ok = false;
|
|
480
|
+
result.warnings.push(...result.registryIssues);
|
|
481
|
+
}
|
|
482
|
+
if (result.mismatches.length) {
|
|
483
|
+
result.warnings.push(`${result.mismatches.length} wrapper(s) com drift semântico detectado`);
|
|
484
|
+
}
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
module.exports = {
|
|
489
|
+
CONTRACT_VERSION,
|
|
490
|
+
CONTRACTS_PATH,
|
|
491
|
+
CONTRACTS_REGISTRY,
|
|
492
|
+
MODE_DEFAULTS,
|
|
493
|
+
MODE_GUIDANCE,
|
|
494
|
+
MODE_REFERENCES,
|
|
495
|
+
REQUIRED_CONTRACT_FIELDS,
|
|
496
|
+
RUNTIME_METADATA_KEYS,
|
|
497
|
+
auditRuntimeTargets,
|
|
498
|
+
auditWrapperText,
|
|
499
|
+
buildContextPackPaths,
|
|
500
|
+
buildContextTiers,
|
|
501
|
+
buildReasoningContractBlock,
|
|
502
|
+
buildWorkflowResolutionBlock,
|
|
503
|
+
computeSemanticsHash,
|
|
504
|
+
getAllWorkflowContracts,
|
|
505
|
+
getRuntimeMetadataForSlug,
|
|
506
|
+
getWorkflowContract,
|
|
507
|
+
parseFrontmatterMap,
|
|
508
|
+
pickRuntimeMetadata,
|
|
509
|
+
renderRuntimeMetadataLines,
|
|
510
|
+
slugFromCommandFilename,
|
|
511
|
+
slugFromPromptFilename,
|
|
512
|
+
splitFrontmatter,
|
|
513
|
+
validateWorkflowContractsRegistry,
|
|
514
|
+
};
|