Skip to content

feat(cli): context-intelligence opt-in dispatch filtering — path-rule to workspace-pattern injection#188

Closed
colombod wants to merge 0 commit into
mainfrom
feat/opt-in-configuration-behaviour
Closed

feat(cli): context-intelligence opt-in dispatch filtering — path-rule to workspace-pattern injection#188
colombod wants to merge 0 commit into
mainfrom
feat/opt-in-configuration-behaviour

Conversation

@colombod
Copy link
Copy Markdown
Contributor

@colombod colombod commented May 20, 2026

Two-PR feature. This is the host-side half. The companion bundle-side PR is microsoft/amplifier-bundle-context-intelligence#19.

Summary

Adds host-side path-rule evaluation that translates disk path patterns to workspace name patterns, injected additively into the context-intelligence bundle's allow_workspaces / deny_workspaces filter config.

This is one half of a two-PR feature. The companion PR in amplifier-bundle-context-intelligence implements the bundle-side workspace filter in ConfigResolver and the dispatch gate in LoggingHandler.

What changed

AppSettings — two new methods (lib/settings.py)

get_context_intelligence_config() — reads the context_intelligence: top-level section from merged settings.

get_context_intelligence_hook_overrides(working_dir) — evaluates context_intelligence.path_rules against the current working directory:

  • Expands ~ in path patterns before matching
  • Evaluates all matching rules (not first-match-wins)
  • Transforms each matched path pattern to a workspace name pattern (~/work/**-home-<user>-work-*)
  • forwarding_enabled: true → appends workspace pattern to allow_workspaces
  • forwarding_enabled: false → appends workspace pattern to deny_workspaces
  • Returns a single hook override dict with the accumulated patterns
  • Returns [] when working_dir is None, no rules are configured, or no rule matches

runtime/config.py — additive list merge + wiring

_merge_hook_config — new helper replacing the flat {**base, **overlay} merge for hook configs. allow_workspaces and deny_workspaces are unioned (base values preserved, overlay appended) rather than replaced. Applied generally across all hook overrides.

One-line wiring — calls get_context_intelligence_hook_overrides(os.getcwd()) alongside get_notification_hook_overrides() so path-rule-derived workspace patterns reach the session config.

Pre-existing test fix

tests/test_session_spawner_subprocess.py::test_subprocess_param_routes_to_subprocess — updated assertion to match the current config shape ({"agents": {}, "session": {}}) which had drifted from the test expectation on main. Acknowledged as pre-existing in the PR #186 commit message.

Configuration

# Host-side path rules — evaluated by the CLI, transformed to workspace patterns
# These are additive with any patterns in overrides.hook-context-intelligence.config
context_intelligence:
  path_rules:
    - path: "~/work/**"
      forwarding_enabled: true    # → appends -home-<user>-work-* to allow_workspaces
    - path: "/tmp/**"
      forwarding_enabled: false   # → appends -tmp-* to deny_workspaces
    - path: "~/client/**"
      forwarding_enabled: false   # → appends -home-<user>-client-* to deny_workspaces

Compatibility

Bundle PR not yet merged: If this PR lands first, the injected workspace patterns are silently ignored by the current bundle (no allow_workspaces support). Old all-dispatch behaviour continues. Zero regression.

This PR not yet merged: If the bundle PR lands first, the bundle's deny-all default activates. No events dispatch until allow_workspaces is explicitly configured in overrides.hook-context-intelligence.config. No crash — silent no-dispatch.

Tests

  • 982/982 tests passing (zero failures)
  • 20 new tests in tests/test_context_intelligence_hook_overrides.py covering: _path_pattern_to_workspace_pattern, tilde expansion, all-match semantics, allow/deny injection, additive union, None working_dir, non-matching rules
  • ruff check / ruff format / pyright — all clean

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant