@oar-sh/oar 0.9.5 → 0.9.7
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.
- package/.github/extensions/web-relay/polling/polling-loop.mjs +12 -32
- package/.github/extensions/web-relay/skills/question-bridge.mjs +14 -39
- package/CHANGELOG.md +340 -0
- package/README.md +196 -26
- package/package.json +2 -1
- package/server/README.md +174 -7
- package/server/claude-cloud-worker/claude-cloud-event-normalizer.mjs +340 -0
- package/server/claude-cloud-worker/claude-cloud-session-process.mjs +1325 -0
- package/server/claude-cloud-worker/claude-cloud-session-worker.mjs +155 -0
- package/server/claude-worker/claude-remote-relay-tool.mjs +2 -0
- package/server/claude-worker/claude-sdk-adapter.mjs +18 -2
- package/server/claude-worker/claude-session-process.mjs +151 -1
- package/server/claude-worker/claude-session-worker.mjs +6 -0
- package/server/claude-worker/claude-turn-failure.mjs +92 -0
- package/server/claude-worker/claude-turn-publisher.mjs +52 -3
- package/server/claude-worker/sdk-message-normalizer.mjs +13 -1
- package/server/copilot-worker/copilot-model-switch.mjs +29 -3
- package/server/copilot-worker/copilot-question-bridge.mjs +2 -4
- package/server/copilot-worker/copilot-runtime-tree.mjs +91 -0
- package/server/copilot-worker/copilot-sdk-adapter.mjs +48 -8
- package/server/copilot-worker/copilot-sdk-session-process.mjs +897 -166
- package/server/cursor-worker/cursor-sdk-adapter.mjs +80 -13
- package/server/cursor-worker/cursor-turn-runner.mjs +5 -2
- package/server/db-schema.mjs +24 -0
- package/server/grok-worker/acp-client.mjs +68 -12
- package/server/grok-worker/grok-sdk-adapter.mjs +4 -0
- package/server/grok-worker/grok-turn-runner.mjs +6 -2
- package/server/migrations/0006-workspace-root-settings.mjs +67 -0
- package/server/migrations/0007-claude-cloud.mjs +82 -0
- package/server/public/app/agent-sessions-settings-ui.js +197 -0
- package/server/public/app/agent-sessions-settings.mjs +134 -0
- package/server/public/app/api-client.js +160 -6
- package/server/public/app/attachments-view.js +20 -1
- package/server/public/app/attribution-control.mjs +46 -0
- package/server/public/app/bootstrap.js +347 -31
- package/server/public/app/claude-cloud-conversation-ui.js +110 -0
- package/server/public/app/claude-cloud-settings-ui.js +374 -0
- package/server/public/app/claude-cloud-ui.mjs +611 -0
- package/server/public/app/composer-control-state.mjs +15 -3
- package/server/public/app/context-menu.mjs +140 -0
- package/server/public/app/context-tier-options.mjs +4 -0
- package/server/public/app/conversation-origin-ui.js +27 -0
- package/server/public/app/conversation-provider-indicator.mjs +22 -4
- package/server/public/app/conversation-view.js +178 -8
- package/server/public/app/cwd-picker.js +12 -0
- package/server/public/app/journal-view.js +704 -28
- package/server/public/app/markdown-strikethrough.mjs +31 -0
- package/server/public/app/math-dollars.mjs +89 -0
- package/server/public/app/model-selector-options.mjs +1 -1
- package/server/public/app/plan-usage-view.mjs +36 -8
- package/server/public/app/relay-board-inline.mjs +70 -0
- package/server/public/app/relay-board-view.js +157 -61
- package/server/public/app/relay-error-ctas.mjs +28 -5
- package/server/public/app/remote-relay-origin-view.mjs +120 -4
- package/server/public/app/router.js +49 -12
- package/server/public/app/settings-modal.js +33 -2
- package/server/public/app/settings-tabs.js +1 -1
- package/server/public/app/socket-handlers.js +60 -0
- package/server/public/app/store.js +4 -1
- package/server/public/app/subagent-fold.mjs +61 -0
- package/server/public/app/usage-limit-ui.js +225 -0
- package/server/public/index.html +471 -8
- package/server/relay-tools.md +13 -1
- package/server/repositories/message-repository.mjs +10 -1
- package/server/repositories/question-repository.mjs +1 -0
- package/server/repositories/remote-relay-repository.mjs +72 -1
- package/server/repositories/session-repository.mjs +47 -1
- package/server/routes/claude-cloud-routes.mjs +140 -0
- package/server/routes/git-routes.mjs +37 -0
- package/server/routes/messages-routes.mjs +202 -26
- package/server/routes/relay-board-routes.mjs +56 -2
- package/server/routes/remote-relay-routes.mjs +15 -1
- package/server/routes/sessions-routes.mjs +538 -72
- package/server/server-runtime.mjs +291 -27
- package/server/services/claude-account-usage-service.mjs +176 -0
- package/server/services/claude-cloud-repo-service.mjs +408 -0
- package/server/services/claude-cloud-session-service.mjs +326 -0
- package/server/services/claude-cloud-settings-service.mjs +269 -0
- package/server/services/git-remote-service.mjs +115 -0
- package/server/services/plan-usage-claude-cloud.mjs +211 -0
- package/server/services/plan-usage-claude.mjs +202 -40
- package/server/services/plan-usage-contract.mjs +39 -3
- package/server/services/plan-usage-service.mjs +82 -2
- package/server/services/preview-proxy-server.mjs +64 -36
- package/server/services/process-list-service.mjs +122 -0
- package/server/services/provider-reasoning-effort.mjs +3 -0
- package/server/services/relay-console-log.mjs +199 -0
- package/server/services/remote-relay-caller-context.mjs +78 -19
- package/server/services/remote-relay-client.mjs +9 -0
- package/server/services/remote-relay-dispatcher.mjs +451 -39
- package/server/services/remote-relay-inbound.mjs +83 -1
- package/server/services/remote-relay-loopback.mjs +245 -0
- package/server/services/remote-relay-registry-service.mjs +52 -0
- package/server/services/session-worker-launch-service.mjs +100 -15
- package/server/services/session-worker-process-service.mjs +410 -138
- package/server/services/session-worker-registry-service.mjs +1 -1
- package/server/services/session-worker-stop-service.mjs +24 -13
- package/server/services/session-worker-supervisor-service.mjs +89 -2
- package/server/services/usage-limit-pause-service.mjs +443 -0
- package/server/services/worker-launch-note-service.mjs +151 -0
- package/shared/ask-user-bridge.mjs +14 -39
- package/shared/claude-attribution.mjs +117 -0
- package/shared/claude-cloud/api-client.mjs +809 -0
- package/shared/claude-cloud/base-url.mjs +47 -0
- package/shared/claude-cloud/credentials.mjs +221 -0
- package/shared/claude-cloud/repo-url.mjs +111 -0
- package/shared/claude-usage-limit.mjs +257 -0
- package/shared/control-poller.mjs +69 -20
- package/shared/failure-note-text.mjs +38 -0
- package/shared/provider-routing.mjs +4 -2
- package/shared/question-wait.mjs +108 -0
- package/shared/remote-relay-contract.mjs +167 -22
- package/shared/remote-relay-tool-core.mjs +11 -8
- package/shared/steer-settle-failure.mjs +17 -0
- package/shared/steer-settle-markers.mjs +8 -0
- package/shared/worker-runtime/process-tree.mjs +483 -0
- package/shared/worker-runtime/relay-errors.mjs +31 -0
- package/shared/worker-runtime/send-and-wait-errors.mjs +4 -4
- package/shared/worker-runtime/turn-liveness.mjs +249 -0
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* while context usage describes one session's token window.
|
|
10
10
|
*
|
|
11
11
|
* Every provider normalizer in `plan-usage-<provider>.mjs` emits the same
|
|
12
|
-
* `{ card: { meters, details, links } }` shape so the browser renderer
|
|
13
|
-
* provider-agnostic, and so a provider that can only report *some* of
|
|
14
|
-
* limits degrades to fewer meters rather than to a special-cased layout.
|
|
12
|
+
* `{ card: { meters, details, notes, links } }` shape so the browser renderer
|
|
13
|
+
* stays provider-agnostic, and so a provider that can only report *some* of
|
|
14
|
+
* its limits degrades to fewer meters rather than to a special-cased layout.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
export const PLAN_USAGE_VERSION = 2;
|
|
@@ -134,6 +134,16 @@ export function resolveMeterMath({
|
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
/**
|
|
138
|
+
* A provider's severity word as a plain lowercase token ("normal",
|
|
139
|
+
* "warning", …). The vocabulary is the provider's; anything that is not a
|
|
140
|
+
* simple word is dropped rather than shown.
|
|
141
|
+
*/
|
|
142
|
+
export function toSeverity(value) {
|
|
143
|
+
const text = String(value ?? '').trim().toLowerCase();
|
|
144
|
+
return /^[a-z][a-z0-9_-]{0,23}$/.test(text) ? text : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
137
147
|
/**
|
|
138
148
|
* @param {object} spec
|
|
139
149
|
* @param {string} spec.id stable key, used by tests and DOM ids
|
|
@@ -141,6 +151,8 @@ export function resolveMeterMath({
|
|
|
141
151
|
* @param {'credits'|'requests'|'usd'|'percent'|'tokens'} [spec.unit]
|
|
142
152
|
* @param {boolean} [spec.unlimited] plan grants unlimited use of this bucket
|
|
143
153
|
* @param {boolean} [spec.estimated] derived/manual rather than provider-authoritative
|
|
154
|
+
* @param {string} [spec.severity] the provider's own word for how close the limit is
|
|
155
|
+
* @param {'expiry'} [spec.resetKind] `resetAt` is when the allowance ends for good, not when it refills
|
|
144
156
|
* @returns {object|null} null when the meter carries no usable signal at all
|
|
145
157
|
*/
|
|
146
158
|
export function buildMeter({
|
|
@@ -156,6 +168,8 @@ export function buildMeter({
|
|
|
156
168
|
unlimited = false,
|
|
157
169
|
estimated = false,
|
|
158
170
|
emphasis = 'primary',
|
|
171
|
+
severity = null,
|
|
172
|
+
resetKind = null,
|
|
159
173
|
} = {}) {
|
|
160
174
|
const meterId = toTrimmedString(id);
|
|
161
175
|
const meterLabel = toTrimmedString(label);
|
|
@@ -181,10 +195,29 @@ export function buildMeter({
|
|
|
181
195
|
remaining: math.remaining,
|
|
182
196
|
utilization: math.utilization,
|
|
183
197
|
resetAt: toIsoTimestamp(resetAt),
|
|
198
|
+
resetKind: resetKind === 'expiry' ? 'expiry' : null,
|
|
199
|
+
severity: toSeverity(severity),
|
|
184
200
|
note: toTrimmedString(note),
|
|
185
201
|
};
|
|
186
202
|
}
|
|
187
203
|
|
|
204
|
+
/**
|
|
205
|
+
* A line of text on the card itself (not inside a collapsed section), with an
|
|
206
|
+
* optional link behind it. Same link rule as the card's footer: https only.
|
|
207
|
+
*/
|
|
208
|
+
export function buildCardNote({ id, text, link = null } = {}) {
|
|
209
|
+
const noteId = toTrimmedString(id);
|
|
210
|
+
const noteText = toTrimmedString(text);
|
|
211
|
+
if (!noteId || !noteText) return null;
|
|
212
|
+
const linkLabel = toTrimmedString(link?.label);
|
|
213
|
+
const url = toTrimmedString(link?.url);
|
|
214
|
+
return {
|
|
215
|
+
id: noteId,
|
|
216
|
+
text: noteText,
|
|
217
|
+
link: linkLabel && url && /^https:\/\//i.test(url) ? { label: linkLabel, url } : null,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
188
221
|
/** A collapsible block of label/value rows shown under the meters. */
|
|
189
222
|
export function buildDetailSection({ id, label, rows = [], note = null } = {}) {
|
|
190
223
|
const sectionId = toTrimmedString(id);
|
|
@@ -214,6 +247,7 @@ export function buildProviderCard({
|
|
|
214
247
|
stale = false,
|
|
215
248
|
meters = [],
|
|
216
249
|
details = [],
|
|
250
|
+
notes = [],
|
|
217
251
|
links = [],
|
|
218
252
|
} = {}) {
|
|
219
253
|
const providerId = toTrimmedString(provider);
|
|
@@ -222,6 +256,7 @@ export function buildProviderCard({
|
|
|
222
256
|
|
|
223
257
|
const normalizedMeters = (Array.isArray(meters) ? meters : []).filter(Boolean);
|
|
224
258
|
const normalizedDetails = (Array.isArray(details) ? details : []).filter(Boolean);
|
|
259
|
+
const normalizedNotes = (Array.isArray(notes) ? notes : []).map((note) => buildCardNote(note || {})).filter(Boolean);
|
|
225
260
|
const normalizedLinks = (Array.isArray(links) ? links : [])
|
|
226
261
|
.map((link) => {
|
|
227
262
|
const linkLabel = toTrimmedString(link?.label);
|
|
@@ -245,6 +280,7 @@ export function buildProviderCard({
|
|
|
245
280
|
stale: stale === true,
|
|
246
281
|
meters: normalizedMeters,
|
|
247
282
|
details: normalizedDetails,
|
|
283
|
+
notes: normalizedNotes,
|
|
248
284
|
links: normalizedLinks,
|
|
249
285
|
};
|
|
250
286
|
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from './plan-usage-contract.mjs';
|
|
21
21
|
import { buildCopilotPlanCard } from './plan-usage-copilot.mjs';
|
|
22
22
|
import { buildClaudePlanCard } from './plan-usage-claude.mjs';
|
|
23
|
+
import { CLAUDE_CLOUD_PROVIDER_ID, buildClaudeCloudPlanCard } from './plan-usage-claude-cloud.mjs';
|
|
23
24
|
import {
|
|
24
25
|
CURSOR_POOLS,
|
|
25
26
|
applyCursorUsageDelta,
|
|
@@ -383,6 +384,59 @@ export function createPlanUsageService({ db, now = () => new Date(), dbg = () =>
|
|
|
383
384
|
return { cycle };
|
|
384
385
|
}
|
|
385
386
|
|
|
387
|
+
// Claude Cloud conversations keep their reported cost on the runtime
|
|
388
|
+
// session row (migration 0007). That table is the relay's, not this
|
|
389
|
+
// service's, so the statements are prepared on first use, and only once
|
|
390
|
+
// the table and the column are there (an older database has neither).
|
|
391
|
+
let claudeCloudSpendStmts = null;
|
|
392
|
+
function claudeCloudSpendStatements() {
|
|
393
|
+
if (claudeCloudSpendStmts) return claudeCloudSpendStmts;
|
|
394
|
+
const columns = new Set(db.prepare(`PRAGMA table_info(runtime_sessions)`).all().map((column) => String(column.name)));
|
|
395
|
+
if (!columns.has('claude_cloud_cost_usd') || !columns.has('provider_type')) return null;
|
|
396
|
+
claudeCloudSpendStmts = {
|
|
397
|
+
totals: db.prepare(`
|
|
398
|
+
SELECT COUNT(*) AS conversation_count, COALESCE(SUM(claude_cloud_cost_usd), 0) AS total_usd
|
|
399
|
+
FROM runtime_sessions
|
|
400
|
+
WHERE LOWER(TRIM(provider_type)) = '${CLAUDE_CLOUD_PROVIDER_ID}'
|
|
401
|
+
`),
|
|
402
|
+
byConversation: db.prepare(`
|
|
403
|
+
SELECT claude_cloud_cost_usd AS cost_usd
|
|
404
|
+
FROM runtime_sessions
|
|
405
|
+
WHERE conversation_id = ? AND LOWER(TRIM(provider_type)) = '${CLAUDE_CLOUD_PROVIDER_ID}'
|
|
406
|
+
`),
|
|
407
|
+
};
|
|
408
|
+
return claudeCloudSpendStmts;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* What the relay's cloud conversations have cost: the sum of the latest
|
|
413
|
+
* cost each one reported and how many there are, plus the cost of
|
|
414
|
+
* `conversationId` when that is a cloud conversation (`conversation` is
|
|
415
|
+
* null for any other). Only conversations that still exist count: a deleted
|
|
416
|
+
* one takes its row with it. There are no dates on these figures, so no
|
|
417
|
+
* per-day or per-week sum is offered. Null when the storage is not there.
|
|
418
|
+
*/
|
|
419
|
+
function readClaudeCloudSpend({ conversationId = '' } = {}) {
|
|
420
|
+
try {
|
|
421
|
+
const statements = claudeCloudSpendStatements();
|
|
422
|
+
if (!statements) return null;
|
|
423
|
+
const totals = statements.totals.get();
|
|
424
|
+
const id = toTrimmedString(conversationId);
|
|
425
|
+
const row = id ? statements.byConversation.get(id) : null;
|
|
426
|
+
const cost = row ? Number(row.cost_usd) : null;
|
|
427
|
+
return {
|
|
428
|
+
totalUsd: Number(totals?.total_usd) || 0,
|
|
429
|
+
conversationCount: Number(totals?.conversation_count) || 0,
|
|
430
|
+
conversation: row
|
|
431
|
+
? { costUsd: row.cost_usd !== null && Number.isFinite(cost) ? cost : null }
|
|
432
|
+
: null,
|
|
433
|
+
};
|
|
434
|
+
} catch (error) {
|
|
435
|
+
dbg('claude cloud spend read failed', error?.message || String(error));
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
386
440
|
/**
|
|
387
441
|
* Assemble the full multi-provider report. Every provider is independent:
|
|
388
442
|
* one failing source produces an unavailable card instead of failing the
|
|
@@ -392,8 +446,17 @@ export function createPlanUsageService({ db, now = () => new Date(), dbg = () =>
|
|
|
392
446
|
copilotSummary = null,
|
|
393
447
|
copilotError = null,
|
|
394
448
|
copilotStale = false,
|
|
449
|
+
// When the quota answer is an earlier one served again (the modal asked
|
|
450
|
+
// for another provider live), the time it was really read.
|
|
451
|
+
copilotCapturedAt = null,
|
|
395
452
|
copilotBilling = null,
|
|
396
453
|
claudeConfigured = true,
|
|
454
|
+
// Live account usage (claude-account-usage-service.mjs), or null: it is
|
|
455
|
+
// only ever read while Claude Cloud is switched on.
|
|
456
|
+
claudeAccount = null,
|
|
457
|
+
claudeCloudConfigured = false,
|
|
458
|
+
// The conversation the modal was opened from, for its own cloud cost.
|
|
459
|
+
conversationId = '',
|
|
397
460
|
cursorConfigured = true,
|
|
398
461
|
cursorAllowances = null,
|
|
399
462
|
cursorBilling = null,
|
|
@@ -404,6 +467,9 @@ export function createPlanUsageService({ db, now = () => new Date(), dbg = () =>
|
|
|
404
467
|
} = {}) {
|
|
405
468
|
const generatedAt = nowIso();
|
|
406
469
|
const claudeSnapshot = readSnapshot('claude');
|
|
470
|
+
// What the cloud workers post to /api/claude-plan-usage is kept under its
|
|
471
|
+
// own key, so the Claude card stays what the Claude workers wrote.
|
|
472
|
+
const claudeCloudSnapshot = claudeCloudConfigured === true ? readSnapshot(CLAUDE_CLOUD_PROVIDER_ID) : null;
|
|
407
473
|
const allowances = normalizeCursorAllowanceSettings(cursorAllowances || {});
|
|
408
474
|
const cursorCycle = readCursorCycleTotals({ resetDay: allowances.resetDay });
|
|
409
475
|
const grokSettings = normalizeGrokAllowanceSettings(grokAllowances || {});
|
|
@@ -421,7 +487,7 @@ export function createPlanUsageService({ db, now = () => new Date(), dbg = () =>
|
|
|
421
487
|
billing: copilotBilling,
|
|
422
488
|
workerUsage: copilotWorkerSnapshot?.payload || null,
|
|
423
489
|
error: copilotError,
|
|
424
|
-
capturedAt: generatedAt,
|
|
490
|
+
capturedAt: copilotCapturedAt || generatedAt,
|
|
425
491
|
stale: copilotStale === true,
|
|
426
492
|
}),
|
|
427
493
|
buildClaudePlanCard({
|
|
@@ -431,9 +497,22 @@ export function createPlanUsageService({ db, now = () => new Date(), dbg = () =>
|
|
|
431
497
|
message: claudeSnapshot?.error || null,
|
|
432
498
|
// A stored snapshot is by definition from an earlier turn; the SDK's
|
|
433
499
|
// usage control call only works while a session transport is open, and
|
|
434
|
-
// the relay never opens a billable turn just to refresh this.
|
|
500
|
+
// the relay never opens a billable turn just to refresh this. Live
|
|
501
|
+
// account usage, where there is any, takes the meters over.
|
|
435
502
|
stale: !!claudeSnapshot?.payload,
|
|
503
|
+
account: claudeAccount,
|
|
436
504
|
}),
|
|
505
|
+
// Opt-in like Grok (no card while the provider is off), and placed next
|
|
506
|
+
// to the Claude card because both are the same account.
|
|
507
|
+
claudeCloudConfigured === true
|
|
508
|
+
? buildClaudeCloudPlanCard({
|
|
509
|
+
account: claudeAccount,
|
|
510
|
+
spend: readClaudeCloudSpend({ conversationId }),
|
|
511
|
+
usage: claudeCloudSnapshot?.payload || null,
|
|
512
|
+
capturedAt: claudeCloudSnapshot?.capturedAt || null,
|
|
513
|
+
configured: true,
|
|
514
|
+
})
|
|
515
|
+
: null,
|
|
437
516
|
buildCursorPlanCard({
|
|
438
517
|
totals: cursorCycle.totals,
|
|
439
518
|
allowances,
|
|
@@ -481,6 +560,7 @@ export function createPlanUsageService({ db, now = () => new Date(), dbg = () =>
|
|
|
481
560
|
recordGrokUsageReport,
|
|
482
561
|
readGrokCycleTotals,
|
|
483
562
|
resetGrokAccounting,
|
|
563
|
+
readClaudeCloudSpend,
|
|
484
564
|
buildReport,
|
|
485
565
|
pools: CURSOR_POOLS,
|
|
486
566
|
};
|
|
@@ -239,6 +239,11 @@ function guardConnectTimeout(upstreamReq, timeoutMs, onTimeout) {
|
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
+
// Requests the lane sends a second time when the connection it kept to the
|
|
243
|
+
// dev server turns out to be closed, and what such a connection fails with.
|
|
244
|
+
const REPEATABLE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
245
|
+
const STALE_CONNECTION_CODES = new Set(['ECONNRESET', 'EPIPE']);
|
|
246
|
+
|
|
242
247
|
export function createPreviewProxyServer({
|
|
243
248
|
registry,
|
|
244
249
|
logger = console,
|
|
@@ -327,46 +332,69 @@ export function createPreviewProxyServer({
|
|
|
327
332
|
bearerTokens: relayBearerTokens,
|
|
328
333
|
});
|
|
329
334
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
335
|
+
// A request without a body can be sent a second time.
|
|
336
|
+
const repeatable = REPEATABLE_METHODS.has(String(req.method || '').toUpperCase())
|
|
337
|
+
&& !(Number(req.headers['content-length']) > 0)
|
|
338
|
+
&& !req.headers['transfer-encoding'];
|
|
339
|
+
let upstreamReq = null;
|
|
340
|
+
|
|
341
|
+
const forward = ({ again = false } = {}) => {
|
|
342
|
+
const current = httpImpl.request({
|
|
343
|
+
host: entry.targetHost,
|
|
344
|
+
port: entry.targetPort,
|
|
345
|
+
method: req.method,
|
|
346
|
+
path: upstreamPath,
|
|
347
|
+
headers,
|
|
348
|
+
agent,
|
|
349
|
+
});
|
|
350
|
+
upstreamReq = current;
|
|
351
|
+
|
|
352
|
+
let timedOut = false;
|
|
353
|
+
guardConnectTimeout(current, connectTimeoutMs, () => { timedOut = true; });
|
|
354
|
+
|
|
355
|
+
current.on('response', (upstreamRes) => {
|
|
356
|
+
const outHeaders = sanitizeResponseHeaders(upstreamRes.headers, {
|
|
357
|
+
basePath: entry.basePath,
|
|
358
|
+
targetHost: entry.targetHost,
|
|
359
|
+
targetPort: entry.targetPort,
|
|
360
|
+
});
|
|
361
|
+
res.writeHead(upstreamRes.statusCode || 502, outHeaders);
|
|
362
|
+
// 204/304 and HEAD carry no body; piping one would desync the connection.
|
|
363
|
+
if (req.method === 'HEAD' || upstreamRes.statusCode === 204 || upstreamRes.statusCode === 304) {
|
|
364
|
+
upstreamRes.resume();
|
|
365
|
+
res.end();
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
upstreamRes.pipe(res);
|
|
369
|
+
upstreamRes.on('error', () => { try { res.destroy(); } catch {} });
|
|
370
|
+
});
|
|
341
371
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
372
|
+
current.on('error', (error) => {
|
|
373
|
+
if (upstreamReq !== current) return;
|
|
374
|
+
// The connection was kept from an earlier request, and the dev server
|
|
375
|
+
// has closed it since (it exited, or was restarted): that says nothing
|
|
376
|
+
// about the server now. One more try on a connection of its own either
|
|
377
|
+
// reaches the restarted server or says that nothing is listening.
|
|
378
|
+
if (!again && repeatable && current.reusedSocket && !res.headersSent && !res.destroyed
|
|
379
|
+
&& STALE_CONNECTION_CODES.has(String(error?.code || ''))) {
|
|
380
|
+
forward({ again: true });
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const refused = String(error?.code || '') === 'ECONNREFUSED';
|
|
384
|
+
const detail = refused || timedOut
|
|
385
|
+
? `Nothing is listening on <code>${escapeHtml(entry.targetHost)}:${entry.targetPort}</code>. The dev server behind this preview has probably exited — restart it on the same port and reload; this link stays valid.`
|
|
386
|
+
: `The upstream connection failed: <code>${escapeHtml(error?.code || error?.message || 'unknown error')}</code>.`;
|
|
387
|
+
sendErrorPage(res, 502, { title: 'Preview upstream unreachable', detail });
|
|
347
388
|
});
|
|
348
|
-
res.writeHead(upstreamRes.statusCode || 502, outHeaders);
|
|
349
|
-
// 204/304 and HEAD carry no body; piping one would desync the connection.
|
|
350
|
-
if (req.method === 'HEAD' || upstreamRes.statusCode === 204 || upstreamRes.statusCode === 304) {
|
|
351
|
-
upstreamRes.resume();
|
|
352
|
-
res.end();
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
upstreamRes.pipe(res);
|
|
356
|
-
upstreamRes.on('error', () => { try { res.destroy(); } catch {} });
|
|
357
|
-
});
|
|
358
389
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
: `The upstream connection failed: <code>${escapeHtml(error?.code || error?.message || 'unknown error')}</code>.`;
|
|
364
|
-
sendErrorPage(res, 502, { title: 'Preview upstream unreachable', detail });
|
|
365
|
-
});
|
|
390
|
+
// The second try has nothing left to read from the request.
|
|
391
|
+
if (again) current.end();
|
|
392
|
+
else req.pipe(current);
|
|
393
|
+
};
|
|
366
394
|
|
|
367
|
-
req.on('aborted', () => { try { upstreamReq
|
|
368
|
-
res.on('close', () => { try { upstreamReq
|
|
369
|
-
|
|
395
|
+
req.on('aborted', () => { try { upstreamReq?.destroy(); } catch {} });
|
|
396
|
+
res.on('close', () => { try { upstreamReq?.destroy(); } catch {} });
|
|
397
|
+
forward();
|
|
370
398
|
}
|
|
371
399
|
|
|
372
400
|
// WebSocket upgrades (Vite HMR, an app's own socket) ride the same prefix.
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The process table, read the way each platform allows, for the tree watch in
|
|
4
|
+
// shared/worker-runtime/process-tree.mjs. Every entry carries the time the
|
|
5
|
+
// process was started: that is what tells it from a later process that was
|
|
6
|
+
// given its pid.
|
|
7
|
+
//
|
|
8
|
+
// - Linux reads `/proc/<pid>/stat`, which needs no process and takes about
|
|
9
|
+
// 3 ms for 160 processes (measured 2026-09-29). The start time is field 22,
|
|
10
|
+
// in clock ticks since boot.
|
|
11
|
+
// - Windows asks PowerShell, through the list the relay's process inspector
|
|
12
|
+
// already reads. It takes about a second, so it is never polled.
|
|
13
|
+
// - Every other platform asks `ps`, whose start time has a resolution of one
|
|
14
|
+
// second.
|
|
15
|
+
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import { execFile } from 'child_process';
|
|
18
|
+
|
|
19
|
+
import { createSessionWorkerProcessInspector } from './session-worker-process-service.mjs';
|
|
20
|
+
|
|
21
|
+
const PS_TIMEOUT_MS = 10_000;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* One `/proc/<pid>/stat`. The name (field 2) is in parentheses and may hold
|
|
25
|
+
* spaces and parentheses of its own, so the fields after it are counted from
|
|
26
|
+
* the LAST closing one. A process that has ended and only waits to be
|
|
27
|
+
* collected (`Z`, `X`) is not running any more.
|
|
28
|
+
*/
|
|
29
|
+
export function parseProcStat(text) {
|
|
30
|
+
const raw = String(text || '');
|
|
31
|
+
const open = raw.indexOf('(');
|
|
32
|
+
const close = raw.lastIndexOf(')');
|
|
33
|
+
if (open < 1 || close < open) return null;
|
|
34
|
+
const processId = Number.parseInt(raw.slice(0, open), 10);
|
|
35
|
+
const fields = raw.slice(close + 2).trim().split(/\s+/);
|
|
36
|
+
const state = fields[0] || '';
|
|
37
|
+
const createdAt = Number(fields[19]);
|
|
38
|
+
if (!(processId > 0) || state === 'Z' || state === 'X' || !(createdAt > 0)) return null;
|
|
39
|
+
return {
|
|
40
|
+
processId,
|
|
41
|
+
parentProcessId: Number.parseInt(fields[1], 10) || 0,
|
|
42
|
+
name: raw.slice(open + 1, close),
|
|
43
|
+
createdAt,
|
|
44
|
+
// The runtime starts a command in a session of its own.
|
|
45
|
+
sessionLeader: Number.parseInt(fields[3], 10) === processId,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One line of `ps -o pid=,ppid=,stat=,lstart=,args=`. */
|
|
50
|
+
export function parsePsLine(line) {
|
|
51
|
+
const match = String(line || '').match(
|
|
52
|
+
/^\s*(\d+)\s+(\d+)\s+(\S+)\s+(\w{3}\s+\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}\s+\d{4})\s*(.*)$/,
|
|
53
|
+
);
|
|
54
|
+
if (!match) return null;
|
|
55
|
+
const createdAt = Date.parse(match[4]);
|
|
56
|
+
if (/^[ZX]/.test(match[3]) || !(createdAt > 0)) return null;
|
|
57
|
+
return {
|
|
58
|
+
processId: Number.parseInt(match[1], 10),
|
|
59
|
+
parentProcessId: Number.parseInt(match[2], 10) || 0,
|
|
60
|
+
createdAt,
|
|
61
|
+
commandLine: match[5],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createProcessLister({
|
|
66
|
+
platform = process.platform,
|
|
67
|
+
readdirSyncImpl = fs.readdirSync,
|
|
68
|
+
readFileSyncImpl = fs.readFileSync,
|
|
69
|
+
execFileImpl = execFile,
|
|
70
|
+
inspector = null,
|
|
71
|
+
} = {}) {
|
|
72
|
+
if (platform === 'win32') {
|
|
73
|
+
const windows = inspector || createSessionWorkerProcessInspector({ platform, execFileImpl });
|
|
74
|
+
return {
|
|
75
|
+
// A child keeps the pid of its parent after the parent has ended.
|
|
76
|
+
orphansKeepParent: true,
|
|
77
|
+
list: () => windows.readWindowsProcessSnapshot(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (platform === 'linux') {
|
|
82
|
+
const read = (pid) => {
|
|
83
|
+
try {
|
|
84
|
+
return parseProcStat(readFileSyncImpl(`/proc/${pid}/stat`, 'utf8'));
|
|
85
|
+
} catch {
|
|
86
|
+
// It ended between the directory listing and the read.
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
orphansKeepParent: false,
|
|
92
|
+
list: () => readdirSyncImpl('/proc')
|
|
93
|
+
.filter((name) => /^\d+$/.test(String(name)))
|
|
94
|
+
.map((name) => read(name))
|
|
95
|
+
.filter(Boolean),
|
|
96
|
+
read,
|
|
97
|
+
describe(pid) {
|
|
98
|
+
try {
|
|
99
|
+
return String(readFileSyncImpl(`/proc/${pid}/cmdline`, 'utf8')).replace(/\0/g, ' ').trim();
|
|
100
|
+
} catch {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
orphansKeepParent: false,
|
|
109
|
+
list: () => new Promise((resolve, reject) => {
|
|
110
|
+
execFileImpl(
|
|
111
|
+
'ps',
|
|
112
|
+
['-axww', '-o', 'pid=,ppid=,stat=,lstart=,args='],
|
|
113
|
+
// `lstart` is parsed as a date: keep it in the one language that is.
|
|
114
|
+
{ timeout: PS_TIMEOUT_MS, maxBuffer: 64 * 1024 * 1024, env: { ...process.env, LC_ALL: 'C' } },
|
|
115
|
+
(error, stdout) => {
|
|
116
|
+
if (error) reject(error);
|
|
117
|
+
else resolve(String(stdout || '').split(/\r?\n/).map(parsePsLine).filter(Boolean));
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -12,6 +12,7 @@ import { openAIReasoningEffortsForModel } from '../../shared/openai-reasoning.mj
|
|
|
12
12
|
export const CLAUDE_ULTRACODE_EFFORT = 'ultracode';
|
|
13
13
|
export const DEFAULT_CLAUDE_REASONING_EFFORTS = Object.freeze(['none', 'low', 'medium', 'high', 'xhigh', 'max', CLAUDE_ULTRACODE_EFFORT]);
|
|
14
14
|
export const DEFAULT_GROK_REASONING_EFFORTS = Object.freeze(['none', 'low', 'medium', 'high']);
|
|
15
|
+
export const CLAUDE_CLOUD_REASONING_EFFORTS = Object.freeze(['none']);
|
|
15
16
|
|
|
16
17
|
// Ultracode requires an xhigh-capable model (the SDK's stated gate), so the
|
|
17
18
|
// tier is derived from a model's discovered efforts rather than discovery —
|
|
@@ -54,6 +55,8 @@ export function supportedReasoningEffortsForProviderModel({
|
|
|
54
55
|
if (provider === 'grok') {
|
|
55
56
|
return effortsForModel(grokSettings?.effortsByModel, model) || [...DEFAULT_GROK_REASONING_EFFORTS];
|
|
56
57
|
}
|
|
58
|
+
// A cloud session takes no effort choice: the only tier is the default one.
|
|
59
|
+
if (provider === 'claude-cloud') return [...CLAUDE_CLOUD_REASONING_EFFORTS];
|
|
57
60
|
if (provider === 'openai' || provider === 'openai-image') {
|
|
58
61
|
const efforts = openAIReasoningEffortsForModel(model);
|
|
59
62
|
return Array.isArray(efforts) && efforts.length ? efforts.map(normalizeEffort).filter(Boolean) : null;
|