Skip to content

Commit a4131c9

Browse files
committed
Merge current main (with NVIDIA#577) into feat/christopherk/python-execution-surface-classification
NVIDIA#577 landed on main as 5ee48ef. This branch carries the superset of its TM1 work: the same lexical-counterevidence fix, the window-identity and execution-surface changes, the NVIDIA#577-only tests ported in 2ba149d, and a differential check showing every call NVIDIA#577 reports is still reported here. For the four files that conflict (static_patterns_tool_misuse.py, static_python_shell_truthiness.py, test_shared_python_ast.py, test_tool_misuse_python_ast.py) keep this branch's version. No other main commit touched them since the previous merge. The shared-AST fixture keeps the input()-before-import subprocess order the review asked for. The other NVIDIA#577 files merged to this branch's content unchanged. Signed-off-by: Narendran Raghavan <[email protected]>
2 parents 4b0043f + 8f4ca7d commit a4131c9

17 files changed

Lines changed: 2837 additions & 117 deletions

‎README.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ Set `SKILLSPECTOR_REASONING_EFFORT` to override it with `low`, `high`, or `max`.
305305
The bundled 128,000-token context and 32,000-token output budgets are conservative
306306
application limits; they do not claim the hosted endpoint's maximum capacity.
307307

308-
Structured output is requested through LangChain's `with_structured_output`,
309-
whose default forces a tool call. Some models reject a forced tool call with
308+
Structured output is requested through LangChain's `with_structured_output`.
309+
The default is client-specific: `ChatOpenAI` uses `json_schema`, while other
310+
clients may use tool calling. Some models reject a forced tool call with
310311
HTTP 400 (`tool_choice: type "tool" and "any" are not supported for this
311312
model`). The `anthropic` and `anthropic_proxy` providers route those models
312313
(`claude-fable-5-1`, `claude-mythos-5-1`, or any registry entry with
@@ -322,6 +323,12 @@ for endpoints that ignore both `response_format` and a forced `tool_choice`
322323
and answer in prose (for example iFlytek's `spark-x2.5`, which is bundled).
323324
`SKILLSPECTOR_STRUCTURED_OUTPUT_METHOD=json_schema|function_calling`
324325
overrides the method for any provider.
326+
The method precedence is `SKILLSPECTOR_STRUCTURED_OUTPUT_METHOD`, the provider's
327+
method hint, an analyzer preference, then the client default. TP4 prefers
328+
`function_calling` only for provider `openai` and the exact model label
329+
`azure/anthropic/claude-opus-5`, with reasoning/thinking controls unset; dated
330+
or suffixed labels and other providers keep their existing behavior. An explicit
331+
environment override or provider hint still wins when reasoning is configured.
325332

326333
```bash
327334
# Stock OpenAI

‎src/skillspector/cli.py‎

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,40 @@ def _ledger_work_identity(entry: dict[str, object]) -> str:
10011001
return f"{record_value}:{entry.get('phase', '')}"
10021002

10031003

1004+
def _ledger_work_identities(value: object) -> dict[str, str]:
1005+
"""Map each child ledger row's own work ID to the identity it was built from.
1006+
1007+
A status ``planned_work`` target carries only the child's work ID, path and
1008+
range, not the identity behind it. Rows whose identity is not the
1009+
analyzer's own -- the static_yara rule-set row is ``rule_set:static``, not
1010+
``static_yara`` -- must be re-scoped with that same identity in the status
1011+
path, or the status target and its ledger row get different scoped IDs
1012+
and the target is dropped as unretained.
1013+
"""
1014+
identities: dict[str, str] = {}
1015+
for event in _coerce_dict_list(value):
1016+
work_id = event.get("work_id")
1017+
if isinstance(work_id, str) and work_id:
1018+
identities[work_id] = _ledger_work_identity(event)
1019+
return identities
1020+
1021+
1022+
def _source_scoped_work_id(identity: str, item: dict[str, object]) -> str:
1023+
"""Build the scoped work ID for an already re-pathed ledger row or status target.
1024+
1025+
Shared by :func:`_source_aware_ledger` and :func:`_source_aware_status_events`
1026+
so the two scoping paths cannot derive different IDs for the same work.
1027+
"""
1028+
start_line = item.get("start_line")
1029+
end_line = item.get("end_line")
1030+
return inspection_work_id(
1031+
identity,
1032+
str(item.get("path", "SKILL.md")),
1033+
start_line if isinstance(start_line, int) else None,
1034+
end_line if isinstance(end_line, int) else None,
1035+
)
1036+
1037+
10041038
def _source_aware_ledger(
10051039
value: object,
10061040
*,
@@ -1026,15 +1060,7 @@ def _source_aware_ledger(
10261060
for item in ids
10271061
if isinstance(item, str)
10281062
]
1029-
scoped_path = str(entry.get("path", "SKILL.md"))
1030-
start_line = entry.get("start_line")
1031-
end_line = entry.get("end_line")
1032-
entry["work_id"] = inspection_work_id(
1033-
_ledger_work_identity(entry),
1034-
scoped_path,
1035-
start_line if isinstance(start_line, int) else None,
1036-
end_line if isinstance(end_line, int) else None,
1037-
)
1063+
entry["work_id"] = _source_scoped_work_id(_ledger_work_identity(entry), entry)
10381064
events.append(entry)
10391065
return events
10401066

@@ -1047,8 +1073,10 @@ def _source_aware_status_events(
10471073
source_digest: str,
10481074
retained_work_ids: set[str],
10491075
max_planned_work: int,
1076+
work_identities: dict[str, str] | None = None,
10501077
) -> list[dict[str, object]]:
10511078
statuses: list[dict[str, object]] = []
1079+
identities = work_identities or {}
10521080
planned_retained = 0
10531081
for status in _coerce_dict_list(value):
10541082
if len(statuses) >= _TRANSITIVE_MAX_STATUS_EVENTS:
@@ -1070,14 +1098,11 @@ def _source_aware_status_events(
10701098
path = scoped_target.get("path")
10711099
if isinstance(path, str) and path:
10721100
scoped_target["path"] = _transitive_component_key(source_identity, path)
1073-
start_line = scoped_target.get("start_line")
1074-
end_line = scoped_target.get("end_line")
1075-
scoped_target["work_id"] = inspection_work_id(
1076-
analyzer_id,
1077-
str(scoped_target.get("path", "SKILL.md")),
1078-
start_line if isinstance(start_line, int) else None,
1079-
end_line if isinstance(end_line, int) else None,
1080-
)
1101+
# Re-scope with the identity the matching ledger row used, so
1102+
# both paths agree on the scoped ID; the analyzer ID is only the
1103+
# fallback for targets with no child ledger row.
1104+
identity = identities.get(str(target.get("work_id", "")), analyzer_id)
1105+
scoped_target["work_id"] = _source_scoped_work_id(identity, scoped_target)
10811106
if scoped_target["work_id"] not in retained_work_ids:
10821107
continue
10831108
scoped_work.append(scoped_target)
@@ -1389,6 +1414,7 @@ def _scope_finding(finding: Finding) -> Finding:
13891414
source_digest=source_digest,
13901415
retained_work_ids=retained_work_ids,
13911416
max_planned_work=len(retained_work_ids),
1417+
work_identities=_ledger_work_identities(child_result.get("inspection_ledger")),
13921418
)
13931419
child_metadata = _decorate_component_metadata(
13941420
_coerce_component_metadata(child_result.get("component_metadata")),

‎src/skillspector/inspection_ledger.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ class LedgerRecordType(StrEnum):
3636
WORK_ITEM = "work_item"
3737
SYSTEM = "system"
3838
SCOPE_BOUNDARY = "scope_boundary"
39+
# An analyzer's own configuration (e.g. its YARA rule set), not a skill
40+
# artifact. Its ``path`` is only a report-safe label, and every relative
41+
# path is also a legal file name, so path-keyed accounting must exclude
42+
# these records by type -- no choice of label can be collision-free.
43+
RULE_SET = "rule_set"
44+
45+
46+
RULE_SET_SCOPE: Final = "rule_set"
47+
"""Public ``scope`` of exception rows describing a rule set rather than a file."""
3948

4049

4150
class LedgerReason(StrEnum):
@@ -303,6 +312,7 @@ class InspectionLedgerException(TypedDict):
303312
error_class: NotRequired[str]
304313
analyzers: NotRequired[list[str]]
305314
fatal: NotRequired[bool]
315+
scope: NotRequired[str]
306316

307317

308318
class AnalysisCompleteness(TypedDict):
@@ -597,6 +607,7 @@ def _exception(
597607
error_class: str | None = None,
598608
analyzers: Iterable[str] = (),
599609
fatal: bool,
610+
scope: str | None = None,
600611
) -> InspectionLedgerException:
601612
"""Build the public, safe projection of one exceptional ledger fact."""
602613
exception: InspectionLedgerException = {
@@ -614,9 +625,16 @@ def _exception(
614625
exception["analyzers"] = analyzer_ids
615626
if error_class:
616627
exception["error_class"] = error_class
628+
if scope:
629+
exception["scope"] = scope
617630
return exception
618631

619632

633+
def _is_rule_set_record(event: Mapping[str, object]) -> bool:
634+
"""Return whether a ledger row describes a rule set rather than an artifact."""
635+
return event.get("record_type") == LedgerRecordType.RULE_SET
636+
637+
620638
def _exception_from_event(
621639
event: InspectionLedgerEvent, *, fatal: bool
622640
) -> InspectionLedgerException:
@@ -637,6 +655,7 @@ def _exception_from_event(
637655
error_class=event.get("error_class"),
638656
analyzers=[str(event.get("analyzer_id", ""))],
639657
fatal=fatal,
658+
scope=RULE_SET_SCOPE if _is_rule_set_record(event) else None,
640659
)
641660

642661

@@ -655,6 +674,9 @@ def _merge_exception_projection(
655674
exception["start_line"],
656675
exception["end_line"],
657676
exception.get("error_class"),
677+
# A rule-set row and a real file's row can share a path label;
678+
# they must never merge into one public row.
679+
exception.get("scope"),
658680
)
659681
existing = grouped.get(key)
660682
if existing is None:
@@ -934,9 +956,17 @@ def accounting_error(path: object = None) -> None:
934956
ledger_exceptions = _merge_exception_projection(exceptional_rows)
935957
scope_exclusions = _merge_exception_projection(scope_rows)
936958

959+
# Rule-set rows describe an analyzer's configuration, not an artifact. Their
960+
# path is only a label, so folding them into per-component coverage would
961+
# charge the rule set's incompleteness to any real file with that name.
962+
rule_set_work_ids = {
963+
str(event.get("work_id", "")) for event in events if _is_rule_set_record(event)
964+
}
937965
per_component: dict[str, list[LedgerOutcome]] = {component: [] for component in components}
938966
if primary_targets:
939967
for _analyzer_id, target, matches in primary_targets:
968+
if str(target.get("work_id", "")) in rule_set_work_ids:
969+
continue
940970
path = _safe_path(target.get("path"), components)
941971
outcomes = per_component.setdefault(path, [])
942972
if len(matches) == 1:

‎src/skillspector/llm_analyzer_base.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ def __init__(
951951
max_retries=native_retries,
952952
)
953953
self._structured_llm = (
954-
bind_structured_output(self._llm, self.response_schema, model)
954+
self._bind_structured_output(self._llm, self.response_schema)
955955
if self.response_schema
956956
else None
957957
)
@@ -962,6 +962,18 @@ def __init__(
962962
chat_model=self._llm,
963963
)
964964

965+
def _structured_output_preference(self, llm: object) -> str | None:
966+
"""Return an analyzer-specific binding preference, if any."""
967+
return None
968+
969+
def _bind_structured_output(self, llm: object, schema: type) -> object:
970+
return bind_structured_output(
971+
llm,
972+
schema,
973+
self.model,
974+
preferred_method=self._structured_output_preference(llm),
975+
)
976+
965977
def _remaining_timeout(self) -> float | None:
966978
if callable(self._timeout):
967979
remaining = self._timeout()
@@ -1022,7 +1034,7 @@ def _model_for_call(self) -> tuple[object, object | None]:
10221034
chat_model_controls(llm),
10231035
)
10241036
structured = (
1025-
bind_structured_output(llm, self.response_schema, self.model)
1037+
self._bind_structured_output(llm, self.response_schema)
10261038
if self.response_schema
10271039
else None
10281040
)

0 commit comments

Comments
 (0)