circuschief 0.6.0 → 0.8.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.
Files changed (187) hide show
  1. package/package.json +1 -1
  2. package/packages/server/src/agents/adapters/CodexAdapter.js +5 -4
  3. package/packages/server/src/api/canvas.js +22 -57
  4. package/packages/server/src/api/index.js +2 -0
  5. package/packages/server/src/api/kanban.js +4 -2
  6. package/packages/server/src/api/projects-helpers.js +20 -3
  7. package/packages/server/src/api/projects-session-helpers.js +35 -4
  8. package/packages/server/src/api/projects.js +11 -0
  9. package/packages/server/src/api/providers.js +11 -1
  10. package/packages/server/src/api/sessions-commands.js +35 -17
  11. package/packages/server/src/api/sessions-draft.js +1 -0
  12. package/packages/server/src/api/sessions-lifecycle.js +10 -10
  13. package/packages/server/src/api/sessions-patch.js +4 -0
  14. package/packages/server/src/api/sessions.js +6 -5
  15. package/packages/server/src/api/settings.js +52 -4
  16. package/packages/server/src/database.js +0 -2
  17. package/packages/server/src/db/ConversationRepository.js +16 -3
  18. package/packages/server/src/db/DatabaseManager.js +5 -1
  19. package/packages/server/src/db/ProjectDefaultsRepository.js +50 -40
  20. package/packages/server/src/db/ProviderRepository.js +87 -32
  21. package/packages/server/src/db/SessionRepository.js +13 -8
  22. package/packages/server/src/db/SettingsRepository.js +44 -16
  23. package/packages/server/src/db/conversation-helpers.js +1 -0
  24. package/packages/server/src/db/index.js +0 -3
  25. package/packages/server/src/db/migrations/index.js +36 -200
  26. package/packages/server/src/db/seedBaselineData.js +137 -0
  27. package/packages/server/src/db/session-helpers.js +9 -3
  28. package/packages/server/src/middleware/sessionLookup.js +81 -8
  29. package/packages/server/src/schema.sql +157 -132
  30. package/packages/server/src/scripts/backupDatabase.js +21 -0
  31. package/packages/server/src/scripts/dbUtils.js +81 -0
  32. package/packages/server/src/scripts/inspectDatabaseSchema.js +81 -0
  33. package/packages/server/src/scripts/validateDatabaseBaseline.js +212 -0
  34. package/packages/server/src/services/agentCallLogger.js +1 -1
  35. package/packages/server/src/services/codexSpawnHelper.js +9 -0
  36. package/packages/server/src/services/commandButtonPrompts.js +48 -0
  37. package/packages/server/src/services/commandRunner.js +7 -1
  38. package/packages/server/src/services/draftSessionService.js +2 -0
  39. package/packages/server/src/services/e2eSpawnCapture.js +147 -0
  40. package/packages/server/src/services/gitCommitAttribution.js +120 -0
  41. package/packages/server/src/services/gitService.js +11 -2
  42. package/packages/server/src/services/gitSessionSetup.js +11 -1
  43. package/packages/server/src/services/kanbanTriggers.js +6 -3
  44. package/packages/server/src/services/nodeSpawnHelper.js +9 -0
  45. package/packages/server/src/services/prUrlService.js +3 -3
  46. package/packages/server/src/services/queryParamBuilder.js +90 -0
  47. package/packages/server/src/services/sessionDuplicator.js +1 -5
  48. package/packages/server/src/services/sessionExecution.js +56 -106
  49. package/packages/server/src/services/sessionPrompts.js +16 -47
  50. package/packages/server/src/services/sessionProvider.js +16 -8
  51. package/packages/server/src/services/streamEventCallbacks.js +72 -40
  52. package/packages/server/src/services/streamEventHandler.js +13 -2
  53. package/packages/server/src/services/streamUsageHandler.js +6 -0
  54. package/packages/server/src/services/summaryClaudeClient.js +37 -12
  55. package/packages/server/src/services/summaryModelClient.js +154 -0
  56. package/packages/server/src/services/summaryModelResolver.js +148 -0
  57. package/packages/server/src/services/summaryService.js +11 -7
  58. package/packages/server/src/services/summaryStaleCheck.js +23 -4
  59. package/packages/server/src/services/templateTriggerService.js +3 -1
  60. package/packages/server/src/services/usageTracker.js +5 -1
  61. package/packages/server/src/services/visibleFinalErrorMessage.js +123 -0
  62. package/packages/shared/src/constants.js +4 -2
  63. package/packages/shared/src/contracts/commandButtons.js +16 -2
  64. package/packages/shared/src/contracts/projects.js +4 -2
  65. package/packages/shared/src/contracts/providers.js +60 -0
  66. package/packages/shared/src/contracts/sessions.js +2 -1
  67. package/packages/shared/src/contracts/templates.js +2 -2
  68. package/packages/shared/src/types.js +1 -9
  69. package/packages/shared/src/utils.js +11 -19
  70. package/packages/web/dist/assets/ActiveSessionsView-B0XHqLmv.js +1 -0
  71. package/packages/web/dist/assets/{AgentLogsView-Cdw4nmvd.js → AgentLogsView-DmsjUMlB.js} +2 -2
  72. package/packages/web/dist/assets/ApiClient-C3ztI9s9.js +1 -0
  73. package/packages/web/dist/assets/ArchiveConfirmModal-BlCyn5Vt.js +1 -0
  74. package/packages/web/dist/assets/ArchiveConfirmModal-DeoCVGXt.css +1 -0
  75. package/packages/web/dist/assets/{CommandButtonDetailView-DnFhJY5A.js → CommandButtonDetailView-CdSCPp78.js} +1 -1
  76. package/packages/web/dist/assets/EffortLevelSelector-hc2MNKg6.js +1 -0
  77. package/packages/web/dist/assets/{GeneralSettingsView-CQkmdczf.js → GeneralSettingsView-D1nI8_zk.js} +1 -1
  78. package/packages/web/dist/assets/InputWithButton-CAkttyqx.js +1 -0
  79. package/packages/web/dist/assets/{InputWithButton-cYdrEmTs.css → InputWithButton-D9HMvfR5.css} +1 -1
  80. package/packages/web/dist/assets/{InterpolationHelp-PfYR3KJo.js → InterpolationHelp-BO1j9Z3_.js} +1 -1
  81. package/packages/web/dist/assets/MarkdownEditor-ucRAP_UM.js +2 -0
  82. package/packages/web/dist/assets/{ModelSelector-BZOT1Jc6.css → ModelSelector-BSxKUSus.css} +1 -1
  83. package/packages/web/dist/assets/ModelSelector-CwTz8ZWO.js +1 -0
  84. package/packages/web/dist/assets/NewSessionView-BDPb-1qr.css +1 -0
  85. package/packages/web/dist/assets/NewSessionView-BsDrp8mj.js +3 -0
  86. package/packages/web/dist/assets/ProjectEditView-CwTOeSun.js +1 -0
  87. package/packages/web/dist/assets/ProjectEditView-J15mcsWz.css +1 -0
  88. package/packages/web/dist/assets/{ProjectListView-CuYMmd3O.js → ProjectListView-DcNyuINs.js} +1 -1
  89. package/packages/web/dist/assets/{ProjectNewView-CNaA4Maf.js → ProjectNewView-B5YV62hv.js} +1 -1
  90. package/packages/web/dist/assets/ProvidersView-bZemq_Rv.css +1 -0
  91. package/packages/web/dist/assets/ProvidersView-nY9GnDdO.js +1 -0
  92. package/packages/web/dist/assets/QuickResponseSettings-B352c75l.css +1 -0
  93. package/packages/web/dist/assets/QuickResponseSettings-BQwQXuL7.js +1 -0
  94. package/packages/web/dist/assets/{QuickResponsesPanel-DIBQFj0W.css → QuickResponsesPanel-BlFDvnZ2.css} +1 -1
  95. package/packages/web/dist/assets/{QuickResponsesPanel-BqMYSHb0.js → QuickResponsesPanel-BzSYcCSP.js} +1 -1
  96. package/packages/web/dist/assets/{ResizableTextarea-wYF3K2RO.js → ResizableTextarea-B3YIdIXv.js} +1 -1
  97. package/packages/web/dist/assets/{SessionCard-bLaQEWWX.js → SessionCard-CjE1tXiT.js} +1 -1
  98. package/packages/web/dist/assets/SessionDetailView-3cPZrbS3.js +36 -0
  99. package/packages/web/dist/assets/SessionDetailView-CZRZMrfM.css +1 -0
  100. package/packages/web/dist/assets/SessionFormOptions-B6AxyREh.js +1 -0
  101. package/packages/web/dist/assets/SessionFormOptions-BpUALRKn.css +1 -0
  102. package/packages/web/dist/assets/SessionListView-B5_6gW49.css +1 -0
  103. package/packages/web/dist/assets/SessionListView-CLXBfLcq.js +1 -0
  104. package/packages/web/dist/assets/{SessionLogStream-DTnDAF95.js → SessionLogStream-LlZ3z_Xj.js} +1 -1
  105. package/packages/web/dist/assets/{SettingsView-DNLUSsHV.js → SettingsView-CTGiGvR2.js} +1 -1
  106. package/packages/web/dist/assets/{SlashCommandWizard-CRGFaO8t.js → SlashCommandWizard-Cy04d7-o.js} +1 -1
  107. package/packages/web/dist/assets/{SlashCommandWizard-Dn7sNaBd.css → SlashCommandWizard-DJzw3LP5.css} +1 -1
  108. package/packages/web/dist/assets/SummarySettingsView-BR2ZjEa3.js +1 -0
  109. package/packages/web/dist/assets/SummarySettingsView-l2bxHmZZ.css +1 -0
  110. package/packages/web/dist/assets/TemplateDetailView-DH6Oswsp.js +1 -0
  111. package/packages/web/dist/assets/{commandButtons-Bbjf3fCt.js → commandButtons-BfqR-fqq.js} +1 -1
  112. package/packages/web/dist/assets/index-1zziPL6l.js +1 -0
  113. package/packages/web/dist/assets/index-7kzHPxSF.js +1 -0
  114. package/packages/web/dist/assets/index-B0N_obMc.js +1 -0
  115. package/packages/web/dist/assets/index-BNk_gdfI.js +1 -0
  116. package/packages/web/dist/assets/{index-gmCCsCQ1.css → index-BY174HVJ.css} +1 -1
  117. package/packages/web/dist/assets/index-CSqaAH-0.js +1 -0
  118. package/packages/web/dist/assets/index-C_q4WlK8.js +1 -0
  119. package/packages/web/dist/assets/index-D1wpU4y0.js +7 -0
  120. package/packages/web/dist/assets/index-D5zCA8sD.js +1 -0
  121. package/packages/web/dist/assets/index-DGR8ELWY.js +1 -0
  122. package/packages/web/dist/assets/index-DHga8pXo.js +1 -0
  123. package/packages/web/dist/assets/index-DSby02Wl.js +1 -0
  124. package/packages/web/dist/assets/{index-Cf6vdW-B.js → index-DgkC10TW.js} +3 -3
  125. package/packages/web/dist/assets/index-DqjXJTVI.js +1 -0
  126. package/packages/web/dist/assets/{index-Bs7Qf5D6.js → index-DtfUt785.js} +2 -2
  127. package/packages/web/dist/assets/index-_4S2uLDI.js +1 -0
  128. package/packages/web/dist/assets/{index-BQL_L4gL.js → index-fK8FIZgP.js} +15 -14
  129. package/packages/web/dist/assets/index-gmiZeFXN.js +1 -0
  130. package/packages/web/dist/assets/index-irD539ZM.js +3 -0
  131. package/packages/web/dist/assets/index-yq-E1Y00.js +1 -0
  132. package/packages/web/dist/assets/{projects-CPt3AB7U.js → projects-DXYQNJIi.js} +1 -1
  133. package/packages/web/dist/assets/{providers-ChfeMvUq.js → providers-1bnH-exJ.js} +1 -1
  134. package/packages/web/dist/assets/sessions-6zGUlFrt.js +1 -0
  135. package/packages/web/dist/assets/settings-MbfRir0d.js +1 -0
  136. package/packages/web/dist/index.html +2 -2
  137. package/packages/server/src/api/sessions-notes.js +0 -51
  138. package/packages/server/src/db/SessionNoteRepository.js +0 -60
  139. package/packages/server/src/db/migrations/canvasItemsMigrations.js +0 -109
  140. package/packages/server/src/db/migrations/conversationsMigrations.js +0 -183
  141. package/packages/server/src/db/migrations/kanbanMigrations.js +0 -99
  142. package/packages/server/src/db/migrations/miscMigrations.js +0 -369
  143. package/packages/server/src/db/migrations/projectsMigrations.js +0 -99
  144. package/packages/server/src/db/migrations/sessionsMigrations.js +0 -282
  145. package/packages/web/dist/assets/ActiveSessionsView-UCbQrF1b.js +0 -1
  146. package/packages/web/dist/assets/ApiClient-CWbXWDUY.js +0 -1
  147. package/packages/web/dist/assets/ArchiveConfirmModal-BQ-4gI0R.css +0 -1
  148. package/packages/web/dist/assets/ArchiveConfirmModal-J48eh3zw.js +0 -1
  149. package/packages/web/dist/assets/EffortLevelSelector-bXbPo4Zw.js +0 -1
  150. package/packages/web/dist/assets/InputWithButton-XyM3k6lN.js +0 -1
  151. package/packages/web/dist/assets/MarkdownEditor-P8F5kO-o.js +0 -2
  152. package/packages/web/dist/assets/ModelSelector-CowKfGMP.js +0 -1
  153. package/packages/web/dist/assets/NewSessionView-D_Hi7M9g.css +0 -1
  154. package/packages/web/dist/assets/NewSessionView-DkjFLvHU.js +0 -3
  155. package/packages/web/dist/assets/ProjectEditView-CpeKj-_w.css +0 -1
  156. package/packages/web/dist/assets/ProjectEditView-embVT7NC.js +0 -1
  157. package/packages/web/dist/assets/ProvidersView-C7rydtOd.js +0 -1
  158. package/packages/web/dist/assets/ProvidersView-DE82G_5W.css +0 -1
  159. package/packages/web/dist/assets/QuickResponseSettings-B8188A1D.css +0 -1
  160. package/packages/web/dist/assets/QuickResponseSettings-BTQEKhwJ.js +0 -1
  161. package/packages/web/dist/assets/SessionDetailView-Cv-xMzXp.css +0 -1
  162. package/packages/web/dist/assets/SessionDetailView-CvQOUsW2.js +0 -36
  163. package/packages/web/dist/assets/SessionFormOptions-3pzbgI2Q.js +0 -1
  164. package/packages/web/dist/assets/SessionFormOptions-DhhIkjIS.css +0 -1
  165. package/packages/web/dist/assets/SessionListView-Dranfb72.js +0 -1
  166. package/packages/web/dist/assets/SessionListView-fHlQyecX.css +0 -1
  167. package/packages/web/dist/assets/SummarySettingsView-C7G_suHp.js +0 -1
  168. package/packages/web/dist/assets/SummarySettingsView-DcsmSVJI.css +0 -1
  169. package/packages/web/dist/assets/TemplateDetailView-B78_DLMR.js +0 -1
  170. package/packages/web/dist/assets/index--V7c-VZf.js +0 -1
  171. package/packages/web/dist/assets/index-8Q04yd7H.js +0 -1
  172. package/packages/web/dist/assets/index-B47XRBDH.js +0 -1
  173. package/packages/web/dist/assets/index-BXbgZrhS.js +0 -1
  174. package/packages/web/dist/assets/index-CGhDVPen.js +0 -1
  175. package/packages/web/dist/assets/index-CKcRO1A6.js +0 -1
  176. package/packages/web/dist/assets/index-CTq-SLIW.js +0 -1
  177. package/packages/web/dist/assets/index-CYyos3iC.js +0 -1
  178. package/packages/web/dist/assets/index-CsCREAxF.js +0 -1
  179. package/packages/web/dist/assets/index-DJTTk_8T.js +0 -3
  180. package/packages/web/dist/assets/index-DPqUJ5JK.js +0 -1
  181. package/packages/web/dist/assets/index-EwAe1dKg.js +0 -1
  182. package/packages/web/dist/assets/index-JBA8axyA.js +0 -1
  183. package/packages/web/dist/assets/index-JkVHFtK5.js +0 -7
  184. package/packages/web/dist/assets/index-gMPUwT55.js +0 -1
  185. package/packages/web/dist/assets/index-wadc_0zT.js +0 -1
  186. package/packages/web/dist/assets/sessions-CwPsJOb1.js +0 -1
  187. package/packages/web/dist/assets/settings-BOj6wq6t.js +0 -1
@@ -5,6 +5,13 @@ const TOKEN_WEIGHTS_KEY = 'token_cost_weights';
5
5
  const SUMMARY_SETTINGS_KEY = 'summary_settings';
6
6
  const GENERAL_SETTINGS_KEY = 'general_settings';
7
7
 
8
+ const DEFAULT_SUMMARY_SETTINGS = Object.freeze({
9
+ disableSessionSummaries: false,
10
+ sessionTitlePrompt: '',
11
+ summaryModel: '',
12
+ summaryProviderId: null,
13
+ });
14
+
8
15
  /**
9
16
  * Settings repository for managing application-wide settings
10
17
  */
@@ -114,22 +121,13 @@ export class SettingsRepository {
114
121
  getSummarySettings() {
115
122
  const value = this.get(SUMMARY_SETTINGS_KEY);
116
123
  if (!value) {
117
- return {
118
- disableSessionSummaries: false,
119
- sessionTitlePrompt: '',
120
- };
124
+ return { ...DEFAULT_SUMMARY_SETTINGS };
121
125
  }
122
126
  try {
123
127
  const parsed = JSON.parse(value);
124
- return {
125
- disableSessionSummaries: parsed.disableSessionSummaries || false,
126
- sessionTitlePrompt: parsed.sessionTitlePrompt || '',
127
- };
128
+ return normalizeStoredSummarySettings(parsed);
128
129
  } catch {
129
- return {
130
- disableSessionSummaries: false,
131
- sessionTitlePrompt: '',
132
- };
130
+ return { ...DEFAULT_SUMMARY_SETTINGS };
133
131
  }
134
132
  }
135
133
 
@@ -138,11 +136,22 @@ export class SettingsRepository {
138
136
  * @param {Object} settings - Summary settings
139
137
  * @param {boolean} settings.disableSessionSummaries - Disable session summaries
140
138
  * @param {string} settings.sessionTitlePrompt - Custom session title prompt
139
+ * @param {string} [settings.summaryModel] - Summary model id; empty string means auto
140
+ * @param {string|null} [settings.summaryProviderId] - Provider id owning summaryModel
141
141
  */
142
142
  setSummarySettings(settings) {
143
+ const summaryModel = String(settings.summaryModel || '');
144
+ const summaryProviderId = typeof settings.summaryProviderId === 'string'
145
+ ? settings.summaryProviderId
146
+ : null;
147
+ if (summaryModel && !summaryProviderId) {
148
+ throw new Error('summaryProviderId is required when summaryModel is set');
149
+ }
143
150
  const validated = {
144
151
  disableSessionSummaries: Boolean(settings.disableSessionSummaries),
145
152
  sessionTitlePrompt: String(settings.sessionTitlePrompt || ''),
153
+ summaryModel,
154
+ summaryProviderId: summaryModel ? summaryProviderId : null,
146
155
  };
147
156
  this.set(SUMMARY_SETTINGS_KEY, JSON.stringify(validated));
148
157
  return validated;
@@ -154,10 +163,7 @@ export class SettingsRepository {
154
163
  */
155
164
  resetSummarySettings() {
156
165
  this.delete(SUMMARY_SETTINGS_KEY);
157
- return {
158
- disableSessionSummaries: false,
159
- sessionTitlePrompt: '',
160
- };
166
+ return { ...DEFAULT_SUMMARY_SETTINGS };
161
167
  }
162
168
 
163
169
  // General Settings
@@ -209,3 +215,25 @@ export class SettingsRepository {
209
215
  };
210
216
  }
211
217
  }
218
+
219
+ function normalizeStoredSummarySettings(parsed) {
220
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
221
+ return { ...DEFAULT_SUMMARY_SETTINGS };
222
+ }
223
+
224
+ const summaryModel = typeof parsed.summaryModel === 'string' ? parsed.summaryModel : '';
225
+ const summaryProviderId = typeof parsed.summaryProviderId === 'string' && parsed.summaryProviderId
226
+ ? parsed.summaryProviderId
227
+ : null;
228
+
229
+ if (summaryModel && !summaryProviderId) {
230
+ return { ...DEFAULT_SUMMARY_SETTINGS };
231
+ }
232
+
233
+ return {
234
+ disableSessionSummaries: Boolean(parsed.disableSessionSummaries),
235
+ sessionTitlePrompt: typeof parsed.sessionTitlePrompt === 'string' ? parsed.sessionTitlePrompt : '',
236
+ summaryModel,
237
+ summaryProviderId: summaryModel ? summaryProviderId : null,
238
+ };
239
+ }
@@ -22,6 +22,7 @@ export function mapConversationRow(row) {
22
22
  // Token usage fields
23
23
  inputTokens: row.input_tokens || 0,
24
24
  outputTokens: row.output_tokens || 0,
25
+ thinkingTokens: row.thinking_tokens || 0,
25
26
  cacheReadInputTokens: row.cache_read_input_tokens || 0,
26
27
  cacheCreationInputTokens: row.cache_creation_input_tokens || 0,
27
28
  webSearchRequests: row.web_search_requests || 0,
@@ -12,7 +12,6 @@ export { SessionTemplateRepository } from './SessionTemplateRepository.js';
12
12
  export { MessageRepository } from './MessageRepository.js';
13
13
  export { ConversationRepository } from './ConversationRepository.js';
14
14
  export { CanvasItemRepository } from './CanvasItemRepository.js';
15
- export { SessionNoteRepository } from './SessionNoteRepository.js';
16
15
  export { TodoRepository } from './TodoRepository.js';
17
16
  export { WorkLogRepository } from './WorkLogRepository.js';
18
17
  export { SessionSummaryRepository } from './SessionSummaryRepository.js';
@@ -35,7 +34,6 @@ import { ProjectDefaultsRepository } from './ProjectDefaultsRepository.js';
35
34
  import { MessageRepository } from './MessageRepository.js';
36
35
  import { ConversationRepository } from './ConversationRepository.js';
37
36
  import { CanvasItemRepository } from './CanvasItemRepository.js';
38
- import { SessionNoteRepository } from './SessionNoteRepository.js';
39
37
  import { TodoRepository } from './TodoRepository.js';
40
38
  import { WorkLogRepository } from './WorkLogRepository.js';
41
39
  import { SessionSummaryRepository } from './SessionSummaryRepository.js';
@@ -56,7 +54,6 @@ export const projectDefaults = new ProjectDefaultsRepository();
56
54
  export const messages = new MessageRepository();
57
55
  export const conversations = new ConversationRepository();
58
56
  export const canvasItems = new CanvasItemRepository();
59
- export const sessionNotes = new SessionNoteRepository();
60
57
  export const todos = new TodoRepository();
61
58
  export const workLogs = new WorkLogRepository();
62
59
  export const sessionSummaries = new SessionSummaryRepository();
@@ -1,208 +1,44 @@
1
1
  /**
2
- * Central registry of all database migrations in execution order.
2
+ * Repair sessions whose parent link was lost during schema consolidation.
3
3
  *
4
- * Each migration is idempotent (checks before acting), so the exact ordering
5
- * only matters where there are hard dependencies (e.g. a table must exist
6
- * before a column references it via FK).
7
- *
8
- * The ordering below mirrors the original #runMigrations() top-to-bottom flow
9
- * as closely as possible.
4
+ * Child sessions inherit their root session's worktree. When parent_session_id
5
+ * is missing, the final UUID segment of git_worktree can identify the owning
6
+ * root session. Only repair rows where that UUID belongs to another session in
7
+ * the same project.
10
8
  */
11
- import { sessionsMigrations } from './sessionsMigrations.js';
12
- import { projectsMigrations } from './projectsMigrations.js';
13
- import { conversationsMigrations } from './conversationsMigrations.js';
14
- import { canvasItemsMigrations } from './canvasItemsMigrations.js';
15
- import { miscMigrations } from './miscMigrations.js';
16
- import { kanbanMigrations } from './kanbanMigrations.js';
17
-
18
- /**
19
- * Build a lookup map from a migrations array keyed by migration name.
20
- * @param {Array<{name: string, up: Function}>} migrations
21
- * @returns {Map<string, {name: string, up: Function}>}
22
- */
23
- function toLookup(migrations) {
24
- const map = new Map();
25
- for (const m of migrations) {
26
- map.set(m.name, m);
27
- }
28
- return map;
29
- }
30
-
31
- const s = toLookup(sessionsMigrations);
32
- const p = toLookup(projectsMigrations);
33
- const c = toLookup(conversationsMigrations);
34
- const ci = toLookup(canvasItemsMigrations);
35
- const m = toLookup(miscMigrations);
36
- const k = toLookup(kanbanMigrations);
9
+ export const repairMissingSessionParentsFromWorktree = {
10
+ name: 'repair-missing-session-parents-from-worktree',
11
+ up(db) {
12
+ db.prepare(`
13
+ UPDATE sessions
14
+ SET parent_session_id = (
15
+ SELECT parent.id
16
+ FROM sessions AS parent
17
+ WHERE parent.id = substr(sessions.git_worktree, length(sessions.git_worktree) - 35, 36)
18
+ AND parent.project_id = sessions.project_id
19
+ AND parent.id <> sessions.id
20
+ )
21
+ WHERE parent_session_id IS NULL
22
+ AND git_worktree IS NOT NULL
23
+ AND EXISTS (
24
+ SELECT 1
25
+ FROM sessions AS parent
26
+ WHERE parent.id = substr(sessions.git_worktree, length(sessions.git_worktree) - 35, 36)
27
+ AND parent.project_id = sessions.project_id
28
+ AND parent.id <> sessions.id
29
+ )
30
+ `).run();
31
+ },
32
+ };
37
33
 
38
34
  /**
39
- * Flat, ordered list of every migration, matching the original execution order
40
- * from DatabaseManager.#runMigrations().
35
+ * Post-baseline database migrations.
36
+ *
37
+ * Pre-release migration history was consolidated into schema.sql. Future
38
+ * shipped schema changes should be added here as explicit migrations.
41
39
  *
42
40
  * @type {Array<{name: string, up: (db: import('better-sqlite3').Database) => void}>}
43
41
  */
44
- // Validate that all migrations are properly defined
45
- function validateMigrations(migrationsArray) {
46
- for (const migration of migrationsArray) {
47
- if (!migration || typeof migration.up !== 'function') {
48
- const name = migration?.name || 'unknown';
49
- throw new Error(`Migration "${name}" is undefined or missing an up() function`);
50
- }
51
- }
52
- return migrationsArray;
53
- }
54
-
55
- export const allMigrations = validateMigrations([
56
- // --- Sessions initial columns ---
57
- s.get('sessions-add-cost_usd'),
58
- s.get('sessions-add-claude_session_id'),
59
- s.get('sessions-add-model'),
60
- s.get('sessions-add-provider_id-early'),
61
- s.get('sessions-add-effort_level'),
62
-
63
- // --- Projects columns ---
64
- p.get('projects-add-system_prompt'),
65
- p.get('projects-add-on_session_created'),
66
- p.get('projects-add-on_session_deleted'),
67
- p.get('projects-add-repo_url'),
68
- p.get('projects-add-worktree_path'),
69
- p.get('projects-drop-summary-columns'),
70
-
71
- // --- Sessions scheduling columns ---
72
- s.get('sessions-add-scheduled_at'),
73
- s.get('sessions-add-reschedule_delay_minutes'),
74
- s.get('sessions-add-auto_reschedule_enabled'),
75
- s.get('sessions-add-reschedule_on_token_limit'),
76
- s.get('sessions-add-reschedule_on_service_error'),
77
- s.get('sessions-add-max_reschedule_count'),
78
- s.get('sessions-add-max_total_tokens'),
79
- s.get('sessions-add-reschedule_count'),
80
- s.get('sessions-add-reschedule_at_token_count'),
81
-
82
- // --- Sessions status constraint migration (table recreation) ---
83
- s.get('sessions-migrate-status-constraint'),
84
-
85
- // --- Session summaries PR columns ---
86
- c.get('session_summaries-add-pr_merged'),
87
- c.get('session_summaries-add-pr_state'),
88
- c.get('session_summaries-add-has_merge_conflicts'),
89
- c.get('session_summaries-add-ci_status'),
90
- c.get('session_summaries-add-ci_failures'),
91
- c.get('session_summaries-add-last_summarized_message_id'),
92
-
93
- // --- Sessions template chaining ---
94
- s.get('sessions-add-next_template_id'),
95
- s.get('sessions-add-parent_session_id'),
96
- s.get('sessions-template-chaining-indexes'),
97
-
98
- // --- Message attachments ---
99
- c.get('message_attachments-add-file_path'),
100
-
101
- // --- Conversation messages: conversation_id ---
102
- c.get('conversation_messages-add-conversation_id'),
103
-
104
- // --- Migrate existing sessions to conversations ---
105
- c.get('conversations-migrate-existing-sessions'),
106
-
107
- // --- Canvas items ---
108
- ci.get('canvas_items-migrate-type-constraint'),
109
- ci.get('canvas_items-add-deleted_at'),
110
- ci.get('canvas_items-drop-label'),
111
- ci.get('canvas_items-add-updated_at'),
112
-
113
- // --- Conversations: claude_session_id + token usage ---
114
- c.get('conversations-add-claude_session_id'),
115
- c.get('conversations-add-input_tokens'),
116
- c.get('conversations-add-output_tokens'),
117
- c.get('conversations-add-cache_read_input_tokens'),
118
- c.get('conversations-add-cache_creation_input_tokens'),
119
- c.get('conversations-add-web_search_requests'),
120
- c.get('conversations-add-context_window'),
121
- c.get('conversations-add-model'),
122
-
123
- // --- Sessions token usage ---
124
- s.get('sessions-add-input_tokens'),
125
- s.get('sessions-add-output_tokens'),
126
- s.get('sessions-add-cache_read_input_tokens'),
127
- s.get('sessions-add-cache_creation_input_tokens'),
128
- s.get('sessions-add-web_search_requests'),
129
- s.get('sessions-add-context_window'),
130
-
131
- // --- Sessions archived / starred / manually_named ---
132
- s.get('sessions-add-archived'),
133
- s.get('sessions-add-starred'),
134
- s.get('sessions-add-manually_named'),
135
-
136
- // --- Project session defaults table ---
137
- p.get('project_session_defaults-create-table'),
138
-
139
- // --- Command buttons ---
140
- m.get('command_buttons-add-show_on_list'),
141
-
142
- // --- Session todos ---
143
- c.get('session_todos-add-conversation_id'),
144
-
145
- // --- Conversation branching ---
146
- c.get('conversations-add-parent_conversation_id'),
147
- c.get('conversations-add-branch_from_message_id'),
148
-
149
- // --- Sessions pending prompt / slash commands / pending model / auto send ---
150
- s.get('sessions-add-pending_prompt'),
151
- s.get('sessions-add-slash_commands'),
152
- s.get('sessions-add-pending_model'),
153
- s.get('sessions-add-auto_send_pending_prompt'),
154
-
155
- // --- Session templates ---
156
- m.get('session_templates-add-model'),
157
- m.get('session_templates-add-mode'),
158
- m.get('session_templates-add-effort_level'),
159
-
160
- // --- Conversation messages model ---
161
- c.get('conversation_messages-add-model'),
162
-
163
- // --- App settings table ---
164
- m.get('app_settings-create-table'),
165
-
166
- // --- Legacy model_providers cleanup ---
167
- m.get('model_providers-cleanup-legacy'),
168
-
169
- // --- Providers + provider_models tables + seed ---
170
- m.get('providers-create-tables'),
171
- m.get('providers-add-kind'),
172
- m.get('providers-seed-built-in'),
173
- m.get('providers-seed-built-in-openai'),
174
-
175
- // --- Sessions provider_id (from providers FK) ---
176
- s.get('sessions-add-provider_id-from-providers'),
177
-
178
- // --- Project session defaults provider_id / effort_level ---
179
- p.get('project_session_defaults-add-provider_id'),
180
- p.get('project_session_defaults-add-effort_level'),
181
-
182
- // --- Update built-in models ---
183
- m.get('providers-update-built-in-models'),
184
-
185
- // --- Sessions agent_type ---
186
- s.get('sessions-add-agent_type'),
187
-
188
- // --- Agent call logs table ---
189
- m.get('agent_call_logs-create-table'),
190
-
191
- // --- Kanban feature ---
192
- k.get('projects-add-kanban_enabled'),
193
- k.get('kanban-create-tables'),
194
- k.get('sessions-add-target_lane_id'),
195
- k.get('sessions-add-lane_trigger_depth'),
196
- k.get('session_templates-add-target_lane_id'),
197
- k.get('kanban_lanes-add-on_enter_prompt'),
198
- k.get('kanban_lanes-add-agent-settings'),
199
-
200
- // --- Seed default global quick responses ---
201
- m.get('quick_responses-seed-defaults'),
202
-
203
- // --- Seed default global session templates ---
204
- m.get('session_templates-seed-defaults'),
205
-
206
- // --- Update built-in Opus model to 4.7 ---
207
- m.get('providers-update-built-in-opus-4-7'),
208
- ]);
42
+ export const allMigrations = [
43
+ repairMissingSessionParentsFromWorktree,
44
+ ];
@@ -0,0 +1,137 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { OPENAI_MODELS } from '../../../shared/src/index.js';
3
+
4
+ export const BUILT_IN_ANTHROPIC_PROVIDER = {
5
+ id: 'anthropic-default',
6
+ name: 'Anthropic (Official)',
7
+ kind: 'anthropic',
8
+ };
9
+
10
+ export const BUILT_IN_OPENAI_PROVIDER = {
11
+ id: 'openai-default',
12
+ name: 'OpenAI (Official)',
13
+ kind: 'openai',
14
+ };
15
+
16
+ export const BUILT_IN_ANTHROPIC_MODELS = [
17
+ { id: 'anthropic-haiku', providerId: BUILT_IN_ANTHROPIC_PROVIDER.id, modelId: 'claude-haiku-4-5-20251001', displayName: 'Haiku 4.5', description: 'Fast & lightweight', tier: 'haiku' },
18
+ { id: 'anthropic-sonnet', providerId: BUILT_IN_ANTHROPIC_PROVIDER.id, modelId: 'claude-sonnet-4-6', displayName: 'Sonnet 4.6', description: 'Balanced', tier: 'sonnet' },
19
+ { id: 'anthropic-opus', providerId: BUILT_IN_ANTHROPIC_PROVIDER.id, modelId: 'claude-opus-4-6', displayName: 'Opus 4.6', description: 'Previous generation', tier: 'opus' },
20
+ { id: 'anthropic-opus-4-7', providerId: BUILT_IN_ANTHROPIC_PROVIDER.id, modelId: 'claude-opus-4-7', displayName: 'Opus 4.7', description: 'Most capable (default)', tier: 'opus' },
21
+ ];
22
+
23
+ export const BUILT_IN_OPENAI_MODELS = OPENAI_MODELS.map((model) => ({
24
+ id: model.seedId,
25
+ providerId: BUILT_IN_OPENAI_PROVIDER.id,
26
+ modelId: model.id,
27
+ displayName: model.name,
28
+ description: model.description,
29
+ tier: 'custom',
30
+ }));
31
+
32
+ export const DEFAULT_QUICK_RESPONSES = [
33
+ { label: 'Put a plan on the canvas', content: 'Put a plan on the canvas to get this done', autoSubmit: false, sortOrder: 0 },
34
+ { label: 'Yes', content: 'Yes', autoSubmit: true, sortOrder: 1 },
35
+ { label: 'Review the plan', content: `Review the plan on the canvas. Are there any issues that you can find? Is test coverage specified explicitly enough? Does the current code match the assumptions in the plan?\n\nList the issues that you find and then update the plan on the canvas to address any issues that you find. Don't talk about issues with the original plan in the plan itself. Just tell me what the issues are, and update the plan so that the plan doesn't have the issues.`, autoSubmit: true, sortOrder: 2 },
36
+ { label: 'Implement the plan on the canvas', content: 'Implement the plan on the canvas', autoSubmit: true, sortOrder: 3 },
37
+ { label: 'Create / Update PR', content: `Ensure all relevant changes are committed and pushed. Then look at the session's summary and create a draft PR if no PR already exists.`, autoSubmit: true, sortOrder: 4 },
38
+ { label: 'Review PR', content: 'Look at the PR related to the root session. Review the PR. Are there any issues? Are best practices adhered to? Does the PR accomplish the goal? Are all changes covered by tests?', autoSubmit: true, sortOrder: 5 },
39
+ { label: 'Add tests', content: 'Inspect the changes on our branch. For each change, ensure we have tests that assert the change is working in the expected way. Implement the tests.', autoSubmit: true, sortOrder: 6 },
40
+ { label: 'Merge in main', content: 'Merge in the latest main branch', autoSubmit: true, sortOrder: 7 },
41
+ { label: 'Add tests to the plan', content: 'Call out specific test cases in the plan, we should have an assertion for each change called for in the plan', autoSubmit: true, sortOrder: 8 },
42
+ { label: 'Tests are failing', content: 'Tests are failing. Look at the canvas for details', autoSubmit: true, sortOrder: 9 },
43
+ { label: 'Continue', content: 'Continue', autoSubmit: true, sortOrder: 10 },
44
+ ];
45
+
46
+ export const DEFAULT_SESSION_TEMPLATE_PROMPTS = {
47
+ REVIEW: `Review the plan on the canvas. If there's more than one plan then review the most recently updated plan. if there are no plans on the canvas then look for the most recently updated plan on the root session canvas.
48
+
49
+ Make sure there are tests explicitly called out for all changes. Make sure that all context necessary to hand off the task is included in the plan.
50
+
51
+ Are there any gaps in the plan? Is test coverage spelled out explicitly? Does the code match the assumptions in the plan?
52
+
53
+ Update the plan according to your review recommendations.`,
54
+ IMPLEMENT: `Implement the plan on the canvas. If there's more than one plan on the canvas then use the most recently updated plan. If you don't see a plan on the canvas then look at the parent session's canvas.`,
55
+ PR: `Ensure all relevant changes are committed and pushed. Then determine the session's goals. You can typically find details about the goals of the session by looking at the most recently modified markdown documents on the root session's canvas - these are typically plans that were implemented during the session. You can also look at the root session's summary, but don't trigger a new summary to be created if the summary is missing.
56
+
57
+ Create a draft pr and ensure all changes are committed and pushed.`,
58
+ };
59
+
60
+ export const DEFAULT_SESSION_TEMPLATES = [
61
+ { name: 'Review the plan', prompt: DEFAULT_SESSION_TEMPLATE_PROMPTS.REVIEW },
62
+ { name: 'Implement the plan on the canvas', prompt: DEFAULT_SESSION_TEMPLATE_PROMPTS.IMPLEMENT },
63
+ { name: 'Create/update PR', prompt: DEFAULT_SESSION_TEMPLATE_PROMPTS.PR },
64
+ ];
65
+
66
+ function seedBuiltInProviders(db) {
67
+ const now = Date.now();
68
+
69
+ db.prepare(
70
+ `INSERT OR IGNORE INTO providers (
71
+ id, name, base_url, auth_token, kind, is_built_in, created_at, updated_at
72
+ )
73
+ VALUES (?, ?, NULL, NULL, ?, 1, ?, ?)`
74
+ ).run(BUILT_IN_ANTHROPIC_PROVIDER.id, BUILT_IN_ANTHROPIC_PROVIDER.name, BUILT_IN_ANTHROPIC_PROVIDER.kind, now, now);
75
+
76
+ db.prepare(
77
+ `INSERT OR IGNORE INTO providers (
78
+ id, name, base_url, auth_token, kind, is_built_in, created_at, updated_at
79
+ )
80
+ VALUES (?, ?, NULL, NULL, ?, 1, ?, ?)`
81
+ ).run(BUILT_IN_OPENAI_PROVIDER.id, BUILT_IN_OPENAI_PROVIDER.name, BUILT_IN_OPENAI_PROVIDER.kind, now, now);
82
+
83
+ const insertModel = db.prepare(
84
+ `INSERT OR IGNORE INTO provider_models (
85
+ id, provider_id, model_id, display_name, description, tier, created_at
86
+ )
87
+ VALUES (?, ?, ?, ?, ?, ?, ?)`
88
+ );
89
+
90
+ for (const model of [...BUILT_IN_ANTHROPIC_MODELS, ...BUILT_IN_OPENAI_MODELS]) {
91
+ insertModel.run(model.id, model.providerId, model.modelId, model.displayName, model.description, model.tier, now);
92
+ }
93
+ }
94
+
95
+ function seedDefaultQuickResponses(db) {
96
+ const count = db.prepare('SELECT COUNT(*) AS cnt FROM quick_responses').get().cnt;
97
+ if (count > 0) return;
98
+
99
+ const now = Date.now();
100
+ const stmt = db.prepare(
101
+ `INSERT INTO quick_responses (
102
+ id, project_id, label, content, auto_submit, category, sort_order, created_at, updated_at
103
+ )
104
+ VALUES (?, NULL, ?, ?, ?, NULL, ?, ?, ?)`
105
+ );
106
+
107
+ for (const item of DEFAULT_QUICK_RESPONSES) {
108
+ stmt.run(randomUUID(), item.label, item.content, item.autoSubmit ? 1 : 0, item.sortOrder, now, now);
109
+ }
110
+ }
111
+
112
+ function seedDefaultSessionTemplates(db) {
113
+ const count = db.prepare(
114
+ 'SELECT COUNT(*) AS cnt FROM session_templates WHERE project_id IS NULL'
115
+ ).get().cnt;
116
+ if (count > 0) return;
117
+
118
+ const now = Date.now();
119
+ const stmt = db.prepare(`
120
+ INSERT INTO session_templates (
121
+ id, project_id, name, prompt,
122
+ next_template_id, thinking_enabled,
123
+ git_branch, git_mode, model, mode, effort_level, target_lane_id,
124
+ created_at, updated_at
125
+ ) VALUES (?, NULL, ?, ?, NULL, 1, NULL, NULL, NULL, 'yolo', NULL, NULL, ?, ?)
126
+ `);
127
+
128
+ for (const item of DEFAULT_SESSION_TEMPLATES) {
129
+ stmt.run(randomUUID(), item.name, item.prompt, now, now);
130
+ }
131
+ }
132
+
133
+ export function seedBaselineData(db) {
134
+ seedBuiltInProviders(db);
135
+ seedDefaultQuickResponses(db);
136
+ seedDefaultSessionTemplates(db);
137
+ }
@@ -3,6 +3,8 @@
3
3
  * config parsing, and update-clause builders.
4
4
  */
5
5
 
6
+ import { DEFAULT_RESCHEDULE_DELAY_MINUTES } from '../../../shared/src/index.js';
7
+
6
8
  /** Reusable SQL fragment for computed activity fields on sessions */
7
9
  export const ACTIVITY_FIELDS_SQL = `
8
10
  (SELECT MAX(cm.timestamp) FROM conversation_messages cm WHERE cm.session_id = s.id) AS last_activity_at,
@@ -24,6 +26,7 @@ export function mapTokenUsage(row) {
24
26
  return {
25
27
  inputTokens: row.input_tokens || 0,
26
28
  outputTokens: row.output_tokens || 0,
29
+ thinkingTokens: row.thinking_tokens || 0,
27
30
  cacheReadInputTokens: row.cache_read_input_tokens || 0,
28
31
  cacheCreationInputTokens: row.cache_creation_input_tokens || 0,
29
32
  webSearchRequests: row.web_search_requests || 0,
@@ -39,7 +42,7 @@ export function mapTokenUsage(row) {
39
42
  export function mapScheduling(row) {
40
43
  return {
41
44
  scheduledAt: row.scheduled_at || null,
42
- rescheduleDelayMinutes: row.reschedule_delay_minutes || 15,
45
+ rescheduleDelayMinutes: row.reschedule_delay_minutes || DEFAULT_RESCHEDULE_DELAY_MINUTES,
43
46
  autoRescheduleEnabled: Boolean(row.auto_reschedule_enabled),
44
47
  rescheduleOnTokenLimit: Boolean(row.reschedule_on_token_limit),
45
48
  rescheduleOnServiceError: Boolean(row.reschedule_on_service_error),
@@ -52,12 +55,13 @@ export function mapScheduling(row) {
52
55
 
53
56
  /** Default values for session-create config fields */
54
57
  const CONFIG_DEFAULTS = {
55
- mode: 'standard',
56
- thinkingEnabled: false,
58
+ mode: 'yolo',
59
+ thinkingEnabled: true,
57
60
  gitBranch: null,
58
61
  parentSessionId: null,
59
62
  status: 'starting',
60
63
  model: null,
64
+ providerId: null,
61
65
  effortLevel: null,
62
66
  // Agent runtime for the session: 'claude-code' (default) or 'codex'.
63
67
  // Defaults to null so SessionRepository.create() can resolve it from the model.
@@ -100,6 +104,7 @@ export const DIRECT_FIELD_MAP = {
100
104
  costUsd: 'cost_usd',
101
105
  claudeSessionId: 'claude_session_id',
102
106
  model: 'model',
107
+ providerId: 'provider_id',
103
108
  nextTemplateId: 'next_template_id',
104
109
  parentSessionId: 'parent_session_id',
105
110
  scheduledAt: 'scheduled_at',
@@ -122,6 +127,7 @@ export const BOOLEAN_FIELD_MAP = {
122
127
  archived: 'archived',
123
128
  starred: 'starred',
124
129
  manuallyNamed: 'manually_named',
130
+ prUrlAutoLinkDisabled: 'pr_url_auto_link_disabled',
125
131
  autoRescheduleEnabled: 'auto_reschedule_enabled',
126
132
  rescheduleOnTokenLimit: 'reschedule_on_token_limit',
127
133
  rescheduleOnServiceError: 'reschedule_on_service_error',