by adom
Drive your whole Google Workspace from the terminal, run by your AI. Read Gmail, write Google Docs, build Google Sheets and Google Slides, search Google Drive, manage Google Calendar and Google Tasks, and post to Google Chat, plus any Google API and a zero-setup personal Gmail.
← Commit history
people/chat dm: review fixes before 0.8.28
From an independent review of PR #3:
- chat dm <name>: only an EXACT match (full name, first name, email local part) can be picked. A prefix-only hit is listed and refused, so if Kale is missing from the directory but Kaleb exists, 'chat dm Kale' errors instead of opening Kaleb's DM. Previously 'a single result' of any rank was accepted ('chat dm Cal' opened Caleb's DM).
- chat dm: an empty target errors with a hint instead of hitting the People API.
- chat dm: a numeric Chat user id (or users/<id>) passes straight to findDirectMessage as it did in 0.8.27, instead of being treated as a name.
- people find --limit must be >= 1 and people list --limit >= 0 (argparse error); --limit 0 used to report 'no match' and a negative limit silently dropped people.
- chat dm help text matches the stricter rule.
- tests/test_people.py: 4 new tests (17 total, all pass).
2 files changed
+63−8
bin/adom-google+27−8@@ -988,6 +988,15 @@ def _fmt_person(r): _RANK_LABEL = {0: "exact", 1: "exact first name / email", 2: "prefix", 3: "partial"} +def _limit_arg(minimum):+ def f(v):+ n = int(v)+ if n < minimum:+ raise argparse.ArgumentTypeError(f"must be >= {minimum}")+ return n+ return f++ def cmd_people_find(a): cfg = _load() q = a.query.strip()@@ -1064,16 +1073,22 @@ def cmd_people_list(a): def _resolve_name_to_email(cfg, name, as_json): """`chat dm <name>`: resolve through the DOMAIN directory only. Exactly one best match or ERROR.- A unique exact hit (full name / first name / local part) wins even if prefix hits exist;- otherwise there must be exactly one result overall. Never guesses."""+ Only an EXACT hit (full name / first name / email local part) can be picked, and it must be+ unique in its tier. Prefix-only hits are listed, never picked: if Kale is not in the directory+ but Kaleb is, `chat dm Kale` errors instead of opening Kaleb's DM. Never guesses.""" domain = _own_domain(cfg, as_json) rows = _people_search(cfg, name, domain, as_json) if not rows: _people_fail(as_json, f'no one in the {domain} directory matches "{name}"; not guessing.', [f"search more broadly: adom-google{_acct_flag()} people find <part-of-name>", "or pass the exact email: adom-google chat dm <email>"])- # A unique hit in the best exact tier wins; otherwise the whole result set must be one person.- pick = [r for r in rows if r["rank"] == rows[0]["rank"]] if rows[0]["rank"] <= 1 else rows+ # Only the best EXACT tier (rank <= 1) can be picked, and only when it holds one person.+ if rows[0]["rank"] > 1:+ listing = "; ".join(f"{r['name']} <{r['email']}>" for r in rows[:15])+ _people_fail(as_json, f'no exact match for "{name}" in the {domain} directory (only partial matches: {listing}); not guessing.',+ ["re-run with the full name or the exact email of the one you mean: adom-google chat dm <email>"],+ data={"query": name, "domain": domain, "people": rows})+ pick = [r for r in rows if r["rank"] == rows[0]["rank"]] if len(pick) != 1: listing = "; ".join(f"{r['name']} <{r['email']}>" for r in pick[:15]) _people_fail(as_json, f'"{name}" matches {len(pick)} people in the {domain} directory: {listing}',@@ -1188,12 +1203,16 @@ def cmd_chat_spaces(a): def cmd_chat_dm(a): cfg = _load() target, person = a.email.strip(), None- if "@" not in target:+ if not target:+ _people_fail(a.json, "empty target", ["pass an email or a name, e.g. adom-google chat dm Kale"])+ if "@" not in target and not target.isdigit() and not target.startswith("users/"): # A NAME: resolve through the Workspace DOMAIN directory only (exactly one match, or ERROR). # An explicit email keeps its original behaviour below, unchanged. person = _resolve_name_to_email(cfg, target, a.json) target = person["email"] sys.stderr.write(f"(resolved \"{a.email}\" -> {person['name']} <{target}> via the domain directory)\n")+ if target.startswith("users/"):+ target = target[len("users/"):] sp = _find_dm(cfg, target) name = sp.get("name") if not name:@@ -2958,14 +2977,14 @@ def main(): ch = sub.add_parser("chat"); chx = ch.add_subparsers(dest="sub") x = chx.add_parser("spaces"); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_chat_spaces)- x = chx.add_parser("dm", help="resolve the 1:1 DM space with a person (email, or a name looked up in your Workspace domain directory)"); x.add_argument("email", metavar="email|name", help="an email, or a name resolved ONLY through your own Workspace domain directory: a unique exact first-name / full-name / email-local-part match, or a single result; anything else is an ERROR listing the candidates"); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_chat_dm)+ x = chx.add_parser("dm", help="resolve the 1:1 DM space with a person (email, or a name looked up in your Workspace domain directory)"); x.add_argument("email", metavar="email|name", help="an email, or a name resolved ONLY through your own Workspace domain directory: a unique exact first-name / full-name / email-local-part match; partial or ambiguous matches are an ERROR listing the candidates"); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_chat_dm) x = chx.add_parser("send"); x.add_argument("--to", required=True, help="spaces/XXX id OR an email (auto-resolves the DM)"); x.add_argument("text", nargs="?", default="", help="message text, or '-' for stdin, or '@file' (optional when --attach is used)"); x.add_argument("--thread", help="threadKey for a threaded reply"); x.add_argument("--attach", action="append", metavar="PATH", help="attach a local file (image/video/PDF/any); repeatable"); x.add_argument("--no-agent-marker", action="store_true", help="don't stamp clientAssignedMessageId=client-agent-*"); x.add_argument("--json", action="store_true", help="print the created message as JSON (name, createTime, text, space, spaceUri, posted)"); x.set_defaults(fn=cmd_chat_send) x = chx.add_parser("read"); x.add_argument("--from", dest="frm", required=True, help="spaces/XXX id OR an email"); x.add_argument("--limit", type=int, default=20); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_chat_read) # Calendar (issue #662) pp = sub.add_parser("people", help="Workspace domain directory: who is <name>, their email, title, Chat DM space"); ppx = pp.add_subparsers(dest="sub")- x = ppx.add_parser("find", help="search YOUR Workspace domain directory by name or email (domain accounts only)"); x.add_argument("query", help="a first/last/full name, email local part, or email"); x.add_argument("--dm", action="store_true", help="also resolve each match's existing 1:1 Chat DM space (first 10 matches)"); x.add_argument("--limit", type=int, default=50, help="max matches to show (default 50)"); x.add_argument("--json", action="store_true", help="{status, data:{query, domain, count, exact, people[]}, hints[]} envelope"); x.set_defaults(fn=cmd_people_find)- x = ppx.add_parser("list", help="every account in YOUR Workspace domain directory (paginated)"); x.add_argument("--limit", type=int, default=0, help="max people to show (default 0 = all)"); x.add_argument("--json", action="store_true", help="{status, data:{domain, count, people[]}, hints[]} envelope"); x.set_defaults(fn=cmd_people_list)+ x = ppx.add_parser("find", help="search YOUR Workspace domain directory by name or email (domain accounts only)"); x.add_argument("query", help="a first/last/full name, email local part, or email"); x.add_argument("--dm", action="store_true", help="also resolve each match's existing 1:1 Chat DM space (first 10 matches)"); x.add_argument("--limit", type=_limit_arg(1), default=50, help="max matches to show (default 50)"); x.add_argument("--json", action="store_true", help="{status, data:{query, domain, count, exact, people[]}, hints[]} envelope"); x.set_defaults(fn=cmd_people_find)+ x = ppx.add_parser("list", help="every account in YOUR Workspace domain directory (paginated)"); x.add_argument("--limit", type=_limit_arg(0), default=0, help="max people to show (default 0 = all)"); x.add_argument("--json", action="store_true", help="{status, data:{domain, count, people[]}, hints[]} envelope"); x.set_defaults(fn=cmd_people_list) cal = sub.add_parser("calendar", help="Google Calendar: list/create events, list calendars"); cax = cal.add_subparsers(dest="sub") x = cax.add_parser("list", help="upcoming events"); x.add_argument("--cal", default="primary"); x.add_argument("--max", type=int, default=10); x.add_argument("--json", action="store_true"); x.set_defaults(fn=cmd_calendar_list)
tests/test_people.py+36@@ -196,6 +196,42 @@ class PeopleTests(unittest.TestCase): self.assertEqual(code, 1) self.assertIn("no 1:1 DM", err) + def test_chat_dm_prefix_only_match_is_never_picked(self):+ # "Cal" only prefix-matches Caleb: listed, never picked (review finding, 2026-11-02)+ fake = Fake(dms={"[email protected]": "spaces/CAL"})+ mod = load(fake)+ code, out, err = run(mod, ["chat", "dm", "Cal"])+ self.assertEqual(code, 1)+ self.assertIn("no exact match", err)+ self.assertIn("[email protected]", err)+ self.assertNotIn("spaces/CAL", out)+ self.assertFalse(any("findDirectMessage" in c[1] for c in fake.calls))++ def test_chat_dm_empty_target_errors_without_api_call(self):+ fake = Fake()+ mod = load(fake)+ code, _, err = run(mod, ["chat", "dm", " "])+ self.assertEqual(code, 1)+ self.assertIn("empty target", err)+ self.assertEqual(fake.calls, [])++ def test_chat_dm_numeric_user_id_passes_through(self):+ for arg in ("123456789", "users/123456789"):+ fake = Fake(dms={"123456789": "spaces/NUM"})+ mod = load(fake)+ code, out, _ = run(mod, ["chat", "dm", arg])+ self.assertEqual(code, 0, arg)+ self.assertIn("spaces/NUM", out)+ self.assertFalse(any("Directory" in c[1] for c in fake.calls), arg)++ def test_limit_validation(self):+ mod = load(Fake())+ self.assertEqual(run(mod, ["people", "find", "Kale", "--limit", "0"])[0], 2) # argparse usage error+ self.assertEqual(run(mod, ["people", "list", "--limit", "-2"])[0], 2)+ code, out, _ = run(mod, ["people", "find", "Kale", "--limit", "1"])+ self.assertEqual(code, 0)+ self.assertIn("[email protected]", out)+ def test_chat_dm_email_path_unchanged(self): fake = Fake(dms={"[email protected]": "spaces/EXT"}) mod = load(fake)