Skip to content

feat(sdk): Add Teams communication adapter#768

Merged
tamirdresher merged 6 commits intodevfrom
squad/761-teams-comms
Apr 5, 2026
Merged

feat(sdk): Add Teams communication adapter#768
tamirdresher merged 6 commits intodevfrom
squad/761-teams-comms

Conversation

@diberry
Copy link
Copy Markdown
Collaborator

@diberry diberry commented Apr 2, 2026

Summary

Split from PR #765 — Teams communication adapter only, loop command extracted to PR #767.

Adds Microsoft Teams communication adapter for bidirectional chat via Microsoft Graph API.

Review findings addressed

  1. Lazy-load — dynamic import() instead of top-level, eliminates cold-start tax for non-Teams users
  2. Config design — replaced Teams-specific fields with generic adapterConfig escape hatch
  3. Token security — file permissions 0o600/0o700 on token storage
  4. Changeset added for minor SDK release

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

🛫 PR Readiness Check

ℹ️ This comment updates on each push. Last checked: commit 9362e30

⚠️ 4 item(s) to address before review

Status Check Details
Single commit 6 commits — consider squashing before review
Not in draft Ready for review
Branch up to date Up to date with dev
Copilot review No Copilot review yet — it may still be processing
Changeset present Changeset file found
Scope clean No .squad/ or docs/proposals/ files
No merge conflicts No merge conflicts
Copilot threads resolved 3 unresolved Copilot thread(s) — fix and resolve before merging
CI passing 13 check(s) still running

This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.

@diberry
Copy link
Copy Markdown
Collaborator Author

diberry commented Apr 4, 2026

Files in this PR:

  • .changeset/teams-comms-adapter.md
  • packages/squad-sdk/src/platform/comms-teams.ts
  • packages/squad-sdk/src/platform/comms.ts
  • packages/squad-sdk/src/platform/types.ts
  • test/comms-teams.test.ts

diberry added a commit that referenced this pull request Apr 4, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from 7c4791b to 2217f2a Compare April 4, 2026 13:08
@diberry diberry marked this pull request as ready for review April 4, 2026 13:40
Copilot AI review requested due to automatic review settings April 4, 2026 13:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Microsoft Teams communication adapter to the SDK (Graph API-based) and wires it into the communication-adapter factory with lazy-loading and new config plumbing.

Changes:

  • Introduces TeamsCommunicationAdapter (Graph API auth + post + poll) and exports pure helper utilities with unit tests.
  • Updates the comms factory to lazy-load the Teams adapter and makes createCommunicationAdapter() async.
  • Extends CommunicationConfig with adapterConfig and adds a changeset for an SDK minor release.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
packages/squad-sdk/src/platform/comms-teams.ts New Teams (Graph API) communication adapter + helper utilities + token storage/auth flows.
packages/squad-sdk/src/platform/comms.ts Makes adapter factory async; adds lazy dynamic import for Teams adapter + config plumbing.
packages/squad-sdk/src/platform/types.ts Adds CommunicationConfig.adapterConfig escape hatch for adapter-specific settings.
test/comms-teams.test.ts Unit tests for Teams adapter pure helper functions (formatting/encoding/validation).
.changeset/teams-comms-adapter.md Changeset documenting the new adapter and the async factory breaking change.

diberry added a commit that referenced this pull request Apr 4, 2026
Add Teams comms adapter with Graph API integration, PKCE auth flow,
deep-link URL generation, and message card formatting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from 89a28ea to 2113a4f Compare April 4, 2026 14:12
diberry added a commit that referenced this pull request Apr 4, 2026
Add Teams comms adapter with Graph API integration, PKCE auth flow,
deep-link URL generation, and message card formatting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from 2113a4f to 91200c9 Compare April 4, 2026 14:36
diberry added a commit that referenced this pull request Apr 4, 2026
Add Teams comms adapter with Graph API integration, PKCE auth flow,
deep-link URL generation, and message card formatting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from 91200c9 to 6816bf2 Compare April 4, 2026 15:01
diberry added a commit that referenced this pull request Apr 4, 2026
Add Teams comms adapter with Graph API integration, PKCE auth flow,
deep-link URL generation, and message card formatting.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from 6816bf2 to ee40621 Compare April 4, 2026 17:01
diberry added a commit that referenced this pull request Apr 4, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from e8bf52b to 0004a38 Compare April 4, 2026 17:07
diberry added a commit that referenced this pull request Apr 4, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from 0004a38 to a650e0e Compare April 4, 2026 23:24
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

🟡 Impact Analysis — PR #768

Risk tier: 🟡 MEDIUM

📊 Summary

Metric Count
Files changed 6
Files added 4
Files modified 2
Files deleted 0
Modules touched 4

🎯 Risk Factors

  • 6 files changed (6-20 → MEDIUM)
  • 4 modules touched (2-4 → MEDIUM)

📦 Modules Affected

docs (1 file)
  • docs/features/teams-adapter.md
root (1 file)
  • .changeset/teams-comms-adapter.md
squad-sdk (3 files)
  • packages/squad-sdk/src/platform/comms-teams.ts
  • packages/squad-sdk/src/platform/comms.ts
  • packages/squad-sdk/src/platform/types.ts
tests (1 file)
  • test/comms-teams.test.ts

This report is generated automatically for every PR. See #733 for details.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment on lines 112 to 116
case 'file-log':
return new FileLogCommunicationAdapter(repoRoot);
default:
return new FileLogCommunicationAdapter(repoRoot);
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createAdapterByChannel falls back to file-log for any unknown communications.channel. Because readCommsConfig() type-asserts JSON, a legacy config value like the previous teams-webhook will silently route to FileLog instead of surfacing a migration/error, effectively breaking existing Teams setups. Add runtime validation (and/or an explicit legacy mapping from teams-webhookteams-graph) so misconfigurations are obvious.

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +73
// Ensure permissions are correct even if file already existed
if (platform() === 'win32') {
execFile('icacls', [TOKEN_PATH, '/inheritance:r', '/grant:r', `${process.env.USERNAME ?? 'CURRENT_USER'}:(R,W)`], () => {});
} else {
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, saveTokens() shells out to icacls and ignores all errors (empty callback). If icacls fails (missing on PATH, permission issues, localized output, etc.), the token file may retain inherited ACLs and be more broadly readable than intended. Handle the callback error (or use execFileSync with try/catch) and surface a warning/error so the security guarantee is enforceable.

Copilot uses AI. Check for mistakes.
Comment on lines +635 to +641
function escapeHtml(s: string): string {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}

function stripHtml(html: string): string {
return html.replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').trim();
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escapeHtml() encodes single quotes as &#39;, but stripHtml() doesn't decode &#39; (or &apos;). This means messages posted by Squad may be returned via pollForReplies() with literal entity text instead of apostrophes. Update stripHtml() to decode these entities and add a unit test to lock it in.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@diberry diberry force-pushed the squad/761-teams-comms branch from a650e0e to 69ec9dd Compare April 4, 2026 23:43
Copy link
Copy Markdown
Collaborator

@tamirdresher tamirdresher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — Well-structured Teams adapter: lazy import, 4-tier auth cascade, Graph ID validation, token security. BREAKING async change documented. Tests cover pure helpers.

@tamirdresher tamirdresher merged commit bbcbf7b into dev Apr 5, 2026
18 checks passed
@tamirdresher tamirdresher deleted the squad/761-teams-comms branch April 5, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants