Commit Graph

661 Commits

Author SHA1 Message Date
harshitsinghbhandari e2b43ec0b2 fix comments 2026-04-05 18:41:46 +05:30
harshitsinghbhandari 5e19249ec3 fix: clean up OrchestratorSelector tests and add spawn resilience
- Remove phantom `projects` prop from test setup (was dead code)
- Deduplicate test coverage: consolidate component tests into
  OrchestratorSelector.test.tsx, keep only page route tests in
  orchestrators.test.tsx
- Fix useRouter mock to capture and assert router.push calls
- Add finally block to handleSpawnNew for resilience (ensures
  isSpawning is reset even if router.push fails)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 23:21:22 +05:30
harshitsinghbhandari a21b97656b fix: correct tmux target fallback and deduplicate orchestrator listing
- Fix tmux target to use session ID when runtimeHandle is missing,
  preventing references to non-existent sessions
- Extract mapSessionsToOrchestrators helper to eliminate duplicate
  orchestrator listing logic between page.tsx and API route

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 22:43:11 +05:30
harshitsinghbhandari 5255f997a1 refactor: deduplicate Orchestrator interface
Export Orchestrator interface from OrchestratorSelector component
and import it in page.tsx to avoid silent divergence risk.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 22:21:26 +05:30
harshitsinghbhandari 25b3f31a1c test: update start command tests for auto-select behavior
Update existing test to verify the new --no-dashboard auto-select
behavior and add a separate test for dashboard-enabled selection
message.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 22:10:11 +05:30
harshitsinghbhandari 4e60238d5d test: add edge case tests for formatRelativeTime
Add tests to verify proper handling of:
- Invalid date strings (returns "Unknown")
- Future timestamps (returns "Just now")
- Null dates (returns "Unknown")

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 22:01:09 +05:30
harshitsinghbhandari f9abcdf32f fix: auto-select orchestrator when --no-dashboard is used
When --no-dashboard is used and existing orchestrators are found,
auto-select the most recently active one instead of deferring to
dashboard selection (which isn't available). This ensures the CLI
remains usable without the dashboard.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 21:57:56 +05:30
harshitsinghbhandari d54ca026c1 fix: wrap session listing in try/catch for proper error handling
The sm.list() call was outside the existing try/catch that handles
orchestrator setup failures. If listing sessions throws, the spinner
could be left running and the dashboard process could leak.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 21:56:53 +05:30
harshitsinghbhandari e0b5aa0975 fix: remove unused projects prop from OrchestratorSelector
The projects prop was declared and passed but never used, causing
unnecessary data fetching and serialization. Removed the prop from
the component interface, page, and tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 21:56:29 +05:30
harshitsinghbhandari 2a0f27a940 fix: handle invalid and future dates in formatRelativeTime
Guard against NaN timestamps from invalid ISO date strings and handle
future timestamps gracefully by returning "Just now" instead of
negative values.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 21:54:47 +05:30
harshitsinghbhandari 2a1b513e7d fix tests 2026-04-04 21:52:50 +05:30
harshitsinghbhandari 71bdf75f53 add missing mock list 2026-04-04 19:32:01 +05:30
harshitsinghbhandari 0b7b3153a9 fix: prevent ao start from spawning duplicate orchestrators
When ao start is run and existing orchestrator sessions exist for the
project, the CLI now skips spawning a new one. Instead:

- Detects existing orchestrator sessions before spawning
- Opens the dashboard to a new /orchestrators page for session selection
- Users can resume an existing orchestrator or start a new one

Changes:
- packages/cli/src/commands/start.ts: Check for existing orchestrators,
  redirect to selection page if found
- packages/web/src/app/api/orchestrators/route.ts: Add GET endpoint to
  list orchestrators for a project
- packages/web/src/app/orchestrators/page.tsx: New page for orchestrator
  selection
- packages/web/src/components/OrchestratorSelector.tsx: UI component for
  selecting or spawning orchestrators
- packages/web/src/components/__tests__/OrchestratorSelector.test.tsx:
  Tests for the selector component

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-04 19:05:51 +05:30
Harsh Batheja 34bc5bb2d5
feat: support multiple concurrent orchestrators with isolated worktrees (#870)
* feat: support multiple concurrent orchestrators with isolated worktrees

- Each orchestrator session gets a numbered ID ({prefix}-orchestrator-N)
  and an isolated git worktree, replacing the single shared orchestrator
- reserveNextOrchestratorIdentity atomically reserves the next available
  number and detects conflicting project prefix configurations early
- isOrchestratorSession / isOrchestratorSessionName accept optional
  allSessionPrefixes for cross-project false-positive prevention
- getProjectPause and resolveGlobalPause track the longest active pause
  across all concurrent orchestrators instead of returning the first found
- cleanupWorktreeAndMetadata helper used consistently on all failure paths
  including post-launch; system prompt file included in cleanup
- pollBacklog, status.ts, ProjectSidebar, sessions page, global-pause,
  project-utils, serialize, and sessions API route all pass
  allSessionPrefixes to isOrchestratorSession
- Web sessions/[id]/page.tsx fetches project prefix map and passes it
  through prefixByProjectRef to avoid stale closure in fetchProjectSessions

* fix: seed sseAttentionLevels from fresh sessions on full refresh

When scheduleRefresh dispatches a reset action, derive sseAttentionLevels
from the freshly fetched sessions using getAttentionLevel. This clears
phantom entries for removed sessions and seeds correct levels for new
sessions, preventing stale favicon color and attention counts until the
next SSE snapshot.

* fix: merge duplicate @/lib/types imports into single import statement

Combining the separate import type and value import from @/lib/types
into one import to satisfy the no-duplicate-imports lint rule.
2026-04-04 12:30:51 +05:30
Dhruv Sharma ed187d976c
Merge pull request #873 from harshitsinghbhandari/feat/736
feat(core): support external tracker, scm, and notifier plugins from config
2026-04-04 02:50:19 +05:30
harshitsinghbhandari 32075b879d fix: address illegalcall review comments
- Fix bad temp name for non-standard packages: use full packageName
  instead of last hyphen-segment to avoid collisions between packages
  like "custom-tracker-plugin" and "my-custom-plugin"

- Fix disabled top-level plugin blocking inline loading: when an
  existing plugin entry has `enabled: false`, it's now set to `true`
  when there's an inline tracker/scm/notifier reference for the same
  package/path

- Create validatePluginConfigFields helper to deduplicate the
  TrackerConfigSchema, SCMConfigSchema, and NotifierConfigSchema
  validation logic (was duplicated thrice)

- Fix multi-project external plugin order-dependency: tracker and SCM
  plugins now receive no project-level config at create() time, making
  them consistent with built-in plugins. Project-specific config is
  passed per-call via ProjectConfig argument, avoiding first-project
  wins behavior

- Document post-validation invariant for plugin field: added
  documentation clarifying that `plugin` is always populated after
  validateConfig() to help downstream consumers understand they can
  safely assume non-null after validation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-03 22:09:24 +05:30
Harsh Batheja be0ce0baac
fix(agent-claude-code): return idle state for freshly spawned sessions with no JSONL file (#891)
* fix(agent-claude-code): return idle state when no JSONL session file exists

Freshly spawned sessions had no Claude Code JSONL file yet (Claude Code
doesn't create it until the first conversation), causing getActivityState
to return null → displayed as 'unknown' in ao status.

When the process is running but no session file exists, return
{ state: 'idle', timestamp: now } so the dashboard shows the correct
state immediately after spawn.

Closes #883

* fix(agent-claude-code): use session.createdAt for idle timestamp when no JSONL file

Using new Date() as the timestamp caused isIdleBeyondThreshold to always
compute ~0ms, preventing stuck detection from ever firing for sessions that
hang before creating a JSONL file. Using session.createdAt correctly
represents when the session began, allowing stuck detection to eventually
trigger.
2026-04-03 19:44:59 +05:30
Dhruv Sharma b5bc899392
Merge pull request #808 from ComposioHQ/fix/dashboard-terminal-websockets
fix: start terminal WebSocket servers in ao dashboard dev mode
2026-04-03 12:03:17 +05:30
Dhruv Sharma c488812245
Merge pull request #756 from ComposioHQ/fix/terminal-statuses-in-lifecycle-poll
fix: use TERMINAL_STATUSES in lifecycle poll accounting
2026-04-03 11:31:32 +05:30
harshitsinghbhandari ddba72a485 Merge branch 'main' of https://github.com/ComposioHQ/agent-orchestrator into feat/736 2026-04-03 02:40:53 +05:30
Harsh Batheja 661a30978f
feat: event-driven live tab titles and favicons via SSE (#848)
* feat: event-driven live tab titles and favicons via SSE

Switch tab titles and favicons from polling to real-time SSE updates:

- Extend useSessionEvents to expose sseAttentionLevels map from SSE
  snapshots (server-computed, includes full PR state)
- Refactor DynamicFavicon to use SSE attention levels instead of
  recomputing from the full sessions array (which has stale PR data
  between refreshes)
- Add useSSESessionActivity hook for session detail page to update
  document.title emoji immediately on activity change
- Add live dashboard title showing count of sessions needing attention
- Update PullRequestsPage to use new DynamicFavicon API

Closes #115

* fix: seed initial attention levels to avoid stale favicon/title on first render

Accept initialAttentionLevels parameter in useSessionEvents so callers
can seed the attention map from initialSessions via getAttentionLevel().
This prevents the favicon and dashboard title from briefly showing
"all clear" before the first SSE snapshot arrives.

* fix: add EventSource mock to session page test for SSE hook compatibility

* fix: reset stale activity state when sessionId changes in useSSESessionActivity

Add sessionId to the effect dependency array and reset state to null at
the start of each effect run so callers that reuse the hook with a
different sessionId don't see the previous session's activity.

* fix: reset sseAttentionLevels on initialSessions change to prevent stale data on project switch

The reset action now accepts an optional sseAttentionLevels field. When
initialSessions changes (e.g., project switch via sidebar), the dispatch
passes the current initialAttentionLevels via ref so the favicon and
dashboard title reflect the new project immediately rather than showing
stale attention data until the first SSE snapshot.
2026-04-03 02:36:26 +05:30
harshitsinghbhandari a41291fba9 comments fixed 2026-04-03 01:44:59 +05:30
harshitsinghbhandari 9a3a18b2c7 performed review and fixed 2026-04-03 01:23:37 +05:30
harshitsinghbhandari 6884425e3d fix load builtin error 2026-04-03 00:09:40 +05:30
harshitsinghbhandari 59546eaf93 feat(core): unify plugin config cleaning and enforce reserved fields for tracker and scm 2026-04-02 23:53:05 +05:30
harshitsinghbhandari c58bae743b feat(core): enforce reserved fields in notifier configs and improve loader error handling 2026-04-02 23:38:13 +05:30
harshitsinghbhandari 44528b3cee add error handling for path in config 2026-04-02 23:13:14 +05:30
harshitsinghbhandari 1268c7fa28 fix(core): ensure consistent temp plugin name generation 2026-04-02 22:48:57 +05:30
harshitsinghbhandari 7dd4dc9b4a fix: ensure notifier config is passed when manifest name differs
extractPluginConfig was being called with mod.manifest.name before the
config was updated from the temp name. When manifest name differs from
temp name (e.g., temp "teams" vs manifest "ms-teams"), extractPluginConfig
found no match and returned undefined, causing the plugin to be registered
without its configuration (webhook URLs, tokens, etc.).

Fix by reordering operations:
1. Validate and update configs with manifest.name FIRST
2. Extract plugin config AFTER (now finds the config by manifest.name)
3. Register plugin with its correct configuration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 21:40:53 +05:30
harshitsinghbhandari fcdbe24d6c fix: prevent one project's bad config from breaking shared plugin
When multiple projects share the same external plugin, a misconfiguration
in one project (wrong expectedPluginName) would prevent the plugin from
being registered at all, silently breaking it for all projects.

Fix by:
1. Register the plugin FIRST, before validating individual project configs
2. Validate each project's config in its own try-catch
3. Log validation errors but continue processing other projects

This ensures:
- Plugin is always registered if it loads successfully
- Projects with correct config get updated
- Projects with bad config get a warning but don't break others
- Misconfigured projects fail at point of use with clearer errors

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 21:28:53 +05:30
harshitsinghbhandari aae6377de4 fix: preserve multi-word plugin names from package specifiers
generateTempPluginName was splitting package names on both hyphens and
slashes, which truncated multi-word names like "jira-cloud" to just
"cloud".

Fix by first extracting the package name without scope, then using a
regex to match the common ao-plugin-{slot}-{name} pattern which
preserves the full plugin name including hyphens.

Examples:
- @acme/ao-plugin-tracker-jira-cloud -> jira-cloud (was: cloud)
- ao-plugin-scm-azure-devops -> azure-devops (was: devops)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 21:14:37 +05:30
Tanuja Nair ed136c5a82
Merge pull request #871 from TanujaNair03/fix/prompt-delivery-retry
fix: prompt delivery retry
2026-04-02 21:08:09 +05:30
harshitsinghbhandari f10f45168a fix: address cursor bugbot review comments
- Strip package and path loading metadata from notifier config passed
  to plugin create(). These fields are used for plugin resolution, not
  plugin-specific configuration. Prevents filesystem paths from leaking
  into plugin config where they could conflict with plugin-specific
  fields of the same name.

- Remove collectExternalPluginConfigs from public API exports since it
  is only used internally within config.ts during validateConfig.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 20:18:28 +05:30
harshitsinghbhandari 3e0ce4e3a9 fix: address remaining PR review comments
- Fix multiple projects sharing same external plugin: change
  findExternalPluginEntry to findAllExternalPluginEntries which returns
  all matching entries, allowing all projects to be updated with the
  actual manifest.name

- Fix path without slashes misidentified as npm package: use separate
  pkg and path parameters in generateTempPluginName instead of combining
  them and checking for slashes. Local paths like "my-tracker" (no
  slashes) are now correctly returned as-is

- Replace console.warn with process.stderr.write for structured logging
  in plugin-registry.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 20:06:28 +05:30
Tanuja Nair 7ff45e69b8
Merge branch 'ComposioHQ:main' into fix/prompt-delivery-retry 2026-04-02 19:54:07 +05:30
harshitsinghbhandari 812bfa5bef fix: remove unused import and add missing location field
- Remove unused collectExternalPluginConfigs import from tests
- Add missing location field to _externalPluginEntries in test

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 19:51:10 +05:30
harshitsinghbhandari 99386a595e fix: address Copilot review feedback on external plugin support
1. Only set expectedPluginName when user explicitly specifies `plugin`
   - Auto-generated temp names no longer block manifest name inference
   - External plugins like @acme/ao-plugin-tracker-jira-cloud with
     manifest.name "jira-cloud" will now load correctly

2. Add structured location data to ExternalPluginEntryRef
   - New ExternalPluginLocation type with kind/projectId/configType
   - Avoids fragile string parsing of source (project/notifier keys
     can legally contain dots)

3. Expand home paths (~/) in inline plugin configs
   - Apply expandHome() to tracker/scm/notifier path fields
   - Consistent behavior with config.plugins path expansion

4. Improve error messages
   - Use "package" vs "path" in manifest mismatch errors instead
     of always saying "package"

5. Fix tests to use config._externalPluginEntries
   - Tests now check entries stored by validateConfig() instead
     of calling collectExternalPluginConfigs() again on modified config

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 19:38:05 +05:30
harshitsinghbhandari add74f1a46 fix: handle optional plugin field in CLI and web packages
Update all usages of project.tracker.plugin and project.scm.plugin
to use optional chaining since the plugin field is now optional
when package or path fields are specified.

Files updated:
- CLI: doctor.ts, status.ts, verify.ts
- Web: issues/route.ts, verify/route.ts, scm-webhooks.ts,
       serialize.ts, services.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 19:19:44 +05:30
harshitsinghbhandari 3dd8a0c316 feat(core): support external tracker, scm, and notifier plugins from config
Add support for specifying external plugins inline in tracker, scm, and
notifier configs using optional `package` or `path` fields.

**Config schema changes:**
- TrackerConfig, SCMConfig, NotifierConfig now accept optional `package`
  (npm) or `path` (local) fields alongside the existing `plugin` field
- When only `package`/`path` is specified, plugin name is auto-inferred
- When both `plugin` and `package`/`path` are specified, manifest.name
  is validated against the declared plugin name

**Example usage:**
```yaml
projects:
  my-app:
    tracker:
      plugin: jira  # optional - validates against manifest.name
      package: "@acme/ao-plugin-tracker-jira"
      teamId: "TEAM-123"
    scm:
      path: ./plugins/my-scm  # local plugin

notifiers:
  teams:
    package: "@acme/ao-plugin-notifier-teams"
```

**Implementation details:**
- collectExternalPluginConfigs() extracts external plugin entries from
  tracker/scm/notifier configs during config validation
- Auto-generates InstalledPluginConfig entries merged into config.plugins
- Plugin registry validates manifest.name matches expectedPluginName and
  updates config with actual manifest.name after loading
- Warns when plugin slot doesn't match configured slot

Closes #736

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-02 19:04:47 +05:30
Your Name 9e78fe3b23 fix: resolve prompt delivery persistence and false warnings 2026-04-02 17:41:46 +05:30
Dhruv Sharma 59a7423d1e
Merge pull request #869 from ComposioHQ/ci/fix-deploy-vps-guard
ci: fix VPS deploy guard and fingerprint config
2026-04-02 17:40:34 +05:30
Your Name feecc6f177 fix: robust prompt delivery with retries and CLI warnings 2026-04-02 17:27:53 +05:30
Tanuu 5d0142fd03 fix: return 400 for invalid verify API payloads 2026-04-02 16:39:44 +05:30
Dhruv Sharma 1d8ed3ef8e ci: harden VPS deploy workflow 2026-04-02 12:44:50 +05:30
Dhruv Sharma d0983913fc ci: print runner-visible VPS host fingerprints 2026-04-02 12:41:56 +05:30
Dhruv Sharma 65e971349a ci: add temporary deploy fingerprint recovery mode 2026-04-02 12:39:56 +05:30
Dhruv Sharma 1c1e7e08b1 ci: add temporary VPS fingerprint helper 2026-04-02 12:38:10 +05:30
Dhruv Sharma 2a77fcd0dd ci: force full checkout on VPS deploy 2026-04-02 12:21:00 +05:30
Dhruv Sharma 42866c6a0e ci: add manual VPS deploy trigger for branch testing 2026-04-02 12:13:39 +05:30
Harsh Batheja 53ef778357
feat: add CI failure detail notifications in lifecycle manager (#850)
* feat: add CI failure detail notifications in lifecycle manager

When CI fails on a PR, the lifecycle manager now fetches individual check
details (names, statuses, URLs) and sends them to the worker session.
This complements the existing static reaction message with actionable
debugging information.

Flow:
- On first transition to ci_failed: static reaction message fires (existing)
- On next poll: detailed CI failure info with check names and URLs dispatched
- Fingerprinting prevents re-sending the same failure set
- New/changed failures trigger fresh detailed notifications
- Tracking metadata cleared when PR is merged/closed or CI passes

Follows the same deduplication pattern as maybeDispatchReviewBacklog().

* fix: send CI details directly to avoid consuming reaction retry budget

The detailed CI failure dispatch now uses sessionManager.send() directly
instead of executeReaction(), so it doesn't increment the ci-failed
reaction tracker. This prevents low retries/escalateAfter settings from
causing premature escalation before the agent receives failure details.

The transition reaction still owns escalation; the detailed dispatch is
purely informational follow-up delivery.

* feat: add merge conflict notifications in lifecycle manager

Adds maybeDispatchMergeConflicts() that detects merge conflicts from
the PR enrichment cache or getMergeability() and notifies the worker
session. Conflicts are dispatched independently of session status since
they can coexist with ci_failed, changes_requested, etc.

- Uses the existing merge-conflicts reaction config
- Dispatches once per conflict occurrence (tracks lastMergeConflictDispatched)
- Clears tracking when conflicts resolve, allowing re-dispatch if they recur
- Sends directly via sessionManager.send() (same pattern as CI details)

* fix: use CICheck type instead of inline type declaration

Replace inline Array<{ name, status, url, conclusion }> with the
existing CICheck type from ./types.js for formatCIFailureMessage and
the checks variable in maybeDispatchCIFailureDetails.

* fix: resolve no-useless-assignment lint error in merge conflict check

Declare hasConflicts without initial value since both branches of the
if/else assign to it before it's read.

* feat: show agent notification state in session page blockers

The blockers section on both SessionDetail (IssuesList) and SessionCard
(alert pills) now shows whether the agent has been notified about each
blocker. Reads lifecycle manager dispatch metadata:
- lastCIFailureDispatchHash for CI failures
- lastMergeConflictDispatched for merge conflicts
- lastPendingReviewDispatchHash for review comments

Displays "agent notified" indicator next to blockers where the lifecycle
manager has already forwarded the issue to the worker session.

* fix: use lifecycle status as fallback for blockers when PR data is stale

The blockers section now uses the lifecycle manager's session status
metadata as a source of truth when PR enrichment data hasn't caught up.
PR enrichment uses a 5-min cache and can timeout or be rate-limited,
causing blockers to show stale/incorrect state.

Changes:
- IssuesList and getAlerts now check metadata["status"] (lifecycle
  manager state) alongside PR enrichment data
- CI failing: shown when pr.ciStatus is "failing" OR lifecycle status
  is "ci_failed"
- Changes requested: shown when pr.reviewDecision matches OR lifecycle
  status is "changes_requested"
- Merge conflicts: shown when pr.mergeability.noConflicts is false OR
  lifecycle dispatch metadata indicates conflicts were detected

* fix: fall back to getMergeability when cached hasConflicts is undefined

When PREnrichmentData has hasConflicts as undefined (the field is typed
as boolean | undefined), the previous check treated it as no conflicts.
Now falls through to the getMergeability() call instead.

* test: add coverage for CI/conflict notify action and recovery paths

- Test CI tracking clears when CI recovers to passing
- Test notify action for CI failure details (human notification path)
- Test notify action for merge conflicts (human notification path)

These cover the previously uncovered notify action branches and the
CI recovery cleanup path in the lifecycle manager.

* fix: resolve typecheck error in CI recovery test

writeMetadata requires SessionMetadata type which doesn't include
custom keys like lastCIFailureFingerprint. Rewrote the test to use
setupCheck and let the lifecycle manager set tracking metadata
naturally through the CI failure flow, then verify cleanup on recovery.

* fix: don't use dispatch metadata for conflict detection in UI

lastMergeConflictDispatched lingers after conflicts resolve until the
lifecycle manager's next poll clears it. Using it as a conflict signal
caused stale "merge conflict" alerts. Now only pr.mergeability.noConflicts
drives conflict detection; the metadata is only used for the "agent
notified" badge.

* fix: use Promise.allSettled for dispatch functions to avoid orphaned rejections

Promise.all rejects immediately on first failure, leaving in-flight
promises unmonitored. Promise.allSettled waits for all to complete.
2026-04-02 11:23:08 +05:30