@allansantos-dev/smart-tool 0.9.68 → 0.9.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,7 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.70 - beta
4
+
5
+ - `project_manage list` no longer fails as a whole when a registered folder was deleted inside a Git repository (a removed
6
+ worktree): that project shows as `unavailable` with "The project folder no longer exists", and `status` on it says so.
7
+ - A search of a folder that holds other registered projects names each one (files indexed, `project_root` to search it),
8
+ because each keeps its own index and its files are not in the outer results. `project_manage status` with a path inside a
9
+ registered project answers for the deepest project that holds it and returns `resolved_from`.
10
+ Tests: `tests/test_nested_projects.py`, `tests/test_agent_efficiency.py`.
11
+
12
+ ## 0.9.69 - beta
13
+
14
+ - `smart_search` answers leaner by default: `detail=compact` cuts each excerpt to whole lines within 240 characters (was 500)
15
+ and leaves out the usual values of `ranking` (`rerank`), `location_kind` (`source_line`) and an empty `symbols`; path:lines,
16
+ score and name:line symbols stay, and the ranked places are the same. `detail=full` returns the previous answer. Measured on
17
+ 8 fixed queries with `tests/search_size_probe.py`: see `docs/research/data/search-size-before.json` and `-after.json`.
18
+ Test: `tests/test_search_detail.py`.
19
+
3
20
  ## 0.9.68 - beta
4
21
 
22
+ - A routed search is answered, not denied, when the host sends no `tool_use_id` or the query cannot be read from the
23
+ command: the Smart Tool answer goes into the call's context (Codex shell: the command prints it) and, without an
24
+ answer in time or without a query, the context names the exact `smart_search` call. `deny` stays only for edits the
25
+ docs and comment rules require redone.
5
26
  - Another tool's marked block in Codex's `config.toml` survives Smart Tool's writes byte for byte. The in-place edit shipped in
6
27
  0.9.67 is now covered for the hook approval record too (`tests/test_codex_audit_hook.py`), the `set_codex_disabled`
7
28
  docstring describes the one-line insert, and `docs/research/2026-11-08-codex-config-marker-who-rewrites.md` lists every
package/README.md CHANGED
@@ -17,7 +17,7 @@ registered as the `playwright` server where this machine lets a browser be drive
17
17
  An optional hook routes the agent's native Grep/Glob/Read/Bash/WebSearch/WebFetch calls to these tools when they
18
18
  are cheaper, or just tells the agent what Smart Tool would do.
19
19
 
20
- **Status:** 0.9.68 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
20
+ **Status:** 0.9.70 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
21
21
 
22
22
  ## How it works
23
23
 
@@ -83,7 +83,7 @@ gateway such as Ollama, nothing about your code leaves the machine.
83
83
  ## Install
84
84
 
85
85
  ```powershell
86
- npx @allansantos-dev/smart-tool@0.9.68 install
86
+ npx @allansantos-dev/smart-tool@0.9.70 install
87
87
  ```
88
88
 
89
89
  Updates install themselves, on by default: the tray checks npm when it starts (at logon) and every 24 h, and when there
package/atomic_io.py CHANGED
@@ -3,6 +3,8 @@
3
3
  do Smart Tool."""
4
4
  import glob
5
5
  import os
6
+ import re
7
+ import shutil
6
8
  import time
7
9
  import uuid
8
10
 
@@ -98,3 +100,40 @@ def write_text(final_path, text, encoding="utf-8"):
98
100
  """Atomic text write of a file other programs and people read and edit (project files): the same temp, fsync and
99
101
  replace as write_secret_text, with the permissions the user's umask gives a new file."""
100
102
  _write_and_replace(final_path, text, encoding=encoding, permissions=0o666)
103
+
104
+
105
+ BACKUP_INFIX = ".smart-tool-backup-"
106
+ _BACKUP_STAMP = re.compile(r"^(\d{8}-\d{6})(?:-(\d+))?$")
107
+
108
+
109
+ def backup_file(path, keep=None):
110
+ """Copies path to a timestamped `.smart-tool-backup-` file beside it and returns that path, None when path does not
111
+ exist. A second backup in the same second gets a numbered name, so it never overwrites the copy of an earlier step.
112
+ With keep, only that many of the newest copies of path stay; other files with a similar name are left alone."""
113
+ if not os.path.exists(path):
114
+ return None
115
+ moment = time.strftime("%Y%m%d-%H%M%S")
116
+ number = max((order[1] for _, order in _backups(path, moment)), default=0) + 1
117
+ backup = f"{path}{BACKUP_INFIX}{moment}" + (f"-{number}" if number > 1 else "")
118
+ shutil.copy2(path, backup)
119
+ if keep is not None:
120
+ _prune_backups(path, keep)
121
+ return backup
122
+
123
+
124
+ def _backups(path, stamp=None):
125
+ """(path, number) of the `.smart-tool-backup-` copies of path, only those of one stamp when given; the copy named
126
+ with the bare stamp is number 1."""
127
+ copies = []
128
+ for candidate in glob.glob(glob.escape(path + BACKUP_INFIX) + "*"):
129
+ found = _BACKUP_STAMP.match(candidate[len(path + BACKUP_INFIX):])
130
+ if found and stamp in (None, found.group(1)):
131
+ copies.append((candidate, (found.group(1), int(found.group(2) or 1))))
132
+ return copies
133
+
134
+
135
+ def _prune_backups(path, keep):
136
+ """Deletes all but the `keep` newest `.smart-tool-backup-` copies of path (newest = latest stamp, then number)."""
137
+ copies = sorted(_backups(path), key=lambda copy: copy[1])
138
+ for candidate, _ in copies[:max(len(copies) - keep, 0)]:
139
+ os.remove(candidate)
package/client_hooks.py CHANGED
@@ -7,6 +7,8 @@ import sys
7
7
  import time
8
8
  import tomllib
9
9
 
10
+ import atomic_io
11
+ import codex_config
10
12
  import daemon_launcher
11
13
  import endpoint_sync
12
14
 
@@ -282,24 +284,10 @@ def install(client_info, token, confirm):
282
284
  "after_install": spec.get("after_install")}
283
285
 
284
286
 
285
- def backup_file(path):
286
- """Copies path to a timestamped `.smart-tool-backup-` file beside it and returns that path, None when path does not
287
- exist. A second backup in the same second gets a numbered name, so it never overwrites the copy of an earlier step."""
288
- if not os.path.exists(path):
289
- return None
290
- stamp = f"{path}.smart-tool-backup-{time.strftime('%Y%m%d-%H%M%S')}"
291
- backup, number = stamp, 1
292
- while os.path.exists(backup):
293
- number += 1
294
- backup = f"{stamp}-{number}"
295
- shutil.copy2(path, backup)
296
- return backup
297
-
298
-
299
287
  def _write_checked(path, data, verify, what):
300
288
  """Writes data as JSON to path through a temp file after a timestamped backup; when verify() fails on the written
301
289
  file, restores the backup (or removes the new file) and raises. Returns the backup path (None for a new file)."""
302
- backup = backup_file(path)
290
+ backup = atomic_io.backup_file(path)
303
291
  os.makedirs(os.path.dirname(path), exist_ok=True)
304
292
  temporary = path + ".smart-tool-tmp"
305
293
  with open(temporary, "w", encoding="utf-8") as stream:
@@ -393,13 +381,13 @@ def _codex_states(path=None):
393
381
  return states if isinstance(states, dict) else {}
394
382
 
395
383
 
396
- def _codex_trusted(event, groups, is_ours):
384
+ def _codex_trusted(event, groups, is_ours, hooks_path=None, config_path=None):
397
385
  """Our handler under `event` is trusted in Codex's config.toml: the entry keyed by hooks.json path, event, group
398
386
  and handler index holds the hash of the definition as it is now (a missing or different hash means Codex does not
399
- run it). An unreadable config.toml raises ValueError."""
400
- states = _codex_states()
387
+ run it). The paths default to Codex's own. An unreadable config.toml raises ValueError."""
388
+ states = _codex_states(config_path)
401
389
  name = _codex_event(event)
402
- path = CLIENTS["codex"]["files"][0]
390
+ path = hooks_path or CLIENTS["codex"]["files"][0]
403
391
  for group_index, group in enumerate(groups):
404
392
  if not _ours(group, is_ours):
405
393
  continue
@@ -511,7 +499,7 @@ def record_codex_trust(wanted, path=None):
511
499
  lines = text.splitlines(keepends=True)
512
500
  for key, value in wanted.items():
513
501
  lines = _with_trusted_hash(lines, key, value, newline)
514
- backup = backup_file(path)
502
+ backup = atomic_io.backup_file(path, keep=codex_config.BACKUPS_KEPT)
515
503
  os.makedirs(os.path.dirname(path), exist_ok=True)
516
504
  temporary = path + ".smart-tool-tmp"
517
505
  with open(temporary, "w", encoding="utf-8", newline="") as stream:
@@ -550,6 +538,27 @@ def audit_state(client="claude"):
550
538
  return "current" if client != "codex" or _codex_trusted("SessionStart", groups, _audit_hook) else AUDIT_WAITING
551
539
 
552
540
 
541
+ def codex_unapproved(hooks_path, config_path):
542
+ """Events whose hook of ours is written in the Codex hooks.json at hooks_path while the config.toml at config_path
543
+ holds no matching approval (`[hooks.state]` trusted_hash), so Codex does not run it. Reads both files, writes
544
+ nothing; [] when hooks.json is missing or holds none of ours. An unreadable config.toml raises ValueError."""
545
+ try:
546
+ with open(hooks_path, encoding="utf-8") as stream:
547
+ data = json.load(stream)
548
+ except FileNotFoundError:
549
+ return []
550
+ hooks = data.get("hooks") if isinstance(data, dict) else None
551
+ if not isinstance(hooks, dict):
552
+ return []
553
+ unapproved = []
554
+ for event, is_ours in [*((event, _our_hook) for event in _entries("codex")), ("SessionStart", _audit_hook)]:
555
+ groups = hooks.get(event)
556
+ if isinstance(groups, list) and any(_ours(group, is_ours) for group in groups) \
557
+ and not _codex_trusted(event, groups, is_ours, hooks_path, config_path):
558
+ unapproved.append(event)
559
+ return unapproved
560
+
561
+
553
562
  def audit_hook_installed(client):
554
563
  """The session-start hook is on and running (Codex: trusted in config.toml), so a search need not repeat the redirect
555
564
  proposals it already carries.
package/codex_config.py CHANGED
@@ -11,6 +11,7 @@ import tomllib
11
11
  import atomic_io
12
12
 
13
13
  _BARE_KEY = re.compile(r"^[A-Za-z0-9_-]+$")
14
+ BACKUPS_KEPT = 10
14
15
 
15
16
 
16
17
  def _header_path(line):
@@ -83,8 +84,9 @@ def _others(text, name):
83
84
 
84
85
 
85
86
  def _write(path, before, after, name, fields):
86
- """Writes after (the edited text) when it parses, holds exactly `fields` for the server and changed nothing else.
87
- Raises ValueError otherwise, leaving the file alone."""
87
+ """Writes after (the edited text) when it parses, holds exactly `fields` for the server and changed nothing else,
88
+ after a numbered backup beside the file (the newest BACKUPS_KEPT stay). Raises ValueError otherwise, leaving the
89
+ file alone."""
88
90
  try:
89
91
  parsed = tomllib.loads(after)
90
92
  unchanged = _others(after, name) == _others(before, name)
@@ -95,6 +97,7 @@ def _write(path, before, after, name, fields):
95
97
  raise ValueError(f"Editing [mcp_servers.{name}] in {path} would change more than that table "
96
98
  f"(a layout this editor does not handle); edit the file by hand.")
97
99
  os.makedirs(os.path.dirname(path), exist_ok=True)
100
+ atomic_io.backup_file(path, keep=BACKUPS_KEPT)
98
101
  atomic_io.write_text(path, after)
99
102
 
100
103
 
package/doc_insights.py CHANGED
@@ -17,6 +17,8 @@ from collections import Counter, defaultdict
17
17
 
18
18
  import affected_tests
19
19
  import doc_scope
20
+ import index_views
21
+ import project_identity
20
22
 
21
23
  MAX_COMMITS = 3000
22
24
  MAX_ROWS = 25
@@ -31,6 +33,8 @@ SIMPLE_TERMS = 12
31
33
  ADR_CANDIDATES = 25
32
34
  ADR_DRAFTS = 5
33
35
  _FIELD, _RECORD = "\x1f", "\x1e"
36
+ HISTORIES_KEPT = 8
37
+ _histories = {}
34
38
  _MANIFEST = re.compile(r"(^|/)(package\.json|requirements[\w.-]*\.txt|go\.mod|pom\.xml|pyproject\.toml|build\.gradle(\.kts)?)$")
35
39
  _DECISION = re.compile(r"\b(decid\w*|replac\w*|switch\w*|migrat\w*|adopt\w*|drop\w*|instead of|introduc\w*|because)\b", re.I)
36
40
  _HTTP_VERB = re.compile(r"^do_[A-Z]+$")
@@ -44,9 +48,33 @@ _STOP = frozenset("""get set add is has are was the and for not with from into t
44
48
  def history(root):
45
49
  """Commits of the project's git history, newest first, with the project-relative files each touched.
46
50
 
51
+ One `git log` of up to MAX_COMMITS commits is the costliest step of a documentation run, and a run reads the history
52
+ more than once (prose writing generates the scope before and after), so the answer is reused while the Git view's
53
+ stamp (HEAD, index, reflog, packed-refs, branch ref) has not moved; checking it is a stat, no process.
54
+
47
55
  Returns: (commits, note): commits is a list of {hash, time, subject, body, files}; note is None, or the reason no
48
- history could be read (not a git repository, git missing), which the page shows in place of the table.
56
+ history could be read (not a git repository, git missing), which the page shows in place of the table. The
57
+ returned lists are shared with later calls and must not be changed.
49
58
  """
59
+ try:
60
+ view = index_views.describe(root, fresh=True)
61
+ except (RuntimeError, ValueError, OSError):
62
+ view = None
63
+ if not view or not view.get("git"):
64
+ return _read_history(root)
65
+ key = project_identity.canonical_root(root)
66
+ saved = _histories.get(key)
67
+ if saved and saved[0] == view["stamp"]:
68
+ return saved[1]
69
+ result = _read_history(root)
70
+ if not index_views.stamp_changed(view):
71
+ if len(_histories) >= HISTORIES_KEPT:
72
+ _histories.clear()
73
+ _histories[key] = (view["stamp"], result)
74
+ return result
75
+
76
+
77
+ def _read_history(root):
50
78
  try:
51
79
  raw = affected_tests._git(root, "-c", "core.quotepath=false", "log", "--no-merges", f"-n{MAX_COMMITS}", "--relative",
52
80
  "--name-status", "-M", f"--pretty=format:{_RECORD}%h{_FIELD}%ct{_FIELD}%s{_FIELD}%b{_FIELD}", "--", ".")
package/hook_decision.py CHANGED
@@ -7,10 +7,12 @@ Uma busca nativa que a regra redireciona, e WebFetch/WebSearch, não são negada
7
7
  texto volta como saída da própria chamada (`tool_redirect`). INVARIANTE: a saída do PreToolUse é `{}`, `updatedInput`
8
8
  sem `permissionDecision` (as regras de permissão do usuário julgam a chamada reescrita), `allow` só junto do comando
9
9
  que o próprio hook escreveu para imprimir a resposta no Codex (`tool_redirect.is_codex_command`), ou `deny` quando a
10
- chamada não dá para montar. Nenhuma decisão aqui é sobre periculosidade, só sobre custo de contexto. Diagnóstico vai em
11
- `systemMessage`, que não altera permissão.
10
+ edição que a regra de documentação ou de comentário exige refazer (`_edit_review`); uma busca sem `tool_use_id` ou sem
11
+ consulta legível nunca é negada: é respondida no contexto (`_answer_in_place`). Diagnóstico vai em `systemMessage`, que
12
+ não altera permissão.
12
13
  """
13
14
  import os
15
+ import uuid
14
16
 
15
17
  import affected_tests
16
18
  import code_graph
@@ -372,7 +374,50 @@ def decide(payload, client, web_route, jobs):
372
374
  return _redirect(payload, client, plan, jobs)
373
375
  if not agent_has_smart_tool(payload.get("agent_type") if payload.get("agent_id") else None, payload.get("cwd")):
374
376
  return {}
375
- return deny(plan["message"])
377
+ return _answer_in_place(payload, client, plan, jobs)
378
+
379
+
380
+ def _start_job(payload, client, plan, jobs, key):
381
+ """Starts the Smart Tool call of a redirected one under key (web calls carry the requester of the hook)."""
382
+ who = requester.CURRENT.set(requester.from_hook(client, payload)) if payload["tool_name"] in WEB_TOOLS else None
383
+ try:
384
+ jobs.start(key, plan["kind"], plan["arguments"])
385
+ finally:
386
+ if who is not None:
387
+ requester.CURRENT.reset(who)
388
+
389
+
390
+ def _codex_print(payload, client, jobs, key, text):
391
+ """Codex shell call rewritten to print the answer; `allow` is what Codex needs to apply the rewrite."""
392
+ tool_input = payload.get("tool_input") if isinstance(payload.get("tool_input"), dict) else {}
393
+ jobs.forget(key)
394
+ _log_served(client, payload)
395
+ return {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "allow",
396
+ "permissionDecisionReason": "Smart Tool answered this search",
397
+ "updatedInput": {**tool_input, "command": tool_redirect.codex_command(text)}}}
398
+
399
+
400
+ def _answer_in_place(payload, client, plan, jobs):
401
+ """A redirected call that cannot be swapped by `tool_use_id` (no id, or no query to run) is still not denied: the
402
+ Smart Tool answer goes into the context of the call, which runs as written, and a codex shell search prints it.
403
+ Without an answer in time, or without a query, the context names the exact Smart Tool call to make."""
404
+ if not agent_has_smart_tool(payload.get("agent_type") if payload.get("agent_id") else None, payload.get("cwd")):
405
+ return {}
406
+ if not plan["kind"]:
407
+ return advise(plan["message"])
408
+ key = f"noid-{uuid.uuid4().hex}"
409
+ _start_job(payload, client, plan, jobs, key)
410
+ text = _answer(jobs, key, PRE_WAIT_S, payload["tool_name"])
411
+ if text is None:
412
+ jobs.forget(key)
413
+ return advise(plan["message"])
414
+ if client == "codex" and payload["tool_name"] in tool_redirect.NO_OP:
415
+ return _codex_print(payload, client, jobs, key, text)
416
+ jobs.forget(key)
417
+ _log_served(client, payload)
418
+ return {"hookSpecificOutput": {"hookEventName": "PreToolUse",
419
+ "additionalContext": f"Smart Tool answered this {payload['tool_name']} call with "
420
+ f"smart_search (the call was not blocked):\n{text}"}}
376
421
 
377
422
 
378
423
  def _redirect(payload, client, plan, jobs):
@@ -382,12 +427,7 @@ def _redirect(payload, client, plan, jobs):
382
427
  else runs as the agent wrote it and, in Claude Code, `after` swaps its output for the answer."""
383
428
  key, tool_name = payload["tool_use_id"], payload["tool_name"]
384
429
  tool_input = payload.get("tool_input") if isinstance(payload.get("tool_input"), dict) else {}
385
- who = requester.CURRENT.set(requester.from_hook(client, payload)) if tool_name in WEB_TOOLS else None
386
- try:
387
- jobs.start(key, plan["kind"], plan["arguments"])
388
- finally:
389
- if who is not None:
390
- requester.CURRENT.reset(who)
430
+ _start_job(payload, client, plan, jobs, key)
391
431
  if tool_name not in tool_redirect.NO_OP:
392
432
  return {}
393
433
  text = _answer(jobs, key, PRE_WAIT_S, tool_name)
@@ -396,11 +436,7 @@ def _redirect(payload, client, plan, jobs):
396
436
  if client != "codex":
397
437
  return {"hookSpecificOutput": {"hookEventName": "PreToolUse",
398
438
  "updatedInput": {**tool_input, "command": tool_redirect.NO_OP[tool_name]}}}
399
- jobs.forget(key)
400
- _log_served(client, payload)
401
- return {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "allow",
402
- "permissionDecisionReason": "Smart Tool answered this search",
403
- "updatedInput": {**tool_input, "command": tool_redirect.codex_command(text)}}}
439
+ return _codex_print(payload, client, jobs, key, text)
404
440
 
405
441
 
406
442
  def _answer(jobs, key, timeout, tool_name):
package/index_views.py CHANGED
@@ -96,6 +96,8 @@ def _resolve(root, key):
96
96
  view = {'root': key, 'git': False, 'view_id': 'workspace', 'label': 'Folder without Git',
97
97
  'branch': None, 'commit': None}
98
98
  if _git_marker(root):
99
+ if not os.path.isdir(root):
100
+ raise FileNotFoundError(f'The project folder no longer exists: {root}. Relocate or remove the project.')
99
101
  if not shutil.which('git'):
100
102
  raise RuntimeError('This folder contains Git, but the git executable is not available.')
101
103
  paths = _run(root, 'rev-parse', '--path-format=absolute', '--show-toplevel', '--absolute-git-dir', '--git-common-dir').splitlines()
package/install.py CHANGED
@@ -13,6 +13,7 @@ import urllib.request
13
13
  import venv
14
14
  from pathlib import Path
15
15
 
16
+ import atomic_io
16
17
  import client_hooks
17
18
  import paths
18
19
  import version
@@ -199,7 +200,7 @@ def remove_other_installs(target):
199
200
  text = _repointed(original, folder, target)
200
201
  if text != original:
201
202
  trust = client_hooks.repoint_trust(str(path), original, text) if path == codex else {}
202
- client_hooks.backup_file(str(path))
203
+ atomic_io.backup_file(str(path))
203
204
  path.write_text(text, encoding="utf-8")
204
205
  client_hooks.record_codex_trust(trust, str(path.with_name("config.toml")))
205
206
  print(f"Hooks in {path} now point to {target}.")
@@ -954,6 +954,10 @@
954
954
  "In {0}, remove `|| true`, `exit 0` and `2>/dev/null` from the command of this {1} hook so its failures show.",
955
955
  "Register MCP server '{0}' for this agent, or delete this {1} hook from {2}.",
956
956
  ", or list the duplicated tools in disabled_tools of one of them.",
957
- "Start the service that listens at {0}, or delete this {1} hook from {2}."
957
+ "Start the service that listens at {0}, or delete this {1} hook from {2}.",
958
+ "Smart Tool's {0} hook is written in hooks.json, but {1} holds no matching approval ([hooks.state] trusted_hash): Codex does not run the hook. The approval is lost when something rewrites config.toml or when the hook changes.",
959
+ "Open /hooks in Codex and approve the Smart Tool entry, or turn the Smart Tool hook off and on again in the setup screen, which records the approval.",
960
+ "{0} holds a block another tool keeps between `# >>> {1} >>>` markers. Smart Tool edits only its own tables there and leaves the block as it is.",
961
+ "Nothing to do. If the markers or the block disappear, the tool that manages '{0}' rewrote {1}; restore it from the newest `{2}.smart-tool-backup-*` copy or run that tool's own repair."
958
962
  ]
959
963
  }
package/package.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "name": "@allansantos-dev/smart-tool",
3
- "version": "0.9.68",
4
- "description": "Local MCP server that gives coding agents (Claude Code, Codex) cheaper, sharper tools than their built-in search. Windows.",
5
- "license": "Apache-2.0",
6
- "author": "Smart Tool contributors",
7
- "homepage": "https://allansantos-dv.github.io/smart-tool/",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/AllanSantos-DV/smart-tool-dist.git"
11
- },
12
- "keywords": [
13
- "mcp",
14
- "claude-code",
15
- "codex",
16
- "semantic-search",
17
- "web-search",
18
- "coding-agent"
19
- ],
20
- "bin": {
21
- "smart-tool": "bin/smart-tool.mjs"
22
- },
23
- "os": [
24
- "win32"
25
- ],
26
- "cpu": [
27
- "x64"
28
- ],
29
- "engines": {
30
- "node": ">=18"
31
- },
32
- "publishConfig": {
33
- "access": "public"
34
- }
35
- }
1
+ {
2
+ "name": "@allansantos-dev/smart-tool",
3
+ "version": "0.9.70",
4
+ "description": "Local MCP server that gives coding agents (Claude Code, Codex) cheaper, sharper tools than their built-in search. Windows.",
5
+ "license": "Apache-2.0",
6
+ "author": "Smart Tool contributors",
7
+ "homepage": "https://allansantos-dv.github.io/smart-tool/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/AllanSantos-DV/smart-tool-dist.git"
11
+ },
12
+ "keywords": [
13
+ "mcp",
14
+ "claude-code",
15
+ "codex",
16
+ "semantic-search",
17
+ "web-search",
18
+ "coding-agent"
19
+ ],
20
+ "bin": {
21
+ "smart-tool": "bin/smart-tool.mjs"
22
+ },
23
+ "os": [
24
+ "win32"
25
+ ],
26
+ "cpu": [
27
+ "x64"
28
+ ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ }
35
+ }
@@ -1,12 +1,30 @@
1
1
  """Identidade única de raízes e contenção de caminhos, inclusive junctions Windows."""
2
2
  import hashlib
3
3
  import os
4
+ import time
5
+
6
+ RESOLVED_TTL_S = 3
7
+ RESOLVED_MAX = 4096
8
+ _resolved = {}
4
9
 
5
10
 
6
11
  def display_root(root):
12
+ """Absolute path of `root` with symlinks and junctions resolved. Resolving costs one filesystem call per path
13
+ component on Windows, and the daemon asks for the same few paths thousands of times in a row (per file of an
14
+ index pass, per project of every monitor tick), so an answer is reused for RESOLVED_TTL_S seconds: a junction
15
+ retargeted inside that window is seen after it."""
7
16
  if not isinstance(root, (str, os.PathLike)) or not str(root).strip():
8
17
  raise ValueError("Provide the project folder.")
9
- return os.path.realpath(os.path.abspath(os.path.expanduser(os.fspath(root))))
18
+ absolute = os.path.abspath(os.path.expanduser(os.fspath(root)))
19
+ now = time.monotonic()
20
+ hit = _resolved.get(absolute)
21
+ if hit and now - hit[0] < RESOLVED_TTL_S:
22
+ return hit[1]
23
+ real = os.path.realpath(absolute)
24
+ if len(_resolved) >= RESOLVED_MAX:
25
+ _resolved.clear()
26
+ _resolved[absolute] = (now, real)
27
+ return real
10
28
 
11
29
 
12
30
  def canonical_root(root):
package/setup_audit.py CHANGED
@@ -30,6 +30,7 @@ import urllib.request
30
30
  import yaml
31
31
 
32
32
  import atomic_io
33
+ import client_hooks
33
34
  import endpoint_sync
34
35
  import paths
35
36
 
@@ -345,7 +346,9 @@ def _collect_codex_plugins(config, snapshot):
345
346
 
346
347
  def collect_codex(project, snapshot):
347
348
  """Codex's effective set for project: config.toml (MCP, hooks), hooks.json, skills, AGENTS.md chain."""
348
- config = snapshot.toml(os.path.join(codex_dir(), "config.toml")) or {}
349
+ config_path = os.path.join(codex_dir(), "config.toml")
350
+ config = snapshot.toml(config_path) or {}
351
+ config_text = snapshot.read(config_path)
349
352
  mcp = _mcp_entries(config.get("mcp_servers"), "user", os.path.join(codex_dir(), "config.toml"))
350
353
  hooks = _hooks_from(snapshot.json(os.path.join(codex_dir(), "hooks.json")), "hooks.json",
351
354
  os.path.join(codex_dir(), "hooks.json"))
@@ -375,7 +378,13 @@ def collect_codex(project, snapshot):
375
378
  instructions.append({"path": os.path.join(folder, name), "kind": "project",
376
379
  "bytes": len(text.encode("utf-8")), "_text": text})
377
380
  break
378
- return {"plugins": plugins, "hooks": hooks, "mcp": mcp, "skills": skills, "instructions": instructions}
381
+ try:
382
+ unapproved = client_hooks.codex_unapproved(os.path.join(codex_dir(), "hooks.json"), config_path)
383
+ except ValueError:
384
+ unapproved = []
385
+ return {"plugins": plugins, "hooks": hooks, "mcp": mcp, "skills": skills, "instructions": instructions,
386
+ "configs": [{"path": config_path, "_text": config_text}] if config_text is not None else [],
387
+ "unapproved": unapproved}
379
388
 
380
389
 
381
390
  def _finding(check, severity, harness, subject, detail, source, action, evidence=()):
@@ -589,6 +598,37 @@ def check_instructions(project, claude, codex):
589
598
  return findings
590
599
 
591
600
 
601
+ _MARKED_BLOCK_RE = re.compile(r"^[ \t]*#[ \t]*>>>[ \t]*(.+?)[ \t]*>>>[ \t]*$", re.MULTILINE)
602
+
603
+
604
+ def check_codex_config(codex):
605
+ """Blocks other tools keep between marker comments in Codex's config.toml (listed, nothing to fix) and Smart Tool
606
+ hooks written in hooks.json that config.toml holds no approval for (`[hooks.state]` trusted_hash), which Codex then
607
+ does not run."""
608
+ findings = []
609
+ for config in codex["configs"]:
610
+ for name in dict.fromkeys(_MARKED_BLOCK_RE.findall(config["_text"])):
611
+ findings.append(_finding("codex_config_foreign_block", "info", "codex", name,
612
+ f"{config['path']} holds a block another tool keeps between `# >>> {name} >>>` "
613
+ "markers. Smart Tool edits only its own tables there and leaves the block as it is.",
614
+ DOCS["codex_hooks"],
615
+ f"Nothing to do. If the markers or the block disappear, the tool that manages "
616
+ f"'{name}' rewrote {config['path']}; restore it from the newest "
617
+ f"`{config['path']}.smart-tool-backup-*` copy or run that tool's own repair.",
618
+ [config["path"]]))
619
+ for event in codex["unapproved"]:
620
+ path = os.path.join(codex_dir(), "config.toml")
621
+ findings.append(_finding("codex_hook_unapproved", "warn", "codex", event,
622
+ f"Smart Tool's {event} hook is written in hooks.json, but {path} holds no matching "
623
+ "approval ([hooks.state] trusted_hash): Codex does not run the hook. The approval is "
624
+ "lost when something rewrites config.toml or when the hook changes.",
625
+ DOCS["codex_hooks"],
626
+ "Open /hooks in Codex and approve the Smart Tool entry, or turn the Smart Tool hook off "
627
+ "and on again in the setup screen, which records the approval.",
628
+ [path]))
629
+ return findings
630
+
631
+
592
632
  def _rpc_stdio(entry, cwd, timeout):
593
633
  """initialize + tools/list over stdio; {"tools": [...]} or {"error", "kind": missing|down|timeout}."""
594
634
  command = entry["command"]
@@ -810,6 +850,7 @@ def run(project, probe=True, save=True, probe_max_age=0, trigger="manual"):
810
850
  findings += check_mcp(harness, data["mcp"], results)
811
851
  findings += check_agents(claude)
812
852
  findings += check_instructions(project, claude, codex)
853
+ findings += check_codex_config(codex)
813
854
  unverified = list(snapshot.unverified)
814
855
  if not probe:
815
856
  unverified.append("MCP servers and HTTP hook endpoints were not contacted (probe off)")
@@ -369,7 +369,7 @@ SERVER_INSTRUCTIONS = (
369
369
  TOOLS = [
370
370
  {
371
371
  "name": "project_manage",
372
- "description": "Manages folders and indexing. Every action takes project_root (the folder) or project_id. list gives a short line per project; status shows storage, scope and jobs. graph with symbol (function, Class.method, class name, or path::name when the name repeats) answers what an edit touches: definition, callers with line, calls, tests that reach it through static calls (depth hops, default 3) and files importing it; use it before changing a function to know what to update. affected_tests answers which tests to run after editing: every test file importing a changed file (git diff against base, default HEAD, untracked included) plus changed tests, likeliest failures first, with the command to run them and run_all when config or unanalyzed code changed. pr_impact (base, default HEAD; main or origin/main for a branch) returns a Markdown report of the change for a pull request: the functions the diff touches with their callers, the documentation entries it leaves out of date and the tests to run with their command; it publishes nothing. graph without symbol reads the indexed view: coverage, references and static calls in Java, Angular, Python, Go and JS/TS/JSX/TSX; includes HTML/CSS/Markdown references and TXT/DOCX coverage; with file_path, narrows to that file's symbols, imports and calls (lists capped by limit). inspect lists the files of a view_id; with file_path, returns only that file's chunks. usage shows consumption and reuse; docs lists public functions without a docstring (Python docstring, JSDoc, Javadoc, Go doc comment starting with the name; private, nested and override functions excluded) with coverage percent, excluding tests unless include_tests=true, for documenting a project that started without it; docs generate=true writes the documentation scope to docs/scope in the project in three levels tied to the code: technical pages by folder (an entry per public function anchored on path::name with signature, first doc line, layer, callers, calls and tests, plus a Mermaid flow by layer), functional.md (each entry point and the functions its flow reaches, by layer) and simple.md; the prose between the prose markers is kept by regeneration; docs write_prose=true writes the empty prose blocks with the Docs model of the setup (each paragraph checked against the code first) within about 40 s and says how many are left, call it again until none is; docs check=true reports anchors whose function changed signature or is gone and broken links; docs validate=true checks every claim of docs/scope against the code (anchors, links, line numbers, callers and tests, coverage, entry points, command-line options, prose names, counts, glossary, navigation, versions) and writes docs/scope/validation.md with pass/fail per check, the evidence, a score and the verdict (generate runs it too); docs with symbol lists where that function is documented; layers declares the project's layers (ordered highest first, each with path globs and annotations): without layers it returns the saved rule or a suggestion read from folder names and annotations, with files, symbols and calls between layers (direction down or up); pass layers to preview a rule and the same layers with confirm=true to save it in the project (.smart-tool/layers.json); duplicates lists duplicated functions (identical, near-identical and semantic bodies, min_similarity default 0.90; below that most pairs measured were false positives), excluding tests unless include_tests=true; fix real duplicates; only dismiss with duplicates_dismiss (finding_id, reason=false_positive|intentional, note) what is not a duplicate or is a copy kept on purpose: the finding stays hidden until the code changes, and duplicates_restore reopens it; integration shows the MCP client, hook and tool usage metrics; install_hook_preview shows the change that would install the hook redirecting Grep/Read to smart_search and WebSearch/WebFetch to web_search/web_fetch in this session's client and returns a plan_id; install_hook writes it with that plan_id and confirm=true, with a backup, only after the user approves the change; search_limits saves the project's default top_k per block ({code, test, doc}, each 1-20, total at most 20); storage shows disk usage and views; pin_view protects a view; cleanup_preview and cleanup_commit remove selected views after confirmation; compare compares two stored views, without checkout or embeddings. register adds a folder; preview checks the scope; index/rebuild update; pause/cancel keep checkpoints; resume continues; policy picks on_search/eager; scope adjusts the scope; remove deletes only the local index. setup_audit (project_root) reports what Claude Code and Codex actually load for that folder (settings layers, plugins, hooks, MCP servers, skills, CLAUDE.md/AGENTS.md) and where they collide: hooks deciding on the same tool in parallel, missing hook scripts, silenced hooks, MCP servers down or offering duplicate tools, skill name and budget problems, AGENTS.md that only Codex reads, broken @imports; what could not be checked is listed as not verified; each finding carries its fix (the file to edit or the command to run), applied by the agent when the user agrees, never by Smart Tool; mode=last returns the stored report instead of auditing again. redirect_proposals (no project_root) lists the redirect patterns proposed from allowed searches, most matched first, with a guide; redirect_decide decides them by ids: accept, instruct (tip without blocking), reject, or remove an accepted one. Jobs via smart_search_result.",
372
+ "description": "Manages folders and indexing. Every action takes project_root (the folder) or project_id. list gives a short line per project (a project whose folder is gone shows as unavailable with the reason); status shows storage, scope and jobs, and with a path inside a registered project answers for the deepest one that holds it (resolved_from). graph with symbol (function, Class.method, class name, or path::name when the name repeats) answers what an edit touches: definition, callers with line, calls, tests that reach it through static calls (depth hops, default 3) and files importing it; use it before changing a function to know what to update. affected_tests answers which tests to run after editing: every test file importing a changed file (git diff against base, default HEAD, untracked included) plus changed tests, likeliest failures first, with the command to run them and run_all when config or unanalyzed code changed. pr_impact (base, default HEAD; main or origin/main for a branch) returns a Markdown report of the change for a pull request: the functions the diff touches with their callers, the documentation entries it leaves out of date and the tests to run with their command; it publishes nothing. graph without symbol reads the indexed view: coverage, references and static calls in Java, Angular, Python, Go and JS/TS/JSX/TSX; includes HTML/CSS/Markdown references and TXT/DOCX coverage; with file_path, narrows to that file's symbols, imports and calls (lists capped by limit). inspect lists the files of a view_id; with file_path, returns only that file's chunks. usage shows consumption and reuse; docs lists public functions without a docstring (Python docstring, JSDoc, Javadoc, Go doc comment starting with the name; private, nested and override functions excluded) with coverage percent, excluding tests unless include_tests=true, for documenting a project that started without it; docs generate=true writes the documentation scope to docs/scope in the project in three levels tied to the code: technical pages by folder (an entry per public function anchored on path::name with signature, first doc line, layer, callers, calls and tests, plus a Mermaid flow by layer), functional.md (each entry point and the functions its flow reaches, by layer) and simple.md; the prose between the prose markers is kept by regeneration; docs write_prose=true writes the empty prose blocks with the Docs model of the setup (each paragraph checked against the code first) within about 40 s and says how many are left, call it again until none is; docs check=true reports anchors whose function changed signature or is gone and broken links; docs validate=true checks every claim of docs/scope against the code (anchors, links, line numbers, callers and tests, coverage, entry points, command-line options, prose names, counts, glossary, navigation, versions) and writes docs/scope/validation.md with pass/fail per check, the evidence, a score and the verdict (generate runs it too); docs with symbol lists where that function is documented; layers declares the project's layers (ordered highest first, each with path globs and annotations): without layers it returns the saved rule or a suggestion read from folder names and annotations, with files, symbols and calls between layers (direction down or up); pass layers to preview a rule and the same layers with confirm=true to save it in the project (.smart-tool/layers.json); duplicates lists duplicated functions (identical, near-identical and semantic bodies, min_similarity default 0.90; below that most pairs measured were false positives), excluding tests unless include_tests=true; fix real duplicates; only dismiss with duplicates_dismiss (finding_id, reason=false_positive|intentional, note) what is not a duplicate or is a copy kept on purpose: the finding stays hidden until the code changes, and duplicates_restore reopens it; integration shows the MCP client, hook and tool usage metrics; install_hook_preview shows the change that would install the hook redirecting Grep/Read to smart_search and WebSearch/WebFetch to web_search/web_fetch in this session's client and returns a plan_id; install_hook writes it with that plan_id and confirm=true, with a backup, only after the user approves the change; search_limits saves the project's default top_k per block ({code, test, doc}, each 1-20, total at most 20); storage shows disk usage and views; pin_view protects a view; cleanup_preview and cleanup_commit remove selected views after confirmation; compare compares two stored views, without checkout or embeddings. register adds a folder; preview checks the scope; index/rebuild update; pause/cancel keep checkpoints; resume continues; policy picks on_search/eager; scope adjusts the scope; remove deletes only the local index. setup_audit (project_root) reports what Claude Code and Codex actually load for that folder (settings layers, plugins, hooks, MCP servers, skills, CLAUDE.md/AGENTS.md) and where they collide: hooks deciding on the same tool in parallel, missing hook scripts, silenced hooks, MCP servers down or offering duplicate tools, skill name and budget problems, AGENTS.md that only Codex reads, broken @imports; what could not be checked is listed as not verified; each finding carries its fix (the file to edit or the command to run), applied by the agent when the user agrees, never by Smart Tool; mode=last returns the stored report instead of auditing again. redirect_proposals (no project_root) lists the redirect patterns proposed from allowed searches, most matched first, with a guide; redirect_decide decides them by ids: accept, instruct (tip without blocking), reject, or remove an accepted one. Jobs via smart_search_result.",
373
373
  "inputSchema": {
374
374
  "type": "object", "properties": {
375
375
  "action": {"type": "string", "enum": ["list", "status", "register", "preview", "index", "rebuild", "pause", "cancel", "resume", "watch", "scope", "remove", "relocate", "probe", "policy", "inspect", "graph", "usage", "storage", "pin_view", "cleanup_preview", "cleanup_commit", "compare", "search_limits", "integration", "install_hook_preview", "install_hook", "duplicates", "duplicates_dismiss", "duplicates_restore", "docs", "layers", "affected_tests", "pr_impact", "setup_audit", "redirect_proposals", "redirect_decide"]},
@@ -450,6 +450,8 @@ TOOLS = [
450
450
  "test": {"type": "integer", "minimum": 1, "maximum": 20},
451
451
  "doc": {"type": "integer", "minimum": 1, "maximum": 20}}}],
452
452
  "description": "Results per block: one number for all blocks or {code, test, doc}; each 1-20, total at most 20. Defaults to the project's search_limits, else 5"},
453
+ "detail": {"type": "string", "enum": ["compact", "full"], "default": "compact",
454
+ "description": "compact: 240-character excerpts, and ranking (when rerank) and location_kind (when source_line) left out of each result; full: 500-character excerpts with every field"},
453
455
  "mode": {"type": "string", "enum": ["search", "dossier"], "default": "search",
454
456
  "description": "dossier answers only with ids and a short excerpt, by keyword from disk and without an index, from docs/research, the backlog, CLAUDE.md and AGENTS.md; it takes query_identifiers or doc_query, timeout_ms and max_hits and ignores the other fields"},
455
457
  "timeout_ms": {"type": "integer", "minimum": 1, "maximum": 5000, "default": 800,
@@ -1221,6 +1223,24 @@ def _perform_smart_search(arguments, job_id):
1221
1223
  return contextvars.copy_context().run(_perform_smart_search_isolated, arguments, job_id)
1222
1224
 
1223
1225
 
1226
+ def _nested_projects_note(root):
1227
+ """Names the registered projects inside `root`: each keeps its own index, so a search of `root` does not cover
1228
+ their files. Returns None when there are none."""
1229
+ inner = project_store.nested_projects(root)
1230
+ if not inner:
1231
+ return None
1232
+ base = project_identity.display_root(root)
1233
+ parts = []
1234
+ for rel in inner[:8]:
1235
+ path = os.path.join(base, *rel.split("/"))
1236
+ files = indexer.info(path).get("files")
1237
+ parts.append(f"{rel} ({files} files): project_root=\"{path}\"" if files is not None else
1238
+ f"{rel} (not indexed yet): project_root=\"{path}\"")
1239
+ more = f" and {len(inner) - 8} more" if len(inner) > 8 else ""
1240
+ return (f"{len(inner)} registered project(s) inside this folder keep their own index and are not in these "
1241
+ f"results; search them with smart_search on their folder: {'; '.join(parts)}{more}.")
1242
+
1243
+
1224
1244
  def _perform_smart_search_isolated(arguments, job_id):
1225
1245
  _update_job(job_id, phase="auth")
1226
1246
  problem = _gateway_problem()
@@ -1321,6 +1341,7 @@ def _perform_smart_search_isolated(arguments, job_id):
1321
1341
  elif symbol_note or (symbol_index or {}).get("note"):
1322
1342
  warnings.append(symbol_note or symbol_index["note"])
1323
1343
  query_terms = _symbol_terms(" ".join(queries[group] for group in groups if group != "doc"))
1344
+ detail = arguments.get("detail", "compact")
1324
1345
  _update_job(job_id, phase="searching")
1325
1346
  found = {group: indexer.search(root, vectors.get(queries[group]), top_k=max(limits[group] * 4, candidate_pool),
1326
1347
  query=queries[group], model_id=search_model, overlay=overlay,
@@ -1348,10 +1369,9 @@ def _perform_smart_search_isolated(arguments, job_id):
1348
1369
  pinned = [(c[0], "overlay", c[1:]) for c in candidates if tuple(c[1:4]) in exact][:2]
1349
1370
  pinned_keys = {tuple(item[2][:3]) for item in pinned}
1350
1371
  ordered = pinned + [item for item in ordered if tuple(item[2][:3]) not in pinned_keys]
1351
- rows =[{"path": path, "lines": f"{start}-{end}", "score": round(score, 6), "snippet": text[:500],
1352
- "ranking": ranking, "location_kind": document_text.location_kind(path),
1353
- **({"symbols": _chunk_symbols(symbol_index, path, start, end, text, query_terms)}
1354
- if symbol_index and group != "doc" else {})}
1372
+ rows = [_result_row(detail, path, start, end, score, ranking, text,
1373
+ _chunk_symbols(symbol_index, path, start, end, text, query_terms)
1374
+ if symbol_index and group != "doc" else None)
1355
1375
  for score, ranking, (path, start, end, text) in ordered[:top_k]]
1356
1376
  return rows, problem
1357
1377
 
@@ -1365,12 +1385,15 @@ def _perform_smart_search_isolated(arguments, job_id):
1365
1385
  _job_checkpoint(job_id)
1366
1386
  if not any(blocks.values()):
1367
1387
  notes.append(EMPTY_RESULT_NOTICE)
1388
+ nested = _nested_projects_note(root)
1389
+ if nested:
1390
+ notes.append(nested)
1368
1391
  warning = " ".join(warnings)
1369
1392
  if warning:
1370
1393
  _update_job(job_id, warning=warning)
1371
1394
  if arguments.get("_structured"):
1372
1395
  return {"source": source if source == "cold" or vectors else "lexical index", "blocks": blocks,
1373
- "warnings": warnings}
1396
+ "warnings": warnings + ([nested] if nested else [])}
1374
1397
  return _grouped_yaml(index_profile.public(profile), blocks, " ".join(warnings + notes))
1375
1398
 
1376
1399
 
@@ -1508,6 +1531,25 @@ def _submit_project_job_locked(kind, arguments):
1508
1531
 
1509
1532
  SEARCH_LIMIT_TOTAL = 20
1510
1533
  SEARCH_LIMIT_DEFAULT = 5
1534
+ SEARCH_DETAILS = ("compact", "full")
1535
+ SNIPPET_CHARS = {"compact": 240, "full": 500}
1536
+
1537
+
1538
+ def _result_row(detail, path, start, end, score, ranking, text, symbols):
1539
+ """One smart_search result. `full` carries every field; `compact` shortens the excerpt to whole lines and leaves out
1540
+ what is the usual value (ranking `rerank`, location_kind `source_line`) and an empty symbol list."""
1541
+ location_kind = document_text.location_kind(path)
1542
+ snippet = text[:SNIPPET_CHARS[detail]]
1543
+ if detail == "compact" and len(text) > len(snippet) and "\n" in snippet.lstrip("\r\n"):
1544
+ snippet = snippet[:snippet.rindex("\n")].rstrip("\r")
1545
+ row = {"path": path, "lines": f"{start}-{end}", "score": round(score, 6), "snippet": snippet}
1546
+ if detail == "full" or ranking != "rerank":
1547
+ row["ranking"] = ranking
1548
+ if detail == "full" or location_kind != "source_line":
1549
+ row["location_kind"] = location_kind
1550
+ if symbols is not None and (detail == "full" or symbols):
1551
+ row["symbols"] = symbols
1552
+ return row
1511
1553
 
1512
1554
 
1513
1555
  def _limit_value(raw, field_name):
@@ -1588,7 +1630,7 @@ def _optional_text(arguments, name):
1588
1630
 
1589
1631
 
1590
1632
  _SMART_SEARCH_FIELDS = {"project_root", "query_identifiers", "query_comments", "doc_query",
1591
- "single_language_reason", "group", "top_k"}
1633
+ "single_language_reason", "group", "top_k", "detail"}
1592
1634
  _DOSSIER_FIELDS = {"project_root", "query_identifiers", "query_comments", "doc_query", "mode", "timeout_ms", "max_hits"}
1593
1635
 
1594
1636
 
@@ -1792,8 +1834,11 @@ def _smart_search_arguments(arguments):
1792
1834
  "To search in a single language, explain why in single_language_reason.")
1793
1835
  project = project_store.get(project_identity.project_id(project_root)) or {}
1794
1836
  limits = _search_limits(arguments.get("top_k"), groups, project.get("search_limits"))
1837
+ detail = arguments.get("detail", "compact")
1838
+ if detail not in SEARCH_DETAILS:
1839
+ raise ValueError("detail must be compact or full.")
1795
1840
  query = " ".join(part for part in (identifiers, comments) if part) or doc_query
1796
- arguments = {"project_root": project_root, "query": query, "top_k": limits, "group": group,
1841
+ arguments = {"project_root": project_root, "query": query, "top_k": limits, "group": group, "detail": detail,
1797
1842
  "doc_query": doc_query or comments or identifiers,
1798
1843
  **({"single_language_reason": reason} if reason else {})}
1799
1844
  session, client = _session_client()
@@ -1944,7 +1989,7 @@ def _scout_search(root, query, question, max_files):
1944
1989
  path runs at once, outside the per-folder queue, as for a redirected search."""
1945
1990
  limits = {"code": min(SEARCH_LIMIT_TOTAL - 6, max_files * 2), "test": 3, "doc": 3}
1946
1991
  search = {"project_root": root, "query": query, "doc_query": question, "group": "all", "top_k": limits,
1947
- "_structured": True}
1992
+ "detail": "full", "_structured": True}
1948
1993
  if _cold_index_building(root):
1949
1994
  return _perform_smart_search(search, "")
1950
1995
  job_id, future = _submit_project_job("smart_search", search)
@@ -2095,13 +2140,23 @@ def _with_project_id(arguments):
2095
2140
  return arguments
2096
2141
  wanted = project_identity.canonical_root(root)
2097
2142
  match = next((p for p in project_store.all_projects() if project_identity.canonical_root(p["root"]) == wanted), None)
2098
- if not match:
2143
+ if match:
2144
+ return {**arguments, "project_id": match["id"]}
2145
+ inner = project_store.containing(root) if arguments.get("action") == "status" else None
2146
+ if not inner:
2099
2147
  raise ValueError(f"No registered project at {root}; register it first (action=register).")
2100
- return {**arguments, "project_id": match["id"]}
2148
+ return {**arguments, "project_id": inner["id"], "resolved_from": root}
2101
2149
 
2102
2150
 
2103
2151
  def _project_summary(project):
2104
- data = _project_payload(project)
2152
+ """One line of `list`. A project whose payload cannot be read (its folder was deleted, Git refuses it) is listed as
2153
+ unavailable with the reason, so one broken entry does not hide the others."""
2154
+ try:
2155
+ data = _project_payload(project)
2156
+ except Exception as exc:
2157
+ return {"project_id": project["id"], "name": project.get("name"), "root": project["root"],
2158
+ "status": "unavailable", "enabled": project.get("enabled"), "paused": project.get("paused"),
2159
+ "last_error": _project_error(exc)[:200]}
2105
2160
  index = data.get("index") or {}
2106
2161
  jobs = data.get("jobs") or []
2107
2162
  return {"project_id": data["id"], "name": data.get("name"), "root": data["root"], "status": data.get("status"),
@@ -2301,6 +2356,9 @@ def _project_action_locked(arguments):
2301
2356
  if not project:
2302
2357
  raise ValueError("Project not registered.")
2303
2358
  if action == "status":
2359
+ if arguments.get("resolved_from"):
2360
+ return {"project": _project_payload(project), "resolved_from": arguments["resolved_from"],
2361
+ "detail": "project_root is inside this registered project (the deepest one that holds it)."}
2304
2362
  return {"project": _project_payload(project)}
2305
2363
  if action == "search_limits":
2306
2364
  if not isinstance(arguments.get("top_k"), dict):
package/version.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Single source of the Smart Tool version and of the User-Agent sent to public APIs."""
2
2
  import re
3
3
 
4
- VERSION = "0.9.68"
4
+ VERSION = "0.9.70"
5
5
  _CONTACT_RE = re.compile(r"^(?:[^\s@()<>;]+@[^\s@()<>;]+\.[^\s@()<>;]+|https?://[^\s()<>;]+)$")
6
6
 
7
7