agent-transport-system 0.7.31 → 0.7.33
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/dist/ats.js +1021 -967
- package/dist/ats.js.map +1 -1
- package/package.json +4 -4
package/dist/ats.js
CHANGED
|
@@ -27,12 +27,12 @@ import wrapAnsi from "wrap-ansi";
|
|
|
27
27
|
import { Box, Container, Editor, Key, ProcessTerminal, TUI, Text, getEditorKeybindings, matchesKey } from "@mariozechner/pi-tui";
|
|
28
28
|
|
|
29
29
|
//#region package.json
|
|
30
|
-
var version = "0.7.
|
|
30
|
+
var version = "0.7.33";
|
|
31
31
|
var package_default = {
|
|
32
32
|
$schema: "https://www.schemastore.org/package.json",
|
|
33
33
|
name: "agent-transport-system",
|
|
34
34
|
version,
|
|
35
|
-
atsReleaseDate: "2026-06-
|
|
35
|
+
atsReleaseDate: "2026-06-05",
|
|
36
36
|
description: "Agent Transport System CLI - https://ats.sh",
|
|
37
37
|
license: "MIT",
|
|
38
38
|
type: "module",
|
|
@@ -56,7 +56,7 @@ var package_default = {
|
|
|
56
56
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
57
57
|
"check": "ultracite check && tsc -p tsconfig.json --noEmit",
|
|
58
58
|
"test": "vitest run --config vitest.config.ts",
|
|
59
|
-
"test:integration": "
|
|
59
|
+
"test:integration": "node scripts/run-integration-tests.mjs",
|
|
60
60
|
"test:full": "pnpm run test && pnpm run test:integration",
|
|
61
61
|
"test:daemon": "vitest run --config vitest.integration.config.ts tests/daemon-state.integration.test.ts tests/daemon-command.integration.test.ts tests/daemon-menu.integration.test.ts tests/daemon-run.integration.test.ts tests/daemon-bootstrap-recommendation.integration.test.ts",
|
|
62
62
|
"test:watch": "vitest"
|
|
@@ -77,7 +77,7 @@ var package_default = {
|
|
|
77
77
|
"@agent-transport-system/adapter-openclaw": "workspace:*",
|
|
78
78
|
"@agent-transport-system/agent-runtime": "workspace:*",
|
|
79
79
|
"@agent-transport-system/api-client": "workspace:*",
|
|
80
|
-
"@agent-transport-system/
|
|
80
|
+
"@agent-transport-system/local-execution": "workspace:*",
|
|
81
81
|
"@agent-transport-system/gateway-contract": "workspace:*",
|
|
82
82
|
"@agent-transport-system/protocol": "workspace:*",
|
|
83
83
|
"@agent-transport-system/schemas": "workspace:*",
|
|
@@ -16267,6 +16267,56 @@ const createStartApi = (client) => {
|
|
|
16267
16267
|
};
|
|
16268
16268
|
};
|
|
16269
16269
|
|
|
16270
|
+
//#endregion
|
|
16271
|
+
//#region src/local-service/carrier/heartbeat-loop.ts
|
|
16272
|
+
function waitForHeartbeatResponse(input) {
|
|
16273
|
+
if (input.waiters.heartbeatResolver || input.waiters.heartbeatRejecter) return Promise.reject(new DaemonServiceRunError({
|
|
16274
|
+
code: "daemon.run.heartbeat_response_busy",
|
|
16275
|
+
message: "heartbeat response waiter is already pending"
|
|
16276
|
+
}));
|
|
16277
|
+
return new Promise((resolve, reject) => {
|
|
16278
|
+
const timeout = setTimeout(() => {
|
|
16279
|
+
input.waiters.heartbeatResolver = null;
|
|
16280
|
+
input.waiters.heartbeatRejecter = null;
|
|
16281
|
+
reject(new DaemonServiceRunError({
|
|
16282
|
+
code: "daemon.run.heartbeat_timeout",
|
|
16283
|
+
message: "heartbeat response timeout"
|
|
16284
|
+
}));
|
|
16285
|
+
}, input.timeoutMs);
|
|
16286
|
+
input.waiters.heartbeatResolver = (payload) => {
|
|
16287
|
+
clearTimeout(timeout);
|
|
16288
|
+
input.waiters.heartbeatRejecter = null;
|
|
16289
|
+
resolve(payload);
|
|
16290
|
+
};
|
|
16291
|
+
input.waiters.heartbeatRejecter = (error) => {
|
|
16292
|
+
clearTimeout(timeout);
|
|
16293
|
+
input.waiters.heartbeatResolver = null;
|
|
16294
|
+
input.waiters.heartbeatRejecter = null;
|
|
16295
|
+
reject(error);
|
|
16296
|
+
};
|
|
16297
|
+
});
|
|
16298
|
+
}
|
|
16299
|
+
function applyAcceptedLeases(input) {
|
|
16300
|
+
input.leasesByProfileId.clear();
|
|
16301
|
+
for (const lease of input.acceptedLeases) input.leasesByProfileId.set(lease.profileId, lease.leaseEpoch);
|
|
16302
|
+
}
|
|
16303
|
+
function pruneStaleLeases(input) {
|
|
16304
|
+
for (const staleLease of input.staleLeases) if (input.leasesByProfileId.get(staleLease.profileId) === staleLease.leaseEpoch) input.leasesByProfileId.delete(staleLease.profileId);
|
|
16305
|
+
}
|
|
16306
|
+
function resolveAdaptiveHeartbeatIntervalMs(input) {
|
|
16307
|
+
if (input.hasDispatchActivity) return MIN_HEARTBEAT_INTERVAL_MS;
|
|
16308
|
+
const growthFactor = typeof input.growthFactor === "number" && Number.isFinite(input.growthFactor) ? input.growthFactor : ADAPTIVE_HEARTBEAT_GROWTH_FACTOR;
|
|
16309
|
+
return clampInteger$1(input.currentIntervalMs * growthFactor, MIN_HEARTBEAT_INTERVAL_MS, MAX_HEARTBEAT_INTERVAL_MS);
|
|
16310
|
+
}
|
|
16311
|
+
function applyIntervalJitterMs(input) {
|
|
16312
|
+
const jitterRatio = typeof input.jitterRatio === "number" && Number.isFinite(input.jitterRatio) ? Math.max(0, input.jitterRatio) : 0;
|
|
16313
|
+
const jitterMultiplier = 1 + ((typeof input.randomValue === "number" && Number.isFinite(input.randomValue) ? Math.min(1, Math.max(0, input.randomValue)) : Math.random()) * 2 - 1) * jitterRatio;
|
|
16314
|
+
return clampInteger$1(input.baseIntervalMs * jitterMultiplier, input.minIntervalMs, input.maxIntervalMs);
|
|
16315
|
+
}
|
|
16316
|
+
function resolveCatalogSyncIntervalMs(input) {
|
|
16317
|
+
return clampInteger$1(input.heartbeatIntervalMs * CATALOG_SYNC_INTERVAL_MULTIPLIER, MIN_CATALOG_SYNC_INTERVAL_MS, MAX_CATALOG_SYNC_INTERVAL_MS);
|
|
16318
|
+
}
|
|
16319
|
+
|
|
16270
16320
|
//#endregion
|
|
16271
16321
|
//#region src/agents/controller-identity.ts
|
|
16272
16322
|
function resolveLocalRegistryAgentIdFromAgentControllerRef(input) {
|
|
@@ -19856,56 +19906,6 @@ function resolveProfileWorkspaceStateReason(input) {
|
|
|
19856
19906
|
return "projected agent profile workspaces look good";
|
|
19857
19907
|
}
|
|
19858
19908
|
|
|
19859
|
-
//#endregion
|
|
19860
|
-
//#region src/daemon/session/heartbeat-loop.ts
|
|
19861
|
-
function waitForHeartbeatResponse(input) {
|
|
19862
|
-
if (input.waiters.heartbeatResolver || input.waiters.heartbeatRejecter) return Promise.reject(new DaemonServiceRunError({
|
|
19863
|
-
code: "daemon.run.heartbeat_response_busy",
|
|
19864
|
-
message: "heartbeat response waiter is already pending"
|
|
19865
|
-
}));
|
|
19866
|
-
return new Promise((resolve, reject) => {
|
|
19867
|
-
const timeout = setTimeout(() => {
|
|
19868
|
-
input.waiters.heartbeatResolver = null;
|
|
19869
|
-
input.waiters.heartbeatRejecter = null;
|
|
19870
|
-
reject(new DaemonServiceRunError({
|
|
19871
|
-
code: "daemon.run.heartbeat_timeout",
|
|
19872
|
-
message: "heartbeat response timeout"
|
|
19873
|
-
}));
|
|
19874
|
-
}, input.timeoutMs);
|
|
19875
|
-
input.waiters.heartbeatResolver = (payload) => {
|
|
19876
|
-
clearTimeout(timeout);
|
|
19877
|
-
input.waiters.heartbeatRejecter = null;
|
|
19878
|
-
resolve(payload);
|
|
19879
|
-
};
|
|
19880
|
-
input.waiters.heartbeatRejecter = (error) => {
|
|
19881
|
-
clearTimeout(timeout);
|
|
19882
|
-
input.waiters.heartbeatResolver = null;
|
|
19883
|
-
input.waiters.heartbeatRejecter = null;
|
|
19884
|
-
reject(error);
|
|
19885
|
-
};
|
|
19886
|
-
});
|
|
19887
|
-
}
|
|
19888
|
-
function applyAcceptedLeases(input) {
|
|
19889
|
-
input.leasesByProfileId.clear();
|
|
19890
|
-
for (const lease of input.acceptedLeases) input.leasesByProfileId.set(lease.profileId, lease.leaseEpoch);
|
|
19891
|
-
}
|
|
19892
|
-
function pruneStaleLeases(input) {
|
|
19893
|
-
for (const staleLease of input.staleLeases) if (input.leasesByProfileId.get(staleLease.profileId) === staleLease.leaseEpoch) input.leasesByProfileId.delete(staleLease.profileId);
|
|
19894
|
-
}
|
|
19895
|
-
function resolveAdaptiveHeartbeatIntervalMs(input) {
|
|
19896
|
-
if (input.hasDispatchActivity) return MIN_HEARTBEAT_INTERVAL_MS;
|
|
19897
|
-
const growthFactor = typeof input.growthFactor === "number" && Number.isFinite(input.growthFactor) ? input.growthFactor : ADAPTIVE_HEARTBEAT_GROWTH_FACTOR;
|
|
19898
|
-
return clampInteger$1(input.currentIntervalMs * growthFactor, MIN_HEARTBEAT_INTERVAL_MS, MAX_HEARTBEAT_INTERVAL_MS);
|
|
19899
|
-
}
|
|
19900
|
-
function applyIntervalJitterMs(input) {
|
|
19901
|
-
const jitterRatio = typeof input.jitterRatio === "number" && Number.isFinite(input.jitterRatio) ? Math.max(0, input.jitterRatio) : 0;
|
|
19902
|
-
const jitterMultiplier = 1 + ((typeof input.randomValue === "number" && Number.isFinite(input.randomValue) ? Math.min(1, Math.max(0, input.randomValue)) : Math.random()) * 2 - 1) * jitterRatio;
|
|
19903
|
-
return clampInteger$1(input.baseIntervalMs * jitterMultiplier, input.minIntervalMs, input.maxIntervalMs);
|
|
19904
|
-
}
|
|
19905
|
-
function resolveCatalogSyncIntervalMs(input) {
|
|
19906
|
-
return clampInteger$1(input.heartbeatIntervalMs * CATALOG_SYNC_INTERVAL_MULTIPLIER, MIN_CATALOG_SYNC_INTERVAL_MS, MAX_CATALOG_SYNC_INTERVAL_MS);
|
|
19907
|
-
}
|
|
19908
|
-
|
|
19909
19909
|
//#endregion
|
|
19910
19910
|
//#region src/daemon/routing/resolve-controller-support.ts
|
|
19911
19911
|
async function readLocalEnabledControllers() {
|
|
@@ -27664,6 +27664,134 @@ function toErrorMessage$18(error) {
|
|
|
27664
27664
|
return String(error);
|
|
27665
27665
|
}
|
|
27666
27666
|
|
|
27667
|
+
//#endregion
|
|
27668
|
+
//#region src/runtime/view-argv.ts
|
|
27669
|
+
const PASSIVE_CLI_QUERY_FLAGS = new Set([
|
|
27670
|
+
"--help",
|
|
27671
|
+
"--version",
|
|
27672
|
+
"-V",
|
|
27673
|
+
"-h"
|
|
27674
|
+
]);
|
|
27675
|
+
function isStandaloneViewQueryArgv(argv) {
|
|
27676
|
+
const args = argv.slice(2);
|
|
27677
|
+
return args.length === 1 && args[0] === "--view";
|
|
27678
|
+
}
|
|
27679
|
+
function parseViewFromArgv(argv, options) {
|
|
27680
|
+
const allowMissingValue = options?.allowMissingValue === true;
|
|
27681
|
+
for (let i = 2; i < argv.length; i += 1) {
|
|
27682
|
+
const arg = argv[i];
|
|
27683
|
+
if (typeof arg !== "string") continue;
|
|
27684
|
+
if (arg === "--") break;
|
|
27685
|
+
if (arg === "--view") {
|
|
27686
|
+
const next = argv[i + 1];
|
|
27687
|
+
if (typeof next !== "string" || next.startsWith("-")) {
|
|
27688
|
+
if (allowMissingValue) return null;
|
|
27689
|
+
throw new Error("missing --view value (use auto|human|agent)");
|
|
27690
|
+
}
|
|
27691
|
+
return parseCliViewMode(next);
|
|
27692
|
+
}
|
|
27693
|
+
if (arg.startsWith("--view=")) return parseCliViewMode(arg.slice(7));
|
|
27694
|
+
}
|
|
27695
|
+
return null;
|
|
27696
|
+
}
|
|
27697
|
+
function parseStandaloneViewSwitchArgv(argv) {
|
|
27698
|
+
const args = argv.slice(2);
|
|
27699
|
+
if (args.length === 0) return null;
|
|
27700
|
+
let view = null;
|
|
27701
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
27702
|
+
const arg = args[i];
|
|
27703
|
+
if (typeof arg !== "string") continue;
|
|
27704
|
+
if (arg === "--view") {
|
|
27705
|
+
const next = args[i + 1];
|
|
27706
|
+
if (typeof next !== "string" || next.startsWith("-")) return null;
|
|
27707
|
+
view = next.trim().toLowerCase();
|
|
27708
|
+
i += 1;
|
|
27709
|
+
continue;
|
|
27710
|
+
}
|
|
27711
|
+
if (arg.startsWith("--view=")) {
|
|
27712
|
+
view = arg.slice(7).trim().toLowerCase();
|
|
27713
|
+
continue;
|
|
27714
|
+
}
|
|
27715
|
+
return null;
|
|
27716
|
+
}
|
|
27717
|
+
return view;
|
|
27718
|
+
}
|
|
27719
|
+
function parseFirstCommandTokenFromArgv(argv) {
|
|
27720
|
+
return parseLeadingCommandTokensFromArgv(argv, 1)[0] ?? null;
|
|
27721
|
+
}
|
|
27722
|
+
function parseLeadingCommandTokensFromArgv(argv, maxTokens = 2) {
|
|
27723
|
+
if (maxTokens <= 0) return [];
|
|
27724
|
+
const args = argv.slice(2);
|
|
27725
|
+
const tokens = [];
|
|
27726
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
27727
|
+
if (collectTokensAfterTerminator(args, i, tokens, maxTokens)) return tokens;
|
|
27728
|
+
if (shouldSkipKnownGlobalFlag(args, i)) {
|
|
27729
|
+
i += 1;
|
|
27730
|
+
continue;
|
|
27731
|
+
}
|
|
27732
|
+
const arg = args[i];
|
|
27733
|
+
if (typeof arg !== "string" || shouldSkipInlineGlobalFlag(arg)) continue;
|
|
27734
|
+
if (pushLeadingCommandToken(arg, tokens, maxTokens)) return tokens;
|
|
27735
|
+
}
|
|
27736
|
+
return tokens;
|
|
27737
|
+
}
|
|
27738
|
+
function isPassiveCliQueryArgv(argv) {
|
|
27739
|
+
const args = argv.slice(2);
|
|
27740
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
27741
|
+
const arg = args[i];
|
|
27742
|
+
if (typeof arg !== "string") continue;
|
|
27743
|
+
if (arg === "--") return false;
|
|
27744
|
+
if (isKnownGlobalFlagExpectValue(arg) && isGlobalFlagValueCandidate(args[i + 1])) {
|
|
27745
|
+
i += 1;
|
|
27746
|
+
continue;
|
|
27747
|
+
}
|
|
27748
|
+
if (arg.startsWith("--view=") || arg.startsWith("--service-auto-install=")) continue;
|
|
27749
|
+
if (arg === "help" || PASSIVE_CLI_QUERY_FLAGS.has(arg)) return true;
|
|
27750
|
+
}
|
|
27751
|
+
return false;
|
|
27752
|
+
}
|
|
27753
|
+
function hasJsonOutputArgv(argv) {
|
|
27754
|
+
for (let i = 2; i < argv.length; i += 1) {
|
|
27755
|
+
const arg = argv[i];
|
|
27756
|
+
if (typeof arg !== "string") continue;
|
|
27757
|
+
if (arg === "--") return false;
|
|
27758
|
+
if (arg === "--json" || arg.startsWith("--json=")) return true;
|
|
27759
|
+
}
|
|
27760
|
+
return false;
|
|
27761
|
+
}
|
|
27762
|
+
function shouldUseAgentViewForNonInteractiveStart(argv, interactive) {
|
|
27763
|
+
if (interactive) return false;
|
|
27764
|
+
if (parseViewFromArgv(argv, { allowMissingValue: true }) !== null) return false;
|
|
27765
|
+
return parseFirstCommandTokenFromArgv(argv) === "start";
|
|
27766
|
+
}
|
|
27767
|
+
function isKnownGlobalFlagExpectValue(value) {
|
|
27768
|
+
return value === "--view" || value === "--service-auto-install";
|
|
27769
|
+
}
|
|
27770
|
+
function isGlobalFlagValueCandidate(value) {
|
|
27771
|
+
return typeof value === "string" && value.length > 0 && !value.startsWith("-");
|
|
27772
|
+
}
|
|
27773
|
+
function collectTokensAfterTerminator(args, index, tokens, maxTokens) {
|
|
27774
|
+
if (args[index] !== "--") return false;
|
|
27775
|
+
for (let i = index + 1; i < args.length; i += 1) {
|
|
27776
|
+
const next = args[i];
|
|
27777
|
+
if (typeof next !== "string" || next.length === 0) continue;
|
|
27778
|
+
tokens.push(next);
|
|
27779
|
+
if (tokens.length >= maxTokens) break;
|
|
27780
|
+
}
|
|
27781
|
+
return true;
|
|
27782
|
+
}
|
|
27783
|
+
function shouldSkipKnownGlobalFlag(args, index) {
|
|
27784
|
+
return isKnownGlobalFlagExpectValue(args[index] ?? "") && isGlobalFlagValueCandidate(args[index + 1]);
|
|
27785
|
+
}
|
|
27786
|
+
function shouldSkipInlineGlobalFlag(value) {
|
|
27787
|
+
return value.startsWith("--view=") || value.startsWith("--service-auto-install=");
|
|
27788
|
+
}
|
|
27789
|
+
function pushLeadingCommandToken(value, tokens, maxTokens) {
|
|
27790
|
+
if (value.startsWith("-")) return false;
|
|
27791
|
+
tokens.push(value);
|
|
27792
|
+
return tokens.length >= maxTokens;
|
|
27793
|
+
}
|
|
27794
|
+
|
|
27667
27795
|
//#endregion
|
|
27668
27796
|
//#region src/command-entry-checks/build-agent-check-result.ts
|
|
27669
27797
|
function buildAgentCheckResult(input) {
|
|
@@ -28440,6 +28568,7 @@ function resolveFreshCachedLatestVersion(input) {
|
|
|
28440
28568
|
return state.latest_version;
|
|
28441
28569
|
}
|
|
28442
28570
|
function shouldCheckNpmCliUpdate(context) {
|
|
28571
|
+
if (hasJsonOutputArgv(context.argv)) return false;
|
|
28443
28572
|
return context.environmentTarget.preset === "prod" && context.environmentTarget.userFacingCommand === "ats";
|
|
28444
28573
|
}
|
|
28445
28574
|
|
|
@@ -28448,7 +28577,7 @@ function shouldCheckNpmCliUpdate(context) {
|
|
|
28448
28577
|
const ATS_ACCEPT_DISCLAIMER_ENV = "ATS_ACCEPT_DISCLAIMER";
|
|
28449
28578
|
const ATS_ONBOARDING_DISCLAIMER_ACCEPT = "__onboarding_disclaimer_accept__";
|
|
28450
28579
|
const ATS_ONBOARDING_DISCLAIMER_DECLINE = "__onboarding_disclaimer_decline__";
|
|
28451
|
-
const ATS_ONBOARDING_DISCLAIMER_TEXT = "
|
|
28580
|
+
const ATS_ONBOARDING_DISCLAIMER_TEXT = "ATS local service is experimental and changes rapidly. Breaking changes may occur. You are fully responsible for data security and sensitive information handling. Use ATS only in trusted environments.";
|
|
28452
28581
|
async function runOnboardingDisclaimerGate(input) {
|
|
28453
28582
|
if (await getConfiguredOnboardingDisclaimerAcceptedAt().catch(() => null)) return true;
|
|
28454
28583
|
if (shouldBypassDisclaimerWithEnv()) {
|
|
@@ -34925,47 +35054,7 @@ function buildDaemonAgentOverviewPayload(command) {
|
|
|
34925
35054
|
}
|
|
34926
35055
|
|
|
34927
35056
|
//#endregion
|
|
34928
|
-
//#region
|
|
34929
|
-
async function connectWebSocket(url, input) {
|
|
34930
|
-
return await new Promise((resolve, reject) => {
|
|
34931
|
-
const ws = new WebSocket(url, { headers: input?.headers });
|
|
34932
|
-
const closePromise = new Promise((r) => {
|
|
34933
|
-
ws.on("close", () => r());
|
|
34934
|
-
ws.on("error", () => r());
|
|
34935
|
-
});
|
|
34936
|
-
ws.on("open", () => {
|
|
34937
|
-
resolve({
|
|
34938
|
-
send: (data) => ws.send(data),
|
|
34939
|
-
close: (code, reason) => ws.close(code, reason),
|
|
34940
|
-
terminate: () => ws.terminate(),
|
|
34941
|
-
onMessage: (handler) => {
|
|
34942
|
-
ws.on("message", (buf) => handler(toUtf8(buf)));
|
|
34943
|
-
},
|
|
34944
|
-
onClose: (handler) => {
|
|
34945
|
-
ws.on("close", (code, reason) => handler(code, reason.toString("utf8")));
|
|
34946
|
-
},
|
|
34947
|
-
onError: (handler) => {
|
|
34948
|
-
ws.on("error", handler);
|
|
34949
|
-
},
|
|
34950
|
-
waitUntilClosed: async () => {
|
|
34951
|
-
await closePromise;
|
|
34952
|
-
}
|
|
34953
|
-
});
|
|
34954
|
-
});
|
|
34955
|
-
ws.on("error", (err) => {
|
|
34956
|
-
reject(err);
|
|
34957
|
-
});
|
|
34958
|
-
});
|
|
34959
|
-
}
|
|
34960
|
-
function toUtf8(value) {
|
|
34961
|
-
if (typeof value === "string") return value;
|
|
34962
|
-
if (value instanceof Buffer) return value.toString("utf8");
|
|
34963
|
-
if (Array.isArray(value)) return Buffer.concat(value).toString("utf8");
|
|
34964
|
-
return String(value);
|
|
34965
|
-
}
|
|
34966
|
-
|
|
34967
|
-
//#endregion
|
|
34968
|
-
//#region ../../runtime/atsd/dist/adapter-routing.js
|
|
35057
|
+
//#region ../../runtime/local-execution/dist/adapter-routing.js
|
|
34969
35058
|
const ADAPTER_ROUTE_ERROR_CODES = {
|
|
34970
35059
|
adapterUnreachable: "adapter.unreachable",
|
|
34971
35060
|
controllerRuntimeMissing: "controller.runtime.missing",
|
|
@@ -35085,7 +35174,7 @@ const isAgentControllerRefRegexMatched = (agentControllerRef, matcherValue) => {
|
|
|
35085
35174
|
};
|
|
35086
35175
|
|
|
35087
35176
|
//#endregion
|
|
35088
|
-
//#region ../../runtime/
|
|
35177
|
+
//#region ../../runtime/local-execution/dist/agent-context-policy.js
|
|
35089
35178
|
const AGENT_CONTEXT_LOOKUP_KEY_SEPARATOR$1 = "|";
|
|
35090
35179
|
const LEDGER_AGENT_CONTEXT_SOURCE_FIELD = "atsd.agent_context_ledger";
|
|
35091
35180
|
const encodeLookupKeyPart = (value) => encodeURIComponent(value);
|
|
@@ -35285,7 +35374,7 @@ const resolveAgentContextForDispatch = (input) => {
|
|
|
35285
35374
|
};
|
|
35286
35375
|
|
|
35287
35376
|
//#endregion
|
|
35288
|
-
//#region ../../runtime/
|
|
35377
|
+
//#region ../../runtime/local-execution/dist/control-plane.js
|
|
35289
35378
|
function parseControlPlaneRequest(input) {
|
|
35290
35379
|
const parsed = atsdControlPlaneRequestSchema.safeParse(input);
|
|
35291
35380
|
if (!parsed.success) throw new Error("invalid daemon control-plane request");
|
|
@@ -35467,7 +35556,7 @@ function parseControlPlaneResponse(input) {
|
|
|
35467
35556
|
}
|
|
35468
35557
|
|
|
35469
35558
|
//#endregion
|
|
35470
|
-
//#region ../../runtime/
|
|
35559
|
+
//#region ../../runtime/local-execution/dist/control-plane-auth.js
|
|
35471
35560
|
const verifyControlPlaneToken = (input) => input.providedToken === input.expectedToken;
|
|
35472
35561
|
const buildAuthenticatedControlPlaneResponse = async (input) => {
|
|
35473
35562
|
const request = parseControlPlaneRequest(input.request);
|
|
@@ -35482,7 +35571,7 @@ const buildAuthenticatedControlPlaneResponse = async (input) => {
|
|
|
35482
35571
|
};
|
|
35483
35572
|
|
|
35484
35573
|
//#endregion
|
|
35485
|
-
//#region ../../runtime/
|
|
35574
|
+
//#region ../../runtime/local-execution/dist/data-plane-contract.js
|
|
35486
35575
|
const buildIdempotencyKey = buildIdempotencyKey$1;
|
|
35487
35576
|
const shouldDedupeWithinWindow = (input) => {
|
|
35488
35577
|
return shouldDedupeWithinWindow$1({
|
|
@@ -35496,7 +35585,7 @@ const shouldBypassDedupeForDeliveryRecoveryReason = (reason) => {
|
|
|
35496
35585
|
};
|
|
35497
35586
|
|
|
35498
35587
|
//#endregion
|
|
35499
|
-
//#region ../../runtime/
|
|
35588
|
+
//#region ../../runtime/local-execution/dist/heartbeat-policy.js
|
|
35500
35589
|
const HEARTBEAT_POLICY_DEFAULTS = {
|
|
35501
35590
|
watchdogTimeoutMs: 45e3,
|
|
35502
35591
|
heartbeatIdleIntervalMs: 6e4,
|
|
@@ -35513,7 +35602,7 @@ const HEARTBEAT_POLICY_DEFAULTS = {
|
|
|
35513
35602
|
};
|
|
35514
35603
|
|
|
35515
35604
|
//#endregion
|
|
35516
|
-
//#region ../../runtime/
|
|
35605
|
+
//#region ../../runtime/local-execution/dist/ledger-store.js
|
|
35517
35606
|
const LEDGER_STATE_VERSION = 1;
|
|
35518
35607
|
const LEDGER_STATE_INVALID_JSON_ERROR = "ledger.state.invalid_json";
|
|
35519
35608
|
const LEDGER_STATE_SCHEMA_ERROR = "ledger.state.schema_invalid";
|
|
@@ -36080,7 +36169,7 @@ function resolveStoredAgentControllerRef(agentControllerRef) {
|
|
|
36080
36169
|
}
|
|
36081
36170
|
|
|
36082
36171
|
//#endregion
|
|
36083
|
-
//#region ../../runtime/
|
|
36172
|
+
//#region ../../runtime/local-execution/dist/trigger-policy.js
|
|
36084
36173
|
const shouldDispatchForMentionOnly = (input) => {
|
|
36085
36174
|
const triggerMode = input.triggerMode ?? LEGACY_RUNTIME_DISPATCH_POLICY;
|
|
36086
36175
|
if (triggerMode === "listen_all") return true;
|
|
@@ -36088,7 +36177,7 @@ const shouldDispatchForMentionOnly = (input) => {
|
|
|
36088
36177
|
};
|
|
36089
36178
|
|
|
36090
36179
|
//#endregion
|
|
36091
|
-
//#region ../../runtime/
|
|
36180
|
+
//#region ../../runtime/local-execution/dist/mention-dispatch-integration.js
|
|
36092
36181
|
const dispatchMentionOnlyTask = async (input) => {
|
|
36093
36182
|
if (!shouldDispatchForMentionOnly({
|
|
36094
36183
|
mentioned: input.mentioned,
|
|
@@ -36164,7 +36253,7 @@ const normalizeAgentControllerConversationId = (value) => {
|
|
|
36164
36253
|
};
|
|
36165
36254
|
|
|
36166
36255
|
//#endregion
|
|
36167
|
-
//#region ../../runtime/
|
|
36256
|
+
//#region ../../runtime/local-execution/dist/recovery-policy.js
|
|
36168
36257
|
const cloneLedgerState = (state) => ({
|
|
36169
36258
|
dedupeFirstSeenByKey: { ...state.dedupeFirstSeenByKey },
|
|
36170
36259
|
inflightByTaskId: Object.fromEntries(Object.entries(state.inflightByTaskId).map(([taskId, inflight]) => [taskId, { ...inflight }])),
|
|
@@ -36263,7 +36352,7 @@ const buildTaskResultPayloadFromOutcome = (input) => {
|
|
|
36263
36352
|
};
|
|
36264
36353
|
|
|
36265
36354
|
//#endregion
|
|
36266
|
-
//#region ../../runtime/
|
|
36355
|
+
//#region ../../runtime/local-execution/dist/result-envelope.js
|
|
36267
36356
|
const buildTaskResultEnvelope = (payload) => {
|
|
36268
36357
|
const parsed = atsdTaskResultEnvelopeWriteSchema.safeParse({
|
|
36269
36358
|
v: ATSD_TASK_RESULT_SCHEMA_VERSION,
|
|
@@ -36275,14 +36364,14 @@ const buildTaskResultEnvelope = (payload) => {
|
|
|
36275
36364
|
};
|
|
36276
36365
|
|
|
36277
36366
|
//#endregion
|
|
36278
|
-
//#region ../../runtime/
|
|
36367
|
+
//#region ../../runtime/local-execution/dist/runtime-health-contract.js
|
|
36279
36368
|
const RUNTIME_HEALTH_SEVERITY = {
|
|
36280
36369
|
error: "error",
|
|
36281
36370
|
warn: "warn"
|
|
36282
36371
|
};
|
|
36283
36372
|
|
|
36284
36373
|
//#endregion
|
|
36285
|
-
//#region ../../runtime/
|
|
36374
|
+
//#region ../../runtime/local-execution/dist/runtime-task-lifecycle-contract.js
|
|
36286
36375
|
const RUNTIME_INFLIGHT_TASK_TRANSITION_MATRIX = {
|
|
36287
36376
|
trackNewInflightTask: {
|
|
36288
36377
|
kind: "track_new_inflight_task",
|
|
@@ -36343,7 +36432,7 @@ const resolveTaskResultTransitionForPayloadStatus = (input) => {
|
|
|
36343
36432
|
const resolveRuntimeTaskResultDeliverySemantic = (input) => resolveTaskResultDeliverySemantic({ payloadStatus: input.payloadStatus });
|
|
36344
36433
|
|
|
36345
36434
|
//#endregion
|
|
36346
|
-
//#region ../../runtime/
|
|
36435
|
+
//#region ../../runtime/local-execution/dist/runtime-health-invariant-policy.js
|
|
36347
36436
|
const normalizeHumanContext = (humanContext) => humanContext && Object.keys(humanContext).length > 0 ? humanContext : null;
|
|
36348
36437
|
const buildRuntimeReplayStuckFinding = (input) => ({
|
|
36349
36438
|
reasonCode: "runtime.replay_stuck",
|
|
@@ -36389,7 +36478,7 @@ const resolveRuntimeResultMappingViolation = (input) => {
|
|
|
36389
36478
|
};
|
|
36390
36479
|
|
|
36391
36480
|
//#endregion
|
|
36392
|
-
//#region ../../runtime/
|
|
36481
|
+
//#region ../../runtime/local-execution/dist/runtime-health-view.js
|
|
36393
36482
|
const emitRuntimeHealthFinding = (input) => {
|
|
36394
36483
|
emitHealthFinding({
|
|
36395
36484
|
eventName: input.eventName,
|
|
@@ -36399,7 +36488,7 @@ const emitRuntimeHealthFinding = (input) => {
|
|
|
36399
36488
|
};
|
|
36400
36489
|
|
|
36401
36490
|
//#endregion
|
|
36402
|
-
//#region ../../runtime/
|
|
36491
|
+
//#region ../../runtime/local-execution/dist/runtime-workspace-fingerprint.js
|
|
36403
36492
|
const SHA256_PREFIX = "sha256:";
|
|
36404
36493
|
function normalizeWorkspacePath(workspacePath) {
|
|
36405
36494
|
const trimmed = workspacePath.trim();
|
|
@@ -36412,7 +36501,7 @@ function buildRuntimeWorkspaceFingerprint(workspacePath) {
|
|
|
36412
36501
|
}
|
|
36413
36502
|
|
|
36414
36503
|
//#endregion
|
|
36415
|
-
//#region ../../runtime/
|
|
36504
|
+
//#region ../../runtime/local-execution/dist/runtime-task-orchestrator.js
|
|
36416
36505
|
const mapAdapterErrorType = (errorType) => {
|
|
36417
36506
|
if (errorType === "adapter") return "adapter";
|
|
36418
36507
|
if (errorType === "auth") return "auth";
|
|
@@ -37988,494 +38077,275 @@ function buildDispatchCorrelation(input) {
|
|
|
37988
38077
|
}
|
|
37989
38078
|
|
|
37990
38079
|
//#endregion
|
|
37991
|
-
//#region src/
|
|
37992
|
-
|
|
37993
|
-
"
|
|
37994
|
-
|
|
37995
|
-
|
|
37996
|
-
"dispatch.lifecycle.send_failed",
|
|
37997
|
-
"dispatch.result.queued",
|
|
37998
|
-
"dispatch.result.sent",
|
|
37999
|
-
"dispatch.result.send_failed",
|
|
38000
|
-
"dispatch.result.accepted"
|
|
38001
|
-
];
|
|
38002
|
-
function emitDaemonDispatchJournalEvent(input) {
|
|
38003
|
-
const event = {
|
|
38004
|
-
schema: "ats-daemon-dispatch-event-v1",
|
|
38005
|
-
v: 1,
|
|
38006
|
-
type: input.type,
|
|
38007
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
38008
|
-
lane: resolveAtsEnvPreset(input.pathInput),
|
|
38009
|
-
pid: process$1.pid,
|
|
38010
|
-
sessionId: resolveCliContextId(),
|
|
38011
|
-
attemptId: normalizeOptionalString$12(input.attemptId),
|
|
38012
|
-
connectionGeneration: normalizeOptionalInteger(input.connectionGeneration),
|
|
38013
|
-
daemonSessionId: normalizeOptionalString$12(input.daemonSessionId),
|
|
38014
|
-
dispatchId: input.dispatchId,
|
|
38015
|
-
leaseEpoch: normalizeOptionalInteger(input.leaseEpoch),
|
|
38016
|
-
profileId: normalizeOptionalString$12(input.profileId),
|
|
38017
|
-
result: normalizeOptionalString$12(input.result),
|
|
38018
|
-
taskId: normalizeOptionalString$12(input.taskId),
|
|
38019
|
-
...input.metadata ? { metadata: input.metadata } : {}
|
|
38020
|
-
};
|
|
38021
|
-
if (!isDaemonDispatchJournalEvent(event)) {
|
|
38022
|
-
console.warn(`[ats:dispatch-journal] rejected invalid event ${input.type}`);
|
|
38023
|
-
return;
|
|
38024
|
-
}
|
|
38025
|
-
try {
|
|
38026
|
-
const journalPath = daemonDispatchJournalPath(input.pathInput);
|
|
38027
|
-
mkdirSync(dirname(journalPath), { recursive: true });
|
|
38028
|
-
appendFileSync(journalPath, `${JSON.stringify(event)}\n`, "utf8");
|
|
38029
|
-
} catch (error) {
|
|
38030
|
-
console.warn(`[ats:dispatch-journal] failed to append event ${input.type}: ${toJournalErrorMessage(error)}`);
|
|
38031
|
-
}
|
|
38032
|
-
}
|
|
38033
|
-
function readRecentDaemonDispatchJournalEvents(input) {
|
|
38034
|
-
const normalizedDispatchId = normalizeOptionalString$12(input.dispatchId);
|
|
38035
|
-
if (!normalizedDispatchId) return [];
|
|
38036
|
-
const limit = Math.max(1, Math.min(100, input.limit ?? 20));
|
|
38037
|
-
const journalPath = daemonDispatchJournalPath(input.pathInput);
|
|
38038
|
-
if (!existsSync(journalPath)) return [];
|
|
38080
|
+
//#region src/daemon/state/context-store.ts
|
|
38081
|
+
async function loadContextStore(contextStorePath) {
|
|
38082
|
+
const raw = await readFile(contextStorePath, "utf8").catch(() => "");
|
|
38083
|
+
if (!raw) return /* @__PURE__ */ new Map();
|
|
38084
|
+
let parsed;
|
|
38039
38085
|
try {
|
|
38040
|
-
|
|
38041
|
-
const trimmed = line.trim();
|
|
38042
|
-
if (!trimmed) return [];
|
|
38043
|
-
try {
|
|
38044
|
-
const parsed = JSON.parse(trimmed);
|
|
38045
|
-
return isDaemonDispatchJournalEvent(parsed) && parsed.dispatchId === normalizedDispatchId ? [parsed] : [];
|
|
38046
|
-
} catch {
|
|
38047
|
-
return [];
|
|
38048
|
-
}
|
|
38049
|
-
}).slice(0, limit).reverse();
|
|
38086
|
+
parsed = JSON.parse(raw);
|
|
38050
38087
|
} catch {
|
|
38051
|
-
return
|
|
38088
|
+
return /* @__PURE__ */ new Map();
|
|
38052
38089
|
}
|
|
38090
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return /* @__PURE__ */ new Map();
|
|
38091
|
+
const contextStore = /* @__PURE__ */ new Map();
|
|
38092
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
38093
|
+
const normalizedKey = normalizeOptionalText$50(key);
|
|
38094
|
+
const normalizedValue = normalizeOptionalText$50(value);
|
|
38095
|
+
if (!(normalizedKey && normalizedValue)) continue;
|
|
38096
|
+
contextStore.set(normalizedKey, normalizedValue);
|
|
38097
|
+
}
|
|
38098
|
+
return contextStore;
|
|
38053
38099
|
}
|
|
38054
|
-
|
|
38055
|
-
|
|
38056
|
-
|
|
38057
|
-
|
|
38100
|
+
|
|
38101
|
+
//#endregion
|
|
38102
|
+
//#region src/daemon/state/daemon-runtime-state.ts
|
|
38103
|
+
function resolveDaemonRunMode$1(inputMode) {
|
|
38104
|
+
if (process.env[DAEMON_SERVICE_RUNTIME_DETACHED_ENV] === "1") return "background";
|
|
38105
|
+
const envMode = parseDaemonRunMode$1(process.env[DAEMON_SERVICE_RUNTIME_MODE_ENV]);
|
|
38106
|
+
if (envMode) return envMode;
|
|
38107
|
+
if (inputMode === "foreground") return "foreground";
|
|
38108
|
+
return "background";
|
|
38058
38109
|
}
|
|
38059
|
-
function
|
|
38060
|
-
const normalized =
|
|
38061
|
-
|
|
38110
|
+
function parseDaemonRunMode$1(value) {
|
|
38111
|
+
const normalized = normalizeText$9(value).toLowerCase();
|
|
38112
|
+
if (normalized === "foreground" || normalized === "background") return normalized;
|
|
38113
|
+
return null;
|
|
38062
38114
|
}
|
|
38063
|
-
function
|
|
38064
|
-
if (
|
|
38065
|
-
if (
|
|
38066
|
-
return
|
|
38115
|
+
function shouldPersistDaemonRuntimeState(input) {
|
|
38116
|
+
if (input.forcePersist) return true;
|
|
38117
|
+
if ("stopRequestedAt" in input.updates) return true;
|
|
38118
|
+
return input.nowMs - input.lastPersistedAtMs >= RUNTIME_STATE_PERSIST_MIN_INTERVAL_MS;
|
|
38067
38119
|
}
|
|
38068
|
-
function
|
|
38069
|
-
|
|
38120
|
+
function resolveReconnectBackoffMs(attempt) {
|
|
38121
|
+
const next = DEFAULT_RECONNECT_DELAY_MS * 2 ** (Math.max(1, attempt) - 1);
|
|
38122
|
+
return Math.min(MAX_RECONNECT_DELAY_MS, next);
|
|
38123
|
+
}
|
|
38124
|
+
function toDaemonStreamUrl(baseUrl) {
|
|
38125
|
+
const url = new URL(baseUrl);
|
|
38126
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
38127
|
+
url.pathname = "/v1/daemon/stream";
|
|
38128
|
+
url.search = "";
|
|
38129
|
+
url.hash = "";
|
|
38130
|
+
return url.toString();
|
|
38131
|
+
}
|
|
38132
|
+
function buildDaemonProcessCommand() {
|
|
38133
|
+
const script = normalizeText$9(process.argv[1]);
|
|
38134
|
+
const args = process.argv.slice(2);
|
|
38135
|
+
const values = script ? [script, ...args] : args;
|
|
38136
|
+
if (values.length === 0) return process.execPath;
|
|
38137
|
+
return `${process.execPath} ${values.join(" ")}`;
|
|
38138
|
+
}
|
|
38139
|
+
function createDaemonRuntimeState(input) {
|
|
38140
|
+
return {
|
|
38141
|
+
v: 1,
|
|
38142
|
+
schema: DAEMON_SERVICE_RUNTIME_STATE_SCHEMA,
|
|
38143
|
+
status: "running",
|
|
38144
|
+
mode: input.mode,
|
|
38145
|
+
pid: input.pid,
|
|
38146
|
+
command: input.command,
|
|
38147
|
+
gatewayUrl: input.gatewayUrl,
|
|
38148
|
+
atsProfileId: input.atsProfileId,
|
|
38149
|
+
workingDirectory: input.workingDirectory,
|
|
38150
|
+
stopRequestedAt: input.stopRequestedAt,
|
|
38151
|
+
startedAt: input.startedAt,
|
|
38152
|
+
updatedAt: input.updatedAt,
|
|
38153
|
+
heartbeatAt: input.heartbeatAt,
|
|
38154
|
+
managedBySystemService: input.runtimeMetadata.managedBySystemService,
|
|
38155
|
+
serviceController: input.runtimeMetadata.serviceController,
|
|
38156
|
+
autoStart: input.runtimeMetadata.autoStart
|
|
38157
|
+
};
|
|
38070
38158
|
}
|
|
38071
38159
|
|
|
38072
38160
|
//#endregion
|
|
38073
|
-
//#region src/
|
|
38074
|
-
const
|
|
38075
|
-
function
|
|
38076
|
-
const
|
|
38077
|
-
const
|
|
38078
|
-
const
|
|
38079
|
-
|
|
38080
|
-
const
|
|
38081
|
-
|
|
38082
|
-
|
|
38083
|
-
|
|
38084
|
-
|
|
38085
|
-
|
|
38086
|
-
|
|
38087
|
-
|
|
38088
|
-
|
|
38089
|
-
|
|
38090
|
-
|
|
38091
|
-
|
|
38092
|
-
|
|
38093
|
-
|
|
38094
|
-
|
|
38095
|
-
|
|
38096
|
-
|
|
38097
|
-
|
|
38098
|
-
|
|
38099
|
-
|
|
38100
|
-
|
|
38101
|
-
|
|
38102
|
-
|
|
38103
|
-
|
|
38104
|
-
|
|
38105
|
-
|
|
38106
|
-
|
|
38107
|
-
|
|
38108
|
-
|
|
38109
|
-
|
|
38110
|
-
|
|
38111
|
-
dispatchId: owner.dispatchId,
|
|
38112
|
-
executionTokenRunId: owner.executionTokenRunId,
|
|
38113
|
-
runtimeCoordinatorExecutionId: owner.runtimeCoordinatorExecutionId,
|
|
38114
|
-
taskId: owner.taskId
|
|
38115
|
-
};
|
|
38116
|
-
};
|
|
38117
|
-
const clearQueuedLifecycle = (pendingTask) => {
|
|
38118
|
-
pendingTask.stopQueuedLifecycle?.();
|
|
38119
|
-
pendingTask.stopQueuedLifecycle = null;
|
|
38120
|
-
};
|
|
38121
|
-
const releaseTaskOwnership = (task) => {
|
|
38122
|
-
ownedAttemptKeys.delete(buildAttemptKey(task.dispatchId, task.attemptId));
|
|
38123
|
-
const activeOwner = ownedTaskIds.get(task.taskId);
|
|
38124
|
-
if (activeOwner && activeOwner.attemptId === task.attemptId && activeOwner.dispatchId === task.dispatchId) ownedTaskIds.delete(task.taskId);
|
|
38125
|
-
};
|
|
38126
|
-
const notifyDrainWaitersIfIdle = () => {
|
|
38127
|
-
if (pendingTasks.length > 0 || activeGlobal > 0) return;
|
|
38128
|
-
while (drainWaiters.length > 0) drainWaiters.shift()?.();
|
|
38129
|
-
};
|
|
38130
|
-
const pump = () => {
|
|
38131
|
-
while (activeGlobal < input.limits.globalConcurrency) {
|
|
38132
|
-
const nextTaskIndex = pendingTasks.findIndex((candidate) => {
|
|
38133
|
-
return resolveActiveForLane(candidate.task.localExecutionLaneKey) < LOCAL_EXECUTION_LANE_CONCURRENCY_LIMIT;
|
|
38134
|
-
});
|
|
38135
|
-
if (nextTaskIndex < 0) break;
|
|
38136
|
-
const selectedPendingTask = pendingTasks.splice(nextTaskIndex, 1)[0];
|
|
38137
|
-
if (!selectedPendingTask) continue;
|
|
38138
|
-
clearQueuedLifecycle(selectedPendingTask);
|
|
38139
|
-
const selectedTask = selectedPendingTask.task;
|
|
38140
|
-
activeGlobal += 1;
|
|
38141
|
-
activeCountByLaneKey.set(selectedTask.localExecutionLaneKey, resolveActiveForLane(selectedTask.localExecutionLaneKey) + 1);
|
|
38142
|
-
const startedEvent = {
|
|
38143
|
-
adapterId: selectedTask.adapterId,
|
|
38144
|
-
attemptId: selectedTask.attemptId,
|
|
38145
|
-
controllerKey: selectedTask.controllerKey,
|
|
38146
|
-
dispatchId: selectedTask.dispatchId,
|
|
38147
|
-
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38148
|
-
localQueue: buildLocalQueueDiagnostics({
|
|
38149
|
-
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38150
|
-
queuePosition: null,
|
|
38151
|
-
status: "starting_runtime",
|
|
38152
|
-
waitReason: "none"
|
|
38153
|
-
}),
|
|
38154
|
-
profileId: selectedTask.profileId,
|
|
38155
|
-
spaceId: selectedTask.spaceId,
|
|
38156
|
-
taskId: selectedTask.taskId,
|
|
38157
|
-
targetLabel: selectedTask.targetLabel,
|
|
38158
|
-
transportMode: selectedTask.transportMode,
|
|
38159
|
-
...buildSnapshot(selectedTask.localExecutionLaneKey)
|
|
38160
|
-
};
|
|
38161
|
-
input.onTaskStarted?.(startedEvent);
|
|
38162
|
-
const startedAtMs = Date.now();
|
|
38163
|
-
Promise.resolve().then(async () => {
|
|
38164
|
-
const completionResult = resolveTaskCompletionResult(await selectedTask.run());
|
|
38165
|
-
input.onTaskCompleted?.({
|
|
38166
|
-
adapterId: selectedTask.adapterId,
|
|
38167
|
-
attemptId: selectedTask.attemptId,
|
|
38168
|
-
...buildSnapshot(selectedTask.localExecutionLaneKey),
|
|
38169
|
-
controllerKey: selectedTask.controllerKey,
|
|
38170
|
-
dispatchId: selectedTask.dispatchId,
|
|
38171
|
-
durationMs: Math.max(0, Date.now() - startedAtMs),
|
|
38172
|
-
errorCode: completionResult.errorCode,
|
|
38173
|
-
errorMessage: completionResult.errorMessage,
|
|
38174
|
-
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38175
|
-
localQueue: buildLocalQueueDiagnostics({
|
|
38176
|
-
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38177
|
-
queuePosition: null,
|
|
38178
|
-
status: "starting_runtime",
|
|
38179
|
-
waitReason: "none"
|
|
38180
|
-
}),
|
|
38181
|
-
profileId: selectedTask.profileId,
|
|
38182
|
-
result: completionResult.result,
|
|
38183
|
-
spaceId: selectedTask.spaceId,
|
|
38184
|
-
taskId: selectedTask.taskId,
|
|
38185
|
-
targetLabel: selectedTask.targetLabel,
|
|
38186
|
-
transportMode: selectedTask.transportMode
|
|
38187
|
-
});
|
|
38188
|
-
}).catch((error) => {
|
|
38189
|
-
input.onTaskCompleted?.({
|
|
38190
|
-
adapterId: selectedTask.adapterId,
|
|
38191
|
-
attemptId: selectedTask.attemptId,
|
|
38192
|
-
...buildSnapshot(selectedTask.localExecutionLaneKey),
|
|
38193
|
-
controllerKey: selectedTask.controllerKey,
|
|
38194
|
-
dispatchId: selectedTask.dispatchId,
|
|
38195
|
-
durationMs: Math.max(0, Date.now() - startedAtMs),
|
|
38196
|
-
errorCode: null,
|
|
38197
|
-
errorMessage: toErrorMessage$14(error),
|
|
38198
|
-
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38199
|
-
localQueue: buildLocalQueueDiagnostics({
|
|
38200
|
-
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38201
|
-
queuePosition: null,
|
|
38202
|
-
status: "starting_runtime",
|
|
38203
|
-
waitReason: "none"
|
|
38204
|
-
}),
|
|
38205
|
-
profileId: selectedTask.profileId,
|
|
38206
|
-
result: "failed",
|
|
38207
|
-
spaceId: selectedTask.spaceId,
|
|
38208
|
-
taskId: selectedTask.taskId,
|
|
38209
|
-
targetLabel: selectedTask.targetLabel,
|
|
38210
|
-
transportMode: selectedTask.transportMode
|
|
38211
|
-
});
|
|
38212
|
-
}).finally(() => {
|
|
38213
|
-
releaseTaskOwnership(selectedTask);
|
|
38214
|
-
activeGlobal = Math.max(0, activeGlobal - 1);
|
|
38215
|
-
const remainingActiveForLane = Math.max(0, resolveActiveForLane(selectedTask.localExecutionLaneKey) - 1);
|
|
38216
|
-
if (remainingActiveForLane === 0) activeCountByLaneKey.delete(selectedTask.localExecutionLaneKey);
|
|
38217
|
-
else activeCountByLaneKey.set(selectedTask.localExecutionLaneKey, remainingActiveForLane);
|
|
38218
|
-
notifyDrainWaitersIfIdle();
|
|
38219
|
-
pump();
|
|
38220
|
-
});
|
|
38221
|
-
}
|
|
38222
|
-
};
|
|
38223
|
-
return {
|
|
38224
|
-
request(task) {
|
|
38225
|
-
const attemptKey = buildAttemptKey(task.dispatchId, task.attemptId);
|
|
38226
|
-
if (ownedAttemptKeys.has(attemptKey)) return {
|
|
38227
|
-
accepted: true,
|
|
38228
|
-
deduped: true,
|
|
38229
|
-
snapshot: buildSnapshot(task.localExecutionLaneKey)
|
|
38230
|
-
};
|
|
38231
|
-
const activeOwner = ownedTaskIds.get(task.taskId);
|
|
38232
|
-
if (activeOwner) return {
|
|
38233
|
-
accepted: false,
|
|
38234
|
-
activeOwner: buildTaskOwnerSnapshot(activeOwner),
|
|
38235
|
-
reason: "task.owner_conflict",
|
|
38236
|
-
snapshot: buildSnapshot(task.localExecutionLaneKey)
|
|
38237
|
-
};
|
|
38238
|
-
if (pendingTasks.length >= input.limits.queueMax) return {
|
|
38239
|
-
accepted: false,
|
|
38240
|
-
reason: "queue.full",
|
|
38241
|
-
snapshot: buildSnapshot(task.localExecutionLaneKey)
|
|
38242
|
-
};
|
|
38243
|
-
ownedAttemptKeys.add(attemptKey);
|
|
38244
|
-
ownedTaskIds.set(task.taskId, {
|
|
38245
|
-
attemptId: task.attemptId,
|
|
38246
|
-
dispatchId: task.dispatchId,
|
|
38247
|
-
executionTokenRunId: task.executionTokenRunId ?? null,
|
|
38248
|
-
runtimeCoordinatorExecutionId: task.runtimeCoordinatorExecutionId ?? null,
|
|
38249
|
-
taskId: task.taskId
|
|
38250
|
-
});
|
|
38251
|
-
const pendingTask = {
|
|
38252
|
-
stopQueuedLifecycle: null,
|
|
38253
|
-
task
|
|
38254
|
-
};
|
|
38255
|
-
pendingTasks.push(pendingTask);
|
|
38256
|
-
const snapshot = buildSnapshot(task.localExecutionLaneKey);
|
|
38257
|
-
if (task.onQueued) try {
|
|
38258
|
-
const queuePosition = pendingTasks.indexOf(pendingTask) + 1;
|
|
38259
|
-
const stopQueuedLifecycle = task.onQueued({
|
|
38260
|
-
adapterId: task.adapterId,
|
|
38261
|
-
attemptId: task.attemptId,
|
|
38262
|
-
controllerKey: task.controllerKey,
|
|
38263
|
-
dispatchId: task.dispatchId,
|
|
38264
|
-
localExecutionLaneKey: task.localExecutionLaneKey,
|
|
38265
|
-
localQueue: buildLocalQueueDiagnostics({
|
|
38266
|
-
localExecutionLaneKey: task.localExecutionLaneKey,
|
|
38267
|
-
queuePosition
|
|
38268
|
-
}),
|
|
38269
|
-
profileId: task.profileId,
|
|
38270
|
-
spaceId: task.spaceId,
|
|
38271
|
-
taskId: task.taskId,
|
|
38272
|
-
targetLabel: task.targetLabel,
|
|
38273
|
-
transportMode: task.transportMode,
|
|
38274
|
-
...snapshot
|
|
38275
|
-
});
|
|
38276
|
-
pendingTask.stopQueuedLifecycle = typeof stopQueuedLifecycle === "function" ? stopQueuedLifecycle : null;
|
|
38277
|
-
} catch (error) {
|
|
38278
|
-
pendingTasks.pop();
|
|
38279
|
-
releaseTaskOwnership(task);
|
|
38280
|
-
throw error;
|
|
38281
|
-
}
|
|
38282
|
-
pump();
|
|
38283
|
-
return {
|
|
38284
|
-
accepted: true,
|
|
38285
|
-
deduped: false,
|
|
38286
|
-
snapshot
|
|
38287
|
-
};
|
|
38288
|
-
},
|
|
38289
|
-
dropPendingTasks(inputDrop) {
|
|
38290
|
-
const reason = toPendingDropReason(inputDrop?.reason);
|
|
38291
|
-
const shouldDrop = inputDrop?.shouldDrop ?? (() => true);
|
|
38292
|
-
let droppedCount = 0;
|
|
38293
|
-
for (let index = pendingTasks.length - 1; index >= 0; index -= 1) {
|
|
38294
|
-
const pendingTask = pendingTasks[index];
|
|
38295
|
-
if (!(pendingTask && shouldDrop(pendingTask.task))) continue;
|
|
38296
|
-
pendingTasks.splice(index, 1);
|
|
38297
|
-
clearQueuedLifecycle(pendingTask);
|
|
38298
|
-
releaseTaskOwnership(pendingTask.task);
|
|
38299
|
-
droppedCount += 1;
|
|
38300
|
-
input.onTaskDropped?.({
|
|
38301
|
-
adapterId: pendingTask.task.adapterId,
|
|
38302
|
-
attemptId: pendingTask.task.attemptId,
|
|
38303
|
-
controllerKey: pendingTask.task.controllerKey,
|
|
38304
|
-
dispatchId: pendingTask.task.dispatchId,
|
|
38305
|
-
localExecutionLaneKey: pendingTask.task.localExecutionLaneKey,
|
|
38306
|
-
localQueue: buildLocalQueueDiagnostics({
|
|
38307
|
-
localExecutionLaneKey: pendingTask.task.localExecutionLaneKey,
|
|
38308
|
-
queuePosition: null,
|
|
38309
|
-
status: "queued"
|
|
38310
|
-
}),
|
|
38311
|
-
profileId: pendingTask.task.profileId,
|
|
38312
|
-
reason,
|
|
38313
|
-
spaceId: pendingTask.task.spaceId,
|
|
38314
|
-
taskId: pendingTask.task.taskId,
|
|
38315
|
-
targetLabel: pendingTask.task.targetLabel,
|
|
38316
|
-
transportMode: pendingTask.task.transportMode,
|
|
38317
|
-
...buildSnapshot(pendingTask.task.profileId)
|
|
38318
|
-
});
|
|
38319
|
-
}
|
|
38320
|
-
notifyDrainWaitersIfIdle();
|
|
38321
|
-
return { droppedCount };
|
|
38322
|
-
},
|
|
38323
|
-
drain() {
|
|
38324
|
-
if (pendingTasks.length === 0 && activeGlobal === 0) return Promise.resolve();
|
|
38325
|
-
return new Promise((resolve) => {
|
|
38326
|
-
drainWaiters.push(resolve);
|
|
38327
|
-
});
|
|
38328
|
-
},
|
|
38329
|
-
getDrainState() {
|
|
38330
|
-
return {
|
|
38331
|
-
activeGlobal,
|
|
38332
|
-
pendingCount: pendingTasks.length
|
|
38333
|
-
};
|
|
38334
|
-
},
|
|
38335
|
-
getSnapshot(localExecutionLaneKey) {
|
|
38336
|
-
return buildSnapshot(localExecutionLaneKey);
|
|
38337
|
-
}
|
|
38161
|
+
//#region src/daemon/state/route-catalog-cache.ts
|
|
38162
|
+
const ROUTE_CATALOG_CACHE_FILE = "route-catalog-cache.json";
|
|
38163
|
+
async function readDaemonRouteCatalogCache(input) {
|
|
38164
|
+
const lane = normalizeCacheLane(input.lane);
|
|
38165
|
+
const ownerUserId = normalizeCacheIdentityField(input.ownerUserId);
|
|
38166
|
+
const serviceBundleId = normalizeServiceBundleId(input.serviceBundleId);
|
|
38167
|
+
if (!(lane && ownerUserId && serviceBundleId)) return null;
|
|
38168
|
+
const cached = await readDaemonLocalStateFile({
|
|
38169
|
+
path: daemonRouteCatalogCachePath(),
|
|
38170
|
+
schema: daemonRouteCatalogCacheSchema
|
|
38171
|
+
});
|
|
38172
|
+
if (!cached || cached.ownerUserId !== ownerUserId || cached.lane !== lane || cached.serviceBundleId !== serviceBundleId) return null;
|
|
38173
|
+
return deserializeRouteCatalog(cached);
|
|
38174
|
+
}
|
|
38175
|
+
async function writeDaemonRouteCatalogCache(input) {
|
|
38176
|
+
const lane = normalizeCacheLane(input.lane);
|
|
38177
|
+
const ownerUserId = normalizeCacheIdentityField(input.ownerUserId);
|
|
38178
|
+
const serviceBundleId = normalizeServiceBundleId(input.serviceBundleId);
|
|
38179
|
+
if (!(lane && ownerUserId && serviceBundleId)) return;
|
|
38180
|
+
if (input.routeCatalog.profileIds.length === 0) {
|
|
38181
|
+
await clearDaemonRouteCatalogCache();
|
|
38182
|
+
return;
|
|
38183
|
+
}
|
|
38184
|
+
const value = {
|
|
38185
|
+
v: DAEMON_ROUTE_CATALOG_CACHE_SCHEMA_VERSION,
|
|
38186
|
+
schema: DAEMON_ROUTE_CATALOG_CACHE_SCHEMA_NAME,
|
|
38187
|
+
cachedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
38188
|
+
runtimeContractEpoch: CURRENT_DAEMON_EXECUTION_CONTRACT_EPOCH,
|
|
38189
|
+
ownerUserId,
|
|
38190
|
+
lane,
|
|
38191
|
+
serviceBundleId,
|
|
38192
|
+
profileIds: [...input.routeCatalog.profileIds],
|
|
38193
|
+
routes: input.routeCatalog.profileIds.map((profileId) => {
|
|
38194
|
+
const route = input.routeCatalog.routeByProfileId.get(profileId);
|
|
38195
|
+
if (!route) throw new Error(`route catalog is missing route for ${profileId}`);
|
|
38196
|
+
return serializeRouteConfig(route);
|
|
38197
|
+
}),
|
|
38198
|
+
skippedProfiles: [...input.routeCatalog.skippedProfiles]
|
|
38338
38199
|
};
|
|
38200
|
+
await writeDaemonLocalStateFile({
|
|
38201
|
+
path: daemonRouteCatalogCachePath(),
|
|
38202
|
+
schema: daemonRouteCatalogCacheSchema,
|
|
38203
|
+
value,
|
|
38204
|
+
mode: 384
|
|
38205
|
+
});
|
|
38339
38206
|
}
|
|
38340
|
-
function
|
|
38341
|
-
|
|
38207
|
+
async function clearDaemonRouteCatalogCache() {
|
|
38208
|
+
await rm(daemonRouteCatalogCachePath(), { force: true });
|
|
38342
38209
|
}
|
|
38343
|
-
function
|
|
38344
|
-
|
|
38345
|
-
if (typeof error === "string" && error.trim().length > 0) return error;
|
|
38346
|
-
return "unknown error";
|
|
38210
|
+
function daemonRouteCatalogCachePath() {
|
|
38211
|
+
return join(daemonRuntimeDataPath(), ROUTE_CATALOG_CACHE_FILE);
|
|
38347
38212
|
}
|
|
38348
|
-
function
|
|
38349
|
-
|
|
38350
|
-
errorCode: null,
|
|
38351
|
-
errorMessage: null,
|
|
38352
|
-
result: "success"
|
|
38353
|
-
};
|
|
38354
|
-
const normalizedResult = result.result === "failed" || result.result === "partial_success" || result.result === "success" ? result.result : "success";
|
|
38355
|
-
return {
|
|
38356
|
-
errorCode: toOptionalText(result.errorCode),
|
|
38357
|
-
errorMessage: toOptionalText(result.errorMessage),
|
|
38358
|
-
result: normalizedResult
|
|
38359
|
-
};
|
|
38213
|
+
function normalizeServiceBundleId(value) {
|
|
38214
|
+
return String(value ?? "").trim();
|
|
38360
38215
|
}
|
|
38361
|
-
function
|
|
38362
|
-
|
|
38363
|
-
const normalized = value.trim();
|
|
38364
|
-
return normalized.length > 0 ? normalized : null;
|
|
38216
|
+
function normalizeCacheIdentityField(value) {
|
|
38217
|
+
return String(value ?? "").trim();
|
|
38365
38218
|
}
|
|
38366
|
-
function
|
|
38367
|
-
|
|
38368
|
-
|
|
38369
|
-
return normalized.length > 0 ? normalized : "queue.drop";
|
|
38219
|
+
function normalizeCacheLane(value) {
|
|
38220
|
+
const parsed = daemonServiceLaneSchema.safeParse(normalizeCacheIdentityField(value));
|
|
38221
|
+
return parsed.success ? parsed.data : null;
|
|
38370
38222
|
}
|
|
38371
|
-
|
|
38372
|
-
|
|
38373
|
-
|
|
38374
|
-
|
|
38375
|
-
|
|
38376
|
-
|
|
38377
|
-
|
|
38378
|
-
|
|
38223
|
+
function serializeRouteConfig(route) {
|
|
38224
|
+
return {
|
|
38225
|
+
agentControllerRef: route.agentControllerRef,
|
|
38226
|
+
contextIdMappingSpec: route.contextIdMappingSpec,
|
|
38227
|
+
...route.launchContract ? { launchContract: route.launchContract } : {},
|
|
38228
|
+
profileId: route.profileId,
|
|
38229
|
+
streamingMode: route.streamingMode,
|
|
38230
|
+
transportMode: route.transportMode
|
|
38231
|
+
};
|
|
38379
38232
|
}
|
|
38380
|
-
function
|
|
38381
|
-
const
|
|
38382
|
-
|
|
38383
|
-
|
|
38384
|
-
|
|
38385
|
-
|
|
38386
|
-
|
|
38387
|
-
|
|
38388
|
-
|
|
38389
|
-
const launchStatus = input.state.launchStatus ?? (input.state.selectable ? "ready" : "not_available");
|
|
38390
|
-
const launchability = resolveLocalAgentControllerLaunchability({
|
|
38391
|
-
adapterSupported: adapterSupport?.supported ?? true,
|
|
38392
|
-
detected: input.state.detected,
|
|
38393
|
-
launchStatus,
|
|
38394
|
-
runtimeSupported: input.state.runtimeSupported,
|
|
38395
|
-
selectable: input.state.selectable,
|
|
38396
|
-
selectableReason: input.state.selectableReason
|
|
38233
|
+
function deserializeRouteCatalog(cache) {
|
|
38234
|
+
const routeByProfileId = /* @__PURE__ */ new Map();
|
|
38235
|
+
for (const route of cache.routes) routeByProfileId.set(route.profileId, {
|
|
38236
|
+
agentControllerRef: route.agentControllerRef,
|
|
38237
|
+
contextIdMappingSpec: route.contextIdMappingSpec,
|
|
38238
|
+
...route.launchContract ? { launchContract: route.launchContract } : {},
|
|
38239
|
+
profileId: route.profileId,
|
|
38240
|
+
streamingMode: route.streamingMode,
|
|
38241
|
+
transportMode: route.transportMode
|
|
38397
38242
|
});
|
|
38398
38243
|
return {
|
|
38399
|
-
|
|
38400
|
-
|
|
38401
|
-
|
|
38402
|
-
selectableReason: input.state.selectableReason
|
|
38403
|
-
}),
|
|
38404
|
-
agentControllerRef,
|
|
38405
|
-
detected: input.state.detected,
|
|
38406
|
-
displayName: input.state.displayName,
|
|
38407
|
-
enabled: input.state.enabled,
|
|
38408
|
-
launchability,
|
|
38409
|
-
launchStatus,
|
|
38410
|
-
launchStatusDetail: input.state.launchStatusDetail ?? null,
|
|
38411
|
-
registered: input.state.registered,
|
|
38412
|
-
selectable: input.state.selectable,
|
|
38413
|
-
selectableReason: input.state.selectableReason
|
|
38244
|
+
profileIds: [...cache.profileIds],
|
|
38245
|
+
routeByProfileId,
|
|
38246
|
+
skippedProfiles: [...cache.skippedProfiles]
|
|
38414
38247
|
};
|
|
38415
38248
|
}
|
|
38416
|
-
|
|
38417
|
-
|
|
38418
|
-
|
|
38419
|
-
|
|
38420
|
-
|
|
38421
|
-
|
|
38422
|
-
|
|
38423
|
-
|
|
38249
|
+
|
|
38250
|
+
//#endregion
|
|
38251
|
+
//#region src/daemon/state/runtime-state-tracker.ts
|
|
38252
|
+
function createDaemonRuntimeStateTracker(input) {
|
|
38253
|
+
let runtimeState = input.initialState;
|
|
38254
|
+
let lastRuntimeStatePersistAtMs = Date.now();
|
|
38255
|
+
const touchRuntimeState = async (updates, options) => {
|
|
38256
|
+
const nowAt = nowIsoString();
|
|
38257
|
+
runtimeState = {
|
|
38258
|
+
...runtimeState,
|
|
38259
|
+
...updates,
|
|
38260
|
+
updatedAt: updates.updatedAt ?? nowAt
|
|
38261
|
+
};
|
|
38262
|
+
if (!shouldPersistDaemonRuntimeState({
|
|
38263
|
+
forcePersist: options?.forcePersist === true,
|
|
38264
|
+
nowMs: Date.now(),
|
|
38265
|
+
lastPersistedAtMs: lastRuntimeStatePersistAtMs,
|
|
38266
|
+
updates
|
|
38267
|
+
})) return;
|
|
38268
|
+
await setDaemonServiceRuntimeState(runtimeState);
|
|
38269
|
+
if (input.leaseDescriptor) await writeDaemonRuntimeLease(buildDaemonRuntimeLease({
|
|
38270
|
+
descriptor: input.leaseDescriptor,
|
|
38271
|
+
runtimeState
|
|
38272
|
+
}));
|
|
38273
|
+
lastRuntimeStatePersistAtMs = Date.now();
|
|
38424
38274
|
};
|
|
38425
38275
|
return {
|
|
38426
|
-
|
|
38427
|
-
|
|
38276
|
+
getRuntimeState: () => runtimeState,
|
|
38277
|
+
touchRuntimeState
|
|
38428
38278
|
};
|
|
38429
38279
|
}
|
|
38430
|
-
function
|
|
38431
|
-
|
|
38432
|
-
if (
|
|
38433
|
-
|
|
38434
|
-
|
|
38435
|
-
|
|
38436
|
-
|
|
38280
|
+
async function resolveDaemonRuntimeLeaseDescriptor(input) {
|
|
38281
|
+
const [contract, activeBundle] = await Promise.all([readDaemonServiceContract().catch(() => null), readDaemonActiveBundleState().catch(() => null)]);
|
|
38282
|
+
if (contract) return {
|
|
38283
|
+
generation: contract.generation,
|
|
38284
|
+
bundleId: contract.bundleId
|
|
38285
|
+
};
|
|
38286
|
+
const activeBundleEntryPath = await resolveDaemonBundleEntryPathFromState(activeBundle).catch(() => null);
|
|
38287
|
+
const commandEntryPath = extractDaemonCommandEntryPath(input.command);
|
|
38288
|
+
const bundleId = (commandEntryPath ? resolveDaemonBundleIdFromEntryPath(commandEntryPath) : null) ?? (activeBundleEntryPath ? resolveDaemonBundleIdFromEntryPath(activeBundleEntryPath) : null) ?? activeBundle?.bundleId ?? null;
|
|
38289
|
+
if (!bundleId) return null;
|
|
38290
|
+
return {
|
|
38291
|
+
generation: 0,
|
|
38292
|
+
bundleId
|
|
38293
|
+
};
|
|
38437
38294
|
}
|
|
38438
|
-
function
|
|
38439
|
-
|
|
38440
|
-
|
|
38441
|
-
|
|
38442
|
-
|
|
38443
|
-
|
|
38444
|
-
|
|
38445
|
-
|
|
38295
|
+
function buildDaemonRuntimeLease(input) {
|
|
38296
|
+
return {
|
|
38297
|
+
schema: "ats-daemon-runtime-lease-v1",
|
|
38298
|
+
v: 1,
|
|
38299
|
+
generation: input.descriptor.generation,
|
|
38300
|
+
bundleId: input.descriptor.bundleId,
|
|
38301
|
+
pid: input.runtimeState.pid,
|
|
38302
|
+
mode: input.runtimeState.mode,
|
|
38303
|
+
startedAt: input.runtimeState.startedAt,
|
|
38304
|
+
updatedAt: input.runtimeState.updatedAt,
|
|
38305
|
+
heartbeatAt: input.runtimeState.heartbeatAt,
|
|
38306
|
+
serviceController: input.runtimeState.serviceController,
|
|
38307
|
+
managedBySystemService: input.runtimeState.managedBySystemService
|
|
38308
|
+
};
|
|
38446
38309
|
}
|
|
38447
38310
|
|
|
38448
38311
|
//#endregion
|
|
38449
|
-
//#region src/
|
|
38450
|
-
async function
|
|
38451
|
-
|
|
38452
|
-
|
|
38453
|
-
const
|
|
38454
|
-
|
|
38455
|
-
|
|
38456
|
-
|
|
38457
|
-
|
|
38458
|
-
|
|
38459
|
-
|
|
38460
|
-
|
|
38461
|
-
|
|
38462
|
-
|
|
38463
|
-
|
|
38464
|
-
|
|
38465
|
-
|
|
38466
|
-
|
|
38467
|
-
|
|
38312
|
+
//#region src/transport/ws.ts
|
|
38313
|
+
async function connectWebSocket(url, input) {
|
|
38314
|
+
return await new Promise((resolve, reject) => {
|
|
38315
|
+
const ws = new WebSocket(url, { headers: input?.headers });
|
|
38316
|
+
const closePromise = new Promise((r) => {
|
|
38317
|
+
ws.on("close", () => r());
|
|
38318
|
+
ws.on("error", () => r());
|
|
38319
|
+
});
|
|
38320
|
+
ws.on("open", () => {
|
|
38321
|
+
resolve({
|
|
38322
|
+
send: (data) => ws.send(data),
|
|
38323
|
+
close: (code, reason) => ws.close(code, reason),
|
|
38324
|
+
terminate: () => ws.terminate(),
|
|
38325
|
+
onMessage: (handler) => {
|
|
38326
|
+
ws.on("message", (buf) => handler(toUtf8(buf)));
|
|
38327
|
+
},
|
|
38328
|
+
onClose: (handler) => {
|
|
38329
|
+
ws.on("close", (code, reason) => handler(code, reason.toString("utf8")));
|
|
38330
|
+
},
|
|
38331
|
+
onError: (handler) => {
|
|
38332
|
+
ws.on("error", handler);
|
|
38333
|
+
},
|
|
38334
|
+
waitUntilClosed: async () => {
|
|
38335
|
+
await closePromise;
|
|
38336
|
+
}
|
|
38337
|
+
});
|
|
38338
|
+
});
|
|
38339
|
+
ws.on("error", (err) => {
|
|
38340
|
+
reject(err);
|
|
38341
|
+
});
|
|
38342
|
+
});
|
|
38468
38343
|
}
|
|
38469
|
-
function
|
|
38470
|
-
|
|
38471
|
-
|
|
38472
|
-
return
|
|
38473
|
-
|
|
38474
|
-
reasonCodes: [...new Set(submissions.flatMap((submission) => submission.reasonCodes).filter((reasonCode) => reasonCode.trim()))],
|
|
38475
|
-
reportCount: submissions.length,
|
|
38476
|
-
submittedCount,
|
|
38477
|
-
failedCount
|
|
38478
|
-
};
|
|
38344
|
+
function toUtf8(value) {
|
|
38345
|
+
if (typeof value === "string") return value;
|
|
38346
|
+
if (value instanceof Buffer) return value.toString("utf8");
|
|
38347
|
+
if (Array.isArray(value)) return Buffer.concat(value).toString("utf8");
|
|
38348
|
+
return String(value);
|
|
38479
38349
|
}
|
|
38480
38350
|
|
|
38481
38351
|
//#endregion
|
|
@@ -38486,6 +38356,88 @@ function resolveDaemonCapabilities(input) {
|
|
|
38486
38356
|
return { runtimeAdapters };
|
|
38487
38357
|
}
|
|
38488
38358
|
|
|
38359
|
+
//#endregion
|
|
38360
|
+
//#region src/local-service/dispatch/daemon-dispatch-journal.ts
|
|
38361
|
+
const DAEMON_DISPATCH_EVENT_TYPES = [
|
|
38362
|
+
"dispatch.deliver.received",
|
|
38363
|
+
"dispatch.local.phase",
|
|
38364
|
+
"dispatch.lifecycle.sent",
|
|
38365
|
+
"dispatch.lifecycle.send_failed",
|
|
38366
|
+
"dispatch.result.queued",
|
|
38367
|
+
"dispatch.result.sent",
|
|
38368
|
+
"dispatch.result.send_failed",
|
|
38369
|
+
"dispatch.result.accepted"
|
|
38370
|
+
];
|
|
38371
|
+
function emitDaemonDispatchJournalEvent(input) {
|
|
38372
|
+
const event = {
|
|
38373
|
+
schema: "ats-daemon-dispatch-event-v1",
|
|
38374
|
+
v: 1,
|
|
38375
|
+
type: input.type,
|
|
38376
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
38377
|
+
lane: resolveAtsEnvPreset(input.pathInput),
|
|
38378
|
+
pid: process$1.pid,
|
|
38379
|
+
sessionId: resolveCliContextId(),
|
|
38380
|
+
attemptId: normalizeOptionalString$12(input.attemptId),
|
|
38381
|
+
connectionGeneration: normalizeOptionalInteger(input.connectionGeneration),
|
|
38382
|
+
daemonSessionId: normalizeOptionalString$12(input.daemonSessionId),
|
|
38383
|
+
dispatchId: input.dispatchId,
|
|
38384
|
+
leaseEpoch: normalizeOptionalInteger(input.leaseEpoch),
|
|
38385
|
+
profileId: normalizeOptionalString$12(input.profileId),
|
|
38386
|
+
result: normalizeOptionalString$12(input.result),
|
|
38387
|
+
taskId: normalizeOptionalString$12(input.taskId),
|
|
38388
|
+
...input.metadata ? { metadata: input.metadata } : {}
|
|
38389
|
+
};
|
|
38390
|
+
if (!isDaemonDispatchJournalEvent(event)) {
|
|
38391
|
+
console.warn(`[ats:dispatch-journal] rejected invalid event ${input.type}`);
|
|
38392
|
+
return;
|
|
38393
|
+
}
|
|
38394
|
+
try {
|
|
38395
|
+
const journalPath = daemonDispatchJournalPath(input.pathInput);
|
|
38396
|
+
mkdirSync(dirname(journalPath), { recursive: true });
|
|
38397
|
+
appendFileSync(journalPath, `${JSON.stringify(event)}\n`, "utf8");
|
|
38398
|
+
} catch (error) {
|
|
38399
|
+
console.warn(`[ats:dispatch-journal] failed to append event ${input.type}: ${toJournalErrorMessage(error)}`);
|
|
38400
|
+
}
|
|
38401
|
+
}
|
|
38402
|
+
function readRecentDaemonDispatchJournalEvents(input) {
|
|
38403
|
+
const normalizedDispatchId = normalizeOptionalString$12(input.dispatchId);
|
|
38404
|
+
if (!normalizedDispatchId) return [];
|
|
38405
|
+
const limit = Math.max(1, Math.min(100, input.limit ?? 20));
|
|
38406
|
+
const journalPath = daemonDispatchJournalPath(input.pathInput);
|
|
38407
|
+
if (!existsSync(journalPath)) return [];
|
|
38408
|
+
try {
|
|
38409
|
+
return readFileSync(journalPath, "utf8").split("\n").reverse().flatMap((line) => {
|
|
38410
|
+
const trimmed = line.trim();
|
|
38411
|
+
if (!trimmed) return [];
|
|
38412
|
+
try {
|
|
38413
|
+
const parsed = JSON.parse(trimmed);
|
|
38414
|
+
return isDaemonDispatchJournalEvent(parsed) && parsed.dispatchId === normalizedDispatchId ? [parsed] : [];
|
|
38415
|
+
} catch {
|
|
38416
|
+
return [];
|
|
38417
|
+
}
|
|
38418
|
+
}).slice(0, limit).reverse();
|
|
38419
|
+
} catch {
|
|
38420
|
+
return [];
|
|
38421
|
+
}
|
|
38422
|
+
}
|
|
38423
|
+
function isDaemonDispatchJournalEvent(value) {
|
|
38424
|
+
if (!value || typeof value !== "object") return false;
|
|
38425
|
+
const candidate = value;
|
|
38426
|
+
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);
|
|
38427
|
+
}
|
|
38428
|
+
function normalizeOptionalString$12(value) {
|
|
38429
|
+
const normalized = String(value ?? "").trim();
|
|
38430
|
+
return normalized.length > 0 ? normalized : null;
|
|
38431
|
+
}
|
|
38432
|
+
function normalizeOptionalInteger(value) {
|
|
38433
|
+
if (typeof value !== "number") return null;
|
|
38434
|
+
if (!Number.isInteger(value)) return null;
|
|
38435
|
+
return value;
|
|
38436
|
+
}
|
|
38437
|
+
function toJournalErrorMessage(error) {
|
|
38438
|
+
return error instanceof Error ? error.message : String(error);
|
|
38439
|
+
}
|
|
38440
|
+
|
|
38489
38441
|
//#endregion
|
|
38490
38442
|
//#region src/daemon/dispatch/send-dispatch-result.ts
|
|
38491
38443
|
function sendDispatchResultEnvelopeFrame(input) {
|
|
@@ -38905,7 +38857,416 @@ const isDispatchResultOutboxRecord = (value) => {
|
|
|
38905
38857
|
};
|
|
38906
38858
|
|
|
38907
38859
|
//#endregion
|
|
38908
|
-
//#region src/
|
|
38860
|
+
//#region src/local-service/execution/local-execution-slots.ts
|
|
38861
|
+
const LOCAL_EXECUTION_LANE_CONCURRENCY_LIMIT = 1;
|
|
38862
|
+
function createLocalExecutionSlots(input) {
|
|
38863
|
+
const pendingTasks = [];
|
|
38864
|
+
const activeCountByLaneKey = /* @__PURE__ */ new Map();
|
|
38865
|
+
const ownedAttemptKeys = /* @__PURE__ */ new Set();
|
|
38866
|
+
const ownedTaskIds = /* @__PURE__ */ new Map();
|
|
38867
|
+
const drainWaiters = [];
|
|
38868
|
+
let activeGlobal = 0;
|
|
38869
|
+
const resolveActiveForLane = (localExecutionLaneKey) => {
|
|
38870
|
+
return activeCountByLaneKey.get(localExecutionLaneKey) ?? 0;
|
|
38871
|
+
};
|
|
38872
|
+
const buildSnapshot = (localExecutionLaneKey) => {
|
|
38873
|
+
return {
|
|
38874
|
+
activeForLane: resolveActiveForLane(localExecutionLaneKey),
|
|
38875
|
+
activeGlobal,
|
|
38876
|
+
limits: input.limits,
|
|
38877
|
+
queueDepth: pendingTasks.length
|
|
38878
|
+
};
|
|
38879
|
+
};
|
|
38880
|
+
const resolveWaitReason = (inputWait) => {
|
|
38881
|
+
if (activeGlobal >= input.limits.globalConcurrency) return "global_concurrency";
|
|
38882
|
+
if (resolveActiveForLane(inputWait.localExecutionLaneKey) >= LOCAL_EXECUTION_LANE_CONCURRENCY_LIMIT) return "local_execution_lane_concurrency";
|
|
38883
|
+
return "none";
|
|
38884
|
+
};
|
|
38885
|
+
const buildLocalQueueDiagnostics = (inputDiagnostics) => {
|
|
38886
|
+
const waitReason = inputDiagnostics.waitReason ?? resolveWaitReason({ localExecutionLaneKey: inputDiagnostics.localExecutionLaneKey });
|
|
38887
|
+
const status = inputDiagnostics.status ?? (waitReason === "none" ? "starting_runtime" : "queued");
|
|
38888
|
+
return {
|
|
38889
|
+
...buildSnapshot(inputDiagnostics.localExecutionLaneKey),
|
|
38890
|
+
queuePosition: status === "queued" ? inputDiagnostics.queuePosition : null,
|
|
38891
|
+
status,
|
|
38892
|
+
waitReason
|
|
38893
|
+
};
|
|
38894
|
+
};
|
|
38895
|
+
const buildTaskOwnerSnapshot = (owner) => {
|
|
38896
|
+
return {
|
|
38897
|
+
attemptId: owner.attemptId,
|
|
38898
|
+
dispatchId: owner.dispatchId,
|
|
38899
|
+
executionTokenRunId: owner.executionTokenRunId,
|
|
38900
|
+
runtimeCoordinatorExecutionId: owner.runtimeCoordinatorExecutionId,
|
|
38901
|
+
taskId: owner.taskId
|
|
38902
|
+
};
|
|
38903
|
+
};
|
|
38904
|
+
const clearQueuedLifecycle = (pendingTask) => {
|
|
38905
|
+
pendingTask.stopQueuedLifecycle?.();
|
|
38906
|
+
pendingTask.stopQueuedLifecycle = null;
|
|
38907
|
+
};
|
|
38908
|
+
const releaseTaskOwnership = (task) => {
|
|
38909
|
+
ownedAttemptKeys.delete(buildAttemptKey(task.dispatchId, task.attemptId));
|
|
38910
|
+
const activeOwner = ownedTaskIds.get(task.taskId);
|
|
38911
|
+
if (activeOwner && activeOwner.attemptId === task.attemptId && activeOwner.dispatchId === task.dispatchId) ownedTaskIds.delete(task.taskId);
|
|
38912
|
+
};
|
|
38913
|
+
const notifyDrainWaitersIfIdle = () => {
|
|
38914
|
+
if (pendingTasks.length > 0 || activeGlobal > 0) return;
|
|
38915
|
+
while (drainWaiters.length > 0) drainWaiters.shift()?.();
|
|
38916
|
+
};
|
|
38917
|
+
const pump = () => {
|
|
38918
|
+
while (activeGlobal < input.limits.globalConcurrency) {
|
|
38919
|
+
const nextTaskIndex = pendingTasks.findIndex((candidate) => {
|
|
38920
|
+
return resolveActiveForLane(candidate.task.localExecutionLaneKey) < LOCAL_EXECUTION_LANE_CONCURRENCY_LIMIT;
|
|
38921
|
+
});
|
|
38922
|
+
if (nextTaskIndex < 0) break;
|
|
38923
|
+
const selectedPendingTask = pendingTasks.splice(nextTaskIndex, 1)[0];
|
|
38924
|
+
if (!selectedPendingTask) continue;
|
|
38925
|
+
clearQueuedLifecycle(selectedPendingTask);
|
|
38926
|
+
const selectedTask = selectedPendingTask.task;
|
|
38927
|
+
activeGlobal += 1;
|
|
38928
|
+
activeCountByLaneKey.set(selectedTask.localExecutionLaneKey, resolveActiveForLane(selectedTask.localExecutionLaneKey) + 1);
|
|
38929
|
+
const startedEvent = {
|
|
38930
|
+
adapterId: selectedTask.adapterId,
|
|
38931
|
+
attemptId: selectedTask.attemptId,
|
|
38932
|
+
controllerKey: selectedTask.controllerKey,
|
|
38933
|
+
dispatchId: selectedTask.dispatchId,
|
|
38934
|
+
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38935
|
+
localQueue: buildLocalQueueDiagnostics({
|
|
38936
|
+
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38937
|
+
queuePosition: null,
|
|
38938
|
+
status: "starting_runtime",
|
|
38939
|
+
waitReason: "none"
|
|
38940
|
+
}),
|
|
38941
|
+
profileId: selectedTask.profileId,
|
|
38942
|
+
spaceId: selectedTask.spaceId,
|
|
38943
|
+
taskId: selectedTask.taskId,
|
|
38944
|
+
targetLabel: selectedTask.targetLabel,
|
|
38945
|
+
transportMode: selectedTask.transportMode,
|
|
38946
|
+
...buildSnapshot(selectedTask.localExecutionLaneKey)
|
|
38947
|
+
};
|
|
38948
|
+
input.onTaskStarted?.(startedEvent);
|
|
38949
|
+
const startedAtMs = Date.now();
|
|
38950
|
+
Promise.resolve().then(async () => {
|
|
38951
|
+
const completionResult = resolveTaskCompletionResult(await selectedTask.run());
|
|
38952
|
+
input.onTaskCompleted?.({
|
|
38953
|
+
adapterId: selectedTask.adapterId,
|
|
38954
|
+
attemptId: selectedTask.attemptId,
|
|
38955
|
+
...buildSnapshot(selectedTask.localExecutionLaneKey),
|
|
38956
|
+
controllerKey: selectedTask.controllerKey,
|
|
38957
|
+
dispatchId: selectedTask.dispatchId,
|
|
38958
|
+
durationMs: Math.max(0, Date.now() - startedAtMs),
|
|
38959
|
+
errorCode: completionResult.errorCode,
|
|
38960
|
+
errorMessage: completionResult.errorMessage,
|
|
38961
|
+
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38962
|
+
localQueue: buildLocalQueueDiagnostics({
|
|
38963
|
+
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38964
|
+
queuePosition: null,
|
|
38965
|
+
status: "starting_runtime",
|
|
38966
|
+
waitReason: "none"
|
|
38967
|
+
}),
|
|
38968
|
+
profileId: selectedTask.profileId,
|
|
38969
|
+
result: completionResult.result,
|
|
38970
|
+
spaceId: selectedTask.spaceId,
|
|
38971
|
+
taskId: selectedTask.taskId,
|
|
38972
|
+
targetLabel: selectedTask.targetLabel,
|
|
38973
|
+
transportMode: selectedTask.transportMode
|
|
38974
|
+
});
|
|
38975
|
+
}).catch((error) => {
|
|
38976
|
+
input.onTaskCompleted?.({
|
|
38977
|
+
adapterId: selectedTask.adapterId,
|
|
38978
|
+
attemptId: selectedTask.attemptId,
|
|
38979
|
+
...buildSnapshot(selectedTask.localExecutionLaneKey),
|
|
38980
|
+
controllerKey: selectedTask.controllerKey,
|
|
38981
|
+
dispatchId: selectedTask.dispatchId,
|
|
38982
|
+
durationMs: Math.max(0, Date.now() - startedAtMs),
|
|
38983
|
+
errorCode: null,
|
|
38984
|
+
errorMessage: toErrorMessage$14(error),
|
|
38985
|
+
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38986
|
+
localQueue: buildLocalQueueDiagnostics({
|
|
38987
|
+
localExecutionLaneKey: selectedTask.localExecutionLaneKey,
|
|
38988
|
+
queuePosition: null,
|
|
38989
|
+
status: "starting_runtime",
|
|
38990
|
+
waitReason: "none"
|
|
38991
|
+
}),
|
|
38992
|
+
profileId: selectedTask.profileId,
|
|
38993
|
+
result: "failed",
|
|
38994
|
+
spaceId: selectedTask.spaceId,
|
|
38995
|
+
taskId: selectedTask.taskId,
|
|
38996
|
+
targetLabel: selectedTask.targetLabel,
|
|
38997
|
+
transportMode: selectedTask.transportMode
|
|
38998
|
+
});
|
|
38999
|
+
}).finally(() => {
|
|
39000
|
+
releaseTaskOwnership(selectedTask);
|
|
39001
|
+
activeGlobal = Math.max(0, activeGlobal - 1);
|
|
39002
|
+
const remainingActiveForLane = Math.max(0, resolveActiveForLane(selectedTask.localExecutionLaneKey) - 1);
|
|
39003
|
+
if (remainingActiveForLane === 0) activeCountByLaneKey.delete(selectedTask.localExecutionLaneKey);
|
|
39004
|
+
else activeCountByLaneKey.set(selectedTask.localExecutionLaneKey, remainingActiveForLane);
|
|
39005
|
+
notifyDrainWaitersIfIdle();
|
|
39006
|
+
pump();
|
|
39007
|
+
});
|
|
39008
|
+
}
|
|
39009
|
+
};
|
|
39010
|
+
return {
|
|
39011
|
+
request(task) {
|
|
39012
|
+
const attemptKey = buildAttemptKey(task.dispatchId, task.attemptId);
|
|
39013
|
+
if (ownedAttemptKeys.has(attemptKey)) return {
|
|
39014
|
+
accepted: true,
|
|
39015
|
+
deduped: true,
|
|
39016
|
+
snapshot: buildSnapshot(task.localExecutionLaneKey)
|
|
39017
|
+
};
|
|
39018
|
+
const activeOwner = ownedTaskIds.get(task.taskId);
|
|
39019
|
+
if (activeOwner) return {
|
|
39020
|
+
accepted: false,
|
|
39021
|
+
activeOwner: buildTaskOwnerSnapshot(activeOwner),
|
|
39022
|
+
reason: "task.owner_conflict",
|
|
39023
|
+
snapshot: buildSnapshot(task.localExecutionLaneKey)
|
|
39024
|
+
};
|
|
39025
|
+
if (pendingTasks.length >= input.limits.queueMax) return {
|
|
39026
|
+
accepted: false,
|
|
39027
|
+
reason: "queue.full",
|
|
39028
|
+
snapshot: buildSnapshot(task.localExecutionLaneKey)
|
|
39029
|
+
};
|
|
39030
|
+
ownedAttemptKeys.add(attemptKey);
|
|
39031
|
+
ownedTaskIds.set(task.taskId, {
|
|
39032
|
+
attemptId: task.attemptId,
|
|
39033
|
+
dispatchId: task.dispatchId,
|
|
39034
|
+
executionTokenRunId: task.executionTokenRunId ?? null,
|
|
39035
|
+
runtimeCoordinatorExecutionId: task.runtimeCoordinatorExecutionId ?? null,
|
|
39036
|
+
taskId: task.taskId
|
|
39037
|
+
});
|
|
39038
|
+
const pendingTask = {
|
|
39039
|
+
stopQueuedLifecycle: null,
|
|
39040
|
+
task
|
|
39041
|
+
};
|
|
39042
|
+
pendingTasks.push(pendingTask);
|
|
39043
|
+
const snapshot = buildSnapshot(task.localExecutionLaneKey);
|
|
39044
|
+
if (task.onQueued) try {
|
|
39045
|
+
const queuePosition = pendingTasks.indexOf(pendingTask) + 1;
|
|
39046
|
+
const stopQueuedLifecycle = task.onQueued({
|
|
39047
|
+
adapterId: task.adapterId,
|
|
39048
|
+
attemptId: task.attemptId,
|
|
39049
|
+
controllerKey: task.controllerKey,
|
|
39050
|
+
dispatchId: task.dispatchId,
|
|
39051
|
+
localExecutionLaneKey: task.localExecutionLaneKey,
|
|
39052
|
+
localQueue: buildLocalQueueDiagnostics({
|
|
39053
|
+
localExecutionLaneKey: task.localExecutionLaneKey,
|
|
39054
|
+
queuePosition
|
|
39055
|
+
}),
|
|
39056
|
+
profileId: task.profileId,
|
|
39057
|
+
spaceId: task.spaceId,
|
|
39058
|
+
taskId: task.taskId,
|
|
39059
|
+
targetLabel: task.targetLabel,
|
|
39060
|
+
transportMode: task.transportMode,
|
|
39061
|
+
...snapshot
|
|
39062
|
+
});
|
|
39063
|
+
pendingTask.stopQueuedLifecycle = typeof stopQueuedLifecycle === "function" ? stopQueuedLifecycle : null;
|
|
39064
|
+
} catch (error) {
|
|
39065
|
+
pendingTasks.pop();
|
|
39066
|
+
releaseTaskOwnership(task);
|
|
39067
|
+
throw error;
|
|
39068
|
+
}
|
|
39069
|
+
pump();
|
|
39070
|
+
return {
|
|
39071
|
+
accepted: true,
|
|
39072
|
+
deduped: false,
|
|
39073
|
+
snapshot
|
|
39074
|
+
};
|
|
39075
|
+
},
|
|
39076
|
+
dropPendingTasks(inputDrop) {
|
|
39077
|
+
const reason = toPendingDropReason(inputDrop?.reason);
|
|
39078
|
+
const shouldDrop = inputDrop?.shouldDrop ?? (() => true);
|
|
39079
|
+
let droppedCount = 0;
|
|
39080
|
+
for (let index = pendingTasks.length - 1; index >= 0; index -= 1) {
|
|
39081
|
+
const pendingTask = pendingTasks[index];
|
|
39082
|
+
if (!(pendingTask && shouldDrop(pendingTask.task))) continue;
|
|
39083
|
+
pendingTasks.splice(index, 1);
|
|
39084
|
+
clearQueuedLifecycle(pendingTask);
|
|
39085
|
+
releaseTaskOwnership(pendingTask.task);
|
|
39086
|
+
droppedCount += 1;
|
|
39087
|
+
input.onTaskDropped?.({
|
|
39088
|
+
adapterId: pendingTask.task.adapterId,
|
|
39089
|
+
attemptId: pendingTask.task.attemptId,
|
|
39090
|
+
controllerKey: pendingTask.task.controllerKey,
|
|
39091
|
+
dispatchId: pendingTask.task.dispatchId,
|
|
39092
|
+
localExecutionLaneKey: pendingTask.task.localExecutionLaneKey,
|
|
39093
|
+
localQueue: buildLocalQueueDiagnostics({
|
|
39094
|
+
localExecutionLaneKey: pendingTask.task.localExecutionLaneKey,
|
|
39095
|
+
queuePosition: null,
|
|
39096
|
+
status: "queued"
|
|
39097
|
+
}),
|
|
39098
|
+
profileId: pendingTask.task.profileId,
|
|
39099
|
+
reason,
|
|
39100
|
+
spaceId: pendingTask.task.spaceId,
|
|
39101
|
+
taskId: pendingTask.task.taskId,
|
|
39102
|
+
targetLabel: pendingTask.task.targetLabel,
|
|
39103
|
+
transportMode: pendingTask.task.transportMode,
|
|
39104
|
+
...buildSnapshot(pendingTask.task.profileId)
|
|
39105
|
+
});
|
|
39106
|
+
}
|
|
39107
|
+
notifyDrainWaitersIfIdle();
|
|
39108
|
+
return { droppedCount };
|
|
39109
|
+
},
|
|
39110
|
+
drain() {
|
|
39111
|
+
if (pendingTasks.length === 0 && activeGlobal === 0) return Promise.resolve();
|
|
39112
|
+
return new Promise((resolve) => {
|
|
39113
|
+
drainWaiters.push(resolve);
|
|
39114
|
+
});
|
|
39115
|
+
},
|
|
39116
|
+
getDrainState() {
|
|
39117
|
+
return {
|
|
39118
|
+
activeGlobal,
|
|
39119
|
+
pendingCount: pendingTasks.length
|
|
39120
|
+
};
|
|
39121
|
+
},
|
|
39122
|
+
getSnapshot(localExecutionLaneKey) {
|
|
39123
|
+
return buildSnapshot(localExecutionLaneKey);
|
|
39124
|
+
}
|
|
39125
|
+
};
|
|
39126
|
+
}
|
|
39127
|
+
function buildAttemptKey(dispatchId, attemptId) {
|
|
39128
|
+
return `${dispatchId}::${attemptId}`;
|
|
39129
|
+
}
|
|
39130
|
+
function toErrorMessage$14(error) {
|
|
39131
|
+
if (error instanceof Error && error.message.trim().length > 0) return error.message;
|
|
39132
|
+
if (typeof error === "string" && error.trim().length > 0) return error;
|
|
39133
|
+
return "unknown error";
|
|
39134
|
+
}
|
|
39135
|
+
function resolveTaskCompletionResult(result) {
|
|
39136
|
+
if (!result || typeof result !== "object") return {
|
|
39137
|
+
errorCode: null,
|
|
39138
|
+
errorMessage: null,
|
|
39139
|
+
result: "success"
|
|
39140
|
+
};
|
|
39141
|
+
const normalizedResult = result.result === "failed" || result.result === "partial_success" || result.result === "success" ? result.result : "success";
|
|
39142
|
+
return {
|
|
39143
|
+
errorCode: toOptionalText(result.errorCode),
|
|
39144
|
+
errorMessage: toOptionalText(result.errorMessage),
|
|
39145
|
+
result: normalizedResult
|
|
39146
|
+
};
|
|
39147
|
+
}
|
|
39148
|
+
function toOptionalText(value) {
|
|
39149
|
+
if (typeof value !== "string") return null;
|
|
39150
|
+
const normalized = value.trim();
|
|
39151
|
+
return normalized.length > 0 ? normalized : null;
|
|
39152
|
+
}
|
|
39153
|
+
function toPendingDropReason(value) {
|
|
39154
|
+
if (typeof value !== "string") return "queue.drop";
|
|
39155
|
+
const normalized = value.trim();
|
|
39156
|
+
return normalized.length > 0 ? normalized : "queue.drop";
|
|
39157
|
+
}
|
|
39158
|
+
|
|
39159
|
+
//#endregion
|
|
39160
|
+
//#region src/local-service/inventory/agent-controller-inventory.ts
|
|
39161
|
+
async function collectLocalAgentControllerInventory(input = {}) {
|
|
39162
|
+
return { capabilities: (await listAgentTargetStates()).filter((state) => state.targetKind === "builtin").map((state) => resolveLocalAgentControllerInventoryItem({
|
|
39163
|
+
localAdapterContainer: input.localAdapterContainer,
|
|
39164
|
+
state
|
|
39165
|
+
})) };
|
|
39166
|
+
}
|
|
39167
|
+
function resolveLocalAgentControllerInventoryItem(input) {
|
|
39168
|
+
const agentControllerRef = buildAgentControllerRef({
|
|
39169
|
+
kind: "builtin",
|
|
39170
|
+
id: input.state.agentId
|
|
39171
|
+
});
|
|
39172
|
+
const adapterSupport = input.localAdapterContainer ? resolveLocalRuntimeControllerSupport({
|
|
39173
|
+
agentControllerRef,
|
|
39174
|
+
localAdapterContainer: input.localAdapterContainer
|
|
39175
|
+
}) : null;
|
|
39176
|
+
const launchStatus = input.state.launchStatus ?? (input.state.selectable ? "ready" : "not_available");
|
|
39177
|
+
const launchability = resolveLocalAgentControllerLaunchability({
|
|
39178
|
+
adapterSupported: adapterSupport?.supported ?? true,
|
|
39179
|
+
detected: input.state.detected,
|
|
39180
|
+
launchStatus,
|
|
39181
|
+
runtimeSupported: input.state.runtimeSupported,
|
|
39182
|
+
selectable: input.state.selectable,
|
|
39183
|
+
selectableReason: input.state.selectableReason
|
|
39184
|
+
});
|
|
39185
|
+
return {
|
|
39186
|
+
agentId: input.state.agentId,
|
|
39187
|
+
blockerReasonCodes: resolveLocalAgentControllerBlockerReasonCodes({
|
|
39188
|
+
launchability,
|
|
39189
|
+
selectableReason: input.state.selectableReason
|
|
39190
|
+
}),
|
|
39191
|
+
agentControllerRef,
|
|
39192
|
+
detected: input.state.detected,
|
|
39193
|
+
displayName: input.state.displayName,
|
|
39194
|
+
enabled: input.state.enabled,
|
|
39195
|
+
launchability,
|
|
39196
|
+
launchStatus,
|
|
39197
|
+
launchStatusDetail: input.state.launchStatusDetail ?? null,
|
|
39198
|
+
registered: input.state.registered,
|
|
39199
|
+
selectable: input.state.selectable,
|
|
39200
|
+
selectableReason: input.state.selectableReason
|
|
39201
|
+
};
|
|
39202
|
+
}
|
|
39203
|
+
function resolveLocalAgentControllerReportDecision(capability, input) {
|
|
39204
|
+
if (input.requireEnabled && !capability.enabled) return {
|
|
39205
|
+
localParticipationState: "needs_agent_prepare",
|
|
39206
|
+
reasonCodes: ["local_agent_preparation.not_enabled"]
|
|
39207
|
+
};
|
|
39208
|
+
if (capability.launchability !== "launchable" || !capability.selectable) return {
|
|
39209
|
+
localParticipationState: "needs_agent_prepare",
|
|
39210
|
+
reasonCodes: capability.blockerReasonCodes.length > 0 ? capability.blockerReasonCodes : [capability.selectableReason ? `local_agent_preparation.${capability.selectableReason}` : "local_agent_preparation.not_selectable"]
|
|
39211
|
+
};
|
|
39212
|
+
return {
|
|
39213
|
+
localParticipationState: "ready",
|
|
39214
|
+
reasonCodes: []
|
|
39215
|
+
};
|
|
39216
|
+
}
|
|
39217
|
+
function resolveLocalAgentControllerLaunchability(input) {
|
|
39218
|
+
if (!input.detected) return "not_detected";
|
|
39219
|
+
if (!input.runtimeSupported || input.selectableReason === "not_supported_yet") return "not_supported";
|
|
39220
|
+
if (input.launchStatus === "needs_choice") return "needs_choice";
|
|
39221
|
+
if (input.launchStatus === "needs_repair") return "needs_repair";
|
|
39222
|
+
if (input.launchStatus === "ready" && input.selectable && input.adapterSupported !== false) return "launchable";
|
|
39223
|
+
return "blocked";
|
|
39224
|
+
}
|
|
39225
|
+
function resolveLocalAgentControllerBlockerReasonCodes(input) {
|
|
39226
|
+
if (input.launchability === "launchable") return [];
|
|
39227
|
+
if (input.launchability === "needs_choice") return ["controller.launch.choice_required"];
|
|
39228
|
+
if (input.launchability === "needs_repair") return ["controller.launch.needs_repair"];
|
|
39229
|
+
if (input.launchability === "not_detected") return ["local_agent_preparation.not_detected"];
|
|
39230
|
+
if (input.launchability === "not_supported") return ["local_agent_preparation.not_supported_yet"];
|
|
39231
|
+
if (input.selectableReason) return [`local_agent_preparation.${input.selectableReason}`];
|
|
39232
|
+
return ["local_agent_preparation.not_enabled"];
|
|
39233
|
+
}
|
|
39234
|
+
|
|
39235
|
+
//#endregion
|
|
39236
|
+
//#region src/local-service/reporting/runtime-agent-controller-report-sync.ts
|
|
39237
|
+
async function syncLocalServiceRuntimeAgentControllerReports(input) {
|
|
39238
|
+
const reports = (await collectLocalAgentControllerInventory({ localAdapterContainer: input.localAdapterContainer })).capabilities.filter((capability) => capability.registered).map((capability) => {
|
|
39239
|
+
if (!capability.agentControllerRef) return null;
|
|
39240
|
+
const reportDecision = resolveLocalAgentControllerReportDecision(capability, { requireEnabled: true });
|
|
39241
|
+
return {
|
|
39242
|
+
agentControllerRef: capability.agentControllerRef,
|
|
39243
|
+
localParticipationState: reportDecision.localParticipationState,
|
|
39244
|
+
reasonCodes: reportDecision.reasonCodes
|
|
39245
|
+
};
|
|
39246
|
+
}).filter((report) => report !== null);
|
|
39247
|
+
if (reports.length === 0) return {
|
|
39248
|
+
status: "skipped",
|
|
39249
|
+
reasonCodes: ["runtime.agent_controller_report.no_local_controllers"],
|
|
39250
|
+
reportCount: 0,
|
|
39251
|
+
submittedCount: 0,
|
|
39252
|
+
failedCount: 0
|
|
39253
|
+
};
|
|
39254
|
+
return summarizeSubmissions(await submitRuntimeAgentControllerReports({ reports }));
|
|
39255
|
+
}
|
|
39256
|
+
function summarizeSubmissions(submissions) {
|
|
39257
|
+
const submittedCount = submissions.filter((submission) => submission.status === "submitted" && submission.agentControllerReportStatus === "accepted").length;
|
|
39258
|
+
const failedCount = submissions.length - submittedCount;
|
|
39259
|
+
return {
|
|
39260
|
+
status: "submitted",
|
|
39261
|
+
reasonCodes: [...new Set(submissions.flatMap((submission) => submission.reasonCodes).filter((reasonCode) => reasonCode.trim()))],
|
|
39262
|
+
reportCount: submissions.length,
|
|
39263
|
+
submittedCount,
|
|
39264
|
+
failedCount
|
|
39265
|
+
};
|
|
39266
|
+
}
|
|
39267
|
+
|
|
39268
|
+
//#endregion
|
|
39269
|
+
//#region src/local-service/carrier/catalog-sync-skipped-profiles.ts
|
|
38909
39270
|
function resolveCatalogSyncSkippedProfilesLogState(input) {
|
|
38910
39271
|
if (input.hasProfiles || input.skippedProfiles.length === 0) return {
|
|
38911
39272
|
fingerprint: null,
|
|
@@ -43078,7 +43439,7 @@ function failMissingCurrentSocket(dispatchId) {
|
|
|
43078
43439
|
}
|
|
43079
43440
|
|
|
43080
43441
|
//#endregion
|
|
43081
|
-
//#region src/
|
|
43442
|
+
//#region src/local-service/carrier/frame-router.ts
|
|
43082
43443
|
function parseDaemonFrame(raw) {
|
|
43083
43444
|
let parsedJson;
|
|
43084
43445
|
try {
|
|
@@ -43281,7 +43642,7 @@ function normalizeResultAckStatus(value) {
|
|
|
43281
43642
|
}
|
|
43282
43643
|
|
|
43283
43644
|
//#endregion
|
|
43284
|
-
//#region src/
|
|
43645
|
+
//#region src/local-service/carrier/register-session.ts
|
|
43285
43646
|
function waitForRegisterResponse(input) {
|
|
43286
43647
|
if (input.waiters.registerResolver || input.waiters.registerRejecter) return Promise.reject(new DaemonServiceRunError({
|
|
43287
43648
|
code: "daemon.run.register_response_busy",
|
|
@@ -43311,7 +43672,7 @@ function waitForRegisterResponse(input) {
|
|
|
43311
43672
|
}
|
|
43312
43673
|
|
|
43313
43674
|
//#endregion
|
|
43314
|
-
//#region src/
|
|
43675
|
+
//#region src/local-service/carrier/run-socket-session.ts
|
|
43315
43676
|
async function runDaemonSocketSession(input) {
|
|
43316
43677
|
const currentSocketRef = input.currentSocketRef ?? {
|
|
43317
43678
|
connectionGeneration: null,
|
|
@@ -44166,239 +44527,7 @@ function normalizeFrameInteger(value) {
|
|
|
44166
44527
|
}
|
|
44167
44528
|
|
|
44168
44529
|
//#endregion
|
|
44169
|
-
//#region src/
|
|
44170
|
-
async function loadContextStore(contextStorePath) {
|
|
44171
|
-
const raw = await readFile(contextStorePath, "utf8").catch(() => "");
|
|
44172
|
-
if (!raw) return /* @__PURE__ */ new Map();
|
|
44173
|
-
let parsed;
|
|
44174
|
-
try {
|
|
44175
|
-
parsed = JSON.parse(raw);
|
|
44176
|
-
} catch {
|
|
44177
|
-
return /* @__PURE__ */ new Map();
|
|
44178
|
-
}
|
|
44179
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return /* @__PURE__ */ new Map();
|
|
44180
|
-
const contextStore = /* @__PURE__ */ new Map();
|
|
44181
|
-
for (const [key, value] of Object.entries(parsed)) {
|
|
44182
|
-
const normalizedKey = normalizeOptionalText$50(key);
|
|
44183
|
-
const normalizedValue = normalizeOptionalText$50(value);
|
|
44184
|
-
if (!(normalizedKey && normalizedValue)) continue;
|
|
44185
|
-
contextStore.set(normalizedKey, normalizedValue);
|
|
44186
|
-
}
|
|
44187
|
-
return contextStore;
|
|
44188
|
-
}
|
|
44189
|
-
|
|
44190
|
-
//#endregion
|
|
44191
|
-
//#region src/daemon/state/daemon-runtime-state.ts
|
|
44192
|
-
function resolveDaemonRunMode$1(inputMode) {
|
|
44193
|
-
if (process.env[DAEMON_SERVICE_RUNTIME_DETACHED_ENV] === "1") return "background";
|
|
44194
|
-
const envMode = parseDaemonRunMode$1(process.env[DAEMON_SERVICE_RUNTIME_MODE_ENV]);
|
|
44195
|
-
if (envMode) return envMode;
|
|
44196
|
-
if (inputMode === "foreground") return "foreground";
|
|
44197
|
-
return "background";
|
|
44198
|
-
}
|
|
44199
|
-
function parseDaemonRunMode$1(value) {
|
|
44200
|
-
const normalized = normalizeText$9(value).toLowerCase();
|
|
44201
|
-
if (normalized === "foreground" || normalized === "background") return normalized;
|
|
44202
|
-
return null;
|
|
44203
|
-
}
|
|
44204
|
-
function shouldPersistDaemonRuntimeState(input) {
|
|
44205
|
-
if (input.forcePersist) return true;
|
|
44206
|
-
if ("stopRequestedAt" in input.updates) return true;
|
|
44207
|
-
return input.nowMs - input.lastPersistedAtMs >= RUNTIME_STATE_PERSIST_MIN_INTERVAL_MS;
|
|
44208
|
-
}
|
|
44209
|
-
function resolveReconnectBackoffMs(attempt) {
|
|
44210
|
-
const next = DEFAULT_RECONNECT_DELAY_MS * 2 ** (Math.max(1, attempt) - 1);
|
|
44211
|
-
return Math.min(MAX_RECONNECT_DELAY_MS, next);
|
|
44212
|
-
}
|
|
44213
|
-
function toDaemonStreamUrl(baseUrl) {
|
|
44214
|
-
const url = new URL(baseUrl);
|
|
44215
|
-
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
44216
|
-
url.pathname = "/v1/daemon/stream";
|
|
44217
|
-
url.search = "";
|
|
44218
|
-
url.hash = "";
|
|
44219
|
-
return url.toString();
|
|
44220
|
-
}
|
|
44221
|
-
function buildDaemonProcessCommand() {
|
|
44222
|
-
const script = normalizeText$9(process.argv[1]);
|
|
44223
|
-
const args = process.argv.slice(2);
|
|
44224
|
-
const values = script ? [script, ...args] : args;
|
|
44225
|
-
if (values.length === 0) return process.execPath;
|
|
44226
|
-
return `${process.execPath} ${values.join(" ")}`;
|
|
44227
|
-
}
|
|
44228
|
-
function createDaemonRuntimeState(input) {
|
|
44229
|
-
return {
|
|
44230
|
-
v: 1,
|
|
44231
|
-
schema: DAEMON_SERVICE_RUNTIME_STATE_SCHEMA,
|
|
44232
|
-
status: "running",
|
|
44233
|
-
mode: input.mode,
|
|
44234
|
-
pid: input.pid,
|
|
44235
|
-
command: input.command,
|
|
44236
|
-
gatewayUrl: input.gatewayUrl,
|
|
44237
|
-
atsProfileId: input.atsProfileId,
|
|
44238
|
-
workingDirectory: input.workingDirectory,
|
|
44239
|
-
stopRequestedAt: input.stopRequestedAt,
|
|
44240
|
-
startedAt: input.startedAt,
|
|
44241
|
-
updatedAt: input.updatedAt,
|
|
44242
|
-
heartbeatAt: input.heartbeatAt,
|
|
44243
|
-
managedBySystemService: input.runtimeMetadata.managedBySystemService,
|
|
44244
|
-
serviceController: input.runtimeMetadata.serviceController,
|
|
44245
|
-
autoStart: input.runtimeMetadata.autoStart
|
|
44246
|
-
};
|
|
44247
|
-
}
|
|
44248
|
-
|
|
44249
|
-
//#endregion
|
|
44250
|
-
//#region src/daemon/state/route-catalog-cache.ts
|
|
44251
|
-
const ROUTE_CATALOG_CACHE_FILE = "route-catalog-cache.json";
|
|
44252
|
-
async function readDaemonRouteCatalogCache(input) {
|
|
44253
|
-
const lane = normalizeCacheLane(input.lane);
|
|
44254
|
-
const ownerUserId = normalizeCacheIdentityField(input.ownerUserId);
|
|
44255
|
-
const serviceBundleId = normalizeServiceBundleId(input.serviceBundleId);
|
|
44256
|
-
if (!(lane && ownerUserId && serviceBundleId)) return null;
|
|
44257
|
-
const cached = await readDaemonLocalStateFile({
|
|
44258
|
-
path: daemonRouteCatalogCachePath(),
|
|
44259
|
-
schema: daemonRouteCatalogCacheSchema
|
|
44260
|
-
});
|
|
44261
|
-
if (!cached || cached.ownerUserId !== ownerUserId || cached.lane !== lane || cached.serviceBundleId !== serviceBundleId) return null;
|
|
44262
|
-
return deserializeRouteCatalog(cached);
|
|
44263
|
-
}
|
|
44264
|
-
async function writeDaemonRouteCatalogCache(input) {
|
|
44265
|
-
const lane = normalizeCacheLane(input.lane);
|
|
44266
|
-
const ownerUserId = normalizeCacheIdentityField(input.ownerUserId);
|
|
44267
|
-
const serviceBundleId = normalizeServiceBundleId(input.serviceBundleId);
|
|
44268
|
-
if (!(lane && ownerUserId && serviceBundleId)) return;
|
|
44269
|
-
if (input.routeCatalog.profileIds.length === 0) {
|
|
44270
|
-
await clearDaemonRouteCatalogCache();
|
|
44271
|
-
return;
|
|
44272
|
-
}
|
|
44273
|
-
const value = {
|
|
44274
|
-
v: DAEMON_ROUTE_CATALOG_CACHE_SCHEMA_VERSION,
|
|
44275
|
-
schema: DAEMON_ROUTE_CATALOG_CACHE_SCHEMA_NAME,
|
|
44276
|
-
cachedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
44277
|
-
runtimeContractEpoch: CURRENT_DAEMON_EXECUTION_CONTRACT_EPOCH,
|
|
44278
|
-
ownerUserId,
|
|
44279
|
-
lane,
|
|
44280
|
-
serviceBundleId,
|
|
44281
|
-
profileIds: [...input.routeCatalog.profileIds],
|
|
44282
|
-
routes: input.routeCatalog.profileIds.map((profileId) => {
|
|
44283
|
-
const route = input.routeCatalog.routeByProfileId.get(profileId);
|
|
44284
|
-
if (!route) throw new Error(`route catalog is missing route for ${profileId}`);
|
|
44285
|
-
return serializeRouteConfig(route);
|
|
44286
|
-
}),
|
|
44287
|
-
skippedProfiles: [...input.routeCatalog.skippedProfiles]
|
|
44288
|
-
};
|
|
44289
|
-
await writeDaemonLocalStateFile({
|
|
44290
|
-
path: daemonRouteCatalogCachePath(),
|
|
44291
|
-
schema: daemonRouteCatalogCacheSchema,
|
|
44292
|
-
value,
|
|
44293
|
-
mode: 384
|
|
44294
|
-
});
|
|
44295
|
-
}
|
|
44296
|
-
async function clearDaemonRouteCatalogCache() {
|
|
44297
|
-
await rm(daemonRouteCatalogCachePath(), { force: true });
|
|
44298
|
-
}
|
|
44299
|
-
function daemonRouteCatalogCachePath() {
|
|
44300
|
-
return join(daemonRuntimeDataPath(), ROUTE_CATALOG_CACHE_FILE);
|
|
44301
|
-
}
|
|
44302
|
-
function normalizeServiceBundleId(value) {
|
|
44303
|
-
return String(value ?? "").trim();
|
|
44304
|
-
}
|
|
44305
|
-
function normalizeCacheIdentityField(value) {
|
|
44306
|
-
return String(value ?? "").trim();
|
|
44307
|
-
}
|
|
44308
|
-
function normalizeCacheLane(value) {
|
|
44309
|
-
const parsed = daemonServiceLaneSchema.safeParse(normalizeCacheIdentityField(value));
|
|
44310
|
-
return parsed.success ? parsed.data : null;
|
|
44311
|
-
}
|
|
44312
|
-
function serializeRouteConfig(route) {
|
|
44313
|
-
return {
|
|
44314
|
-
agentControllerRef: route.agentControllerRef,
|
|
44315
|
-
contextIdMappingSpec: route.contextIdMappingSpec,
|
|
44316
|
-
...route.launchContract ? { launchContract: route.launchContract } : {},
|
|
44317
|
-
profileId: route.profileId,
|
|
44318
|
-
streamingMode: route.streamingMode,
|
|
44319
|
-
transportMode: route.transportMode
|
|
44320
|
-
};
|
|
44321
|
-
}
|
|
44322
|
-
function deserializeRouteCatalog(cache) {
|
|
44323
|
-
const routeByProfileId = /* @__PURE__ */ new Map();
|
|
44324
|
-
for (const route of cache.routes) routeByProfileId.set(route.profileId, {
|
|
44325
|
-
agentControllerRef: route.agentControllerRef,
|
|
44326
|
-
contextIdMappingSpec: route.contextIdMappingSpec,
|
|
44327
|
-
...route.launchContract ? { launchContract: route.launchContract } : {},
|
|
44328
|
-
profileId: route.profileId,
|
|
44329
|
-
streamingMode: route.streamingMode,
|
|
44330
|
-
transportMode: route.transportMode
|
|
44331
|
-
});
|
|
44332
|
-
return {
|
|
44333
|
-
profileIds: [...cache.profileIds],
|
|
44334
|
-
routeByProfileId,
|
|
44335
|
-
skippedProfiles: [...cache.skippedProfiles]
|
|
44336
|
-
};
|
|
44337
|
-
}
|
|
44338
|
-
|
|
44339
|
-
//#endregion
|
|
44340
|
-
//#region src/daemon/state/runtime-state-tracker.ts
|
|
44341
|
-
function createDaemonRuntimeStateTracker(input) {
|
|
44342
|
-
let runtimeState = input.initialState;
|
|
44343
|
-
let lastRuntimeStatePersistAtMs = Date.now();
|
|
44344
|
-
const touchRuntimeState = async (updates, options) => {
|
|
44345
|
-
const nowAt = nowIsoString();
|
|
44346
|
-
runtimeState = {
|
|
44347
|
-
...runtimeState,
|
|
44348
|
-
...updates,
|
|
44349
|
-
updatedAt: updates.updatedAt ?? nowAt
|
|
44350
|
-
};
|
|
44351
|
-
if (!shouldPersistDaemonRuntimeState({
|
|
44352
|
-
forcePersist: options?.forcePersist === true,
|
|
44353
|
-
nowMs: Date.now(),
|
|
44354
|
-
lastPersistedAtMs: lastRuntimeStatePersistAtMs,
|
|
44355
|
-
updates
|
|
44356
|
-
})) return;
|
|
44357
|
-
await setDaemonServiceRuntimeState(runtimeState);
|
|
44358
|
-
if (input.leaseDescriptor) await writeDaemonRuntimeLease(buildDaemonRuntimeLease({
|
|
44359
|
-
descriptor: input.leaseDescriptor,
|
|
44360
|
-
runtimeState
|
|
44361
|
-
}));
|
|
44362
|
-
lastRuntimeStatePersistAtMs = Date.now();
|
|
44363
|
-
};
|
|
44364
|
-
return {
|
|
44365
|
-
getRuntimeState: () => runtimeState,
|
|
44366
|
-
touchRuntimeState
|
|
44367
|
-
};
|
|
44368
|
-
}
|
|
44369
|
-
async function resolveDaemonRuntimeLeaseDescriptor(input) {
|
|
44370
|
-
const [contract, activeBundle] = await Promise.all([readDaemonServiceContract().catch(() => null), readDaemonActiveBundleState().catch(() => null)]);
|
|
44371
|
-
if (contract) return {
|
|
44372
|
-
generation: contract.generation,
|
|
44373
|
-
bundleId: contract.bundleId
|
|
44374
|
-
};
|
|
44375
|
-
const activeBundleEntryPath = await resolveDaemonBundleEntryPathFromState(activeBundle).catch(() => null);
|
|
44376
|
-
const commandEntryPath = extractDaemonCommandEntryPath(input.command);
|
|
44377
|
-
const bundleId = (commandEntryPath ? resolveDaemonBundleIdFromEntryPath(commandEntryPath) : null) ?? (activeBundleEntryPath ? resolveDaemonBundleIdFromEntryPath(activeBundleEntryPath) : null) ?? activeBundle?.bundleId ?? null;
|
|
44378
|
-
if (!bundleId) return null;
|
|
44379
|
-
return {
|
|
44380
|
-
generation: 0,
|
|
44381
|
-
bundleId
|
|
44382
|
-
};
|
|
44383
|
-
}
|
|
44384
|
-
function buildDaemonRuntimeLease(input) {
|
|
44385
|
-
return {
|
|
44386
|
-
schema: "ats-daemon-runtime-lease-v1",
|
|
44387
|
-
v: 1,
|
|
44388
|
-
generation: input.descriptor.generation,
|
|
44389
|
-
bundleId: input.descriptor.bundleId,
|
|
44390
|
-
pid: input.runtimeState.pid,
|
|
44391
|
-
mode: input.runtimeState.mode,
|
|
44392
|
-
startedAt: input.runtimeState.startedAt,
|
|
44393
|
-
updatedAt: input.runtimeState.updatedAt,
|
|
44394
|
-
heartbeatAt: input.runtimeState.heartbeatAt,
|
|
44395
|
-
serviceController: input.runtimeState.serviceController,
|
|
44396
|
-
managedBySystemService: input.runtimeState.managedBySystemService
|
|
44397
|
-
};
|
|
44398
|
-
}
|
|
44399
|
-
|
|
44400
|
-
//#endregion
|
|
44401
|
-
//#region src/daemon/service-runner.ts
|
|
44530
|
+
//#region src/local-service/carrier/service-runner.ts
|
|
44402
44531
|
async function resolveDaemonServiceOwnerContext(input) {
|
|
44403
44532
|
const explicitAtsProfileId = normalizeText$9(input.atsProfileId);
|
|
44404
44533
|
if (explicitAtsProfileId) return resolveDaemonServiceOwnerContextFromProfile(await requireAtsProfile({
|
|
@@ -46917,6 +47046,14 @@ async function runDaemonStatus(input) {
|
|
|
46917
47046
|
profile: input.profile,
|
|
46918
47047
|
view: input.view
|
|
46919
47048
|
});
|
|
47049
|
+
if (input.json === true) {
|
|
47050
|
+
outJsonLine(buildDaemonStatusJsonPayload({
|
|
47051
|
+
environmentTarget: await resolveAtsEnvironmentTarget({ gatewayUrl: input.gatewayUrl }),
|
|
47052
|
+
localSnapshot: await resolveDaemonLocalStatusSnapshot(),
|
|
47053
|
+
snapshot: await resolveDaemonStatusSnapshot({ runtime })
|
|
47054
|
+
}));
|
|
47055
|
+
return;
|
|
47056
|
+
}
|
|
46920
47057
|
const presenter = createPresenter(runtime);
|
|
46921
47058
|
emitDaemonOverviewIfAgent({
|
|
46922
47059
|
presenter,
|
|
@@ -47208,33 +47345,55 @@ async function runDaemonStatusFlow(input) {
|
|
|
47208
47345
|
await runDaemonStatus(input);
|
|
47209
47346
|
return "completed";
|
|
47210
47347
|
}
|
|
47348
|
+
function buildDaemonStatusJsonPayload(input) {
|
|
47349
|
+
return {
|
|
47350
|
+
schemaVersion: 1,
|
|
47351
|
+
type: "daemon.status",
|
|
47352
|
+
localResult: buildDaemonAgentLocalStatusPayload({
|
|
47353
|
+
environmentTarget: input.environmentTarget,
|
|
47354
|
+
snapshot: input.localSnapshot
|
|
47355
|
+
}),
|
|
47356
|
+
result: buildDaemonAgentStatusPayload({
|
|
47357
|
+
environmentTarget: input.environmentTarget,
|
|
47358
|
+
snapshot: input.snapshot
|
|
47359
|
+
}),
|
|
47360
|
+
runtimeProjection: input.snapshot.currentReplyReadiness.runtimeProjection ?? null
|
|
47361
|
+
};
|
|
47362
|
+
}
|
|
47363
|
+
function buildDaemonAgentStatusPayload(input) {
|
|
47364
|
+
const { environmentTarget, snapshot } = input;
|
|
47365
|
+
const currentProfileWorkspace = buildProfileWorkspacePresentation(snapshot.currentReplyReadiness.profileWorkspaceRuntimeResolution);
|
|
47366
|
+
return {
|
|
47367
|
+
...snapshot.currentReplyReadiness.daemonStatus,
|
|
47368
|
+
environmentTarget,
|
|
47369
|
+
...snapshot.currentReplyReadiness.runtimeStatus ? { runtime: snapshot.currentReplyReadiness.runtimeStatus } : {},
|
|
47370
|
+
...snapshot.runtimeContractRepairReport ? { runtimeContractRepair: snapshot.runtimeContractRepairReport } : {},
|
|
47371
|
+
...snapshot.currentReplyReadiness.inventory ? { inventory: {
|
|
47372
|
+
anomalies: snapshot.currentReplyReadiness.inventory.anomalies,
|
|
47373
|
+
...snapshot.currentReplyReadiness.inventory.runtimeContractCompatibility ? { runtimeContractCompatibility: snapshot.currentReplyReadiness.inventory.runtimeContractCompatibility } : {},
|
|
47374
|
+
cleanupPlan: buildDaemonServiceCleanupPlan({
|
|
47375
|
+
intent: "status_cleanup",
|
|
47376
|
+
inventory: snapshot.currentReplyReadiness.inventory
|
|
47377
|
+
})
|
|
47378
|
+
} } : {},
|
|
47379
|
+
daemonRouteObservation: snapshot.currentReplyReadiness.daemonRouteObservation,
|
|
47380
|
+
diagnostics: buildDaemonLocalReplyReadinessEvidenceDiagnostics({
|
|
47381
|
+
deviceReplyReadiness: snapshot.currentReplyReadiness.deviceReplyReadiness,
|
|
47382
|
+
legacyAgentReplyReadiness: snapshot.currentReplyReadiness.agentReplyReadiness
|
|
47383
|
+
}),
|
|
47384
|
+
currentProfileWorkspace,
|
|
47385
|
+
...snapshot.attention ? { attention: snapshot.attention } : {},
|
|
47386
|
+
...snapshot.latestLifecycleEvent ? { latestLifecycleEvent: snapshot.latestLifecycleEvent } : {}
|
|
47387
|
+
};
|
|
47388
|
+
}
|
|
47211
47389
|
function emitDaemonAgentStatus(input) {
|
|
47212
47390
|
const { environmentTarget, presenter, snapshot } = input;
|
|
47213
|
-
const currentProfileWorkspace = buildProfileWorkspacePresentation(snapshot.currentReplyReadiness.profileWorkspaceRuntimeResolution);
|
|
47214
47391
|
presenter.data({
|
|
47215
47392
|
code: "daemon.status.result",
|
|
47216
|
-
payload: {
|
|
47217
|
-
...snapshot.currentReplyReadiness.daemonStatus,
|
|
47393
|
+
payload: buildDaemonAgentStatusPayload({
|
|
47218
47394
|
environmentTarget,
|
|
47219
|
-
|
|
47220
|
-
|
|
47221
|
-
...snapshot.currentReplyReadiness.inventory ? { inventory: {
|
|
47222
|
-
anomalies: snapshot.currentReplyReadiness.inventory.anomalies,
|
|
47223
|
-
...snapshot.currentReplyReadiness.inventory.runtimeContractCompatibility ? { runtimeContractCompatibility: snapshot.currentReplyReadiness.inventory.runtimeContractCompatibility } : {},
|
|
47224
|
-
cleanupPlan: buildDaemonServiceCleanupPlan({
|
|
47225
|
-
intent: "status_cleanup",
|
|
47226
|
-
inventory: snapshot.currentReplyReadiness.inventory
|
|
47227
|
-
})
|
|
47228
|
-
} } : {},
|
|
47229
|
-
daemonRouteObservation: snapshot.currentReplyReadiness.daemonRouteObservation,
|
|
47230
|
-
diagnostics: buildDaemonLocalReplyReadinessEvidenceDiagnostics({
|
|
47231
|
-
deviceReplyReadiness: snapshot.currentReplyReadiness.deviceReplyReadiness,
|
|
47232
|
-
legacyAgentReplyReadiness: snapshot.currentReplyReadiness.agentReplyReadiness
|
|
47233
|
-
}),
|
|
47234
|
-
currentProfileWorkspace,
|
|
47235
|
-
...snapshot.attention ? { attention: snapshot.attention } : {},
|
|
47236
|
-
...snapshot.latestLifecycleEvent ? { latestLifecycleEvent: snapshot.latestLifecycleEvent } : {}
|
|
47237
|
-
}
|
|
47395
|
+
snapshot
|
|
47396
|
+
})
|
|
47238
47397
|
});
|
|
47239
47398
|
if (!snapshot.currentReplyReadiness.runtimeProjection) return;
|
|
47240
47399
|
presenter.data({
|
|
@@ -47248,28 +47407,35 @@ function buildDaemonLocalReplyReadinessEvidenceDiagnostics(input) {
|
|
|
47248
47407
|
agentEvidence: input.legacyAgentReplyReadiness
|
|
47249
47408
|
});
|
|
47250
47409
|
}
|
|
47410
|
+
function buildDaemonAgentLocalStatusPayload(input) {
|
|
47411
|
+
const { environmentTarget, snapshot } = input;
|
|
47412
|
+
return {
|
|
47413
|
+
...snapshot.daemonStatus,
|
|
47414
|
+
environmentTarget,
|
|
47415
|
+
statusScope: "local_service",
|
|
47416
|
+
...snapshot.runtimeStatus ? { runtime: snapshot.runtimeStatus } : {},
|
|
47417
|
+
...snapshot.serviceManagerStatus ? { serviceManagerStatus: snapshot.serviceManagerStatus } : {},
|
|
47418
|
+
...snapshot.runtimeContractRepairReport ? { runtimeContractRepair: snapshot.runtimeContractRepairReport } : {},
|
|
47419
|
+
...snapshot.inventory ? { inventory: {
|
|
47420
|
+
anomalies: snapshot.inventory.anomalies,
|
|
47421
|
+
...snapshot.inventory.runtimeContractCompatibility ? { runtimeContractCompatibility: snapshot.inventory.runtimeContractCompatibility } : {},
|
|
47422
|
+
cleanupPlan: buildDaemonServiceCleanupPlan({
|
|
47423
|
+
intent: "status_cleanup",
|
|
47424
|
+
inventory: snapshot.inventory
|
|
47425
|
+
})
|
|
47426
|
+
} } : {},
|
|
47427
|
+
...snapshot.attention ? { attention: snapshot.attention } : {},
|
|
47428
|
+
...snapshot.latestLifecycleEvent ? { latestLifecycleEvent: snapshot.latestLifecycleEvent } : {}
|
|
47429
|
+
};
|
|
47430
|
+
}
|
|
47251
47431
|
function emitDaemonAgentLocalStatus(input) {
|
|
47252
47432
|
const { environmentTarget, presenter, snapshot } = input;
|
|
47253
47433
|
presenter.data({
|
|
47254
47434
|
code: "daemon.status.local_result",
|
|
47255
|
-
payload: {
|
|
47256
|
-
...snapshot.daemonStatus,
|
|
47435
|
+
payload: buildDaemonAgentLocalStatusPayload({
|
|
47257
47436
|
environmentTarget,
|
|
47258
|
-
|
|
47259
|
-
|
|
47260
|
-
...snapshot.serviceManagerStatus ? { serviceManagerStatus: snapshot.serviceManagerStatus } : {},
|
|
47261
|
-
...snapshot.runtimeContractRepairReport ? { runtimeContractRepair: snapshot.runtimeContractRepairReport } : {},
|
|
47262
|
-
...snapshot.inventory ? { inventory: {
|
|
47263
|
-
anomalies: snapshot.inventory.anomalies,
|
|
47264
|
-
...snapshot.inventory.runtimeContractCompatibility ? { runtimeContractCompatibility: snapshot.inventory.runtimeContractCompatibility } : {},
|
|
47265
|
-
cleanupPlan: buildDaemonServiceCleanupPlan({
|
|
47266
|
-
intent: "status_cleanup",
|
|
47267
|
-
inventory: snapshot.inventory
|
|
47268
|
-
})
|
|
47269
|
-
} } : {},
|
|
47270
|
-
...snapshot.attention ? { attention: snapshot.attention } : {},
|
|
47271
|
-
...snapshot.latestLifecycleEvent ? { latestLifecycleEvent: snapshot.latestLifecycleEvent } : {}
|
|
47272
|
-
}
|
|
47437
|
+
snapshot
|
|
47438
|
+
})
|
|
47273
47439
|
});
|
|
47274
47440
|
}
|
|
47275
47441
|
async function emitDaemonStatusForView(input) {
|
|
@@ -94562,125 +94728,6 @@ function addExplicitProfileToSpaceHint(hint) {
|
|
|
94562
94728
|
return `ats space ${subcommand} --profile <profile-id>${rest}`;
|
|
94563
94729
|
}
|
|
94564
94730
|
|
|
94565
|
-
//#endregion
|
|
94566
|
-
//#region src/runtime/view-argv.ts
|
|
94567
|
-
const PASSIVE_CLI_QUERY_FLAGS = new Set([
|
|
94568
|
-
"--help",
|
|
94569
|
-
"--version",
|
|
94570
|
-
"-V",
|
|
94571
|
-
"-h"
|
|
94572
|
-
]);
|
|
94573
|
-
function isStandaloneViewQueryArgv(argv) {
|
|
94574
|
-
const args = argv.slice(2);
|
|
94575
|
-
return args.length === 1 && args[0] === "--view";
|
|
94576
|
-
}
|
|
94577
|
-
function parseViewFromArgv(argv, options) {
|
|
94578
|
-
const allowMissingValue = options?.allowMissingValue === true;
|
|
94579
|
-
for (let i = 2; i < argv.length; i += 1) {
|
|
94580
|
-
const arg = argv[i];
|
|
94581
|
-
if (typeof arg !== "string") continue;
|
|
94582
|
-
if (arg === "--") break;
|
|
94583
|
-
if (arg === "--view") {
|
|
94584
|
-
const next = argv[i + 1];
|
|
94585
|
-
if (typeof next !== "string" || next.startsWith("-")) {
|
|
94586
|
-
if (allowMissingValue) return null;
|
|
94587
|
-
throw new Error("missing --view value (use auto|human|agent)");
|
|
94588
|
-
}
|
|
94589
|
-
return parseCliViewMode(next);
|
|
94590
|
-
}
|
|
94591
|
-
if (arg.startsWith("--view=")) return parseCliViewMode(arg.slice(7));
|
|
94592
|
-
}
|
|
94593
|
-
return null;
|
|
94594
|
-
}
|
|
94595
|
-
function parseStandaloneViewSwitchArgv(argv) {
|
|
94596
|
-
const args = argv.slice(2);
|
|
94597
|
-
if (args.length === 0) return null;
|
|
94598
|
-
let view = null;
|
|
94599
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
94600
|
-
const arg = args[i];
|
|
94601
|
-
if (typeof arg !== "string") continue;
|
|
94602
|
-
if (arg === "--view") {
|
|
94603
|
-
const next = args[i + 1];
|
|
94604
|
-
if (typeof next !== "string" || next.startsWith("-")) return null;
|
|
94605
|
-
view = next.trim().toLowerCase();
|
|
94606
|
-
i += 1;
|
|
94607
|
-
continue;
|
|
94608
|
-
}
|
|
94609
|
-
if (arg.startsWith("--view=")) {
|
|
94610
|
-
view = arg.slice(7).trim().toLowerCase();
|
|
94611
|
-
continue;
|
|
94612
|
-
}
|
|
94613
|
-
return null;
|
|
94614
|
-
}
|
|
94615
|
-
return view;
|
|
94616
|
-
}
|
|
94617
|
-
function parseFirstCommandTokenFromArgv(argv) {
|
|
94618
|
-
return parseLeadingCommandTokensFromArgv(argv, 1)[0] ?? null;
|
|
94619
|
-
}
|
|
94620
|
-
function parseLeadingCommandTokensFromArgv(argv, maxTokens = 2) {
|
|
94621
|
-
if (maxTokens <= 0) return [];
|
|
94622
|
-
const args = argv.slice(2);
|
|
94623
|
-
const tokens = [];
|
|
94624
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
94625
|
-
if (collectTokensAfterTerminator(args, i, tokens, maxTokens)) return tokens;
|
|
94626
|
-
if (shouldSkipKnownGlobalFlag(args, i)) {
|
|
94627
|
-
i += 1;
|
|
94628
|
-
continue;
|
|
94629
|
-
}
|
|
94630
|
-
const arg = args[i];
|
|
94631
|
-
if (typeof arg !== "string" || shouldSkipInlineGlobalFlag(arg)) continue;
|
|
94632
|
-
if (pushLeadingCommandToken(arg, tokens, maxTokens)) return tokens;
|
|
94633
|
-
}
|
|
94634
|
-
return tokens;
|
|
94635
|
-
}
|
|
94636
|
-
function isPassiveCliQueryArgv(argv) {
|
|
94637
|
-
const args = argv.slice(2);
|
|
94638
|
-
for (let i = 0; i < args.length; i += 1) {
|
|
94639
|
-
const arg = args[i];
|
|
94640
|
-
if (typeof arg !== "string") continue;
|
|
94641
|
-
if (arg === "--") return false;
|
|
94642
|
-
if (isKnownGlobalFlagExpectValue(arg) && isGlobalFlagValueCandidate(args[i + 1])) {
|
|
94643
|
-
i += 1;
|
|
94644
|
-
continue;
|
|
94645
|
-
}
|
|
94646
|
-
if (arg.startsWith("--view=") || arg.startsWith("--service-auto-install=")) continue;
|
|
94647
|
-
if (arg === "help" || PASSIVE_CLI_QUERY_FLAGS.has(arg)) return true;
|
|
94648
|
-
}
|
|
94649
|
-
return false;
|
|
94650
|
-
}
|
|
94651
|
-
function shouldUseAgentViewForNonInteractiveStart(argv, interactive) {
|
|
94652
|
-
if (interactive) return false;
|
|
94653
|
-
if (parseViewFromArgv(argv, { allowMissingValue: true }) !== null) return false;
|
|
94654
|
-
return parseFirstCommandTokenFromArgv(argv) === "start";
|
|
94655
|
-
}
|
|
94656
|
-
function isKnownGlobalFlagExpectValue(value) {
|
|
94657
|
-
return value === "--view" || value === "--service-auto-install";
|
|
94658
|
-
}
|
|
94659
|
-
function isGlobalFlagValueCandidate(value) {
|
|
94660
|
-
return typeof value === "string" && value.length > 0 && !value.startsWith("-");
|
|
94661
|
-
}
|
|
94662
|
-
function collectTokensAfterTerminator(args, index, tokens, maxTokens) {
|
|
94663
|
-
if (args[index] !== "--") return false;
|
|
94664
|
-
for (let i = index + 1; i < args.length; i += 1) {
|
|
94665
|
-
const next = args[i];
|
|
94666
|
-
if (typeof next !== "string" || next.length === 0) continue;
|
|
94667
|
-
tokens.push(next);
|
|
94668
|
-
if (tokens.length >= maxTokens) break;
|
|
94669
|
-
}
|
|
94670
|
-
return true;
|
|
94671
|
-
}
|
|
94672
|
-
function shouldSkipKnownGlobalFlag(args, index) {
|
|
94673
|
-
return isKnownGlobalFlagExpectValue(args[index] ?? "") && isGlobalFlagValueCandidate(args[index + 1]);
|
|
94674
|
-
}
|
|
94675
|
-
function shouldSkipInlineGlobalFlag(value) {
|
|
94676
|
-
return value.startsWith("--view=") || value.startsWith("--service-auto-install=");
|
|
94677
|
-
}
|
|
94678
|
-
function pushLeadingCommandToken(value, tokens, maxTokens) {
|
|
94679
|
-
if (value.startsWith("-")) return false;
|
|
94680
|
-
tokens.push(value);
|
|
94681
|
-
return tokens.length >= maxTokens;
|
|
94682
|
-
}
|
|
94683
|
-
|
|
94684
94731
|
//#endregion
|
|
94685
94732
|
//#region src/runtime/retired-command-argv.ts
|
|
94686
94733
|
const RETIRED_CLI_COMMANDS = [{
|
|
@@ -97188,6 +97235,10 @@ function buildCommandHelpExamples(title, examples) {
|
|
|
97188
97235
|
async function runCommandWithEntryChecks(input) {
|
|
97189
97236
|
const entryName = resolveCommandEntryNameFromTokens(input.routeTokens);
|
|
97190
97237
|
if (!entryName) throw new Error(`missing command entry mapping for route: ${input.routeTokens.join(" ")}`);
|
|
97238
|
+
if (hasJsonOutputArgv(process.argv)) {
|
|
97239
|
+
await input.run();
|
|
97240
|
+
return;
|
|
97241
|
+
}
|
|
97191
97242
|
const requirements = getCommandCheckRequirements(entryName);
|
|
97192
97243
|
const environmentTarget = await resolveAtsEnvironmentTarget({ gatewayUrl: input.gatewayUrl });
|
|
97193
97244
|
const normalizedGatewayUrl = await resolveGatewayUrlForEntryChecks({
|
|
@@ -97831,18 +97882,20 @@ const serviceCmd = program.command("service").alias("daemon").description("Manag
|
|
|
97831
97882
|
});
|
|
97832
97883
|
serviceCmd.command("start").description("Start ATS Service on this device.").option("--mode <mode>", "Start mode: background (default) or foreground").option("--gateway-url <url>", "ATS gateway URL (command line, ATS_GATEWAY_URL, or saved ATS settings)").option("--profile <id-or-name>", "Optional ATS profile override used for owner resolution").option("--device-id <id>", "Override daemon device id for this run").option("--heartbeat-ms <n>", "Heartbeat interval in milliseconds (default: 25000)").action(runServiceStartCliAction);
|
|
97833
97884
|
serviceCmd.command("run").description("Legacy alias for `ats service start`.").option("--mode <mode>", "Run mode: background (default) or foreground").option("--gateway-url <url>", "ATS gateway URL (command line, ATS_GATEWAY_URL, or saved ATS settings)").option("--profile <id-or-name>", "Optional ATS profile override used for owner resolution").option("--device-id <id>", "Override daemon device id for this run").option("--heartbeat-ms <n>", "Heartbeat interval in milliseconds (default: 25000)").action(runServiceStartCliAction);
|
|
97834
|
-
serviceCmd.command("status").description("Show ATS Service status on this device.").option("--profile <id-or-name>", "Optional ATS profile context for local service diagnostics").action(async (opts) => {
|
|
97835
|
-
const
|
|
97885
|
+
serviceCmd.command("status").description("Show ATS Service status on this device.").option("--json", "Print machine-readable JSON.", false).option("--profile <id-or-name>", "Optional ATS profile context for local service diagnostics").action(async (opts) => {
|
|
97886
|
+
const json = opts.json === true;
|
|
97887
|
+
const view = json ? "agent" : getGlobalViewOption();
|
|
97836
97888
|
await runCommandWithEntryChecks({
|
|
97837
97889
|
routeTokens: ["service", "status"],
|
|
97838
97890
|
profile: opts.profile,
|
|
97839
97891
|
view,
|
|
97840
97892
|
run: async () => {
|
|
97841
97893
|
await runDaemonStatusFlow({
|
|
97894
|
+
json,
|
|
97842
97895
|
profile: opts.profile,
|
|
97843
97896
|
view
|
|
97844
97897
|
});
|
|
97845
|
-
await maybeRunAgentViewRecoveryAfterSuccess({ view });
|
|
97898
|
+
if (!json) await maybeRunAgentViewRecoveryAfterSuccess({ view });
|
|
97846
97899
|
}
|
|
97847
97900
|
});
|
|
97848
97901
|
});
|
|
@@ -99050,6 +99103,7 @@ async function runRootCommand() {
|
|
|
99050
99103
|
}
|
|
99051
99104
|
}
|
|
99052
99105
|
async function shouldPrintTagline(argv, effectiveView) {
|
|
99106
|
+
if (hasJsonOutputArgv(argv)) return false;
|
|
99053
99107
|
if ((effectiveView === "auto" ? (await resolveRuntimeContext({ view: "auto" })).resolvedView : effectiveView) === "agent") return false;
|
|
99054
99108
|
const [firstCommand, secondCommand] = parseLeadingCommandTokensFromArgv(argv, 2);
|
|
99055
99109
|
if (firstCommand === "setup" || firstCommand === "agents" && secondCommand === "prepare") return false;
|