Skip to content

let mng ask read the source code#827

Draft
evgunter wants to merge 6 commits intomng/headless-claudefrom
claude/mng-ask-source-access-i09KQ
Draft

let mng ask read the source code#827
evgunter wants to merge 6 commits intomng/headless-claudefrom
claude/mng-ask-source-access-i09KQ

Conversation

@evgunter
Copy link
Contributor

@evgunter evgunter commented Mar 11, 2026

Summary

  • Give mng ask read-only access to the mng source code via Read, Glob, and Grep tools (previously it had no tools at all), so it can look up implementation details when answering questions
  • Add --allow-web flag that additionally enables WebFetch restricted to github.com and raw.githubusercontent.com, for reading issues/PRs/docs from the repo
  • Extract system prompt assembly into _run_ask_query so the source-access and web-access context sections are composed in one place

Details

The headless claude agent previously ran with --tools "" (no tools). This changes it to:

  • Always: --tools "Read,Glob,Grep" with --allowedTools Read,Glob,Grep and --permission-mode dontAsk
  • With --allow-web: additionally includes WebFetch in the tool list, restricted to GitHub domains via --allowedTools "WebFetch(domain:github.com)" and --allowedTools "WebFetch(domain:raw.githubusercontent.com)"

The system prompt is enriched with the on-disk source tree location (auto-detected by walking up from ask.py) and, when --allow-web is set, a note about the available GitHub access.

Test plan

  • _find_mng_source_directory finds the source tree and returns None when not in the tree
  • _build_source_access_context includes/omits docs directory based on existence
  • _build_web_access_context includes GitHub info
  • _run_ask_query composes source context always, web context only when enabled
  • --allow-web CLI flag is accepted
  • All 28 ask tests pass

https://claude.ai/code/session_01P6ioKexZAqMkD4vv16BxXi

… headless-claude)

Re-implements the source access and web access features on top of the
headless-claude branch which replaced SubprocessClaudeBackend with
HeadlessClaudeBackend.

Changes:
- Add _find_mng_source_directory to locate the mng source tree
- Add _build_source_access_context to enrich the system prompt with
  source code directory information
- Add _build_web_access_context for GitHub repository access context
- Configure headless claude agent with Read/Glob/Grep tools (and
  optionally WebFetch) instead of empty tool list
- Add --allowedTools and --permission-mode dontAsk to agent args
- Add --allow-web CLI flag
- Extract _run_ask_query for system prompt assembly and dispatch

https://claude.ai/code/session_01P6ioKexZAqMkD4vv16BxXi
@evgunter evgunter changed the base branch from main to mng/headless-claude March 11, 2026 07:52
@evgunter evgunter marked this pull request as draft March 11, 2026 07:52
@evgunter evgunter changed the title Add HeadlessClaude agent type for non-interactive Claude usage let mng ask read the source code Mar 11, 2026
claude added 5 commits March 11, 2026 08:23
…missionsAgentMixin

- Path-scope Read, Glob, Grep tools to the mng source directory via
  --allowedTools "Read(//path/**)" syntax, preventing the ask agent
  from reading arbitrary files on the machine.
- When source directory is not found (installed package), these tools
  are omitted entirely rather than granted unrestricted access.
- Extract _build_read_only_tools_and_permissions() to build both the
  --tools CSV and --allowedTools args in one place.
- Rename NoPermissionsAgentMixin -> SafePermissionsAgentMixin to
  accurately reflect that these agents may have permissions, but they
  are safe enough to skip user confirmation.

https://claude.ai/code/session_01P6ioKexZAqMkD4vv16BxXi
Previously the function walked up to parents[3] and checked for
imbue/mng/, which incorrectly matched site-packages/ when mng was
installed as a package (scoping the agent to all of site-packages).

Now distinguishes source checkouts (pyproject.toml present) from
installed packages. For source checkouts, returns the project root
(includes docs/). For installed packages, returns the imbue/ directory
(scopes to just the mng source).

Also fixes _build_source_access_context to compute the mng package
path relative to whichever root was returned, avoiding doubled
imbue/imbue/mng paths.

https://claude.ai/code/session_01P6ioKexZAqMkD4vv16BxXi
Instead of scoping Read/Glob/Grep to just the mng project root,
discover all sibling libraries under libs/ that have pyproject.toml
and an imbue/ directory. This includes mng plugins (mng_opencode,
mng_schedule, etc.) and dependency libraries (imbue_common,
concurrency_group, etc.).

For installed packages (non-editable), all packages merge under a
single imbue/ directory in site-packages, so a single scope suffices.

Each discovered directory gets its own --allowedTools scope entries.

Adds test_find_source_checkout_directories_includes_all_monorepo_libs
which verifies that every libs/ package with pyproject.toml and imbue/
is discovered, ensuring new packages are automatically included.

https://claude.ai/code/session_01P6ioKexZAqMkD4vv16BxXi
…irectories

Replace _find_source_checkout_directories filesystem scan with a
hard-coded _MONOREPO_PACKAGE_DIRS tuple that lists the dir_name of
every publishable package. This is validated by a sync test against
scripts/utils.py PACKAGES.

https://claude.ai/code/session_01P6ioKexZAqMkD4vv16BxXi
Installs mng and all published plugins from PyPI into a temporary
venv, then verifies the directory layout is correctly detected as an
installed (non-source-checkout) environment with all packages under
site-packages/imbue/.

https://claude.ai/code/session_01P6ioKexZAqMkD4vv16BxXi
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.

2 participants