bonecode 1.2.3 → 1.4.1

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.
Files changed (85) hide show
  1. package/README.md +62 -0
  2. package/compat/opencode_adapter.ts +69 -8
  3. package/dist/compat/opencode_adapter.js +63 -7
  4. package/dist/compat/opencode_adapter.js.map +1 -1
  5. package/dist/src/db_adapter.js +30 -0
  6. package/dist/src/db_adapter.js.map +1 -1
  7. package/dist/src/engine/agent/prompt/compaction.txt +9 -0
  8. package/dist/src/engine/agent/prompt/explore.txt +18 -0
  9. package/dist/src/engine/agent/prompt/scout.txt +36 -0
  10. package/dist/src/engine/agent/prompt/summary.txt +11 -0
  11. package/dist/src/engine/agent/prompt/title.txt +44 -0
  12. package/dist/src/engine/session/build_mode.d.ts +83 -0
  13. package/dist/src/engine/session/build_mode.js +789 -0
  14. package/dist/src/engine/session/build_mode.js.map +1 -0
  15. package/dist/src/engine/session/build_mode_helpers.d.ts +6 -0
  16. package/dist/src/engine/session/build_mode_helpers.js +61 -0
  17. package/dist/src/engine/session/build_mode_helpers.js.map +1 -0
  18. package/dist/src/engine/session/prompt/anthropic.txt +105 -0
  19. package/dist/src/engine/session/prompt/beast.txt +147 -0
  20. package/dist/src/engine/session/prompt/bonescript.txt +402 -0
  21. package/dist/src/engine/session/prompt/build-switch.txt +5 -0
  22. package/dist/src/engine/session/prompt/codex.txt +79 -0
  23. package/dist/src/engine/session/prompt/copilot-gpt-5.txt +143 -0
  24. package/dist/src/engine/session/prompt/default.txt +105 -0
  25. package/dist/src/engine/session/prompt/gemini.txt +155 -0
  26. package/dist/src/engine/session/prompt/gpt.txt +107 -0
  27. package/dist/src/engine/session/prompt/kimi.txt +95 -0
  28. package/dist/src/engine/session/prompt/max-steps.txt +16 -0
  29. package/dist/src/engine/session/prompt/plan-reminder-anthropic.txt +67 -0
  30. package/dist/src/engine/session/prompt/plan.txt +26 -0
  31. package/dist/src/engine/session/prompt/trinity.txt +97 -0
  32. package/dist/src/engine/session/prompt.js +92 -4
  33. package/dist/src/engine/session/prompt.js.map +1 -1
  34. package/dist/src/engine/skill/prompt/customize-opencode.md +377 -0
  35. package/dist/src/engine/tool/apply_patch.txt +33 -0
  36. package/dist/src/engine/tool/edit.txt +10 -0
  37. package/dist/src/engine/tool/glob.txt +6 -0
  38. package/dist/src/engine/tool/grep.txt +8 -0
  39. package/dist/src/engine/tool/lsp.txt +24 -0
  40. package/dist/src/engine/tool/plan-enter.txt +14 -0
  41. package/dist/src/engine/tool/plan-exit.txt +13 -0
  42. package/dist/src/engine/tool/question.txt +10 -0
  43. package/dist/src/engine/tool/read.txt +14 -0
  44. package/dist/src/engine/tool/repo_clone.txt +5 -0
  45. package/dist/src/engine/tool/repo_overview.txt +4 -0
  46. package/dist/src/engine/tool/shell/shell.txt +77 -0
  47. package/dist/src/engine/tool/skill.txt +5 -0
  48. package/dist/src/engine/tool/task.txt +58 -0
  49. package/dist/src/engine/tool/task_status.txt +13 -0
  50. package/dist/src/engine/tool/todowrite.txt +167 -0
  51. package/dist/src/engine/tool/tool/apply_patch.txt +33 -0
  52. package/dist/src/engine/tool/tool/edit.txt +10 -0
  53. package/dist/src/engine/tool/tool/glob.txt +6 -0
  54. package/dist/src/engine/tool/tool/grep.txt +8 -0
  55. package/dist/src/engine/tool/tool/lsp.txt +24 -0
  56. package/dist/src/engine/tool/tool/plan-enter.txt +14 -0
  57. package/dist/src/engine/tool/tool/plan-exit.txt +13 -0
  58. package/dist/src/engine/tool/tool/question.txt +10 -0
  59. package/dist/src/engine/tool/tool/read.txt +14 -0
  60. package/dist/src/engine/tool/tool/repo_clone.txt +5 -0
  61. package/dist/src/engine/tool/tool/repo_overview.txt +4 -0
  62. package/dist/src/engine/tool/tool/shell/shell.txt +77 -0
  63. package/dist/src/engine/tool/tool/skill.txt +5 -0
  64. package/dist/src/engine/tool/tool/task.txt +58 -0
  65. package/dist/src/engine/tool/tool/task_status.txt +13 -0
  66. package/dist/src/engine/tool/tool/todowrite.txt +167 -0
  67. package/dist/src/engine/tool/tool/webfetch.txt +13 -0
  68. package/dist/src/engine/tool/tool/websearch.txt +14 -0
  69. package/dist/src/engine/tool/tool/write.txt +8 -0
  70. package/dist/src/engine/tool/webfetch.txt +13 -0
  71. package/dist/src/engine/tool/websearch.txt +14 -0
  72. package/dist/src/engine/tool/write.txt +8 -0
  73. package/dist/src/tui.js +146 -9
  74. package/dist/src/tui.js.map +1 -1
  75. package/package.json +2 -2
  76. package/scripts/copy_prompts.js +58 -0
  77. package/scripts/test_bonescript_primer.js +111 -0
  78. package/scripts/test_build_fallback.js +221 -0
  79. package/scripts/test_build_mode.js +301 -0
  80. package/src/db_adapter.ts +29 -0
  81. package/src/engine/session/build_mode.ts +895 -0
  82. package/src/engine/session/build_mode_helpers.ts +72 -0
  83. package/src/engine/session/prompt/bonescript.txt +402 -0
  84. package/src/engine/session/prompt.ts +105 -4
  85. package/src/tui.ts +147 -9
@@ -0,0 +1,167 @@
1
+ Use this tool to create and manage a structured task list for your current coding session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
2
+ It also helps the user understand the progress of the task and overall progress of their requests.
3
+
4
+ ## When to Use This Tool
5
+ Use this tool proactively in these scenarios:
6
+
7
+ 1. Complex multistep tasks - When a task requires 3 or more distinct steps or actions
8
+ 2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
9
+ 3. User explicitly requests todo list - When the user directly asks you to use the todo list
10
+ 4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
11
+ 5. After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo list based on new information.
12
+ 6. After completing a task - Mark it complete and add any new follow-up tasks
13
+ 7. When you start working on a new task, mark the todo as in_progress. Ideally you should only have one todo as in_progress at a time. Complete existing tasks before starting new ones.
14
+
15
+ ## When NOT to Use This Tool
16
+
17
+ Skip using this tool when:
18
+ 1. There is only a single, straightforward task
19
+ 2. The task is trivial and tracking it provides no organizational benefit
20
+ 3. The task can be completed in less than 3 trivial steps
21
+ 4. The task is purely conversational or informational
22
+
23
+ NOTE that you should not use this tool if there is only one trivial task to do. In this case you are better off just doing the task directly.
24
+
25
+ ## Examples of When to Use the Todo List
26
+
27
+ <example>
28
+ User: I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when you're done!
29
+ Assistant: I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this implementation.
30
+ *Creates todo list with the following items:*
31
+ 1. Create dark mode toggle component in Settings page
32
+ 2. Add dark mode state management (context/store)
33
+ 3. Implement CSS-in-JS styles for dark theme
34
+ 4. Update existing components to support theme switching
35
+ 5. Run tests and build process, addressing any failures or errors that occur
36
+ *Begins working on the first task*
37
+
38
+ <reasoning>
39
+ The assistant used the todo list because:
40
+ 1. Adding dark mode is a multi-step feature requiring UI, state management, and styling changes
41
+ 2. The user explicitly requested tests and build be run afterward
42
+ 3. The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as the final task
43
+ </reasoning>
44
+ </example>
45
+
46
+ <example>
47
+ User: Help me rename the function getCwd to getCurrentWorkingDirectory across my project
48
+ Assistant: Let me first search through your codebase to find all occurrences of 'getCwd'.
49
+ *Uses grep or search tools to locate all instances of getCwd in the codebase*
50
+ Assistant: I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these changes.
51
+ *Creates todo list with specific items for each file that needs updating*
52
+
53
+ <reasoning>
54
+ The assistant used the todo list because:
55
+ 1. First, the assistant searched to understand the scope of the task
56
+ 2. Upon finding multiple occurrences across different files, it determined this was a complex task with multiple steps
57
+ 3. The todo list helps ensure every instance is tracked and updated systematically
58
+ 4. This approach prevents missing any occurrences and maintains code consistency
59
+ </reasoning>
60
+ </example>
61
+
62
+
63
+ <example>
64
+ User: I need to implement these features for my e-commerce site: user registration, product catalog, shopping cart, and checkout flow.
65
+ Assistant: I'll help implement these features. First, let's add all the features to the todo list.
66
+ *Creates a todo list breaking down each feature into specific tasks based on the project architecture*
67
+ Assistant: Let's start with user registration. This will involve creating database models, API endpoints, and frontend forms that integrate with your existing authentication system.
68
+
69
+ <reasoning>
70
+ The assistant used the todo list because:
71
+ 1. The user provided multiple complex features to implement in a comma separated list
72
+ 2. The todo list helps organize these large features into manageable tasks
73
+ 3. This approach allows for tracking progress across the entire implementation
74
+ </reasoning>
75
+ </example>
76
+
77
+ <example>
78
+ User: Can you help optimize my React application? It's rendering slowly and has performance issues.</user>
79
+ Assistant: I'll help optimize your React application. First, let me examine your codebase to identify potential performance bottlenecks.
80
+ *Reviews component structure, render patterns, state management, and data fetching*
81
+ Assistant: After analyzing your codebase, I've identified several performance issues. Let me create a todo list to track our optimization efforts.
82
+ *Creates todo list with items like: 1) Implement memoization for expensive calculations in ProductList, 2) Add virtualization for long lists in Dashboard, 3) Optimize image loading in Gallery component, 4) Fix state update loops in ShoppingCart, 5) Review bundle size and implement code splitting*
83
+ Let's start by implementing memoization for the expensive calculations in your ProductList component.</assistant>
84
+
85
+ <reasoning>
86
+ The assistant used the todo list because:
87
+ 1. First, the assistant examined the codebase to identify specific performance issues
88
+ 2. Based on this analysis, it identified multiple optimization opportunities
89
+ 3. Performance optimization is a non-trivial task requiring multiple steps
90
+ 4. The todo list helps methodically track improvements across different components
91
+ 5. This systematic approach ensures all performance bottlenecks are addressed
92
+ </reasoning>
93
+ </example>
94
+
95
+ ## Examples of When NOT to Use the Todo List
96
+
97
+ <example>
98
+ User: How do I print 'Hello World' in Python?
99
+ Assistant: In Python, you can print "Hello World" with this simple code:
100
+
101
+ python
102
+ print("Hello World")
103
+
104
+ This will output the text "Hello World" to the console when executed.</assistant>
105
+
106
+ <reasoning>
107
+ The assistant did not use the todo list because this is a single, trivial task that can be completed in one step. There's no need to track multiple tasks or steps for such a straightforward request.
108
+ </reasoning>
109
+ </example>
110
+
111
+ <example>
112
+ User: What does the git status command do?
113
+ Assistant: The git status command shows the current state of your working directory and staging area. It displays which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a fundamental command for understanding the current state of your repository before making commits.
114
+
115
+ <reasoning>
116
+ The assistant did not use the todo list because this is an informational request with no actual coding task to complete. The user is simply asking for an explanation, not for the assistant to perform multiple steps or tasks.
117
+ </reasoning>
118
+ </example>
119
+
120
+ <example>
121
+ User: Can you add a comment to the calculateTotal function to explain what it does?
122
+ Assistant: Sure, let me add a comment to the calculateTotal function to explain what it does.
123
+ * Uses the Edit tool to add a comment to the calculateTotal function *
124
+
125
+ <reasoning>
126
+ The assistant did not use the todo list because this is a single, straightforward task confined to one location in the code. Adding a comment doesn't require tracking multiple steps or systematic organization.
127
+ </reasoning>
128
+ </example>
129
+
130
+ <example>
131
+ User: Run npm install for me and tell me what happens.
132
+ Assistant: I'll run the npm install command for you.
133
+
134
+ *Executes: npm install*
135
+
136
+ The command completed successfully. Here's the output:
137
+ [Output of npm install command]
138
+
139
+ All dependencies have been installed according to your package.json file.
140
+
141
+ <reasoning>
142
+ The assistant did not use the todo list because this is a single command execution with immediate results. There are no multiple steps to track or organize, making the todo list unnecessary for this straightforward task.
143
+ </reasoning>
144
+ </example>
145
+
146
+ ## Task States and Management
147
+
148
+ 1. **Task States**: Use these states to track progress:
149
+ - pending: Task not yet started
150
+ - in_progress: Currently working on (limit to ONE task at a time)
151
+ - completed: Task finished successfully
152
+ - cancelled: Task no longer needed
153
+
154
+ 2. **Task Management**:
155
+ - Update task status in real-time as you work
156
+ - Mark tasks complete IMMEDIATELY after finishing (don't batch completions)
157
+ - Only have ONE task in_progress at any time
158
+ - Complete current tasks before starting new ones
159
+ - Cancel tasks that become irrelevant
160
+
161
+ 3. **Task Breakdown**:
162
+ - Create specific, actionable items
163
+ - Break complex tasks into smaller, manageable steps
164
+ - Use clear, descriptive task names
165
+
166
+ When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
167
+
@@ -0,0 +1,13 @@
1
+ - Fetches content from a specified URL
2
+ - Takes a URL and optional format as input
3
+ - Fetches the URL content, converts to requested format (markdown by default)
4
+ - Returns the content in the specified format
5
+ - Use this tool when you need to retrieve and analyze web content
6
+
7
+ Usage notes:
8
+ - IMPORTANT: if another tool is present that offers better web fetching capabilities, is more targeted to the task, or has fewer restrictions, prefer using that tool instead of this one.
9
+ - The URL must be a fully-formed valid URL
10
+ - HTTP URLs will be automatically upgraded to HTTPS
11
+ - Format options: "markdown" (default), "text", or "html"
12
+ - This tool is read-only and does not modify any files
13
+ - Results may be summarized if the content is very large
@@ -0,0 +1,14 @@
1
+ - Search the web using the session's web search provider - performs real-time web searches and can scrape content from specific URLs
2
+ - Provides up-to-date information for current events and recent data
3
+ - Supports configurable result counts and returns the content from the most relevant websites
4
+ - Use this tool for accessing information beyond knowledge cutoff
5
+ - Searches are performed automatically within a single API call
6
+
7
+ Usage notes:
8
+ - Supports live crawling modes when available: 'fallback' (backup if cached unavailable) or 'preferred' (prioritize live crawling)
9
+ - Search types when available: 'auto' (balanced), 'fast' (quick results), 'deep' (comprehensive search)
10
+ - Configurable context length for optimal LLM integration
11
+ - Domain filtering and advanced search options available
12
+
13
+ The current year is {{year}}. You MUST use this year when searching for recent information or current events
14
+ - Example: If the current year is 2026 and the user asks for "latest AI news", search for "AI news 2026", NOT "AI news 2025"
@@ -0,0 +1,8 @@
1
+ Writes a file to the local filesystem.
2
+
3
+ Usage:
4
+ - This tool will overwrite the existing file if there is one at the provided path.
5
+ - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
6
+ - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
7
+ - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
8
+ - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
@@ -0,0 +1,13 @@
1
+ - Fetches content from a specified URL
2
+ - Takes a URL and optional format as input
3
+ - Fetches the URL content, converts to requested format (markdown by default)
4
+ - Returns the content in the specified format
5
+ - Use this tool when you need to retrieve and analyze web content
6
+
7
+ Usage notes:
8
+ - IMPORTANT: if another tool is present that offers better web fetching capabilities, is more targeted to the task, or has fewer restrictions, prefer using that tool instead of this one.
9
+ - The URL must be a fully-formed valid URL
10
+ - HTTP URLs will be automatically upgraded to HTTPS
11
+ - Format options: "markdown" (default), "text", or "html"
12
+ - This tool is read-only and does not modify any files
13
+ - Results may be summarized if the content is very large
@@ -0,0 +1,14 @@
1
+ - Search the web using the session's web search provider - performs real-time web searches and can scrape content from specific URLs
2
+ - Provides up-to-date information for current events and recent data
3
+ - Supports configurable result counts and returns the content from the most relevant websites
4
+ - Use this tool for accessing information beyond knowledge cutoff
5
+ - Searches are performed automatically within a single API call
6
+
7
+ Usage notes:
8
+ - Supports live crawling modes when available: 'fallback' (backup if cached unavailable) or 'preferred' (prioritize live crawling)
9
+ - Search types when available: 'auto' (balanced), 'fast' (quick results), 'deep' (comprehensive search)
10
+ - Configurable context length for optimal LLM integration
11
+ - Domain filtering and advanced search options available
12
+
13
+ The current year is {{year}}. You MUST use this year when searching for recent information or current events
14
+ - Example: If the current year is 2026 and the user asks for "latest AI news", search for "AI news 2026", NOT "AI news 2025"
@@ -0,0 +1,8 @@
1
+ Writes a file to the local filesystem.
2
+
3
+ Usage:
4
+ - This tool will overwrite the existing file if there is one at the provided path.
5
+ - If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
6
+ - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
7
+ - NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
8
+ - Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.
package/dist/src/tui.js CHANGED
@@ -96,6 +96,7 @@ function getVersion() {
96
96
  }
97
97
  const COMMANDS = [
98
98
  { name: "/new", description: "Start a new session" },
99
+ { name: "/build", description: "Start autonomous build mode", args: "<project description>" },
99
100
  { name: "/session", description: "Show current session ID" },
100
101
  { name: "/sessions", description: "List recent sessions" },
101
102
  { name: "/model", description: "Switch model", args: "<provider/model>" },
@@ -673,6 +674,91 @@ async function streamPrompt(opts) {
673
674
  nl(` ${BLUE}⊕ Context compacted${R}`);
674
675
  continue;
675
676
  }
677
+ // Build mode events — autonomous orchestration progress
678
+ if (ev.type === "session.warning") {
679
+ flushTextLine();
680
+ nl(` ${YELLOW}⚠ ${ev.message || ""}${R}`);
681
+ continue;
682
+ }
683
+ if (ev.type === "build.stage") {
684
+ flushTextLine();
685
+ const stage = (ev.stage || "?").toUpperCase();
686
+ nl(` ${CYAN}${BOLD}▶ Build stage: ${stage}${R}`);
687
+ continue;
688
+ }
689
+ if (ev.type === "build.questions") {
690
+ flushTextLine();
691
+ nl(` ${CYAN}${BOLD}? Clarifying questions:${R}`);
692
+ for (const q of ev.questions || []) {
693
+ nl(` ${WHITE}- ${q}${R}`);
694
+ }
695
+ nl(` ${GRAY}Reply with your answers to continue.${R}`);
696
+ continue;
697
+ }
698
+ if (ev.type === "build.design") {
699
+ flushTextLine();
700
+ const d = ev.design || {};
701
+ nl(` ${CYAN}${BOLD}✓ Design locked in${R}`);
702
+ if (d.goal)
703
+ nl(` ${GRAY}goal: ${d.goal}${R}`);
704
+ if (Array.isArray(d.requirements))
705
+ nl(` ${GRAY}${d.requirements.length} requirement(s), ${d.artifacts?.length || 0} artifact(s)${R}`);
706
+ continue;
707
+ }
708
+ if (ev.type === "build.plan") {
709
+ flushTextLine();
710
+ const todos = ev.todos || [];
711
+ nl(` ${CYAN}${BOLD}✓ Plan: ${todos.length} task(s)${R}`);
712
+ for (let i = 0; i < Math.min(todos.length, 10); i++) {
713
+ const t = todos[i];
714
+ nl(` ${GRAY}${(i + 1).toString().padStart(2, " ")}. ${t.title}${R}`);
715
+ }
716
+ if (todos.length > 10)
717
+ nl(` ${GRAY}... ${todos.length - 10} more${R}`);
718
+ continue;
719
+ }
720
+ if (ev.type === "build.todo.start") {
721
+ flushTextLine();
722
+ const t = ev.todo || {};
723
+ nl(` ${WHITE}● ${t.title || ""}${R}`);
724
+ continue;
725
+ }
726
+ if (ev.type === "build.todo.done") {
727
+ flushTextLine();
728
+ const t = ev.todo || {};
729
+ nl(` ${GREEN}✓ ${t.title || ""}${R}${t.evidence ? ` ${GRAY}(${t.evidence})${R}` : ""}`);
730
+ continue;
731
+ }
732
+ if (ev.type === "build.todo.retry") {
733
+ flushTextLine();
734
+ const t = ev.todo || {};
735
+ nl(` ${YELLOW}⟳ Retry ${ev.attempt || ""}: ${t.title || ""}${R}`);
736
+ continue;
737
+ }
738
+ if (ev.type === "build.todo.failed") {
739
+ flushTextLine();
740
+ const t = ev.todo || {};
741
+ nl(` ${RED}✗ ${t.title || ""}${R} ${GRAY}${ev.reason || ""}${R}`);
742
+ continue;
743
+ }
744
+ if (ev.type === "build.verify.item") {
745
+ flushTextLine();
746
+ const icon = ev.satisfied ? `${GREEN}✓${R}` : `${RED}✗${R}`;
747
+ nl(` ${icon} ${WHITE}${ev.requirement || ""}${R}`);
748
+ if (ev.evidence)
749
+ nl(` ${GRAY}${ev.evidence}${R}`);
750
+ continue;
751
+ }
752
+ if (ev.type === "build.replan") {
753
+ flushTextLine();
754
+ nl(` ${YELLOW}↻ Re-planning: ${ev.added || 0} new task(s) to address gaps${R}`);
755
+ continue;
756
+ }
757
+ if (ev.type === "build.done") {
758
+ flushTextLine();
759
+ nl(` ${GREEN}${BOLD}✓✓ Build complete — all requirements satisfied${R}`);
760
+ continue;
761
+ }
676
762
  }
677
763
  catch {
678
764
  // Ignore malformed events
@@ -808,12 +894,14 @@ async function runTUI(opts) {
808
894
  });
809
895
  const promptStr = () => `${CYAN}${BOLD}>${R} `;
810
896
  // ─── Ctrl+C handling ──────────────────────────────────────────────────────
811
- // When streaming: abort the request AND notify server
812
- // When idle: clear menu/input or hint to use /exit
897
+ // Windows quirk: rl.on("SIGINT") only fires when readline is actively
898
+ // reading. We pause readline during streaming, which makes Ctrl+C dead.
899
+ // Use process.on("SIGINT") as the always-on handler so streaming aborts work.
900
+ let interruptCount = 0;
813
901
  const onSigint = async () => {
814
902
  if (streaming && abort) {
815
903
  abort.abort();
816
- // Also tell the server to cancel the agent loop
904
+ // Tell the server to cancel the agent loop too
817
905
  try {
818
906
  await fetch(`http://localhost:${port}/v2/session/${sessionId}/cancel`, {
819
907
  method: "POST",
@@ -821,22 +909,41 @@ async function runTUI(opts) {
821
909
  });
822
910
  }
823
911
  catch { /* server may not have the endpoint, abort is enough */ }
912
+ out(`\n${YELLOW}interrupted${R}\n`);
824
913
  // Don't reprompt here — the streamPrompt finally block will handle UI
825
914
  return;
826
915
  }
827
- // Idle: clear menu if visible, else hint
916
+ interruptCount++;
917
+ // Idle: clear menu/input first, then on second Ctrl+C, exit
828
918
  if (menu.visible) {
829
919
  clearMenu(menu.rowsRendered);
830
920
  menu.visible = false;
831
921
  menu.rowsRendered = 0;
832
922
  menu.selected = 0;
923
+ interruptCount = 0;
924
+ out(`\n${promptStr()}`);
925
+ return;
833
926
  }
834
- out(`\n${GRAY}(Ctrl+D or /exit to quit)${R}\n`);
835
- rl.setPrompt(promptStr());
836
- rl.prompt();
927
+ // If user typed something, clear it
928
+ const lineLen = (rl.line || "").length;
929
+ if (lineLen > 0) {
930
+ rl.line = "";
931
+ rl.cursor = 0;
932
+ out(`\r${ESC}[2K${promptStr()}`);
933
+ interruptCount = 0;
934
+ return;
935
+ }
936
+ // Empty prompt + Ctrl+C: first time hint, second time exit
937
+ if (interruptCount >= 2) {
938
+ out(`\n${GRAY}Goodbye.${R}\n`);
939
+ process.exit(0);
940
+ }
941
+ out(`\n${GRAY}(Press Ctrl+C again or Ctrl+D to exit)${R}\n${promptStr()}`);
837
942
  };
838
- // Detach readline's default SIGINT (which closes the line buffer)
839
- // and route it to our handler.
943
+ // Register on BOTH process and readline so it works during streaming AND
944
+ // during input. Process-level catches signals while rl is paused; readline
945
+ // catches them while the user is typing.
946
+ process.on("SIGINT", onSigint);
840
947
  rl.on("SIGINT", onSigint);
841
948
  rl.on("close", () => {
842
949
  if (streaming && abort)
@@ -982,6 +1089,36 @@ async function runTUI(opts) {
982
1089
  nl(`${RED}✗ ${e.message}${R}`);
983
1090
  }
984
1091
  break;
1092
+ case "build": {
1093
+ // /build <description> — start autonomous build mode for this prompt
1094
+ const description = args.join(" ").trim();
1095
+ if (!description) {
1096
+ nl(`${YELLOW}Usage:${R} /build <project description>`);
1097
+ nl(`${GRAY}Example: /build a 2D market simulation with 1000 shops over 100 years${R}`);
1098
+ break;
1099
+ }
1100
+ // Send the prompt prefixed with /build so the server enters build mode
1101
+ rl.pause();
1102
+ renderUserMessage(`/build ${description}`);
1103
+ out(` ${GRAY}entering build mode...${R}`);
1104
+ streaming = true;
1105
+ abort = new AbortController();
1106
+ const result = await streamPrompt({
1107
+ port, token, sessionId: sessionId, model, provider,
1108
+ message: `/build ${description}`,
1109
+ worktree, abortSignal: abort.signal,
1110
+ });
1111
+ streaming = false;
1112
+ abort = null;
1113
+ if (!result.text && !result.error)
1114
+ clearLine();
1115
+ renderTurnEnd(model, result.elapsedMs, result.interrupted);
1116
+ if (result.error && !result.interrupted)
1117
+ nl(` ${RED}✗ ${result.error}${R}`);
1118
+ nl();
1119
+ rl.resume();
1120
+ break;
1121
+ }
985
1122
  case "session":
986
1123
  nl(`${GRAY}${sessionId}${R}`);
987
1124
  break;