Skip to content

feat(ai): choose a persona lens from evidence with a rule table #4830

Done

Description

@dan-petty

Problem or Motivation

A flag or a fixed default chooses the persona today: devops ai chat --persona (default architect) and the agents default. No caller uses evidence. Telemetry has no persona label, so nobody can see which lens a call used.

The owner asked on 2026-11-11 (#4780) for persona selection from evidence (changed paths, tool findings, the item type and scope), with a measure that shows that the selection improves the result. Reviews stay evidence-first: tools find the findings, and a model only explains or answers (ADR 0005).

Proposed Solution & Architectural Design

  • Add select_lens(evidence) -> LensChoice (lens or none, rule id, source) in src/devops_cli/ai/personas/lens.py, with the ordered data table lens.toml.
  • The first match wins, in this order:
    1. an explicit flag;
    2. a fixed step role (challenger for each refute call);
    3. the finding producer and CWE (gitleaks, trivy, kube-linter, and bandit or semgrep with a CWE give devsecops; mypy and c901 give architect; pytest and coverage give qa);
    4. changed or cited paths through pathspec (k8s/**, tf/**, .github/workflows/** and Dockerfile give devsecops; tests/** gives qa; docs/**, openspec/** and docs/adr/** give pm; src/** gives architect);
    5. the type/* and scope/* labels (446 open items carry them).
  • No match gives no lens, and the caller uses the generic prompt.
  • No Jev point: an ordered table has no tie, and ADR 0019 starts no step without labels.
  • Record the lens, the rule and prompt_digest in profile.json, the run store and the span attribute ai.lens.
  • Add the counter devops_cli_ai_lens_total{caller,lens,source} (84 series or fewer).
  • Add devops ai chat --persona auto as an option. The default stays architect until a chat measure exists (owner decision of 2026-11-11, feat(roadmap): track the issue stewards and persona selection #4780).

Target Subsystem

AI & Agentic Review Pipeline (src/devops_cli/ai/personas/).

Existing Tool Considered

pathspec 1.1.1 (a dependency already) matches the paths. No library maps the evidence of this project to its own prompts. Cost to build: about 80,000 tokens and 2 hours.

Acceptance Criteria

  • A table test for each row.
  • An evidence set with no match gives none.
  • devops ai chat --persona auto on a change under k8s/ gives devsecops.
  • The counter has 84 series or fewer.

Dependencies

Source: #4780

Alternatives check of 2026-11-21: in-use.
The repository already uses this tool.
Tool: pathspec (https://pypi.org/project/pathspec), Mozilla Public License 2.0 (MPL 2.0), last activity 2026-04-27, maintained.
Reason: Searches found no library that maps this project's evidence to its own persona prompts; pathspec, already a pinned dependency, covers only the gitignore-style path rows, so the selector, rules, telemetry and option remain to build.

Covers:

  • Gitignore-style globs for k8s/, tf/ and Dockerfile patterns
  • Recursive ** meaning that fnmatch and PurePath.match lack
  • Matching changed and cited paths against one pattern syntax

Lacks:

  • Evidence-to-lens mapping and the ordered first-match rule table
  • Finding producer and CWE rules, plus type/* and scope/* label rules
  • ai.lens span attribute, profile.json record and bounded counter
  • devops ai chat --persona auto option and its source label

Proposed design

Problem statement

A flag or a fixed default chooses the persona lens today: devops ai chat --persona defaults to architect, and no caller uses evidence. Telemetry carries no lens label, so nobody can see which lens a call used. This issue adds an ordered, data-driven select_lens(evidence) rule table, records the choice on the span and in the review profile, adds a bounded counter, and adds devops ai chat --persona auto; the default stays architect until a measure shows that the selection improves the result.

Acceptance criteria

Requirement: Ordered rule table

The selector SHALL read its ordered rules from the data file src/devops_cli/ai/personas/lens.toml, and each rule SHALL have a unique id.

Scenario: Rows load in file order

  • WHEN A test loads lens.toml and reads the rule ids.
  • THEN The ids match the file order and are unique.

Requirement: First match wins

The selector SHALL return the lens of the first matching row and stop at it.

Scenario: Explicit flag beats a path

  • WHEN The evidence holds the explicit flag pm and the changed path k8s/devops/api/deployment.yaml.
  • THEN The choice holds the pm lens and the id of the explicit-flag row.

Requirement: Fixed step role

The selector SHALL return the challenger lens for a refute step before any finding, path or label row.

Scenario: Refute step with a finding

  • WHEN The evidence names the refute step role and holds a gitleaks finding.
  • THEN The choice holds the challenger lens and the id of the step-role row.

Requirement: Finding producer and CWE

The selector SHALL map each finding producer and CWE in the table to its lens, with gitleaks, trivy, kube-linter, bandit and semgrep with a CWE giving devsecops, mypy and c901 giving architect, and pytest and coverage giving qa.

Scenario: One finding from each producer

  • WHEN A test feeds one finding for each producer row: gitleaks, trivy, kube-linter, bandit with a CWE, semgrep with a CWE, mypy, c901, pytest and coverage.
  • THEN Each result holds the lens and row id of that producer.

Requirement: Path matching with pathspec

The selector SHALL match changed and cited paths against the table patterns with the pathspec library at the version that pyproject.toml pins.

Scenario: Kubernetes path

  • WHEN The evidence holds the changed path k8s/devops/api/deployment.yaml and no other signal.
  • THEN The choice holds the devsecops lens and the id of the k8s/** row.

Requirement: Label rule after paths

The selector SHALL map the type/* and scope/* labels only after every finding and path row, and SHALL use the type/* labels that workflow_labels.py declares, such as type/infra and not a type/ci label.

Scenario: Docs label behind a source path

  • WHEN The evidence holds the label type/docs and the changed path src/devops_cli/cli.py.
  • THEN The choice holds the architect lens from the src/** row, not the pm lens from the label.

Requirement: No match gives no lens

The selector SHALL return no lens when no row matches.

Scenario: Unknown evidence

  • WHEN The evidence holds no flag, no step role, no finding, no path and no label.
  • THEN The choice holds no lens and the caller uses the generic prompt.

Requirement: Lens record

The caller SHALL record the lens and rule id on the span attributes ai.lens and ai.lens.rule, and SHALL write lens and lens_rule into the review profile.json beside prompt_digest, with none and an empty rule when no lens matched.

Scenario: Selected lens is recorded

  • WHEN A test runs a call that selects the devsecops lens and writes its profile.
  • THEN The span holds ai.lens=devsecops and the rule id, and profile.json holds lens=devsecops, the rule id and a prompt_digest.

Requirement: Bounded lens counter

The caller SHALL increment devops_cli_ai_lens_total{caller,lens,source} with closed label sets, and the product of those sets SHALL stay at 84 or fewer series.

Scenario: Series product

  • WHEN A test computes the product of the declared caller, lens and source values, where caller is chat, lens is the six personas plus none, and source is flag, rule or default.
  • THEN The product is 21, which is 84 or fewer, and one call adds one series.

Requirement: Counter declaration and register

The counter SHALL be declared as an Instrument in src/devops_cli/telemetry/instruments.py, and the generated docs/TELEMETRY.md SHALL list it with its labels.

Scenario: Docs are up to date

  • WHEN A test runs devops docs check after the counter is declared.
  • THEN The check passes and the devops_cli_ai_lens_total row names caller, lens and source.

Requirement: Chat persona option

devops ai chat SHALL accept --persona auto and select the lens from the evidence of the working tree.

Scenario: Auto persona on a Kubernetes change

  • WHEN A test resolves the chat lens for --persona auto with a changed path under k8s/.
  • THEN The call uses the devsecops lens and records the source rule.

Requirement: Default persona

devops ai chat SHALL use the architect lens when the caller gives no --persona and SHALL record the source default, while an explicit --persona architect SHALL record the source flag.

Scenario: No option

  • WHEN A test resolves the chat lens with no --persona.
  • THEN The call uses the architect lens and records the source default.

Requirement: Row test coverage

Each row of lens.toml SHALL have one test case that asserts its lens and rule id.

Scenario: Every row is tested

  • WHEN The table test runs.
  • THEN Each row id in the file appears in the test case list and no case fails.

Existing Tool Considered

pathspec (https://pypi.org/project/pathspec), MPL 2.0, maintained, last activity 2026-04-27, is in use at the version pyproject.toml pins, 1.1.1. It covers the gitignore-style path matching of the k8s/**, tf/**, .github/workflows/**, Dockerfile*, tests/**, docs/** and src/** rows, and its gitignore semantics give ** its recursive meaning, which fnmatch and pathlib.PurePath.match do not. It lacks the evidence-to-lens mapping, the ordered first-match table, the flag, step-role, producer/CWE and label rules, the profile.json and ai.lens record, the devops_cli_ai_lens_total counter and the --persona auto option. The selector code costs about 80,000 tokens and 2 hours to build, keep and fix.

Key questions

  • Which format and location does the ordered rule table use?: Use the TOML data file src/devops_cli/ai/personas/lens.toml, beside the persona folders. Each row holds a rule id, a matcher, a pattern and a lens, and the selector reads the rows in file order. The repository already keeps its ordered configuration in TOML, as .devops/review.toml does for its path classes. (best practice) [sources: .devops/review.toml:5, src/devops_cli/ai/personas/init.py:14]
    • Chosen: TOML data file. The repository keeps its ordered configuration in TOML files, and a data file lets a test read every row without importing code.
    • Rejected: Python module constant. A test cannot read the rows as data without running the module, and a code change is needed for each row.
    • Rejected: YAML data file. The repository uses TOML for its configuration files, so a second format adds a parser and a convention.
  • Which library matches the changed and cited paths?: Use pathspec 1.1.1, which pyproject.toml already pins. Its gitignore-style globs give ** recursive meaning, so k8s/**, tf/**, .github/workflows/**, Dockerfile*, tests/**, docs/** and src/** all work in one syntax. The project's own library note names it the canonical matcher and rejects fnmatch and glob for this job. (best practice) [sources: pyproject.toml:33, src/devops_cli/ai/knowledge_base/devops_cli/libraries/pathspec.md:27, src/devops_cli/ai/knowledge_base/devops_cli/libraries/pathspec.md:40]
    • Chosen: pathspec. It is already a dependency at 1.1.1, it is maintained under MPL 2.0, and its gitignore-style globs cover the recursive and bare-name patterns of the table.
    • Rejected: fnmatch. ** has no recursive meaning, so k8s/** would not match a file two folders deep.
    • Rejected: pathlib.PurePath.match. It has no gitignore semantics, so a negation or a directory-only pattern needs custom code.
  • Which order do the rules take?: Keep the order of the body: the explicit flag, the fixed step role, the finding producer and CWE, the changed or cited paths, then the type/* and scope/* labels. The first match wins, and no row scores. ADR 0020 puts a deterministic rule before any decision model and stops at the first resolver that answers, and ADR 0005 keeps tools, not models, as the source of findings. (best practice) [sources: docs/adr/0020-a-decision-point-is-a-unit-of-a-workflow-with-a-resolver-chain-and-a-rule-goes-before-a-decision-model.md:60, docs/adr/0005-review-findings-come-from-tools-not-models.md]
    • Chosen: Ordered first-match table. The order is deterministic, each row is testable alone, and the strongest evidence comes first: a flag, a fixed step, a tool finding, a path, a label.
    • Rejected: Weighted score over the evidence. The weights need a measured corpus that does not exist, and a score needs a tie-break.
    • Rejected: Model choice of the lens. ADR 0005 keeps the model out of the finding path and ADR 0020 asks a rule first, so a model choice is not testable offline.
  • Which lens does each type/* and scope/* label give?: Use one row for each label glob, after every path row. The real type/* set is the one workflow_labels.py declares: type/docs and type/epic give pm; type/test gives qa; type/security and type/infra give devsecops, and there is no type/ci label, so the body's type/ci row is corrected to type/infra. Of the scope/* labels of .github/labels.yml, scope/docs, scope/adr and scope/openspec give pm; scope/tests gives qa; scope/security, scope/k8s, scope/infra, scope/terraform, scope/ci, scope/monitoring and scope/deps give devsecops. A final row matches any other type/* or scope/* label and gives architect. (best practice) [sources: .github/labels.yml:8, .github/labels.yml:52, src/devops_cli/roadmap/workflow_labels.py:55, src/devops_cli/roadmap/workflow_labels.py:61, src/devops_cli/roadmap/workflow_labels.py:63]
    • Chosen: Label rows in lens.toml. The mapping stays data-driven and testable, and a new label needs one row and no code change.
    • Rejected: The body's type/ci row. No type/ci label exists: the declared types are feature, bug, security, refactor, docs, infra, test, chore and epic, so the CI and build case belongs to type/infra and scope/ci.
    • Rejected: Hardcoded label check in code. The mapping leaves the table, and a test cannot read it as data.
  • Which label sets bound the counter to 84 series?: Use closed sets, and correct the four-caller claim. devops ai chat is the only caller that builds a persona agent today: devops ai agents generates instruction files and has no persona option, and no review stage calls a persona. So caller is chat now, lens is the six Persona values plus none for no match, and source is flag, rule or default. The product is 1 × 7 × 3 = 21 series, within the 84 cap; the cap allows up to four callers, so a later review or roadmap caller fits. A test asserts the product is 84 or fewer. Prometheus labels stay on a closed set, never on free text. (best practice) [sources: src/devops_cli/commands/ai.py:931, src/devops_cli/commands/ai.py:1161, ARCHITECTURE.md:81, src/devops_cli/ai/personas/init.py:18, docs/TELEMETRY.md:106, src/devops_cli/ai/knowledge_base/it_domains/tools/prometheus.md:87]
    • Chosen: Closed sets: caller chat, lens 6 plus none, source 3. It names only the caller that exists, gives 21 series now, and the 84 cap leaves room for three more callers.
    • Rejected: Four callers now (chat, agents, review, roadmap). devops ai agents has no persona option, and ARCHITECTURE.md says no review stage calls the personas, so three of those four series would never appear.
    • Rejected: Free-text label values. A new value makes a new series, so the count is unbounded.
  • Where does the call record the lens, the rule and prompt_digest?: Record the lens and rule id on the span attributes ai.lens and ai.lens.rule, and write lens and lens_rule into the review profile.json beside prompt_digest, which lives in the run store. Note the correction: the review prompt_digest covers only ai/tasks/*.md, and the personas under ai/personas/ are deliberately outside it (fix(ai): the review prompt digest leaves out the chat persona prompts #4829), so a chat call computes its own digest of the selected persona's chat_prompt with run_store.digest rather than reusing the review digest. The review profile fields default to none and an empty rule until a review stage selects a lens. [sources: src/devops_cli/ai/review/profile.py:123, src/devops_cli/ai/personas/init.py:80, src/devops_cli/ai/personas/init.py:85, src/devops_cli/ai/personas/init.py:89, src/devops_cli/telemetry/instruments.py:96]
  • Which lens does devops ai chat use by default?: Keep the architect lens as the default. --persona auto is opt-in. The documented option default is architect, and the body keeps it until a chat measure shows that the selection improves the result (owner decision of 2026-11-11, feat(roadmap): track the issue stewards and persona selection #4780). (best practice) [sources: src/devops_cli/commands/ai.py:1169, docs/commands/ai.md:145]
    • Chosen: Keep architect as the default. The documented default is architect, and the owner decision keeps it until a chat measure exists.
    • Rejected: Make auto the default. No measure shows that the selection improves the result, so the change has no evidence.
    • Rejected: Auto with an architect fallback. It changes the default for every call, and the owner decision holds the default.
  • Does this issue include the measure that shows the selection improves the result?: No. Defer the measure to a new issue. ADR 0020 starts a new decision point in shadow and turns it on only after its record and a fit report exist; here the record is the lens counter and the chat measure, and neither exists yet. This issue builds the selector, the record and the counter, and keeps the default architect. (best practice) [sources: docs/adr/0020-a-decision-point-is-a-unit-of-a-workflow-with-a-resolver-chain-and-a-rule-goes-before-a-decision-model.md:84]
    • Chosen: Defer the measure. The measure waits on a chat measure and a fixed corpus that the repository does not have, and the rest of the issue is workable.
    • Rejected: Build the measure here. There is no chat measure to compare against, so the issue would block.
    • Rejected: Drop the measure. The owner asked for it in feat(roadmap): track the issue stewards and persona selection #4780, so it stays on record as a new issue.
  • How does the caller tell an explicit --persona from the default?: Change the option to str | None = None and resolve None to the architect lens with source default; an explicit --persona architect then records source flag. A plain architect default cannot be told from a flag the user typed, so the counter and the rule table would mislabel every explicit architect call. (best practice) [sources: src/devops_cli/commands/ai.py:1162, src/devops_cli/commands/ai.py:1169, docs/commands/ai.md:145]
    • Chosen: None default resolved to architect. It keeps the documented default behavior and makes the explicit flag observable for the first-match rule and the source label.
    • Rejected: Keep the architect default and always record default. An explicit --persona architect would be recorded as the default, so the counter could not show a flag choice.
    • Rejected: A second option that states the source. It makes the user repeat what the flag already says and adds a way to lie to the rule table.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4824

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/ai
    status/new
    on Nov 11, 2026
  3. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. The owner requested it, but it is an enhancement with a stated token and time cost, not a critical defect.
    • Value: Medium. It improves persona choice and adds lens telemetry, but the default stays architect, so users see a limited gain.
    • Effort: Medium. It adds a rule table, a selector, tests, telemetry and a chat option across several files, at about 80,000 tokens.
    • Related: fix(ai): chat loads each persona prompt and challenger gets tools #4824, which asks for a different change. Both work on persona plumbing in src/devops_cli/ai/personas/, but 4824 fixes prompt loading and the challenger tool map while the candidate adds evidence-based lens selection.
  4. removed
    priority/p2-medium
    on Nov 11, 2026
  5. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. The owner requested it, but the system works with a fixed default until this lands.
    • Value: Medium. It improves persona accuracy and adds observability, but the current fixed default still functions.
    • Effort: Medium. It adds a new module, a TOML table, a CLI flag, telemetry, and table tests, estimated at about 2 hours.
    • Related: fix(review): record active personas accurately in review session findings and candidates #720, which asks for a different change. Both items deal with persona identity in the AI pipeline, but #720 fixes recording of which personas ran, while this candidate adds a mechanism to select which persona to run.
  6. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: Searches found no library that maps this project's evidence (findings, CWE, labels, item type/scope) to its own persona prompts, so the selector itself has to be built. The one open tool that covers a piece is pathspec, which the issue already lists as a dependency: it does the gitignore-style path matching behind the k8s/**, tests/**, docs/**, src/** rule, but nothing else in the rule table.

    The repository already uses this tool.

    Tool: pathspec (https://pypi.org/project/pathspec)

    • License: Mozilla Public License 2.0 (MPL 2.0)
    • Last activity: 2026-04-27
    • Maintained: yes

    Covers:

    • Gitignore-style glob matching of changed or cited paths (e.g. k8s/**, tf/**, .github/workflows/**, Dockerfile, tests/**, docs/**, src/**)
    • Already a project dependency at 1.1.1, so the path rule of the table needs no new package

    Lacks:

    • No mapping from evidence to a persona lens or LensChoice (lens, rule id, source)
    • No ordered, first-match rule table loaded from lens.toml
    • No rules for tool findings and CWE (gitleaks, trivy, kube-linter, bandit/semgrep, mypy, c901, pytest/coverage), the explicit flag, the fixed step role, or the type/* and scope/* labels
    • No recording of lens, rule and prompt_digest in profile.json, the run store or the ai.lens span attribute
    • No devops_cli_ai_lens_total{caller,lens,source} counter
    • No devops ai chat --persona auto option
    • No measure that the selection improves the result

    Tools considered:

    Searches run:

    • pathspec gitignore-style path matching Python library, results: 5
    • Python rule engine first match ordered rule table library, results: 5
    • pathspec PyPI package, results: 5
    • business-rules python package rules engine, results: 5
    • LLM agent persona selection from evidence rules library, results: 5

    Sources:

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/ready
    and removed
    status/new
    on Nov 15, 2026
  8. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at e5dfddb (see proposed design in issue body).

    Moved to new items: #5818, #5819.

  9. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  10. removed
    status/in-review
    owner/agent
    on Nov 25, 2026
  11. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 06:00 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions