821 Commits

Author SHA1 Message Date
0xmrpeter
68ee7a20a5 test: add comprehensive flow tests for multi-instance feature
Covers CLI flag resolution, instance lifecycle (create/register/query/remove),
instance copy with settings inheritance, status file reading, config migration,
and naming/slug generation. Exports readInstanceInfo from status.ts for testability.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:37:46 +07:00
0xmrpeter
8f1efc21be fix: critical bugs in daemon restart, shouldAutoStart, and cmdDefault context passing
- Pass ctx.root to shouldAutoStart() so it checks the correct instance's running marker
- Create and pass InstanceContext in cmdDefault() so local instances retain their context
- Resolve actual instance ID from registry in --daemon-child handler instead of hardcoding 'unknown'
- Add missing path import in cli.ts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:34:21 +07:00
0xmrpeter
b563a47af4 fix: add instanceRoot to plugin SDK test context
The TestPluginContext was missing the instanceRoot field added to
PluginContext in Task 7, causing build:publish to fail.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:27:55 +07:00
0xmrpeter
b4b7428bb7 feat: remove all remaining hardcoded ~/.openacp paths
Replace hardcoded os.homedir() + '.openacp' references with
instance-aware alternatives: getGlobalRoot(), ctx.instanceRoot,
or optional params with defaults. Files updated:

- context plugin: use ctx.instanceRoot for history/cache paths
- file-service plugin: use ctx.instanceRoot in setup/install/configure
- cloudflare tunnel: accept binDir param
- config-editor: use getGlobalRoot() for plugin basePath
- config-registry: import getGlobalRoot() for agents.json lookup
- config-migrations: use getGlobalRoot() for agents.json path
- doctor engine: accept dataDir param, derive bin path from ctx.dataDir
- setup-channels: use getGlobalRoot() for plugin data path
- wizard: use getGlobalRoot() for plugins dir
- onboard CLI: use getGlobalRoot() instead of manual path
- InstallContext: add optional instanceRoot field

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:25:30 +07:00
0xmrpeter
75d533ef53 feat: auto-register global instance and migrate instanceName
- Auto-register the current instance in instances.json after startup so existing users who upgrade get their instance registered without manual intervention
- Add 'add-instance-name' config migration that sets instanceName to "Main" for configs that don't have it
- Update config-migrations test fixture to include instanceName so the "no migrations needed" test remains accurate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 23:19:33 +07:00
0xmrpeter
563c6f9adf feat: add status --all and --id for multi-instance overview
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 23:17:14 +07:00
0xmrpeter
19bd57aa73 feat: add instance naming, copy flow, and partial setup to wizard
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:15:09 +07:00
0xmrpeter
8ee7557cdf feat: add instance copy logic with progress callback
Implements copyInstance() that clones an OpenACP instance directory,
stripping runtime/session state and filtering plugin settings by
configurable inheritable keys.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 23:11:51 +07:00
0xmrpeter
13400a2024 feat: refactor plugins and agents to accept paths from InstanceContext
Remove module-level path constants from plugins and agent modules,
making them instance-aware. All parameters are optional with defaults
falling back to ~/.openacp for backward compatibility.

- Add instanceRoot to PluginContext and LifecycleManagerOpts
- Add inheritableKeys to OpenACPPlugin interface
- Refactor api-server, tunnel, agent-catalog, agent-installer, and
  install-binary to accept paths as constructor/function parameters
- Add inheritableKeys to telegram, security, speech, tunnel, api-server plugins

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:09:47 +07:00
0xmrpeter
28fe530d4a feat: refactor CLI commands to accept instance root parameter
All CLI commands and daemon functions now accept an optional instanceRoot
parameter, defaulting to ~/.openacp for backward compatibility. The daemon
child process receives the instance root via OPENACP_INSTANCE_ROOT env var.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 23:03:47 +07:00
0xmrpeter
369634308c feat: pass InstanceContext through startServer → OpenACPCore
Replace hardcoded ~/.openacp paths in main.ts with ctx.paths from
InstanceContext. OpenACPCore constructor now accepts optional ctx
parameter with fallbacks to global paths for backward compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:57:50 +07:00
0xmrpeter
16af19da30 feat: parse --local, --global, --dir, --from, --name CLI flags
Extract instance flags from CLI args before command dispatch and resolve
the instance root directory. Commands will consume the resolved root in
subsequent tasks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:54:56 +07:00
0xmrpeter
4d1c7fd014 feat: add instanceName to config schema, remove global path constants
- Add optional instanceName field to ConfigSchema for multi-instance support
- Make ConfigManager constructor accept optional configPath parameter
- Remove exported OPENACP_DIR, PLUGINS_DIR, PLUGINS_DATA_DIR, REGISTRY_PATH
  module-level constants from config.ts
- Add temporary local constants in main.ts, install.ts, uninstall.ts, onboard.ts
  (to be replaced by InstanceContext in later tasks)
- Remove PLUGINS_DIR re-export from core/index.ts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:52:55 +07:00
0xmrpeter
9d7a02cb2d feat: add InstanceRegistry for tracking known instances
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 22:50:34 +07:00
0xmrpeter
7dab4d497c feat: add InstanceContext type, path resolution, and slug generation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 22:48:22 +07:00
0xmrpeter
71c8b47be0 Add multi-instance implementation plan (13 tasks)
Detailed step-by-step plan covering: InstanceContext type, registry,
config schema changes, CLI flag parsing, startServer refactor, CLI
command refactoring, plugin path refactoring, instance copy logic,
setup wizard changes, status commands, and migration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:33:48 +07:00
0xmrpeter
ab89febcae Slim down instance registry to minimal index
Registry only stores id + root path. All details (name, ports,
channels, mode, PID) are read from each instance's own config and
state files. This avoids stale data and keeps the registry simple.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:26:40 +07:00
0xmrpeter
f3d69229d1 Update spec: show parent directory in status, clarify port columns
- Status table Directory column shows parent path without .openacp suffix
- API and Tunnel port columns clearly labeled with actual port numbers
- Mode column shows daemon/fg/— for clarity

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:23:02 +07:00
0xmrpeter
dd849125eb Update spec: instance naming, copy progress, path UX improvements
- Add instance id (slug) and name to InstanceContext and Registry
- Paths in flags use parent dir, system appends .openacp internally
- Copy from any existing setup, not just global
- Show step-by-step progress with spinner during copy
- Status table includes id, name, mode, channels columns
- Add --name flag, status --id subcommand
- Clearer user-facing language throughout

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:22:20 +07:00
0xmrpeter
e5cf9ffa73 Update multi-instance spec: clone artifacts, source selection, full paths
- Clone now includes plugins/node_modules, agents/, bin/ directories
- Clone source can be any existing instance, not just global
- Add --from <path> CLI flag to specify clone source
- All prompts show full paths for clarity
- Show equivalent CLI command as tip after interactive selection

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:14:30 +07:00
0xmrpeter
9b3d26943d Add multi-instance support design spec
Defines architecture for running multiple OpenACP instances on the same
machine with independent config, sessions, ports, and lifecycle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 22:04:56 +07:00
0xmrpeter
88bccb1661 fix(agent-switch): session resume, prompt cancel, and queue clear in switch handlers
Use getOrResumeSession instead of getSessionByThread in Telegram switch
handlers so sessions are found after process restart. Cancel in-flight
prompts before confirming a switch. Clear the prompt queue in
Session.switchAgent() before destroying the old agent.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:40:12 +07:00
0xmrpeter
aa36315a42 fix(agent-switch): update docs for Discord/Slack, improve rollback with resume
Mark Discord and Slack as "coming soon" in agent-switch docs and chat-commands table since those adapter integrations were reverted. In the rollback path of switchSessionAgent(), attempt agentManager.resume() with the saved fromAgentSessionId before falling back to a fresh spawn, preserving conversation history on rollback when possible.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 20:38:58 +07:00
0xmrpeter
6b7272090b fix(agent-switch): clean up session, adapter, and permission state on switch
Reset agent-specific ACP state (capabilities, modes, models, config) in
Session.switchAgent() so stale values from the previous agent don't leak
into the new agent's session. Reject pending PermissionGate requests before
destroying the old agent to prevent callers from hanging. Add adapter-level
cleanupSessionState() to finalize DraftManager drafts and destroy
ActivityTracker timers on agent switch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:27:33 +07:00
0xmrpeter
2bae0d49c3 fix(agent-switch): clear old agent commands before switching
Send an empty commands array to the adapter after disconnecting the bridge
so stale skill commands from the previous agent don't linger in the UI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 20:18:33 +07:00
0xmrpeter
fa15424f26 fix(agent-switch): add rollback, in-flight check, and cache key fix
- Add rollback logic in switchSessionAgent() to re-spawn the old agent
  if the new agent fails to spawn, preventing broken session state
- Add in-flight prompt confirmation in Telegram /switch handler so users
  are warned before interrupting a running prompt
- Include labelAgent option in context cache key to prevent stale results
  when switching between labelAgent=true and labelAgent=false

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:57:00 +07:00
0xmrpeter
74afa0bcaa docs(agent-switch): update plugin template with new middleware hooks
Add agent:beforeSwitch (blocking) and agent:afterSwitch (fire-and-forget)
to the middleware hooks reference in claude-md.ts; bump hook count to 20.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:55:50 +07:00
0xmrpeter
93c0b34403 Revert "feat(agent-switch): add /switch command handler to Discord and Slack adapters"
This reverts commit 3543aab280f282427085d6fb719d21a6ea6a994c.
2026-03-30 18:50:55 +07:00
0xmrpeter
3543aab280 feat(agent-switch): add /switch command handler to Discord and Slack adapters
Cherry-pick Discord and Slack adapter plugins from fix/api-channel-flag branch
and add /switch command handling to both:
- Discord: /switch slash command with agent selection buttons (sw: prefix)
- Slack: /openacp-switch slash command with interactive button menu
- Add DiscordPlatformData type to core types
- Fix renderer interface compatibility for renderPlan signature
- Install discord.js and @slack/bolt dependencies

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:49:57 +07:00
0xmrpeter
efb7f552a9 docs: add agent switch feature documentation
Documents the /switch command, mid-conversation agent switching behavior,
history label injection, session resume logic, and the agentSwitch.labelHistory
config option. Adds a dedicated feature page and updates chat-commands,
agents, configuration-schema, README, and SUMMARY.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:43:24 +07:00
0xmrpeter
8678e22676 feat(agent-switch): add /switch command handler to Telegram adapter
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:43:02 +07:00
0xmrpeter
f06b765e6a feat(agent-switch): add core switch orchestration and update lazyResume
Add switchSessionAgent() to OpenACPCore that orchestrates the full agent
switch flow: middleware hooks, bridge disconnect/reconnect, context
injection, and persistence. Update lazyResume to restore switch history
fields (firstAgent, agentSwitchHistory, currentPromptCount) and persist
them in createSession.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:40:13 +07:00
0xmrpeter
78dfb0300b feat(agent-switch): add agent label support to history context
When labelAgent option is true, conversation history markdown includes
### [agentName] headers at agent boundaries, making it clear which agent
produced which parts of the conversation during agent switches.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:34:39 +07:00
0xmrpeter
ba0fcf505d feat(agent-switch): persist promptCount for resume decisions
Emit prompt_count_changed after each prompt increment in Session and
wire SessionBridge to persist currentPromptCount to the store so it
survives process restarts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:34:22 +07:00
0xmrpeter
18e22a8e2e feat(agent-switch): add agentSwitch.labelHistory config setting
Adds agentSwitch.labelHistory boolean config (default true) to control whether conversation history injected during agent switch includes agent name labels. Also registers the field in config-registry for /config toggle support.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:31:29 +07:00
0xmrpeter
348eb1ab01 feat(agent-switch): ensure SessionBridge supports disconnect/reconnect
Add tests verifying that SessionBridge.disconnect() cleanly removes all
listeners from the old agent instance and that connect() can be safely
called again after swapping session.agentInstance, correctly wiring the
new agent. No bridge code changes required — connect() already reads the
current session.agentInstance at call time.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:31:25 +07:00
0xmrpeter
129ff9d321 feat(agent-switch): add /switch command registration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:31:18 +07:00
0xmrpeter
777678f97c feat(agent-switch): add switchAgent method to Session class
Add switchAgent(), findLastSwitchEntry(), firstAgent, and agentSwitchHistory
to Session. Enables in-place agent swapping while preserving session identity.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:27:51 +07:00
0xmrpeter
9e5b8ca7bb feat(agent-switch): add beforeSwitch/afterSwitch middleware hooks
Add agent:beforeSwitch and agent:afterSwitch hook type definitions to
MiddlewarePayloadMap so plugins can intercept agent switch operations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:25:16 +07:00
0xmrpeter
30b22bf345 feat(agent-switch): extend SessionRecord with switch history fields
Add AgentSwitchEntry interface and extend SessionRecord with optional
firstAgent, currentPromptCount, and agentSwitchHistory fields. Update
findByAgentSessionId to also search switch history entries.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:24:18 +07:00
0xmrpeter
1327a0d948 docs: add agent switch implementation plan
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:16:50 +07:00
0xmrpeter
66eed520ce docs: add agent switch feature design spec
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:02:23 +07:00
0xmrpeter
a707bf15e9 fix(trace): log full event/message objects for verbose debug tracing
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 09:36:48 +07:00
0xmrpeter
196657d3b1 feat(history): add history store, provider, context builder and improve tool display
- Add HistoryStore, HistoryProvider, HistoryContextBuilder with tests
- Wire history provider into context plugin
- Enhance DisplaySpecBuilder with diff stats and output viewer links
- Improve message-transformer with richer tool metadata extraction
- Update extract-file-info to handle more ACP content patterns
- Refine Telegram formatting: inline viewer links, cleaner tool cards
- Fix viewer-store cleanup and core event wiring
2026-03-30 09:01:40 +07:00
0xmrpeter
ce51688c4f feat(history): add HistoryRecorder for event accumulation and turn writing
Implements the write-side component that captures agent events from
middleware hooks, accumulates them into structured turns (text/thinking
chunk merging, tool call tracking, diff extraction, permission capture),
and writes completed turns to disk via HistoryStore.

Includes 32 tests covering all event types, accumulation rules, edge
cases, multi-turn sequences, and session cleanup.
2026-03-30 02:19:18 +07:00
0xmrpeter
16e0884354 fix(output-mode): wire outputViewerLink, fix verbosity callback key, update docs
- DisplaySpecBuilder: add TunnelServiceInterface constructor injection, implement
  outputViewerLink/outputFallbackContent for long output (>15 lines or >800 chars)
- DisplaySpecBuilder: fix buildThoughtSpec indicator to "Thinking..."
- ActivityTracker: store and pass tunnelService to DisplaySpecBuilder, pass sessionContext
  to all buildToolSpec calls
- setupVerbosityCallbacks: write outputMode instead of deprecated displayVerbosity key
- /verbosity static command description updated to note deprecation
- Docs: update displayVerbosity → outputMode across configuration, chat-commands,
  troubleshooting, and architecture docs; add /outputmode command reference
2026-03-30 01:52:51 +07:00
0xmrpeter
646c2d8812 fix(output-mode): fix verbosity callback toast text to say output mode 2026-03-30 01:38:22 +07:00
0xmrpeter
617b94b865 feat(output-mode): add /outputmode command with session-level override
Adds /outputmode [low|medium|high] for adapter-level config and /outputmode session [low|medium|high|reset] for per-session override. Deprecates /verbosity as an alias that forwards to /outputmode. Prefixes unused verbosity params in adapter.ts with underscore to suppress TS warnings.
2026-03-30 01:35:10 +07:00
0xmrpeter
72b675d85f feat(output-mode): filter before serial queue, OutputModeResolver cascade, pass content through tool updates
- Add OutputModeResolver field to TelegramAdapter; resolve mode per-call in handleToolCall, handleToolUpdate, handleThought, handleText, handlePlan instead of forwarding raw DisplayVerbosity
- Update getOrCreateTracker signature from verbosity: DisplayVerbosity to outputMode: OutputMode; pass tunnelService and sessionContext to ActivityTracker constructor
- Pass content, rawInput, and diffStats through onToolUpdate calls so ActivityTracker receives full update payload
2026-03-30 01:30:44 +07:00
0xmrpeter
7bc6215825 fix(tests): update old tool-card-state tests to use new updateFromSpec API
Replace addTool/updateTool/verbosity calls with updateFromSpec(ToolDisplaySpec),
update snapshot field references (entries→specs, hidden→isHidden, visibleCount→totalVisible),
and remove the verbosity config param that was removed from ToolCardStateConfig.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 01:27:18 +07:00