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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/system-specs/modules/memory-skills-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,24 @@ unbounded archival memory.

Admitted project essentials are the active project's root `AGENTS.md` and
`SOUL.md`, default/`always` documents under `.kiro/steering`, and Markdown file
resources explicitly declared by the template. Native `manual`, `auto` and
resources explicitly declared by the template. The global `~/.kiro/steering`
always documents, the root `AGENTS.md` and undeclared `.kiro/steering`
documents are kiro-cli default resources: when kiro-cli serves the session and
`chat.disableInheritingDefaultResources` opts the workspace out, the snapshot
omits them and keeps the prompt, the declared resources and `SOUL.md`, which is
Crew's own file rather than a kiro-cli default. The verdict is computed once
per normal turn, where the harness is known, and handed to the snapshot and the
folder-steering dedup; no consumer reads the setting itself, and on any other
harness the member keeps inheriting because a kiro-cli setting changes nothing
there. A profile validation pass does not read the setting and instead measures
the inheriting envelope, which is the largest envelope any harness can build.
The preference comes from the skill projection's decision (see
[ACP client](acp-client.md)), so Crew's overlay on that key never reads as an
opt-out; settings that cannot be read keep inheritance. A non-member kiro-cli
chat follows the same decision: in an opted-out workspace a folder that
declares the project's or the global `.kiro/steering` root carries those
always documents itself, at session start and after a compaction, instead of
skipping them as already delivered. Native `manual`, `auto` and
`fileMatch` steering retain their trigger semantics. A custom template's
declared prompt may be inline or a file source. Missing optional root files
are allowed; an unreadable declared source or malformed/shadowed template
Expand Down
18 changes: 12 additions & 6 deletions docs/system-specs/modules/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ Kiro's supported `--agent` prompt/resources contract, not a per-file model recei
Changes to a launch-version source receive a complete manual replacement.
Kiro's implicit workspace-root AGENTS and default/always steering in project and
global steering directories also belong to that launch contract, even when no
resource glob declares them. SOUL is native-owned only when explicitly declared.
resource glob declares them, while the workspace inherits kiro-cli's default
resources; an opted-out workspace's contract is its declared sources alone. The
opt-out is kiro-cli's own setting, so it applies only when kiro-cli serves the
session: every other harness keeps the inheriting contract, and the non-member
folder-steering dedup follows the same decision.
SOUL is native-owned only when explicitly declared.
The mirrored steering reference records engine/version differences for conditional
modes, so Kiro uses the fallback selector instead of claiming full native support.

Expand All @@ -176,11 +181,12 @@ the harnesses carry no folder-steering field, so every harness produces an
identical `SpawnPlan` for a folder chat and a non-folder chat; delivery cannot be
lost by adding a provider. A file whose realpath lies under the chat project's
`.kiro/steering` or under `~/.kiro/steering` is skipped ONLY where the active provider
already delivers those trees -- kiro-cli loads them natively, the Claude Code seam
receives the explicit steering load, KAS reports `native_steering` -- so they are
not sent twice; on a harness with no such path (Codex, OpenCode, Pi, Goose,
DeepSeek) the folder delivers them like any other document rather than skipping
rules nothing else would carry. Documents honor the steering
already delivers those trees -- kiro-cli loads them natively while the workspace
inherits kiro-cli's default resources, the Claude Code seam receives the explicit
steering load, KAS reports `native_steering` -- so they are not sent twice; on a
harness with no such path (Codex, OpenCode, Pi, Goose, DeepSeek) the folder
delivers them like any other document rather than skipping rules nothing else
would carry. Documents honor the steering
`inclusion` frontmatter (`always`, or absent, is included; `manual`, `auto` and
`fileMatch` are skipped and left to their native trigger), and each file is
admitted against its own declared directory as the trust base, so a symlink can
Expand Down
63 changes: 53 additions & 10 deletions src/kiro_crew/acp/skill_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,55 @@ def _settings(path: Path) -> dict[str, Any]:
return data


def _inheritance_preference(
local: dict[str, Any], global_settings: dict[str, Any]
) -> tuple[bool, Any, bool]:
"""Return ``(inherited, source, overlaid)`` for custom agents in one workspace.

Once Crew's overlay is in place the native key reads ``true`` whatever the
user chose, so the recorded preference decides: a ``global`` source follows
the live global setting and any other source keeps the recorded value.
Without the overlay, or after the user moves the native key off ``true``,
the native key decides -- the workspace value when present, else the global
one -- and only the literal ``true`` opts out.
"""
inherited = local.get(_MANAGED_SETTING)
source = local.get(_INHERIT_SOURCE)
if not isinstance(inherited, bool) or local.get(_INHERIT_SETTING) is not True:
source = "local" if _INHERIT_SETTING in local else "global"
native = local.get(_INHERIT_SETTING, global_settings.get(_INHERIT_SETTING))
return native is not True, source, False
if source == "global":
return global_settings.get(_INHERIT_SETTING) is not True, source, True
return inherited, source, True


def inherits_default_resources(work_dir: str | os.PathLike[str] | None) -> bool:
"""Whether a custom agent started in *work_dir* inherits kiro-cli's default resources.

Those defaults are global and workspace steering plus ``AGENTS.md``. This is
the read-only twin of the decision :func:`prepare_native_skill_projection`
makes, for callers that must mirror what the native agent loads. Settings
that cannot be read keep inheritance, which is how those callers behaved
before they asked.
"""
try:
global_settings = _settings(kiro_home() / "settings" / "cli.json")
local = (
_settings(Path(work_dir) / ".kiro" / "settings" / "cli.json")
if work_dir is not None
else {}
)
# RuntimeError: Path.resolve() reports a symlink loop that way before Python 3.13.
except (OSError, ValueError, RuntimeError, RecursionError, FileTooLargeError):
logger.warning(
"skill projection: Kiro settings unreadable; keeping inherited resources",
exc_info=True,
)
return True
return _inheritance_preference(local, global_settings)[0]


def _restore_inheritance(path: Path, local: dict[str, Any]) -> None:
"""Undo only our overlay; a changed or removed native setting wins."""
inherited = local.get(_MANAGED_SETTING)
Expand Down Expand Up @@ -1595,20 +1644,14 @@ def prepare_native_skill_projection(
# the same sidecar lock, so no effort or Tool Search update can land
# between this read and commit.
local = _settings(locked_settings)
inherited = local.get(_MANAGED_SETTING)
preference_source = local.get(_INHERIT_SOURCE)
if not isinstance(inherited, bool) or local.get(_INHERIT_SETTING) is not True:
inherited, preference_source, overlaid = _inheritance_preference(
local, global_settings
)
if not overlaid:
local[_PREVIOUS_INHERITANCE] = {
"present": _INHERIT_SETTING in local,
"value": local.get(_INHERIT_SETTING),
}
preference_source = "local" if _INHERIT_SETTING in local else "global"
inherited = (
local.get(_INHERIT_SETTING, global_settings.get(_INHERIT_SETTING))
is not True
)
elif preference_source == "global":
inherited = global_settings.get(_INHERIT_SETTING) is not True

if inherited:
for view in specs.values():
Expand Down
14 changes: 14 additions & 0 deletions src/kiro_crew/agent_sdk/drivers/acp.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,20 @@ def projected_session_mcp_servers(
return session_mcp_servers(agent, work_dir=work_dir)


def inherits_default_resources(work_dir: str | Path | None) -> bool:
"""Whether a custom agent started in *work_dir* inherits kiro-cli's default resources.

Global and workspace steering plus ``AGENTS.md``. The answer is the skill
projection's, so Crew's own overlay on the native setting is not mistaken for
the user opting out.
"""
from kiro_crew.acp.skill_projection import (
inherits_default_resources as projection_inherits_default_resources,
)

return projection_inherits_default_resources(work_dir)


def skill_view_alias_census(agents_dir: "Path") -> dict[str, int]:
"""Count projected skill-view aliases as plain integers; reads, never writes.

Expand Down
87 changes: 69 additions & 18 deletions src/kiro_crew/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from kiro_crew._sqlite_compat import sqlite3
from kiro_crew.agent import _prompt_path, is_managed_prompt
from kiro_crew.agent_discovery import agent_skill_globs
from kiro_crew.agent_sdk.drivers import acp as acp_driver
from kiro_crew.agent_sdk.provider_identity import PROVIDER_ACP, is_claude_code
from kiro_crew.agent_spec_format import iter_agent_spec_files, parse_agent_spec_text
from kiro_crew.board_tag_grammar import is_grantable_tag_id
Expand Down Expand Up @@ -54,6 +55,7 @@
_MAX_DOCUMENTS,
ESSENTIAL_MAX_CHARS,
MemberEssentialContextError,
member_inherits_default_resources,
render_essentials,
)
from kiro_crew.members import (
Expand Down Expand Up @@ -2218,20 +2220,32 @@ def _load_steering_resources() -> str:
return ""


def _project_steering_delivered(provider_type: str, native_steering: bool) -> bool:
def _project_steering_delivered(
provider_type: str, native_steering: bool, project: str | None
) -> bool:
"""Whether the project/global ``.kiro/steering`` trees already reach the model.

Three paths exist and this names all of them, so the folder-steering dedup
skips those trees ONLY where one of them is in effect: kiro-cli (the ACP
default label) loads an agent's ``resources`` natively when spawned with
``--agent``; the Claude Code seam receives the explicit ``[Steering
resources]`` load in ``build_message`` (gated on ``is_cc``); KAS reports
``native_steering`` on its session provider. Every other harness -- Codex,
OpenCode, Pi, Goose, DeepSeek -- has NO path for those trees today, so a
folder that declares one of them must deliver its documents itself rather
than skip them as "already delivered" with nothing arriving in their place.
``--agent``, but only while *project* inherits kiro-cli's default resources
(a workspace that sets ``chat.disableInheritingDefaultResources`` gets
those trees from nobody, so the folder must carry them); the Claude Code
seam receives the explicit ``[Steering resources]`` load in
``build_message`` (gated on ``is_cc``); KAS reports ``native_steering`` on
its session provider. Every other harness -- Codex, OpenCode, Pi, Goose,
DeepSeek -- has NO path for those trees today, so a folder that declares one
of them must deliver its documents itself rather than skip them as "already
delivered" with nothing arriving in their place. The opt-out is read only
on the kiro-cli disjunct: a kiro-cli setting changes nothing on another
harness. The driver is asked directly, with no admission check on
*project*: this path also serves non-member sessions and must not raise.
"""
return provider_type == PROVIDER_ACP or is_claude_code(provider_type) or bool(native_steering)
return (
(provider_type == PROVIDER_ACP and acp_driver.inherits_default_resources(project))
or is_claude_code(provider_type)
or bool(native_steering)
)


def _render_folder_steering_section(
Expand Down Expand Up @@ -3729,13 +3743,19 @@ def _build_v2_essentials(
trigger_text: str = "",
steering_dirs: tuple[str, ...] = (),
template_selected: bool = False,
provider_type: str = PROVIDER_ACP,
) -> str:
"""Refresh complete member essentials without opening learned memory.

``template_selected`` is :func:`_template_selected_on_member_store`'s verdict
for the execution being built and is handed to the member-section builder
unchanged: the envelope keeps the member's identity, rules, documents and
anchors, and withholds only the desk protocol and briefing.

``provider_type`` names the harness serving the session. Only kiro-cli
(:data:`PROVIDER_ACP`) honours ``chat.disableInheritingDefaultResources``,
so its verdict is read once here, where the harness is known, and handed
to every consumer; no consumer reads the setting itself.
"""
from kiro_crew.member_essential_context import (
MemberEssentialContextError,
Expand Down Expand Up @@ -3765,17 +3785,29 @@ def _build_v2_essentials(
if profile_overrides is None:
context_groups = _config_scoped_groups(context_groups)
reads = not blocks_reads and _group_included(context_groups, CONTEXT_GROUP_MEMORY)
include_project = not blocks_reads and _group_included(
context_groups, CONTEXT_GROUP_PROJECT
)
identity = self._build_member_section(
owner, strict=True, include_briefing=reads, template_selected=template_selected
)
# A validation pass measures the largest envelope any harness can build,
# so it keeps inheritance and never reads kiro-cli's opt-out. On a normal
# turn, the setting changes what a member loads only on a session
# kiro-cli serves: every other harness keeps inheriting. Read once, where
# the project group applies, and pass the verdict to the snapshot and the
# folder-steering dedup below so the two cannot disagree.
inherits_default_resources = True
if profile_overrides is None and include_project and provider_type == PROVIDER_ACP:
inherits_default_resources = member_inherits_default_resources(project)
documents = documents_for_member(
template,
project,
conditional_index=conditional_index,
context_settings=True,
trigger_text=trigger_text,
include_project=not blocks_reads
and _group_included(context_groups, CONTEXT_GROUP_PROJECT),
include_project=include_project,
inherits_default_resources=inherits_default_resources,
)
if execution_template and execution_template != template:
sources = dict(documents)
Expand All @@ -3785,8 +3817,8 @@ def _build_v2_essentials(
conditional_index=conditional_index,
context_settings=True,
trigger_text=trigger_text,
include_project=not blocks_reads
and _group_included(context_groups, CONTEXT_GROUP_PROJECT),
include_project=include_project,
inherits_default_resources=inherits_default_resources,
):
if source in sources and sources[source] != body:
raise MemberEssentialContextError(
Expand All @@ -3809,14 +3841,29 @@ def _build_v2_essentials(
# until the folder shrinks. The character budget depends on the memory
# documents appended below, so the candidates are collected here (their
# position recorded) and fitted just before the envelope renders.
#
# The project and global ``.kiro/steering`` trees are skipped as already
# delivered only while the snapshot above actually delivered them: a
# kiro-cli workspace that opts out of the default resources gets them
# from neither the snapshot nor the harness, so a folder that declares
# one of those roots must carry its documents itself. The template's
# declared resources can still carry some of those files, so under the
# opt-out a folder document whose canonical path the template already
# delivered is not collected again. Same verdict as the snapshot, read
# once above.
folder_docs: SteeringCollection = SteeringCollection()
folder_insert_at = len(documents)
if (
steering_dirs
and not blocks_reads
and _group_included(context_groups, CONTEXT_GROUP_PROJECT)
):
folder_docs = collect_folder_steering(steering_dirs, project=project)
if steering_dirs and include_project:
folder_docs = collect_folder_steering(
steering_dirs,
project=project,
skip_delivered_roots=inherits_default_resources,
delivered_sources=(
tuple(source for source, _ in documents)
if not inherits_default_resources
else ()
),
)
if reads:
from kiro_crew.memory_stores import memory_store_dir_for

Expand Down Expand Up @@ -3983,6 +4030,7 @@ def append_required(text: str) -> None:
member_template=execution_context.template_id if execution_context else "",
steering_dirs=steering_dirs,
template_selected=_template_selected_on_member_store(execution_context),
provider_type=provider_type,
)

# Minimal V1 stays date/time + agent identity. Private V2 also carries
Expand Down Expand Up @@ -4964,6 +5012,7 @@ def build_message(
and not context_provider.native_steering,
steering_dirs=steering_dirs,
template_selected=_template_selected_on_member_store(execution_context),
provider_type=provider_type,
)
if _essentials and not is_new_session:
parts.append(_essentials)
Expand Down Expand Up @@ -5151,6 +5200,7 @@ def build_message(
skip_delivered_roots=_project_steering_delivered(
provider_type,
context_provider is not None and context_provider.native_steering,
project,
),
)
if _folder_ctx:
Expand Down Expand Up @@ -5298,6 +5348,7 @@ def build_message(
skip_delivered_roots=_project_steering_delivered(
provider_type,
context_provider is not None and context_provider.native_steering,
project,
),
)
if _folder_ctx:
Expand Down
Loading
Loading