Skip to content

Extend SecretsManager, agent loop, and CLI commands#66

Open
warengonzaga wants to merge 8 commits intodevfrom
fix/agent-loop
Open

Extend SecretsManager, agent loop, and CLI commands#66
warengonzaga wants to merge 8 commits intodevfrom
fix/agent-loop

Conversation

@warengonzaga
Copy link
Copy Markdown
Owner

This pull request introduces several important improvements to plugin setup, tool execution, and plugin status tracking, with a focus on better user guidance and robust handling of plugin pairing and restarts. It also adds new tests to ensure these behaviors. The main changes are grouped as follows:

Plugin Setup Guidance and Agent Loop Enhancements:

  • Adds detailed "Plugin Setup Guidance" to the system prompt in agentLoop, ensuring the agent walks users through plugin setup step by step and never claims a plugin is active unless pairing and restart are complete.
  • Refactors tool execution in agentLoop to automatically trigger a restart (via the tinyclaw_restart tool) after successful pairing tools (like *_pair), and ensures the agent's reply is natural and conversational, summarizing all tool results. [1] [2] [3] [4] [5]

Discord Plugin Status Tracking:

  • Introduces a runtime status object and accessor (getDiscordRuntimeStatus) in the Discord channel plugin, tracking enabled state, connection state, errors, and ready tag, and updates this status throughout the plugin lifecycle. [1] [2] [3] [4] [5]
  • Exposes this runtime status for external inspection and adds tests to verify its correctness. [1] [2]

Tool and Secrets Management Improvements:

  • Updates the Discord pairing tool to explicitly instruct the agent to walk the user through creating a bot in the Discord Developer Portal if a token hasn't been provided.
  • Adds a destroy() method to the SecretsManager interface and implementation, allowing permanent destruction of the secrets store. [1] [2]

Testing:

  • Adds comprehensive tests for the new agent loop behaviors, including plugin setup prompt injection, natural reply generation after tool calls, auto-restart after pairing, and inclusion of auto-restart results in agent replies.

Other:

  • Updates type imports to include StreamEvent and Tool where needed.

These changes collectively improve the reliability, transparency, and user experience of plugin setup and management, while ensuring robust test coverage for new behaviors.

@warengonzaga warengonzaga self-assigned this Apr 6, 2026
Copilot AI review requested due to automatic review settings April 6, 2026 15:07
Copy link
Copy Markdown

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

This PR improves plugin setup reliability and observability by enhancing the agent loop’s plugin-setup guidance and tool execution flow (including auto-restart after pairing), adding Discord runtime status tracking, and extending secrets management with a destroy operation (plus CLI recovery/purge behavior and tests).

Changes:

  • Add “Plugin Setup Guidance” to the agent loop prompt, generate natural replies after tool usage, and auto-run tinyclaw_restart after successful *_pair/*_unpair tools.
  • Add Discord plugin runtime status (getDiscordRuntimeStatus) and expose it via a new discord_status runtime tool in the CLI.
  • Extend SecretsManager with destroy() and improve purge/recovery flows with added tests.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/cli/tests/purge.test.ts Adds coverage for purge fallback when secrets store is corrupt.
src/cli/tests/commands/start.test.ts Tests discord_status tool registration and output scenarios.
src/cli/src/utils/secrets.ts Centralizes secrets path resolution and integrity recovery messaging.
src/cli/src/commands/start.ts Uses new secrets integrity helpers; registers discord_status tool.
src/cli/src/commands/setup.ts Adds integrity-error handling and recovery guidance during setup.
src/cli/src/commands/setup-web.ts Adds integrity-error handling and recovery guidance during web setup.
src/cli/src/commands/purge.ts Adds secrets-engine-aware purge (destroy + fallback) and Windows-friendly deletion retry.
plugins/channel/plugin-channel-discord/tests/index.test.ts Verifies runtime status accessor is exposed.
plugins/channel/plugin-channel-discord/src/pairing.ts Updates pairing tool description to guide token creation steps.
plugins/channel/plugin-channel-discord/src/index.ts Implements Discord runtime status tracking and accessor.
packages/types/src/index.ts Extends SecretsManager interface with destroy().
packages/secrets/src/secrets-engine.d.ts Updates secrets-engine typings to include destroy().
packages/secrets/src/manager.ts Implements SecretsManager destroy() by delegating to the engine.
packages/core/tests/loop.test.ts Adds tests for plugin setup prompt injection, natural replies, and auto-restart behavior.
packages/core/src/loop.ts Adds plugin setup guidance, tool-result-to-natural-reply flow, and auto-restart after pairing tools.

@warengonzaga
Copy link
Copy Markdown
Owner Author

@copilot apply changes based on the comments in this thread and reply to each of the comments.

Copilot AI and others added 2 commits April 7, 2026 03:29
…tion, and error state readyTag

Agent-Logs-Url: https://github.com/warengonzaga/tinyclaw/sessions/eb1b6ce1-d1b7-4f02-aec2-673c9274380d

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

@copilot apply changes based on the comments in this thread and reply to each of the comments.

All four review comments addressed in commits f357dd9 and 77261cb:

  1. purge.ts double-retryremoveDirectoryWithRetry now calls rm() with only {recursive, force}, keeping all retry logic in the wrapper loop.
  2. secrets.ts path quoting — Added quoteForPosixShell and quoteForPowerShell helpers; getManualRemovalCommand now uses them to safely handle paths with spaces or shell metacharacters.
  3. loop.ts duplicate restart — Replaced the for+continue guard with a cleaner if (!batchHasRestartCall) block that wraps the entire auto-restart loop. Also extracted RESTART_TOOL_NAME constant to eliminate the repeated 'tinyclaw_restart' magic string.
  4. discord/index.ts error stateruntimeStatus.readyTag is now set to null when transitioning to the error state, preventing contradictory "error + logged in" status output.

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