@assistkick/create 1.10.0 → 1.12.0
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/dist/src/scaffolder.d.ts +12 -1
- package/dist/src/scaffolder.js +40 -3
- package/dist/src/scaffolder.js.map +1 -1
- package/package.json +1 -1
- package/templates/assistkick-product-system/package.json +1 -1
- package/templates/assistkick-product-system/packages/backend/package.json +1 -0
- package/templates/assistkick-product-system/packages/backend/src/mcp/permission_mcp_server.ts +196 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/agents.ts +31 -7
- package/templates/assistkick-product-system/packages/backend/src/routes/auth.ts +15 -12
- package/templates/assistkick-product-system/packages/backend/src/routes/chat_files.test.ts +95 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/chat_files.ts +97 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/chat_permission.ts +94 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/chat_sessions.ts +189 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/chat_upload.test.ts +131 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/chat_upload.ts +94 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/files.test.ts +12 -3
- package/templates/assistkick-product-system/packages/backend/src/routes/files.ts +2 -2
- package/templates/assistkick-product-system/packages/backend/src/routes/git.ts +390 -22
- package/templates/assistkick-product-system/packages/backend/src/routes/git_branches.test.ts +306 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/git_connect.test.ts +133 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/pipeline.ts +66 -9
- package/templates/assistkick-product-system/packages/backend/src/routes/preview.ts +204 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/projects.test.ts +205 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/projects.ts +37 -9
- package/templates/assistkick-product-system/packages/backend/src/routes/skills.test.ts +139 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/skills.ts +95 -0
- package/templates/assistkick-product-system/packages/backend/src/routes/terminal.ts +5 -4
- package/templates/assistkick-product-system/packages/backend/src/routes/users.ts +4 -4
- package/templates/assistkick-product-system/packages/backend/src/routes/video.ts +8 -8
- package/templates/assistkick-product-system/packages/backend/src/routes/workflow_groups.ts +5 -5
- package/templates/assistkick-product-system/packages/backend/src/routes/workflows.ts +6 -6
- package/templates/assistkick-product-system/packages/backend/src/server.ts +107 -27
- package/templates/assistkick-product-system/packages/backend/src/services/agent_service.test.ts +105 -203
- package/templates/assistkick-product-system/packages/backend/src/services/agent_service.ts +76 -266
- package/templates/assistkick-product-system/packages/backend/src/services/chat_cli_bridge.test.ts +427 -0
- package/templates/assistkick-product-system/packages/backend/src/services/chat_cli_bridge.ts +345 -0
- package/templates/assistkick-product-system/packages/backend/src/services/chat_message_repository.test.ts +170 -0
- package/templates/assistkick-product-system/packages/backend/src/services/chat_message_repository.ts +106 -0
- package/templates/assistkick-product-system/packages/backend/src/services/chat_session_service.test.ts +217 -0
- package/templates/assistkick-product-system/packages/backend/src/services/chat_session_service.ts +188 -0
- package/templates/assistkick-product-system/packages/backend/src/services/chat_ws_handler.test.ts +1243 -0
- package/templates/assistkick-product-system/packages/backend/src/services/chat_ws_handler.ts +894 -0
- package/templates/assistkick-product-system/packages/backend/src/services/coherence-review.ts +3 -3
- package/templates/assistkick-product-system/packages/backend/src/services/dev_command_detector.test.ts +85 -0
- package/templates/assistkick-product-system/packages/backend/src/services/dev_command_detector.ts +54 -0
- package/templates/assistkick-product-system/packages/backend/src/services/email_service.ts +13 -10
- package/templates/assistkick-product-system/packages/backend/src/services/init.ts +11 -3
- package/templates/assistkick-product-system/packages/backend/src/services/invitation_service.ts +1 -1
- package/templates/assistkick-product-system/packages/backend/src/services/password_reset_service.ts +1 -1
- package/templates/assistkick-product-system/packages/backend/src/services/permission_service.test.ts +243 -0
- package/templates/assistkick-product-system/packages/backend/src/services/permission_service.ts +259 -0
- package/templates/assistkick-product-system/packages/backend/src/services/preview_server_manager.test.ts +172 -0
- package/templates/assistkick-product-system/packages/backend/src/services/preview_server_manager.ts +225 -0
- package/templates/assistkick-product-system/packages/backend/src/services/project_service.test.ts +29 -0
- package/templates/assistkick-product-system/packages/backend/src/services/project_service.ts +17 -0
- package/templates/assistkick-product-system/packages/backend/src/services/project_workspace_service.test.ts +255 -0
- package/templates/assistkick-product-system/packages/backend/src/services/project_workspace_service.ts +300 -25
- package/templates/assistkick-product-system/packages/backend/src/services/pty_session_manager.test.ts +44 -0
- package/templates/assistkick-product-system/packages/backend/src/services/pty_session_manager.ts +62 -7
- package/templates/assistkick-product-system/packages/backend/src/services/ssh_key_service.test.ts +77 -6
- package/templates/assistkick-product-system/packages/backend/src/services/ssh_key_service.ts +129 -8
- package/templates/assistkick-product-system/packages/backend/src/services/terminal_ws_handler.ts +2 -1
- package/templates/assistkick-product-system/packages/backend/src/services/title_generator_service.test.ts +45 -0
- package/templates/assistkick-product-system/packages/backend/src/services/title_generator_service.ts +157 -0
- package/templates/assistkick-product-system/packages/backend/src/services/tts_service.ts +4 -3
- package/templates/assistkick-product-system/packages/backend/src/services/video_render_service.ts +3 -3
- package/templates/assistkick-product-system/packages/frontend/package.json +5 -0
- package/templates/assistkick-product-system/packages/frontend/src/App.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/api/client.ts +336 -5
- package/templates/assistkick-product-system/packages/frontend/src/components/AgentsView.tsx +192 -12
- package/templates/assistkick-product-system/packages/frontend/src/components/AttachmentPreviewList.tsx +98 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/AutocompleteDropdown.tsx +65 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatAttachButton.tsx +56 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatDropZone.tsx +80 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatMessageBubble.tsx +155 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatMessageContent.tsx +182 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatMessageInput.tsx +233 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatSessionSidebar.tsx +218 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatStopButton.tsx +32 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatTodoSidebar.tsx +113 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ChatView.tsx +842 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/CommitMessageModal.tsx +82 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/DiagramOverlay.tsx +160 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/EditorTabBar.tsx +5 -5
- package/templates/assistkick-product-system/packages/frontend/src/components/FileTree.tsx +9 -10
- package/templates/assistkick-product-system/packages/frontend/src/components/FileTreeInlineInput.tsx +5 -5
- package/templates/assistkick-product-system/packages/frontend/src/components/FilesView.tsx +112 -41
- package/templates/assistkick-product-system/packages/frontend/src/components/GraphLegend.tsx +2 -2
- package/templates/assistkick-product-system/packages/frontend/src/components/HighlightedText.tsx +87 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ImageLightbox.tsx +192 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/KanbanView.tsx +2 -2
- package/templates/assistkick-product-system/packages/frontend/src/components/MentionPill.tsx +33 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/MermaidBlock.tsx +148 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/PermissionDialog.tsx +91 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/PermissionModeSelector.tsx +229 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ProjectSelector.tsx +249 -83
- package/templates/assistkick-product-system/packages/frontend/src/components/QueuedMessageBubble.tsx +38 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/SidePanel.tsx +212 -117
- package/templates/assistkick-product-system/packages/frontend/src/components/SystemPromptAccordion.tsx +48 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/TaskIcon.tsx +11 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/TerminalView.tsx +25 -9
- package/templates/assistkick-product-system/packages/frontend/src/components/ToolDiffView.tsx +114 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ToolResultCard.tsx +87 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/ToolUseCard.tsx +149 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/Toolbar.tsx +25 -8
- package/templates/assistkick-product-system/packages/frontend/src/components/UnifiedGitWidget.tsx +722 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/workflow/GroupNode.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/workflow/NodePalette.tsx +2 -1
- package/templates/assistkick-product-system/packages/frontend/src/components/workflow/ProgrammableNode.tsx +178 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/workflow/WorkflowCanvas.tsx +3 -0
- package/templates/assistkick-product-system/packages/frontend/src/components/workflow/WorkflowMonitorModal.tsx +103 -9
- package/templates/assistkick-product-system/packages/frontend/src/components/workflow/monitor_nodes.tsx +26 -2
- package/templates/assistkick-product-system/packages/frontend/src/components/workflow/workflow_types.ts +42 -1
- package/templates/assistkick-product-system/packages/frontend/src/hooks/useDocumentTitle.ts +11 -0
- package/templates/assistkick-product-system/packages/frontend/src/hooks/useProjects.ts +1 -0
- package/templates/assistkick-product-system/packages/frontend/src/hooks/use_chat_stream.ts +826 -0
- package/templates/assistkick-product-system/packages/frontend/src/hooks/use_file_tree_cache.ts +69 -0
- package/templates/assistkick-product-system/packages/frontend/src/hooks/use_mention_autocomplete.ts +284 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/attachment_manager.test.ts +183 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/attachment_manager.ts +150 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/chat_message_helpers.test.ts +305 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/chat_message_helpers.ts +113 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/context_usage_helpers.test.ts +157 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/context_usage_helpers.ts +95 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/mermaid_helpers.test.ts +65 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/mermaid_helpers.ts +110 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/message_queue.ts +66 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/tool_use_summary.test.ts +124 -0
- package/templates/assistkick-product-system/packages/frontend/src/lib/tool_use_summary.ts +112 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/AgentsRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/ChatRoute.tsx +8 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/CoherenceRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/DashboardLayout.tsx +0 -4
- package/templates/assistkick-product-system/packages/frontend/src/routes/DesignSystemRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/FilesRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/GraphRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/KanbanRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/TerminalRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/UsersRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/VideographyRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/WorkflowsRoute.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/accept_invitation.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/forgot_password.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/login.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/register.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/routes/reset_password.tsx +2 -0
- package/templates/assistkick-product-system/packages/frontend/src/stores/useAttachmentStore.ts +66 -0
- package/templates/assistkick-product-system/packages/frontend/src/stores/useChatSessionStore.ts +107 -0
- package/templates/assistkick-product-system/packages/frontend/src/stores/useMessageQueueStore.ts +110 -0
- package/templates/assistkick-product-system/packages/frontend/src/stores/usePreviewStore.ts +78 -0
- package/templates/assistkick-product-system/packages/frontend/src/stores/useProjectStore.ts +7 -0
- package/templates/assistkick-product-system/packages/frontend/src/stores/useSidePanelStore.ts +6 -1
- package/templates/assistkick-product-system/packages/frontend/src/styles/index.css +30 -357
- package/templates/assistkick-product-system/packages/frontend/src/utils/parse_node_markdown.test.ts +115 -0
- package/templates/assistkick-product-system/packages/frontend/src/utils/parse_node_markdown.ts +91 -0
- package/templates/assistkick-product-system/packages/frontend/src/utils/preview_utils.test.ts +30 -0
- package/templates/assistkick-product-system/packages/frontend/src/utils/preview_utils.ts +3 -0
- package/templates/assistkick-product-system/packages/shared/db/migrate.ts +82 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0000_outgoing_ultron.sql +277 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0015_magenta_jazinda.sql +1 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0016_giant_xorn.sql +1 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0017_sloppy_mentor.sql +6 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0018_vengeful_kabuki.sql +9 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0019_careful_sentinels.sql +8 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0020_clever_spot.sql +27 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0021_graceful_hex.sql +1 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0022_short_kingpin.sql +1 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0023_ambiguous_sharon_carter.sql +1 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/0024_fat_unus.sql +1 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0000_snapshot.json +972 -22
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0015_snapshot.json +1552 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0016_snapshot.json +1560 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0017_snapshot.json +1598 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0018_snapshot.json +1657 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0019_snapshot.json +1709 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0020_snapshot.json +1733 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0021_snapshot.json +1740 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0022_snapshot.json +1755 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0023_snapshot.json +1762 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/0024_snapshot.json +1769 -0
- package/templates/assistkick-product-system/packages/shared/db/migrations/meta/_journal.json +2 -100
- package/templates/assistkick-product-system/packages/shared/db/schema.ts +40 -1
- package/templates/assistkick-product-system/packages/shared/lib/claude-service.test.ts +236 -0
- package/templates/assistkick-product-system/packages/shared/lib/claude-service.ts +46 -5
- package/templates/assistkick-product-system/packages/shared/lib/git_workflow.ts +65 -39
- package/templates/assistkick-product-system/packages/shared/lib/programmable_node_executor.test.ts +173 -0
- package/templates/assistkick-product-system/packages/shared/lib/programmable_node_executor.ts +213 -0
- package/templates/assistkick-product-system/packages/shared/lib/validator.test.ts +70 -0
- package/templates/assistkick-product-system/packages/shared/lib/validator.ts +17 -1
- package/templates/assistkick-product-system/packages/shared/lib/workflow_engine.test.ts +803 -27
- package/templates/assistkick-product-system/packages/shared/lib/workflow_engine.ts +502 -68
- package/templates/assistkick-product-system/packages/shared/lib/workflow_orchestrator.ts +4 -4
- package/templates/assistkick-product-system/packages/shared/package.json +2 -1
- package/templates/assistkick-product-system/packages/shared/test_fixtures/hanging_stream.mjs +46 -0
- package/templates/assistkick-product-system/packages/shared/tools/add_node.test.ts +44 -0
- package/templates/assistkick-product-system/packages/shared/tools/add_node.ts +7 -0
- package/templates/assistkick-product-system/packages/shared/tools/remove_node.ts +2 -1
- package/templates/assistkick-product-system/packages/shared/tools/resolve_question.ts +2 -1
- package/templates/assistkick-product-system/packages/shared/tools/update_node.ts +2 -1
- package/templates/assistkick-product-system/tests/message_queue.test.ts +178 -0
- package/templates/assistkick-product-system/tests/message_queue_per_session.test.ts +143 -0
- package/templates/skills/assistkick-bootstrap/SKILL.md +26 -26
- package/templates/skills/assistkick-code-reviewer/SKILL.md +45 -46
- package/templates/skills/assistkick-db-explorer/SKILL.md +13 -13
- package/templates/skills/assistkick-debugger/SKILL.md +23 -23
- package/templates/skills/assistkick-developer/SKILL.md +59 -63
- package/templates/skills/assistkick-interview/SKILL.md +26 -26
- package/templates/skills/assistkick-video-composition-agent/SKILL.md +231 -0
- package/templates/skills/assistkick-video-script-writer/SKILL.md +136 -0
package/templates/assistkick-product-system/packages/backend/src/services/chat_cli_bridge.test.ts
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { describe, it, mock, beforeEach, afterEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { existsSync, unlinkSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { ChatCliBridge, type PermissionMode } from './chat_cli_bridge.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a mock ChildProcess with controllable stdout/stderr/stdin.
|
|
8
|
+
* Allows simulating CLI output by pushing data and firing close/error events.
|
|
9
|
+
*/
|
|
10
|
+
const createMockChildProcess = () => {
|
|
11
|
+
const stdoutListeners: Record<string, Function[]> = {};
|
|
12
|
+
const stderrListeners: Record<string, Function[]> = {};
|
|
13
|
+
const processListeners: Record<string, Function[]> = {};
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
stdin: {
|
|
17
|
+
write: mock.fn(),
|
|
18
|
+
end: mock.fn(),
|
|
19
|
+
},
|
|
20
|
+
stdout: {
|
|
21
|
+
on: mock.fn((event: string, cb: Function) => {
|
|
22
|
+
if (!stdoutListeners[event]) stdoutListeners[event] = [];
|
|
23
|
+
stdoutListeners[event].push(cb);
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
stderr: {
|
|
27
|
+
on: mock.fn((event: string, cb: Function) => {
|
|
28
|
+
if (!stderrListeners[event]) stderrListeners[event] = [];
|
|
29
|
+
stderrListeners[event].push(cb);
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
on: mock.fn((event: string, cb: Function) => {
|
|
33
|
+
if (!processListeners[event]) processListeners[event] = [];
|
|
34
|
+
processListeners[event].push(cb);
|
|
35
|
+
}),
|
|
36
|
+
kill: mock.fn(),
|
|
37
|
+
killed: false,
|
|
38
|
+
_emitStdout: (data: string) => {
|
|
39
|
+
for (const cb of stdoutListeners['data'] || []) cb(Buffer.from(data));
|
|
40
|
+
},
|
|
41
|
+
_emitStderr: (data: string) => {
|
|
42
|
+
for (const cb of stderrListeners['data'] || []) cb(Buffer.from(data));
|
|
43
|
+
},
|
|
44
|
+
_emitClose: (code: number | null) => {
|
|
45
|
+
for (const cb of processListeners['close'] || []) cb(code);
|
|
46
|
+
},
|
|
47
|
+
_emitError: (err: Error) => {
|
|
48
|
+
for (const cb of processListeners['error'] || []) cb(err);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Capture the args passed to spawn for assertions. */
|
|
54
|
+
let lastSpawnArgs: { cmd: string; args: string[]; options: Record<string, unknown> } | null = null;
|
|
55
|
+
let mockChild: ReturnType<typeof createMockChildProcess>;
|
|
56
|
+
|
|
57
|
+
describe('ChatCliBridge', () => {
|
|
58
|
+
let bridge: ChatCliBridge;
|
|
59
|
+
let logMock: ReturnType<typeof mock.fn>;
|
|
60
|
+
const WORKSPACES_DIR = '/data/workspaces';
|
|
61
|
+
const PROJECT_ID = 'proj_test123';
|
|
62
|
+
|
|
63
|
+
/** Track MCP config files created during tests for cleanup */
|
|
64
|
+
const createdConfigs: string[] = [];
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
logMock = mock.fn();
|
|
68
|
+
mockChild = createMockChildProcess();
|
|
69
|
+
lastSpawnArgs = null;
|
|
70
|
+
|
|
71
|
+
bridge = new ChatCliBridge({
|
|
72
|
+
workspacesDir: WORKSPACES_DIR,
|
|
73
|
+
log: logMock,
|
|
74
|
+
backendPort: 3000,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
for (const path of createdConfigs) {
|
|
80
|
+
try { unlinkSync(path); } catch { /* already cleaned */ }
|
|
81
|
+
}
|
|
82
|
+
createdConfigs.length = 0;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('getWorkspaceCwd', () => {
|
|
86
|
+
it('returns the correct workspace path for a project', () => {
|
|
87
|
+
const cwd = bridge.getWorkspaceCwd('proj_abc');
|
|
88
|
+
assert.equal(cwd, '/data/workspaces/proj_abc');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('uses the injected workspacesDir', () => {
|
|
92
|
+
const customBridge = new ChatCliBridge({
|
|
93
|
+
workspacesDir: '/custom/path',
|
|
94
|
+
log: logMock,
|
|
95
|
+
});
|
|
96
|
+
assert.equal(customBridge.getWorkspaceCwd('proj_x'), '/custom/path/proj_x');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('buildArgs', () => {
|
|
101
|
+
const baseOptions = {
|
|
102
|
+
projectId: PROJECT_ID,
|
|
103
|
+
message: 'Hello',
|
|
104
|
+
claudeSessionId: 'session-uuid-123',
|
|
105
|
+
isNewSession: true,
|
|
106
|
+
permissionMode: 'skip' as PermissionMode,
|
|
107
|
+
onEvent: mock.fn(),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
it('includes -p - for stdin prompt delivery', () => {
|
|
111
|
+
const { args } = bridge.buildArgs(baseOptions);
|
|
112
|
+
const pIdx = args.indexOf('-p');
|
|
113
|
+
assert.ok(pIdx !== -1);
|
|
114
|
+
assert.equal(args[pIdx + 1], '-');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('includes stream-json output format', () => {
|
|
118
|
+
const { args } = bridge.buildArgs(baseOptions);
|
|
119
|
+
const fmtIdx = args.indexOf('--output-format');
|
|
120
|
+
assert.ok(fmtIdx !== -1);
|
|
121
|
+
assert.equal(args[fmtIdx + 1], 'stream-json');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('includes --verbose flag', () => {
|
|
125
|
+
const { args } = bridge.buildArgs(baseOptions);
|
|
126
|
+
assert.ok(args.includes('--verbose'));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('includes --include-partial-messages flag', () => {
|
|
130
|
+
const { args } = bridge.buildArgs(baseOptions);
|
|
131
|
+
assert.ok(args.includes('--include-partial-messages'));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('includes --append-system-prompt with project context', () => {
|
|
135
|
+
const { args } = bridge.buildArgs(baseOptions);
|
|
136
|
+
const promptIdx = args.indexOf('--append-system-prompt');
|
|
137
|
+
assert.ok(promptIdx !== -1);
|
|
138
|
+
assert.ok(args[promptIdx + 1].startsWith(`We are working on project-id ${PROJECT_ID}`));
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('session mode', () => {
|
|
142
|
+
it('uses --session-id for new sessions', () => {
|
|
143
|
+
const { args } = bridge.buildArgs({ ...baseOptions, isNewSession: true });
|
|
144
|
+
assert.ok(args.includes('--session-id'));
|
|
145
|
+
assert.ok(!args.includes('--resume'));
|
|
146
|
+
assert.ok(args.includes('session-uuid-123'));
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('uses --resume for existing sessions', () => {
|
|
150
|
+
const { args } = bridge.buildArgs({ ...baseOptions, isNewSession: false });
|
|
151
|
+
assert.ok(args.includes('--resume'));
|
|
152
|
+
assert.ok(!args.includes('--session-id'));
|
|
153
|
+
assert.ok(args.includes('session-uuid-123'));
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('permission modes', () => {
|
|
158
|
+
it('uses --dangerously-skip-permissions for skip mode', () => {
|
|
159
|
+
const { args } = bridge.buildArgs({ ...baseOptions, permissionMode: 'skip' });
|
|
160
|
+
assert.ok(args.includes('--dangerously-skip-permissions'));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('uses --allowedTools for allowed_tools mode', () => {
|
|
164
|
+
const { args } = bridge.buildArgs({
|
|
165
|
+
...baseOptions,
|
|
166
|
+
permissionMode: 'allowed_tools',
|
|
167
|
+
allowedTools: ['Read', 'Glob', 'Grep'],
|
|
168
|
+
});
|
|
169
|
+
assert.ok(!args.includes('--dangerously-skip-permissions'));
|
|
170
|
+
const allowedIndices = args.reduce((acc: number[], arg, i) => {
|
|
171
|
+
if (arg === '--allowedTools') acc.push(i);
|
|
172
|
+
return acc;
|
|
173
|
+
}, []);
|
|
174
|
+
assert.equal(allowedIndices.length, 3);
|
|
175
|
+
assert.equal(args[allowedIndices[0] + 1], 'Read');
|
|
176
|
+
assert.equal(args[allowedIndices[1] + 1], 'Glob');
|
|
177
|
+
assert.equal(args[allowedIndices[2] + 1], 'Grep');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('uses --permission-prompt-tool and --mcp-config for prompt mode', () => {
|
|
181
|
+
const { args } = bridge.buildArgs({
|
|
182
|
+
...baseOptions,
|
|
183
|
+
permissionMode: 'prompt',
|
|
184
|
+
permissionPromptTool: 'mcp__permission__ask',
|
|
185
|
+
});
|
|
186
|
+
assert.ok(!args.includes('--dangerously-skip-permissions'));
|
|
187
|
+
|
|
188
|
+
// Should have --mcp-config
|
|
189
|
+
const mcpConfigIdx = args.indexOf('--mcp-config');
|
|
190
|
+
assert.ok(mcpConfigIdx !== -1);
|
|
191
|
+
const configPath = args[mcpConfigIdx + 1];
|
|
192
|
+
assert.ok(configPath.includes('mcp-perm-'));
|
|
193
|
+
createdConfigs.push(configPath);
|
|
194
|
+
|
|
195
|
+
// Should have --permission-prompt-tool
|
|
196
|
+
const promptToolIdx = args.indexOf('--permission-prompt-tool');
|
|
197
|
+
assert.ok(promptToolIdx !== -1);
|
|
198
|
+
assert.equal(args[promptToolIdx + 1], 'mcp__permission__ask');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('uses default tool name mcp__permission__ask when none specified for prompt mode', () => {
|
|
202
|
+
const { args } = bridge.buildArgs({
|
|
203
|
+
...baseOptions,
|
|
204
|
+
permissionMode: 'prompt',
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const promptToolIdx = args.indexOf('--permission-prompt-tool');
|
|
208
|
+
assert.ok(promptToolIdx !== -1);
|
|
209
|
+
assert.equal(args[promptToolIdx + 1], 'mcp__permission__ask');
|
|
210
|
+
|
|
211
|
+
// Clean up config
|
|
212
|
+
const mcpConfigIdx = args.indexOf('--mcp-config');
|
|
213
|
+
if (mcpConfigIdx !== -1) createdConfigs.push(args[mcpConfigIdx + 1]);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('falls through to no permission flag when allowed_tools has empty list', () => {
|
|
217
|
+
const { args } = bridge.buildArgs({
|
|
218
|
+
...baseOptions,
|
|
219
|
+
permissionMode: 'allowed_tools',
|
|
220
|
+
allowedTools: [],
|
|
221
|
+
});
|
|
222
|
+
assert.ok(!args.includes('--dangerously-skip-permissions'));
|
|
223
|
+
assert.ok(!args.includes('--allowedTools'));
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('systemPrompt return value', () => {
|
|
228
|
+
it('returns the composed system prompt for new sessions', () => {
|
|
229
|
+
const { systemPrompt } = bridge.buildArgs({ ...baseOptions, isNewSession: true });
|
|
230
|
+
assert.ok(systemPrompt !== null);
|
|
231
|
+
assert.ok(systemPrompt!.includes(`We are working on project-id ${PROJECT_ID}`));
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('returns null systemPrompt for resumed sessions', () => {
|
|
235
|
+
const { systemPrompt } = bridge.buildArgs({ ...baseOptions, isNewSession: false });
|
|
236
|
+
assert.equal(systemPrompt, null);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('includes continuation context in systemPrompt when provided', () => {
|
|
240
|
+
const { systemPrompt } = bridge.buildArgs({
|
|
241
|
+
...baseOptions,
|
|
242
|
+
isNewSession: true,
|
|
243
|
+
continuationContext: 'Previous conversation summary here',
|
|
244
|
+
});
|
|
245
|
+
assert.ok(systemPrompt !== null);
|
|
246
|
+
assert.ok(systemPrompt!.includes('Previous conversation summary here'));
|
|
247
|
+
assert.ok(systemPrompt!.includes(`We are working on project-id ${PROJECT_ID}`));
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('generateMcpConfig', () => {
|
|
253
|
+
it('creates a config file at the expected path', () => {
|
|
254
|
+
const configPath = bridge.generateMcpConfig('test-session-id', 'proj_123');
|
|
255
|
+
createdConfigs.push(configPath);
|
|
256
|
+
assert.ok(existsSync(configPath));
|
|
257
|
+
assert.ok(configPath.includes('mcp-perm-test-session'));
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('config file contains correct JSON structure', () => {
|
|
261
|
+
const configPath = bridge.generateMcpConfig('test-session-2', 'proj_456');
|
|
262
|
+
createdConfigs.push(configPath);
|
|
263
|
+
|
|
264
|
+
const content = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
265
|
+
assert.ok(content.mcpServers);
|
|
266
|
+
assert.ok(content.mcpServers.permission);
|
|
267
|
+
assert.equal(content.mcpServers.permission.command, 'npx');
|
|
268
|
+
assert.ok(Array.isArray(content.mcpServers.permission.args));
|
|
269
|
+
assert.equal(content.mcpServers.permission.env.CLAUDE_SESSION_ID, 'test-session-2');
|
|
270
|
+
assert.equal(content.mcpServers.permission.env.PROJECT_ID, 'proj_456');
|
|
271
|
+
assert.equal(content.mcpServers.permission.env.BACKEND_URL, 'http://localhost:3000');
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe('cleanupMcpConfig', () => {
|
|
276
|
+
it('removes the config file', () => {
|
|
277
|
+
const configPath = bridge.generateMcpConfig('cleanup-session', 'proj_789');
|
|
278
|
+
assert.ok(existsSync(configPath));
|
|
279
|
+
bridge.cleanupMcpConfig('cleanup-session');
|
|
280
|
+
assert.ok(!existsSync(configPath));
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('does not throw when config does not exist', () => {
|
|
284
|
+
assert.doesNotThrow(() => bridge.cleanupMcpConfig('nonexistent'));
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe('buildEnv', () => {
|
|
289
|
+
it('returns an environment object with PATH augmented', () => {
|
|
290
|
+
const env = bridge.buildEnv();
|
|
291
|
+
assert.ok(typeof env.PATH === 'string');
|
|
292
|
+
assert.ok(env.PATH.includes('/usr/local/bin'));
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('preserves existing environment variables', () => {
|
|
296
|
+
const originalHome = process.env.HOME;
|
|
297
|
+
const env = bridge.buildEnv();
|
|
298
|
+
assert.equal(env.HOME, originalHome);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe('kill', () => {
|
|
303
|
+
it('returns false when no active process for session', () => {
|
|
304
|
+
assert.equal(bridge.kill('nonexistent'), false);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe('isActive', () => {
|
|
309
|
+
it('returns false for unknown session', () => {
|
|
310
|
+
assert.equal(bridge.isActive('nonexistent'), false);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe('getActiveCount', () => {
|
|
315
|
+
it('returns 0 when no processes are active', () => {
|
|
316
|
+
assert.equal(bridge.getActiveCount(), 0);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe('killAll', () => {
|
|
321
|
+
it('does not throw when no processes are active', () => {
|
|
322
|
+
assert.doesNotThrow(() => bridge.killAll());
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe('processLine (via spawn event parsing)', () => {
|
|
327
|
+
it('parses valid JSON events and calls onEvent', () => {
|
|
328
|
+
const events: Record<string, unknown>[] = [];
|
|
329
|
+
const onEvent = (event: Record<string, unknown>) => { events.push(event); };
|
|
330
|
+
const processLine = (bridge as any).processLine.bind(bridge);
|
|
331
|
+
|
|
332
|
+
const assistantEvent = JSON.stringify({
|
|
333
|
+
type: 'assistant',
|
|
334
|
+
message: { content: [{ type: 'text', text: 'Hello world' }] },
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
processLine(assistantEvent, onEvent, mock.fn());
|
|
338
|
+
assert.equal(events.length, 1);
|
|
339
|
+
assert.equal(events[0].type, 'assistant');
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('captures session_id from result events', () => {
|
|
343
|
+
let capturedSessionId: string | null = null;
|
|
344
|
+
const onSessionId = (sid: string) => { capturedSessionId = sid; };
|
|
345
|
+
const processLine = (bridge as any).processLine.bind(bridge);
|
|
346
|
+
|
|
347
|
+
const resultEvent = JSON.stringify({
|
|
348
|
+
type: 'result',
|
|
349
|
+
session_id: 'captured-session-uuid',
|
|
350
|
+
cost_usd: 0.05,
|
|
351
|
+
duration_ms: 3000,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
processLine(resultEvent, mock.fn(), onSessionId);
|
|
355
|
+
assert.equal(capturedSessionId, 'captured-session-uuid');
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('does not capture session_id from non-result events', () => {
|
|
359
|
+
let capturedSessionId: string | null = null;
|
|
360
|
+
const onSessionId = (sid: string) => { capturedSessionId = sid; };
|
|
361
|
+
const processLine = (bridge as any).processLine.bind(bridge);
|
|
362
|
+
|
|
363
|
+
const assistantEvent = JSON.stringify({
|
|
364
|
+
type: 'assistant',
|
|
365
|
+
session_id: 'should-not-capture',
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
processLine(assistantEvent, mock.fn(), onSessionId);
|
|
369
|
+
assert.equal(capturedSessionId, null);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('skips invalid JSON lines silently', () => {
|
|
373
|
+
const events: Record<string, unknown>[] = [];
|
|
374
|
+
const processLine = (bridge as any).processLine.bind(bridge);
|
|
375
|
+
|
|
376
|
+
processLine('not valid json', (e: any) => events.push(e), mock.fn());
|
|
377
|
+
processLine('', (e: any) => events.push(e), mock.fn());
|
|
378
|
+
processLine('{incomplete', (e: any) => events.push(e), mock.fn());
|
|
379
|
+
|
|
380
|
+
assert.equal(events.length, 0);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('parses tool_use events correctly', () => {
|
|
384
|
+
const events: Record<string, unknown>[] = [];
|
|
385
|
+
const processLine = (bridge as any).processLine.bind(bridge);
|
|
386
|
+
|
|
387
|
+
const toolEvent = JSON.stringify({
|
|
388
|
+
type: 'assistant',
|
|
389
|
+
message: {
|
|
390
|
+
content: [
|
|
391
|
+
{ type: 'tool_use', name: 'Read', input: { file_path: '/test/file.ts' } },
|
|
392
|
+
],
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
processLine(toolEvent, (e: any) => events.push(e), mock.fn());
|
|
397
|
+
|
|
398
|
+
assert.equal(events.length, 1);
|
|
399
|
+
const msg = events[0].message as any;
|
|
400
|
+
assert.equal(msg.content[0].type, 'tool_use');
|
|
401
|
+
assert.equal(msg.content[0].name, 'Read');
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('parses result event with cost and duration', () => {
|
|
405
|
+
const events: Record<string, unknown>[] = [];
|
|
406
|
+
const processLine = (bridge as any).processLine.bind(bridge);
|
|
407
|
+
|
|
408
|
+
const resultEvent = JSON.stringify({
|
|
409
|
+
type: 'result',
|
|
410
|
+
session_id: 'test-uuid',
|
|
411
|
+
cost_usd: 0.0123,
|
|
412
|
+
duration_ms: 5432,
|
|
413
|
+
num_turns: 3,
|
|
414
|
+
stop_reason: 'end_turn',
|
|
415
|
+
result: 'Final response text',
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
processLine(resultEvent, (e: any) => events.push(e), mock.fn());
|
|
419
|
+
|
|
420
|
+
assert.equal(events.length, 1);
|
|
421
|
+
assert.equal(events[0].type, 'result');
|
|
422
|
+
assert.equal(events[0].cost_usd, 0.0123);
|
|
423
|
+
assert.equal(events[0].duration_ms, 5432);
|
|
424
|
+
assert.equal(events[0].result, 'Final response text');
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
});
|