From fda4c6154e977f5794c8af41f93874b9f66d215d Mon Sep 17 00:00:00 2001 From: asdacdsfca Date: Mon, 23 Nov 2026 11:03:34 -0500 Subject: [PATCH] context: add walk-bound inputs and expand_context (interface only) start_symbol and token_budget map to the existing --from and --page-budget; direction and max_depth are checked but not yet used; expand_context is refused as not implemented. With the new inputs left out, answers are unchanged. --- plugins/axiomcode/AGENTS.md | 3 +- plugins/axiomcode/mcp/server.py | 33 +++++++++++++++---- plugins/axiomcode/skills/axiomcode/SKILL.md | 5 +++ .../skills/axiomcode/scripts/ax_web.py | 2 +- .../skills/axiomcode/scripts/axiomcode | 4 +-- .../axiomcode/scripts/axiomcode-context | 24 ++++++++++++-- tests/front_door.py | 7 ++-- tests/mcp.py | 14 +++++--- tests/mcp_docs.py | 2 +- tests/surfaces.py | 5 +-- 10 files changed, 76 insertions(+), 23 deletions(-) diff --git a/plugins/axiomcode/AGENTS.md b/plugins/axiomcode/AGENTS.md index dc3cd82e3..087caf457 100644 --- a/plugins/axiomcode/AGENTS.md +++ b/plugins/axiomcode/AGENTS.md @@ -13,7 +13,8 @@ that never spell the name: unresolved() every open call site that may land in the project; after a build, settle them in a subagent with /axiomcode:fill context(task) how something works, as a narrative: the call flow step by step; - context(task, source=True) carries each step's code + context(task, source=True) carries each step's code; + start_symbol, direction, max_depth and token_budget bound the walk (being built) Without the tools, the same from the shell: `axiomcode impact `, `axiomcode path `, `axiomcode tests`, `axiomcode context "" --source`. diff --git a/plugins/axiomcode/mcp/server.py b/plugins/axiomcode/mcp/server.py index c90000740..f0771e372 100755 --- a/plugins/axiomcode/mcp/server.py +++ b/plugins/axiomcode/mcp/server.py @@ -172,7 +172,7 @@ async def call_tool(self, name, arguments, *a, **k): # the SDK: refused as a SEEN = set() # the flags whose next argument is their value, as the dispatcher skips them when it looks for the repository VALUED = {'--in', '--from', '--budget', '--seeds', '--depth', '--limit', '--tests-in', '--kind', '--range', '--old', - '--new', '--file', '--page', '--page-budget', '--out'} + '--new', '--file', '--page', '--page-budget', '--out', '--direction', '--continue', '--branch'} def orphaned(root=None): """ax_orphan.orphaned for the install this server runs now (plugin_root): '' while it is current. An install whose scripts are gone cannot be imported, so that is said here""" @@ -271,7 +271,7 @@ def run(args, cwd=None, timeout=None): # and only the tools' own parameters count as a `name=` to set, never an HTML attribute (`style="…"`, `class="…"`). _CLI_OPTIONS = ('json|tests|tests-only|tests-in|why|unknown|depends|in|limit|depth|page|page-budget|budget|kind|top|warm|from-text|delete|' 'help|fresh|no-refresh|every|all|grep|grep-limit|paths|from|seeds|source|lang|language|languages|src|library|exclude-tests|' - 'debug|range|selftest|version|exact|evidence|no-evidence|verbs|alongside|drop|slug') + 'debug|range|selftest|version|exact|evidence|no-evidence|verbs|alongside|drop|slug|direction|continue|branch') _OPTION = re.compile(r"(? str: +def context(task: str, source: bool = False, start_symbol: str = '', direction: str = '', max_depth: int = 0, + token_budget: int = 0) -> str: """How something works, from a task in words: the files and callables the task touches, and for a "how does X work" question the call FLOW — every step in the order the calls are written, with ⚠ where the graph lost a - call. source=True asks for the flow with each step's code, so it is read without opening files.""" - return answer(['context', task] + (['--source'] if source else []) + [os.getcwd()]) + call. source=True asks for the flow with each step's code, so it is read without opening files. + start_symbol starts the flow at that declaration. direction (callers, callees or both) and max_depth bound the + walk; token_budget bounds the answer's size. Each is optional: left out, the answer is today's.""" + # interface only: start_symbol and token_budget map to the existing + # --from and --page-budget; direction and max_depth are checked by the CLI and not yet used by the walk + # checked here, in the tool's own words: the CLI's refusal names its flag, and plain() drops a clause that does + if direction.strip() and direction.strip() not in ('callers', 'callees', 'both'): + raise ToolError(f"direction must be callers, callees or both, not {direction!r}") + if max_depth < 0: raise ToolError(f"max_depth must be 1 or more, not {max_depth}") + if token_budget < 0: raise ToolError(f"token_budget must be a positive number of tokens, not {token_budget}") + return answer(['context', task] + (['--source'] if source else []) + + (['--from', start_symbol] if start_symbol.strip() else []) + + (['--direction', direction] if direction.strip() else []) + + (['--depth', str(max_depth)] if max_depth else []) + + (['--page-budget', str(token_budget)] if token_budget else []) + [os.getcwd()]) + +@srv.tool() +def expand_context(continuation_id: str, branch: str = '') -> str: + """Continue a context answer that stopped early: continuation_id as the answer gives it, and branch (optional) + one of the branches it lists as remaining. Not implemented yet: every call is refused.""" + # until the CLI implements --continue, refused here in the tool's own words (its refusal names the flag) + raise ToolError("expand_context is not implemented yet: call context again with the task instead") @srv.tool() def impact(name: str = '') -> str: diff --git a/plugins/axiomcode/skills/axiomcode/SKILL.md b/plugins/axiomcode/skills/axiomcode/SKILL.md index 4978387de..41c44d0ab 100644 --- a/plugins/axiomcode/skills/axiomcode/SKILL.md +++ b/plugins/axiomcode/skills/axiomcode/SKILL.md @@ -99,6 +99,11 @@ source=True)` — source carries each step's code, so the flow is read without o words land (the graph's vocabulary is the code's identifiers); any language works once the task includes one identifier as written in the code. +Optional bounds on the walk (being built): `start_symbol` starts the flow at that declaration and +`token_budget` caps the answer's size; `direction` (callers, callees or both) and `max_depth` are accepted but not +yet used. `expand_context(continuation_id, branch)` will continue an answer that stopped early; it is not +implemented yet. Leave them all out for today's answer. + ## index `axiomcode index` builds the graph explicitly; `--lang` and `--src` narrow it. Never re-run it on an diff --git a/plugins/axiomcode/skills/axiomcode/scripts/ax_web.py b/plugins/axiomcode/skills/axiomcode/scripts/ax_web.py index 573d3b86f..6441c245c 100644 --- a/plugins/axiomcode/skills/axiomcode/scripts/ax_web.py +++ b/plugins/axiomcode/skills/axiomcode/scripts/ax_web.py @@ -46,7 +46,7 @@ def language_of(db): # the options dev's verbs take with a value (review #10, #26): the value is neither the repository nor a target -VALUE_FLAGS = ('--in', '--limit', '--depth', '--kind', '--budget', '--paths', '--page', '--from', '--seeds', '--top', '--tests-in', '--page-budget', '--grep-limit') +VALUE_FLAGS = ('--in', '--limit', '--depth', '--kind', '--budget', '--paths', '--page', '--from', '--seeds', '--top', '--tests-in', '--page-budget', '--grep-limit', '--direction', '--continue', '--branch') def like_esc(s): diff --git a/plugins/axiomcode/skills/axiomcode/scripts/axiomcode b/plugins/axiomcode/skills/axiomcode/scripts/axiomcode index 8b89b0426..4b1b8e4e8 100755 --- a/plugins/axiomcode/skills/axiomcode/scripts/axiomcode +++ b/plugins/axiomcode/skills/axiomcode/scripts/axiomcode @@ -195,7 +195,7 @@ dirlike(){ [[ "$1" =~ :[0-9]+$ ]] && return 1 gone(){ echo "axiomcode $cmd: no such directory: $1 (the repository to ask). Nothing was built or asked; pass a directory that exists, or leave it out to use the current one." >&2; exit 2; } POS=(); skip=""; for a in ${ARGS[@]+"${ARGS[@]}"}; do if [ -n "$skip" ]; then skip=""; continue; fi - case "$a" in --in|--from|--budget|--seeds|--depth|--limit|--tests-in|--kind|--range|--old|--new|--file|--page|--page-budget|--out|--from-text|--top) skip=1; continue ;; -*) continue ;; esac + case "$a" in --in|--from|--budget|--seeds|--depth|--limit|--tests-in|--kind|--range|--old|--new|--file|--page|--page-budget|--out|--from-text|--top|--direction|--continue|--branch) skip=1; continue ;; -*) continue ;; esac POS+=("$a") done LASTPOS=""; [ "${#POS[@]}" -gt 0 ] && LASTPOS="${POS[${#POS[@]}-1]}" @@ -209,7 +209,7 @@ case "$cmd" in esac FR=.; skip=""; for a in ${ARGS[@]+"${ARGS[@]}"}; do if [ -n "$skip" ]; then skip=""; continue; fi - case "$a" in --in|--from|--budget|--seeds|--depth|--limit|--tests-in|--kind|--range|--old|--new|--file|--page|--page-budget|--out) skip=1; continue ;; esac + case "$a" in --in|--from|--budget|--seeds|--depth|--limit|--tests-in|--kind|--range|--old|--new|--file|--page|--page-budget|--out|--direction|--continue|--branch) skip=1; continue ;; esac [ -d "$a" ] && FR="$a" done # --grep (internal: the suites and their cases): the answer's sites one per line, `path:line: code [tag]`, the way diff --git a/plugins/axiomcode/skills/axiomcode/scripts/axiomcode-context b/plugins/axiomcode/skills/axiomcode/scripts/axiomcode-context index df420db32..51ced7724 100755 --- a/plugins/axiomcode/skills/axiomcode/scripts/axiomcode-context +++ b/plugins/axiomcode/skills/axiomcode/scripts/axiomcode-context @@ -1526,7 +1526,13 @@ def print_flow(g, roots, steps, gaps, chosen, show_source=False, marks=None): RESULT = {'task': None, 'repo': None, 'scope': None, 'scope_offered': None, 'terms': [], - 'entry_points': [], 'files': [], 'flow': []} + 'entry_points': [], 'files': [], 'flow': [], + # the walk's own account of where it stopped. Not computed yet, + # so None (unknown), never an empty list that would read as "nothing omitted" + 'depth_reached': None, 'stop_reason': None, 'branches_remaining': None, 'continuation_id': None, + 'unresolved': None, 'omitted': None} + +DIRECTIONS = ('callers', 'callees', 'both') def main(argv): @@ -1540,6 +1546,7 @@ def main(argv): as_json = False explain = None # None: decided from the task's wording; --explain / --no-explain force it starts = [] # --from : where the flow starts, when the caller knows (repeatable) + direction = depth = continuation = branch = None # --direction, --depth, --continue, --branch i = 0 while i < len(argv): a = argv[i] @@ -1554,8 +1561,21 @@ def main(argv): elif a == '--explain': explain = True; i += 1 elif a == '--from' and i + 1 < len(argv): starts.append(argv[i + 1]); explain = True if explain is None else explain; i += 2 elif a == '--no-explain': explain = False; i += 1 + # interface only: parsed and checked so a bad value is refused rather than read as task words; + # the walk does not use them yet + elif a == '--direction' and i + 1 < len(argv): direction = argv[i + 1]; i += 2 + elif a == '--depth' and i + 1 < len(argv): depth = argv[i + 1]; i += 2 + elif a == '--continue' and i + 1 < len(argv): continuation = argv[i + 1]; i += 2 + elif a == '--branch' and i + 1 < len(argv): branch = argv[i + 1]; i += 2 elif a in ('-h', '--help'): print(__doc__); return 0 else: args.append(a); i += 1 + if continuation is not None or branch is not None: + print("context --continue is not implemented yet: ask context again with the task instead") + return 2 + if direction is not None and direction not in DIRECTIONS: + print(f"--direction must be one of {', '.join(DIRECTIONS)}, not {direction!r}"); return 2 + if depth is not None and not (depth.isdigit() and int(depth) >= 1): + print(f"--depth must be a whole number, 1 or more, not {depth!r}"); return 2 if not args: print(__doc__); return 2 task = args[0] repo = args[1] if len(args) > 1 else '.' @@ -2004,7 +2024,7 @@ QUOTED = re.compile(r'"([^"\n]{4,120})"|(? 2): - bad.append(f"{label}: {name} takes {params}, want {TOOLS[name]} (at most two)") + if name in TOOLS and (sorted(params) != sorted(TOOLS[name]) or len(params) > MAX_PARAMS.get(name, 2)): + bad.append(f"{label}: {name} takes {params}, want {TOOLS[name]} (at most {MAX_PARAMS.get(name, 2)})") content = replies.get(3, {}).get('result', {}).get('content', []) if not any(c.get('type') == 'text' and c.get('text') for c in content): bad.append(f"{label}: tools/call returned no text: {replies.get(3)}") diff --git a/tests/mcp_docs.py b/tests/mcp_docs.py index 6884dab3b..c751981fc 100644 --- a/tests/mcp_docs.py +++ b/tests/mcp_docs.py @@ -130,7 +130,7 @@ def controls(tools): got = len(mismatches(documented(text), fake, 'control')) if got != want: bad.append(f"control {text!r}: {got} mismatch(es), want {want}") - if set(tools) != {'context', 'impact', 'link', 'path', 'tests', 'unresolved'}: + if set(tools) != {'context', 'expand_context', 'impact', 'link', 'path', 'tests', 'unresolved'}: bad.append(f"the server listed {sorted(tools)}; the MCP tools were not read") return bad diff --git a/tests/surfaces.py b/tests/surfaces.py index 76f9ece01..e0c38cb60 100644 --- a/tests/surfaces.py +++ b/tests/surfaces.py @@ -33,6 +33,7 @@ NO_MCP = {'index': 'setup, not a question: the first query through the MCP server builds the graph itself', 'report': 'a page for the user, not a question for the agent: the end-of-turn receipt already reaches both', 'graph': 'a page for the user to look at, not an answer for the agent'} +MCP_ONLY = {'expand_context': 'context --continue: the continuation of a context answer, so it is not a second verb'} # dispatched, not advertised: verb -> why INTERNAL = { 'build': 'the old name of index', @@ -123,8 +124,8 @@ def main(): for v in INTERNAL: if v in tools: bad.append(f"{v}: internal, and still an MCP tool") if re.search(r'^## .*\b%s\b' % re.escape(v), skill, re.M): bad.append(f"{v}: internal, and still a SKILL.md section") - if tools != {v for v in PUBLIC if v not in NO_MCP}: - bad.append(f"the MCP tools are {sorted(tools)}, want {sorted(v for v in PUBLIC if v not in NO_MCP)}") + if tools != {v for v in PUBLIC if v not in NO_MCP} | set(MCP_ONLY): + bad.append(f"the MCP tools are {sorted(tools)}, want {sorted({v for v in PUBLIC if v not in NO_MCP} | set(MCP_ONLY))}") for label, text in docs(): bad += doc_findings(label, text)