1use serde_json::{Value, json};
2
3use crate::error;
4
5fn field(name: &str, kind: &str) -> Value {
6 json!({"name": name, "type": kind})
7}
8fn array_field(name: &str, item_kind: &str) -> Value {
9 json!({"name": name, "type": "array", "items": {"type": item_kind}})
10}
11fn nullable_field(name: &str, kind: &str) -> Value {
12 json!({"name": name, "type": kind, "nullable": true})
13}
14fn nullable_array_field(name: &str, item_kind: &str) -> Value {
15 json!({"name": name, "type": "array", "items": {"type": item_kind}, "nullable": true})
16}
17fn object_field(name: &str, nullable: bool, description: &str, fields: Vec<Value>) -> Value {
18 json!({"name": name, "type": "object", "nullable": nullable, "description": description, "fields": fields})
19}
20fn described(mut field: Value, description: &str) -> Value {
21 field["description"] = json!(description);
22 field
23}
24fn debugging_setup() -> Value {
25 object_field(
26 "debugging_setup",
27 true,
28 "Managed connection commands, available when no endpoint listens. Restart commands require confirmation and preserve prior settings; recover restores interrupted setup settings",
29 vec![
30 described(
31 field("shell", "string"),
32 "zsh, wsl or powershell: where the commands run",
33 ),
34 field("open", "string"),
35 field("close", "string"),
36 ],
37 )
38}
39fn sender() -> Value {
40 object_field(
41 "from",
42 true,
43 "Sender; null for system events",
44 vec![object_field(
45 "user",
46 true,
47 "The sending user",
48 vec![
49 field("id", "string"),
50 nullable_field("displayName", "string"),
51 ],
52 )],
53 )
54}
55fn body() -> Value {
56 object_field(
57 "body",
58 false,
59 "Message content",
60 vec![
61 json!({"name": "contentType", "type": "string", "enum": ["text", "html"]}),
62 field("content", "string"),
63 ],
64 )
65}
66fn arg(name: &str, kind: &str, description: &str) -> Value {
67 json!({"name": name, "type": kind, "description": description})
68}
69fn required_arg(name: &str, kind: &str, description: &str) -> Value {
70 json!({"name": name, "type": kind, "description": description, "required": true})
71}
72
73fn single(name: &str, description: &str, effects: &str, fields: Vec<Value>) -> Value {
74 json!({"name": name, "description": description, "effects": effects, "cardinality": "single", "output_fields": fields})
75}
76
77fn paged(name: &str, description: &str, fields: Vec<Value>) -> Value {
78 json!({
79 "name": name, "description": description, "effects": "read_only", "cardinality": "unbounded",
80 "pagination": {"style": "cursor", "cursor_field": "next_cursor", "cursor_arg": "--cursor", "limit_arg": "--limit"},
81 "fields_arg": "--fields",
82 "args": [
83 {"name": "--limit", "type": "integer", "default": 50, "x-minimum": 1, "x-maximum": 50, "description": "Maximum records in this page"},
84 arg("--cursor", "string", "Opaque next_cursor value from the previous page; omit for the newest page"),
85 arg("--fields", "string", "Comma-separated top-level output fields to keep; unknown names are omitted")
86 ],
87 "output_fields": fields
88 })
89}
90
91fn offset_paged(name: &str, description: &str, fields: Vec<Value>) -> Value {
92 json!({
93 "name": name, "description": description, "effects": "read_only", "cardinality": "unbounded",
94 "pagination": {"style": "offset", "offset_arg": "--offset", "limit_arg": "--limit"},
95 "fields_arg": "--fields",
96 "args": [
97 {"name": "--limit", "type": "integer", "default": 50, "x-minimum": 1, "x-maximum": 100, "description": "Maximum records in this page"},
98 {"name": "--offset", "type": "integer", "default": 0, "x-minimum": 0, "description": "Number of records to skip; use next_offset from the previous page"},
99 arg("--fields", "string", "Comma-separated top-level output fields to keep; unknown names are omitted")
100 ],
101 "output_fields": fields
102 })
103}
104
105fn conversation_args() -> Vec<Value> {
106 vec![
107 json!({"name": "--chat", "type": "string", "x-conflicts": ["--team", "--channel"], "description": "Chat ID from chats list; give this, or --team with --channel"}),
108 json!({"name": "--team", "type": "string", "x-requires": ["--channel"], "description": "Team ID (Graph only)"}),
109 json!({"name": "--channel", "type": "string", "x-requires": ["--team"], "description": "Channel ID within --team (Graph only)"}),
110 ]
111}
112
113fn command_errors(name: &str) -> &'static [&'static str] {
116 const GRAPH_READ: &[&str] = &[
117 "auth",
118 "permission_denied",
119 "not_found",
120 "rate_limit",
121 "api_error",
122 "unsupported",
123 ];
124 const CONVERSATION_READ: &[&str] = &[
125 "auth",
126 "permission_denied",
127 "not_found",
128 "rate_limit",
129 "api_error",
130 "unsupported",
131 "desktop_error",
132 ];
133 match name {
134 "init" => &[
135 "auth",
136 "tty_required",
137 "confirmation_required",
138 "unsupported",
139 "desktop_error",
140 ],
141 "auth login" => &["auth", "tty_required", "unsupported"],
142 "auth logout" => &["unsupported"],
143 "auth status" => &["auth", "rate_limit", "api_error", "desktop_error"],
144 "profile remove" => &["confirmation_required"],
145 "whoami" | "list" | "channels list" => GRAPH_READ,
146 "chats list" | "messages list" => CONVERSATION_READ,
147 "messages send" => &[
148 "auth",
149 "read_only",
150 "permission_denied",
151 "not_found",
152 "rate_limit",
153 "api_error",
154 "confirmation_required",
155 "unconfirmed",
156 "unsupported",
157 "desktop_error",
158 ],
159 "messages status" => &["unsupported", "desktop_error"],
160 "desktop status" | "desktop recover" => &["desktop_error", "unsupported"],
161 "desktop connect" | "desktop disconnect" => {
162 &["desktop_error", "unsupported", "confirmation_required"]
163 }
164 "tui" => &["tty_required"],
165 "doctor" => &["unhealthy"],
166 "schema" => &["not_found"],
167 _ => &[],
168 }
169}
170
171fn example(name: &str) -> Value {
172 let (args, stdin): (&[&str], Option<&str>) = match name {
173 "init" => (&["init", "--no-login"], None),
174 "auth login" => (&["auth", "login", "--device-code"], None),
175 "auth logout" => (&["auth", "logout"], None),
176 "auth status" => (&["auth", "status", "--offline"], None),
177 "profile list" => (&["profile", "list"], None),
178 "profile use" => (&["profile", "use", "work"], None),
179 "profile remove" => (&["profile", "remove", "old", "--yes"], None),
180 "config show" => (&["config", "show"], None),
181 "config path" => (&["config", "path"], None),
182 "whoami" => (&["whoami"], None),
183 "list" => (&["list", "--limit", "20"], None),
184 "channels list" => (&["channels", "list", "TEAM_ID"], None),
185 "chats list" => (
186 &[
187 "chats",
188 "list",
189 "--limit",
190 "20",
191 "--fields",
192 "id,topic,lastUpdatedDateTime",
193 ],
194 None,
195 ),
196 "messages list" => (
197 &["messages", "list", "--chat", "CHAT_ID", "--limit", "20"],
198 None,
199 ),
200 "messages send" => (
201 &[
202 "messages", "send", "--chat", "CHAT_ID", "--body", "-", "--yes",
203 ],
204 Some("On it."),
205 ),
206 "messages status" => (
207 &[
208 "messages",
209 "status",
210 "--chat",
211 "CHAT_ID",
212 "--client-message-id",
213 "100000000000000001",
214 ],
215 None,
216 ),
217 "desktop status" => (&["desktop", "status", "--port", "9222"], None),
218 "desktop connect" => (&["desktop", "connect", "--port", "9222", "--yes"], None),
219 "desktop disconnect" => (&["desktop", "disconnect", "--port", "9222", "--yes"], None),
220 "desktop recover" => (&["desktop", "recover", "--port", "9222"], None),
221 "tui" => (&["tui", "--demo", "--snapshot"], None),
222 "doctor" => (&["doctor", "--offline"], None),
223 "capabilities" => (&["capabilities"], None),
224 "schema" => (&["schema", "--command", "messages send"], None),
225 "completions" => (&["completions", "bash"], None),
226 _ => return Value::Null,
227 };
228 let mut value = json!({"args": args});
229 if let Some(stdin) = stdin {
230 value["stdin"] = json!(stdin);
231 }
232 value
233}
234
235pub fn generate(command_filter: Option<&str>) -> Value {
236 let identity = vec![
237 field("id", "string"),
238 field("displayName", "string"),
239 field("userPrincipalName", "string"),
240 nullable_field("mail", "string"),
241 ];
242 let mut commands = vec![
243 {
244 let mut value = single(
245 "init",
246 "Configure a Graph or experimental desktop profile; desktop init opens Teams' debugging port (restarting Teams after confirmation) and verifies a chat read",
247 "non_idempotent",
248 vec![
249 field("profile", "string"),
250 field("backend", "string"),
251 field("config_path", "string"),
252 nullable_field("signed_in", "boolean"),
253 field("client_id", "string"),
254 field("tenant", "string"),
255 field("channel_history_requested", "boolean"),
256 field("read_only", "boolean"),
257 nullable_field("desktop_port", "integer"),
258 nullable_field("desktop_account", "string"),
259 nullable_field("endpoint_available", "boolean"),
260 nullable_field("connection", "object"),
261 field("session_verified", "boolean"),
262 nullable_field("teams_restarted", "boolean"),
263 nullable_field("chat_list_empty", "boolean"),
264 ],
265 );
266 value["args"] = json!([
267 {"name":"--backend","type":"string","enum":["graph","desktop"],"default":"graph","description":"Connection method; desktop supports diagnostics, chats and opt-in chat sending"},
268 {"name":"--desktop-port","type":"integer","description":"Existing loopback endpoint port (desktop only; default 9222)","x-minimum":1024,"x-maximum":65535},
269 {"name":"--desktop-account","type":"string","enum":["auto","personal","work-school"],"default":"auto","description":"Select the Teams account surface; multiple cached accounts within it remain unsupported"},
270 arg(
271 "--client-id",
272 "string",
273 "Override the maintained teams-cli public-client application ID"
274 ),
275 arg("--tenant", "string", "Tenant ID, domain, or organizations"),
276 arg(
277 "--no-login",
278 "boolean",
279 "Save configuration without sign-in or contacting Teams"
280 ),
281 arg("--device-code", "boolean", "Use device-code sign-in"),
282 arg(
283 "--channel-history",
284 "boolean",
285 "Request admin-consented channel-history access"
286 ),
287 {"name":"--read-only","type":"boolean","x-conflicts":["--allow-send"],"description":"Block remote write operations"},
288 {"name":"--allow-send","type":"boolean","x-requires":{"--backend":"desktop"},"x-conflicts":["--read-only"],"description":"Allow a desktop profile to send chat messages (desktop profiles are read-only otherwise)"}
289 ]);
290 value["confirmation_bypass_arg"] = json!("--yes");
291 value
292 },
293 {
294 let mut value = single(
295 "auth login",
296 "Sign in with delegated Microsoft OAuth and protect credentials in the OS store",
297 "idempotent",
298 vec![
299 field("profile", "string"),
300 field("expires_at", "integer"),
301 nullable_field("scope", "string"),
302 field("channel_history_requested", "boolean"),
303 ],
304 );
305 value["args"] = json!([
306 arg(
307 "--device-code",
308 "boolean",
309 "Use device-code sign-in for headless and remote environments"
310 ),
311 arg(
312 "--channel-history",
313 "boolean",
314 "Request admin-consented channel-history access"
315 )
316 ]);
317 value
318 },
319 single(
320 "auth logout",
321 "Remove locally stored delegated credentials",
322 "idempotent",
323 vec![field("profile", "string"), field("signed_in", "boolean")],
324 ),
325 {
326 let mut value = single(
327 "auth status",
328 "Verify authentication and inspect credential state",
329 "read_only",
330 vec![
331 field("profile", "string"),
332 field("configured", "boolean"),
333 field("backend", "string"),
334 nullable_field("signed_in", "boolean"),
335 field("verified", "boolean"),
336 nullable_field("identity", "object"),
337 field("config_path", "string"),
338 field("read_only", "boolean"),
339 nullable_array_field("granted_scopes", "string"),
340 nullable_field("channel_history", "boolean"),
341 nullable_field("endpoint_available", "boolean"),
342 nullable_field("connection", "object"),
343 field("session_verified", "boolean"),
344 ],
345 );
346 value["args"] = json!([arg(
347 "--offline",
348 "boolean",
349 "Inspect local state without contacting Graph or the desktop endpoint"
350 )]);
351 value
352 },
353 single(
354 "profile list",
355 "List configured profiles and identify the active one",
356 "read_only",
357 vec![
358 json!({"name": "items", "type": "array", "items": {"type": "object", "fields": [
359 field("name", "string"),
360 field("active", "boolean"),
361 json!({"name": "backend", "type": "string", "enum": ["graph", "desktop"]}),
362 field("client_id", "string"),
363 field("tenant", "string"),
364 field("read_only", "boolean")
365 ]}}),
366 field("total", "integer"),
367 ],
368 ),
369 {
370 let mut value = single(
371 "profile use",
372 "Select the default profile for future commands",
373 "idempotent",
374 vec![field("profile", "string"), field("active", "boolean")],
375 );
376 value["args"] = json!([required_arg("name", "string", "Profile name")]);
377 value
378 },
379 {
380 let mut value = single(
381 "profile remove",
382 "Remove a profile and its stored credential",
383 "idempotent",
384 vec![field("profile", "string"), field("removed", "boolean")],
385 );
386 value["args"] = json!([required_arg("name", "string", "Profile name")]);
387 value["confirmation_bypass_arg"] = json!("--yes");
388 value
389 },
390 single(
391 "config show",
392 "Print the resolved profile without credentials",
393 "read_only",
394 vec![
395 field("profile", "string"),
396 field("backend", "string"),
397 nullable_field("desktop_port", "integer"),
398 nullable_field("desktop_account", "string"),
399 field("client_id", "string"),
400 field("tenant", "string"),
401 field("read_only", "boolean"),
402 field("config_path", "string"),
403 ],
404 ),
405 single(
406 "config path",
407 "Print the absolute configuration file path",
408 "read_only",
409 vec![],
410 ),
411 single(
412 "whoami",
413 "Show the signed-in Microsoft 365 identity",
414 "read_only",
415 identity,
416 ),
417 offset_paged(
418 "list",
419 "List teams joined by the signed-in user",
420 vec![
421 field("id", "string"),
422 field("displayName", "string"),
423 nullable_field("description", "string"),
424 ],
425 ),
426 {
427 let mut value = offset_paged(
428 "channels list",
429 "List channels in a team",
430 vec![
431 field("id", "string"),
432 field("displayName", "string"),
433 nullable_field("description", "string"),
434 field("membershipType", "string"),
435 ],
436 );
437 value["args"]
438 .as_array_mut()
439 .unwrap()
440 .insert(0, required_arg("team", "string", "Team ID"));
441 value
442 },
443 paged(
444 "chats list",
445 "List one-to-one, group, and meeting chats",
446 vec![
447 described(
448 field("id", "string"),
449 "Chat ID for messages list/send; the chat with yourself is 48:notes on desktop",
450 ),
451 json!({"name": "chatType", "type": "string", "enum": ["oneOnOne", "group", "meeting"]}),
452 nullable_field("topic", "string"),
453 described(field("lastUpdatedDateTime", "string"), "RFC 3339"),
454 json!({"name": "members", "type": "array", "items": {"type": "object", "fields": [
455 field("userId", "string"),
456 nullable_field("displayName", "string")
457 ]}}),
458 object_field(
459 "viewpoint",
460 true,
461 "The signed-in user's read state",
462 vec![nullable_field("lastMessageReadDateTime", "string")],
463 ),
464 object_field(
465 "lastMessagePreview",
466 true,
467 "Latest message; desktop only",
468 vec![
469 field("id", "string"),
470 field("createdDateTime", "string"),
471 sender(),
472 body(),
473 ],
474 ),
475 ],
476 ),
477 {
478 let mut value = paged(
479 "messages list",
480 "List messages from one chat, or from a channel with optional admin-consented access",
481 vec![
482 field("id", "string"),
483 described(
484 field("createdDateTime", "string"),
485 "RFC 3339; pages are newest first",
486 ),
487 sender(),
488 body(),
489 described(nullable_field("deleted", "boolean"), "Desktop only"),
490 described(
491 nullable_field("clientMessageId", "string"),
492 "Desktop cache only; exact send correlation ID",
493 ),
494 described(
495 nullable_field("status", "string"),
496 "Desktop cache only; raw Teams status",
497 ),
498 ],
499 );
500 let args = value["args"].as_array_mut().unwrap();
501 args.splice(0..0, conversation_args());
502 value
503 },
504 {
505 let mut value = single(
506 "messages send",
507 "Send one plain-text message as the signed-in user",
508 "non_idempotent",
509 vec![
510 described(field("id", "string"), "Message ID"),
511 nullable_field("createdDateTime", "string"),
512 nullable_field("webUrl", "string"),
513 nullable_field("chatId", "string"),
514 described(
515 nullable_field("source", "string"),
516 "\"desktop\" for desktop sends",
517 ),
518 described(
519 nullable_field("clientMessageId", "string"),
520 "Desktop only; correlation ID, not an idempotency key",
521 ),
522 described(
523 nullable_field("delivery_state", "string"),
524 "Desktop only: submitted, queued, delivered, failed or unknown",
525 ),
526 described(
527 nullable_field("status", "string"),
528 "Desktop only; Teams' own delivery label, e.g. Delivered",
529 ),
530 ],
531 );
532 let mut args = conversation_args();
533 args.push(json!({"name": "--body", "type": "string", "required": true, "x-max-length": crate::desktop::MAX_BODY,
534 "description": "Plain-text message body, or - to read it from stdin; must not be blank"}));
535 value["args"] = json!(args);
536 value["confirmation_bypass_arg"] = json!("--yes");
537 value
538 },
539 json!({"name":"tui", "description":"Open the keyboard-first terminal interface; offers a confirmed Teams debugging restart on WSL when no endpoint listens; Enter sends a chat message on a profile that allows writes", "effects":"non_idempotent", "output_kind":"opaque", "media_type":"text/plain", "requires_tty":true, "args":[arg("--demo", "boolean", "Use deterministic sample data"), arg("--snapshot", "boolean", "Print one ANSI-free demo frame")]}),
540 {
541 let mut value = single(
542 "doctor",
543 "Check configuration and the selected backend's access (desktop checks endpoint metadata)",
544 "read_only",
545 vec![
546 field("backend", "string"),
547 array_field("checks", "object"),
548 field("healthy", "boolean"),
549 nullable_field("connection", "object"),
550 nullable_field("endpoint_available", "boolean"),
551 field("session_verified", "boolean"),
552 debugging_setup(),
553 ],
554 );
555 value["args"] = json!([arg(
556 "--offline",
557 "boolean",
558 "Check local state without contacting Graph or the desktop endpoint"
559 )]);
560 value
561 },
562 single(
563 "capabilities",
564 "Describe supported and deliberately unsupported capabilities",
565 "read_only",
566 vec![
567 array_field("supported", "string"),
568 array_field("unsupported", "string"),
569 array_field("account_types", "string"),
570 field("api", "string"),
571 array_field("notes", "string"),
572 field("backends", "object"),
573 ],
574 ),
575 json!({
576 "name":"schema",
577 "description":"Emit the offline CLI Spec v0.3 contract",
578 "effects":"read_only",
579 "cardinality":"single",
580 "stdout_schema":{},
581 "args":[arg("--command", "string", "Return only one complete command path")]
582 }),
583 json!({"name":"completions", "description":"Generate a shell completion script", "effects":"read_only", "output_kind":"opaque", "media_type":"text/plain", "args":[arg("shell", "string", "Shell name")]}),
584 ];
585 let mut status = single(
586 "messages status",
587 "Reconcile one client message ID against the newest 50 cached desktop messages; absence remains unknown",
588 "read_only",
589 vec![
590 field("chatId", "string"),
591 field("clientMessageId", "string"),
592 field("found", "boolean"),
593 nullable_field("id", "string"),
594 nullable_field("status", "string"),
595 field("delivery_state", "string"),
596 field("source", "string"),
597 field("scope", "string"),
598 field("retryable", "boolean"),
599 ],
600 );
601 status["args"] = json!([
602 required_arg("--chat", "string", "Chat ID"),
603 required_arg(
604 "--client-message-id",
605 "string",
606 "18-digit correlation ID returned by send or unconfirmed error"
607 )
608 ]);
609 commands.push(status);
610 for (name, description, effects) in [
611 (
612 "desktop status",
613 "Inspect endpoint metadata and managed-session state; does not verify sign-in",
614 "read_only",
615 ),
616 (
617 "desktop connect",
618 "Explicitly restart Teams with debugging; preserve settings and never adopt an existing endpoint",
619 "non_idempotent",
620 ),
621 (
622 "desktop disconnect",
623 "Explicitly restart this managed Teams process normally; preserve unrelated processes and settings",
624 "non_idempotent",
625 ),
626 (
627 "desktop recover",
628 "Restore interrupted setup settings without restarting Teams or accessing the endpoint",
629 "idempotent",
630 ),
631 ] {
632 let mut value = single(
633 name,
634 description,
635 effects,
636 vec![
637 field("port", "integer"),
638 nullable_field("endpoint_available", "boolean"),
639 field("session_verified", "boolean"),
640 field("management", "object"),
641 nullable_field("connection", "object"),
642 ],
643 );
644 value["args"] = json!([{"name":"--port","type":"integer","x-minimum":1024,"x-maximum":65535,"description":"Override selected profile port"}]);
645 if matches!(name, "desktop connect" | "desktop disconnect") {
646 value["confirmation_bypass_arg"] = json!("--yes");
647 }
648 commands.push(value);
649 }
650 for command in &mut commands {
651 let name = command["name"].as_str().unwrap_or_default().to_string();
652 let mut errors = vec!["invalid_input", "unexpected_error"];
653 errors.extend(command_errors(&name));
654 command["errors"] = json!(errors);
655 let example = example(&name);
656 if !example.is_null() {
657 command["example"] = example;
658 }
659 command["extensions"] = json!({"backends": match command["name"].as_str().unwrap_or_default() {
660 "auth login" | "auth logout" | "whoami" | "list" | "channels list" => vec!["graph"],
661 "desktop status" | "desktop connect" | "desktop disconnect" | "desktop recover" | "messages status" => vec!["desktop"],
662 _ => vec!["graph", "desktop"],
663 }});
664 match command["name"].as_str().unwrap_or_default() {
665 "tui" => {
666 command["extensions"]["desktop"] = json!(
667 "macOS/Windows/WSL; chats and chat messages from the Teams client's local cache; sending needs a profile created with --allow-send"
668 )
669 }
670 "chats list" | "messages list" => {
671 command["extensions"]["desktop"] = json!(
672 "macOS/Windows/WSL; chats, not channels; read from the Teams client's local cache; pages carry source \"desktop_cache\""
673 )
674 }
675 "messages send" => {
676 command["extensions"]["desktop"] = json!(
677 "macOS/Windows/WSL; plain-text chat messages through the running Teams window; needs a profile created with `init --allow-send`; prompts on a terminal and needs --yes otherwise; results carry source \"desktop\", clientMessageId and Teams' status"
678 )
679 }
680 _ => {}
681 }
682 }
683 if let Some(filter) = command_filter {
684 commands.retain(|value| value["name"] == filter);
685 }
686 json!({
687 "$schema": "https://clispec.dev/schema/v0.3.json",
688 "clispec": "0.3",
689 "name": "teams",
690 "version": env!("CARGO_PKG_VERSION"),
691 "description": "A Microsoft Teams CLI and TUI designed equally for humans and agents",
692 "output": {"tty": "text", "piped": "json"},
693 "global_args": [
694 {"name":"--output", "short":"-o", "type":"string", "enum":["auto","text","json"], "default":"auto", "description":"Output format"},
695 {"name":"--profile", "type":"string", "x-env":"TEAMS_PROFILE", "description":"Configuration profile; defaults to the active one"},
696 {"name":"--quiet", "type":"boolean", "description":"Suppress informational stderr output"},
697 {"name":"--yes", "short":"-y", "type":"boolean", "description":"Confirm without prompting (desktop sends, profile removal)"}
698 ],
699 "commands": commands,
700 "errors": error::ALL.iter().map(|e| json!({"kind":e.kind,"exit_code":e.exit_code,"retryable":e.retryable,"description":e.description})).collect::<Vec<_>>(),
701 "extensions": {
702 "backends":backend_capabilities(),
703 "authentication":"delegated_oauth",
704 "api":"Microsoft Graph v1.0",
705 "default_client_id": crate::config::DEFAULT_CLIENT_ID,
706 "login_modes":["browser_pkce","device_code"],
707 "read_only_env":"TEAMS_READ_ONLY",
708 "environment":{
709 "TEAMS_PROFILE":"Profile to use when --profile is not given",
710 "TEAMS_READ_ONLY":"true blocks every remote write; false cannot unlock a desktop profile",
711 "TEAMS_ACCESS_TOKEN":"Graph access token that overrides the stored credential for this run",
712 "TEAMS_CLIENT_ID":"Graph application ID override",
713 "TEAMS_TENANT":"Graph tenant override",
714 "TEAMS_DESKTOP_HELPER":"Path to a teams.exe speaking the same helper protocol to use as the WSL desktop helper"
715 },
716 "collection_envelope":{
717 "items":"array of records described by the command's output_fields",
718 "next_cursor":"cursor-paged commands: pass to --cursor for the next page; absent on the last page",
719 "next_offset":"offset-paged commands: pass to --offset for the next page; absent on the last page",
720 "truncated":"true when more records exist",
721 "source":"\"desktop_cache\" when records come from the Teams client's local cache; absent for Graph"
722 },
723 "error_envelope":"stderr carries {\"error\":{\"kind\",\"message\",\"retryable\"}} when stdout is not a terminal or --output json is given; rate_limit adds retry_after_seconds when Microsoft sends it; uncertain desktop sends add chatId, clientMessageId and delivery_state unknown",
724 "idempotency":"Sends cannot be made idempotent: neither Graph nor Teams accepts a caller-supplied key. Never resend after unconfirmed without reading the conversation first.",
725 "baseline_scopes": crate::auth::BASE_SCOPES.split_whitespace().collect::<Vec<_>>(),
726 "privileged_scopes":[crate::auth::CHANNEL_HISTORY_SCOPE]
727 }
728 })
729}
730
731pub fn backend_capabilities() -> Value {
732 json!({
733 "graph":{"default":true,"authentication":"delegated_oauth","api":"Microsoft Graph v1.0","account_types":["Microsoft 365 work or school"]},
734 "desktop":{"experimental":true,"read_only_by_default":true,"platforms":["macos","windows","wsl"],
735 "account_types":["Microsoft 365 work or school","personal Microsoft accounts"],"account_selection":"account_type_then_single_account_only",
736 "authentication":"teams_desktop_session_unverified","supported":["configuration","connection metadata","doctor","auth status","managed connect/status/disconnect/recover","delivery reconciliation by client message ID","chats (macos, windows, wsl)","chat messages (macos, windows, wsl)","send plain-text chat messages (macos, windows, wsl; opt-in)","TUI (macos, windows, wsl)"],
737 "unsupported":["teams and channels","identity","channel messages, replies, mentions, attachments and edits","subscriptions","automatic Teams launch or restart"],
738 "requires":"existing Teams-owned loopback debugging endpoint; WSL requires Windows executable interop",
739 "transport":{"macos":"native_loopback","windows":"windows_native","wsl":"windows_helper_stdio"},
740 "chat_source":"desktop_cache","session_verified":false,"default_port":crate::config::DEFAULT_DESKTOP_PORT}
741 })
742}