@walkhi/code-relax 0.1.0-beta.30 → 0.1.0-beta.32

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/README.md +95 -89
  2. package/dist/bin/cleanup-accounts.mjs +63 -63
  3. package/dist/bin/codex-remote.mjs +374 -367
  4. package/dist/bin/manage-relay-admin.mjs +20 -20
  5. package/dist/bin/migrate-relay-db.mjs +109 -109
  6. package/dist/bin/publish-android-release.mjs +63 -58
  7. package/dist/bin/publish-harmony-release.mjs +46 -0
  8. package/dist/bin/release-upload-server.mjs +174 -0
  9. package/dist/bin/self-relay-admin.mjs +8 -8
  10. package/dist/bin/self-relay-demo.mjs +33 -33
  11. package/dist/bin/self-relay-server.mjs +66 -66
  12. package/dist/build-platform.json +1 -1
  13. package/dist/get-lan-networks.ps1 +40 -40
  14. package/dist/get-shared-service-url.ps1 +6 -6
  15. package/dist/shared/app-server-events.cjs +422 -412
  16. package/dist/shared/code-browser.cjs +159 -159
  17. package/dist/shared/file-changes.cjs +31 -31
  18. package/dist/shared/file-citations.cjs +117 -117
  19. package/dist/shared/file-mentions.cjs +92 -92
  20. package/dist/shared/message-delivery.cjs +54 -54
  21. package/dist/shared/p2p-data-channel.cjs +72 -72
  22. package/dist/shared/p2p-diagnostics.cjs +28 -28
  23. package/dist/shared/p2p-file-channel.cjs +78 -74
  24. package/dist/shared/plan-pricing.cjs +32 -32
  25. package/dist/shared/question-attention.cjs +69 -0
  26. package/dist/shared/server-requests.cjs +219 -219
  27. package/dist/shared/timeline-sync.cjs +173 -173
  28. package/dist/skills/code-relax/SKILL.md +22 -22
  29. package/dist/src/archived-threads.mjs +22 -0
  30. package/dist/src/background-process.mjs +18 -18
  31. package/dist/src/bounded-process-log.mjs +63 -63
  32. package/dist/src/celsius-client.mjs +107 -107
  33. package/dist/src/code-browser.mjs +100 -100
  34. package/dist/src/desktop-launcher.mjs +46 -46
  35. package/dist/src/dots-approval-timeline.mjs +99 -99
  36. package/dist/src/dots-avatar.mjs +42 -42
  37. package/dist/src/dots-chat-projection.mjs +50 -50
  38. package/dist/src/dots-chat-server.mjs +461 -461
  39. package/dist/src/dots-message-images.mjs +319 -319
  40. package/dist/src/dots-profile.mjs +77 -77
  41. package/dist/src/dots-room-activity.mjs +94 -94
  42. package/dist/src/dots-room-client.mjs +135 -135
  43. package/dist/src/dots-room-projection.mjs +94 -94
  44. package/dist/src/dots-schedules.mjs +66 -66
  45. package/dist/src/dots-summary-tasks.mjs +32 -32
  46. package/dist/src/dots-task-catalog.mjs +430 -430
  47. package/dist/src/dots-task-files.mjs +52 -52
  48. package/dist/src/execution-health.mjs +26 -26
  49. package/dist/src/file-transfer-range.mjs +22 -22
  50. package/dist/src/file-upload-session.mjs +130 -130
  51. package/dist/src/hosted-history-app-server.mjs +103 -103
  52. package/dist/src/hosted-history-cache.mjs +113 -113
  53. package/dist/src/lan-socket-server.mjs +265 -263
  54. package/dist/src/managed-app-server.mjs +244 -244
  55. package/dist/src/message-images.mjs +9 -9
  56. package/dist/src/message-upload-files.mjs +74 -74
  57. package/dist/src/onboarding.mjs +12 -12
  58. package/dist/src/plan-pricing.mjs +47 -47
  59. package/dist/src/platform/README.md +12 -12
  60. package/dist/src/platform/codex-protocol.mjs +46 -46
  61. package/dist/src/platform/codex-runtime.mjs +3 -3
  62. package/dist/src/platform/credential-store.mjs +3 -3
  63. package/dist/src/platform/desktop-host.mjs +3 -3
  64. package/dist/src/platform/desktop-project-registration.mjs +3 -3
  65. package/dist/src/platform/desktop-project-store.mjs +208 -149
  66. package/dist/src/platform/file-opener.mjs +9 -0
  67. package/dist/src/platform/linux/README.md +3 -3
  68. package/dist/src/platform/linux/codex-runtime.mjs +56 -0
  69. package/dist/src/platform/linux/credential-store.mjs +28 -0
  70. package/dist/src/platform/linux/desktop-host.mjs +83 -0
  71. package/dist/src/platform/linux/desktop-installation.mjs +36 -0
  72. package/dist/src/platform/linux/desktop-project-registration.mjs +11 -0
  73. package/dist/src/platform/linux/network-info.mjs +11 -0
  74. package/dist/src/platform/linux/process.mjs +42 -0
  75. package/dist/src/platform/linux/project-locations.mjs +17 -0
  76. package/dist/src/platform/linux/resident-startup.mjs +52 -0
  77. package/dist/src/platform/linux/retained-runtime.mjs +76 -0
  78. package/dist/src/platform/linux/service-host.mjs +18 -0
  79. package/dist/src/platform/linux/system.mjs +49 -0
  80. package/dist/src/platform/linux/user-environment.mjs +7 -0
  81. package/dist/src/platform/macos/README.md +3 -3
  82. package/dist/src/platform/macos/codex-runtime.mjs +125 -125
  83. package/dist/src/platform/macos/credential-store.mjs +10 -10
  84. package/dist/src/platform/macos/desktop-host.mjs +82 -82
  85. package/dist/src/platform/macos/desktop-project-registration.mjs +11 -10
  86. package/dist/src/platform/macos/network-info.mjs +8 -28
  87. package/dist/src/platform/macos/project-locations.mjs +8 -8
  88. package/dist/src/platform/macos/resident-startup.mjs +84 -84
  89. package/dist/src/platform/macos/retained-runtime.mjs +127 -127
  90. package/dist/src/platform/macos/service-host.mjs +18 -18
  91. package/dist/src/platform/macos/system.mjs +29 -29
  92. package/dist/src/platform/macos/user-environment.mjs +7 -7
  93. package/dist/src/platform/native-package.mjs +58 -46
  94. package/dist/src/platform/network-info.mjs +3 -3
  95. package/dist/src/platform/path-identity.mjs +5 -5
  96. package/dist/src/platform/posix/network-candidates.mjs +23 -0
  97. package/dist/src/platform/posix/runtime-paths.mjs +25 -25
  98. package/dist/src/platform/project-locations.mjs +3 -3
  99. package/dist/src/platform/runtime-paths.mjs +8 -8
  100. package/dist/src/platform/select.mjs +5 -5
  101. package/dist/src/platform/service-host.mjs +3 -3
  102. package/dist/src/platform/user-environment.mjs +3 -3
  103. package/dist/src/platform/windows/IsolatedProcess.cs +79 -79
  104. package/dist/src/platform/windows/activate-desktop.ps1 +48 -48
  105. package/dist/src/platform/windows/background-process.mjs +30 -30
  106. package/dist/src/platform/windows/codex-runtime.mjs +215 -215
  107. package/dist/src/platform/windows/credential-store.mjs +27 -27
  108. package/dist/src/platform/windows/credential-store.ps1 +49 -49
  109. package/dist/src/platform/windows/desktop-helper.mjs +179 -179
  110. package/dist/src/platform/windows/desktop-host.mjs +58 -58
  111. package/dist/src/platform/windows/desktop-info.ps1 +14 -14
  112. package/dist/src/platform/windows/desktop-project-registration.mjs +4 -4
  113. package/dist/src/platform/windows/desktop-runtime.ps1 +10 -10
  114. package/dist/src/platform/windows/desktop-shortcuts.ps1 +21 -21
  115. package/dist/src/platform/windows/dots-profile.mjs +49 -49
  116. package/dist/src/platform/windows/launch-worker.mjs +41 -41
  117. package/dist/src/platform/windows/network-info.mjs +34 -34
  118. package/dist/src/platform/windows/project-locations.mjs +16 -16
  119. package/dist/src/platform/windows/resident-start.js +20 -20
  120. package/dist/src/platform/windows/resident-start.ps1 +7 -7
  121. package/dist/src/platform/windows/resident-startup.ps1 +83 -83
  122. package/dist/src/platform/windows/resolve-state-root.ps1 +14 -14
  123. package/dist/src/platform/windows/runtime-paths.mjs +20 -20
  124. package/dist/src/platform/windows/rustdesk-video-probe.mjs +167 -167
  125. package/dist/src/platform/windows/service-host.mjs +31 -31
  126. package/dist/src/platform/windows/start-hidden-console.ps1 +49 -49
  127. package/dist/src/platform/windows/stop-desktop.ps1 +22 -22
  128. package/dist/src/platform/windows/user-environment.mjs +50 -50
  129. package/dist/src/platform/windows/user-environment.ps1 +41 -41
  130. package/dist/src/project-archive.mjs +30 -0
  131. package/dist/src/project-create.mjs +121 -119
  132. package/dist/src/project-management.mjs +59 -69
  133. package/dist/src/project-remove.mjs +55 -0
  134. package/dist/src/project-update.mjs +56 -0
  135. package/dist/src/runtime-discovery.mjs +47 -47
  136. package/dist/src/self-relay/account-cleanup.mjs +30 -30
  137. package/dist/src/self-relay/account-connections.mjs +52 -52
  138. package/dist/src/self-relay/admin-cloud.mjs +101 -101
  139. package/dist/src/self-relay/admin-page.mjs +80 -80
  140. package/dist/src/self-relay/admin-server.mjs +74 -74
  141. package/dist/src/self-relay/admin-state.mjs +127 -127
  142. package/dist/src/self-relay/admin-style.mjs +14 -14
  143. package/dist/src/self-relay/android-releases.mjs +61 -61
  144. package/dist/src/self-relay/client.mjs +61 -61
  145. package/dist/src/self-relay/connector.mjs +439 -438
  146. package/dist/src/self-relay/debug-allowlist.mjs +33 -33
  147. package/dist/src/self-relay/demo.mjs +37 -37
  148. package/dist/src/self-relay/device-info.mjs +27 -0
  149. package/dist/src/self-relay/device-store.mjs +92 -84
  150. package/dist/src/self-relay/diagnostics.mjs +54 -54
  151. package/dist/src/self-relay/email-accounts.mjs +183 -183
  152. package/dist/src/self-relay/file-wire.mjs +13 -13
  153. package/dist/src/self-relay/lan-authorizations.mjs +71 -42
  154. package/dist/src/self-relay/lifecycle.mjs +264 -250
  155. package/dist/src/self-relay/long-pairing.mjs +40 -40
  156. package/dist/src/self-relay/mysql-state.mjs +118 -105
  157. package/dist/src/self-relay/p2p-probe.mjs +159 -159
  158. package/dist/src/self-relay/privacy-page.mjs +26 -26
  159. package/dist/src/self-relay/public-releases.mjs +52 -0
  160. package/dist/src/self-relay/rtc-file-bridge.mjs +41 -41
  161. package/dist/src/self-relay/server.mjs +1006 -932
  162. package/dist/src/self-relay/usage-daily.mjs +55 -55
  163. package/dist/src/self-relay/usage-meter.mjs +141 -141
  164. package/dist/src/self-relay/windows-route-helper.mjs +75 -75
  165. package/dist/src/self-relay/wire.mjs +36 -36
  166. package/dist/src/server.mjs +1861 -1778
  167. package/dist/src/service-control.mjs +82 -82
  168. package/dist/src/service-doctor.mjs +110 -110
  169. package/dist/src/service-health.mjs +33 -33
  170. package/dist/src/service-install.mjs +91 -91
  171. package/dist/src/service-lifecycle.mjs +138 -138
  172. package/dist/src/service-restart.mjs +81 -81
  173. package/dist/src/shared-app-server.mjs +615 -611
  174. package/dist/src/shared-catalog.mjs +132 -132
  175. package/dist/src/shared-recovery.mjs +146 -146
  176. package/dist/src/shared-thread-stream.mjs +164 -164
  177. package/dist/src/skill-install.mjs +51 -51
  178. package/dist/src/thread-title-generation.mjs +150 -150
  179. package/dist/src/turn-model-history.mjs +47 -47
  180. package/dist/src/usage-reset.mjs +17 -17
  181. package/dist/src/workstation-downloads.mjs +120 -120
  182. package/dist/tools/rtc-route-helper.ps1 +99 -99
  183. package/dist/tools/start-rtc-route-helper.ps1 +15 -15
  184. package/dist/web/vendor/markdown-it.LICENSE.txt +22 -22
  185. package/dist/web/vendor/markdown-it.umd.min.js +13 -13
  186. package/package.json +7 -6
  187. package/tools/postinstall.mjs +127 -127
@@ -1,50 +1,50 @@
1
- import path from 'node:path';
2
- import fs from 'node:fs';
3
- import { readRecord, writeRecord } from '../../service-lifecycle.mjs';
4
- import { runScript } from './desktop-host.mjs';
5
- import { managedAppServerUrl } from '../../managed-app-server.mjs';
6
-
7
- const ownershipFile = 'managed-environment.json';
8
-
9
- export async function readManagedEnvironment() {
10
- return JSON.parse(await runScript('user-environment.ps1', ['-Action', 'Read']));
11
- }
12
-
13
- export async function configureManagedEnvironment(stateRoot) {
14
- const current = await readManagedEnvironment();
15
- const ownershipPath = path.join(stateRoot, ownershipFile);
16
- const ownership = readRecord(ownershipPath);
17
- if (current.forceCliUser === '1' || current.forceCliMachine === '1') {
18
- throw new Error('CODEX_APP_SERVER_FORCE_CLI=1 会让 Codex 忽略当前内核地址;未修改该配置。');
19
- }
20
- if (current.userValue && current.userValue !== managedAppServerUrl) {
21
- throw new Error(`用户已有 CODEX_APP_SERVER_WS_URL=${current.userValue};未覆盖该配置。`);
22
- }
23
- if (current.userValue === managedAppServerUrl) {
24
- const owned = ownership?.value === managedAppServerUrl;
25
- return { configured: true, value: current.userValue, changed: false, owned };
26
- }
27
- const applied = JSON.parse(await runScript('user-environment.ps1', ['-Action', 'Set', '-Value', managedAppServerUrl]));
28
- writeRecord(ownershipPath, { name: 'CODEX_APP_SERVER_WS_URL', value: managedAppServerUrl,
29
- configuredAt: new Date().toISOString() });
30
- return { configured: true, value: applied.userValue, changed: true, owned: true };
31
- }
32
-
33
- export async function clearManagedEnvironment(stateRoot) {
34
- const ownershipPath = path.join(stateRoot, ownershipFile);
35
- const ownership = readRecord(ownershipPath);
36
- const current = await readManagedEnvironment();
37
- if (!current.userValue) {
38
- fs.rmSync(ownershipPath, { force: true });
39
- return { removed: false, preserved: false, reason: 'already-empty' };
40
- }
41
- if (ownership?.value !== managedAppServerUrl || current.userValue !== managedAppServerUrl) {
42
- fs.rmSync(ownershipPath, { force: true });
43
- return { removed: false, preserved: true, value: current.userValue,
44
- reason: ownership?.value === managedAppServerUrl ? 'user-modified' : 'not-owned' };
45
- }
46
- const result = JSON.parse(await runScript('user-environment.ps1', ['-Action', 'Clear']));
47
- if (result.userValue) throw new Error('CODEX_APP_SERVER_WS_URL 清理后读回仍不为空。');
48
- fs.rmSync(ownershipPath, { force: true });
49
- return { removed: true, preserved: false, reason: 'removed' };
50
- }
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
+ import { readRecord, writeRecord } from '../../service-lifecycle.mjs';
4
+ import { runScript } from './desktop-host.mjs';
5
+ import { managedAppServerUrl } from '../../managed-app-server.mjs';
6
+
7
+ const ownershipFile = 'managed-environment.json';
8
+
9
+ export async function readManagedEnvironment() {
10
+ return JSON.parse(await runScript('user-environment.ps1', ['-Action', 'Read']));
11
+ }
12
+
13
+ export async function configureManagedEnvironment(stateRoot) {
14
+ const current = await readManagedEnvironment();
15
+ const ownershipPath = path.join(stateRoot, ownershipFile);
16
+ const ownership = readRecord(ownershipPath);
17
+ if (current.forceCliUser === '1' || current.forceCliMachine === '1') {
18
+ throw new Error('CODEX_APP_SERVER_FORCE_CLI=1 会让 Codex 忽略当前内核地址;未修改该配置。');
19
+ }
20
+ if (current.userValue && current.userValue !== managedAppServerUrl) {
21
+ throw new Error(`用户已有 CODEX_APP_SERVER_WS_URL=${current.userValue};未覆盖该配置。`);
22
+ }
23
+ if (current.userValue === managedAppServerUrl) {
24
+ const owned = ownership?.value === managedAppServerUrl;
25
+ return { configured: true, value: current.userValue, changed: false, owned };
26
+ }
27
+ const applied = JSON.parse(await runScript('user-environment.ps1', ['-Action', 'Set', '-Value', managedAppServerUrl]));
28
+ writeRecord(ownershipPath, { name: 'CODEX_APP_SERVER_WS_URL', value: managedAppServerUrl,
29
+ configuredAt: new Date().toISOString() });
30
+ return { configured: true, value: applied.userValue, changed: true, owned: true };
31
+ }
32
+
33
+ export async function clearManagedEnvironment(stateRoot) {
34
+ const ownershipPath = path.join(stateRoot, ownershipFile);
35
+ const ownership = readRecord(ownershipPath);
36
+ const current = await readManagedEnvironment();
37
+ if (!current.userValue) {
38
+ fs.rmSync(ownershipPath, { force: true });
39
+ return { removed: false, preserved: false, reason: 'already-empty' };
40
+ }
41
+ if (ownership?.value !== managedAppServerUrl || current.userValue !== managedAppServerUrl) {
42
+ fs.rmSync(ownershipPath, { force: true });
43
+ return { removed: false, preserved: true, value: current.userValue,
44
+ reason: ownership?.value === managedAppServerUrl ? 'user-modified' : 'not-owned' };
45
+ }
46
+ const result = JSON.parse(await runScript('user-environment.ps1', ['-Action', 'Clear']));
47
+ if (result.userValue) throw new Error('CODEX_APP_SERVER_WS_URL 清理后读回仍不为空。');
48
+ fs.rmSync(ownershipPath, { force: true });
49
+ return { removed: true, preserved: false, reason: 'removed' };
50
+ }
@@ -1,41 +1,41 @@
1
- param(
2
- [ValidateSet('Read', 'Set', 'Clear')][string]$Action = 'Read',
3
- [string]$Value = ''
4
- )
5
- $ErrorActionPreference = 'Stop'
6
- [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
7
- $name = 'CODEX_APP_SERVER_WS_URL'
8
-
9
- function Broadcast-EnvironmentChange {
10
- if (-not ('CodeRelax.EnvironmentBroadcast' -as [type])) {
11
- Add-Type -Namespace CodeRelax -Name EnvironmentBroadcast -MemberDefinition @'
12
- [System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
13
- public static extern System.IntPtr SendMessageTimeout(
14
- System.IntPtr hWnd, uint Msg, System.UIntPtr wParam, string lParam,
15
- uint flags, uint timeout, out System.UIntPtr result);
16
- '@
17
- }
18
- [UIntPtr]$result = [UIntPtr]::Zero
19
- [void][CodeRelax.EnvironmentBroadcast]::SendMessageTimeout(
20
- [IntPtr]0xffff, 0x001A, [UIntPtr]::Zero, 'Environment', 0x0002, 5000, [ref]$result)
21
- }
22
-
23
- if ($Action -eq 'Set') {
24
- if ([string]::IsNullOrWhiteSpace($Value)) { throw 'Environment value is required.' }
25
- [Environment]::SetEnvironmentVariable($name, $Value, 'User')
26
- Broadcast-EnvironmentChange
27
- } elseif ($Action -eq 'Clear') {
28
- [Environment]::SetEnvironmentVariable($name, $null, 'User')
29
- Broadcast-EnvironmentChange
30
- }
31
-
32
- $userValue = [Environment]::GetEnvironmentVariable($name, 'User')
33
- $result = @{
34
- userValue = $userValue
35
- machineValue = [Environment]::GetEnvironmentVariable($name, 'Machine')
36
- forceCliUser = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'User')
37
- forceCliMachine = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'Machine')
38
- }
39
- if ($Action -eq 'Set' -and $userValue -ne $Value) { throw 'Environment value verification failed.' }
40
- if ($Action -eq 'Clear' -and -not [string]::IsNullOrEmpty($userValue)) { throw 'Environment removal verification failed.' }
41
- $result | ConvertTo-Json -Compress
1
+ param(
2
+ [ValidateSet('Read', 'Set', 'Clear')][string]$Action = 'Read',
3
+ [string]$Value = ''
4
+ )
5
+ $ErrorActionPreference = 'Stop'
6
+ [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
7
+ $name = 'CODEX_APP_SERVER_WS_URL'
8
+
9
+ function Broadcast-EnvironmentChange {
10
+ if (-not ('CodeRelax.EnvironmentBroadcast' -as [type])) {
11
+ Add-Type -Namespace CodeRelax -Name EnvironmentBroadcast -MemberDefinition @'
12
+ [System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
13
+ public static extern System.IntPtr SendMessageTimeout(
14
+ System.IntPtr hWnd, uint Msg, System.UIntPtr wParam, string lParam,
15
+ uint flags, uint timeout, out System.UIntPtr result);
16
+ '@
17
+ }
18
+ [UIntPtr]$result = [UIntPtr]::Zero
19
+ [void][CodeRelax.EnvironmentBroadcast]::SendMessageTimeout(
20
+ [IntPtr]0xffff, 0x001A, [UIntPtr]::Zero, 'Environment', 0x0002, 5000, [ref]$result)
21
+ }
22
+
23
+ if ($Action -eq 'Set') {
24
+ if ([string]::IsNullOrWhiteSpace($Value)) { throw 'Environment value is required.' }
25
+ [Environment]::SetEnvironmentVariable($name, $Value, 'User')
26
+ Broadcast-EnvironmentChange
27
+ } elseif ($Action -eq 'Clear') {
28
+ [Environment]::SetEnvironmentVariable($name, $null, 'User')
29
+ Broadcast-EnvironmentChange
30
+ }
31
+
32
+ $userValue = [Environment]::GetEnvironmentVariable($name, 'User')
33
+ $result = @{
34
+ userValue = $userValue
35
+ machineValue = [Environment]::GetEnvironmentVariable($name, 'Machine')
36
+ forceCliUser = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'User')
37
+ forceCliMachine = [Environment]::GetEnvironmentVariable('CODEX_APP_SERVER_FORCE_CLI', 'Machine')
38
+ }
39
+ if ($Action -eq 'Set' -and $userValue -ne $Value) { throw 'Environment value verification failed.' }
40
+ if ($Action -eq 'Clear' -and -not [string]::IsNullOrEmpty($userValue)) { throw 'Environment removal verification failed.' }
41
+ $result | ConvertTo-Json -Compress
@@ -0,0 +1,30 @@
1
+ import { sharedThreadProjectId, dotsThreadProjectId } from './shared-catalog.mjs';
2
+
3
+ // Enumerate metadata, not the sidebar's limited window or conversation bodies.
4
+ export async function projectArchiveCandidates(server, dotsServer, projectId) {
5
+ const projects = await server.projects();
6
+ const project = projects.find(value => value.id === projectId);
7
+ if (!project) throw Object.assign(new Error('项目不存在,请刷新列表。'), { statusCode: 404 });
8
+ const local = [];
9
+ let cursor;
10
+ do {
11
+ const page = await server.request('thread/list', { limit: 100, archived: false,
12
+ sortKey: 'recency_at', sortDirection: 'desc', ...(cursor ? { cursor } : {}) });
13
+ local.push(...page.data); cursor = page.nextCursor;
14
+ } while (cursor);
15
+ let hosted = [], catalogError = '';
16
+ if (dotsServer) {
17
+ try { hosted = await dotsServer.taskCatalog(false, true); }
18
+ catch (error) { catalogError = `云端目录读取失败,本次仅包含本机对话:${error.message}`; }
19
+ }
20
+ const threads = [];
21
+ for (const [hostId, values, group] of [['local', local, sharedThreadProjectId], ['durable', hosted, dotsThreadProjectId]]) {
22
+ for (const thread of values) {
23
+ if (thread.threadSource === 'aeon' || group(thread, projects) !== projectId) continue;
24
+ const status = typeof thread.status === 'string' ? thread.status : thread.status?.type || 'unknown';
25
+ threads.push({ id: thread.id, hostId, projectId, threadSource: thread.threadSource,
26
+ title: thread.name || thread.preview || thread.id, status });
27
+ }
28
+ }
29
+ return { projectId, threads, ...(catalogError ? { catalogError } : {}) };
30
+ }
@@ -1,119 +1,121 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { createHash } from 'node:crypto';
4
- import { readRecord, writeRecord } from './service-lifecycle.mjs';
5
- import { projectRoots, projectSummary } from './project-management.mjs';
6
- import { projectLocations } from './platform/project-locations.mjs';
7
- import { withDesktopProjectRegistration } from './platform/desktop-project-registration.mjs';
8
-
9
- const pending = new Map();
10
- const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
11
- const fail = message => { throw Object.assign(new Error(message), { statusCode: 400 }); };
12
- const pathKey = value => process.platform === 'win32' ? path.normalize(value).toLowerCase() : path.normalize(value);
13
-
14
- function defaultName(name) {
15
- let value = path.basename(name).trim().replace(/[<>:"/\\|?*\x00-\x1f]/g, '_').replace(/[ .]+$/g, '') || 'New project';
16
- if (/^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/i.test(value)) value = `_${value}`;
17
- return value;
18
- }
19
-
20
- export async function createWorkstationProject(server, stateRoot, codexDataRoot, body, dependencies = {}) {
21
- if (!uuid.test(body.idempotencyKey || '')) fail('项目创建标识无效。');
22
- const name = typeof body.name === 'string' ? body.name.trim() : '';
23
- if (!name) fail('请输入项目名称。');
24
- if (!Array.isArray(body.roots) || body.roots.some(root => typeof root?.path !== 'string' || !path.isAbsolute(root.path.trim()))) {
25
- fail('项目文件夹路径无效。');
26
- }
27
- const roots = body.roots.map(root => ({ path: path.normalize(root.path.trim()) }));
28
- const signature = createHash('sha256').update(JSON.stringify({ name, roots })).digest('hex');
29
- const directory = path.join(stateRoot, 'project-create-operations');
30
- const record = path.join(directory, `${body.idempotencyKey}.json`);
31
- const running = pending.get(record);
32
- if (running) {
33
- if (running.signature !== signature) fail('同一个创建请求不能修改项目名称或目录。');
34
- return running.promise;
35
- }
36
- const promise = perform().finally(() => pending.delete(record));
37
- pending.set(record, { signature, promise });
38
- return promise;
39
-
40
- async function perform() {
41
- await fs.mkdir(directory, { recursive: true });
42
- let operation = readRecord(record);
43
- if (operation && operation.signature !== signature) fail('项目创建标识已用于其他内容,请重新打开项目编辑器。');
44
- if (operation?.result) return operation.result;
45
- operation ||= { signature, name, roots };
46
- const save = () => writeRecord(record, operation);
47
- const rpc = (method, params) => server.request(method, params);
48
- const register = dependencies.registration || withDesktopProjectRegistration;
49
- try {
50
- return await register({ stateRoot, codexDataRoot, operationId: body.idempotencyKey,
51
- confirmed: body.confirmDesktopRestart === true, serverUrl: server.url }, async desktop => {
52
- // The restart confirmation and state checks happen before any
53
- // directory or project write. Existing folders are never moved or copied.
54
- if (!operation.resolvedRoots) {
55
- operation.resolvedRoots = await projectRoots(rpc, roots);
56
- if (!operation.resolvedRoots.length) {
57
- const locations = await (dependencies.locations || projectLocations)();
58
- await rpc('fs/createDirectory', { path: locations.defaultParent, recursive: true });
59
- const entries = (await rpc('fs/readDirectory', { path: locations.defaultParent })).entries;
60
- const names = new Set(entries.map(entry => entry.fileName.toLowerCase()));
61
- const base = defaultName(name);
62
- let folder = base;
63
- for (let suffix = 2; names.has(folder.toLowerCase()); suffix++) folder = `${base} ${suffix}`;
64
- operation.defaultDirectory = path.join(locations.defaultParent, folder);
65
- operation.resolvedRoots = [{ path: operation.defaultDirectory }];
66
- }
67
- save();
68
- }
69
- if (operation.defaultDirectory && !operation.directoryCreated) {
70
- if (operation.directoryAttempted) {
71
- // On an explicit retry, keep the originally allocated directory. Never
72
- // allocate another name after an interrupted createDirectory response.
73
- await projectRoots(rpc, operation.resolvedRoots);
74
- } else {
75
- operation.directoryAttempted = true; save();
76
- await rpc('fs/createDirectory', { path: operation.defaultDirectory, recursive: false });
77
- }
78
- operation.directoryCreated = true; save();
79
- try {
80
- const result = await rpc('command/exec', { command: ['git', 'init'], cwd: operation.defaultDirectory, timeoutMs: 10000 });
81
- if (result.exitCode !== 0) throw new Error(result.stderr || result.stdout || `退出码 ${result.exitCode}`);
82
- } catch (error) { operation.gitWarning = `项目目录已创建,Git 初始化未完成:${error.message}`; save(); }
83
- }
84
- const resolvedRoots = await projectRoots(rpc, operation.resolvedRoots);
85
- if (!operation.projectId) {
86
- operation.createAttempted = true; save();
87
- // Native project/create owns idempotency; a retry uses this exact key
88
- // and original roots on the same server, never a second transport.
89
- const created = await rpc('project/create', { name, roots: resolvedRoots, idempotencyKey: body.idempotencyKey });
90
- operation.projectId = created.project.id; save();
91
- }
92
- const { project } = await rpc('project/read', { projectId: operation.projectId });
93
- if (project.id !== operation.projectId || project.name !== name || project.roots.length !== resolvedRoots.length
94
- || project.roots.some((root, index) => pathKey(root.path) !== pathKey(resolvedRoots[index].path))) {
95
- throw new Error('已创建项目的名称或目录发生变化,未覆盖其内容。');
96
- }
97
- if (!operation.ordered) {
98
- const first = (await rpc('project/list', { limit: 1, sortKey: 'position', sortDirection: 'asc' })).data[0];
99
- if (first && first.id !== project.id) await rpc('project/move', { projectId: project.id, beforeProjectId: first.id });
100
- operation.ordered = true; save();
101
- }
102
- const desktopRegistration = await desktop.register(project, operation, save);
103
- operation.result = { project: projectSummary(project), desktopRegistration,
104
- ...(operation.gitWarning ? { warning: operation.gitWarning } : {}) };
105
- save();
106
- return operation.result;
107
- });
108
- } catch (error) {
109
- if (operation.projectId || operation.createAttempted || operation.directoryAttempted) {
110
- error.details = { ...error.details, projectCreationPending: true,
111
- ...(operation.projectId ? { createdProjectId: operation.projectId } : {}) };
112
- error.message += operation.projectId
113
- ? ' 项目已创建,请继续完成桌面登记;会沿用同一项目,不会重复创建。'
114
- : ' 请继续核对本次创建;会沿用原请求标识和目录。';
115
- } else error.details = { ...error.details, projectCreationPending: false };
116
- throw error;
117
- }
118
- }
119
- }
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { createHash } from 'node:crypto';
4
+ import { readRecord, writeRecord } from './service-lifecycle.mjs';
5
+ import { projectRoots, projectSummary } from './project-management.mjs';
6
+ import { projectLocations } from './platform/project-locations.mjs';
7
+ import { withDesktopProjectRegistration } from './platform/desktop-project-registration.mjs';
8
+
9
+ const pending = new Map();
10
+ const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
11
+ const fail = message => { throw Object.assign(new Error(message), { statusCode: 400 }); };
12
+ const pathKey = value => process.platform === 'win32' ? path.normalize(value).toLowerCase() : path.normalize(value);
13
+
14
+ function defaultName(name) {
15
+ let value = path.basename(name).trim().replace(/[<>:"/\\|?*\x00-\x1f]/g, '_').replace(/[ .]+$/g, '') || 'New project';
16
+ if (/^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/i.test(value)) value = `_${value}`;
17
+ return value;
18
+ }
19
+
20
+ export async function createWorkstationProject(server, stateRoot, codexDataRoot, body, dependencies = {}) {
21
+ if (!uuid.test(body.idempotencyKey || '')) fail('项目创建标识无效。');
22
+ const name = typeof body.name === 'string' ? body.name.trim() : '';
23
+ if (!name) fail('请输入项目名称。');
24
+ if (!Array.isArray(body.roots) || body.roots.some(root => typeof root?.path !== 'string' || !path.isAbsolute(root.path.trim()))) {
25
+ fail('项目文件夹路径无效。');
26
+ }
27
+ const roots = body.roots.map(root => ({ path: path.normalize(root.path.trim()) }));
28
+ const signature = createHash('sha256').update(JSON.stringify({ name, roots })).digest('hex');
29
+ const directory = path.join(stateRoot, 'project-create-operations');
30
+ const record = path.join(directory, `${body.idempotencyKey}.json`);
31
+ const running = pending.get(record);
32
+ if (running) {
33
+ if (running.signature !== signature) fail('同一个创建请求不能修改项目名称或目录。');
34
+ return running.promise;
35
+ }
36
+ const promise = perform().finally(() => pending.delete(record));
37
+ pending.set(record, { signature, promise });
38
+ return promise;
39
+
40
+ async function perform() {
41
+ await fs.mkdir(directory, { recursive: true });
42
+ let operation = readRecord(record);
43
+ if (operation && operation.signature !== signature) fail('项目创建标识已用于其他内容,请重新打开项目编辑器。');
44
+ if (operation?.result) return operation.result;
45
+ operation ||= { signature, name, roots };
46
+ const save = () => writeRecord(record, operation);
47
+ const rpc = (method, params) => server.request(method, params);
48
+ const register = dependencies.registration || withDesktopProjectRegistration;
49
+ try {
50
+ return await register({ stateRoot, codexDataRoot, operationId: body.idempotencyKey,
51
+ confirmed: body.confirmDesktopRestart === true, serverUrl: server.url }, async desktop => {
52
+ // The restart confirmation and state checks happen before any
53
+ // directory or project write. Existing folders are never moved or copied.
54
+ let validatedRoots;
55
+ if (!operation.resolvedRoots) {
56
+ validatedRoots = await projectRoots(rpc, roots);
57
+ operation.resolvedRoots = validatedRoots;
58
+ if (!operation.resolvedRoots.length) {
59
+ const locations = await (dependencies.locations || projectLocations)();
60
+ await rpc('fs/createDirectory', { path: locations.defaultParent, recursive: true });
61
+ const entries = (await rpc('fs/readDirectory', { path: locations.defaultParent })).entries;
62
+ const names = new Set(entries.map(entry => entry.fileName.toLowerCase()));
63
+ const base = defaultName(name);
64
+ let folder = base;
65
+ for (let suffix = 2; names.has(folder.toLowerCase()); suffix++) folder = `${base} ${suffix}`;
66
+ operation.defaultDirectory = path.join(locations.defaultParent, folder);
67
+ operation.resolvedRoots = [{ path: operation.defaultDirectory }];
68
+ }
69
+ save();
70
+ }
71
+ if (operation.defaultDirectory && !operation.directoryCreated) {
72
+ if (operation.directoryAttempted) {
73
+ // On an explicit retry, keep the originally allocated directory. Never
74
+ // allocate another name after an interrupted createDirectory response.
75
+ await projectRoots(rpc, operation.resolvedRoots);
76
+ } else {
77
+ operation.directoryAttempted = true; save();
78
+ await rpc('fs/createDirectory', { path: operation.defaultDirectory, recursive: false });
79
+ }
80
+ operation.directoryCreated = true; save();
81
+ try {
82
+ const result = await rpc('command/exec', { command: ['git', 'init'], cwd: operation.defaultDirectory, timeoutMs: 10000 });
83
+ if (result.exitCode !== 0) throw new Error(result.stderr || result.stdout || `退出码 ${result.exitCode}`);
84
+ } catch (error) { operation.gitWarning = `项目目录已创建,Git 初始化未完成:${error.message}`; save(); }
85
+ }
86
+ const resolvedRoots = validatedRoots?.length ? validatedRoots : await projectRoots(rpc, operation.resolvedRoots);
87
+ if (!operation.projectId) {
88
+ operation.createAttempted = true; save();
89
+ // Native project/create owns idempotency; a retry uses this exact key
90
+ // and original roots on the same server, never a second transport.
91
+ const created = await rpc('project/create', { name, roots: resolvedRoots, idempotencyKey: body.idempotencyKey });
92
+ operation.projectId = created.project.id; save();
93
+ }
94
+ const { project } = await rpc('project/read', { projectId: operation.projectId });
95
+ if (project.id !== operation.projectId || project.name !== name || project.roots.length !== resolvedRoots.length
96
+ || project.roots.some((root, index) => pathKey(root.path) !== pathKey(resolvedRoots[index].path))) {
97
+ throw new Error('已创建项目的名称或目录发生变化,未覆盖其内容。');
98
+ }
99
+ if (!operation.ordered) {
100
+ const first = (await rpc('project/list', { limit: 1, sortKey: 'position', sortDirection: 'asc' })).data[0];
101
+ if (first && first.id !== project.id) await rpc('project/move', { projectId: project.id, beforeProjectId: first.id });
102
+ operation.ordered = true; save();
103
+ }
104
+ const desktopRegistration = await desktop.register(project, operation, save);
105
+ operation.result = { project: projectSummary(project), desktopRegistration,
106
+ ...(operation.gitWarning ? { warning: operation.gitWarning } : {}) };
107
+ save();
108
+ return operation.result;
109
+ });
110
+ } catch (error) {
111
+ if (operation.projectId || operation.createAttempted || operation.directoryAttempted) {
112
+ error.details = { ...error.details, projectCreationPending: true,
113
+ ...(operation.projectId ? { createdProjectId: operation.projectId } : {}) };
114
+ error.message += operation.projectId
115
+ ? ' 项目已创建,请继续完成桌面登记;会沿用同一项目,不会重复创建。'
116
+ : ' 请继续核对本次创建;会沿用原请求标识和目录。';
117
+ } else error.details = { ...error.details, projectCreationPending: false };
118
+ throw error;
119
+ }
120
+ }
121
+ }
@@ -1,69 +1,59 @@
1
- import path from 'node:path';
2
-
3
- const fail = (message, statusCode = 400) => { throw Object.assign(new Error(message), { statusCode }); };
4
- const pathKey = value => process.platform === 'win32' ? value.toLowerCase() : value;
5
-
6
- function absoluteDirectory(value) {
7
- if (typeof value !== 'string' || !value.trim() || !path.isAbsolute(value.trim())) fail('请输入电脑上的绝对文件夹路径。');
8
- return path.normalize(value.trim());
9
- }
10
-
11
- async function directory(rpc, value) {
12
- const target = absoluteDirectory(value);
13
- const stat = await rpc('fs/getMetadata', { path: target });
14
- if (!stat.isDirectory) fail(`此路径不是文件夹:${target}`);
15
- return target;
16
- }
17
-
18
- function folderName(value) {
19
- if (typeof value !== 'string' || !value.trim() || /[<>:"/\\|?*\x00-\x1f]/.test(value) || /[ .]$/.test(value)
20
- || /^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/i.test(value) || ['.', '..'].includes(value)) {
21
- fail('文件夹名称无效,请勿使用路径分隔符或系统保留名称。');
22
- }
23
- return value;
24
- }
25
-
26
- export async function projectRoots(rpc, roots) {
27
- if (!Array.isArray(roots)) fail('项目文件夹列表无效。');
28
- const result = [], seen = new Set();
29
- for (const root of roots) {
30
- const target = await directory(rpc, root?.path);
31
- const key = pathKey(target);
32
- if (seen.has(key)) fail(`重复的项目文件夹:${target}`);
33
- seen.add(key); result.push({ path: target });
34
- }
35
- return result;
36
- }
37
-
38
- export function projectSummary(project) {
39
- return { projectId: project.id, name: project.name, label: project.name, roots: project.roots,
40
- path: project.roots[0]?.path || '', cwd: project.roots[0]?.path || '', hostId: 'local' };
41
- }
42
-
43
- export async function browseProjectFolders(rpc, locations, value) {
44
- const target = await directory(rpc, value || locations.home);
45
- const entries = (await rpc('fs/readDirectory', { path: target })).entries
46
- .filter(entry => entry.isDirectory).map(entry => ({ name: entry.fileName, path: path.join(target, entry.fileName) }))
47
- .sort((a, b) => a.name.localeCompare(b.name, 'zh-CN', { numeric: true }));
48
- return { path: target, parent: path.dirname(target) === target ? null : path.dirname(target), entries, ...locations };
49
- }
50
-
51
- export async function createProjectFolder(rpc, body) {
52
- const parent = await directory(rpc, body.parent);
53
- const name = folderName(body.name);
54
- const entries = (await rpc('fs/readDirectory', { path: parent })).entries;
55
- if (entries.some(entry => pathKey(entry.fileName) === pathKey(name))) fail('同名文件夹已存在,请选择它或使用其他名称。', 409);
56
- const target = path.join(parent, name);
57
- await rpc('fs/createDirectory', { path: target, recursive: false });
58
- return { path: target };
59
- }
60
-
61
- export async function saveProject(rpc, locations, body, projectId = null) {
62
- // Native creation and Desktop registration are coordinated by project-create.mjs.
63
- if (!projectId) fail('新建项目必须通过工作站项目创建流程。', 503);
64
- const name = typeof body.name === 'string' ? body.name.trim() : '';
65
- if (!name) fail('请输入项目名称。');
66
- const roots = await projectRoots(rpc, body.roots);
67
- const result = await rpc('project/update', { name, roots, projectId });
68
- return { project: projectSummary(result.project) };
69
- }
1
+ import path from 'node:path';
2
+
3
+ const fail = (message, statusCode = 400) => { throw Object.assign(new Error(message), { statusCode }); };
4
+ const pathKey = value => process.platform === 'win32' ? value.toLowerCase() : value;
5
+
6
+ function absoluteDirectory(value) {
7
+ if (typeof value !== 'string' || !value.trim() || !path.isAbsolute(value.trim())) fail('请输入电脑上的绝对文件夹路径。');
8
+ return path.normalize(value.trim());
9
+ }
10
+
11
+ async function directory(rpc, value) {
12
+ const target = absoluteDirectory(value);
13
+ const stat = await rpc('fs/getMetadata', { path: target });
14
+ if (!stat.isDirectory) fail(`此路径不是文件夹:${target}`);
15
+ return target;
16
+ }
17
+
18
+ function folderName(value) {
19
+ if (typeof value !== 'string' || !value.trim() || /[<>:"/\\|?*\x00-\x1f]/.test(value) || /[ .]$/.test(value)
20
+ || /^(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)/i.test(value) || ['.', '..'].includes(value)) {
21
+ fail('文件夹名称无效,请勿使用路径分隔符或系统保留名称。');
22
+ }
23
+ return value;
24
+ }
25
+
26
+ export async function projectRoots(rpc, roots) {
27
+ if (!Array.isArray(roots)) fail('项目文件夹列表无效。');
28
+ const result = [], seen = new Set();
29
+ for (const root of roots) {
30
+ const target = await directory(rpc, root?.path);
31
+ const key = pathKey(target);
32
+ if (seen.has(key)) fail(`重复的项目文件夹:${target}`);
33
+ seen.add(key); result.push({ path: target });
34
+ }
35
+ return result;
36
+ }
37
+
38
+ export function projectSummary(project) {
39
+ return { projectId: project.id, name: project.name, label: project.name, roots: project.roots,
40
+ path: project.roots[0]?.path || '', cwd: project.roots[0]?.path || '', hostId: 'local' };
41
+ }
42
+
43
+ export async function browseProjectFolders(rpc, locations, value) {
44
+ const target = absoluteDirectory(value || locations?.home);
45
+ const entries = (await rpc('fs/readDirectory', { path: target })).entries
46
+ .filter(entry => entry.isDirectory).map(entry => ({ name: entry.fileName, path: path.join(target, entry.fileName) }))
47
+ .sort((a, b) => a.name.localeCompare(b.name, 'zh-CN', { numeric: true }));
48
+ return { path: target, parent: path.dirname(target) === target ? null : path.dirname(target), entries, ...(locations || {}) };
49
+ }
50
+
51
+ export async function createProjectFolder(rpc, body) {
52
+ const parent = await directory(rpc, body.parent);
53
+ const name = folderName(body.name);
54
+ const entries = (await rpc('fs/readDirectory', { path: parent })).entries;
55
+ if (entries.some(entry => pathKey(entry.fileName) === pathKey(name))) fail('同名文件夹已存在,请选择它或使用其他名称。', 409);
56
+ const target = path.join(parent, name);
57
+ await rpc('fs/createDirectory', { path: target, recursive: false });
58
+ return { path: target };
59
+ }