-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ts
More file actions
219 lines (211 loc) · 9.85 KB
/
Copy pathplugin.ts
File metadata and controls
219 lines (211 loc) · 9.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { DEFAULT_MAX_INSPECT_TARGETS } from '../shared/workspace-observation.js'
import type { HostPluginContext } from './contracts.js'
import { ideGateway } from './gateway.js'
import { DEFAULT_SEARCH_LIMITS } from './search.js'
import { workspaceSearchProvider } from './search-provider.js'
import { resolveTerminalShell } from './terminal.js'
import { terminalProvider } from './terminal-provider.js'
import { workspaceFilesProvider } from './workspace-files-provider.js'
import { workspaceMutationsGateway } from './workspace-mutations-gateway.js'
import { workspaceMutationsProvider } from './workspace-mutations-provider.js'
import { workspaceMutationBackendProvider } from './mutation-backend-provider.js'
import { workspaceResourcesProvider } from './workspace-resources-provider.js'
export interface Config {
staticRoot?: string
maxFileBytes?: number
maxMediaBytes?: number
maxRequestBytes?: number
maxDirectoryEntries?: number
maxInspectTargets?: number
maxInspectDirectoryEntries?: number
terminalShell?: string
terminalArgs?: string[]
maxTerminalSessions?: number
maxTerminalMessageBytes?: number
maxTerminalInputBytes?: number
maxTerminalBufferedBytes?: number
maxSearchFileResults?: number
maxSearchTextResults?: number
maxSearchCandidates?: number
maxSearchRawBytes?: number
maxSearchPreviewBytes?: number
maxSearchQueryBytes?: number
maxSearchLineBytes?: number
maxSearchResponseBytes?: number
maxConcurrentSearches?: number
searchTimeoutMs?: number
searchTerminationGraceMs?: number
maxQueuedMutations?: number
mutationReceiptTtlMs?: number
maxMutationReceipts?: number
maxMutationOperationIds?: number
maxMutationPurgeJobs?: number
maxMutationPurgeEntries?: number
maxMutationRequestBytes?: number
}
export interface ResolvedConfig {
routePrefix: string
staticRoot: string
maxFileBytes: number
maxMediaBytes: number
maxRequestBytes: number
maxDirectoryEntries: number
maxInspectTargets: number
maxInspectDirectoryEntries: number
terminalShell: string
terminalArgs: string[]
maxTerminalSessions: number
maxTerminalMessageBytes: number
maxTerminalInputBytes: number
maxTerminalBufferedBytes: number
maxSearchFileResults: number
maxSearchTextResults: number
maxSearchCandidates: number
maxSearchRawBytes: number
maxSearchPreviewBytes: number
maxSearchQueryBytes: number
maxSearchLineBytes: number
maxSearchResponseBytes: number
maxConcurrentSearches: number
searchTimeoutMs: number
searchTerminationGraceMs: number
maxQueuedMutations: number
mutationReceiptTtlMs: number
maxMutationReceipts: number
maxMutationOperationIds: number
maxMutationPurgeJobs: number
maxMutationPurgeEntries: number
maxMutationRequestBytes: number
}
function positiveInteger(value: number | undefined, fallback: number, name: string, maximum: number): number {
const resolved = value ?? fallback
if (!Number.isSafeInteger(resolved) || resolved <= 0 || resolved > maximum) {
throw new Error(`dsh-code-ide: ${name} must be a positive integer no greater than ${String(maximum)}`)
}
return resolved
}
function defaultStaticRoot(): string {
const compiled = fileURLToPath(new URL('../../client/', import.meta.url))
if (existsSync(compiled)) return compiled
return fileURLToPath(new URL('../../dist/client/', import.meta.url))
}
/** Resolve and validate Host limits before any child component is registered. */
export function resolveConfig(config: Config): ResolvedConfig {
const routePrefix = '/dsh-code-ide'
const maxFileBytes = positiveInteger(config.maxFileBytes, 4 * 1024 * 1024, 'maxFileBytes', 64 * 1024 * 1024)
const maxDirectoryEntries = positiveInteger(config.maxDirectoryEntries, 5_000, 'maxDirectoryEntries', 100_000)
const terminal = resolveTerminalShell(config.terminalShell)
return {
routePrefix,
staticRoot: config.staticRoot ?? defaultStaticRoot(),
maxFileBytes,
maxMediaBytes: positiveInteger(
config.maxMediaBytes,
512 * 1024 * 1024,
'maxMediaBytes',
8 * 1024 * 1024 * 1024,
),
maxRequestBytes: positiveInteger(
config.maxRequestBytes,
maxFileBytes * 6 + 64 * 1024,
'maxRequestBytes',
64 * 1024 * 1024 * 6 + 64 * 1024,
),
maxDirectoryEntries,
maxInspectTargets: positiveInteger(
config.maxInspectTargets,
DEFAULT_MAX_INSPECT_TARGETS,
'maxInspectTargets',
4_096,
),
maxInspectDirectoryEntries: positiveInteger(
config.maxInspectDirectoryEntries,
maxDirectoryEntries,
'maxInspectDirectoryEntries',
100_000,
),
terminalShell: terminal.shell,
terminalArgs: config.terminalArgs ?? terminal.args,
maxTerminalSessions: positiveInteger(config.maxTerminalSessions, 8, 'maxTerminalSessions', 64),
maxTerminalMessageBytes: positiveInteger(config.maxTerminalMessageBytes, 256 * 1024, 'maxTerminalMessageBytes', 4 * 1024 * 1024),
maxTerminalInputBytes: positiveInteger(config.maxTerminalInputBytes, 64 * 1024, 'maxTerminalInputBytes', 1024 * 1024),
maxTerminalBufferedBytes: positiveInteger(config.maxTerminalBufferedBytes, 4 * 1024 * 1024, 'maxTerminalBufferedBytes', 64 * 1024 * 1024),
maxSearchFileResults: positiveInteger(config.maxSearchFileResults, DEFAULT_SEARCH_LIMITS.maxFileResults, 'maxSearchFileResults', 10_000),
maxSearchTextResults: positiveInteger(config.maxSearchTextResults, DEFAULT_SEARCH_LIMITS.maxTextResults, 'maxSearchTextResults', 100_000),
maxSearchCandidates: positiveInteger(config.maxSearchCandidates, DEFAULT_SEARCH_LIMITS.maxCandidates, 'maxSearchCandidates', 1_000_000),
maxSearchRawBytes: positiveInteger(config.maxSearchRawBytes, DEFAULT_SEARCH_LIMITS.maxRawBytes, 'maxSearchRawBytes', 64 * 1024 * 1024),
maxSearchPreviewBytes: positiveInteger(config.maxSearchPreviewBytes, DEFAULT_SEARCH_LIMITS.maxPreviewBytes, 'maxSearchPreviewBytes', 64 * 1024),
maxSearchQueryBytes: positiveInteger(config.maxSearchQueryBytes, DEFAULT_SEARCH_LIMITS.maxQueryBytes, 'maxSearchQueryBytes', 64 * 1024),
maxSearchLineBytes: positiveInteger(config.maxSearchLineBytes, DEFAULT_SEARCH_LIMITS.maxLineBytes, 'maxSearchLineBytes', 16 * 1024 * 1024),
maxSearchResponseBytes: positiveInteger(config.maxSearchResponseBytes, DEFAULT_SEARCH_LIMITS.maxResponseBytes, 'maxSearchResponseBytes', 64 * 1024 * 1024),
maxConcurrentSearches: positiveInteger(config.maxConcurrentSearches, DEFAULT_SEARCH_LIMITS.maxConcurrent, 'maxConcurrentSearches', 32),
searchTimeoutMs: positiveInteger(config.searchTimeoutMs, DEFAULT_SEARCH_LIMITS.timeoutMs, 'searchTimeoutMs', 10 * 60 * 1_000),
searchTerminationGraceMs: positiveInteger(config.searchTerminationGraceMs, DEFAULT_SEARCH_LIMITS.terminationGraceMs, 'searchTerminationGraceMs', 30_000),
maxQueuedMutations: positiveInteger(config.maxQueuedMutations, 64, 'maxQueuedMutations', 4_096),
mutationReceiptTtlMs: positiveInteger(config.mutationReceiptTtlMs, 5 * 60_000, 'mutationReceiptTtlMs', 24 * 60 * 60_000),
maxMutationReceipts: positiveInteger(config.maxMutationReceipts, 1_024, 'maxMutationReceipts', 65_536),
maxMutationOperationIds: positiveInteger(config.maxMutationOperationIds, 65_536, 'maxMutationOperationIds', 262_144),
maxMutationPurgeJobs: positiveInteger(config.maxMutationPurgeJobs, 1_024, 'maxMutationPurgeJobs', 65_536),
maxMutationPurgeEntries: positiveInteger(config.maxMutationPurgeEntries, 100_000, 'maxMutationPurgeEntries', 1_000_000),
maxMutationRequestBytes: positiveInteger(config.maxMutationRequestBytes, 64 * 1024, 'maxMutationRequestBytes', 256 * 1024),
}
}
/** Stable Cordis plugin name. */
export const name = 'dsh-code-ide'
/** Root orchestration deliberately owns no Host services or routes itself. */
export const inject: string[] = []
/** Compose independently reloadable providers with their route-owning gateway. */
export function apply(ctx: HostPluginContext, input: Config = {}): void {
const config = resolveConfig(input)
ctx.plugin(workspaceResourcesProvider, {
maxQueuedMutations: config.maxQueuedMutations,
})
ctx.plugin(workspaceMutationBackendProvider, {})
ctx.plugin(workspaceFilesProvider, {
maxFileBytes: config.maxFileBytes,
maxMediaBytes: config.maxMediaBytes,
maxDirectoryEntries: config.maxDirectoryEntries,
maxInspectTargets: config.maxInspectTargets,
maxInspectDirectoryEntries: config.maxInspectDirectoryEntries,
})
ctx.plugin(workspaceMutationsProvider, {
receiptTtlMs: config.mutationReceiptTtlMs,
maxReceipts: config.maxMutationReceipts,
maxOperationIds: config.maxMutationOperationIds,
maxPurgeJobs: config.maxMutationPurgeJobs,
maxPurgeEntries: config.maxMutationPurgeEntries,
})
ctx.plugin(terminalProvider, {
terminalShell: config.terminalShell,
terminalArgs: config.terminalArgs,
maxTerminalSessions: config.maxTerminalSessions,
maxTerminalMessageBytes: config.maxTerminalMessageBytes,
maxTerminalInputBytes: config.maxTerminalInputBytes,
maxTerminalBufferedBytes: config.maxTerminalBufferedBytes,
})
ctx.plugin(workspaceSearchProvider, {
maxFileBytes: config.maxFileBytes,
maxFileResults: config.maxSearchFileResults,
maxTextResults: config.maxSearchTextResults,
maxCandidates: config.maxSearchCandidates,
maxRawBytes: config.maxSearchRawBytes,
maxPreviewBytes: config.maxSearchPreviewBytes,
maxQueryBytes: config.maxSearchQueryBytes,
maxLineBytes: config.maxSearchLineBytes,
maxResponseBytes: config.maxSearchResponseBytes,
maxConcurrent: config.maxConcurrentSearches,
timeoutMs: config.searchTimeoutMs,
terminationGraceMs: config.searchTerminationGraceMs,
})
ctx.plugin(ideGateway, {
routePrefix: config.routePrefix,
staticRoot: config.staticRoot,
maxRequestBytes: config.maxRequestBytes,
maxTerminalSessions: config.maxTerminalSessions,
})
ctx.plugin(workspaceMutationsGateway, {
maxRequestBytes: config.maxMutationRequestBytes,
})
}