{"record":{"id":"7ccc8136744d319f","repo":"ruvnet/ruflo","slug":"mode-must-be-legacy-observe-or-enforce","errorCode":null,"errorMessage":"mode must be legacy, observe, or enforce","messagePattern":"mode must be legacy, observe, or enforce","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/commands/policy.ts","lineNumber":55,"sourceCode":"export const policyCommand: Command = {\n  name: 'policy',\n  description: 'Agentic policy engine — evaluate actions, manage rules/approvals, and verify the decision ledger (ADR-324)',\n  options: [\n    { name: 'mode', type: 'string', description: 'Policy mode: legacy | observe | enforce' },\n    { name: 'project-root', type: 'string', description: 'Project root containing .claude-flow/policy' },\n  ],\n  async action(context: CommandContext): Promise<CommandResult> {\n    const args = (context as { args?: string[] }).args ?? [];\n    const flags = (context as { flags?: Record<string, unknown> }).flags ?? {};\n    const root = String(flags.projectRoot ?? process.cwd());\n    const operation = args[0] ?? 'status';\n    try {\n      if (operation === 'init' || operation === 'migrate') {\n        if (flags.mode || args[1]) requireInteractiveAdministrator();\n        const migration = await autoMigratePolicyStateIfNeeded(root);\n        const mode = String(flags.mode ?? args[1] ?? '') as PolicyState['mode'];\n        if (mode) {\n          if (!['legacy', 'observe', 'enforce'].includes(mode)) throw new Error('mode must be legacy, observe, or enforce');\n          await setPolicyMode(mode, root);\n        }\n        return print({ ...migration, state: loadPolicyState(root) });\n      }\n      if (operation === 'status') {\n        const state = loadPolicyState(root);\n        return print({\n          version: state.version,\n          mode: state.mode,\n          migratedFrom: state.migratedFrom,\n          rules: state.rules.length,\n          budgets: state.budgets.length,\n          approvals: state.approvals.length,\n          receipts: state.receipts.length,\n          ledger: await verifyPolicyLedger(root),\n        });\n      }\n      if (operation === 'evaluate') {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/commands/policy.ts#L37-L73","documentation":"During `policy init`/`policy migrate`, the requested mode is validated against the fixed ADR-324 vocabulary legacy | observe | enforce before setPolicyMode is called. Any other string — including differently-cased ones — is rejected so the policy state file never records an unknown mode.","triggerScenarios":"Passing --mode strict, --mode enforcement, --mode Enforce (case-sensitive check), or accidentally supplying a second positional (args[1] is also interpreted as the mode: `ruflo policy init production`).","commonSituations":"Assuming stricter-sounding mode names exist; capitalization drift; passing a project name as a positional that gets consumed as the mode.","solutions":["Use exactly one of legacy, observe, or enforce, all lowercase","Check `ruflo policy status` to see the current mode and vocabulary","If a positional was swallowed as the mode, move it to a flag or remove it"],"exampleFix":"# before\nruflo policy init --mode Enforce\n\n# after\nruflo policy init --mode enforce","handlingStrategy":"validation","validationCode":"const POLICY_MODES = ['legacy', 'observe', 'enforce'] as const;\nconst mode = POLICY_MODES.includes(candidate as any) ? candidate : 'observe';\nawait runPolicyCli(['policy', 'init', '--mode', mode]);","typeGuard":"function isPolicyMode(v: unknown): v is 'legacy' | 'observe' | 'enforce' {\n  return v === 'legacy' || v === 'observe' || v === 'enforce';\n}","tryCatchPattern":null,"preventionTips":["Type mode fields as the literal union 'legacy' | 'observe' | 'enforce' in your config","Lowercase and trim user-supplied modes before passing them on","Never pass a free-form second positional to `policy init` — it is parsed as the mode"],"tags":["cli","policy","enum","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}