@ascenda-one/agent-mcp 0.1.33 → 0.1.35
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/cli.js +1942 -893
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -633,9 +633,11 @@ var require_out = __commonJS({
|
|
|
633
633
|
"../packages/tool-contract/out/index.js"(exports) {
|
|
634
634
|
"use strict";
|
|
635
635
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
636
|
-
exports.backendMetricKeys = exports.METRIC_KEYS = exports.ASCENDA_SEMANTIC_PROVENANCE = exports.ASCENDA_HISTORICAL_CONSENT_SCOPE = exports.ASCENDA_COLLABORATION_CONSENT_SCOPE = exports.ASCENDA_SEMANTIC_CONSENT_SCOPE = exports.ASCENDA_PROVENANCE = exports.ASCENDA_CONSENT_SCOPE = exports.EVENT_WORKLOAD_CATEGORY = exports.TOOL_EVENT_DELIVERED_STATUSES = exports.IDEMPOTENCY_KEY_MAX_LENGTH = exports.EVENT_METADATA_FIELDS = exports.EVENT_METADATA_DISCLOSURE = exports.COLLABORATION_EVENT_TYPES = exports.SEMANTIC_WORK_SIGNAL_EVENT_TYPES = exports.ASCENDA_ELAPSED_QUANTITIES = exports.ASCENDA_ACTIVE_TIME_QUANTITIES = exports.ASCENDA_TOOL_TYPES = exports.ASCENDA_TELEMETRY_SOURCES = void 0;
|
|
636
|
+
exports.backendMetricKeys = exports.METRIC_KEYS = exports.ASCENDA_SEMANTIC_PROVENANCE = exports.ASCENDA_HISTORICAL_CONSENT_SCOPE = exports.ASCENDA_COLLABORATION_CONSENT_SCOPE = exports.ASCENDA_SEMANTIC_CONSENT_SCOPE = exports.ASCENDA_PROVENANCE = exports.ASCENDA_CONSENT_SCOPE = exports.EVENT_WORKLOAD_CATEGORY = exports.TOOL_EVENT_DELIVERED_STATUSES = exports.IDEMPOTENCY_KEY_MAX_LENGTH = exports.DELIVERY_ENVELOPE_KEYS = exports.EVENT_METADATA_FIELDS = exports.EVENT_METADATA_DISCLOSURE = exports.COLLABORATION_EVENT_TYPES = exports.SEMANTIC_WORK_SIGNAL_EVENT_TYPES = exports.ASCENDA_ELAPSED_QUANTITIES = exports.ASCENDA_ACTIVE_TIME_QUANTITIES = exports.ASCENDA_TOOL_TYPES = exports.ASCENDA_TELEMETRY_SOURCES = void 0;
|
|
637
637
|
exports.combineDisjointHalves = combineDisjointHalves;
|
|
638
638
|
exports.requireComparableQuantities = requireComparableQuantities;
|
|
639
|
+
exports.joinEventPayload = joinEventPayload;
|
|
640
|
+
exports.splitEventPayload = splitEventPayload;
|
|
639
641
|
exports.ASCENDA_TELEMETRY_SOURCES = [
|
|
640
642
|
"vscode_extension",
|
|
641
643
|
"cursor_mcp",
|
|
@@ -787,6 +789,24 @@ var require_out = __commonJS({
|
|
|
787
789
|
"importSchema",
|
|
788
790
|
"collectorVersion"
|
|
789
791
|
];
|
|
792
|
+
exports.DELIVERY_ENVELOPE_KEYS = ["toolInstallationId", "idempotencyKey"];
|
|
793
|
+
function joinEventPayload(envelope, body) {
|
|
794
|
+
const payload = { toolInstallationId: envelope.toolInstallationId };
|
|
795
|
+
for (const [key, value] of Object.entries(body)) {
|
|
796
|
+
payload[key] = value;
|
|
797
|
+
if (key === "occurredAt" && envelope.idempotencyKey !== void 0) {
|
|
798
|
+
payload.idempotencyKey = envelope.idempotencyKey;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return payload;
|
|
802
|
+
}
|
|
803
|
+
function splitEventPayload(payload) {
|
|
804
|
+
const { toolInstallationId, idempotencyKey, ...body } = payload;
|
|
805
|
+
const envelope = { toolInstallationId };
|
|
806
|
+
if (idempotencyKey !== void 0)
|
|
807
|
+
envelope.idempotencyKey = idempotencyKey;
|
|
808
|
+
return { envelope, body };
|
|
809
|
+
}
|
|
790
810
|
exports.IDEMPOTENCY_KEY_MAX_LENGTH = 128;
|
|
791
811
|
exports.TOOL_EVENT_DELIVERED_STATUSES = ["accepted", "duplicate"];
|
|
792
812
|
exports.EVENT_WORKLOAD_CATEGORY = {
|
|
@@ -965,16 +985,125 @@ var require_collectorVersion = __commonJS({
|
|
|
965
985
|
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
966
986
|
exports.describeCollectorVersion = describeCollectorVersion;
|
|
967
987
|
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
968
|
-
exports.COLLECTOR_VERSION = "0.1.
|
|
988
|
+
exports.COLLECTOR_VERSION = "0.1.35" ? "0.1.35" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
969
989
|
function describeCollectorVersion(version2 = exports.COLLECTOR_VERSION) {
|
|
970
990
|
return version2 === exports.UNRELEASED_COLLECTOR_VERSION ? `${version2} (built from a checkout, not a release)` : version2;
|
|
971
991
|
}
|
|
972
992
|
}
|
|
973
993
|
});
|
|
974
994
|
|
|
975
|
-
// ../packages/
|
|
976
|
-
var
|
|
977
|
-
"../packages/
|
|
995
|
+
// ../packages/agent-events/out/index.js
|
|
996
|
+
var require_out2 = __commonJS({
|
|
997
|
+
"../packages/agent-events/out/index.js"(exports) {
|
|
998
|
+
"use strict";
|
|
999
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1000
|
+
exports.KNOWN_AGENTS = exports.AGENT_EVENT_KINDS = exports.AGENT_EVENT_SCHEMA = void 0;
|
|
1001
|
+
exports.isAgentEventV0 = isAgentEventV0;
|
|
1002
|
+
exports.parseEventLogLine = parseEventLogLine;
|
|
1003
|
+
exports.normaliseKind = normaliseKind;
|
|
1004
|
+
exports.AGENT_EVENT_SCHEMA = "agent-event/v0";
|
|
1005
|
+
exports.AGENT_EVENT_KINDS = [
|
|
1006
|
+
"session.started",
|
|
1007
|
+
"session.ended",
|
|
1008
|
+
"prompt.submitted",
|
|
1009
|
+
"tool.started",
|
|
1010
|
+
"tool.completed",
|
|
1011
|
+
"tool.failed",
|
|
1012
|
+
"turn.completed",
|
|
1013
|
+
"agent.waiting",
|
|
1014
|
+
"context.compacted",
|
|
1015
|
+
"subagent.started",
|
|
1016
|
+
"subagent.stopped",
|
|
1017
|
+
"other"
|
|
1018
|
+
];
|
|
1019
|
+
exports.KNOWN_AGENTS = ["claude_code", "codex", "cursor", "gemini_cli", "windsurf", "vscode"];
|
|
1020
|
+
function isAgentEventV0(value) {
|
|
1021
|
+
if (!value || typeof value !== "object")
|
|
1022
|
+
return false;
|
|
1023
|
+
const e = value;
|
|
1024
|
+
return e.schema === exports.AGENT_EVENT_SCHEMA && typeof e.id === "string" && e.id.length > 0 && typeof e.time === "string" && !Number.isNaN(Date.parse(e.time)) && typeof e.agent === "string" && e.agent.length > 0 && typeof e.kind === "string";
|
|
1025
|
+
}
|
|
1026
|
+
function parseEventLogLine(line) {
|
|
1027
|
+
if (!line.trim())
|
|
1028
|
+
return void 0;
|
|
1029
|
+
try {
|
|
1030
|
+
const parsed = JSON.parse(line);
|
|
1031
|
+
return isAgentEventV0(parsed?.event) ? parsed.event : void 0;
|
|
1032
|
+
} catch {
|
|
1033
|
+
return void 0;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
function normaliseKind(kind) {
|
|
1037
|
+
return exports.AGENT_EVENT_KINDS.includes(kind) ? kind : "other";
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
// ../packages/tool-kit/out/agentEvent.js
|
|
1043
|
+
var require_agentEvent = __commonJS({
|
|
1044
|
+
"../packages/tool-kit/out/agentEvent.js"(exports) {
|
|
1045
|
+
"use strict";
|
|
1046
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1047
|
+
exports.toAgentEvent = toAgentEvent;
|
|
1048
|
+
var agent_events_1 = require_out2();
|
|
1049
|
+
var KIND_BY_TYPE = {
|
|
1050
|
+
create_focus_session: "session.started",
|
|
1051
|
+
recovery_offline_period: "session.ended",
|
|
1052
|
+
ai_prompt_submitted: "prompt.submitted",
|
|
1053
|
+
ai_tool_call_started: "tool.started",
|
|
1054
|
+
ai_tool_call_completed: "tool.completed",
|
|
1055
|
+
ai_file_write: "tool.completed",
|
|
1056
|
+
ai_file_edit: "tool.completed",
|
|
1057
|
+
editor_verification_activity: "tool.completed",
|
|
1058
|
+
ai_tool_call_failed: "tool.failed",
|
|
1059
|
+
compile_error: "tool.failed",
|
|
1060
|
+
tool_failure: "tool.failed",
|
|
1061
|
+
ai_turn_completed: "turn.completed",
|
|
1062
|
+
supervision_interruption: "agent.waiting",
|
|
1063
|
+
context_compression_manual: "context.compacted",
|
|
1064
|
+
context_compression_auto: "context.compacted",
|
|
1065
|
+
subagent_started: "subagent.started",
|
|
1066
|
+
subagent_stopped: "subagent.stopped"
|
|
1067
|
+
};
|
|
1068
|
+
function agentOf(payload) {
|
|
1069
|
+
const host = stringField(payload.metadata?.host);
|
|
1070
|
+
if (host)
|
|
1071
|
+
return host;
|
|
1072
|
+
return payload.source === "vscode_extension" ? "vscode" : payload.source;
|
|
1073
|
+
}
|
|
1074
|
+
function stringField(value) {
|
|
1075
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1076
|
+
}
|
|
1077
|
+
function toAgentEvent(payload) {
|
|
1078
|
+
const metadata = payload.metadata ?? {};
|
|
1079
|
+
const kind = KIND_BY_TYPE[payload.eventType] ?? "other";
|
|
1080
|
+
const tool = kind.startsWith("tool.") ? stringField(metadata.toolName) : void 0;
|
|
1081
|
+
const outcome = stringField(metadata.outcome);
|
|
1082
|
+
return {
|
|
1083
|
+
schema: agent_events_1.AGENT_EVENT_SCHEMA,
|
|
1084
|
+
id: payload.idempotencyKey ?? `${payload.toolInstallationId}:${payload.occurredAt}:${payload.eventType}`,
|
|
1085
|
+
time: payload.occurredAt,
|
|
1086
|
+
// `+ 0` turns the -0 a UTC machine computes into 0, which is what JSON
|
|
1087
|
+
// writes anyway; without it the event in memory and the one on disk differ.
|
|
1088
|
+
...typeof payload.utcOffsetMinutes === "number" ? { utcOffsetMinutes: payload.utcOffsetMinutes + 0 } : {},
|
|
1089
|
+
agent: agentOf(payload),
|
|
1090
|
+
kind,
|
|
1091
|
+
...stringField(payload.sessionId) ? { sessionId: payload.sessionId } : {},
|
|
1092
|
+
...stringField(metadata.subagentId) ? { subagentId: metadata.subagentId } : {},
|
|
1093
|
+
...tool ? { tool } : {},
|
|
1094
|
+
...outcome && outcome !== "unknown" ? { outcome } : {},
|
|
1095
|
+
...stringField(metadata.durationBucket) ? { durationBucket: metadata.durationBucket } : {},
|
|
1096
|
+
...stringField(payload.projectHash) ? { projectHash: payload.projectHash } : {},
|
|
1097
|
+
...stringField(metadata.collectorVersion) ? { collectorVersion: metadata.collectorVersion } : {},
|
|
1098
|
+
sourceType: payload.eventType
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
|
|
1104
|
+
// ../packages/tool-kit/out/tokenStore.js
|
|
1105
|
+
var require_tokenStore = __commonJS({
|
|
1106
|
+
"../packages/tool-kit/out/tokenStore.js"(exports) {
|
|
978
1107
|
"use strict";
|
|
979
1108
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
980
1109
|
if (k2 === void 0) k2 = k;
|
|
@@ -1014,306 +1143,232 @@ var require_eventLog = __commonJS({
|
|
|
1014
1143
|
};
|
|
1015
1144
|
}();
|
|
1016
1145
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1017
|
-
exports.
|
|
1018
|
-
exports.
|
|
1019
|
-
exports.
|
|
1020
|
-
exports.
|
|
1146
|
+
exports.EVENT_TOKEN_TTL_MS = void 0;
|
|
1147
|
+
exports.ascendaHome = ascendaHome;
|
|
1148
|
+
exports.defaultTokenFilePath = defaultTokenFilePath2;
|
|
1149
|
+
exports.tokenExpiryFilePath = tokenExpiryFilePath;
|
|
1150
|
+
exports.persistEventWriteToken = persistEventWriteToken2;
|
|
1151
|
+
exports.readTokenExpiry = readTokenExpiry;
|
|
1152
|
+
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds;
|
|
1153
|
+
exports.readTokenFile = readTokenFile2;
|
|
1154
|
+
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1021
1155
|
var fs = __importStar(__require("fs"));
|
|
1022
1156
|
var os = __importStar(__require("os"));
|
|
1023
1157
|
var path = __importStar(__require("path"));
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
return void 0;
|
|
1030
|
-
if (value === "~")
|
|
1031
|
-
return os.homedir();
|
|
1032
|
-
if (value.startsWith("~/"))
|
|
1033
|
-
return path.join(os.homedir(), value.slice(2));
|
|
1034
|
-
return path.resolve(value);
|
|
1158
|
+
function ascendaHome(home = os.homedir()) {
|
|
1159
|
+
return process.env.ASCENDA_HOME ?? path.join(home, ".ascenda");
|
|
1160
|
+
}
|
|
1161
|
+
function defaultTokenFilePath2(toolInstallationId) {
|
|
1162
|
+
return path.join(ascendaHome(), "tokens", sanitizeFilePart(toolInstallationId));
|
|
1035
1163
|
}
|
|
1036
|
-
function
|
|
1037
|
-
return
|
|
1164
|
+
function tokenExpiryFilePath(tokenFilePath) {
|
|
1165
|
+
return path.join(path.dirname(tokenFilePath), "expiry", path.basename(tokenFilePath));
|
|
1038
1166
|
}
|
|
1039
|
-
function
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
fs.
|
|
1045
|
-
|
|
1046
|
-
if (process.platform !== "win32")
|
|
1047
|
-
fs.chmodSync(logFilePath, 384);
|
|
1048
|
-
} catch {
|
|
1167
|
+
function persistEventWriteToken2(tokenFilePath, token, expiresAt) {
|
|
1168
|
+
const dir = path.dirname(tokenFilePath);
|
|
1169
|
+
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1170
|
+
fs.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
1171
|
+
if (process.platform !== "win32") {
|
|
1172
|
+
fs.chmodSync(dir, 448);
|
|
1173
|
+
fs.chmodSync(tokenFilePath, 384);
|
|
1049
1174
|
}
|
|
1050
|
-
|
|
1051
|
-
function rotateIfLarge(logFilePath) {
|
|
1175
|
+
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1052
1176
|
try {
|
|
1053
|
-
if (
|
|
1054
|
-
|
|
1055
|
-
|
|
1177
|
+
if (expiresAt && Number.isFinite(Date.parse(expiresAt))) {
|
|
1178
|
+
fs.mkdirSync(path.dirname(expiryFile), { recursive: true, mode: 448 });
|
|
1179
|
+
fs.writeFileSync(expiryFile, expiresAt, { encoding: "utf8", mode: 384 });
|
|
1180
|
+
} else {
|
|
1181
|
+
fs.rmSync(expiryFile, { force: true });
|
|
1182
|
+
}
|
|
1056
1183
|
} catch {
|
|
1057
1184
|
}
|
|
1058
1185
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
// ../packages/tool-kit/out/http.js
|
|
1063
|
-
var require_http = __commonJS({
|
|
1064
|
-
"../packages/tool-kit/out/http.js"(exports) {
|
|
1065
|
-
"use strict";
|
|
1066
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1067
|
-
exports.AscendaApiError = void 0;
|
|
1068
|
-
exports.createPairingSession = createPairingSession;
|
|
1069
|
-
exports.getPairingStatus = getPairingStatus;
|
|
1070
|
-
exports.startStudyJoin = startStudyJoin;
|
|
1071
|
-
exports.getStudyJoinStatus = getStudyJoinStatus;
|
|
1072
|
-
exports.readInitiatives = readInitiatives;
|
|
1073
|
-
exports.readStudyNotices = readStudyNotices;
|
|
1074
|
-
exports.setStudyObjection = setStudyObjection;
|
|
1075
|
-
exports.markStudyNoticeShown = markStudyNoticeShown;
|
|
1076
|
-
exports.renewToolToken = renewToolToken;
|
|
1077
|
-
exports.isRetryableStatus = isRetryableStatus;
|
|
1078
|
-
exports.postToolEvent = postToolEvent;
|
|
1079
|
-
exports.postToolEventsBatch = postToolEventsBatch;
|
|
1080
|
-
exports.parseIngestResponse = parseIngestResponse;
|
|
1081
|
-
var tool_contract_1 = require_out();
|
|
1082
|
-
var AscendaApiError = class extends Error {
|
|
1083
|
-
status;
|
|
1084
|
-
errorCode;
|
|
1085
|
-
constructor(status, errorCode, body) {
|
|
1086
|
-
super(body ?? `Ascenda API error ${status}`);
|
|
1087
|
-
this.status = status;
|
|
1088
|
-
this.errorCode = errorCode;
|
|
1089
|
-
this.name = "AscendaApiError";
|
|
1090
|
-
}
|
|
1091
|
-
};
|
|
1092
|
-
exports.AscendaApiError = AscendaApiError;
|
|
1093
|
-
async function createPairingSession(apiBaseUrl, toolInstallationId, toolType, displayName) {
|
|
1094
|
-
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions`, {
|
|
1095
|
-
method: "POST",
|
|
1096
|
-
headers: { "Content-Type": "application/json" },
|
|
1097
|
-
body: JSON.stringify({ toolInstallationId, toolType, displayName })
|
|
1098
|
-
});
|
|
1099
|
-
if (!response.ok)
|
|
1100
|
-
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1101
|
-
return await response.json();
|
|
1102
|
-
}
|
|
1103
|
-
async function getPairingStatus(apiBaseUrl, pairingSessionId) {
|
|
1104
|
-
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions/${encodeURIComponent(pairingSessionId)}/status`, {
|
|
1105
|
-
method: "GET",
|
|
1106
|
-
headers: { Accept: "application/json" }
|
|
1107
|
-
});
|
|
1108
|
-
if (!response.ok)
|
|
1109
|
-
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1110
|
-
return await response.json();
|
|
1111
|
-
}
|
|
1112
|
-
async function startStudyJoin(apiBaseUrl, eventWriteToken, joinCode, mode) {
|
|
1113
|
-
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions`, {
|
|
1114
|
-
method: "POST",
|
|
1115
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1116
|
-
body: JSON.stringify({ joinCode, mode })
|
|
1117
|
-
});
|
|
1118
|
-
if (!response.ok)
|
|
1119
|
-
throw await apiError(response);
|
|
1120
|
-
return await response.json();
|
|
1121
|
-
}
|
|
1122
|
-
async function getStudyJoinStatus(apiBaseUrl, eventWriteToken, joinSessionId) {
|
|
1123
|
-
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions/${encodeURIComponent(joinSessionId)}/status`, {
|
|
1124
|
-
method: "GET",
|
|
1125
|
-
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` }
|
|
1126
|
-
});
|
|
1127
|
-
if (!response.ok)
|
|
1128
|
-
throw await apiError(response);
|
|
1129
|
-
return await response.json();
|
|
1130
|
-
}
|
|
1131
|
-
async function readInitiatives(apiBaseUrl, eventWriteToken, signal) {
|
|
1132
|
-
let response;
|
|
1186
|
+
exports.EVENT_TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1187
|
+
function readTokenExpiry(tokenFilePath) {
|
|
1133
1188
|
try {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
});
|
|
1139
|
-
} catch (error2) {
|
|
1140
|
-
return { kind: "failed", reason: error2 instanceof Error && error2.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1189
|
+
const recorded = Date.parse(fs.readFileSync(tokenExpiryFilePath(tokenFilePath), "utf8").trim());
|
|
1190
|
+
if (Number.isFinite(recorded))
|
|
1191
|
+
return recorded;
|
|
1192
|
+
} catch {
|
|
1141
1193
|
}
|
|
1142
|
-
if (response.status === 401)
|
|
1143
|
-
return { kind: "rejected", httpStatus: 401 };
|
|
1144
|
-
if (!response.ok)
|
|
1145
|
-
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1146
|
-
let body;
|
|
1147
1194
|
try {
|
|
1148
|
-
|
|
1195
|
+
return fs.statSync(tokenFilePath).mtimeMs + exports.EVENT_TOKEN_TTL_MS;
|
|
1149
1196
|
} catch {
|
|
1150
|
-
return
|
|
1197
|
+
return void 0;
|
|
1151
1198
|
}
|
|
1152
|
-
if (!Array.isArray(body))
|
|
1153
|
-
return { kind: "failed", reason: "the reply was not a list" };
|
|
1154
|
-
return { kind: "ok", initiatives: body };
|
|
1155
1199
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1200
|
+
function listPersistedToolInstallationIds(toolType) {
|
|
1201
|
+
const prefix = `${sanitizeFilePart(toolType)}_`;
|
|
1202
|
+
const dir = path.join(ascendaHome(), "tokens");
|
|
1203
|
+
let names;
|
|
1158
1204
|
try {
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
signal
|
|
1163
|
-
});
|
|
1164
|
-
} catch (error2) {
|
|
1165
|
-
return { kind: "failed", reason: error2 instanceof Error && error2.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1205
|
+
names = fs.readdirSync(dir);
|
|
1206
|
+
} catch {
|
|
1207
|
+
return [];
|
|
1166
1208
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1209
|
+
const ids = [];
|
|
1210
|
+
for (const name of names.sort()) {
|
|
1211
|
+
if (!name.startsWith(prefix) || name.length === prefix.length)
|
|
1212
|
+
continue;
|
|
1213
|
+
const file = path.join(dir, name);
|
|
1214
|
+
try {
|
|
1215
|
+
if (!fs.statSync(file).isFile())
|
|
1216
|
+
continue;
|
|
1217
|
+
} catch {
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
if (readTokenFile2(file) === void 0)
|
|
1221
|
+
continue;
|
|
1222
|
+
ids.push(`${toolType}:${name.slice(prefix.length)}`);
|
|
1223
|
+
}
|
|
1224
|
+
return ids;
|
|
1225
|
+
}
|
|
1226
|
+
function readTokenFile2(tokenFilePath) {
|
|
1174
1227
|
try {
|
|
1175
|
-
|
|
1228
|
+
if (!fs.existsSync(tokenFilePath))
|
|
1229
|
+
return void 0;
|
|
1230
|
+
const value = fs.readFileSync(tokenFilePath, "utf8").trim();
|
|
1231
|
+
return value || void 0;
|
|
1176
1232
|
} catch {
|
|
1177
|
-
return
|
|
1233
|
+
return void 0;
|
|
1178
1234
|
}
|
|
1179
|
-
if (!Array.isArray(body))
|
|
1180
|
-
return { kind: "absent" };
|
|
1181
|
-
return { kind: "ok", notices: body };
|
|
1182
1235
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
method: objected ? "POST" : "DELETE",
|
|
1186
|
-
headers: { Authorization: `Bearer ${eventWriteToken}` }
|
|
1187
|
-
});
|
|
1188
|
-
if (!response.ok)
|
|
1189
|
-
throw await apiError(response);
|
|
1236
|
+
function sanitizeFilePart(value) {
|
|
1237
|
+
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
1190
1238
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
|
|
1242
|
+
// ../packages/tool-kit/out/credentials.js
|
|
1243
|
+
var require_credentials = __commonJS({
|
|
1244
|
+
"../packages/tool-kit/out/credentials.js"(exports) {
|
|
1245
|
+
"use strict";
|
|
1246
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1247
|
+
if (k2 === void 0) k2 = k;
|
|
1248
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1249
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1250
|
+
desc = { enumerable: true, get: function() {
|
|
1251
|
+
return m[k];
|
|
1252
|
+
} };
|
|
1201
1253
|
}
|
|
1254
|
+
Object.defineProperty(o, k2, desc);
|
|
1255
|
+
} : function(o, m, k, k2) {
|
|
1256
|
+
if (k2 === void 0) k2 = k;
|
|
1257
|
+
o[k2] = m[k];
|
|
1258
|
+
});
|
|
1259
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1260
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1261
|
+
} : function(o, v) {
|
|
1262
|
+
o["default"] = v;
|
|
1263
|
+
});
|
|
1264
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1265
|
+
var ownKeys = function(o) {
|
|
1266
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1267
|
+
var ar = [];
|
|
1268
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1269
|
+
return ar;
|
|
1270
|
+
};
|
|
1271
|
+
return ownKeys(o);
|
|
1272
|
+
};
|
|
1273
|
+
return function(mod) {
|
|
1274
|
+
if (mod && mod.__esModule) return mod;
|
|
1275
|
+
var result = {};
|
|
1276
|
+
if (mod != null) {
|
|
1277
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1278
|
+
}
|
|
1279
|
+
__setModuleDefault(result, mod);
|
|
1280
|
+
return result;
|
|
1281
|
+
};
|
|
1282
|
+
}();
|
|
1283
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1284
|
+
exports.credentialsFilePath = credentialsFilePath;
|
|
1285
|
+
exports.readMachineCredentials = readMachineCredentials;
|
|
1286
|
+
exports.writeMachineCredentials = writeMachineCredentials;
|
|
1287
|
+
exports.writeTopLevelCredentials = writeTopLevelCredentials;
|
|
1288
|
+
exports.writeEventLogSetting = writeEventLogSetting;
|
|
1289
|
+
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
1290
|
+
exports.readHostCredentials = readHostCredentials;
|
|
1291
|
+
exports.writeHostCredentials = writeHostCredentials;
|
|
1292
|
+
exports.removeHostCredentials = removeHostCredentials;
|
|
1293
|
+
var fs = __importStar(__require("fs"));
|
|
1294
|
+
var path = __importStar(__require("path"));
|
|
1295
|
+
var tokenStore_1 = require_tokenStore();
|
|
1296
|
+
function credentialsFilePath() {
|
|
1297
|
+
return path.join((0, tokenStore_1.ascendaHome)(), "credentials.json");
|
|
1202
1298
|
}
|
|
1203
|
-
|
|
1204
|
-
const body = await response.text();
|
|
1205
|
-
let errorCode;
|
|
1299
|
+
function readMachineCredentials() {
|
|
1206
1300
|
try {
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1301
|
+
const raw = fs.readFileSync(credentialsFilePath(), "utf8").trim();
|
|
1302
|
+
if (!raw)
|
|
1303
|
+
return void 0;
|
|
1304
|
+
const parsed = JSON.parse(raw);
|
|
1305
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
1306
|
+
return void 0;
|
|
1307
|
+
return parsed;
|
|
1209
1308
|
} catch {
|
|
1210
|
-
|
|
1309
|
+
return void 0;
|
|
1211
1310
|
}
|
|
1212
|
-
return new AscendaApiError(response.status, errorCode, body);
|
|
1213
|
-
}
|
|
1214
|
-
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
1215
|
-
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
1216
|
-
method: "POST",
|
|
1217
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1218
|
-
signal
|
|
1219
|
-
});
|
|
1220
|
-
if (response.status === 401)
|
|
1221
|
-
return null;
|
|
1222
|
-
if (!response.ok)
|
|
1223
|
-
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1224
|
-
return await response.json();
|
|
1225
|
-
}
|
|
1226
|
-
function isDeliveredStatus(value) {
|
|
1227
|
-
return typeof value === "string" && tool_contract_1.TOOL_EVENT_DELIVERED_STATUSES.includes(value);
|
|
1228
1311
|
}
|
|
1229
|
-
function
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
return { duplicates: 0 };
|
|
1238
|
-
const single = parsed.status;
|
|
1239
|
-
if (isDeliveredStatus(single))
|
|
1240
|
-
return { duplicates: single === "duplicate" ? 1 : 0 };
|
|
1241
|
-
const raw = parsed.results;
|
|
1242
|
-
if (!Array.isArray(raw))
|
|
1243
|
-
return { duplicates: 0 };
|
|
1244
|
-
const results = [];
|
|
1245
|
-
for (const item of raw) {
|
|
1246
|
-
if (!item || typeof item !== "object")
|
|
1247
|
-
continue;
|
|
1248
|
-
const { index, status, reason } = item;
|
|
1249
|
-
if (typeof index !== "number" || typeof status !== "string")
|
|
1250
|
-
continue;
|
|
1251
|
-
results.push({ index, status, ...typeof reason === "string" ? { reason } : {} });
|
|
1312
|
+
function writeMachineCredentials(credentials) {
|
|
1313
|
+
const file = credentialsFilePath();
|
|
1314
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 448 });
|
|
1315
|
+
fs.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
1316
|
+
`, { encoding: "utf8", mode: 384 });
|
|
1317
|
+
if (process.platform !== "win32") {
|
|
1318
|
+
fs.chmodSync(path.dirname(file), 448);
|
|
1319
|
+
fs.chmodSync(file, 384);
|
|
1252
1320
|
}
|
|
1253
|
-
return { duplicates: results.filter((item) => item.status === "duplicate").length, results };
|
|
1254
1321
|
}
|
|
1255
|
-
function
|
|
1256
|
-
|
|
1322
|
+
function writeTopLevelCredentials(credentials) {
|
|
1323
|
+
const existing = readMachineCredentials();
|
|
1324
|
+
const eventLogPath = credentials.eventLogPath ?? existing?.eventLogPath;
|
|
1325
|
+
writeMachineCredentials({
|
|
1326
|
+
...credentials,
|
|
1327
|
+
...eventLogPath ? { eventLogPath } : {},
|
|
1328
|
+
...existing?.tools ? { tools: existing.tools } : {}
|
|
1329
|
+
});
|
|
1257
1330
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1331
|
+
function writeEventLogSetting(value) {
|
|
1332
|
+
const existing = readMachineCredentials() ?? {};
|
|
1333
|
+
writeMachineCredentials({ ...existing, eventLogPath: value });
|
|
1260
1334
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1335
|
+
function isLocalOnlyHostInstall(host, hasToken) {
|
|
1336
|
+
const credentials = readHostCredentials(host);
|
|
1337
|
+
if (!credentials?.localOnly)
|
|
1338
|
+
return false;
|
|
1339
|
+
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
1340
|
+
return false;
|
|
1341
|
+
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
1263
1342
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
body,
|
|
1270
|
-
signal
|
|
1271
|
-
});
|
|
1272
|
-
return parseIngestResponse(response);
|
|
1273
|
-
} catch (error2) {
|
|
1274
|
-
return {
|
|
1275
|
-
result: "transport_error",
|
|
1276
|
-
detail: error2 instanceof Error ? `${error2.name}: ${error2.message}` : String(error2)
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1343
|
+
function readHostCredentials(host) {
|
|
1344
|
+
const entry = readMachineCredentials()?.tools?.[host];
|
|
1345
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
1346
|
+
return void 0;
|
|
1347
|
+
return entry;
|
|
1279
1348
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
let errorCode;
|
|
1297
|
-
try {
|
|
1298
|
-
errorCode = JSON.parse(body).error;
|
|
1299
|
-
} catch {
|
|
1300
|
-
errorCode = void 0;
|
|
1301
|
-
}
|
|
1302
|
-
const base = { httpStatus: response.status, errorCode, detail: body || void 0 };
|
|
1303
|
-
if (response.status === 401)
|
|
1304
|
-
return { ...base, result: "auth_failed" };
|
|
1305
|
-
if (response.status === 403 && errorCode === "consent_missing_or_expired")
|
|
1306
|
-
return { ...base, result: "consent_missing" };
|
|
1307
|
-
if (response.status === 400 || response.status === 422)
|
|
1308
|
-
return { ...base, result: "validation_failed" };
|
|
1309
|
-
return { ...base, result: "transport_error" };
|
|
1349
|
+
function writeHostCredentials(host, credentials) {
|
|
1350
|
+
const existing = readMachineCredentials() ?? {};
|
|
1351
|
+
writeMachineCredentials({ ...existing, tools: { ...existing.tools ?? {}, [host]: credentials } });
|
|
1352
|
+
}
|
|
1353
|
+
function removeHostCredentials(host) {
|
|
1354
|
+
const existing = readMachineCredentials();
|
|
1355
|
+
if (!existing?.tools || !(host in existing.tools))
|
|
1356
|
+
return;
|
|
1357
|
+
const tools = { ...existing.tools };
|
|
1358
|
+
delete tools[host];
|
|
1359
|
+
const next = { ...existing };
|
|
1360
|
+
if (Object.keys(tools).length)
|
|
1361
|
+
next.tools = tools;
|
|
1362
|
+
else
|
|
1363
|
+
delete next.tools;
|
|
1364
|
+
writeMachineCredentials(next);
|
|
1310
1365
|
}
|
|
1311
1366
|
}
|
|
1312
1367
|
});
|
|
1313
1368
|
|
|
1314
|
-
// ../packages/tool-kit/out/
|
|
1315
|
-
var
|
|
1316
|
-
"../packages/tool-kit/out/
|
|
1369
|
+
// ../packages/tool-kit/out/eventLog.js
|
|
1370
|
+
var require_eventLog = __commonJS({
|
|
1371
|
+
"../packages/tool-kit/out/eventLog.js"(exports) {
|
|
1317
1372
|
"use strict";
|
|
1318
1373
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1319
1374
|
if (k2 === void 0) k2 = k;
|
|
@@ -1353,137 +1408,386 @@ var require_tokenStore = __commonJS({
|
|
|
1353
1408
|
};
|
|
1354
1409
|
}();
|
|
1355
1410
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1356
|
-
exports.
|
|
1357
|
-
exports.
|
|
1358
|
-
exports.
|
|
1359
|
-
exports.
|
|
1360
|
-
exports.
|
|
1361
|
-
exports.
|
|
1362
|
-
exports.
|
|
1363
|
-
exports.
|
|
1364
|
-
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1411
|
+
exports.EVENT_LOG_OFF = exports.EVENT_LOG_ENV_VAR = void 0;
|
|
1412
|
+
exports.expandUserPath = expandUserPath;
|
|
1413
|
+
exports.defaultEventLogPath = defaultEventLogPath;
|
|
1414
|
+
exports.resolveEventLog = resolveEventLog;
|
|
1415
|
+
exports.resolveEventLogPath = resolveEventLogPath;
|
|
1416
|
+
exports.describeEventLog = describeEventLog;
|
|
1417
|
+
exports.parseEventLogFlag = parseEventLogFlag;
|
|
1418
|
+
exports.appendEventLog = appendEventLog;
|
|
1365
1419
|
var fs = __importStar(__require("fs"));
|
|
1366
1420
|
var os = __importStar(__require("os"));
|
|
1367
1421
|
var path = __importStar(__require("path"));
|
|
1368
|
-
|
|
1369
|
-
|
|
1422
|
+
var agentEvent_1 = require_agentEvent();
|
|
1423
|
+
var credentials_1 = require_credentials();
|
|
1424
|
+
var tokenStore_1 = require_tokenStore();
|
|
1425
|
+
exports.EVENT_LOG_ENV_VAR = "ASCENDA_EVENT_LOG_FILE";
|
|
1426
|
+
exports.EVENT_LOG_OFF = "off";
|
|
1427
|
+
var MAX_BYTES = 5 * 1024 * 1024;
|
|
1428
|
+
function expandUserPath(configured) {
|
|
1429
|
+
const value = configured?.trim();
|
|
1430
|
+
if (!value)
|
|
1431
|
+
return void 0;
|
|
1432
|
+
if (value === "~")
|
|
1433
|
+
return os.homedir();
|
|
1434
|
+
if (value.startsWith("~/"))
|
|
1435
|
+
return path.join(os.homedir(), value.slice(2));
|
|
1436
|
+
return path.resolve(value);
|
|
1370
1437
|
}
|
|
1371
|
-
function
|
|
1372
|
-
return path.join(ascendaHome(), "
|
|
1438
|
+
function defaultEventLogPath() {
|
|
1439
|
+
return path.join((0, tokenStore_1.ascendaHome)(), "events.jsonl");
|
|
1373
1440
|
}
|
|
1374
|
-
function
|
|
1375
|
-
|
|
1441
|
+
function resolveEventLog(options = {}) {
|
|
1442
|
+
for (const [source, raw] of [
|
|
1443
|
+
["env", process.env[exports.EVENT_LOG_ENV_VAR]],
|
|
1444
|
+
["credentials", (0, credentials_1.readMachineCredentials)()?.eventLogPath]
|
|
1445
|
+
]) {
|
|
1446
|
+
const value = raw?.trim();
|
|
1447
|
+
if (!value)
|
|
1448
|
+
continue;
|
|
1449
|
+
if (value.toLowerCase() === exports.EVENT_LOG_OFF)
|
|
1450
|
+
return { path: void 0, source: "disabled" };
|
|
1451
|
+
return { path: expandUserPath(value), source };
|
|
1452
|
+
}
|
|
1453
|
+
if (options.localOnly)
|
|
1454
|
+
return { path: defaultEventLogPath(), source: "unpaired-default" };
|
|
1455
|
+
return { path: void 0, source: "off" };
|
|
1456
|
+
}
|
|
1457
|
+
function resolveEventLogPath(options = {}) {
|
|
1458
|
+
return resolveEventLog(options).path;
|
|
1459
|
+
}
|
|
1460
|
+
function describeEventLog(setting, command) {
|
|
1461
|
+
switch (setting.source) {
|
|
1462
|
+
case "env":
|
|
1463
|
+
return `${setting.path} (from ${exports.EVENT_LOG_ENV_VAR})`;
|
|
1464
|
+
case "credentials":
|
|
1465
|
+
return `${setting.path} (set by ${command} --event-log)`;
|
|
1466
|
+
case "unpaired-default":
|
|
1467
|
+
return `${setting.path} (on because this install isn't paired; ${command} --event-log off to stop)`;
|
|
1468
|
+
case "disabled":
|
|
1469
|
+
return `off (turned off; ${command} --event-log to turn it on)`;
|
|
1470
|
+
case "off":
|
|
1471
|
+
return `off (${command} --event-log to keep a local copy of every event)`;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
function parseEventLogFlag(argv, index) {
|
|
1475
|
+
const peek = argv[index + 1];
|
|
1476
|
+
if (peek !== void 0 && !peek.startsWith("-"))
|
|
1477
|
+
return { value: peek, consumed: 1 };
|
|
1478
|
+
return { value: defaultEventLogPath(), consumed: 0 };
|
|
1376
1479
|
}
|
|
1377
|
-
function
|
|
1378
|
-
const dir = path.dirname(tokenFilePath);
|
|
1379
|
-
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1380
|
-
fs.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
1381
|
-
if (process.platform !== "win32") {
|
|
1382
|
-
fs.chmodSync(dir, 448);
|
|
1383
|
-
fs.chmodSync(tokenFilePath, 384);
|
|
1384
|
-
}
|
|
1385
|
-
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1480
|
+
function appendEventLog(logFilePath, entry) {
|
|
1386
1481
|
try {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1482
|
+
rotateIfLarge(logFilePath);
|
|
1483
|
+
const dir = path.dirname(logFilePath);
|
|
1484
|
+
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1485
|
+
const line = { ...entry, event: entry.event ?? (0, agentEvent_1.toAgentEvent)(entry.payload) };
|
|
1486
|
+
fs.appendFileSync(logFilePath, `${JSON.stringify(line)}
|
|
1487
|
+
`, { encoding: "utf8", mode: 384 });
|
|
1488
|
+
if (process.platform !== "win32")
|
|
1489
|
+
fs.chmodSync(logFilePath, 384);
|
|
1393
1490
|
} catch {
|
|
1394
1491
|
}
|
|
1395
1492
|
}
|
|
1396
|
-
|
|
1397
|
-
function readTokenExpiry(tokenFilePath) {
|
|
1493
|
+
function rotateIfLarge(logFilePath) {
|
|
1398
1494
|
try {
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1495
|
+
if (fs.statSync(logFilePath).size < MAX_BYTES)
|
|
1496
|
+
return;
|
|
1497
|
+
fs.renameSync(logFilePath, `${logFilePath}.1`);
|
|
1402
1498
|
} catch {
|
|
1403
1499
|
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
// ../packages/tool-kit/out/http.js
|
|
1505
|
+
var require_http = __commonJS({
|
|
1506
|
+
"../packages/tool-kit/out/http.js"(exports) {
|
|
1507
|
+
"use strict";
|
|
1508
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1509
|
+
exports.AscendaApiError = void 0;
|
|
1510
|
+
exports.createPairingSession = createPairingSession;
|
|
1511
|
+
exports.getPairingStatus = getPairingStatus;
|
|
1512
|
+
exports.startStudyJoin = startStudyJoin;
|
|
1513
|
+
exports.getStudyJoinStatus = getStudyJoinStatus;
|
|
1514
|
+
exports.readInitiatives = readInitiatives;
|
|
1515
|
+
exports.readStudyNotices = readStudyNotices;
|
|
1516
|
+
exports.setStudyObjection = setStudyObjection;
|
|
1517
|
+
exports.markStudyNoticeShown = markStudyNoticeShown;
|
|
1518
|
+
exports.renewToolToken = renewToolToken;
|
|
1519
|
+
exports.isRetryableStatus = isRetryableStatus;
|
|
1520
|
+
exports.postToolEvent = postToolEvent;
|
|
1521
|
+
exports.postToolEventsBatch = postToolEventsBatch;
|
|
1522
|
+
exports.parseIngestResponse = parseIngestResponse;
|
|
1523
|
+
var tool_contract_1 = require_out();
|
|
1524
|
+
var AscendaApiError = class extends Error {
|
|
1525
|
+
status;
|
|
1526
|
+
errorCode;
|
|
1527
|
+
constructor(status, errorCode, body) {
|
|
1528
|
+
super(body ?? `Ascenda API error ${status}`);
|
|
1529
|
+
this.status = status;
|
|
1530
|
+
this.errorCode = errorCode;
|
|
1531
|
+
this.name = "AscendaApiError";
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
exports.AscendaApiError = AscendaApiError;
|
|
1535
|
+
async function createPairingSession(apiBaseUrl, toolInstallationId, toolType, displayName) {
|
|
1536
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions`, {
|
|
1537
|
+
method: "POST",
|
|
1538
|
+
headers: { "Content-Type": "application/json" },
|
|
1539
|
+
body: JSON.stringify({ toolInstallationId, toolType, displayName })
|
|
1540
|
+
});
|
|
1541
|
+
if (!response.ok)
|
|
1542
|
+
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1543
|
+
return await response.json();
|
|
1544
|
+
}
|
|
1545
|
+
async function getPairingStatus(apiBaseUrl, pairingSessionId) {
|
|
1546
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions/${encodeURIComponent(pairingSessionId)}/status`, {
|
|
1547
|
+
method: "GET",
|
|
1548
|
+
headers: { Accept: "application/json" }
|
|
1549
|
+
});
|
|
1550
|
+
if (!response.ok)
|
|
1551
|
+
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1552
|
+
return await response.json();
|
|
1553
|
+
}
|
|
1554
|
+
async function startStudyJoin(apiBaseUrl, eventWriteToken, joinCode, mode) {
|
|
1555
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions`, {
|
|
1556
|
+
method: "POST",
|
|
1557
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1558
|
+
body: JSON.stringify({ joinCode, mode })
|
|
1559
|
+
});
|
|
1560
|
+
if (!response.ok)
|
|
1561
|
+
throw await apiError(response);
|
|
1562
|
+
return await response.json();
|
|
1563
|
+
}
|
|
1564
|
+
async function getStudyJoinStatus(apiBaseUrl, eventWriteToken, joinSessionId) {
|
|
1565
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions/${encodeURIComponent(joinSessionId)}/status`, {
|
|
1566
|
+
method: "GET",
|
|
1567
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` }
|
|
1568
|
+
});
|
|
1569
|
+
if (!response.ok)
|
|
1570
|
+
throw await apiError(response);
|
|
1571
|
+
return await response.json();
|
|
1572
|
+
}
|
|
1573
|
+
async function readInitiatives(apiBaseUrl, eventWriteToken, signal) {
|
|
1574
|
+
let response;
|
|
1575
|
+
try {
|
|
1576
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/initiatives`, {
|
|
1577
|
+
method: "GET",
|
|
1578
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1579
|
+
signal
|
|
1580
|
+
});
|
|
1581
|
+
} catch (error2) {
|
|
1582
|
+
return { kind: "failed", reason: error2 instanceof Error && error2.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1583
|
+
}
|
|
1584
|
+
if (response.status === 401)
|
|
1585
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1586
|
+
if (!response.ok)
|
|
1587
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1588
|
+
let body;
|
|
1404
1589
|
try {
|
|
1405
|
-
|
|
1590
|
+
body = await response.json();
|
|
1406
1591
|
} catch {
|
|
1407
|
-
return
|
|
1592
|
+
return { kind: "failed", reason: "the reply was not readable" };
|
|
1408
1593
|
}
|
|
1594
|
+
if (!Array.isArray(body))
|
|
1595
|
+
return { kind: "failed", reason: "the reply was not a list" };
|
|
1596
|
+
return { kind: "ok", initiatives: body };
|
|
1409
1597
|
}
|
|
1410
|
-
function
|
|
1411
|
-
|
|
1412
|
-
const dir = path.join(ascendaHome(), "tokens");
|
|
1413
|
-
let names;
|
|
1598
|
+
async function readStudyNotices(apiBaseUrl, eventWriteToken, signal) {
|
|
1599
|
+
let response;
|
|
1414
1600
|
try {
|
|
1415
|
-
|
|
1601
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices`, {
|
|
1602
|
+
method: "GET",
|
|
1603
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1604
|
+
signal
|
|
1605
|
+
});
|
|
1606
|
+
} catch (error2) {
|
|
1607
|
+
return { kind: "failed", reason: error2 instanceof Error && error2.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1608
|
+
}
|
|
1609
|
+
if (response.status === 404)
|
|
1610
|
+
return { kind: "absent" };
|
|
1611
|
+
if (response.status === 401)
|
|
1612
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1613
|
+
if (!response.ok)
|
|
1614
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1615
|
+
let body;
|
|
1616
|
+
try {
|
|
1617
|
+
body = await response.json();
|
|
1416
1618
|
} catch {
|
|
1417
|
-
return
|
|
1619
|
+
return { kind: "absent" };
|
|
1418
1620
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1621
|
+
if (!Array.isArray(body))
|
|
1622
|
+
return { kind: "absent" };
|
|
1623
|
+
return { kind: "ok", notices: body };
|
|
1624
|
+
}
|
|
1625
|
+
async function setStudyObjection(apiBaseUrl, eventWriteToken, code, objected) {
|
|
1626
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(String(code))}/objection`, {
|
|
1627
|
+
method: objected ? "POST" : "DELETE",
|
|
1628
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` }
|
|
1629
|
+
});
|
|
1630
|
+
if (!response.ok)
|
|
1631
|
+
throw await apiError(response);
|
|
1632
|
+
}
|
|
1633
|
+
async function markStudyNoticeShown(apiBaseUrl, eventWriteToken, organisationId, code, signal) {
|
|
1634
|
+
try {
|
|
1635
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(organisationId)}/${encodeURIComponent(String(code))}/shown`, {
|
|
1636
|
+
method: "POST",
|
|
1637
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` },
|
|
1638
|
+
signal
|
|
1639
|
+
});
|
|
1640
|
+
return response.ok;
|
|
1641
|
+
} catch {
|
|
1642
|
+
return false;
|
|
1433
1643
|
}
|
|
1434
|
-
return ids;
|
|
1435
1644
|
}
|
|
1436
|
-
function
|
|
1645
|
+
async function apiError(response) {
|
|
1646
|
+
const body = await response.text();
|
|
1647
|
+
let errorCode;
|
|
1437
1648
|
try {
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
const value = fs.readFileSync(tokenFilePath, "utf8").trim();
|
|
1441
|
-
return value || void 0;
|
|
1649
|
+
const parsed = JSON.parse(body);
|
|
1650
|
+
errorCode = parsed.code ?? parsed.error;
|
|
1442
1651
|
} catch {
|
|
1443
|
-
|
|
1652
|
+
errorCode = void 0;
|
|
1444
1653
|
}
|
|
1654
|
+
return new AscendaApiError(response.status, errorCode, body);
|
|
1445
1655
|
}
|
|
1446
|
-
function
|
|
1447
|
-
|
|
1656
|
+
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
1657
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
1658
|
+
method: "POST",
|
|
1659
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1660
|
+
signal
|
|
1661
|
+
});
|
|
1662
|
+
if (response.status === 401)
|
|
1663
|
+
return null;
|
|
1664
|
+
if (!response.ok)
|
|
1665
|
+
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1666
|
+
return await response.json();
|
|
1448
1667
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1459
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1460
|
-
desc = { enumerable: true, get: function() {
|
|
1461
|
-
return m[k];
|
|
1462
|
-
} };
|
|
1668
|
+
function isDeliveredStatus(value) {
|
|
1669
|
+
return typeof value === "string" && tool_contract_1.TOOL_EVENT_DELIVERED_STATUSES.includes(value);
|
|
1670
|
+
}
|
|
1671
|
+
function readSuccessBody(body) {
|
|
1672
|
+
let parsed;
|
|
1673
|
+
try {
|
|
1674
|
+
parsed = JSON.parse(body);
|
|
1675
|
+
} catch {
|
|
1676
|
+
return { duplicates: 0 };
|
|
1463
1677
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1678
|
+
if (!parsed || typeof parsed !== "object")
|
|
1679
|
+
return { duplicates: 0 };
|
|
1680
|
+
const single = parsed.status;
|
|
1681
|
+
if (isDeliveredStatus(single))
|
|
1682
|
+
return { duplicates: single === "duplicate" ? 1 : 0 };
|
|
1683
|
+
const raw = parsed.results;
|
|
1684
|
+
if (!Array.isArray(raw))
|
|
1685
|
+
return { duplicates: 0 };
|
|
1686
|
+
const results = [];
|
|
1687
|
+
for (const item of raw) {
|
|
1688
|
+
if (!item || typeof item !== "object")
|
|
1689
|
+
continue;
|
|
1690
|
+
const { index, status, reason } = item;
|
|
1691
|
+
if (typeof index !== "number" || typeof status !== "string")
|
|
1692
|
+
continue;
|
|
1693
|
+
results.push({ index, status, ...typeof reason === "string" ? { reason } : {} });
|
|
1694
|
+
}
|
|
1695
|
+
return { duplicates: results.filter((item) => item.status === "duplicate").length, results };
|
|
1696
|
+
}
|
|
1697
|
+
function isRetryableStatus(status) {
|
|
1698
|
+
return status === 408 || status === 429 || status !== void 0 && status >= 500 && status <= 599;
|
|
1699
|
+
}
|
|
1700
|
+
async function postToolEvent(apiBaseUrl, eventWriteToken, payload, signal) {
|
|
1701
|
+
return sendIngest(`${apiBaseUrl}/v1/tool-events`, eventWriteToken, JSON.stringify(payload), signal);
|
|
1702
|
+
}
|
|
1703
|
+
async function postToolEventsBatch(apiBaseUrl, eventWriteToken, payloads, signal) {
|
|
1704
|
+
return sendIngest(`${apiBaseUrl}/v1/tool-events/batch`, eventWriteToken, JSON.stringify({ events: payloads }), signal);
|
|
1705
|
+
}
|
|
1706
|
+
async function sendIngest(url, eventWriteToken, body, signal) {
|
|
1707
|
+
try {
|
|
1708
|
+
const response = await fetch(url, {
|
|
1709
|
+
method: "POST",
|
|
1710
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1711
|
+
body,
|
|
1712
|
+
signal
|
|
1713
|
+
});
|
|
1714
|
+
return parseIngestResponse(response);
|
|
1715
|
+
} catch (error2) {
|
|
1716
|
+
return {
|
|
1717
|
+
result: "transport_error",
|
|
1718
|
+
detail: error2 instanceof Error ? `${error2.name}: ${error2.message}` : String(error2)
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
async function parseIngestResponse(response) {
|
|
1723
|
+
if (response.ok) {
|
|
1724
|
+
const outcome = { result: "accepted", httpStatus: response.status };
|
|
1725
|
+
let read = { duplicates: 0 };
|
|
1726
|
+
try {
|
|
1727
|
+
read = readSuccessBody(await response.text());
|
|
1728
|
+
} catch {
|
|
1729
|
+
read = { duplicates: 0 };
|
|
1730
|
+
}
|
|
1731
|
+
return {
|
|
1732
|
+
...outcome,
|
|
1733
|
+
...read.duplicates > 0 ? { duplicates: read.duplicates } : {},
|
|
1734
|
+
...read.results !== void 0 ? { results: read.results } : {}
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1737
|
+
const body = await response.text();
|
|
1738
|
+
let errorCode;
|
|
1739
|
+
try {
|
|
1740
|
+
errorCode = JSON.parse(body).error;
|
|
1741
|
+
} catch {
|
|
1742
|
+
errorCode = void 0;
|
|
1743
|
+
}
|
|
1744
|
+
const base = { httpStatus: response.status, errorCode, detail: body || void 0 };
|
|
1745
|
+
if (response.status === 401)
|
|
1746
|
+
return { ...base, result: "auth_failed" };
|
|
1747
|
+
if (response.status === 403 && errorCode === "consent_missing_or_expired")
|
|
1748
|
+
return { ...base, result: "consent_missing" };
|
|
1749
|
+
if (response.status === 400 || response.status === 422)
|
|
1750
|
+
return { ...base, result: "validation_failed" };
|
|
1751
|
+
return { ...base, result: "transport_error" };
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
});
|
|
1755
|
+
|
|
1756
|
+
// ../packages/tool-kit/out/stateStore.js
|
|
1757
|
+
var require_stateStore = __commonJS({
|
|
1758
|
+
"../packages/tool-kit/out/stateStore.js"(exports) {
|
|
1759
|
+
"use strict";
|
|
1760
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1761
|
+
if (k2 === void 0) k2 = k;
|
|
1762
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1763
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1764
|
+
desc = { enumerable: true, get: function() {
|
|
1765
|
+
return m[k];
|
|
1766
|
+
} };
|
|
1767
|
+
}
|
|
1768
|
+
Object.defineProperty(o, k2, desc);
|
|
1769
|
+
} : function(o, m, k, k2) {
|
|
1770
|
+
if (k2 === void 0) k2 = k;
|
|
1771
|
+
o[k2] = m[k];
|
|
1772
|
+
});
|
|
1773
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1774
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1775
|
+
} : function(o, v) {
|
|
1776
|
+
o["default"] = v;
|
|
1777
|
+
});
|
|
1778
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1779
|
+
var ownKeys = function(o) {
|
|
1780
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1781
|
+
var ar = [];
|
|
1782
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1783
|
+
return ar;
|
|
1784
|
+
};
|
|
1785
|
+
return ownKeys(o);
|
|
1786
|
+
};
|
|
1787
|
+
return function(mod) {
|
|
1788
|
+
if (mod && mod.__esModule) return mod;
|
|
1789
|
+
var result = {};
|
|
1790
|
+
if (mod != null) {
|
|
1487
1791
|
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1488
1792
|
}
|
|
1489
1793
|
__setModuleDefault(result, mod);
|
|
@@ -1853,6 +2157,7 @@ var require_eventSender = __commonJS({
|
|
|
1853
2157
|
"use strict";
|
|
1854
2158
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1855
2159
|
exports.AscendaEventSender = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = void 0;
|
|
2160
|
+
exports.buildEventBody = buildEventBody;
|
|
1856
2161
|
exports.buildEventPayload = buildEventPayload;
|
|
1857
2162
|
var afterHours_1 = require_afterHours();
|
|
1858
2163
|
var tool_contract_1 = require_out();
|
|
@@ -1871,12 +2176,10 @@ var require_eventSender = __commonJS({
|
|
|
1871
2176
|
}
|
|
1872
2177
|
};
|
|
1873
2178
|
exports.AscendaSemanticEventError = AscendaSemanticEventError;
|
|
1874
|
-
function
|
|
2179
|
+
function buildEventBody(identity, mapped) {
|
|
1875
2180
|
return {
|
|
1876
|
-
toolInstallationId: identity.toolInstallationId,
|
|
1877
2181
|
source: identity.source,
|
|
1878
2182
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1879
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
1880
2183
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
1881
2184
|
sessionId: identity.sessionId ?? void 0,
|
|
1882
2185
|
workspaceHash: identity.workspaceHash ?? void 0,
|
|
@@ -1888,6 +2191,9 @@ var require_eventSender = __commonJS({
|
|
|
1888
2191
|
metadata: withCollectorVersion(mapped.metadata)
|
|
1889
2192
|
};
|
|
1890
2193
|
}
|
|
2194
|
+
function buildEventPayload(identity, mapped) {
|
|
2195
|
+
return (0, tool_contract_1.joinEventPayload)({ toolInstallationId: identity.toolInstallationId, idempotencyKey: (0, payload_1.mintIdempotencyKey)() }, buildEventBody(identity, mapped));
|
|
2196
|
+
}
|
|
1891
2197
|
function withCollectorVersion(metadata) {
|
|
1892
2198
|
return { ...metadata, collectorVersion: collectorVersion_1.COLLECTOR_VERSION };
|
|
1893
2199
|
}
|
|
@@ -1963,12 +2269,10 @@ var require_eventSender = __commonJS({
|
|
|
1963
2269
|
if (!mapped.metadata.skillVersion || !mapped.metadata.skillVersion.trim()) {
|
|
1964
2270
|
throw new AscendaSemanticEventError(`metadata.skillVersion is required for semantic event "${mapped.eventType}".`);
|
|
1965
2271
|
}
|
|
1966
|
-
const
|
|
1967
|
-
toolInstallationId: this.config.toolInstallationId,
|
|
2272
|
+
const body = {
|
|
1968
2273
|
source: this.config.source,
|
|
1969
2274
|
eventType: mapped.eventType,
|
|
1970
2275
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1971
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
1972
2276
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
1973
2277
|
severity: "low",
|
|
1974
2278
|
sessionId: this.config.sessionId ?? void 0,
|
|
@@ -1979,7 +2283,7 @@ var require_eventSender = __commonJS({
|
|
|
1979
2283
|
privacyMode: "metadata_only",
|
|
1980
2284
|
metadata: withCollectorVersion(mapped.metadata)
|
|
1981
2285
|
};
|
|
1982
|
-
return this.post(
|
|
2286
|
+
return this.post((0, tool_contract_1.joinEventPayload)(this.envelope(), body));
|
|
1983
2287
|
}
|
|
1984
2288
|
/**
|
|
1985
2289
|
* Sends a collaboration event under `workflow_telemetry`.
|
|
@@ -1994,12 +2298,10 @@ var require_eventSender = __commonJS({
|
|
|
1994
2298
|
if (!tool_contract_1.COLLABORATION_EVENT_TYPES.includes(mapped.eventType)) {
|
|
1995
2299
|
throw new AscendaSemanticEventError(`"${mapped.eventType}" is not a collaboration event type. Use send() for a deterministic host event.`);
|
|
1996
2300
|
}
|
|
1997
|
-
const
|
|
1998
|
-
toolInstallationId: this.config.toolInstallationId,
|
|
2301
|
+
const body = {
|
|
1999
2302
|
source: this.config.source,
|
|
2000
2303
|
eventType: mapped.eventType,
|
|
2001
2304
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2002
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
2003
2305
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
2004
2306
|
severity: "low",
|
|
2005
2307
|
sessionId: this.config.sessionId ?? void 0,
|
|
@@ -2010,7 +2312,11 @@ var require_eventSender = __commonJS({
|
|
|
2010
2312
|
privacyMode: "metadata_only",
|
|
2011
2313
|
metadata: withCollectorVersion(mapped.metadata)
|
|
2012
2314
|
};
|
|
2013
|
-
return this.post(
|
|
2315
|
+
return this.post((0, tool_contract_1.joinEventPayload)(this.envelope(), body));
|
|
2316
|
+
}
|
|
2317
|
+
/** A fresh envelope per event: the key belongs to the event, so every retry of it reuses this one. */
|
|
2318
|
+
envelope() {
|
|
2319
|
+
return { toolInstallationId: this.config.toolInstallationId, idempotencyKey: (0, payload_1.mintIdempotencyKey)() };
|
|
2014
2320
|
}
|
|
2015
2321
|
/**
|
|
2016
2322
|
* The single choke point every event passes through, and therefore the only
|
|
@@ -2430,123 +2736,6 @@ var require_contextRegistry = __commonJS({
|
|
|
2430
2736
|
}
|
|
2431
2737
|
});
|
|
2432
2738
|
|
|
2433
|
-
// ../packages/tool-kit/out/credentials.js
|
|
2434
|
-
var require_credentials = __commonJS({
|
|
2435
|
-
"../packages/tool-kit/out/credentials.js"(exports) {
|
|
2436
|
-
"use strict";
|
|
2437
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
2438
|
-
if (k2 === void 0) k2 = k;
|
|
2439
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2440
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2441
|
-
desc = { enumerable: true, get: function() {
|
|
2442
|
-
return m[k];
|
|
2443
|
-
} };
|
|
2444
|
-
}
|
|
2445
|
-
Object.defineProperty(o, k2, desc);
|
|
2446
|
-
} : function(o, m, k, k2) {
|
|
2447
|
-
if (k2 === void 0) k2 = k;
|
|
2448
|
-
o[k2] = m[k];
|
|
2449
|
-
});
|
|
2450
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
2451
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
2452
|
-
} : function(o, v) {
|
|
2453
|
-
o["default"] = v;
|
|
2454
|
-
});
|
|
2455
|
-
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
2456
|
-
var ownKeys = function(o) {
|
|
2457
|
-
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
2458
|
-
var ar = [];
|
|
2459
|
-
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
2460
|
-
return ar;
|
|
2461
|
-
};
|
|
2462
|
-
return ownKeys(o);
|
|
2463
|
-
};
|
|
2464
|
-
return function(mod) {
|
|
2465
|
-
if (mod && mod.__esModule) return mod;
|
|
2466
|
-
var result = {};
|
|
2467
|
-
if (mod != null) {
|
|
2468
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
2469
|
-
}
|
|
2470
|
-
__setModuleDefault(result, mod);
|
|
2471
|
-
return result;
|
|
2472
|
-
};
|
|
2473
|
-
}();
|
|
2474
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2475
|
-
exports.credentialsFilePath = credentialsFilePath;
|
|
2476
|
-
exports.readMachineCredentials = readMachineCredentials;
|
|
2477
|
-
exports.writeMachineCredentials = writeMachineCredentials;
|
|
2478
|
-
exports.writeTopLevelCredentials = writeTopLevelCredentials;
|
|
2479
|
-
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
2480
|
-
exports.readHostCredentials = readHostCredentials;
|
|
2481
|
-
exports.writeHostCredentials = writeHostCredentials;
|
|
2482
|
-
exports.removeHostCredentials = removeHostCredentials;
|
|
2483
|
-
var fs = __importStar(__require("fs"));
|
|
2484
|
-
var path = __importStar(__require("path"));
|
|
2485
|
-
var tokenStore_1 = require_tokenStore();
|
|
2486
|
-
function credentialsFilePath() {
|
|
2487
|
-
return path.join((0, tokenStore_1.ascendaHome)(), "credentials.json");
|
|
2488
|
-
}
|
|
2489
|
-
function readMachineCredentials() {
|
|
2490
|
-
try {
|
|
2491
|
-
const raw = fs.readFileSync(credentialsFilePath(), "utf8").trim();
|
|
2492
|
-
if (!raw)
|
|
2493
|
-
return void 0;
|
|
2494
|
-
const parsed = JSON.parse(raw);
|
|
2495
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
2496
|
-
return void 0;
|
|
2497
|
-
return parsed;
|
|
2498
|
-
} catch {
|
|
2499
|
-
return void 0;
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
function writeMachineCredentials(credentials) {
|
|
2503
|
-
const file = credentialsFilePath();
|
|
2504
|
-
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 448 });
|
|
2505
|
-
fs.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
2506
|
-
`, { encoding: "utf8", mode: 384 });
|
|
2507
|
-
if (process.platform !== "win32") {
|
|
2508
|
-
fs.chmodSync(path.dirname(file), 448);
|
|
2509
|
-
fs.chmodSync(file, 384);
|
|
2510
|
-
}
|
|
2511
|
-
}
|
|
2512
|
-
function writeTopLevelCredentials(credentials) {
|
|
2513
|
-
const existing = readMachineCredentials();
|
|
2514
|
-
writeMachineCredentials({ ...credentials, ...existing?.tools ? { tools: existing.tools } : {} });
|
|
2515
|
-
}
|
|
2516
|
-
function isLocalOnlyHostInstall(host, hasToken) {
|
|
2517
|
-
const credentials = readHostCredentials(host);
|
|
2518
|
-
if (!credentials?.localOnly)
|
|
2519
|
-
return false;
|
|
2520
|
-
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
2521
|
-
return false;
|
|
2522
|
-
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
2523
|
-
}
|
|
2524
|
-
function readHostCredentials(host) {
|
|
2525
|
-
const entry = readMachineCredentials()?.tools?.[host];
|
|
2526
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
2527
|
-
return void 0;
|
|
2528
|
-
return entry;
|
|
2529
|
-
}
|
|
2530
|
-
function writeHostCredentials(host, credentials) {
|
|
2531
|
-
const existing = readMachineCredentials() ?? {};
|
|
2532
|
-
writeMachineCredentials({ ...existing, tools: { ...existing.tools ?? {}, [host]: credentials } });
|
|
2533
|
-
}
|
|
2534
|
-
function removeHostCredentials(host) {
|
|
2535
|
-
const existing = readMachineCredentials();
|
|
2536
|
-
if (!existing?.tools || !(host in existing.tools))
|
|
2537
|
-
return;
|
|
2538
|
-
const tools = { ...existing.tools };
|
|
2539
|
-
delete tools[host];
|
|
2540
|
-
const next = { ...existing };
|
|
2541
|
-
if (Object.keys(tools).length)
|
|
2542
|
-
next.tools = tools;
|
|
2543
|
-
else
|
|
2544
|
-
delete next.tools;
|
|
2545
|
-
writeMachineCredentials(next);
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
});
|
|
2549
|
-
|
|
2550
2739
|
// ../packages/tool-kit/out/forgeProject.js
|
|
2551
2740
|
var require_forgeProject = __commonJS({
|
|
2552
2741
|
"../packages/tool-kit/out/forgeProject.js"(exports) {
|
|
@@ -3090,8 +3279,12 @@ var require_hookAdapter = __commonJS({
|
|
|
3090
3279
|
return;
|
|
3091
3280
|
const notice = options.onNotice ?? ((message) => console.error(message));
|
|
3092
3281
|
const hasToken = (id) => (0, tokenStore_1.readTokenFile)(process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0;
|
|
3093
|
-
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken))
|
|
3282
|
+
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken)) {
|
|
3283
|
+
const logFile = (0, eventLog_1.resolveEventLogPath)({ localOnly: true });
|
|
3284
|
+
if (logFile)
|
|
3285
|
+
logUnsent(logFile, events, options);
|
|
3094
3286
|
return;
|
|
3287
|
+
}
|
|
3095
3288
|
let config2;
|
|
3096
3289
|
try {
|
|
3097
3290
|
config2 = loadCliAgentConfig(options.toolType, options.sessionId, options.cwd, options);
|
|
@@ -3101,20 +3294,7 @@ var require_hookAdapter = __commonJS({
|
|
|
3101
3294
|
const logFile = (0, eventLog_1.resolveEventLogPath)();
|
|
3102
3295
|
if (!logFile)
|
|
3103
3296
|
throw error2;
|
|
3104
|
-
|
|
3105
|
-
for (const event of events) {
|
|
3106
|
-
(0, eventLog_1.appendEventLog)(logFile, {
|
|
3107
|
-
loggedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3108
|
-
delivery: "not_sent",
|
|
3109
|
-
payload: (0, eventSender_1.buildEventPayload)({
|
|
3110
|
-
toolInstallationId: `${options.toolType}:unpaired`,
|
|
3111
|
-
source: options.source,
|
|
3112
|
-
sessionId: options.sessionId ?? null,
|
|
3113
|
-
workspaceHash: contextHashes.workspaceHash,
|
|
3114
|
-
projectHash: contextHashes.projectHash
|
|
3115
|
-
}, event)
|
|
3116
|
-
});
|
|
3117
|
-
}
|
|
3297
|
+
logUnsent(logFile, events, options);
|
|
3118
3298
|
return;
|
|
3119
3299
|
}
|
|
3120
3300
|
const sender = new eventSender_1.AscendaEventSender({
|
|
@@ -3144,6 +3324,22 @@ var require_hookAdapter = __commonJS({
|
|
|
3144
3324
|
return;
|
|
3145
3325
|
}
|
|
3146
3326
|
}
|
|
3327
|
+
function logUnsent(logFile, events, options) {
|
|
3328
|
+
const contextHashes = resolveContextHashes(options.cwd);
|
|
3329
|
+
for (const event of events) {
|
|
3330
|
+
(0, eventLog_1.appendEventLog)(logFile, {
|
|
3331
|
+
loggedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3332
|
+
delivery: "not_sent",
|
|
3333
|
+
payload: (0, eventSender_1.buildEventPayload)({
|
|
3334
|
+
toolInstallationId: `${options.toolType}:unpaired`,
|
|
3335
|
+
source: options.source,
|
|
3336
|
+
sessionId: process.env.ASCENDA_SESSION_ID?.trim() || options.sessionId || null,
|
|
3337
|
+
workspaceHash: contextHashes.workspaceHash,
|
|
3338
|
+
projectHash: contextHashes.projectHash
|
|
3339
|
+
}, event)
|
|
3340
|
+
});
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3147
3343
|
function journalSkippedSend(host, error2) {
|
|
3148
3344
|
const who = host ? `${host}: ` : "";
|
|
3149
3345
|
(0, stateStore_1.recordSendOutcome)((0, stateStore_1.unresolvedStateFilePath)(error2.toolType), (0, stateStore_1.unresolvedToolInstallationId)(error2.toolType), "skipped_no_installation_id", {
|
|
@@ -3524,152 +3720,917 @@ var require_initiatives = __commonJS({
|
|
|
3524
3720
|
}
|
|
3525
3721
|
return lines;
|
|
3526
3722
|
}
|
|
3527
|
-
function renderOne(initiative, copy) {
|
|
3528
|
-
const lines = [` ${initiative.organisationName}: ${initiative.title}`];
|
|
3529
|
-
lines.push(` ${describeStatus(initiative)}`);
|
|
3530
|
-
if (initiative.summaryForCohort) {
|
|
3531
|
-
for (const line of initiative.summaryForCohort.split(/\r?\n/))
|
|
3532
|
-
lines.push(` ${line}`);
|
|
3533
|
-
}
|
|
3534
|
-
if (initiative.direction)
|
|
3535
|
-
lines.push(` ${DIRECTION_WORDS[initiative.direction] ?? DIRECTION_UNKNOWN}`);
|
|
3536
|
-
lines.push(` Scoring window: ${formatWindowOrRaw(initiative.scoringStartUtc, initiative.scoringEndUtc)}`);
|
|
3537
|
-
if (initiative.result)
|
|
3538
|
-
lines.push(...renderResult(initiative.result, initiative.measureUnit, copy));
|
|
3539
|
-
lines.push("");
|
|
3540
|
-
return lines;
|
|
3723
|
+
function renderOne(initiative, copy) {
|
|
3724
|
+
const lines = [` ${initiative.organisationName}: ${initiative.title}`];
|
|
3725
|
+
lines.push(` ${describeStatus(initiative)}`);
|
|
3726
|
+
if (initiative.summaryForCohort) {
|
|
3727
|
+
for (const line of initiative.summaryForCohort.split(/\r?\n/))
|
|
3728
|
+
lines.push(` ${line}`);
|
|
3729
|
+
}
|
|
3730
|
+
if (initiative.direction)
|
|
3731
|
+
lines.push(` ${DIRECTION_WORDS[initiative.direction] ?? DIRECTION_UNKNOWN}`);
|
|
3732
|
+
lines.push(` Scoring window: ${formatWindowOrRaw(initiative.scoringStartUtc, initiative.scoringEndUtc)}`);
|
|
3733
|
+
if (initiative.result)
|
|
3734
|
+
lines.push(...renderResult(initiative.result, initiative.measureUnit, copy));
|
|
3735
|
+
lines.push("");
|
|
3736
|
+
return lines;
|
|
3737
|
+
}
|
|
3738
|
+
function describeStatus(initiative) {
|
|
3739
|
+
switch (initiative.status) {
|
|
3740
|
+
case "published":
|
|
3741
|
+
return "Published, not scored yet.";
|
|
3742
|
+
case "scored":
|
|
3743
|
+
return "Scored.";
|
|
3744
|
+
case "withdrawn":
|
|
3745
|
+
return initiative.withdrawnUtc ? `Withdrawn on ${formatDay(initiative.withdrawnUtc)}. It won't be scored.` : "Withdrawn. It won't be scored.";
|
|
3746
|
+
default:
|
|
3747
|
+
return "Status not recognised.";
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
function renderResult(result, unit, copy) {
|
|
3751
|
+
const lines = [];
|
|
3752
|
+
const show = (n) => unit ? `${figure(n)} ${unit}` : figure(n);
|
|
3753
|
+
if (result.value === null) {
|
|
3754
|
+
const why = copy.withheldReasons[result.withheldReason ?? ""];
|
|
3755
|
+
lines.push(` ${why ? `Withheld: ${why}.` : WITHHELD_UNKNOWN}`);
|
|
3756
|
+
return lines;
|
|
3757
|
+
}
|
|
3758
|
+
lines.push(` Result: ${show(result.value)}`);
|
|
3759
|
+
lines.push(` ${movementLine(result)}`);
|
|
3760
|
+
lines.push(` ${result.outcome ? copy.outcomes[result.outcome] ?? OUTCOME_UNKNOWN : OUTCOME_EMPTY}`);
|
|
3761
|
+
return lines;
|
|
3762
|
+
}
|
|
3763
|
+
function movementLine(result) {
|
|
3764
|
+
if (result.outcome === "within_own_variation")
|
|
3765
|
+
return "No material change against frozen baseline";
|
|
3766
|
+
if (result.delta === null)
|
|
3767
|
+
return "No reading";
|
|
3768
|
+
if (result.delta > 0)
|
|
3769
|
+
return `Up ${figure(result.delta)} against frozen baseline`;
|
|
3770
|
+
if (result.delta < 0)
|
|
3771
|
+
return `Down ${figure(Math.abs(result.delta))} against frozen baseline`;
|
|
3772
|
+
return "No change against frozen baseline";
|
|
3773
|
+
}
|
|
3774
|
+
function figure(n) {
|
|
3775
|
+
return String(Number(n.toPrecision(12)));
|
|
3776
|
+
}
|
|
3777
|
+
function asInitiative(value) {
|
|
3778
|
+
if (!value || typeof value !== "object")
|
|
3779
|
+
return void 0;
|
|
3780
|
+
const o = value;
|
|
3781
|
+
if (typeof o.title !== "string" || typeof o.status !== "string")
|
|
3782
|
+
return void 0;
|
|
3783
|
+
return {
|
|
3784
|
+
id: typeof o.id === "string" ? o.id : "",
|
|
3785
|
+
organisationName: typeof o.organisationName === "string" ? o.organisationName : "Your organisation",
|
|
3786
|
+
title: o.title,
|
|
3787
|
+
summaryForCohort: typeof o.summaryForCohort === "string" ? o.summaryForCohort : "",
|
|
3788
|
+
measureUnit: typeof o.measureUnit === "string" ? o.measureUnit : null,
|
|
3789
|
+
scoringStartUtc: typeof o.scoringStartUtc === "string" ? o.scoringStartUtc : "",
|
|
3790
|
+
scoringEndUtc: typeof o.scoringEndUtc === "string" ? o.scoringEndUtc : "",
|
|
3791
|
+
withdrawnUtc: typeof o.withdrawnUtc === "string" ? o.withdrawnUtc : null,
|
|
3792
|
+
status: o.status,
|
|
3793
|
+
direction: typeof o.direction === "string" ? o.direction : null,
|
|
3794
|
+
result: asResult(o.result)
|
|
3795
|
+
};
|
|
3796
|
+
}
|
|
3797
|
+
function asResult(value) {
|
|
3798
|
+
if (!value || typeof value !== "object")
|
|
3799
|
+
return null;
|
|
3800
|
+
const r = value;
|
|
3801
|
+
const num = (x) => typeof x === "number" && Number.isFinite(x) ? x : null;
|
|
3802
|
+
return {
|
|
3803
|
+
scoredAtUtc: typeof r.scoredAtUtc === "string" ? r.scoredAtUtc : "",
|
|
3804
|
+
value: num(r.value),
|
|
3805
|
+
baselineValue: num(r.baselineValue),
|
|
3806
|
+
delta: num(r.delta),
|
|
3807
|
+
movement: typeof r.movement === "string" ? r.movement : null,
|
|
3808
|
+
outcome: typeof r.outcome === "string" ? r.outcome : "",
|
|
3809
|
+
withheldReason: typeof r.withheldReason === "string" ? r.withheldReason : null,
|
|
3810
|
+
basis: typeof r.basis === "string" ? r.basis : null
|
|
3811
|
+
};
|
|
3812
|
+
}
|
|
3813
|
+
function formatWindowOrRaw(startUtc, endUtc) {
|
|
3814
|
+
if (Number.isNaN(Date.parse(startUtc)) || Number.isNaN(Date.parse(endUtc)))
|
|
3815
|
+
return "not given";
|
|
3816
|
+
return (0, studyJoin_1.formatWindow)(startUtc, endUtc);
|
|
3817
|
+
}
|
|
3818
|
+
function formatDay(iso) {
|
|
3819
|
+
const date3 = new Date(iso);
|
|
3820
|
+
if (Number.isNaN(date3.getTime()))
|
|
3821
|
+
return iso;
|
|
3822
|
+
return new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" }).format(date3);
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
});
|
|
3826
|
+
|
|
3827
|
+
// ../packages/tool-kit/out/setupDisclosure.js
|
|
3828
|
+
var require_setupDisclosure = __commonJS({
|
|
3829
|
+
"../packages/tool-kit/out/setupDisclosure.js"(exports) {
|
|
3830
|
+
"use strict";
|
|
3831
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3832
|
+
exports.FREE_TEXT_KEYS = exports.REFUSALS = exports.ALWAYS_SENT = exports.FAMILY_SENTENCES = void 0;
|
|
3833
|
+
exports.renderSetupDisclosure = renderSetupDisclosure;
|
|
3834
|
+
exports.FAMILY_SENTENCES = {
|
|
3835
|
+
session: "when a session starts and ends, the one-word reason for the end if your agent gives one, how long each turn took, and whether it ran on this machine or in a hosted cloud session",
|
|
3836
|
+
counts: "how many prompts you sent, how many replies came back, and what class of command ran in a terminal \u2014 test, lint, build, git and so on",
|
|
3837
|
+
tools: "the name of each tool your agent calls",
|
|
3838
|
+
outcome: "whether a call succeeded, failed, or was interrupted",
|
|
3839
|
+
clock: "your machine's offset from UTC, so an evening is read as an evening",
|
|
3840
|
+
repo: "your project and branch as digests computed on this machine \u2014 never the names themselves",
|
|
3841
|
+
model: "which model served the session, by name and by tier",
|
|
3842
|
+
posture: "the permission posture your agent was working under \u2014 asking each time, accepting edits, and so on",
|
|
3843
|
+
git: "that a commit, push or revert happened, and when a pull request opened or merged",
|
|
3844
|
+
edits: "roughly how much a file changed, as a bucket, and whether you edited it after the agent wrote it",
|
|
3845
|
+
context: "how full the context window got",
|
|
3846
|
+
waiting: "that your agent stopped and waited for you, as one word: permission_request, idle_prompt, or other",
|
|
3847
|
+
subagents: "when a subagent starts and stops, the id your agent gives it, and whether it was built in, from a plugin or one you defined \u2014 never its name or what it was asked",
|
|
3848
|
+
reading: "what the reader could not make sense of \u2014 lines it failed to parse, files it could not open, and prompts it judged machine-written rather than typed"
|
|
3849
|
+
};
|
|
3850
|
+
exports.ALWAYS_SENT = ["session", "counts", "tools", "outcome", "repo", "clock"];
|
|
3851
|
+
exports.REFUSALS = [
|
|
3852
|
+
"Never your prompts, your agent's replies, or anything inside a file.",
|
|
3853
|
+
"Never a file path, a command line, or a repository or branch name.",
|
|
3854
|
+
"Content is read here only to choose one of a fixed set of labels, then discarded. No mapper writes it to an event, and a test fails the build if one starts."
|
|
3855
|
+
];
|
|
3856
|
+
exports.FREE_TEXT_KEYS = ["message"];
|
|
3857
|
+
function renderSetupDisclosure({ sends, displayName }) {
|
|
3858
|
+
const declared = /* @__PURE__ */ new Set([...exports.ALWAYS_SENT, ...sends]);
|
|
3859
|
+
const ordered = Object.keys(exports.FAMILY_SENTENCES).filter((family) => declared.has(family));
|
|
3860
|
+
const lines = [
|
|
3861
|
+
`What this sends from ${displayName}, once paired:`,
|
|
3862
|
+
...ordered.map((family) => ` \xB7 ${exports.FAMILY_SENTENCES[family]}`),
|
|
3863
|
+
"",
|
|
3864
|
+
...exports.REFUSALS.map((line) => ` ${line}`),
|
|
3865
|
+
"",
|
|
3866
|
+
" Turn it off by revoking this tool in the Ascenda app."
|
|
3867
|
+
];
|
|
3868
|
+
return lines.join("\n");
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
});
|
|
3872
|
+
|
|
3873
|
+
// ../packages/tool-kit/out/hookRunner.js
|
|
3874
|
+
var require_hookRunner = __commonJS({
|
|
3875
|
+
"../packages/tool-kit/out/hookRunner.js"(exports) {
|
|
3876
|
+
"use strict";
|
|
3877
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
3878
|
+
if (k2 === void 0) k2 = k;
|
|
3879
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3880
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3881
|
+
desc = { enumerable: true, get: function() {
|
|
3882
|
+
return m[k];
|
|
3883
|
+
} };
|
|
3884
|
+
}
|
|
3885
|
+
Object.defineProperty(o, k2, desc);
|
|
3886
|
+
} : function(o, m, k, k2) {
|
|
3887
|
+
if (k2 === void 0) k2 = k;
|
|
3888
|
+
o[k2] = m[k];
|
|
3889
|
+
});
|
|
3890
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
3891
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
3892
|
+
} : function(o, v) {
|
|
3893
|
+
o["default"] = v;
|
|
3894
|
+
});
|
|
3895
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
3896
|
+
var ownKeys = function(o) {
|
|
3897
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
3898
|
+
var ar = [];
|
|
3899
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
3900
|
+
return ar;
|
|
3901
|
+
};
|
|
3902
|
+
return ownKeys(o);
|
|
3903
|
+
};
|
|
3904
|
+
return function(mod) {
|
|
3905
|
+
if (mod && mod.__esModule) return mod;
|
|
3906
|
+
var result = {};
|
|
3907
|
+
if (mod != null) {
|
|
3908
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
3909
|
+
}
|
|
3910
|
+
__setModuleDefault(result, mod);
|
|
3911
|
+
return result;
|
|
3912
|
+
};
|
|
3913
|
+
}();
|
|
3914
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3915
|
+
exports.hookRunnerPaths = hookRunnerPaths;
|
|
3916
|
+
exports.hookLauncherScript = hookLauncherScript;
|
|
3917
|
+
exports.installHookRunner = installHookRunner;
|
|
3918
|
+
exports.removeHookRunner = removeHookRunner;
|
|
3919
|
+
exports.hookRunnerCommand = hookRunnerCommand;
|
|
3920
|
+
exports.lastHookPath = lastHookPath;
|
|
3921
|
+
exports.stampLastHook = stampLastHook;
|
|
3922
|
+
exports.readLastHook = readLastHook;
|
|
3923
|
+
exports.describeAge = describeAge;
|
|
3924
|
+
exports.resolveHookNode = resolveHookNode;
|
|
3925
|
+
exports.tidyHomePath = tidyHomePath;
|
|
3926
|
+
var child_process_1 = __require("child_process");
|
|
3927
|
+
var fs = __importStar(__require("fs"));
|
|
3928
|
+
var path = __importStar(__require("path"));
|
|
3929
|
+
var tokenStore_1 = require_tokenStore();
|
|
3930
|
+
function hookRunnerPaths(binaryName) {
|
|
3931
|
+
const launcher = path.join((0, tokenStore_1.ascendaHome)(), "bin", binaryName);
|
|
3932
|
+
return { launcher, bundle: `${launcher}.mjs`, record: `${launcher}.node`, noNode: `${launcher}.no-node` };
|
|
3933
|
+
}
|
|
3934
|
+
var LAUNCHER_MANAGEMENT_COMMANDS = ["setup", "install", "status", "uninstall", "doctor", "pair", "join", "object", "-h", "--help"];
|
|
3935
|
+
function hookLauncherScript(options) {
|
|
3936
|
+
const { binaryName, setupCommand, loudEvent } = options;
|
|
3937
|
+
return [
|
|
3938
|
+
"#!/bin/sh",
|
|
3939
|
+
`# Ascenda hook launcher (${binaryName}). Written by \`setup\`, replaced by the`,
|
|
3940
|
+
"# next one; edits here are lost. Finds a Node to run the hook bundle beside it.",
|
|
3941
|
+
"",
|
|
3942
|
+
'dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || exit 0',
|
|
3943
|
+
`bundle="$dir/${binaryName}.mjs"`,
|
|
3944
|
+
`record="$dir/${binaryName}.node"`,
|
|
3945
|
+
`missing="$dir/${binaryName}.no-node"`,
|
|
3946
|
+
"",
|
|
3947
|
+
'runs() { [ -n "$1" ] && [ -f "$1" ] && [ -x "$1" ]; }',
|
|
3948
|
+
"",
|
|
3949
|
+
"# The hook bundle needs Node 20 or newer. Checked only while searching, so",
|
|
3950
|
+
"# the recorded path costs nothing to reuse.",
|
|
3951
|
+
"recent() {",
|
|
3952
|
+
` runs "$1" && "$1" -e 'process.exit(parseInt(process.versions.node, 10) >= 20 ? 0 : 1)' >/dev/null 2>&1`,
|
|
3953
|
+
"}",
|
|
3954
|
+
"",
|
|
3955
|
+
"newest_nvm() {",
|
|
3956
|
+
' [ -d "$HOME/.nvm/versions/node" ] || return 0',
|
|
3957
|
+
` ls "$HOME/.nvm/versions/node" 2>/dev/null | sed 's/^v//' | sort -t. -k1,1n -k2,2n -k3,3n | tail -n 1 | sed 's/^/v/'`,
|
|
3958
|
+
"}",
|
|
3959
|
+
"",
|
|
3960
|
+
'node=""',
|
|
3961
|
+
"how=recorded",
|
|
3962
|
+
'[ -r "$record" ] && IFS= read -r node < "$record"',
|
|
3963
|
+
"",
|
|
3964
|
+
'if ! runs "$node"; then',
|
|
3965
|
+
' node=""',
|
|
3966
|
+
" how=found",
|
|
3967
|
+
' nvm_default=""',
|
|
3968
|
+
' if [ -r "$HOME/.nvm/alias/default" ]; then',
|
|
3969
|
+
' IFS= read -r wanted < "$HOME/.nvm/alias/default"',
|
|
3970
|
+
" wanted=${wanted#v}",
|
|
3971
|
+
' for candidate in "$HOME/.nvm/versions/node/v$wanted"*; do',
|
|
3972
|
+
' [ -x "$candidate/bin/node" ] && nvm_default="$candidate/bin/node"',
|
|
3973
|
+
" done",
|
|
3974
|
+
" fi",
|
|
3975
|
+
" nvm_newest=$(newest_nvm)",
|
|
3976
|
+
" for candidate in \\",
|
|
3977
|
+
' "$(command -v node 2>/dev/null)" \\',
|
|
3978
|
+
" /opt/homebrew/bin/node \\",
|
|
3979
|
+
" /usr/local/bin/node \\",
|
|
3980
|
+
' "$HOME/.volta/bin/node" \\',
|
|
3981
|
+
' "$nvm_default" \\',
|
|
3982
|
+
' "$HOME/.local/share/fnm/aliases/default/bin/node" \\',
|
|
3983
|
+
' "$HOME/Library/Application Support/fnm/aliases/default/bin/node" \\',
|
|
3984
|
+
' "$HOME/.asdf/shims/node" \\',
|
|
3985
|
+
' "$HOME/.local/share/mise/shims/node" \\',
|
|
3986
|
+
' "$HOME/.nvm/versions/node/$nvm_newest/bin/node"',
|
|
3987
|
+
" do",
|
|
3988
|
+
' if recent "$candidate"; then node=$candidate; break; fi',
|
|
3989
|
+
" done",
|
|
3990
|
+
' if [ -n "$node" ]; then',
|
|
3991
|
+
` printf '%s\\n' "$node" > "$record.$$" 2>/dev/null && mv -f "$record.$$" "$record" 2>/dev/null`,
|
|
3992
|
+
' rm -f "$missing" 2>/dev/null',
|
|
3993
|
+
" fi",
|
|
3994
|
+
"fi",
|
|
3995
|
+
"",
|
|
3996
|
+
'if [ -n "$ASCENDA_HOOK_LAUNCHER_PROBE" ]; then',
|
|
3997
|
+
' [ -n "$node" ] || { echo "no Node 20 or newer found on PATH or in the usual install locations" >&2; exit 1; }',
|
|
3998
|
+
` printf '%s\\t%s\\n' "$node" "$how"`,
|
|
3999
|
+
" exit 0",
|
|
4000
|
+
"fi",
|
|
4001
|
+
"",
|
|
4002
|
+
'if [ -z "$node" ]; then',
|
|
4003
|
+
' date -u +%Y-%m-%dT%H:%M:%SZ > "$missing" 2>/dev/null',
|
|
4004
|
+
' case "$1" in',
|
|
4005
|
+
...loudEvent ? [
|
|
4006
|
+
` ${loudEvent})`,
|
|
4007
|
+
" cat >/dev/null 2>&1",
|
|
4008
|
+
` echo "Ascenda hooks cannot find Node 20 or newer, so none of them are running. Install Node, then run: ${setupCommand}" >&2`,
|
|
4009
|
+
" exit 1 ;;"
|
|
4010
|
+
] : [],
|
|
4011
|
+
` ${LAUNCHER_MANAGEMENT_COMMANDS.join("|")})`,
|
|
4012
|
+
` echo "${binaryName}: no Node 20 or newer found on PATH or in the usual install locations." >&2`,
|
|
4013
|
+
" exit 1 ;;",
|
|
4014
|
+
" *)",
|
|
4015
|
+
" # A hook: say nothing per tool call. status and doctor read the",
|
|
4016
|
+
" # file written above.",
|
|
4017
|
+
" cat >/dev/null 2>&1",
|
|
4018
|
+
" exit 0 ;;",
|
|
4019
|
+
" esac",
|
|
4020
|
+
"fi",
|
|
4021
|
+
"",
|
|
4022
|
+
'exec "$node" "$bundle" "$@"',
|
|
4023
|
+
""
|
|
4024
|
+
].join("\n");
|
|
4025
|
+
}
|
|
4026
|
+
function installHookRunner(options) {
|
|
4027
|
+
const paths = hookRunnerPaths(options.binaryName);
|
|
4028
|
+
if (options.dryRun)
|
|
4029
|
+
return paths.launcher;
|
|
4030
|
+
const source = path.resolve(options.source ?? process.argv[1]);
|
|
4031
|
+
fs.mkdirSync(path.dirname(paths.launcher), { recursive: true });
|
|
4032
|
+
if (process.platform === "win32") {
|
|
4033
|
+
if (source !== path.resolve(paths.launcher))
|
|
4034
|
+
fs.copyFileSync(source, paths.launcher);
|
|
4035
|
+
return paths.launcher;
|
|
4036
|
+
}
|
|
4037
|
+
if (source !== path.resolve(paths.bundle))
|
|
4038
|
+
writeAtomically(paths.bundle, fs.readFileSync(source), 493);
|
|
4039
|
+
writeAtomically(paths.launcher, hookLauncherScript(options), 493);
|
|
4040
|
+
writeAtomically(paths.record, `${process.execPath}
|
|
4041
|
+
`, 420);
|
|
4042
|
+
fs.rmSync(paths.noNode, { force: true });
|
|
4043
|
+
return paths.launcher;
|
|
4044
|
+
}
|
|
4045
|
+
function removeHookRunner(binaryName) {
|
|
4046
|
+
const removed = [];
|
|
4047
|
+
for (const file of Object.values(hookRunnerPaths(binaryName))) {
|
|
4048
|
+
if (!fs.existsSync(file))
|
|
4049
|
+
continue;
|
|
4050
|
+
fs.rmSync(file, { force: true });
|
|
4051
|
+
removed.push(file);
|
|
4052
|
+
}
|
|
4053
|
+
return removed;
|
|
4054
|
+
}
|
|
4055
|
+
function hookRunnerCommand(launcher) {
|
|
4056
|
+
return process.platform === "win32" ? `"${process.execPath}" "${launcher}"` : `"${launcher}"`;
|
|
4057
|
+
}
|
|
4058
|
+
function writeAtomically(target, contents, mode) {
|
|
4059
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
4060
|
+
fs.writeFileSync(tmp, contents, { mode });
|
|
4061
|
+
fs.chmodSync(tmp, mode);
|
|
4062
|
+
fs.renameSync(tmp, target);
|
|
4063
|
+
}
|
|
4064
|
+
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
4065
|
+
function lastHookPath(tool) {
|
|
4066
|
+
return path.join(stateDir(), `${tool}-last-hook.json`);
|
|
4067
|
+
}
|
|
4068
|
+
function stampLastHook(tool, event, now = /* @__PURE__ */ new Date()) {
|
|
4069
|
+
try {
|
|
4070
|
+
fs.mkdirSync(stateDir(), { recursive: true });
|
|
4071
|
+
const file = lastHookPath(tool);
|
|
4072
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
4073
|
+
fs.writeFileSync(tmp, `${JSON.stringify({ event, at: now.toISOString() })}
|
|
4074
|
+
`, { mode: 384 });
|
|
4075
|
+
fs.renameSync(tmp, file);
|
|
4076
|
+
} catch {
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
function readLastHook(tool) {
|
|
4080
|
+
try {
|
|
4081
|
+
const parsed = JSON.parse(fs.readFileSync(lastHookPath(tool), "utf8"));
|
|
4082
|
+
if (typeof parsed.event !== "string" || typeof parsed.at !== "string")
|
|
4083
|
+
return void 0;
|
|
4084
|
+
return { event: parsed.event, at: parsed.at };
|
|
4085
|
+
} catch {
|
|
4086
|
+
return void 0;
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
function describeAge(ms) {
|
|
4090
|
+
if (!Number.isFinite(ms) || ms < 0)
|
|
4091
|
+
return "just now";
|
|
4092
|
+
const seconds = Math.round(ms / 1e3);
|
|
4093
|
+
if (seconds < 60)
|
|
4094
|
+
return `${seconds} s ago`;
|
|
4095
|
+
const minutes = Math.round(seconds / 60);
|
|
4096
|
+
if (minutes < 60)
|
|
4097
|
+
return `${minutes} min ago`;
|
|
4098
|
+
const hours = Math.round(minutes / 60);
|
|
4099
|
+
if (hours < 48)
|
|
4100
|
+
return `${hours} h ago`;
|
|
4101
|
+
return `${Math.round(hours / 24)} days ago`;
|
|
4102
|
+
}
|
|
4103
|
+
function resolveHookNode(launcher) {
|
|
4104
|
+
if (!fs.existsSync(launcher))
|
|
4105
|
+
return { problem: "the hook launcher is not installed" };
|
|
4106
|
+
const probe = (0, child_process_1.spawnSync)("/bin/sh", [launcher], {
|
|
4107
|
+
encoding: "utf8",
|
|
4108
|
+
timeout: 5e3,
|
|
4109
|
+
env: { HOME: process.env.HOME ?? "", PATH: "/usr/bin:/bin:/usr/sbin:/sbin", ASCENDA_HOOK_LAUNCHER_PROBE: "1" }
|
|
4110
|
+
});
|
|
4111
|
+
const [node, how] = (probe.stdout ?? "").trim().split(" ");
|
|
4112
|
+
if (probe.status !== 0 || !node) {
|
|
4113
|
+
return { problem: (probe.stderr ?? "").trim() || "the launcher found no Node it can run" };
|
|
4114
|
+
}
|
|
4115
|
+
const version2 = (0, child_process_1.spawnSync)(node, ["--version"], { encoding: "utf8", timeout: 5e3 });
|
|
4116
|
+
if (version2.status !== 0)
|
|
4117
|
+
return { node, how, problem: `${node} did not run` };
|
|
4118
|
+
return { node, how, version: version2.stdout.trim() };
|
|
4119
|
+
}
|
|
4120
|
+
function tidyHomePath(file, home = process.env.HOME ?? "") {
|
|
4121
|
+
return home && file.startsWith(`${home}/`) ? `~${file.slice(home.length)}` : file;
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
});
|
|
4125
|
+
|
|
4126
|
+
// ../packages/tool-kit/out/saverHandoff.js
|
|
4127
|
+
var require_saverHandoff = __commonJS({
|
|
4128
|
+
"../packages/tool-kit/out/saverHandoff.js"(exports) {
|
|
4129
|
+
"use strict";
|
|
4130
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4131
|
+
if (k2 === void 0) k2 = k;
|
|
4132
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4133
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4134
|
+
desc = { enumerable: true, get: function() {
|
|
4135
|
+
return m[k];
|
|
4136
|
+
} };
|
|
4137
|
+
}
|
|
4138
|
+
Object.defineProperty(o, k2, desc);
|
|
4139
|
+
} : function(o, m, k, k2) {
|
|
4140
|
+
if (k2 === void 0) k2 = k;
|
|
4141
|
+
o[k2] = m[k];
|
|
4142
|
+
});
|
|
4143
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4144
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4145
|
+
} : function(o, v) {
|
|
4146
|
+
o["default"] = v;
|
|
4147
|
+
});
|
|
4148
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4149
|
+
var ownKeys = function(o) {
|
|
4150
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4151
|
+
var ar = [];
|
|
4152
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4153
|
+
return ar;
|
|
4154
|
+
};
|
|
4155
|
+
return ownKeys(o);
|
|
4156
|
+
};
|
|
4157
|
+
return function(mod) {
|
|
4158
|
+
if (mod && mod.__esModule) return mod;
|
|
4159
|
+
var result = {};
|
|
4160
|
+
if (mod != null) {
|
|
4161
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4162
|
+
}
|
|
4163
|
+
__setModuleDefault(result, mod);
|
|
4164
|
+
return result;
|
|
4165
|
+
};
|
|
4166
|
+
}();
|
|
4167
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4168
|
+
exports.SAVER_REPLAY_SCHEMA = exports.SAVER_REPLAY_WINDOW_MS = void 0;
|
|
4169
|
+
exports.saverContainerDir = saverContainerDir;
|
|
4170
|
+
exports.saverSupportDir = saverSupportDir;
|
|
4171
|
+
exports.saverReplayPath = saverReplayPath;
|
|
4172
|
+
exports.saverStatusDir = saverStatusDir;
|
|
4173
|
+
exports.holdForSaver = holdForSaver;
|
|
4174
|
+
exports.heldForSaver = heldForSaver;
|
|
4175
|
+
exports.readSaverStatuses = readSaverStatuses;
|
|
4176
|
+
exports.probeSocket = probeSocket;
|
|
4177
|
+
var fs = __importStar(__require("fs"));
|
|
4178
|
+
var net = __importStar(__require("net"));
|
|
4179
|
+
var os = __importStar(__require("os"));
|
|
4180
|
+
var path = __importStar(__require("path"));
|
|
4181
|
+
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4182
|
+
function saverContainerDir() {
|
|
4183
|
+
return process.env.ASCENDA_SAVER_CONTAINER ?? path.join(os.homedir(), "Library", "Containers", SAVER_HOST_BUNDLE_ID, "Data");
|
|
4184
|
+
}
|
|
4185
|
+
function saverSupportDir() {
|
|
4186
|
+
return path.join(saverContainerDir(), "Library", "Application Support", "AscendaWaterlineSaver");
|
|
4187
|
+
}
|
|
4188
|
+
function saverReplayPath() {
|
|
4189
|
+
return path.join(saverContainerDir(), "l.replay.json");
|
|
4190
|
+
}
|
|
4191
|
+
function saverStatusDir() {
|
|
4192
|
+
return path.join(saverSupportDir(), "status");
|
|
4193
|
+
}
|
|
4194
|
+
exports.SAVER_REPLAY_WINDOW_MS = 30 * 60 * 1e3;
|
|
4195
|
+
var SAVER_REPLAY_MAX = 32;
|
|
4196
|
+
exports.SAVER_REPLAY_SCHEMA = 1;
|
|
4197
|
+
function holdForSaver(signal, now = Date.now()) {
|
|
4198
|
+
try {
|
|
4199
|
+
if (process.env.ASCENDA_LIVE_BUS_SOCKET && !process.env.ASCENDA_SAVER_CONTAINER)
|
|
4200
|
+
return;
|
|
4201
|
+
if (!fs.existsSync(saverSupportDir()))
|
|
4202
|
+
return;
|
|
4203
|
+
const wire = signal;
|
|
4204
|
+
const tool = wire.tool;
|
|
4205
|
+
const session = wire.session;
|
|
4206
|
+
const event = wire.event;
|
|
4207
|
+
if (typeof tool !== "string" || typeof session !== "string" || typeof event !== "string")
|
|
4208
|
+
return;
|
|
4209
|
+
const file = saverReplayPath();
|
|
4210
|
+
const kept = readHeld(file).filter((held) => now - held.at <= exports.SAVER_REPLAY_WINDOW_MS && !(held.tool === tool && held.session === session));
|
|
4211
|
+
kept.push({ ...wire, tool, session, event, at: now });
|
|
4212
|
+
kept.sort((a, b) => a.at - b.at);
|
|
4213
|
+
const body = JSON.stringify({ schema: exports.SAVER_REPLAY_SCHEMA, signals: kept.slice(-SAVER_REPLAY_MAX) });
|
|
4214
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
4215
|
+
fs.writeFileSync(tmp, `${body}
|
|
4216
|
+
`, { mode: 384 });
|
|
4217
|
+
fs.renameSync(tmp, file);
|
|
4218
|
+
} catch {
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4221
|
+
function readHeld(file) {
|
|
4222
|
+
try {
|
|
4223
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
4224
|
+
if (parsed.schema !== exports.SAVER_REPLAY_SCHEMA || !Array.isArray(parsed.signals))
|
|
4225
|
+
return [];
|
|
4226
|
+
return parsed.signals.filter((held) => typeof held === "object" && held !== null && typeof held.tool === "string" && typeof held.session === "string" && typeof held.event === "string" && typeof held.at === "number");
|
|
4227
|
+
} catch {
|
|
4228
|
+
return [];
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
function heldForSaver(now = Date.now()) {
|
|
4232
|
+
const held = readHeld(saverReplayPath()).filter((entry) => now - entry.at <= exports.SAVER_REPLAY_WINDOW_MS);
|
|
4233
|
+
if (held.length === 0)
|
|
4234
|
+
return { count: 0 };
|
|
4235
|
+
return { count: held.length, newestAgeMs: now - Math.max(...held.map((entry) => entry.at)) };
|
|
4236
|
+
}
|
|
4237
|
+
function readSaverStatuses(now = Date.now()) {
|
|
4238
|
+
let names;
|
|
4239
|
+
try {
|
|
4240
|
+
names = fs.readdirSync(saverStatusDir()).filter((name) => name.endsWith(".json"));
|
|
4241
|
+
} catch {
|
|
4242
|
+
return [];
|
|
4243
|
+
}
|
|
4244
|
+
const readings = [];
|
|
4245
|
+
for (const name of names) {
|
|
4246
|
+
try {
|
|
4247
|
+
const status = JSON.parse(fs.readFileSync(path.join(saverStatusDir(), name), "utf8"));
|
|
4248
|
+
if (typeof status.pid !== "number" || typeof status.updatedAt !== "string")
|
|
4249
|
+
continue;
|
|
4250
|
+
readings.push({ ...status, alive: processAlive(status.pid), ageMs: now - Date.parse(status.updatedAt) });
|
|
4251
|
+
} catch {
|
|
4252
|
+
}
|
|
4253
|
+
}
|
|
4254
|
+
return readings.sort((a, b) => a.ageMs - b.ageMs);
|
|
4255
|
+
}
|
|
4256
|
+
function processAlive(pid) {
|
|
4257
|
+
try {
|
|
4258
|
+
process.kill(pid, 0);
|
|
4259
|
+
return true;
|
|
4260
|
+
} catch (error2) {
|
|
4261
|
+
return error2.code === "EPERM";
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
function probeSocket(socketPath, timeoutMs = 300) {
|
|
4265
|
+
return new Promise((resolve) => {
|
|
4266
|
+
try {
|
|
4267
|
+
if (!fs.statSync(socketPath).isSocket()) {
|
|
4268
|
+
resolve("absent");
|
|
4269
|
+
return;
|
|
4270
|
+
}
|
|
4271
|
+
} catch {
|
|
4272
|
+
resolve("absent");
|
|
4273
|
+
return;
|
|
4274
|
+
}
|
|
4275
|
+
let settled = false;
|
|
4276
|
+
const finish = (state) => {
|
|
4277
|
+
if (settled)
|
|
4278
|
+
return;
|
|
4279
|
+
settled = true;
|
|
4280
|
+
clearTimeout(timer);
|
|
4281
|
+
socket.destroy();
|
|
4282
|
+
resolve(state);
|
|
4283
|
+
};
|
|
4284
|
+
const socket = net.createConnection(socketPath);
|
|
4285
|
+
const timer = setTimeout(() => finish("unreachable"), timeoutMs);
|
|
4286
|
+
socket.on("connect", () => finish("listening"));
|
|
4287
|
+
socket.on("error", (error2) => finish(error2.code === "ECONNREFUSED" || error2.code === "ENOENT" ? "stale" : "unreachable"));
|
|
4288
|
+
});
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
});
|
|
4292
|
+
|
|
4293
|
+
// ../packages/tool-kit/out/liveBus.js
|
|
4294
|
+
var require_liveBus = __commonJS({
|
|
4295
|
+
"../packages/tool-kit/out/liveBus.js"(exports) {
|
|
4296
|
+
"use strict";
|
|
4297
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4298
|
+
if (k2 === void 0) k2 = k;
|
|
4299
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4300
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4301
|
+
desc = { enumerable: true, get: function() {
|
|
4302
|
+
return m[k];
|
|
4303
|
+
} };
|
|
4304
|
+
}
|
|
4305
|
+
Object.defineProperty(o, k2, desc);
|
|
4306
|
+
} : function(o, m, k, k2) {
|
|
4307
|
+
if (k2 === void 0) k2 = k;
|
|
4308
|
+
o[k2] = m[k];
|
|
4309
|
+
});
|
|
4310
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4311
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4312
|
+
} : function(o, v) {
|
|
4313
|
+
o["default"] = v;
|
|
4314
|
+
});
|
|
4315
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4316
|
+
var ownKeys = function(o) {
|
|
4317
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4318
|
+
var ar = [];
|
|
4319
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4320
|
+
return ar;
|
|
4321
|
+
};
|
|
4322
|
+
return ownKeys(o);
|
|
4323
|
+
};
|
|
4324
|
+
return function(mod) {
|
|
4325
|
+
if (mod && mod.__esModule) return mod;
|
|
4326
|
+
var result = {};
|
|
4327
|
+
if (mod != null) {
|
|
4328
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4329
|
+
}
|
|
4330
|
+
__setModuleDefault(result, mod);
|
|
4331
|
+
return result;
|
|
4332
|
+
};
|
|
4333
|
+
}();
|
|
4334
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4335
|
+
exports.SAVER_HOST_BUNDLE_ID = exports.LIVE_BUS_BACKGROUND_TRUST_MS = void 0;
|
|
4336
|
+
exports.liveBusSocketCandidates = liveBusSocketCandidates;
|
|
4337
|
+
exports.existingSocketCandidates = existingSocketCandidates;
|
|
4338
|
+
exports.liveBusSocketPath = liveBusSocketPath;
|
|
4339
|
+
exports.bucketPromptSize = bucketPromptSize;
|
|
4340
|
+
exports.emitLiveSignal = emitLiveSignal;
|
|
4341
|
+
exports.deliverLine = deliverLine;
|
|
4342
|
+
var fs = __importStar(__require("fs"));
|
|
4343
|
+
var net = __importStar(__require("net"));
|
|
4344
|
+
var os = __importStar(__require("os"));
|
|
4345
|
+
var path = __importStar(__require("path"));
|
|
4346
|
+
var hookSet_1 = require_hookSet();
|
|
4347
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
4348
|
+
var WRITE_TIMEOUT_MS = 50;
|
|
4349
|
+
exports.LIVE_BUS_BACKGROUND_TRUST_MS = 60 * 60 * 1e3;
|
|
4350
|
+
var APP_BUNDLE_ID = "one.ascenda.ascendaMissionControl";
|
|
4351
|
+
exports.SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4352
|
+
function liveBusSocketCandidates() {
|
|
4353
|
+
const override = process.env.ASCENDA_LIVE_BUS_SOCKET;
|
|
4354
|
+
if (override)
|
|
4355
|
+
return [override];
|
|
4356
|
+
const home = os.homedir();
|
|
4357
|
+
return [
|
|
4358
|
+
path.join(home, ".ascenda", "live.sock"),
|
|
4359
|
+
path.join(home, "Library", "Containers", APP_BUNDLE_ID, "Data", ".ascenda", "live.sock"),
|
|
4360
|
+
path.join(home, "Library", "Containers", exports.SAVER_HOST_BUNDLE_ID, "Data", "l.sock")
|
|
4361
|
+
];
|
|
4362
|
+
}
|
|
4363
|
+
function existingSocketCandidates() {
|
|
4364
|
+
const candidates = liveBusSocketCandidates();
|
|
4365
|
+
if (process.env.ASCENDA_LIVE_BUS_SOCKET)
|
|
4366
|
+
return candidates;
|
|
4367
|
+
return candidates.filter((candidate) => {
|
|
4368
|
+
try {
|
|
4369
|
+
return fs.statSync(candidate).isSocket();
|
|
4370
|
+
} catch {
|
|
4371
|
+
return false;
|
|
4372
|
+
}
|
|
4373
|
+
});
|
|
3541
4374
|
}
|
|
3542
|
-
function
|
|
3543
|
-
|
|
3544
|
-
case "published":
|
|
3545
|
-
return "Published, not scored yet.";
|
|
3546
|
-
case "scored":
|
|
3547
|
-
return "Scored.";
|
|
3548
|
-
case "withdrawn":
|
|
3549
|
-
return initiative.withdrawnUtc ? `Withdrawn on ${formatDay(initiative.withdrawnUtc)}. It won't be scored.` : "Withdrawn. It won't be scored.";
|
|
3550
|
-
default:
|
|
3551
|
-
return "Status not recognised.";
|
|
3552
|
-
}
|
|
4375
|
+
function liveBusSocketPath() {
|
|
4376
|
+
return existingSocketCandidates()[0] ?? liveBusSocketCandidates()[0];
|
|
3553
4377
|
}
|
|
3554
|
-
function
|
|
3555
|
-
const
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
lines.push(` ${movementLine(result)}`);
|
|
3564
|
-
lines.push(` ${result.outcome ? copy.outcomes[result.outcome] ?? OUTCOME_UNKNOWN : OUTCOME_EMPTY}`);
|
|
3565
|
-
return lines;
|
|
4378
|
+
function bucketPromptSize(text) {
|
|
4379
|
+
const length = typeof text === "string" ? text.length : 0;
|
|
4380
|
+
if (length <= 280)
|
|
4381
|
+
return "s";
|
|
4382
|
+
if (length <= 2e3)
|
|
4383
|
+
return "m";
|
|
4384
|
+
if (length <= 8e3)
|
|
4385
|
+
return "l";
|
|
4386
|
+
return "xl";
|
|
3566
4387
|
}
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
if (
|
|
3571
|
-
|
|
3572
|
-
if (
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
return `Down ${figure(Math.abs(result.delta))} against frozen baseline`;
|
|
3576
|
-
return "No change against frozen baseline";
|
|
4388
|
+
var NOBODY_LISTENING = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOENT"]);
|
|
4389
|
+
function onTheWire(signal) {
|
|
4390
|
+
const out = { ...signal };
|
|
4391
|
+
if ("hookSet" in out && !(0, hookSet_1.isHookSet)(out.hookSet))
|
|
4392
|
+
delete out.hookSet;
|
|
4393
|
+
if ("viaPlugin" in out && out.viaPlugin !== true)
|
|
4394
|
+
delete out.viaPlugin;
|
|
4395
|
+
return out;
|
|
3577
4396
|
}
|
|
3578
|
-
function
|
|
3579
|
-
|
|
4397
|
+
function emitLiveSignal(signal) {
|
|
4398
|
+
const wire = onTheWire(signal);
|
|
4399
|
+
return deliverLine(`${JSON.stringify(wire)}
|
|
4400
|
+
`).then((delivered) => {
|
|
4401
|
+
if (!delivered)
|
|
4402
|
+
(0, saverHandoff_1.holdForSaver)(wire);
|
|
4403
|
+
});
|
|
3580
4404
|
}
|
|
3581
|
-
function
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
4405
|
+
function deliverLine(line) {
|
|
4406
|
+
return new Promise((resolve) => {
|
|
4407
|
+
const candidates = existingSocketCandidates();
|
|
4408
|
+
if (candidates.length === 0) {
|
|
4409
|
+
resolve(void 0);
|
|
4410
|
+
return;
|
|
4411
|
+
}
|
|
4412
|
+
let settled = false;
|
|
4413
|
+
let accepted;
|
|
4414
|
+
let socket;
|
|
4415
|
+
const drop = () => {
|
|
4416
|
+
try {
|
|
4417
|
+
socket?.destroy();
|
|
4418
|
+
} catch {
|
|
4419
|
+
}
|
|
4420
|
+
socket = void 0;
|
|
4421
|
+
};
|
|
4422
|
+
const done = () => {
|
|
4423
|
+
if (settled)
|
|
4424
|
+
return;
|
|
4425
|
+
settled = true;
|
|
4426
|
+
clearTimeout(timer);
|
|
4427
|
+
drop();
|
|
4428
|
+
resolve(accepted);
|
|
4429
|
+
};
|
|
4430
|
+
const timer = setTimeout(done, WRITE_TIMEOUT_MS);
|
|
4431
|
+
const tryFrom = (index) => {
|
|
4432
|
+
if (settled)
|
|
4433
|
+
return;
|
|
4434
|
+
if (index >= candidates.length) {
|
|
4435
|
+
done();
|
|
4436
|
+
return;
|
|
4437
|
+
}
|
|
4438
|
+
let attempt;
|
|
4439
|
+
try {
|
|
4440
|
+
attempt = net.createConnection(candidates[index]);
|
|
4441
|
+
} catch {
|
|
4442
|
+
tryFrom(index + 1);
|
|
4443
|
+
return;
|
|
4444
|
+
}
|
|
4445
|
+
socket = attempt;
|
|
4446
|
+
if (typeof attempt.unref === "function")
|
|
4447
|
+
attempt.unref();
|
|
4448
|
+
let connected = false;
|
|
4449
|
+
attempt.on("error", (error2) => {
|
|
4450
|
+
if (settled || socket !== attempt)
|
|
4451
|
+
return;
|
|
4452
|
+
if (!connected && error2.code && NOBODY_LISTENING.has(error2.code)) {
|
|
4453
|
+
drop();
|
|
4454
|
+
tryFrom(index + 1);
|
|
4455
|
+
return;
|
|
4456
|
+
}
|
|
4457
|
+
done();
|
|
4458
|
+
});
|
|
4459
|
+
attempt.on("connect", () => {
|
|
4460
|
+
if (settled || socket !== attempt)
|
|
4461
|
+
return;
|
|
4462
|
+
connected = true;
|
|
4463
|
+
accepted = candidates[index];
|
|
4464
|
+
try {
|
|
4465
|
+
attempt.write(line, done);
|
|
4466
|
+
} catch {
|
|
4467
|
+
done();
|
|
4468
|
+
}
|
|
4469
|
+
});
|
|
4470
|
+
};
|
|
4471
|
+
tryFrom(0);
|
|
4472
|
+
});
|
|
3600
4473
|
}
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
4474
|
+
}
|
|
4475
|
+
});
|
|
4476
|
+
|
|
4477
|
+
// ../packages/tool-kit/out/terminalStyle.js
|
|
4478
|
+
var require_terminalStyle = __commonJS({
|
|
4479
|
+
"../packages/tool-kit/out/terminalStyle.js"(exports) {
|
|
4480
|
+
"use strict";
|
|
4481
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4482
|
+
exports.colourEnabled = colourEnabled;
|
|
4483
|
+
exports.terminalStyle = terminalStyle;
|
|
4484
|
+
function colourEnabled(stream = process.stdout, env = process.env) {
|
|
4485
|
+
if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "")
|
|
4486
|
+
return false;
|
|
4487
|
+
if (env.FORCE_COLOR !== void 0)
|
|
4488
|
+
return env.FORCE_COLOR !== "0";
|
|
4489
|
+
if (env.TERM === "dumb")
|
|
4490
|
+
return false;
|
|
4491
|
+
return Boolean(stream.isTTY);
|
|
4492
|
+
}
|
|
4493
|
+
function terminalStyle(enabled = colourEnabled()) {
|
|
4494
|
+
const wrap = (open, close) => (text) => enabled ? `\x1B[${open}m${text}\x1B[${close}m` : text;
|
|
4495
|
+
const bold = wrap(1, 22);
|
|
4496
|
+
const dim = wrap(2, 22);
|
|
4497
|
+
const green = wrap(32, 39);
|
|
4498
|
+
const yellow = wrap(33, 39);
|
|
4499
|
+
const red = wrap(31, 39);
|
|
4500
|
+
const cyan = wrap(36, 39);
|
|
4501
|
+
const colour = { ok: green, warn: yellow, bad: red, info: dim };
|
|
4502
|
+
const marks = { ok: "\u2713", warn: "!", bad: "\u2717", info: "\xB7" };
|
|
3606
4503
|
return {
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
4504
|
+
enabled,
|
|
4505
|
+
bold,
|
|
4506
|
+
dim,
|
|
4507
|
+
green,
|
|
4508
|
+
yellow,
|
|
4509
|
+
red,
|
|
4510
|
+
cyan,
|
|
4511
|
+
mark: (tone) => colour[tone](marks[tone]),
|
|
4512
|
+
tone: (tone, text) => colour[tone](text)
|
|
3615
4513
|
};
|
|
3616
4514
|
}
|
|
3617
|
-
function formatWindowOrRaw(startUtc, endUtc) {
|
|
3618
|
-
if (Number.isNaN(Date.parse(startUtc)) || Number.isNaN(Date.parse(endUtc)))
|
|
3619
|
-
return "not given";
|
|
3620
|
-
return (0, studyJoin_1.formatWindow)(startUtc, endUtc);
|
|
3621
|
-
}
|
|
3622
|
-
function formatDay(iso) {
|
|
3623
|
-
const date3 = new Date(iso);
|
|
3624
|
-
if (Number.isNaN(date3.getTime()))
|
|
3625
|
-
return iso;
|
|
3626
|
-
return new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" }).format(date3);
|
|
3627
|
-
}
|
|
3628
4515
|
}
|
|
3629
4516
|
});
|
|
3630
4517
|
|
|
3631
|
-
// ../packages/tool-kit/out/
|
|
3632
|
-
var
|
|
3633
|
-
"../packages/tool-kit/out/
|
|
4518
|
+
// ../packages/tool-kit/out/liveSignalDoctor.js
|
|
4519
|
+
var require_liveSignalDoctor = __commonJS({
|
|
4520
|
+
"../packages/tool-kit/out/liveSignalDoctor.js"(exports) {
|
|
3634
4521
|
"use strict";
|
|
3635
4522
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3636
|
-
exports.
|
|
3637
|
-
exports.
|
|
3638
|
-
exports.
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
"
|
|
3671
|
-
|
|
3672
|
-
|
|
4523
|
+
exports.DOCTOR_VALUE_COLUMN = void 0;
|
|
4524
|
+
exports.doctorRow = doctorRow;
|
|
4525
|
+
exports.liveSignalDoctorLines = liveSignalDoctorLines;
|
|
4526
|
+
var hookRunner_1 = require_hookRunner();
|
|
4527
|
+
var liveBus_1 = require_liveBus();
|
|
4528
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
4529
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
4530
|
+
exports.DOCTOR_VALUE_COLUMN = 25;
|
|
4531
|
+
function doctorRow(ui, tone, label, value) {
|
|
4532
|
+
return ` ${ui.mark(tone)} ${label.padEnd(exports.DOCTOR_VALUE_COLUMN - 5)} ${value}`;
|
|
4533
|
+
}
|
|
4534
|
+
async function liveSignalDoctorLines(options) {
|
|
4535
|
+
const ui = options.ui ?? (0, terminalStyle_1.terminalStyle)();
|
|
4536
|
+
const lines = [` ${ui.bold("Live signal")} ${ui.dim("(this machine; needs no pairing)")}`];
|
|
4537
|
+
const now = Date.now();
|
|
4538
|
+
let problems = 0;
|
|
4539
|
+
const row = (tone, label, value) => {
|
|
4540
|
+
if (tone === "bad" || tone === "warn")
|
|
4541
|
+
problems += 1;
|
|
4542
|
+
lines.push(doctorRow(ui, tone, label, tone === "bad" ? ui.red(value) : value));
|
|
4543
|
+
};
|
|
4544
|
+
const more = (value) => lines.push(`${" ".repeat(exports.DOCTOR_VALUE_COLUMN)}${value}`);
|
|
4545
|
+
if (options.launcher && process.platform !== "win32") {
|
|
4546
|
+
const node = (0, hookRunner_1.resolveHookNode)(options.launcher);
|
|
4547
|
+
if (node.problem)
|
|
4548
|
+
row("bad", "Node", `${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
4549
|
+
else
|
|
4550
|
+
row("ok", "Node", `${node.node} ${ui.dim(`(${node.version}, ${node.how === "recorded" ? "recorded at setup" : "found by the launcher"})`)}`);
|
|
4551
|
+
}
|
|
4552
|
+
if (options.registrations.length === 0)
|
|
4553
|
+
row("bad", "Hooks", `not registered. Run: ${options.setupCommand}`);
|
|
4554
|
+
for (const entry of options.registrations) {
|
|
4555
|
+
const where = entry.homeProject ? `loads only when ${options.displayName} starts in the home folder. Run setup again to move it to every project` : entry.scope === "user" ? "every project" : "this project only";
|
|
4556
|
+
const complete = entry.registered === options.eventCount;
|
|
4557
|
+
row(entry.homeProject || !complete ? "warn" : entry.scope === "user" ? "ok" : "info", "Hooks", `${entry.registered}/${options.eventCount} in ${entry.file} ${ui.dim(`(${where})`)}`);
|
|
4558
|
+
}
|
|
4559
|
+
if (options.registrations.length > 1) {
|
|
4560
|
+
problems += 1;
|
|
4561
|
+
more(ui.yellow("Registered in more than one file, so each event runs more than once. Run setup again to fix."));
|
|
4562
|
+
}
|
|
4563
|
+
const last = (0, hookRunner_1.readLastHook)(options.tool);
|
|
4564
|
+
if (last)
|
|
4565
|
+
row("ok", "Last hook", `${last.event}, ${(0, hookRunner_1.describeAge)(now - Date.parse(last.at))}`);
|
|
4566
|
+
else
|
|
4567
|
+
row("info", "Last hook", `none yet. Start ${options.displayName} (restart it if it was open during setup)${options.lookHint ? `, then ${options.lookHint}` : ""}`);
|
|
4568
|
+
const [appSocket, appContainerSocket, saverSocket] = (0, liveBus_1.liveBusSocketCandidates)();
|
|
4569
|
+
const appState = await (0, saverHandoff_1.probeSocket)(appSocket);
|
|
4570
|
+
const legacyState = appContainerSocket ? await (0, saverHandoff_1.probeSocket)(appContainerSocket) : "absent";
|
|
4571
|
+
if (appState === "listening" || legacyState === "listening")
|
|
4572
|
+
row("ok", "Desktop app", "listening. It takes every signal, and the saver mirrors it");
|
|
4573
|
+
else
|
|
4574
|
+
row("info", "Desktop app", "not listening");
|
|
4575
|
+
const saverState = saverSocket ? await (0, saverHandoff_1.probeSocket)(saverSocket) : "absent";
|
|
4576
|
+
const live = (0, saverHandoff_1.readSaverStatuses)(now).filter((status) => status.alive);
|
|
4577
|
+
const holder = live.find((status) => status.ownsBus);
|
|
4578
|
+
const saver = describeSaver(saverState, holder, live);
|
|
4579
|
+
row(saver.tone, "Screen saver", saver.text);
|
|
4580
|
+
for (const status of live)
|
|
4581
|
+
more(ui.dim(describeProcess(status, now)));
|
|
4582
|
+
const held = (0, saverHandoff_1.heldForSaver)(now);
|
|
4583
|
+
if (held.count > 0) {
|
|
4584
|
+
row("info", "Held for the saver", `${held.count} session${held.count === 1 ? "" : "s"}, newest ${(0, hookRunner_1.describeAge)(held.newestAgeMs ?? 0)}. Replayed when the saver starts`);
|
|
4585
|
+
}
|
|
4586
|
+
const trip = await pingRoundTrip(saverSocket, options.selfCommand);
|
|
4587
|
+
row(trip.tone, "Round trip", trip.text);
|
|
4588
|
+
lines.push("");
|
|
4589
|
+
lines.push(problems === 0 ? ` ${ui.mark("ok")} ${ui.bold("Ready.")} The hooks can run, and the screen saver hears them while it's on screen.` : ` ${ui.mark("bad")} ${ui.bold(`${problems} problem${problems === 1 ? "" : "s"} above.`)} Each line says how to fix it.`);
|
|
4590
|
+
return lines;
|
|
4591
|
+
}
|
|
4592
|
+
function describeSaver(state, holder, live) {
|
|
4593
|
+
if (state === "listening") {
|
|
4594
|
+
if (!holder)
|
|
4595
|
+
return { tone: "warn", text: "listening, from a process that isn't reporting. Restart it: killall legacyScreenSaver" };
|
|
4596
|
+
if (holder.saverViews === 0) {
|
|
4597
|
+
return { tone: "bad", text: `pid ${holder.pid} holds the socket but isn't drawing the saver, so signals go nowhere you can see. Fix: killall legacyScreenSaver` };
|
|
4598
|
+
}
|
|
4599
|
+
return { tone: "ok", text: `listening, pid ${holder.pid}, on screen` };
|
|
4600
|
+
}
|
|
4601
|
+
if (state === "stale")
|
|
4602
|
+
return { tone: "info", text: "not running (a socket file was left behind, which is harmless)" };
|
|
4603
|
+
if (live.some((status) => status.previewViews > 0)) {
|
|
4604
|
+
return { tone: "info", text: "not running. The System Settings preview never listens, so it stays still; the water goes live once the saver itself runs" };
|
|
4605
|
+
}
|
|
4606
|
+
return { tone: "info", text: "not running. That's normal: it listens only while it's on screen" };
|
|
4607
|
+
}
|
|
4608
|
+
function describeProcess(status, now) {
|
|
4609
|
+
const what = [
|
|
4610
|
+
status.saverViews > 0 ? `saver on ${status.saverViews} display${status.saverViews === 1 ? "" : "s"}` : void 0,
|
|
4611
|
+
status.previewViews > 0 ? "preview" : void 0
|
|
4612
|
+
].filter(Boolean).join(" + ") || "not drawing";
|
|
4613
|
+
const heard = status.lastSignalAt ? `last signal ${status.lastSignalEvent ?? ""} ${(0, hookRunner_1.describeAge)(now - Date.parse(status.lastSignalAt))}`.replace(/\s+/g, " ") : "no signal yet";
|
|
4614
|
+
const replay = status.replayed > 0 ? `, replayed ${status.replayed} since this process started` : "";
|
|
4615
|
+
const beat = status.ageMs > 1e4 ? `, heartbeat ${(0, hookRunner_1.describeAge)(status.ageMs)} (not animating)` : "";
|
|
4616
|
+
return `pid ${status.pid} ${status.version ?? ""}: ${what}, ${status.mode ?? "?"}${status.ownsBus ? ", owns the socket" : ""}, ${heard}${replay}${beat}`.replace(/\s+:/, ":");
|
|
4617
|
+
}
|
|
4618
|
+
async function pingRoundTrip(saverSocket, selfCommand) {
|
|
4619
|
+
const session = `doctor-${process.pid}-${Date.now()}`;
|
|
4620
|
+
const accepted = await (0, liveBus_1.deliverLine)(`${JSON.stringify({ tool: "doctor", session, event: "ping" })}
|
|
4621
|
+
`);
|
|
4622
|
+
if (!accepted) {
|
|
4623
|
+
return { tone: "info", text: `nobody is listening right now, so there is nothing to test. To test the saver: open -a ScreenSaverEngine; sleep 5; ${selfCommand} doctor` };
|
|
4624
|
+
}
|
|
4625
|
+
if (accepted !== saverSocket)
|
|
4626
|
+
return { tone: "ok", text: `the desktop app took it (${accepted})` };
|
|
4627
|
+
for (let waited = 0; waited < 2e3; waited += 100) {
|
|
4628
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
4629
|
+
const answered = (0, saverHandoff_1.readSaverStatuses)().find((status) => status.lastPingSession === session);
|
|
4630
|
+
if (answered)
|
|
4631
|
+
return { tone: "ok", text: `OK. The screen saver (pid ${answered.pid}) received it` };
|
|
4632
|
+
}
|
|
4633
|
+
return { tone: "bad", text: "the saver's socket took the ping but no saver reported it. It may be a version from before 0.8.1, or stuck. Fix: killall legacyScreenSaver" };
|
|
3673
4634
|
}
|
|
3674
4635
|
}
|
|
3675
4636
|
});
|
|
@@ -3923,37 +4884,47 @@ var require_cliAgentSetup = __commonJS({
|
|
|
3923
4884
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3924
4885
|
exports.isCliAgentManagementCommand = isCliAgentManagementCommand;
|
|
3925
4886
|
exports.cliAgentHookBinPath = cliAgentHookBinPath;
|
|
4887
|
+
exports.cliAgentSelfCommand = cliAgentSelfCommand;
|
|
3926
4888
|
exports.runCliAgentSetup = runCliAgentSetup;
|
|
3927
4889
|
exports.writeHookSettings = writeHookSettings;
|
|
3928
4890
|
exports.registeredHookSets = registeredHookSets;
|
|
3929
4891
|
exports.findStaleHookCommands = findStaleHookCommands;
|
|
4892
|
+
exports.cliAgentRegistrations = cliAgentRegistrations;
|
|
3930
4893
|
var crypto = __importStar(__require("crypto"));
|
|
3931
4894
|
var fs = __importStar(__require("fs"));
|
|
3932
4895
|
var os = __importStar(__require("os"));
|
|
3933
4896
|
var path = __importStar(__require("path"));
|
|
3934
4897
|
var collectorVersion_1 = require_collectorVersion();
|
|
3935
4898
|
var credentials_1 = require_credentials();
|
|
4899
|
+
var eventLog_1 = require_eventLog();
|
|
3936
4900
|
var hookAdapter_1 = require_hookAdapter();
|
|
3937
4901
|
var http_1 = require_http();
|
|
3938
4902
|
var hookSet_1 = require_hookSet();
|
|
3939
4903
|
var initiatives_1 = require_initiatives();
|
|
3940
4904
|
var setupDisclosure_1 = require_setupDisclosure();
|
|
4905
|
+
var hookRunner_1 = require_hookRunner();
|
|
4906
|
+
var liveSignalDoctor_1 = require_liveSignalDoctor();
|
|
3941
4907
|
var stateStore_1 = require_stateStore();
|
|
3942
4908
|
var studyJoin_1 = require_studyJoin();
|
|
3943
4909
|
var studyNotices_1 = require_studyNotices();
|
|
4910
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
3944
4911
|
var tokenStore_1 = require_tokenStore();
|
|
3945
|
-
var MANAGEMENT_COMMANDS = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "join", "object", "-h", "--help"]);
|
|
4912
|
+
var MANAGEMENT_COMMANDS = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "doctor", "join", "object", "-h", "--help"]);
|
|
3946
4913
|
function isCliAgentManagementCommand(argument) {
|
|
3947
4914
|
return argument !== void 0 && MANAGEMENT_COMMANDS.has(argument);
|
|
3948
4915
|
}
|
|
3949
4916
|
function cliAgentHookBinPath(binaryName) {
|
|
3950
|
-
return
|
|
4917
|
+
return (0, hookRunner_1.hookRunnerPaths)(binaryName).launcher;
|
|
4918
|
+
}
|
|
4919
|
+
function cliAgentSelfCommand(spec) {
|
|
4920
|
+
return process.platform === "win32" ? `npx ${spec.packageName}` : (0, hookRunner_1.tidyHomePath)(cliAgentHookBinPath(spec.binaryName), os.homedir());
|
|
3951
4921
|
}
|
|
3952
4922
|
function usage(spec) {
|
|
3953
4923
|
return `${spec.binaryName} setup \u2014 wire ${spec.displayName} to Ascenda telemetry
|
|
3954
4924
|
|
|
3955
4925
|
npx ${spec.packageName} setup [options]
|
|
3956
4926
|
npx ${spec.packageName} status
|
|
4927
|
+
npx ${spec.packageName} doctor
|
|
3957
4928
|
npx ${spec.packageName} uninstall
|
|
3958
4929
|
npx ${spec.packageName} join <code>
|
|
3959
4930
|
npx ${spec.packageName} object <purpose> [--undo]
|
|
@@ -3964,7 +4935,9 @@ Options
|
|
|
3964
4935
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
3965
4936
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
3966
4937
|
--no-pair install without pairing: local features on, nothing sent
|
|
3967
|
-
--
|
|
4938
|
+
--event-log [path|off] keep every event in a local JSONL file (default ~/.ascenda/events.jsonl).
|
|
4939
|
+
On by default when not paired; machine-wide, shared by every agent
|
|
4940
|
+
--scope user|project where hooks are registered (default user: every project)
|
|
3968
4941
|
--project-dir <path> project root for --scope project (default cwd)
|
|
3969
4942
|
--dry-run print what would change, write nothing
|
|
3970
4943
|
-h, --help
|
|
@@ -3990,29 +4963,26 @@ Options
|
|
|
3990
4963
|
return await printStatus(options, spec);
|
|
3991
4964
|
if (options.action === "uninstall")
|
|
3992
4965
|
return uninstall(options, spec);
|
|
4966
|
+
if (options.action === "doctor")
|
|
4967
|
+
return await runDoctor(options, spec);
|
|
3993
4968
|
const apiBaseUrl = (options.apiBaseUrl ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
3994
|
-
|
|
3995
|
-
console.log(`
|
|
3996
|
-
|
|
3997
|
-
`);
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
console.log(` pairing ${identity.toolInstallationId}${identity.paired ? " (new)" : " (existing)"}`);
|
|
4006
|
-
} else {
|
|
4007
|
-
unpairedReason = "pairing did not finish \u2014 installing the local half anyway";
|
|
4008
|
-
}
|
|
4009
|
-
}
|
|
4010
|
-
if (unpairedReason) {
|
|
4011
|
-
console.log(` pairing none: ${unpairedReason}`);
|
|
4012
|
-
console.log(" local features on, nothing is sent");
|
|
4013
|
-
}
|
|
4969
|
+
const ui = (0, terminalStyle_1.terminalStyle)();
|
|
4970
|
+
const row = (tone, label, value) => console.log(` ${ui.mark(tone)} ${label.padEnd(12)} ${value}`);
|
|
4971
|
+
const detail = (label, value) => console.log(ui.dim(` ${label.padEnd(12)} ${value}`));
|
|
4972
|
+
console.log(`${ui.bold("Ascenda setup")} ${ui.dim(`\xB7 ${spec.displayName} \xB7 ${apiBaseUrl}`)}`);
|
|
4973
|
+
if (!options.skipPairing)
|
|
4974
|
+
console.log(`
|
|
4975
|
+
${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName })}`);
|
|
4976
|
+
console.log("");
|
|
4977
|
+
let identity;
|
|
4978
|
+
if (!options.skipPairing)
|
|
4979
|
+
identity = await resolveIdentity(apiBaseUrl, options, spec);
|
|
4014
4980
|
const binary = installBinary(spec, options.dryRun);
|
|
4015
|
-
|
|
4981
|
+
const node = options.dryRun || process.platform === "win32" ? void 0 : (0, hookRunner_1.resolveHookNode)(binary);
|
|
4982
|
+
if (node?.problem)
|
|
4983
|
+
row("bad", "hook binary", `${(0, hookRunner_1.tidyHomePath)(binary, os.homedir())}, but ${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
4984
|
+
else
|
|
4985
|
+
row("ok", "hook binary", `${(0, hookRunner_1.tidyHomePath)(binary, os.homedir())}${node?.version ? ui.dim(` (Node ${node.version})`) : ""}`);
|
|
4016
4986
|
if (!options.dryRun) {
|
|
4017
4987
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4018
4988
|
const toolInstallationId = identity?.toolInstallationId ?? options.toolInstallationId ?? (0, credentials_1.readHostCredentials)(spec.host)?.toolInstallationId ?? `${spec.toolType}:${crypto.randomUUID()}`;
|
|
@@ -4021,32 +4991,86 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
4021
4991
|
toolInstallationId,
|
|
4022
4992
|
...identity ? { pairedAt: now } : { localOnly: true, installedAt: now }
|
|
4023
4993
|
});
|
|
4994
|
+
if (options.eventLog !== void 0)
|
|
4995
|
+
(0, credentials_1.writeEventLogSetting)(options.eventLog);
|
|
4996
|
+
}
|
|
4997
|
+
if (isHomeProject(options)) {
|
|
4998
|
+
detail("scope", "user (a project install in the home folder only loads when the agent starts there)");
|
|
4999
|
+
options.scope = "user";
|
|
4024
5000
|
}
|
|
4025
|
-
console.log(` credentials ${(0, credentials_1.credentialsFilePath)()} (tools.${spec.host})`);
|
|
4026
5001
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
4027
5002
|
const before = registeredHookSets(readSettings(settingsFile), spec);
|
|
4028
5003
|
const written = writeHookSettings(settingsFile, binary, spec, options.dryRun);
|
|
4029
5004
|
if (written === null)
|
|
4030
5005
|
return 1;
|
|
4031
|
-
|
|
5006
|
+
const reach = options.scope === "user" ? "every project" : "this project only";
|
|
5007
|
+
row("ok", "hooks", `${(0, hookRunner_1.tidyHomePath)(settingsFile, os.homedir())} ${ui.dim(`(${spec.hookEvents.length} events, ${reach}${written ? "" : ", already current"})`)}`);
|
|
4032
5008
|
const changes = spec.hookSet === void 0 ? void 0 : (0, hookSet_1.describeHookSetChanges)((0, hookSet_1.hookSetChanges)(before, spec.hookEvents), spec.hookSet);
|
|
4033
5009
|
if (changes)
|
|
4034
|
-
|
|
5010
|
+
detail("", changes);
|
|
5011
|
+
const otherFile = spec.settings.settingsPath(options.scope === "user" ? "project" : "user", options.projectDir);
|
|
5012
|
+
if (otherFile !== settingsFile && registeredHookSets(readSettings(otherFile), spec).size > 0) {
|
|
5013
|
+
if (options.dryRun) {
|
|
5014
|
+
row("info", "moved", `would remove the copy in ${(0, hookRunner_1.tidyHomePath)(otherFile, os.homedir())}, so each event runs once`);
|
|
5015
|
+
} else if (removeOurHookEntries(otherFile, spec)) {
|
|
5016
|
+
row("ok", "moved", `removed the copy in ${(0, hookRunner_1.tidyHomePath)(otherFile, os.homedir())}, so each event runs once ${ui.dim("(backup beside it)")}`);
|
|
5017
|
+
} else {
|
|
5018
|
+
row("warn", "note", `${(0, hookRunner_1.tidyHomePath)(otherFile, os.homedir())} registers these hooks too, so each event runs twice.`);
|
|
5019
|
+
detail("", `Remove the ${spec.binaryName} entries from one of the two files.`);
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
5022
|
+
const chosenLocal = options.skipPairing;
|
|
5023
|
+
if (identity)
|
|
5024
|
+
row("ok", "pairing", `${identity.toolInstallationId}${ui.dim(identity.paired ? " (new)" : " (existing)")}`);
|
|
5025
|
+
else if (chosenLocal)
|
|
5026
|
+
row("info", "pairing", `none, as asked ${ui.dim("(--no-pair)")}`);
|
|
5027
|
+
else
|
|
5028
|
+
row("warn", "pairing", "not paired: pairing did not finish");
|
|
5029
|
+
detail("credentials", `${(0, hookRunner_1.tidyHomePath)((0, credentials_1.credentialsFilePath)(), os.homedir())} (tools.${spec.host})`);
|
|
5030
|
+
const eventLog = (0, eventLog_1.resolveEventLog)({ localOnly: !identity });
|
|
5031
|
+
if (eventLog.path)
|
|
5032
|
+
row("ok", "events", `${(0, hookRunner_1.tidyHomePath)(eventLog.path, os.homedir())} ${ui.dim("(on this machine only)")}`);
|
|
5033
|
+
else if (options.eventLog !== void 0)
|
|
5034
|
+
row("info", "events", "off");
|
|
4035
5035
|
if (options.dryRun) {
|
|
4036
|
-
console.log("\nDry run
|
|
5036
|
+
console.log("\nDry run. Nothing was written.");
|
|
4037
5037
|
return 0;
|
|
4038
5038
|
}
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
5039
|
+
const self = cliAgentSelfCommand(spec);
|
|
5040
|
+
const next = (label, value) => console.log(` ${ui.bold(label.padEnd(6))} ${value}`);
|
|
5041
|
+
console.log("");
|
|
5042
|
+
if (chosenLocal) {
|
|
5043
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Ready.")} The screen saver and the Ascenda app's live view work now.`);
|
|
5044
|
+
console.log(" They run on this machine and need no account or pairing.");
|
|
5045
|
+
if (eventLog.path)
|
|
5046
|
+
console.log(` Every event is also written to ${(0, hookRunner_1.tidyHomePath)(eventLog.path, os.homedir())}, for you or any tool to read.`);
|
|
5047
|
+
} else if (!identity) {
|
|
5048
|
+
console.log(`${ui.mark("warn")} ${ui.bold("Installed, not paired.")} The screen saver and the live view work now.`);
|
|
5049
|
+
console.log(" Your sessions won't reach Ascenda's servers until pairing completes.");
|
|
5050
|
+
} else {
|
|
5051
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Done.")} Paired, and the hooks are installed.`);
|
|
5052
|
+
}
|
|
5053
|
+
console.log("");
|
|
5054
|
+
next("Next", spec.restartHint);
|
|
5055
|
+
next("Check", ui.cyan(`${self} doctor`));
|
|
5056
|
+
if (!identity)
|
|
5057
|
+
next(chosenLocal ? "Pair" : "Retry", `${ui.cyan(`${self} setup`)}${chosenLocal ? ui.dim(" (optional)") : ""}`);
|
|
5058
|
+
if (chosenLocal) {
|
|
5059
|
+
console.log("");
|
|
5060
|
+
console.log(ui.dim(" Pairing sends the details below to Ascenda's servers, under the account the"));
|
|
5061
|
+
console.log(ui.dim(" Ascenda app is signed in to when you confirm the code, so your sessions appear"));
|
|
5062
|
+
console.log(ui.dim(" in the app. Until you pair, nothing leaves this machine."));
|
|
5063
|
+
console.log("");
|
|
5064
|
+
console.log(ui.dim((0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName }).split("\n").map((line) => ` ${line}`).join("\n")));
|
|
4043
5065
|
}
|
|
4044
|
-
console.log(`Check anytime: npx ${spec.packageName} status`);
|
|
4045
5066
|
return 0;
|
|
4046
5067
|
}
|
|
5068
|
+
function isHomeProject(options) {
|
|
5069
|
+
return options.scope === "project" && path.resolve(options.projectDir) === path.resolve(os.homedir());
|
|
5070
|
+
}
|
|
4047
5071
|
function parseArgs(argv, spec) {
|
|
4048
5072
|
const options = {
|
|
4049
|
-
scope: "
|
|
5073
|
+
scope: "user",
|
|
4050
5074
|
projectDir: process.cwd(),
|
|
4051
5075
|
dryRun: false,
|
|
4052
5076
|
skipPairing: false,
|
|
@@ -4071,6 +5095,9 @@ Done. ${spec.restartHint}`);
|
|
|
4071
5095
|
case "uninstall":
|
|
4072
5096
|
options.action = "uninstall";
|
|
4073
5097
|
break;
|
|
5098
|
+
case "doctor":
|
|
5099
|
+
options.action = "doctor";
|
|
5100
|
+
break;
|
|
4074
5101
|
case "--api-base-url":
|
|
4075
5102
|
options.apiBaseUrl = next();
|
|
4076
5103
|
break;
|
|
@@ -4099,6 +5126,12 @@ Done. ${spec.restartHint}`);
|
|
|
4099
5126
|
case "--dry-run":
|
|
4100
5127
|
options.dryRun = true;
|
|
4101
5128
|
break;
|
|
5129
|
+
case "--event-log": {
|
|
5130
|
+
const { value, consumed } = (0, eventLog_1.parseEventLogFlag)(argv, i);
|
|
5131
|
+
options.eventLog = value;
|
|
5132
|
+
i += consumed;
|
|
5133
|
+
break;
|
|
5134
|
+
}
|
|
4102
5135
|
case "--no-pair":
|
|
4103
5136
|
// `--no-pairing` is the spelling this landed under first. Both appeared
|
|
4104
5137
|
// only in an unreleased changelog, so this alias exists to spare anyone
|
|
@@ -4228,17 +5261,7 @@ Pairing ${status.status}. Run setup again.`);
|
|
|
4228
5261
|
return void 0;
|
|
4229
5262
|
}
|
|
4230
5263
|
function installBinary(spec, dryRun) {
|
|
4231
|
-
|
|
4232
|
-
if (dryRun)
|
|
4233
|
-
return target;
|
|
4234
|
-
const source = process.argv[1];
|
|
4235
|
-
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
4236
|
-
if (path.resolve(source) !== path.resolve(target)) {
|
|
4237
|
-
fs.copyFileSync(source, target);
|
|
4238
|
-
}
|
|
4239
|
-
if (process.platform !== "win32")
|
|
4240
|
-
fs.chmodSync(target, 493);
|
|
4241
|
-
return target;
|
|
5264
|
+
return (0, hookRunner_1.installHookRunner)({ binaryName: spec.binaryName, setupCommand: `npx ${spec.packageName} setup`, dryRun });
|
|
4242
5265
|
}
|
|
4243
5266
|
function writeHookSettings(settingsFile, binary, spec, dryRun) {
|
|
4244
5267
|
let settings = { ...spec.settings.scaffold ?? {} };
|
|
@@ -4279,7 +5302,7 @@ ${serialised}`);
|
|
|
4279
5302
|
return true;
|
|
4280
5303
|
}
|
|
4281
5304
|
function hookCommand(binary, spec) {
|
|
4282
|
-
return
|
|
5305
|
+
return `${(0, hookRunner_1.hookRunnerCommand)(binary)}${(0, hookSet_1.hookSetArgument)(spec.hookSet)}`;
|
|
4283
5306
|
}
|
|
4284
5307
|
function registeredHookSets(settings, spec) {
|
|
4285
5308
|
const sets = /* @__PURE__ */ new Map();
|
|
@@ -4331,8 +5354,20 @@ ${serialised}`);
|
|
|
4331
5354
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
4332
5355
|
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}${localOnly ? " (installed, not paired \u2014 local features active, telemetry inactive)" : ""}`);
|
|
4333
5356
|
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
5357
|
+
console.log(`event log ${(0, eventLog_1.describeEventLog)((0, eventLog_1.resolveEventLog)({ localOnly }), `npx ${spec.packageName} setup`)}`);
|
|
4334
5358
|
console.log(`hook binary ${fs.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
5359
|
+
const node = process.platform === "win32" ? void 0 : (0, hookRunner_1.resolveHookNode)(binary);
|
|
5360
|
+
if (node) {
|
|
5361
|
+
console.log(node.problem ? `node \u2014 ${node.problem}. Install Node 20 or newer, then run setup again` : `node ${node.node} (${node.version}, ${node.how === "recorded" ? "recorded at setup" : "found by the launcher"})`);
|
|
5362
|
+
}
|
|
5363
|
+
const last = (0, hookRunner_1.readLastHook)(spec.host);
|
|
5364
|
+
console.log(last ? `last hook ${last.event}, ${(0, hookRunner_1.describeAge)(Date.now() - Date.parse(last.at))}` : `last hook \u2014 none has run yet. Start ${spec.displayName} (restart it if it was open during setup)`);
|
|
4335
5365
|
console.log(`hooks ${registered}/${spec.hookEvents.length} registered in ${settingsFile}`);
|
|
5366
|
+
const otherScope = options.scope === "user" ? "project" : "user";
|
|
5367
|
+
const otherFile = spec.settings.settingsPath(otherScope, options.projectDir);
|
|
5368
|
+
const elsewhere = registered === 0 && otherFile !== settingsFile ? countRegistered(readSettings(otherFile), spec) : 0;
|
|
5369
|
+
if (elsewhere > 0)
|
|
5370
|
+
console.log(` ${elsewhere}/${spec.hookEvents.length} found in ${otherFile} (--scope ${otherScope})`);
|
|
4336
5371
|
if (spec.hookSet !== void 0 && registered > 0) {
|
|
4337
5372
|
const sets = [...registeredHookSets(settings, spec).values()];
|
|
4338
5373
|
const oldest = Math.min(...sets);
|
|
@@ -4358,38 +5393,118 @@ ${serialised}`);
|
|
|
4358
5393
|
if (process.stdout.isTTY)
|
|
4359
5394
|
await notices.markShown();
|
|
4360
5395
|
const paired = localOnly || credentials?.toolInstallationId !== void 0;
|
|
4361
|
-
const
|
|
5396
|
+
const wired = registered === spec.hookEvents.length || options.scope === "project" && elsewhere === spec.hookEvents.length;
|
|
5397
|
+
const healthy = paired && wired && fs.existsSync(binary) && !stale.length && !node?.problem;
|
|
4362
5398
|
return healthy ? 0 : 1;
|
|
4363
5399
|
}
|
|
5400
|
+
function countRegistered(settings, spec) {
|
|
5401
|
+
return spec.hookEvents.filter((event) => (settings.hooks?.[event] ?? []).some((entry) => isOurs(entry, spec))).length;
|
|
5402
|
+
}
|
|
5403
|
+
function cliAgentRegistrations(spec, projectDir = process.cwd()) {
|
|
5404
|
+
const home = os.homedir();
|
|
5405
|
+
const userFile = spec.settings.settingsPath("user", projectDir);
|
|
5406
|
+
const projectFile = spec.settings.settingsPath("project", projectDir);
|
|
5407
|
+
const found = [];
|
|
5408
|
+
for (const [scope, file] of [["user", userFile], ["project", projectFile]]) {
|
|
5409
|
+
if (scope === "project" && file === userFile)
|
|
5410
|
+
continue;
|
|
5411
|
+
const registered = countRegistered(readSettings(file), spec);
|
|
5412
|
+
if (registered === 0)
|
|
5413
|
+
continue;
|
|
5414
|
+
found.push({
|
|
5415
|
+
file: (0, hookRunner_1.tidyHomePath)(file, home),
|
|
5416
|
+
registered,
|
|
5417
|
+
scope,
|
|
5418
|
+
homeProject: scope === "project" && path.resolve(projectDir) === path.resolve(home)
|
|
5419
|
+
});
|
|
5420
|
+
}
|
|
5421
|
+
return found;
|
|
5422
|
+
}
|
|
5423
|
+
async function runDoctor(options, spec) {
|
|
5424
|
+
const ui = (0, terminalStyle_1.terminalStyle)();
|
|
5425
|
+
const lines = [`${ui.bold("Ascenda doctor")} ${ui.dim(`\xB7 ${spec.displayName}`)}`, ""];
|
|
5426
|
+
try {
|
|
5427
|
+
lines.push(...await (0, liveSignalDoctor_1.liveSignalDoctorLines)({
|
|
5428
|
+
displayName: spec.displayName,
|
|
5429
|
+
tool: spec.host,
|
|
5430
|
+
launcher: process.platform === "win32" ? void 0 : cliAgentHookBinPath(spec.binaryName),
|
|
5431
|
+
registrations: cliAgentRegistrations(spec, options.projectDir),
|
|
5432
|
+
eventCount: spec.hookEvents.length,
|
|
5433
|
+
selfCommand: cliAgentSelfCommand(spec),
|
|
5434
|
+
setupCommand: `npx ${spec.packageName} setup`,
|
|
5435
|
+
ui
|
|
5436
|
+
}));
|
|
5437
|
+
} catch (error2) {
|
|
5438
|
+
lines.push(` Live signal (could not be checked: ${error2 instanceof Error ? error2.message : String(error2)})`);
|
|
5439
|
+
}
|
|
5440
|
+
lines.push("", ...accountLines(ui, spec));
|
|
5441
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (id) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0);
|
|
5442
|
+
lines.push("", ` ${ui.bold("Local events")} ${(0, eventLog_1.describeEventLog)((0, eventLog_1.resolveEventLog)({ localOnly }), `npx ${spec.packageName} setup`)}`);
|
|
5443
|
+
console.log(lines.join("\n"));
|
|
5444
|
+
return 0;
|
|
5445
|
+
}
|
|
5446
|
+
function accountLines(ui, spec) {
|
|
5447
|
+
const credentials = (0, credentials_1.readHostCredentials)(spec.host);
|
|
5448
|
+
const id = credentials?.toolInstallationId;
|
|
5449
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (installationId) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(installationId)) !== void 0);
|
|
5450
|
+
const row = (tone, label, value) => ` ${ui.mark(tone)} ${label.padEnd(20)} ${value}`;
|
|
5451
|
+
if (!id || localOnly) {
|
|
5452
|
+
return [
|
|
5453
|
+
` ${ui.bold("Account sync")} ${ui.dim("(optional; this install isn't paired)")}`,
|
|
5454
|
+
...id ? [ui.dim(row("info", "Installation id", id))] : [],
|
|
5455
|
+
"",
|
|
5456
|
+
" Not paired, which is fine: the screen saver, the live view and the local",
|
|
5457
|
+
" event log work without it. Nothing leaves this machine and nothing is queued.",
|
|
5458
|
+
" To send your sessions to Ascenda's servers, so they appear in the app:",
|
|
5459
|
+
` ${ui.cyan(`${cliAgentSelfCommand(spec)} setup`)}`
|
|
5460
|
+
];
|
|
5461
|
+
}
|
|
5462
|
+
const token = (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) ?? process.env.ASCENDA_EVENT_WRITE_TOKEN?.trim();
|
|
5463
|
+
const state = (0, stateStore_1.readCollectorState)((0, stateStore_1.defaultStateFilePath)(id));
|
|
5464
|
+
const outcome = state?.lastOutcome;
|
|
5465
|
+
return [
|
|
5466
|
+
` ${ui.bold("Account sync")}`,
|
|
5467
|
+
row("info", "Installation id", id),
|
|
5468
|
+
token ? row("ok", "Token", "present") : row("bad", "Token", ui.red(`missing, so nothing can be sent. Run: npx ${spec.packageName} setup`)),
|
|
5469
|
+
outcome ? row(outcome === "accepted" ? "ok" : "warn", "Last send", `${outcome}${state?.lastAttemptAt ? ui.dim(` (${state.lastAttemptAt})`) : ""}`) : row("info", "Last send", "none yet")
|
|
5470
|
+
];
|
|
5471
|
+
}
|
|
5472
|
+
function removeOurHookEntries(settingsFile, spec) {
|
|
5473
|
+
if (!fs.existsSync(settingsFile))
|
|
5474
|
+
return true;
|
|
5475
|
+
try {
|
|
5476
|
+
const settings = JSON.parse(fs.readFileSync(settingsFile, "utf8"));
|
|
5477
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
5478
|
+
for (const event of Object.keys(hooks)) {
|
|
5479
|
+
const kept = hooks[event].filter((entry) => !isOurs(entry, spec));
|
|
5480
|
+
if (kept.length)
|
|
5481
|
+
hooks[event] = kept;
|
|
5482
|
+
else
|
|
5483
|
+
delete hooks[event];
|
|
5484
|
+
}
|
|
5485
|
+
const updated = { ...settings, hooks };
|
|
5486
|
+
if (!Object.keys(hooks).length)
|
|
5487
|
+
delete updated.hooks;
|
|
5488
|
+
fs.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
5489
|
+
fs.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
5490
|
+
`, "utf8");
|
|
5491
|
+
return true;
|
|
5492
|
+
} catch {
|
|
5493
|
+
return false;
|
|
5494
|
+
}
|
|
5495
|
+
}
|
|
4364
5496
|
function uninstall(options, spec) {
|
|
4365
5497
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
4366
5498
|
if (fs.existsSync(settingsFile)) {
|
|
4367
|
-
|
|
4368
|
-
const settings = JSON.parse(fs.readFileSync(settingsFile, "utf8"));
|
|
4369
|
-
const hooks = { ...settings.hooks ?? {} };
|
|
4370
|
-
for (const event of Object.keys(hooks)) {
|
|
4371
|
-
const kept = hooks[event].filter((entry) => !isOurs(entry, spec));
|
|
4372
|
-
if (kept.length)
|
|
4373
|
-
hooks[event] = kept;
|
|
4374
|
-
else
|
|
4375
|
-
delete hooks[event];
|
|
4376
|
-
}
|
|
4377
|
-
const updated = { ...settings, hooks };
|
|
4378
|
-
if (!Object.keys(hooks).length)
|
|
4379
|
-
delete updated.hooks;
|
|
4380
|
-
fs.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
4381
|
-
fs.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
4382
|
-
`, "utf8");
|
|
4383
|
-
console.log(`hooks removed from ${settingsFile}`);
|
|
4384
|
-
} catch {
|
|
5499
|
+
if (!removeOurHookEntries(settingsFile, spec)) {
|
|
4385
5500
|
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
4386
5501
|
return 1;
|
|
4387
5502
|
}
|
|
5503
|
+
console.log(`hooks removed from ${settingsFile}`);
|
|
4388
5504
|
}
|
|
4389
|
-
const
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
console.log(`removed ${binary}`);
|
|
5505
|
+
for (const file of (0, hookRunner_1.removeHookRunner)(spec.binaryName)) {
|
|
5506
|
+
if (!file.endsWith(".node") && !file.endsWith(".no-node"))
|
|
5507
|
+
console.log(`removed ${file}`);
|
|
4393
5508
|
}
|
|
4394
5509
|
if ((0, credentials_1.readHostCredentials)(spec.host)) {
|
|
4395
5510
|
(0, credentials_1.removeHostCredentials)(spec.host);
|
|
@@ -4481,180 +5596,6 @@ var require_turnState = __commonJS({
|
|
|
4481
5596
|
}
|
|
4482
5597
|
});
|
|
4483
5598
|
|
|
4484
|
-
// ../packages/tool-kit/out/liveBus.js
|
|
4485
|
-
var require_liveBus = __commonJS({
|
|
4486
|
-
"../packages/tool-kit/out/liveBus.js"(exports) {
|
|
4487
|
-
"use strict";
|
|
4488
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4489
|
-
if (k2 === void 0) k2 = k;
|
|
4490
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4491
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4492
|
-
desc = { enumerable: true, get: function() {
|
|
4493
|
-
return m[k];
|
|
4494
|
-
} };
|
|
4495
|
-
}
|
|
4496
|
-
Object.defineProperty(o, k2, desc);
|
|
4497
|
-
} : function(o, m, k, k2) {
|
|
4498
|
-
if (k2 === void 0) k2 = k;
|
|
4499
|
-
o[k2] = m[k];
|
|
4500
|
-
});
|
|
4501
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4502
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4503
|
-
} : function(o, v) {
|
|
4504
|
-
o["default"] = v;
|
|
4505
|
-
});
|
|
4506
|
-
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4507
|
-
var ownKeys = function(o) {
|
|
4508
|
-
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4509
|
-
var ar = [];
|
|
4510
|
-
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4511
|
-
return ar;
|
|
4512
|
-
};
|
|
4513
|
-
return ownKeys(o);
|
|
4514
|
-
};
|
|
4515
|
-
return function(mod) {
|
|
4516
|
-
if (mod && mod.__esModule) return mod;
|
|
4517
|
-
var result = {};
|
|
4518
|
-
if (mod != null) {
|
|
4519
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4520
|
-
}
|
|
4521
|
-
__setModuleDefault(result, mod);
|
|
4522
|
-
return result;
|
|
4523
|
-
};
|
|
4524
|
-
}();
|
|
4525
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4526
|
-
exports.LIVE_BUS_BACKGROUND_TRUST_MS = void 0;
|
|
4527
|
-
exports.liveBusSocketCandidates = liveBusSocketCandidates;
|
|
4528
|
-
exports.liveBusSocketPath = liveBusSocketPath;
|
|
4529
|
-
exports.bucketPromptSize = bucketPromptSize;
|
|
4530
|
-
exports.emitLiveSignal = emitLiveSignal;
|
|
4531
|
-
var fs = __importStar(__require("fs"));
|
|
4532
|
-
var net = __importStar(__require("net"));
|
|
4533
|
-
var os = __importStar(__require("os"));
|
|
4534
|
-
var path = __importStar(__require("path"));
|
|
4535
|
-
var hookSet_1 = require_hookSet();
|
|
4536
|
-
var WRITE_TIMEOUT_MS = 50;
|
|
4537
|
-
exports.LIVE_BUS_BACKGROUND_TRUST_MS = 60 * 60 * 1e3;
|
|
4538
|
-
var APP_BUNDLE_ID = "one.ascenda.ascendaMissionControl";
|
|
4539
|
-
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4540
|
-
function liveBusSocketCandidates() {
|
|
4541
|
-
const override = process.env.ASCENDA_LIVE_BUS_SOCKET;
|
|
4542
|
-
if (override)
|
|
4543
|
-
return [override];
|
|
4544
|
-
const home = os.homedir();
|
|
4545
|
-
return [
|
|
4546
|
-
path.join(home, ".ascenda", "live.sock"),
|
|
4547
|
-
path.join(home, "Library", "Containers", APP_BUNDLE_ID, "Data", ".ascenda", "live.sock"),
|
|
4548
|
-
path.join(home, "Library", "Containers", SAVER_HOST_BUNDLE_ID, "Data", "l.sock")
|
|
4549
|
-
];
|
|
4550
|
-
}
|
|
4551
|
-
function existingSocketCandidates() {
|
|
4552
|
-
const candidates = liveBusSocketCandidates();
|
|
4553
|
-
if (process.env.ASCENDA_LIVE_BUS_SOCKET)
|
|
4554
|
-
return candidates;
|
|
4555
|
-
return candidates.filter((candidate) => {
|
|
4556
|
-
try {
|
|
4557
|
-
return fs.statSync(candidate).isSocket();
|
|
4558
|
-
} catch {
|
|
4559
|
-
return false;
|
|
4560
|
-
}
|
|
4561
|
-
});
|
|
4562
|
-
}
|
|
4563
|
-
function liveBusSocketPath() {
|
|
4564
|
-
return existingSocketCandidates()[0] ?? liveBusSocketCandidates()[0];
|
|
4565
|
-
}
|
|
4566
|
-
function bucketPromptSize(text) {
|
|
4567
|
-
const length = typeof text === "string" ? text.length : 0;
|
|
4568
|
-
if (length <= 280)
|
|
4569
|
-
return "s";
|
|
4570
|
-
if (length <= 2e3)
|
|
4571
|
-
return "m";
|
|
4572
|
-
if (length <= 8e3)
|
|
4573
|
-
return "l";
|
|
4574
|
-
return "xl";
|
|
4575
|
-
}
|
|
4576
|
-
var NOBODY_LISTENING = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOENT"]);
|
|
4577
|
-
function onTheWire(signal) {
|
|
4578
|
-
const out = { ...signal };
|
|
4579
|
-
if ("hookSet" in out && !(0, hookSet_1.isHookSet)(out.hookSet))
|
|
4580
|
-
delete out.hookSet;
|
|
4581
|
-
if ("viaPlugin" in out && out.viaPlugin !== true)
|
|
4582
|
-
delete out.viaPlugin;
|
|
4583
|
-
return out;
|
|
4584
|
-
}
|
|
4585
|
-
function emitLiveSignal(signal) {
|
|
4586
|
-
return new Promise((resolve) => {
|
|
4587
|
-
const candidates = existingSocketCandidates();
|
|
4588
|
-
if (candidates.length === 0) {
|
|
4589
|
-
resolve();
|
|
4590
|
-
return;
|
|
4591
|
-
}
|
|
4592
|
-
let settled = false;
|
|
4593
|
-
let socket;
|
|
4594
|
-
const drop = () => {
|
|
4595
|
-
try {
|
|
4596
|
-
socket?.destroy();
|
|
4597
|
-
} catch {
|
|
4598
|
-
}
|
|
4599
|
-
socket = void 0;
|
|
4600
|
-
};
|
|
4601
|
-
const done = () => {
|
|
4602
|
-
if (settled)
|
|
4603
|
-
return;
|
|
4604
|
-
settled = true;
|
|
4605
|
-
clearTimeout(timer);
|
|
4606
|
-
drop();
|
|
4607
|
-
resolve();
|
|
4608
|
-
};
|
|
4609
|
-
const timer = setTimeout(done, WRITE_TIMEOUT_MS);
|
|
4610
|
-
if (typeof timer.unref === "function")
|
|
4611
|
-
timer.unref();
|
|
4612
|
-
const tryFrom = (index) => {
|
|
4613
|
-
if (settled)
|
|
4614
|
-
return;
|
|
4615
|
-
if (index >= candidates.length) {
|
|
4616
|
-
done();
|
|
4617
|
-
return;
|
|
4618
|
-
}
|
|
4619
|
-
let attempt;
|
|
4620
|
-
try {
|
|
4621
|
-
attempt = net.createConnection(candidates[index]);
|
|
4622
|
-
} catch {
|
|
4623
|
-
tryFrom(index + 1);
|
|
4624
|
-
return;
|
|
4625
|
-
}
|
|
4626
|
-
socket = attempt;
|
|
4627
|
-
if (typeof attempt.unref === "function")
|
|
4628
|
-
attempt.unref();
|
|
4629
|
-
let connected = false;
|
|
4630
|
-
attempt.on("error", (error2) => {
|
|
4631
|
-
if (settled || socket !== attempt)
|
|
4632
|
-
return;
|
|
4633
|
-
if (!connected && error2.code && NOBODY_LISTENING.has(error2.code)) {
|
|
4634
|
-
drop();
|
|
4635
|
-
tryFrom(index + 1);
|
|
4636
|
-
return;
|
|
4637
|
-
}
|
|
4638
|
-
done();
|
|
4639
|
-
});
|
|
4640
|
-
attempt.on("connect", () => {
|
|
4641
|
-
if (settled || socket !== attempt)
|
|
4642
|
-
return;
|
|
4643
|
-
connected = true;
|
|
4644
|
-
try {
|
|
4645
|
-
attempt.write(`${JSON.stringify(onTheWire(signal))}
|
|
4646
|
-
`, done);
|
|
4647
|
-
} catch {
|
|
4648
|
-
done();
|
|
4649
|
-
}
|
|
4650
|
-
});
|
|
4651
|
-
};
|
|
4652
|
-
tryFrom(0);
|
|
4653
|
-
});
|
|
4654
|
-
}
|
|
4655
|
-
}
|
|
4656
|
-
});
|
|
4657
|
-
|
|
4658
5599
|
// ../packages/tool-kit/out/agentProcess.js
|
|
4659
5600
|
var require_agentProcess = __commonJS({
|
|
4660
5601
|
"../packages/tool-kit/out/agentProcess.js"(exports) {
|
|
@@ -4795,13 +5736,14 @@ var require_agentProcess = __commonJS({
|
|
|
4795
5736
|
});
|
|
4796
5737
|
|
|
4797
5738
|
// ../packages/tool-kit/out/index.js
|
|
4798
|
-
var
|
|
5739
|
+
var require_out3 = __commonJS({
|
|
4799
5740
|
"../packages/tool-kit/out/index.js"(exports) {
|
|
4800
5741
|
"use strict";
|
|
4801
5742
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4802
|
-
exports.
|
|
4803
|
-
exports.
|
|
4804
|
-
exports.
|
|
5743
|
+
exports.findStaleHookCommands = exports.cliAgentHookBinPath = exports.resolveContextHashes = exports.resolveCliAgentInstallationId = exports.loadCliAgentConfig = exports.deliverHookEvents = exports.MissingInstallationIdError = exports.DEFAULT_API_BASE_URL = exports.resolveEventLogPath = exports.resolveEventLog = exports.parseEventLogFlag = exports.expandUserPath = exports.describeEventLog = exports.defaultEventLogPath = exports.appendEventLog = exports.EVENT_LOG_OFF = exports.EVENT_LOG_ENV_VAR = exports.toAgentEvent = exports.buildEventPayload = exports.buildEventBody = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = exports.AscendaEventSender = exports.describeCollectorVersion = exports.UNRELEASED_COLLECTOR_VERSION = exports.COLLECTOR_VERSION = exports.mintIdempotencyKey = exports.looksLikeCorrection = exports.outcomeForHook = exports.inferOutcome = exports.getNestedNumber = exports.getNestedString = exports.getNested = exports.getNumber = exports.getString = exports.localHourAt = exports.utcOffsetMinutesAt = exports.BUSINESS_DAY = exports.isOutsideBusinessHours = exports.isAfterHours = exports.bucketDurationMs = exports.bucketLinesChanged = exports.classifyModelClass = exports.autonomyBand = exports.invitesDebrief = exports.classifyWorkMilestone = exports.isReworkGitAction = exports.classifyGitAction = exports.isVerificationCommand = exports.classifyCommand = void 0;
|
|
5744
|
+
exports.readOrCreateMachineSalt = exports.machineSaltFilePath = exports.fixedTimeProvider = exports.systemTimeProvider = exports.enforceOutboxBounds = exports.claimOutbox = exports.readOutboxSummary = exports.appendToOutbox = exports.defaultOutboxFilePath = exports.outboxDrainEnabled = exports.DEFAULT_OUTBOX_DRAIN_BATCH_SIZE = exports.DEFAULT_OUTBOX_MAX_AGE_MS = exports.DEFAULT_OUTBOX_MAX_ENTRIES = exports.OUTBOX_DRAIN_ENV_VAR = exports.recordOutboxDiscard = exports.unresolvedToolInstallationId = exports.unresolvedStateFilePath = exports.markFailureNotified = exports.shouldAnnounceFailure = exports.recordSendOutcome = exports.readCollectorState = exports.defaultStateFilePath = exports.tokenExpiryFilePath = exports.readTokenFile = exports.readTokenExpiry = exports.persistEventWriteToken = exports.listPersistedToolInstallationIds = exports.defaultTokenFilePath = exports.ascendaHome = exports.EVENT_TOKEN_TTL_MS = exports.recordTurnStart = exports.consumeTurnDurationMs = exports.writeTopLevelCredentials = exports.writeMachineCredentials = exports.writeEventLogSetting = exports.writeHostCredentials = exports.removeHostCredentials = exports.readMachineCredentials = exports.readHostCredentials = exports.isLocalOnlyHostInstall = exports.credentialsFilePath = exports.renderSetupDisclosure = exports.REFUSALS = exports.FREE_TEXT_KEYS = exports.FAMILY_SENTENCES = exports.ALWAYS_SENT = exports.writeHookSettings = exports.runCliAgentSetup = exports.registeredHookSets = exports.isCliAgentManagementCommand = void 0;
|
|
5745
|
+
exports.hookSetArgument = exports.describeHookSetChanges = exports.UNVERSIONED_HOOK_SET = exports.HOOK_SET_FLAG = exports.liveSignalDoctorLines = exports.doctorRow = exports.DOCTOR_VALUE_COLUMN = exports.tidyHomePath = exports.stampLastHook = exports.resolveHookNode = exports.removeHookRunner = exports.readLastHook = exports.lastHookPath = exports.installHookRunner = exports.hookRunnerPaths = exports.hookRunnerCommand = exports.hookLauncherScript = exports.describeAge = exports.terminalStyle = exports.colourEnabled = exports.SAVER_REPLAY_WINDOW_MS = exports.saverSupportDir = exports.saverStatusDir = exports.saverReplayPath = exports.saverContainerDir = exports.readSaverStatuses = exports.probeSocket = exports.heldForSaver = exports.holdForSaver = exports.LIVE_BUS_BACKGROUND_TRUST_MS = exports.liveBusSocketCandidates = exports.liveBusSocketPath = exports.bucketPromptSize = exports.deliverLine = exports.emitLiveSignal = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = exports.readForgeFullName = exports.parseForgeFullName = exports.forgeProjectHash = exports.workContextRegistryFilePath = exports.readWorkContextRegistry = exports.recordWorkContextAlias = exports.recordWorkContext = exports.readBranchName = exports.normalizeBranchName = exports.deriveBranchHashForCwd = exports.deriveBranchHash = exports.deriveWorkContext = exports.hashWithMachineSalt = void 0;
|
|
5746
|
+
exports.runStudyJoin = exports.studyNoticeStatus = exports.runStudyObjection = exports.renderStudyNotices = exports.NOTICED_PURPOSES = exports.renderInitiatives = exports.initiativesStatusLines = exports.INITIATIVE_COPY = exports.startStudyJoin = exports.setStudyObjection = exports.markStudyNoticeShown = exports.readStudyNotices = exports.readInitiatives = exports.isRetryableStatus = exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = exports.getStudyJoinStatus = exports.getPairingStatus = exports.createPairingSession = exports.AscendaApiError = exports.scriptMarkerIn = exports.psLookup = exports.psArgsLookup = exports.livePidFields = exports.findAgentProcess = exports.findAgentPid = exports.AGENT_PROCESS = exports.readViaPlugin = exports.readHookSet = exports.isHookSet = exports.hookSetOfCommand = exports.hookSetChanges = void 0;
|
|
4805
5747
|
var commandClassifier_1 = require_commandClassifier();
|
|
4806
5748
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
4807
5749
|
return commandClassifier_1.classifyCommand;
|
|
@@ -4902,19 +5844,41 @@ var require_out2 = __commonJS({
|
|
|
4902
5844
|
Object.defineProperty(exports, "TOKEN_RENEW_LEAD_MS", { enumerable: true, get: function() {
|
|
4903
5845
|
return eventSender_1.TOKEN_RENEW_LEAD_MS;
|
|
4904
5846
|
} });
|
|
5847
|
+
Object.defineProperty(exports, "buildEventBody", { enumerable: true, get: function() {
|
|
5848
|
+
return eventSender_1.buildEventBody;
|
|
5849
|
+
} });
|
|
4905
5850
|
Object.defineProperty(exports, "buildEventPayload", { enumerable: true, get: function() {
|
|
4906
5851
|
return eventSender_1.buildEventPayload;
|
|
4907
5852
|
} });
|
|
5853
|
+
var agentEvent_1 = require_agentEvent();
|
|
5854
|
+
Object.defineProperty(exports, "toAgentEvent", { enumerable: true, get: function() {
|
|
5855
|
+
return agentEvent_1.toAgentEvent;
|
|
5856
|
+
} });
|
|
4908
5857
|
var eventLog_1 = require_eventLog();
|
|
4909
5858
|
Object.defineProperty(exports, "EVENT_LOG_ENV_VAR", { enumerable: true, get: function() {
|
|
4910
5859
|
return eventLog_1.EVENT_LOG_ENV_VAR;
|
|
4911
5860
|
} });
|
|
5861
|
+
Object.defineProperty(exports, "EVENT_LOG_OFF", { enumerable: true, get: function() {
|
|
5862
|
+
return eventLog_1.EVENT_LOG_OFF;
|
|
5863
|
+
} });
|
|
4912
5864
|
Object.defineProperty(exports, "appendEventLog", { enumerable: true, get: function() {
|
|
4913
5865
|
return eventLog_1.appendEventLog;
|
|
4914
5866
|
} });
|
|
5867
|
+
Object.defineProperty(exports, "defaultEventLogPath", { enumerable: true, get: function() {
|
|
5868
|
+
return eventLog_1.defaultEventLogPath;
|
|
5869
|
+
} });
|
|
5870
|
+
Object.defineProperty(exports, "describeEventLog", { enumerable: true, get: function() {
|
|
5871
|
+
return eventLog_1.describeEventLog;
|
|
5872
|
+
} });
|
|
4915
5873
|
Object.defineProperty(exports, "expandUserPath", { enumerable: true, get: function() {
|
|
4916
5874
|
return eventLog_1.expandUserPath;
|
|
4917
5875
|
} });
|
|
5876
|
+
Object.defineProperty(exports, "parseEventLogFlag", { enumerable: true, get: function() {
|
|
5877
|
+
return eventLog_1.parseEventLogFlag;
|
|
5878
|
+
} });
|
|
5879
|
+
Object.defineProperty(exports, "resolveEventLog", { enumerable: true, get: function() {
|
|
5880
|
+
return eventLog_1.resolveEventLog;
|
|
5881
|
+
} });
|
|
4918
5882
|
Object.defineProperty(exports, "resolveEventLogPath", { enumerable: true, get: function() {
|
|
4919
5883
|
return eventLog_1.resolveEventLogPath;
|
|
4920
5884
|
} });
|
|
@@ -4991,6 +5955,9 @@ var require_out2 = __commonJS({
|
|
|
4991
5955
|
Object.defineProperty(exports, "writeHostCredentials", { enumerable: true, get: function() {
|
|
4992
5956
|
return credentials_1.writeHostCredentials;
|
|
4993
5957
|
} });
|
|
5958
|
+
Object.defineProperty(exports, "writeEventLogSetting", { enumerable: true, get: function() {
|
|
5959
|
+
return credentials_1.writeEventLogSetting;
|
|
5960
|
+
} });
|
|
4994
5961
|
Object.defineProperty(exports, "writeMachineCredentials", { enumerable: true, get: function() {
|
|
4995
5962
|
return credentials_1.writeMachineCredentials;
|
|
4996
5963
|
} });
|
|
@@ -5151,6 +6118,9 @@ var require_out2 = __commonJS({
|
|
|
5151
6118
|
Object.defineProperty(exports, "emitLiveSignal", { enumerable: true, get: function() {
|
|
5152
6119
|
return liveBus_1.emitLiveSignal;
|
|
5153
6120
|
} });
|
|
6121
|
+
Object.defineProperty(exports, "deliverLine", { enumerable: true, get: function() {
|
|
6122
|
+
return liveBus_1.deliverLine;
|
|
6123
|
+
} });
|
|
5154
6124
|
Object.defineProperty(exports, "bucketPromptSize", { enumerable: true, get: function() {
|
|
5155
6125
|
return liveBus_1.bucketPromptSize;
|
|
5156
6126
|
} });
|
|
@@ -5163,6 +6133,85 @@ var require_out2 = __commonJS({
|
|
|
5163
6133
|
Object.defineProperty(exports, "LIVE_BUS_BACKGROUND_TRUST_MS", { enumerable: true, get: function() {
|
|
5164
6134
|
return liveBus_1.LIVE_BUS_BACKGROUND_TRUST_MS;
|
|
5165
6135
|
} });
|
|
6136
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
6137
|
+
Object.defineProperty(exports, "holdForSaver", { enumerable: true, get: function() {
|
|
6138
|
+
return saverHandoff_1.holdForSaver;
|
|
6139
|
+
} });
|
|
6140
|
+
Object.defineProperty(exports, "heldForSaver", { enumerable: true, get: function() {
|
|
6141
|
+
return saverHandoff_1.heldForSaver;
|
|
6142
|
+
} });
|
|
6143
|
+
Object.defineProperty(exports, "probeSocket", { enumerable: true, get: function() {
|
|
6144
|
+
return saverHandoff_1.probeSocket;
|
|
6145
|
+
} });
|
|
6146
|
+
Object.defineProperty(exports, "readSaverStatuses", { enumerable: true, get: function() {
|
|
6147
|
+
return saverHandoff_1.readSaverStatuses;
|
|
6148
|
+
} });
|
|
6149
|
+
Object.defineProperty(exports, "saverContainerDir", { enumerable: true, get: function() {
|
|
6150
|
+
return saverHandoff_1.saverContainerDir;
|
|
6151
|
+
} });
|
|
6152
|
+
Object.defineProperty(exports, "saverReplayPath", { enumerable: true, get: function() {
|
|
6153
|
+
return saverHandoff_1.saverReplayPath;
|
|
6154
|
+
} });
|
|
6155
|
+
Object.defineProperty(exports, "saverStatusDir", { enumerable: true, get: function() {
|
|
6156
|
+
return saverHandoff_1.saverStatusDir;
|
|
6157
|
+
} });
|
|
6158
|
+
Object.defineProperty(exports, "saverSupportDir", { enumerable: true, get: function() {
|
|
6159
|
+
return saverHandoff_1.saverSupportDir;
|
|
6160
|
+
} });
|
|
6161
|
+
Object.defineProperty(exports, "SAVER_REPLAY_WINDOW_MS", { enumerable: true, get: function() {
|
|
6162
|
+
return saverHandoff_1.SAVER_REPLAY_WINDOW_MS;
|
|
6163
|
+
} });
|
|
6164
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
6165
|
+
Object.defineProperty(exports, "colourEnabled", { enumerable: true, get: function() {
|
|
6166
|
+
return terminalStyle_1.colourEnabled;
|
|
6167
|
+
} });
|
|
6168
|
+
Object.defineProperty(exports, "terminalStyle", { enumerable: true, get: function() {
|
|
6169
|
+
return terminalStyle_1.terminalStyle;
|
|
6170
|
+
} });
|
|
6171
|
+
var hookRunner_1 = require_hookRunner();
|
|
6172
|
+
Object.defineProperty(exports, "describeAge", { enumerable: true, get: function() {
|
|
6173
|
+
return hookRunner_1.describeAge;
|
|
6174
|
+
} });
|
|
6175
|
+
Object.defineProperty(exports, "hookLauncherScript", { enumerable: true, get: function() {
|
|
6176
|
+
return hookRunner_1.hookLauncherScript;
|
|
6177
|
+
} });
|
|
6178
|
+
Object.defineProperty(exports, "hookRunnerCommand", { enumerable: true, get: function() {
|
|
6179
|
+
return hookRunner_1.hookRunnerCommand;
|
|
6180
|
+
} });
|
|
6181
|
+
Object.defineProperty(exports, "hookRunnerPaths", { enumerable: true, get: function() {
|
|
6182
|
+
return hookRunner_1.hookRunnerPaths;
|
|
6183
|
+
} });
|
|
6184
|
+
Object.defineProperty(exports, "installHookRunner", { enumerable: true, get: function() {
|
|
6185
|
+
return hookRunner_1.installHookRunner;
|
|
6186
|
+
} });
|
|
6187
|
+
Object.defineProperty(exports, "lastHookPath", { enumerable: true, get: function() {
|
|
6188
|
+
return hookRunner_1.lastHookPath;
|
|
6189
|
+
} });
|
|
6190
|
+
Object.defineProperty(exports, "readLastHook", { enumerable: true, get: function() {
|
|
6191
|
+
return hookRunner_1.readLastHook;
|
|
6192
|
+
} });
|
|
6193
|
+
Object.defineProperty(exports, "removeHookRunner", { enumerable: true, get: function() {
|
|
6194
|
+
return hookRunner_1.removeHookRunner;
|
|
6195
|
+
} });
|
|
6196
|
+
Object.defineProperty(exports, "resolveHookNode", { enumerable: true, get: function() {
|
|
6197
|
+
return hookRunner_1.resolveHookNode;
|
|
6198
|
+
} });
|
|
6199
|
+
Object.defineProperty(exports, "stampLastHook", { enumerable: true, get: function() {
|
|
6200
|
+
return hookRunner_1.stampLastHook;
|
|
6201
|
+
} });
|
|
6202
|
+
Object.defineProperty(exports, "tidyHomePath", { enumerable: true, get: function() {
|
|
6203
|
+
return hookRunner_1.tidyHomePath;
|
|
6204
|
+
} });
|
|
6205
|
+
var liveSignalDoctor_1 = require_liveSignalDoctor();
|
|
6206
|
+
Object.defineProperty(exports, "DOCTOR_VALUE_COLUMN", { enumerable: true, get: function() {
|
|
6207
|
+
return liveSignalDoctor_1.DOCTOR_VALUE_COLUMN;
|
|
6208
|
+
} });
|
|
6209
|
+
Object.defineProperty(exports, "doctorRow", { enumerable: true, get: function() {
|
|
6210
|
+
return liveSignalDoctor_1.doctorRow;
|
|
6211
|
+
} });
|
|
6212
|
+
Object.defineProperty(exports, "liveSignalDoctorLines", { enumerable: true, get: function() {
|
|
6213
|
+
return liveSignalDoctor_1.liveSignalDoctorLines;
|
|
6214
|
+
} });
|
|
5166
6215
|
var hookSet_1 = require_hookSet();
|
|
5167
6216
|
Object.defineProperty(exports, "HOOK_SET_FLAG", { enumerable: true, get: function() {
|
|
5168
6217
|
return hookSet_1.HOOK_SET_FLAG;
|
|
@@ -18286,7 +19335,7 @@ var StdioServerTransport = class {
|
|
|
18286
19335
|
};
|
|
18287
19336
|
|
|
18288
19337
|
// src/config.ts
|
|
18289
|
-
var import_tool_kit = __toESM(
|
|
19338
|
+
var import_tool_kit = __toESM(require_out3(), 1);
|
|
18290
19339
|
import { randomUUID } from "node:crypto";
|
|
18291
19340
|
function loadConfigFromEnv() {
|
|
18292
19341
|
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
@@ -26415,7 +27464,7 @@ var EMPTY_COMPLETION_RESULT = {
|
|
|
26415
27464
|
};
|
|
26416
27465
|
|
|
26417
27466
|
// src/server.ts
|
|
26418
|
-
var import_tool_kit2 = __toESM(
|
|
27467
|
+
var import_tool_kit2 = __toESM(require_out3(), 1);
|
|
26419
27468
|
var import_tool_contract = __toESM(require_out(), 1);
|
|
26420
27469
|
var RESERVED_METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
26421
27470
|
"skillVersion",
|