Skip to content

Incremental engine for long horizon agents 🌟 Star if you like it!

fix(google_docs): name a block held by a pending suggestion as such (#2872)

Jiangzhou27883d593d34
diff --git a/docs/src/content/docs/connectors/google_docs.mdx b/docs/src/content/docs/connectors/google_docs.mdx
index e341cc49..fbbf6d79 100644
--- a/docs/src/content/docs/connectors/google_docs.mdx
+++ b/docs/src/content/docs/connectors/google_docs.mdx
@@ -134,6 +134,7 @@ People can edit the doc. A block a person changed since the target last wrote it
- When the flow's version becomes the same as the person's text (for example, because the flow took the person's fix in), the block is the target's again, and later changes to it are written.
- A block a person deleted as a whole stays deleted, and is reported the same way.
- A block the flow no longer declares, but that a person edited, is left in the doc with the person's text, and the target lets go of it.
+- A block that holds a pending suggestion (made in Suggesting mode, not yet accepted or rejected) is left as it is too, so the suggestion stays, and the warning says it holds one. The flow's newer version is written once the suggestion is accepted or rejected.
A change of formatting counts as an edit as well, since the target compares the text with its bold, italic, code and links. Whitespace does not: an empty paragraph, a space at either end of a paragraph, or bold that takes in the space after a word. Text a person adds between blocks belongs to no block, and the target leaves it alone.
diff --git a/python/cocoindex/connectors/google_docs/_docs.py b/python/cocoindex/connectors/google_docs/_docs.py
index c14d54de..f8209c90 100644
--- a/python/cocoindex/connectors/google_docs/_docs.py
+++ b/python/cocoindex/connectors/google_docs/_docs.py
@@ -361,10 +361,11 @@ class PersonEdit:
"""A block a person changed since the target last wrote it; the target left it as it is."""
label: str # the block's heading path, or its first line when no longer declared
- # "edited": the block is there, changed. "deleted": the person removed it
- # all. "undeclared": the flow no longer declares it, so the target let go
- # of it with the person's text in place.
- kind: Literal["edited", "deleted", "undeclared"]
+ # "edited": the block is there, changed. "suggested": it differs only by a
+ # pending suggestion, which no one has accepted or rejected yet. "deleted":
+ # the person removed it all. "undeclared": the flow no longer declares it,
+ # so the target let go of it with the person's text in place.
+ kind: Literal["edited", "suggested", "deleted", "undeclared"]
# The flow has a newer version of the block, which the target did not write.
withheld: bool
@@ -495,8 +496,14 @@ def plan_write(
# is the target's again.
status[block.block_id] = classify(state, rng, new_fp)
if status[block.block_id] == "kept":
+ # Kept for its pending suggestion alone, or for a person's edit.
+ only_suggested = classify(state, rng, new_fp, settled=True) != "kept"
edits.append(
- PersonEdit(block.label, "edited", withheld=new_fp != rng.written)
+ PersonEdit(
+ block.label,
+ "suggested" if only_suggested else "edited",
+ withheld=new_fp != rng.written,
+ )
)
# Blocks that keep their place: the most already in the declared order. A
diff --git a/python/cocoindex/connectors/google_docs/_target.py b/python/cocoindex/connectors/google_docs/_target.py
index a62c9af1..4da51d35 100644
--- a/python/cocoindex/connectors/google_docs/_target.py
+++ b/python/cocoindex/connectors/google_docs/_target.py
@@ -427,6 +427,8 @@ def _describe(edit: _docs.PersonEdit) -> str:
what = "deleted; the flow still declares it, and it was not written back"
elif edit.kind == "undeclared":
what = "edited, then no longer declared: left with the person's text"
+ elif edit.kind == "suggested":
+ what = "holds a pending suggestion; written once it is accepted or rejected"
elif edit.withheld:
what = "edited; the flow's newer version was not written"
else:
diff --git a/python/tests/connectors/test_google_docs_target.py b/python/tests/connectors/test_google_docs_target.py
index c14bee68..025f9b99 100644
--- a/python/tests/connectors/test_google_docs_target.py
+++ b/python/tests/connectors/test_google_docs_target.py
@@ -1570,7 +1570,7 @@ def test_a_pending_suggestion_is_no_edit_until_accepted(
assert "Google may change eventually named range behavior." in [
t for _, _, t in doc.lines()
]
- assert "'Brief > Risks' (edited" in caplog.text
+ assert "'Brief > Risks' (holds a pending suggestion" in caplog.text
doc.accept_suggestions()
read = _read(setup, BRIEF.replace("behavior.", "behavior, soon."))