@oar-sh/oar 0.9.19 → 0.9.21

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 (190) hide show
  1. package/.github/extensions/web-relay/polling/polling-loop.mjs +2 -26
  2. package/.github/extensions/web-relay/skills/question-routing-hooks.mjs +2 -26
  3. package/CHANGELOG.md +529 -0
  4. package/README.md +14 -14
  5. package/bin/oar.js +392 -98
  6. package/package.json +4 -2
  7. package/server/claude-cloud-worker/claude-cloud-event-normalizer.mjs +60 -0
  8. package/server/claude-cloud-worker/claude-cloud-session-process.mjs +258 -1
  9. package/server/claude-cloud-worker/claude-cloud-session-worker.mjs +22 -1
  10. package/server/claude-cloud-worker/claude-cloud-worker-steering.mjs +34 -0
  11. package/server/claude-worker/claude-remote-relay-tool.mjs +1 -0
  12. package/server/claude-worker/claude-session-process.mjs +10 -0
  13. package/server/claude-worker/claude-session-worker-main.mjs +8 -1
  14. package/server/claude-worker/claude-turn-publisher.mjs +163 -8
  15. package/server/claude-worker/claude-usage-totals.mjs +58 -0
  16. package/server/copilot-worker/copilot-plan-board.mjs +4 -7
  17. package/server/copilot-worker/copilot-sdk-event-normalizer.mjs +86 -3
  18. package/server/copilot-worker/copilot-sdk-session-process.mjs +131 -5
  19. package/server/copilot-worker/copilot-sdk-session-worker.mjs +8 -1
  20. package/server/cursor-worker/cursor-session-worker.mjs +12 -1
  21. package/server/cursor-worker/cursor-turn-runner.mjs +42 -6
  22. package/server/cursor-worker/cursor-worker-steering.mjs +20 -0
  23. package/server/db-schema.mjs +18 -0
  24. package/server/deepseek-worker/deepseek-claude-backend.mjs +14 -0
  25. package/server/grok-worker/grok-background-tasks.mjs +9 -0
  26. package/server/grok-worker/grok-session-worker.mjs +12 -1
  27. package/server/grok-worker/grok-turn-runner.mjs +47 -6
  28. package/server/grok-worker/grok-worker-steering.mjs +23 -0
  29. package/server/migrations/0001-add-structured-answer.mjs +5 -7
  30. package/server/migrations/0002-recent-workspace-roots-path-key.mjs +5 -7
  31. package/server/migrations/0003-push-subscriptions.mjs +5 -7
  32. package/server/migrations/0004-steer-settle-markers.mjs +5 -7
  33. package/server/migrations/0005-remote-relays.mjs +5 -7
  34. package/server/migrations/0006-workspace-root-settings.mjs +5 -7
  35. package/server/migrations/0007-claude-cloud.mjs +5 -7
  36. package/server/migrations/0008-message-pins.mjs +5 -7
  37. package/server/migrations/0009-subagent-timeline.mjs +5 -7
  38. package/server/migrations/0010-subagent-timeline-pruning.mjs +5 -7
  39. package/server/migrations/0011-relay-event-subscriptions.mjs +5 -7
  40. package/server/migrations/0012-cross-relay-event-subscriptions.mjs +5 -7
  41. package/server/migrations/0013-previews.mjs +5 -7
  42. package/server/migrations/0014-conversation-groups.mjs +5 -7
  43. package/server/migrations/0015-conversation-group-position.mjs +5 -7
  44. package/server/migrations/0016-share-access-log.mjs +5 -7
  45. package/server/migrations/0017-conversation-history-indexes.mjs +5 -7
  46. package/server/migrations/0018-background-task-rows.mjs +5 -7
  47. package/server/migrations/0019-relay-event-subscription-options.mjs +5 -7
  48. package/server/migrations/0020-conversation-may-create-sessions.mjs +5 -7
  49. package/server/migrations/0021-conversation-group-agent-marks.mjs +5 -7
  50. package/server/migrations/0022-relay-schedules.mjs +5 -7
  51. package/server/migrations/0023-relay-asks.mjs +5 -7
  52. package/server/migrations/0024-deepseek-usage-totals.mjs +5 -7
  53. package/server/migrations/0025-deepseek-usage-requests-daily.mjs +5 -7
  54. package/server/migrations/0026-deepseek-usage-served-models.mjs +5 -7
  55. package/server/migrations/0027-deepseek-usage-checkpoint-runs.mjs +5 -7
  56. package/server/migrations/0028-deepseek-usage-checkpoint-request-runs.mjs +5 -7
  57. package/server/migrations/0029-deepseek-balance-rises.mjs +5 -7
  58. package/server/migrations/0030-deepseek-usage-actuals.mjs +5 -7
  59. package/server/migrations/0031-queue-provider.mjs +5 -7
  60. package/server/migrations/0032-runtime-session-billing-switch.mjs +5 -7
  61. package/server/migrations/0033-claude-api-usage-checkpoints.mjs +5 -7
  62. package/server/migrations/0034-claude-api-usage-totals.mjs +5 -7
  63. package/server/migrations/0035-conversation-plan-only.mjs +87 -0
  64. package/server/migrations/0036-token-usage.mjs +267 -0
  65. package/server/public/app/about-ui.js +1 -1
  66. package/server/public/app/about-view.mjs +106 -3
  67. package/server/public/app/action-confirmations.js +1 -1
  68. package/server/public/app/api-client.js +6 -3
  69. package/server/public/app/ask-user-view.js +20 -6
  70. package/server/public/app/attachments-view.js +1 -1
  71. package/server/public/app/back-guard.mjs +31 -5
  72. package/server/public/app/bootstrap.js +611 -70
  73. package/server/public/app/chat-actions-menu-state.mjs +139 -4
  74. package/server/public/app/chat-header-meta.mjs +27 -0
  75. package/server/public/app/claude-billing-toggle-ui.js +2 -1
  76. package/server/public/app/claude-cloud-conversation-ui.js +2 -2
  77. package/server/public/app/composer-control-state.mjs +12 -2
  78. package/server/public/app/composer-settings-label.mjs +90 -0
  79. package/server/public/app/composer-settings-ui.js +442 -0
  80. package/server/public/app/context-menu.mjs +36 -5
  81. package/server/public/app/context-usage-view.mjs +16 -0
  82. package/server/public/app/conversation-deep-link.mjs +15 -11
  83. package/server/public/app/conversation-group-drag.mjs +12 -2
  84. package/server/public/app/conversation-group-order.mjs +9 -2
  85. package/server/public/app/conversation-group-state.mjs +47 -10
  86. package/server/public/app/conversation-origin-ui.js +17 -1
  87. package/server/public/app/conversation-view.js +20 -2
  88. package/server/public/app/cwd-menu-placement.mjs +18 -6
  89. package/server/public/app/cwd-picker.js +36 -6
  90. package/server/public/app/emoji-view.js +1 -1
  91. package/server/public/app/font-scaling.js +26 -0
  92. package/server/public/app/header-priority-actions.mjs +234 -0
  93. package/server/public/app/hidden-messages-view.mjs +4 -0
  94. package/server/public/app/inbox-ui.js +50 -2
  95. package/server/public/app/inbox-view.mjs +141 -5
  96. package/server/public/app/journal-view.js +311 -58
  97. package/server/public/app/phone-landscape-ui.js +225 -0
  98. package/server/public/app/phone-landscape.mjs +99 -0
  99. package/server/public/app/phone-typing-state.mjs +104 -0
  100. package/server/public/app/pinned-messages-view.mjs +5 -0
  101. package/server/public/app/plan-board-shared.mjs +49 -0
  102. package/server/public/app/plan-usage-view.mjs +1 -1
  103. package/server/public/app/push-settings.js +2 -2
  104. package/server/public/app/pwa-install.js +24 -3
  105. package/server/public/app/relay-board-inline.mjs +4 -1
  106. package/server/public/app/relay-board-view.js +38 -10
  107. package/server/public/app/relay-event-subscriptions-ui.js +71 -22
  108. package/server/public/app/relay-event-view.mjs +42 -0
  109. package/server/public/app/relay-restart-ui.js +2 -2
  110. package/server/public/app/relay-schedule-view.mjs +32 -6
  111. package/server/public/app/relay-schedules-ui.js +69 -20
  112. package/server/public/app/remote-relay-origin-view.mjs +41 -23
  113. package/server/public/app/session-history-ui.js +250 -0
  114. package/server/public/app/session-history.mjs +599 -0
  115. package/server/public/app/settings-modal.js +61 -6
  116. package/server/public/app/settings-tabs.js +12 -0
  117. package/server/public/app/share-state.js +1 -1
  118. package/server/public/app/shared-conversations-settings.js +2 -2
  119. package/server/public/app/socket-handlers.js +15 -4
  120. package/server/public/app/status-view.mjs +18 -2
  121. package/server/public/app/store.js +87 -16
  122. package/server/public/app/subagent-viewer.mjs +27 -2
  123. package/server/public/app/tab-strip-fade.mjs +101 -0
  124. package/server/public/app/tap-actions.js +66 -0
  125. package/server/public/app/usage-limit-ui.js +63 -2
  126. package/server/public/app/viewer-history.mjs +13 -2
  127. package/server/public/index.html +2258 -1585
  128. package/server/public/sw.js +8 -0
  129. package/server/relay-heap-guard.mjs +14 -1
  130. package/server/relay-self-restart.mjs +83 -2
  131. package/server/relay-tools.md +5 -3
  132. package/server/repositories/message-repository.mjs +54 -1
  133. package/server/repositories/remote-relay-repository.mjs +10 -0
  134. package/server/repositories/session-repository.mjs +25 -1
  135. package/server/routes/claude-cloud-routes.mjs +19 -0
  136. package/server/routes/messages-routes.mjs +144 -1
  137. package/server/routes/relay-ask-routes.mjs +138 -8
  138. package/server/routes/relay-board-routes.mjs +55 -40
  139. package/server/routes/sessions-routes.mjs +144 -14
  140. package/server/server-runtime.mjs +322 -51
  141. package/server/services/about-service.mjs +81 -53
  142. package/server/services/cache-rebuild-service.mjs +7 -0
  143. package/server/services/claude-billing-swap-service.mjs +7 -20
  144. package/server/services/claude-cloud-session-service.mjs +47 -5
  145. package/server/services/conversation-preferences-service.mjs +31 -0
  146. package/server/services/database-file.mjs +413 -0
  147. package/server/services/db-backup-service.mjs +809 -0
  148. package/server/services/deepseek-usage-import.mjs +6 -9
  149. package/server/services/delete-archive-service.mjs +3 -0
  150. package/server/services/earlier-database-service.mjs +69 -126
  151. package/server/services/oar-cli-helpers.mjs +214 -12
  152. package/server/services/oar-cli-menu.mjs +1 -0
  153. package/server/services/oar-state-migration-service.mjs +33 -13
  154. package/server/services/package-data-rescue.mjs +4 -2
  155. package/server/services/plan-usage-claude-api.mjs +14 -15
  156. package/server/services/plan-usage-contract.mjs +6 -2
  157. package/server/services/plan-usage-deepseek.mjs +1 -1
  158. package/server/services/plan-usage-tokens.mjs +248 -0
  159. package/server/services/push-dispatch-service.mjs +134 -9
  160. package/server/services/relay-cli-launcher-service.mjs +3 -0
  161. package/server/services/relay-event-service.mjs +30 -0
  162. package/server/services/relay-question-context.mjs +11 -0
  163. package/server/services/relay-restart-picture.mjs +67 -22
  164. package/server/services/remote-inbox-watch-service.mjs +204 -0
  165. package/server/services/remote-relay-caller-context.mjs +80 -7
  166. package/server/services/remote-relay-dispatcher.mjs +101 -19
  167. package/server/services/restart-resume-service.mjs +5 -2
  168. package/server/services/session-activity-tracker.mjs +1 -1
  169. package/server/services/session-launch-mutex-service.mjs +23 -0
  170. package/server/services/session-worker-launch-service.mjs +12 -3
  171. package/server/services/session-worker-registry-service.mjs +36 -0
  172. package/server/services/session-worker-stop-service.mjs +27 -6
  173. package/server/services/session-worker-websocket-service.mjs +40 -16
  174. package/server/services/token-usage-service.mjs +430 -0
  175. package/server/services/update-install-service.mjs +13 -0
  176. package/server/services/usage-limit-pause-service.mjs +8 -1
  177. package/server/services/worker-recycle-service.mjs +772 -0
  178. package/server/services/worker-replacement.mjs +197 -0
  179. package/server/services/worker-scope.mjs +77 -0
  180. package/shared/build-id.mjs +128 -0
  181. package/shared/plan-board-actions.mjs +130 -0
  182. package/shared/plan-only.mjs +43 -0
  183. package/shared/relay-asks.mjs +3 -0
  184. package/shared/relay-events.mjs +38 -4
  185. package/shared/remote-relay-contract.mjs +66 -11
  186. package/shared/turn-token-usage.mjs +144 -0
  187. package/shared/worker-runtime/heartbeat.mjs +5 -0
  188. package/shared/worker-runtime/simple-steering-state.mjs +38 -0
  189. package/shared/worker-runtime/worker-websocket-link.mjs +23 -0
  190. package/shared/worker-runtime/working-directory.mjs +1 -1
@@ -11,13 +11,14 @@
11
11
  *
12
12
  * Additive and idempotent. Safe to run on every boot.
13
13
  *
14
- * Usage: node server/migrations/0006-workspace-root-settings.mjs [path/to/copilot.db]
14
+ * Usage: node server/migrations/0006-workspace-root-settings.mjs [path/to/oar.db]
15
15
  */
16
16
 
17
17
  import { fileURLToPath } from 'url';
18
18
  import path from 'path';
19
19
  import process from 'process';
20
20
  import Database from 'better-sqlite3';
21
+ import { cliDbPath } from '../services/database-file.mjs';
21
22
 
22
23
  function tableExists(db, name) {
23
24
  return !!db
@@ -38,11 +39,6 @@ export function migrateWorkspaceRootSettings(db) {
38
39
  return { applied: !existed, tableCreated: !existed };
39
40
  }
40
41
 
41
- function defaultDbPath() {
42
- const here = path.dirname(fileURLToPath(import.meta.url));
43
- return path.resolve(here, '..', 'data', 'copilot.db');
44
- }
45
-
46
42
  export function migrate(dbPath, options = {}) {
47
43
  const db = new Database(dbPath, options);
48
44
  try {
@@ -54,8 +50,10 @@ export function migrate(dbPath, options = {}) {
54
50
 
55
51
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
56
52
  if (isMain) {
57
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
58
53
  try {
54
+ // The given path, else the database in server/data (oar.db, else the
55
+ // name before 0.9.20); never a new one.
56
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
59
57
  const result = migrate(dbPath);
60
58
  console.log(`Migration 0006 on ${dbPath}`);
61
59
  console.log(result.applied ? ' workspace_root_settings table created' : ' skipped: nothing to change');
@@ -17,13 +17,14 @@
17
17
  *
18
18
  * Additive and idempotent. Safe to run on every boot.
19
19
  *
20
- * Usage: node server/migrations/0007-claude-cloud.mjs [path/to/copilot.db]
20
+ * Usage: node server/migrations/0007-claude-cloud.mjs [path/to/oar.db]
21
21
  */
22
22
 
23
23
  import { fileURLToPath } from 'url';
24
24
  import path from 'path';
25
25
  import process from 'process';
26
26
  import Database from 'better-sqlite3';
27
+ import { cliDbPath } from '../services/database-file.mjs';
27
28
 
28
29
  const COLUMNS = Object.freeze([
29
30
  Object.freeze({ table: 'runtime_sessions', name: 'claude_cloud_session_id', type: 'TEXT' }),
@@ -53,11 +54,6 @@ export function migrateClaudeCloud(db) {
53
54
  return { applied: columnsAdded > 0, columnsAdded };
54
55
  }
55
56
 
56
- function defaultDbPath() {
57
- const here = path.dirname(fileURLToPath(import.meta.url));
58
- return path.resolve(here, '..', 'data', 'copilot.db');
59
- }
60
-
61
57
  export function migrate(dbPath, options = {}) {
62
58
  const db = new Database(dbPath, options);
63
59
  try {
@@ -69,8 +65,10 @@ export function migrate(dbPath, options = {}) {
69
65
 
70
66
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
71
67
  if (isMain) {
72
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
73
68
  try {
69
+ // The given path, else the database in server/data (oar.db, else the
70
+ // name before 0.9.20); never a new one.
71
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
74
72
  const result = migrate(dbPath);
75
73
  console.log(`Migration 0007 on ${dbPath}`);
76
74
  console.log(result.applied ? ` claude cloud columns added: ${result.columnsAdded}` : ' skipped: nothing to change');
@@ -11,13 +11,14 @@
11
11
  *
12
12
  * Additive and idempotent. Safe to run on every boot.
13
13
  *
14
- * Usage: node server/migrations/0008-message-pins.mjs [path/to/copilot.db]
14
+ * Usage: node server/migrations/0008-message-pins.mjs [path/to/oar.db]
15
15
  */
16
16
 
17
17
  import { fileURLToPath } from 'url';
18
18
  import path from 'path';
19
19
  import process from 'process';
20
20
  import Database from 'better-sqlite3';
21
+ import { cliDbPath } from '../services/database-file.mjs';
21
22
 
22
23
  function tableExists(db, name) {
23
24
  return !!db
@@ -54,11 +55,6 @@ export function migrateMessagePins(db) {
54
55
  return { applied: columnsAdded + indexesAdded > 0, columnsAdded, indexesAdded };
55
56
  }
56
57
 
57
- function defaultDbPath() {
58
- const here = path.dirname(fileURLToPath(import.meta.url));
59
- return path.resolve(here, '..', 'data', 'copilot.db');
60
- }
61
-
62
58
  export function migrate(dbPath, options = {}) {
63
59
  const db = new Database(dbPath, options);
64
60
  try {
@@ -70,8 +66,10 @@ export function migrate(dbPath, options = {}) {
70
66
 
71
67
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
72
68
  if (isMain) {
73
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
74
69
  try {
70
+ // The given path, else the database in server/data (oar.db, else the
71
+ // name before 0.9.20); never a new one.
72
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
75
73
  const result = migrate(dbPath);
76
74
  console.log(`Migration 0008 on ${dbPath}`);
77
75
  console.log(result.applied
@@ -16,13 +16,14 @@
16
16
  *
17
17
  * Additive and idempotent. Safe to run on every boot.
18
18
  *
19
- * Usage: node server/migrations/0009-subagent-timeline.mjs [path/to/copilot.db]
19
+ * Usage: node server/migrations/0009-subagent-timeline.mjs [path/to/oar.db]
20
20
  */
21
21
 
22
22
  import { fileURLToPath } from 'url';
23
23
  import path from 'path';
24
24
  import process from 'process';
25
25
  import Database from 'better-sqlite3';
26
+ import { cliDbPath } from '../services/database-file.mjs';
26
27
 
27
28
  function tableExists(db, name) {
28
29
  return !!db
@@ -104,11 +105,6 @@ export function migrateSubagentTimeline(db) {
104
105
  };
105
106
  }
106
107
 
107
- function defaultDbPath() {
108
- const here = path.dirname(fileURLToPath(import.meta.url));
109
- return path.resolve(here, '..', 'data', 'copilot.db');
110
- }
111
-
112
108
  export function migrate(dbPath, options = {}) {
113
109
  const db = new Database(dbPath, options);
114
110
  try {
@@ -120,8 +116,10 @@ export function migrate(dbPath, options = {}) {
120
116
 
121
117
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
122
118
  if (isMain) {
123
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
124
119
  try {
120
+ // The given path, else the database in server/data (oar.db, else the
121
+ // name before 0.9.20); never a new one.
122
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
125
123
  const result = migrate(dbPath);
126
124
  console.log(`Migration 0009 on ${dbPath}`);
127
125
  console.log(result.applied
@@ -11,13 +11,14 @@
11
11
  *
12
12
  * Additive and idempotent. Safe to run on every boot.
13
13
  *
14
- * Usage: node server/migrations/0010-subagent-timeline-pruning.mjs [path/to/copilot.db]
14
+ * Usage: node server/migrations/0010-subagent-timeline-pruning.mjs [path/to/oar.db]
15
15
  */
16
16
 
17
17
  import { fileURLToPath } from 'url';
18
18
  import path from 'path';
19
19
  import process from 'process';
20
20
  import Database from 'better-sqlite3';
21
+ import { cliDbPath } from '../services/database-file.mjs';
21
22
 
22
23
  export const PRUNABLE_INDEX_NAME = 'idx_subagent_timeline_prunable';
23
24
 
@@ -58,11 +59,6 @@ export function migrateSubagentTimelinePruning(db) {
58
59
  return { applied: columnsAdded + indexesAdded > 0, columnsAdded, indexesAdded };
59
60
  }
60
61
 
61
- function defaultDbPath() {
62
- const here = path.dirname(fileURLToPath(import.meta.url));
63
- return path.resolve(here, '..', 'data', 'copilot.db');
64
- }
65
-
66
62
  export function migrate(dbPath, options = {}) {
67
63
  const db = new Database(dbPath, options);
68
64
  try {
@@ -74,8 +70,10 @@ export function migrate(dbPath, options = {}) {
74
70
 
75
71
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
76
72
  if (isMain) {
77
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
78
73
  try {
74
+ // The given path, else the database in server/data (oar.db, else the
75
+ // name before 0.9.20); never a new one.
76
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
79
77
  const result = migrate(dbPath);
80
78
  console.log(`Migration 0010 on ${dbPath}`);
81
79
  console.log(result.applied
@@ -18,13 +18,14 @@
18
18
  *
19
19
  * Additive and idempotent. Safe to run on every boot.
20
20
  *
21
- * Usage: node server/migrations/0011-relay-event-subscriptions.mjs [path/to/copilot.db]
21
+ * Usage: node server/migrations/0011-relay-event-subscriptions.mjs [path/to/oar.db]
22
22
  */
23
23
 
24
24
  import { fileURLToPath } from 'url';
25
25
  import path from 'path';
26
26
  import process from 'process';
27
27
  import Database from 'better-sqlite3';
28
+ import { cliDbPath } from '../services/database-file.mjs';
28
29
 
29
30
  function tableExists(db, name) {
30
31
  return !!db
@@ -94,11 +95,6 @@ export function migrateRelayEventSubscriptions(db) {
94
95
  return { applied: tablesAdded > 0, tablesAdded };
95
96
  }
96
97
 
97
- function defaultDbPath() {
98
- const here = path.dirname(fileURLToPath(import.meta.url));
99
- return path.resolve(here, '..', 'data', 'copilot.db');
100
- }
101
-
102
98
  export function migrate(dbPath, options = {}) {
103
99
  const db = new Database(dbPath, options);
104
100
  try {
@@ -110,8 +106,10 @@ export function migrate(dbPath, options = {}) {
110
106
 
111
107
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
112
108
  if (isMain) {
113
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
114
109
  try {
110
+ // The given path, else the database in server/data (oar.db, else the
111
+ // name before 0.9.20); never a new one.
112
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
115
113
  const result = migrate(dbPath);
116
114
  console.log(`Migration 0011 on ${dbPath}`);
117
115
  console.log(result.applied
@@ -21,13 +21,14 @@
21
21
  *
22
22
  * Additive and idempotent. Safe to run on every boot.
23
23
  *
24
- * Usage: node server/migrations/0012-cross-relay-event-subscriptions.mjs [path/to/copilot.db]
24
+ * Usage: node server/migrations/0012-cross-relay-event-subscriptions.mjs [path/to/oar.db]
25
25
  */
26
26
 
27
27
  import { fileURLToPath } from 'url';
28
28
  import path from 'path';
29
29
  import process from 'process';
30
30
  import Database from 'better-sqlite3';
31
+ import { cliDbPath } from '../services/database-file.mjs';
31
32
 
32
33
  const SUBSCRIPTION_COLUMNS = Object.freeze([
33
34
  ['remote_subscription_id', 'TEXT'],
@@ -85,11 +86,6 @@ export function migrateCrossRelayEventSubscriptions(db) {
85
86
  return { applied: columnsAdded > 0 || tablesAdded > 0, columnsAdded, tablesAdded };
86
87
  }
87
88
 
88
- function defaultDbPath() {
89
- const here = path.dirname(fileURLToPath(import.meta.url));
90
- return path.resolve(here, '..', 'data', 'copilot.db');
91
- }
92
-
93
89
  export function migrate(dbPath, options = {}) {
94
90
  const db = new Database(dbPath, options);
95
91
  try {
@@ -101,8 +97,10 @@ export function migrate(dbPath, options = {}) {
101
97
 
102
98
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
103
99
  if (isMain) {
104
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
105
100
  try {
101
+ // The given path, else the database in server/data (oar.db, else the
102
+ // name before 0.9.20); never a new one.
103
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
106
104
  const result = migrate(dbPath);
107
105
  console.log(`Migration 0012 on ${dbPath}`);
108
106
  console.log(result.applied
@@ -27,7 +27,7 @@
27
27
  * alone and reported as not compatible; the relay then keeps previews in
28
28
  * memory only, it never refuses to start over it.
29
29
  *
30
- * Usage: node server/migrations/0013-previews.mjs [path/to/copilot.db]
30
+ * Usage: node server/migrations/0013-previews.mjs [path/to/oar.db]
31
31
  * The file must exist: a wrong path is refused rather than creating an empty
32
32
  * database.
33
33
  */
@@ -37,6 +37,7 @@ import { fileURLToPath } from 'url';
37
37
  import path from 'path';
38
38
  import process from 'process';
39
39
  import Database from 'better-sqlite3';
40
+ import { cliDbPath } from '../services/database-file.mjs';
40
41
 
41
42
  function tableExists(db, name) {
42
43
  return !!db
@@ -94,11 +95,6 @@ export function migratePreviews(db) {
94
95
  return { applied: tablesAdded > 0, tablesAdded, compatible: true };
95
96
  }
96
97
 
97
- function defaultDbPath() {
98
- const here = path.dirname(fileURLToPath(import.meta.url));
99
- return path.resolve(here, '..', 'data', 'copilot.db');
100
- }
101
-
102
98
  export function migrate(dbPath, options = {}) {
103
99
  if (!fs.existsSync(dbPath)) throw new Error(`no database at ${dbPath}`);
104
100
  const db = new Database(dbPath, { fileMustExist: true, ...options });
@@ -111,8 +107,10 @@ export function migrate(dbPath, options = {}) {
111
107
 
112
108
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
113
109
  if (isMain) {
114
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
115
110
  try {
111
+ // The given path, else the database in server/data (oar.db, else the
112
+ // name before 0.9.20); never a new one.
113
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
116
114
  const result = migrate(dbPath);
117
115
  console.log(`Migration 0013 on ${dbPath}`);
118
116
  if (!result.compatible) {
@@ -13,13 +13,14 @@
13
13
  *
14
14
  * Additive and idempotent. Safe to run on every boot.
15
15
  *
16
- * Usage: node server/migrations/0014-conversation-groups.mjs [path/to/copilot.db]
16
+ * Usage: node server/migrations/0014-conversation-groups.mjs [path/to/oar.db]
17
17
  */
18
18
 
19
19
  import { fileURLToPath } from 'url';
20
20
  import path from 'path';
21
21
  import process from 'process';
22
22
  import Database from 'better-sqlite3';
23
+ import { cliDbPath } from '../services/database-file.mjs';
23
24
 
24
25
  function tableExists(db, name) {
25
26
  return !!db
@@ -58,11 +59,6 @@ export function migrateConversationGroups(db) {
58
59
  return { applied: columnsAdded > 0 || tablesAdded > 0, columnsAdded, tablesAdded };
59
60
  }
60
61
 
61
- function defaultDbPath() {
62
- const here = path.dirname(fileURLToPath(import.meta.url));
63
- return path.resolve(here, '..', 'data', 'copilot.db');
64
- }
65
-
66
62
  export function migrate(dbPath, options = {}) {
67
63
  const db = new Database(dbPath, options);
68
64
  try {
@@ -74,8 +70,10 @@ export function migrate(dbPath, options = {}) {
74
70
 
75
71
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
76
72
  if (isMain) {
77
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
78
73
  try {
74
+ // The given path, else the database in server/data (oar.db, else the
75
+ // name before 0.9.20); never a new one.
76
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
79
77
  const result = migrate(dbPath);
80
78
  console.log(`Migration 0014 on ${dbPath}`);
81
79
  console.log(result.applied
@@ -13,13 +13,14 @@
13
13
  * data change: older code ignores the column; a row it moves out of a group
14
14
  * keeps a stale place, which the next run here clears.
15
15
  *
16
- * Usage: node server/migrations/0015-conversation-group-position.mjs [path/to/copilot.db]
16
+ * Usage: node server/migrations/0015-conversation-group-position.mjs [path/to/oar.db]
17
17
  */
18
18
 
19
19
  import { fileURLToPath } from 'url';
20
20
  import path from 'path';
21
21
  import process from 'process';
22
22
  import Database from 'better-sqlite3';
23
+ import { cliDbPath } from '../services/database-file.mjs';
23
24
 
24
25
  function tableExists(db, name) {
25
26
  return !!db
@@ -45,11 +46,6 @@ export function migrateConversationGroupPosition(db) {
45
46
  return { applied: columnsAdded > 0 || placesCleared > 0, columnsAdded, placesCleared };
46
47
  }
47
48
 
48
- function defaultDbPath() {
49
- const here = path.dirname(fileURLToPath(import.meta.url));
50
- return path.resolve(here, '..', 'data', 'copilot.db');
51
- }
52
-
53
49
  export function migrate(dbPath, options = {}) {
54
50
  const db = new Database(dbPath, options);
55
51
  try {
@@ -61,8 +57,10 @@ export function migrate(dbPath, options = {}) {
61
57
 
62
58
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
63
59
  if (isMain) {
64
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
65
60
  try {
61
+ // The given path, else the database in server/data (oar.db, else the
62
+ // name before 0.9.20); never a new one.
63
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
66
64
  const result = migrate(dbPath);
67
65
  console.log(`Migration 0015 on ${dbPath}`);
68
66
  console.log(result.applied
@@ -25,13 +25,14 @@
25
25
  * reads the new table, and a share it creates has no lineage, which this build
26
26
  * reads as the share's own token.
27
27
  *
28
- * Usage: node server/migrations/0016-share-access-log.mjs [path/to/copilot.db]
28
+ * Usage: node server/migrations/0016-share-access-log.mjs [path/to/oar.db]
29
29
  */
30
30
 
31
31
  import { fileURLToPath } from 'url';
32
32
  import path from 'path';
33
33
  import process from 'process';
34
34
  import Database from 'better-sqlite3';
35
+ import { cliDbPath } from '../services/database-file.mjs';
35
36
 
36
37
  function tableExists(db, name) {
37
38
  return !!db
@@ -79,11 +80,6 @@ export function migrateShareAccessLog(db) {
79
80
  return { applied: columnsAdded > 0 || tablesAdded > 0 || lineagesSet > 0, columnsAdded, tablesAdded, lineagesSet };
80
81
  }
81
82
 
82
- function defaultDbPath() {
83
- const here = path.dirname(fileURLToPath(import.meta.url));
84
- return path.resolve(here, '..', 'data', 'copilot.db');
85
- }
86
-
87
83
  export function migrate(dbPath, options = {}) {
88
84
  const db = new Database(dbPath, options);
89
85
  try {
@@ -95,8 +91,10 @@ export function migrate(dbPath, options = {}) {
95
91
 
96
92
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
97
93
  if (isMain) {
98
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
99
94
  try {
95
+ // The given path, else the database in server/data (oar.db, else the
96
+ // name before 0.9.20); never a new one.
97
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
100
98
  const result = migrate(dbPath);
101
99
  console.log(`Migration 0016 on ${dbPath}`);
102
100
  console.log(result.applied
@@ -15,13 +15,14 @@
15
15
  * Additive and idempotent. Safe to run on every boot. An older build ignores
16
16
  * both indexes.
17
17
  *
18
- * Usage: node server/migrations/0017-conversation-history-indexes.mjs [path/to/copilot.db]
18
+ * Usage: node server/migrations/0017-conversation-history-indexes.mjs [path/to/oar.db]
19
19
  */
20
20
 
21
21
  import { fileURLToPath } from 'url';
22
22
  import path from 'path';
23
23
  import process from 'process';
24
24
  import Database from 'better-sqlite3';
25
+ import { cliDbPath } from '../services/database-file.mjs';
25
26
 
26
27
  function tableExists(db, name) {
27
28
  return !!db
@@ -58,11 +59,6 @@ export function migrateConversationHistoryIndexes(db) {
58
59
  return { applied: indexesAdded > 0, indexesAdded };
59
60
  }
60
61
 
61
- function defaultDbPath() {
62
- const here = path.dirname(fileURLToPath(import.meta.url));
63
- return path.resolve(here, '..', 'data', 'copilot.db');
64
- }
65
-
66
62
  export function migrate(dbPath, options = {}) {
67
63
  const db = new Database(dbPath, options);
68
64
  try {
@@ -74,8 +70,10 @@ export function migrate(dbPath, options = {}) {
74
70
 
75
71
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
76
72
  if (isMain) {
77
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
78
73
  try {
74
+ // The given path, else the database in server/data (oar.db, else the
75
+ // name before 0.9.20); never a new one.
76
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
79
77
  const result = migrate(dbPath);
80
78
  console.log(`Migration 0017 on ${dbPath}`);
81
79
  console.log(result.applied
@@ -23,13 +23,14 @@
23
23
  * Additive and idempotent. Safe to run on every boot. An older build never
24
24
  * reads the table; its consoles start empty after a restart as before.
25
25
  *
26
- * Usage: node server/migrations/0018-background-task-rows.mjs [path/to/copilot.db]
26
+ * Usage: node server/migrations/0018-background-task-rows.mjs [path/to/oar.db]
27
27
  */
28
28
 
29
29
  import { fileURLToPath } from 'url';
30
30
  import path from 'path';
31
31
  import process from 'process';
32
32
  import Database from 'better-sqlite3';
33
+ import { cliDbPath } from '../services/database-file.mjs';
33
34
 
34
35
  export const BACKGROUND_TASK_ROWS_COLUMNS = Object.freeze(['store_key', 'task_id', 'state', 'row_json', 'ended_at', 'updated_at']);
35
36
 
@@ -70,11 +71,6 @@ export function migrateBackgroundTaskRows(db) {
70
71
  return { applied: tablesAdded > 0, tablesAdded };
71
72
  }
72
73
 
73
- function defaultDbPath() {
74
- const here = path.dirname(fileURLToPath(import.meta.url));
75
- return path.resolve(here, '..', 'data', 'copilot.db');
76
- }
77
-
78
74
  export function migrate(dbPath, options = {}) {
79
75
  const db = new Database(dbPath, options);
80
76
  try {
@@ -86,8 +82,10 @@ export function migrate(dbPath, options = {}) {
86
82
 
87
83
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
88
84
  if (isMain) {
89
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
90
85
  try {
86
+ // The given path, else the database in server/data (oar.db, else the
87
+ // name before 0.9.20); never a new one.
88
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
91
89
  const result = migrate(dbPath);
92
90
  console.log(`Migration 0018 on ${dbPath}`);
93
91
  console.log(result.applied
@@ -22,13 +22,14 @@
22
22
  *
23
23
  * Additive and idempotent. Safe to run on every boot.
24
24
  *
25
- * Usage: node server/migrations/0019-relay-event-subscription-options.mjs [path/to/copilot.db]
25
+ * Usage: node server/migrations/0019-relay-event-subscription-options.mjs [path/to/oar.db]
26
26
  */
27
27
 
28
28
  import { fileURLToPath } from 'url';
29
29
  import path from 'path';
30
30
  import process from 'process';
31
31
  import Database from 'better-sqlite3';
32
+ import { cliDbPath } from '../services/database-file.mjs';
32
33
 
33
34
  export const RELAY_EVENT_OPTION_COLUMNS = Object.freeze([
34
35
  ['digest_minutes', 'INTEGER'],
@@ -75,11 +76,6 @@ export function migrateRelayEventSubscriptionOptions(db) {
75
76
  return { applied: columnsAdded > 0 || tablesAdded > 0, columnsAdded, tablesAdded };
76
77
  }
77
78
 
78
- function defaultDbPath() {
79
- const here = path.dirname(fileURLToPath(import.meta.url));
80
- return path.resolve(here, '..', 'data', 'copilot.db');
81
- }
82
-
83
79
  export function migrate(dbPath, options = {}) {
84
80
  const db = new Database(dbPath, options);
85
81
  try {
@@ -91,8 +87,10 @@ export function migrate(dbPath, options = {}) {
91
87
 
92
88
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
93
89
  if (isMain) {
94
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
95
90
  try {
91
+ // The given path, else the database in server/data (oar.db, else the
92
+ // name before 0.9.20); never a new one.
93
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
96
94
  const result = migrate(dbPath);
97
95
  console.log(`Migration 0019 on ${dbPath}`);
98
96
  console.log(result.applied
@@ -12,13 +12,14 @@
12
12
  * Additive and idempotent. Safe to run on every boot. Rolling back needs no
13
13
  * data change: older code ignores the column and keeps the one-level rule.
14
14
  *
15
- * Usage: node server/migrations/0020-conversation-may-create-sessions.mjs [path/to/copilot.db]
15
+ * Usage: node server/migrations/0020-conversation-may-create-sessions.mjs [path/to/oar.db]
16
16
  */
17
17
 
18
18
  import { fileURLToPath } from 'url';
19
19
  import path from 'path';
20
20
  import process from 'process';
21
21
  import Database from 'better-sqlite3';
22
+ import { cliDbPath } from '../services/database-file.mjs';
22
23
 
23
24
  function tableExists(db, name) {
24
25
  return !!db
@@ -36,11 +37,6 @@ export function migrateConversationMayCreateSessions(db) {
36
37
  return { applied: true, columnsAdded: 1 };
37
38
  }
38
39
 
39
- function defaultDbPath() {
40
- const here = path.dirname(fileURLToPath(import.meta.url));
41
- return path.resolve(here, '..', 'data', 'copilot.db');
42
- }
43
-
44
40
  export function migrate(dbPath, options = {}) {
45
41
  const db = new Database(dbPath, options);
46
42
  try {
@@ -52,8 +48,10 @@ export function migrate(dbPath, options = {}) {
52
48
 
53
49
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
54
50
  if (isMain) {
55
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
56
51
  try {
52
+ // The given path, else the database in server/data (oar.db, else the
53
+ // name before 0.9.20); never a new one.
54
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
57
55
  const result = migrate(dbPath);
58
56
  console.log(`Migration 0020 on ${dbPath}`);
59
57
  console.log(result.applied
@@ -15,13 +15,14 @@
15
15
  * data change: older code ignores both columns (its boot repair removes an
16
16
  * empty group, as it always did).
17
17
  *
18
- * Usage: node server/migrations/0021-conversation-group-agent-marks.mjs [path/to/copilot.db]
18
+ * Usage: node server/migrations/0021-conversation-group-agent-marks.mjs [path/to/oar.db]
19
19
  */
20
20
 
21
21
  import { fileURLToPath } from 'url';
22
22
  import path from 'path';
23
23
  import process from 'process';
24
24
  import Database from 'better-sqlite3';
25
+ import { cliDbPath } from '../services/database-file.mjs';
25
26
 
26
27
  function tableExists(db, name) {
27
28
  return !!db
@@ -46,11 +47,6 @@ export function migrateConversationGroupAgentMarks(db) {
46
47
  return { applied: columnsAdded > 0, columnsAdded };
47
48
  }
48
49
 
49
- function defaultDbPath() {
50
- const here = path.dirname(fileURLToPath(import.meta.url));
51
- return path.resolve(here, '..', 'data', 'copilot.db');
52
- }
53
-
54
50
  export function migrate(dbPath, options = {}) {
55
51
  const db = new Database(dbPath, options);
56
52
  try {
@@ -62,8 +58,10 @@ export function migrate(dbPath, options = {}) {
62
58
 
63
59
  const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
64
60
  if (isMain) {
65
- const dbPath = process.argv[2] ? path.resolve(process.argv[2]) : defaultDbPath();
66
61
  try {
62
+ // The given path, else the database in server/data (oar.db, else the
63
+ // name before 0.9.20); never a new one.
64
+ const dbPath = cliDbPath(process.argv[2], new URL('..', import.meta.url));
67
65
  const result = migrate(dbPath);
68
66
  console.log(`Migration 0021 on ${dbPath}`);
69
67
  console.log(result.applied