@bitkyc08/opencodex 2.92.0 → 2.93.0-preview.20261027
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/bin/ocx.mjs +10 -5
- package/gui/dist/assets/App-CJZoq-uF.js +58 -0
- package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-BWQPcgZn.js} +1 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/{index-BlFE_VB_.js → index-Xfct8owH.js} +12 -12
- package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-DxToX1rV.js} +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +5 -5
- package/src/adapters/anthropic.ts +28 -5
- package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
- package/src/adapters/coding-agent/profile.ts +54 -16
- package/src/adapters/coding-agent/turn.ts +30 -2
- package/src/adapters/command-code.ts +114 -7
- package/src/adapters/cursor/native-exec-fs.ts +11 -9
- package/src/adapters/devin/live-models.ts +4 -0
- package/src/adapters/google-wire-compiler.ts +1 -2
- package/src/adapters/kiro/reasoning.ts +2 -0
- package/src/adapters/kiro-refusal.ts +6 -1
- package/src/adapters/kiro-wire.ts +1 -1
- package/src/adapters/openai-chat/messages.ts +8 -2
- package/src/adapters/openai-chat/passthrough.ts +35 -14
- package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
- package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
- package/src/adapters/openai-chat/required-tool-result.ts +64 -0
- package/src/adapters/openai-chat.ts +7 -8
- package/src/adapters/openai-responses/passthrough.ts +7 -4
- package/src/adapters/openai-responses/reasoning.ts +13 -0
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/qoder/adapter.ts +129 -8
- package/src/adapters/qoder/scaffold-guard.ts +5 -0
- package/src/adapters/reasoning-controls.ts +16 -0
- package/src/adapters/tool-call-id.ts +1 -3
- package/src/bridge/errors.ts +27 -0
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +9 -2
- package/src/chat/reasoning-details.ts +28 -5
- package/src/claude/desktop-first-party.ts +54 -4
- package/src/claude/desktop-picker.ts +11 -8
- package/src/claude/first-party-settings.ts +3 -1
- package/src/claude/inbound.ts +2 -1
- package/src/claude/intercept/local-ca.ts +2 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
- package/src/claude/intercept/picker-ca-startup.ts +3 -1
- package/src/claude/intercept/picker-models.ts +6 -3
- package/src/claude/intercept/picker-runtime.ts +3 -2
- package/src/claude/intercept/runtime.ts +6 -3
- package/src/claude/model-info.ts +31 -8
- package/src/cli/account-api.ts +11 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +7 -1
- package/src/cli/capabilities-observe-system.ts +10 -0
- package/src/cli/claude-desktop.ts +9 -8
- package/src/cli/claude.ts +3 -2
- package/src/cli/codex-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +7 -0
- package/src/cli/combo.ts +18 -0
- package/src/cli/cross-home-owner.ts +13 -1
- package/src/cli/dispatch.ts +25 -6
- package/src/cli/ensure-desired-integrations.ts +8 -6
- package/src/cli/export-command.ts +4 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/index.ts +45 -45
- package/src/cli/integration-plan-dto.ts +4 -0
- package/src/cli/opencode.ts +20 -9
- package/src/cli/registry.ts +6 -4
- package/src/cli/root.ts +9 -0
- package/src/cli/status.ts +59 -1
- package/src/cli/stop-restore.ts +113 -0
- package/src/cli/sync-expectation.ts +60 -0
- package/src/cli/uninstall-integrations.ts +41 -7
- package/src/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/machine-api.ts +3 -1
- package/src/client/sync-expectation.ts +118 -0
- package/src/clients/config-export/agent-clients.ts +96 -0
- package/src/clients/config-export/contracts.ts +25 -7
- package/src/clients/config-export/qoder.ts +38 -23
- package/src/clients/config-export/reasoning-metadata.ts +55 -8
- package/src/clients/config-export.ts +12 -0
- package/src/clients/lazycodex.ts +7 -2
- package/src/clients/reasoning-controls.ts +49 -0
- package/src/codex/auth-api/account-identity.ts +14 -0
- package/src/codex/auth-api/account-list.ts +29 -2
- package/src/codex/auth-api/http.ts +13 -0
- package/src/codex/auth-api/main-account-probe.ts +2 -2
- package/src/codex/auth-api/pool-mode-gate.ts +16 -3
- package/src/codex/auth-api/pool-quota-probe.ts +15 -0
- package/src/codex/auth-context.ts +15 -12
- package/src/codex/catalog/build-entries.ts +22 -0
- package/src/codex/catalog/configured-tiers.ts +70 -0
- package/src/codex/catalog/effort.ts +44 -10
- package/src/codex/catalog/gather-capture.ts +1 -0
- package/src/codex/catalog/heal-observation.ts +155 -13
- package/src/codex/catalog/metadata.ts +6 -0
- package/src/codex/catalog/model-hints.ts +60 -11
- package/src/codex/catalog/model-visibility.ts +3 -2
- package/src/codex/catalog/native-models.ts +18 -3
- package/src/codex/catalog/parsing.ts +10 -8
- package/src/codex/catalog/pinned-models.ts +2 -1
- package/src/codex/catalog/provider-models.ts +4 -5
- package/src/codex/catalog/retained-sync.ts +2 -1
- package/src/codex/catalog/routed-gather.ts +19 -20
- package/src/codex/catalog/write-audit.ts +3 -2
- package/src/codex/catalog-self-heal.ts +43 -23
- package/src/codex/collision-identity.ts +30 -5
- package/src/codex/convergence.ts +4 -3
- package/src/codex/data/roster-pinned-models.json +177 -1
- package/src/codex/desired-state.ts +6 -1
- package/src/codex/desktop-compatibility/installed-build.ts +88 -12
- package/src/codex/desktop-compatibility/runtime.ts +29 -5
- package/src/codex/desktop-compatibility/usage-controller.ts +2 -0
- package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
- package/src/codex/inject/config-toml.ts +0 -18
- package/src/codex/inject/plan.ts +18 -3
- package/src/codex/inject/remove.ts +6 -2
- package/src/codex/inject.ts +1 -1
- package/src/codex/journal.ts +61 -1
- package/src/codex/model-entitlements.ts +1 -1
- package/src/codex/native-main-owner.ts +27 -1
- package/src/codex/native-profile-store.ts +2 -1
- package/src/codex/pool-credit-policy.ts +35 -1
- package/src/codex/quota-types.ts +3 -0
- package/src/codex/quota.ts +24 -4
- package/src/codex/role-auto-assign.ts +6 -2
- package/src/codex/subagent-defaults.ts +49 -4
- package/src/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev.ts +95 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +24 -0
- package/src/config/load-degrade.ts +5 -0
- package/src/config/paths.ts +19 -3
- package/src/config/pending-teardown.ts +22 -1
- package/src/config/provider-validation.ts +15 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +5 -0
- package/src/generated/compatibility-version.json +314 -230
- package/src/generated/model-metadata.ts +5 -5
- package/src/images/loop.ts +16 -2
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-profiles.ts +251 -0
- package/src/integrations/merge.ts +8 -0
- package/src/integrations/mutation-plan.ts +19 -4
- package/src/integrations/registry.ts +5 -0
- package/src/integrations/state.ts +36 -1
- package/src/integrations/writer.ts +18 -4
- package/src/lib/bun-path-runtime.mjs +2 -1
- package/src/lib/errors.ts +62 -0
- package/src/lib/eventstream-decoder.ts +81 -37
- package/src/lib/opaque-proxy-tunnel.ts +32 -8
- package/src/lib/pinned-http.ts +35 -2
- package/src/lib/process-control.ts +13 -1
- package/src/lib/socks5-fetch.ts +59 -64
- package/src/lib/socks5-upload-waiter.ts +50 -0
- package/src/lib/sse-decoder.ts +7 -2
- package/src/lib/state-store-sweeper.ts +40 -14
- package/src/lib/windows-native-principal-worker.ts +14 -0
- package/src/lib/windows-native-principal.ts +188 -0
- package/src/lib/windows-secret-acl.ts +39 -3
- package/src/lib/windows-user-principal.ts +62 -18
- package/src/link/ssh-config.ts +35 -3
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +28 -0
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-rename-fields.ts +1 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +14 -12
- package/src/providers/registry/entries-extended.ts +63 -20
- package/src/providers/registry/model-ids.ts +2 -0
- package/src/providers/registry/model-seeds.ts +93 -28
- package/src/providers/registry/types.ts +10 -1
- package/src/providers/resolved-model-policy.ts +26 -6
- package/src/providers/routed-config.ts +9 -1
- package/src/providers/stale-model-roster-migration.ts +44 -7
- package/src/remote-control/workspace-pi-runtime.ts +11 -6
- package/src/responses/compaction-summary.ts +45 -0
- package/src/responses/muse-tool-name-alias.ts +1 -2
- package/src/responses/parser.ts +3 -2
- package/src/responses/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/routing/capability.ts +8 -2
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +3 -2
- package/src/server/chat-completions.ts +7 -0
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +14 -4
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +4 -0
- package/src/server/management/config-routes.ts +2 -2
- package/src/server/management/decision-discovery.ts +12 -2
- package/src/server/management/hermes-profile-routes.ts +156 -0
- package/src/server/management/integration-routes.ts +85 -24
- package/src/server/management/model-routes.ts +2 -2
- package/src/server/management/model-row-export-metadata.ts +25 -6
- package/src/server/management/model-rows.ts +15 -20
- package/src/server/management/native-integration-routes.ts +11 -8
- package/src/server/management/route-registry.ts +4 -0
- package/src/server/management-api.ts +5 -0
- package/src/server/models-capabilities.ts +21 -3
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- package/src/server/responses/codex-ws-exchange.ts +39 -9
- package/src/server/responses/codex-ws-session.ts +38 -4
- package/src/server/responses/codex-ws-wire.ts +6 -1
- package/src/server/responses/combo-required-tool-contract.ts +103 -0
- package/src/server/responses/combo-stream-preflight.ts +8 -1
- package/src/server/responses/compact.ts +4 -3
- package/src/server/responses/context-overflow.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +10 -0
- package/src/server/responses/core-combo.ts +23 -15
- package/src/server/responses/core-lifetime.ts +3 -0
- package/src/server/responses/core-normalize.ts +11 -1
- package/src/server/responses/core-options.ts +2 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +40 -2
- package/src/server/responses/policy-fallback.ts +6 -1
- package/src/server/responses/request-compression.ts +12 -7
- package/src/server/responses/request-prepare.ts +22 -2
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/sidecar-execution.ts +11 -3
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- package/src/service/desktop-supervision.d.mts +7 -4
- package/src/service/desktop-supervision.mjs +90 -13
- package/src/service/ownership-mutation-lease.mjs +21 -7
- package/src/types/config.ts +8 -2
- package/src/types/provider.ts +20 -6
- package/src/types/request.ts +10 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -0
- package/src/update/job.ts +10 -29
- package/src/update/npm-install-job.ps1 +173 -0
- package/src/update/npm-install.mjs +70 -0
- package/src/update/stop-contract.d.mts +1 -0
- package/src/update/stop-contract.mjs +14 -0
- package/src/update/stop-decision.d.mts +1 -1
- package/src/update/stop-decision.mjs +13 -3
- package/src/update/teardown-handover.ts +166 -0
- package/src/update/transactional-install.d.mts +14 -3
- package/src/update/transactional-install.mjs +33 -7
- package/src/usage/expected-prices.ts +64 -31
- package/src/usage/timeline.ts +19 -9
- package/src/vision/eligibility.ts +15 -5
- package/src/vision/plan.ts +2 -2
- package/src/web-search/loop.ts +16 -2
- package/gui/dist/assets/App-sUf_8afJ.js +0 -58
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
package/src/lib/sse-decoder.ts
CHANGED
|
@@ -78,6 +78,9 @@ export async function* decodeServerSentEvents(
|
|
|
78
78
|
const reader = source.getReader();
|
|
79
79
|
const decoder = new TextDecoder();
|
|
80
80
|
let lineBuffer = "";
|
|
81
|
+
// Keep field classification separate from the growing line. Re-slicing its
|
|
82
|
+
// prefix on every fragment can repeatedly flatten/copy a long string rope.
|
|
83
|
+
let linePrefix = "";
|
|
81
84
|
let skipLineFeed = false;
|
|
82
85
|
let lineRawBytes = 0;
|
|
83
86
|
let lineRetainedBytes = 0;
|
|
@@ -103,8 +106,8 @@ export async function* decodeServerSentEvents(
|
|
|
103
106
|
};
|
|
104
107
|
|
|
105
108
|
const linePrefixAfter = (sourceValue: string, start: number, end: number): string => {
|
|
106
|
-
if (
|
|
107
|
-
return
|
|
109
|
+
if (linePrefix.length >= 6) return linePrefix;
|
|
110
|
+
return linePrefix + sourceValue.slice(start, Math.min(end, start + 6 - linePrefix.length));
|
|
108
111
|
};
|
|
109
112
|
|
|
110
113
|
const accountedLineBytes = (rawBytes: number, prefix: string): number => {
|
|
@@ -132,6 +135,7 @@ export async function* decodeServerSentEvents(
|
|
|
132
135
|
translatorBudget.releaseRetained(lineRetainedBytes, scope);
|
|
133
136
|
lineRawBytes = nextRawBytes;
|
|
134
137
|
lineRetainedBytes = nextRawBytes;
|
|
138
|
+
linePrefix = prefix;
|
|
135
139
|
} catch (error) {
|
|
136
140
|
reservation.release();
|
|
137
141
|
throw error;
|
|
@@ -194,6 +198,7 @@ export async function* decodeServerSentEvents(
|
|
|
194
198
|
translatorBudget.releaseRetained(retainedLineBytes, scope);
|
|
195
199
|
};
|
|
196
200
|
lineBuffer = "";
|
|
201
|
+
linePrefix = "";
|
|
197
202
|
lineRawBytes = 0;
|
|
198
203
|
lineRetainedBytes = 0;
|
|
199
204
|
try {
|
|
@@ -36,9 +36,9 @@ export interface StateStoreSweeperOptions {
|
|
|
36
36
|
|
|
37
37
|
const registrations = new Map<string, StateStoreRegistration>();
|
|
38
38
|
interface AfterTickRegistrationNode {
|
|
39
|
-
registration: StateSweepAfterTickRegistration;
|
|
39
|
+
registration: StateSweepAfterTickRegistration | null;
|
|
40
40
|
previous: AfterTickRegistrationNode | null;
|
|
41
|
-
|
|
41
|
+
next: AfterTickRegistrationNode | null;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const afterTickRegistrations = new Map<string, AfterTickRegistrationNode>();
|
|
@@ -62,22 +62,43 @@ export function registerStateStore(registration: StateStoreRegistration): () =>
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export function registerStateSweepAfterTick(registration: StateSweepAfterTickRegistration): () => void {
|
|
65
|
+
const name = registration.name;
|
|
65
66
|
const node: AfterTickRegistrationNode = {
|
|
66
67
|
registration,
|
|
67
|
-
previous: afterTickRegistrations.get(
|
|
68
|
-
|
|
68
|
+
previous: afterTickRegistrations.get(name) ?? null,
|
|
69
|
+
next: null,
|
|
69
70
|
};
|
|
70
|
-
|
|
71
|
+
if (node.previous) node.previous.next = node;
|
|
72
|
+
afterTickRegistrations.set(name, node);
|
|
71
73
|
return () => {
|
|
72
|
-
node.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (previous)
|
|
77
|
-
|
|
74
|
+
if (!node.registration) return;
|
|
75
|
+
// Unlink even a displaced owner immediately. Tombstones in the older-owner
|
|
76
|
+
// chain retain its callback (and captured config) until every newer owner exits.
|
|
77
|
+
const { previous, next } = node;
|
|
78
|
+
if (previous) previous.next = next;
|
|
79
|
+
if (next) next.previous = previous;
|
|
80
|
+
if (afterTickRegistrations.get(name) === node) {
|
|
81
|
+
if (previous) afterTickRegistrations.set(name, previous);
|
|
82
|
+
else afterTickRegistrations.delete(name);
|
|
83
|
+
}
|
|
84
|
+
// A caller can retain its idempotent detach function after invoking it.
|
|
85
|
+
// Do not let that handle retain either the callback or neighboring owners.
|
|
86
|
+
node.registration = null;
|
|
87
|
+
node.previous = null;
|
|
88
|
+
node.next = null;
|
|
78
89
|
};
|
|
79
90
|
}
|
|
80
91
|
|
|
92
|
+
/** Test-only resource oracle: includes every reachable node, not just active callbacks. */
|
|
93
|
+
export function stateSweepAfterTickRegistrationCountForTests(): number {
|
|
94
|
+
let count = 0;
|
|
95
|
+
for (const top of afterTickRegistrations.values()) {
|
|
96
|
+
let node: AfterTickRegistrationNode | null = top;
|
|
97
|
+
while (node) { count += 1; node = node.previous; }
|
|
98
|
+
}
|
|
99
|
+
return count;
|
|
100
|
+
}
|
|
101
|
+
|
|
81
102
|
function runCallbacks(
|
|
82
103
|
callback: (registration: StateStoreRegistration) => (() => number) | undefined,
|
|
83
104
|
): StateSweepResult {
|
|
@@ -121,6 +142,7 @@ export function sweepLiveness(): StateSweepResult {
|
|
|
121
142
|
|
|
122
143
|
function runAfterTickCallbacks(): void {
|
|
123
144
|
for (const { registration } of afterTickRegistrations.values()) {
|
|
145
|
+
if (!registration) continue;
|
|
124
146
|
try {
|
|
125
147
|
registration.afterTick();
|
|
126
148
|
} catch {
|
|
@@ -171,13 +193,17 @@ export function startStateStoreSweeper(
|
|
|
171
193
|
): { stop(): void } {
|
|
172
194
|
stopStateStoreSweeper();
|
|
173
195
|
const now = options.now ?? Date.now;
|
|
174
|
-
|
|
196
|
+
const ownedInterval = setInterval(() => {
|
|
175
197
|
sweepExpired(now());
|
|
176
198
|
sweepLiveness();
|
|
177
199
|
runAfterTickCallbacks();
|
|
178
200
|
}, options.intervalMs ?? STATE_SWEEP_INTERVAL_MS);
|
|
179
|
-
interval
|
|
180
|
-
|
|
201
|
+
interval = ownedInterval;
|
|
202
|
+
ownedInterval.unref?.();
|
|
203
|
+
return { stop() {
|
|
204
|
+
// An old server owner must not stop a newer owner's replacement timer.
|
|
205
|
+
if (interval === ownedInterval) stopStateStoreSweeper();
|
|
206
|
+
} };
|
|
181
207
|
}
|
|
182
208
|
|
|
183
209
|
export function stopStateStoreSweeper(): void {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resolveWindowsNativePrincipal } from "./windows-native-principal";
|
|
2
|
+
|
|
3
|
+
declare const self: Worker;
|
|
4
|
+
self.addEventListener("message", () => {
|
|
5
|
+
try {
|
|
6
|
+
const identity = resolveWindowsNativePrincipal();
|
|
7
|
+
self.postMessage(identity ? { kind: "identity", ...identity } : { kind: "unavailable" });
|
|
8
|
+
} catch {
|
|
9
|
+
self.postMessage({ kind: "failure" });
|
|
10
|
+
} finally {
|
|
11
|
+
// Native token/string/DLL finally blocks completed before the result was posted.
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
}, { once: true });
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { dlopen, ptr, read, type Pointer } from "bun:ffi";
|
|
2
|
+
import { win32 } from "node:path";
|
|
3
|
+
import { readWindowsCurrentSid, type WindowsTokenSidApi } from "../codex/windows-current-sid";
|
|
4
|
+
import { resolveTrustedWindowsSystemDirectory } from "./windows-elevation";
|
|
5
|
+
import { spawnWorker } from "./worker-embed";
|
|
6
|
+
|
|
7
|
+
export interface NativeWindowsPrincipal { readonly sid: string; readonly name: string }
|
|
8
|
+
export interface WindowsNativePrincipalApi extends WindowsTokenSidApi {
|
|
9
|
+
lookupAccountSid(sid: number, name: Uint16Array | null, nameLength: Uint32Array,
|
|
10
|
+
domain: Uint16Array | null, domainLength: Uint32Array, use: Uint32Array): number;
|
|
11
|
+
lastError(): number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const MAX_ACCOUNT_CODE_UNITS = 32_768;
|
|
15
|
+
function lookupError(): Error { return new Error("Windows native account translation failed."); }
|
|
16
|
+
|
|
17
|
+
function wideString(buffer: Uint16Array, reported: number): string {
|
|
18
|
+
if (reported > buffer.length) throw lookupError();
|
|
19
|
+
const end = buffer.indexOf(0);
|
|
20
|
+
if (end < 0) throw lookupError();
|
|
21
|
+
const value = String.fromCharCode(...buffer.subarray(0, end));
|
|
22
|
+
if (/[\r\n]/.test(value)) throw lookupError();
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function accountName(api: WindowsNativePrincipalApi, sid: number): string {
|
|
27
|
+
const nameLength = new Uint32Array(1), domainLength = new Uint32Array(1), use = new Uint32Array(1);
|
|
28
|
+
const sized = api.lookupAccountSid(sid, null, nameLength, null, domainLength, use);
|
|
29
|
+
const error = sized === 0 ? api.lastError() : 0;
|
|
30
|
+
if (sized !== 0 || error !== 122 || nameLength[0]! < 2
|
|
31
|
+
|| nameLength[0]! > MAX_ACCOUNT_CODE_UNITS || domainLength[0]! > MAX_ACCOUNT_CODE_UNITS) {
|
|
32
|
+
throw lookupError();
|
|
33
|
+
}
|
|
34
|
+
const name = new Uint16Array(nameLength[0]!);
|
|
35
|
+
// An empty domain is valid; its storage still needs a non-null, addressable NUL.
|
|
36
|
+
const domain = new Uint16Array(Math.max(1, domainLength[0]!));
|
|
37
|
+
domainLength[0] = domain.length;
|
|
38
|
+
if (api.lookupAccountSid(sid, name, nameLength, domain, domainLength, use) === 0) {
|
|
39
|
+
// No resize/retry downgrade: an unmapped SID or changing requirement refuses.
|
|
40
|
+
throw lookupError();
|
|
41
|
+
}
|
|
42
|
+
const account = wideString(name, nameLength[0]!);
|
|
43
|
+
const authority = wideString(domain, domainLength[0]!);
|
|
44
|
+
if (!account) throw lookupError();
|
|
45
|
+
return authority ? `${authority}\\${account}` : account;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Reuse the token reader's lifetime; translate its live binary SID before allocating the string. */
|
|
49
|
+
export function readWindowsNativePrincipal(api: WindowsNativePrincipalApi): NativeWindowsPrincipal {
|
|
50
|
+
let name = "";
|
|
51
|
+
const sid = readWindowsCurrentSid({
|
|
52
|
+
...api,
|
|
53
|
+
convertSidToStringSid(address, output) {
|
|
54
|
+
// The reader synchronously invokes this while retaining TOKEN_USER's backing buffer.
|
|
55
|
+
name = accountName(api, address);
|
|
56
|
+
return api.convertSidToStringSid(address, output);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
return Object.freeze({ sid, name });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface NativeResolution {
|
|
63
|
+
platform: NodeJS.Platform;
|
|
64
|
+
arch: string;
|
|
65
|
+
systemDirectory(): string;
|
|
66
|
+
load: typeof dlopen;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Null means unsupported native execution. DLL/path/API failures propagate, never downgrade. */
|
|
70
|
+
export function resolveWindowsNativePrincipal(resolution: NativeResolution = {
|
|
71
|
+
platform: process.platform, arch: process.arch,
|
|
72
|
+
systemDirectory: resolveTrustedWindowsSystemDirectory, load: dlopen,
|
|
73
|
+
}): NativeWindowsPrincipal | null {
|
|
74
|
+
if (resolution.platform !== "win32" || resolution.arch !== "x64") return null;
|
|
75
|
+
const directory = resolution.systemDirectory();
|
|
76
|
+
const advapi = resolution.load(win32.join(directory, "advapi32.dll"), {
|
|
77
|
+
OpenProcessToken: { args: ["u64", "u32", "ptr"], returns: "i32" },
|
|
78
|
+
GetTokenInformation: { args: ["u64", "u32", "ptr", "u32", "ptr"], returns: "i32" },
|
|
79
|
+
ConvertSidToStringSidW: { args: ["ptr", "ptr"], returns: "i32" },
|
|
80
|
+
LookupAccountSidW: { args: ["ptr", "ptr", "ptr", "ptr", "ptr", "ptr", "ptr"], returns: "i32" },
|
|
81
|
+
});
|
|
82
|
+
try {
|
|
83
|
+
const kernel = resolution.load(win32.join(directory, "kernel32.dll"), {
|
|
84
|
+
GetCurrentProcess: { args: [], returns: "u64" },
|
|
85
|
+
CloseHandle: { args: ["u64"], returns: "i32" },
|
|
86
|
+
LocalFree: { args: ["ptr"], returns: "ptr" },
|
|
87
|
+
GetLastError: { args: [], returns: "u32" },
|
|
88
|
+
});
|
|
89
|
+
try {
|
|
90
|
+
return readWindowsNativePrincipal({
|
|
91
|
+
openProcessToken: (access, output) => advapi.symbols.OpenProcessToken(
|
|
92
|
+
kernel.symbols.GetCurrentProcess(), access, ptr(output)),
|
|
93
|
+
getTokenInformation: (token, kind, buffer, length) => advapi.symbols.GetTokenInformation(
|
|
94
|
+
token, kind, ptr(buffer), buffer.byteLength, ptr(length)),
|
|
95
|
+
convertSidToStringSid: (address, output) => advapi.symbols.ConvertSidToStringSidW(
|
|
96
|
+
address as Pointer, ptr(output)),
|
|
97
|
+
lookupAccountSid: (address, name, nameLength, domain, domainLength, use) =>
|
|
98
|
+
advapi.symbols.LookupAccountSidW(null, address as Pointer, name ? ptr(name) : null,
|
|
99
|
+
ptr(nameLength), domain ? ptr(domain) : null, ptr(domainLength), ptr(use)),
|
|
100
|
+
lastError: () => kernel.symbols.GetLastError(),
|
|
101
|
+
readCodeUnit: (address, offset) => read.u16(address as Pointer, offset),
|
|
102
|
+
localFree: address => { kernel.symbols.LocalFree(address as Pointer); },
|
|
103
|
+
closeHandle: token => { kernel.symbols.CloseHandle(token); },
|
|
104
|
+
});
|
|
105
|
+
} finally { kernel.close(); }
|
|
106
|
+
} finally { advapi.close(); }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface NativePrincipalTiming {
|
|
110
|
+
now(): number;
|
|
111
|
+
schedule(callback: () => void, milliseconds: number): () => void;
|
|
112
|
+
}
|
|
113
|
+
const timing: NativePrincipalTiming = {
|
|
114
|
+
now: () => performance.now(),
|
|
115
|
+
schedule: (callback, milliseconds) => {
|
|
116
|
+
const timer = setTimeout(callback, milliseconds);
|
|
117
|
+
return () => clearTimeout(timer);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** A worker may remain in FFI after a caller expires; its slot belongs to closure, not the caller. */
|
|
122
|
+
export function createWindowsNativePrincipalLookup(
|
|
123
|
+
createWorker: () => Worker = () => spawnWorker(
|
|
124
|
+
new URL("./windows-native-principal-worker.ts", import.meta.url).href, "windows-native-principal-worker"),
|
|
125
|
+
): (timeoutMs: number, clock?: NativePrincipalTiming) => Promise<NativeWindowsPrincipal | null> {
|
|
126
|
+
let active: { result: Promise<NativeWindowsPrincipal | null> } | null = null;
|
|
127
|
+
const start = () => {
|
|
128
|
+
const worker = createWorker();
|
|
129
|
+
let resolve!: (identity: NativeWindowsPrincipal | null) => void, reject!: (error: Error) => void;
|
|
130
|
+
const job = { result: new Promise<NativeWindowsPrincipal | null>((yes, no) => { resolve = yes; reject = no; }) };
|
|
131
|
+
void job.result.catch(() => {});
|
|
132
|
+
active = job;
|
|
133
|
+
let response: NativeWindowsPrincipal | null | undefined;
|
|
134
|
+
let received = false;
|
|
135
|
+
const fail = () => reject(lookupError());
|
|
136
|
+
worker.addEventListener("message", event => {
|
|
137
|
+
if (received) { fail(); return; }
|
|
138
|
+
received = true;
|
|
139
|
+
const message: unknown = event.data;
|
|
140
|
+
if (!message || typeof message !== "object") { fail(); return; }
|
|
141
|
+
const data = message as Record<string, unknown>;
|
|
142
|
+
if (data.kind === "unavailable") response = null;
|
|
143
|
+
else if (data.kind === "identity" && typeof data.sid === "string" && typeof data.name === "string") {
|
|
144
|
+
response = { sid: data.sid, name: data.name };
|
|
145
|
+
} else fail();
|
|
146
|
+
});
|
|
147
|
+
worker.addEventListener("error", fail);
|
|
148
|
+
worker.addEventListener("messageerror", fail);
|
|
149
|
+
worker.addEventListener("close", () => {
|
|
150
|
+
if (active === job) active = null;
|
|
151
|
+
if (received && response !== undefined) resolve(response);
|
|
152
|
+
else fail();
|
|
153
|
+
}, { once: true });
|
|
154
|
+
(worker as Worker & { unref(): void }).unref();
|
|
155
|
+
try { worker.postMessage({ kind: "lookup" }); }
|
|
156
|
+
catch { fail(); }
|
|
157
|
+
return job;
|
|
158
|
+
};
|
|
159
|
+
return (timeoutMs, clock = timing) => {
|
|
160
|
+
const deadline = clock.now() + timeoutMs;
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
let settled = false, cancel = () => {};
|
|
163
|
+
const finish = (error?: unknown, identity?: NativeWindowsPrincipal | null) => {
|
|
164
|
+
if (settled) return;
|
|
165
|
+
settled = true; cancel();
|
|
166
|
+
if (error) reject(error); else resolve(identity!);
|
|
167
|
+
};
|
|
168
|
+
const expired = () => finish(new Error("Windows native principal lookup timed out."));
|
|
169
|
+
if (timeoutMs <= 0) { expired(); return; }
|
|
170
|
+
cancel = clock.schedule(expired, timeoutMs);
|
|
171
|
+
if (settled) { cancel(); return; }
|
|
172
|
+
try {
|
|
173
|
+
const job = active ?? start();
|
|
174
|
+
// Timer callbacks can lag synchronous worker construction or promise delivery.
|
|
175
|
+
if (clock.now() >= deadline) expired();
|
|
176
|
+
void job.result.then(identity => {
|
|
177
|
+
if (clock.now() >= deadline) expired(); else finish(undefined, identity);
|
|
178
|
+
}, error => finish(error));
|
|
179
|
+
} catch (error) { finish(error); }
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const nativeLookup = createWindowsNativePrincipalLookup();
|
|
185
|
+
export function resolveWindowsNativePrincipalAsync(timeoutMs: number): Promise<NativeWindowsPrincipal | null> {
|
|
186
|
+
if (process.platform !== "win32" || process.arch !== "x64") return Promise.resolve(null);
|
|
187
|
+
return nativeLookup(timeoutMs);
|
|
188
|
+
}
|
|
@@ -493,7 +493,7 @@ function pathIsAtOrBelow(target: string, root: string): boolean {
|
|
|
493
493
|
return suffix !== ".." && !suffix.startsWith(`..${sep}`) && !isAbsolute(suffix);
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
function retainedWorkIsAtOrBelow(entry: AsyncAclWork, root: RemovalIdentity): boolean {
|
|
496
|
+
function retainedWorkIsAtOrBelow(entry: AsyncAclWork, root: RemovalIdentity, includeAncestors = false): boolean {
|
|
497
497
|
const target = entry.identity;
|
|
498
498
|
// Failure at capture stays conservative, even if the alias later becomes readable.
|
|
499
499
|
if (target.canonical === undefined || root.canonical === undefined) return true;
|
|
@@ -501,7 +501,43 @@ function retainedWorkIsAtOrBelow(entry: AsyncAclWork, root: RemovalIdentity): bo
|
|
|
501
501
|
if (current === undefined) return true;
|
|
502
502
|
const targets = [target.lexical, target.canonical, current];
|
|
503
503
|
return [root.lexical, root.canonical].some(rootPath =>
|
|
504
|
-
targets.some(targetPath => pathIsAtOrBelow(targetPath, rootPath)
|
|
504
|
+
targets.some(targetPath => pathIsAtOrBelow(targetPath, rootPath)
|
|
505
|
+
|| (includeAncestors && pathIsAtOrBelow(rootPath, targetPath))));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Admission can refuse without surrendering the registry's retained-child cleanup ownership. */
|
|
509
|
+
export class WindowsSecretAclSettleTimeoutError extends Error {
|
|
510
|
+
readonly code = "ETIMEDOUT";
|
|
511
|
+
readonly aclFailureOrigin = "acl_settle_timeout";
|
|
512
|
+
constructor() { super("ACL settlement timed out"); this.name = "WindowsSecretAclSettleTimeoutError"; }
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/** Run a synchronous mutation after overlapping ACL work exits, within one harden budget. */
|
|
516
|
+
export async function withWindowsSecretAclSettled<T>(rootPath: string, mutate: () => T): Promise<T> {
|
|
517
|
+
const deadline = nowFn() + resolveHardenDeadlineMs();
|
|
518
|
+
const root = captureRemovalIdentity(rootPath);
|
|
519
|
+
let cancelDeadline: (() => void) | undefined;
|
|
520
|
+
let timeout: Promise<never> | undefined;
|
|
521
|
+
let expired = false;
|
|
522
|
+
try {
|
|
523
|
+
while (true) {
|
|
524
|
+
if (expired || nowFn() >= deadline) throw new WindowsSecretAclSettleTimeoutError();
|
|
525
|
+
const pending = [...activeAsyncAclWork.values(), ...pendingAsyncIcaclsReaps.values()]
|
|
526
|
+
.flatMap(entries => [...entries])
|
|
527
|
+
.filter(entry => retainedWorkIsAtOrBelow(entry, root, true))
|
|
528
|
+
.map(entry => entry.reap);
|
|
529
|
+
// No await between this final observation and the mutation. A newly queued hardener's
|
|
530
|
+
// microtasks cannot run icacls until the synchronous callback has completely returned.
|
|
531
|
+
if (pending.length === 0) return mutate();
|
|
532
|
+
timeout ??= new Promise<never>((_resolve, reject) => {
|
|
533
|
+
cancelDeadline = asyncIcaclsBeltScheduler(() => {
|
|
534
|
+
expired = true;
|
|
535
|
+
reject(new WindowsSecretAclSettleTimeoutError());
|
|
536
|
+
}, Math.max(1, deadline - nowFn()));
|
|
537
|
+
});
|
|
538
|
+
await Promise.race([Promise.all(pending), timeout]);
|
|
539
|
+
}
|
|
540
|
+
} finally { cancelDeadline?.(); }
|
|
505
541
|
}
|
|
506
542
|
|
|
507
543
|
/** True while an async icacls runner still owns this exact path after its caller's belt fired. */
|
|
@@ -550,7 +586,7 @@ export function setAsyncIcaclsRunnerForTests(runner: AsyncIcaclsRunner | null):
|
|
|
550
586
|
asyncIcaclsRunner = runner ?? defaultAsyncIcaclsRunner;
|
|
551
587
|
}
|
|
552
588
|
|
|
553
|
-
/** Test seam:
|
|
589
|
+
/** Test seam: drive child belts and admission deadlines without sleeping. */
|
|
554
590
|
export function setAsyncIcaclsBeltSchedulerForTests(
|
|
555
591
|
scheduler: SubprocessDeadlineScheduler | null,
|
|
556
592
|
): void {
|
|
@@ -12,18 +12,21 @@
|
|
|
12
12
|
* different account holding the secret or strands the file with no usable ACE.
|
|
13
13
|
* When the SID cannot be resolved, the caller declines to touch the ACL at all.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* would mean passing an absolute deadline through the runner interface.
|
|
15
|
+
* Windows x64 reads SID and account name natively. The async path owns one
|
|
16
|
+
* Worker through closure, with a separate monotonic deadline per caller. A late
|
|
17
|
+
* result cannot enter the successful identity cache. The sync path checks elapsed
|
|
18
|
+
* time after its native call; synchronous FFI cannot be interrupted. Unsupported
|
|
19
|
+
* architectures retain the trusted, bounded PowerShell helper.
|
|
21
20
|
*/
|
|
22
21
|
|
|
23
22
|
import { existsSync } from "node:fs";
|
|
24
23
|
import { win32 as windowsPath } from "node:path";
|
|
25
24
|
import { waitForSubprocessExit } from "./bounded-subprocess";
|
|
26
25
|
import { decodeWindowsTextBytes } from "./windows-text";
|
|
26
|
+
import {
|
|
27
|
+
resolveWindowsNativePrincipal, resolveWindowsNativePrincipalAsync,
|
|
28
|
+
type NativeWindowsPrincipal,
|
|
29
|
+
} from "./windows-native-principal";
|
|
27
30
|
|
|
28
31
|
import {
|
|
29
32
|
resolveTrustedWindowsPowerShellExe,
|
|
@@ -31,7 +34,7 @@ import {
|
|
|
31
34
|
} from "./windows-elevation";
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
|
-
* Shared ceiling for a full effective-token identity lookup. PowerShell startup can
|
|
37
|
+
* Shared ceiling for a full effective-token identity lookup. Fallback PowerShell startup can
|
|
35
38
|
* legitimately take several seconds on loaded desktops as well as CI, so every caller
|
|
36
39
|
* that is not spending a smaller pre-existing deadline uses the same #2914-tested budget.
|
|
37
40
|
*/
|
|
@@ -133,11 +136,16 @@ export function windowsPrincipalPowerShellCommandForTests(): string[] {
|
|
|
133
136
|
}
|
|
134
137
|
|
|
135
138
|
function defaultWindowsPrincipalRunner(timeoutMs: number): WindowsPrincipalLookupResult {
|
|
139
|
+
const started = performance.now();
|
|
140
|
+
const native = nativeLookups.sync();
|
|
141
|
+
const remaining = timeoutMs - (performance.now() - started);
|
|
142
|
+
if (remaining <= 0) return { success: false, exitCode: null, timedOut: true, stdout: "" };
|
|
143
|
+
if (native) return nativeResult(native);
|
|
136
144
|
const result = Bun.spawnSync(windowsPrincipalPowerShellCommand(), {
|
|
137
145
|
stdin: "ignore",
|
|
138
146
|
stdout: "pipe",
|
|
139
147
|
stderr: "ignore",
|
|
140
|
-
timeout: Math.max(1,
|
|
148
|
+
timeout: Math.max(1, remaining),
|
|
141
149
|
windowsHide: true,
|
|
142
150
|
});
|
|
143
151
|
return {
|
|
@@ -154,6 +162,11 @@ function defaultWindowsPrincipalRunner(timeoutMs: number): WindowsPrincipalLooku
|
|
|
154
162
|
async function defaultAsyncWindowsPrincipalRunner(
|
|
155
163
|
timeoutMs: number,
|
|
156
164
|
): Promise<WindowsPrincipalLookupResult> {
|
|
165
|
+
const started = performance.now();
|
|
166
|
+
const native = await nativeLookups.async(timeoutMs);
|
|
167
|
+
const remaining = timeoutMs - (performance.now() - started);
|
|
168
|
+
if (remaining <= 0) return { success: false, exitCode: null, timedOut: true, stdout: "" };
|
|
169
|
+
if (native) return nativeResult(native);
|
|
157
170
|
const proc = Bun.spawn(windowsPrincipalPowerShellCommand(), {
|
|
158
171
|
stdin: "ignore",
|
|
159
172
|
stdout: "pipe",
|
|
@@ -164,7 +177,7 @@ async function defaultAsyncWindowsPrincipalRunner(
|
|
|
164
177
|
// remove; this lookup holds no such path, and it runs during `ocx start`, where the composed
|
|
165
178
|
// acceptance cases already measure real startups at up to 38.8s against a bounded watchdog.
|
|
166
179
|
// Paying two extra seconds per timed-out resolution there buys nothing and costs margin.
|
|
167
|
-
const { exitCode, timedOut } = await waitForSubprocessExit(proc,
|
|
180
|
+
const { exitCode, timedOut } = await waitForSubprocessExit(proc, remaining, 0);
|
|
168
181
|
// `.bytes()` rather than `.text()`, for the same reason as the sync runner above.
|
|
169
182
|
const stdout: string | Uint8Array = !timedOut && proc.stdout
|
|
170
183
|
? await new Response(proc.stdout).bytes().catch(() => new Uint8Array())
|
|
@@ -180,6 +193,19 @@ async function defaultAsyncWindowsPrincipalRunner(
|
|
|
180
193
|
let principalRunner: WindowsPrincipalRunner = defaultWindowsPrincipalRunner;
|
|
181
194
|
let asyncPrincipalRunner: AsyncWindowsPrincipalRunner = defaultAsyncWindowsPrincipalRunner;
|
|
182
195
|
let principalLocaleForTests: string | undefined;
|
|
196
|
+
const defaultNativeLookups = { sync: resolveWindowsNativePrincipal, async: resolveWindowsNativePrincipalAsync };
|
|
197
|
+
let nativeLookups = defaultNativeLookups;
|
|
198
|
+
let defaultAsyncCallers = 0;
|
|
199
|
+
function nativeResult(identity: NativeWindowsPrincipal): WindowsPrincipalLookupResult {
|
|
200
|
+
return { success: true, exitCode: 0, timedOut: false, stdout: `${identity.sid}\n${identity.name}` };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Boundary injection; undefined restores production. Existing runner overrides still win. */
|
|
204
|
+
export function setNativeWindowsPrincipalLookupsForTests(next: typeof defaultNativeLookups | null): void {
|
|
205
|
+
if (asyncLookupInFlight || defaultAsyncCallers) throw new Error("Cannot replace a native lookup in flight.");
|
|
206
|
+
nativeLookups = next ?? defaultNativeLookups;
|
|
207
|
+
cachedIdentity = null;
|
|
208
|
+
}
|
|
183
209
|
|
|
184
210
|
/**
|
|
185
211
|
* Decode child stdout the way the rest of this repository already decodes Windows
|
|
@@ -288,13 +314,16 @@ export function resolveCurrentWindowsPrincipal(timeoutMs: number): string {
|
|
|
288
314
|
if (cachedIdentity) return `*${cachedIdentity.sid}`;
|
|
289
315
|
if (syntheticPrincipalForTests) return syntheticPrincipalForTests;
|
|
290
316
|
if (timeoutMs <= 0) throw identityError("had no remaining deadline");
|
|
317
|
+
const deadline = performance.now() + timeoutMs;
|
|
291
318
|
let result: WindowsPrincipalLookupResult;
|
|
292
319
|
try {
|
|
293
320
|
result = principalRunner(timeoutMs);
|
|
294
321
|
} catch {
|
|
295
322
|
throw identityError("could not start");
|
|
296
323
|
}
|
|
297
|
-
|
|
324
|
+
const identity = identityFromResult(result);
|
|
325
|
+
if (performance.now() >= deadline) throw identityError("timed out");
|
|
326
|
+
cachedIdentity = identity;
|
|
298
327
|
return `*${cachedIdentity.sid}`;
|
|
299
328
|
}
|
|
300
329
|
|
|
@@ -320,10 +349,9 @@ async function waitForExistingLookup(
|
|
|
320
349
|
}
|
|
321
350
|
|
|
322
351
|
/**
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
* later, longer budget deliberately does not extend an already-running child.
|
|
352
|
+
* Native callers share one Worker with independent waits. Fallback/injected
|
|
353
|
+
* child runners retain the first caller's owned process timeout; later callers
|
|
354
|
+
* may exhaust their own wait without extending or cancelling that child.
|
|
327
355
|
*/
|
|
328
356
|
export async function resolveCurrentWindowsPrincipalAsync(timeoutMs: number): Promise<string> {
|
|
329
357
|
const overridden = hasAsyncRunnerOverride();
|
|
@@ -333,6 +361,22 @@ export async function resolveCurrentWindowsPrincipalAsync(timeoutMs: number): Pr
|
|
|
333
361
|
if (!overridden && syntheticPrincipalForTests) return syntheticPrincipalForTests;
|
|
334
362
|
if (timeoutMs <= 0) throw identityError("had no remaining deadline");
|
|
335
363
|
|
|
364
|
+
// Native jobs own their Worker through close; each caller owns its own wait/cache admission.
|
|
365
|
+
// Keep the old first-owner child timeout contract for explicit runners and ARM64 fallback.
|
|
366
|
+
if (!overridden && process.platform === "win32" && process.arch === "x64") {
|
|
367
|
+
defaultAsyncCallers += 1;
|
|
368
|
+
try {
|
|
369
|
+
const deadline = performance.now() + timeoutMs;
|
|
370
|
+
let result: WindowsPrincipalLookupResult;
|
|
371
|
+
try { result = await defaultAsyncWindowsPrincipalRunner(timeoutMs); }
|
|
372
|
+
catch { throw identityError("could not complete the native lookup"); }
|
|
373
|
+
const identity = identityFromResult(result);
|
|
374
|
+
if (performance.now() >= deadline) throw identityError("timed out");
|
|
375
|
+
cachedIdentity = identity;
|
|
376
|
+
return `*${cachedIdentity.sid}`;
|
|
377
|
+
} finally { defaultAsyncCallers -= 1; }
|
|
378
|
+
}
|
|
379
|
+
|
|
336
380
|
const lookup = (async (): Promise<string> => {
|
|
337
381
|
let result: WindowsPrincipalLookupResult;
|
|
338
382
|
try {
|
|
@@ -355,7 +399,7 @@ export async function resolveCurrentWindowsPrincipalAsync(timeoutMs: number): Pr
|
|
|
355
399
|
export function setWindowsPrincipalRunnerForTests(
|
|
356
400
|
runner: WindowsPrincipalRunner | null,
|
|
357
401
|
): void {
|
|
358
|
-
if (asyncLookupInFlight) {
|
|
402
|
+
if (asyncLookupInFlight || defaultAsyncCallers) {
|
|
359
403
|
throw new Error("Cannot replace the Windows principal runner while a lookup is in flight.");
|
|
360
404
|
}
|
|
361
405
|
principalRunner = runner ?? defaultWindowsPrincipalRunner;
|
|
@@ -366,7 +410,7 @@ export function setWindowsPrincipalRunnerForTests(
|
|
|
366
410
|
export function setAsyncWindowsPrincipalRunnerForTests(
|
|
367
411
|
runner: AsyncWindowsPrincipalRunner | null,
|
|
368
412
|
): void {
|
|
369
|
-
if (asyncLookupInFlight) {
|
|
413
|
+
if (asyncLookupInFlight || defaultAsyncCallers) {
|
|
370
414
|
throw new Error("Cannot replace the Windows principal runner while a lookup is in flight.");
|
|
371
415
|
}
|
|
372
416
|
asyncPrincipalRunner = runner ?? defaultAsyncWindowsPrincipalRunner;
|
|
@@ -386,7 +430,7 @@ export function setAsyncWindowsPrincipalRunnerForTests(
|
|
|
386
430
|
* decodes after its runner resolves.
|
|
387
431
|
*/
|
|
388
432
|
export function setWindowsPrincipalLocaleForTests(locale: string | null): void {
|
|
389
|
-
if (asyncLookupInFlight) {
|
|
433
|
+
if (asyncLookupInFlight || defaultAsyncCallers) {
|
|
390
434
|
throw new Error("Cannot change the Windows principal locale while a lookup is in flight.");
|
|
391
435
|
}
|
|
392
436
|
principalLocaleForTests = locale ?? undefined;
|
|
@@ -395,7 +439,7 @@ export function setWindowsPrincipalLocaleForTests(locale: string | null): void {
|
|
|
395
439
|
|
|
396
440
|
/** Test seam: clear only process-local principal state. */
|
|
397
441
|
export function resetWindowsPrincipalForTests(): void {
|
|
398
|
-
if (asyncLookupInFlight) {
|
|
442
|
+
if (asyncLookupInFlight || defaultAsyncCallers) {
|
|
399
443
|
throw new Error("Cannot reset the Windows principal while a lookup is in flight.");
|
|
400
444
|
}
|
|
401
445
|
cachedIdentity = null;
|
package/src/link/ssh-config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
4
4
|
import { isSshAlias } from "./ssh-argv";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -117,11 +117,43 @@ export interface LoadHostCandidatesOptions {
|
|
|
117
117
|
glob?: (pattern: string) => string[];
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/** OpenSSH Include uses glob(..., GLOB_TILDE): parentheses and braces are literal. */
|
|
121
|
+
function normalizeIncludeGlob(pattern: string): string {
|
|
122
|
+
let normalized = "";
|
|
123
|
+
for (let i = 0; i < pattern.length; i += 1) {
|
|
124
|
+
const char = pattern[i]!;
|
|
125
|
+
if (char === "\\" && i + 1 < pattern.length) {
|
|
126
|
+
normalized += char + pattern[++i];
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (char === "[") {
|
|
130
|
+
let end = i + 1;
|
|
131
|
+
if (pattern[end] === "!" || pattern[end] === "^") end += 1;
|
|
132
|
+
if (pattern[end] === "]") end += 1;
|
|
133
|
+
for (; end < pattern.length; end += 1) {
|
|
134
|
+
if (pattern[end] === "\\") end += 1;
|
|
135
|
+
else if (pattern[end] === "]") break;
|
|
136
|
+
}
|
|
137
|
+
if (end < pattern.length) {
|
|
138
|
+
normalized += pattern.slice(i, end + 1);
|
|
139
|
+
i = end;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// Keep a malformed suffix intact: generated quoting must not close its class.
|
|
143
|
+
return normalized + pattern.slice(i);
|
|
144
|
+
}
|
|
145
|
+
// Character classes work on both Bun versions, without enabling 1.4.4's extglobs.
|
|
146
|
+
normalized += char === "(" ? "[(]" : char === "{" ? "[{]" : char;
|
|
147
|
+
}
|
|
148
|
+
return normalized;
|
|
149
|
+
}
|
|
150
|
+
|
|
120
151
|
function defaultGlob(pattern: string): string[] {
|
|
121
152
|
if (!/[*?[]/.test(pattern)) return [pattern];
|
|
122
153
|
const base = dirname(pattern.slice(0, pattern.search(/[*?[]/) + 1));
|
|
123
|
-
|
|
124
|
-
|
|
154
|
+
// Only native Windows separators become slashes; POSIX backslash escapes stay intact.
|
|
155
|
+
const relative = pattern.slice(base.length + 1).split(sep).join("/");
|
|
156
|
+
return [...new Bun.Glob(normalizeIncludeGlob(relative)).scanSync({ cwd: base, absolute: true, onlyFiles: true })].sort();
|
|
125
157
|
}
|
|
126
158
|
|
|
127
159
|
/**
|