Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/axiomcode/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>`,
`axiomcode path <A> <B>`, `axiomcode tests`, `axiomcode context "<task>" --source`.
Expand Down
33 changes: 27 additions & 6 deletions plugins/axiomcode/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"(?<![\w(-])--(?:" + _CLI_OPTIONS + r")(?![\w-])(?!\s*:)|\b(?:task|source|name|start|end)=(?:True|False|N\b|<|\d|\"|')")
def plain(text):
out = []; code = False
Expand Down Expand Up @@ -322,13 +322,34 @@ def answer(args):
# THE SMALL SURFACE. Search is grep's job; the graph answers what grep cannot. Three questions, each answered as
# numbered places with the code of the function each sits in, so a place is understood without opening its file,
# plus context, the one narrative verb: a task in words answered as the verb's own flow. No options beyond
# context's source: the repository is the one the session works in.
# context's source and its walk bounds: the repository is the one the session works in.
@srv.tool()
def context(task: str, source: bool = False) -> 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:
Expand Down
5 changes: 5 additions & 0 deletions plugins/axiomcode/skills/axiomcode/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugins/axiomcode/skills/axiomcode/scripts/ax_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions plugins/axiomcode/skills/axiomcode/scripts/axiomcode
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand All @@ -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
Expand Down
24 changes: 22 additions & 2 deletions plugins/axiomcode/skills/axiomcode/scripts/axiomcode-context
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 <name>: 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]
Expand All @@ -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 '.'
Expand Down Expand Up @@ -2004,7 +2024,7 @@ QUOTED = re.compile(r'"([^"\n]{4,120})"|(?<![\w])\'([^\'\n]{4,120})\'(?![\w])|`(


def quoted_text(argv):
skip = {'--budget', '--seeds', '--in', '--from', '--page', '--page-budget'}
skip = {'--budget', '--seeds', '--in', '--from', '--page', '--page-budget', '--direction', '--depth', '--continue', '--branch'}
pos, i = [], 0
while i < len(argv):
if argv[i] in skip: i += 2; continue
Expand Down
7 changes: 4 additions & 3 deletions tests/front_door.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
path answer with numbered places and a fenced code block; after an edit, impact with no name starts with
`your edits:`, and tests lists the test with its code and ends with a `run:` line. A verb off the surface is
refused with the supported list.
b. the MCP server lists exactly context, impact, path, tests, link and unresolved, each with at most two parameters, and a call to one
b. the MCP server lists exactly context, expand_context, impact, path, tests, link and unresolved, each with at most two
parameters but context (its walk bounds), and a call to one
answers in the same shape.
c. CONTROLS: the dispatcher run directly, bin/axiomcode with --json, and AXIOMCODE_RAW=1 give the old answer — no
fenced block — for the same question.
Expand Down Expand Up @@ -130,8 +131,8 @@ def main():
# ── b. the MCP server ──────────────────────────────────────────────────────────────────────────────────────
got = mcp(repo, [('path', {'start': 'total', 'end': 'vat_rate'}), ('impact', {'name': 'vat_rate'})])
tools = {t['name']: list((t.get('inputSchema') or {}).get('properties', {})) for t in got.get(2, {}).get('tools', [])}
check('MCP tools/list is exactly context, impact, path, tests, link and unresolved (search is grep\'s)', set(tools) == {'context', 'impact', 'path', 'tests', 'link', 'unresolved'}, tools)
check('MCP: every tool takes at most two parameters', bool(tools) and all(len(p) <= 2 for p in tools.values()), tools)
check('MCP tools/list is exactly context, expand_context, impact, path, tests, link and unresolved (search is grep\'s)', set(tools) == {'context', 'expand_context', 'impact', 'path', 'tests', 'link', 'unresolved'}, tools)
check('MCP: every tool but context takes at most two parameters', bool(tools) and all(len(p) <= (6 if n == 'context' else 2) for n, p in tools.items()), tools)
text = lambda i: ''.join(c.get('text', '') for c in got.get(i, {}).get('content', []))
check('MCP path answers as numbered places with their code', places(text(3)), text(3)[:600])
check('MCP impact answers as numbered places with their code', places(text(4)) and 'shop/pricing.py:6' in text(4), text(4)[:600])
Expand Down
14 changes: 9 additions & 5 deletions tests/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@
SERVER = os.path.join(ROOT, 'plugins', 'axiomcode', 'mcp', 'server.py')
# THE SMALL SURFACE: four questions, each with at most two parameters and no options. The front-door answer is capped
# at ten places with the rest counted, so no tool is paged. context is the one narrative verb: a task in words,
# answered as the verb's own flow rather than as places.
TOOLS = {'context': ['task', 'source'], 'impact': ['name'], 'path': ['start', 'end'], 'tests': [], 'link': ['site', 'target'],
'unresolved': ['limit', 'decisions']}
# answered as the verb's own flow rather than as places. ONE EXCEPTION: context
# also takes optional bounds on its walk, and expand_context continues an answer that stopped early; each bound left
# out gives today's answer.
TOOLS = {'context': ['task', 'source', 'start_symbol', 'direction', 'max_depth', 'token_budget'], 'impact': ['name'],
'path': ['start', 'end'], 'tests': [], 'link': ['site', 'target'], 'unresolved': ['limit', 'decisions'],
'expand_context': ['continuation_id', 'branch']}
MAX_PARAMS = {'context': 6}


def exchange(cmd, cwd, env=None, workdir=None):
Expand Down Expand Up @@ -375,8 +379,8 @@ def check(label, cmd, cwd, env=None, workdir=None, want_err=None):
if set(listed) != set(TOOLS):
bad.append(f"{label}: tools/list gave {sorted(listed)}, want {sorted(TOOLS)}")
for name, params in listed.items():
if name in TOOLS and (sorted(params) != sorted(TOOLS[name]) or len(params) > 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)}")
Expand Down
2 changes: 1 addition & 1 deletion tests/mcp_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions tests/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)

Expand Down
Loading