agent-transport-system 0.7.97 → 0.7.99
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/README.md +2 -1
- package/dist/{add-me-membership-CT_vAgoU.js → add-me-membership-Cfi5fbyb.js} +3 -3
- package/dist/{add-me-membership-CT_vAgoU.js.map → add-me-membership-Cfi5fbyb.js.map} +1 -1
- package/dist/{api-client-foundation-DFdzzDaR.js → api-client-foundation-CBoyrvoT.js} +1 -1
- package/dist/ats-dev.js +2 -2
- package/dist/ats.js +1682 -955
- package/dist/ats.js.map +1 -1
- package/dist/{auth-session-DBnyC4LY.js → auth-session-DbA1IFeL.js} +1 -1
- package/dist/{base-url-SXaImoj4.js → base-url-CiDhrDeP.js} +2 -2
- package/dist/{base-url-SXaImoj4.js.map → base-url-CiDhrDeP.js.map} +1 -1
- package/dist/{daemon-runtime-lease-DzRz8pH5.js → daemon-runtime-lease-D1x-3a2_.js} +1 -1
- package/dist/{dist-zUuzNkK0.js → dist-DV2pViNq.js} +1 -1
- package/dist/{dist-CyQTYZTj.js → dist-DkHDSnUA.js} +103 -31
- package/dist/dist-DkHDSnUA.js.map +1 -0
- package/package.json +1 -1
- package/dist/dist-CyQTYZTj.js.map +0 -1
package/dist/ats.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { C as updateConfiguredSkillsConfig, S as updateConfiguredOnboardingConfig, _ as getRuntimeConfigReadHealth, a as resolveBaseUrl, b as setConfiguredSkillsConfig, c as resolveExplicitGatewayUrlOrThrow, d as createDefaultRuntimeAgentControllerSettings, f as getConfiguredDaemonDispatchLimits, g as getConfiguredViewCustomization, h as getConfiguredSkillsConfig, i as normalizeGatewayBaseUrlOrNull, l as DEFAULT_RUNTIME_AGENT_TRANSPORT_MODE, m as getConfiguredOnboardingDisclaimerAcceptedAt, o as resolveBaseUrlOrNull, p as getConfiguredDeviceRuntimeState, r as normalizeGatewayBaseUrl, s as resolveDefaultGatewayBaseUrl, u as alignRuntimeConfigStorage, v as resolveRuntimeSkillsCustomTargetId, w as updateConfiguredStartV1OnboardingState, x as updateConfiguredDeviceRuntimeState, y as setConfiguredBaseUrl } from "./base-url-
|
|
4
|
-
import { $ as getSpaceStatusResponseSchema, $n as
|
|
3
|
+
import { C as updateConfiguredSkillsConfig, S as updateConfiguredOnboardingConfig, _ as getRuntimeConfigReadHealth, a as resolveBaseUrl, b as setConfiguredSkillsConfig, c as resolveExplicitGatewayUrlOrThrow, d as createDefaultRuntimeAgentControllerSettings, f as getConfiguredDaemonDispatchLimits, g as getConfiguredViewCustomization, h as getConfiguredSkillsConfig, i as normalizeGatewayBaseUrlOrNull, l as DEFAULT_RUNTIME_AGENT_TRANSPORT_MODE, m as getConfiguredOnboardingDisclaimerAcceptedAt, o as resolveBaseUrlOrNull, p as getConfiguredDeviceRuntimeState, r as normalizeGatewayBaseUrl, s as resolveDefaultGatewayBaseUrl, u as alignRuntimeConfigStorage, v as resolveRuntimeSkillsCustomTargetId, w as updateConfiguredStartV1OnboardingState, x as updateConfiguredDeviceRuntimeState, y as setConfiguredBaseUrl } from "./base-url-CiDhrDeP.js";
|
|
4
|
+
import { $ as getSpaceStatusResponseSchema, $n as canonicalizeBuiltinAgentControllerRef, $t as spaceCreatorSchema, A as deleteSpaceResponseSchema, An as LEGACY_RUNTIME_DISPATCH_POLICY, Ar as runtimeTransportDeliverDispatchRequestSchema, At as postSpaceThreadSignalResponseSchema, B as getAgentExecutionReadinessBatchBodySchema, Bn as SPACE_MENTION_REJECT_NOTICE_PURPOSE, Br as runtimeTransportLocalAgentControlRefreshCatalogFramePayloadSchema, Bt as refreshCurrentLocalAgentCatalogResponseSchema, C as createSpaceThreadBodySchema, Cn as ATSD_CONTROL_PLANE_SCHEMA_VERSION, Cr as resolveBuiltinAgentControllerConversationKind, Ct as patchSpaceContractBodySchema, D as daemonRouteCatalogCacheSchema, Dn as DISPATCH_ACTIVITY_DISPATCHING_PURPOSE, Dt as postSpaceMembersBodySchema, E as currentLocalRuntimeReplyReadinessResponseSchema, En as CURRENT_DAEMON_EXECUTION_CONTRACT_EPOCH, Er as resolveSpaceMentionLabels, Et as postNormalMessageResponseSchema, F as forgetComputerResponseSchema, Fn as MAX_VISITED_PROFILE_IDS, Fr as runtimeTransportDispatchRuntimeEvidenceRequestSchema, Ft as projectObservabilityWakeCorrelation, G as getLocalRuntimeExpectedRoutesResponseSchema, Gn as atsdControlPlaneRequestSchema, Gr as runtimeTransportSubmitTaskResultRequestSchema, Gt as setCurrentLocalAgentEnabledResponseSchema, H as getAgentExecutionReadinessResponseSchema, Hn as SPACE_UPDATES_MAX_LIMIT, Hr as runtimeTransportRegisterSessionRequestSchema, Ht as resolveSpaceDispatchTraceRootCause, I as forgetCurrentComputerResponseSchema, In as MESSAGE_MENTION_TYPE_VALUES, Ir as runtimeTransportHeartbeatRequestSchema, It as projectSpaceDispatchTraceFinalVisibleOutcome, J as getPrepareReadinessResponseSchema, Jn as atsdTaskResultOpenClawGatewayVisibilityStatusSchema, Jt as setupPlanAgentViewEventSchema, K as getModelCatalogResponseSchema, Kn as atsdControlPlaneResponseSchema, Kr as sanitizeSignalTextPreview, Kt as setLocalRuntimeDisplayNameBodySchema, L as gatewayErrorCodeSchema, Ln as RUNTIME_TRANSPORT_SCHEMA_VERSION, Lr as runtimeTransportHeartbeatResponseSchema, Lt as redactPrepareStepDiagnosticsBundle, M as ensureAgentProfilePrimaryBindingBodySchema, Mn as MAX_PROFILE_ID_LENGTH, Mr as runtimeTransportDispatchLifecycleRequestSchema, Mt as prepareSessionStreamServerFrameSchema, N as ensureAgentProfilePrimaryBindingResponseSchema, Nn as MAX_PROFILE_WORKING_DIRECTORY_LENGTH, Nr as runtimeTransportDispatchPreviewEndRequestSchema, Nt as prepareSetupBootstrapWriteSchema, O as daemonRouteObservationResponseSchema, On as DISPATCH_ACTIVITY_FAILED_PURPOSE, Ot as postSpaceMembersResponseSchema, P as entryBriefSchema, Pn as MAX_SIGNAL_REPLY_TO_PREVIEW_LENGTH, Pr as runtimeTransportDispatchPreviewRequestSchema, Pt as prepareStepDiagnosticsBundleSchema, Q as getSpaceMessageDetailsResponseSchema, Qn as canonicalizeAgentControllerRef, Qt as spaceBootstrapResponseSchema, R as gatewayErrorEnvelopeSchema, Rn as SPACE_MEMBER_JOIN_NOTICE_PURPOSE, Rr as runtimeTransportLocalAgentControlCancelFramePayloadSchema, Rt as redactPrepareStepDiagnosticsText, S as createSpaceResponseSchema, Sn as AGENT_REPLY_PREVIEW_PURPOSE, Sr as providerDispatchRuntimeContextSchema, St as patchProfileSpaceHistoryStatusResponseSchema, T as currentDeviceTargetResponseSchema, Tn as CONVERSATION_CONTINUITY_WARNING_PURPOSE, Tr as resolveSingleSpaceMentionLabels, Tt as postNormalMessageBodySchema, U as getAgentProfilePrimaryBindingResponseSchema, Un as atsRuntimeProfileIdSchema, Ur as runtimeTransportRegisterSessionResponseSchema, Ut as serverErrorFrameSchema, V as getAgentExecutionReadinessBatchResponseSchema, Vn as SPACE_PASSWORD_MIN_LENGTH, Vr as runtimeTransportLocalAgentControlSetEnabledFramePayloadSchema, Vt as removeSpaceMembersResponseSchema, W as getLocalRuntimeExpectedRoutesQuerySchema, Wn as atsSpaceEgressActionSchema, Wr as runtimeTransportRouteCatalogChangedFramePayloadSchema, Wt as setCurrentLocalAgentEnabledBodySchema, X as getSpaceDispatchLookupResponseSchema, Xn as buildAgentControllerConversationRef, Xt as signalEnvelopeSchema, Y as getSpaceContractResponseSchema, Yn as atsdTaskResultPayloadSchema, Yt as setupPlanAgentViewPayloadSchema, Z as getSpaceDispatchResultResponseSchema, Zn as buildAgentControllerRoutingKey, Zt as spaceAccessModeStateSchema, _ as cliJsonOutputEnvelopeSchema, _n as writeCurrentDeviceObservedMetadataBodySchema, _r as parseAgentControllerRef$1, _t as normalizeSpaceCursorPatch, a as DAEMON_ROUTE_CATALOG_CACHE_SCHEMA_VERSION, an as spaceMetaSchema, ar as formatCanonicalMentionLiteral, at as leaveSpaceResponseSchema, b as createSpaceDiagnosticReportBodySchema, bn as AGENT_REPLYING_PURPOSE, br as postSpaceWakeStopResponseSchema, bt as notifyAgentProfilesRouteCatalogChangedBodySchema, c as SETUP_PLAN_AGENT_VIEW_CODE, cn as submitRuntimeAgentControllerReportsBodySchema, cr as formatLocalSetupActionDescription, ct as listSpaceThreadSignalsResponseSchema, d as accountSpaceIndexResponseSchema, dn as submitRuntimeProviderConversationProofsResponseSchema, dr as installedLocalComponentsSnapshotSchema, dt as localRuntimeEnrollmentBodySchema, en as spaceDispatchTraceResponseSchema, er as collectCanonicalMentionTextFragments, et as getSpaceThreadResponseSchema, f as agentControllerPermissionModeSchema, fn as submitRuntimeRegistrationBodySchema, fr as normalizeBuiltinAgentControllerId, ft as localRuntimeEnrollmentResponseSchema, g as catchupResponseSchema, gn as upsertProfileSpaceHistoryResponseSchema, gr as normalizeSpacePasswordText, gt as normalizeListSignalsReadQuerySemantics, h as atsRequestContextSchema, hn as updateAgentProfilePrimaryBindingModelSelectionBodySchema, hr as normalizeOptionalWorkingDirectory, ht as modelCatalogSchema, i as DAEMON_ROUTE_CATALOG_CACHE_SCHEMA_NAME, in as spaceMembersSnapshotSchema, ir as daemonStreamFrameSchema, it as incomingServerMessageSchema, j as dispatchBriefSchema, jn as LOCAL_COMPONENTS_SCHEMA_VERSION, jr as runtimeTransportDeliveryExecutionIdentitySchema, jt as prepareSessionResponseSchema, k as daemonRuntimeLeaseSchema, kn as DISPATCH_ACTIVITY_RETRYING_PURPOSE, kr as runtimeCoordinatorExecutionTokenEnvelopeSchema, kt as postSpaceThreadSignalBodySchema, l as SETUP_PLAN_AGENT_VIEW_SCHEMA_VERSION, ln as submitRuntimeAgentControllerReportsResponseSchema, lr as formatLocalSetupActionLabel, lt as listSpaceThreadsResponseSchema, m as agentProfileBindingRouteParamsSchema, mn as updateAgentProfilePrimaryBindingAgentControllerPermissionModeBodySchema, mr as normalizeMessageEnvelope, mt as localRuntimesResponseSchema, n as resolveBuiltinAgentControllerBrand, nn as spaceMemberDirectoryEntrySchema, nr as daemonServiceContractSchema, nt as getSpaceWakeProgressResponseSchema, o as PREPARE_SESSION_STREAM_PROTOCOL_VERSION, on as spaceViewerMembershipResponseSchema, or as formatLocalComponentsSummaryDescription, ot as listProfileSpaceHistoryResponseSchema, p as agentExecutionReadinessRouteParamsSchema, pn as submitRuntimeRegistrationResponseSchema, pr as normalizeKnownBuiltinAgentControllerId, pt as localRuntimesQuerySchema, q as getPrepareReadinessQuerySchema, qn as atsdTaskResultEnvelopeWriteSchema, qt as setSpaceAccessModeBodySchema, r as resolveMappedPublicAgentFailureReason, rn as spaceMemberDirectorySchema, rr as daemonServiceLaneSchema, rt as getSpaceWakeTraceWaterfallResponseSchema, s as PREPARE_STEP_DIAGNOSTICS_MAX_CHARS, sn as structuredGuidePayloadFromInputSchema, sr as formatLocalComponentsSummaryLabel, st as listSpaceThreadEventsResponseSchema, t as CODEX_UPGRADE_REQUIRED_REASON, tn as spaceIdentityDirectorySchema, tr as conversationExecutionStateSchema, tt as getSpaceUpdatesResponseSchema, u as SPACE_DISPATCH_TRACE_PROMPT_PREVIEW_MAX_CHARS, un as submitRuntimeProviderConversationProofsBodySchema, ur as getSpaceMessageAddressingRelationSupportForTargetKind, ut as localAgentCatalogSchema, v as continuitySchema, vn as writeCurrentDeviceObservedMetadataResponseSchema, vr as parseOptionalClientMessageId, vt as notifyAgentProfileRouteCatalogChangedBodySchema, w as createSpaceThreadResponseSchema, wn as ATSD_TASK_RESULT_SCHEMA_VERSION, wr as resolveMessageEnvelopeTargetField, wt as patchSpaceContractResponseSchema, x as createSpaceDiagnosticReportResponseSchema, xn as AGENT_REPLY_PREVIEW_END_PURPOSE, xr as profileWorkspaceModeSchema, xt as observabilityWakeTraceSelectorSchema, y as createSpaceBodySchema, yn as AGENT_REPLYING_END_PURPOSE, yr as postSpaceWakeStopBodySchema, yt as notifyAgentProfileRouteCatalogChangedResponseSchema, z as getActiveSpaceWakeProgressResponseSchema, zn as SPACE_MEMBER_REMOVE_NOTICE_PURPOSE, zr as runtimeTransportLocalAgentControlInterruptFramePayloadSchema, zt as redactPrepareStepDiagnosticsValue } from "./dist-DkHDSnUA.js";
|
|
5
5
|
import { A as runtimeDir, C as normalizeAtsProfileId, D as resolveAtsEnvPreset, E as resolveAtsCliEntryNameFromArgv, F as systemDir, N as skillsDir, O as resolveAtsRootDir, P as spacesDir, S as normalizeAccountKey, T as profileViewPath, a as accountProfileWorkspacePath, c as atsRootDir, d as deviceOpenClawProfileBootstrapPath, f as deviceOpenClawProfileDir, i as accountProfileViewPath, j as runtimeLogsDir, k as resolveDefaultAtsHomeDirname, n as accountProfileLocalMetaPath, o as accountsDir, p as deviceOpenClawProfileWorkspaceDir, r as accountProfileSpaceCacheDir, s as atsBackupsDir, t as ATS_HOME_ENV_KEY, w as profileDir, y as legacyAccountProfileSpacesDir } from "./paths-DP4LBid2.js";
|
|
6
6
|
import { a as runWithHeldLock, c as LEGACY_ATS_CLI_CONTEXT_ENV_KEY, d as resolveCliContext, f as resolveCliContextId, i as releaseLock, l as listCliContextStates, n as isAtsLockError, o as tryCleanupStaleLock, p as writeCliContextState, r as readLockMeta, s as ATS_CLI_CONTEXT_ENV_KEY, t as acquireLock, u as readCliContextState } from "./lock-CBIWEyt0.js";
|
|
7
7
|
import { _ as toSpaceWsUrl, a as toSpaceCursorUrl, c as toSpaceDispatchTraceUrl, d as toSpaceMetaUrl, f as toSpacePasswordUrl, g as toSpaceUpdatesUrl, h as toSpaceSignalsUrl, i as toSpaceCreateUrl, l as toSpaceLeaveUrl, m as toSpaceResultUrl, n as toDaemonRouteObservationUrl, o as toSpaceDeleteUrl, p as toSpaceRemoveMembersUrl, r as toSpaceContractUrl, s as toSpaceDispatchLookupUrl, t as normalizeBaseUrl, u as toSpaceMembersUrl } from "./urls-B8ZoQgpS.js";
|
|
@@ -20,7 +20,7 @@ import { execFile, spawn } from "node:child_process";
|
|
|
20
20
|
import { clearLine, createInterface, cursorTo, emitKeypressEvents, moveCursor } from "node:readline";
|
|
21
21
|
import { Writable } from "node:stream";
|
|
22
22
|
import stringWidth from "string-width";
|
|
23
|
-
import { accessSync, appendFileSync, chmodSync, closeSync, constants, existsSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
23
|
+
import { accessSync, appendFileSync, chmodSync, closeSync, constants, existsSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
24
24
|
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
25
25
|
import { createConnection, createServer } from "node:net";
|
|
26
26
|
import { fileURLToPath } from "node:url";
|
|
@@ -32,7 +32,7 @@ import { ReadStream, WriteStream } from "node:tty";
|
|
|
32
32
|
import { performance } from "node:perf_hooks";
|
|
33
33
|
|
|
34
34
|
//#region package.json
|
|
35
|
-
var version = "0.7.
|
|
35
|
+
var version = "0.7.99";
|
|
36
36
|
var package_default = {
|
|
37
37
|
$schema: "https://www.schemastore.org/package.json",
|
|
38
38
|
name: "agent-transport-system",
|
|
@@ -3898,15 +3898,15 @@ function parseLegacySelectionPayload(raw) {
|
|
|
3898
3898
|
try {
|
|
3899
3899
|
const payload = JSON.parse(raw);
|
|
3900
3900
|
if (payload.v !== 1) return null;
|
|
3901
|
-
const sessionId = normalizeOptionalString$
|
|
3902
|
-
const atsProfileId = normalizeOptionalString$
|
|
3901
|
+
const sessionId = normalizeOptionalString$29(payload.sessionId);
|
|
3902
|
+
const atsProfileId = normalizeOptionalString$29(payload.atsProfileId);
|
|
3903
3903
|
if (!(sessionId && atsProfileId)) return null;
|
|
3904
3904
|
return {
|
|
3905
3905
|
v: 1,
|
|
3906
3906
|
sessionId,
|
|
3907
|
-
sessionSource: normalizeOptionalString$
|
|
3907
|
+
sessionSource: normalizeOptionalString$29(payload.sessionSource) ?? "manual",
|
|
3908
3908
|
atsProfileId,
|
|
3909
|
-
updatedAt: normalizeOptionalString$
|
|
3909
|
+
updatedAt: normalizeOptionalString$29(payload.updatedAt) ?? (/* @__PURE__ */ new Date(0)).toISOString()
|
|
3910
3910
|
};
|
|
3911
3911
|
} catch {
|
|
3912
3912
|
return null;
|
|
@@ -3936,12 +3936,12 @@ function toSafeSessionFile(value) {
|
|
|
3936
3936
|
const maxBaseLength = Math.max(1, SESSION_FILE_MAX_LENGTH - SESSION_FILE_HASH_LENGTH - 1);
|
|
3937
3937
|
return `${safeBase.slice(0, maxBaseLength)}-${hash}`;
|
|
3938
3938
|
}
|
|
3939
|
-
function normalizeOptionalString$
|
|
3939
|
+
function normalizeOptionalString$29(value) {
|
|
3940
3940
|
const normalized = String(value ?? "").trim();
|
|
3941
3941
|
return normalized.length > 0 ? normalized : null;
|
|
3942
3942
|
}
|
|
3943
3943
|
function normalizeRequiredString$1(value, field) {
|
|
3944
|
-
const normalized = normalizeOptionalString$
|
|
3944
|
+
const normalized = normalizeOptionalString$29(value);
|
|
3945
3945
|
if (!normalized) throw new Error(`${field} is required`);
|
|
3946
3946
|
return normalized;
|
|
3947
3947
|
}
|
|
@@ -3967,13 +3967,13 @@ function resolveAtsAccountContext(input) {
|
|
|
3967
3967
|
key: normalizeAccountKey({}),
|
|
3968
3968
|
source: "fallback"
|
|
3969
3969
|
};
|
|
3970
|
-
const normalizedBaseUrl = normalizeOptionalString$
|
|
3970
|
+
const normalizedBaseUrl = normalizeOptionalString$28(session.authBaseUrl);
|
|
3971
3971
|
const hostKey = resolveHostKey(normalizedBaseUrl);
|
|
3972
3972
|
const user = normalizeUser(session.user);
|
|
3973
3973
|
const userKey = user?.id ?? user?.email ?? buildSessionScopedUserKey({
|
|
3974
3974
|
authBaseUrl: normalizedBaseUrl,
|
|
3975
|
-
clientId: normalizeOptionalString$
|
|
3976
|
-
createdAt: normalizeOptionalString$
|
|
3975
|
+
clientId: normalizeOptionalString$28(session.clientId),
|
|
3976
|
+
createdAt: normalizeOptionalString$28(session.createdAt)
|
|
3977
3977
|
});
|
|
3978
3978
|
return {
|
|
3979
3979
|
key: normalizeAccountKey({
|
|
@@ -3986,7 +3986,7 @@ function resolveAtsAccountContext(input) {
|
|
|
3986
3986
|
};
|
|
3987
3987
|
}
|
|
3988
3988
|
async function resolveCurrentAtsAccountContext() {
|
|
3989
|
-
const { getAuthSessionMetadata } = await import("./auth-session-
|
|
3989
|
+
const { getAuthSessionMetadata } = await import("./auth-session-DbA1IFeL.js");
|
|
3990
3990
|
return resolveAtsAccountContext({ session: await getAuthSessionMetadata().catch(() => null) });
|
|
3991
3991
|
}
|
|
3992
3992
|
function resolveHostKey(baseUrl) {
|
|
@@ -4009,9 +4009,9 @@ function buildSessionScopedUserKey(input) {
|
|
|
4009
4009
|
function normalizeUser(value) {
|
|
4010
4010
|
if (!(value && typeof value === "object")) return null;
|
|
4011
4011
|
const record = value;
|
|
4012
|
-
const id = normalizeOptionalString$
|
|
4013
|
-
const email = normalizeOptionalString$
|
|
4014
|
-
const name = normalizeOptionalString$
|
|
4012
|
+
const id = normalizeOptionalString$28(record.id);
|
|
4013
|
+
const email = normalizeOptionalString$28(record.email);
|
|
4014
|
+
const name = normalizeOptionalString$28(record.name);
|
|
4015
4015
|
if (!(id || email || name)) return null;
|
|
4016
4016
|
return {
|
|
4017
4017
|
...id ? { id } : {},
|
|
@@ -4019,7 +4019,7 @@ function normalizeUser(value) {
|
|
|
4019
4019
|
...name ? { name } : {}
|
|
4020
4020
|
};
|
|
4021
4021
|
}
|
|
4022
|
-
function normalizeOptionalString$
|
|
4022
|
+
function normalizeOptionalString$28(value) {
|
|
4023
4023
|
if (typeof value !== "string") return null;
|
|
4024
4024
|
const normalized = value.trim();
|
|
4025
4025
|
return normalized.length > 0 ? normalized : null;
|
|
@@ -4131,9 +4131,9 @@ function createAuthenticationError(input) {
|
|
|
4131
4131
|
return new AtsAuthenticationError(resolveAuthenticationGuidance(input));
|
|
4132
4132
|
}
|
|
4133
4133
|
function resolveAuthenticationGuidance(input) {
|
|
4134
|
-
const action = normalizeOptionalString$
|
|
4135
|
-
const authBaseUrl = normalizeOptionalString$
|
|
4136
|
-
const gatewayUrl = normalizeOptionalString$
|
|
4134
|
+
const action = normalizeOptionalString$27(input.action);
|
|
4135
|
+
const authBaseUrl = normalizeOptionalString$27(input.authBaseUrl);
|
|
4136
|
+
const gatewayUrl = normalizeOptionalString$27(input.gatewayUrl);
|
|
4137
4137
|
if (input.reason === "mismatch") return {
|
|
4138
4138
|
reason: input.reason,
|
|
4139
4139
|
action,
|
|
@@ -4157,7 +4157,7 @@ function resolveAuthenticationGuidance(input) {
|
|
|
4157
4157
|
};
|
|
4158
4158
|
}
|
|
4159
4159
|
function buildCommandAuthenticationPromptMessage$1(action) {
|
|
4160
|
-
const normalizedAction = normalizeOptionalString$
|
|
4160
|
+
const normalizedAction = normalizeOptionalString$27(action);
|
|
4161
4161
|
if (!normalizedAction) return "Sign in is required to continue. What do you want to do?";
|
|
4162
4162
|
return `Sign in is required before ${normalizedAction}. What do you want to do?`;
|
|
4163
4163
|
}
|
|
@@ -4246,7 +4246,7 @@ function resolveAuthenticationGuidanceFromMessage(message) {
|
|
|
4246
4246
|
function extractAuthenticationPromptAction(promptMessage) {
|
|
4247
4247
|
const normalizedMessage = String(promptMessage ?? "").trim();
|
|
4248
4248
|
if (normalizedMessage.length === 0) return null;
|
|
4249
|
-
return normalizeOptionalString$
|
|
4249
|
+
return normalizeOptionalString$27(AUTH_PROMPT_ACTION_RE.exec(normalizedMessage)?.groups?.action);
|
|
4250
4250
|
}
|
|
4251
4251
|
function resolveRequiredAuthenticationGuidance(reason) {
|
|
4252
4252
|
switch (reason) {
|
|
@@ -4316,7 +4316,7 @@ function buildAgentAuthenticationNotes(guidance) {
|
|
|
4316
4316
|
if (guidance.gatewayUrl) notes.push(`Current gateway: ${guidance.gatewayUrl}`);
|
|
4317
4317
|
return notes;
|
|
4318
4318
|
}
|
|
4319
|
-
function normalizeOptionalString$
|
|
4319
|
+
function normalizeOptionalString$27(value) {
|
|
4320
4320
|
const normalized = String(value ?? "").trim();
|
|
4321
4321
|
return normalized.length > 0 ? normalized : null;
|
|
4322
4322
|
}
|
|
@@ -4386,7 +4386,7 @@ async function getDaemonRuntimeStatus(pathInput = {}) {
|
|
|
4386
4386
|
autoStart: state.autoStart,
|
|
4387
4387
|
reason: "invalid_pid"
|
|
4388
4388
|
};
|
|
4389
|
-
if (!isPidAlive$
|
|
4389
|
+
if (!isPidAlive$6(state.pid)) return {
|
|
4390
4390
|
status: "stale",
|
|
4391
4391
|
mode: state.mode,
|
|
4392
4392
|
pid: state.pid,
|
|
@@ -4437,7 +4437,7 @@ async function setDaemonServiceRuntimeState(state, pathInput = {}) {
|
|
|
4437
4437
|
await writeDaemonServiceRuntimeState(state, pathInput);
|
|
4438
4438
|
}
|
|
4439
4439
|
async function clearDaemonServiceRuntimeState(pathInput = {}) {
|
|
4440
|
-
const { clearDaemonRuntimeLease } = await import("./daemon-runtime-lease-
|
|
4440
|
+
const { clearDaemonRuntimeLease } = await import("./daemon-runtime-lease-D1x-3a2_.js");
|
|
4441
4441
|
await Promise.all([rm(daemonServiceRuntimeStatePath(pathInput), { force: true }), clearDaemonRuntimeLease(pathInput)]);
|
|
4442
4442
|
}
|
|
4443
4443
|
async function withDaemonServiceRunLock(callback, meta = {
|
|
@@ -4624,7 +4624,7 @@ async function ensureDaemonControlPlaneToken(pathInput = {}) {
|
|
|
4624
4624
|
async function readDaemonControlPlaneToken(pathInput = {}) {
|
|
4625
4625
|
return (await readDaemonTokenState(pathInput))?.token ?? null;
|
|
4626
4626
|
}
|
|
4627
|
-
function isPidAlive$
|
|
4627
|
+
function isPidAlive$6(pid) {
|
|
4628
4628
|
try {
|
|
4629
4629
|
process.kill(pid, 0);
|
|
4630
4630
|
return true;
|
|
@@ -4932,6 +4932,7 @@ const DEFAULT_HEARTBEAT_INTERVAL_MS$1 = 25e3;
|
|
|
4932
4932
|
const MIN_HEARTBEAT_INTERVAL_MS$2 = 5e3;
|
|
4933
4933
|
const MAX_HEARTBEAT_INTERVAL_MS$2 = 6e4;
|
|
4934
4934
|
const DAEMON_STREAM_KEEPALIVE_INTERVAL_MS$1 = 2e4;
|
|
4935
|
+
const DAEMON_STREAM_KEEPALIVE_PONG_TIMEOUT_MS$1 = 1e4;
|
|
4935
4936
|
const CATALOG_SYNC_RETRY_INTERVAL_MS$1 = 5e3;
|
|
4936
4937
|
const CATALOG_SYNC_SIGNAL_POLL_INTERVAL_MS$1 = 1e3;
|
|
4937
4938
|
const RUNTIME_AGENT_CONTROLLER_REPORT_SYNC_INTERVAL_MS$1 = 5 * 6e4;
|
|
@@ -5034,10 +5035,17 @@ async function storeAccessToken(input) {
|
|
|
5034
5035
|
throw new Error(`secure token storage is unavailable on platform "${process.platform}". Use ${INSECURE_FALLBACK_ENV_KEY}=1 only for local testing fallback.`);
|
|
5035
5036
|
}
|
|
5036
5037
|
async function readAccessToken(ref) {
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5038
|
+
try {
|
|
5039
|
+
if (ref.provider === "macos-keychain") return toAccessTokenReadResult(await getMacOsKeychainToken(ref));
|
|
5040
|
+
if (ref.provider === "windows-dpapi") return toAccessTokenReadResult(await getWindowsDpapiToken(ref));
|
|
5041
|
+
if (ref.provider === "insecure-file") return toAccessTokenReadResult(await getInsecureFileToken(ref));
|
|
5042
|
+
return { status: "missing" };
|
|
5043
|
+
} catch (error) {
|
|
5044
|
+
return {
|
|
5045
|
+
errorMessage: toErrorMessage$44(error),
|
|
5046
|
+
status: "unavailable"
|
|
5047
|
+
};
|
|
5048
|
+
}
|
|
5041
5049
|
}
|
|
5042
5050
|
async function deleteAccessToken(ref) {
|
|
5043
5051
|
if (ref.provider === "macos-keychain") {
|
|
@@ -5115,7 +5123,10 @@ async function setWindowsDpapiToken(input) {
|
|
|
5115
5123
|
});
|
|
5116
5124
|
}
|
|
5117
5125
|
async function getWindowsDpapiToken(input) {
|
|
5118
|
-
const encrypted = await readFile(windowsDpapiTokenPath(input.key), "utf8").catch(() =>
|
|
5126
|
+
const encrypted = await readFile(windowsDpapiTokenPath(input.key), "utf8").catch((error) => {
|
|
5127
|
+
if (isFileNotFoundError$4(error)) return null;
|
|
5128
|
+
throw error;
|
|
5129
|
+
});
|
|
5119
5130
|
if (!encrypted) return null;
|
|
5120
5131
|
return runPowerShellScript(WINDOWS_DPAPI_DECRYPT_SCRIPT, encrypted.trim(), input.key);
|
|
5121
5132
|
}
|
|
@@ -5130,7 +5141,10 @@ async function setInsecureFileToken(input) {
|
|
|
5130
5141
|
});
|
|
5131
5142
|
}
|
|
5132
5143
|
async function getInsecureFileToken(input) {
|
|
5133
|
-
const raw = await readFile(insecureTokenPath(input.key), "utf8").catch(() =>
|
|
5144
|
+
const raw = await readFile(insecureTokenPath(input.key), "utf8").catch((error) => {
|
|
5145
|
+
if (isFileNotFoundError$4(error)) return null;
|
|
5146
|
+
throw error;
|
|
5147
|
+
});
|
|
5134
5148
|
return raw ? raw.trim() : null;
|
|
5135
5149
|
}
|
|
5136
5150
|
async function deleteInsecureFileToken(input) {
|
|
@@ -5271,10 +5285,21 @@ function normalizeToken(value) {
|
|
|
5271
5285
|
const normalized = value.trim();
|
|
5272
5286
|
return normalized.length > 0 ? normalized : null;
|
|
5273
5287
|
}
|
|
5288
|
+
function toAccessTokenReadResult(value) {
|
|
5289
|
+
const accessToken = normalizeToken(value);
|
|
5290
|
+
if (!accessToken) return { status: "missing" };
|
|
5291
|
+
return {
|
|
5292
|
+
accessToken,
|
|
5293
|
+
status: "found"
|
|
5294
|
+
};
|
|
5295
|
+
}
|
|
5274
5296
|
function toErrorMessage$44(error) {
|
|
5275
5297
|
if (error instanceof Error) return error.message;
|
|
5276
5298
|
return String(error);
|
|
5277
5299
|
}
|
|
5300
|
+
function isFileNotFoundError$4(error) {
|
|
5301
|
+
return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
|
|
5302
|
+
}
|
|
5278
5303
|
const WINDOWS_DPAPI_ENCRYPT_SCRIPT = [
|
|
5279
5304
|
"$ErrorActionPreference='Stop'",
|
|
5280
5305
|
"$rawInput = [Console]::In.ReadToEnd()",
|
|
@@ -5310,8 +5335,8 @@ async function getAuthSessionState(options = {}) {
|
|
|
5310
5335
|
const remoteState = await getRemoteAuthSessionState(localState.session);
|
|
5311
5336
|
if (remoteState === "valid") return localState;
|
|
5312
5337
|
if (remoteState === "unknown") return localState;
|
|
5313
|
-
await clearAuthSession();
|
|
5314
5338
|
return {
|
|
5339
|
+
reasonCode: resolveRemoteAuthSessionReasonCode(remoteState),
|
|
5315
5340
|
state: remoteState,
|
|
5316
5341
|
session: null
|
|
5317
5342
|
};
|
|
@@ -5360,9 +5385,9 @@ async function getAuthSession() {
|
|
|
5360
5385
|
async function getAuthSessionMetadata() {
|
|
5361
5386
|
const payload = await readSessionPayload();
|
|
5362
5387
|
if (payload?.v !== 1) return null;
|
|
5363
|
-
const authBaseUrl = normalizeOptionalString$
|
|
5364
|
-
const clientId = normalizeOptionalString$
|
|
5365
|
-
const createdAt = normalizeOptionalString$
|
|
5388
|
+
const authBaseUrl = normalizeOptionalString$26(payload.authBaseUrl);
|
|
5389
|
+
const clientId = normalizeOptionalString$26(payload.clientId);
|
|
5390
|
+
const createdAt = normalizeOptionalString$26(payload.createdAt);
|
|
5366
5391
|
if (!(authBaseUrl && clientId && createdAt)) return null;
|
|
5367
5392
|
return {
|
|
5368
5393
|
authBaseUrl,
|
|
@@ -5381,39 +5406,40 @@ async function clearAuthSession() {
|
|
|
5381
5406
|
async function getLocalAuthSessionState() {
|
|
5382
5407
|
const payload = await readSessionPayload();
|
|
5383
5408
|
if (payload?.v !== 1) return {
|
|
5409
|
+
reasonCode: "session_missing",
|
|
5384
5410
|
state: "missing",
|
|
5385
5411
|
session: null
|
|
5386
5412
|
};
|
|
5387
5413
|
const tokenRef = normalizeTokenRef(payload.tokenRef);
|
|
5388
|
-
if (!tokenRef) {
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
const
|
|
5396
|
-
const
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
}
|
|
5414
|
+
if (!tokenRef) return {
|
|
5415
|
+
reasonCode: "session_token_ref_invalid",
|
|
5416
|
+
state: "invalid",
|
|
5417
|
+
session: null
|
|
5418
|
+
};
|
|
5419
|
+
const tokenType = normalizeOptionalString$26(payload.tokenType);
|
|
5420
|
+
const authBaseUrl = normalizeOptionalString$26(payload.authBaseUrl);
|
|
5421
|
+
const clientId = normalizeOptionalString$26(payload.clientId);
|
|
5422
|
+
const createdAt = normalizeOptionalString$26(payload.createdAt);
|
|
5423
|
+
if (!(tokenType && authBaseUrl && clientId && createdAt)) return {
|
|
5424
|
+
reasonCode: "session_metadata_invalid",
|
|
5425
|
+
state: "invalid",
|
|
5426
|
+
session: null
|
|
5427
|
+
};
|
|
5428
|
+
const accessToken = await readAccessToken(tokenRef);
|
|
5429
|
+
if (accessToken.status === "missing") return {
|
|
5430
|
+
reasonCode: "session_token_missing",
|
|
5431
|
+
state: "invalid",
|
|
5432
|
+
session: null
|
|
5433
|
+
};
|
|
5434
|
+
if (accessToken.status === "unavailable") return {
|
|
5435
|
+
errorMessage: accessToken.errorMessage,
|
|
5436
|
+
reasonCode: "session_token_unavailable",
|
|
5437
|
+
state: "invalid",
|
|
5438
|
+
session: null
|
|
5439
|
+
};
|
|
5414
5440
|
const session = {
|
|
5415
5441
|
v: 1,
|
|
5416
|
-
accessToken,
|
|
5442
|
+
accessToken: accessToken.accessToken,
|
|
5417
5443
|
tokenType,
|
|
5418
5444
|
authBaseUrl,
|
|
5419
5445
|
clientId,
|
|
@@ -5423,6 +5449,7 @@ async function getLocalAuthSessionState() {
|
|
|
5423
5449
|
...buildAuthUserPayload(payload.user)
|
|
5424
5450
|
};
|
|
5425
5451
|
if (isExpired(session.expiresAt)) return {
|
|
5452
|
+
reasonCode: "session_expired",
|
|
5426
5453
|
state: "expired",
|
|
5427
5454
|
session
|
|
5428
5455
|
};
|
|
@@ -5481,10 +5508,15 @@ function isExpired(expiresAt) {
|
|
|
5481
5508
|
if (Number.isNaN(expiresAtMs)) return false;
|
|
5482
5509
|
return expiresAtMs <= Date.now();
|
|
5483
5510
|
}
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5511
|
+
function resolveRemoteAuthSessionReasonCode(state) {
|
|
5512
|
+
switch (state) {
|
|
5513
|
+
case "invalid": return "remote_session_invalid";
|
|
5514
|
+
case "revoked": return "remote_session_revoked";
|
|
5515
|
+
default: {
|
|
5516
|
+
const exhaustiveState = state;
|
|
5517
|
+
throw new Error(`unsupported remote auth session state: ${exhaustiveState}`);
|
|
5518
|
+
}
|
|
5519
|
+
}
|
|
5488
5520
|
}
|
|
5489
5521
|
async function readSessionPayload() {
|
|
5490
5522
|
const raw = await readFile(authSessionPath(), "utf8").catch(() => null);
|
|
@@ -5517,9 +5549,9 @@ async function writeSessionPayloadAtomically(path, payload) {
|
|
|
5517
5549
|
function buildAuthUserPayload(value) {
|
|
5518
5550
|
if (!(value && typeof value === "object")) return {};
|
|
5519
5551
|
const record = value;
|
|
5520
|
-
const id = normalizeOptionalString$
|
|
5521
|
-
const email = normalizeOptionalString$
|
|
5522
|
-
const name = normalizeOptionalString$
|
|
5552
|
+
const id = normalizeOptionalString$26(record.id);
|
|
5553
|
+
const email = normalizeOptionalString$26(record.email);
|
|
5554
|
+
const name = normalizeOptionalString$26(record.name);
|
|
5523
5555
|
if (!(id || email || name)) return {};
|
|
5524
5556
|
return { user: {
|
|
5525
5557
|
...id ? { id } : {},
|
|
@@ -5531,7 +5563,7 @@ function normalizeTokenType$2(value) {
|
|
|
5531
5563
|
const normalized = value.trim();
|
|
5532
5564
|
return normalized.length > 0 ? normalized : "Bearer";
|
|
5533
5565
|
}
|
|
5534
|
-
function normalizeOptionalString$
|
|
5566
|
+
function normalizeOptionalString$26(value) {
|
|
5535
5567
|
const normalized = String(value ?? "").trim();
|
|
5536
5568
|
return normalized.length > 0 ? normalized : null;
|
|
5537
5569
|
}
|
|
@@ -5580,7 +5612,7 @@ var AuthProfilesApiError = class extends Error {
|
|
|
5580
5612
|
this.name = "AuthProfilesApiError";
|
|
5581
5613
|
this.status = input.status;
|
|
5582
5614
|
this.endpoint = input.endpoint;
|
|
5583
|
-
this.code = normalizeOptionalString$
|
|
5615
|
+
this.code = normalizeOptionalString$25(input.code);
|
|
5584
5616
|
}
|
|
5585
5617
|
};
|
|
5586
5618
|
function isAuthProfilesApiError(error) {
|
|
@@ -5597,13 +5629,13 @@ async function resolveAtsProfile(input) {
|
|
|
5597
5629
|
method: "POST",
|
|
5598
5630
|
path: "/v1/profiles/resolve",
|
|
5599
5631
|
body: {
|
|
5600
|
-
...normalizeOptionalString$
|
|
5632
|
+
...normalizeOptionalString$25(input.atsProfileId) ? { atsProfileId: normalizeOptionalString$25(input.atsProfileId) } : {},
|
|
5601
5633
|
...input.profileKind ? { profileKind: input.profileKind } : {}
|
|
5602
5634
|
}
|
|
5603
5635
|
}), "profile"));
|
|
5604
5636
|
}
|
|
5605
5637
|
async function resolveAtsProfileByIdOrName(input) {
|
|
5606
|
-
const profileIdentifier = normalizeOptionalString$
|
|
5638
|
+
const profileIdentifier = normalizeOptionalString$25(input.profileIdentifier);
|
|
5607
5639
|
if (!profileIdentifier) throw new Error("profile identifier is required");
|
|
5608
5640
|
try {
|
|
5609
5641
|
return await resolveAtsProfile({
|
|
@@ -5622,8 +5654,8 @@ async function resolveAtsProfileByIdOrName(input) {
|
|
|
5622
5654
|
}
|
|
5623
5655
|
}
|
|
5624
5656
|
function createAtsAgentProfile(input) {
|
|
5625
|
-
const profileName = normalizeOptionalString$
|
|
5626
|
-
const creatorProfileId = normalizeOptionalString$
|
|
5657
|
+
const profileName = normalizeOptionalString$25(input.profileName);
|
|
5658
|
+
const creatorProfileId = normalizeOptionalString$25(input.creatorProfileId) ?? void 0;
|
|
5627
5659
|
if (!profileName) throw new Error("profile name is required");
|
|
5628
5660
|
return createAtsAgentProfileRequest({
|
|
5629
5661
|
profileName,
|
|
@@ -5631,8 +5663,8 @@ function createAtsAgentProfile(input) {
|
|
|
5631
5663
|
});
|
|
5632
5664
|
}
|
|
5633
5665
|
function ensureAtsManagedAgentProfile(input) {
|
|
5634
|
-
const profileName = normalizeOptionalString$
|
|
5635
|
-
const creatorProfileId = normalizeOptionalString$
|
|
5666
|
+
const profileName = normalizeOptionalString$25(input.profileName);
|
|
5667
|
+
const creatorProfileId = normalizeOptionalString$25(input.creatorProfileId) ?? void 0;
|
|
5636
5668
|
if (!profileName) throw new Error("profile name is required");
|
|
5637
5669
|
return ensureAtsManagedAgentProfileRequest({
|
|
5638
5670
|
profileName,
|
|
@@ -5641,8 +5673,8 @@ function ensureAtsManagedAgentProfile(input) {
|
|
|
5641
5673
|
});
|
|
5642
5674
|
}
|
|
5643
5675
|
async function createAtsHumanProfile(input) {
|
|
5644
|
-
const profileName = normalizeOptionalString$
|
|
5645
|
-
const creatorProfileId = normalizeOptionalString$
|
|
5676
|
+
const profileName = normalizeOptionalString$25(input.profileName);
|
|
5677
|
+
const creatorProfileId = normalizeOptionalString$25(input.creatorProfileId) ?? void 0;
|
|
5646
5678
|
if (!profileName) throw new Error("profile name is required");
|
|
5647
5679
|
const created = parseAtsProfileItem(readRecordField(await requestAtsProfilesApi({
|
|
5648
5680
|
method: "POST",
|
|
@@ -5656,9 +5688,9 @@ async function createAtsHumanProfile(input) {
|
|
|
5656
5688
|
return created;
|
|
5657
5689
|
}
|
|
5658
5690
|
async function updateAtsProfile(input) {
|
|
5659
|
-
const atsProfileId = normalizeOptionalString$
|
|
5691
|
+
const atsProfileId = normalizeOptionalString$25(input.atsProfileId);
|
|
5660
5692
|
if (!atsProfileId) throw new Error("atsProfileId is required");
|
|
5661
|
-
const profileName = normalizeOptionalString$
|
|
5693
|
+
const profileName = normalizeOptionalString$25(input.profileName);
|
|
5662
5694
|
if (!Boolean(profileName)) throw new Error("profileName is required");
|
|
5663
5695
|
const updated = parseAtsProfileItem(readRecordField(await requestAtsProfilesApi({
|
|
5664
5696
|
method: "PATCH",
|
|
@@ -5669,7 +5701,7 @@ async function updateAtsProfile(input) {
|
|
|
5669
5701
|
return updated;
|
|
5670
5702
|
}
|
|
5671
5703
|
async function deleteAtsProfile(input) {
|
|
5672
|
-
const atsProfileId = normalizeOptionalString$
|
|
5704
|
+
const atsProfileId = normalizeOptionalString$25(input.atsProfileId);
|
|
5673
5705
|
if (!atsProfileId) throw new Error("atsProfileId is required");
|
|
5674
5706
|
const deleted = parseAtsProfileItem(readRecordField(await requestAtsProfilesApi({
|
|
5675
5707
|
method: "DELETE",
|
|
@@ -5866,12 +5898,12 @@ function readArrayField(input, field) {
|
|
|
5866
5898
|
return value.filter(isRecord$4);
|
|
5867
5899
|
}
|
|
5868
5900
|
function readRequiredStringField(input, field) {
|
|
5869
|
-
const value = normalizeOptionalString$
|
|
5901
|
+
const value = normalizeOptionalString$25(input[field]);
|
|
5870
5902
|
if (!value) throw new Error(`invalid profile payload: missing ${field}`);
|
|
5871
5903
|
return value;
|
|
5872
5904
|
}
|
|
5873
5905
|
function readOptionalStringField$1(input, field) {
|
|
5874
|
-
return normalizeOptionalString$
|
|
5906
|
+
return normalizeOptionalString$25(input[field]);
|
|
5875
5907
|
}
|
|
5876
5908
|
function readBooleanField(input, field) {
|
|
5877
5909
|
return input[field] === true;
|
|
@@ -5881,7 +5913,7 @@ function readOptionalBooleanField(input, field) {
|
|
|
5881
5913
|
if (typeof value === "boolean") return value;
|
|
5882
5914
|
return null;
|
|
5883
5915
|
}
|
|
5884
|
-
function normalizeOptionalString$
|
|
5916
|
+
function normalizeOptionalString$25(value) {
|
|
5885
5917
|
const normalized = String(value ?? "").trim();
|
|
5886
5918
|
return normalized.length > 0 ? normalized : null;
|
|
5887
5919
|
}
|
|
@@ -5907,7 +5939,7 @@ async function parseResponseJson$1(response) {
|
|
|
5907
5939
|
}
|
|
5908
5940
|
function extractApiErrorMessage$1(payload, status) {
|
|
5909
5941
|
const record = isRecord$4(payload) ? payload : {};
|
|
5910
|
-
const message = normalizeOptionalString$
|
|
5942
|
+
const message = normalizeOptionalString$25(record.message) ?? normalizeOptionalString$25(record.error_description) ?? normalizeOptionalString$25(record.error);
|
|
5911
5943
|
if (message) return message;
|
|
5912
5944
|
return `request failed with status ${status}`;
|
|
5913
5945
|
}
|
|
@@ -5962,7 +5994,7 @@ function isSelectedAtsProfileRequiredError(error) {
|
|
|
5962
5994
|
return error.message.startsWith(PROFILE_REQUIRED_ERROR_PREFIX) && error.message.endsWith(PROFILE_REQUIRED_ERROR_SUFFIX);
|
|
5963
5995
|
}
|
|
5964
5996
|
async function resolveAtsProfileOrNull(input = {}) {
|
|
5965
|
-
const explicitAtsProfileId = normalizeOptionalString$
|
|
5997
|
+
const explicitAtsProfileId = normalizeOptionalString$24(input.atsProfileId);
|
|
5966
5998
|
if (explicitAtsProfileId) return await resolveExplicitAtsProfile(explicitAtsProfileId, {
|
|
5967
5999
|
profileKind: input.profileKind,
|
|
5968
6000
|
allowUnauthenticated: input.allowUnauthenticated === true,
|
|
@@ -6035,7 +6067,7 @@ async function resolveSelectedAtsProfile(selectedAtsProfileId, input) {
|
|
|
6035
6067
|
throw error;
|
|
6036
6068
|
}
|
|
6037
6069
|
}
|
|
6038
|
-
function normalizeOptionalString$
|
|
6070
|
+
function normalizeOptionalString$24(value) {
|
|
6039
6071
|
const normalized = String(value ?? "").trim();
|
|
6040
6072
|
return normalized.length > 0 ? normalized : null;
|
|
6041
6073
|
}
|
|
@@ -6050,13 +6082,13 @@ function isProfileMissingError(error) {
|
|
|
6050
6082
|
//#endregion
|
|
6051
6083
|
//#region src/config/view-profile-key.ts
|
|
6052
6084
|
async function resolveViewProfileKey(inputProfile) {
|
|
6053
|
-
const explicit = normalizeOptionalString$
|
|
6085
|
+
const explicit = normalizeOptionalString$23(inputProfile);
|
|
6054
6086
|
if (explicit) return (await resolveAtsProfileByIdOrName({ profileIdentifier: explicit }).catch(() => null))?.atsProfileId ?? explicit;
|
|
6055
6087
|
const selected = await getSelectedAtsProfileId();
|
|
6056
6088
|
if (selected) return selected;
|
|
6057
6089
|
return null;
|
|
6058
6090
|
}
|
|
6059
|
-
function normalizeOptionalString$
|
|
6091
|
+
function normalizeOptionalString$23(value) {
|
|
6060
6092
|
const normalized = String(value ?? "").trim();
|
|
6061
6093
|
return normalized.length > 0 ? normalized : null;
|
|
6062
6094
|
}
|
|
@@ -6488,7 +6520,7 @@ function buildStartRecapItems() {
|
|
|
6488
6520
|
//#endregion
|
|
6489
6521
|
//#region src/start-shell/notices.ts
|
|
6490
6522
|
function renderStartWelcome(input) {
|
|
6491
|
-
const email = normalizeOptionalString$
|
|
6523
|
+
const email = normalizeOptionalString$22(input.session.user?.email) ?? "(unknown)";
|
|
6492
6524
|
if (input.runtime.resolvedView === "agent") {
|
|
6493
6525
|
input.presenter.data({
|
|
6494
6526
|
code: "start.welcome",
|
|
@@ -6502,10 +6534,10 @@ function renderStartWelcome(input) {
|
|
|
6502
6534
|
note([`Signed In: ${email}`, `Gateway: ${input.gatewayUrl}`].join("\n"), "Welcome");
|
|
6503
6535
|
}
|
|
6504
6536
|
function emitStartCompatibilityNotice(input) {
|
|
6505
|
-
const normalizedSkillsMode = normalizeOptionalString$
|
|
6537
|
+
const normalizedSkillsMode = normalizeOptionalString$22(input.input.skillsMode)?.toLowerCase();
|
|
6506
6538
|
const ignoredFlags = [
|
|
6507
|
-
normalizeOptionalString$
|
|
6508
|
-
normalizeOptionalString$
|
|
6539
|
+
normalizeOptionalString$22(input.input.agentModel) ? "--agent-model" : null,
|
|
6540
|
+
normalizeOptionalString$22(input.input.agentOwner) ? "--agent-owner" : null,
|
|
6509
6541
|
normalizedSkillsMode && normalizedSkillsMode !== "auto" ? "--skills-mode" : null
|
|
6510
6542
|
].filter((value) => value !== null);
|
|
6511
6543
|
if (ignoredFlags.length === 0) return;
|
|
@@ -6556,7 +6588,7 @@ function emitStartSetupHint(input) {
|
|
|
6556
6588
|
text: formatInlineAtsCliCommands("If this computer needs local service or agent setup, run `ats setup`.")
|
|
6557
6589
|
});
|
|
6558
6590
|
}
|
|
6559
|
-
function normalizeOptionalString$
|
|
6591
|
+
function normalizeOptionalString$22(value) {
|
|
6560
6592
|
if (typeof value !== "string") return null;
|
|
6561
6593
|
const normalized = value.trim();
|
|
6562
6594
|
return normalized.length > 0 ? normalized : null;
|
|
@@ -6771,7 +6803,7 @@ async function readProfileWorkspaceConfigForAccount(input) {
|
|
|
6771
6803
|
path,
|
|
6772
6804
|
status: "missing"
|
|
6773
6805
|
};
|
|
6774
|
-
const parsedJson = safeParseJson$
|
|
6806
|
+
const parsedJson = safeParseJson$2(raw);
|
|
6775
6807
|
if (parsedJson === null) return {
|
|
6776
6808
|
path,
|
|
6777
6809
|
reason: "invalid_json",
|
|
@@ -6967,7 +6999,7 @@ function buildWorkspacePayload(value) {
|
|
|
6967
6999
|
async function readExistingEnvelopeDraft(input) {
|
|
6968
7000
|
const raw = await readOptionalFile(input.path);
|
|
6969
7001
|
if (raw === null) return null;
|
|
6970
|
-
const parsed = safeParseJson$
|
|
7002
|
+
const parsed = safeParseJson$2(raw);
|
|
6971
7003
|
if (!(parsed && typeof parsed === "object")) return null;
|
|
6972
7004
|
const record = parsed;
|
|
6973
7005
|
if (record.v !== PROFILE_LOCAL_META_ENVELOPE_VERSION) return null;
|
|
@@ -7079,7 +7111,7 @@ function hasOnlyExpectedKeys(record, expectedKeys) {
|
|
|
7079
7111
|
const allowedKeys = new Set(expectedKeys);
|
|
7080
7112
|
return Object.keys(record).every((key) => allowedKeys.has(key));
|
|
7081
7113
|
}
|
|
7082
|
-
function safeParseJson$
|
|
7114
|
+
function safeParseJson$2(raw) {
|
|
7083
7115
|
try {
|
|
7084
7116
|
return JSON.parse(raw);
|
|
7085
7117
|
} catch {
|
|
@@ -7454,7 +7486,7 @@ function resolveDefaultAuthBaseUrl(env) {
|
|
|
7454
7486
|
|
|
7455
7487
|
//#endregion
|
|
7456
7488
|
//#region ../../packages/utils/dist/index.js
|
|
7457
|
-
function sleep
|
|
7489
|
+
function sleep(ms) {
|
|
7458
7490
|
return new Promise((resolve) => {
|
|
7459
7491
|
setTimeout(resolve, ms);
|
|
7460
7492
|
});
|
|
@@ -8239,7 +8271,7 @@ function buildAuthStatusSnapshot(input) {
|
|
|
8239
8271
|
expiresIn: null,
|
|
8240
8272
|
expired: false
|
|
8241
8273
|
};
|
|
8242
|
-
const expiresAt = normalizeOptionalString$
|
|
8274
|
+
const expiresAt = normalizeOptionalString$21(session.expiresAt);
|
|
8243
8275
|
const expiresAtMs = expiresAt ? Date.parse(expiresAt) : NaN;
|
|
8244
8276
|
const hasValidExpiresAt = Number.isFinite(expiresAtMs);
|
|
8245
8277
|
const expiresInMs = hasValidExpiresAt ? expiresAtMs - Date.now() : NaN;
|
|
@@ -8247,14 +8279,14 @@ function buildAuthStatusSnapshot(input) {
|
|
|
8247
8279
|
return {
|
|
8248
8280
|
signedIn: input.state === "valid",
|
|
8249
8281
|
state: input.state,
|
|
8250
|
-
userId: normalizeOptionalString$
|
|
8251
|
-
userEmail: normalizeOptionalString$
|
|
8252
|
-
userName: normalizeOptionalString$
|
|
8253
|
-
clientId: normalizeOptionalString$
|
|
8254
|
-
authBaseUrl: normalizeOptionalString$
|
|
8255
|
-
tokenType: normalizeOptionalString$
|
|
8256
|
-
scope: normalizeOptionalString$
|
|
8257
|
-
createdAt: normalizeOptionalString$
|
|
8282
|
+
userId: normalizeOptionalString$21(session.user?.id),
|
|
8283
|
+
userEmail: normalizeOptionalString$21(session.user?.email),
|
|
8284
|
+
userName: normalizeOptionalString$21(session.user?.name),
|
|
8285
|
+
clientId: normalizeOptionalString$21(session.clientId),
|
|
8286
|
+
authBaseUrl: normalizeOptionalString$21(session.authBaseUrl),
|
|
8287
|
+
tokenType: normalizeOptionalString$21(session.tokenType),
|
|
8288
|
+
scope: normalizeOptionalString$21(session.scope),
|
|
8289
|
+
createdAt: normalizeOptionalString$21(session.createdAt),
|
|
8258
8290
|
expiresAt,
|
|
8259
8291
|
expiresIn: hasValidExpiresAt ? formatRemainingDuration(expiresInMs) : null,
|
|
8260
8292
|
expired
|
|
@@ -8329,7 +8361,7 @@ function appendRowIfValue(rows, label, value) {
|
|
|
8329
8361
|
value
|
|
8330
8362
|
});
|
|
8331
8363
|
}
|
|
8332
|
-
function normalizeOptionalString$
|
|
8364
|
+
function normalizeOptionalString$21(value) {
|
|
8333
8365
|
const normalized = String(value ?? "").trim();
|
|
8334
8366
|
return normalized.length > 0 ? normalized : null;
|
|
8335
8367
|
}
|
|
@@ -8684,7 +8716,7 @@ async function readDaemonLocalStateFile(input) {
|
|
|
8684
8716
|
throw error;
|
|
8685
8717
|
});
|
|
8686
8718
|
if (raw === null) return null;
|
|
8687
|
-
const parsedJson = safeParseJson(raw);
|
|
8719
|
+
const parsedJson = safeParseJson$1(raw);
|
|
8688
8720
|
if (parsedJson === null) return null;
|
|
8689
8721
|
const parsed = input.schema.safeParse(parsedJson);
|
|
8690
8722
|
return parsed.success ? parsed.data : null;
|
|
@@ -8707,7 +8739,7 @@ async function writeDaemonLocalStateFile(input) {
|
|
|
8707
8739
|
if (shouldCleanupTemp) await rm(tempPath, { force: true }).catch(() => void 0);
|
|
8708
8740
|
}
|
|
8709
8741
|
}
|
|
8710
|
-
function safeParseJson(raw) {
|
|
8742
|
+
function safeParseJson$1(raw) {
|
|
8711
8743
|
try {
|
|
8712
8744
|
return JSON.parse(raw);
|
|
8713
8745
|
} catch {
|
|
@@ -15576,14 +15608,14 @@ const createAuthorityAtsServiceRuntimeId = (input) => {
|
|
|
15576
15608
|
source: RUNTIME_REGISTRY_AUTHORITY_SOURCE
|
|
15577
15609
|
};
|
|
15578
15610
|
};
|
|
15579
|
-
const normalizeOptionalString$
|
|
15611
|
+
const normalizeOptionalString$20 = (value) => {
|
|
15580
15612
|
const normalized = String(value ?? "").trim();
|
|
15581
15613
|
return normalized.length > 0 ? normalized : void 0;
|
|
15582
15614
|
};
|
|
15583
15615
|
const createAgentProfileBindingModelSelection = (input) => {
|
|
15584
|
-
const modelId = normalizeOptionalString$
|
|
15616
|
+
const modelId = normalizeOptionalString$20(input?.modelId);
|
|
15585
15617
|
if (!modelId) return;
|
|
15586
|
-
const reasoningLevel = normalizeOptionalString$
|
|
15618
|
+
const reasoningLevel = normalizeOptionalString$20(input?.reasoningLevel);
|
|
15587
15619
|
return {
|
|
15588
15620
|
modelId,
|
|
15589
15621
|
...reasoningLevel ? { reasoningLevel } : {}
|
|
@@ -21327,16 +21359,16 @@ function renderRegistryOriginLaunchCommand(input) {
|
|
|
21327
21359
|
function parseAgentsRegistryDocument(value, registryPath) {
|
|
21328
21360
|
const objectValue = readObjectValue(value, `agents registry file '${registryPath}'`);
|
|
21329
21361
|
return {
|
|
21330
|
-
schemaVersion: readStringValue(objectValue.schemaVersion, "schemaVersion"),
|
|
21362
|
+
schemaVersion: readStringValue$1(objectValue.schemaVersion, "schemaVersion"),
|
|
21331
21363
|
agents: readArrayValue(objectValue.agents, "agents").map((agent, index) => parseAgentsRegistryAgent(agent, `agents[${String(index)}]`))
|
|
21332
21364
|
};
|
|
21333
21365
|
}
|
|
21334
21366
|
function parseAgentsRegistryAgent(value, context) {
|
|
21335
21367
|
const objectValue = readObjectValue(value, context);
|
|
21336
|
-
const id = readStringValue(objectValue.id, `${context}.id`);
|
|
21337
|
-
const displayName = readStringValue(objectValue.displayName, `${context}.displayName`);
|
|
21368
|
+
const id = readStringValue$1(objectValue.id, `${context}.id`);
|
|
21369
|
+
const displayName = readStringValue$1(objectValue.displayName, `${context}.displayName`);
|
|
21338
21370
|
const category = readEnumValue(objectValue.category, `${context}.category`, ["builtin", "custom"]);
|
|
21339
|
-
const skillsDir = readStringValue(objectValue.skillsDir, `${context}.skillsDir`);
|
|
21371
|
+
const skillsDir = readStringValue$1(objectValue.skillsDir, `${context}.skillsDir`);
|
|
21340
21372
|
const globalSkillsDir = readOptionalStringOrStringArray(objectValue.globalSkillsDir, `${context}.globalSkillsDir`);
|
|
21341
21373
|
const detection = parseAgentsRegistryDetection(objectValue.detection, `${context}.detection`);
|
|
21342
21374
|
const service = parseAgentsRegistryServiceCapability(objectValue.service, `${context}.service`);
|
|
@@ -21397,7 +21429,7 @@ function parseAgentsRegistryDetectionCheck(value, context) {
|
|
|
21397
21429
|
"envTruthy"
|
|
21398
21430
|
]);
|
|
21399
21431
|
if (!SUPPORTED_DETECTION_CHECK_KINDS.has(kind)) throw new Error(`Unsupported detection check kind at ${context}.kind: ${kind}`);
|
|
21400
|
-
const detectionValue = readStringValue(objectValue.value, `${context}.value`);
|
|
21432
|
+
const detectionValue = readStringValue$1(objectValue.value, `${context}.value`);
|
|
21401
21433
|
const platform = readOptionalEnumValue(objectValue.platform, `${context}.platform`, [
|
|
21402
21434
|
"all",
|
|
21403
21435
|
"darwin",
|
|
@@ -21427,7 +21459,7 @@ function parseAgentsRegistryRuntimeSupport(value, context) {
|
|
|
21427
21459
|
}
|
|
21428
21460
|
function parseAgentsRegistryAdapterBinding(value, context) {
|
|
21429
21461
|
const objectValue = readObjectValue(value, context);
|
|
21430
|
-
const adapterId = readStringValue(objectValue.adapterId, `${context}.adapterId`);
|
|
21462
|
+
const adapterId = readStringValue$1(objectValue.adapterId, `${context}.adapterId`);
|
|
21431
21463
|
const controllerRefMatcher = parseAgentsRegistryAgentControllerRefMatcher(objectValue.controllerRefMatcher, `${context}.controllerRefMatcher`);
|
|
21432
21464
|
const transportModes = readArrayValue(objectValue.transportModes, `${context}.transportModes`).map((transportMode, index) => parseTransportMode$1(transportMode, `${context}.transportModes[${String(index)}]`));
|
|
21433
21465
|
const capabilityDeclaration = parseAgentsRegistryRuntimeCapabilityDeclaration(objectValue.capabilityDeclaration, `${context}.capabilityDeclaration`);
|
|
@@ -21471,7 +21503,7 @@ function parseAgentsRegistryAgentControllerRefMatcher(value, context) {
|
|
|
21471
21503
|
"regex"
|
|
21472
21504
|
]);
|
|
21473
21505
|
if (!SUPPORTED_RUNTIME_MATCHER_KINDS.has(kind)) throw new Error(`Unsupported controller matcher kind at ${context}.kind: ${kind}`);
|
|
21474
|
-
const values = readArrayValue(objectValue.values, `${context}.values`).map((entry, index) => readStringValue(entry, `${context}.values[${String(index)}]`));
|
|
21506
|
+
const values = readArrayValue(objectValue.values, `${context}.values`).map((entry, index) => readStringValue$1(entry, `${context}.values[${String(index)}]`));
|
|
21475
21507
|
if (values.length === 0) throw new Error(`Expected non-empty matcher values at ${context}.values`);
|
|
21476
21508
|
return {
|
|
21477
21509
|
kind,
|
|
@@ -21484,7 +21516,7 @@ function parseOptionalTransportModes(value, context) {
|
|
|
21484
21516
|
}
|
|
21485
21517
|
function parseOptionalOriginLaunch(value, context) {
|
|
21486
21518
|
if (value === void 0 || value === null) return null;
|
|
21487
|
-
const commandTemplate = readStringValue(readObjectValue(value, context).commandTemplate, `${context}.commandTemplate`);
|
|
21519
|
+
const commandTemplate = readStringValue$1(readObjectValue(value, context).commandTemplate, `${context}.commandTemplate`);
|
|
21488
21520
|
const placeholderMatches = [...commandTemplate.matchAll(ANY_BRACE_TOKEN_RE)];
|
|
21489
21521
|
if (placeholderMatches.length === 0) throw new Error(`Expected origin launch placeholder token at ${context}.commandTemplate`);
|
|
21490
21522
|
for (const match of placeholderMatches) {
|
|
@@ -21615,7 +21647,7 @@ function readArrayValue(value, context) {
|
|
|
21615
21647
|
if (!Array.isArray(value)) throw new Error(`Expected array at ${context}`);
|
|
21616
21648
|
return value;
|
|
21617
21649
|
}
|
|
21618
|
-
function readStringValue(value, context) {
|
|
21650
|
+
function readStringValue$1(value, context) {
|
|
21619
21651
|
if (typeof value !== "string") throw new Error(`Expected string at ${context}`);
|
|
21620
21652
|
const trimmed = value.trim();
|
|
21621
21653
|
if (!trimmed) throw new Error(`Expected non-empty string at ${context}`);
|
|
@@ -21636,8 +21668,8 @@ function readOptionalEnumValue(value, context, allowed) {
|
|
|
21636
21668
|
}
|
|
21637
21669
|
function readOptionalStringOrStringArray(value, context) {
|
|
21638
21670
|
if (value === void 0 || value === null) return null;
|
|
21639
|
-
if (typeof value === "string") return readStringValue(value, context);
|
|
21640
|
-
if (Array.isArray(value)) return value.map((item, index) => readStringValue(item, `${context}[${String(index)}]`));
|
|
21671
|
+
if (typeof value === "string") return readStringValue$1(value, context);
|
|
21672
|
+
if (Array.isArray(value)) return value.map((item, index) => readStringValue$1(item, `${context}[${String(index)}]`));
|
|
21641
21673
|
throw new Error(`Expected string or string[] at ${context}`);
|
|
21642
21674
|
}
|
|
21643
21675
|
function isMissingFileError(error) {
|
|
@@ -22679,6 +22711,7 @@ const CATALOG_SYNC_SIGNAL_POLL_INTERVAL_MS = CATALOG_SYNC_SIGNAL_POLL_INTERVAL_M
|
|
|
22679
22711
|
const DAEMON_RUNTIME_CONTRACT_EPOCH = DAEMON_RUNTIME_CONTRACT_EPOCH$1;
|
|
22680
22712
|
const DAEMON_STREAM_CONNECT_TIMEOUT_MS = DAEMON_STREAM_CONNECT_TIMEOUT_MS$1;
|
|
22681
22713
|
const DAEMON_STREAM_KEEPALIVE_INTERVAL_MS = DAEMON_STREAM_KEEPALIVE_INTERVAL_MS$1;
|
|
22714
|
+
const DAEMON_STREAM_KEEPALIVE_PONG_TIMEOUT_MS = DAEMON_STREAM_KEEPALIVE_PONG_TIMEOUT_MS$1;
|
|
22682
22715
|
const DEFAULT_HEARTBEAT_INTERVAL_MS = DEFAULT_HEARTBEAT_INTERVAL_MS$1;
|
|
22683
22716
|
const HEARTBEAT_RESPONSE_TIMEOUT_MS = HEARTBEAT_RESPONSE_TIMEOUT_MS$1;
|
|
22684
22717
|
const MAX_HEARTBEAT_INTERVAL_MS = MAX_HEARTBEAT_INTERVAL_MS$2;
|
|
@@ -22772,7 +22805,6 @@ function nowIsoString() {
|
|
|
22772
22805
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
22773
22806
|
}
|
|
22774
22807
|
const toErrorMessage$30 = toErrorMessage$43;
|
|
22775
|
-
const sleep = sleep$1;
|
|
22776
22808
|
function dirnamePath(path) {
|
|
22777
22809
|
const lastSlash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
22778
22810
|
if (lastSlash <= 0) return ".";
|
|
@@ -29280,8 +29312,8 @@ function buildSpaceSignalsReadSearchParams(query) {
|
|
|
29280
29312
|
return searchParams;
|
|
29281
29313
|
}
|
|
29282
29314
|
function normalizeSpaceSignalsReadQuery(query) {
|
|
29283
|
-
const afterSignalId = normalizeOptionalString$
|
|
29284
|
-
const aroundSignalId = normalizeOptionalString$
|
|
29315
|
+
const afterSignalId = normalizeOptionalString$19(query?.afterSignalId);
|
|
29316
|
+
const aroundSignalId = normalizeOptionalString$19(query?.aroundSignalId);
|
|
29285
29317
|
const beforeCount = normalizeOptionalNonNegativeInteger(query?.beforeCount);
|
|
29286
29318
|
const afterCount = normalizeOptionalNonNegativeInteger(query?.afterCount);
|
|
29287
29319
|
const limit = normalizeOptionalNonNegativeInteger(query?.limit);
|
|
@@ -29309,7 +29341,7 @@ function normalizeSpaceSignalsReadQuery(query) {
|
|
|
29309
29341
|
kinds
|
|
29310
29342
|
};
|
|
29311
29343
|
}
|
|
29312
|
-
function normalizeOptionalString$
|
|
29344
|
+
function normalizeOptionalString$19(value) {
|
|
29313
29345
|
if (typeof value !== "string") return null;
|
|
29314
29346
|
const normalized = value.trim();
|
|
29315
29347
|
return normalized.length > 0 ? normalized : null;
|
|
@@ -29322,7 +29354,7 @@ function normalizeOptionalNonNegativeInteger(value) {
|
|
|
29322
29354
|
function normalizeUniqueStrings(values) {
|
|
29323
29355
|
const deduped = /* @__PURE__ */ new Set();
|
|
29324
29356
|
for (const value of values) {
|
|
29325
|
-
const normalized = normalizeOptionalString$
|
|
29357
|
+
const normalized = normalizeOptionalString$19(value);
|
|
29326
29358
|
if (normalized) deduped.add(normalized);
|
|
29327
29359
|
}
|
|
29328
29360
|
return [...deduped];
|
|
@@ -30936,9 +30968,9 @@ function createModelCatalogReadSession(input) {
|
|
|
30936
30968
|
async function readModelCatalogOnce(baseUrl) {
|
|
30937
30969
|
try {
|
|
30938
30970
|
const [apiClient, baseUrlModule, clientFoundationModule] = await Promise.all([
|
|
30939
|
-
import("./dist-
|
|
30940
|
-
import("./base-url-
|
|
30941
|
-
import("./api-client-foundation-
|
|
30971
|
+
import("./dist-DV2pViNq.js"),
|
|
30972
|
+
import("./base-url-CiDhrDeP.js").then((n) => n.n),
|
|
30973
|
+
import("./api-client-foundation-CBoyrvoT.js")
|
|
30942
30974
|
]);
|
|
30943
30975
|
if (typeof apiClient.createConfigApi !== "function") throw new Error("config api client is unavailable");
|
|
30944
30976
|
const resolvedBaseUrl = baseUrl ?? await baseUrlModule.resolveBaseUrl();
|
|
@@ -32014,7 +32046,7 @@ function isDaemonBundleSourceAllowedForLane(input) {
|
|
|
32014
32046
|
}
|
|
32015
32047
|
async function readDaemonActiveBundleState() {
|
|
32016
32048
|
const raw = await readFile(daemonServiceActiveBundlePath(), "utf8").catch((error) => {
|
|
32017
|
-
if (getErrorCode$
|
|
32049
|
+
if (getErrorCode$4(error) === "ENOENT") return null;
|
|
32018
32050
|
throw error;
|
|
32019
32051
|
});
|
|
32020
32052
|
if (raw === null) return null;
|
|
@@ -32290,7 +32322,7 @@ async function listDaemonSourceDistFiles(path) {
|
|
|
32290
32322
|
async function collectDaemonBundleRuntimeDependencyClosure(input) {
|
|
32291
32323
|
const packageManifestPath = join(input.sourcePackageRootPath, "package.json");
|
|
32292
32324
|
const packageManifestRaw = await readFile(packageManifestPath, "utf8").catch((error) => {
|
|
32293
|
-
if (getErrorCode$
|
|
32325
|
+
if (getErrorCode$4(error) === "ENOENT") throw new Error(`ATS could not find the CLI package manifest for background service bundling at ${packageManifestPath}.`);
|
|
32294
32326
|
throw error;
|
|
32295
32327
|
});
|
|
32296
32328
|
const packageManifest = JSON.parse(packageManifestRaw);
|
|
@@ -32352,7 +32384,7 @@ async function readDaemonBundleDependencyManifest(input) {
|
|
|
32352
32384
|
if (!dependencyPackageRootPath) return null;
|
|
32353
32385
|
const dependencyManifestPath = join(dependencyPackageRootPath, "package.json");
|
|
32354
32386
|
const dependencyManifestRaw = await readFile(dependencyManifestPath, "utf8").catch((error) => {
|
|
32355
|
-
if (getErrorCode$
|
|
32387
|
+
if (getErrorCode$4(error) === "ENOENT") {
|
|
32356
32388
|
if (!input.required) return null;
|
|
32357
32389
|
throw new Error(`ATS could not find runtime dependency ${input.dependencyName} for background service bundling at ${dependencyManifestPath}. Run \`pnpm install\` and retry.`);
|
|
32358
32390
|
}
|
|
@@ -32707,7 +32739,7 @@ function quoteShellSingle(value) {
|
|
|
32707
32739
|
}
|
|
32708
32740
|
async function readDirectoryNames(path) {
|
|
32709
32741
|
return (await readdir(path, { withFileTypes: true }).catch((error) => {
|
|
32710
|
-
if (getErrorCode$
|
|
32742
|
+
if (getErrorCode$4(error) === "ENOENT") return [];
|
|
32711
32743
|
throw error;
|
|
32712
32744
|
})).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
32713
32745
|
}
|
|
@@ -32725,7 +32757,7 @@ function isDaemonBundleSourceKind(value) {
|
|
|
32725
32757
|
return value === DAEMON_BUNDLE_SOURCE_KIND_WORKSPACE || value === DAEMON_BUNDLE_SOURCE_KIND_PACKAGE_INSTALL || value === DAEMON_BUNDLE_SOURCE_KIND_NPX_CACHE || value === DAEMON_BUNDLE_SOURCE_KIND_UNKNOWN;
|
|
32726
32758
|
}
|
|
32727
32759
|
function isPackageEntryResolutionError(error) {
|
|
32728
|
-
const code = getErrorCode$
|
|
32760
|
+
const code = getErrorCode$4(error);
|
|
32729
32761
|
return code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
|
|
32730
32762
|
}
|
|
32731
32763
|
function normalizeOptionalText$27(value) {
|
|
@@ -32737,7 +32769,7 @@ async function pathExists$6(path) {
|
|
|
32737
32769
|
await stat(path);
|
|
32738
32770
|
return true;
|
|
32739
32771
|
} catch (error) {
|
|
32740
|
-
if (getErrorCode$
|
|
32772
|
+
if (getErrorCode$4(error) === "ENOENT") return false;
|
|
32741
32773
|
throw error;
|
|
32742
32774
|
}
|
|
32743
32775
|
}
|
|
@@ -32765,7 +32797,7 @@ function buildPreferredCliScriptNames(rawPath) {
|
|
|
32765
32797
|
function isSupportedDaemonCliEntryName(value) {
|
|
32766
32798
|
return DAEMON_CLI_ENTRY_NAMES.includes(value);
|
|
32767
32799
|
}
|
|
32768
|
-
function getErrorCode$
|
|
32800
|
+
function getErrorCode$4(error) {
|
|
32769
32801
|
if (!error || typeof error !== "object") return;
|
|
32770
32802
|
const code = error.code;
|
|
32771
32803
|
return typeof code === "string" ? code : void 0;
|
|
@@ -33417,7 +33449,7 @@ async function computeDirectoryContentHash(input) {
|
|
|
33417
33449
|
}
|
|
33418
33450
|
async function collectFiles(input) {
|
|
33419
33451
|
const entries = await readdir(input.dir, { withFileTypes: true }).catch((error) => {
|
|
33420
|
-
if (getErrorCode$
|
|
33452
|
+
if (getErrorCode$3(error) === "ENOENT") return [];
|
|
33421
33453
|
warnDirectoryReadError(input.dir, error);
|
|
33422
33454
|
throw error;
|
|
33423
33455
|
});
|
|
@@ -33446,7 +33478,7 @@ async function collectFiles(input) {
|
|
|
33446
33478
|
function normalizeRelativePath(value) {
|
|
33447
33479
|
return value.split("\\").join("/");
|
|
33448
33480
|
}
|
|
33449
|
-
function getErrorCode$
|
|
33481
|
+
function getErrorCode$3(error) {
|
|
33450
33482
|
if (!error || typeof error !== "object") return;
|
|
33451
33483
|
const code = error.code;
|
|
33452
33484
|
return typeof code === "string" ? code : void 0;
|
|
@@ -33719,7 +33751,7 @@ async function withSkillsInstallLock(run) {
|
|
|
33719
33751
|
acquired = true;
|
|
33720
33752
|
break;
|
|
33721
33753
|
} catch (error) {
|
|
33722
|
-
if (getErrorCode$
|
|
33754
|
+
if (getErrorCode$2(error) !== "EEXIST") throw error;
|
|
33723
33755
|
if (!await recoverStaleSkillsInstallLock(lockPath)) throw new Error("another skills installation is already running; retry after it finishes");
|
|
33724
33756
|
try {
|
|
33725
33757
|
await writeFile(lockPath, lockContents, {
|
|
@@ -33729,7 +33761,7 @@ async function withSkillsInstallLock(run) {
|
|
|
33729
33761
|
acquired = true;
|
|
33730
33762
|
break;
|
|
33731
33763
|
} catch (retryError) {
|
|
33732
|
-
if (getErrorCode$
|
|
33764
|
+
if (getErrorCode$2(retryError) !== "EEXIST") throw retryError;
|
|
33733
33765
|
}
|
|
33734
33766
|
}
|
|
33735
33767
|
if (!acquired) throw new Error("another skills installation is already running; retry after it finishes");
|
|
@@ -33741,14 +33773,14 @@ async function withSkillsInstallLock(run) {
|
|
|
33741
33773
|
}
|
|
33742
33774
|
async function recoverStaleSkillsInstallLock(lockPath) {
|
|
33743
33775
|
const lockRaw = await readFile(lockPath, "utf8").catch((error) => {
|
|
33744
|
-
if (getErrorCode$
|
|
33776
|
+
if (getErrorCode$2(error) === "ENOENT") return "";
|
|
33745
33777
|
throw error;
|
|
33746
33778
|
});
|
|
33747
33779
|
if (!lockRaw) return true;
|
|
33748
33780
|
const pid = resolveLockPid(parseLockMeta(lockRaw));
|
|
33749
|
-
if (pid && isPidAlive$
|
|
33781
|
+
if (pid && isPidAlive$5(pid)) return false;
|
|
33750
33782
|
const latestLockRaw = await readFile(lockPath, "utf8").catch((error) => {
|
|
33751
|
-
if (getErrorCode$
|
|
33783
|
+
if (getErrorCode$2(error) === "ENOENT") return "";
|
|
33752
33784
|
throw error;
|
|
33753
33785
|
});
|
|
33754
33786
|
if (!latestLockRaw) return true;
|
|
@@ -33759,7 +33791,7 @@ async function recoverStaleSkillsInstallLock(lockPath) {
|
|
|
33759
33791
|
afterPid: resolveLockPid(parseLockMeta(latestLockRaw))
|
|
33760
33792
|
})) return false;
|
|
33761
33793
|
await rm(lockPath, { force: true }).catch((error) => {
|
|
33762
|
-
if (getErrorCode$
|
|
33794
|
+
if (getErrorCode$2(error) === "ENOENT") return;
|
|
33763
33795
|
throw error;
|
|
33764
33796
|
});
|
|
33765
33797
|
return true;
|
|
@@ -33776,15 +33808,15 @@ function resolveLockPid(meta) {
|
|
|
33776
33808
|
const pid = meta.pid;
|
|
33777
33809
|
return typeof pid === "number" && Number.isInteger(pid) ? pid : null;
|
|
33778
33810
|
}
|
|
33779
|
-
function isPidAlive$
|
|
33811
|
+
function isPidAlive$5(pid) {
|
|
33780
33812
|
try {
|
|
33781
33813
|
process$1.kill(pid, 0);
|
|
33782
33814
|
return true;
|
|
33783
33815
|
} catch (error) {
|
|
33784
|
-
return getErrorCode$
|
|
33816
|
+
return getErrorCode$2(error) !== "ESRCH";
|
|
33785
33817
|
}
|
|
33786
33818
|
}
|
|
33787
|
-
function getErrorCode$
|
|
33819
|
+
function getErrorCode$2(error) {
|
|
33788
33820
|
if (!error || typeof error !== "object") return;
|
|
33789
33821
|
const code = error.code;
|
|
33790
33822
|
return typeof code === "string" ? code : void 0;
|
|
@@ -37528,16 +37560,30 @@ async function pathExists$5(path) {
|
|
|
37528
37560
|
throw error;
|
|
37529
37561
|
}
|
|
37530
37562
|
}
|
|
37563
|
+
var DaemonServiceWaitTimeoutError = class extends Error {
|
|
37564
|
+
jobDiagnostics;
|
|
37565
|
+
constructor(input) {
|
|
37566
|
+
super(input.message);
|
|
37567
|
+
this.name = "DaemonServiceWaitTimeoutError";
|
|
37568
|
+
this.jobDiagnostics = input.jobDiagnostics ?? null;
|
|
37569
|
+
}
|
|
37570
|
+
};
|
|
37571
|
+
function isDaemonServiceWaitTimeoutError(error) {
|
|
37572
|
+
return error instanceof DaemonServiceWaitTimeoutError;
|
|
37573
|
+
}
|
|
37531
37574
|
function buildSystemServiceWaitTimeoutError(input) {
|
|
37532
37575
|
const detailSuffix = input.details && input.details.trim().length > 0 ? ` Last observed state: ${input.details.trim()}` : "";
|
|
37533
|
-
return
|
|
37576
|
+
return new DaemonServiceWaitTimeoutError({
|
|
37577
|
+
message: `timed out waiting for ${input.controller} service to become ${input.action}.${detailSuffix}`,
|
|
37578
|
+
jobDiagnostics: input.jobDiagnostics ?? null
|
|
37579
|
+
});
|
|
37534
37580
|
}
|
|
37535
37581
|
async function waitForCondition(input) {
|
|
37536
37582
|
const deadline = Date.now() + (input.waitMs ?? SYSTEM_SERVICE_WAIT_MS);
|
|
37537
37583
|
const pollMs = input.pollMs ?? SYSTEM_SERVICE_POLL_MS;
|
|
37538
37584
|
while (Date.now() < deadline) {
|
|
37539
37585
|
if (await input.until()) return;
|
|
37540
|
-
await sleep
|
|
37586
|
+
await sleep(pollMs);
|
|
37541
37587
|
}
|
|
37542
37588
|
throw await input.onTimeout();
|
|
37543
37589
|
}
|
|
@@ -38074,10 +38120,14 @@ function buildLaunchdManager(pathInput = {}) {
|
|
|
38074
38120
|
await waitForCondition({
|
|
38075
38121
|
until: async () => (await buildLaunchdManager(pathInput).status()).running,
|
|
38076
38122
|
onTimeout: async () => {
|
|
38123
|
+
const manager = buildLaunchdManager(pathInput);
|
|
38124
|
+
const status = await manager.status();
|
|
38125
|
+
const jobDiagnostics = manager.readJobDiagnostics ? await manager.readJobDiagnostics().catch(() => null) : null;
|
|
38077
38126
|
return buildSystemServiceWaitTimeoutError({
|
|
38078
38127
|
action: "running",
|
|
38079
38128
|
controller: LAUNCHD_CONTROLLER,
|
|
38080
|
-
details: formatManagerStatusDetails(
|
|
38129
|
+
details: formatManagerStatusDetails(status),
|
|
38130
|
+
jobDiagnostics
|
|
38081
38131
|
});
|
|
38082
38132
|
}
|
|
38083
38133
|
});
|
|
@@ -38752,7 +38802,7 @@ function resolveObservedRuntimeCommandEntryPath(input) {
|
|
|
38752
38802
|
function resolveRuntimeLeaseIssue(runtimeLease) {
|
|
38753
38803
|
if (!runtimeLease) return "runtime_lease_missing";
|
|
38754
38804
|
if (!Number.isInteger(runtimeLease.pid) || runtimeLease.pid <= 0) return "invalid_pid";
|
|
38755
|
-
if (!isPidAlive$
|
|
38805
|
+
if (!isPidAlive$4(runtimeLease.pid)) return "process_not_alive";
|
|
38756
38806
|
if (isRuntimeLeaseHeartbeatStale(runtimeLease)) return "heartbeat_stale";
|
|
38757
38807
|
return null;
|
|
38758
38808
|
}
|
|
@@ -38780,7 +38830,7 @@ function resolveModePriority(mode) {
|
|
|
38780
38830
|
default: return 2;
|
|
38781
38831
|
}
|
|
38782
38832
|
}
|
|
38783
|
-
function isPidAlive$
|
|
38833
|
+
function isPidAlive$4(pid) {
|
|
38784
38834
|
try {
|
|
38785
38835
|
process$1.kill(pid, 0);
|
|
38786
38836
|
return true;
|
|
@@ -38891,7 +38941,7 @@ async function waitForDaemonSystemServiceToStop(input) {
|
|
|
38891
38941
|
if (!(await input.manager.status().catch(() => null))?.running && currentRuntime?.status !== "running") return true;
|
|
38892
38942
|
if (currentRuntime?.status === "stale" && !currentRuntime.managedBySystemService) return true;
|
|
38893
38943
|
if (currentRuntime?.status === "not_running") return true;
|
|
38894
|
-
await sleep
|
|
38944
|
+
await sleep(pollMs);
|
|
38895
38945
|
}
|
|
38896
38946
|
const finalRuntime = await readCurrentObservedDaemonRuntimeStatus().catch(() => null);
|
|
38897
38947
|
if (finalRuntime?.status === "not_running") return true;
|
|
@@ -39413,266 +39463,6 @@ function mergeOwnedProcesses(currentLaneProcesses, legacySharedProcesses) {
|
|
|
39413
39463
|
return merged;
|
|
39414
39464
|
}
|
|
39415
39465
|
|
|
39416
|
-
//#endregion
|
|
39417
|
-
//#region src/local-service/lifecycle/daemon-service-anomaly-groups.ts
|
|
39418
|
-
const DAEMON_SERVICE_FULL_ALIGNMENT_ANOMALIES = new Set([
|
|
39419
|
-
"legacy_shared_service_present",
|
|
39420
|
-
"version_outdated",
|
|
39421
|
-
"legacy_detached_runtime",
|
|
39422
|
-
"multiple_active_owners",
|
|
39423
|
-
"runtime_bundle_mismatch",
|
|
39424
|
-
"runtime_contract_missing",
|
|
39425
|
-
"runtime_contract_mismatch",
|
|
39426
|
-
"runtime_contract_unavailable",
|
|
39427
|
-
"bundle_missing",
|
|
39428
|
-
"bundle_content_drift",
|
|
39429
|
-
"bundle_id_drift",
|
|
39430
|
-
"bundle_version_drift",
|
|
39431
|
-
"bundle_lane_drift",
|
|
39432
|
-
"bundle_strategy_legacy",
|
|
39433
|
-
"bundle_provenance_drift",
|
|
39434
|
-
"bundle_path_invalid",
|
|
39435
|
-
"duplicate_owned_processes"
|
|
39436
|
-
]);
|
|
39437
|
-
const DAEMON_SERVICE_AUTO_HEAL_ANOMALIES = new Set([
|
|
39438
|
-
"runtime_stale",
|
|
39439
|
-
"manager_running_without_runtime",
|
|
39440
|
-
"service_manager_path_drift"
|
|
39441
|
-
]);
|
|
39442
|
-
const DAEMON_SERVICE_REPAIR_ANOMALIES = new Set([
|
|
39443
|
-
"runtime_stale",
|
|
39444
|
-
"manager_running_without_runtime",
|
|
39445
|
-
"legacy_detached_runtime",
|
|
39446
|
-
"multiple_active_owners",
|
|
39447
|
-
"runtime_bundle_mismatch",
|
|
39448
|
-
"runtime_contract_missing",
|
|
39449
|
-
"runtime_contract_mismatch",
|
|
39450
|
-
"runtime_contract_unavailable",
|
|
39451
|
-
"bundle_missing",
|
|
39452
|
-
"bundle_content_drift",
|
|
39453
|
-
"bundle_id_drift",
|
|
39454
|
-
"bundle_version_drift",
|
|
39455
|
-
"bundle_lane_drift",
|
|
39456
|
-
"bundle_strategy_legacy",
|
|
39457
|
-
"bundle_provenance_drift",
|
|
39458
|
-
"bundle_path_invalid",
|
|
39459
|
-
"service_manager_path_drift",
|
|
39460
|
-
"duplicate_owned_processes"
|
|
39461
|
-
]);
|
|
39462
|
-
const DAEMON_SERVICE_ARTIFACT_DRIFT_ANOMALIES = new Set([
|
|
39463
|
-
"background_foreground_conflict",
|
|
39464
|
-
"bundle_lane_drift",
|
|
39465
|
-
"bundle_missing",
|
|
39466
|
-
"bundle_content_drift",
|
|
39467
|
-
"bundle_id_drift",
|
|
39468
|
-
"bundle_path_invalid",
|
|
39469
|
-
"bundle_provenance_drift",
|
|
39470
|
-
"bundle_strategy_legacy",
|
|
39471
|
-
"bundle_version_drift",
|
|
39472
|
-
"manager_running_without_runtime",
|
|
39473
|
-
"runtime_bundle_mismatch",
|
|
39474
|
-
"runtime_contract_missing",
|
|
39475
|
-
"runtime_contract_mismatch",
|
|
39476
|
-
"runtime_contract_unavailable",
|
|
39477
|
-
"runtime_stale",
|
|
39478
|
-
"service_manager_path_drift",
|
|
39479
|
-
"version_outdated"
|
|
39480
|
-
]);
|
|
39481
|
-
const DAEMON_SERVICE_RUN_BLOCKING_ANOMALIES = new Set([
|
|
39482
|
-
...[...DAEMON_SERVICE_ARTIFACT_DRIFT_ANOMALIES].filter((code) => code !== "runtime_stale" && code !== "version_outdated" && code !== "bundle_version_drift"),
|
|
39483
|
-
"duplicate_owned_processes",
|
|
39484
|
-
"foreground_background_conflict"
|
|
39485
|
-
]);
|
|
39486
|
-
const DAEMON_SERVICE_WAKEABILITY_HARD_BLOCKER_ANOMALIES = new Set([
|
|
39487
|
-
"duplicate_owned_processes",
|
|
39488
|
-
"manager_running_without_runtime",
|
|
39489
|
-
"multiple_active_owners",
|
|
39490
|
-
"runtime_bundle_mismatch",
|
|
39491
|
-
"runtime_contract_mismatch"
|
|
39492
|
-
]);
|
|
39493
|
-
const DAEMON_SERVICE_WAKEABILITY_CONDITIONAL_ANOMALIES = new Set(["bundle_missing", "bundle_path_invalid"]);
|
|
39494
|
-
const DAEMON_SERVICE_WAKEABILITY_ADVISORY_ANOMALIES = new Set([
|
|
39495
|
-
"bundle_content_drift",
|
|
39496
|
-
"bundle_id_drift",
|
|
39497
|
-
"bundle_lane_drift",
|
|
39498
|
-
"bundle_provenance_drift",
|
|
39499
|
-
"bundle_strategy_legacy",
|
|
39500
|
-
"bundle_version_drift",
|
|
39501
|
-
"runtime_contract_missing",
|
|
39502
|
-
"runtime_contract_unavailable",
|
|
39503
|
-
"service_manager_path_drift",
|
|
39504
|
-
"version_outdated"
|
|
39505
|
-
]);
|
|
39506
|
-
function classifyDaemonServiceWakeability(input) {
|
|
39507
|
-
const anomalyCodes = collectUniqueAnomalyCodes(input.inventory);
|
|
39508
|
-
const executionEvidenceSafe = hasVerifiedRunningDaemonExecutionEvidence({
|
|
39509
|
-
anomalyCodes,
|
|
39510
|
-
inventory: input.inventory
|
|
39511
|
-
});
|
|
39512
|
-
const blockingCodes = [];
|
|
39513
|
-
const advisoryCodes = [];
|
|
39514
|
-
const conditionalCodes = [];
|
|
39515
|
-
for (const code of anomalyCodes) {
|
|
39516
|
-
if (DAEMON_SERVICE_WAKEABILITY_HARD_BLOCKER_ANOMALIES.has(code)) {
|
|
39517
|
-
blockingCodes.push(code);
|
|
39518
|
-
continue;
|
|
39519
|
-
}
|
|
39520
|
-
if (DAEMON_SERVICE_WAKEABILITY_CONDITIONAL_ANOMALIES.has(code)) {
|
|
39521
|
-
conditionalCodes.push(code);
|
|
39522
|
-
if (shouldBlockConditionalWakeabilityAnomaly({
|
|
39523
|
-
code,
|
|
39524
|
-
executionEvidenceSafe
|
|
39525
|
-
})) blockingCodes.push(code);
|
|
39526
|
-
else advisoryCodes.push(code);
|
|
39527
|
-
continue;
|
|
39528
|
-
}
|
|
39529
|
-
if (DAEMON_SERVICE_WAKEABILITY_ADVISORY_ANOMALIES.has(code)) advisoryCodes.push(code);
|
|
39530
|
-
}
|
|
39531
|
-
return {
|
|
39532
|
-
advisoryCodes,
|
|
39533
|
-
blockingCodes,
|
|
39534
|
-
blocksWake: blockingCodes.length > 0,
|
|
39535
|
-
conditionalCodes,
|
|
39536
|
-
executionEvidenceSafe
|
|
39537
|
-
};
|
|
39538
|
-
}
|
|
39539
|
-
function classifyDaemonServiceRunStartability(input) {
|
|
39540
|
-
const anomalyCodes = collectUniqueAnomalyCodes(input.inventory);
|
|
39541
|
-
const executionEvidenceSafe = hasVerifiedRunningDaemonExecutionEvidence({
|
|
39542
|
-
anomalyCodes,
|
|
39543
|
-
inventory: input.inventory
|
|
39544
|
-
});
|
|
39545
|
-
const blockingCodes = anomalyCodes.filter((code) => {
|
|
39546
|
-
if (!DAEMON_SERVICE_RUN_BLOCKING_ANOMALIES.has(code)) return false;
|
|
39547
|
-
return !(executionEvidenceSafe && DAEMON_SERVICE_WAKEABILITY_ADVISORY_ANOMALIES.has(code));
|
|
39548
|
-
});
|
|
39549
|
-
return {
|
|
39550
|
-
blockingCodes,
|
|
39551
|
-
blocksStart: blockingCodes.length > 0
|
|
39552
|
-
};
|
|
39553
|
-
}
|
|
39554
|
-
function shouldBlockConditionalWakeabilityAnomaly(input) {
|
|
39555
|
-
return !input.executionEvidenceSafe;
|
|
39556
|
-
}
|
|
39557
|
-
function hasVerifiedRunningDaemonExecutionEvidence(input) {
|
|
39558
|
-
const inventory = input.inventory;
|
|
39559
|
-
if (inventory?.runtimeStatus.status !== "running") return false;
|
|
39560
|
-
if (inventory.runtimeContractCompatibility?.status !== "compatible") return false;
|
|
39561
|
-
if (!hasUsableServiceContract(inventory.serviceContract)) return false;
|
|
39562
|
-
if (!(inventory.activeBundleEntryPath && inventory.runtimeCommandEntryPath && inventory.runtimeCommandPathExists === true)) return false;
|
|
39563
|
-
return !input.anomalyCodes.some((code) => DAEMON_SERVICE_WAKEABILITY_HARD_BLOCKER_ANOMALIES.has(code));
|
|
39564
|
-
}
|
|
39565
|
-
function hasUsableServiceContract(contract) {
|
|
39566
|
-
return Boolean(contract?.deviceId && contract.gatewayUrl && contract.lane && Number.isFinite(contract.heartbeatMs) && contract.heartbeatMs > 0);
|
|
39567
|
-
}
|
|
39568
|
-
function collectUniqueAnomalyCodes(inventory) {
|
|
39569
|
-
const codes = [];
|
|
39570
|
-
for (const anomaly of inventory?.anomalies ?? []) if (!codes.includes(anomaly.code)) codes.push(anomaly.code);
|
|
39571
|
-
return codes;
|
|
39572
|
-
}
|
|
39573
|
-
|
|
39574
|
-
//#endregion
|
|
39575
|
-
//#region src/system/local-service-install-attention.ts
|
|
39576
|
-
const DAEMON_INSTALL_DECISION_CHOICE = {
|
|
39577
|
-
install: "install",
|
|
39578
|
-
notNow: "not_now"
|
|
39579
|
-
};
|
|
39580
|
-
const DAEMON_INSTALL_COMMAND = "ats service install";
|
|
39581
|
-
const DAEMON_UPGRADE_COMMAND = "ats upgrade";
|
|
39582
|
-
const DAEMON_DECISION_RECOMMENDED_HINT = "Recommended";
|
|
39583
|
-
const DAEMON_INSTALL_DECISION_COPY = {
|
|
39584
|
-
missing: {
|
|
39585
|
-
question: "ATS Service is missing. Install it now?",
|
|
39586
|
-
explanation: "Without it, this computer can't receive local Wake work.",
|
|
39587
|
-
primaryLabel: "Yes, install it for me",
|
|
39588
|
-
deferred: "ATS Service is still missing. Install it later with `ats service install` so this computer can receive local Wake work.",
|
|
39589
|
-
failed: "ATS Service could not be installed. Run `ats service install` so this computer can receive local Wake work."
|
|
39590
|
-
},
|
|
39591
|
-
outdated: {
|
|
39592
|
-
question: "ATS Service update required. Update it now?",
|
|
39593
|
-
explanation: "This service artifact is not compatible with current local Wake execution.",
|
|
39594
|
-
primaryLabel: "Yes, update it for me",
|
|
39595
|
-
deferred: "ATS Service update skipped. Run `ats service update` before using local Wake work.",
|
|
39596
|
-
failed: "ATS Service was not updated. Run `ats service update`."
|
|
39597
|
-
}
|
|
39598
|
-
};
|
|
39599
|
-
function buildDaemonInstallDecisionPromptConfig(input) {
|
|
39600
|
-
const copy = DAEMON_INSTALL_DECISION_COPY[input.kind];
|
|
39601
|
-
const detailLine = input.kind === "outdated" && typeof input.installedVersion === "string" && typeof input.expectedVersion === "string" ? `Installed v${input.installedVersion}, expected v${input.expectedVersion}.` : null;
|
|
39602
|
-
return {
|
|
39603
|
-
message: [
|
|
39604
|
-
copy.question,
|
|
39605
|
-
copy.explanation,
|
|
39606
|
-
detailLine
|
|
39607
|
-
].filter((line) => typeof line === "string" && line.length > 0).join("\n"),
|
|
39608
|
-
initialValue: DAEMON_INSTALL_DECISION_CHOICE.install,
|
|
39609
|
-
options: [{
|
|
39610
|
-
value: DAEMON_INSTALL_DECISION_CHOICE.install,
|
|
39611
|
-
label: copy.primaryLabel,
|
|
39612
|
-
hint: DAEMON_DECISION_RECOMMENDED_HINT
|
|
39613
|
-
}, {
|
|
39614
|
-
value: DAEMON_INSTALL_DECISION_CHOICE.notNow,
|
|
39615
|
-
label: "Not now"
|
|
39616
|
-
}]
|
|
39617
|
-
};
|
|
39618
|
-
}
|
|
39619
|
-
async function promptForDaemonInstallDecision(input) {
|
|
39620
|
-
const choice = await select(buildDaemonInstallDecisionPromptConfig(input));
|
|
39621
|
-
if (isCancel(choice)) return "cancelled";
|
|
39622
|
-
return choice === DAEMON_INSTALL_DECISION_CHOICE.install ? DAEMON_INSTALL_DECISION_CHOICE.install : DAEMON_INSTALL_DECISION_CHOICE.notNow;
|
|
39623
|
-
}
|
|
39624
|
-
async function runDaemonInstallDecisionPrompt(input) {
|
|
39625
|
-
const decision = await promptForDaemonInstallDecision({
|
|
39626
|
-
kind: input.kind,
|
|
39627
|
-
installedVersion: input.installedVersion,
|
|
39628
|
-
expectedVersion: input.expectedVersion
|
|
39629
|
-
});
|
|
39630
|
-
if (decision === DAEMON_INSTALL_DECISION_CHOICE.install) try {
|
|
39631
|
-
await input.installService();
|
|
39632
|
-
return "install";
|
|
39633
|
-
} catch {
|
|
39634
|
-
await input.emitLine(formatDaemonInstallFailedMessage(input.kind));
|
|
39635
|
-
return "failed";
|
|
39636
|
-
}
|
|
39637
|
-
if (decision === "cancelled") return "cancelled";
|
|
39638
|
-
await input.emitLine(formatDaemonInstallDeferredMessage(input.kind));
|
|
39639
|
-
return decision;
|
|
39640
|
-
}
|
|
39641
|
-
function formatDaemonInstallDeferredMessage(kind) {
|
|
39642
|
-
return formatInlineAtsCliCommands(DAEMON_INSTALL_DECISION_COPY[kind].deferred);
|
|
39643
|
-
}
|
|
39644
|
-
function formatDaemonInstallFailedMessage(kind) {
|
|
39645
|
-
return formatInlineAtsCliCommands(DAEMON_INSTALL_DECISION_COPY[kind].failed);
|
|
39646
|
-
}
|
|
39647
|
-
function formatDaemonServiceMissingRecommendation() {
|
|
39648
|
-
return "ATS Service is not installed yet. Install it so this computer can receive local Wake work.";
|
|
39649
|
-
}
|
|
39650
|
-
function formatDaemonServiceMissingStatus() {
|
|
39651
|
-
return "Not installed yet.";
|
|
39652
|
-
}
|
|
39653
|
-
function formatDaemonServiceMissingMeaning() {
|
|
39654
|
-
return "Missing — install ATS Service before this computer can receive local Wake work.";
|
|
39655
|
-
}
|
|
39656
|
-
function formatDaemonServiceMissingAction() {
|
|
39657
|
-
return `Run \`${formatAtsCliCommand(DAEMON_INSTALL_COMMAND)}\` to set it up.`;
|
|
39658
|
-
}
|
|
39659
|
-
function formatDaemonServiceMissingRunStepOne() {
|
|
39660
|
-
return `\`${formatAtsCliCommand(DAEMON_INSTALL_COMMAND)}\``;
|
|
39661
|
-
}
|
|
39662
|
-
function formatDaemonServiceMissingRunStepTwo() {
|
|
39663
|
-
return `\`${formatAtsCliCommand("ats service start")}\``;
|
|
39664
|
-
}
|
|
39665
|
-
function formatDaemonServiceDowngradeBlockedRecommendation(input) {
|
|
39666
|
-
if (input.installedVersion) return `ATS Service is already newer (installed v${input.installedVersion}, current CLI v${input.expectedVersion}). ATS will not downgrade it automatically. Run \`${formatAtsCliCommand(DAEMON_UPGRADE_COMMAND)}\`.`;
|
|
39667
|
-
return `ATS Service is already newer than this CLI. ATS will not downgrade it automatically. Run \`${formatAtsCliCommand(DAEMON_UPGRADE_COMMAND)}\`.`;
|
|
39668
|
-
}
|
|
39669
|
-
function getDaemonDowngradeBlockedTitle() {
|
|
39670
|
-
return "⛔ ATS Service Downgrade Blocked";
|
|
39671
|
-
}
|
|
39672
|
-
function formatDaemonDowngradeBlockedNextStep() {
|
|
39673
|
-
return `Run \`${formatAtsCliCommand(DAEMON_UPGRADE_COMMAND)}\`.`;
|
|
39674
|
-
}
|
|
39675
|
-
|
|
39676
39466
|
//#endregion
|
|
39677
39467
|
//#region src/local-service/lifecycle/daemon-service-repair-guidance.ts
|
|
39678
39468
|
const DAEMON_SERVICE_SETUP_COMMAND = "ats setup";
|
|
@@ -39878,6 +39668,465 @@ function formatDaemonStartStartedNextStep() {
|
|
|
39878
39668
|
return "Use `ats service status` if you want to check the local service link and cloud connection.";
|
|
39879
39669
|
}
|
|
39880
39670
|
|
|
39671
|
+
//#endregion
|
|
39672
|
+
//#region src/commands/service-error-text.ts
|
|
39673
|
+
const ROOT_ERROR_PATTERN$1 = /\s*Try re-running the command as root for richer errors\.?/i;
|
|
39674
|
+
function sanitizeSystemServiceErrorMessage$1(message) {
|
|
39675
|
+
return message.replace(ROOT_ERROR_PATTERN$1, "");
|
|
39676
|
+
}
|
|
39677
|
+
|
|
39678
|
+
//#endregion
|
|
39679
|
+
//#region src/commands/service-start-failure.ts
|
|
39680
|
+
const DAEMON_STARTUP_BLOCKING_ANOMALIES = new Set([
|
|
39681
|
+
"duplicate_owned_processes",
|
|
39682
|
+
"multiple_active_owners",
|
|
39683
|
+
"runtime_bundle_mismatch",
|
|
39684
|
+
"runtime_contract_mismatch"
|
|
39685
|
+
]);
|
|
39686
|
+
var SystemServiceStartupTimeoutError = class extends Error {
|
|
39687
|
+
code = "ats.service.startup_timeout";
|
|
39688
|
+
inventory;
|
|
39689
|
+
managerStatus;
|
|
39690
|
+
runtimeStatus;
|
|
39691
|
+
jobDiagnostics;
|
|
39692
|
+
constructor(input) {
|
|
39693
|
+
super(buildSystemServiceStartupTimeoutMessage(input));
|
|
39694
|
+
this.name = "SystemServiceStartupTimeoutError";
|
|
39695
|
+
this.inventory = input.inventory;
|
|
39696
|
+
this.managerStatus = input.managerStatus;
|
|
39697
|
+
this.runtimeStatus = input.runtimeStatus;
|
|
39698
|
+
this.jobDiagnostics = input.jobDiagnostics ?? null;
|
|
39699
|
+
}
|
|
39700
|
+
};
|
|
39701
|
+
function resolveSystemServiceStartupFailureVerdict(input) {
|
|
39702
|
+
return {
|
|
39703
|
+
controller: input.controller,
|
|
39704
|
+
jobDiagnostics: isSystemServiceStartupTimeoutError(input.error) ? input.error.jobDiagnostics ?? null : null,
|
|
39705
|
+
message: sanitizeSystemServiceErrorMessage$1(toErrorMessage$43(input.error)),
|
|
39706
|
+
detail: input.detail ?? null
|
|
39707
|
+
};
|
|
39708
|
+
}
|
|
39709
|
+
function buildSystemServiceStartupFailureReport(input) {
|
|
39710
|
+
return buildSystemServiceStartupFailureReportFromVerdict(resolveSystemServiceStartupFailureVerdict({
|
|
39711
|
+
controller: input.controller,
|
|
39712
|
+
error: input.error,
|
|
39713
|
+
detail: input.detail
|
|
39714
|
+
}), { autoRepairAttempted: input.autoRepairAttempted });
|
|
39715
|
+
}
|
|
39716
|
+
function buildSystemServiceStartupFailureReportFromVerdict(verdict, options) {
|
|
39717
|
+
const autoRepairAttempted = options?.autoRepairAttempted;
|
|
39718
|
+
const { message, detail, jobDiagnostics } = verdict;
|
|
39719
|
+
const localLogPath = getDaemonSystemServiceLogPath();
|
|
39720
|
+
if (jobDiagnostics && isDaemonServiceJobNeverSpawned(jobDiagnostics)) {
|
|
39721
|
+
const summary = "macOS is blocking the ATS Service background item, so ATS Service never launched.";
|
|
39722
|
+
const card = buildDaemonStartNeedsAttentionCard({
|
|
39723
|
+
summary,
|
|
39724
|
+
nextStep: formatInlineAtsCliCommands("Path A (recommended): open System Settings > General > Login Items & Extensions, enable the ATS background item, then run `ats service start` again. Power users can audit Background Task Management with `sfltool dumpbtm`. Path B: if you would rather not change System Settings, open a separate terminal window, run `ats service start --mode foreground`, and keep that window open — but note ATS Service stops the moment you close that window or restart your Mac, so Wake will not be received."),
|
|
39725
|
+
autoRepairAttempted,
|
|
39726
|
+
detail: detail ?? formatDaemonServiceJobDiagnosticsEvidence(jobDiagnostics)
|
|
39727
|
+
});
|
|
39728
|
+
return {
|
|
39729
|
+
title: card.title,
|
|
39730
|
+
summary,
|
|
39731
|
+
rows: card.rows
|
|
39732
|
+
};
|
|
39733
|
+
}
|
|
39734
|
+
const crashExitCode = jobDiagnostics ? readDaemonServiceJobCrashExitCode(jobDiagnostics) : null;
|
|
39735
|
+
if (jobDiagnostics && crashExitCode !== null) {
|
|
39736
|
+
const summary = `ATS Service launched but keeps exiting (launchd reports ${jobDiagnostics.runs} runs, last exit code ${crashExitCode}).`;
|
|
39737
|
+
const card = buildDaemonStartNeedsAttentionCard({
|
|
39738
|
+
summary,
|
|
39739
|
+
nextStep: formatInlineAtsCliCommands(`Run \`ats service start --mode foreground\` to see the live error. The latest local service log is at \`${localLogPath}\`. If it still fails, run \`ats service repair\`.`),
|
|
39740
|
+
autoRepairAttempted,
|
|
39741
|
+
detail: detail ?? formatDaemonServiceJobDiagnosticsEvidence(jobDiagnostics)
|
|
39742
|
+
});
|
|
39743
|
+
return {
|
|
39744
|
+
title: card.title,
|
|
39745
|
+
summary,
|
|
39746
|
+
rows: card.rows
|
|
39747
|
+
};
|
|
39748
|
+
}
|
|
39749
|
+
if (isLaunchdBootstrapIosError$1(message)) {
|
|
39750
|
+
const card = buildDaemonStartNeedsAttentionCard({
|
|
39751
|
+
summary: "ATS could not finish starting ATS Service on this Mac.",
|
|
39752
|
+
nextStep: formatInlineAtsCliCommands(`Run \`launchctl enable gui/$(id -u)/${getDaemonServiceLaunchdLabel()}\`, then retry with \`ats service start\`. The latest local service log is at \`${localLogPath}\`. If it still fails, run \`ats service repair\`.`),
|
|
39753
|
+
autoRepairAttempted,
|
|
39754
|
+
detail: detail ?? void 0
|
|
39755
|
+
});
|
|
39756
|
+
return {
|
|
39757
|
+
title: card.title,
|
|
39758
|
+
summary: "ATS could not finish starting ATS Service on this Mac.",
|
|
39759
|
+
rows: card.rows
|
|
39760
|
+
};
|
|
39761
|
+
}
|
|
39762
|
+
if (isPermissionOrAuthorizationError(message)) {
|
|
39763
|
+
const card = buildDaemonStartNeedsAttentionCard({
|
|
39764
|
+
summary: "ATS needs local OS permission before it can start ATS Service.",
|
|
39765
|
+
nextStep: formatInlineAtsCliCommands(`Approve the local permission prompt or OS setting, then run \`ats service start\` again. The latest local service log is at \`${localLogPath}\`.`),
|
|
39766
|
+
autoRepairAttempted,
|
|
39767
|
+
detail: detail ?? void 0
|
|
39768
|
+
});
|
|
39769
|
+
return {
|
|
39770
|
+
title: card.title,
|
|
39771
|
+
summary: "ATS needs local OS permission before it can start ATS Service.",
|
|
39772
|
+
rows: card.rows
|
|
39773
|
+
};
|
|
39774
|
+
}
|
|
39775
|
+
const card = buildDaemonStartNeedsAttentionCard({
|
|
39776
|
+
summary: "ATS could not finish starting ATS Service.",
|
|
39777
|
+
nextStep: formatInlineAtsCliCommands(`Run \`ats service start --mode foreground\` to see the live error. The latest local service log is at \`${localLogPath}\`. If it still fails, run \`ats service repair\`.`),
|
|
39778
|
+
autoRepairAttempted,
|
|
39779
|
+
detail: detail ?? void 0
|
|
39780
|
+
});
|
|
39781
|
+
return {
|
|
39782
|
+
title: card.title,
|
|
39783
|
+
summary: `ATS could not finish starting ATS Service (${verdict.controller}).`,
|
|
39784
|
+
rows: card.rows
|
|
39785
|
+
};
|
|
39786
|
+
}
|
|
39787
|
+
function buildSystemServiceStartupFailureMessage(input) {
|
|
39788
|
+
const report = buildSystemServiceStartupFailureReport(input);
|
|
39789
|
+
const rowLines = report.rows.map((row) => formatSystemServiceFailureRow(row)).filter((line) => line.length > 0);
|
|
39790
|
+
return [report.summary, ...rowLines].join("\n");
|
|
39791
|
+
}
|
|
39792
|
+
function buildSystemServiceStartupFailureDiagnostics(input) {
|
|
39793
|
+
const timeoutError = isSystemServiceStartupTimeoutError(input.error) ? input.error : null;
|
|
39794
|
+
return {
|
|
39795
|
+
anomalies: timeoutError?.inventory?.anomalies ?? [],
|
|
39796
|
+
autoRepairAttempted: input.autoRepairAttempted === true,
|
|
39797
|
+
controller: input.controller ?? null,
|
|
39798
|
+
jobDiagnostics: timeoutError?.jobDiagnostics ?? null,
|
|
39799
|
+
launchdLabel: (input.controller ?? null) === "launchd" ? getDaemonServiceLaunchdLabel() : null,
|
|
39800
|
+
lifecycleJournalPath: daemonLifecycleJournalPath(),
|
|
39801
|
+
managerStatus: timeoutError?.managerStatus ?? null,
|
|
39802
|
+
nextSteps: [formatAtsCliCommand("ats service start --mode foreground"), formatAtsCliCommand("ats service repair")],
|
|
39803
|
+
recovery: input.recovery,
|
|
39804
|
+
runtimeStatus: timeoutError?.runtimeStatus ?? null,
|
|
39805
|
+
serviceLogPath: getDaemonSystemServiceLogPath()
|
|
39806
|
+
};
|
|
39807
|
+
}
|
|
39808
|
+
function buildSystemServiceStartupTimeoutMessage(input) {
|
|
39809
|
+
const base = `ATS Service failed to reach a running local service state in time. runtime=${input.runtimeStatus?.status ?? "unknown"}, reason=${input.runtimeStatus?.reason || "unknown"}, managerRunning=${String(input.managerStatus?.running ?? false)}, anomalies=${input.inventory?.anomalies.map((anomaly) => anomaly.code).join(",") || "unknown"}`;
|
|
39810
|
+
if (!input.jobDiagnostics) return base;
|
|
39811
|
+
return `${base}; ${formatDaemonServiceJobDiagnosticsEvidence(input.jobDiagnostics)}`;
|
|
39812
|
+
}
|
|
39813
|
+
function isSystemServiceStartupTimeoutError(error) {
|
|
39814
|
+
return error instanceof SystemServiceStartupTimeoutError || typeof error === "object" && error !== null && "code" in error && error.code === "ats.service.startup_timeout";
|
|
39815
|
+
}
|
|
39816
|
+
function formatSystemServiceFailureRow(row) {
|
|
39817
|
+
const label = row.label.trim();
|
|
39818
|
+
const value = formatAtsCliTextBlock(row.value).trim();
|
|
39819
|
+
if (label.length === 0 && value.length === 0) return "";
|
|
39820
|
+
if (value.length === 0) return `${row.label}:`;
|
|
39821
|
+
if (label.length === 0) return row.value;
|
|
39822
|
+
return `${row.label}: ${row.value}`;
|
|
39823
|
+
}
|
|
39824
|
+
function isLaunchdBootstrapIosError$1(message) {
|
|
39825
|
+
const normalized = message.toLowerCase();
|
|
39826
|
+
return normalized.includes("bootstrap failed") && normalized.includes("input/output error");
|
|
39827
|
+
}
|
|
39828
|
+
function isPermissionOrAuthorizationError(message) {
|
|
39829
|
+
const normalized = message.toLowerCase();
|
|
39830
|
+
return normalized.includes("permission") || normalized.includes("operation not permitted") || normalized.includes("access is denied") || normalized.includes("requires admin") || normalized.includes("elevation") || normalized.includes("access denied") || normalized.includes("not authorized");
|
|
39831
|
+
}
|
|
39832
|
+
function isDaemonInventoryRunningAndStartReady(inventory) {
|
|
39833
|
+
if (inventory.runtimeStatus.status !== "running") return false;
|
|
39834
|
+
if (inventory.runtimeStatus.mode !== "background") return false;
|
|
39835
|
+
if (inventory.runtimeStatus.managedBySystemService !== true) return false;
|
|
39836
|
+
return !inventory.anomalies.some((anomaly) => DAEMON_STARTUP_BLOCKING_ANOMALIES.has(anomaly.code));
|
|
39837
|
+
}
|
|
39838
|
+
async function waitForSystemServiceStartup(input) {
|
|
39839
|
+
const deadlineMs = Date.now() + input.waitMs;
|
|
39840
|
+
while (Date.now() < deadlineMs) {
|
|
39841
|
+
const inventory = await inspectDaemonServiceInventory({
|
|
39842
|
+
expectedVersion: input.expectedVersion,
|
|
39843
|
+
intendedMode: "background",
|
|
39844
|
+
intent: "run_background"
|
|
39845
|
+
}).catch(() => null);
|
|
39846
|
+
if (inventory && isDaemonInventoryRunningAndStartReady(inventory)) return {
|
|
39847
|
+
state: "running",
|
|
39848
|
+
runtimeStatus: inventory.runtimeStatus
|
|
39849
|
+
};
|
|
39850
|
+
await sleep(input.pollMs);
|
|
39851
|
+
}
|
|
39852
|
+
const finalInventory = await inspectDaemonServiceInventory({
|
|
39853
|
+
expectedVersion: input.expectedVersion,
|
|
39854
|
+
intendedMode: "background",
|
|
39855
|
+
intent: "run_background"
|
|
39856
|
+
}).catch(() => null);
|
|
39857
|
+
if (finalInventory && isDaemonInventoryRunningAndStartReady(finalInventory)) return {
|
|
39858
|
+
state: "running",
|
|
39859
|
+
runtimeStatus: finalInventory.runtimeStatus
|
|
39860
|
+
};
|
|
39861
|
+
const finalRuntimeStatus = await readCurrentObservedDaemonRuntimeStatus().catch(() => null);
|
|
39862
|
+
throw new SystemServiceStartupTimeoutError({
|
|
39863
|
+
inventory: finalInventory,
|
|
39864
|
+
managerStatus: await input.manager.status().catch(() => null),
|
|
39865
|
+
runtimeStatus: finalRuntimeStatus,
|
|
39866
|
+
jobDiagnostics: await input.manager.readJobDiagnostics?.().catch(() => null) ?? null
|
|
39867
|
+
});
|
|
39868
|
+
}
|
|
39869
|
+
|
|
39870
|
+
//#endregion
|
|
39871
|
+
//#region src/local-service/lifecycle/daemon-service-anomaly-groups.ts
|
|
39872
|
+
const DAEMON_SERVICE_FULL_ALIGNMENT_ANOMALIES = new Set([
|
|
39873
|
+
"legacy_shared_service_present",
|
|
39874
|
+
"version_outdated",
|
|
39875
|
+
"legacy_detached_runtime",
|
|
39876
|
+
"multiple_active_owners",
|
|
39877
|
+
"runtime_bundle_mismatch",
|
|
39878
|
+
"runtime_contract_missing",
|
|
39879
|
+
"runtime_contract_mismatch",
|
|
39880
|
+
"runtime_contract_unavailable",
|
|
39881
|
+
"bundle_missing",
|
|
39882
|
+
"bundle_content_drift",
|
|
39883
|
+
"bundle_id_drift",
|
|
39884
|
+
"bundle_version_drift",
|
|
39885
|
+
"bundle_lane_drift",
|
|
39886
|
+
"bundle_strategy_legacy",
|
|
39887
|
+
"bundle_provenance_drift",
|
|
39888
|
+
"bundle_path_invalid",
|
|
39889
|
+
"duplicate_owned_processes"
|
|
39890
|
+
]);
|
|
39891
|
+
const DAEMON_SERVICE_AUTO_HEAL_ANOMALIES = new Set([
|
|
39892
|
+
"runtime_stale",
|
|
39893
|
+
"manager_running_without_runtime",
|
|
39894
|
+
"service_manager_path_drift"
|
|
39895
|
+
]);
|
|
39896
|
+
const DAEMON_SERVICE_REPAIR_ANOMALIES = new Set([
|
|
39897
|
+
"runtime_stale",
|
|
39898
|
+
"manager_running_without_runtime",
|
|
39899
|
+
"legacy_detached_runtime",
|
|
39900
|
+
"multiple_active_owners",
|
|
39901
|
+
"runtime_bundle_mismatch",
|
|
39902
|
+
"runtime_contract_missing",
|
|
39903
|
+
"runtime_contract_mismatch",
|
|
39904
|
+
"runtime_contract_unavailable",
|
|
39905
|
+
"bundle_missing",
|
|
39906
|
+
"bundle_content_drift",
|
|
39907
|
+
"bundle_id_drift",
|
|
39908
|
+
"bundle_version_drift",
|
|
39909
|
+
"bundle_lane_drift",
|
|
39910
|
+
"bundle_strategy_legacy",
|
|
39911
|
+
"bundle_provenance_drift",
|
|
39912
|
+
"bundle_path_invalid",
|
|
39913
|
+
"service_manager_path_drift",
|
|
39914
|
+
"duplicate_owned_processes"
|
|
39915
|
+
]);
|
|
39916
|
+
const DAEMON_SERVICE_ARTIFACT_DRIFT_ANOMALIES = new Set([
|
|
39917
|
+
"background_foreground_conflict",
|
|
39918
|
+
"bundle_lane_drift",
|
|
39919
|
+
"bundle_missing",
|
|
39920
|
+
"bundle_content_drift",
|
|
39921
|
+
"bundle_id_drift",
|
|
39922
|
+
"bundle_path_invalid",
|
|
39923
|
+
"bundle_provenance_drift",
|
|
39924
|
+
"bundle_strategy_legacy",
|
|
39925
|
+
"bundle_version_drift",
|
|
39926
|
+
"manager_running_without_runtime",
|
|
39927
|
+
"runtime_bundle_mismatch",
|
|
39928
|
+
"runtime_contract_missing",
|
|
39929
|
+
"runtime_contract_mismatch",
|
|
39930
|
+
"runtime_contract_unavailable",
|
|
39931
|
+
"runtime_stale",
|
|
39932
|
+
"service_manager_path_drift",
|
|
39933
|
+
"version_outdated"
|
|
39934
|
+
]);
|
|
39935
|
+
const DAEMON_SERVICE_RUN_BLOCKING_ANOMALIES = new Set([
|
|
39936
|
+
...[...DAEMON_SERVICE_ARTIFACT_DRIFT_ANOMALIES].filter((code) => code !== "runtime_stale" && code !== "version_outdated" && code !== "bundle_version_drift"),
|
|
39937
|
+
"duplicate_owned_processes",
|
|
39938
|
+
"foreground_background_conflict"
|
|
39939
|
+
]);
|
|
39940
|
+
const DAEMON_SERVICE_WAKEABILITY_HARD_BLOCKER_ANOMALIES = new Set([
|
|
39941
|
+
"duplicate_owned_processes",
|
|
39942
|
+
"manager_running_without_runtime",
|
|
39943
|
+
"multiple_active_owners",
|
|
39944
|
+
"runtime_bundle_mismatch",
|
|
39945
|
+
"runtime_contract_mismatch"
|
|
39946
|
+
]);
|
|
39947
|
+
const DAEMON_SERVICE_WAKEABILITY_CONDITIONAL_ANOMALIES = new Set(["bundle_missing", "bundle_path_invalid"]);
|
|
39948
|
+
const DAEMON_SERVICE_WAKEABILITY_ADVISORY_ANOMALIES = new Set([
|
|
39949
|
+
"bundle_content_drift",
|
|
39950
|
+
"bundle_id_drift",
|
|
39951
|
+
"bundle_lane_drift",
|
|
39952
|
+
"bundle_provenance_drift",
|
|
39953
|
+
"bundle_strategy_legacy",
|
|
39954
|
+
"bundle_version_drift",
|
|
39955
|
+
"runtime_contract_missing",
|
|
39956
|
+
"runtime_contract_unavailable",
|
|
39957
|
+
"service_manager_path_drift",
|
|
39958
|
+
"version_outdated"
|
|
39959
|
+
]);
|
|
39960
|
+
function classifyDaemonServiceWakeability(input) {
|
|
39961
|
+
const anomalyCodes = collectUniqueAnomalyCodes(input.inventory);
|
|
39962
|
+
const executionEvidenceSafe = hasVerifiedRunningDaemonExecutionEvidence({
|
|
39963
|
+
anomalyCodes,
|
|
39964
|
+
inventory: input.inventory
|
|
39965
|
+
});
|
|
39966
|
+
const blockingCodes = [];
|
|
39967
|
+
const advisoryCodes = [];
|
|
39968
|
+
const conditionalCodes = [];
|
|
39969
|
+
for (const code of anomalyCodes) {
|
|
39970
|
+
if (DAEMON_SERVICE_WAKEABILITY_HARD_BLOCKER_ANOMALIES.has(code)) {
|
|
39971
|
+
blockingCodes.push(code);
|
|
39972
|
+
continue;
|
|
39973
|
+
}
|
|
39974
|
+
if (DAEMON_SERVICE_WAKEABILITY_CONDITIONAL_ANOMALIES.has(code)) {
|
|
39975
|
+
conditionalCodes.push(code);
|
|
39976
|
+
if (shouldBlockConditionalWakeabilityAnomaly({
|
|
39977
|
+
code,
|
|
39978
|
+
executionEvidenceSafe
|
|
39979
|
+
})) blockingCodes.push(code);
|
|
39980
|
+
else advisoryCodes.push(code);
|
|
39981
|
+
continue;
|
|
39982
|
+
}
|
|
39983
|
+
if (DAEMON_SERVICE_WAKEABILITY_ADVISORY_ANOMALIES.has(code)) advisoryCodes.push(code);
|
|
39984
|
+
}
|
|
39985
|
+
return {
|
|
39986
|
+
advisoryCodes,
|
|
39987
|
+
blockingCodes,
|
|
39988
|
+
blocksWake: blockingCodes.length > 0,
|
|
39989
|
+
conditionalCodes,
|
|
39990
|
+
executionEvidenceSafe
|
|
39991
|
+
};
|
|
39992
|
+
}
|
|
39993
|
+
function classifyDaemonServiceRunStartability(input) {
|
|
39994
|
+
const anomalyCodes = collectUniqueAnomalyCodes(input.inventory);
|
|
39995
|
+
const executionEvidenceSafe = hasVerifiedRunningDaemonExecutionEvidence({
|
|
39996
|
+
anomalyCodes,
|
|
39997
|
+
inventory: input.inventory
|
|
39998
|
+
});
|
|
39999
|
+
const blockingCodes = anomalyCodes.filter((code) => {
|
|
40000
|
+
if (!DAEMON_SERVICE_RUN_BLOCKING_ANOMALIES.has(code)) return false;
|
|
40001
|
+
return !(executionEvidenceSafe && DAEMON_SERVICE_WAKEABILITY_ADVISORY_ANOMALIES.has(code));
|
|
40002
|
+
});
|
|
40003
|
+
return {
|
|
40004
|
+
blockingCodes,
|
|
40005
|
+
blocksStart: blockingCodes.length > 0
|
|
40006
|
+
};
|
|
40007
|
+
}
|
|
40008
|
+
function shouldBlockConditionalWakeabilityAnomaly(input) {
|
|
40009
|
+
return !input.executionEvidenceSafe;
|
|
40010
|
+
}
|
|
40011
|
+
function hasVerifiedRunningDaemonExecutionEvidence(input) {
|
|
40012
|
+
const inventory = input.inventory;
|
|
40013
|
+
if (inventory?.runtimeStatus.status !== "running") return false;
|
|
40014
|
+
if (inventory.runtimeContractCompatibility?.status !== "compatible") return false;
|
|
40015
|
+
if (!hasUsableServiceContract(inventory.serviceContract)) return false;
|
|
40016
|
+
if (!(inventory.activeBundleEntryPath && inventory.runtimeCommandEntryPath && inventory.runtimeCommandPathExists === true)) return false;
|
|
40017
|
+
return !input.anomalyCodes.some((code) => DAEMON_SERVICE_WAKEABILITY_HARD_BLOCKER_ANOMALIES.has(code));
|
|
40018
|
+
}
|
|
40019
|
+
function hasUsableServiceContract(contract) {
|
|
40020
|
+
return Boolean(contract?.deviceId && contract.gatewayUrl && contract.lane && Number.isFinite(contract.heartbeatMs) && contract.heartbeatMs > 0);
|
|
40021
|
+
}
|
|
40022
|
+
function collectUniqueAnomalyCodes(inventory) {
|
|
40023
|
+
const codes = [];
|
|
40024
|
+
for (const anomaly of inventory?.anomalies ?? []) if (!codes.includes(anomaly.code)) codes.push(anomaly.code);
|
|
40025
|
+
return codes;
|
|
40026
|
+
}
|
|
40027
|
+
|
|
40028
|
+
//#endregion
|
|
40029
|
+
//#region src/system/local-service-install-attention.ts
|
|
40030
|
+
const DAEMON_INSTALL_DECISION_CHOICE = {
|
|
40031
|
+
install: "install",
|
|
40032
|
+
notNow: "not_now"
|
|
40033
|
+
};
|
|
40034
|
+
const DAEMON_INSTALL_COMMAND = "ats service install";
|
|
40035
|
+
const DAEMON_UPGRADE_COMMAND = "ats upgrade";
|
|
40036
|
+
const DAEMON_DECISION_RECOMMENDED_HINT = "Recommended";
|
|
40037
|
+
const DAEMON_INSTALL_DECISION_COPY = {
|
|
40038
|
+
missing: {
|
|
40039
|
+
question: "ATS Service is missing. Install it now?",
|
|
40040
|
+
explanation: "Without it, this computer can't receive local Wake work.",
|
|
40041
|
+
primaryLabel: "Yes, install it for me",
|
|
40042
|
+
deferred: "ATS Service is still missing. Install it later with `ats service install` so this computer can receive local Wake work.",
|
|
40043
|
+
failed: "ATS Service could not be installed. Run `ats service install` so this computer can receive local Wake work."
|
|
40044
|
+
},
|
|
40045
|
+
outdated: {
|
|
40046
|
+
question: "ATS Service update required. Update it now?",
|
|
40047
|
+
explanation: "This service artifact is not compatible with current local Wake execution.",
|
|
40048
|
+
primaryLabel: "Yes, update it for me",
|
|
40049
|
+
deferred: "ATS Service update skipped. Run `ats service update` before using local Wake work.",
|
|
40050
|
+
failed: "ATS Service was not updated. Run `ats service update`."
|
|
40051
|
+
}
|
|
40052
|
+
};
|
|
40053
|
+
function buildDaemonInstallDecisionPromptConfig(input) {
|
|
40054
|
+
const copy = DAEMON_INSTALL_DECISION_COPY[input.kind];
|
|
40055
|
+
const detailLine = input.kind === "outdated" && typeof input.installedVersion === "string" && typeof input.expectedVersion === "string" ? `Installed v${input.installedVersion}, expected v${input.expectedVersion}.` : null;
|
|
40056
|
+
return {
|
|
40057
|
+
message: [
|
|
40058
|
+
copy.question,
|
|
40059
|
+
copy.explanation,
|
|
40060
|
+
detailLine
|
|
40061
|
+
].filter((line) => typeof line === "string" && line.length > 0).join("\n"),
|
|
40062
|
+
initialValue: DAEMON_INSTALL_DECISION_CHOICE.install,
|
|
40063
|
+
options: [{
|
|
40064
|
+
value: DAEMON_INSTALL_DECISION_CHOICE.install,
|
|
40065
|
+
label: copy.primaryLabel,
|
|
40066
|
+
hint: DAEMON_DECISION_RECOMMENDED_HINT
|
|
40067
|
+
}, {
|
|
40068
|
+
value: DAEMON_INSTALL_DECISION_CHOICE.notNow,
|
|
40069
|
+
label: "Not now"
|
|
40070
|
+
}]
|
|
40071
|
+
};
|
|
40072
|
+
}
|
|
40073
|
+
async function promptForDaemonInstallDecision(input) {
|
|
40074
|
+
const choice = await select(buildDaemonInstallDecisionPromptConfig(input));
|
|
40075
|
+
if (isCancel(choice)) return "cancelled";
|
|
40076
|
+
return choice === DAEMON_INSTALL_DECISION_CHOICE.install ? DAEMON_INSTALL_DECISION_CHOICE.install : DAEMON_INSTALL_DECISION_CHOICE.notNow;
|
|
40077
|
+
}
|
|
40078
|
+
async function runDaemonInstallDecisionPrompt(input) {
|
|
40079
|
+
const decision = await promptForDaemonInstallDecision({
|
|
40080
|
+
kind: input.kind,
|
|
40081
|
+
installedVersion: input.installedVersion,
|
|
40082
|
+
expectedVersion: input.expectedVersion
|
|
40083
|
+
});
|
|
40084
|
+
if (decision === DAEMON_INSTALL_DECISION_CHOICE.install) try {
|
|
40085
|
+
await input.installService();
|
|
40086
|
+
return "install";
|
|
40087
|
+
} catch {
|
|
40088
|
+
await input.emitLine(formatDaemonInstallFailedMessage(input.kind));
|
|
40089
|
+
return "failed";
|
|
40090
|
+
}
|
|
40091
|
+
if (decision === "cancelled") return "cancelled";
|
|
40092
|
+
await input.emitLine(formatDaemonInstallDeferredMessage(input.kind));
|
|
40093
|
+
return decision;
|
|
40094
|
+
}
|
|
40095
|
+
function formatDaemonInstallDeferredMessage(kind) {
|
|
40096
|
+
return formatInlineAtsCliCommands(DAEMON_INSTALL_DECISION_COPY[kind].deferred);
|
|
40097
|
+
}
|
|
40098
|
+
function formatDaemonInstallFailedMessage(kind) {
|
|
40099
|
+
return formatInlineAtsCliCommands(DAEMON_INSTALL_DECISION_COPY[kind].failed);
|
|
40100
|
+
}
|
|
40101
|
+
function formatDaemonServiceMissingRecommendation() {
|
|
40102
|
+
return "ATS Service is not installed yet. Install it so this computer can receive local Wake work.";
|
|
40103
|
+
}
|
|
40104
|
+
function formatDaemonServiceMissingStatus() {
|
|
40105
|
+
return "Not installed yet.";
|
|
40106
|
+
}
|
|
40107
|
+
function formatDaemonServiceMissingMeaning() {
|
|
40108
|
+
return "Missing — install ATS Service before this computer can receive local Wake work.";
|
|
40109
|
+
}
|
|
40110
|
+
function formatDaemonServiceMissingAction() {
|
|
40111
|
+
return `Run \`${formatAtsCliCommand(DAEMON_INSTALL_COMMAND)}\` to set it up.`;
|
|
40112
|
+
}
|
|
40113
|
+
function formatDaemonServiceMissingRunStepOne() {
|
|
40114
|
+
return `\`${formatAtsCliCommand(DAEMON_INSTALL_COMMAND)}\``;
|
|
40115
|
+
}
|
|
40116
|
+
function formatDaemonServiceMissingRunStepTwo() {
|
|
40117
|
+
return `\`${formatAtsCliCommand("ats service start")}\``;
|
|
40118
|
+
}
|
|
40119
|
+
function formatDaemonServiceDowngradeBlockedRecommendation(input) {
|
|
40120
|
+
if (input.installedVersion) return `ATS Service is already newer (installed v${input.installedVersion}, current CLI v${input.expectedVersion}). ATS will not downgrade it automatically. Run \`${formatAtsCliCommand(DAEMON_UPGRADE_COMMAND)}\`.`;
|
|
40121
|
+
return `ATS Service is already newer than this CLI. ATS will not downgrade it automatically. Run \`${formatAtsCliCommand(DAEMON_UPGRADE_COMMAND)}\`.`;
|
|
40122
|
+
}
|
|
40123
|
+
function getDaemonDowngradeBlockedTitle() {
|
|
40124
|
+
return "⛔ ATS Service Downgrade Blocked";
|
|
40125
|
+
}
|
|
40126
|
+
function formatDaemonDowngradeBlockedNextStep() {
|
|
40127
|
+
return `Run \`${formatAtsCliCommand(DAEMON_UPGRADE_COMMAND)}\`.`;
|
|
40128
|
+
}
|
|
40129
|
+
|
|
39881
40130
|
//#endregion
|
|
39882
40131
|
//#region src/system/local-service-participation-gate.ts
|
|
39883
40132
|
function shouldRequireDaemonServiceParticipation(localDemand) {
|
|
@@ -40195,12 +40444,26 @@ async function runDaemonServiceParticipationRefresh(input) {
|
|
|
40195
40444
|
}
|
|
40196
40445
|
return startMapped;
|
|
40197
40446
|
}
|
|
40447
|
+
if (!refreshOutcome.ok && (refreshOutcome.result === "start_failed" || refreshOutcome.result === "start_blocked") && refreshOutcome.startFailureVerdict?.jobDiagnostics) {
|
|
40448
|
+
const report = buildSystemServiceStartupFailureReportFromVerdict(refreshOutcome.startFailureVerdict, { autoRepairAttempted: true });
|
|
40449
|
+
renderInfoCard({
|
|
40450
|
+
presenter: input.input.presenter,
|
|
40451
|
+
title: report.title,
|
|
40452
|
+
codePrefix: `${input.codePrefix}.failed`,
|
|
40453
|
+
rows: report.rows
|
|
40454
|
+
});
|
|
40455
|
+
return {
|
|
40456
|
+
errorMessage: report.summary,
|
|
40457
|
+
status: "needs_attention"
|
|
40458
|
+
};
|
|
40459
|
+
}
|
|
40198
40460
|
if (!(refreshOutcome.ok && refreshOutcome.result === "completed" && refreshOutcome.serviceState === "running")) throw new Error(`ATS Service refresh did not complete: ${refreshOutcome.result}`);
|
|
40199
40461
|
} catch (error) {
|
|
40200
40462
|
renderDaemonStartNeedsAttention({
|
|
40201
40463
|
presenter: input.input.presenter,
|
|
40202
40464
|
codePrefix: input.codePrefix,
|
|
40203
|
-
summary: "ATS Service was repaired, but it is not running yet. Local Wake work will keep waiting until ATS Service starts. Run `ats service start`."
|
|
40465
|
+
summary: "ATS Service was repaired, but it is not running yet. Local Wake work will keep waiting until ATS Service starts. Run `ats service start`.",
|
|
40466
|
+
autoRepairAttempted: true
|
|
40204
40467
|
});
|
|
40205
40468
|
return {
|
|
40206
40469
|
errorMessage: toErrorMessage$30(error),
|
|
@@ -40321,7 +40584,12 @@ function renderDaemonStartDeferred(input) {
|
|
|
40321
40584
|
});
|
|
40322
40585
|
}
|
|
40323
40586
|
function renderDaemonStartNeedsAttention(input) {
|
|
40324
|
-
const card = buildDaemonStartNeedsAttentionCard({
|
|
40587
|
+
const card = buildDaemonStartNeedsAttentionCard({
|
|
40588
|
+
summary: input.summary,
|
|
40589
|
+
...input.nextStep ? { nextStep: input.nextStep } : {},
|
|
40590
|
+
...input.detail ? { detail: input.detail } : {},
|
|
40591
|
+
...input.autoRepairAttempted ? { autoRepairAttempted: input.autoRepairAttempted } : {}
|
|
40592
|
+
});
|
|
40325
40593
|
renderInfoCard({
|
|
40326
40594
|
presenter: input.presenter,
|
|
40327
40595
|
title: card.title,
|
|
@@ -40450,8 +40718,8 @@ function resolveLocalComponentsSetupAction(input) {
|
|
|
40450
40718
|
return "none";
|
|
40451
40719
|
}
|
|
40452
40720
|
function resolveCliComponentStatus(input) {
|
|
40453
|
-
const latestPackageVersion = normalizeOptionalString$
|
|
40454
|
-
const requiredCommandContractVersion = normalizeOptionalString$
|
|
40721
|
+
const latestPackageVersion = normalizeOptionalString$18(input.latestPackageVersion);
|
|
40722
|
+
const requiredCommandContractVersion = normalizeOptionalString$18(input.requiredCommandContractVersion);
|
|
40455
40723
|
const reasonCodes = [];
|
|
40456
40724
|
let status = "ok";
|
|
40457
40725
|
if (requiredCommandContractVersion && requiredCommandContractVersion !== ATS_CLI_COMMAND_CONTRACT_VERSION) {
|
|
@@ -40573,7 +40841,7 @@ function resolveInstalledServiceVersion(participation) {
|
|
|
40573
40841
|
default: return null;
|
|
40574
40842
|
}
|
|
40575
40843
|
}
|
|
40576
|
-
function normalizeOptionalString$
|
|
40844
|
+
function normalizeOptionalString$18(value) {
|
|
40577
40845
|
const normalized = String(value ?? "").trim();
|
|
40578
40846
|
return normalized.length > 0 ? normalized : null;
|
|
40579
40847
|
}
|
|
@@ -40615,14 +40883,14 @@ function emitDaemonDispatchJournalEvent(input) {
|
|
|
40615
40883
|
lane: resolveAtsEnvPreset(input.pathInput),
|
|
40616
40884
|
pid: process$1.pid,
|
|
40617
40885
|
sessionId: resolveCliContextId(),
|
|
40618
|
-
attemptId: normalizeOptionalString$
|
|
40886
|
+
attemptId: normalizeOptionalString$17(input.attemptId),
|
|
40619
40887
|
connectionGeneration: normalizeOptionalInteger(input.connectionGeneration),
|
|
40620
|
-
daemonSessionId: normalizeOptionalString$
|
|
40888
|
+
daemonSessionId: normalizeOptionalString$17(input.daemonSessionId),
|
|
40621
40889
|
dispatchId: input.dispatchId,
|
|
40622
40890
|
leaseEpoch: normalizeOptionalInteger(input.leaseEpoch),
|
|
40623
|
-
profileId: normalizeOptionalString$
|
|
40624
|
-
result: normalizeOptionalString$
|
|
40625
|
-
taskId: normalizeOptionalString$
|
|
40891
|
+
profileId: normalizeOptionalString$17(input.profileId),
|
|
40892
|
+
result: normalizeOptionalString$17(input.result),
|
|
40893
|
+
taskId: normalizeOptionalString$17(input.taskId),
|
|
40626
40894
|
...input.metadata ? { metadata: input.metadata } : {}
|
|
40627
40895
|
};
|
|
40628
40896
|
if (!isDaemonDispatchJournalEvent(event)) {
|
|
@@ -40638,7 +40906,7 @@ function emitDaemonDispatchJournalEvent(input) {
|
|
|
40638
40906
|
}
|
|
40639
40907
|
}
|
|
40640
40908
|
function readRecentDaemonDispatchJournalEvents(input) {
|
|
40641
|
-
const normalizedDispatchId = normalizeOptionalString$
|
|
40909
|
+
const normalizedDispatchId = normalizeOptionalString$17(input.dispatchId);
|
|
40642
40910
|
if (!normalizedDispatchId) return [];
|
|
40643
40911
|
const limit = Math.max(1, Math.min(100, input.limit ?? 20));
|
|
40644
40912
|
const journalPath = daemonDispatchJournalPath(input.pathInput);
|
|
@@ -40663,7 +40931,7 @@ function isDaemonDispatchJournalEvent(value) {
|
|
|
40663
40931
|
const candidate = value;
|
|
40664
40932
|
return candidate.schema === "ats-daemon-dispatch-event-v1" && candidate.v === 1 && DAEMON_DISPATCH_EVENT_TYPES.includes(candidate.type) && typeof candidate.timestamp === "string" && candidate.timestamp.length > 0 && typeof candidate.lane === "string" && candidate.lane.length > 0 && typeof candidate.pid === "number" && Number.isInteger(candidate.pid) && candidate.pid > 0 && (candidate.sessionId === null || typeof candidate.sessionId === "string" && candidate.sessionId.length > 0) && (candidate.attemptId === null || typeof candidate.attemptId === "string" && candidate.attemptId.length > 0) && (candidate.connectionGeneration === null || typeof candidate.connectionGeneration === "number" && Number.isInteger(candidate.connectionGeneration)) && (candidate.daemonSessionId === null || typeof candidate.daemonSessionId === "string" && candidate.daemonSessionId.length > 0) && typeof candidate.dispatchId === "string" && candidate.dispatchId.length > 0 && (candidate.leaseEpoch === null || typeof candidate.leaseEpoch === "number" && Number.isInteger(candidate.leaseEpoch)) && (candidate.profileId === null || typeof candidate.profileId === "string" && candidate.profileId.length > 0) && (candidate.result === null || typeof candidate.result === "string" && candidate.result.length > 0) && (candidate.taskId === null || typeof candidate.taskId === "string" && candidate.taskId.length > 0);
|
|
40665
40933
|
}
|
|
40666
|
-
function normalizeOptionalString$
|
|
40934
|
+
function normalizeOptionalString$17(value) {
|
|
40667
40935
|
const normalized = String(value ?? "").trim();
|
|
40668
40936
|
return normalized.length > 0 ? normalized : null;
|
|
40669
40937
|
}
|
|
@@ -41177,6 +41445,53 @@ function summarizeSubmissions(submissions) {
|
|
|
41177
41445
|
};
|
|
41178
41446
|
}
|
|
41179
41447
|
|
|
41448
|
+
//#endregion
|
|
41449
|
+
//#region src/local-service/carrier/daemon-stream-keepalive.ts
|
|
41450
|
+
function createDaemonStreamKeepalive(input) {
|
|
41451
|
+
const intervalMs = input.intervalMs ?? DAEMON_STREAM_KEEPALIVE_INTERVAL_MS;
|
|
41452
|
+
const pongTimeoutMs = input.pongTimeoutMs ?? DAEMON_STREAM_KEEPALIVE_PONG_TIMEOUT_MS;
|
|
41453
|
+
let pingTimer = null;
|
|
41454
|
+
let pongDeadlineTimer = null;
|
|
41455
|
+
const clearPongDeadline = () => {
|
|
41456
|
+
if (!pongDeadlineTimer) return;
|
|
41457
|
+
clearTimeout(pongDeadlineTimer);
|
|
41458
|
+
pongDeadlineTimer = null;
|
|
41459
|
+
};
|
|
41460
|
+
const stop = () => {
|
|
41461
|
+
if (pingTimer) {
|
|
41462
|
+
clearInterval(pingTimer);
|
|
41463
|
+
pingTimer = null;
|
|
41464
|
+
}
|
|
41465
|
+
clearPongDeadline();
|
|
41466
|
+
};
|
|
41467
|
+
const armPongDeadline = () => {
|
|
41468
|
+
clearPongDeadline();
|
|
41469
|
+
pongDeadlineTimer = setTimeout(() => {
|
|
41470
|
+
pongDeadlineTimer = null;
|
|
41471
|
+
stop();
|
|
41472
|
+
input.onPongTimeout();
|
|
41473
|
+
}, pongTimeoutMs);
|
|
41474
|
+
};
|
|
41475
|
+
return {
|
|
41476
|
+
observePong() {
|
|
41477
|
+
clearPongDeadline();
|
|
41478
|
+
},
|
|
41479
|
+
start() {
|
|
41480
|
+
stop();
|
|
41481
|
+
pingTimer = setInterval(() => {
|
|
41482
|
+
let sent = false;
|
|
41483
|
+
try {
|
|
41484
|
+
sent = input.sendPing();
|
|
41485
|
+
} catch {
|
|
41486
|
+
sent = false;
|
|
41487
|
+
}
|
|
41488
|
+
if (sent) armPongDeadline();
|
|
41489
|
+
}, intervalMs);
|
|
41490
|
+
},
|
|
41491
|
+
stop
|
|
41492
|
+
};
|
|
41493
|
+
}
|
|
41494
|
+
|
|
41180
41495
|
//#endregion
|
|
41181
41496
|
//#region src/provider-hosts/openclaw/bootstrap-lock.ts
|
|
41182
41497
|
const OPENCLAW_BOOTSTRAP_LOCK_KEY = "openclaw-bootstrap";
|
|
@@ -44016,11 +44331,6 @@ async function handleDispatchDeliverFrame(input) {
|
|
|
44016
44331
|
profileOwnerUserId: input.profileOwnerUserId,
|
|
44017
44332
|
parsedTask
|
|
44018
44333
|
});
|
|
44019
|
-
emitSendTargetReferenceLoadFailureIfNeeded({
|
|
44020
|
-
parsedTask,
|
|
44021
|
-
presenter: input.presenter,
|
|
44022
|
-
sendTargetReference: bootstrapContext.sendTargetReference
|
|
44023
|
-
});
|
|
44024
44334
|
let localRuntimeContextPlan = null;
|
|
44025
44335
|
let agentControllerConversationResumePlan = null;
|
|
44026
44336
|
let contextIdForDispatch = null;
|
|
@@ -44058,10 +44368,17 @@ async function handleDispatchDeliverFrame(input) {
|
|
|
44058
44368
|
targetProfileId: parsedTask.targetProfileId
|
|
44059
44369
|
});
|
|
44060
44370
|
effectiveRuntimeContext = runtimePreparation.effectiveRuntimeContext;
|
|
44371
|
+
const sendTargetReference = await bootstrapContext.sendTargetReferencePromise;
|
|
44372
|
+
emitSendTargetReferenceLoadFailureIfNeeded({
|
|
44373
|
+
parsedTask,
|
|
44374
|
+
presenter: input.presenter,
|
|
44375
|
+
sendTargetReference
|
|
44376
|
+
});
|
|
44061
44377
|
const spaceActionRuntimeContext = createDispatchSpaceActionRuntimeContext({
|
|
44062
44378
|
bootstrapContext,
|
|
44063
44379
|
parsedTask,
|
|
44064
|
-
runtimePreparation
|
|
44380
|
+
runtimePreparation,
|
|
44381
|
+
sendTargetReference
|
|
44065
44382
|
});
|
|
44066
44383
|
dispatchSpaceActionContext = spaceActionRuntimeContext.dispatchSpaceActionContext;
|
|
44067
44384
|
runtimeEnvOverrides = spaceActionRuntimeContext.runtimeEnvOverrides;
|
|
@@ -44147,6 +44464,7 @@ async function handleDispatchDeliverFrame(input) {
|
|
|
44147
44464
|
parsedTask,
|
|
44148
44465
|
profileOwnerName: input.profileOwnerName,
|
|
44149
44466
|
profileOwnerUserId: input.profileOwnerUserId,
|
|
44467
|
+
sendTargetReference,
|
|
44150
44468
|
shouldInjectBootstrap: bootstrapPlan.shouldInject
|
|
44151
44469
|
});
|
|
44152
44470
|
emitRunLine({
|
|
@@ -44412,7 +44730,7 @@ async function handleDispatchDeliverFrame(input) {
|
|
|
44412
44730
|
cliEntry: bootstrapContext.cliEntry,
|
|
44413
44731
|
dispatchSpaceActionContext,
|
|
44414
44732
|
runtimeResult,
|
|
44415
|
-
sendTargetReference
|
|
44733
|
+
sendTargetReference,
|
|
44416
44734
|
runtimeContext: activeRuntimeContext,
|
|
44417
44735
|
runtimeEnvOverrides,
|
|
44418
44736
|
runtimeControllerSupport,
|
|
@@ -44809,17 +45127,19 @@ async function resolveDispatchBootstrapContext(input) {
|
|
|
44809
45127
|
targetProfileNamePresent: targetProfileContext.targetProfileName !== null,
|
|
44810
45128
|
targetProfileRolePresent: targetProfileContext.targetProfileRole !== null
|
|
44811
45129
|
});
|
|
44812
|
-
const
|
|
45130
|
+
const sendTargetReferencePromise = resolveDispatchSendTargetReference({
|
|
44813
45131
|
agentControllerRef: input.parsedTask.agentControllerRef,
|
|
44814
45132
|
dispatchTask: input.parsedTask,
|
|
44815
45133
|
profileOwnerName: input.profileOwnerName,
|
|
44816
45134
|
profileOwnerUserId: input.profileOwnerUserId,
|
|
44817
45135
|
targetProfileName: targetProfileContext.targetProfileName
|
|
44818
|
-
})
|
|
44819
|
-
|
|
44820
|
-
|
|
44821
|
-
|
|
44822
|
-
|
|
45136
|
+
}).then((sendTargetReference) => {
|
|
45137
|
+
input.onPhase?.("send_target_reference_ready", {
|
|
45138
|
+
sendTargetReferenceCount: sendTargetReference.status === "loaded" ? sendTargetReference.projection.length : null,
|
|
45139
|
+
sendTargetReferenceStatus: sendTargetReference.status,
|
|
45140
|
+
source: "dispatch_send_target_reference"
|
|
45141
|
+
});
|
|
45142
|
+
return sendTargetReference;
|
|
44823
45143
|
});
|
|
44824
45144
|
const cliEntry = resolveDispatchOwnedRuntimeActionCliEntryCommand();
|
|
44825
45145
|
const serviceFreshnessWarningLines = await resolveDispatchServiceFreshnessWarningLines({ cliEntry });
|
|
@@ -44840,7 +45160,7 @@ async function resolveDispatchBootstrapContext(input) {
|
|
|
44840
45160
|
cliEntry,
|
|
44841
45161
|
mentionSourceMentionLabel: mentionSourceContext.mentionSourceMentionLabel ?? null,
|
|
44842
45162
|
mentionSourceProfileName: mentionSourceContext.mentionSourceProfileName,
|
|
44843
|
-
|
|
45163
|
+
sendTargetReferencePromise,
|
|
44844
45164
|
serviceFreshnessWarningLines,
|
|
44845
45165
|
spaceOwnerProfileId,
|
|
44846
45166
|
targetProfileMentionLabel: targetProfileContext.targetProfileMentionLabel,
|
|
@@ -44868,7 +45188,7 @@ function buildDispatchRuntimePrompt(input) {
|
|
|
44868
45188
|
prompt: input.parsedTask.prompt,
|
|
44869
45189
|
recipientExplicitlyAddressedByActivationTargets: input.parsedTask.recipientExplicitlyAddressedByActivationTargets,
|
|
44870
45190
|
sourceMessageEnvelope: input.parsedTask.sourceMessageEnvelope,
|
|
44871
|
-
sendTargetReferenceLines: input.
|
|
45191
|
+
sendTargetReferenceLines: input.sendTargetReference.referenceLines,
|
|
44872
45192
|
serviceFreshnessWarningLines: input.bootstrapContext.serviceFreshnessWarningLines,
|
|
44873
45193
|
spaceId: input.parsedTask.spaceId,
|
|
44874
45194
|
spaceOwnerProfileId: input.bootstrapContext.spaceOwnerProfileId,
|
|
@@ -44897,7 +45217,7 @@ function createDispatchSpaceActionRuntimeContext(input) {
|
|
|
44897
45217
|
dispatchId: input.parsedTask.dispatchId,
|
|
44898
45218
|
env: process.env,
|
|
44899
45219
|
replyToSignalId: input.parsedTask.replyToSnapshot?.signalId ?? null,
|
|
44900
|
-
sendTargetReference: input.
|
|
45220
|
+
sendTargetReference: input.sendTargetReference,
|
|
44901
45221
|
sourceEventId: input.parsedTask.sourceEventId,
|
|
44902
45222
|
spaceContractSnapshot: input.parsedTask.spaceContractSnapshot,
|
|
44903
45223
|
spaceId: input.parsedTask.spaceId,
|
|
@@ -46838,7 +47158,25 @@ async function runDaemonSocketSession(input) {
|
|
|
46838
47158
|
let routeCatalogSyncInFlight = false;
|
|
46839
47159
|
let heartbeatTimer = null;
|
|
46840
47160
|
let heartbeatTimerDueAtMs = null;
|
|
46841
|
-
|
|
47161
|
+
const keepalive = createDaemonStreamKeepalive({
|
|
47162
|
+
onPongTimeout: () => {
|
|
47163
|
+
emitRunLine({
|
|
47164
|
+
presenter: input.presenter,
|
|
47165
|
+
code: "daemon.run.keepalive_pong_timeout",
|
|
47166
|
+
text: "daemon stream keepalive PONG missing; terminating half-open socket for reconnect",
|
|
47167
|
+
payload: {
|
|
47168
|
+
connectionGeneration: activeConnectionGeneration,
|
|
47169
|
+
daemonSessionId: input.daemonSessionId
|
|
47170
|
+
}
|
|
47171
|
+
});
|
|
47172
|
+
input.socket.terminate();
|
|
47173
|
+
},
|
|
47174
|
+
sendPing: () => {
|
|
47175
|
+
if (closed) return false;
|
|
47176
|
+
input.socket.send(DAEMON_STREAM_KEEPALIVE_PING);
|
|
47177
|
+
return true;
|
|
47178
|
+
}
|
|
47179
|
+
});
|
|
46842
47180
|
let lastDispatchActivityAtMs = null;
|
|
46843
47181
|
let lastHeartbeatSentAtMs = null;
|
|
46844
47182
|
let consecutiveHeartbeatFailures = 0;
|
|
@@ -47007,20 +47345,6 @@ async function runDaemonSocketSession(input) {
|
|
|
47007
47345
|
heartbeatTimer = null;
|
|
47008
47346
|
heartbeatTimerDueAtMs = null;
|
|
47009
47347
|
};
|
|
47010
|
-
const clearKeepalivePingTimer = () => {
|
|
47011
|
-
if (!keepalivePingTimer) return;
|
|
47012
|
-
clearInterval(keepalivePingTimer);
|
|
47013
|
-
keepalivePingTimer = null;
|
|
47014
|
-
};
|
|
47015
|
-
const startKeepalivePing = () => {
|
|
47016
|
-
clearKeepalivePingTimer();
|
|
47017
|
-
keepalivePingTimer = setInterval(() => {
|
|
47018
|
-
if (closed) return;
|
|
47019
|
-
try {
|
|
47020
|
-
input.socket.send(DAEMON_STREAM_KEEPALIVE_PING);
|
|
47021
|
-
} catch {}
|
|
47022
|
-
}, DAEMON_STREAM_KEEPALIVE_INTERVAL_MS);
|
|
47023
|
-
};
|
|
47024
47348
|
const resolvePendingRouteCatalogSyncRequests = (result) => {
|
|
47025
47349
|
const pending = pendingRouteCatalogSyncRequests.splice(0, pendingRouteCatalogSyncRequests.length);
|
|
47026
47350
|
for (const request of pending) request.resolve(result);
|
|
@@ -47746,7 +48070,10 @@ async function runDaemonSocketSession(input) {
|
|
|
47746
48070
|
});
|
|
47747
48071
|
});
|
|
47748
48072
|
input.socket.onMessage((raw) => {
|
|
47749
|
-
if (raw === DAEMON_STREAM_KEEPALIVE_PONG)
|
|
48073
|
+
if (raw === DAEMON_STREAM_KEEPALIVE_PONG) {
|
|
48074
|
+
keepalive.observePong();
|
|
48075
|
+
return;
|
|
48076
|
+
}
|
|
47750
48077
|
const parsedFrame = parseDaemonFrame(raw);
|
|
47751
48078
|
if (!parsedFrame) {
|
|
47752
48079
|
emitRunLine({
|
|
@@ -47879,7 +48206,7 @@ async function runDaemonSocketSession(input) {
|
|
|
47879
48206
|
latestCatalogSyncSignalUpdatedAtMs = (await readDaemonCatalogSyncSignal().catch(() => null))?.updatedAtMs ?? 0;
|
|
47880
48207
|
scheduleCatalogSyncSignalPoll();
|
|
47881
48208
|
await sendHeartbeat();
|
|
47882
|
-
|
|
48209
|
+
keepalive.start();
|
|
47883
48210
|
await waitForClose;
|
|
47884
48211
|
if (currentSocketRef.socket === input.socket) {
|
|
47885
48212
|
currentSocketRef.socket = null;
|
|
@@ -47887,7 +48214,7 @@ async function runDaemonSocketSession(input) {
|
|
|
47887
48214
|
}
|
|
47888
48215
|
input.attachRouteCatalogSyncInvoker?.(null);
|
|
47889
48216
|
clearHeartbeatTimer();
|
|
47890
|
-
|
|
48217
|
+
keepalive.stop();
|
|
47891
48218
|
clearCatalogSyncSignalTimer();
|
|
47892
48219
|
if (closeCode === 1e3 && closeReason === "shutdown") await localExecutionSlots.drain();
|
|
47893
48220
|
else {
|
|
@@ -48020,6 +48347,39 @@ function resolveLocalAgentEnabledErrorCode$1(error) {
|
|
|
48020
48347
|
return normalized?.includes(".") ? normalized : "agents.unexpected_error";
|
|
48021
48348
|
}
|
|
48022
48349
|
|
|
48350
|
+
//#endregion
|
|
48351
|
+
//#region src/local-service/carrier/stop-aware-delay.ts
|
|
48352
|
+
function createStopAwareDelay() {
|
|
48353
|
+
let interrupted = false;
|
|
48354
|
+
const pendingInterruptNotifiers = /* @__PURE__ */ new Set();
|
|
48355
|
+
return {
|
|
48356
|
+
interrupt: () => {
|
|
48357
|
+
if (interrupted) return;
|
|
48358
|
+
interrupted = true;
|
|
48359
|
+
for (const notifyInterrupted of pendingInterruptNotifiers) notifyInterrupted();
|
|
48360
|
+
pendingInterruptNotifiers.clear();
|
|
48361
|
+
},
|
|
48362
|
+
wait: (delayMs) => {
|
|
48363
|
+
if (interrupted) return Promise.resolve("interrupted");
|
|
48364
|
+
return new Promise((resolve) => {
|
|
48365
|
+
let timer = null;
|
|
48366
|
+
const notifyInterrupted = () => {
|
|
48367
|
+
if (timer) {
|
|
48368
|
+
clearTimeout(timer);
|
|
48369
|
+
timer = null;
|
|
48370
|
+
}
|
|
48371
|
+
resolve("interrupted");
|
|
48372
|
+
};
|
|
48373
|
+
pendingInterruptNotifiers.add(notifyInterrupted);
|
|
48374
|
+
timer = setTimeout(() => {
|
|
48375
|
+
pendingInterruptNotifiers.delete(notifyInterrupted);
|
|
48376
|
+
resolve("elapsed");
|
|
48377
|
+
}, delayMs);
|
|
48378
|
+
});
|
|
48379
|
+
}
|
|
48380
|
+
};
|
|
48381
|
+
}
|
|
48382
|
+
|
|
48023
48383
|
//#endregion
|
|
48024
48384
|
//#region src/local-service/carrier/service-runner.ts
|
|
48025
48385
|
var DaemonStreamAuthenticationRequiredError = class extends Error {
|
|
@@ -48208,6 +48568,7 @@ const runDaemonServiceLoop = async (input) => {
|
|
|
48208
48568
|
})
|
|
48209
48569
|
});
|
|
48210
48570
|
let stopRequested = false;
|
|
48571
|
+
const reconnectBackoffDelay = createStopAwareDelay();
|
|
48211
48572
|
let reconnectAttempt = 0;
|
|
48212
48573
|
let activeSocket = null;
|
|
48213
48574
|
const currentSocketRef = {
|
|
@@ -48271,6 +48632,7 @@ const runDaemonServiceLoop = async (input) => {
|
|
|
48271
48632
|
if (stopRequested) return;
|
|
48272
48633
|
stopRequested = true;
|
|
48273
48634
|
connectionState.set("stopping");
|
|
48635
|
+
reconnectBackoffDelay.interrupt();
|
|
48274
48636
|
activeSocket?.close(1e3, "shutdown");
|
|
48275
48637
|
};
|
|
48276
48638
|
const onSigint = () => {
|
|
@@ -48323,6 +48685,10 @@ const runDaemonServiceLoop = async (input) => {
|
|
|
48323
48685
|
headers: authContext.headers,
|
|
48324
48686
|
openTimeoutMs: DAEMON_STREAM_CONNECT_TIMEOUT_MS
|
|
48325
48687
|
});
|
|
48688
|
+
if (stopRequested) {
|
|
48689
|
+
ws.close(1e3, "shutdown");
|
|
48690
|
+
break;
|
|
48691
|
+
}
|
|
48326
48692
|
activeSocket = ws;
|
|
48327
48693
|
emitRunLine({
|
|
48328
48694
|
presenter: input.presenter,
|
|
@@ -48381,59 +48747,14 @@ const runDaemonServiceLoop = async (input) => {
|
|
|
48381
48747
|
requestActiveRouteCatalogSync = null;
|
|
48382
48748
|
if (stopRequested) break;
|
|
48383
48749
|
reconnectAttempt += 1;
|
|
48384
|
-
const
|
|
48385
|
-
const failureReason = classifyConnectionFailureReason(errorMessage);
|
|
48386
|
-
const authState = error instanceof DaemonStreamAuthenticationRequiredError ? error.authState : null;
|
|
48387
|
-
const backoffMs = resolveServiceConnectionReconnectBackoffMs({
|
|
48388
|
-
attempt: reconnectAttempt,
|
|
48389
|
-
reason: failureReason
|
|
48390
|
-
});
|
|
48391
|
-
noteReconnectFailureState({
|
|
48392
|
-
authState,
|
|
48750
|
+
const backoffMs = noteRunLoopReconnectScheduled({
|
|
48393
48751
|
connectionState,
|
|
48394
|
-
|
|
48395
|
-
|
|
48396
|
-
reconnectAttempt
|
|
48397
|
-
});
|
|
48398
|
-
const reconcileDecision = resolveRouteRegistrationReconcileDecision({
|
|
48399
|
-
driftDetected: true,
|
|
48400
|
-
foregroundActive: mode === "foreground"
|
|
48401
|
-
});
|
|
48402
|
-
emitDriftDetectedEvidence({
|
|
48403
|
-
action: reconcileDecision.action,
|
|
48404
|
-
backoffMs,
|
|
48405
|
-
driftClass: reconcileDecision.driftClass,
|
|
48406
|
-
error: errorMessage,
|
|
48407
|
-
foregroundActive: reconcileDecision.foregroundActive,
|
|
48408
|
-
lifecycleLocked: reconcileDecision.lifecycleLocked,
|
|
48409
|
-
owner: reconcileDecision.owner,
|
|
48410
|
-
reconnectAttempt,
|
|
48411
|
-
skipReason: reconcileDecision.skipReason
|
|
48412
|
-
});
|
|
48413
|
-
emitReconcileStartedEvidence({
|
|
48414
|
-
action: reconcileDecision.action,
|
|
48415
|
-
backoffMs,
|
|
48416
|
-
driftClass: reconcileDecision.driftClass,
|
|
48417
|
-
error: errorMessage,
|
|
48418
|
-
foregroundActive: reconcileDecision.foregroundActive,
|
|
48419
|
-
lifecycleLocked: reconcileDecision.lifecycleLocked,
|
|
48420
|
-
owner: reconcileDecision.owner,
|
|
48421
|
-
reconnectAttempt,
|
|
48422
|
-
skipReason: reconcileDecision.skipReason
|
|
48423
|
-
});
|
|
48424
|
-
emitRunLine({
|
|
48752
|
+
error,
|
|
48753
|
+
foregroundActive: mode === "foreground",
|
|
48425
48754
|
presenter: input.presenter,
|
|
48426
|
-
|
|
48427
|
-
text: `daemon stream reconnect scheduled in ${String(backoffMs)}ms (${errorMessage})`,
|
|
48428
|
-
payload: {
|
|
48429
|
-
attempt: reconnectAttempt,
|
|
48430
|
-
authState,
|
|
48431
|
-
backoffMs,
|
|
48432
|
-
error: errorMessage,
|
|
48433
|
-
reason: failureReason
|
|
48434
|
-
}
|
|
48755
|
+
reconnectAttempt
|
|
48435
48756
|
});
|
|
48436
|
-
await
|
|
48757
|
+
await reconnectBackoffDelay.wait(backoffMs);
|
|
48437
48758
|
}
|
|
48438
48759
|
} finally {
|
|
48439
48760
|
process.off("SIGINT", onSigint);
|
|
@@ -48744,6 +49065,61 @@ function createRunLoopConnectionStateTracker(presenter) {
|
|
|
48744
49065
|
}).catch(() => void 0);
|
|
48745
49066
|
} });
|
|
48746
49067
|
}
|
|
49068
|
+
function noteRunLoopReconnectScheduled(input) {
|
|
49069
|
+
const errorMessage = toErrorMessage$30(input.error);
|
|
49070
|
+
const failureReason = classifyConnectionFailureReason(errorMessage);
|
|
49071
|
+
const authState = input.error instanceof DaemonStreamAuthenticationRequiredError ? input.error.authState : null;
|
|
49072
|
+
const backoffMs = resolveServiceConnectionReconnectBackoffMs({
|
|
49073
|
+
attempt: input.reconnectAttempt,
|
|
49074
|
+
reason: failureReason
|
|
49075
|
+
});
|
|
49076
|
+
noteReconnectFailureState({
|
|
49077
|
+
authState,
|
|
49078
|
+
connectionState: input.connectionState,
|
|
49079
|
+
errorMessage,
|
|
49080
|
+
failureReason,
|
|
49081
|
+
reconnectAttempt: input.reconnectAttempt
|
|
49082
|
+
});
|
|
49083
|
+
const reconcileDecision = resolveRouteRegistrationReconcileDecision({
|
|
49084
|
+
driftDetected: true,
|
|
49085
|
+
foregroundActive: input.foregroundActive
|
|
49086
|
+
});
|
|
49087
|
+
emitDriftDetectedEvidence({
|
|
49088
|
+
action: reconcileDecision.action,
|
|
49089
|
+
backoffMs,
|
|
49090
|
+
driftClass: reconcileDecision.driftClass,
|
|
49091
|
+
error: errorMessage,
|
|
49092
|
+
foregroundActive: reconcileDecision.foregroundActive,
|
|
49093
|
+
lifecycleLocked: reconcileDecision.lifecycleLocked,
|
|
49094
|
+
owner: reconcileDecision.owner,
|
|
49095
|
+
reconnectAttempt: input.reconnectAttempt,
|
|
49096
|
+
skipReason: reconcileDecision.skipReason
|
|
49097
|
+
});
|
|
49098
|
+
emitReconcileStartedEvidence({
|
|
49099
|
+
action: reconcileDecision.action,
|
|
49100
|
+
backoffMs,
|
|
49101
|
+
driftClass: reconcileDecision.driftClass,
|
|
49102
|
+
error: errorMessage,
|
|
49103
|
+
foregroundActive: reconcileDecision.foregroundActive,
|
|
49104
|
+
lifecycleLocked: reconcileDecision.lifecycleLocked,
|
|
49105
|
+
owner: reconcileDecision.owner,
|
|
49106
|
+
reconnectAttempt: input.reconnectAttempt,
|
|
49107
|
+
skipReason: reconcileDecision.skipReason
|
|
49108
|
+
});
|
|
49109
|
+
emitRunLine({
|
|
49110
|
+
presenter: input.presenter,
|
|
49111
|
+
code: "daemon.run.reconnect",
|
|
49112
|
+
text: `daemon stream reconnect scheduled in ${String(backoffMs)}ms (${errorMessage})`,
|
|
49113
|
+
payload: {
|
|
49114
|
+
attempt: input.reconnectAttempt,
|
|
49115
|
+
authState,
|
|
49116
|
+
backoffMs,
|
|
49117
|
+
error: errorMessage,
|
|
49118
|
+
reason: failureReason
|
|
49119
|
+
}
|
|
49120
|
+
});
|
|
49121
|
+
return backoffMs;
|
|
49122
|
+
}
|
|
48747
49123
|
function noteReconnectFailureState(input) {
|
|
48748
49124
|
if (input.failureReason === "auth_rejected") {
|
|
48749
49125
|
input.connectionState.set("authentication_required", {
|
|
@@ -49534,7 +49910,7 @@ async function resolveLocalServiceDemand(input) {
|
|
|
49534
49910
|
expectedRoutesRead: input.expectedRoutesRead,
|
|
49535
49911
|
mode: "check"
|
|
49536
49912
|
}).catch(() => null) : input.projection;
|
|
49537
|
-
const ownerUserId = normalizeOptionalString$
|
|
49913
|
+
const ownerUserId = normalizeOptionalString$16(input.ownerUserId);
|
|
49538
49914
|
if (!ownerUserId) return {
|
|
49539
49915
|
decision: "indeterminate",
|
|
49540
49916
|
hasLocalExecutionRoute: false,
|
|
@@ -49710,7 +50086,7 @@ function formatLocalServiceAutoStoppedMessage(localDemand) {
|
|
|
49710
50086
|
if (localDemand.projection?.status === "ok" && localDemand.projection.projectedControllerIds.length === 0) return "ATS stopped the background service because this device currently has no projected local agent controllers.";
|
|
49711
50087
|
return "ATS stopped the background service because this device currently has no local execution routes.";
|
|
49712
50088
|
}
|
|
49713
|
-
function normalizeOptionalString$
|
|
50089
|
+
function normalizeOptionalString$16(value) {
|
|
49714
50090
|
const normalized = String(value ?? "").trim();
|
|
49715
50091
|
return normalized.length > 0 ? normalized : null;
|
|
49716
50092
|
}
|
|
@@ -52242,6 +52618,150 @@ async function cleanupStaleDaemonRuntimeDataBackups(input = {}) {
|
|
|
52242
52618
|
}
|
|
52243
52619
|
}
|
|
52244
52620
|
|
|
52621
|
+
//#endregion
|
|
52622
|
+
//#region src/local-service/lifecycle/daemon-service-stalled-force-kill.ts
|
|
52623
|
+
const FORCE_KILL_MIN_HEARTBEAT_STALL_MS = 600 * 1e3;
|
|
52624
|
+
const FORCE_KILL_EXIT_WAIT_MS = 2e3;
|
|
52625
|
+
const FORCE_KILL_EXIT_POLL_MS = 100;
|
|
52626
|
+
function resolveStalledDaemonForceKillVerdict(input) {
|
|
52627
|
+
const lease = input.runtimeLease;
|
|
52628
|
+
if (!lease) return {
|
|
52629
|
+
decision: "skip",
|
|
52630
|
+
reason: "runtime_lease_missing",
|
|
52631
|
+
pid: null,
|
|
52632
|
+
heartbeatStalledMs: null
|
|
52633
|
+
};
|
|
52634
|
+
if (!Number.isInteger(lease.pid) || lease.pid <= 0) return {
|
|
52635
|
+
decision: "skip",
|
|
52636
|
+
reason: "lease_pid_invalid",
|
|
52637
|
+
pid: null,
|
|
52638
|
+
heartbeatStalledMs: null
|
|
52639
|
+
};
|
|
52640
|
+
const ownedProcess = input.ownedProcesses.find((candidate) => candidate.pid === lease.pid && candidate.ownership !== "unknown");
|
|
52641
|
+
if (!ownedProcess) return {
|
|
52642
|
+
decision: "skip",
|
|
52643
|
+
reason: "lease_pid_not_owned",
|
|
52644
|
+
pid: lease.pid,
|
|
52645
|
+
heartbeatStalledMs: null
|
|
52646
|
+
};
|
|
52647
|
+
if (ownedProcess.mode === "foreground") return {
|
|
52648
|
+
decision: "skip",
|
|
52649
|
+
reason: "foreground_process",
|
|
52650
|
+
pid: lease.pid,
|
|
52651
|
+
heartbeatStalledMs: null
|
|
52652
|
+
};
|
|
52653
|
+
const freshnessTimestamp = lease.heartbeatAt ?? lease.updatedAt;
|
|
52654
|
+
const heartbeatMs = Date.parse(freshnessTimestamp);
|
|
52655
|
+
if (Number.isNaN(heartbeatMs)) return {
|
|
52656
|
+
decision: "skip",
|
|
52657
|
+
reason: "heartbeat_unparseable",
|
|
52658
|
+
pid: lease.pid,
|
|
52659
|
+
heartbeatStalledMs: null
|
|
52660
|
+
};
|
|
52661
|
+
const heartbeatStalledMs = input.nowMs - heartbeatMs;
|
|
52662
|
+
if (heartbeatStalledMs < FORCE_KILL_MIN_HEARTBEAT_STALL_MS) return {
|
|
52663
|
+
decision: "skip",
|
|
52664
|
+
reason: "heartbeat_fresh",
|
|
52665
|
+
pid: lease.pid,
|
|
52666
|
+
heartbeatStalledMs
|
|
52667
|
+
};
|
|
52668
|
+
return {
|
|
52669
|
+
decision: "force_kill",
|
|
52670
|
+
pid: lease.pid,
|
|
52671
|
+
heartbeatStalledMs
|
|
52672
|
+
};
|
|
52673
|
+
}
|
|
52674
|
+
const defaultStalledDaemonForceKillDeps = {
|
|
52675
|
+
emitLifecycleEvent: emitDaemonLifecycleEvent,
|
|
52676
|
+
killProcess: (pid, signal) => process$1.kill(pid, signal),
|
|
52677
|
+
listOwnedProcesses: async () => await listDaemonOwnedProcesses({ ignoreProcessIds: [process$1.pid, process$1.ppid].filter((pid) => Number.isInteger(pid) && pid > 0) }),
|
|
52678
|
+
nowMs: () => Date.now(),
|
|
52679
|
+
readRuntimeLease: async () => await readDaemonRuntimeLease(),
|
|
52680
|
+
waitForProcessExit: async (pid) => {
|
|
52681
|
+
const deadline = Date.now() + FORCE_KILL_EXIT_WAIT_MS;
|
|
52682
|
+
while (Date.now() < deadline) {
|
|
52683
|
+
if (!isPidAlive$3(pid)) return true;
|
|
52684
|
+
await sleep(FORCE_KILL_EXIT_POLL_MS);
|
|
52685
|
+
}
|
|
52686
|
+
return !isPidAlive$3(pid);
|
|
52687
|
+
}
|
|
52688
|
+
};
|
|
52689
|
+
async function forceKillStalledDaemonAfterStopTimeout(input, deps = defaultStalledDaemonForceKillDeps) {
|
|
52690
|
+
const [runtimeLease, ownedProcesses] = await Promise.all([deps.readRuntimeLease().catch(() => null), deps.listOwnedProcesses().catch(() => [])]);
|
|
52691
|
+
const verdict = resolveStalledDaemonForceKillVerdict({
|
|
52692
|
+
nowMs: deps.nowMs(),
|
|
52693
|
+
ownedProcesses,
|
|
52694
|
+
runtimeLease
|
|
52695
|
+
});
|
|
52696
|
+
if (verdict.decision === "skip") {
|
|
52697
|
+
await deps.emitLifecycleEvent({
|
|
52698
|
+
type: "process_stop.action",
|
|
52699
|
+
result: "force_kill_skipped",
|
|
52700
|
+
metadata: {
|
|
52701
|
+
heartbeatStalledMs: verdict.heartbeatStalledMs,
|
|
52702
|
+
pid: verdict.pid,
|
|
52703
|
+
reason: verdict.reason,
|
|
52704
|
+
signal: "SIGKILL",
|
|
52705
|
+
stage: input.stage
|
|
52706
|
+
}
|
|
52707
|
+
});
|
|
52708
|
+
return {
|
|
52709
|
+
killed: false,
|
|
52710
|
+
verdict
|
|
52711
|
+
};
|
|
52712
|
+
}
|
|
52713
|
+
try {
|
|
52714
|
+
deps.killProcess(verdict.pid, "SIGKILL");
|
|
52715
|
+
} catch (error) {
|
|
52716
|
+
if (!isProcessGoneError(error)) {
|
|
52717
|
+
await deps.emitLifecycleEvent({
|
|
52718
|
+
type: "process_stop.action",
|
|
52719
|
+
result: "force_kill_failed",
|
|
52720
|
+
metadata: {
|
|
52721
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
52722
|
+
heartbeatStalledMs: verdict.heartbeatStalledMs,
|
|
52723
|
+
pid: verdict.pid,
|
|
52724
|
+
reason: "stalled_heartbeat_after_stop_timeout",
|
|
52725
|
+
signal: "SIGKILL",
|
|
52726
|
+
stage: input.stage
|
|
52727
|
+
}
|
|
52728
|
+
});
|
|
52729
|
+
return {
|
|
52730
|
+
killed: false,
|
|
52731
|
+
verdict
|
|
52732
|
+
};
|
|
52733
|
+
}
|
|
52734
|
+
}
|
|
52735
|
+
const exited = await deps.waitForProcessExit(verdict.pid);
|
|
52736
|
+
await deps.emitLifecycleEvent({
|
|
52737
|
+
type: "process_stop.action",
|
|
52738
|
+
result: "force_killed",
|
|
52739
|
+
metadata: {
|
|
52740
|
+
exitObserved: exited,
|
|
52741
|
+
heartbeatStalledMs: verdict.heartbeatStalledMs,
|
|
52742
|
+
pid: verdict.pid,
|
|
52743
|
+
reason: "stalled_heartbeat_after_stop_timeout",
|
|
52744
|
+
signal: "SIGKILL",
|
|
52745
|
+
stage: input.stage
|
|
52746
|
+
}
|
|
52747
|
+
});
|
|
52748
|
+
return {
|
|
52749
|
+
killed: true,
|
|
52750
|
+
verdict
|
|
52751
|
+
};
|
|
52752
|
+
}
|
|
52753
|
+
function isProcessGoneError(error) {
|
|
52754
|
+
return error instanceof Error && error.code === "ESRCH";
|
|
52755
|
+
}
|
|
52756
|
+
function isPidAlive$3(pid) {
|
|
52757
|
+
try {
|
|
52758
|
+
process$1.kill(pid, 0);
|
|
52759
|
+
return true;
|
|
52760
|
+
} catch (error) {
|
|
52761
|
+
return !(error instanceof Error && error.code === "ESRCH");
|
|
52762
|
+
}
|
|
52763
|
+
}
|
|
52764
|
+
|
|
52245
52765
|
//#endregion
|
|
52246
52766
|
//#region src/local-service/lifecycle/daemon-service-lifecycle.ts
|
|
52247
52767
|
const STRICT_TEARDOWN_VERIFY_WAIT_MS$1 = 15e3;
|
|
@@ -52501,7 +53021,15 @@ async function executeDaemonServiceLifecycle(input) {
|
|
|
52501
53021
|
});
|
|
52502
53022
|
input.state.failureStage = "wait_running";
|
|
52503
53023
|
await input.emitPhase("wait_running");
|
|
52504
|
-
await
|
|
53024
|
+
await runDaemonServiceManagerAction({
|
|
53025
|
+
action: "wait_running",
|
|
53026
|
+
controller: input.context.serviceManager.controller,
|
|
53027
|
+
intent: toLifecycleIntent(input.operation),
|
|
53028
|
+
resolveErrorMetadata: (error) => isDaemonServiceWaitTimeoutError(error) && error.jobDiagnostics ? { jobDiagnostics: error.jobDiagnostics } : null,
|
|
53029
|
+
run: async () => {
|
|
53030
|
+
await input.context.serviceManager.waitUntilRunning();
|
|
53031
|
+
}
|
|
53032
|
+
});
|
|
52505
53033
|
}
|
|
52506
53034
|
input.state.failureStage = "verify_final_inventory";
|
|
52507
53035
|
await input.emitPhase("verify_final_inventory");
|
|
@@ -52790,8 +53318,11 @@ async function stopLifecycleRuntime(input) {
|
|
|
52790
53318
|
stage: "stop_or_drain"
|
|
52791
53319
|
});
|
|
52792
53320
|
if (await stopDaemonProcessWithTimeout(runtimeStatus.pid, "SIGTERM", input.drainWaitMs)) return;
|
|
52793
|
-
if (
|
|
52794
|
-
|
|
53321
|
+
if (input.forceKillAfterDrainTimeout) {
|
|
53322
|
+
await stopDaemonProcess$1(runtimeStatus.pid, "SIGKILL");
|
|
53323
|
+
return;
|
|
53324
|
+
}
|
|
53325
|
+
if (!(await forceKillStalledDaemonAfterStopTimeout({ stage: "stop_or_drain" })).killed) throw new DaemonServiceLifecycleDrainTimeoutError(input.drainWaitMs);
|
|
52795
53326
|
}
|
|
52796
53327
|
async function ensureLifecycleRuntimeStopped() {
|
|
52797
53328
|
const runtimeAfterStop = await readCurrentObservedDaemonRuntimeStatus();
|
|
@@ -52806,11 +53337,15 @@ async function ensureLifecycleRuntimeStopped() {
|
|
|
52806
53337
|
}
|
|
52807
53338
|
async function waitForLifecycleRuntimeStopped(input) {
|
|
52808
53339
|
if (input.inventory.runtimeStatus.managedBySystemService || input.inventory.serviceManagerStatus?.installed === true || input.inventory.serviceManagerStatus?.running === true) {
|
|
52809
|
-
if (!await waitForDaemonSystemServiceToStop({
|
|
53340
|
+
if (!(await waitForDaemonSystemServiceToStop({
|
|
52810
53341
|
manager: input.serviceManager,
|
|
52811
53342
|
waitMs: STRICT_TEARDOWN_VERIFY_WAIT_MS$1,
|
|
52812
53343
|
pollMs: STRICT_TEARDOWN_VERIFY_POLL_MS$1
|
|
52813
|
-
})) {
|
|
53344
|
+
}) || (await forceKillStalledDaemonAfterStopTimeout({ stage: "wait_stopped" })).killed && await waitForDaemonSystemServiceToStop({
|
|
53345
|
+
manager: input.serviceManager,
|
|
53346
|
+
waitMs: STRICT_TEARDOWN_VERIFY_WAIT_MS$1,
|
|
53347
|
+
pollMs: STRICT_TEARDOWN_VERIFY_POLL_MS$1
|
|
53348
|
+
}))) {
|
|
52814
53349
|
const runtimeAfterWait = await readCurrentObservedDaemonRuntimeStatus();
|
|
52815
53350
|
throw new DaemonServiceLifecycleStageError({
|
|
52816
53351
|
message: `ATS service is still running after stop phase (pid=${String(runtimeAfterWait.pid)}).`,
|
|
@@ -52831,7 +53366,7 @@ async function ensureNoOwnedProcessesRemain() {
|
|
|
52831
53366
|
return;
|
|
52832
53367
|
}
|
|
52833
53368
|
}
|
|
52834
|
-
await sleep
|
|
53369
|
+
await sleep(STRICT_TEARDOWN_VERIFY_POLL_MS$1);
|
|
52835
53370
|
}
|
|
52836
53371
|
const [ownedProcesses, runtimeStatus] = await Promise.all([listDaemonOwnedProcesses({ ignoreProcessIds: [process$1.pid, process$1.ppid].filter((pid) => Number.isInteger(pid) && pid > 0) }), readCurrentObservedDaemonRuntimeStatus()]);
|
|
52837
53372
|
if (ownedProcesses.length > 0) throw new DaemonServiceLifecycleStageError({
|
|
@@ -52854,7 +53389,7 @@ async function waitForLegacySharedServiceCleanup(input) {
|
|
|
52854
53389
|
});
|
|
52855
53390
|
lastInventory = inventory;
|
|
52856
53391
|
if (!(inventory.legacySharedService?.present === true || inventory.anomalies.some((anomaly) => anomaly.code === "legacy_shared_service_present"))) return;
|
|
52857
|
-
await sleep
|
|
53392
|
+
await sleep(STRICT_TEARDOWN_VERIFY_POLL_MS$1);
|
|
52858
53393
|
}
|
|
52859
53394
|
throw new DaemonServiceLifecycleStageError({
|
|
52860
53395
|
message: "ATS Service legacy shared registration is still present after cleanup. reason=legacy_shared_service_present",
|
|
@@ -53078,7 +53613,7 @@ async function waitForVerifiedLifecycleInventory(input) {
|
|
|
53078
53613
|
});
|
|
53079
53614
|
lastInventory = inventory;
|
|
53080
53615
|
lastError = verificationError;
|
|
53081
|
-
await sleep
|
|
53616
|
+
await sleep(STRICT_TEARDOWN_VERIFY_POLL_MS$1);
|
|
53082
53617
|
}
|
|
53083
53618
|
throw new DaemonServiceLifecycleStageError({
|
|
53084
53619
|
message: lastError ?? "ATS could not verify the final local service inventory state.",
|
|
@@ -53217,7 +53752,7 @@ async function waitForProcessToExit$1(pid, timeoutMs) {
|
|
|
53217
53752
|
const deadline = Date.now() + timeoutMs;
|
|
53218
53753
|
while (Date.now() < deadline) {
|
|
53219
53754
|
if (!isPidAlive$2(pid)) return true;
|
|
53220
|
-
await sleep
|
|
53755
|
+
await sleep(STRICT_TEARDOWN_VERIFY_POLL_MS$1);
|
|
53221
53756
|
}
|
|
53222
53757
|
return !isPidAlive$2(pid);
|
|
53223
53758
|
}
|
|
@@ -53240,7 +53775,7 @@ async function writeLifecycleEvidenceEvent(input) {
|
|
|
53240
53775
|
|
|
53241
53776
|
//#endregion
|
|
53242
53777
|
//#region src/local-service/lifecycle/daemon-service-start-recovery.ts
|
|
53243
|
-
const ROOT_ERROR_PATTERN
|
|
53778
|
+
const ROOT_ERROR_PATTERN = /\s*Try re-running the command as root for richer errors\.?/i;
|
|
53244
53779
|
async function startDaemonSystemServiceWithAutoRepair(input) {
|
|
53245
53780
|
let autoRepairAttempted = false;
|
|
53246
53781
|
try {
|
|
@@ -53268,16 +53803,16 @@ async function startDaemonSystemServiceWithAutoRepair(input) {
|
|
|
53268
53803
|
}
|
|
53269
53804
|
}
|
|
53270
53805
|
}
|
|
53271
|
-
function sanitizeSystemServiceErrorMessage
|
|
53272
|
-
return message.replace(ROOT_ERROR_PATTERN
|
|
53806
|
+
function sanitizeSystemServiceErrorMessage(message) {
|
|
53807
|
+
return message.replace(ROOT_ERROR_PATTERN, "");
|
|
53273
53808
|
}
|
|
53274
|
-
function isLaunchdBootstrapIosError
|
|
53809
|
+
function isLaunchdBootstrapIosError(message) {
|
|
53275
53810
|
const normalized = message.toLowerCase();
|
|
53276
53811
|
return normalized.includes("bootstrap failed") && normalized.includes("input/output error");
|
|
53277
53812
|
}
|
|
53278
53813
|
function shouldAttemptLaunchdAutoRepair(input) {
|
|
53279
53814
|
if (input.controller !== "launchd") return false;
|
|
53280
|
-
return isLaunchdBootstrapIosError
|
|
53815
|
+
return isLaunchdBootstrapIosError(sanitizeSystemServiceErrorMessage(toErrorMessage$17(input.error)));
|
|
53281
53816
|
}
|
|
53282
53817
|
function buildLaunchdAutoRepairFailureError(input) {
|
|
53283
53818
|
return new Error([
|
|
@@ -53667,7 +54202,7 @@ async function recordDaemonServiceRepairFailure(input) {
|
|
|
53667
54202
|
}
|
|
53668
54203
|
async function readDaemonServiceRepairJournal() {
|
|
53669
54204
|
const raw = await readFile(daemonServiceRepairJournalPath(), "utf8").catch((error) => {
|
|
53670
|
-
if (getErrorCode(error) === "ENOENT") return null;
|
|
54205
|
+
if (getErrorCode$1(error) === "ENOENT") return null;
|
|
53671
54206
|
throw error;
|
|
53672
54207
|
});
|
|
53673
54208
|
if (raw === null) return createEmptyDaemonServiceRepairJournalState();
|
|
@@ -53704,7 +54239,7 @@ function createEmptyDaemonServiceRepairJournalState() {
|
|
|
53704
54239
|
function isDaemonServiceRepairJournalRecord(value) {
|
|
53705
54240
|
return !!value && typeof value === "object" && "actionKey" in value && typeof value.actionKey === "string" && "consecutiveFailures" in value && typeof value.consecutiveFailures === "number" && "lastAttemptAt" in value && typeof value.lastAttemptAt === "string" && "lastFailureAt" in value && (typeof value.lastFailureAt === "string" || value.lastFailureAt === null) && "lastSuccessAt" in value && (typeof value.lastSuccessAt === "string" || value.lastSuccessAt === null) && "cooldownUntil" in value && (typeof value.cooldownUntil === "string" || value.cooldownUntil === null) && "lastErrorMessage" in value && (typeof value.lastErrorMessage === "string" || value.lastErrorMessage === null);
|
|
53706
54241
|
}
|
|
53707
|
-
function getErrorCode(error) {
|
|
54242
|
+
function getErrorCode$1(error) {
|
|
53708
54243
|
if (error && typeof error === "object" && "code" in error) return typeof error.code === "string" ? error.code : null;
|
|
53709
54244
|
return null;
|
|
53710
54245
|
}
|
|
@@ -53868,7 +54403,7 @@ async function terminateDaemonOwnedProcess(pid) {
|
|
|
53868
54403
|
const deadline = Date.now() + AUTO_HEAL_DUPLICATE_WAIT_MS;
|
|
53869
54404
|
while (Date.now() < deadline) {
|
|
53870
54405
|
if (!isPidAlive$1(pid)) return;
|
|
53871
|
-
await sleep
|
|
54406
|
+
await sleep(AUTO_HEAL_DUPLICATE_POLL_MS);
|
|
53872
54407
|
}
|
|
53873
54408
|
if (isPidAlive$1(pid)) process$1.kill(pid, "SIGKILL");
|
|
53874
54409
|
}
|
|
@@ -54081,7 +54616,7 @@ async function waitForDaemonStartupAlignmentSettlement(input) {
|
|
|
54081
54616
|
cliScriptPath: input.cliScriptPath
|
|
54082
54617
|
}).catch(() => null);
|
|
54083
54618
|
if (!inventory) {
|
|
54084
|
-
await sleep
|
|
54619
|
+
await sleep(input.pollMs);
|
|
54085
54620
|
continue;
|
|
54086
54621
|
}
|
|
54087
54622
|
const decision = resolveDaemonServiceAlignmentDecision({
|
|
@@ -54102,7 +54637,7 @@ async function waitForDaemonStartupAlignmentSettlement(input) {
|
|
|
54102
54637
|
cooldownUntil: null,
|
|
54103
54638
|
backupDataPath: null
|
|
54104
54639
|
};
|
|
54105
|
-
await sleep
|
|
54640
|
+
await sleep(input.pollMs);
|
|
54106
54641
|
}
|
|
54107
54642
|
return null;
|
|
54108
54643
|
}
|
|
@@ -54896,6 +55431,11 @@ function buildRuntimeDetailRows(input) {
|
|
|
54896
55431
|
serviceManagerStatus: input.serviceManagerStatus
|
|
54897
55432
|
})]);
|
|
54898
55433
|
}
|
|
55434
|
+
function formatDaemonRunModeLabel(mode) {
|
|
55435
|
+
if (mode === "foreground") return "foreground — stops when the terminal closes";
|
|
55436
|
+
if (mode === "background") return "background service";
|
|
55437
|
+
return "unknown";
|
|
55438
|
+
}
|
|
54899
55439
|
function buildCoreRuntimeStateRows(input) {
|
|
54900
55440
|
const rows = [{
|
|
54901
55441
|
label: "⚙️ Runtime",
|
|
@@ -54904,7 +55444,7 @@ function buildCoreRuntimeStateRows(input) {
|
|
|
54904
55444
|
if (input.runtimeState.status === "running") {
|
|
54905
55445
|
rows.push({
|
|
54906
55446
|
label: "🎚️ Mode",
|
|
54907
|
-
value: input.runtimeState.mode
|
|
55447
|
+
value: formatDaemonRunModeLabel(input.runtimeState.mode)
|
|
54908
55448
|
}, {
|
|
54909
55449
|
label: "🧬 PID",
|
|
54910
55450
|
value: input.runtimeState.pid === null ? "not available" : String(input.runtimeState.pid)
|
|
@@ -54920,7 +55460,7 @@ function buildCoreRuntimeStateRows(input) {
|
|
|
54920
55460
|
if (input.effectiveStatus === "running") {
|
|
54921
55461
|
rows.push({
|
|
54922
55462
|
label: "🎚️ Mode",
|
|
54923
|
-
value: input.runtimeState.mode
|
|
55463
|
+
value: formatDaemonRunModeLabel(input.runtimeState.mode)
|
|
54924
55464
|
}, {
|
|
54925
55465
|
label: "🧬 PID",
|
|
54926
55466
|
value: input.runtimeState.pid === null ? "being managed by OS service manager" : String(input.runtimeState.pid)
|
|
@@ -55029,8 +55569,8 @@ function mapLocalControllerStatusReason(reason) {
|
|
|
55029
55569
|
}
|
|
55030
55570
|
function describeDaemonRuntimeStatus(status) {
|
|
55031
55571
|
if (!status) return "No runtime status available.";
|
|
55032
|
-
if (status.status === "running") return `Service is running (
|
|
55033
|
-
if (status.status === "stale") return `Service status is stale (
|
|
55572
|
+
if (status.status === "running") return `Service is running (${formatDaemonRunModeLabel(status.mode)}, pid=${String(status.pid)}, started=${status.startedAt || "unknown"}).`;
|
|
55573
|
+
if (status.status === "stale") return `Service status is stale (${formatDaemonRunModeLabel(status.mode)}, pid=${String(status.pid)}, reason=${status.reason || "unknown"}).`;
|
|
55034
55574
|
if (status.status === "not_running") return "Service is not running.";
|
|
55035
55575
|
return "Service runtime status is unknown.";
|
|
55036
55576
|
}
|
|
@@ -55263,13 +55803,6 @@ function capitalizeDaemonControlCommand(command) {
|
|
|
55263
55803
|
return command === "cancel" ? "Cancel" : "Interrupt";
|
|
55264
55804
|
}
|
|
55265
55805
|
|
|
55266
|
-
//#endregion
|
|
55267
|
-
//#region src/commands/service-error-text.ts
|
|
55268
|
-
const ROOT_ERROR_PATTERN = /\s*Try re-running the command as root for richer errors\.?/i;
|
|
55269
|
-
function sanitizeSystemServiceErrorMessage(message) {
|
|
55270
|
-
return message.replace(ROOT_ERROR_PATTERN, "");
|
|
55271
|
-
}
|
|
55272
|
-
|
|
55273
55806
|
//#endregion
|
|
55274
55807
|
//#region src/commands/service-reinstall-view.ts
|
|
55275
55808
|
var DaemonReinstallUnexpectedStartError = class extends Error {
|
|
@@ -55388,7 +55921,8 @@ function createDaemonReinstallStartFailedOutcome(input) {
|
|
|
55388
55921
|
forceUsed: input.forceUsed,
|
|
55389
55922
|
backupDataPath: input.backupDataPath,
|
|
55390
55923
|
...input.failureStage ? { failureStage: input.failureStage } : {},
|
|
55391
|
-
...input.evidencePath ? { evidencePath: input.evidencePath } : {}
|
|
55924
|
+
...input.evidencePath ? { evidencePath: input.evidencePath } : {},
|
|
55925
|
+
...input.startFailureVerdict ? { startFailureVerdict: input.startFailureVerdict } : {}
|
|
55392
55926
|
};
|
|
55393
55927
|
}
|
|
55394
55928
|
function createDaemonReinstallStartBlockedOutcome(input) {
|
|
@@ -55398,7 +55932,8 @@ function createDaemonReinstallStartBlockedOutcome(input) {
|
|
|
55398
55932
|
blockReason: input.blockReason,
|
|
55399
55933
|
desiredState: input.desiredState,
|
|
55400
55934
|
forceUsed: input.forceUsed,
|
|
55401
|
-
backupDataPath: input.backupDataPath
|
|
55935
|
+
backupDataPath: input.backupDataPath,
|
|
55936
|
+
...input.startFailureVerdict ? { startFailureVerdict: input.startFailureVerdict } : {}
|
|
55402
55937
|
};
|
|
55403
55938
|
}
|
|
55404
55939
|
async function attachDaemonReinstallEvidence(input) {
|
|
@@ -55679,7 +56214,7 @@ function summarizeDaemonReinstallJournalResult(outcome) {
|
|
|
55679
56214
|
}
|
|
55680
56215
|
function buildDaemonReinstallUnexpectedStartSummary(error, action = "repair") {
|
|
55681
56216
|
const actionLabel = formatDaemonServiceMaintenanceActionLabel(action);
|
|
55682
|
-
const detail = sanitizeSystemServiceErrorMessage(toErrorMessage$43(error));
|
|
56217
|
+
const detail = sanitizeSystemServiceErrorMessage$1(toErrorMessage$43(error));
|
|
55683
56218
|
if (!detail) return `ATS hit a local start error right after service ${actionLabel}.`;
|
|
55684
56219
|
return `ATS hit a local start error right after service ${actionLabel}: ${detail}`;
|
|
55685
56220
|
}
|
|
@@ -55753,183 +56288,6 @@ function createDaemonAlreadyRunningResult() {
|
|
|
55753
56288
|
};
|
|
55754
56289
|
}
|
|
55755
56290
|
|
|
55756
|
-
//#endregion
|
|
55757
|
-
//#region src/commands/service-start-failure.ts
|
|
55758
|
-
const DAEMON_STARTUP_BLOCKING_ANOMALIES = new Set([
|
|
55759
|
-
"duplicate_owned_processes",
|
|
55760
|
-
"multiple_active_owners",
|
|
55761
|
-
"runtime_bundle_mismatch",
|
|
55762
|
-
"runtime_contract_mismatch"
|
|
55763
|
-
]);
|
|
55764
|
-
var SystemServiceStartupTimeoutError = class extends Error {
|
|
55765
|
-
code = "ats.service.startup_timeout";
|
|
55766
|
-
inventory;
|
|
55767
|
-
managerStatus;
|
|
55768
|
-
runtimeStatus;
|
|
55769
|
-
jobDiagnostics;
|
|
55770
|
-
constructor(input) {
|
|
55771
|
-
super(buildSystemServiceStartupTimeoutMessage(input));
|
|
55772
|
-
this.name = "SystemServiceStartupTimeoutError";
|
|
55773
|
-
this.inventory = input.inventory;
|
|
55774
|
-
this.managerStatus = input.managerStatus;
|
|
55775
|
-
this.runtimeStatus = input.runtimeStatus;
|
|
55776
|
-
this.jobDiagnostics = input.jobDiagnostics ?? null;
|
|
55777
|
-
}
|
|
55778
|
-
};
|
|
55779
|
-
function buildSystemServiceStartupFailureReport(input) {
|
|
55780
|
-
const message = sanitizeSystemServiceErrorMessage(toErrorMessage$43(input.error));
|
|
55781
|
-
const localLogPath = getDaemonSystemServiceLogPath();
|
|
55782
|
-
const jobDiagnostics = isSystemServiceStartupTimeoutError(input.error) ? input.error.jobDiagnostics ?? null : null;
|
|
55783
|
-
if (jobDiagnostics && isDaemonServiceJobNeverSpawned(jobDiagnostics)) {
|
|
55784
|
-
const summary = "macOS is blocking the ATS Service background item, so ATS Service never launched.";
|
|
55785
|
-
const card = buildDaemonStartNeedsAttentionCard({
|
|
55786
|
-
summary,
|
|
55787
|
-
nextStep: formatInlineAtsCliCommands("Open System Settings > General > Login Items & Extensions, enable the ATS background item, then run `ats service start` again. Power users can audit Background Task Management with `sfltool dumpbtm`."),
|
|
55788
|
-
autoRepairAttempted: input.autoRepairAttempted,
|
|
55789
|
-
detail: input.detail ?? formatDaemonServiceJobDiagnosticsEvidence(jobDiagnostics)
|
|
55790
|
-
});
|
|
55791
|
-
return {
|
|
55792
|
-
title: card.title,
|
|
55793
|
-
summary,
|
|
55794
|
-
rows: card.rows
|
|
55795
|
-
};
|
|
55796
|
-
}
|
|
55797
|
-
const crashExitCode = jobDiagnostics ? readDaemonServiceJobCrashExitCode(jobDiagnostics) : null;
|
|
55798
|
-
if (jobDiagnostics && crashExitCode !== null) {
|
|
55799
|
-
const summary = `ATS Service launched but keeps exiting (launchd reports ${jobDiagnostics.runs} runs, last exit code ${crashExitCode}).`;
|
|
55800
|
-
const card = buildDaemonStartNeedsAttentionCard({
|
|
55801
|
-
summary,
|
|
55802
|
-
nextStep: formatInlineAtsCliCommands(`Run \`ats service start --mode foreground\` to see the live error. The latest local service log is at \`${localLogPath}\`. If it still fails, run \`ats service repair\`.`),
|
|
55803
|
-
autoRepairAttempted: input.autoRepairAttempted,
|
|
55804
|
-
detail: input.detail ?? formatDaemonServiceJobDiagnosticsEvidence(jobDiagnostics)
|
|
55805
|
-
});
|
|
55806
|
-
return {
|
|
55807
|
-
title: card.title,
|
|
55808
|
-
summary,
|
|
55809
|
-
rows: card.rows
|
|
55810
|
-
};
|
|
55811
|
-
}
|
|
55812
|
-
if (isLaunchdBootstrapIosError(message)) {
|
|
55813
|
-
const card = buildDaemonStartNeedsAttentionCard({
|
|
55814
|
-
summary: "ATS could not finish starting ATS Service on this Mac.",
|
|
55815
|
-
nextStep: formatInlineAtsCliCommands(`Run \`launchctl enable gui/$(id -u)/${getDaemonServiceLaunchdLabel()}\`, then retry with \`ats service start\`. The latest local service log is at \`${localLogPath}\`. If it still fails, run \`ats service repair\`.`),
|
|
55816
|
-
autoRepairAttempted: input.autoRepairAttempted,
|
|
55817
|
-
detail: input.detail ?? void 0
|
|
55818
|
-
});
|
|
55819
|
-
return {
|
|
55820
|
-
title: card.title,
|
|
55821
|
-
summary: "ATS could not finish starting ATS Service on this Mac.",
|
|
55822
|
-
rows: card.rows
|
|
55823
|
-
};
|
|
55824
|
-
}
|
|
55825
|
-
if (isPermissionOrAuthorizationError(message)) {
|
|
55826
|
-
const card = buildDaemonStartNeedsAttentionCard({
|
|
55827
|
-
summary: "ATS needs local OS permission before it can start ATS Service.",
|
|
55828
|
-
nextStep: formatInlineAtsCliCommands(`Approve the local permission prompt or OS setting, then run \`ats service start\` again. The latest local service log is at \`${localLogPath}\`.`),
|
|
55829
|
-
autoRepairAttempted: input.autoRepairAttempted,
|
|
55830
|
-
detail: input.detail ?? void 0
|
|
55831
|
-
});
|
|
55832
|
-
return {
|
|
55833
|
-
title: card.title,
|
|
55834
|
-
summary: "ATS needs local OS permission before it can start ATS Service.",
|
|
55835
|
-
rows: card.rows
|
|
55836
|
-
};
|
|
55837
|
-
}
|
|
55838
|
-
const card = buildDaemonStartNeedsAttentionCard({
|
|
55839
|
-
summary: "ATS could not finish starting ATS Service.",
|
|
55840
|
-
nextStep: formatInlineAtsCliCommands(`Run \`ats service start --mode foreground\` to see the live error. The latest local service log is at \`${localLogPath}\`. If it still fails, run \`ats service repair\`.`),
|
|
55841
|
-
autoRepairAttempted: input.autoRepairAttempted,
|
|
55842
|
-
detail: input.detail ?? void 0
|
|
55843
|
-
});
|
|
55844
|
-
return {
|
|
55845
|
-
title: card.title,
|
|
55846
|
-
summary: `ATS could not finish starting ATS Service (${input.controller}).`,
|
|
55847
|
-
rows: card.rows
|
|
55848
|
-
};
|
|
55849
|
-
}
|
|
55850
|
-
function buildSystemServiceStartupFailureMessage(input) {
|
|
55851
|
-
const report = buildSystemServiceStartupFailureReport(input);
|
|
55852
|
-
const rowLines = report.rows.map((row) => formatSystemServiceFailureRow(row)).filter((line) => line.length > 0);
|
|
55853
|
-
return [report.summary, ...rowLines].join("\n");
|
|
55854
|
-
}
|
|
55855
|
-
function buildSystemServiceStartupFailureDiagnostics(input) {
|
|
55856
|
-
const timeoutError = isSystemServiceStartupTimeoutError(input.error) ? input.error : null;
|
|
55857
|
-
return {
|
|
55858
|
-
anomalies: timeoutError?.inventory?.anomalies ?? [],
|
|
55859
|
-
autoRepairAttempted: input.autoRepairAttempted === true,
|
|
55860
|
-
controller: input.controller ?? null,
|
|
55861
|
-
jobDiagnostics: timeoutError?.jobDiagnostics ?? null,
|
|
55862
|
-
launchdLabel: (input.controller ?? null) === "launchd" ? getDaemonServiceLaunchdLabel() : null,
|
|
55863
|
-
lifecycleJournalPath: daemonLifecycleJournalPath(),
|
|
55864
|
-
managerStatus: timeoutError?.managerStatus ?? null,
|
|
55865
|
-
nextSteps: [formatAtsCliCommand("ats service start --mode foreground"), formatAtsCliCommand("ats service repair")],
|
|
55866
|
-
recovery: input.recovery,
|
|
55867
|
-
runtimeStatus: timeoutError?.runtimeStatus ?? null,
|
|
55868
|
-
serviceLogPath: getDaemonSystemServiceLogPath()
|
|
55869
|
-
};
|
|
55870
|
-
}
|
|
55871
|
-
function buildSystemServiceStartupTimeoutMessage(input) {
|
|
55872
|
-
const base = `ATS Service failed to reach a running local service state in time. runtime=${input.runtimeStatus?.status ?? "unknown"}, reason=${input.runtimeStatus?.reason || "unknown"}, managerRunning=${String(input.managerStatus?.running ?? false)}, anomalies=${input.inventory?.anomalies.map((anomaly) => anomaly.code).join(",") || "unknown"}`;
|
|
55873
|
-
if (!input.jobDiagnostics) return base;
|
|
55874
|
-
return `${base}; ${formatDaemonServiceJobDiagnosticsEvidence(input.jobDiagnostics)}`;
|
|
55875
|
-
}
|
|
55876
|
-
function isSystemServiceStartupTimeoutError(error) {
|
|
55877
|
-
return error instanceof SystemServiceStartupTimeoutError || typeof error === "object" && error !== null && "code" in error && error.code === "ats.service.startup_timeout";
|
|
55878
|
-
}
|
|
55879
|
-
function formatSystemServiceFailureRow(row) {
|
|
55880
|
-
const label = row.label.trim();
|
|
55881
|
-
const value = formatAtsCliTextBlock(row.value).trim();
|
|
55882
|
-
if (label.length === 0 && value.length === 0) return "";
|
|
55883
|
-
if (value.length === 0) return `${row.label}:`;
|
|
55884
|
-
if (label.length === 0) return row.value;
|
|
55885
|
-
return `${row.label}: ${row.value}`;
|
|
55886
|
-
}
|
|
55887
|
-
function isLaunchdBootstrapIosError(message) {
|
|
55888
|
-
const normalized = message.toLowerCase();
|
|
55889
|
-
return normalized.includes("bootstrap failed") && normalized.includes("input/output error");
|
|
55890
|
-
}
|
|
55891
|
-
function isPermissionOrAuthorizationError(message) {
|
|
55892
|
-
const normalized = message.toLowerCase();
|
|
55893
|
-
return normalized.includes("permission") || normalized.includes("operation not permitted") || normalized.includes("access is denied") || normalized.includes("requires admin") || normalized.includes("elevation") || normalized.includes("access denied") || normalized.includes("not authorized");
|
|
55894
|
-
}
|
|
55895
|
-
function isDaemonInventoryRunningAndStartReady(inventory) {
|
|
55896
|
-
if (inventory.runtimeStatus.status !== "running") return false;
|
|
55897
|
-
if (inventory.runtimeStatus.mode !== "background") return false;
|
|
55898
|
-
if (inventory.runtimeStatus.managedBySystemService !== true) return false;
|
|
55899
|
-
return !inventory.anomalies.some((anomaly) => DAEMON_STARTUP_BLOCKING_ANOMALIES.has(anomaly.code));
|
|
55900
|
-
}
|
|
55901
|
-
async function waitForSystemServiceStartup(input) {
|
|
55902
|
-
const deadlineMs = Date.now() + input.waitMs;
|
|
55903
|
-
while (Date.now() < deadlineMs) {
|
|
55904
|
-
const inventory = await inspectDaemonServiceInventory({
|
|
55905
|
-
expectedVersion: input.expectedVersion,
|
|
55906
|
-
intendedMode: "background",
|
|
55907
|
-
intent: "run_background"
|
|
55908
|
-
}).catch(() => null);
|
|
55909
|
-
if (inventory && isDaemonInventoryRunningAndStartReady(inventory)) return {
|
|
55910
|
-
state: "running",
|
|
55911
|
-
runtimeStatus: inventory.runtimeStatus
|
|
55912
|
-
};
|
|
55913
|
-
await sleep$1(input.pollMs);
|
|
55914
|
-
}
|
|
55915
|
-
const finalInventory = await inspectDaemonServiceInventory({
|
|
55916
|
-
expectedVersion: input.expectedVersion,
|
|
55917
|
-
intendedMode: "background",
|
|
55918
|
-
intent: "run_background"
|
|
55919
|
-
}).catch(() => null);
|
|
55920
|
-
if (finalInventory && isDaemonInventoryRunningAndStartReady(finalInventory)) return {
|
|
55921
|
-
state: "running",
|
|
55922
|
-
runtimeStatus: finalInventory.runtimeStatus
|
|
55923
|
-
};
|
|
55924
|
-
const finalRuntimeStatus = await readCurrentObservedDaemonRuntimeStatus().catch(() => null);
|
|
55925
|
-
throw new SystemServiceStartupTimeoutError({
|
|
55926
|
-
inventory: finalInventory,
|
|
55927
|
-
managerStatus: await input.manager.status().catch(() => null),
|
|
55928
|
-
runtimeStatus: finalRuntimeStatus,
|
|
55929
|
-
jobDiagnostics: await input.manager.readJobDiagnostics?.().catch(() => null) ?? null
|
|
55930
|
-
});
|
|
55931
|
-
}
|
|
55932
|
-
|
|
55933
56291
|
//#endregion
|
|
55934
56292
|
//#region src/commands/service-stop-command.ts
|
|
55935
56293
|
const STOP_WAIT_MS = 2e3;
|
|
@@ -56481,7 +56839,7 @@ async function verifySystemServiceRemovedAfterStrictTeardown(input) {
|
|
|
56481
56839
|
}
|
|
56482
56840
|
}
|
|
56483
56841
|
if (allRemoved) return;
|
|
56484
|
-
await sleep
|
|
56842
|
+
await sleep(STRICT_TEARDOWN_VERIFY_POLL_MS);
|
|
56485
56843
|
}
|
|
56486
56844
|
for (const manager of managers) {
|
|
56487
56845
|
const finalManagerStatus = await manager.status().catch((error) => {
|
|
@@ -56518,7 +56876,7 @@ async function ensureRuntimeCleanAfterStrictTeardown(input) {
|
|
|
56518
56876
|
if ((await input.deps.readCurrentObservedDaemonRuntimeStatus()).status === "not_running") return;
|
|
56519
56877
|
}
|
|
56520
56878
|
}
|
|
56521
|
-
await sleep
|
|
56879
|
+
await sleep(STRICT_TEARDOWN_VERIFY_POLL_MS);
|
|
56522
56880
|
}
|
|
56523
56881
|
const [ownedProcesses, finalRuntime] = await Promise.all([input.deps.listDaemonOwnedProcesses({ ignoreProcessIds: [process.pid] }), input.deps.readCurrentObservedDaemonRuntimeStatus()]);
|
|
56524
56882
|
if (finalRuntime.status === "running") throw createStrictTeardownError({
|
|
@@ -57057,7 +57415,7 @@ async function autoStartDaemonAfterReinstall(input) {
|
|
|
57057
57415
|
startRetryDelayMs: input.resolved.startRetryDelayMs,
|
|
57058
57416
|
view: input.runtime.resolvedView
|
|
57059
57417
|
});
|
|
57060
|
-
if (startOutcome === "cancelled") {
|
|
57418
|
+
if (startOutcome.reason === "cancelled") {
|
|
57061
57419
|
await clearDaemonStartFailureStateSafely();
|
|
57062
57420
|
return createDaemonReinstallCompletedOutcome({
|
|
57063
57421
|
backupDataPath: null,
|
|
@@ -57066,7 +57424,7 @@ async function autoStartDaemonAfterReinstall(input) {
|
|
|
57066
57424
|
serviceState: "stopped"
|
|
57067
57425
|
});
|
|
57068
57426
|
}
|
|
57069
|
-
const blockReason = resolveDaemonReinstallStartBlockedReason(startOutcome);
|
|
57427
|
+
const blockReason = resolveDaemonReinstallStartBlockedReason(startOutcome.reason);
|
|
57070
57428
|
if (blockReason) {
|
|
57071
57429
|
const recheckedInventory = await inspectDaemonServiceInventory({
|
|
57072
57430
|
expectedVersion: input.resolved.daemonVersion,
|
|
@@ -57086,13 +57444,15 @@ async function autoStartDaemonAfterReinstall(input) {
|
|
|
57086
57444
|
backupDataPath: null,
|
|
57087
57445
|
blockReason,
|
|
57088
57446
|
desiredState: input.desiredState,
|
|
57089
|
-
forceUsed: input.forceUsed
|
|
57447
|
+
forceUsed: input.forceUsed,
|
|
57448
|
+
startFailureVerdict: startOutcome.startFailureVerdict
|
|
57090
57449
|
});
|
|
57091
57450
|
}
|
|
57092
|
-
if (startOutcome === "start_failed") return createDaemonReinstallStartFailedOutcome({
|
|
57451
|
+
if (startOutcome.reason === "start_failed") return createDaemonReinstallStartFailedOutcome({
|
|
57093
57452
|
backupDataPath: null,
|
|
57094
57453
|
desiredState: input.desiredState,
|
|
57095
|
-
forceUsed: input.forceUsed
|
|
57454
|
+
forceUsed: input.forceUsed,
|
|
57455
|
+
startFailureVerdict: startOutcome.startFailureVerdict
|
|
57096
57456
|
});
|
|
57097
57457
|
await waitForDaemonHealthyAfterReinstall({
|
|
57098
57458
|
expectedVersion: input.resolved.daemonVersion,
|
|
@@ -57123,14 +57483,17 @@ async function runDaemonAfterReinstallStartWithRetry(input) {
|
|
|
57123
57483
|
if (result.ok || isDaemonRunAlreadyRunningReason(result.reason) || normalizeDaemonRunReason(result.reason) === "cancelled") process.exitCode = previousExitCode;
|
|
57124
57484
|
if (normalizeDaemonRunReason(result.reason) === "start_failed" && attempt < REINSTALL_START_RETRY_ATTEMPTS) {
|
|
57125
57485
|
process.exitCode = previousExitCode;
|
|
57126
|
-
await sleep
|
|
57486
|
+
await sleep(input.startRetryDelayMs);
|
|
57127
57487
|
continue;
|
|
57128
57488
|
}
|
|
57129
|
-
return
|
|
57489
|
+
return {
|
|
57490
|
+
reason: result.reason,
|
|
57491
|
+
startFailureVerdict: result.ok === false ? result.startFailureVerdict ?? null : null
|
|
57492
|
+
};
|
|
57130
57493
|
} catch (error) {
|
|
57131
57494
|
if (attempt < REINSTALL_START_RETRY_ATTEMPTS) {
|
|
57132
57495
|
process.exitCode = previousExitCode;
|
|
57133
|
-
await sleep
|
|
57496
|
+
await sleep(input.startRetryDelayMs);
|
|
57134
57497
|
continue;
|
|
57135
57498
|
}
|
|
57136
57499
|
const startupDiagnostic = await readDaemonStartFailureLogDiagnostic({ cursor: startFailureLogCursor });
|
|
@@ -57142,7 +57505,10 @@ async function runDaemonAfterReinstallStartWithRetry(input) {
|
|
|
57142
57505
|
});
|
|
57143
57506
|
}
|
|
57144
57507
|
}
|
|
57145
|
-
return
|
|
57508
|
+
return {
|
|
57509
|
+
reason: "start_failed",
|
|
57510
|
+
startFailureVerdict: null
|
|
57511
|
+
};
|
|
57146
57512
|
}
|
|
57147
57513
|
async function resolveDaemonReinstallTargetDesiredState() {
|
|
57148
57514
|
const currentContract = await readDaemonServiceContract().catch(() => null);
|
|
@@ -57223,7 +57589,7 @@ async function waitForDaemonHealthyAfterReinstall(input) {
|
|
|
57223
57589
|
}).catch(() => null);
|
|
57224
57590
|
if (inventory && isDaemonInventoryRunningAndAligned(inventory)) return inventory.runtimeStatus;
|
|
57225
57591
|
lastRuntime = inventory?.runtimeStatus ?? await readCurrentObservedDaemonRuntimeStatus();
|
|
57226
|
-
await sleep
|
|
57592
|
+
await sleep(REINSTALL_VERIFY_POLL_MS);
|
|
57227
57593
|
}
|
|
57228
57594
|
const statusText = lastRuntime ? describeDaemonRuntimeStatus(lastRuntime) : "No runtime status available.";
|
|
57229
57595
|
throw new Error(`ATS Service repair verification timed out after ${String(input.verifyWaitMs)}ms. ${statusText}`);
|
|
@@ -57610,9 +57976,15 @@ async function handleDaemonRunStartFailure(input) {
|
|
|
57610
57976
|
});
|
|
57611
57977
|
}
|
|
57612
57978
|
process.exitCode = 1;
|
|
57979
|
+
const startFailureVerdict = input.genericErrorPayload.controller ? resolveSystemServiceStartupFailureVerdict({
|
|
57980
|
+
controller: input.genericErrorPayload.controller,
|
|
57981
|
+
error: input.genericErrorPayload.error,
|
|
57982
|
+
detail: failure?.detail ?? null
|
|
57983
|
+
}) : null;
|
|
57613
57984
|
return {
|
|
57614
57985
|
ok: false,
|
|
57615
|
-
reason: "start_failed"
|
|
57986
|
+
reason: "start_failed",
|
|
57987
|
+
...startFailureVerdict ? { startFailureVerdict } : {}
|
|
57616
57988
|
};
|
|
57617
57989
|
}
|
|
57618
57990
|
async function runDirectDaemonServiceLoop(input) {
|
|
@@ -59292,7 +59664,7 @@ async function waitForDetachedBackgroundProcessStartup(child, startupDelayMs, st
|
|
|
59292
59664
|
reason: startupLifecycle,
|
|
59293
59665
|
startupOutput: startupOutput.summary()
|
|
59294
59666
|
}));
|
|
59295
|
-
await sleep
|
|
59667
|
+
await sleep(startupPollMs);
|
|
59296
59668
|
}
|
|
59297
59669
|
const finalStatus = await readCurrentObservedDaemonRuntimeStatus().catch(() => null);
|
|
59298
59670
|
if (finalStatus?.status === "running" && finalStatus.pid === child.pid) return;
|
|
@@ -59778,7 +60150,7 @@ async function runAuthMenu(input) {
|
|
|
59778
60150
|
}
|
|
59779
60151
|
async function resolveAuthLoginRequest(input) {
|
|
59780
60152
|
const explicitMethod = parseAuthLoginMethod(input.method);
|
|
59781
|
-
const providedToken = normalizeOptionalString$
|
|
60153
|
+
const providedToken = normalizeOptionalString$15(input.ott);
|
|
59782
60154
|
const isInteractiveHuman = input.runtime.resolvedView === "human" && canUseInteractivePrompts(input.runtime);
|
|
59783
60155
|
if (providedToken && explicitMethod === LOGIN_METHOD_DEVICE) throw new Error("`--ott` cannot be used with `--method device`");
|
|
59784
60156
|
const explicitRequest = await resolveExplicitAuthLoginRequest({
|
|
@@ -59960,7 +60332,7 @@ async function runDeviceLoginFlow(input) {
|
|
|
59960
60332
|
authBaseUrl: input.authBaseUrl,
|
|
59961
60333
|
clientId: input.clientId,
|
|
59962
60334
|
expiresAt: resolveExpiresAt(token.expires_in),
|
|
59963
|
-
scope: normalizeOptionalString$
|
|
60335
|
+
scope: normalizeOptionalString$15(token.scope) ?? void 0,
|
|
59964
60336
|
user: authUser ?? void 0
|
|
59965
60337
|
});
|
|
59966
60338
|
emitLineWithHumanSpacer({
|
|
@@ -60004,7 +60376,7 @@ async function assertOneTimeTokenAuthSessionSaved(input) {
|
|
|
60004
60376
|
const authState = await getAuthSessionState({ validateRemote: false }).catch(() => null);
|
|
60005
60377
|
if (authState?.state !== "valid" || !authState.session) throw new OneTimeTokenAuthError("session_not_saved", `one-time token verified, but ATS could not save a usable local sign-in session (${authState?.state ?? "unknown"}); copy a fresh setup command from ATS Web and retry`);
|
|
60006
60378
|
if (authState.session.accessToken !== input.accessToken) throw new OneTimeTokenAuthError("session_not_saved", "one-time token verified, but ATS saved a different local sign-in session; copy a fresh setup command from ATS Web and retry");
|
|
60007
|
-
if (!normalizeOptionalString$
|
|
60379
|
+
if (!normalizeOptionalString$15(authState.session.user?.id)) throw new OneTimeTokenAuthError("session_not_saved", "one-time token verified, but the saved local sign-in is missing its ATS account ID; copy a fresh setup command from ATS Web and retry");
|
|
60008
60380
|
}
|
|
60009
60381
|
async function promptOneTimeTokenForHuman(input) {
|
|
60010
60382
|
const result = await promptTextEntry({
|
|
@@ -60013,10 +60385,10 @@ async function promptOneTimeTokenForHuman(input) {
|
|
|
60013
60385
|
allowBack: input.allowBack,
|
|
60014
60386
|
backLabel: input.backLabel,
|
|
60015
60387
|
requiredMessage: "Enter a one-time sign-in token.",
|
|
60016
|
-
validate: (value) => normalizeOptionalString$
|
|
60388
|
+
validate: (value) => normalizeOptionalString$15(value) ? null : "Enter a one-time sign-in token."
|
|
60017
60389
|
});
|
|
60018
60390
|
if (result.status !== "submitted") return result;
|
|
60019
|
-
const token = normalizeOptionalString$
|
|
60391
|
+
const token = normalizeOptionalString$15(result.value);
|
|
60020
60392
|
if (!token) throw new OneTimeTokenAuthError("missing_access_token", "one-time token is required");
|
|
60021
60393
|
return {
|
|
60022
60394
|
status: "submitted",
|
|
@@ -60313,7 +60685,7 @@ async function verifyOneTimeToken(input) {
|
|
|
60313
60685
|
if (normalizedMessage.includes("invalid")) throw new OneTimeTokenAuthError("invalid_token", "invalid one-time token; generate a new token and retry");
|
|
60314
60686
|
throw new OneTimeTokenAuthError("unknown", `one-time token verification failed: ${message}`);
|
|
60315
60687
|
}
|
|
60316
|
-
const accessToken = normalizeOptionalString$
|
|
60688
|
+
const accessToken = normalizeOptionalString$15(response.headers.get("set-auth-token"));
|
|
60317
60689
|
if (!accessToken) throw new OneTimeTokenAuthError("missing_access_token", "one-time token verified but auth response is missing set-auth-token");
|
|
60318
60690
|
return {
|
|
60319
60691
|
accessToken,
|
|
@@ -60348,8 +60720,8 @@ async function requestDeviceCode(input) {
|
|
|
60348
60720
|
return {
|
|
60349
60721
|
device_code: normalizeRequiredString(readStringField$2(payload, "device_code"), "missing device_code in device code response"),
|
|
60350
60722
|
user_code: normalizeRequiredString(readStringField$2(payload, "user_code"), "missing user_code in device code response"),
|
|
60351
|
-
verification_uri: normalizeOptionalString$
|
|
60352
|
-
verification_uri_complete: normalizeOptionalString$
|
|
60723
|
+
verification_uri: normalizeOptionalString$15(readStringField$2(payload, "verification_uri")) ?? void 0,
|
|
60724
|
+
verification_uri_complete: normalizeOptionalString$15(readStringField$2(payload, "verification_uri_complete")) ?? void 0,
|
|
60353
60725
|
expires_in: readNumberField(payload, "expires_in"),
|
|
60354
60726
|
interval: readNumberField(payload, "interval")
|
|
60355
60727
|
};
|
|
@@ -60371,17 +60743,17 @@ async function requestDeviceToken(input) {
|
|
|
60371
60743
|
ok: true,
|
|
60372
60744
|
data: {
|
|
60373
60745
|
access_token: normalizeRequiredString(readStringField$2(payload, "access_token"), "missing access_token in device token response"),
|
|
60374
|
-
token_type: normalizeOptionalString$
|
|
60746
|
+
token_type: normalizeOptionalString$15(readStringField$2(payload, "token_type")) ?? void 0,
|
|
60375
60747
|
expires_in: readNumberField(payload, "expires_in"),
|
|
60376
|
-
scope: normalizeOptionalString$
|
|
60748
|
+
scope: normalizeOptionalString$15(readStringField$2(payload, "scope")) ?? void 0
|
|
60377
60749
|
}
|
|
60378
60750
|
};
|
|
60379
60751
|
return {
|
|
60380
60752
|
ok: false,
|
|
60381
60753
|
error: {
|
|
60382
|
-
error: normalizeOptionalString$
|
|
60383
|
-
error_description: normalizeOptionalString$
|
|
60384
|
-
message: normalizeOptionalString$
|
|
60754
|
+
error: normalizeOptionalString$15(readStringField$2(payload, "error")) ?? void 0,
|
|
60755
|
+
error_description: normalizeOptionalString$15(readStringField$2(payload, "error_description")) ?? void 0,
|
|
60756
|
+
message: normalizeOptionalString$15(readStringField$2(payload, "message")) ?? void 0
|
|
60385
60757
|
},
|
|
60386
60758
|
status: response.status
|
|
60387
60759
|
};
|
|
@@ -60398,7 +60770,7 @@ async function pollForDeviceToken(input) {
|
|
|
60398
60770
|
deviceCode: input.deviceCode
|
|
60399
60771
|
});
|
|
60400
60772
|
if (result.ok) return result.data;
|
|
60401
|
-
const errorCode = normalizeOptionalString$
|
|
60773
|
+
const errorCode = normalizeOptionalString$15(result.error.error);
|
|
60402
60774
|
if (errorCode === "authorization_pending") {
|
|
60403
60775
|
input.onProgress?.({
|
|
60404
60776
|
event: "authorization_pending",
|
|
@@ -60428,7 +60800,7 @@ async function pollForDeviceToken(input) {
|
|
|
60428
60800
|
throw new DeviceAuthError("expired_token", "browser sign-in timed out; sign in again");
|
|
60429
60801
|
}
|
|
60430
60802
|
function resolveVerificationUrl(response, authBaseUrl) {
|
|
60431
|
-
const raw = normalizeOptionalString$
|
|
60803
|
+
const raw = normalizeOptionalString$15(response.verification_uri_complete) ?? normalizeOptionalString$15(response.verification_uri);
|
|
60432
60804
|
if (!raw) throw new Error("missing verification_uri in device code response");
|
|
60433
60805
|
const url = toAbsoluteUrl(raw, authBaseUrl);
|
|
60434
60806
|
if (!url.searchParams.has("user_code")) url.searchParams.set("user_code", response.user_code);
|
|
@@ -60469,16 +60841,16 @@ function clampInteger(value, min, max) {
|
|
|
60469
60841
|
return Math.max(min, Math.min(max, Math.floor(value)));
|
|
60470
60842
|
}
|
|
60471
60843
|
function resolveClientId(value) {
|
|
60472
|
-
const clientId = normalizeOptionalString$
|
|
60844
|
+
const clientId = normalizeOptionalString$15(value) ?? normalizeOptionalString$15(process.env.ATS_AUTH_CLIENT_ID) ?? DEFAULT_DEVICE_CLIENT_ID;
|
|
60473
60845
|
if (!DEVICE_CLIENT_ID_PATTERN.test(clientId)) throw new Error(`invalid client_id "${clientId}" (allowed: letters, numbers, . _ : -)`);
|
|
60474
60846
|
return clientId;
|
|
60475
60847
|
}
|
|
60476
60848
|
function normalizeRequiredString(value, message) {
|
|
60477
|
-
const normalized = normalizeOptionalString$
|
|
60849
|
+
const normalized = normalizeOptionalString$15(value);
|
|
60478
60850
|
if (!normalized) throw new Error(message);
|
|
60479
60851
|
return normalized;
|
|
60480
60852
|
}
|
|
60481
|
-
function normalizeOptionalString$
|
|
60853
|
+
function normalizeOptionalString$15(value) {
|
|
60482
60854
|
const normalized = String(value ?? "").trim();
|
|
60483
60855
|
return normalized.length > 0 ? normalized : null;
|
|
60484
60856
|
}
|
|
@@ -60506,13 +60878,13 @@ async function parseResponseJson(response) {
|
|
|
60506
60878
|
}
|
|
60507
60879
|
}
|
|
60508
60880
|
function extractApiErrorMessage(payload, status) {
|
|
60509
|
-
const errorDescription = normalizeOptionalString$
|
|
60881
|
+
const errorDescription = normalizeOptionalString$15(readStringField$2(payload, "error_description"));
|
|
60510
60882
|
if (errorDescription) return errorDescription;
|
|
60511
|
-
const detail = normalizeOptionalString$
|
|
60883
|
+
const detail = normalizeOptionalString$15(readStringField$2(payload, "detail"));
|
|
60512
60884
|
if (detail) return detail;
|
|
60513
|
-
const message = normalizeOptionalString$
|
|
60885
|
+
const message = normalizeOptionalString$15(readStringField$2(payload, "message"));
|
|
60514
60886
|
if (message) return message;
|
|
60515
|
-
const errorCode = normalizeOptionalString$
|
|
60887
|
+
const errorCode = normalizeOptionalString$15(readStringField$2(payload, "error"));
|
|
60516
60888
|
if (errorCode) return errorCode;
|
|
60517
60889
|
return `HTTP ${status}`;
|
|
60518
60890
|
}
|
|
@@ -60586,14 +60958,14 @@ function readAuthUserFromSessionPayload(payload) {
|
|
|
60586
60958
|
};
|
|
60587
60959
|
}
|
|
60588
60960
|
function resolveHumanLoginSuccessText(user) {
|
|
60589
|
-
const email = normalizeOptionalString$
|
|
60961
|
+
const email = normalizeOptionalString$15(user?.email);
|
|
60590
60962
|
if (email) return `✅ Welcome ${email}`;
|
|
60591
60963
|
return "✅ Signed in.";
|
|
60592
60964
|
}
|
|
60593
60965
|
function readOptionalStringField(input, key) {
|
|
60594
60966
|
const value = input[key];
|
|
60595
60967
|
if (typeof value !== "string") return;
|
|
60596
|
-
return normalizeOptionalString$
|
|
60968
|
+
return normalizeOptionalString$15(value) ?? void 0;
|
|
60597
60969
|
}
|
|
60598
60970
|
function toDeviceAuthError(error) {
|
|
60599
60971
|
if (error instanceof DeviceAuthError) return error;
|
|
@@ -60665,8 +61037,8 @@ const COMMAND_AUTH_ACTION_CANCEL = "__command_auth_cancel__";
|
|
|
60665
61037
|
async function evaluateCommandAuthentication(input) {
|
|
60666
61038
|
const authState = await getAuthSessionState({ validateRemote: true }).catch(() => null);
|
|
60667
61039
|
const session = authState?.session ?? null;
|
|
60668
|
-
const authBaseUrl = normalizeOptionalString$
|
|
60669
|
-
const email = normalizeOptionalString$
|
|
61040
|
+
const authBaseUrl = normalizeOptionalString$14(session?.authBaseUrl);
|
|
61041
|
+
const email = normalizeOptionalString$14(session?.user?.email);
|
|
60670
61042
|
const isCompatibleWithGateway = authState?.state === "valid" && session !== null && (!(input?.gatewayUrl && input.gatewayUrl.trim().length > 0) || canAttachAuthTokenToRequest(session, input.gatewayUrl));
|
|
60671
61043
|
return {
|
|
60672
61044
|
status: authState?.state === "valid" && session !== null && !isCompatibleWithGateway ? "mismatch" : authState?.state ?? "unknown",
|
|
@@ -60677,7 +61049,7 @@ async function evaluateCommandAuthentication(input) {
|
|
|
60677
61049
|
}
|
|
60678
61050
|
async function ensureCommandAuthenticationOrCancel(input) {
|
|
60679
61051
|
const currentState = getCurrentCommandCheckState();
|
|
60680
|
-
if (isCurrentCommandCheckScopeActive() && currentState.signIn && currentState.signIn.status === "valid" && currentState.signIn.checkedGatewayUrl === normalizeOptionalString$
|
|
61052
|
+
if (isCurrentCommandCheckScopeActive() && currentState.signIn && currentState.signIn.status === "valid" && currentState.signIn.checkedGatewayUrl === normalizeOptionalString$14(input.gatewayUrl)) return true;
|
|
60681
61053
|
const auth = input.evaluated ?? await evaluateCommandAuthentication({ gatewayUrl: input.gatewayUrl });
|
|
60682
61054
|
if (auth.status === "valid" && auth.session) return true;
|
|
60683
61055
|
const canPrompt = input.allowPrompt ?? input.runtime.interactive;
|
|
@@ -60727,12 +61099,12 @@ async function ensureCommandAuthenticationOrCancel(input) {
|
|
|
60727
61099
|
return false;
|
|
60728
61100
|
}
|
|
60729
61101
|
if (isCurrentCommandCheckScopeActive()) currentState.signIn = {
|
|
60730
|
-
checkedGatewayUrl: normalizeOptionalString$
|
|
61102
|
+
checkedGatewayUrl: normalizeOptionalString$14(input.gatewayUrl),
|
|
60731
61103
|
status: "valid"
|
|
60732
61104
|
};
|
|
60733
61105
|
return true;
|
|
60734
61106
|
}
|
|
60735
|
-
function normalizeOptionalString$
|
|
61107
|
+
function normalizeOptionalString$14(value) {
|
|
60736
61108
|
const normalized = String(value ?? "").trim();
|
|
60737
61109
|
return normalized.length > 0 ? normalized : null;
|
|
60738
61110
|
}
|
|
@@ -61029,7 +61401,7 @@ function formatStatusTextForHuman(value) {
|
|
|
61029
61401
|
const normalized = value.replaceAll("_", " ");
|
|
61030
61402
|
return normalized[0]?.toUpperCase() + normalized.slice(1);
|
|
61031
61403
|
}
|
|
61032
|
-
function normalizeOptionalString$
|
|
61404
|
+
function normalizeOptionalString$13(value) {
|
|
61033
61405
|
if (typeof value !== "string") return null;
|
|
61034
61406
|
const trimmed = value.trim();
|
|
61035
61407
|
return trimmed.length > 0 ? trimmed : null;
|
|
@@ -62103,8 +62475,8 @@ async function promptInteractiveCustomAgentAddDetails(input) {
|
|
|
62103
62475
|
status: "submitted",
|
|
62104
62476
|
value: {
|
|
62105
62477
|
dir: dirResult.value,
|
|
62106
|
-
id: normalizeOptionalString$
|
|
62107
|
-
idInput: normalizeOptionalString$
|
|
62478
|
+
id: normalizeOptionalString$13(idResult.value) ?? void 0,
|
|
62479
|
+
idInput: normalizeOptionalString$13(idResult.value) ?? void 0
|
|
62108
62480
|
}
|
|
62109
62481
|
};
|
|
62110
62482
|
}
|
|
@@ -62194,7 +62566,7 @@ async function promptRequiredInteractiveText(input) {
|
|
|
62194
62566
|
});
|
|
62195
62567
|
if (valueResult.status === "cancelled" || valueResult.status === "back") return valueResult;
|
|
62196
62568
|
if (valueResult.status !== "selected") continue;
|
|
62197
|
-
const normalizedValue = normalizeOptionalString$
|
|
62569
|
+
const normalizedValue = normalizeOptionalString$13(valueResult.value);
|
|
62198
62570
|
if (!normalizedValue) {
|
|
62199
62571
|
process.stderr.write(`${input.requiredMessage}\n`);
|
|
62200
62572
|
continue;
|
|
@@ -62777,7 +63149,7 @@ async function runAgentsEnable(input) {
|
|
|
62777
63149
|
handled: input.presentation === "handoff"
|
|
62778
63150
|
});
|
|
62779
63151
|
const explicitIds = normalizeAgentIds(input.agent ?? []);
|
|
62780
|
-
const explicitInstallId = normalizeOptionalString$
|
|
63152
|
+
const explicitInstallId = normalizeOptionalString$13(input.install);
|
|
62781
63153
|
validateBuiltinAgentSelectionInput({
|
|
62782
63154
|
all: input.all,
|
|
62783
63155
|
command: "enable",
|
|
@@ -62874,7 +63246,7 @@ async function runAgentsRepair(input) {
|
|
|
62874
63246
|
handled: input.presentation === "handoff"
|
|
62875
63247
|
});
|
|
62876
63248
|
const explicitIds = normalizeAgentIds(input.agent ?? []);
|
|
62877
|
-
const explicitInstallId = normalizeOptionalString$
|
|
63249
|
+
const explicitInstallId = normalizeOptionalString$13(input.install);
|
|
62878
63250
|
validateBuiltinAgentSelectionInput({
|
|
62879
63251
|
all: input.all,
|
|
62880
63252
|
command: "repair",
|
|
@@ -63534,11 +63906,11 @@ async function runAgentsCustomAdd(input) {
|
|
|
63534
63906
|
resolvedView: runtime.resolvedView,
|
|
63535
63907
|
command: "custom_add"
|
|
63536
63908
|
});
|
|
63537
|
-
const name = normalizeOptionalString$
|
|
63538
|
-
const dir = normalizeOptionalString$
|
|
63909
|
+
const name = normalizeOptionalString$13(input.name);
|
|
63910
|
+
const dir = normalizeOptionalString$13(input.dir);
|
|
63539
63911
|
if (!(name && dir)) throw new Error("agents.custom.invalid_argument: provide --name <name> and --dir <dir>");
|
|
63540
63912
|
if (!isAbsolute(dir)) throw new Error("agents.custom.invalid_argument: --dir must be an absolute path");
|
|
63541
|
-
const id = normalizeOptionalString$
|
|
63913
|
+
const id = normalizeOptionalString$13(input.id) ?? void 0;
|
|
63542
63914
|
const target = await addAgentCustomTarget({
|
|
63543
63915
|
name,
|
|
63544
63916
|
dir,
|
|
@@ -63578,8 +63950,8 @@ async function runAgentsCustomUpdate(input) {
|
|
|
63578
63950
|
});
|
|
63579
63951
|
const id = normalizeAgentId(input.id ?? "");
|
|
63580
63952
|
if (!id) throw new Error("agents.custom.invalid_argument: provide --id <id>");
|
|
63581
|
-
const name = normalizeOptionalString$
|
|
63582
|
-
const dir = normalizeOptionalString$
|
|
63953
|
+
const name = normalizeOptionalString$13(input.name) ?? void 0;
|
|
63954
|
+
const dir = normalizeOptionalString$13(input.dir) ?? void 0;
|
|
63583
63955
|
if (name === void 0 && dir === void 0) throw new Error("agents.custom.invalid_argument: provide at least one option (--name/--dir)");
|
|
63584
63956
|
if (dir && !isAbsolute(dir)) throw new Error("agents.custom.invalid_argument: --dir must be an absolute path");
|
|
63585
63957
|
const updated = await updateAgentCustomTarget({
|
|
@@ -64687,7 +65059,7 @@ async function waitForExecutionReadinessAfterBinding(input) {
|
|
|
64687
65059
|
requestContext: input.requestContext
|
|
64688
65060
|
});
|
|
64689
65061
|
if (isAgentExecutionReadyOrConnecting(latest.agentExecutionReadiness)) return latest;
|
|
64690
|
-
await sleep
|
|
65062
|
+
await sleep(EXECUTION_READINESS_AFTER_BINDING_RETRY_DELAY_MS);
|
|
64691
65063
|
}
|
|
64692
65064
|
return latest;
|
|
64693
65065
|
}
|
|
@@ -65288,9 +65660,9 @@ async function prepareAuthenticatedSpaceCommandContext(input) {
|
|
|
65288
65660
|
};
|
|
65289
65661
|
}
|
|
65290
65662
|
async function ensureSpaceCommandGatewayAuthenticationOrCancel(input) {
|
|
65291
|
-
const targetGatewayUrl = normalizeOptionalString$
|
|
65292
|
-
if (!targetGatewayUrl) return normalizeOptionalString$
|
|
65293
|
-
const authenticatedGatewayUrl = normalizeOptionalString$
|
|
65663
|
+
const targetGatewayUrl = normalizeOptionalString$12(input.gatewayUrl);
|
|
65664
|
+
if (!targetGatewayUrl) return normalizeOptionalString$12(input.authenticatedGatewayUrl);
|
|
65665
|
+
const authenticatedGatewayUrl = normalizeOptionalString$12(input.authenticatedGatewayUrl);
|
|
65294
65666
|
if (authenticatedGatewayUrl !== null && authenticatedGatewayUrl === targetGatewayUrl) return authenticatedGatewayUrl;
|
|
65295
65667
|
if (!await ensureHumanSpaceCommandAuthenticationOrCancel({
|
|
65296
65668
|
runtime: input.runtime,
|
|
@@ -65359,7 +65731,7 @@ function isValidSpaceId$1(space) {
|
|
|
65359
65731
|
function isProfileKindSupportedForSpaceCommand(profileKind) {
|
|
65360
65732
|
return profileKind === "human" || profileKind === "agent";
|
|
65361
65733
|
}
|
|
65362
|
-
function normalizeOptionalString$
|
|
65734
|
+
function normalizeOptionalString$12(value) {
|
|
65363
65735
|
const normalized = String(value ?? "").trim();
|
|
65364
65736
|
return normalized.length > 0 ? normalized : null;
|
|
65365
65737
|
}
|
|
@@ -65573,7 +65945,7 @@ function toErrorMessage$13(error) {
|
|
|
65573
65945
|
//#endregion
|
|
65574
65946
|
//#region src/space/command-http-errors.ts
|
|
65575
65947
|
const HTTP_STATUS_IN_TEXT_REGEX = /^HTTP\s+(\d{3}):/i;
|
|
65576
|
-
function normalizeOptionalString$
|
|
65948
|
+
function normalizeOptionalString$11(value) {
|
|
65577
65949
|
if (typeof value !== "string") return null;
|
|
65578
65950
|
const normalized = value.trim();
|
|
65579
65951
|
return normalized.length > 0 ? normalized : null;
|
|
@@ -65822,13 +66194,13 @@ function resolveKnownSpaceSortKey(space) {
|
|
|
65822
66194
|
};
|
|
65823
66195
|
}
|
|
65824
66196
|
function parseKnownSpaceTimestamp(value) {
|
|
65825
|
-
const normalized = normalizeOptionalString$
|
|
66197
|
+
const normalized = normalizeOptionalString$11(value);
|
|
65826
66198
|
if (!normalized) return null;
|
|
65827
66199
|
const timestamp = Date.parse(normalized);
|
|
65828
66200
|
return Number.isFinite(timestamp) ? timestamp : null;
|
|
65829
66201
|
}
|
|
65830
66202
|
function normalizeKnownSpaceSortName(value) {
|
|
65831
|
-
return normalizeOptionalString$
|
|
66203
|
+
return normalizeOptionalString$11(value)?.toLowerCase() ?? "untitled-space";
|
|
65832
66204
|
}
|
|
65833
66205
|
function normalizeKnownSpaceVisibilityScope(visibilityScope) {
|
|
65834
66206
|
return visibilityScope === "owner" ? "owner" : "profile";
|
|
@@ -65975,7 +66347,7 @@ function buildKnownSpaceDisplayProjection(input) {
|
|
|
65975
66347
|
});
|
|
65976
66348
|
}
|
|
65977
66349
|
function resolveKnownSpaceJoinedTimestamp(space) {
|
|
65978
|
-
return normalizeOptionalString$
|
|
66350
|
+
return normalizeOptionalString$11(space.lastJoinedAt) ?? resolveKnownSpaceLastSeenTimestamp(space.lastSeenTs);
|
|
65979
66351
|
}
|
|
65980
66352
|
function resolveKnownSpaceLastSeenTimestamp(value) {
|
|
65981
66353
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0xe8d4a51000) return null;
|
|
@@ -66066,7 +66438,7 @@ function resolveSpaceMemberJoinOnlyReason(candidate) {
|
|
|
66066
66438
|
if (candidate.controllerEnabled !== true || typeof candidate.agentControllerRef !== "string" || candidate.agentControllerRef.trim().length === 0) return "Not connected to a local agent on this device yet.";
|
|
66067
66439
|
if (candidate.localParticipationReadiness === "not_running") return "ATS Service is not running on this device.";
|
|
66068
66440
|
if (candidate.localParticipationReadiness === "not_installed") return "ATS Service is not installed on this device.";
|
|
66069
|
-
const reasonText = normalizeOptionalString$
|
|
66441
|
+
const reasonText = normalizeOptionalString$11(candidate.localParticipationReasonText);
|
|
66070
66442
|
if (reasonText) {
|
|
66071
66443
|
const sanitizedReasonText = sanitizeSingleLinePromptText(reasonText);
|
|
66072
66444
|
if (sanitizedReasonText) return sanitizedReasonText.endsWith(".") ? sanitizedReasonText : `${sanitizedReasonText}.`;
|
|
@@ -66098,7 +66470,7 @@ function formatSpaceMemberRecoveryNextAction(action) {
|
|
|
66098
66470
|
return `Use \`${formatAtsCliCommand(action.command)}\` to check the local reply path.`;
|
|
66099
66471
|
}
|
|
66100
66472
|
function resolveSpaceMemberTerminalProfileLabel(profileName) {
|
|
66101
|
-
return sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
66473
|
+
return sanitizeSingleLinePromptText(normalizeOptionalString$11(profileName)) || "This agent";
|
|
66102
66474
|
}
|
|
66103
66475
|
function resolveSpaceMemberTerminalLocalTargetLabel(input) {
|
|
66104
66476
|
const displayName = sanitizeSingleLinePromptText(input.displayName);
|
|
@@ -66152,8 +66524,8 @@ function formatKnownSpaceDeletedNoticeMessage(deletedNotices) {
|
|
|
66152
66524
|
}
|
|
66153
66525
|
function formatKnownSpaceDeletedNoticeLabel(item, resolvedView) {
|
|
66154
66526
|
const name = sanitizeSingleLinePromptText(item.spaceName) || shortenSpaceId(item.spaceId);
|
|
66155
|
-
const deletedByName = normalizeOptionalString$
|
|
66156
|
-
const deletedById = normalizeOptionalString$
|
|
66527
|
+
const deletedByName = normalizeOptionalString$11(item.deletedByProfileName);
|
|
66528
|
+
const deletedById = normalizeOptionalString$11(item.deletedByProfileId);
|
|
66157
66529
|
if (resolvedView === "human") return deletedByName ? `${name} (deleted by ${sanitizeSingleLinePromptText(deletedByName)})` : `${name} (deleted)`;
|
|
66158
66530
|
if (deletedByName && deletedById) return `${name} (deleted by ${sanitizeSingleLinePromptText(deletedByName)} · ${sanitizeSingleLinePromptText(deletedById)})`;
|
|
66159
66531
|
if (deletedByName) return `${name} (deleted by ${sanitizeSingleLinePromptText(deletedByName)})`;
|
|
@@ -66842,7 +67214,7 @@ function buildHumanKnownSpaceSearchText(input) {
|
|
|
66842
67214
|
formatSpaceDisplayValue(projection.spaceName, ""),
|
|
66843
67215
|
formatSpaceDisplayValue(projection.creatorProfileName, ""),
|
|
66844
67216
|
formatSpaceDisplayValue(projection.creatorProfileId, ""),
|
|
66845
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
67217
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(input.space.creatorOwnerUserId)),
|
|
66846
67218
|
formatSpaceDisplayValue(projection.availableViaProfileName, ""),
|
|
66847
67219
|
formatSpaceDisplayValue(projection.availableViaProfileId, ""),
|
|
66848
67220
|
formatSpaceDisplayValue(projection.creatorDisplayName, ""),
|
|
@@ -67240,15 +67612,15 @@ function requireReadableSpaceConfigList(result, operation) {
|
|
|
67240
67612
|
return result.items;
|
|
67241
67613
|
}
|
|
67242
67614
|
function filterKnownSpacesCreatedByProfile(input) {
|
|
67243
|
-
const profileId = normalizeOptionalString$
|
|
67615
|
+
const profileId = normalizeOptionalString$11(input.profileId);
|
|
67244
67616
|
if (!profileId) return [];
|
|
67245
67617
|
return input.known.filter((item) => {
|
|
67246
|
-
return (typeof item.creatorProfileId === "string" ? normalizeOptionalString$
|
|
67618
|
+
return (typeof item.creatorProfileId === "string" ? normalizeOptionalString$11(item.creatorProfileId) : null) === profileId;
|
|
67247
67619
|
});
|
|
67248
67620
|
}
|
|
67249
67621
|
async function resolveOwnedKnownSpacesForDelete(input) {
|
|
67250
|
-
const currentProfileId = normalizeOptionalString$
|
|
67251
|
-
const currentOwnerUserId = normalizeOptionalString$
|
|
67622
|
+
const currentProfileId = normalizeOptionalString$11(input.atsProfileId);
|
|
67623
|
+
const currentOwnerUserId = normalizeOptionalString$11(input.ownerUserId);
|
|
67252
67624
|
if (!currentProfileId) return [];
|
|
67253
67625
|
const owned = [];
|
|
67254
67626
|
for (const candidate of input.known) {
|
|
@@ -67326,21 +67698,21 @@ async function findKnownSpaceForDeleteBySpaceId(input) {
|
|
|
67326
67698
|
}
|
|
67327
67699
|
function classifyKnownSpaceOwnershipForDelete(input) {
|
|
67328
67700
|
const creatorKind = resolveMetaCreatorKind(input.item.creatorKind);
|
|
67329
|
-
const creatorProfileId = normalizeOptionalString$
|
|
67701
|
+
const creatorProfileId = normalizeOptionalString$11(input.item.creatorProfileId);
|
|
67330
67702
|
if (!creatorKind) return "unknown";
|
|
67331
67703
|
if (creatorKind === "system") return "foreign";
|
|
67332
67704
|
if (creatorKind === "human") {
|
|
67333
67705
|
if (!creatorProfileId) return "unknown";
|
|
67334
67706
|
return creatorProfileId === input.currentProfileId ? "owned" : "foreign";
|
|
67335
67707
|
}
|
|
67336
|
-
const creatorOwnerUserId = normalizeOptionalString$
|
|
67708
|
+
const creatorOwnerUserId = normalizeOptionalString$11(input.item.creatorOwnerUserId);
|
|
67337
67709
|
if (!(creatorOwnerUserId && input.currentOwnerUserId)) return "unknown";
|
|
67338
67710
|
return creatorOwnerUserId === input.currentOwnerUserId ? "owned" : "foreign";
|
|
67339
67711
|
}
|
|
67340
67712
|
function shouldHydrateCreatorProfileNameForDelete(input) {
|
|
67341
|
-
if (normalizeOptionalString$
|
|
67713
|
+
if (normalizeOptionalString$11(input.item.creatorProfileName)) return false;
|
|
67342
67714
|
const creatorKind = resolveMetaCreatorKind(input.item.creatorKind);
|
|
67343
|
-
const creatorProfileId = normalizeOptionalString$
|
|
67715
|
+
const creatorProfileId = normalizeOptionalString$11(input.item.creatorProfileId);
|
|
67344
67716
|
if (creatorKind === "human" && creatorProfileId === input.currentProfileId) return false;
|
|
67345
67717
|
return true;
|
|
67346
67718
|
}
|
|
@@ -67357,9 +67729,9 @@ async function hydrateKnownSpaceForDeleteFromMeta(input) {
|
|
|
67357
67729
|
const creatorProfileName = resolveMetaCreatorProfileName(meta.creator);
|
|
67358
67730
|
const creatorOwnerUserId = resolveMetaCreatorOwnerUserId(meta.creator);
|
|
67359
67731
|
const creatorKind = resolveMetaCreatorKind(meta.creator?.kind);
|
|
67360
|
-
const spaceName = typeof meta.name === "string" ? normalizeOptionalString$
|
|
67361
|
-
const spaceCreatedAt = typeof meta.createdAt === "string" ? normalizeOptionalString$
|
|
67362
|
-
const spaceUpdatedAt = typeof meta.updatedAt === "string" ? normalizeOptionalString$
|
|
67732
|
+
const spaceName = typeof meta.name === "string" ? normalizeOptionalString$11(meta.name) : null;
|
|
67733
|
+
const spaceCreatedAt = typeof meta.createdAt === "string" ? normalizeOptionalString$11(meta.createdAt) : null;
|
|
67734
|
+
const spaceUpdatedAt = typeof meta.updatedAt === "string" ? normalizeOptionalString$11(meta.updatedAt) : null;
|
|
67363
67735
|
return {
|
|
67364
67736
|
...input.item,
|
|
67365
67737
|
...spaceName === null ? {} : { name: spaceName },
|
|
@@ -67375,11 +67747,11 @@ async function hydrateKnownSpaceForDeleteFromMeta(input) {
|
|
|
67375
67747
|
}
|
|
67376
67748
|
}
|
|
67377
67749
|
function applyKnownSpaceDeleteCreatorFallback(input) {
|
|
67378
|
-
const creatorProfileName = normalizeOptionalString$
|
|
67379
|
-
const creatorOwnerUserId = normalizeOptionalString$
|
|
67380
|
-
const creatorProfileId = normalizeOptionalString$
|
|
67381
|
-
const nextCreatorProfileName = creatorProfileName ?? (creatorProfileId === input.currentProfileId ? normalizeOptionalString$
|
|
67382
|
-
const nextCreatorOwnerUserId = creatorOwnerUserId ?? normalizeOptionalString$
|
|
67750
|
+
const creatorProfileName = normalizeOptionalString$11(input.item.creatorProfileName);
|
|
67751
|
+
const creatorOwnerUserId = normalizeOptionalString$11(input.item.creatorOwnerUserId);
|
|
67752
|
+
const creatorProfileId = normalizeOptionalString$11(input.item.creatorProfileId);
|
|
67753
|
+
const nextCreatorProfileName = creatorProfileName ?? (creatorProfileId === input.currentProfileId ? normalizeOptionalString$11(input.currentProfileName) : null);
|
|
67754
|
+
const nextCreatorOwnerUserId = creatorOwnerUserId ?? normalizeOptionalString$11(input.currentOwnerUserId);
|
|
67383
67755
|
if (nextCreatorProfileName === creatorProfileName && nextCreatorOwnerUserId === creatorOwnerUserId) return input.item;
|
|
67384
67756
|
return {
|
|
67385
67757
|
...input.item,
|
|
@@ -67549,9 +67921,9 @@ function maybeEmitSpaceCacheMaintenanceNotice(input) {
|
|
|
67549
67921
|
function normalizeMetaForHistory(meta) {
|
|
67550
67922
|
const creatorProfileId = resolveMetaCreatorProfileId(meta.creator);
|
|
67551
67923
|
const creatorKind = resolveMetaCreatorKind(meta.creator?.kind);
|
|
67552
|
-
const spaceName = typeof meta.name === "string" ? normalizeOptionalString$
|
|
67553
|
-
const spaceCreatedAt = typeof meta.createdAt === "string" ? normalizeOptionalString$
|
|
67554
|
-
const spaceUpdatedAt = typeof meta.updatedAt === "string" ? normalizeOptionalString$
|
|
67924
|
+
const spaceName = typeof meta.name === "string" ? normalizeOptionalString$11(meta.name) : null;
|
|
67925
|
+
const spaceCreatedAt = typeof meta.createdAt === "string" ? normalizeOptionalString$11(meta.createdAt) : null;
|
|
67926
|
+
const spaceUpdatedAt = typeof meta.updatedAt === "string" ? normalizeOptionalString$11(meta.updatedAt) : null;
|
|
67555
67927
|
if (!(spaceName !== null || creatorProfileId !== null || creatorKind !== null || spaceCreatedAt !== null || spaceUpdatedAt !== null)) return null;
|
|
67556
67928
|
return {
|
|
67557
67929
|
...spaceName === null ? {} : { spaceName },
|
|
@@ -67563,19 +67935,19 @@ function normalizeMetaForHistory(meta) {
|
|
|
67563
67935
|
}
|
|
67564
67936
|
function resolveMetaCreatorProfileId(creator) {
|
|
67565
67937
|
if (!creator || typeof creator !== "object") return null;
|
|
67566
|
-
if (typeof creator.profileId === "string") return normalizeOptionalString$
|
|
67567
|
-
if (typeof creator.profile === "string") return normalizeOptionalString$
|
|
67938
|
+
if (typeof creator.profileId === "string") return normalizeOptionalString$11(creator.profileId);
|
|
67939
|
+
if (typeof creator.profile === "string") return normalizeOptionalString$11(creator.profile);
|
|
67568
67940
|
return null;
|
|
67569
67941
|
}
|
|
67570
67942
|
function resolveMetaCreatorProfileName(creator) {
|
|
67571
67943
|
if (!creator || typeof creator !== "object") return null;
|
|
67572
67944
|
if (typeof creator.profileName !== "string") return null;
|
|
67573
|
-
return normalizeOptionalString$
|
|
67945
|
+
return normalizeOptionalString$11(creator.profileName);
|
|
67574
67946
|
}
|
|
67575
67947
|
function resolveMetaCreatorOwnerUserId(creator) {
|
|
67576
67948
|
if (!creator || typeof creator !== "object") return null;
|
|
67577
67949
|
if (typeof creator.ownerUserId !== "string") return null;
|
|
67578
|
-
return normalizeOptionalString$
|
|
67950
|
+
return normalizeOptionalString$11(creator.ownerUserId);
|
|
67579
67951
|
}
|
|
67580
67952
|
function resolveMetaCreatorKind(kind) {
|
|
67581
67953
|
if (kind === "human" || kind === "agent" || kind === "system") return kind;
|
|
@@ -82055,18 +82427,18 @@ function normalizeSpaceJoinMembershipCandidate(value) {
|
|
|
82055
82427
|
profileKind,
|
|
82056
82428
|
alreadyJoined: candidate.alreadyJoined === true,
|
|
82057
82429
|
needsActivation: candidate.needsActivation === true,
|
|
82058
|
-
profileHandle: normalizeOptionalString$
|
|
82059
|
-
ownerProfileName: normalizeOptionalString$
|
|
82060
|
-
ownerUserId: normalizeOptionalString$
|
|
82061
|
-
ownerName: normalizeOptionalString$
|
|
82062
|
-
agentControllerRef: normalizeOptionalString$
|
|
82430
|
+
profileHandle: normalizeOptionalString$10(candidate.profileHandle),
|
|
82431
|
+
ownerProfileName: normalizeOptionalString$10(candidate.ownerProfileName),
|
|
82432
|
+
ownerUserId: normalizeOptionalString$10(candidate.ownerUserId),
|
|
82433
|
+
ownerName: normalizeOptionalString$10(candidate.ownerName),
|
|
82434
|
+
agentControllerRef: normalizeOptionalString$10(candidate.agentControllerRef),
|
|
82063
82435
|
controllerEnabled: candidate.controllerEnabled === true
|
|
82064
82436
|
};
|
|
82065
82437
|
}
|
|
82066
82438
|
function resolveSpaceJoinMembershipProfileKind(value) {
|
|
82067
82439
|
return value === "human" || value === "agent" ? value : null;
|
|
82068
82440
|
}
|
|
82069
|
-
function normalizeOptionalString$
|
|
82441
|
+
function normalizeOptionalString$10(value) {
|
|
82070
82442
|
return typeof value === "string" ? value : void 0;
|
|
82071
82443
|
}
|
|
82072
82444
|
function buildLocallyCreatedPendingSpaceJoinMembershipCandidate(profile) {
|
|
@@ -83209,7 +83581,7 @@ async function syncProfileSpaceHistoryForCreate(input) {
|
|
|
83209
83581
|
const gatewayHost = resolveGatewayHost(input.baseUrl);
|
|
83210
83582
|
if (!gatewayHost) return;
|
|
83211
83583
|
const normalizedMeta = input.meta ? normalizeMetaForHistory(input.meta) : null;
|
|
83212
|
-
const fallbackSpaceName = normalizeOptionalString$
|
|
83584
|
+
const fallbackSpaceName = normalizeOptionalString$11(input.fallbackSpaceName);
|
|
83213
83585
|
const historySpaceName = normalizedMeta?.spaceName === void 0 ? fallbackSpaceName : normalizedMeta.spaceName;
|
|
83214
83586
|
const requestContext = buildAtsRequestContextFromProfile({ atsProfile: input.atsProfile });
|
|
83215
83587
|
await upsertProfileSpaceHistory({
|
|
@@ -84032,7 +84404,7 @@ async function runSpaceList(input) {
|
|
|
84032
84404
|
});
|
|
84033
84405
|
}
|
|
84034
84406
|
function resolveSpaceListAccountIndexScope(input) {
|
|
84035
|
-
if (normalizeOptionalString$
|
|
84407
|
+
if (normalizeOptionalString$11(input.explicitProfile)) return "profile";
|
|
84036
84408
|
if (input.atsProfile.profileKind === "human" && input.atsProfile.isDefault === true) return "account";
|
|
84037
84409
|
return "profile";
|
|
84038
84410
|
}
|
|
@@ -84072,13 +84444,13 @@ function buildSpaceListProofPayload() {
|
|
|
84072
84444
|
}
|
|
84073
84445
|
async function runSpaceAddMembers(input) {
|
|
84074
84446
|
const hasExplicitBaseUrlInput = String(input.baseUrl ?? "").trim().length > 0;
|
|
84075
|
-
const explicitMemberIds = (input.members ?? []).map((memberId) => normalizeOptionalString$
|
|
84447
|
+
const explicitMemberIds = (input.members ?? []).map((memberId) => normalizeOptionalString$11(memberId)).filter((memberId) => Boolean(memberId));
|
|
84076
84448
|
if (input.all === true || explicitMemberIds.length > 0) validateSpaceMemberSelectionInput({
|
|
84077
84449
|
all: input.all === true,
|
|
84078
84450
|
command: resolveSpaceAddMembersSelectionCommand(input.mode ?? "profiles"),
|
|
84079
84451
|
explicitMemberIds
|
|
84080
84452
|
});
|
|
84081
|
-
const currentProfileId = normalizeOptionalString$
|
|
84453
|
+
const currentProfileId = normalizeOptionalString$11(input.profile) ?? getCurrentCommandCheckState().selectedProfile?.profile?.atsProfileId ?? null;
|
|
84082
84454
|
if (currentProfileId && explicitMemberIds.includes(currentProfileId) && input.allowCurrentProfileMember !== true) throw createSpaceAddMembersCurrentProfileGuideError({ profileId: currentProfileId });
|
|
84083
84455
|
const context = await prepareAuthenticatedSpaceCommandContext({
|
|
84084
84456
|
profile: input.profile,
|
|
@@ -84155,8 +84527,8 @@ async function runSpaceAddMembers(input) {
|
|
|
84155
84527
|
}
|
|
84156
84528
|
async function runSpaceRemoveMembers(input) {
|
|
84157
84529
|
const hasExplicitBaseUrlInput = String(input.baseUrl ?? "").trim().length > 0;
|
|
84158
|
-
const explicitMemberIds = (input.members ?? []).map((memberId) => normalizeOptionalString$
|
|
84159
|
-
const currentProfileId = normalizeOptionalString$
|
|
84530
|
+
const explicitMemberIds = (input.members ?? []).map((memberId) => normalizeOptionalString$11(memberId)).filter((memberId) => Boolean(memberId));
|
|
84531
|
+
const currentProfileId = normalizeOptionalString$11(input.profile) ?? getCurrentCommandCheckState().selectedProfile?.profile?.atsProfileId ?? null;
|
|
84160
84532
|
if (currentProfileId && explicitMemberIds.includes(currentProfileId)) throw createSpaceRemoveMembersCurrentProfileGuideError({ profileId: currentProfileId });
|
|
84161
84533
|
const context = await prepareAuthenticatedSpaceCommandContext({
|
|
84162
84534
|
profile: input.profile,
|
|
@@ -85244,7 +85616,7 @@ async function runSpaceDelete(input) {
|
|
|
85244
85616
|
if (atsProfile.profileKind !== "human") throw createSpaceDeleteHumanApprovalGuideError("space delete requires a human ATS profile.");
|
|
85245
85617
|
const atsProfileId = atsProfile.atsProfileId;
|
|
85246
85618
|
const accountContext = await resolveCurrentAtsAccountContext().catch(() => null);
|
|
85247
|
-
const ownerUserIdForDelete = normalizeOptionalString$
|
|
85619
|
+
const ownerUserIdForDelete = normalizeOptionalString$11(atsProfile.ownerUserId) ?? normalizeOptionalString$11(accountContext?.user?.id) ?? void 0;
|
|
85248
85620
|
for (;;) {
|
|
85249
85621
|
const targets = await resolveSpaceDeleteTargets({
|
|
85250
85622
|
atsProfile: {
|
|
@@ -85454,7 +85826,7 @@ async function deleteSpaceTargetWithCleanup(input) {
|
|
|
85454
85826
|
return true;
|
|
85455
85827
|
}
|
|
85456
85828
|
async function deleteSpaceWithHumanFallback(input) {
|
|
85457
|
-
const approvedAgentCreatorProfileId = input.target.creatorKind === "agent" ? normalizeOptionalString$
|
|
85829
|
+
const approvedAgentCreatorProfileId = input.target.creatorKind === "agent" ? normalizeOptionalString$11(input.target.creatorProfileId) ?? void 0 : void 0;
|
|
85458
85830
|
let nextDeletePassword = input.password;
|
|
85459
85831
|
let lastPasswordError = null;
|
|
85460
85832
|
for (let attempt = 0; attempt < MAX_DELETE_PASSWORD_PROMPT_ATTEMPTS; attempt += 1) try {
|
|
@@ -85589,7 +85961,7 @@ function isAuthUpstreamUnavailableError(input) {
|
|
|
85589
85961
|
function summarizeFailedDeleteTargets(failures) {
|
|
85590
85962
|
const MAX_VISIBLE = 3;
|
|
85591
85963
|
const names = failures.slice(0, MAX_VISIBLE).map((item) => {
|
|
85592
|
-
const label = normalizeOptionalString$
|
|
85964
|
+
const label = normalizeOptionalString$11(item.target.name);
|
|
85593
85965
|
if (label) return label;
|
|
85594
85966
|
return item.target.space;
|
|
85595
85967
|
});
|
|
@@ -86112,7 +86484,7 @@ async function resolveSpaceLeaveTarget(input) {
|
|
|
86112
86484
|
async function confirmSpaceLeave(input) {
|
|
86113
86485
|
if (!(input.allowPrompt && input.resolvedView === "human")) return "confirmed";
|
|
86114
86486
|
const confirmed = await confirm({
|
|
86115
|
-
message: `Leave space ${normalizeOptionalString$
|
|
86487
|
+
message: `Leave space ${normalizeOptionalString$11(input.target.name) ?? input.target.space}? You will stop seeing this space in your active list.`,
|
|
86116
86488
|
initialValue: false
|
|
86117
86489
|
});
|
|
86118
86490
|
if (isCancel(confirmed)) {
|
|
@@ -86314,7 +86686,7 @@ async function resolveSpaceMemberCandidatesForRemove(input) {
|
|
|
86314
86686
|
requestContext: buildAtsRequestContextFromProfile({ atsProfile: input.currentProfile }),
|
|
86315
86687
|
...input.password === void 0 ? {} : { spacePassword: input.password }
|
|
86316
86688
|
});
|
|
86317
|
-
const currentOwnerUserId = normalizeOptionalString$
|
|
86689
|
+
const currentOwnerUserId = normalizeOptionalString$11(input.currentOwnerUserId);
|
|
86318
86690
|
const creatorProfileIds = /* @__PURE__ */ new Set();
|
|
86319
86691
|
const allProfiles = await listAtsProfiles();
|
|
86320
86692
|
const localProfileById = new Map(allProfiles.map((profile) => [profile.atsProfileId, profile]));
|
|
@@ -86323,7 +86695,7 @@ async function resolveSpaceMemberCandidatesForRemove(input) {
|
|
|
86323
86695
|
for (const member of snapshotMembers) if (member.memberSource === "space_creator") creatorProfileIds.add(member.profileId);
|
|
86324
86696
|
const activeMembers = snapshotMembers.filter((member) => {
|
|
86325
86697
|
if (!currentOwnerUserId) return true;
|
|
86326
|
-
return normalizeOptionalString$
|
|
86698
|
+
return normalizeOptionalString$11(member.ownerUserId) === currentOwnerUserId;
|
|
86327
86699
|
}).filter((member) => member.profileId !== input.currentProfile.atsProfileId).filter((member) => member.memberSource !== "space_creator").map((member) => hydrateSpaceRemoveMemberCandidate({
|
|
86328
86700
|
candidate: toSpaceRemoveMemberCandidateFromSnapshot({
|
|
86329
86701
|
member,
|
|
@@ -86340,7 +86712,7 @@ async function resolveSpaceMemberCandidatesForRemove(input) {
|
|
|
86340
86712
|
const { profileKind } = profile;
|
|
86341
86713
|
if (profile.status !== "active" || !isSpaceMembershipProfileKind(profileKind)) continue;
|
|
86342
86714
|
if (profile.atsProfileId === input.currentProfile.atsProfileId) continue;
|
|
86343
|
-
if (currentOwnerUserId && normalizeOptionalString$
|
|
86715
|
+
if (currentOwnerUserId && normalizeOptionalString$11(profile.ownerUserId) !== currentOwnerUserId) continue;
|
|
86344
86716
|
explicitFallbackById.set(profile.atsProfileId, toSpaceRemoveMemberCandidateFromProfile({
|
|
86345
86717
|
...profile,
|
|
86346
86718
|
profileKind
|
|
@@ -86356,8 +86728,8 @@ function buildOwnerProfileNameByOwnerUserId(profiles) {
|
|
|
86356
86728
|
const ownerProfileMap = /* @__PURE__ */ new Map();
|
|
86357
86729
|
const activeHumanProfiles = profiles.filter((profile) => profile.status === "active").filter((profile) => profile.profileKind === "human");
|
|
86358
86730
|
for (const profile of activeHumanProfiles) {
|
|
86359
|
-
const ownerUserId = normalizeOptionalString$
|
|
86360
|
-
const profileName = normalizeOptionalString$
|
|
86731
|
+
const ownerUserId = normalizeOptionalString$11(profile.ownerUserId);
|
|
86732
|
+
const profileName = normalizeOptionalString$11(profile.profileName);
|
|
86361
86733
|
if (!(ownerUserId && profileName)) continue;
|
|
86362
86734
|
if (!ownerProfileMap.has(ownerUserId)) {
|
|
86363
86735
|
ownerProfileMap.set(ownerUserId, profileName);
|
|
@@ -86671,7 +87043,7 @@ async function applySpaceAddMembers(input) {
|
|
|
86671
87043
|
const alreadyMemberProfileIds = new Set(response.alreadyMemberIds);
|
|
86672
87044
|
const responseItemByProfileId = new Map(response.items.map((item) => [item.profileId, item]));
|
|
86673
87045
|
const lastJoinedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
86674
|
-
const spaceName = normalizeOptionalString$
|
|
87046
|
+
const spaceName = normalizeOptionalString$11(input.spaceName);
|
|
86675
87047
|
for (const candidate of selectedCandidates) {
|
|
86676
87048
|
const nextCandidate = hydrateSpaceMemberCandidateFromResponseItem({
|
|
86677
87049
|
candidate,
|
|
@@ -86714,14 +87086,14 @@ function hydrateSpaceMemberCandidateFromResponseItem(input) {
|
|
|
86714
87086
|
...input.candidate,
|
|
86715
87087
|
profileName: input.item.profileName,
|
|
86716
87088
|
profileKind: input.item.profileKind,
|
|
86717
|
-
ownerUserId: normalizeOptionalString$
|
|
86718
|
-
ownerName: normalizeOptionalString$
|
|
87089
|
+
ownerUserId: normalizeOptionalString$11(input.item.ownerUserId) ?? void 0,
|
|
87090
|
+
ownerName: normalizeOptionalString$11(input.item.ownerName) ?? void 0,
|
|
86719
87091
|
targetMentionLabel: resolvePrimaryMentionLabelFromSpaceMemberItem(input.item),
|
|
86720
|
-
...input.item.profileKind === "agent" ? { agentControllerRef: normalizeOptionalString$
|
|
87092
|
+
...input.item.profileKind === "agent" ? { agentControllerRef: normalizeOptionalString$11(input.item.agentControllerRef) ?? input.candidate.agentControllerRef } : {}
|
|
86721
87093
|
};
|
|
86722
87094
|
}
|
|
86723
87095
|
function resolvePrimaryMentionLabelFromSpaceMemberItem(item) {
|
|
86724
|
-
const mentionAlias = normalizeOptionalString$
|
|
87096
|
+
const mentionAlias = normalizeOptionalString$11(item.mentionAlias);
|
|
86725
87097
|
if (mentionAlias) return mentionAlias;
|
|
86726
87098
|
return resolveSingleSpaceMentionLabels({
|
|
86727
87099
|
mentionAlias,
|
|
@@ -87150,7 +87522,7 @@ async function persistSpaceAddMembersJoinNotices(input) {
|
|
|
87150
87522
|
function buildKnownMentionLabelByProfileId(members) {
|
|
87151
87523
|
const labelsByProfileId = /* @__PURE__ */ new Map();
|
|
87152
87524
|
for (const member of members) {
|
|
87153
|
-
const targetMentionLabel = normalizeOptionalString$
|
|
87525
|
+
const targetMentionLabel = normalizeOptionalString$11(member.targetMentionLabel);
|
|
87154
87526
|
if (targetMentionLabel) labelsByProfileId.set(member.profileId, targetMentionLabel);
|
|
87155
87527
|
}
|
|
87156
87528
|
return labelsByProfileId;
|
|
@@ -87290,9 +87662,9 @@ function buildHumanSpaceRemoveMemberCandidateSearchText(candidate) {
|
|
|
87290
87662
|
sanitizeSingleLinePromptText(candidate.profileId),
|
|
87291
87663
|
sanitizeSingleLinePromptText(candidate.profileName),
|
|
87292
87664
|
sanitizeSingleLinePromptText(candidate.profileKind),
|
|
87293
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
87294
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
87295
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
87665
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(candidate.profileHandle)),
|
|
87666
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(candidate.ownerName)),
|
|
87667
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(candidate.ownerUserId))
|
|
87296
87668
|
].filter((value) => typeof value === "string").join("\n");
|
|
87297
87669
|
}
|
|
87298
87670
|
function formatSpaceMemberCandidateLabel(candidate) {
|
|
@@ -87326,10 +87698,10 @@ function buildHumanSpaceMemberCandidateSearchText(candidate) {
|
|
|
87326
87698
|
sanitizeSingleLinePromptText(candidate.profileId),
|
|
87327
87699
|
sanitizeSingleLinePromptText(candidate.profileName),
|
|
87328
87700
|
sanitizeSingleLinePromptText(candidate.profileKind),
|
|
87329
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
87330
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
87331
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
87332
|
-
sanitizeSingleLinePromptText(normalizeOptionalString$
|
|
87701
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(candidate.ownerProfileName)),
|
|
87702
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(candidate.ownerName)),
|
|
87703
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(candidate.ownerUserId)),
|
|
87704
|
+
sanitizeSingleLinePromptText(normalizeOptionalString$11(candidate.agentControllerRef)),
|
|
87333
87705
|
...resolveSpaceMemberCandidateStatusBadges(candidate),
|
|
87334
87706
|
candidate.alreadyJoined ? "already in this space" : null,
|
|
87335
87707
|
candidate.needsActivation ? "needs mention setup" : null
|
|
@@ -87350,15 +87722,15 @@ function toSpaceRemoveMemberCandidateFromSnapshot(input) {
|
|
|
87350
87722
|
profileId: input.member.profileId,
|
|
87351
87723
|
profileName: input.member.profileName,
|
|
87352
87724
|
profileKind: input.member.profileKind,
|
|
87353
|
-
targetMentionLabel: normalizeOptionalString$
|
|
87354
|
-
ownerUserId: normalizeOptionalString$
|
|
87355
|
-
ownerName: normalizeOptionalString$
|
|
87356
|
-
creatorProfileId: input.member.memberSource === "space_creator" ? normalizeOptionalString$
|
|
87725
|
+
targetMentionLabel: normalizeOptionalString$11(input.targetMentionLabel),
|
|
87726
|
+
ownerUserId: normalizeOptionalString$11(input.member.ownerUserId),
|
|
87727
|
+
ownerName: normalizeOptionalString$11(input.member.ownerName),
|
|
87728
|
+
creatorProfileId: input.member.memberSource === "space_creator" ? normalizeOptionalString$11(input.member.profileId) : null
|
|
87357
87729
|
};
|
|
87358
87730
|
}
|
|
87359
87731
|
function hydrateSpaceRemoveMemberCandidate(input) {
|
|
87360
87732
|
if (input.candidate.profileHandle) return input.candidate;
|
|
87361
|
-
const profileHandle = normalizeOptionalString$
|
|
87733
|
+
const profileHandle = normalizeOptionalString$11(input.profile?.profileHandle);
|
|
87362
87734
|
if (!profileHandle) return input.candidate;
|
|
87363
87735
|
return {
|
|
87364
87736
|
...input.candidate,
|
|
@@ -87372,8 +87744,8 @@ function toSpaceRemoveMemberCandidateFromProfile(profile) {
|
|
|
87372
87744
|
profileName: profile.profileName,
|
|
87373
87745
|
profileKind: profile.profileKind,
|
|
87374
87746
|
targetMentionLabel: null,
|
|
87375
|
-
ownerUserId: normalizeOptionalString$
|
|
87376
|
-
ownerName: normalizeOptionalString$
|
|
87747
|
+
ownerUserId: normalizeOptionalString$11(profile.ownerUserId),
|
|
87748
|
+
ownerName: normalizeOptionalString$11(profile.ownerName),
|
|
87377
87749
|
creatorProfileId: null
|
|
87378
87750
|
};
|
|
87379
87751
|
}
|
|
@@ -87647,7 +88019,7 @@ async function deleteSpace(input) {
|
|
|
87647
88019
|
atsProfile: input.atsProfile,
|
|
87648
88020
|
spacePassword: input.password
|
|
87649
88021
|
});
|
|
87650
|
-
const approvedAgentCreatorProfileId = normalizeOptionalString$
|
|
88022
|
+
const approvedAgentCreatorProfileId = normalizeOptionalString$11(input.approvedAgentCreatorProfileId);
|
|
87651
88023
|
if (approvedAgentCreatorProfileId) headers["content-type"] = "application/json";
|
|
87652
88024
|
const response = await fetchSpaceRequestWithTimeout({
|
|
87653
88025
|
url: endpoint,
|
|
@@ -87930,7 +88302,7 @@ function ensureStartAgentIdentityPreflight(input) {
|
|
|
87930
88302
|
}
|
|
87931
88303
|
function shouldEnsureDefaultHumanProfile(input) {
|
|
87932
88304
|
if (input.resolvedView !== "human") return false;
|
|
87933
|
-
if (normalizeOptionalString$
|
|
88305
|
+
if (normalizeOptionalString$9(input.profileId) ?? normalizeOptionalString$9(input.profile)) return false;
|
|
87934
88306
|
return resolveCreateProfileInputFromArgs(input) === null;
|
|
87935
88307
|
}
|
|
87936
88308
|
function renderDefaultHumanProfileCard(input) {
|
|
@@ -88028,9 +88400,9 @@ async function resolveStartSelectedProfileFromArguments(input) {
|
|
|
88028
88400
|
return { handled: false };
|
|
88029
88401
|
}
|
|
88030
88402
|
function resolveExplicitStartProfile(input) {
|
|
88031
|
-
const explicitProfileId = normalizeOptionalString$
|
|
88403
|
+
const explicitProfileId = normalizeOptionalString$9(input.profileId);
|
|
88032
88404
|
if (explicitProfileId) return resolveAtsProfile({ atsProfileId: explicitProfileId });
|
|
88033
|
-
const explicitProfile = normalizeOptionalString$
|
|
88405
|
+
const explicitProfile = normalizeOptionalString$9(input.profile);
|
|
88034
88406
|
if (!explicitProfile) return Promise.resolve(null);
|
|
88035
88407
|
return resolveAtsProfile({ atsProfileId: explicitProfile }).catch(async () => {
|
|
88036
88408
|
const matched = (await listAtsProfiles()).find((profile) => profile.profileName.toLowerCase() === explicitProfile.toLowerCase());
|
|
@@ -88140,7 +88512,7 @@ async function resolveInteractiveStartProfileSearchSelection(input) {
|
|
|
88140
88512
|
}
|
|
88141
88513
|
function resolveCreateProfileInputFromArgs(input) {
|
|
88142
88514
|
const kind = parseStartProfileKind(input.kind);
|
|
88143
|
-
const profileName = normalizeOptionalString$
|
|
88515
|
+
const profileName = normalizeOptionalString$9(input.profileName) ?? (kind === "agent" ? normalizeOptionalString$9(input.agentName) : null);
|
|
88144
88516
|
if (!(kind && profileName)) return null;
|
|
88145
88517
|
return {
|
|
88146
88518
|
kind,
|
|
@@ -88148,11 +88520,11 @@ function resolveCreateProfileInputFromArgs(input) {
|
|
|
88148
88520
|
};
|
|
88149
88521
|
}
|
|
88150
88522
|
function inspectStartAgentIdentityInput(input) {
|
|
88151
|
-
if (normalizeOptionalString$
|
|
88152
|
-
const rawKind = normalizeOptionalString$
|
|
88523
|
+
if (normalizeOptionalString$9(input.profileId) ?? normalizeOptionalString$9(input.profile)) return { status: "valid" };
|
|
88524
|
+
const rawKind = normalizeOptionalString$9(input.kind);
|
|
88153
88525
|
const parsedKind = parseStartProfileKind(input.kind);
|
|
88154
|
-
const rawProfileName = normalizeOptionalString$
|
|
88155
|
-
const rawAgentName = normalizeOptionalString$
|
|
88526
|
+
const rawProfileName = normalizeOptionalString$9(input.profileName);
|
|
88527
|
+
const rawAgentName = normalizeOptionalString$9(input.agentName);
|
|
88156
88528
|
if (parsedKind === "human") return {
|
|
88157
88529
|
status: "error",
|
|
88158
88530
|
summary: "agent view cannot create human profiles. use --kind agent, or switch to human view."
|
|
@@ -88352,7 +88724,7 @@ function throwStartAgentIdentityGuide(input) {
|
|
|
88352
88724
|
function formatStartProfileKindLabel(profileKind) {
|
|
88353
88725
|
return profileKind === "agent" ? "AI agent" : "human";
|
|
88354
88726
|
}
|
|
88355
|
-
function normalizeOptionalString$
|
|
88727
|
+
function normalizeOptionalString$9(value) {
|
|
88356
88728
|
const normalized = String(value ?? "").trim();
|
|
88357
88729
|
return normalized.length > 0 ? normalized : null;
|
|
88358
88730
|
}
|
|
@@ -90955,7 +91327,7 @@ const CHOOSE_PROFILE = "__command_entry_choose_profile__";
|
|
|
90955
91327
|
const CREATE_PROFILE = "__command_entry_create_profile__";
|
|
90956
91328
|
const CANCEL_PROFILE = "__command_entry_cancel_profile__";
|
|
90957
91329
|
async function runSelectedProfileCheck(input) {
|
|
90958
|
-
const explicitProfileArg = normalizeOptionalString$
|
|
91330
|
+
const explicitProfileArg = normalizeOptionalString$8(input.context.profileArg);
|
|
90959
91331
|
const hasExplicitProfileArg = explicitProfileArg !== null;
|
|
90960
91332
|
const requiresConfirmation = input.requirement.mode === "confirm" && input.context.runtime.resolvedView === "human" && input.context.allowPrompt && !hasExplicitProfileArg;
|
|
90961
91333
|
const currentState = getCurrentCommandCheckState();
|
|
@@ -91128,7 +91500,7 @@ function ensureCurrentProfileIsVisible(input) {
|
|
|
91128
91500
|
function resolveProfileConfirmationMessage(entryName) {
|
|
91129
91501
|
return entryName === "space.join" ? SPACE_JOIN_PROFILE_SELECTION_MESSAGE : SPACE_COMMAND_PROFILE_SELECTION_MESSAGE;
|
|
91130
91502
|
}
|
|
91131
|
-
function normalizeOptionalString$
|
|
91503
|
+
function normalizeOptionalString$8(value) {
|
|
91132
91504
|
const normalized = String(value ?? "").trim();
|
|
91133
91505
|
return normalized.length > 0 ? normalized : null;
|
|
91134
91506
|
}
|
|
@@ -91758,7 +92130,7 @@ async function runCommandWithEntryChecks(input) {
|
|
|
91758
92130
|
allowPrompt: runtime.interactive,
|
|
91759
92131
|
environmentTarget,
|
|
91760
92132
|
gatewayUrl: normalizedGatewayUrl,
|
|
91761
|
-
profileArg: normalizeOptionalString$
|
|
92133
|
+
profileArg: normalizeOptionalString$7(input.profile),
|
|
91762
92134
|
jsonOutput
|
|
91763
92135
|
}),
|
|
91764
92136
|
jsonOutput
|
|
@@ -91767,7 +92139,7 @@ async function runCommandWithEntryChecks(input) {
|
|
|
91767
92139
|
finishCurrentCommandCheckScope();
|
|
91768
92140
|
}
|
|
91769
92141
|
}
|
|
91770
|
-
function normalizeOptionalString$
|
|
92142
|
+
function normalizeOptionalString$7(value) {
|
|
91771
92143
|
const normalized = String(value ?? "").trim();
|
|
91772
92144
|
return normalized.length > 0 ? normalized : null;
|
|
91773
92145
|
}
|
|
@@ -93716,7 +94088,7 @@ async function resolveAgentControllerPermissionModeInput(input) {
|
|
|
93716
94088
|
value: input.agentControllerPermissionModeInput
|
|
93717
94089
|
});
|
|
93718
94090
|
if (!agentControllerPermissionMode) return { hasAnyAgentControllerPermissionModeInput: false };
|
|
93719
|
-
const agentControllerRef = normalizeOptionalString$
|
|
94091
|
+
const agentControllerRef = normalizeOptionalString$6(input.agentControllerRef);
|
|
93720
94092
|
assertAgentControllerPermissionModeSupported({
|
|
93721
94093
|
agentControllerPermissionMode,
|
|
93722
94094
|
agentControllerRef,
|
|
@@ -93737,7 +94109,7 @@ async function resolveAgentControllerPermissionModeInput(input) {
|
|
|
93737
94109
|
};
|
|
93738
94110
|
}
|
|
93739
94111
|
function normalizeAgentControllerPermissionModeCliInput(input) {
|
|
93740
|
-
const raw = normalizeOptionalString$
|
|
94112
|
+
const raw = normalizeOptionalString$6(input.value);
|
|
93741
94113
|
if (!raw) return null;
|
|
93742
94114
|
const options = listAgentControllerPermissionModeOptions(input.agentControllerRef ? { agentControllerRef: input.agentControllerRef } : void 0);
|
|
93743
94115
|
for (const option of options) if (raw === option.value) return option.value;
|
|
@@ -93795,7 +94167,7 @@ const AGENT_CONTROLLER_PERMISSION_MODE_BY_CLI_VALUE = {
|
|
|
93795
94167
|
custom: "codex:customConfig",
|
|
93796
94168
|
customconfig: "codex:customConfig"
|
|
93797
94169
|
};
|
|
93798
|
-
function normalizeOptionalString$
|
|
94170
|
+
function normalizeOptionalString$6(value) {
|
|
93799
94171
|
const normalized = String(value ?? "").trim();
|
|
93800
94172
|
return normalized.length > 0 ? normalized : null;
|
|
93801
94173
|
}
|
|
@@ -94164,7 +94536,7 @@ async function runProfileShow(input) {
|
|
|
94164
94536
|
}
|
|
94165
94537
|
const presenter = createPresenter(runtime);
|
|
94166
94538
|
const allowPrompt = canUseInteractivePrompts(runtime);
|
|
94167
|
-
const explicitProfileId = normalizeOptionalString$
|
|
94539
|
+
const explicitProfileId = normalizeOptionalString$5(input.profile);
|
|
94168
94540
|
const visibleProfiles = explicitProfileId ? [] : await listVisibleProfilesForListByView(runtime.resolvedView);
|
|
94169
94541
|
const current = explicitProfileId ? null : await resolveCurrentProfileId({
|
|
94170
94542
|
profiles: visibleProfiles,
|
|
@@ -94646,7 +95018,7 @@ async function runProfileUpdate(input) {
|
|
|
94646
95018
|
}
|
|
94647
95019
|
const presenter = createPresenter(runtime);
|
|
94648
95020
|
const allowPrompt = canUseInteractivePrompts(runtime);
|
|
94649
|
-
const explicitProfileId = normalizeOptionalString$
|
|
95021
|
+
const explicitProfileId = normalizeOptionalString$5(input.profile);
|
|
94650
95022
|
const visibleProfiles = explicitProfileId ? [] : await listVisibleProfilesForListByView(runtime.resolvedView);
|
|
94651
95023
|
const current = explicitProfileId ? null : await resolveCurrentProfileId({
|
|
94652
95024
|
profiles: visibleProfiles,
|
|
@@ -94880,7 +95252,7 @@ function emitProfileUpdateCandidatesForHuman(input) {
|
|
|
94880
95252
|
}
|
|
94881
95253
|
}
|
|
94882
95254
|
async function resolveProfileUpdatePayload(input) {
|
|
94883
|
-
const profileName = normalizeOptionalString$
|
|
95255
|
+
const profileName = normalizeOptionalString$5(input.profileName);
|
|
94884
95256
|
const explicitAgentController = await resolveExplicitAgentControllerPatchForProfile({
|
|
94885
95257
|
agentController: input.agentController,
|
|
94886
95258
|
agentControllerConversationId: input.agentControllerConversationId,
|
|
@@ -94925,7 +95297,7 @@ async function resolveProfileUpdatePayload(input) {
|
|
|
94925
95297
|
}
|
|
94926
95298
|
function resolveExplicitWorkspacePatchForProfile(input) {
|
|
94927
95299
|
const normalizedMode = normalizeWorkspaceModeInput(input.workspaceMode);
|
|
94928
|
-
const normalizedWorkspacePath = normalizeOptionalString$
|
|
95300
|
+
const normalizedWorkspacePath = normalizeOptionalString$5(input.workspacePath);
|
|
94929
95301
|
if (!(normalizedMode || normalizedWorkspacePath)) return null;
|
|
94930
95302
|
if (input.profile.profileKind !== "agent") throw new Error("Workspace can only be configured for agent profiles.");
|
|
94931
95303
|
if (!normalizedMode) throw new Error("--workspace-path can only be used with --workspace-mode custom.");
|
|
@@ -94958,7 +95330,7 @@ function resolveExplicitModelSelectionPatchForProfile(input) {
|
|
|
94958
95330
|
};
|
|
94959
95331
|
}
|
|
94960
95332
|
async function resolveExplicitAgentControllerPermissionModePatchForProfile(input) {
|
|
94961
|
-
if (!normalizeOptionalString$
|
|
95333
|
+
if (!normalizeOptionalString$5(input.agentControllerPermissionModeInput)) return null;
|
|
94962
95334
|
if (input.profile.profileKind !== "agent") throw new Error("Agent Controller Permission Mode can only be configured for agent profiles.");
|
|
94963
95335
|
const currentBinding = input.agentControllerRef ? null : await resolveAgentProfilePrimaryAgentControllerReport({ profile: input.profile });
|
|
94964
95336
|
const agentControllerRef = input.agentControllerRef ?? currentBinding?.agentControllerRef ?? null;
|
|
@@ -94977,8 +95349,8 @@ async function resolveExplicitAgentControllerPermissionModePatchForProfile(input
|
|
|
94977
95349
|
};
|
|
94978
95350
|
}
|
|
94979
95351
|
async function resolveExplicitAgentControllerPatchForProfile(input) {
|
|
94980
|
-
const agentController = normalizeOptionalString$
|
|
94981
|
-
const agentControllerConversationId = normalizeOptionalString$
|
|
95352
|
+
const agentController = normalizeOptionalString$5(input.agentController);
|
|
95353
|
+
const agentControllerConversationId = normalizeOptionalString$5(input.agentControllerConversationId);
|
|
94982
95354
|
if (!(agentController || agentControllerConversationId)) return null;
|
|
94983
95355
|
if (input.profile.profileKind !== "agent") throw new Error("Agent controller can only be configured for agent profiles.");
|
|
94984
95356
|
if (!agentController) throw new Error("--agent-controller-conversation-id requires --agent-controller.");
|
|
@@ -94992,7 +95364,7 @@ async function resolveExplicitAgentControllerPatchForProfile(input) {
|
|
|
94992
95364
|
};
|
|
94993
95365
|
}
|
|
94994
95366
|
async function applyAgentProfileControllerBinding(input) {
|
|
94995
|
-
const agentControllerRef = normalizeOptionalString$
|
|
95367
|
+
const agentControllerRef = normalizeOptionalString$5(input.agentControllerRef);
|
|
94996
95368
|
const hasModelSelectionPatch = input.modelId !== void 0;
|
|
94997
95369
|
if (!(agentControllerRef || hasModelSelectionPatch)) return;
|
|
94998
95370
|
if (input.profile.profileKind !== "agent") throw new Error("Agent controller can only be configured for agent profiles.");
|
|
@@ -95125,7 +95497,7 @@ async function promptWorkspacePayload(profile) {
|
|
|
95125
95497
|
});
|
|
95126
95498
|
if (workspacePath.status === "cancelled") return { status: "cancelled" };
|
|
95127
95499
|
if (workspacePath.status === "back") continue;
|
|
95128
|
-
const customWorkspacePath = normalizeOptionalString$
|
|
95500
|
+
const customWorkspacePath = normalizeOptionalString$5(workspacePath.value);
|
|
95129
95501
|
if (!customWorkspacePath) throw new Error("Custom workspace path is required.");
|
|
95130
95502
|
return {
|
|
95131
95503
|
status: "submitted",
|
|
@@ -95216,7 +95588,7 @@ async function promptProfileNamePayload(currentProfileName) {
|
|
|
95216
95588
|
});
|
|
95217
95589
|
if (nextName.status === "cancelled") return { status: "cancelled" };
|
|
95218
95590
|
if (nextName.status === "back") return { status: "back" };
|
|
95219
|
-
const profileName = normalizeOptionalString$
|
|
95591
|
+
const profileName = normalizeOptionalString$5(nextName.value);
|
|
95220
95592
|
if (!profileName) throw new Error("profileName is required");
|
|
95221
95593
|
return {
|
|
95222
95594
|
status: "submitted",
|
|
@@ -95472,11 +95844,11 @@ function buildProfileSearchItem(input) {
|
|
|
95472
95844
|
function buildProfileSearchText(profile) {
|
|
95473
95845
|
return [
|
|
95474
95846
|
profile.atsProfileId,
|
|
95475
|
-
normalizeOptionalString$
|
|
95847
|
+
normalizeOptionalString$5(profile.profileName),
|
|
95476
95848
|
profile.profileKind,
|
|
95477
|
-
normalizeOptionalString$
|
|
95478
|
-
normalizeOptionalString$
|
|
95479
|
-
normalizeOptionalString$
|
|
95849
|
+
normalizeOptionalString$5(profile.ownerUserId),
|
|
95850
|
+
normalizeOptionalString$5(profile.ownerName),
|
|
95851
|
+
normalizeOptionalString$5(profile.source)
|
|
95480
95852
|
].filter((value) => typeof value === "string").join("\n");
|
|
95481
95853
|
}
|
|
95482
95854
|
function resolveProfileSelectLabel(input) {
|
|
@@ -95527,7 +95899,7 @@ function normalizeProfileDisplayName(profile) {
|
|
|
95527
95899
|
}
|
|
95528
95900
|
function normalizeAgentControllerArgumentInput(input) {
|
|
95529
95901
|
const agentController = String(input.agentController ?? "").trim();
|
|
95530
|
-
const agentControllerConversationId = normalizeOptionalString$
|
|
95902
|
+
const agentControllerConversationId = normalizeOptionalString$5(input.agentControllerConversationId);
|
|
95531
95903
|
const hasControllerEnabled = typeof input.controllerEnabled === "boolean";
|
|
95532
95904
|
const hasAnyAgentControllerInput = Boolean(agentController) || Boolean(agentControllerConversationId) || hasControllerEnabled;
|
|
95533
95905
|
return {
|
|
@@ -95734,7 +96106,7 @@ function resolveProfileUpdateCommandExamples() {
|
|
|
95734
96106
|
function toProfileActionGuideExamples(_input) {
|
|
95735
96107
|
return {};
|
|
95736
96108
|
}
|
|
95737
|
-
function normalizeOptionalString$
|
|
96109
|
+
function normalizeOptionalString$5(value) {
|
|
95738
96110
|
const normalized = String(value ?? "").trim();
|
|
95739
96111
|
return normalized.length > 0 ? normalized : null;
|
|
95740
96112
|
}
|
|
@@ -95745,8 +96117,8 @@ function normalizeWorkspaceModeInput(value) {
|
|
|
95745
96117
|
throw new Error("--workspace-mode must be ats-managed|custom");
|
|
95746
96118
|
}
|
|
95747
96119
|
function normalizeModelSelectionInput(input) {
|
|
95748
|
-
const modelId = normalizeOptionalString$
|
|
95749
|
-
const reasoningLevel = normalizeOptionalString$
|
|
96120
|
+
const modelId = normalizeOptionalString$5(input.model);
|
|
96121
|
+
const reasoningLevel = normalizeOptionalString$5(input.reasoningEffort);
|
|
95750
96122
|
if (!(modelId || reasoningLevel)) return { hasAnyModelSelectionInput: false };
|
|
95751
96123
|
if (!modelId) throw new Error("--reasoning-effort requires --model.");
|
|
95752
96124
|
return {
|
|
@@ -96782,10 +97154,10 @@ function resolveDaemonDispatchJournalEvidence(dispatchId) {
|
|
|
96782
97154
|
};
|
|
96783
97155
|
}
|
|
96784
97156
|
async function resolveDispatchTraceSelection(input) {
|
|
96785
|
-
const dispatchSelector = normalizeOptionalString$
|
|
96786
|
-
const sourceSignalSelector = normalizeOptionalString$
|
|
96787
|
-
const clientMessageSelector = normalizeOptionalString$
|
|
96788
|
-
const targetProfileSelector = normalizeOptionalString$
|
|
97157
|
+
const dispatchSelector = normalizeOptionalString$4(input.dispatchId);
|
|
97158
|
+
const sourceSignalSelector = normalizeOptionalString$4(input.sourceSignalId);
|
|
97159
|
+
const clientMessageSelector = normalizeOptionalString$4(input.clientMessageId);
|
|
97160
|
+
const targetProfileSelector = normalizeOptionalString$4(input.targetProfileId);
|
|
96789
97161
|
if (Number(dispatchSelector !== null) + Number(sourceSignalSelector !== null) + Number(clientMessageSelector !== null) !== 1) throw new Error("exactly one of dispatchId, sourceSignalId, or clientMessageId is required");
|
|
96790
97162
|
if (dispatchSelector) return {
|
|
96791
97163
|
dispatchId: dispatchSelector,
|
|
@@ -97283,7 +97655,7 @@ function parenthesizedDetail(value, label) {
|
|
|
97283
97655
|
return detail.length > 0 ? detail : null;
|
|
97284
97656
|
}
|
|
97285
97657
|
async function resolveServiceTraceActorProfile(input) {
|
|
97286
|
-
if (normalizeOptionalString$
|
|
97658
|
+
if (normalizeOptionalString$4(input.explicitProfileId) || !canUseInteractivePrompts(input.runtime)) return input.actingProfile;
|
|
97287
97659
|
while (true) {
|
|
97288
97660
|
const selectedAction = await select({
|
|
97289
97661
|
message: `Use ${input.actingProfile.profileName} (${input.actingProfile.atsProfileId}) to read this dispatch trace?`,
|
|
@@ -98107,7 +98479,7 @@ function truncateText(text, maxLength) {
|
|
|
98107
98479
|
if (text.length <= maxLength) return text;
|
|
98108
98480
|
return `${text.slice(0, maxLength)}...`;
|
|
98109
98481
|
}
|
|
98110
|
-
function normalizeOptionalString$
|
|
98482
|
+
function normalizeOptionalString$4(value) {
|
|
98111
98483
|
const normalized = String(value ?? "").trim();
|
|
98112
98484
|
return normalized.length > 0 ? normalized : null;
|
|
98113
98485
|
}
|
|
@@ -98959,6 +99331,289 @@ function readErrorName(error) {
|
|
|
98959
99331
|
return error instanceof Error && error.name.trim().length > 0 ? error.name : null;
|
|
98960
99332
|
}
|
|
98961
99333
|
|
|
99334
|
+
//#endregion
|
|
99335
|
+
//#region src/commands/setup-command-lock.ts
|
|
99336
|
+
const SETUP_COMMAND_LOCK_PROFILE = "setup";
|
|
99337
|
+
const SETUP_COMMAND_LOCK_KEY = "setup-command";
|
|
99338
|
+
const SETUP_GLOBAL_DEADLINE_MS = 900 * 1e3;
|
|
99339
|
+
const SETUP_TAKEOVER_WINDOW_MS = 1e4;
|
|
99340
|
+
const SETUP_TAKEOVER_POLL_MS = 250;
|
|
99341
|
+
const SETUP_DEADLINE_SUPPORT_CODE = "setup.deadline_exceeded";
|
|
99342
|
+
const SETUP_SUPERSEDED_SUPPORT_CODE = "setup.superseded";
|
|
99343
|
+
async function withSetupCommandLock(input) {
|
|
99344
|
+
const acquisition = await acquireSetupCommandLockWithTakeover({
|
|
99345
|
+
lockMeta: input.lockMeta,
|
|
99346
|
+
startSession: input.startSession
|
|
99347
|
+
});
|
|
99348
|
+
if (acquisition.status === "contended") throw buildSetupLockContentionError({
|
|
99349
|
+
contention: acquisition,
|
|
99350
|
+
view: input.view
|
|
99351
|
+
});
|
|
99352
|
+
const { lock } = acquisition;
|
|
99353
|
+
const standDown = installSetupStandDownHandler({
|
|
99354
|
+
lock,
|
|
99355
|
+
view: input.view
|
|
99356
|
+
});
|
|
99357
|
+
const deadline = createSetupGlobalDeadline({ onExpire: () => handleSetupGlobalDeadlineExpiry({
|
|
99358
|
+
lock,
|
|
99359
|
+
view: input.view
|
|
99360
|
+
}) });
|
|
99361
|
+
deadline.arm();
|
|
99362
|
+
try {
|
|
99363
|
+
return await runWithHeldLock({
|
|
99364
|
+
lock,
|
|
99365
|
+
run: input.run,
|
|
99366
|
+
releaseContext: {
|
|
99367
|
+
atsProfileId: SETUP_COMMAND_LOCK_PROFILE,
|
|
99368
|
+
component: "setup_command",
|
|
99369
|
+
lockKey: SETUP_COMMAND_LOCK_KEY
|
|
99370
|
+
}
|
|
99371
|
+
});
|
|
99372
|
+
} finally {
|
|
99373
|
+
deadline.disarm();
|
|
99374
|
+
standDown.remove();
|
|
99375
|
+
}
|
|
99376
|
+
}
|
|
99377
|
+
async function acquireSetupCommandLockWithTakeover(input) {
|
|
99378
|
+
const deps = {
|
|
99379
|
+
...defaultTakeoverDeps(),
|
|
99380
|
+
...input.deps
|
|
99381
|
+
};
|
|
99382
|
+
const first = await deps.tryAcquire(input.lockMeta);
|
|
99383
|
+
if (first.ok) return {
|
|
99384
|
+
lock: first.lock,
|
|
99385
|
+
status: "acquired"
|
|
99386
|
+
};
|
|
99387
|
+
const lockError = first.error;
|
|
99388
|
+
const pid = resolveLockHolderPid(lockError);
|
|
99389
|
+
const startedAtLabel = resolveLockStartedAtLabel(lockError);
|
|
99390
|
+
const contendedBase = {
|
|
99391
|
+
lockError,
|
|
99392
|
+
pid,
|
|
99393
|
+
startedAtLabel
|
|
99394
|
+
};
|
|
99395
|
+
if (!(normalizeOptionalString$3(input.startSession) !== null && pid !== null && pid !== deps.selfPid && deps.probePid(pid) === "alive")) return {
|
|
99396
|
+
status: "contended",
|
|
99397
|
+
...contendedBase,
|
|
99398
|
+
takeoverAttempted: false
|
|
99399
|
+
};
|
|
99400
|
+
if (deps.sendTerm(pid) === "not_permitted") return {
|
|
99401
|
+
status: "contended",
|
|
99402
|
+
...contendedBase,
|
|
99403
|
+
takeoverAttempted: true
|
|
99404
|
+
};
|
|
99405
|
+
let lastError = lockError;
|
|
99406
|
+
const until = deps.now() + deps.takeoverWindowMs;
|
|
99407
|
+
while (deps.now() < until) {
|
|
99408
|
+
const retry = await deps.tryAcquire(input.lockMeta);
|
|
99409
|
+
if (retry.ok) return {
|
|
99410
|
+
lock: retry.lock,
|
|
99411
|
+
status: "acquired"
|
|
99412
|
+
};
|
|
99413
|
+
lastError = retry.error;
|
|
99414
|
+
await deps.sleep(deps.pollIntervalMs);
|
|
99415
|
+
}
|
|
99416
|
+
const finalTry = await deps.tryAcquire(input.lockMeta);
|
|
99417
|
+
if (finalTry.ok) return {
|
|
99418
|
+
lock: finalTry.lock,
|
|
99419
|
+
status: "acquired"
|
|
99420
|
+
};
|
|
99421
|
+
return {
|
|
99422
|
+
status: "contended",
|
|
99423
|
+
lockError: finalTry.ok ? lastError : finalTry.error,
|
|
99424
|
+
pid,
|
|
99425
|
+
startedAtLabel,
|
|
99426
|
+
takeoverAttempted: true
|
|
99427
|
+
};
|
|
99428
|
+
}
|
|
99429
|
+
function buildSetupLockContentionError(input) {
|
|
99430
|
+
if (input.view === "agent") return input.contention.lockError;
|
|
99431
|
+
return new Error(buildHumanSetupLockLine(input.contention));
|
|
99432
|
+
}
|
|
99433
|
+
function buildHumanSetupLockLine(contention) {
|
|
99434
|
+
const descriptorParts = [];
|
|
99435
|
+
if (contention.startedAtLabel) descriptorParts.push(`started ${contention.startedAtLabel}`);
|
|
99436
|
+
if (contention.pid !== null) descriptorParts.push(`pid ${contention.pid}`);
|
|
99437
|
+
return `Another ATS setup${descriptorParts.length > 0 ? ` (${descriptorParts.join(", ")})` : ""} ${contention.takeoverAttempted ? "did not stop after ATS asked it to stand down" : "is still running"} on this computer. ${contention.pid === null ? "Close that Terminal window, then run this command again." : `Close that Terminal window, or run \`kill ${contention.pid}\`, then run this command again.`}`;
|
|
99438
|
+
}
|
|
99439
|
+
function createSetupGlobalDeadline(input) {
|
|
99440
|
+
const clock = input.clock ?? realDeadlineClock;
|
|
99441
|
+
const deadlineMs = input.deadlineMs ?? SETUP_GLOBAL_DEADLINE_MS;
|
|
99442
|
+
let handle = null;
|
|
99443
|
+
return {
|
|
99444
|
+
arm() {
|
|
99445
|
+
if (handle !== null) return;
|
|
99446
|
+
handle = clock.setTimer(() => {
|
|
99447
|
+
handle = null;
|
|
99448
|
+
input.onExpire();
|
|
99449
|
+
}, deadlineMs);
|
|
99450
|
+
},
|
|
99451
|
+
disarm() {
|
|
99452
|
+
if (handle === null) return;
|
|
99453
|
+
clock.clearTimer(handle);
|
|
99454
|
+
handle = null;
|
|
99455
|
+
}
|
|
99456
|
+
};
|
|
99457
|
+
}
|
|
99458
|
+
function handleSetupGlobalDeadlineExpiry(input) {
|
|
99459
|
+
const deadlineMs = input.deadlineMs ?? SETUP_GLOBAL_DEADLINE_MS;
|
|
99460
|
+
const message = `ATS setup did not finish within ${Math.max(1, Math.round(deadlineMs / 6e4))} minutes on this computer and was stopped. This computer's setup lock has been released. Copy a fresh setup command from ATS Web and run setup again.`;
|
|
99461
|
+
runSafely(() => (input.releaseLockSync ?? defaultReleaseLockSync)(input.lock.path));
|
|
99462
|
+
runSafely(() => {
|
|
99463
|
+
if (input.view === "agent") {
|
|
99464
|
+
(input.emitAgent ?? defaultEmitAgent)({
|
|
99465
|
+
code: SETUP_DEADLINE_SUPPORT_CODE,
|
|
99466
|
+
message,
|
|
99467
|
+
type: "error"
|
|
99468
|
+
});
|
|
99469
|
+
return;
|
|
99470
|
+
}
|
|
99471
|
+
(input.emitHuman ?? defaultEmitErrorLine)(`error: ${message} (support code: ${SETUP_DEADLINE_SUPPORT_CODE})`);
|
|
99472
|
+
});
|
|
99473
|
+
(input.exit ?? defaultExit)(1);
|
|
99474
|
+
}
|
|
99475
|
+
function installSetupStandDownHandler(input) {
|
|
99476
|
+
const message = "ATS setup was asked to stop and has released this computer's setup lock. You can close this window.";
|
|
99477
|
+
const handler = () => {
|
|
99478
|
+
runSafely(() => (input.releaseLockSync ?? defaultReleaseLockSync)(input.lock.path));
|
|
99479
|
+
runSafely(() => {
|
|
99480
|
+
if (input.view === "agent") {
|
|
99481
|
+
(input.emitAgent ?? defaultEmitAgent)({
|
|
99482
|
+
code: SETUP_SUPERSEDED_SUPPORT_CODE,
|
|
99483
|
+
message,
|
|
99484
|
+
type: "info"
|
|
99485
|
+
});
|
|
99486
|
+
return;
|
|
99487
|
+
}
|
|
99488
|
+
(input.emitHuman ?? defaultEmitOutLine)(message);
|
|
99489
|
+
});
|
|
99490
|
+
(input.exit ?? defaultExit)(0);
|
|
99491
|
+
};
|
|
99492
|
+
const register = input.register ?? ((h) => process$1.once("SIGTERM", h));
|
|
99493
|
+
const unregister = input.unregister ?? ((h) => {
|
|
99494
|
+
process$1.removeListener("SIGTERM", h);
|
|
99495
|
+
});
|
|
99496
|
+
register(handler);
|
|
99497
|
+
return { remove() {
|
|
99498
|
+
unregister(handler);
|
|
99499
|
+
} };
|
|
99500
|
+
}
|
|
99501
|
+
const realDeadlineClock = {
|
|
99502
|
+
clearTimer: (handle) => {
|
|
99503
|
+
clearTimeout(handle);
|
|
99504
|
+
},
|
|
99505
|
+
setTimer: (callback, ms) => setTimeout(callback, ms)
|
|
99506
|
+
};
|
|
99507
|
+
function defaultTakeoverDeps() {
|
|
99508
|
+
return {
|
|
99509
|
+
now: () => Date.now(),
|
|
99510
|
+
pollIntervalMs: SETUP_TAKEOVER_POLL_MS,
|
|
99511
|
+
probePid: defaultProbePid,
|
|
99512
|
+
selfPid: process$1.pid,
|
|
99513
|
+
sendTerm: defaultSendTerm,
|
|
99514
|
+
sleep: (ms) => new Promise((resolve) => {
|
|
99515
|
+
setTimeout(resolve, ms);
|
|
99516
|
+
}),
|
|
99517
|
+
takeoverWindowMs: SETUP_TAKEOVER_WINDOW_MS,
|
|
99518
|
+
tryAcquire: defaultTryAcquireSetupLock
|
|
99519
|
+
};
|
|
99520
|
+
}
|
|
99521
|
+
async function defaultTryAcquireSetupLock(meta) {
|
|
99522
|
+
try {
|
|
99523
|
+
return {
|
|
99524
|
+
lock: await acquireLock({
|
|
99525
|
+
atsProfileId: SETUP_COMMAND_LOCK_PROFILE,
|
|
99526
|
+
key: SETUP_COMMAND_LOCK_KEY,
|
|
99527
|
+
meta
|
|
99528
|
+
}),
|
|
99529
|
+
ok: true
|
|
99530
|
+
};
|
|
99531
|
+
} catch (error) {
|
|
99532
|
+
if (isAtsLockError(error)) return {
|
|
99533
|
+
error,
|
|
99534
|
+
ok: false
|
|
99535
|
+
};
|
|
99536
|
+
throw error;
|
|
99537
|
+
}
|
|
99538
|
+
}
|
|
99539
|
+
function defaultProbePid(pid) {
|
|
99540
|
+
try {
|
|
99541
|
+
process$1.kill(pid, 0);
|
|
99542
|
+
return "alive";
|
|
99543
|
+
} catch (error) {
|
|
99544
|
+
return getErrorCode(error) === "ESRCH" ? "dead" : "unsignalable";
|
|
99545
|
+
}
|
|
99546
|
+
}
|
|
99547
|
+
function defaultSendTerm(pid) {
|
|
99548
|
+
try {
|
|
99549
|
+
process$1.kill(pid, "SIGTERM");
|
|
99550
|
+
return "sent";
|
|
99551
|
+
} catch (error) {
|
|
99552
|
+
return getErrorCode(error) === "ESRCH" ? "gone" : "not_permitted";
|
|
99553
|
+
}
|
|
99554
|
+
}
|
|
99555
|
+
function defaultReleaseLockSync(path) {
|
|
99556
|
+
rmSync(path, { force: true });
|
|
99557
|
+
}
|
|
99558
|
+
function defaultEmitAgent(payload) {
|
|
99559
|
+
outJsonLine(payload);
|
|
99560
|
+
}
|
|
99561
|
+
function defaultEmitErrorLine(line) {
|
|
99562
|
+
errLine(line);
|
|
99563
|
+
}
|
|
99564
|
+
function defaultEmitOutLine(line) {
|
|
99565
|
+
outLine(line);
|
|
99566
|
+
}
|
|
99567
|
+
function defaultExit(code) {
|
|
99568
|
+
process$1.exit(code);
|
|
99569
|
+
}
|
|
99570
|
+
function runSafely(action) {
|
|
99571
|
+
try {
|
|
99572
|
+
action();
|
|
99573
|
+
} catch {}
|
|
99574
|
+
}
|
|
99575
|
+
function resolveLockHolderPid(error) {
|
|
99576
|
+
const fromMeta = readPidValue(error.meta);
|
|
99577
|
+
if (fromMeta !== null) return fromMeta;
|
|
99578
|
+
return readPidValue(safeParseJson(error.metaRaw));
|
|
99579
|
+
}
|
|
99580
|
+
function resolveLockStartedAtLabel(error) {
|
|
99581
|
+
const at = readStringValue(error.meta, "at") ?? readStringValue(safeParseJson(error.metaRaw), "at");
|
|
99582
|
+
if (!at) return null;
|
|
99583
|
+
const date = new Date(at);
|
|
99584
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
99585
|
+
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
99586
|
+
}
|
|
99587
|
+
function readPidValue(source) {
|
|
99588
|
+
if (!source || typeof source !== "object") return null;
|
|
99589
|
+
const pid = source.pid;
|
|
99590
|
+
return typeof pid === "number" && Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
99591
|
+
}
|
|
99592
|
+
function readStringValue(source, key) {
|
|
99593
|
+
if (!source || typeof source !== "object") return null;
|
|
99594
|
+
const value = source[key];
|
|
99595
|
+
if (typeof value !== "string") return null;
|
|
99596
|
+
const normalized = value.trim();
|
|
99597
|
+
return normalized.length > 0 ? normalized : null;
|
|
99598
|
+
}
|
|
99599
|
+
function safeParseJson(value) {
|
|
99600
|
+
if (typeof value !== "string") return null;
|
|
99601
|
+
try {
|
|
99602
|
+
return JSON.parse(value);
|
|
99603
|
+
} catch {
|
|
99604
|
+
return null;
|
|
99605
|
+
}
|
|
99606
|
+
}
|
|
99607
|
+
function getErrorCode(error) {
|
|
99608
|
+
if (!error || typeof error !== "object") return;
|
|
99609
|
+
const code = error.code;
|
|
99610
|
+
return typeof code === "string" ? code : void 0;
|
|
99611
|
+
}
|
|
99612
|
+
function normalizeOptionalString$3(value) {
|
|
99613
|
+
const normalized = String(value ?? "").trim();
|
|
99614
|
+
return normalized.length > 0 ? normalized : null;
|
|
99615
|
+
}
|
|
99616
|
+
|
|
98962
99617
|
//#endregion
|
|
98963
99618
|
//#region src/commands/setup-current-device.ts
|
|
98964
99619
|
async function syncLocalSetupCurrentDeviceTargetFromServiceContract(input) {
|
|
@@ -99005,11 +99660,21 @@ async function writeConnectedComputerEnrollmentToServiceContract(input) {
|
|
|
99005
99660
|
//#region src/commands/prepare-step-diagnostics.ts
|
|
99006
99661
|
const PREPARE_STEP_DIAGNOSTICS_PAYLOAD_MAX_CHARS = Math.min(16e3, PREPARE_STEP_DIAGNOSTICS_MAX_CHARS);
|
|
99007
99662
|
const ATS_NO_DIAGNOSTICS_ENV = "ATS_NO_DIAGNOSTICS";
|
|
99663
|
+
const PREPARE_STEP_DIAGNOSTICS_BUNDLE_VERSION = 2;
|
|
99008
99664
|
const LIFECYCLE_JOURNAL_TAIL_MAX_ENTRIES = 10;
|
|
99009
99665
|
const SERVICE_LOG_TAIL_MAX_LINES = 30;
|
|
99010
99666
|
const SERVICE_LOG_LINE_MAX_CHARS = 320;
|
|
99011
99667
|
const JOURNAL_ENTRY_MAX_CHARS = 700;
|
|
99012
99668
|
const SOURCE_TIMEOUT_MS = 2e3;
|
|
99669
|
+
const LIFECYCLE_JOURNAL_METADATA_WHITELIST = [
|
|
99670
|
+
"action",
|
|
99671
|
+
"ok",
|
|
99672
|
+
"errorMessage",
|
|
99673
|
+
"jobDiagnostics",
|
|
99674
|
+
"durationMs",
|
|
99675
|
+
"reason"
|
|
99676
|
+
];
|
|
99677
|
+
const LIFECYCLE_JOURNAL_METADATA_COMPACT_WHITELIST = LIFECYCLE_JOURNAL_METADATA_WHITELIST.filter((key) => key !== "jobDiagnostics");
|
|
99013
99678
|
function isPrepareStepDiagnosticsOptedOut(env = process$1.env) {
|
|
99014
99679
|
return String(env[ATS_NO_DIAGNOSTICS_ENV] ?? "").trim() === "1";
|
|
99015
99680
|
}
|
|
@@ -99018,7 +99683,7 @@ async function collectPrepareStepDiagnostics(input) {
|
|
|
99018
99683
|
if (isPrepareStepDiagnosticsOptedOut(input.env)) return null;
|
|
99019
99684
|
const sources = input.sources ?? {};
|
|
99020
99685
|
const collectionErrors = [];
|
|
99021
|
-
const [lifecycleJournalTail,
|
|
99686
|
+
const [lifecycleJournalTail, serviceLog, inventoryAnomalies, serviceJob, deviceId] = await Promise.all([
|
|
99022
99687
|
collectDiagnosticsSource({
|
|
99023
99688
|
collectionErrors,
|
|
99024
99689
|
sourceName: "lifecycle_journal",
|
|
@@ -99027,7 +99692,7 @@ async function collectPrepareStepDiagnostics(input) {
|
|
|
99027
99692
|
collectDiagnosticsSource({
|
|
99028
99693
|
collectionErrors,
|
|
99029
99694
|
sourceName: "service_log",
|
|
99030
|
-
read: sources.readServiceLogTail ??
|
|
99695
|
+
read: sources.readServiceLogTail ?? readServiceLogTailWithPresence
|
|
99031
99696
|
}),
|
|
99032
99697
|
collectDiagnosticsSource({
|
|
99033
99698
|
collectionErrors,
|
|
@@ -99038,14 +99703,22 @@ async function collectPrepareStepDiagnostics(input) {
|
|
|
99038
99703
|
collectionErrors,
|
|
99039
99704
|
sourceName: "service_job",
|
|
99040
99705
|
read: sources.readServiceJobDiagnostics ?? readServiceJobDiagnostics
|
|
99706
|
+
}),
|
|
99707
|
+
collectDiagnosticsSource({
|
|
99708
|
+
collectionErrors,
|
|
99709
|
+
sourceName: "device_id",
|
|
99710
|
+
read: sources.readDeviceId ?? readDaemonServiceContractDeviceId
|
|
99041
99711
|
})
|
|
99042
99712
|
]);
|
|
99713
|
+
const serviceLogNote = serviceLog?.note ?? null;
|
|
99714
|
+
const serviceLogTail = serviceLog === null || serviceLogNote !== null ? null : serviceLog.lines.map(boundServiceLogLine);
|
|
99043
99715
|
const cliVersion = getCliVersionInfo().version;
|
|
99044
99716
|
return serializeBoundedPrepareStepDiagnostics({
|
|
99045
|
-
bundleVersion:
|
|
99717
|
+
bundleVersion: PREPARE_STEP_DIAGNOSTICS_BUNDLE_VERSION,
|
|
99046
99718
|
collectedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
99047
99719
|
supportCode: input.supportCode,
|
|
99048
99720
|
stepId: input.stepId,
|
|
99721
|
+
...deviceId ? { deviceId } : {},
|
|
99049
99722
|
cliVersion,
|
|
99050
99723
|
os: {
|
|
99051
99724
|
platform: process$1.platform,
|
|
@@ -99054,7 +99727,8 @@ async function collectPrepareStepDiagnostics(input) {
|
|
|
99054
99727
|
inventoryAnomalies,
|
|
99055
99728
|
serviceJob,
|
|
99056
99729
|
lifecycleJournalTail: lifecycleJournalTail === null ? null : lifecycleJournalTail.map(boundLifecycleJournalEntry),
|
|
99057
|
-
serviceLogTail
|
|
99730
|
+
serviceLogTail,
|
|
99731
|
+
...serviceLogNote ? { serviceLogNote } : {},
|
|
99058
99732
|
collectionErrors,
|
|
99059
99733
|
truncated: false
|
|
99060
99734
|
});
|
|
@@ -99063,9 +99737,17 @@ async function collectPrepareStepDiagnostics(input) {
|
|
|
99063
99737
|
}
|
|
99064
99738
|
}
|
|
99065
99739
|
function serializeBoundedPrepareStepDiagnostics(bundle) {
|
|
99066
|
-
|
|
99740
|
+
const cappedForSchema = (bundle.inventoryAnomalies?.length ?? 0) > 32 || (bundle.lifecycleJournalTail?.length ?? 0) > LIFECYCLE_JOURNAL_TAIL_MAX_ENTRIES || (bundle.serviceLogTail?.length ?? 0) > SERVICE_LOG_TAIL_MAX_LINES || bundle.collectionErrors.length > 8;
|
|
99741
|
+
let candidate = redactPrepareStepDiagnosticsBundle({
|
|
99742
|
+
...bundle,
|
|
99743
|
+
inventoryAnomalies: bundle.inventoryAnomalies === null ? null : bundle.inventoryAnomalies.slice(-32),
|
|
99744
|
+
lifecycleJournalTail: bundle.lifecycleJournalTail === null ? null : bundle.lifecycleJournalTail.slice(-LIFECYCLE_JOURNAL_TAIL_MAX_ENTRIES),
|
|
99745
|
+
serviceLogTail: bundle.serviceLogTail === null ? null : bundle.serviceLogTail.slice(-SERVICE_LOG_TAIL_MAX_LINES).map(boundServiceLogLine),
|
|
99746
|
+
collectionErrors: bundle.collectionErrors.slice(-8),
|
|
99747
|
+
truncated: bundle.truncated || cappedForSchema
|
|
99748
|
+
});
|
|
99067
99749
|
let serialized = JSON.stringify(candidate);
|
|
99068
|
-
if (serialized.length <= PREPARE_STEP_DIAGNOSTICS_PAYLOAD_MAX_CHARS) return
|
|
99750
|
+
if (serialized.length <= PREPARE_STEP_DIAGNOSTICS_PAYLOAD_MAX_CHARS) return finalizePrepareStepDiagnosticsSerialization(candidate);
|
|
99069
99751
|
candidate = {
|
|
99070
99752
|
...candidate,
|
|
99071
99753
|
truncated: true
|
|
@@ -99093,7 +99775,7 @@ function serializeBoundedPrepareStepDiagnostics(bundle) {
|
|
|
99093
99775
|
}
|
|
99094
99776
|
serialized = JSON.stringify(candidate);
|
|
99095
99777
|
}
|
|
99096
|
-
return
|
|
99778
|
+
return finalizePrepareStepDiagnosticsSerialization(candidate);
|
|
99097
99779
|
}
|
|
99098
99780
|
async function collectDiagnosticsSource(input) {
|
|
99099
99781
|
let timer = null;
|
|
@@ -99114,16 +99796,65 @@ async function readInventoryAnomalyCodes() {
|
|
|
99114
99796
|
async function readServiceJobDiagnostics() {
|
|
99115
99797
|
return await (await resolveDaemonServiceManager())?.readJobDiagnostics?.() ?? null;
|
|
99116
99798
|
}
|
|
99117
|
-
function
|
|
99118
|
-
|
|
99799
|
+
async function resolvePrepareServiceJobVerdict() {
|
|
99800
|
+
const diagnostics = await readServiceJobDiagnostics().catch(() => null);
|
|
99801
|
+
if (!diagnostics) return null;
|
|
99802
|
+
if (isDaemonServiceJobNeverSpawned(diagnostics)) return "never_spawned";
|
|
99803
|
+
if (readDaemonServiceJobCrashExitCode(diagnostics) !== null) return "crashed";
|
|
99804
|
+
return null;
|
|
99805
|
+
}
|
|
99806
|
+
async function readDaemonServiceContractDeviceId() {
|
|
99807
|
+
return (await readDaemonServiceContract())?.deviceId ?? null;
|
|
99808
|
+
}
|
|
99809
|
+
async function readServiceLogTailWithPresence() {
|
|
99810
|
+
const stats = await stat(getDaemonSystemServiceLogPath()).catch(() => null);
|
|
99811
|
+
if (!stats?.isFile()) return {
|
|
99812
|
+
lines: [],
|
|
99813
|
+
note: "file_missing"
|
|
99814
|
+
};
|
|
99815
|
+
if (stats.size === 0) return {
|
|
99816
|
+
lines: [],
|
|
99817
|
+
note: "file_empty"
|
|
99818
|
+
};
|
|
99119
99819
|
return {
|
|
99820
|
+
lines: await readDaemonStartFailureLogTailLines({ maxLines: SERVICE_LOG_TAIL_MAX_LINES }),
|
|
99821
|
+
note: null
|
|
99822
|
+
};
|
|
99823
|
+
}
|
|
99824
|
+
function selectWhitelistedJournalMetadata(metadata, keys) {
|
|
99825
|
+
const selected = {};
|
|
99826
|
+
for (const key of keys) if (Object.hasOwn(metadata, key)) selected[key] = metadata[key];
|
|
99827
|
+
return selected;
|
|
99828
|
+
}
|
|
99829
|
+
function boundLifecycleJournalEntry(entry) {
|
|
99830
|
+
if (!entry.metadata) return redactPrepareStepDiagnosticsValue(entry);
|
|
99831
|
+
const whitelisted = redactPrepareStepDiagnosticsValue({
|
|
99120
99832
|
...entry,
|
|
99833
|
+
metadata: selectWhitelistedJournalMetadata(entry.metadata, LIFECYCLE_JOURNAL_METADATA_WHITELIST)
|
|
99834
|
+
});
|
|
99835
|
+
if (JSON.stringify(whitelisted).length <= JOURNAL_ENTRY_MAX_CHARS) return whitelisted;
|
|
99836
|
+
const compact = redactPrepareStepDiagnosticsValue({
|
|
99837
|
+
...entry,
|
|
99838
|
+
metadata: {
|
|
99839
|
+
...selectWhitelistedJournalMetadata(entry.metadata, LIFECYCLE_JOURNAL_METADATA_COMPACT_WHITELIST),
|
|
99840
|
+
truncated: true
|
|
99841
|
+
}
|
|
99842
|
+
});
|
|
99843
|
+
if (JSON.stringify(compact).length <= JOURNAL_ENTRY_MAX_CHARS) return compact;
|
|
99844
|
+
return {
|
|
99845
|
+
...whitelisted,
|
|
99121
99846
|
metadata: { truncated: true }
|
|
99122
99847
|
};
|
|
99123
99848
|
}
|
|
99124
99849
|
function boundServiceLogLine(line) {
|
|
99125
|
-
|
|
99126
|
-
|
|
99850
|
+
const redactedLine = redactPrepareStepDiagnosticsText(line);
|
|
99851
|
+
if (redactedLine.length <= SERVICE_LOG_LINE_MAX_CHARS) return redactedLine;
|
|
99852
|
+
return `${redactedLine.slice(0, SERVICE_LOG_LINE_MAX_CHARS - 1).trimEnd()}…`;
|
|
99853
|
+
}
|
|
99854
|
+
function finalizePrepareStepDiagnosticsSerialization(bundle) {
|
|
99855
|
+
const parsed = prepareStepDiagnosticsBundleSchema.safeParse(bundle);
|
|
99856
|
+
if (!parsed.success) return null;
|
|
99857
|
+
return JSON.stringify(parsed.data);
|
|
99127
99858
|
}
|
|
99128
99859
|
|
|
99129
99860
|
//#endregion
|
|
@@ -99173,7 +99904,7 @@ async function runPrepareSessionExecutor(input) {
|
|
|
99173
99904
|
if (error instanceof PrepareSessionConnectionInterruptedError && reconnectAttempts < PREPARE_SESSION_MAX_RECONNECT_ATTEMPTS) {
|
|
99174
99905
|
reconnectAttempts += 1;
|
|
99175
99906
|
emitHumanStatus(input, "Reconnecting", ["ATS Web connection was interrupted.", "Reconnecting to the setup session..."]);
|
|
99176
|
-
await sleep
|
|
99907
|
+
await sleep(PREPARE_SESSION_RECONNECT_DELAY_MS);
|
|
99177
99908
|
initial = await resolvePrepareSessionToken({
|
|
99178
99909
|
gatewayUrl: input.gatewayUrl,
|
|
99179
99910
|
opaqueToken: input.startSession
|
|
@@ -99570,13 +100301,19 @@ async function runTerminalStep(input) {
|
|
|
99570
100301
|
throw error;
|
|
99571
100302
|
}
|
|
99572
100303
|
const rawMessage = error instanceof Error && error.message.trim().length > 0 ? error.message.trim() : "Setup could not continue.";
|
|
100304
|
+
const serviceJobVerdict = await resolveRefreshServiceJobVerdict({
|
|
100305
|
+
stepId: input.stepId,
|
|
100306
|
+
resolveServiceJobVerdict: input.resolveServiceJobVerdict
|
|
100307
|
+
});
|
|
99573
100308
|
const message = formatTerminalStepFailureMessage({
|
|
99574
100309
|
stepId: input.stepId,
|
|
99575
|
-
rawMessage
|
|
100310
|
+
rawMessage,
|
|
100311
|
+
serviceJobVerdict
|
|
99576
100312
|
});
|
|
99577
100313
|
const reasonCode = resolveTerminalStepFailureReasonCode({
|
|
99578
100314
|
rawMessage,
|
|
99579
|
-
stepId: input.stepId
|
|
100315
|
+
stepId: input.stepId,
|
|
100316
|
+
serviceJobVerdict
|
|
99580
100317
|
});
|
|
99581
100318
|
const diagnostics = await (input.collectDiagnostics ?? collectPrepareStepDiagnostics)({
|
|
99582
100319
|
stepId: input.stepId,
|
|
@@ -99945,7 +100682,7 @@ async function connectSelectedLocalAgentsToAts(input) {
|
|
|
99945
100682
|
} catch (error) {
|
|
99946
100683
|
if (!isTransientSelectedAgentConnectionError(error) || attempt >= REPORT_RUNTIME_CONNECTION_MAX_ATTEMPTS) throw error;
|
|
99947
100684
|
lastTransientError = error;
|
|
99948
|
-
await sleep
|
|
100685
|
+
await sleep(REPORT_RUNTIME_CONNECTION_RETRY_DELAY_MS);
|
|
99949
100686
|
}
|
|
99950
100687
|
throw lastTransientError ?? /* @__PURE__ */ new Error("ATS could not connect local agents.");
|
|
99951
100688
|
}
|
|
@@ -100050,9 +100787,15 @@ function buildPrepareLocalReadinessSnapshot(readiness) {
|
|
|
100050
100787
|
}
|
|
100051
100788
|
};
|
|
100052
100789
|
}
|
|
100790
|
+
async function resolveRefreshServiceJobVerdict(input) {
|
|
100791
|
+
if (input.stepId !== "refresh_service") return null;
|
|
100792
|
+
return await (input.resolveServiceJobVerdict ?? resolvePrepareServiceJobVerdict)().catch(() => null);
|
|
100793
|
+
}
|
|
100053
100794
|
function formatTerminalStepFailureMessage(input) {
|
|
100054
100795
|
if (input.rawMessage.includes("prepare session revision conflict")) return "This setup changed while Terminal was working. Copy a fresh setup command from ATS Web and run setup again to continue from the latest step.";
|
|
100055
100796
|
if (input.stepId === "refresh_service") {
|
|
100797
|
+
if (input.serviceJobVerdict === "never_spawned") return `macOS is blocking the ATS Service background item, so ATS Service never launched. Path A: open System Settings > General > Login Items & Extensions, enable the ATS background item, then copy a fresh setup command from ATS Web and run setup again. Path B: run \`${formatAtsCliCommand("ats service start --mode foreground")}\` in a separate terminal and keep it open (Wake stops when you close that window), then run setup again.`;
|
|
100798
|
+
if (input.serviceJobVerdict === "crashed") return `ATS Service started but keeps exiting on this Mac. Run \`${formatAtsCliCommand("ats service start --mode foreground")}\` to see the live error, fix it, then copy a fresh setup command from ATS Web and run setup again.`;
|
|
100056
100799
|
const detail = formatTerminalStepFailureDetail(input.rawMessage);
|
|
100057
100800
|
return `ATS Service did not report a running local connection during setup. Copy a fresh setup command from ATS Web and run setup again to continue from this step. If it fails again, run \`${formatAtsCliCommand("ats service start --mode foreground")}\` to see live startup logs, then copy a fresh setup command from ATS Web and run setup again.${detail ? ` Detail: ${detail}` : ""}`;
|
|
100058
100801
|
}
|
|
@@ -100066,6 +100809,10 @@ function formatTerminalStepFailureDetail(rawMessage) {
|
|
|
100066
100809
|
}
|
|
100067
100810
|
function resolveTerminalStepFailureReasonCode(input) {
|
|
100068
100811
|
if (input.rawMessage.includes("runtime.registration.device_forgotten")) return "runtime.registration.device_forgotten";
|
|
100812
|
+
if (input.stepId === "refresh_service") {
|
|
100813
|
+
if (input.serviceJobVerdict === "never_spawned") return "prepare.refresh_service.service_never_spawned";
|
|
100814
|
+
if (input.serviceJobVerdict === "crashed") return "prepare.refresh_service.service_crash_loop";
|
|
100815
|
+
}
|
|
100069
100816
|
return `prepare.${input.stepId}.failed`;
|
|
100070
100817
|
}
|
|
100071
100818
|
function findStep(snapshot, stepId) {
|
|
@@ -101088,11 +101835,18 @@ function isAgentProfile(profile) {
|
|
|
101088
101835
|
|
|
101089
101836
|
//#endregion
|
|
101090
101837
|
//#region src/commands/setup.ts
|
|
101091
|
-
const SETUP_COMMAND_LOCK_PROFILE = "setup";
|
|
101092
|
-
const SETUP_COMMAND_LOCK_KEY = "setup-command";
|
|
101093
101838
|
async function runSetup(input) {
|
|
101094
|
-
return await withSetupCommandLock(
|
|
101095
|
-
|
|
101839
|
+
return await withSetupCommandLock({
|
|
101840
|
+
lockMeta: {
|
|
101841
|
+
command: "ats setup",
|
|
101842
|
+
path: shouldUseSetupLocalAgentConnection(input) ? "delegated_or_profile_setup" : "local_setup",
|
|
101843
|
+
view: input.view ?? null
|
|
101844
|
+
},
|
|
101845
|
+
run: async () => {
|
|
101846
|
+
await runSetupUnlocked(input);
|
|
101847
|
+
},
|
|
101848
|
+
startSession: input.startSession,
|
|
101849
|
+
view: input.view
|
|
101096
101850
|
});
|
|
101097
101851
|
}
|
|
101098
101852
|
async function runSetupUnlocked(input) {
|
|
@@ -101251,33 +102005,6 @@ async function runSetupUnlocked(input) {
|
|
|
101251
102005
|
async function runSetupStartupLocalStateRepair() {
|
|
101252
102006
|
await runLocalStateAlignment({ mode: "repair" });
|
|
101253
102007
|
}
|
|
101254
|
-
async function withSetupCommandLock(input, run) {
|
|
101255
|
-
try {
|
|
101256
|
-
return await runWithHeldLock({
|
|
101257
|
-
lock: await acquireLock({
|
|
101258
|
-
atsProfileId: SETUP_COMMAND_LOCK_PROFILE,
|
|
101259
|
-
key: SETUP_COMMAND_LOCK_KEY,
|
|
101260
|
-
meta: {
|
|
101261
|
-
command: "ats setup",
|
|
101262
|
-
path: shouldUseSetupLocalAgentConnection(input) ? "delegated_or_profile_setup" : "local_setup",
|
|
101263
|
-
view: input.view ?? null
|
|
101264
|
-
}
|
|
101265
|
-
}),
|
|
101266
|
-
run,
|
|
101267
|
-
releaseContext: {
|
|
101268
|
-
atsProfileId: SETUP_COMMAND_LOCK_PROFILE,
|
|
101269
|
-
component: "setup_command",
|
|
101270
|
-
lockKey: SETUP_COMMAND_LOCK_KEY
|
|
101271
|
-
}
|
|
101272
|
-
});
|
|
101273
|
-
} catch (error) {
|
|
101274
|
-
if (isAtsLockError(error)) throw new Error(buildSetupCommandLockMessage(error));
|
|
101275
|
-
throw error;
|
|
101276
|
-
}
|
|
101277
|
-
}
|
|
101278
|
-
function buildSetupCommandLockMessage(error) {
|
|
101279
|
-
return `Another ATS setup is already running on this computer. Wait for it to finish, then run setup again.${error.metaRaw ? ` Existing setup: ${error.metaRaw}` : ""}`;
|
|
101280
|
-
}
|
|
101281
102008
|
function shouldUseSetupLocalAgentConnection(input) {
|
|
101282
102009
|
return Boolean(normalizeOptionalString$1(input.startSession) ?? normalizeOptionalString$1(input.humanProfile) ?? normalizeOptionalString$1(input.profile) ?? (input.agent && input.agent.length > 0 ? "agent" : null));
|
|
101283
102010
|
}
|
|
@@ -104235,7 +104962,7 @@ function normalizeOptionalString(value) {
|
|
|
104235
104962
|
return normalized.length > 0 ? normalized : null;
|
|
104236
104963
|
}
|
|
104237
104964
|
async function runDefaultSpaceAddMeMembership(input) {
|
|
104238
|
-
const { runSpaceAddMeMembership } = await import("./add-me-membership-
|
|
104965
|
+
const { runSpaceAddMeMembership } = await import("./add-me-membership-Cfi5fbyb.js");
|
|
104239
104966
|
return await runSpaceAddMeMembership(input);
|
|
104240
104967
|
}
|
|
104241
104968
|
|
|
@@ -107151,10 +107878,10 @@ serviceCmd.command("trace").description("Read a Space delivery trace for debuggi
|
|
|
107151
107878
|
profile: opts.profile,
|
|
107152
107879
|
gatewayUrl: opts.gatewayUrl,
|
|
107153
107880
|
run: async () => {
|
|
107154
|
-
const dispatchId = normalizeOptionalString$
|
|
107155
|
-
const sourceSignalId = normalizeOptionalString$
|
|
107156
|
-
const clientMessageId = normalizeOptionalString$
|
|
107157
|
-
const targetProfileId = normalizeOptionalString$
|
|
107881
|
+
const dispatchId = normalizeOptionalString$7(opts.dispatch);
|
|
107882
|
+
const sourceSignalId = normalizeOptionalString$7(opts.sourceSignal);
|
|
107883
|
+
const clientMessageId = normalizeOptionalString$7(opts.clientMessage);
|
|
107884
|
+
const targetProfileId = normalizeOptionalString$7(opts.targetProfile);
|
|
107158
107885
|
if (Number(dispatchId !== null) + Number(sourceSignalId !== null) + Number(clientMessageId !== null) !== 1) throw new Error("exactly one of --dispatch, --source-signal, or --client-message is required");
|
|
107159
107886
|
await runServiceTrace({
|
|
107160
107887
|
profile: opts.profile,
|
|
@@ -107344,7 +108071,7 @@ spaceActionCmd.command("help").description("Show ATS Space Action help.").action
|
|
|
107344
108071
|
withSpaceProfileOption(spaceCmd.command("create").description("Create a new space and print its space ID.").option("--name <name>", "Space name (<=80 chars; prompted in human interactive mode)").option("--guide <text>", "Optional space guide").option("--password <value>", "Optional space password (minimum 6 characters; numbers/letters/symbols accepted)").option("--join", "Join immediately after create").option("--no-join", "Do not ask to join after create").option("--output <mode>", "Output mode when auto-joining: ndjson|text", "text")).action(async (opts, command) => {
|
|
107345
108072
|
const cliOptions = resolveSpaceCommandCliOptions(command, opts);
|
|
107346
108073
|
const view = getGlobalViewOption();
|
|
107347
|
-
if (view === "agent" && normalizeOptionalString$
|
|
108074
|
+
if (view === "agent" && normalizeOptionalString$7(opts.name) === null) {
|
|
107348
108075
|
await runSpaceCreate({
|
|
107349
108076
|
profile: cliOptions.profile,
|
|
107350
108077
|
baseUrl: cliOptions.gatewayUrl,
|
|
@@ -107401,7 +108128,7 @@ withSpaceProfileOption(spaceCmd.command("join").description("Join a space and ch
|
|
|
107401
108128
|
const cliOptions = resolveSpaceCommandCliOptions(command, opts);
|
|
107402
108129
|
const localEcho = opts.noLocalEcho !== true;
|
|
107403
108130
|
const view = getGlobalViewOption();
|
|
107404
|
-
if (view === "agent" && normalizeOptionalString$
|
|
108131
|
+
if (view === "agent" && normalizeOptionalString$7(space) === null) {
|
|
107405
108132
|
await runSpaceJoin({
|
|
107406
108133
|
profile: cliOptions.profile,
|
|
107407
108134
|
baseUrl: cliOptions.gatewayUrl,
|
|
@@ -107896,8 +108623,8 @@ withSpaceProfileOption(spaceCmd.command("updates").description("Read formal upda
|
|
|
107896
108623
|
withSpaceProfileOption(spaceCmd.command("result").description("Read one formal dispatch result scoped to this space.").argument("[space]", "Space ID (64-character hex)").option("--dispatch <dispatch-id>", "Lookup by dispatch ID").option("--result-ref <result-ref>", "Lookup by dispatch result ref").option("--json", "Print canonical JSON", false).option("--password <value>", "Space password for protected access")).action(async (space, opts, command) => {
|
|
107897
108624
|
const cliOptions = resolveSpaceCommandCliOptions(command, opts);
|
|
107898
108625
|
const spaceValue = String(space ?? "").trim();
|
|
107899
|
-
const dispatchId = normalizeOptionalString$
|
|
107900
|
-
const resultRef = normalizeOptionalString$
|
|
108626
|
+
const dispatchId = normalizeOptionalString$7(opts.dispatch);
|
|
108627
|
+
const resultRef = normalizeOptionalString$7(opts.resultRef);
|
|
107901
108628
|
const selectorCount = Number(dispatchId !== null) + Number(resultRef !== null);
|
|
107902
108629
|
const outputView = await resolveEffectiveViewForOutput();
|
|
107903
108630
|
if ((spaceValue.length === 0 || selectorCount !== 1) && outputView === "agent") throw createSpaceResultGuideError();
|