Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
eaf8aca
Add Investigation Engine SDK and investigate CLI group
maximelb Nov 10, 2026
1f90fb0
Investigation Engine: tests, docs, help topic, changelog
maximelb Nov 10, 2026
cad3f10
Investigation Engine CLI: review round 1
maximelb Nov 10, 2026
8fc2401
Investigation Engine CLI: landed-write guard also compares comment an…
maximelb Nov 10, 2026
4c42051
Investigation Engine CLI: YAML 1.2 input files, structured errors for…
maximelb Nov 10, 2026
5a4302f
Investigation Engine CLI: drop a dead assignment in a test
maximelb Nov 10, 2026
5e20b76
Investigation Engine CLI: flags, enums and help match the engine
maximelb Nov 10, 2026
178a9fd
Investigation CLI: tests and docs for report.summary sentences of bot…
maximelb Nov 11, 2026
aef84c4
Investigation CLI: read and write scalars exactly as the engine's YAM…
maximelb Nov 11, 2026
5f77b1f
Investigation CLI: pin the typed template fields to the engine's type…
maximelb Nov 11, 2026
85824ba
Explain read-only live sensor identity permissions
maximelb Nov 11, 2026
b0b05c8
Add investigation run deletion to the SDK and CLI
maximelb Nov 11, 2026
3cc81af
Investigation CLI: say when the API does not serve run deletion; drop…
maximelb Nov 11, 2026
7834408
Investigation CLI: rebuild the run-deletion 404 error so the message …
maximelb Nov 11, 2026
39a1891
Preserve template test decision diagnostics in CLI output (#456)
maximelb Nov 12, 2026
852bed9
Pass explicit run trust additions through investigation CLI
maximelb Nov 14, 2026
39a770a
Omit empty optional trust from run requests
maximelb Nov 14, 2026
406f803
Refuse unsupported wave trust before sending requests
maximelb Nov 14, 2026
1481d6a
Clarify template trust and organize the command reference
maximelb Nov 14, 2026
d8eb5c1
Integrate current master with explicit run trust options
maximelb Nov 14, 2026
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: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@

### Investigation Engine — `limacharlie investigate` (experimental)

- `investigate runs start` adds repeatable `--trust-lookup NAME` and
`--trust-value VALUE` options, additive to template trust for one run only.
The SDK validates the same optional request object and omits empty trust.
- New `investigate` command group and `limacharlie.sdk.investigation.Investigation`
SDK class to build, test and tune Investigation Engine templates and to run
investigations, so a person or an AI agent can drive the whole loop from the
Expand Down
18 changes: 17 additions & 1 deletion doc/cli/investigation-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ limacharlie investigate runs start (--template NAME | --file plan.yaml | --auto)
(--detection-id ID | --case-id ID | --entity-id ID | --question TEXT) \
[--category C] [--severity S] [--priority N] [--tag T]... \
[--input K=V]... [--inputs-json JSON] [--urgency low|medium|high|critical] [--mode triage|full|scope] \
[--case-mode create|none|attach:ID] [--idempotency-key KEY] [--wait SECONDS] [--follow [--timeout SECONDS]]
[--case-mode create|none|attach:ID] [--idempotency-key KEY] [--wait SECONDS] [--follow [--timeout SECONDS]] \
[--trust-lookup NAME]... [--trust-value VALUE]...
limacharlie investigate runs get RUN_ID
limacharlie investigate runs list [--state S] [--verdict V] [--template T] [--trigger T] [--entity E] \
[--started-by user:UID] [--since TIME] [--until TIME] [--limit N] [--cursor C | --all]
Expand Down Expand Up @@ -235,6 +236,21 @@ result = inv.save_template("my-plan", open("plan.yaml").read(), comment="10 samp

`InvestigationError` carries `status_code`, `error_code`, `issues` and `warnings`.

## Explicit trust

Templates may declare `trust: {lookups: [partner-domains], values: [partner.example.test]}`.
The identity starting the run needs `lookup.get` to read these same-org Lookup records.
For Autopilot this is the onboarding key, rather than an identity that only reads settings.
Repeat `--trust-lookup NAME` or `--trust-value VALUE` on `investigate runs start` to add
trust for that run only (up to 64 Lookup names and 100 nonblank inline values).
Runs started automatically by D&R rules or Autopilot use only the template's trust.
The manual `--auto` option selects a template and still allows these run-only additions.
A match accounts for the initial target as customer-declared trusted and skips active
analysis; it never means verified or benign. Domains include DNS-boundary subdomains
and URL hosts. Broad/shared entries and embedded URL destinations do not skip analysis.
Missing, disabled or unreadable Lookups grant nothing and appear as run problems.


## See Also

- [Hive & Data Stores](hive-data.md) - the `investigation_plan` records are ordinary hive records
Expand Down
14 changes: 13 additions & 1 deletion limacharlie/commands/investigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
the org's policy says (response actions may wait for a person's approval).
--idempotency-key makes a repeated start return the same run.

Repeat --trust-lookup NAME / --trust-value VALUE to add to template trust for
this run only. The identity starting the run needs lookup.get for Lookups.
Automatic runs use only template trust.

With --wait N the call blocks up to N seconds for the verdict; --follow then
streams the run's events until it ends (--timeout defaults to 900 seconds;
0 has no time limit). On an interruption or stream error, resume with
Expand Down Expand Up @@ -917,6 +921,8 @@ def runs_group() -> None:


@runs_group.command("start")
@click.option("--trust-lookup", "trust_lookups", multiple=True, help="Same-org Lookup to trust for this run only (repeatable; up to 64; adds to template trust). The identity starting the run needs lookup.get.")
@click.option("--trust-value", "trust_values", multiple=True, help="Inline trusted value for this run only (repeatable; at most 100).")
@click.option("--template", default=None, help="Stored template to run.")
@_file_option
@click.option("--auto", is_flag=True, default=False,
Expand Down Expand Up @@ -945,7 +951,7 @@ def runs_group() -> None:
@pass_context
@_engine_errors
def runs_start(ctx, template, file_path, auto, detection_id, case_id, entity_id, question, category, severity, priority,
tags, inputs, inputs_json, urgency, mode, case_mode, idempotency_key, wait_seconds, follow, timeout) -> None:
tags, inputs, inputs_json, urgency, mode, case_mode, idempotency_key, wait_seconds, follow, timeout, trust_lookups, trust_values) -> None:
"""Start an investigation run on a detection, case, entity or question."""
if sum(bool(x) for x in (template, file_path, auto)) != 1:
raise click.UsageError("Give exactly one of --template, --file or --auto.")
Expand Down Expand Up @@ -974,6 +980,12 @@ def runs_start(ctx, template, file_path, auto, detection_id, case_id, entity_id,
request[key] = value
if wait_seconds:
request["wait_seconds"] = wait_seconds
if trust_lookups or trust_values:
request["trust"] = {}
if trust_lookups:
request["trust"]["lookups"] = list(trust_lookups)
if trust_values:
request["trust"]["values"] = list(trust_values)
inv = _get_investigation(ctx)
answer = inv.start_run(request)
if follow and _fmt(ctx) in _STRUCTURED:
Expand Down
31 changes: 30 additions & 1 deletion limacharlie/sdk/investigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,12 +994,39 @@ def start_run(self, request: dict[str, Any]) -> dict[str, Any]:
whose ``applies_to`` matches the trigger; ``{"auto": true}`` is
refused for a person's run), ``inputs``, ``urgency`` (``low``,
``medium``, ``high`` or ``critical``), ``mode``, ``case``,
``idempotency_key``, ``wait_seconds``, ...
``idempotency_key``, ``wait_seconds``, and optional ``trust``
(``lookups`` and ``values`` lists), additive to template trust
for this run only.

Returns:
dict: ``run`` and ``joined`` (True when an open run of the same
key absorbed the request instead of a new one starting).
"""
if "trust" in request:
trust = request["trust"]
normalized = {}
if trust is not None:
if not isinstance(trust, dict):
raise ValidationError("trust must be an object")
if any(key not in {"lookups", "values"} for key in trust):
raise ValidationError("trust accepts only lookups and values")
for key, maximum in (("lookups", 64), ("values", 100)):
if key not in trust:
continue
entries = trust[key]
if not isinstance(entries, list):
raise ValidationError(f"trust.{key} must be a list of nonblank strings")
if len(entries) > maximum:
raise ValidationError(f"trust.{key} accepts at most {maximum} entries")
if any(not isinstance(entry, str) or not entry.strip() for entry in entries):
raise ValidationError(f"trust.{key} must contain only nonblank strings")
if entries:
normalized[key] = list(entries)
request = dict(request)
if normalized:
request["trust"] = normalized
else:
request.pop("trust")
wait = request.get("wait_seconds") or 0
return self._call("POST", "runs", body=request, write=True, timeout=max(_WAIT_MARGIN, int(wait) + _WAIT_MARGIN))

Expand Down Expand Up @@ -1242,6 +1269,8 @@ def run_wave(self, request: dict[str, Any]) -> dict[str, Any]:
dict: ``results``, ``stopped_by``, ``usage`` and ``compact``; with
``validate_only``, the validation report.
"""
if "trust" in request:
raise ValidationError("request-level trust is supported only by run start")
if not isinstance(request.get("steps"), list) or not request["steps"]:
raise ValidationError("a wave needs a non-empty 'steps' list")
deadline = request.get("deadline_ms") or 30000
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_cli_investigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,23 @@ def test_test_cost_and_summary_output(capsys, monkeypatch):
assert list(mod._test_rows({"results": [{}]})[0])[:9] == ["index", "sample", "state", "verdict", "p", "expected", "agreement", "unknowns", "wall_ms"]


def test_run_explicit_trust_additions(sdk):
sdk.start_run.return_value = {"run": {"run_id": "r1"}}
result = run(["investigate", "runs", "start", "--template", "mail", "--detection-id", "d",
"--trust-lookup", "partners", "--trust-lookup", "corporate",
"--trust-value", "partner.example.test", "--trust-value", "https://portal.example.test/a"])
assert result.exit_code == 0, result.stderr
assert sdk.start_run.call_args.args[0]["trust"] == {"lookups": ["partners", "corporate"],
"values": ["partner.example.test", "https://portal.example.test/a"]}


def test_run_without_trust_omits_the_optional_field(sdk):
sdk.start_run.return_value = {"run": {"run_id": "r1"}}
result = run(["investigate", "runs", "start", "--template", "mail", "--detection-id", "d"])
assert result.exit_code == 0, result.stderr
assert "trust" not in sdk.start_run.call_args.args[0]


@pytest.mark.parametrize("seconds,expected", [(0, None), (12, 12.0)])
def test_start_follow_timeout_is_configurable(sdk, seconds, expected):
sdk.start_run.return_value = {"run": {"run_id": "r1"}}
Expand Down Expand Up @@ -749,3 +766,23 @@ def test_start_follow_rejects_negative_timeout_before_start(sdk):
result = run(["investigate", "runs", "start", "--template", "p", "--detection-id", "d", "--follow", "--timeout", "-1"])
assert result.exit_code == 2
sdk.start_run.assert_not_called()


@pytest.mark.parametrize("flag,value,expected", [
("--trust-lookup", "partners", {"lookups": ["partners"]}),
("--trust-value", "partner.example.test", {"values": ["partner.example.test"]}),
])
def test_run_trust_omits_unused_keys(sdk, flag, value, expected):
sdk.start_run.return_value = {"run": {"run_id": "r1"}}
result = run(["investigate", "runs", "start", "--template", "mail", "--detection-id", "d", flag, value])
assert result.exit_code == 0, result.stderr
assert sdk.start_run.call_args.args[0]["trust"] == expected


def test_start_ai_help_explains_run_only_additive_trust(sdk):
result = run(["investigate", "runs", "start", "--ai-help"])
assert result.exit_code == 0
assert "--trust-lookup" in result.stdout and "--trust-value" in result.stdout
assert "template trust" in result.stdout and "this run only" in result.stdout
assert "identity starting the run" in result.stdout
sdk.start_run.assert_not_called()
60 changes: 60 additions & 0 deletions tests/unit/test_sdk_investigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,22 @@ def test_a_set_tag_is_refused(self):
parse_document("a: !!set {x}\n")


@pytest.mark.parametrize("spec", [None, {}])
def test_start_run_empty_trust_wire_contract(inv, mock_org, spec):
mock_org.client.request.return_value = {"run": {"run_id": "r1"}}
request = {"trigger": {"question": "fictional"}, "trust": spec}
inv.start_run(request)
sent = json.loads(_request_args(mock_org)[2]["raw_body"])
assert "trust" not in sent
assert "trust" in request # the SDK does not mutate its caller's object


def test_wave_never_sends_unsupported_request_trust(inv, mock_org):
with pytest.raises(ValidationError, match="only by run start"):
inv.run_wave({"steps": [{"id": "s", "op": "entity.get"}], "trust": {"lookups": ["partners"]}})
mock_org.client.request.assert_not_called()


@pytest.mark.parametrize("method,key", [("iter_runs", "runs"), ("iter_actions", "actions")])
def test_pagination_rejects_multicursor_cycles(inv, mock_org, method, key):
mock_org.client.request.side_effect = [
Expand Down Expand Up @@ -933,3 +949,47 @@ def test_scalar_fixture_rejects_unknown_kind_clearly():
with pytest.raises(pytest.fail.Exception, match="Unknown scalar fixture kind"):
TestTemplateSource().test_args_scalars_are_read_as_the_engine_reads_them(
{"src": "example", "kind": "unrecognized-collection"})


@pytest.mark.parametrize("spec,expected", [
({"lookups": []}, None),
({"values": []}, None),
({"lookups": [], "values": []}, None),
({"lookups": ["partners"], "values": []}, {"lookups": ["partners"]}),
({"lookups": [], "values": ["partner.example.test"]}, {"values": ["partner.example.test"]}),
])
def test_start_run_normalizes_trust_without_mutating_caller(inv, mock_org, spec, expected):
import copy
request = {"trigger": {"question": "example"}, "trust": spec}
original = copy.deepcopy(request)
inv.start_run(request)
sent = json.loads(_request_args(mock_org)[2]["raw_body"])
if expected is None:
assert "trust" not in sent
else:
assert sent["trust"] == expected
assert request == original
assert request["trust"] is spec


@pytest.mark.parametrize("spec", [
"invalid", [], False, {"extra": []},
{"lookups": "partners"}, {"values": "partner.example.test"},
{"lookups": None}, {"values": None},
{"lookups": [None]}, {"values": [None]},
{"lookups": [1]}, {"values": [False]},
{"lookups": [""]}, {"values": [""]},
{"lookups": [" \t"]}, {"values": ["\n "]},
{"lookups": ["partners"] * 65}, {"values": ["partner.example.test"] * 101},
])
def test_invalid_start_trust_is_rejected_before_request(inv, mock_org, spec):
with pytest.raises(ValidationError, match="trust"):
inv.start_run({"trigger": {"question": "example"}, "trust": spec})
mock_org.client.request.assert_not_called()


def test_start_trust_accepts_exact_entry_limits(inv, mock_org):
spec = {"lookups": [f"partners-{i}" for i in range(64)],
"values": [f"partner-{i}.example.test" for i in range(100)]}
inv.start_run({"trigger": {"question": "example"}, "trust": spec})
assert json.loads(_request_args(mock_org)[2]["raw_body"])["trust"] == spec
Loading