966 Commits

Author SHA1 Message Date
0xmrpeter
cb251ae462 fix(api): accept client-provided turnId in prompt endpoint to prevent SSE echo race condition 2026-04-08 09:22:51 +07:00
0xmrpeter
9e83103574 fix: show Install button for agents with missing external CLI dependencies
Agents like claude-acp and codex-acp wrap external CLIs (claude, codex)
and have an npx/binary distribution in the registry. Previously, missing
external CLIs caused available: false, hiding the Install button entirely
— even though the agent package itself CAN be installed independently.

agent-catalog: for uninstalled agents, available = dist !== null
  Availability now means 'has a distribution to install', not 'all deps
  met'. Missing deps are still surfaced via missingDeps for the UI.

agent-installer: remove hard dep-check block before installation
  Installation proceeds even when external CLIs are absent. The required
  setup steps (e.g. 'npm install -g @anthropic-ai/claude-code') are
  returned in the result so callers can guide the user post-install.
  The uvx runtime check is kept as it is a true hard requirement.
2026-04-08 00:56:11 +07:00
0xmrpeter
44b658e3db chore: bump version to 2026.407.1
fix(tests): update force_reply assertions to match removed selective flag

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 16:49:42 +07:00
0xmrpeter
5fb0b60355 fix(telegram): remove selective flag from force_reply to auto-open input box
Without selective, Telegram automatically opens the reply compose box
in private chats when bot sends a force_reply message.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 16:45:54 +07:00
0xmrpeter
83f349c47e fix(tests): update enqueuePrompt assertions and add eventBus mock for API prompt route 2026-04-07 16:12:59 +07:00
0xmrpeter
9f2abea16d Merge branch 'feat/telegram-custom-path-wizard' into develop 2026-04-07 15:56:37 +07:00
0xmrpeter
85fdbf9bf1 fix: resolve defaultAgent options from config.agents when agents.json missing 2026-04-07 15:55:20 +07:00
0xmrpeter
b893fb7062 fix: emit MESSAGE_QUEUED/PROCESSING for API prompts so all SSE clients see user messages
API-sourced prompts (from the App) were bypassing MESSAGE_QUEUED and
MESSAGE_PROCESSING emission, so only the sending App window showed the
user message. Other connected windows only saw the AI response.

- routes/sessions.ts: generate turnId, emit MESSAGE_QUEUED before
  enqueuePrompt, return turnId in response body
- session-bridge.ts: remove 'api' exclusion from MESSAGE_PROCESSING
  so all connected SSE clients receive the streaming stub event
2026-04-07 15:53:18 +07:00
0xmrpeter
24ed74a699 fix: add chatId guard to force-reply interceptor 2026-04-07 15:45:15 +07:00
0xmrpeter
e2759b97ce refactor: remove getAssistantSession param from setupNewSessionCallbacks 2026-04-07 15:42:45 +07:00
0xmrpeter
a9fbdc8340 feat: register force-reply interceptor for custom path wizard 2026-04-07 15:41:13 +07:00
0xmrpeter
8dd6cfd8c3 feat: replace ns:custom AI delegation with force-reply path input 2026-04-07 15:39:33 +07:00
0xmrpeter
06150713ac feat: add force-reply state helpers for telegram custom path wizard
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 15:35:46 +07:00
lngdao
8073235299 fix: set workspace.baseDir to target directory on instances create/clone 2026-04-07 10:41:40 +07:00
Mr.Peter
39037f560c
Merge pull request #212 from lngdao/fix/instances-create-flags
fix: instances create — flag forwarding, TTY check, complete config
2026-04-06 17:40:39 +07:00
0xmrpeter
5b132d1b50 feat: add openacp remote to CLI help and assistant guide
Add Remote Access section to `openacp --help` output with all supported
flags. Add `core:remote` assistant section so the AI agent knows how to
generate remote access links, explain roles, tunnel vs local links, and
QR code behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 17:16:23 +07:00
lngdao
15e0e1ef1f fix: instances create generates complete config with SSE channel and defaultAgent 2026-04-06 17:14:39 +07:00
lngdao
e718e2d5f2 fix: set defaultAgent to 'claude' when creating instance without --agent 2026-04-06 17:11:37 +07:00
lngdao
4386cd0b19 fix: skip update prompt when stdin is not a TTY
Prevents interactive update prompt from blocking when CLI is invoked
programmatically (e.g. from Tauri app via invoke_cli).
2026-04-06 17:10:50 +07:00
lngdao
24fd15f7f9 fix: forward --dir/--from/--name flags to instances create subcommand
Top-level extractInstanceFlags strips these flags before passing args
to cmdInstances, so cmdInstancesCreate never receives them. Re-inject
parent flags into subArgs when dispatching to create subcommand.
2026-04-06 16:46:57 +07:00
0xmrpeter
9ec2dddb4a fix: improve path/file UX and fix agent relay wiring bug
Workspace path handling:
- Add `allowExternalWorkspaces` config flag (default: true) to allow workspace
  paths outside baseDir; external paths must exist on disk (no auto-create)
- Remove absolute path restriction from WorkspaceNameSchema so agents can pass
  full paths directly to the API
- API route wraps resolveWorkspace() in try/catch and throws BadRequestError
  (HTTP 400 with INVALID_WORKSPACE code) instead of leaking 500 errors
- CLI extractApiError() helper properly extracts .message from structured error
  objects, preventing "[object Object]" display

File attachment handling:
- Add AVIF, HEIC, HEIF to SUPPORTED_IMAGE_MIMES (Claude API supports them)
- Remove filename regex restriction from AttachmentInputSchema (was blocking
  filenames with spaces and unicode)
- Extract attachment logic to attachment-blocks.ts for testability

Security / allowedPaths:
- Propagate config.workspace.security.allowedPaths through AgentManager.spawn()
  and AgentManager.resume() to PathGuard in AgentInstance

Bug fix — agent relay wiring:
- Convert Session.agentInstance to getter/setter so wireAgentRelay() and
  wireCommandsBuffer() are called automatically on any assignment, not just
  via switchAgent(). Fixes 4 pre-existing test failures in session-bridge-switch.
- Fix closure capture bug: wireAgentRelay/wireCommandsBuffer now capture the
  agent instance by value (const instance = this._agentInstance) instead of
  via getter, preventing cleanup from running on the wrong instance when the
  setter assigns a new agent before calling the cleanup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 16:44:26 +07:00
0xmrpeter
8084061c3e feat: propagate sourceAdapterId through middleware to history recorder
Merge sourceAdapterId into routing before enqueue so middleware hooks
(e.g. history recorder) receive it via the agent:beforePrompt payload.
Store sourceAdapterId on user turns in history for downstream use.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 16:03:13 +07:00
0xmrpeter
abe0d8ed29 docs: update CLAUDE.md to reflect the addition of a new middleware hook
- Updated the documentation to indicate the total number of middleware hooks has increased from 18 to 19.
- Adjusted references in the getting-started-plugin guide to ensure consistency with the updated middleware hook count.
- Corrected the middleware hooks section in the plugin template to reflect the accurate total.
2026-04-06 15:50:16 +07:00
0xmrpeter
1327f0f470 refactor: standardize event handling with BusEvent constants
- Replaced string literals in event emissions and middleware executions with BusEvent constants across various modules, enhancing consistency and maintainability.
- Updated event handling in session management, agent switching, and plugin lifecycle to utilize the new BusEvent structure.
- Improved clarity in event-driven architecture by centralizing event definitions.
2026-04-06 15:38:12 +07:00
0xmrpeter
0373225f55 feat: enhance session handling for headless sessions
- Introduced event handling for agent events, status changes, and prompt count updates directly in headless sessions, previously managed by SessionBridge.
- Updated session creation and event emission to exclude assistant sessions from certain notifications.
- Refactored agent event relay wiring to ensure proper event handling across all session types, including headless sessions.
2026-04-06 15:13:32 +07:00
0xmrpeter
15bc3ae4bb fix: address code review issues in persistent assistant session
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 01:43:31 +07:00
0xmrpeter
3b69880c5d feat: remove /clear command for assistant (no longer needed) 2026-04-06 01:30:14 +07:00
0xmrpeter
67720e2661 feat: expose sessionStore publicly on OpenACPCore for AssistantManager access 2026-04-06 01:29:56 +07:00
0xmrpeter
446071b0e9 feat: replace spawn/respawn with getOrSpawn in AssistantManager
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 01:27:54 +07:00
0xmrpeter
b395d30919 feat: filter assistant sessions from all session listings
listSessions(), listAllSessions(), and listRecords() now exclude sessions
and records with isAssistant=true so they never appear in user-facing listings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 01:24:34 +07:00
0xmrpeter
e83a3b08e7 feat: persist isAssistant flag through session creation pipeline
Add isAssistant parameter to SessionCreateParams and createSession method,
then pass it through to the patchRecord call so it gets persisted in the
session record store.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 01:21:49 +07:00
0xmrpeter
c542f8e837 feat: add findAssistant() to SessionStore and exempt assistant records from TTL cleanup
Added findAssistant() method to SessionStore interface and JsonFileSessionStore implementation
to retrieve the assistant session for a given channel. Updated cleanup() logic to preserve
assistant sessions regardless of TTL expiration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 01:20:21 +07:00
0xmrpeter
4c16b59d2f feat: add isAssistant field to SessionRecord type 2026-04-06 01:18:18 +07:00
0xmrpeter
b1eae11d1e fix(telegram): pass next() in PermissionHandler to unblock menu callbacks
PermissionHandler.setupCallbackHandler() used bot.on('callback_query:data')
without calling next() for non-p: prefixed data, silently consuming all
callback queries and preventing m:, ns:, ar:, c/ handlers from ever firing.

Fix: pass next middleware function and call return next() for unrecognized
callback data so the handler chain continues to the correct handler.

Also add a warn log when a menu item ID is not found in the registry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 00:37:56 +07:00
0xmrpeter
3e1dd3d913 fix(telegram): guard setupRoutes message handler against uninitialized topic IDs
Before topics are initialized, this.assistantTopicId is 0. A non-command
message arriving before initTopicDependentFeatures() completes would
generate an invalid redirect URL (t.me/c/.../0).

Add _topicsInitialized guard to the message:text handler in setupRoutes(),
matching the existing guard on the command dispatcher, so messages received
during startup get a clear "still setting up" reply instead of a broken link.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 00:19:09 +07:00
0xmrpeter
e5eb22072f test(telegram): add regression tests for adapter startup handler registration order
Verifies that all grammY handlers (setupAllCallbacks, setupRoutes) are
registered BEFORE bot.start() is called. The MockBot throws if any handler
registration is attempted after start(), mirroring grammY's real behavior.

This catches the regression where initTopicDependentFeatures() called
setupMenuCallbacks/setupRoutes after bot.start(), causing the bot to silently
fail on startup with grammY's "cannot augment composer after the fact" error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 00:14:22 +07:00
0xmrpeter
3e7da2ad7d fix(telegram): register bot handlers before bot.start() to prevent grammY error
grammY throws "cannot augment the composer after the fact" when bot.use()
is called after bot.start(). setupMenuCallbacks and setupRoutes were being
called inside initTopicDependentFeatures(), which runs after bot.start().

Fix: move all handler registration (setupMenuCallbacks, setupRoutes) to
before bot.start() in the start() method. Topic IDs are passed via a
mutable _systemTopicIds ref that is updated in-place by
initTopicDependentFeatures() once topics are ready — callbacks close over
this reference and see correct IDs at invocation time.

Also adds detailed diagnostic logging to validators.ts and adapter.ts
to trace the prerequisite check and topic initialization flow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 00:07:25 +07:00
0xmrpeter
897b73354f chore: bump version to 2026.405.1
Also fix api-server test mock missing agentCatalog.load() method.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 23:11:01 +07:00
0xmrpeter
35b2ff9626 fix(merge): use canonical discord-adapter/slack-adapter plugin names
Correct conflict resolution: keep @openacp/discord-adapter and
@openacp/slack-adapter as normalized in faf6286, not the old
@openacp/discord and @openacp/slack names from the refactor branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 23:06:36 +07:00
0xmrpeter
68fe7b1e96 Merge branch 'refactor/config-legacy-removal' into develop 2026-04-05 23:02:53 +07:00
0xmrpeter
0756c87b0d Merge branch 'feat/api-agent-catalog-reload' into develop 2026-04-05 23:00:54 +07:00
0xmrpeter
e96777bc2d fix(api): use agents:write scope for reload, extract shared helper
- POST /agents/reload now requires agents:write instead of agents:read
  to better reflect its side-effectful nature
- Extract loadAndListAgents() helper to eliminate code duplication
  between GET /agents and POST /agents/reload
- Add agents:write to KNOWN_SCOPES and operator role in roles.ts
- Add clarifying comment on per-request I/O trade-off

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 22:55:53 +07:00
0xmrpeter
ad6b1d9614 feat(api): add permission feedback and broadcast permission:resolved via SSE
Merge feat/api-permission-feedback-prompt

- Add optional `feedback` field to PermissionResponseBodySchema
- When feedback provided with permission deny, abort current turn then queue
  feedback as next prompt (sequential, race-free)
- Broadcast `permission:resolved` event via SSE manager so desktop app and
  other adapters can dismiss permission UI when resolved from another adapter
- Route feedback prompt with correct sourceAdapterId (api/sse)
- Tests covering feedback flow, abort-before-enqueue ordering, and no-op cases
2026-04-05 22:51:44 +07:00
0xmrpeter
4e6425e414 fix(api): await permission feedback abort/enqueue sequentially and add tests
- Await abortPrompt() before enqueuePrompt() to eliminate the race condition
  where enqueued feedback could be cleared by the concurrent queue.clear() call
- Log abortPrompt failures via request.log.warn instead of silently swallowing
- Pass sourceAdapterId routing to enqueuePrompt (api/sse) so agent responses
  are routed correctly
- Add tests for feedback flow in both api-server and sse-adapter route handlers,
  verifying abort-before-enqueue ordering, correct routing, and no-op when no
  feedback is provided

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 22:51:29 +07:00
0xmrpeter
c16f4170a2 feat(api): add file attachment support to prompt endpoint
Extends POST /sessions/:id/prompt (REST + SSE) to accept an optional
`attachments` array of base64-encoded files. Attachments are decoded
server-side and persisted via FileService, which handles naming,
storage under ~/.openacp/files/{sessionId}/, and PathGuard whitelisting
so agents can read uploaded files without manual path configuration.

Fixes from code review:
- Restore sourceAdapterId/responseAdapterId routing args in enqueuePrompt
  (both REST and SSE routes were dropping them from the original PR)
- Extract shared resolveAttachments() utility to eliminate duplication
  between api-server and sse-adapter routes
- Return 503 with FILE_SERVICE_UNAVAILABLE when file-service plugin is
  not loaded, instead of an unhandled internal error
- Clean up already-written files on partial save failure to avoid orphans
- Validate fileName against safe-char regex at schema level so raw value
  forwarded to agent cannot contain path traversal characters
- Validate mimeType against type/subtype regex to prevent malformed MIME
  values from reaching agent processing
- Raise per-route bodyLimit to 115 MB to make the 10-attachment cap
  reachable (Fastify default 1 MB would reject payloads before schema
  validation otherwise)
- Add .DS_Store to .gitignore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 22:43:13 +07:00
0xmrpeter
914ac48eef fix(telegram): idempotency guard in initTopicDependentFeatures, fix retry message, add network error test
- Add idempotent guard to initTopicDependentFeatures() to prevent multiple initializations
- Update retry message from specific interval to more accurate description
- Add network error test case to validateBotAdmin to verify error handling
2026-04-05 22:33:06 +07:00
0xmrpeter
88138e29ce fix(telegram): correct prerequisite watcher retry schedule (off-by-one) 2026-04-05 22:25:15 +07:00
0xmrpeter
9f4f688961 feat(telegram): split start() into phases, add prerequisite watcher
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 22:22:36 +07:00
0xmrpeter
6baf41f0b6 feat(telegram): warn during install when Topics disabled or bot lacks manage-topics perm 2026-04-05 22:18:05 +07:00
0xmrpeter
71c8a3478b feat(telegram): add checkTopicsPrerequisites validator
Add a new exported function checkTopicsPrerequisites(token, chatId) that validates all 3 runtime prerequisites for the Telegram adapter:
1. Topics enabled on the group (is_forum === true)
2. Bot is admin
3. Bot has can_manage_topics permission

Returns { ok: true } if all checks pass, or { ok: false; issues: string[] } with human-readable issue messages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 22:16:23 +07:00