fix(fence): the cross-project permission prompt says what changes and where first, in plain words
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Successful in 2m2s
CI & Build / integration (push) Successful in 2m40s
CI & Build / Build & push image (push) Successful in 25s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Successful in 2m2s
CI & Build / integration (push) Successful in 2m40s
CI & Build / Build & push image (push) Successful in 25s
The first line names the act and the project it lands in against the one the session works in; the second says when to approve; the agent's issue-filing call moves to a last line in parentheses. Tool names are spelled out and project ids dropped from the operator's text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -303,8 +303,21 @@ async def _titles(ids: list[int]) -> dict[int, str]:
|
|||||||
|
|
||||||
|
|
||||||
def _named(project_id: int, titles: dict[int, str]) -> str:
|
def _named(project_id: int, titles: dict[int, str]) -> str:
|
||||||
title = titles.get(project_id)
|
return titles.get(project_id) or f"project {project_id}"
|
||||||
return f"{title} (project {project_id})" if title else f"project {project_id}"
|
|
||||||
|
|
||||||
|
def _doing(tool: str, act: str) -> str:
|
||||||
|
"""The act in words a person reads at a glance: "Retire family idea",
|
||||||
|
"git push", "Editing a file". A tool name is spelled out, not quoted."""
|
||||||
|
act = act.strip()
|
||||||
|
if act.endswith(" in"):
|
||||||
|
act = act[:-3]
|
||||||
|
if act:
|
||||||
|
return act[:1].upper() + act[1:]
|
||||||
|
if tool:
|
||||||
|
words = tool.replace("_", " ").strip()
|
||||||
|
return words[:1].upper() + words[1:]
|
||||||
|
return "This change"
|
||||||
|
|
||||||
|
|
||||||
async def check_act(
|
async def check_act(
|
||||||
@@ -343,22 +356,24 @@ async def check_act(
|
|||||||
targets = [{"id": p, "title": titles.get(p, "")} for p in others]
|
targets = [{"id": p, "title": titles.get(p, "")} for p in others]
|
||||||
if tool and is_issue_filing(tool, args):
|
if tool and is_issue_filing(tool, args):
|
||||||
return {"allowed": True, "targets": targets, "issue": True, "reason": ""}
|
return {"allowed": True, "targets": targets, "issue": True, "reason": ""}
|
||||||
|
# The reason is the permission prompt's text: the operator reads it
|
||||||
|
# first, so it leads with what changes and where, then when to approve.
|
||||||
|
# The session reads it after a "no", so the last line is for the agent.
|
||||||
there = ", ".join(_named(p, titles) for p in others)
|
there = ", ".join(_named(p, titles) for p in others)
|
||||||
|
home = _named(session_project, titles)
|
||||||
if tool in RULE_CURATION_TOOLS:
|
if tool in RULE_CURATION_TOOLS:
|
||||||
rules = sorted({r for name in _RULE_ARGS for r in _positive_ints(args.get(name))})
|
rules = sorted({r for name in _RULE_ARGS for r in _positive_ints(args.get(name))})
|
||||||
which = ", ".join(f"rule {r}" for r in rules) or "a rule"
|
which = ", ".join(f"rule {r}" for r in rules) or "a rule"
|
||||||
reason = (
|
reason = (
|
||||||
f"This session belongs to {_named(session_project, titles)}. {tool} changes "
|
f"Changing {which} in {there}, but this session is working in {home}.\n"
|
||||||
f"{which} of {there}, a different project. Rules are the operator's to "
|
"Rules are yours to curate from any session. Approve if you asked for this change."
|
||||||
f"curate from any session: approve if they asked for this change."
|
|
||||||
)
|
)
|
||||||
return {"allowed": False, "targets": targets, "issue": False, "reason": reason}
|
return {"allowed": False, "targets": targets, "issue": False, "reason": reason}
|
||||||
what = act.strip() or (f"{tool} changes" if tool else "This changes")
|
|
||||||
first = others[0]
|
first = others[0]
|
||||||
reason = (
|
reason = (
|
||||||
f"This session belongs to {_named(session_project, titles)}. {what} {there}, "
|
f"{_doing(tool, act)} in {there}, but this session is working in {home}.\n"
|
||||||
f"a different project. From here, the one change to make there is filing an "
|
f"Approve only if you asked for this change to {there}.\n"
|
||||||
f"issue: create_task(project_id={first}, kind=\"issue\") with how it was found "
|
f"(If not: the agent can report it there instead, with "
|
||||||
f"and the evidence. Approve only if this session should change {there} itself."
|
f"create_task(project_id={first}, kind=\"issue\").)"
|
||||||
)
|
)
|
||||||
return {"allowed": False, "targets": targets, "issue": False, "reason": reason}
|
return {"allowed": False, "targets": targets, "issue": False, "reason": reason}
|
||||||
|
|||||||
@@ -147,9 +147,10 @@ async def test_a_write_in_another_project_asks_and_says_how_to_file_an_issue_ins
|
|||||||
out = await check_act(1, 2, tool="update_task", args={"task_id": 5})
|
out = await check_act(1, 2, tool="update_task", args={"task_id": 5})
|
||||||
assert out["allowed"] is False
|
assert out["allowed"] is False
|
||||||
assert out["targets"] == [{"id": 9, "title": "Elsewhere"}]
|
assert out["targets"] == [{"id": 9, "title": "Elsewhere"}]
|
||||||
assert "Home (project 2)" in out["reason"]
|
first, ask, agent = out["reason"].split("\n")
|
||||||
assert "Elsewhere (project 9)" in out["reason"]
|
assert first == "Update task in Elsewhere, but this session is working in Home."
|
||||||
assert 'create_task(project_id=9, kind="issue")' in out["reason"]
|
assert ask == "Approve only if you asked for this change to Elsewhere."
|
||||||
|
assert 'create_task(project_id=9, kind="issue")' in agent
|
||||||
|
|
||||||
|
|
||||||
async def test_a_rule_edit_in_another_project_names_the_rule_and_suggests_no_issue():
|
async def test_a_rule_edit_in_another_project_names_the_rule_and_suggests_no_issue():
|
||||||
@@ -157,12 +158,12 @@ async def test_a_rule_edit_in_another_project_names_the_rule_and_suggests_no_iss
|
|||||||
with a, b, c:
|
with a, b, c:
|
||||||
out = await check_act(1, 2, tool="update_rule", args={"rule_id": 130, "salience": "low"})
|
out = await check_act(1, 2, tool="update_rule", args={"rule_id": 130, "salience": "low"})
|
||||||
assert out["allowed"] is False
|
assert out["allowed"] is False
|
||||||
assert "rule 130 of Elsewhere (project 9)" in out["reason"]
|
assert out["reason"].startswith("Changing rule 130 in Elsewhere, but this session is working in Home.")
|
||||||
assert "create_task" not in out["reason"]
|
assert "create_task" not in out["reason"]
|
||||||
with a, b, c:
|
with a, b, c:
|
||||||
related = await check_act(1, 2, tool="relate_rules",
|
related = await check_act(1, 2, tool="relate_rules",
|
||||||
args={"from_rule_id": 4, "to_rule_id": 130, "kind": "overrides"})
|
args={"from_rule_id": 4, "to_rule_id": 130, "kind": "overrides"})
|
||||||
assert "rule 4, rule 130 of" in related["reason"]
|
assert related["reason"].startswith("Changing rule 4, rule 130 in Elsewhere")
|
||||||
|
|
||||||
|
|
||||||
async def test_filing_an_issue_in_another_project_goes_ahead():
|
async def test_filing_an_issue_in_another_project_goes_ahead():
|
||||||
@@ -192,7 +193,7 @@ async def test_a_directory_in_another_project_asks_in_the_words_of_the_act():
|
|||||||
out = await check_act(1, 2, target_project=9, act="git push in")
|
out = await check_act(1, 2, target_project=9, act="git push in")
|
||||||
same = await check_act(1, 2, target_project=2, act="git push in")
|
same = await check_act(1, 2, target_project=2, act="git push in")
|
||||||
assert out["allowed"] is False
|
assert out["allowed"] is False
|
||||||
assert "git push in Elsewhere (project 9)" in out["reason"]
|
assert out["reason"].startswith("Git push in Elsewhere, but this session is working in Home.")
|
||||||
assert same["allowed"] is True
|
assert same["allowed"] is True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user