import { generateWorkflowRules } from "../shared/workflow_template.js";
import { recordConsumptionTrace, CONSUMER_FIELD_CONTRACTS } from "../../engine/templates/consumption_trace_store.js";
import { listConsumableAssetsByConsumer } from "../../engine/templates/consumable_asset_registry.js";
import { getContractByPath } from "../../engine/templates/template_asset_contract_registry.js";
import { debug } from "../../engine/core/logger.js";
/**
 * 生成 Codex AGENTS.md 规则文件内容。
 * @param config - 项目配置
 * @returns AGENTS.md 文件的文本内容
 */
export function generateCodexAgentsMd(config) {
    debug("Codex规则", "生成 AGENTS.md");
    const result = generateWorkflowRules(config) + "\n";
    const registeredAssets = listConsumableAssetsByConsumer("generateCodexAgentsMd");
    for (const asset of registeredAssets) {
        const checkResult = result.length > 0
            ? { pass: true, proof: `length=${result.length}` }
            : { pass: false, proof: "empty" };
        if (checkResult.pass) {
            const contract = getContractByPath(asset.path);
            recordConsumptionTrace({
                consumer: "adapter_prompt",
                asset_id: asset.id,
                asset_path: asset.path,
                fields_consumed: CONSUMER_FIELD_CONTRACTS.adapter_prompt,
                matched_reason: `AGENTS.md content_verified consumed ${asset.id} ${checkResult.proof}`,
                task_id_or_route: "codex-agents-md",
                consumed_at: new Date().toISOString(),
                declared_consumer: contract?.mainline_consumer,
            });
        }
    }
    return result;
}
//# sourceMappingURL=codex_rules.js.map