@yeshwanthyk/coding-agent 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/adapters/acp/index.d.ts +10 -0
- package/dist/adapters/acp/index.d.ts.map +1 -0
- package/dist/adapters/acp/index.js +250 -0
- package/dist/adapters/acp/index.js.map +1 -0
- package/dist/adapters/acp/protocol.d.ts +171 -0
- package/dist/adapters/acp/protocol.d.ts.map +1 -0
- package/dist/adapters/acp/protocol.js +25 -0
- package/dist/adapters/acp/protocol.js.map +1 -0
- package/dist/adapters/acp/session.d.ts +33 -0
- package/dist/adapters/acp/session.d.ts.map +1 -0
- package/dist/adapters/acp/session.js +216 -0
- package/dist/adapters/acp/session.js.map +1 -0
- package/dist/adapters/acp/updates.d.ts +17 -0
- package/dist/adapters/acp/updates.d.ts.map +1 -0
- package/dist/adapters/acp/updates.js +62 -0
- package/dist/adapters/acp/updates.js.map +1 -0
- package/dist/adapters/cli/headless.d.ts +7 -0
- package/dist/adapters/cli/headless.d.ts.map +1 -0
- package/dist/adapters/cli/headless.js +93 -0
- package/dist/adapters/cli/headless.js.map +1 -0
- package/dist/adapters/cli/validate.d.ts +3 -0
- package/dist/adapters/cli/validate.d.ts.map +1 -0
- package/dist/adapters/cli/validate.js +40 -0
- package/dist/adapters/cli/validate.js.map +1 -0
- package/dist/adapters/tui/app.d.ts +8 -0
- package/dist/adapters/tui/app.d.ts.map +1 -0
- package/dist/adapters/tui/app.jsx +25 -0
- package/dist/adapters/tui/app.jsx.map +1 -0
- package/dist/agent-events.d.ts +63 -0
- package/dist/agent-events.d.ts.map +1 -0
- package/dist/agent-events.js +510 -0
- package/dist/agent-events.js.map +1 -0
- package/dist/args.d.ts +18 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +87 -0
- package/dist/args.js.map +1 -0
- package/dist/autocomplete-commands.d.ts +26 -0
- package/dist/autocomplete-commands.d.ts.map +1 -0
- package/dist/autocomplete-commands.js +82 -0
- package/dist/autocomplete-commands.js.map +1 -0
- package/dist/commands.d.ts +10 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +17 -0
- package/dist/commands.js.map +1 -0
- package/dist/compact-handler.d.ts +42 -0
- package/dist/compact-handler.d.ts.map +1 -0
- package/dist/compact-handler.js +211 -0
- package/dist/compact-handler.js.map +1 -0
- package/dist/components/Footer.d.ts +9 -0
- package/dist/components/Footer.d.ts.map +1 -0
- package/dist/components/Footer.jsx +36 -0
- package/dist/components/Footer.jsx.map +1 -0
- package/dist/components/Header.d.ts +23 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Header.jsx +174 -0
- package/dist/components/Header.jsx.map +1 -0
- package/dist/components/MessageList.d.ts +19 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/components/MessageList.jsx +237 -0
- package/dist/components/MessageList.jsx.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -0
- package/dist/domain/commands/builtin/clear.d.ts +3 -0
- package/dist/domain/commands/builtin/clear.d.ts.map +1 -0
- package/dist/domain/commands/builtin/clear.js +13 -0
- package/dist/domain/commands/builtin/clear.js.map +1 -0
- package/dist/domain/commands/builtin/compact.d.ts +3 -0
- package/dist/domain/commands/builtin/compact.d.ts.map +1 -0
- package/dist/domain/commands/builtin/compact.js +84 -0
- package/dist/domain/commands/builtin/compact.js.map +1 -0
- package/dist/domain/commands/builtin/conceal.d.ts +3 -0
- package/dist/domain/commands/builtin/conceal.d.ts.map +1 -0
- package/dist/domain/commands/builtin/conceal.js +8 -0
- package/dist/domain/commands/builtin/conceal.js.map +1 -0
- package/dist/domain/commands/builtin/diffwrap.d.ts +3 -0
- package/dist/domain/commands/builtin/diffwrap.d.ts.map +1 -0
- package/dist/domain/commands/builtin/diffwrap.js +8 -0
- package/dist/domain/commands/builtin/diffwrap.js.map +1 -0
- package/dist/domain/commands/builtin/editor.d.ts +3 -0
- package/dist/domain/commands/builtin/editor.d.ts.map +1 -0
- package/dist/domain/commands/builtin/editor.js +22 -0
- package/dist/domain/commands/builtin/editor.js.map +1 -0
- package/dist/domain/commands/builtin/exit.d.ts +3 -0
- package/dist/domain/commands/builtin/exit.d.ts.map +1 -0
- package/dist/domain/commands/builtin/exit.js +14 -0
- package/dist/domain/commands/builtin/exit.js.map +1 -0
- package/dist/domain/commands/builtin/followup.d.ts +3 -0
- package/dist/domain/commands/builtin/followup.d.ts.map +1 -0
- package/dist/domain/commands/builtin/followup.js +20 -0
- package/dist/domain/commands/builtin/followup.js.map +1 -0
- package/dist/domain/commands/builtin/index.d.ts +2 -0
- package/dist/domain/commands/builtin/index.d.ts.map +1 -0
- package/dist/domain/commands/builtin/index.js +29 -0
- package/dist/domain/commands/builtin/index.js.map +1 -0
- package/dist/domain/commands/builtin/login.d.ts +3 -0
- package/dist/domain/commands/builtin/login.d.ts.map +1 -0
- package/dist/domain/commands/builtin/login.js +92 -0
- package/dist/domain/commands/builtin/login.js.map +1 -0
- package/dist/domain/commands/builtin/model.d.ts +3 -0
- package/dist/domain/commands/builtin/model.d.ts.map +1 -0
- package/dist/domain/commands/builtin/model.js +53 -0
- package/dist/domain/commands/builtin/model.js.map +1 -0
- package/dist/domain/commands/builtin/status.d.ts +3 -0
- package/dist/domain/commands/builtin/status.d.ts.map +1 -0
- package/dist/domain/commands/builtin/status.js +30 -0
- package/dist/domain/commands/builtin/status.js.map +1 -0
- package/dist/domain/commands/builtin/steer.d.ts +3 -0
- package/dist/domain/commands/builtin/steer.d.ts.map +1 -0
- package/dist/domain/commands/builtin/steer.js +20 -0
- package/dist/domain/commands/builtin/steer.js.map +1 -0
- package/dist/domain/commands/builtin/theme.d.ts +3 -0
- package/dist/domain/commands/builtin/theme.d.ts.map +1 -0
- package/dist/domain/commands/builtin/theme.js +19 -0
- package/dist/domain/commands/builtin/theme.js.map +1 -0
- package/dist/domain/commands/builtin/thinking.d.ts +3 -0
- package/dist/domain/commands/builtin/thinking.d.ts.map +1 -0
- package/dist/domain/commands/builtin/thinking.js +16 -0
- package/dist/domain/commands/builtin/thinking.js.map +1 -0
- package/dist/domain/commands/helpers.d.ts +7 -0
- package/dist/domain/commands/helpers.d.ts.map +1 -0
- package/dist/domain/commands/helpers.js +34 -0
- package/dist/domain/commands/helpers.js.map +1 -0
- package/dist/domain/commands/registry.d.ts +10 -0
- package/dist/domain/commands/registry.d.ts.map +1 -0
- package/dist/domain/commands/registry.js +36 -0
- package/dist/domain/commands/registry.js.map +1 -0
- package/dist/domain/commands/types.d.ts +62 -0
- package/dist/domain/commands/types.d.ts.map +1 -0
- package/dist/domain/commands/types.js +2 -0
- package/dist/domain/commands/types.js.map +1 -0
- package/dist/domain/messaging/content.d.ts +37 -0
- package/dist/domain/messaging/content.d.ts.map +1 -0
- package/dist/domain/messaging/content.js +103 -0
- package/dist/domain/messaging/content.js.map +1 -0
- package/dist/editor.d.ts +26 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +81 -0
- package/dist/editor.js.map +1 -0
- package/dist/extensibility/schema.d.ts +2 -0
- package/dist/extensibility/schema.d.ts.map +1 -0
- package/{src/extensibility/schema.ts → dist/extensibility/schema.js} +2 -1
- package/dist/extensibility/schema.js.map +1 -0
- package/dist/extensibility/validation.d.ts +2 -0
- package/dist/extensibility/validation.d.ts.map +1 -0
- package/{src/extensibility/validation.ts → dist/extensibility/validation.js} +2 -1
- package/dist/extensibility/validation.js.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useAgentEvents.d.ts +8 -0
- package/dist/hooks/useAgentEvents.d.ts.map +1 -0
- package/dist/hooks/useAgentEvents.js +22 -0
- package/dist/hooks/useAgentEvents.js.map +1 -0
- package/dist/hooks/useEditorBridge.d.ts +20 -0
- package/dist/hooks/useEditorBridge.d.ts.map +1 -0
- package/dist/hooks/useEditorBridge.js +80 -0
- package/dist/hooks/useEditorBridge.js.map +1 -0
- package/dist/hooks/useGitStatus.d.ts +2 -0
- package/dist/hooks/useGitStatus.d.ts.map +1 -0
- package/dist/hooks/useGitStatus.js +26 -0
- package/dist/hooks/useGitStatus.js.map +1 -0
- package/dist/hooks/usePromptQueue.d.ts +2 -0
- package/dist/hooks/usePromptQueue.d.ts.map +1 -0
- package/dist/hooks/usePromptQueue.js +2 -0
- package/dist/hooks/usePromptQueue.js.map +1 -0
- package/dist/hooks/useSessionController.d.ts +2 -0
- package/dist/hooks/useSessionController.d.ts.map +1 -0
- package/dist/hooks/useSessionController.js +2 -0
- package/dist/hooks/useSessionController.js.map +1 -0
- package/dist/hooks/useSpinner.d.ts +4 -0
- package/dist/hooks/useSpinner.d.ts.map +1 -0
- package/dist/hooks/useSpinner.js +25 -0
- package/dist/hooks/useSpinner.js.map +1 -0
- package/dist/hooks/useToastManager.d.ts +6 -0
- package/dist/hooks/useToastManager.d.ts.map +1 -0
- package/dist/hooks/useToastManager.js +22 -0
- package/dist/hooks/useToastManager.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +156 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard-handler.d.ts +30 -0
- package/dist/keyboard-handler.d.ts.map +1 -0
- package/dist/keyboard-handler.js +96 -0
- package/dist/keyboard-handler.js.map +1 -0
- package/dist/profiler.d.ts +2 -0
- package/dist/profiler.d.ts.map +1 -0
- package/dist/profiler.js +41 -0
- package/dist/profiler.js.map +1 -0
- package/dist/runtime/context.d.ts +8 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/context.jsx +11 -0
- package/dist/runtime/context.jsx.map +1 -0
- package/dist/runtime/factory.d.ts +12 -0
- package/dist/runtime/factory.d.ts.map +1 -0
- package/dist/runtime/factory.js +37 -0
- package/dist/runtime/factory.js.map +1 -0
- package/dist/runtime/git/git-info.d.ts +3 -0
- package/dist/runtime/git/git-info.d.ts.map +1 -0
- package/dist/runtime/git/git-info.js +29 -0
- package/dist/runtime/git/git-info.js.map +1 -0
- package/dist/runtime/session/session-controller.d.ts +48 -0
- package/dist/runtime/session/session-controller.d.ts.map +1 -0
- package/dist/runtime/session/session-controller.js +159 -0
- package/dist/runtime/session/session-controller.js.map +1 -0
- package/dist/session-manager.d.ts +2 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/session-manager.js +2 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/session-picker.d.ts +6 -0
- package/dist/session-picker.d.ts.map +1 -0
- package/dist/session-picker.jsx +96 -0
- package/dist/session-picker.jsx.map +1 -0
- package/dist/shell-runner.d.ts +21 -0
- package/dist/shell-runner.d.ts.map +1 -0
- package/dist/shell-runner.js +106 -0
- package/dist/shell-runner.js.map +1 -0
- package/dist/syntax-highlighting.d.ts +4 -0
- package/dist/syntax-highlighting.d.ts.map +1 -0
- package/dist/syntax-highlighting.js +108 -0
- package/dist/syntax-highlighting.js.map +1 -0
- package/dist/theme-names.d.ts +7 -0
- package/dist/theme-names.d.ts.map +1 -0
- package/dist/theme-names.js +38 -0
- package/dist/theme-names.js.map +1 -0
- package/dist/tool-ui-contracts.d.ts +30 -0
- package/dist/tool-ui-contracts.d.ts.map +1 -0
- package/dist/tool-ui-contracts.js +53 -0
- package/dist/tool-ui-contracts.js.map +1 -0
- package/dist/tui-open-rendering.d.ts +37 -0
- package/dist/tui-open-rendering.d.ts.map +1 -0
- package/dist/tui-open-rendering.jsx +462 -0
- package/dist/tui-open-rendering.jsx.map +1 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/app-shell/TuiApp.d.ts +6 -0
- package/dist/ui/app-shell/TuiApp.d.ts.map +1 -0
- package/dist/ui/app-shell/TuiApp.jsx +480 -0
- package/dist/ui/app-shell/TuiApp.jsx.map +1 -0
- package/dist/ui/clipboard/osc52.d.ts +2 -0
- package/dist/ui/clipboard/osc52.d.ts.map +1 -0
- package/dist/ui/clipboard/osc52.js +19 -0
- package/dist/ui/clipboard/osc52.js.map +1 -0
- package/dist/ui/components/modals/ConfirmModal.d.ts +8 -0
- package/dist/ui/components/modals/ConfirmModal.d.ts.map +1 -0
- package/dist/ui/components/modals/ConfirmModal.jsx +39 -0
- package/dist/ui/components/modals/ConfirmModal.jsx.map +1 -0
- package/dist/ui/components/modals/EditorModal.d.ts +8 -0
- package/dist/ui/components/modals/EditorModal.d.ts.map +1 -0
- package/dist/ui/components/modals/EditorModal.jsx +23 -0
- package/dist/ui/components/modals/EditorModal.jsx.map +1 -0
- package/dist/ui/components/modals/InputModal.d.ts +8 -0
- package/dist/ui/components/modals/InputModal.d.ts.map +1 -0
- package/dist/ui/components/modals/InputModal.jsx +15 -0
- package/dist/ui/components/modals/InputModal.jsx.map +1 -0
- package/dist/ui/components/modals/ModalContainer.d.ts +8 -0
- package/dist/ui/components/modals/ModalContainer.d.ts.map +1 -0
- package/dist/ui/components/modals/ModalContainer.jsx +34 -0
- package/dist/ui/components/modals/ModalContainer.jsx.map +1 -0
- package/dist/ui/components/modals/SelectModal.d.ts +8 -0
- package/dist/ui/components/modals/SelectModal.d.ts.map +1 -0
- package/dist/ui/components/modals/SelectModal.jsx +32 -0
- package/dist/ui/components/modals/SelectModal.jsx.map +1 -0
- package/{src/ui/components/modals/index.ts → dist/ui/components/modals/index.d.ts} +5 -4
- package/dist/ui/components/modals/index.d.ts.map +1 -0
- package/dist/ui/components/modals/index.js +5 -0
- package/dist/ui/components/modals/index.js.map +1 -0
- package/dist/ui/features/composer/Composer.d.ts +16 -0
- package/dist/ui/features/composer/Composer.d.ts.map +1 -0
- package/dist/ui/features/composer/Composer.jsx +39 -0
- package/dist/ui/features/composer/Composer.jsx.map +1 -0
- package/dist/ui/features/composer/SlashCommandHandler.d.ts +14 -0
- package/dist/ui/features/composer/SlashCommandHandler.d.ts.map +1 -0
- package/dist/ui/features/composer/SlashCommandHandler.js +43 -0
- package/dist/ui/features/composer/SlashCommandHandler.js.map +1 -0
- package/dist/ui/features/composer/keyboard.d.ts +3 -0
- package/dist/ui/features/composer/keyboard.d.ts.map +1 -0
- package/dist/ui/features/composer/keyboard.js +3 -0
- package/dist/ui/features/composer/keyboard.js.map +1 -0
- package/dist/ui/features/main-view/MainView.d.ts +52 -0
- package/dist/ui/features/main-view/MainView.d.ts.map +1 -0
- package/dist/ui/features/main-view/MainView.jsx +269 -0
- package/dist/ui/features/main-view/MainView.jsx.map +1 -0
- package/dist/ui/features/message-pane/MessagePane.d.ts +15 -0
- package/dist/ui/features/message-pane/MessagePane.d.ts.map +1 -0
- package/dist/ui/features/message-pane/MessagePane.jsx +7 -0
- package/dist/ui/features/message-pane/MessagePane.jsx.map +1 -0
- package/dist/ui/hooks/useModals.d.ts +35 -0
- package/dist/ui/hooks/useModals.d.ts.map +1 -0
- package/dist/ui/hooks/useModals.js +36 -0
- package/dist/ui/hooks/useModals.js.map +1 -0
- package/dist/ui/state/app-store.d.ts +42 -0
- package/dist/ui/state/app-store.d.ts.map +1 -0
- package/dist/ui/state/app-store.js +28 -0
- package/dist/ui/state/app-store.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +3 -0
- package/dist/utils.js.map +1 -0
- package/package.json +19 -6
- package/src/adapters/acp/index.ts +0 -305
- package/src/adapters/acp/protocol.ts +0 -191
- package/src/adapters/acp/session.ts +0 -289
- package/src/adapters/acp/updates.ts +0 -96
- package/src/adapters/cli/headless.ts +0 -112
- package/src/adapters/cli/validate.ts +0 -50
- package/src/adapters/tui/app.tsx +0 -39
- package/src/agent-events.ts +0 -671
- package/src/args.ts +0 -102
- package/src/autocomplete-commands.ts +0 -102
- package/src/commands.ts +0 -23
- package/src/compact-handler.ts +0 -272
- package/src/components/Footer.tsx +0 -49
- package/src/components/Header.tsx +0 -218
- package/src/components/MessageList.tsx +0 -380
- package/src/config.ts +0 -1
- package/src/domain/commands/builtin/clear.ts +0 -14
- package/src/domain/commands/builtin/compact.ts +0 -96
- package/src/domain/commands/builtin/conceal.ts +0 -9
- package/src/domain/commands/builtin/diffwrap.ts +0 -9
- package/src/domain/commands/builtin/editor.ts +0 -24
- package/src/domain/commands/builtin/exit.ts +0 -14
- package/src/domain/commands/builtin/followup.ts +0 -24
- package/src/domain/commands/builtin/index.ts +0 -29
- package/src/domain/commands/builtin/login.ts +0 -118
- package/src/domain/commands/builtin/model.ts +0 -66
- package/src/domain/commands/builtin/status.ts +0 -32
- package/src/domain/commands/builtin/steer.ts +0 -24
- package/src/domain/commands/builtin/theme.ts +0 -23
- package/src/domain/commands/builtin/thinking.ts +0 -16
- package/src/domain/commands/helpers.ts +0 -41
- package/src/domain/commands/registry.ts +0 -42
- package/src/domain/commands/types.ts +0 -69
- package/src/domain/messaging/content.ts +0 -117
- package/src/editor.ts +0 -103
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useAgentEvents.ts +0 -28
- package/src/hooks/useEditorBridge.ts +0 -101
- package/src/hooks/useGitStatus.ts +0 -28
- package/src/hooks/usePromptQueue.ts +0 -7
- package/src/hooks/useSessionController.ts +0 -5
- package/src/hooks/useSpinner.ts +0 -28
- package/src/hooks/useToastManager.ts +0 -26
- package/src/index.ts +0 -188
- package/src/keyboard-handler.ts +0 -134
- package/src/profiler.ts +0 -40
- package/src/runtime/context.tsx +0 -16
- package/src/runtime/factory.ts +0 -63
- package/src/runtime/git/git-info.ts +0 -25
- package/src/runtime/session/session-controller.ts +0 -208
- package/src/session-manager.ts +0 -1
- package/src/session-picker.tsx +0 -134
- package/src/shell-runner.ts +0 -134
- package/src/syntax-highlighting.ts +0 -114
- package/src/theme-names.ts +0 -37
- package/src/tool-ui-contracts.ts +0 -77
- package/src/tui-open-rendering.tsx +0 -565
- package/src/types.ts +0 -89
- package/src/ui/app-shell/TuiApp.tsx +0 -586
- package/src/ui/clipboard/osc52.ts +0 -18
- package/src/ui/components/modals/ConfirmModal.tsx +0 -52
- package/src/ui/components/modals/EditorModal.tsx +0 -39
- package/src/ui/components/modals/InputModal.tsx +0 -30
- package/src/ui/components/modals/ModalContainer.tsx +0 -67
- package/src/ui/components/modals/SelectModal.tsx +0 -48
- package/src/ui/features/composer/Composer.tsx +0 -73
- package/src/ui/features/composer/SlashCommandHandler.ts +0 -58
- package/src/ui/features/composer/keyboard.ts +0 -3
- package/src/ui/features/main-view/MainView.tsx +0 -367
- package/src/ui/features/message-pane/MessagePane.tsx +0 -34
- package/src/ui/hooks/useModals.ts +0 -74
- package/src/ui/state/app-store.ts +0 -67
- package/src/utils.ts +0 -14
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { handleCompact as doCompact } from "../../../compact-handler.js"
|
|
2
|
-
import { addSystemMessage } from "../helpers.js"
|
|
3
|
-
import type { CommandDefinition } from "../types.js"
|
|
4
|
-
|
|
5
|
-
export const compactCommand: CommandDefinition = {
|
|
6
|
-
name: "compact",
|
|
7
|
-
execute: async (args, ctx) => {
|
|
8
|
-
if (ctx.isResponding()) {
|
|
9
|
-
addSystemMessage(ctx, "Cannot compact while responding. Use /abort first.")
|
|
10
|
-
return true
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const messages = ctx.agent.state.messages
|
|
14
|
-
if (messages.length < 2) {
|
|
15
|
-
addSystemMessage(ctx, "Nothing to compact (need at least one exchange)")
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const customInstructions = args.trim() || undefined
|
|
20
|
-
|
|
21
|
-
// Emit session.before_compact hook - allows hooks to cancel or add context
|
|
22
|
-
const beforeCompactEvent = {
|
|
23
|
-
type: "session.before_compact" as const,
|
|
24
|
-
input: { sessionId: ctx.sessionManager.sessionId },
|
|
25
|
-
output: { cancel: false, prompt: undefined as string | undefined, context: [] as string[] },
|
|
26
|
-
}
|
|
27
|
-
await ctx.hookRunner?.emit(beforeCompactEvent)
|
|
28
|
-
if (beforeCompactEvent.output.cancel) {
|
|
29
|
-
addSystemMessage(ctx, "Compaction cancelled by hook")
|
|
30
|
-
return true
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Merge hook-provided instructions with user-provided ones
|
|
34
|
-
const hookPrompt = beforeCompactEvent.output.prompt
|
|
35
|
-
const mergedInstructions = [customInstructions, hookPrompt, ...beforeCompactEvent.output.context]
|
|
36
|
-
.filter(Boolean)
|
|
37
|
-
.join("\n\n") || undefined
|
|
38
|
-
|
|
39
|
-
ctx.setActivityState("compacting")
|
|
40
|
-
ctx.setIsResponding(true)
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const prevState = ctx.sessionManager.getCompactionState()
|
|
44
|
-
|
|
45
|
-
const { summary, summaryMessage, fileOps } = await doCompact({
|
|
46
|
-
agent: ctx.agent,
|
|
47
|
-
currentProvider: ctx.currentProvider,
|
|
48
|
-
getApiKey: ctx.getApiKey,
|
|
49
|
-
codexTransport: ctx.codexTransport,
|
|
50
|
-
customInstructions: mergedInstructions,
|
|
51
|
-
previousSummary: prevState?.lastSummary,
|
|
52
|
-
previousFileOps: prevState
|
|
53
|
-
? {
|
|
54
|
-
readFiles: prevState.readFiles,
|
|
55
|
-
modifiedFiles: prevState.modifiedFiles,
|
|
56
|
-
}
|
|
57
|
-
: undefined,
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
// Emit session.compact hook after successful compaction
|
|
61
|
-
await ctx.hookRunner?.emit({
|
|
62
|
-
type: "session.compact",
|
|
63
|
-
sessionId: ctx.sessionManager.sessionId,
|
|
64
|
-
summary,
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
ctx.agent.reset()
|
|
68
|
-
ctx.agent.replaceMessages([summaryMessage])
|
|
69
|
-
|
|
70
|
-
ctx.sessionManager.startSession(ctx.currentProvider, ctx.currentModelId, ctx.currentThinking)
|
|
71
|
-
ctx.sessionManager.appendMessage(summaryMessage)
|
|
72
|
-
|
|
73
|
-
const modified = new Set([...fileOps.edited, ...fileOps.written])
|
|
74
|
-
const readOnly = [...fileOps.read].filter((file) => !modified.has(file))
|
|
75
|
-
ctx.sessionManager.updateCompactionState({
|
|
76
|
-
lastSummary: summary,
|
|
77
|
-
readFiles: readOnly.sort(),
|
|
78
|
-
modifiedFiles: [...modified].sort(),
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
ctx.setMessages(() => [
|
|
82
|
-
{ id: crypto.randomUUID(), role: "assistant" as const, content: `Context compacted:\n\n${summary}` },
|
|
83
|
-
])
|
|
84
|
-
ctx.setToolBlocks(() => [])
|
|
85
|
-
ctx.setContextTokens(0)
|
|
86
|
-
ctx.setCacheStats(null)
|
|
87
|
-
} catch (err) {
|
|
88
|
-
addSystemMessage(ctx, `Compact failed: ${err instanceof Error ? err.message : String(err)}`)
|
|
89
|
-
} finally {
|
|
90
|
-
ctx.setIsResponding(false)
|
|
91
|
-
ctx.setActivityState("idle")
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return true
|
|
95
|
-
},
|
|
96
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { buildEditorInvocation } from "../../../editor.js"
|
|
2
|
-
import { defaultLaunchEditor } from "../helpers.js"
|
|
3
|
-
import type { CommandDefinition } from "../types.js"
|
|
4
|
-
|
|
5
|
-
export const editorCommand: CommandDefinition = {
|
|
6
|
-
name: "editor",
|
|
7
|
-
execute: async (_args, ctx) => {
|
|
8
|
-
if (ctx.openEditor) {
|
|
9
|
-
await ctx.openEditor()
|
|
10
|
-
return true
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const editor = ctx.editor ?? { command: "nvim", args: [] }
|
|
14
|
-
const { command, args } = buildEditorInvocation(editor, ctx.cwd, { appendCwd: true })
|
|
15
|
-
const launch = ctx.launchEditor ?? defaultLaunchEditor
|
|
16
|
-
launch(command, args, ctx.cwd, (error) => {
|
|
17
|
-
ctx.setMessages((prev) => [
|
|
18
|
-
...prev,
|
|
19
|
-
{ id: crypto.randomUUID(), role: "assistant" as const, content: `Failed to launch editor: ${error.message}` },
|
|
20
|
-
])
|
|
21
|
-
})
|
|
22
|
-
return true
|
|
23
|
-
},
|
|
24
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { CommandDefinition } from "../types.js"
|
|
2
|
-
|
|
3
|
-
export const exitCommand: CommandDefinition = {
|
|
4
|
-
name: "exit",
|
|
5
|
-
aliases: ["quit"],
|
|
6
|
-
execute: (_args, ctx) => {
|
|
7
|
-
if (ctx.onExit) {
|
|
8
|
-
ctx.onExit()
|
|
9
|
-
} else {
|
|
10
|
-
process.exit(0)
|
|
11
|
-
}
|
|
12
|
-
return true
|
|
13
|
-
},
|
|
14
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { addSystemMessage } from "../helpers.js"
|
|
2
|
-
import type { CommandDefinition } from "../types.js"
|
|
3
|
-
|
|
4
|
-
const USAGE = "Usage: /followup <text>"
|
|
5
|
-
|
|
6
|
-
export const followupCommand: CommandDefinition = {
|
|
7
|
-
name: "followup",
|
|
8
|
-
description: "Queue text to deliver after the agent becomes idle",
|
|
9
|
-
execute: async (args, ctx) => {
|
|
10
|
-
const text = args.trim()
|
|
11
|
-
if (!text) {
|
|
12
|
-
addSystemMessage(ctx, USAGE)
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (ctx.isResponding()) {
|
|
17
|
-
await ctx.followUp(text)
|
|
18
|
-
return true
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
await ctx.submitPrompt(text, { mode: "followUp" })
|
|
22
|
-
return true
|
|
23
|
-
},
|
|
24
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { clearCommand } from "./clear.js"
|
|
2
|
-
import { compactCommand } from "./compact.js"
|
|
3
|
-
import { concealCommand } from "./conceal.js"
|
|
4
|
-
import { diffwrapCommand } from "./diffwrap.js"
|
|
5
|
-
import { editorCommand } from "./editor.js"
|
|
6
|
-
import { exitCommand } from "./exit.js"
|
|
7
|
-
import { followupCommand } from "./followup.js"
|
|
8
|
-
import { loginCommand } from "./login.js"
|
|
9
|
-
import { modelCommand } from "./model.js"
|
|
10
|
-
import { statusCommand } from "./status.js"
|
|
11
|
-
import { steerCommand } from "./steer.js"
|
|
12
|
-
import { themeCommand } from "./theme.js"
|
|
13
|
-
import { thinkingCommand } from "./thinking.js"
|
|
14
|
-
|
|
15
|
-
export const builtinCommands = [
|
|
16
|
-
exitCommand,
|
|
17
|
-
clearCommand,
|
|
18
|
-
thinkingCommand,
|
|
19
|
-
diffwrapCommand,
|
|
20
|
-
concealCommand,
|
|
21
|
-
themeCommand,
|
|
22
|
-
editorCommand,
|
|
23
|
-
modelCommand,
|
|
24
|
-
compactCommand,
|
|
25
|
-
statusCommand,
|
|
26
|
-
loginCommand,
|
|
27
|
-
steerCommand,
|
|
28
|
-
followupCommand,
|
|
29
|
-
]
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { exec } from "node:child_process"
|
|
2
|
-
import {
|
|
3
|
-
saveAnthropicTokens,
|
|
4
|
-
loadAnthropicTokens,
|
|
5
|
-
clearAnthropicTokens,
|
|
6
|
-
getAnthropicTokensPath,
|
|
7
|
-
} from "@yeshwanthyk/agent-core"
|
|
8
|
-
import { loginAnthropic } from "@yeshwanthyk/ai"
|
|
9
|
-
import type { CommandDefinition } from "../types.js"
|
|
10
|
-
import { addSystemMessage } from "../helpers.js"
|
|
11
|
-
|
|
12
|
-
let pendingAuthUrl: string | null = null
|
|
13
|
-
|
|
14
|
-
function openBrowser(url: string): void {
|
|
15
|
-
const cmd =
|
|
16
|
-
process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open"
|
|
17
|
-
exec(`${cmd} "${url}"`)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const loginCommand: CommandDefinition = {
|
|
21
|
-
name: "login",
|
|
22
|
-
description: "Login with Anthropic OAuth (Claude Pro/Max)",
|
|
23
|
-
execute: async (args, ctx) => {
|
|
24
|
-
const configDir = ctx.configDir
|
|
25
|
-
|
|
26
|
-
// /login status - show current login status
|
|
27
|
-
if (args === "status") {
|
|
28
|
-
const tokens = loadAnthropicTokens({ configDir })
|
|
29
|
-
if (tokens) {
|
|
30
|
-
const expiresAt = new Date(tokens.expires).toLocaleString()
|
|
31
|
-
const isExpired = tokens.expires <= Date.now()
|
|
32
|
-
addSystemMessage(
|
|
33
|
-
ctx,
|
|
34
|
-
isExpired
|
|
35
|
-
? `Anthropic OAuth: Token expired at ${expiresAt}. Run /login to re-authenticate.`
|
|
36
|
-
: `Anthropic OAuth: Logged in, token expires ${expiresAt}`,
|
|
37
|
-
)
|
|
38
|
-
} else {
|
|
39
|
-
addSystemMessage(ctx, "Anthropic OAuth: Not logged in. Run /login to authenticate.")
|
|
40
|
-
}
|
|
41
|
-
return true
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// /login clear - clear stored tokens
|
|
45
|
-
if (args === "clear" || args === "logout") {
|
|
46
|
-
clearAnthropicTokens({ configDir })
|
|
47
|
-
addSystemMessage(ctx, "Anthropic OAuth tokens cleared.")
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// /login <code#state> - complete the OAuth flow
|
|
52
|
-
if (args && args.includes("#")) {
|
|
53
|
-
if (!pendingAuthUrl) {
|
|
54
|
-
addSystemMessage(ctx, "No pending login. Run /login first to start the OAuth flow.")
|
|
55
|
-
return true
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const credentials = await loginAnthropic(
|
|
60
|
-
() => {}, // URL already shown
|
|
61
|
-
async () => args, // Return the provided code
|
|
62
|
-
)
|
|
63
|
-
saveAnthropicTokens(credentials, { configDir })
|
|
64
|
-
pendingAuthUrl = null
|
|
65
|
-
addSystemMessage(
|
|
66
|
-
ctx,
|
|
67
|
-
`Logged in successfully! Token saved to ${getAnthropicTokensPath({ configDir })}`,
|
|
68
|
-
)
|
|
69
|
-
} catch (err) {
|
|
70
|
-
pendingAuthUrl = null
|
|
71
|
-
addSystemMessage(ctx, `Login failed: ${err instanceof Error ? err.message : String(err)}`)
|
|
72
|
-
}
|
|
73
|
-
return true
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// /login - start the OAuth flow
|
|
77
|
-
addSystemMessage(ctx, "Starting Anthropic OAuth flow...")
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
// We need to capture the URL without completing the flow
|
|
81
|
-
const credentials = await loginAnthropic(
|
|
82
|
-
(url: string) => {
|
|
83
|
-
pendingAuthUrl = url
|
|
84
|
-
openBrowser(url)
|
|
85
|
-
},
|
|
86
|
-
async () => {
|
|
87
|
-
// Show instructions and return empty to abort this attempt
|
|
88
|
-
// User will call /login <code> to complete
|
|
89
|
-
throw new Error("PENDING")
|
|
90
|
-
},
|
|
91
|
-
)
|
|
92
|
-
// If we get here, somehow completed without user input (shouldn't happen)
|
|
93
|
-
saveAnthropicTokens(credentials, { configDir })
|
|
94
|
-
addSystemMessage(ctx, "Logged in successfully!")
|
|
95
|
-
} catch (err) {
|
|
96
|
-
if (err instanceof Error && err.message === "PENDING") {
|
|
97
|
-
// Expected - show instructions
|
|
98
|
-
addSystemMessage(
|
|
99
|
-
ctx,
|
|
100
|
-
[
|
|
101
|
-
"Browser opened for Anthropic login.",
|
|
102
|
-
"",
|
|
103
|
-
"After authorizing, you'll see a code like: abc123#xyz789",
|
|
104
|
-
"",
|
|
105
|
-
"Run: /login <code#state>",
|
|
106
|
-
"",
|
|
107
|
-
`Or visit: ${pendingAuthUrl}`,
|
|
108
|
-
].join("\n"),
|
|
109
|
-
)
|
|
110
|
-
} else {
|
|
111
|
-
pendingAuthUrl = null
|
|
112
|
-
addSystemMessage(ctx, `Login failed: ${err instanceof Error ? err.message : String(err)}`)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return true
|
|
117
|
-
},
|
|
118
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { getModels, getProviders } from "@yeshwanthyk/ai"
|
|
2
|
-
import { updateAppConfig } from "../../../config.js"
|
|
3
|
-
import type { CommandDefinition } from "../types.js"
|
|
4
|
-
import { addSystemMessage, resolveModel, resolveProvider } from "../helpers.js"
|
|
5
|
-
|
|
6
|
-
export const modelCommand: CommandDefinition = {
|
|
7
|
-
name: "model",
|
|
8
|
-
execute: (args, ctx) => {
|
|
9
|
-
if (!args) {
|
|
10
|
-
addSystemMessage(ctx, "Usage: /model <provider> <modelId> (or /model <modelId>)")
|
|
11
|
-
return true
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (ctx.isResponding()) {
|
|
15
|
-
addSystemMessage(ctx, "Model cannot be changed while responding. Use /abort first.")
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const parts = args.split(/\s+/)
|
|
20
|
-
if (parts.length === 1) {
|
|
21
|
-
const modelId = parts[0]!
|
|
22
|
-
const model = resolveModel(ctx.currentProvider, modelId)
|
|
23
|
-
if (!model) {
|
|
24
|
-
const examples = getModels(ctx.currentProvider).slice(0, 5).map((m) => m.id).join(", ")
|
|
25
|
-
addSystemMessage(ctx, `Unknown model "${modelId}" for ${ctx.currentProvider}. Examples: ${examples}`)
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
ctx.agent.setModel(model)
|
|
30
|
-
ctx.setCurrentModelId(model.id)
|
|
31
|
-
ctx.setDisplayModelId(model.id)
|
|
32
|
-
ctx.setDisplayContextWindow(model.contextWindow)
|
|
33
|
-
void updateAppConfig(
|
|
34
|
-
{ configDir: ctx.configDir, configPath: ctx.configPath },
|
|
35
|
-
{ model: model.id },
|
|
36
|
-
)
|
|
37
|
-
return true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const [providerRaw, ...modelParts] = parts
|
|
41
|
-
const provider = resolveProvider(providerRaw!)
|
|
42
|
-
if (!provider) {
|
|
43
|
-
addSystemMessage(ctx, `Unknown provider "${providerRaw}". Known: ${getProviders().join(", ")}`)
|
|
44
|
-
return true
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const modelId = modelParts.join(" ")
|
|
48
|
-
const model = resolveModel(provider, modelId)
|
|
49
|
-
if (!model) {
|
|
50
|
-
const examples = getModels(provider).slice(0, 5).map((m) => m.id).join(", ")
|
|
51
|
-
addSystemMessage(ctx, `Unknown model "${modelId}" for ${provider}. Examples: ${examples}`)
|
|
52
|
-
return true
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
ctx.agent.setModel(model)
|
|
56
|
-
ctx.setCurrentProvider(provider)
|
|
57
|
-
ctx.setCurrentModelId(model.id)
|
|
58
|
-
ctx.setDisplayModelId(model.id)
|
|
59
|
-
ctx.setDisplayContextWindow(model.contextWindow)
|
|
60
|
-
void updateAppConfig(
|
|
61
|
-
{ configDir: ctx.configDir, configPath: ctx.configPath },
|
|
62
|
-
{ provider, model: model.id },
|
|
63
|
-
)
|
|
64
|
-
return true
|
|
65
|
-
},
|
|
66
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { addSystemMessage } from "../helpers.js"
|
|
2
|
-
import type { CommandDefinition } from "../types.js"
|
|
3
|
-
|
|
4
|
-
const formatNumber = (n: number): string => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n))
|
|
5
|
-
|
|
6
|
-
export const statusCommand: CommandDefinition = {
|
|
7
|
-
name: "status",
|
|
8
|
-
execute: (_args, ctx) => {
|
|
9
|
-
const model = ctx.agent.state.model
|
|
10
|
-
const messages = ctx.agent.state.messages
|
|
11
|
-
let usage: { totalTokens?: number; cacheRead?: number } | undefined
|
|
12
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
13
|
-
const msg = messages[i] as { role: string; usage?: { totalTokens?: number; cacheRead?: number } }
|
|
14
|
-
if (msg.role === "assistant" && msg.usage?.totalTokens) {
|
|
15
|
-
usage = msg.usage
|
|
16
|
-
break
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
let ctxStr = `0/${formatNumber(model.contextWindow)}`
|
|
21
|
-
let cache = ""
|
|
22
|
-
if (usage?.totalTokens) {
|
|
23
|
-
const pct = ((usage.totalTokens / model.contextWindow) * 100).toFixed(1)
|
|
24
|
-
ctxStr = `${formatNumber(usage.totalTokens)}/${formatNumber(model.contextWindow)} (${pct}%)`
|
|
25
|
-
if (usage.cacheRead) cache = ` | cache: ${formatNumber(usage.cacheRead)} read`
|
|
26
|
-
}
|
|
27
|
-
const turns = messages.filter((m) => (m as { role: string }).role === "user").length
|
|
28
|
-
const status = `${ctx.currentModelId} (${ctx.currentProvider}) | ${ctx.currentThinking} | ${ctxStr}${cache} | turns: ${turns}`
|
|
29
|
-
addSystemMessage(ctx, status)
|
|
30
|
-
return true
|
|
31
|
-
},
|
|
32
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { addSystemMessage } from "../helpers.js"
|
|
2
|
-
import type { CommandDefinition } from "../types.js"
|
|
3
|
-
|
|
4
|
-
const USAGE = "Usage: /steer <text>"
|
|
5
|
-
|
|
6
|
-
export const steerCommand: CommandDefinition = {
|
|
7
|
-
name: "steer",
|
|
8
|
-
description: "Interrupt after the current tool turn with steering instructions",
|
|
9
|
-
execute: async (args, ctx) => {
|
|
10
|
-
const text = args.trim()
|
|
11
|
-
if (!text) {
|
|
12
|
-
addSystemMessage(ctx, USAGE)
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (ctx.isResponding()) {
|
|
17
|
-
await ctx.steer(text)
|
|
18
|
-
return true
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
await ctx.submitPrompt(text, { mode: "steer" })
|
|
22
|
-
return true
|
|
23
|
-
},
|
|
24
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { THEME_NAMES } from "../../../theme-names.js"
|
|
2
|
-
import { addSystemMessage } from "../helpers.js"
|
|
3
|
-
import type { CommandDefinition } from "../types.js"
|
|
4
|
-
|
|
5
|
-
export const themeCommand: CommandDefinition = {
|
|
6
|
-
name: "theme",
|
|
7
|
-
execute: (args, ctx) => {
|
|
8
|
-
const themeName = args.trim()
|
|
9
|
-
|
|
10
|
-
if (!themeName) {
|
|
11
|
-
addSystemMessage(ctx, `Available themes: ${THEME_NAMES.join(", ")}`)
|
|
12
|
-
return true
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!THEME_NAMES.includes(themeName)) {
|
|
16
|
-
addSystemMessage(ctx, `Unknown theme "${themeName}". Available: ${THEME_NAMES.join(", ")}`)
|
|
17
|
-
return true
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
ctx.setTheme?.(themeName)
|
|
21
|
-
return true
|
|
22
|
-
},
|
|
23
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { THINKING_LEVELS, type CommandDefinition } from "../types.js"
|
|
2
|
-
import { updateAppConfig } from "../../../config.js"
|
|
3
|
-
|
|
4
|
-
export const thinkingCommand: CommandDefinition = {
|
|
5
|
-
name: "thinking",
|
|
6
|
-
execute: (args, ctx) => {
|
|
7
|
-
const next = args.trim() as typeof THINKING_LEVELS[number]
|
|
8
|
-
if (!THINKING_LEVELS.includes(next)) return false
|
|
9
|
-
|
|
10
|
-
ctx.agent.setThinkingLevel(next)
|
|
11
|
-
ctx.setCurrentThinking(next)
|
|
12
|
-
ctx.setDisplayThinking(next)
|
|
13
|
-
void updateAppConfig({ configDir: ctx.configDir, configPath: ctx.configPath }, { thinking: next })
|
|
14
|
-
return true
|
|
15
|
-
},
|
|
16
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process"
|
|
2
|
-
import type { Api, Model, KnownProvider } from "@yeshwanthyk/ai"
|
|
3
|
-
import { getModels, getProviders } from "@yeshwanthyk/ai"
|
|
4
|
-
import type { CommandContext } from "./types.js"
|
|
5
|
-
|
|
6
|
-
export const resolveProvider = (raw: string): KnownProvider | undefined => {
|
|
7
|
-
const trimmed = raw.trim()
|
|
8
|
-
if (!trimmed) return undefined
|
|
9
|
-
const providers = getProviders()
|
|
10
|
-
return providers.includes(trimmed as KnownProvider) ? (trimmed as KnownProvider) : undefined
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const resolveModel = (provider: KnownProvider, raw: string): Model<Api> | undefined => {
|
|
14
|
-
const modelId = raw.trim()
|
|
15
|
-
if (!modelId) return undefined
|
|
16
|
-
return getModels(provider).find((m) => m.id === modelId) as Model<Api> | undefined
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const addSystemMessage = (ctx: CommandContext, content: string): void => {
|
|
20
|
-
ctx.setMessages((prev) => [
|
|
21
|
-
...prev,
|
|
22
|
-
{ id: crypto.randomUUID(), role: "assistant" as const, content },
|
|
23
|
-
])
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const defaultLaunchEditor = (
|
|
27
|
-
command: string,
|
|
28
|
-
args: string[],
|
|
29
|
-
cwd: string,
|
|
30
|
-
onError: (error: Error) => void,
|
|
31
|
-
): void => {
|
|
32
|
-
try {
|
|
33
|
-
const child = spawn(command, args, { cwd, detached: true, stdio: "ignore" })
|
|
34
|
-
child.once("error", (err) => {
|
|
35
|
-
onError(err instanceof Error ? err : new Error(String(err)))
|
|
36
|
-
})
|
|
37
|
-
child.unref()
|
|
38
|
-
} catch (err) {
|
|
39
|
-
onError(err instanceof Error ? err : new Error(String(err)))
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { CommandContext, CommandDefinition } from "./types.js"
|
|
2
|
-
|
|
3
|
-
const normalizeName = (value: string): string => value.trim().toLowerCase()
|
|
4
|
-
|
|
5
|
-
export class CommandRegistry {
|
|
6
|
-
private readonly definitions = new Map<string, CommandDefinition>()
|
|
7
|
-
private readonly lookup = new Map<string, CommandDefinition>()
|
|
8
|
-
|
|
9
|
-
register(definition: CommandDefinition): void {
|
|
10
|
-
const canonical = normalizeName(definition.name)
|
|
11
|
-
this.definitions.set(canonical, definition)
|
|
12
|
-
this.lookup.set(canonical, definition)
|
|
13
|
-
for (const alias of definition.aliases ?? []) {
|
|
14
|
-
const aliasKey = normalizeName(alias)
|
|
15
|
-
this.lookup.set(aliasKey, definition)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get(name: string): CommandDefinition | undefined {
|
|
20
|
-
return this.lookup.get(normalizeName(name))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
list(): CommandDefinition[] {
|
|
24
|
-
return Array.from(this.definitions.values())
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async execute(input: string, ctx: CommandContext): Promise<boolean> {
|
|
28
|
-
const trimmed = input.trim()
|
|
29
|
-
if (!trimmed.startsWith("/")) return false
|
|
30
|
-
|
|
31
|
-
const withoutSlash = trimmed.slice(1)
|
|
32
|
-
const whitespaceMatch = withoutSlash.match(/\s/)
|
|
33
|
-
const spaceIdx = whitespaceMatch?.index ?? -1
|
|
34
|
-
const commandName = spaceIdx === -1 ? withoutSlash : withoutSlash.slice(0, spaceIdx)
|
|
35
|
-
const args = spaceIdx === -1 ? "" : withoutSlash.slice(spaceIdx + 1)
|
|
36
|
-
const command = this.get(commandName)
|
|
37
|
-
if (!command) return false
|
|
38
|
-
|
|
39
|
-
const handled = command.execute(args, ctx)
|
|
40
|
-
return handled instanceof Promise ? await handled : handled
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { Agent, ThinkingLevel } from "@yeshwanthyk/agent-core"
|
|
2
|
-
import type { CodexTransport } from "@yeshwanthyk/agent-core"
|
|
3
|
-
import type { Api, Model, KnownProvider } from "@yeshwanthyk/ai"
|
|
4
|
-
import type { SessionManager } from "../../session-manager.js"
|
|
5
|
-
import type { ActivityState, ToolBlock, UIMessage } from "../../types.js"
|
|
6
|
-
import type { EditorConfig } from "../../config.js"
|
|
7
|
-
import type { HookRunner } from "../../hooks/index.js"
|
|
8
|
-
import type { PromptDeliveryMode } from "@yeshwanthyk/runtime-effect/session/prompt-queue.js"
|
|
9
|
-
import type { PromptSubmitOptions } from "@yeshwanthyk/runtime-effect/session/orchestrator.js"
|
|
10
|
-
|
|
11
|
-
export const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh"]
|
|
12
|
-
|
|
13
|
-
export interface CommandContext {
|
|
14
|
-
agent: Agent
|
|
15
|
-
sessionManager: SessionManager
|
|
16
|
-
configDir: string
|
|
17
|
-
configPath: string
|
|
18
|
-
cwd: string
|
|
19
|
-
editor?: EditorConfig
|
|
20
|
-
codexTransport: CodexTransport
|
|
21
|
-
getApiKey: (provider: string) => string | undefined
|
|
22
|
-
|
|
23
|
-
currentProvider: KnownProvider
|
|
24
|
-
currentModelId: string
|
|
25
|
-
currentThinking: ThinkingLevel
|
|
26
|
-
|
|
27
|
-
setCurrentProvider: (provider: KnownProvider) => void
|
|
28
|
-
setCurrentModelId: (modelId: string) => void
|
|
29
|
-
setCurrentThinking: (thinking: ThinkingLevel) => void
|
|
30
|
-
|
|
31
|
-
isResponding: () => boolean
|
|
32
|
-
setIsResponding: (value: boolean) => void
|
|
33
|
-
setActivityState: (state: ActivityState) => void
|
|
34
|
-
setMessages: (updater: (prev: UIMessage[]) => UIMessage[]) => void
|
|
35
|
-
setToolBlocks: (updater: (prev: ToolBlock[]) => ToolBlock[]) => void
|
|
36
|
-
setContextTokens: (value: number) => void
|
|
37
|
-
setCacheStats: (value: { cacheRead: number; input: number } | null) => void
|
|
38
|
-
|
|
39
|
-
setDisplayModelId: (modelId: string) => void
|
|
40
|
-
setDisplayThinking: (thinking: ThinkingLevel) => void
|
|
41
|
-
setDisplayContextWindow: (tokens: number) => void
|
|
42
|
-
|
|
43
|
-
setDiffWrapMode: (updater: (prev: "word" | "none") => "word" | "none") => void
|
|
44
|
-
setConcealMarkdown: (updater: (prev: boolean) => boolean) => void
|
|
45
|
-
|
|
46
|
-
setTheme?: (name: string) => void
|
|
47
|
-
launchEditor?: (command: string, args: string[], cwd: string, onError: (error: Error) => void) => void
|
|
48
|
-
openEditor?: () => Promise<void> | void
|
|
49
|
-
|
|
50
|
-
onExit?: () => void
|
|
51
|
-
hookRunner?: HookRunner
|
|
52
|
-
submitPrompt: (text: string, options?: PromptSubmitOptions) => Promise<void>
|
|
53
|
-
steer: (text: string) => Promise<void>
|
|
54
|
-
followUp: (text: string) => Promise<void>
|
|
55
|
-
sendUserMessage: (text: string, options?: { deliverAs?: PromptDeliveryMode }) => Promise<void>
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type CommandHandlerResult = boolean | Promise<boolean>
|
|
59
|
-
|
|
60
|
-
export interface CommandDefinition {
|
|
61
|
-
name: string
|
|
62
|
-
aliases?: string[]
|
|
63
|
-
description?: string
|
|
64
|
-
execute: (args: string, ctx: CommandContext) => CommandHandlerResult
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type CommandHandler = CommandDefinition["execute"]
|
|
68
|
-
|
|
69
|
-
export type ModelResolver = (provider: KnownProvider, modelId: string) => Model<Api> | undefined
|