@antoneeo/kb-agentic-skill 1.35.1 → 1.37.0

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.
@@ -2653,7 +2653,9 @@ def print_check_notes(root):
2653
2653
  #
2654
2654
  # The carrier is kb's (F-041 item B), lifted here so all three lenses share one
2655
2655
  # machine instead of two that do the same thing. Its contract is kept: the line
2656
- # is CONSTANT and reads NOTHING -- nothing repo- or session-controlled may ride
2656
+ # is CONSTANT and reads NOTHING repo- or session-controlled (F-093 / r44: it does
2657
+ # read which family lenses the machine has installed, names only) -- nothing
2658
+ # repo- or session-controlled may ride
2657
2659
  # text injected every turn, and zero reads is what keeps the per-turn cost flat.
2658
2660
  # What changed is the payload's first duty and the wiring. First duty: decide
2659
2661
  # whether the skill governs this work and, if it does, read it once -- an
@@ -2674,16 +2676,40 @@ REMIND_FALLBACK = (
2674
2676
  REMIND_LENS_SUFFIX = (" Above L1, with sibling lenses installed: choose the lens with "
2675
2677
  "routing.md and declare it.")
2676
2678
 
2679
+ # F-093: the family wires ONE shared reminder, the first installer's, so its
2680
+ # own text led a knowledge task to the code lens. With siblings installed the
2681
+ # suffix names every installed lens and its domain. The owner accepted the cost
2682
+ # (REQUEST_family_hook_wiring.md R3, rulings r19/r32 amended): the skills
2683
+ # directories are read each turn, names only, filtered by routing.md's table.
2684
+ REMIND_LENS_NAMED = (" Installed lenses: {lenses}. Above L1, choose the one that "
2685
+ "governs this work with routing.md, load it and declare it.")
2686
+
2687
+
2688
+ def remind_lens_suffix():
2689
+ """The lens-choice suffix: the constant one on a single-lens install, the
2690
+ named one when a sibling lens is installed. Never raises."""
2691
+ try:
2692
+ siblings = installed_sibling_lenses()
2693
+ if not siblings:
2694
+ return REMIND_LENS_SUFFIX
2695
+ family = lens_table()
2696
+ names = sorted(set(siblings) | {profile()["skill_name"]})
2697
+ return REMIND_LENS_NAMED.format(lenses=", ".join(
2698
+ f"{n} ({family[n]})" if n in family else n for n in names))
2699
+ except Exception:
2700
+ return REMIND_LENS_SUFFIX
2701
+
2677
2702
 
2678
2703
  def cmd_remind(args):
2679
- """UserPromptSubmit hook: print the lens's constant per-turn line. Always 0.
2704
+ """UserPromptSubmit hook: print the lens's per-turn line. Always 0.
2680
2705
 
2681
- argv is ignored whole and nothing is read: a hook surface must not fail, and
2682
- a flag typo must not cost a turn's context."""
2706
+ argv is ignored whole and nothing repo- or session-controlled is read: a
2707
+ hook surface must not fail, and a flag typo must not cost a turn's context.
2708
+ The one input is which family lenses this machine has installed (F-093)."""
2683
2709
  try:
2684
2710
  prof = profile()
2685
2711
  line = prof.get("remind_line") or REMIND_FALLBACK.format(skill=prof["skill_name"])
2686
- print(f"{prof['skill_name']}: {line}{REMIND_LENS_SUFFIX}")
2712
+ print(f"{prof['skill_name']}: {line}{remind_lens_suffix()}")
2687
2713
  except Exception:
2688
2714
  pass
2689
2715
  return 0
@@ -2775,8 +2801,21 @@ def cmd_gate(args):
2775
2801
  # 0) only on certainty; whatever it cannot tell resolves to silence. It never
2776
2802
  # prints `allow` -- that would skip the user's permission prompt. Owner: block
2777
2803
  # (REQUEST_guide_verdict_check.md R3), wired by default (R4, rulings.md r34).
2804
+ #
2805
+ # F-094: a named guide counts as read only when the session read EVERY line of
2806
+ # it. Before, the guide's name anywhere in a non-edit tool's input was a read, so
2807
+ # `Read offset=1 limit=130` of a 225-line guide, `head -30` or a Grep on it all
2808
+ # passed (field scan: 157 partial Reads of guides against 118 whole ones), and
2809
+ # the agent applied the part it had seen. A read is now a line span: a Read call
2810
+ # (offset is the 1-based first line, probed 2026-11-12; no limit = the client's
2811
+ # READ_DEFAULT_LIMIT), a literal shell `cat`/`Get-Content` (whole, or its
2812
+ # -TotalCount), a get_file_content (whole). Grep, head, sed, an Agent prompt
2813
+ # naming the guide: no span. The guide is read when the spans cover 1..its last
2814
+ # line. Owner: REQUEST_whole_guide_read.md R1.
2778
2815
 
2779
2816
  VERDICT_EDIT_TOOLS = ("Edit", "Write", "MultiEdit", "NotebookEdit")
2817
+ READ_DEFAULT_LIMIT = 2000 # Claude Code's Read without `limit` stops at line 2000
2818
+ GUIDE_COUNT_MAX = 8 * 1024 * 1024 # a larger guide: cannot afford to count its lines
2780
2819
  VERDICT_MAX_BYTES = 256 * 1024 * 1024 # a larger transcript: cannot afford to tell
2781
2820
  VERDICT_LINE_MAX = 1024 * 1024 # assistant lines are small; skip the rest unparsed
2782
2821
  # Markdown emphasis between the word and the colon ("**router**: no match") and
@@ -2860,6 +2899,13 @@ def hook_edits(payload):
2860
2899
 
2861
2900
  def shell_read_paths(command, cwd, workdir=None):
2862
2901
  """Literal Get-Content/cat reads only: no shell expansion or execution."""
2902
+ found = shell_read(command, cwd, workdir)
2903
+ return found[0] if found else None
2904
+
2905
+
2906
+ def shell_read(command, cwd, workdir=None):
2907
+ """(paths, line count or None) of a literal Get-Content/cat read, else None.
2908
+ The count is Get-Content's -TotalCount (F-094): those lines only, not the file."""
2863
2909
  if not isinstance(command, str) or re.search(r"[$`\r\n;|&<>\x00]", command):
2864
2910
  return None
2865
2911
  token_re = re.compile(r"\s*(?:'([^']*)'|\"([^\"]*)\"|([^\s'\"]+))")
@@ -2873,7 +2919,7 @@ def shell_read_paths(command, cwd, workdir=None):
2873
2919
  pos = match.end()
2874
2920
  if not tokens or tokens[0].lower() not in ("get-content", "cat"):
2875
2921
  return None
2876
- paths, i = [], 1
2922
+ paths, i, count = [], 1, None
2877
2923
  while i < len(tokens):
2878
2924
  token = tokens[i]
2879
2925
  if tokens[0].lower() == "get-content" and token.lower() in ("-literalpath", "-path", "-raw"):
@@ -2883,6 +2929,7 @@ def shell_read_paths(command, cwd, workdir=None):
2883
2929
  i += 1
2884
2930
  if i == len(tokens) or not tokens[i].isdigit():
2885
2931
  return None
2932
+ count = int(tokens[i])
2886
2933
  elif tokens[0] == "cat" and token == "--":
2887
2934
  pass
2888
2935
  elif token.startswith("-") or re.search(r"[*?\[\],]", token):
@@ -2894,7 +2941,7 @@ def shell_read_paths(command, cwd, workdir=None):
2894
2941
  return None
2895
2942
  paths.append(resolved)
2896
2943
  i += 1
2897
- return paths or None
2944
+ return (paths, count) if paths else None
2898
2945
 
2899
2946
 
2900
2947
  def _codex_literal_calls(code):
@@ -2980,8 +3027,12 @@ def transcript_events(path):
2980
3027
  for edit in hook_edits({"tool_input": {"command": command}, "cwd": cwd}) or []:
2981
3028
  blocks.append({"type": "tool_use", "name": "Write", "input": {"file_path": edit["path"]}})
2982
3029
  for args in calls:
2983
- for target in shell_read_paths(args.get("cmd", args.get("command")), cwd, args.get("workdir")) or []:
2984
- blocks.append({"type": "tool_use", "name": "Read", "input": {"file_path": target}})
3030
+ found = shell_read(args.get("cmd", args.get("command")), cwd, args.get("workdir"))
3031
+ for target in (found[0] if found else []):
3032
+ # F-094: the shell read is whole (no limit) unless -TotalCount
3033
+ inp = {"file_path": target}
3034
+ inp.update({"limit": found[1]} if found[1] is not None else {"whole": True})
3035
+ blocks.append({"type": "tool_use", "name": "Read", "input": inp})
2985
3036
  if blocks:
2986
3037
  yield {"type": "assistant", "isSidechain": bool(entry.get("agent_id") or data.get("agent_id")),
2987
3038
  "message": {"content": blocks}}
@@ -2994,9 +3045,9 @@ def transcript_facts(path):
2994
3045
  Returns {"assistant": entries parsed, "sidechain": a subagent's own transcript
2995
3046
  (Claude Code marks every entry of one `isSidechain`), "declared": a router verdict seen,
2996
3047
  "trivial": a level-1 declaration seen (`Level: L1`, `E1`), "named": guides the verdicts name,
2997
- "read": guide names that appeared in a non-edit tool's input}."""
3048
+ "read": guide name -> the line spans the session read of it (F-094, _read_spans)}."""
2998
3049
  facts = {"assistant": 0, "sidechain": False, "declared": False, "trivial": False,
2999
- "named": set(), "read": set()}
3050
+ "named": set(), "read": {}}
3000
3051
  try:
3001
3052
  p = Path(path)
3002
3053
  if not p.is_file() or p.stat().st_size > VERDICT_MAX_BYTES:
@@ -3023,15 +3074,75 @@ def transcript_facts(path):
3023
3074
  facts["declared"] = True
3024
3075
  if not _VERDICT_NONE_RE.match(m.group(1)):
3025
3076
  facts["named"].update(_GUIDE_NAME_RE.findall(m.group(1)))
3026
- elif (block.get("type") == "tool_use"
3027
- and block.get("name") not in VERDICT_EDIT_TOOLS):
3028
- facts["read"].update(_GUIDE_NAME_RE.findall(
3029
- json.dumps(block.get("input"), ensure_ascii=False)))
3077
+ elif block.get("type") == "tool_use":
3078
+ base = entry.get("cwd") if isinstance(entry.get("cwd"), str) else None
3079
+ for name, span in _read_spans(block, base or str(p.parent)):
3080
+ facts["read"].setdefault(name, []).append(span)
3030
3081
  except (OSError, ValueError, TypeError, AttributeError):
3031
3082
  return None
3032
3083
  return facts
3033
3084
 
3034
3085
 
3086
+ def _read_spans(block, cwd):
3087
+ """(guide name, (first line, last line or None = end of file)) for each guide
3088
+ this tool call read (F-094). Only reads that return the file's lines count; a
3089
+ search, an excerpt command or a prompt naming the guide reads nothing. `cwd`
3090
+ only anchors a relative shell path: the guide is matched by its name."""
3091
+ name, inp = block.get("name"), block.get("input")
3092
+ if not isinstance(inp, dict):
3093
+ return []
3094
+ if name == "Read" and isinstance(inp.get("file_path"), str):
3095
+ if inp.get("whole") is True:
3096
+ span = (1, None)
3097
+ else:
3098
+ offset, limit = inp.get("offset"), inp.get("limit")
3099
+ for v in (offset, limit): # present but not a plain int: cannot tell, no credit
3100
+ if v is not None and (not isinstance(v, int) or isinstance(v, bool)):
3101
+ return []
3102
+ if limit is not None and limit <= 0:
3103
+ return []
3104
+ first = offset if offset is not None and offset > 1 else 1
3105
+ count = limit if limit is not None else READ_DEFAULT_LIMIT
3106
+ span = (first, first + count - 1)
3107
+ return [(g, span) for g in _GUIDE_NAME_RE.findall(Path(inp["file_path"]).name)]
3108
+ if name in ("Bash", "PowerShell"):
3109
+ found = shell_read(inp.get("command"), cwd)
3110
+ if not found:
3111
+ return []
3112
+ span = (1, found[1]) if found[1] is not None else (1, None)
3113
+ return [(g, span) for path in found[0] for g in _GUIDE_NAME_RE.findall(Path(path).name)]
3114
+ if isinstance(name, str) and name.endswith("get_file_content"):
3115
+ paths = inp.get("paths") if isinstance(inp.get("paths"), list) else []
3116
+ return [(g, (1, None)) for path in paths if isinstance(path, str)
3117
+ for g in _GUIDE_NAME_RE.findall(Path(path).name)]
3118
+ return []
3119
+
3120
+
3121
+ def _guide_lines(path):
3122
+ """The guide's line count, or None when it cannot be counted within the bounds."""
3123
+ try:
3124
+ if path.stat().st_size > GUIDE_COUNT_MAX:
3125
+ return None
3126
+ text = path.read_bytes()
3127
+ except OSError:
3128
+ return None
3129
+ return text.count(b"\n") + (0 if not text or text.endswith(b"\n") else 1)
3130
+
3131
+
3132
+ def _read_whole(spans, lines):
3133
+ """True when the spans cover lines 1..lines. Unknown size: any read counts."""
3134
+ if not spans:
3135
+ return False
3136
+ if lines is None:
3137
+ return True
3138
+ reached = 0
3139
+ for first, last in sorted(spans, key=lambda s: s[0]):
3140
+ if first > reached + 1:
3141
+ break
3142
+ reached = max(reached, lines if last is None else last)
3143
+ return reached >= lines
3144
+
3145
+
3035
3146
  def verdict_reason(payload, root=None, docs_name=None):
3036
3147
  """The refusal line for this edit event, or None when the edit may proceed.
3037
3148
  Without a root, the project is the one holding the edited file (hook_project)."""
@@ -3072,10 +3183,12 @@ def verdict_reason(payload, root=None, docs_name=None):
3072
3183
  f"guides ({docs_dir()}/reference/INDEX.md). Declare it with the level, e.g. "
3073
3184
  "\"Level: L2 · router: no match\" or \"router: GUIDE_x.md -> read\" "
3074
3185
  "(L1: \"Level: L1\"), then retry.")
3075
- unread = sorted((facts["named"] & guides) - facts["read"])
3186
+ unread = sorted(g for g in facts["named"] & guides
3187
+ if not _read_whole(facts["read"].get(g), _guide_lines(ref / g)))
3076
3188
  if unread:
3077
- return (f"[sdlc verdict] The router verdict names {', '.join(unread)}, not read in "
3078
- "this session. Read it, then retry.")
3189
+ return (f"[sdlc verdict] The router verdict names {', '.join(unread)}, not read "
3190
+ "whole in this session. Read every line (no offset or limit; past the read "
3191
+ "cap, in chunks to the end), then retry.")
3079
3192
  return None
3080
3193
 
3081
3194
 
@@ -4171,7 +4284,7 @@ def cmd_orient(args):
4171
4284
  left = share - len("\n".join(head + tail)) - 2
4172
4285
  body = []
4173
4286
  for rel, title, builder, cap in (
4174
- (router_rel, "## Guide router (reference/INDEX.md) -- read the matching guide before acting",
4287
+ (router_rel, "## Guide router (reference/INDEX.md) -- read a matching guide whole, every line, before acting",
4175
4288
  _orient_router_lines, ORIENT_ROUTER_CHARS),
4176
4289
  (handoff_rel, "## Workstream registry (audit/handoff.md)",
4177
4290
  _orient_registry_lines, ORIENT_REGISTRY_CHARS),