@ascenda-one/claude-code-hooks 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/NOTICE +6 -0
- package/README.md +46 -30
- package/dist/cli.js +2257 -1008
- package/dist/cli.js.map +1 -1
- package/dist/hookHealth.js +21 -0
- package/dist/hookHealth.js.map +1 -0
- package/dist/launcher.js +14 -0
- package/dist/launcher.js.map +1 -0
- package/dist/liveDoctor.js +27 -0
- package/dist/liveDoctor.js.map +1 -0
- package/dist/liveEvent.js +8 -0
- package/dist/liveEvent.js.map +1 -1
- package/dist/paths.js +30 -1
- package/dist/paths.js.map +1 -1
- package/dist/setup.js +241 -90
- package/dist/setup.js.map +1 -1
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -636,9 +636,11 @@ var require_out = __commonJS({
|
|
|
636
636
|
"../packages/tool-contract/out/index.js"(exports) {
|
|
637
637
|
"use strict";
|
|
638
638
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
639
|
-
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;
|
|
639
|
+
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;
|
|
640
640
|
exports.combineDisjointHalves = combineDisjointHalves;
|
|
641
641
|
exports.requireComparableQuantities = requireComparableQuantities;
|
|
642
|
+
exports.joinEventPayload = joinEventPayload;
|
|
643
|
+
exports.splitEventPayload = splitEventPayload;
|
|
642
644
|
exports.ASCENDA_TELEMETRY_SOURCES = [
|
|
643
645
|
"vscode_extension",
|
|
644
646
|
"cursor_mcp",
|
|
@@ -790,6 +792,24 @@ var require_out = __commonJS({
|
|
|
790
792
|
"importSchema",
|
|
791
793
|
"collectorVersion"
|
|
792
794
|
];
|
|
795
|
+
exports.DELIVERY_ENVELOPE_KEYS = ["toolInstallationId", "idempotencyKey"];
|
|
796
|
+
function joinEventPayload(envelope, body) {
|
|
797
|
+
const payload = { toolInstallationId: envelope.toolInstallationId };
|
|
798
|
+
for (const [key, value] of Object.entries(body)) {
|
|
799
|
+
payload[key] = value;
|
|
800
|
+
if (key === "occurredAt" && envelope.idempotencyKey !== void 0) {
|
|
801
|
+
payload.idempotencyKey = envelope.idempotencyKey;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return payload;
|
|
805
|
+
}
|
|
806
|
+
function splitEventPayload(payload) {
|
|
807
|
+
const { toolInstallationId, idempotencyKey, ...body } = payload;
|
|
808
|
+
const envelope = { toolInstallationId };
|
|
809
|
+
if (idempotencyKey !== void 0)
|
|
810
|
+
envelope.idempotencyKey = idempotencyKey;
|
|
811
|
+
return { envelope, body };
|
|
812
|
+
}
|
|
793
813
|
exports.IDEMPOTENCY_KEY_MAX_LENGTH = 128;
|
|
794
814
|
exports.TOOL_EVENT_DELIVERED_STATUSES = ["accepted", "duplicate"];
|
|
795
815
|
exports.EVENT_WORKLOAD_CATEGORY = {
|
|
@@ -968,16 +988,125 @@ var require_collectorVersion = __commonJS({
|
|
|
968
988
|
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
969
989
|
exports.describeCollectorVersion = describeCollectorVersion2;
|
|
970
990
|
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
971
|
-
exports.COLLECTOR_VERSION = "0.1.
|
|
991
|
+
exports.COLLECTOR_VERSION = "0.1.35" ? "0.1.35" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
972
992
|
function describeCollectorVersion2(version = exports.COLLECTOR_VERSION) {
|
|
973
993
|
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
974
994
|
}
|
|
975
995
|
}
|
|
976
996
|
});
|
|
977
997
|
|
|
978
|
-
// ../packages/
|
|
979
|
-
var
|
|
980
|
-
"../packages/
|
|
998
|
+
// ../packages/agent-events/out/index.js
|
|
999
|
+
var require_out2 = __commonJS({
|
|
1000
|
+
"../packages/agent-events/out/index.js"(exports) {
|
|
1001
|
+
"use strict";
|
|
1002
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1003
|
+
exports.KNOWN_AGENTS = exports.AGENT_EVENT_KINDS = exports.AGENT_EVENT_SCHEMA = void 0;
|
|
1004
|
+
exports.isAgentEventV0 = isAgentEventV0;
|
|
1005
|
+
exports.parseEventLogLine = parseEventLogLine;
|
|
1006
|
+
exports.normaliseKind = normaliseKind;
|
|
1007
|
+
exports.AGENT_EVENT_SCHEMA = "agent-event/v0";
|
|
1008
|
+
exports.AGENT_EVENT_KINDS = [
|
|
1009
|
+
"session.started",
|
|
1010
|
+
"session.ended",
|
|
1011
|
+
"prompt.submitted",
|
|
1012
|
+
"tool.started",
|
|
1013
|
+
"tool.completed",
|
|
1014
|
+
"tool.failed",
|
|
1015
|
+
"turn.completed",
|
|
1016
|
+
"agent.waiting",
|
|
1017
|
+
"context.compacted",
|
|
1018
|
+
"subagent.started",
|
|
1019
|
+
"subagent.stopped",
|
|
1020
|
+
"other"
|
|
1021
|
+
];
|
|
1022
|
+
exports.KNOWN_AGENTS = ["claude_code", "codex", "cursor", "gemini_cli", "windsurf", "vscode"];
|
|
1023
|
+
function isAgentEventV0(value) {
|
|
1024
|
+
if (!value || typeof value !== "object")
|
|
1025
|
+
return false;
|
|
1026
|
+
const e = value;
|
|
1027
|
+
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";
|
|
1028
|
+
}
|
|
1029
|
+
function parseEventLogLine(line) {
|
|
1030
|
+
if (!line.trim())
|
|
1031
|
+
return void 0;
|
|
1032
|
+
try {
|
|
1033
|
+
const parsed = JSON.parse(line);
|
|
1034
|
+
return isAgentEventV0(parsed?.event) ? parsed.event : void 0;
|
|
1035
|
+
} catch {
|
|
1036
|
+
return void 0;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
function normaliseKind(kind) {
|
|
1040
|
+
return exports.AGENT_EVENT_KINDS.includes(kind) ? kind : "other";
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
// ../packages/tool-kit/out/agentEvent.js
|
|
1046
|
+
var require_agentEvent = __commonJS({
|
|
1047
|
+
"../packages/tool-kit/out/agentEvent.js"(exports) {
|
|
1048
|
+
"use strict";
|
|
1049
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1050
|
+
exports.toAgentEvent = toAgentEvent;
|
|
1051
|
+
var agent_events_1 = require_out2();
|
|
1052
|
+
var KIND_BY_TYPE = {
|
|
1053
|
+
create_focus_session: "session.started",
|
|
1054
|
+
recovery_offline_period: "session.ended",
|
|
1055
|
+
ai_prompt_submitted: "prompt.submitted",
|
|
1056
|
+
ai_tool_call_started: "tool.started",
|
|
1057
|
+
ai_tool_call_completed: "tool.completed",
|
|
1058
|
+
ai_file_write: "tool.completed",
|
|
1059
|
+
ai_file_edit: "tool.completed",
|
|
1060
|
+
editor_verification_activity: "tool.completed",
|
|
1061
|
+
ai_tool_call_failed: "tool.failed",
|
|
1062
|
+
compile_error: "tool.failed",
|
|
1063
|
+
tool_failure: "tool.failed",
|
|
1064
|
+
ai_turn_completed: "turn.completed",
|
|
1065
|
+
supervision_interruption: "agent.waiting",
|
|
1066
|
+
context_compression_manual: "context.compacted",
|
|
1067
|
+
context_compression_auto: "context.compacted",
|
|
1068
|
+
subagent_started: "subagent.started",
|
|
1069
|
+
subagent_stopped: "subagent.stopped"
|
|
1070
|
+
};
|
|
1071
|
+
function agentOf(payload) {
|
|
1072
|
+
const host = stringField(payload.metadata?.host);
|
|
1073
|
+
if (host)
|
|
1074
|
+
return host;
|
|
1075
|
+
return payload.source === "vscode_extension" ? "vscode" : payload.source;
|
|
1076
|
+
}
|
|
1077
|
+
function stringField(value) {
|
|
1078
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1079
|
+
}
|
|
1080
|
+
function toAgentEvent(payload) {
|
|
1081
|
+
const metadata = payload.metadata ?? {};
|
|
1082
|
+
const kind = KIND_BY_TYPE[payload.eventType] ?? "other";
|
|
1083
|
+
const tool = kind.startsWith("tool.") ? stringField(metadata.toolName) : void 0;
|
|
1084
|
+
const outcome = stringField(metadata.outcome);
|
|
1085
|
+
return {
|
|
1086
|
+
schema: agent_events_1.AGENT_EVENT_SCHEMA,
|
|
1087
|
+
id: payload.idempotencyKey ?? `${payload.toolInstallationId}:${payload.occurredAt}:${payload.eventType}`,
|
|
1088
|
+
time: payload.occurredAt,
|
|
1089
|
+
// `+ 0` turns the -0 a UTC machine computes into 0, which is what JSON
|
|
1090
|
+
// writes anyway; without it the event in memory and the one on disk differ.
|
|
1091
|
+
...typeof payload.utcOffsetMinutes === "number" ? { utcOffsetMinutes: payload.utcOffsetMinutes + 0 } : {},
|
|
1092
|
+
agent: agentOf(payload),
|
|
1093
|
+
kind,
|
|
1094
|
+
...stringField(payload.sessionId) ? { sessionId: payload.sessionId } : {},
|
|
1095
|
+
...stringField(metadata.subagentId) ? { subagentId: metadata.subagentId } : {},
|
|
1096
|
+
...tool ? { tool } : {},
|
|
1097
|
+
...outcome && outcome !== "unknown" ? { outcome } : {},
|
|
1098
|
+
...stringField(metadata.durationBucket) ? { durationBucket: metadata.durationBucket } : {},
|
|
1099
|
+
...stringField(payload.projectHash) ? { projectHash: payload.projectHash } : {},
|
|
1100
|
+
...stringField(metadata.collectorVersion) ? { collectorVersion: metadata.collectorVersion } : {},
|
|
1101
|
+
sourceType: payload.eventType
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
// ../packages/tool-kit/out/tokenStore.js
|
|
1108
|
+
var require_tokenStore = __commonJS({
|
|
1109
|
+
"../packages/tool-kit/out/tokenStore.js"(exports) {
|
|
981
1110
|
"use strict";
|
|
982
1111
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
983
1112
|
if (k2 === void 0) k2 = k;
|
|
@@ -1017,306 +1146,232 @@ var require_eventLog = __commonJS({
|
|
|
1017
1146
|
};
|
|
1018
1147
|
}();
|
|
1019
1148
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1020
|
-
exports.
|
|
1021
|
-
exports.
|
|
1022
|
-
exports.
|
|
1023
|
-
exports.
|
|
1149
|
+
exports.EVENT_TOKEN_TTL_MS = void 0;
|
|
1150
|
+
exports.ascendaHome = ascendaHome3;
|
|
1151
|
+
exports.defaultTokenFilePath = defaultTokenFilePath4;
|
|
1152
|
+
exports.tokenExpiryFilePath = tokenExpiryFilePath;
|
|
1153
|
+
exports.persistEventWriteToken = persistEventWriteToken4;
|
|
1154
|
+
exports.readTokenExpiry = readTokenExpiry;
|
|
1155
|
+
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds2;
|
|
1156
|
+
exports.readTokenFile = readTokenFile3;
|
|
1157
|
+
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1024
1158
|
var fs5 = __importStar(__require("fs"));
|
|
1025
|
-
var
|
|
1159
|
+
var os5 = __importStar(__require("os"));
|
|
1026
1160
|
var path4 = __importStar(__require("path"));
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
function expandUserPath(configured) {
|
|
1030
|
-
const value = configured?.trim();
|
|
1031
|
-
if (!value)
|
|
1032
|
-
return void 0;
|
|
1033
|
-
if (value === "~")
|
|
1034
|
-
return os3.homedir();
|
|
1035
|
-
if (value.startsWith("~/"))
|
|
1036
|
-
return path4.join(os3.homedir(), value.slice(2));
|
|
1037
|
-
return path4.resolve(value);
|
|
1161
|
+
function ascendaHome3(home = os5.homedir()) {
|
|
1162
|
+
return process.env.ASCENDA_HOME ?? path4.join(home, ".ascenda");
|
|
1038
1163
|
}
|
|
1039
|
-
function
|
|
1040
|
-
return
|
|
1164
|
+
function defaultTokenFilePath4(toolInstallationId) {
|
|
1165
|
+
return path4.join(ascendaHome3(), "tokens", sanitizeFilePart(toolInstallationId));
|
|
1041
1166
|
}
|
|
1042
|
-
function
|
|
1043
|
-
|
|
1044
|
-
rotateIfLarge(logFilePath);
|
|
1045
|
-
const dir = path4.dirname(logFilePath);
|
|
1046
|
-
fs5.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1047
|
-
fs5.appendFileSync(logFilePath, `${JSON.stringify(entry)}
|
|
1048
|
-
`, { encoding: "utf8", mode: 384 });
|
|
1049
|
-
if (process.platform !== "win32")
|
|
1050
|
-
fs5.chmodSync(logFilePath, 384);
|
|
1051
|
-
} catch {
|
|
1052
|
-
}
|
|
1167
|
+
function tokenExpiryFilePath(tokenFilePath) {
|
|
1168
|
+
return path4.join(path4.dirname(tokenFilePath), "expiry", path4.basename(tokenFilePath));
|
|
1053
1169
|
}
|
|
1054
|
-
function
|
|
1170
|
+
function persistEventWriteToken4(tokenFilePath, token, expiresAt) {
|
|
1171
|
+
const dir = path4.dirname(tokenFilePath);
|
|
1172
|
+
fs5.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1173
|
+
fs5.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
1174
|
+
if (process.platform !== "win32") {
|
|
1175
|
+
fs5.chmodSync(dir, 448);
|
|
1176
|
+
fs5.chmodSync(tokenFilePath, 384);
|
|
1177
|
+
}
|
|
1178
|
+
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1055
1179
|
try {
|
|
1056
|
-
if (
|
|
1057
|
-
|
|
1058
|
-
|
|
1180
|
+
if (expiresAt && Number.isFinite(Date.parse(expiresAt))) {
|
|
1181
|
+
fs5.mkdirSync(path4.dirname(expiryFile), { recursive: true, mode: 448 });
|
|
1182
|
+
fs5.writeFileSync(expiryFile, expiresAt, { encoding: "utf8", mode: 384 });
|
|
1183
|
+
} else {
|
|
1184
|
+
fs5.rmSync(expiryFile, { force: true });
|
|
1185
|
+
}
|
|
1059
1186
|
} catch {
|
|
1060
1187
|
}
|
|
1061
1188
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
// ../packages/tool-kit/out/http.js
|
|
1066
|
-
var require_http = __commonJS({
|
|
1067
|
-
"../packages/tool-kit/out/http.js"(exports) {
|
|
1068
|
-
"use strict";
|
|
1069
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1070
|
-
exports.AscendaApiError = void 0;
|
|
1071
|
-
exports.createPairingSession = createPairingSession3;
|
|
1072
|
-
exports.getPairingStatus = getPairingStatus3;
|
|
1073
|
-
exports.startStudyJoin = startStudyJoin;
|
|
1074
|
-
exports.getStudyJoinStatus = getStudyJoinStatus;
|
|
1075
|
-
exports.readInitiatives = readInitiatives;
|
|
1076
|
-
exports.readStudyNotices = readStudyNotices;
|
|
1077
|
-
exports.setStudyObjection = setStudyObjection;
|
|
1078
|
-
exports.markStudyNoticeShown = markStudyNoticeShown;
|
|
1079
|
-
exports.renewToolToken = renewToolToken;
|
|
1080
|
-
exports.isRetryableStatus = isRetryableStatus;
|
|
1081
|
-
exports.postToolEvent = postToolEvent;
|
|
1082
|
-
exports.postToolEventsBatch = postToolEventsBatch;
|
|
1083
|
-
exports.parseIngestResponse = parseIngestResponse;
|
|
1084
|
-
var tool_contract_1 = require_out();
|
|
1085
|
-
var AscendaApiError2 = class extends Error {
|
|
1086
|
-
status;
|
|
1087
|
-
errorCode;
|
|
1088
|
-
constructor(status, errorCode, body) {
|
|
1089
|
-
super(body ?? `Ascenda API error ${status}`);
|
|
1090
|
-
this.status = status;
|
|
1091
|
-
this.errorCode = errorCode;
|
|
1092
|
-
this.name = "AscendaApiError";
|
|
1093
|
-
}
|
|
1094
|
-
};
|
|
1095
|
-
exports.AscendaApiError = AscendaApiError2;
|
|
1096
|
-
async function createPairingSession3(apiBaseUrl, toolInstallationId, toolType, displayName) {
|
|
1097
|
-
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions`, {
|
|
1098
|
-
method: "POST",
|
|
1099
|
-
headers: { "Content-Type": "application/json" },
|
|
1100
|
-
body: JSON.stringify({ toolInstallationId, toolType, displayName })
|
|
1101
|
-
});
|
|
1102
|
-
if (!response.ok)
|
|
1103
|
-
throw new AscendaApiError2(response.status, void 0, await response.text());
|
|
1104
|
-
return await response.json();
|
|
1105
|
-
}
|
|
1106
|
-
async function getPairingStatus3(apiBaseUrl, pairingSessionId) {
|
|
1107
|
-
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions/${encodeURIComponent(pairingSessionId)}/status`, {
|
|
1108
|
-
method: "GET",
|
|
1109
|
-
headers: { Accept: "application/json" }
|
|
1110
|
-
});
|
|
1111
|
-
if (!response.ok)
|
|
1112
|
-
throw new AscendaApiError2(response.status, void 0, await response.text());
|
|
1113
|
-
return await response.json();
|
|
1114
|
-
}
|
|
1115
|
-
async function startStudyJoin(apiBaseUrl, eventWriteToken, joinCode, mode) {
|
|
1116
|
-
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions`, {
|
|
1117
|
-
method: "POST",
|
|
1118
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1119
|
-
body: JSON.stringify({ joinCode, mode })
|
|
1120
|
-
});
|
|
1121
|
-
if (!response.ok)
|
|
1122
|
-
throw await apiError(response);
|
|
1123
|
-
return await response.json();
|
|
1124
|
-
}
|
|
1125
|
-
async function getStudyJoinStatus(apiBaseUrl, eventWriteToken, joinSessionId) {
|
|
1126
|
-
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions/${encodeURIComponent(joinSessionId)}/status`, {
|
|
1127
|
-
method: "GET",
|
|
1128
|
-
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` }
|
|
1129
|
-
});
|
|
1130
|
-
if (!response.ok)
|
|
1131
|
-
throw await apiError(response);
|
|
1132
|
-
return await response.json();
|
|
1133
|
-
}
|
|
1134
|
-
async function readInitiatives(apiBaseUrl, eventWriteToken, signal) {
|
|
1135
|
-
let response;
|
|
1189
|
+
exports.EVENT_TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1190
|
+
function readTokenExpiry(tokenFilePath) {
|
|
1136
1191
|
try {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
});
|
|
1142
|
-
} catch (error) {
|
|
1143
|
-
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1192
|
+
const recorded = Date.parse(fs5.readFileSync(tokenExpiryFilePath(tokenFilePath), "utf8").trim());
|
|
1193
|
+
if (Number.isFinite(recorded))
|
|
1194
|
+
return recorded;
|
|
1195
|
+
} catch {
|
|
1144
1196
|
}
|
|
1145
|
-
if (response.status === 401)
|
|
1146
|
-
return { kind: "rejected", httpStatus: 401 };
|
|
1147
|
-
if (!response.ok)
|
|
1148
|
-
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1149
|
-
let body;
|
|
1150
1197
|
try {
|
|
1151
|
-
|
|
1198
|
+
return fs5.statSync(tokenFilePath).mtimeMs + exports.EVENT_TOKEN_TTL_MS;
|
|
1152
1199
|
} catch {
|
|
1153
|
-
return
|
|
1200
|
+
return void 0;
|
|
1154
1201
|
}
|
|
1155
|
-
if (!Array.isArray(body))
|
|
1156
|
-
return { kind: "failed", reason: "the reply was not a list" };
|
|
1157
|
-
return { kind: "ok", initiatives: body };
|
|
1158
1202
|
}
|
|
1159
|
-
|
|
1160
|
-
|
|
1203
|
+
function listPersistedToolInstallationIds2(toolType) {
|
|
1204
|
+
const prefix = `${sanitizeFilePart(toolType)}_`;
|
|
1205
|
+
const dir = path4.join(ascendaHome3(), "tokens");
|
|
1206
|
+
let names;
|
|
1161
1207
|
try {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
signal
|
|
1166
|
-
});
|
|
1167
|
-
} catch (error) {
|
|
1168
|
-
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1208
|
+
names = fs5.readdirSync(dir);
|
|
1209
|
+
} catch {
|
|
1210
|
+
return [];
|
|
1169
1211
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1212
|
+
const ids = [];
|
|
1213
|
+
for (const name of names.sort()) {
|
|
1214
|
+
if (!name.startsWith(prefix) || name.length === prefix.length)
|
|
1215
|
+
continue;
|
|
1216
|
+
const file = path4.join(dir, name);
|
|
1217
|
+
try {
|
|
1218
|
+
if (!fs5.statSync(file).isFile())
|
|
1219
|
+
continue;
|
|
1220
|
+
} catch {
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
if (readTokenFile3(file) === void 0)
|
|
1224
|
+
continue;
|
|
1225
|
+
ids.push(`${toolType}:${name.slice(prefix.length)}`);
|
|
1226
|
+
}
|
|
1227
|
+
return ids;
|
|
1228
|
+
}
|
|
1229
|
+
function readTokenFile3(tokenFilePath) {
|
|
1177
1230
|
try {
|
|
1178
|
-
|
|
1231
|
+
if (!fs5.existsSync(tokenFilePath))
|
|
1232
|
+
return void 0;
|
|
1233
|
+
const value = fs5.readFileSync(tokenFilePath, "utf8").trim();
|
|
1234
|
+
return value || void 0;
|
|
1179
1235
|
} catch {
|
|
1180
|
-
return
|
|
1236
|
+
return void 0;
|
|
1181
1237
|
}
|
|
1182
|
-
if (!Array.isArray(body))
|
|
1183
|
-
return { kind: "absent" };
|
|
1184
|
-
return { kind: "ok", notices: body };
|
|
1185
1238
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
method: objected ? "POST" : "DELETE",
|
|
1189
|
-
headers: { Authorization: `Bearer ${eventWriteToken}` }
|
|
1190
|
-
});
|
|
1191
|
-
if (!response.ok)
|
|
1192
|
-
throw await apiError(response);
|
|
1239
|
+
function sanitizeFilePart(value) {
|
|
1240
|
+
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
1193
1241
|
}
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
// ../packages/tool-kit/out/credentials.js
|
|
1246
|
+
var require_credentials = __commonJS({
|
|
1247
|
+
"../packages/tool-kit/out/credentials.js"(exports) {
|
|
1248
|
+
"use strict";
|
|
1249
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1250
|
+
if (k2 === void 0) k2 = k;
|
|
1251
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1252
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1253
|
+
desc = { enumerable: true, get: function() {
|
|
1254
|
+
return m[k];
|
|
1255
|
+
} };
|
|
1204
1256
|
}
|
|
1257
|
+
Object.defineProperty(o, k2, desc);
|
|
1258
|
+
} : function(o, m, k, k2) {
|
|
1259
|
+
if (k2 === void 0) k2 = k;
|
|
1260
|
+
o[k2] = m[k];
|
|
1261
|
+
});
|
|
1262
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1263
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1264
|
+
} : function(o, v) {
|
|
1265
|
+
o["default"] = v;
|
|
1266
|
+
});
|
|
1267
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1268
|
+
var ownKeys = function(o) {
|
|
1269
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1270
|
+
var ar = [];
|
|
1271
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1272
|
+
return ar;
|
|
1273
|
+
};
|
|
1274
|
+
return ownKeys(o);
|
|
1275
|
+
};
|
|
1276
|
+
return function(mod) {
|
|
1277
|
+
if (mod && mod.__esModule) return mod;
|
|
1278
|
+
var result = {};
|
|
1279
|
+
if (mod != null) {
|
|
1280
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1281
|
+
}
|
|
1282
|
+
__setModuleDefault(result, mod);
|
|
1283
|
+
return result;
|
|
1284
|
+
};
|
|
1285
|
+
}();
|
|
1286
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1287
|
+
exports.credentialsFilePath = credentialsFilePath2;
|
|
1288
|
+
exports.readMachineCredentials = readMachineCredentials2;
|
|
1289
|
+
exports.writeMachineCredentials = writeMachineCredentials2;
|
|
1290
|
+
exports.writeTopLevelCredentials = writeTopLevelCredentials2;
|
|
1291
|
+
exports.writeEventLogSetting = writeEventLogSetting2;
|
|
1292
|
+
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
1293
|
+
exports.readHostCredentials = readHostCredentials;
|
|
1294
|
+
exports.writeHostCredentials = writeHostCredentials;
|
|
1295
|
+
exports.removeHostCredentials = removeHostCredentials;
|
|
1296
|
+
var fs5 = __importStar(__require("fs"));
|
|
1297
|
+
var path4 = __importStar(__require("path"));
|
|
1298
|
+
var tokenStore_1 = require_tokenStore();
|
|
1299
|
+
function credentialsFilePath2() {
|
|
1300
|
+
return path4.join((0, tokenStore_1.ascendaHome)(), "credentials.json");
|
|
1205
1301
|
}
|
|
1206
|
-
|
|
1207
|
-
const body = await response.text();
|
|
1208
|
-
let errorCode;
|
|
1302
|
+
function readMachineCredentials2() {
|
|
1209
1303
|
try {
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1304
|
+
const raw = fs5.readFileSync(credentialsFilePath2(), "utf8").trim();
|
|
1305
|
+
if (!raw)
|
|
1306
|
+
return void 0;
|
|
1307
|
+
const parsed = JSON.parse(raw);
|
|
1308
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
1309
|
+
return void 0;
|
|
1310
|
+
return parsed;
|
|
1212
1311
|
} catch {
|
|
1213
|
-
|
|
1312
|
+
return void 0;
|
|
1214
1313
|
}
|
|
1215
|
-
return new AscendaApiError2(response.status, errorCode, body);
|
|
1216
|
-
}
|
|
1217
|
-
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
1218
|
-
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
1219
|
-
method: "POST",
|
|
1220
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1221
|
-
signal
|
|
1222
|
-
});
|
|
1223
|
-
if (response.status === 401)
|
|
1224
|
-
return null;
|
|
1225
|
-
if (!response.ok)
|
|
1226
|
-
throw new AscendaApiError2(response.status, void 0, await response.text());
|
|
1227
|
-
return await response.json();
|
|
1228
|
-
}
|
|
1229
|
-
function isDeliveredStatus(value) {
|
|
1230
|
-
return typeof value === "string" && tool_contract_1.TOOL_EVENT_DELIVERED_STATUSES.includes(value);
|
|
1231
1314
|
}
|
|
1232
|
-
function
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
return { duplicates: 0 };
|
|
1241
|
-
const single = parsed.status;
|
|
1242
|
-
if (isDeliveredStatus(single))
|
|
1243
|
-
return { duplicates: single === "duplicate" ? 1 : 0 };
|
|
1244
|
-
const raw = parsed.results;
|
|
1245
|
-
if (!Array.isArray(raw))
|
|
1246
|
-
return { duplicates: 0 };
|
|
1247
|
-
const results = [];
|
|
1248
|
-
for (const item of raw) {
|
|
1249
|
-
if (!item || typeof item !== "object")
|
|
1250
|
-
continue;
|
|
1251
|
-
const { index, status, reason } = item;
|
|
1252
|
-
if (typeof index !== "number" || typeof status !== "string")
|
|
1253
|
-
continue;
|
|
1254
|
-
results.push({ index, status, ...typeof reason === "string" ? { reason } : {} });
|
|
1315
|
+
function writeMachineCredentials2(credentials) {
|
|
1316
|
+
const file = credentialsFilePath2();
|
|
1317
|
+
fs5.mkdirSync(path4.dirname(file), { recursive: true, mode: 448 });
|
|
1318
|
+
fs5.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
1319
|
+
`, { encoding: "utf8", mode: 384 });
|
|
1320
|
+
if (process.platform !== "win32") {
|
|
1321
|
+
fs5.chmodSync(path4.dirname(file), 448);
|
|
1322
|
+
fs5.chmodSync(file, 384);
|
|
1255
1323
|
}
|
|
1256
|
-
return { duplicates: results.filter((item) => item.status === "duplicate").length, results };
|
|
1257
1324
|
}
|
|
1258
|
-
function
|
|
1259
|
-
|
|
1325
|
+
function writeTopLevelCredentials2(credentials) {
|
|
1326
|
+
const existing = readMachineCredentials2();
|
|
1327
|
+
const eventLogPath = credentials.eventLogPath ?? existing?.eventLogPath;
|
|
1328
|
+
writeMachineCredentials2({
|
|
1329
|
+
...credentials,
|
|
1330
|
+
...eventLogPath ? { eventLogPath } : {},
|
|
1331
|
+
...existing?.tools ? { tools: existing.tools } : {}
|
|
1332
|
+
});
|
|
1260
1333
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1334
|
+
function writeEventLogSetting2(value) {
|
|
1335
|
+
const existing = readMachineCredentials2() ?? {};
|
|
1336
|
+
writeMachineCredentials2({ ...existing, eventLogPath: value });
|
|
1263
1337
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1338
|
+
function isLocalOnlyHostInstall(host, hasToken) {
|
|
1339
|
+
const credentials = readHostCredentials(host);
|
|
1340
|
+
if (!credentials?.localOnly)
|
|
1341
|
+
return false;
|
|
1342
|
+
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
1343
|
+
return false;
|
|
1344
|
+
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
1266
1345
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
body,
|
|
1273
|
-
signal
|
|
1274
|
-
});
|
|
1275
|
-
return parseIngestResponse(response);
|
|
1276
|
-
} catch (error) {
|
|
1277
|
-
return {
|
|
1278
|
-
result: "transport_error",
|
|
1279
|
-
detail: error instanceof Error ? `${error.name}: ${error.message}` : String(error)
|
|
1280
|
-
};
|
|
1281
|
-
}
|
|
1346
|
+
function readHostCredentials(host) {
|
|
1347
|
+
const entry = readMachineCredentials2()?.tools?.[host];
|
|
1348
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
1349
|
+
return void 0;
|
|
1350
|
+
return entry;
|
|
1282
1351
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
let errorCode;
|
|
1300
|
-
try {
|
|
1301
|
-
errorCode = JSON.parse(body).error;
|
|
1302
|
-
} catch {
|
|
1303
|
-
errorCode = void 0;
|
|
1304
|
-
}
|
|
1305
|
-
const base = { httpStatus: response.status, errorCode, detail: body || void 0 };
|
|
1306
|
-
if (response.status === 401)
|
|
1307
|
-
return { ...base, result: "auth_failed" };
|
|
1308
|
-
if (response.status === 403 && errorCode === "consent_missing_or_expired")
|
|
1309
|
-
return { ...base, result: "consent_missing" };
|
|
1310
|
-
if (response.status === 400 || response.status === 422)
|
|
1311
|
-
return { ...base, result: "validation_failed" };
|
|
1312
|
-
return { ...base, result: "transport_error" };
|
|
1352
|
+
function writeHostCredentials(host, credentials) {
|
|
1353
|
+
const existing = readMachineCredentials2() ?? {};
|
|
1354
|
+
writeMachineCredentials2({ ...existing, tools: { ...existing.tools ?? {}, [host]: credentials } });
|
|
1355
|
+
}
|
|
1356
|
+
function removeHostCredentials(host) {
|
|
1357
|
+
const existing = readMachineCredentials2();
|
|
1358
|
+
if (!existing?.tools || !(host in existing.tools))
|
|
1359
|
+
return;
|
|
1360
|
+
const tools = { ...existing.tools };
|
|
1361
|
+
delete tools[host];
|
|
1362
|
+
const next = { ...existing };
|
|
1363
|
+
if (Object.keys(tools).length)
|
|
1364
|
+
next.tools = tools;
|
|
1365
|
+
else
|
|
1366
|
+
delete next.tools;
|
|
1367
|
+
writeMachineCredentials2(next);
|
|
1313
1368
|
}
|
|
1314
1369
|
}
|
|
1315
1370
|
});
|
|
1316
1371
|
|
|
1317
|
-
// ../packages/tool-kit/out/
|
|
1318
|
-
var
|
|
1319
|
-
"../packages/tool-kit/out/
|
|
1372
|
+
// ../packages/tool-kit/out/eventLog.js
|
|
1373
|
+
var require_eventLog = __commonJS({
|
|
1374
|
+
"../packages/tool-kit/out/eventLog.js"(exports) {
|
|
1320
1375
|
"use strict";
|
|
1321
1376
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1322
1377
|
if (k2 === void 0) k2 = k;
|
|
@@ -1356,144 +1411,393 @@ var require_tokenStore = __commonJS({
|
|
|
1356
1411
|
};
|
|
1357
1412
|
}();
|
|
1358
1413
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1359
|
-
exports.
|
|
1360
|
-
exports.
|
|
1361
|
-
exports.
|
|
1362
|
-
exports.
|
|
1363
|
-
exports.
|
|
1364
|
-
exports.
|
|
1365
|
-
exports.
|
|
1366
|
-
exports.
|
|
1367
|
-
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1414
|
+
exports.EVENT_LOG_OFF = exports.EVENT_LOG_ENV_VAR = void 0;
|
|
1415
|
+
exports.expandUserPath = expandUserPath;
|
|
1416
|
+
exports.defaultEventLogPath = defaultEventLogPath;
|
|
1417
|
+
exports.resolveEventLog = resolveEventLog3;
|
|
1418
|
+
exports.resolveEventLogPath = resolveEventLogPath2;
|
|
1419
|
+
exports.describeEventLog = describeEventLog3;
|
|
1420
|
+
exports.parseEventLogFlag = parseEventLogFlag2;
|
|
1421
|
+
exports.appendEventLog = appendEventLog2;
|
|
1368
1422
|
var fs5 = __importStar(__require("fs"));
|
|
1369
|
-
var
|
|
1423
|
+
var os5 = __importStar(__require("os"));
|
|
1370
1424
|
var path4 = __importStar(__require("path"));
|
|
1371
|
-
|
|
1372
|
-
|
|
1425
|
+
var agentEvent_1 = require_agentEvent();
|
|
1426
|
+
var credentials_1 = require_credentials();
|
|
1427
|
+
var tokenStore_1 = require_tokenStore();
|
|
1428
|
+
exports.EVENT_LOG_ENV_VAR = "ASCENDA_EVENT_LOG_FILE";
|
|
1429
|
+
exports.EVENT_LOG_OFF = "off";
|
|
1430
|
+
var MAX_BYTES = 5 * 1024 * 1024;
|
|
1431
|
+
function expandUserPath(configured) {
|
|
1432
|
+
const value = configured?.trim();
|
|
1433
|
+
if (!value)
|
|
1434
|
+
return void 0;
|
|
1435
|
+
if (value === "~")
|
|
1436
|
+
return os5.homedir();
|
|
1437
|
+
if (value.startsWith("~/"))
|
|
1438
|
+
return path4.join(os5.homedir(), value.slice(2));
|
|
1439
|
+
return path4.resolve(value);
|
|
1373
1440
|
}
|
|
1374
|
-
function
|
|
1375
|
-
return path4.join(
|
|
1441
|
+
function defaultEventLogPath() {
|
|
1442
|
+
return path4.join((0, tokenStore_1.ascendaHome)(), "events.jsonl");
|
|
1376
1443
|
}
|
|
1377
|
-
function
|
|
1378
|
-
|
|
1444
|
+
function resolveEventLog3(options = {}) {
|
|
1445
|
+
for (const [source, raw] of [
|
|
1446
|
+
["env", process.env[exports.EVENT_LOG_ENV_VAR]],
|
|
1447
|
+
["credentials", (0, credentials_1.readMachineCredentials)()?.eventLogPath]
|
|
1448
|
+
]) {
|
|
1449
|
+
const value = raw?.trim();
|
|
1450
|
+
if (!value)
|
|
1451
|
+
continue;
|
|
1452
|
+
if (value.toLowerCase() === exports.EVENT_LOG_OFF)
|
|
1453
|
+
return { path: void 0, source: "disabled" };
|
|
1454
|
+
return { path: expandUserPath(value), source };
|
|
1455
|
+
}
|
|
1456
|
+
if (options.localOnly)
|
|
1457
|
+
return { path: defaultEventLogPath(), source: "unpaired-default" };
|
|
1458
|
+
return { path: void 0, source: "off" };
|
|
1459
|
+
}
|
|
1460
|
+
function resolveEventLogPath2(options = {}) {
|
|
1461
|
+
return resolveEventLog3(options).path;
|
|
1462
|
+
}
|
|
1463
|
+
function describeEventLog3(setting, command) {
|
|
1464
|
+
switch (setting.source) {
|
|
1465
|
+
case "env":
|
|
1466
|
+
return `${setting.path} (from ${exports.EVENT_LOG_ENV_VAR})`;
|
|
1467
|
+
case "credentials":
|
|
1468
|
+
return `${setting.path} (set by ${command} --event-log)`;
|
|
1469
|
+
case "unpaired-default":
|
|
1470
|
+
return `${setting.path} (on because this install isn't paired; ${command} --event-log off to stop)`;
|
|
1471
|
+
case "disabled":
|
|
1472
|
+
return `off (turned off; ${command} --event-log to turn it on)`;
|
|
1473
|
+
case "off":
|
|
1474
|
+
return `off (${command} --event-log to keep a local copy of every event)`;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
function parseEventLogFlag2(argv, index) {
|
|
1478
|
+
const peek = argv[index + 1];
|
|
1479
|
+
if (peek !== void 0 && !peek.startsWith("-"))
|
|
1480
|
+
return { value: peek, consumed: 1 };
|
|
1481
|
+
return { value: defaultEventLogPath(), consumed: 0 };
|
|
1379
1482
|
}
|
|
1380
|
-
function
|
|
1381
|
-
const dir = path4.dirname(tokenFilePath);
|
|
1382
|
-
fs5.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1383
|
-
fs5.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
1384
|
-
if (process.platform !== "win32") {
|
|
1385
|
-
fs5.chmodSync(dir, 448);
|
|
1386
|
-
fs5.chmodSync(tokenFilePath, 384);
|
|
1387
|
-
}
|
|
1388
|
-
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1483
|
+
function appendEventLog2(logFilePath, entry) {
|
|
1389
1484
|
try {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1485
|
+
rotateIfLarge(logFilePath);
|
|
1486
|
+
const dir = path4.dirname(logFilePath);
|
|
1487
|
+
fs5.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1488
|
+
const line = { ...entry, event: entry.event ?? (0, agentEvent_1.toAgentEvent)(entry.payload) };
|
|
1489
|
+
fs5.appendFileSync(logFilePath, `${JSON.stringify(line)}
|
|
1490
|
+
`, { encoding: "utf8", mode: 384 });
|
|
1491
|
+
if (process.platform !== "win32")
|
|
1492
|
+
fs5.chmodSync(logFilePath, 384);
|
|
1396
1493
|
} catch {
|
|
1397
1494
|
}
|
|
1398
1495
|
}
|
|
1399
|
-
|
|
1400
|
-
function readTokenExpiry(tokenFilePath) {
|
|
1496
|
+
function rotateIfLarge(logFilePath) {
|
|
1401
1497
|
try {
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1498
|
+
if (fs5.statSync(logFilePath).size < MAX_BYTES)
|
|
1499
|
+
return;
|
|
1500
|
+
fs5.renameSync(logFilePath, `${logFilePath}.1`);
|
|
1405
1501
|
} catch {
|
|
1406
1502
|
}
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
|
|
1507
|
+
// ../packages/tool-kit/out/http.js
|
|
1508
|
+
var require_http = __commonJS({
|
|
1509
|
+
"../packages/tool-kit/out/http.js"(exports) {
|
|
1510
|
+
"use strict";
|
|
1511
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1512
|
+
exports.AscendaApiError = void 0;
|
|
1513
|
+
exports.createPairingSession = createPairingSession3;
|
|
1514
|
+
exports.getPairingStatus = getPairingStatus3;
|
|
1515
|
+
exports.startStudyJoin = startStudyJoin;
|
|
1516
|
+
exports.getStudyJoinStatus = getStudyJoinStatus;
|
|
1517
|
+
exports.readInitiatives = readInitiatives;
|
|
1518
|
+
exports.readStudyNotices = readStudyNotices;
|
|
1519
|
+
exports.setStudyObjection = setStudyObjection;
|
|
1520
|
+
exports.markStudyNoticeShown = markStudyNoticeShown;
|
|
1521
|
+
exports.renewToolToken = renewToolToken;
|
|
1522
|
+
exports.isRetryableStatus = isRetryableStatus;
|
|
1523
|
+
exports.postToolEvent = postToolEvent;
|
|
1524
|
+
exports.postToolEventsBatch = postToolEventsBatch;
|
|
1525
|
+
exports.parseIngestResponse = parseIngestResponse;
|
|
1526
|
+
var tool_contract_1 = require_out();
|
|
1527
|
+
var AscendaApiError2 = class extends Error {
|
|
1528
|
+
status;
|
|
1529
|
+
errorCode;
|
|
1530
|
+
constructor(status, errorCode, body) {
|
|
1531
|
+
super(body ?? `Ascenda API error ${status}`);
|
|
1532
|
+
this.status = status;
|
|
1533
|
+
this.errorCode = errorCode;
|
|
1534
|
+
this.name = "AscendaApiError";
|
|
1535
|
+
}
|
|
1536
|
+
};
|
|
1537
|
+
exports.AscendaApiError = AscendaApiError2;
|
|
1538
|
+
async function createPairingSession3(apiBaseUrl, toolInstallationId, toolType, displayName) {
|
|
1539
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions`, {
|
|
1540
|
+
method: "POST",
|
|
1541
|
+
headers: { "Content-Type": "application/json" },
|
|
1542
|
+
body: JSON.stringify({ toolInstallationId, toolType, displayName })
|
|
1543
|
+
});
|
|
1544
|
+
if (!response.ok)
|
|
1545
|
+
throw new AscendaApiError2(response.status, void 0, await response.text());
|
|
1546
|
+
return await response.json();
|
|
1547
|
+
}
|
|
1548
|
+
async function getPairingStatus3(apiBaseUrl, pairingSessionId) {
|
|
1549
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions/${encodeURIComponent(pairingSessionId)}/status`, {
|
|
1550
|
+
method: "GET",
|
|
1551
|
+
headers: { Accept: "application/json" }
|
|
1552
|
+
});
|
|
1553
|
+
if (!response.ok)
|
|
1554
|
+
throw new AscendaApiError2(response.status, void 0, await response.text());
|
|
1555
|
+
return await response.json();
|
|
1556
|
+
}
|
|
1557
|
+
async function startStudyJoin(apiBaseUrl, eventWriteToken, joinCode, mode) {
|
|
1558
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions`, {
|
|
1559
|
+
method: "POST",
|
|
1560
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1561
|
+
body: JSON.stringify({ joinCode, mode })
|
|
1562
|
+
});
|
|
1563
|
+
if (!response.ok)
|
|
1564
|
+
throw await apiError(response);
|
|
1565
|
+
return await response.json();
|
|
1566
|
+
}
|
|
1567
|
+
async function getStudyJoinStatus(apiBaseUrl, eventWriteToken, joinSessionId) {
|
|
1568
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions/${encodeURIComponent(joinSessionId)}/status`, {
|
|
1569
|
+
method: "GET",
|
|
1570
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` }
|
|
1571
|
+
});
|
|
1572
|
+
if (!response.ok)
|
|
1573
|
+
throw await apiError(response);
|
|
1574
|
+
return await response.json();
|
|
1575
|
+
}
|
|
1576
|
+
async function readInitiatives(apiBaseUrl, eventWriteToken, signal) {
|
|
1577
|
+
let response;
|
|
1578
|
+
try {
|
|
1579
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/initiatives`, {
|
|
1580
|
+
method: "GET",
|
|
1581
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1582
|
+
signal
|
|
1583
|
+
});
|
|
1584
|
+
} catch (error) {
|
|
1585
|
+
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1586
|
+
}
|
|
1587
|
+
if (response.status === 401)
|
|
1588
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1589
|
+
if (!response.ok)
|
|
1590
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1591
|
+
let body;
|
|
1407
1592
|
try {
|
|
1408
|
-
|
|
1593
|
+
body = await response.json();
|
|
1409
1594
|
} catch {
|
|
1410
|
-
return
|
|
1595
|
+
return { kind: "failed", reason: "the reply was not readable" };
|
|
1411
1596
|
}
|
|
1597
|
+
if (!Array.isArray(body))
|
|
1598
|
+
return { kind: "failed", reason: "the reply was not a list" };
|
|
1599
|
+
return { kind: "ok", initiatives: body };
|
|
1412
1600
|
}
|
|
1413
|
-
function
|
|
1414
|
-
|
|
1415
|
-
const dir = path4.join(ascendaHome3(), "tokens");
|
|
1416
|
-
let names;
|
|
1601
|
+
async function readStudyNotices(apiBaseUrl, eventWriteToken, signal) {
|
|
1602
|
+
let response;
|
|
1417
1603
|
try {
|
|
1418
|
-
|
|
1604
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices`, {
|
|
1605
|
+
method: "GET",
|
|
1606
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1607
|
+
signal
|
|
1608
|
+
});
|
|
1609
|
+
} catch (error) {
|
|
1610
|
+
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1611
|
+
}
|
|
1612
|
+
if (response.status === 404)
|
|
1613
|
+
return { kind: "absent" };
|
|
1614
|
+
if (response.status === 401)
|
|
1615
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1616
|
+
if (!response.ok)
|
|
1617
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1618
|
+
let body;
|
|
1619
|
+
try {
|
|
1620
|
+
body = await response.json();
|
|
1419
1621
|
} catch {
|
|
1420
|
-
return
|
|
1622
|
+
return { kind: "absent" };
|
|
1421
1623
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1624
|
+
if (!Array.isArray(body))
|
|
1625
|
+
return { kind: "absent" };
|
|
1626
|
+
return { kind: "ok", notices: body };
|
|
1627
|
+
}
|
|
1628
|
+
async function setStudyObjection(apiBaseUrl, eventWriteToken, code, objected) {
|
|
1629
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(String(code))}/objection`, {
|
|
1630
|
+
method: objected ? "POST" : "DELETE",
|
|
1631
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` }
|
|
1632
|
+
});
|
|
1633
|
+
if (!response.ok)
|
|
1634
|
+
throw await apiError(response);
|
|
1635
|
+
}
|
|
1636
|
+
async function markStudyNoticeShown(apiBaseUrl, eventWriteToken, organisationId, code, signal) {
|
|
1637
|
+
try {
|
|
1638
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(organisationId)}/${encodeURIComponent(String(code))}/shown`, {
|
|
1639
|
+
method: "POST",
|
|
1640
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` },
|
|
1641
|
+
signal
|
|
1642
|
+
});
|
|
1643
|
+
return response.ok;
|
|
1644
|
+
} catch {
|
|
1645
|
+
return false;
|
|
1436
1646
|
}
|
|
1437
|
-
return ids;
|
|
1438
1647
|
}
|
|
1439
|
-
function
|
|
1648
|
+
async function apiError(response) {
|
|
1649
|
+
const body = await response.text();
|
|
1650
|
+
let errorCode;
|
|
1440
1651
|
try {
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
const value = fs5.readFileSync(tokenFilePath, "utf8").trim();
|
|
1444
|
-
return value || void 0;
|
|
1652
|
+
const parsed = JSON.parse(body);
|
|
1653
|
+
errorCode = parsed.code ?? parsed.error;
|
|
1445
1654
|
} catch {
|
|
1446
|
-
|
|
1655
|
+
errorCode = void 0;
|
|
1447
1656
|
}
|
|
1657
|
+
return new AscendaApiError2(response.status, errorCode, body);
|
|
1448
1658
|
}
|
|
1449
|
-
function
|
|
1450
|
-
|
|
1659
|
+
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
1660
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
1661
|
+
method: "POST",
|
|
1662
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1663
|
+
signal
|
|
1664
|
+
});
|
|
1665
|
+
if (response.status === 401)
|
|
1666
|
+
return null;
|
|
1667
|
+
if (!response.ok)
|
|
1668
|
+
throw new AscendaApiError2(response.status, void 0, await response.text());
|
|
1669
|
+
return await response.json();
|
|
1451
1670
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1462
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1463
|
-
desc = { enumerable: true, get: function() {
|
|
1464
|
-
return m[k];
|
|
1465
|
-
} };
|
|
1671
|
+
function isDeliveredStatus(value) {
|
|
1672
|
+
return typeof value === "string" && tool_contract_1.TOOL_EVENT_DELIVERED_STATUSES.includes(value);
|
|
1673
|
+
}
|
|
1674
|
+
function readSuccessBody(body) {
|
|
1675
|
+
let parsed;
|
|
1676
|
+
try {
|
|
1677
|
+
parsed = JSON.parse(body);
|
|
1678
|
+
} catch {
|
|
1679
|
+
return { duplicates: 0 };
|
|
1466
1680
|
}
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1681
|
+
if (!parsed || typeof parsed !== "object")
|
|
1682
|
+
return { duplicates: 0 };
|
|
1683
|
+
const single = parsed.status;
|
|
1684
|
+
if (isDeliveredStatus(single))
|
|
1685
|
+
return { duplicates: single === "duplicate" ? 1 : 0 };
|
|
1686
|
+
const raw = parsed.results;
|
|
1687
|
+
if (!Array.isArray(raw))
|
|
1688
|
+
return { duplicates: 0 };
|
|
1689
|
+
const results = [];
|
|
1690
|
+
for (const item of raw) {
|
|
1691
|
+
if (!item || typeof item !== "object")
|
|
1692
|
+
continue;
|
|
1693
|
+
const { index, status, reason } = item;
|
|
1694
|
+
if (typeof index !== "number" || typeof status !== "string")
|
|
1695
|
+
continue;
|
|
1696
|
+
results.push({ index, status, ...typeof reason === "string" ? { reason } : {} });
|
|
1697
|
+
}
|
|
1698
|
+
return { duplicates: results.filter((item) => item.status === "duplicate").length, results };
|
|
1699
|
+
}
|
|
1700
|
+
function isRetryableStatus(status) {
|
|
1701
|
+
return status === 408 || status === 429 || status !== void 0 && status >= 500 && status <= 599;
|
|
1702
|
+
}
|
|
1703
|
+
async function postToolEvent(apiBaseUrl, eventWriteToken, payload, signal) {
|
|
1704
|
+
return sendIngest(`${apiBaseUrl}/v1/tool-events`, eventWriteToken, JSON.stringify(payload), signal);
|
|
1705
|
+
}
|
|
1706
|
+
async function postToolEventsBatch(apiBaseUrl, eventWriteToken, payloads, signal) {
|
|
1707
|
+
return sendIngest(`${apiBaseUrl}/v1/tool-events/batch`, eventWriteToken, JSON.stringify({ events: payloads }), signal);
|
|
1708
|
+
}
|
|
1709
|
+
async function sendIngest(url, eventWriteToken, body, signal) {
|
|
1710
|
+
try {
|
|
1711
|
+
const response = await fetch(url, {
|
|
1712
|
+
method: "POST",
|
|
1713
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1714
|
+
body,
|
|
1715
|
+
signal
|
|
1716
|
+
});
|
|
1717
|
+
return parseIngestResponse(response);
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
return {
|
|
1720
|
+
result: "transport_error",
|
|
1721
|
+
detail: error instanceof Error ? `${error.name}: ${error.message}` : String(error)
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
async function parseIngestResponse(response) {
|
|
1726
|
+
if (response.ok) {
|
|
1727
|
+
const outcome = { result: "accepted", httpStatus: response.status };
|
|
1728
|
+
let read = { duplicates: 0 };
|
|
1729
|
+
try {
|
|
1730
|
+
read = readSuccessBody(await response.text());
|
|
1731
|
+
} catch {
|
|
1732
|
+
read = { duplicates: 0 };
|
|
1733
|
+
}
|
|
1734
|
+
return {
|
|
1735
|
+
...outcome,
|
|
1736
|
+
...read.duplicates > 0 ? { duplicates: read.duplicates } : {},
|
|
1737
|
+
...read.results !== void 0 ? { results: read.results } : {}
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
const body = await response.text();
|
|
1741
|
+
let errorCode;
|
|
1742
|
+
try {
|
|
1743
|
+
errorCode = JSON.parse(body).error;
|
|
1744
|
+
} catch {
|
|
1745
|
+
errorCode = void 0;
|
|
1746
|
+
}
|
|
1747
|
+
const base = { httpStatus: response.status, errorCode, detail: body || void 0 };
|
|
1748
|
+
if (response.status === 401)
|
|
1749
|
+
return { ...base, result: "auth_failed" };
|
|
1750
|
+
if (response.status === 403 && errorCode === "consent_missing_or_expired")
|
|
1751
|
+
return { ...base, result: "consent_missing" };
|
|
1752
|
+
if (response.status === 400 || response.status === 422)
|
|
1753
|
+
return { ...base, result: "validation_failed" };
|
|
1754
|
+
return { ...base, result: "transport_error" };
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
|
|
1759
|
+
// ../packages/tool-kit/out/stateStore.js
|
|
1760
|
+
var require_stateStore = __commonJS({
|
|
1761
|
+
"../packages/tool-kit/out/stateStore.js"(exports) {
|
|
1762
|
+
"use strict";
|
|
1763
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1764
|
+
if (k2 === void 0) k2 = k;
|
|
1765
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1766
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1767
|
+
desc = { enumerable: true, get: function() {
|
|
1768
|
+
return m[k];
|
|
1769
|
+
} };
|
|
1770
|
+
}
|
|
1771
|
+
Object.defineProperty(o, k2, desc);
|
|
1772
|
+
} : function(o, m, k, k2) {
|
|
1773
|
+
if (k2 === void 0) k2 = k;
|
|
1774
|
+
o[k2] = m[k];
|
|
1775
|
+
});
|
|
1776
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1777
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1778
|
+
} : function(o, v) {
|
|
1779
|
+
o["default"] = v;
|
|
1780
|
+
});
|
|
1781
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1782
|
+
var ownKeys = function(o) {
|
|
1783
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1784
|
+
var ar = [];
|
|
1785
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1786
|
+
return ar;
|
|
1787
|
+
};
|
|
1788
|
+
return ownKeys(o);
|
|
1789
|
+
};
|
|
1790
|
+
return function(mod) {
|
|
1791
|
+
if (mod && mod.__esModule) return mod;
|
|
1792
|
+
var result = {};
|
|
1793
|
+
if (mod != null) {
|
|
1794
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1795
|
+
}
|
|
1796
|
+
__setModuleDefault(result, mod);
|
|
1797
|
+
return result;
|
|
1798
|
+
};
|
|
1799
|
+
}();
|
|
1800
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1497
1801
|
exports.defaultStateFilePath = defaultStateFilePath2;
|
|
1498
1802
|
exports.unresolvedToolInstallationId = unresolvedToolInstallationId2;
|
|
1499
1803
|
exports.unresolvedStateFilePath = unresolvedStateFilePath2;
|
|
@@ -1856,6 +2160,7 @@ var require_eventSender = __commonJS({
|
|
|
1856
2160
|
"use strict";
|
|
1857
2161
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1858
2162
|
exports.AscendaEventSender = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = void 0;
|
|
2163
|
+
exports.buildEventBody = buildEventBody;
|
|
1859
2164
|
exports.buildEventPayload = buildEventPayload2;
|
|
1860
2165
|
var afterHours_1 = require_afterHours();
|
|
1861
2166
|
var tool_contract_1 = require_out();
|
|
@@ -1874,12 +2179,10 @@ var require_eventSender = __commonJS({
|
|
|
1874
2179
|
}
|
|
1875
2180
|
};
|
|
1876
2181
|
exports.AscendaSemanticEventError = AscendaSemanticEventError;
|
|
1877
|
-
function
|
|
2182
|
+
function buildEventBody(identity, mapped) {
|
|
1878
2183
|
return {
|
|
1879
|
-
toolInstallationId: identity.toolInstallationId,
|
|
1880
2184
|
source: identity.source,
|
|
1881
2185
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1882
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
1883
2186
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
1884
2187
|
sessionId: identity.sessionId ?? void 0,
|
|
1885
2188
|
workspaceHash: identity.workspaceHash ?? void 0,
|
|
@@ -1891,6 +2194,9 @@ var require_eventSender = __commonJS({
|
|
|
1891
2194
|
metadata: withCollectorVersion(mapped.metadata)
|
|
1892
2195
|
};
|
|
1893
2196
|
}
|
|
2197
|
+
function buildEventPayload2(identity, mapped) {
|
|
2198
|
+
return (0, tool_contract_1.joinEventPayload)({ toolInstallationId: identity.toolInstallationId, idempotencyKey: (0, payload_1.mintIdempotencyKey)() }, buildEventBody(identity, mapped));
|
|
2199
|
+
}
|
|
1894
2200
|
function withCollectorVersion(metadata) {
|
|
1895
2201
|
return { ...metadata, collectorVersion: collectorVersion_1.COLLECTOR_VERSION };
|
|
1896
2202
|
}
|
|
@@ -1966,12 +2272,10 @@ var require_eventSender = __commonJS({
|
|
|
1966
2272
|
if (!mapped.metadata.skillVersion || !mapped.metadata.skillVersion.trim()) {
|
|
1967
2273
|
throw new AscendaSemanticEventError(`metadata.skillVersion is required for semantic event "${mapped.eventType}".`);
|
|
1968
2274
|
}
|
|
1969
|
-
const
|
|
1970
|
-
toolInstallationId: this.config.toolInstallationId,
|
|
2275
|
+
const body = {
|
|
1971
2276
|
source: this.config.source,
|
|
1972
2277
|
eventType: mapped.eventType,
|
|
1973
2278
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1974
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
1975
2279
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
1976
2280
|
severity: "low",
|
|
1977
2281
|
sessionId: this.config.sessionId ?? void 0,
|
|
@@ -1982,7 +2286,7 @@ var require_eventSender = __commonJS({
|
|
|
1982
2286
|
privacyMode: "metadata_only",
|
|
1983
2287
|
metadata: withCollectorVersion(mapped.metadata)
|
|
1984
2288
|
};
|
|
1985
|
-
return this.post(
|
|
2289
|
+
return this.post((0, tool_contract_1.joinEventPayload)(this.envelope(), body));
|
|
1986
2290
|
}
|
|
1987
2291
|
/**
|
|
1988
2292
|
* Sends a collaboration event under `workflow_telemetry`.
|
|
@@ -1997,12 +2301,10 @@ var require_eventSender = __commonJS({
|
|
|
1997
2301
|
if (!tool_contract_1.COLLABORATION_EVENT_TYPES.includes(mapped.eventType)) {
|
|
1998
2302
|
throw new AscendaSemanticEventError(`"${mapped.eventType}" is not a collaboration event type. Use send() for a deterministic host event.`);
|
|
1999
2303
|
}
|
|
2000
|
-
const
|
|
2001
|
-
toolInstallationId: this.config.toolInstallationId,
|
|
2304
|
+
const body = {
|
|
2002
2305
|
source: this.config.source,
|
|
2003
2306
|
eventType: mapped.eventType,
|
|
2004
2307
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2005
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
2006
2308
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
2007
2309
|
severity: "low",
|
|
2008
2310
|
sessionId: this.config.sessionId ?? void 0,
|
|
@@ -2013,7 +2315,11 @@ var require_eventSender = __commonJS({
|
|
|
2013
2315
|
privacyMode: "metadata_only",
|
|
2014
2316
|
metadata: withCollectorVersion(mapped.metadata)
|
|
2015
2317
|
};
|
|
2016
|
-
return this.post(
|
|
2318
|
+
return this.post((0, tool_contract_1.joinEventPayload)(this.envelope(), body));
|
|
2319
|
+
}
|
|
2320
|
+
/** A fresh envelope per event: the key belongs to the event, so every retry of it reuses this one. */
|
|
2321
|
+
envelope() {
|
|
2322
|
+
return { toolInstallationId: this.config.toolInstallationId, idempotencyKey: (0, payload_1.mintIdempotencyKey)() };
|
|
2017
2323
|
}
|
|
2018
2324
|
/**
|
|
2019
2325
|
* The single choke point every event passes through, and therefore the only
|
|
@@ -2336,11 +2642,11 @@ var require_contextRegistry = __commonJS({
|
|
|
2336
2642
|
exports.recordWorkContext = recordWorkContext2;
|
|
2337
2643
|
exports.recordWorkContextAlias = recordWorkContextAlias;
|
|
2338
2644
|
var fs5 = __importStar(__require("fs"));
|
|
2339
|
-
var
|
|
2645
|
+
var os5 = __importStar(__require("os"));
|
|
2340
2646
|
var path4 = __importStar(__require("path"));
|
|
2341
2647
|
var MAX_PATHS_PER_ENTRY = 8;
|
|
2342
2648
|
function workContextRegistryFilePath() {
|
|
2343
|
-
return path4.join(
|
|
2649
|
+
return path4.join(os5.homedir(), ".ascenda", "work-contexts.json");
|
|
2344
2650
|
}
|
|
2345
2651
|
function readWorkContextRegistry(registryFilePath = workContextRegistryFilePath()) {
|
|
2346
2652
|
try {
|
|
@@ -2433,123 +2739,6 @@ var require_contextRegistry = __commonJS({
|
|
|
2433
2739
|
}
|
|
2434
2740
|
});
|
|
2435
2741
|
|
|
2436
|
-
// ../packages/tool-kit/out/credentials.js
|
|
2437
|
-
var require_credentials = __commonJS({
|
|
2438
|
-
"../packages/tool-kit/out/credentials.js"(exports) {
|
|
2439
|
-
"use strict";
|
|
2440
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
2441
|
-
if (k2 === void 0) k2 = k;
|
|
2442
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2443
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2444
|
-
desc = { enumerable: true, get: function() {
|
|
2445
|
-
return m[k];
|
|
2446
|
-
} };
|
|
2447
|
-
}
|
|
2448
|
-
Object.defineProperty(o, k2, desc);
|
|
2449
|
-
} : function(o, m, k, k2) {
|
|
2450
|
-
if (k2 === void 0) k2 = k;
|
|
2451
|
-
o[k2] = m[k];
|
|
2452
|
-
});
|
|
2453
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
2454
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
2455
|
-
} : function(o, v) {
|
|
2456
|
-
o["default"] = v;
|
|
2457
|
-
});
|
|
2458
|
-
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
2459
|
-
var ownKeys = function(o) {
|
|
2460
|
-
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
2461
|
-
var ar = [];
|
|
2462
|
-
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
2463
|
-
return ar;
|
|
2464
|
-
};
|
|
2465
|
-
return ownKeys(o);
|
|
2466
|
-
};
|
|
2467
|
-
return function(mod) {
|
|
2468
|
-
if (mod && mod.__esModule) return mod;
|
|
2469
|
-
var result = {};
|
|
2470
|
-
if (mod != null) {
|
|
2471
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
2472
|
-
}
|
|
2473
|
-
__setModuleDefault(result, mod);
|
|
2474
|
-
return result;
|
|
2475
|
-
};
|
|
2476
|
-
}();
|
|
2477
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2478
|
-
exports.credentialsFilePath = credentialsFilePath2;
|
|
2479
|
-
exports.readMachineCredentials = readMachineCredentials2;
|
|
2480
|
-
exports.writeMachineCredentials = writeMachineCredentials2;
|
|
2481
|
-
exports.writeTopLevelCredentials = writeTopLevelCredentials2;
|
|
2482
|
-
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
2483
|
-
exports.readHostCredentials = readHostCredentials;
|
|
2484
|
-
exports.writeHostCredentials = writeHostCredentials;
|
|
2485
|
-
exports.removeHostCredentials = removeHostCredentials;
|
|
2486
|
-
var fs5 = __importStar(__require("fs"));
|
|
2487
|
-
var path4 = __importStar(__require("path"));
|
|
2488
|
-
var tokenStore_1 = require_tokenStore();
|
|
2489
|
-
function credentialsFilePath2() {
|
|
2490
|
-
return path4.join((0, tokenStore_1.ascendaHome)(), "credentials.json");
|
|
2491
|
-
}
|
|
2492
|
-
function readMachineCredentials2() {
|
|
2493
|
-
try {
|
|
2494
|
-
const raw = fs5.readFileSync(credentialsFilePath2(), "utf8").trim();
|
|
2495
|
-
if (!raw)
|
|
2496
|
-
return void 0;
|
|
2497
|
-
const parsed = JSON.parse(raw);
|
|
2498
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
2499
|
-
return void 0;
|
|
2500
|
-
return parsed;
|
|
2501
|
-
} catch {
|
|
2502
|
-
return void 0;
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
function writeMachineCredentials2(credentials) {
|
|
2506
|
-
const file = credentialsFilePath2();
|
|
2507
|
-
fs5.mkdirSync(path4.dirname(file), { recursive: true, mode: 448 });
|
|
2508
|
-
fs5.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
2509
|
-
`, { encoding: "utf8", mode: 384 });
|
|
2510
|
-
if (process.platform !== "win32") {
|
|
2511
|
-
fs5.chmodSync(path4.dirname(file), 448);
|
|
2512
|
-
fs5.chmodSync(file, 384);
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
function writeTopLevelCredentials2(credentials) {
|
|
2516
|
-
const existing = readMachineCredentials2();
|
|
2517
|
-
writeMachineCredentials2({ ...credentials, ...existing?.tools ? { tools: existing.tools } : {} });
|
|
2518
|
-
}
|
|
2519
|
-
function isLocalOnlyHostInstall(host, hasToken) {
|
|
2520
|
-
const credentials = readHostCredentials(host);
|
|
2521
|
-
if (!credentials?.localOnly)
|
|
2522
|
-
return false;
|
|
2523
|
-
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
2524
|
-
return false;
|
|
2525
|
-
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
2526
|
-
}
|
|
2527
|
-
function readHostCredentials(host) {
|
|
2528
|
-
const entry = readMachineCredentials2()?.tools?.[host];
|
|
2529
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
2530
|
-
return void 0;
|
|
2531
|
-
return entry;
|
|
2532
|
-
}
|
|
2533
|
-
function writeHostCredentials(host, credentials) {
|
|
2534
|
-
const existing = readMachineCredentials2() ?? {};
|
|
2535
|
-
writeMachineCredentials2({ ...existing, tools: { ...existing.tools ?? {}, [host]: credentials } });
|
|
2536
|
-
}
|
|
2537
|
-
function removeHostCredentials(host) {
|
|
2538
|
-
const existing = readMachineCredentials2();
|
|
2539
|
-
if (!existing?.tools || !(host in existing.tools))
|
|
2540
|
-
return;
|
|
2541
|
-
const tools = { ...existing.tools };
|
|
2542
|
-
delete tools[host];
|
|
2543
|
-
const next = { ...existing };
|
|
2544
|
-
if (Object.keys(tools).length)
|
|
2545
|
-
next.tools = tools;
|
|
2546
|
-
else
|
|
2547
|
-
delete next.tools;
|
|
2548
|
-
writeMachineCredentials2(next);
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
});
|
|
2552
|
-
|
|
2553
2742
|
// ../packages/tool-kit/out/forgeProject.js
|
|
2554
2743
|
var require_forgeProject = __commonJS({
|
|
2555
2744
|
"../packages/tool-kit/out/forgeProject.js"(exports) {
|
|
@@ -3093,8 +3282,12 @@ var require_hookAdapter = __commonJS({
|
|
|
3093
3282
|
return;
|
|
3094
3283
|
const notice = options.onNotice ?? ((message) => console.error(message));
|
|
3095
3284
|
const hasToken = (id) => (0, tokenStore_1.readTokenFile)(process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0;
|
|
3096
|
-
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken))
|
|
3285
|
+
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken)) {
|
|
3286
|
+
const logFile = (0, eventLog_1.resolveEventLogPath)({ localOnly: true });
|
|
3287
|
+
if (logFile)
|
|
3288
|
+
logUnsent2(logFile, events, options);
|
|
3097
3289
|
return;
|
|
3290
|
+
}
|
|
3098
3291
|
let config;
|
|
3099
3292
|
try {
|
|
3100
3293
|
config = loadCliAgentConfig(options.toolType, options.sessionId, options.cwd, options);
|
|
@@ -3104,20 +3297,7 @@ var require_hookAdapter = __commonJS({
|
|
|
3104
3297
|
const logFile = (0, eventLog_1.resolveEventLogPath)();
|
|
3105
3298
|
if (!logFile)
|
|
3106
3299
|
throw error;
|
|
3107
|
-
|
|
3108
|
-
for (const event of events) {
|
|
3109
|
-
(0, eventLog_1.appendEventLog)(logFile, {
|
|
3110
|
-
loggedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3111
|
-
delivery: "not_sent",
|
|
3112
|
-
payload: (0, eventSender_1.buildEventPayload)({
|
|
3113
|
-
toolInstallationId: `${options.toolType}:unpaired`,
|
|
3114
|
-
source: options.source,
|
|
3115
|
-
sessionId: options.sessionId ?? null,
|
|
3116
|
-
workspaceHash: contextHashes.workspaceHash,
|
|
3117
|
-
projectHash: contextHashes.projectHash
|
|
3118
|
-
}, event)
|
|
3119
|
-
});
|
|
3120
|
-
}
|
|
3300
|
+
logUnsent2(logFile, events, options);
|
|
3121
3301
|
return;
|
|
3122
3302
|
}
|
|
3123
3303
|
const sender = new eventSender_1.AscendaEventSender({
|
|
@@ -3147,6 +3327,22 @@ var require_hookAdapter = __commonJS({
|
|
|
3147
3327
|
return;
|
|
3148
3328
|
}
|
|
3149
3329
|
}
|
|
3330
|
+
function logUnsent2(logFile, events, options) {
|
|
3331
|
+
const contextHashes = resolveContextHashes(options.cwd);
|
|
3332
|
+
for (const event of events) {
|
|
3333
|
+
(0, eventLog_1.appendEventLog)(logFile, {
|
|
3334
|
+
loggedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3335
|
+
delivery: "not_sent",
|
|
3336
|
+
payload: (0, eventSender_1.buildEventPayload)({
|
|
3337
|
+
toolInstallationId: `${options.toolType}:unpaired`,
|
|
3338
|
+
source: options.source,
|
|
3339
|
+
sessionId: process.env.ASCENDA_SESSION_ID?.trim() || options.sessionId || null,
|
|
3340
|
+
workspaceHash: contextHashes.workspaceHash,
|
|
3341
|
+
projectHash: contextHashes.projectHash
|
|
3342
|
+
}, event)
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3150
3346
|
function journalSkippedSend2(host, error) {
|
|
3151
3347
|
const who = host ? `${host}: ` : "";
|
|
3152
3348
|
(0, stateStore_1.recordSendOutcome)((0, stateStore_1.unresolvedStateFilePath)(error.toolType), (0, stateStore_1.unresolvedToolInstallationId)(error.toolType), "skipped_no_installation_id", {
|
|
@@ -3601,78 +3797,843 @@ var require_initiatives = __commonJS({
|
|
|
3601
3797
|
result: asResult(o.result)
|
|
3602
3798
|
};
|
|
3603
3799
|
}
|
|
3604
|
-
function asResult(value) {
|
|
3605
|
-
if (!value || typeof value !== "object")
|
|
3606
|
-
return null;
|
|
3607
|
-
const r = value;
|
|
3608
|
-
const num = (x) => typeof x === "number" && Number.isFinite(x) ? x : null;
|
|
3800
|
+
function asResult(value) {
|
|
3801
|
+
if (!value || typeof value !== "object")
|
|
3802
|
+
return null;
|
|
3803
|
+
const r = value;
|
|
3804
|
+
const num = (x) => typeof x === "number" && Number.isFinite(x) ? x : null;
|
|
3805
|
+
return {
|
|
3806
|
+
scoredAtUtc: typeof r.scoredAtUtc === "string" ? r.scoredAtUtc : "",
|
|
3807
|
+
value: num(r.value),
|
|
3808
|
+
baselineValue: num(r.baselineValue),
|
|
3809
|
+
delta: num(r.delta),
|
|
3810
|
+
movement: typeof r.movement === "string" ? r.movement : null,
|
|
3811
|
+
outcome: typeof r.outcome === "string" ? r.outcome : "",
|
|
3812
|
+
withheldReason: typeof r.withheldReason === "string" ? r.withheldReason : null,
|
|
3813
|
+
basis: typeof r.basis === "string" ? r.basis : null
|
|
3814
|
+
};
|
|
3815
|
+
}
|
|
3816
|
+
function formatWindowOrRaw(startUtc, endUtc) {
|
|
3817
|
+
if (Number.isNaN(Date.parse(startUtc)) || Number.isNaN(Date.parse(endUtc)))
|
|
3818
|
+
return "not given";
|
|
3819
|
+
return (0, studyJoin_1.formatWindow)(startUtc, endUtc);
|
|
3820
|
+
}
|
|
3821
|
+
function formatDay(iso) {
|
|
3822
|
+
const date = new Date(iso);
|
|
3823
|
+
if (Number.isNaN(date.getTime()))
|
|
3824
|
+
return iso;
|
|
3825
|
+
return new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" }).format(date);
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
});
|
|
3829
|
+
|
|
3830
|
+
// ../packages/tool-kit/out/setupDisclosure.js
|
|
3831
|
+
var require_setupDisclosure = __commonJS({
|
|
3832
|
+
"../packages/tool-kit/out/setupDisclosure.js"(exports) {
|
|
3833
|
+
"use strict";
|
|
3834
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3835
|
+
exports.FREE_TEXT_KEYS = exports.REFUSALS = exports.ALWAYS_SENT = exports.FAMILY_SENTENCES = void 0;
|
|
3836
|
+
exports.renderSetupDisclosure = renderSetupDisclosure3;
|
|
3837
|
+
exports.FAMILY_SENTENCES = {
|
|
3838
|
+
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",
|
|
3839
|
+
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",
|
|
3840
|
+
tools: "the name of each tool your agent calls",
|
|
3841
|
+
outcome: "whether a call succeeded, failed, or was interrupted",
|
|
3842
|
+
clock: "your machine's offset from UTC, so an evening is read as an evening",
|
|
3843
|
+
repo: "your project and branch as digests computed on this machine \u2014 never the names themselves",
|
|
3844
|
+
model: "which model served the session, by name and by tier",
|
|
3845
|
+
posture: "the permission posture your agent was working under \u2014 asking each time, accepting edits, and so on",
|
|
3846
|
+
git: "that a commit, push or revert happened, and when a pull request opened or merged",
|
|
3847
|
+
edits: "roughly how much a file changed, as a bucket, and whether you edited it after the agent wrote it",
|
|
3848
|
+
context: "how full the context window got",
|
|
3849
|
+
waiting: "that your agent stopped and waited for you, as one word: permission_request, idle_prompt, or other",
|
|
3850
|
+
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",
|
|
3851
|
+
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"
|
|
3852
|
+
};
|
|
3853
|
+
exports.ALWAYS_SENT = ["session", "counts", "tools", "outcome", "repo", "clock"];
|
|
3854
|
+
exports.REFUSALS = [
|
|
3855
|
+
"Never your prompts, your agent's replies, or anything inside a file.",
|
|
3856
|
+
"Never a file path, a command line, or a repository or branch name.",
|
|
3857
|
+
"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."
|
|
3858
|
+
];
|
|
3859
|
+
exports.FREE_TEXT_KEYS = ["message"];
|
|
3860
|
+
function renderSetupDisclosure3({ sends, displayName }) {
|
|
3861
|
+
const declared = /* @__PURE__ */ new Set([...exports.ALWAYS_SENT, ...sends]);
|
|
3862
|
+
const ordered = Object.keys(exports.FAMILY_SENTENCES).filter((family) => declared.has(family));
|
|
3863
|
+
const lines = [
|
|
3864
|
+
`What this sends from ${displayName}, once paired:`,
|
|
3865
|
+
...ordered.map((family) => ` \xB7 ${exports.FAMILY_SENTENCES[family]}`),
|
|
3866
|
+
"",
|
|
3867
|
+
...exports.REFUSALS.map((line) => ` ${line}`),
|
|
3868
|
+
"",
|
|
3869
|
+
" Turn it off by revoking this tool in the Ascenda app."
|
|
3870
|
+
];
|
|
3871
|
+
return lines.join("\n");
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
});
|
|
3875
|
+
|
|
3876
|
+
// ../packages/tool-kit/out/hookRunner.js
|
|
3877
|
+
var require_hookRunner = __commonJS({
|
|
3878
|
+
"../packages/tool-kit/out/hookRunner.js"(exports) {
|
|
3879
|
+
"use strict";
|
|
3880
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
3881
|
+
if (k2 === void 0) k2 = k;
|
|
3882
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3883
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3884
|
+
desc = { enumerable: true, get: function() {
|
|
3885
|
+
return m[k];
|
|
3886
|
+
} };
|
|
3887
|
+
}
|
|
3888
|
+
Object.defineProperty(o, k2, desc);
|
|
3889
|
+
} : function(o, m, k, k2) {
|
|
3890
|
+
if (k2 === void 0) k2 = k;
|
|
3891
|
+
o[k2] = m[k];
|
|
3892
|
+
});
|
|
3893
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
3894
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
3895
|
+
} : function(o, v) {
|
|
3896
|
+
o["default"] = v;
|
|
3897
|
+
});
|
|
3898
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
3899
|
+
var ownKeys = function(o) {
|
|
3900
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
3901
|
+
var ar = [];
|
|
3902
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
3903
|
+
return ar;
|
|
3904
|
+
};
|
|
3905
|
+
return ownKeys(o);
|
|
3906
|
+
};
|
|
3907
|
+
return function(mod) {
|
|
3908
|
+
if (mod && mod.__esModule) return mod;
|
|
3909
|
+
var result = {};
|
|
3910
|
+
if (mod != null) {
|
|
3911
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
3912
|
+
}
|
|
3913
|
+
__setModuleDefault(result, mod);
|
|
3914
|
+
return result;
|
|
3915
|
+
};
|
|
3916
|
+
}();
|
|
3917
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3918
|
+
exports.hookRunnerPaths = hookRunnerPaths;
|
|
3919
|
+
exports.hookLauncherScript = hookLauncherScript2;
|
|
3920
|
+
exports.installHookRunner = installHookRunner2;
|
|
3921
|
+
exports.removeHookRunner = removeHookRunner;
|
|
3922
|
+
exports.hookRunnerCommand = hookRunnerCommand2;
|
|
3923
|
+
exports.lastHookPath = lastHookPath;
|
|
3924
|
+
exports.stampLastHook = stampLastHook2;
|
|
3925
|
+
exports.readLastHook = readLastHook2;
|
|
3926
|
+
exports.describeAge = describeAge3;
|
|
3927
|
+
exports.resolveHookNode = resolveHookNode2;
|
|
3928
|
+
exports.tidyHomePath = tidyHomePath;
|
|
3929
|
+
var child_process_1 = __require("child_process");
|
|
3930
|
+
var fs5 = __importStar(__require("fs"));
|
|
3931
|
+
var path4 = __importStar(__require("path"));
|
|
3932
|
+
var tokenStore_1 = require_tokenStore();
|
|
3933
|
+
function hookRunnerPaths(binaryName) {
|
|
3934
|
+
const launcher = path4.join((0, tokenStore_1.ascendaHome)(), "bin", binaryName);
|
|
3935
|
+
return { launcher, bundle: `${launcher}.mjs`, record: `${launcher}.node`, noNode: `${launcher}.no-node` };
|
|
3936
|
+
}
|
|
3937
|
+
var LAUNCHER_MANAGEMENT_COMMANDS = ["setup", "install", "status", "uninstall", "doctor", "pair", "join", "object", "-h", "--help"];
|
|
3938
|
+
function hookLauncherScript2(options) {
|
|
3939
|
+
const { binaryName, setupCommand, loudEvent } = options;
|
|
3940
|
+
return [
|
|
3941
|
+
"#!/bin/sh",
|
|
3942
|
+
`# Ascenda hook launcher (${binaryName}). Written by \`setup\`, replaced by the`,
|
|
3943
|
+
"# next one; edits here are lost. Finds a Node to run the hook bundle beside it.",
|
|
3944
|
+
"",
|
|
3945
|
+
'dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || exit 0',
|
|
3946
|
+
`bundle="$dir/${binaryName}.mjs"`,
|
|
3947
|
+
`record="$dir/${binaryName}.node"`,
|
|
3948
|
+
`missing="$dir/${binaryName}.no-node"`,
|
|
3949
|
+
"",
|
|
3950
|
+
'runs() { [ -n "$1" ] && [ -f "$1" ] && [ -x "$1" ]; }',
|
|
3951
|
+
"",
|
|
3952
|
+
"# The hook bundle needs Node 20 or newer. Checked only while searching, so",
|
|
3953
|
+
"# the recorded path costs nothing to reuse.",
|
|
3954
|
+
"recent() {",
|
|
3955
|
+
` runs "$1" && "$1" -e 'process.exit(parseInt(process.versions.node, 10) >= 20 ? 0 : 1)' >/dev/null 2>&1`,
|
|
3956
|
+
"}",
|
|
3957
|
+
"",
|
|
3958
|
+
"newest_nvm() {",
|
|
3959
|
+
' [ -d "$HOME/.nvm/versions/node" ] || return 0',
|
|
3960
|
+
` 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/'`,
|
|
3961
|
+
"}",
|
|
3962
|
+
"",
|
|
3963
|
+
'node=""',
|
|
3964
|
+
"how=recorded",
|
|
3965
|
+
'[ -r "$record" ] && IFS= read -r node < "$record"',
|
|
3966
|
+
"",
|
|
3967
|
+
'if ! runs "$node"; then',
|
|
3968
|
+
' node=""',
|
|
3969
|
+
" how=found",
|
|
3970
|
+
' nvm_default=""',
|
|
3971
|
+
' if [ -r "$HOME/.nvm/alias/default" ]; then',
|
|
3972
|
+
' IFS= read -r wanted < "$HOME/.nvm/alias/default"',
|
|
3973
|
+
" wanted=${wanted#v}",
|
|
3974
|
+
' for candidate in "$HOME/.nvm/versions/node/v$wanted"*; do',
|
|
3975
|
+
' [ -x "$candidate/bin/node" ] && nvm_default="$candidate/bin/node"',
|
|
3976
|
+
" done",
|
|
3977
|
+
" fi",
|
|
3978
|
+
" nvm_newest=$(newest_nvm)",
|
|
3979
|
+
" for candidate in \\",
|
|
3980
|
+
' "$(command -v node 2>/dev/null)" \\',
|
|
3981
|
+
" /opt/homebrew/bin/node \\",
|
|
3982
|
+
" /usr/local/bin/node \\",
|
|
3983
|
+
' "$HOME/.volta/bin/node" \\',
|
|
3984
|
+
' "$nvm_default" \\',
|
|
3985
|
+
' "$HOME/.local/share/fnm/aliases/default/bin/node" \\',
|
|
3986
|
+
' "$HOME/Library/Application Support/fnm/aliases/default/bin/node" \\',
|
|
3987
|
+
' "$HOME/.asdf/shims/node" \\',
|
|
3988
|
+
' "$HOME/.local/share/mise/shims/node" \\',
|
|
3989
|
+
' "$HOME/.nvm/versions/node/$nvm_newest/bin/node"',
|
|
3990
|
+
" do",
|
|
3991
|
+
' if recent "$candidate"; then node=$candidate; break; fi',
|
|
3992
|
+
" done",
|
|
3993
|
+
' if [ -n "$node" ]; then',
|
|
3994
|
+
` printf '%s\\n' "$node" > "$record.$$" 2>/dev/null && mv -f "$record.$$" "$record" 2>/dev/null`,
|
|
3995
|
+
' rm -f "$missing" 2>/dev/null',
|
|
3996
|
+
" fi",
|
|
3997
|
+
"fi",
|
|
3998
|
+
"",
|
|
3999
|
+
'if [ -n "$ASCENDA_HOOK_LAUNCHER_PROBE" ]; then',
|
|
4000
|
+
' [ -n "$node" ] || { echo "no Node 20 or newer found on PATH or in the usual install locations" >&2; exit 1; }',
|
|
4001
|
+
` printf '%s\\t%s\\n' "$node" "$how"`,
|
|
4002
|
+
" exit 0",
|
|
4003
|
+
"fi",
|
|
4004
|
+
"",
|
|
4005
|
+
'if [ -z "$node" ]; then',
|
|
4006
|
+
' date -u +%Y-%m-%dT%H:%M:%SZ > "$missing" 2>/dev/null',
|
|
4007
|
+
' case "$1" in',
|
|
4008
|
+
...loudEvent ? [
|
|
4009
|
+
` ${loudEvent})`,
|
|
4010
|
+
" cat >/dev/null 2>&1",
|
|
4011
|
+
` echo "Ascenda hooks cannot find Node 20 or newer, so none of them are running. Install Node, then run: ${setupCommand}" >&2`,
|
|
4012
|
+
" exit 1 ;;"
|
|
4013
|
+
] : [],
|
|
4014
|
+
` ${LAUNCHER_MANAGEMENT_COMMANDS.join("|")})`,
|
|
4015
|
+
` echo "${binaryName}: no Node 20 or newer found on PATH or in the usual install locations." >&2`,
|
|
4016
|
+
" exit 1 ;;",
|
|
4017
|
+
" *)",
|
|
4018
|
+
" # A hook: say nothing per tool call. status and doctor read the",
|
|
4019
|
+
" # file written above.",
|
|
4020
|
+
" cat >/dev/null 2>&1",
|
|
4021
|
+
" exit 0 ;;",
|
|
4022
|
+
" esac",
|
|
4023
|
+
"fi",
|
|
4024
|
+
"",
|
|
4025
|
+
'exec "$node" "$bundle" "$@"',
|
|
4026
|
+
""
|
|
4027
|
+
].join("\n");
|
|
4028
|
+
}
|
|
4029
|
+
function installHookRunner2(options) {
|
|
4030
|
+
const paths = hookRunnerPaths(options.binaryName);
|
|
4031
|
+
if (options.dryRun)
|
|
4032
|
+
return paths.launcher;
|
|
4033
|
+
const source = path4.resolve(options.source ?? process.argv[1]);
|
|
4034
|
+
fs5.mkdirSync(path4.dirname(paths.launcher), { recursive: true });
|
|
4035
|
+
if (process.platform === "win32") {
|
|
4036
|
+
if (source !== path4.resolve(paths.launcher))
|
|
4037
|
+
fs5.copyFileSync(source, paths.launcher);
|
|
4038
|
+
return paths.launcher;
|
|
4039
|
+
}
|
|
4040
|
+
if (source !== path4.resolve(paths.bundle))
|
|
4041
|
+
writeAtomically(paths.bundle, fs5.readFileSync(source), 493);
|
|
4042
|
+
writeAtomically(paths.launcher, hookLauncherScript2(options), 493);
|
|
4043
|
+
writeAtomically(paths.record, `${process.execPath}
|
|
4044
|
+
`, 420);
|
|
4045
|
+
fs5.rmSync(paths.noNode, { force: true });
|
|
4046
|
+
return paths.launcher;
|
|
4047
|
+
}
|
|
4048
|
+
function removeHookRunner(binaryName) {
|
|
4049
|
+
const removed = [];
|
|
4050
|
+
for (const file of Object.values(hookRunnerPaths(binaryName))) {
|
|
4051
|
+
if (!fs5.existsSync(file))
|
|
4052
|
+
continue;
|
|
4053
|
+
fs5.rmSync(file, { force: true });
|
|
4054
|
+
removed.push(file);
|
|
4055
|
+
}
|
|
4056
|
+
return removed;
|
|
4057
|
+
}
|
|
4058
|
+
function hookRunnerCommand2(launcher) {
|
|
4059
|
+
return process.platform === "win32" ? `"${process.execPath}" "${launcher}"` : `"${launcher}"`;
|
|
4060
|
+
}
|
|
4061
|
+
function writeAtomically(target, contents, mode) {
|
|
4062
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
4063
|
+
fs5.writeFileSync(tmp, contents, { mode });
|
|
4064
|
+
fs5.chmodSync(tmp, mode);
|
|
4065
|
+
fs5.renameSync(tmp, target);
|
|
4066
|
+
}
|
|
4067
|
+
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path4.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
4068
|
+
function lastHookPath(tool) {
|
|
4069
|
+
return path4.join(stateDir(), `${tool}-last-hook.json`);
|
|
4070
|
+
}
|
|
4071
|
+
function stampLastHook2(tool, event, now = /* @__PURE__ */ new Date()) {
|
|
4072
|
+
try {
|
|
4073
|
+
fs5.mkdirSync(stateDir(), { recursive: true });
|
|
4074
|
+
const file = lastHookPath(tool);
|
|
4075
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
4076
|
+
fs5.writeFileSync(tmp, `${JSON.stringify({ event, at: now.toISOString() })}
|
|
4077
|
+
`, { mode: 384 });
|
|
4078
|
+
fs5.renameSync(tmp, file);
|
|
4079
|
+
} catch {
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
function readLastHook2(tool) {
|
|
4083
|
+
try {
|
|
4084
|
+
const parsed = JSON.parse(fs5.readFileSync(lastHookPath(tool), "utf8"));
|
|
4085
|
+
if (typeof parsed.event !== "string" || typeof parsed.at !== "string")
|
|
4086
|
+
return void 0;
|
|
4087
|
+
return { event: parsed.event, at: parsed.at };
|
|
4088
|
+
} catch {
|
|
4089
|
+
return void 0;
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
function describeAge3(ms) {
|
|
4093
|
+
if (!Number.isFinite(ms) || ms < 0)
|
|
4094
|
+
return "just now";
|
|
4095
|
+
const seconds = Math.round(ms / 1e3);
|
|
4096
|
+
if (seconds < 60)
|
|
4097
|
+
return `${seconds} s ago`;
|
|
4098
|
+
const minutes = Math.round(seconds / 60);
|
|
4099
|
+
if (minutes < 60)
|
|
4100
|
+
return `${minutes} min ago`;
|
|
4101
|
+
const hours = Math.round(minutes / 60);
|
|
4102
|
+
if (hours < 48)
|
|
4103
|
+
return `${hours} h ago`;
|
|
4104
|
+
return `${Math.round(hours / 24)} days ago`;
|
|
4105
|
+
}
|
|
4106
|
+
function resolveHookNode2(launcher) {
|
|
4107
|
+
if (!fs5.existsSync(launcher))
|
|
4108
|
+
return { problem: "the hook launcher is not installed" };
|
|
4109
|
+
const probe = (0, child_process_1.spawnSync)("/bin/sh", [launcher], {
|
|
4110
|
+
encoding: "utf8",
|
|
4111
|
+
timeout: 5e3,
|
|
4112
|
+
env: { HOME: process.env.HOME ?? "", PATH: "/usr/bin:/bin:/usr/sbin:/sbin", ASCENDA_HOOK_LAUNCHER_PROBE: "1" }
|
|
4113
|
+
});
|
|
4114
|
+
const [node, how] = (probe.stdout ?? "").trim().split(" ");
|
|
4115
|
+
if (probe.status !== 0 || !node) {
|
|
4116
|
+
return { problem: (probe.stderr ?? "").trim() || "the launcher found no Node it can run" };
|
|
4117
|
+
}
|
|
4118
|
+
const version = (0, child_process_1.spawnSync)(node, ["--version"], { encoding: "utf8", timeout: 5e3 });
|
|
4119
|
+
if (version.status !== 0)
|
|
4120
|
+
return { node, how, problem: `${node} did not run` };
|
|
4121
|
+
return { node, how, version: version.stdout.trim() };
|
|
4122
|
+
}
|
|
4123
|
+
function tidyHomePath(file, home = process.env.HOME ?? "") {
|
|
4124
|
+
return home && file.startsWith(`${home}/`) ? `~${file.slice(home.length)}` : file;
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
});
|
|
4128
|
+
|
|
4129
|
+
// ../packages/tool-kit/out/saverHandoff.js
|
|
4130
|
+
var require_saverHandoff = __commonJS({
|
|
4131
|
+
"../packages/tool-kit/out/saverHandoff.js"(exports) {
|
|
4132
|
+
"use strict";
|
|
4133
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4134
|
+
if (k2 === void 0) k2 = k;
|
|
4135
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4136
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4137
|
+
desc = { enumerable: true, get: function() {
|
|
4138
|
+
return m[k];
|
|
4139
|
+
} };
|
|
4140
|
+
}
|
|
4141
|
+
Object.defineProperty(o, k2, desc);
|
|
4142
|
+
} : function(o, m, k, k2) {
|
|
4143
|
+
if (k2 === void 0) k2 = k;
|
|
4144
|
+
o[k2] = m[k];
|
|
4145
|
+
});
|
|
4146
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4147
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4148
|
+
} : function(o, v) {
|
|
4149
|
+
o["default"] = v;
|
|
4150
|
+
});
|
|
4151
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4152
|
+
var ownKeys = function(o) {
|
|
4153
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4154
|
+
var ar = [];
|
|
4155
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4156
|
+
return ar;
|
|
4157
|
+
};
|
|
4158
|
+
return ownKeys(o);
|
|
4159
|
+
};
|
|
4160
|
+
return function(mod) {
|
|
4161
|
+
if (mod && mod.__esModule) return mod;
|
|
4162
|
+
var result = {};
|
|
4163
|
+
if (mod != null) {
|
|
4164
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4165
|
+
}
|
|
4166
|
+
__setModuleDefault(result, mod);
|
|
4167
|
+
return result;
|
|
4168
|
+
};
|
|
4169
|
+
}();
|
|
4170
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4171
|
+
exports.SAVER_REPLAY_SCHEMA = exports.SAVER_REPLAY_WINDOW_MS = void 0;
|
|
4172
|
+
exports.saverContainerDir = saverContainerDir;
|
|
4173
|
+
exports.saverSupportDir = saverSupportDir;
|
|
4174
|
+
exports.saverReplayPath = saverReplayPath;
|
|
4175
|
+
exports.saverStatusDir = saverStatusDir;
|
|
4176
|
+
exports.holdForSaver = holdForSaver;
|
|
4177
|
+
exports.heldForSaver = heldForSaver;
|
|
4178
|
+
exports.readSaverStatuses = readSaverStatuses;
|
|
4179
|
+
exports.probeSocket = probeSocket;
|
|
4180
|
+
var fs5 = __importStar(__require("fs"));
|
|
4181
|
+
var net = __importStar(__require("net"));
|
|
4182
|
+
var os5 = __importStar(__require("os"));
|
|
4183
|
+
var path4 = __importStar(__require("path"));
|
|
4184
|
+
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4185
|
+
function saverContainerDir() {
|
|
4186
|
+
return process.env.ASCENDA_SAVER_CONTAINER ?? path4.join(os5.homedir(), "Library", "Containers", SAVER_HOST_BUNDLE_ID, "Data");
|
|
4187
|
+
}
|
|
4188
|
+
function saverSupportDir() {
|
|
4189
|
+
return path4.join(saverContainerDir(), "Library", "Application Support", "AscendaWaterlineSaver");
|
|
4190
|
+
}
|
|
4191
|
+
function saverReplayPath() {
|
|
4192
|
+
return path4.join(saverContainerDir(), "l.replay.json");
|
|
4193
|
+
}
|
|
4194
|
+
function saverStatusDir() {
|
|
4195
|
+
return path4.join(saverSupportDir(), "status");
|
|
4196
|
+
}
|
|
4197
|
+
exports.SAVER_REPLAY_WINDOW_MS = 30 * 60 * 1e3;
|
|
4198
|
+
var SAVER_REPLAY_MAX = 32;
|
|
4199
|
+
exports.SAVER_REPLAY_SCHEMA = 1;
|
|
4200
|
+
function holdForSaver(signal, now = Date.now()) {
|
|
4201
|
+
try {
|
|
4202
|
+
if (process.env.ASCENDA_LIVE_BUS_SOCKET && !process.env.ASCENDA_SAVER_CONTAINER)
|
|
4203
|
+
return;
|
|
4204
|
+
if (!fs5.existsSync(saverSupportDir()))
|
|
4205
|
+
return;
|
|
4206
|
+
const wire = signal;
|
|
4207
|
+
const tool = wire.tool;
|
|
4208
|
+
const session = wire.session;
|
|
4209
|
+
const event = wire.event;
|
|
4210
|
+
if (typeof tool !== "string" || typeof session !== "string" || typeof event !== "string")
|
|
4211
|
+
return;
|
|
4212
|
+
const file = saverReplayPath();
|
|
4213
|
+
const kept = readHeld(file).filter((held) => now - held.at <= exports.SAVER_REPLAY_WINDOW_MS && !(held.tool === tool && held.session === session));
|
|
4214
|
+
kept.push({ ...wire, tool, session, event, at: now });
|
|
4215
|
+
kept.sort((a, b) => a.at - b.at);
|
|
4216
|
+
const body = JSON.stringify({ schema: exports.SAVER_REPLAY_SCHEMA, signals: kept.slice(-SAVER_REPLAY_MAX) });
|
|
4217
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
4218
|
+
fs5.writeFileSync(tmp, `${body}
|
|
4219
|
+
`, { mode: 384 });
|
|
4220
|
+
fs5.renameSync(tmp, file);
|
|
4221
|
+
} catch {
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
function readHeld(file) {
|
|
4225
|
+
try {
|
|
4226
|
+
const parsed = JSON.parse(fs5.readFileSync(file, "utf8"));
|
|
4227
|
+
if (parsed.schema !== exports.SAVER_REPLAY_SCHEMA || !Array.isArray(parsed.signals))
|
|
4228
|
+
return [];
|
|
4229
|
+
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");
|
|
4230
|
+
} catch {
|
|
4231
|
+
return [];
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
function heldForSaver(now = Date.now()) {
|
|
4235
|
+
const held = readHeld(saverReplayPath()).filter((entry) => now - entry.at <= exports.SAVER_REPLAY_WINDOW_MS);
|
|
4236
|
+
if (held.length === 0)
|
|
4237
|
+
return { count: 0 };
|
|
4238
|
+
return { count: held.length, newestAgeMs: now - Math.max(...held.map((entry) => entry.at)) };
|
|
4239
|
+
}
|
|
4240
|
+
function readSaverStatuses(now = Date.now()) {
|
|
4241
|
+
let names;
|
|
4242
|
+
try {
|
|
4243
|
+
names = fs5.readdirSync(saverStatusDir()).filter((name) => name.endsWith(".json"));
|
|
4244
|
+
} catch {
|
|
4245
|
+
return [];
|
|
4246
|
+
}
|
|
4247
|
+
const readings = [];
|
|
4248
|
+
for (const name of names) {
|
|
4249
|
+
try {
|
|
4250
|
+
const status = JSON.parse(fs5.readFileSync(path4.join(saverStatusDir(), name), "utf8"));
|
|
4251
|
+
if (typeof status.pid !== "number" || typeof status.updatedAt !== "string")
|
|
4252
|
+
continue;
|
|
4253
|
+
readings.push({ ...status, alive: processAlive(status.pid), ageMs: now - Date.parse(status.updatedAt) });
|
|
4254
|
+
} catch {
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
return readings.sort((a, b) => a.ageMs - b.ageMs);
|
|
4258
|
+
}
|
|
4259
|
+
function processAlive(pid) {
|
|
4260
|
+
try {
|
|
4261
|
+
process.kill(pid, 0);
|
|
4262
|
+
return true;
|
|
4263
|
+
} catch (error) {
|
|
4264
|
+
return error.code === "EPERM";
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
function probeSocket(socketPath, timeoutMs = 300) {
|
|
4268
|
+
return new Promise((resolve2) => {
|
|
4269
|
+
try {
|
|
4270
|
+
if (!fs5.statSync(socketPath).isSocket()) {
|
|
4271
|
+
resolve2("absent");
|
|
4272
|
+
return;
|
|
4273
|
+
}
|
|
4274
|
+
} catch {
|
|
4275
|
+
resolve2("absent");
|
|
4276
|
+
return;
|
|
4277
|
+
}
|
|
4278
|
+
let settled = false;
|
|
4279
|
+
const finish = (state) => {
|
|
4280
|
+
if (settled)
|
|
4281
|
+
return;
|
|
4282
|
+
settled = true;
|
|
4283
|
+
clearTimeout(timer);
|
|
4284
|
+
socket.destroy();
|
|
4285
|
+
resolve2(state);
|
|
4286
|
+
};
|
|
4287
|
+
const socket = net.createConnection(socketPath);
|
|
4288
|
+
const timer = setTimeout(() => finish("unreachable"), timeoutMs);
|
|
4289
|
+
socket.on("connect", () => finish("listening"));
|
|
4290
|
+
socket.on("error", (error) => finish(error.code === "ECONNREFUSED" || error.code === "ENOENT" ? "stale" : "unreachable"));
|
|
4291
|
+
});
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
});
|
|
4295
|
+
|
|
4296
|
+
// ../packages/tool-kit/out/liveBus.js
|
|
4297
|
+
var require_liveBus = __commonJS({
|
|
4298
|
+
"../packages/tool-kit/out/liveBus.js"(exports) {
|
|
4299
|
+
"use strict";
|
|
4300
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4301
|
+
if (k2 === void 0) k2 = k;
|
|
4302
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4303
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4304
|
+
desc = { enumerable: true, get: function() {
|
|
4305
|
+
return m[k];
|
|
4306
|
+
} };
|
|
4307
|
+
}
|
|
4308
|
+
Object.defineProperty(o, k2, desc);
|
|
4309
|
+
} : function(o, m, k, k2) {
|
|
4310
|
+
if (k2 === void 0) k2 = k;
|
|
4311
|
+
o[k2] = m[k];
|
|
4312
|
+
});
|
|
4313
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4314
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4315
|
+
} : function(o, v) {
|
|
4316
|
+
o["default"] = v;
|
|
4317
|
+
});
|
|
4318
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4319
|
+
var ownKeys = function(o) {
|
|
4320
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4321
|
+
var ar = [];
|
|
4322
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4323
|
+
return ar;
|
|
4324
|
+
};
|
|
4325
|
+
return ownKeys(o);
|
|
4326
|
+
};
|
|
4327
|
+
return function(mod) {
|
|
4328
|
+
if (mod && mod.__esModule) return mod;
|
|
4329
|
+
var result = {};
|
|
4330
|
+
if (mod != null) {
|
|
4331
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4332
|
+
}
|
|
4333
|
+
__setModuleDefault(result, mod);
|
|
4334
|
+
return result;
|
|
4335
|
+
};
|
|
4336
|
+
}();
|
|
4337
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4338
|
+
exports.SAVER_HOST_BUNDLE_ID = exports.LIVE_BUS_BACKGROUND_TRUST_MS = void 0;
|
|
4339
|
+
exports.liveBusSocketCandidates = liveBusSocketCandidates;
|
|
4340
|
+
exports.existingSocketCandidates = existingSocketCandidates;
|
|
4341
|
+
exports.liveBusSocketPath = liveBusSocketPath;
|
|
4342
|
+
exports.bucketPromptSize = bucketPromptSize2;
|
|
4343
|
+
exports.emitLiveSignal = emitLiveSignal2;
|
|
4344
|
+
exports.deliverLine = deliverLine;
|
|
4345
|
+
var fs5 = __importStar(__require("fs"));
|
|
4346
|
+
var net = __importStar(__require("net"));
|
|
4347
|
+
var os5 = __importStar(__require("os"));
|
|
4348
|
+
var path4 = __importStar(__require("path"));
|
|
4349
|
+
var hookSet_1 = require_hookSet();
|
|
4350
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
4351
|
+
var WRITE_TIMEOUT_MS = 50;
|
|
4352
|
+
exports.LIVE_BUS_BACKGROUND_TRUST_MS = 60 * 60 * 1e3;
|
|
4353
|
+
var APP_BUNDLE_ID = "one.ascenda.ascendaMissionControl";
|
|
4354
|
+
exports.SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4355
|
+
function liveBusSocketCandidates() {
|
|
4356
|
+
const override = process.env.ASCENDA_LIVE_BUS_SOCKET;
|
|
4357
|
+
if (override)
|
|
4358
|
+
return [override];
|
|
4359
|
+
const home = os5.homedir();
|
|
4360
|
+
return [
|
|
4361
|
+
path4.join(home, ".ascenda", "live.sock"),
|
|
4362
|
+
path4.join(home, "Library", "Containers", APP_BUNDLE_ID, "Data", ".ascenda", "live.sock"),
|
|
4363
|
+
path4.join(home, "Library", "Containers", exports.SAVER_HOST_BUNDLE_ID, "Data", "l.sock")
|
|
4364
|
+
];
|
|
4365
|
+
}
|
|
4366
|
+
function existingSocketCandidates() {
|
|
4367
|
+
const candidates = liveBusSocketCandidates();
|
|
4368
|
+
if (process.env.ASCENDA_LIVE_BUS_SOCKET)
|
|
4369
|
+
return candidates;
|
|
4370
|
+
return candidates.filter((candidate) => {
|
|
4371
|
+
try {
|
|
4372
|
+
return fs5.statSync(candidate).isSocket();
|
|
4373
|
+
} catch {
|
|
4374
|
+
return false;
|
|
4375
|
+
}
|
|
4376
|
+
});
|
|
4377
|
+
}
|
|
4378
|
+
function liveBusSocketPath() {
|
|
4379
|
+
return existingSocketCandidates()[0] ?? liveBusSocketCandidates()[0];
|
|
4380
|
+
}
|
|
4381
|
+
function bucketPromptSize2(text) {
|
|
4382
|
+
const length = typeof text === "string" ? text.length : 0;
|
|
4383
|
+
if (length <= 280)
|
|
4384
|
+
return "s";
|
|
4385
|
+
if (length <= 2e3)
|
|
4386
|
+
return "m";
|
|
4387
|
+
if (length <= 8e3)
|
|
4388
|
+
return "l";
|
|
4389
|
+
return "xl";
|
|
4390
|
+
}
|
|
4391
|
+
var NOBODY_LISTENING = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOENT"]);
|
|
4392
|
+
function onTheWire(signal) {
|
|
4393
|
+
const out = { ...signal };
|
|
4394
|
+
if ("hookSet" in out && !(0, hookSet_1.isHookSet)(out.hookSet))
|
|
4395
|
+
delete out.hookSet;
|
|
4396
|
+
if ("viaPlugin" in out && out.viaPlugin !== true)
|
|
4397
|
+
delete out.viaPlugin;
|
|
4398
|
+
return out;
|
|
4399
|
+
}
|
|
4400
|
+
function emitLiveSignal2(signal) {
|
|
4401
|
+
const wire = onTheWire(signal);
|
|
4402
|
+
return deliverLine(`${JSON.stringify(wire)}
|
|
4403
|
+
`).then((delivered) => {
|
|
4404
|
+
if (!delivered)
|
|
4405
|
+
(0, saverHandoff_1.holdForSaver)(wire);
|
|
4406
|
+
});
|
|
4407
|
+
}
|
|
4408
|
+
function deliverLine(line) {
|
|
4409
|
+
return new Promise((resolve2) => {
|
|
4410
|
+
const candidates = existingSocketCandidates();
|
|
4411
|
+
if (candidates.length === 0) {
|
|
4412
|
+
resolve2(void 0);
|
|
4413
|
+
return;
|
|
4414
|
+
}
|
|
4415
|
+
let settled = false;
|
|
4416
|
+
let accepted;
|
|
4417
|
+
let socket;
|
|
4418
|
+
const drop = () => {
|
|
4419
|
+
try {
|
|
4420
|
+
socket?.destroy();
|
|
4421
|
+
} catch {
|
|
4422
|
+
}
|
|
4423
|
+
socket = void 0;
|
|
4424
|
+
};
|
|
4425
|
+
const done = () => {
|
|
4426
|
+
if (settled)
|
|
4427
|
+
return;
|
|
4428
|
+
settled = true;
|
|
4429
|
+
clearTimeout(timer);
|
|
4430
|
+
drop();
|
|
4431
|
+
resolve2(accepted);
|
|
4432
|
+
};
|
|
4433
|
+
const timer = setTimeout(done, WRITE_TIMEOUT_MS);
|
|
4434
|
+
const tryFrom = (index) => {
|
|
4435
|
+
if (settled)
|
|
4436
|
+
return;
|
|
4437
|
+
if (index >= candidates.length) {
|
|
4438
|
+
done();
|
|
4439
|
+
return;
|
|
4440
|
+
}
|
|
4441
|
+
let attempt;
|
|
4442
|
+
try {
|
|
4443
|
+
attempt = net.createConnection(candidates[index]);
|
|
4444
|
+
} catch {
|
|
4445
|
+
tryFrom(index + 1);
|
|
4446
|
+
return;
|
|
4447
|
+
}
|
|
4448
|
+
socket = attempt;
|
|
4449
|
+
if (typeof attempt.unref === "function")
|
|
4450
|
+
attempt.unref();
|
|
4451
|
+
let connected = false;
|
|
4452
|
+
attempt.on("error", (error) => {
|
|
4453
|
+
if (settled || socket !== attempt)
|
|
4454
|
+
return;
|
|
4455
|
+
if (!connected && error.code && NOBODY_LISTENING.has(error.code)) {
|
|
4456
|
+
drop();
|
|
4457
|
+
tryFrom(index + 1);
|
|
4458
|
+
return;
|
|
4459
|
+
}
|
|
4460
|
+
done();
|
|
4461
|
+
});
|
|
4462
|
+
attempt.on("connect", () => {
|
|
4463
|
+
if (settled || socket !== attempt)
|
|
4464
|
+
return;
|
|
4465
|
+
connected = true;
|
|
4466
|
+
accepted = candidates[index];
|
|
4467
|
+
try {
|
|
4468
|
+
attempt.write(line, done);
|
|
4469
|
+
} catch {
|
|
4470
|
+
done();
|
|
4471
|
+
}
|
|
4472
|
+
});
|
|
4473
|
+
};
|
|
4474
|
+
tryFrom(0);
|
|
4475
|
+
});
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
});
|
|
4479
|
+
|
|
4480
|
+
// ../packages/tool-kit/out/terminalStyle.js
|
|
4481
|
+
var require_terminalStyle = __commonJS({
|
|
4482
|
+
"../packages/tool-kit/out/terminalStyle.js"(exports) {
|
|
4483
|
+
"use strict";
|
|
4484
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4485
|
+
exports.colourEnabled = colourEnabled;
|
|
4486
|
+
exports.terminalStyle = terminalStyle3;
|
|
4487
|
+
function colourEnabled(stream = process.stdout, env = process.env) {
|
|
4488
|
+
if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "")
|
|
4489
|
+
return false;
|
|
4490
|
+
if (env.FORCE_COLOR !== void 0)
|
|
4491
|
+
return env.FORCE_COLOR !== "0";
|
|
4492
|
+
if (env.TERM === "dumb")
|
|
4493
|
+
return false;
|
|
4494
|
+
return Boolean(stream.isTTY);
|
|
4495
|
+
}
|
|
4496
|
+
function terminalStyle3(enabled = colourEnabled()) {
|
|
4497
|
+
const wrap = (open, close) => (text) => enabled ? `\x1B[${open}m${text}\x1B[${close}m` : text;
|
|
4498
|
+
const bold = wrap(1, 22);
|
|
4499
|
+
const dim = wrap(2, 22);
|
|
4500
|
+
const green = wrap(32, 39);
|
|
4501
|
+
const yellow = wrap(33, 39);
|
|
4502
|
+
const red = wrap(31, 39);
|
|
4503
|
+
const cyan = wrap(36, 39);
|
|
4504
|
+
const colour = { ok: green, warn: yellow, bad: red, info: dim };
|
|
4505
|
+
const marks = { ok: "\u2713", warn: "!", bad: "\u2717", info: "\xB7" };
|
|
3609
4506
|
return {
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
4507
|
+
enabled,
|
|
4508
|
+
bold,
|
|
4509
|
+
dim,
|
|
4510
|
+
green,
|
|
4511
|
+
yellow,
|
|
4512
|
+
red,
|
|
4513
|
+
cyan,
|
|
4514
|
+
mark: (tone) => colour[tone](marks[tone]),
|
|
4515
|
+
tone: (tone, text) => colour[tone](text)
|
|
3618
4516
|
};
|
|
3619
4517
|
}
|
|
3620
|
-
function formatWindowOrRaw(startUtc, endUtc) {
|
|
3621
|
-
if (Number.isNaN(Date.parse(startUtc)) || Number.isNaN(Date.parse(endUtc)))
|
|
3622
|
-
return "not given";
|
|
3623
|
-
return (0, studyJoin_1.formatWindow)(startUtc, endUtc);
|
|
3624
|
-
}
|
|
3625
|
-
function formatDay(iso) {
|
|
3626
|
-
const date = new Date(iso);
|
|
3627
|
-
if (Number.isNaN(date.getTime()))
|
|
3628
|
-
return iso;
|
|
3629
|
-
return new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" }).format(date);
|
|
3630
|
-
}
|
|
3631
4518
|
}
|
|
3632
4519
|
});
|
|
3633
4520
|
|
|
3634
|
-
// ../packages/tool-kit/out/
|
|
3635
|
-
var
|
|
3636
|
-
"../packages/tool-kit/out/
|
|
4521
|
+
// ../packages/tool-kit/out/liveSignalDoctor.js
|
|
4522
|
+
var require_liveSignalDoctor = __commonJS({
|
|
4523
|
+
"../packages/tool-kit/out/liveSignalDoctor.js"(exports) {
|
|
3637
4524
|
"use strict";
|
|
3638
4525
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3639
|
-
exports.
|
|
3640
|
-
exports.
|
|
3641
|
-
exports.
|
|
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
|
-
|
|
3673
|
-
"
|
|
3674
|
-
|
|
3675
|
-
|
|
4526
|
+
exports.DOCTOR_VALUE_COLUMN = void 0;
|
|
4527
|
+
exports.doctorRow = doctorRow2;
|
|
4528
|
+
exports.liveSignalDoctorLines = liveSignalDoctorLines2;
|
|
4529
|
+
var hookRunner_1 = require_hookRunner();
|
|
4530
|
+
var liveBus_1 = require_liveBus();
|
|
4531
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
4532
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
4533
|
+
exports.DOCTOR_VALUE_COLUMN = 25;
|
|
4534
|
+
function doctorRow2(ui, tone, label, value) {
|
|
4535
|
+
return ` ${ui.mark(tone)} ${label.padEnd(exports.DOCTOR_VALUE_COLUMN - 5)} ${value}`;
|
|
4536
|
+
}
|
|
4537
|
+
async function liveSignalDoctorLines2(options) {
|
|
4538
|
+
const ui = options.ui ?? (0, terminalStyle_1.terminalStyle)();
|
|
4539
|
+
const lines = [` ${ui.bold("Live signal")} ${ui.dim("(this machine; needs no pairing)")}`];
|
|
4540
|
+
const now = Date.now();
|
|
4541
|
+
let problems = 0;
|
|
4542
|
+
const row = (tone, label, value) => {
|
|
4543
|
+
if (tone === "bad" || tone === "warn")
|
|
4544
|
+
problems += 1;
|
|
4545
|
+
lines.push(doctorRow2(ui, tone, label, tone === "bad" ? ui.red(value) : value));
|
|
4546
|
+
};
|
|
4547
|
+
const more = (value) => lines.push(`${" ".repeat(exports.DOCTOR_VALUE_COLUMN)}${value}`);
|
|
4548
|
+
if (options.launcher && process.platform !== "win32") {
|
|
4549
|
+
const node = (0, hookRunner_1.resolveHookNode)(options.launcher);
|
|
4550
|
+
if (node.problem)
|
|
4551
|
+
row("bad", "Node", `${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
4552
|
+
else
|
|
4553
|
+
row("ok", "Node", `${node.node} ${ui.dim(`(${node.version}, ${node.how === "recorded" ? "recorded at setup" : "found by the launcher"})`)}`);
|
|
4554
|
+
}
|
|
4555
|
+
if (options.registrations.length === 0)
|
|
4556
|
+
row("bad", "Hooks", `not registered. Run: ${options.setupCommand}`);
|
|
4557
|
+
for (const entry of options.registrations) {
|
|
4558
|
+
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";
|
|
4559
|
+
const complete = entry.registered === options.eventCount;
|
|
4560
|
+
row(entry.homeProject || !complete ? "warn" : entry.scope === "user" ? "ok" : "info", "Hooks", `${entry.registered}/${options.eventCount} in ${entry.file} ${ui.dim(`(${where})`)}`);
|
|
4561
|
+
}
|
|
4562
|
+
if (options.registrations.length > 1) {
|
|
4563
|
+
problems += 1;
|
|
4564
|
+
more(ui.yellow("Registered in more than one file, so each event runs more than once. Run setup again to fix."));
|
|
4565
|
+
}
|
|
4566
|
+
const last = (0, hookRunner_1.readLastHook)(options.tool);
|
|
4567
|
+
if (last)
|
|
4568
|
+
row("ok", "Last hook", `${last.event}, ${(0, hookRunner_1.describeAge)(now - Date.parse(last.at))}`);
|
|
4569
|
+
else
|
|
4570
|
+
row("info", "Last hook", `none yet. Start ${options.displayName} (restart it if it was open during setup)${options.lookHint ? `, then ${options.lookHint}` : ""}`);
|
|
4571
|
+
const [appSocket, appContainerSocket, saverSocket] = (0, liveBus_1.liveBusSocketCandidates)();
|
|
4572
|
+
const appState = await (0, saverHandoff_1.probeSocket)(appSocket);
|
|
4573
|
+
const legacyState = appContainerSocket ? await (0, saverHandoff_1.probeSocket)(appContainerSocket) : "absent";
|
|
4574
|
+
if (appState === "listening" || legacyState === "listening")
|
|
4575
|
+
row("ok", "Desktop app", "listening. It takes every signal, and the saver mirrors it");
|
|
4576
|
+
else
|
|
4577
|
+
row("info", "Desktop app", "not listening");
|
|
4578
|
+
const saverState = saverSocket ? await (0, saverHandoff_1.probeSocket)(saverSocket) : "absent";
|
|
4579
|
+
const live = (0, saverHandoff_1.readSaverStatuses)(now).filter((status) => status.alive);
|
|
4580
|
+
const holder = live.find((status) => status.ownsBus);
|
|
4581
|
+
const saver = describeSaver(saverState, holder, live);
|
|
4582
|
+
row(saver.tone, "Screen saver", saver.text);
|
|
4583
|
+
for (const status of live)
|
|
4584
|
+
more(ui.dim(describeProcess(status, now)));
|
|
4585
|
+
const held = (0, saverHandoff_1.heldForSaver)(now);
|
|
4586
|
+
if (held.count > 0) {
|
|
4587
|
+
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`);
|
|
4588
|
+
}
|
|
4589
|
+
const trip = await pingRoundTrip(saverSocket, options.selfCommand);
|
|
4590
|
+
row(trip.tone, "Round trip", trip.text);
|
|
4591
|
+
lines.push("");
|
|
4592
|
+
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.`);
|
|
4593
|
+
return lines;
|
|
4594
|
+
}
|
|
4595
|
+
function describeSaver(state, holder, live) {
|
|
4596
|
+
if (state === "listening") {
|
|
4597
|
+
if (!holder)
|
|
4598
|
+
return { tone: "warn", text: "listening, from a process that isn't reporting. Restart it: killall legacyScreenSaver" };
|
|
4599
|
+
if (holder.saverViews === 0) {
|
|
4600
|
+
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` };
|
|
4601
|
+
}
|
|
4602
|
+
return { tone: "ok", text: `listening, pid ${holder.pid}, on screen` };
|
|
4603
|
+
}
|
|
4604
|
+
if (state === "stale")
|
|
4605
|
+
return { tone: "info", text: "not running (a socket file was left behind, which is harmless)" };
|
|
4606
|
+
if (live.some((status) => status.previewViews > 0)) {
|
|
4607
|
+
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" };
|
|
4608
|
+
}
|
|
4609
|
+
return { tone: "info", text: "not running. That's normal: it listens only while it's on screen" };
|
|
4610
|
+
}
|
|
4611
|
+
function describeProcess(status, now) {
|
|
4612
|
+
const what = [
|
|
4613
|
+
status.saverViews > 0 ? `saver on ${status.saverViews} display${status.saverViews === 1 ? "" : "s"}` : void 0,
|
|
4614
|
+
status.previewViews > 0 ? "preview" : void 0
|
|
4615
|
+
].filter(Boolean).join(" + ") || "not drawing";
|
|
4616
|
+
const heard = status.lastSignalAt ? `last signal ${status.lastSignalEvent ?? ""} ${(0, hookRunner_1.describeAge)(now - Date.parse(status.lastSignalAt))}`.replace(/\s+/g, " ") : "no signal yet";
|
|
4617
|
+
const replay = status.replayed > 0 ? `, replayed ${status.replayed} since this process started` : "";
|
|
4618
|
+
const beat = status.ageMs > 1e4 ? `, heartbeat ${(0, hookRunner_1.describeAge)(status.ageMs)} (not animating)` : "";
|
|
4619
|
+
return `pid ${status.pid} ${status.version ?? ""}: ${what}, ${status.mode ?? "?"}${status.ownsBus ? ", owns the socket" : ""}, ${heard}${replay}${beat}`.replace(/\s+:/, ":");
|
|
4620
|
+
}
|
|
4621
|
+
async function pingRoundTrip(saverSocket, selfCommand2) {
|
|
4622
|
+
const session = `doctor-${process.pid}-${Date.now()}`;
|
|
4623
|
+
const accepted = await (0, liveBus_1.deliverLine)(`${JSON.stringify({ tool: "doctor", session, event: "ping" })}
|
|
4624
|
+
`);
|
|
4625
|
+
if (!accepted) {
|
|
4626
|
+
return { tone: "info", text: `nobody is listening right now, so there is nothing to test. To test the saver: open -a ScreenSaverEngine; sleep 5; ${selfCommand2} doctor` };
|
|
4627
|
+
}
|
|
4628
|
+
if (accepted !== saverSocket)
|
|
4629
|
+
return { tone: "ok", text: `the desktop app took it (${accepted})` };
|
|
4630
|
+
for (let waited = 0; waited < 2e3; waited += 100) {
|
|
4631
|
+
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
4632
|
+
const answered = (0, saverHandoff_1.readSaverStatuses)().find((status) => status.lastPingSession === session);
|
|
4633
|
+
if (answered)
|
|
4634
|
+
return { tone: "ok", text: `OK. The screen saver (pid ${answered.pid}) received it` };
|
|
4635
|
+
}
|
|
4636
|
+
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" };
|
|
3676
4637
|
}
|
|
3677
4638
|
}
|
|
3678
4639
|
});
|
|
@@ -3926,37 +4887,47 @@ var require_cliAgentSetup = __commonJS({
|
|
|
3926
4887
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3927
4888
|
exports.isCliAgentManagementCommand = isCliAgentManagementCommand;
|
|
3928
4889
|
exports.cliAgentHookBinPath = cliAgentHookBinPath;
|
|
4890
|
+
exports.cliAgentSelfCommand = cliAgentSelfCommand;
|
|
3929
4891
|
exports.runCliAgentSetup = runCliAgentSetup;
|
|
3930
4892
|
exports.writeHookSettings = writeHookSettings;
|
|
3931
4893
|
exports.registeredHookSets = registeredHookSets;
|
|
3932
4894
|
exports.findStaleHookCommands = findStaleHookCommands2;
|
|
4895
|
+
exports.cliAgentRegistrations = cliAgentRegistrations;
|
|
3933
4896
|
var crypto2 = __importStar(__require("crypto"));
|
|
3934
4897
|
var fs5 = __importStar(__require("fs"));
|
|
3935
|
-
var
|
|
4898
|
+
var os5 = __importStar(__require("os"));
|
|
3936
4899
|
var path4 = __importStar(__require("path"));
|
|
3937
4900
|
var collectorVersion_1 = require_collectorVersion();
|
|
3938
4901
|
var credentials_1 = require_credentials();
|
|
4902
|
+
var eventLog_1 = require_eventLog();
|
|
3939
4903
|
var hookAdapter_1 = require_hookAdapter();
|
|
3940
4904
|
var http_1 = require_http();
|
|
3941
4905
|
var hookSet_1 = require_hookSet();
|
|
3942
4906
|
var initiatives_1 = require_initiatives();
|
|
3943
4907
|
var setupDisclosure_1 = require_setupDisclosure();
|
|
4908
|
+
var hookRunner_1 = require_hookRunner();
|
|
4909
|
+
var liveSignalDoctor_1 = require_liveSignalDoctor();
|
|
3944
4910
|
var stateStore_1 = require_stateStore();
|
|
3945
4911
|
var studyJoin_1 = require_studyJoin();
|
|
3946
4912
|
var studyNotices_1 = require_studyNotices();
|
|
4913
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
3947
4914
|
var tokenStore_1 = require_tokenStore();
|
|
3948
|
-
var MANAGEMENT_COMMANDS2 = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "join", "object", "-h", "--help"]);
|
|
4915
|
+
var MANAGEMENT_COMMANDS2 = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "doctor", "join", "object", "-h", "--help"]);
|
|
3949
4916
|
function isCliAgentManagementCommand(argument) {
|
|
3950
4917
|
return argument !== void 0 && MANAGEMENT_COMMANDS2.has(argument);
|
|
3951
4918
|
}
|
|
3952
4919
|
function cliAgentHookBinPath(binaryName) {
|
|
3953
|
-
return
|
|
4920
|
+
return (0, hookRunner_1.hookRunnerPaths)(binaryName).launcher;
|
|
4921
|
+
}
|
|
4922
|
+
function cliAgentSelfCommand(spec) {
|
|
4923
|
+
return process.platform === "win32" ? `npx ${spec.packageName}` : (0, hookRunner_1.tidyHomePath)(cliAgentHookBinPath(spec.binaryName), os5.homedir());
|
|
3954
4924
|
}
|
|
3955
4925
|
function usage(spec) {
|
|
3956
4926
|
return `${spec.binaryName} setup \u2014 wire ${spec.displayName} to Ascenda telemetry
|
|
3957
4927
|
|
|
3958
4928
|
npx ${spec.packageName} setup [options]
|
|
3959
4929
|
npx ${spec.packageName} status
|
|
4930
|
+
npx ${spec.packageName} doctor
|
|
3960
4931
|
npx ${spec.packageName} uninstall
|
|
3961
4932
|
npx ${spec.packageName} join <code>
|
|
3962
4933
|
npx ${spec.packageName} object <purpose> [--undo]
|
|
@@ -3967,7 +4938,9 @@ Options
|
|
|
3967
4938
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
3968
4939
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
3969
4940
|
--no-pair install without pairing: local features on, nothing sent
|
|
3970
|
-
--
|
|
4941
|
+
--event-log [path|off] keep every event in a local JSONL file (default ~/.ascenda/events.jsonl).
|
|
4942
|
+
On by default when not paired; machine-wide, shared by every agent
|
|
4943
|
+
--scope user|project where hooks are registered (default user: every project)
|
|
3971
4944
|
--project-dir <path> project root for --scope project (default cwd)
|
|
3972
4945
|
--dry-run print what would change, write nothing
|
|
3973
4946
|
-h, --help
|
|
@@ -3993,29 +4966,26 @@ Options
|
|
|
3993
4966
|
return await printStatus2(options, spec);
|
|
3994
4967
|
if (options.action === "uninstall")
|
|
3995
4968
|
return uninstall2(options, spec);
|
|
4969
|
+
if (options.action === "doctor")
|
|
4970
|
+
return await runDoctor2(options, spec);
|
|
3996
4971
|
const apiBaseUrl = (options.apiBaseUrl ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
3997
|
-
|
|
3998
|
-
console.log(`
|
|
3999
|
-
|
|
4000
|
-
`);
|
|
4972
|
+
const ui = (0, terminalStyle_1.terminalStyle)();
|
|
4973
|
+
const row = (tone, label, value) => console.log(` ${ui.mark(tone)} ${label.padEnd(12)} ${value}`);
|
|
4974
|
+
const detail = (label, value) => console.log(ui.dim(` ${label.padEnd(12)} ${value}`));
|
|
4975
|
+
console.log(`${ui.bold("Ascenda setup")} ${ui.dim(`\xB7 ${spec.displayName} \xB7 ${apiBaseUrl}`)}`);
|
|
4976
|
+
if (!options.skipPairing)
|
|
4977
|
+
console.log(`
|
|
4978
|
+
${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName })}`);
|
|
4979
|
+
console.log("");
|
|
4001
4980
|
let identity;
|
|
4002
|
-
|
|
4003
|
-
if (options.skipPairing) {
|
|
4004
|
-
unpairedReason = "asked not to pair (--no-pair)";
|
|
4005
|
-
} else {
|
|
4981
|
+
if (!options.skipPairing)
|
|
4006
4982
|
identity = await resolveIdentity2(apiBaseUrl, options, spec);
|
|
4007
|
-
if (identity) {
|
|
4008
|
-
console.log(` pairing ${identity.toolInstallationId}${identity.paired ? " (new)" : " (existing)"}`);
|
|
4009
|
-
} else {
|
|
4010
|
-
unpairedReason = "pairing did not finish \u2014 installing the local half anyway";
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
|
-
if (unpairedReason) {
|
|
4014
|
-
console.log(` pairing none: ${unpairedReason}`);
|
|
4015
|
-
console.log(" local features on, nothing is sent");
|
|
4016
|
-
}
|
|
4017
4983
|
const binary = installBinary2(spec, options.dryRun);
|
|
4018
|
-
|
|
4984
|
+
const node = options.dryRun || process.platform === "win32" ? void 0 : (0, hookRunner_1.resolveHookNode)(binary);
|
|
4985
|
+
if (node?.problem)
|
|
4986
|
+
row("bad", "hook binary", `${(0, hookRunner_1.tidyHomePath)(binary, os5.homedir())}, but ${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
4987
|
+
else
|
|
4988
|
+
row("ok", "hook binary", `${(0, hookRunner_1.tidyHomePath)(binary, os5.homedir())}${node?.version ? ui.dim(` (Node ${node.version})`) : ""}`);
|
|
4019
4989
|
if (!options.dryRun) {
|
|
4020
4990
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4021
4991
|
const toolInstallationId = identity?.toolInstallationId ?? options.toolInstallationId ?? (0, credentials_1.readHostCredentials)(spec.host)?.toolInstallationId ?? `${spec.toolType}:${crypto2.randomUUID()}`;
|
|
@@ -4024,32 +4994,86 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
4024
4994
|
toolInstallationId,
|
|
4025
4995
|
...identity ? { pairedAt: now } : { localOnly: true, installedAt: now }
|
|
4026
4996
|
});
|
|
4997
|
+
if (options.eventLog !== void 0)
|
|
4998
|
+
(0, credentials_1.writeEventLogSetting)(options.eventLog);
|
|
4999
|
+
}
|
|
5000
|
+
if (isHomeProject2(options)) {
|
|
5001
|
+
detail("scope", "user (a project install in the home folder only loads when the agent starts there)");
|
|
5002
|
+
options.scope = "user";
|
|
4027
5003
|
}
|
|
4028
|
-
console.log(` credentials ${(0, credentials_1.credentialsFilePath)()} (tools.${spec.host})`);
|
|
4029
5004
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
4030
5005
|
const before = registeredHookSets(readSettings(settingsFile), spec);
|
|
4031
5006
|
const written = writeHookSettings(settingsFile, binary, spec, options.dryRun);
|
|
4032
5007
|
if (written === null)
|
|
4033
5008
|
return 1;
|
|
4034
|
-
|
|
5009
|
+
const reach = options.scope === "user" ? "every project" : "this project only";
|
|
5010
|
+
row("ok", "hooks", `${(0, hookRunner_1.tidyHomePath)(settingsFile, os5.homedir())} ${ui.dim(`(${spec.hookEvents.length} events, ${reach}${written ? "" : ", already current"})`)}`);
|
|
4035
5011
|
const changes = spec.hookSet === void 0 ? void 0 : (0, hookSet_1.describeHookSetChanges)((0, hookSet_1.hookSetChanges)(before, spec.hookEvents), spec.hookSet);
|
|
4036
5012
|
if (changes)
|
|
4037
|
-
|
|
5013
|
+
detail("", changes);
|
|
5014
|
+
const otherFile = spec.settings.settingsPath(options.scope === "user" ? "project" : "user", options.projectDir);
|
|
5015
|
+
if (otherFile !== settingsFile && registeredHookSets(readSettings(otherFile), spec).size > 0) {
|
|
5016
|
+
if (options.dryRun) {
|
|
5017
|
+
row("info", "moved", `would remove the copy in ${(0, hookRunner_1.tidyHomePath)(otherFile, os5.homedir())}, so each event runs once`);
|
|
5018
|
+
} else if (removeOurHookEntries(otherFile, spec)) {
|
|
5019
|
+
row("ok", "moved", `removed the copy in ${(0, hookRunner_1.tidyHomePath)(otherFile, os5.homedir())}, so each event runs once ${ui.dim("(backup beside it)")}`);
|
|
5020
|
+
} else {
|
|
5021
|
+
row("warn", "note", `${(0, hookRunner_1.tidyHomePath)(otherFile, os5.homedir())} registers these hooks too, so each event runs twice.`);
|
|
5022
|
+
detail("", `Remove the ${spec.binaryName} entries from one of the two files.`);
|
|
5023
|
+
}
|
|
5024
|
+
}
|
|
5025
|
+
const chosenLocal = options.skipPairing;
|
|
5026
|
+
if (identity)
|
|
5027
|
+
row("ok", "pairing", `${identity.toolInstallationId}${ui.dim(identity.paired ? " (new)" : " (existing)")}`);
|
|
5028
|
+
else if (chosenLocal)
|
|
5029
|
+
row("info", "pairing", `none, as asked ${ui.dim("(--no-pair)")}`);
|
|
5030
|
+
else
|
|
5031
|
+
row("warn", "pairing", "not paired: pairing did not finish");
|
|
5032
|
+
detail("credentials", `${(0, hookRunner_1.tidyHomePath)((0, credentials_1.credentialsFilePath)(), os5.homedir())} (tools.${spec.host})`);
|
|
5033
|
+
const eventLog = (0, eventLog_1.resolveEventLog)({ localOnly: !identity });
|
|
5034
|
+
if (eventLog.path)
|
|
5035
|
+
row("ok", "events", `${(0, hookRunner_1.tidyHomePath)(eventLog.path, os5.homedir())} ${ui.dim("(on this machine only)")}`);
|
|
5036
|
+
else if (options.eventLog !== void 0)
|
|
5037
|
+
row("info", "events", "off");
|
|
4038
5038
|
if (options.dryRun) {
|
|
4039
|
-
console.log("\nDry run
|
|
5039
|
+
console.log("\nDry run. Nothing was written.");
|
|
4040
5040
|
return 0;
|
|
4041
5041
|
}
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
5042
|
+
const self = cliAgentSelfCommand(spec);
|
|
5043
|
+
const next = (label, value) => console.log(` ${ui.bold(label.padEnd(6))} ${value}`);
|
|
5044
|
+
console.log("");
|
|
5045
|
+
if (chosenLocal) {
|
|
5046
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Ready.")} The screen saver and the Ascenda app's live view work now.`);
|
|
5047
|
+
console.log(" They run on this machine and need no account or pairing.");
|
|
5048
|
+
if (eventLog.path)
|
|
5049
|
+
console.log(` Every event is also written to ${(0, hookRunner_1.tidyHomePath)(eventLog.path, os5.homedir())}, for you or any tool to read.`);
|
|
5050
|
+
} else if (!identity) {
|
|
5051
|
+
console.log(`${ui.mark("warn")} ${ui.bold("Installed, not paired.")} The screen saver and the live view work now.`);
|
|
5052
|
+
console.log(" Your sessions won't reach Ascenda's servers until pairing completes.");
|
|
5053
|
+
} else {
|
|
5054
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Done.")} Paired, and the hooks are installed.`);
|
|
5055
|
+
}
|
|
5056
|
+
console.log("");
|
|
5057
|
+
next("Next", spec.restartHint);
|
|
5058
|
+
next("Check", ui.cyan(`${self} doctor`));
|
|
5059
|
+
if (!identity)
|
|
5060
|
+
next(chosenLocal ? "Pair" : "Retry", `${ui.cyan(`${self} setup`)}${chosenLocal ? ui.dim(" (optional)") : ""}`);
|
|
5061
|
+
if (chosenLocal) {
|
|
5062
|
+
console.log("");
|
|
5063
|
+
console.log(ui.dim(" Pairing sends the details below to Ascenda's servers, under the account the"));
|
|
5064
|
+
console.log(ui.dim(" Ascenda app is signed in to when you confirm the code, so your sessions appear"));
|
|
5065
|
+
console.log(ui.dim(" in the app. Until you pair, nothing leaves this machine."));
|
|
5066
|
+
console.log("");
|
|
5067
|
+
console.log(ui.dim((0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName: spec.displayName }).split("\n").map((line) => ` ${line}`).join("\n")));
|
|
4046
5068
|
}
|
|
4047
|
-
console.log(`Check anytime: npx ${spec.packageName} status`);
|
|
4048
5069
|
return 0;
|
|
4049
5070
|
}
|
|
5071
|
+
function isHomeProject2(options) {
|
|
5072
|
+
return options.scope === "project" && path4.resolve(options.projectDir) === path4.resolve(os5.homedir());
|
|
5073
|
+
}
|
|
4050
5074
|
function parseArgs2(argv, spec) {
|
|
4051
5075
|
const options = {
|
|
4052
|
-
scope: "
|
|
5076
|
+
scope: "user",
|
|
4053
5077
|
projectDir: process.cwd(),
|
|
4054
5078
|
dryRun: false,
|
|
4055
5079
|
skipPairing: false,
|
|
@@ -4074,6 +5098,9 @@ Done. ${spec.restartHint}`);
|
|
|
4074
5098
|
case "uninstall":
|
|
4075
5099
|
options.action = "uninstall";
|
|
4076
5100
|
break;
|
|
5101
|
+
case "doctor":
|
|
5102
|
+
options.action = "doctor";
|
|
5103
|
+
break;
|
|
4077
5104
|
case "--api-base-url":
|
|
4078
5105
|
options.apiBaseUrl = next();
|
|
4079
5106
|
break;
|
|
@@ -4102,6 +5129,12 @@ Done. ${spec.restartHint}`);
|
|
|
4102
5129
|
case "--dry-run":
|
|
4103
5130
|
options.dryRun = true;
|
|
4104
5131
|
break;
|
|
5132
|
+
case "--event-log": {
|
|
5133
|
+
const { value, consumed } = (0, eventLog_1.parseEventLogFlag)(argv, i);
|
|
5134
|
+
options.eventLog = value;
|
|
5135
|
+
i += consumed;
|
|
5136
|
+
break;
|
|
5137
|
+
}
|
|
4105
5138
|
case "--no-pair":
|
|
4106
5139
|
// `--no-pairing` is the spelling this landed under first. Both appeared
|
|
4107
5140
|
// only in an unreleased changelog, so this alias exists to spare anyone
|
|
@@ -4182,7 +5215,7 @@ ${usage(spec)}`);
|
|
|
4182
5215
|
const toolInstallationId = existingId ?? `${spec.toolType}:${crypto2.randomUUID()}`;
|
|
4183
5216
|
let session;
|
|
4184
5217
|
try {
|
|
4185
|
-
session = await (0, http_1.createPairingSession)(apiBaseUrl, toolInstallationId, spec.toolType, `${spec.displayName} on ${
|
|
5218
|
+
session = await (0, http_1.createPairingSession)(apiBaseUrl, toolInstallationId, spec.toolType, `${spec.displayName} on ${os5.hostname()}`);
|
|
4186
5219
|
} catch (error) {
|
|
4187
5220
|
console.error(`
|
|
4188
5221
|
Could not reach ${apiBaseUrl} to pair: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -4231,17 +5264,7 @@ Pairing ${status.status}. Run setup again.`);
|
|
|
4231
5264
|
return void 0;
|
|
4232
5265
|
}
|
|
4233
5266
|
function installBinary2(spec, dryRun) {
|
|
4234
|
-
|
|
4235
|
-
if (dryRun)
|
|
4236
|
-
return target;
|
|
4237
|
-
const source = process.argv[1];
|
|
4238
|
-
fs5.mkdirSync(path4.dirname(target), { recursive: true });
|
|
4239
|
-
if (path4.resolve(source) !== path4.resolve(target)) {
|
|
4240
|
-
fs5.copyFileSync(source, target);
|
|
4241
|
-
}
|
|
4242
|
-
if (process.platform !== "win32")
|
|
4243
|
-
fs5.chmodSync(target, 493);
|
|
4244
|
-
return target;
|
|
5267
|
+
return (0, hookRunner_1.installHookRunner)({ binaryName: spec.binaryName, setupCommand: `npx ${spec.packageName} setup`, dryRun });
|
|
4245
5268
|
}
|
|
4246
5269
|
function writeHookSettings(settingsFile, binary, spec, dryRun) {
|
|
4247
5270
|
let settings = { ...spec.settings.scaffold ?? {} };
|
|
@@ -4282,7 +5305,7 @@ ${serialised}`);
|
|
|
4282
5305
|
return true;
|
|
4283
5306
|
}
|
|
4284
5307
|
function hookCommand2(binary, spec) {
|
|
4285
|
-
return
|
|
5308
|
+
return `${(0, hookRunner_1.hookRunnerCommand)(binary)}${(0, hookSet_1.hookSetArgument)(spec.hookSet)}`;
|
|
4286
5309
|
}
|
|
4287
5310
|
function registeredHookSets(settings, spec) {
|
|
4288
5311
|
const sets = /* @__PURE__ */ new Map();
|
|
@@ -4334,8 +5357,20 @@ ${serialised}`);
|
|
|
4334
5357
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
4335
5358
|
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}${localOnly ? " (installed, not paired \u2014 local features active, telemetry inactive)" : ""}`);
|
|
4336
5359
|
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
5360
|
+
console.log(`event log ${(0, eventLog_1.describeEventLog)((0, eventLog_1.resolveEventLog)({ localOnly }), `npx ${spec.packageName} setup`)}`);
|
|
4337
5361
|
console.log(`hook binary ${fs5.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
5362
|
+
const node = process.platform === "win32" ? void 0 : (0, hookRunner_1.resolveHookNode)(binary);
|
|
5363
|
+
if (node) {
|
|
5364
|
+
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"})`);
|
|
5365
|
+
}
|
|
5366
|
+
const last = (0, hookRunner_1.readLastHook)(spec.host);
|
|
5367
|
+
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)`);
|
|
4338
5368
|
console.log(`hooks ${registered}/${spec.hookEvents.length} registered in ${settingsFile}`);
|
|
5369
|
+
const otherScope = options.scope === "user" ? "project" : "user";
|
|
5370
|
+
const otherFile = spec.settings.settingsPath(otherScope, options.projectDir);
|
|
5371
|
+
const elsewhere = registered === 0 && otherFile !== settingsFile ? countRegistered2(readSettings(otherFile), spec) : 0;
|
|
5372
|
+
if (elsewhere > 0)
|
|
5373
|
+
console.log(` ${elsewhere}/${spec.hookEvents.length} found in ${otherFile} (--scope ${otherScope})`);
|
|
4339
5374
|
if (spec.hookSet !== void 0 && registered > 0) {
|
|
4340
5375
|
const sets = [...registeredHookSets(settings, spec).values()];
|
|
4341
5376
|
const oldest = Math.min(...sets);
|
|
@@ -4361,38 +5396,118 @@ ${serialised}`);
|
|
|
4361
5396
|
if (process.stdout.isTTY)
|
|
4362
5397
|
await notices.markShown();
|
|
4363
5398
|
const paired = localOnly || credentials?.toolInstallationId !== void 0;
|
|
4364
|
-
const
|
|
5399
|
+
const wired = registered === spec.hookEvents.length || options.scope === "project" && elsewhere === spec.hookEvents.length;
|
|
5400
|
+
const healthy = paired && wired && fs5.existsSync(binary) && !stale.length && !node?.problem;
|
|
4365
5401
|
return healthy ? 0 : 1;
|
|
4366
5402
|
}
|
|
5403
|
+
function countRegistered2(settings, spec) {
|
|
5404
|
+
return spec.hookEvents.filter((event) => (settings.hooks?.[event] ?? []).some((entry) => isOurs2(entry, spec))).length;
|
|
5405
|
+
}
|
|
5406
|
+
function cliAgentRegistrations(spec, projectDir = process.cwd()) {
|
|
5407
|
+
const home = os5.homedir();
|
|
5408
|
+
const userFile = spec.settings.settingsPath("user", projectDir);
|
|
5409
|
+
const projectFile = spec.settings.settingsPath("project", projectDir);
|
|
5410
|
+
const found = [];
|
|
5411
|
+
for (const [scope, file] of [["user", userFile], ["project", projectFile]]) {
|
|
5412
|
+
if (scope === "project" && file === userFile)
|
|
5413
|
+
continue;
|
|
5414
|
+
const registered = countRegistered2(readSettings(file), spec);
|
|
5415
|
+
if (registered === 0)
|
|
5416
|
+
continue;
|
|
5417
|
+
found.push({
|
|
5418
|
+
file: (0, hookRunner_1.tidyHomePath)(file, home),
|
|
5419
|
+
registered,
|
|
5420
|
+
scope,
|
|
5421
|
+
homeProject: scope === "project" && path4.resolve(projectDir) === path4.resolve(home)
|
|
5422
|
+
});
|
|
5423
|
+
}
|
|
5424
|
+
return found;
|
|
5425
|
+
}
|
|
5426
|
+
async function runDoctor2(options, spec) {
|
|
5427
|
+
const ui = (0, terminalStyle_1.terminalStyle)();
|
|
5428
|
+
const lines = [`${ui.bold("Ascenda doctor")} ${ui.dim(`\xB7 ${spec.displayName}`)}`, ""];
|
|
5429
|
+
try {
|
|
5430
|
+
lines.push(...await (0, liveSignalDoctor_1.liveSignalDoctorLines)({
|
|
5431
|
+
displayName: spec.displayName,
|
|
5432
|
+
tool: spec.host,
|
|
5433
|
+
launcher: process.platform === "win32" ? void 0 : cliAgentHookBinPath(spec.binaryName),
|
|
5434
|
+
registrations: cliAgentRegistrations(spec, options.projectDir),
|
|
5435
|
+
eventCount: spec.hookEvents.length,
|
|
5436
|
+
selfCommand: cliAgentSelfCommand(spec),
|
|
5437
|
+
setupCommand: `npx ${spec.packageName} setup`,
|
|
5438
|
+
ui
|
|
5439
|
+
}));
|
|
5440
|
+
} catch (error) {
|
|
5441
|
+
lines.push(` Live signal (could not be checked: ${error instanceof Error ? error.message : String(error)})`);
|
|
5442
|
+
}
|
|
5443
|
+
lines.push("", ...accountLines(ui, spec));
|
|
5444
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (id) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0);
|
|
5445
|
+
lines.push("", ` ${ui.bold("Local events")} ${(0, eventLog_1.describeEventLog)((0, eventLog_1.resolveEventLog)({ localOnly }), `npx ${spec.packageName} setup`)}`);
|
|
5446
|
+
console.log(lines.join("\n"));
|
|
5447
|
+
return 0;
|
|
5448
|
+
}
|
|
5449
|
+
function accountLines(ui, spec) {
|
|
5450
|
+
const credentials = (0, credentials_1.readHostCredentials)(spec.host);
|
|
5451
|
+
const id = credentials?.toolInstallationId;
|
|
5452
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (installationId) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(installationId)) !== void 0);
|
|
5453
|
+
const row = (tone, label, value) => ` ${ui.mark(tone)} ${label.padEnd(20)} ${value}`;
|
|
5454
|
+
if (!id || localOnly) {
|
|
5455
|
+
return [
|
|
5456
|
+
` ${ui.bold("Account sync")} ${ui.dim("(optional; this install isn't paired)")}`,
|
|
5457
|
+
...id ? [ui.dim(row("info", "Installation id", id))] : [],
|
|
5458
|
+
"",
|
|
5459
|
+
" Not paired, which is fine: the screen saver, the live view and the local",
|
|
5460
|
+
" event log work without it. Nothing leaves this machine and nothing is queued.",
|
|
5461
|
+
" To send your sessions to Ascenda's servers, so they appear in the app:",
|
|
5462
|
+
` ${ui.cyan(`${cliAgentSelfCommand(spec)} setup`)}`
|
|
5463
|
+
];
|
|
5464
|
+
}
|
|
5465
|
+
const token = (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) ?? process.env.ASCENDA_EVENT_WRITE_TOKEN?.trim();
|
|
5466
|
+
const state = (0, stateStore_1.readCollectorState)((0, stateStore_1.defaultStateFilePath)(id));
|
|
5467
|
+
const outcome = state?.lastOutcome;
|
|
5468
|
+
return [
|
|
5469
|
+
` ${ui.bold("Account sync")}`,
|
|
5470
|
+
row("info", "Installation id", id),
|
|
5471
|
+
token ? row("ok", "Token", "present") : row("bad", "Token", ui.red(`missing, so nothing can be sent. Run: npx ${spec.packageName} setup`)),
|
|
5472
|
+
outcome ? row(outcome === "accepted" ? "ok" : "warn", "Last send", `${outcome}${state?.lastAttemptAt ? ui.dim(` (${state.lastAttemptAt})`) : ""}`) : row("info", "Last send", "none yet")
|
|
5473
|
+
];
|
|
5474
|
+
}
|
|
5475
|
+
function removeOurHookEntries(settingsFile, spec) {
|
|
5476
|
+
if (!fs5.existsSync(settingsFile))
|
|
5477
|
+
return true;
|
|
5478
|
+
try {
|
|
5479
|
+
const settings = JSON.parse(fs5.readFileSync(settingsFile, "utf8"));
|
|
5480
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
5481
|
+
for (const event of Object.keys(hooks)) {
|
|
5482
|
+
const kept = hooks[event].filter((entry) => !isOurs2(entry, spec));
|
|
5483
|
+
if (kept.length)
|
|
5484
|
+
hooks[event] = kept;
|
|
5485
|
+
else
|
|
5486
|
+
delete hooks[event];
|
|
5487
|
+
}
|
|
5488
|
+
const updated = { ...settings, hooks };
|
|
5489
|
+
if (!Object.keys(hooks).length)
|
|
5490
|
+
delete updated.hooks;
|
|
5491
|
+
fs5.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
5492
|
+
fs5.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
5493
|
+
`, "utf8");
|
|
5494
|
+
return true;
|
|
5495
|
+
} catch {
|
|
5496
|
+
return false;
|
|
5497
|
+
}
|
|
5498
|
+
}
|
|
4367
5499
|
function uninstall2(options, spec) {
|
|
4368
5500
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
4369
5501
|
if (fs5.existsSync(settingsFile)) {
|
|
4370
|
-
|
|
4371
|
-
const settings = JSON.parse(fs5.readFileSync(settingsFile, "utf8"));
|
|
4372
|
-
const hooks = { ...settings.hooks ?? {} };
|
|
4373
|
-
for (const event of Object.keys(hooks)) {
|
|
4374
|
-
const kept = hooks[event].filter((entry) => !isOurs2(entry, spec));
|
|
4375
|
-
if (kept.length)
|
|
4376
|
-
hooks[event] = kept;
|
|
4377
|
-
else
|
|
4378
|
-
delete hooks[event];
|
|
4379
|
-
}
|
|
4380
|
-
const updated = { ...settings, hooks };
|
|
4381
|
-
if (!Object.keys(hooks).length)
|
|
4382
|
-
delete updated.hooks;
|
|
4383
|
-
fs5.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
4384
|
-
fs5.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
4385
|
-
`, "utf8");
|
|
4386
|
-
console.log(`hooks removed from ${settingsFile}`);
|
|
4387
|
-
} catch {
|
|
5502
|
+
if (!removeOurHookEntries(settingsFile, spec)) {
|
|
4388
5503
|
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
4389
5504
|
return 1;
|
|
4390
5505
|
}
|
|
5506
|
+
console.log(`hooks removed from ${settingsFile}`);
|
|
4391
5507
|
}
|
|
4392
|
-
const
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
console.log(`removed ${binary}`);
|
|
5508
|
+
for (const file of (0, hookRunner_1.removeHookRunner)(spec.binaryName)) {
|
|
5509
|
+
if (!file.endsWith(".node") && !file.endsWith(".no-node"))
|
|
5510
|
+
console.log(`removed ${file}`);
|
|
4396
5511
|
}
|
|
4397
5512
|
if ((0, credentials_1.readHostCredentials)(spec.host)) {
|
|
4398
5513
|
(0, credentials_1.removeHostCredentials)(spec.host);
|
|
@@ -4402,91 +5517,11 @@ ${serialised}`);
|
|
|
4402
5517
|
return 0;
|
|
4403
5518
|
}
|
|
4404
5519
|
}
|
|
4405
|
-
});
|
|
4406
|
-
|
|
4407
|
-
// ../packages/tool-kit/out/turnState.js
|
|
4408
|
-
var require_turnState = __commonJS({
|
|
4409
|
-
"../packages/tool-kit/out/turnState.js"(exports) {
|
|
4410
|
-
"use strict";
|
|
4411
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4412
|
-
if (k2 === void 0) k2 = k;
|
|
4413
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4414
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4415
|
-
desc = { enumerable: true, get: function() {
|
|
4416
|
-
return m[k];
|
|
4417
|
-
} };
|
|
4418
|
-
}
|
|
4419
|
-
Object.defineProperty(o, k2, desc);
|
|
4420
|
-
} : function(o, m, k, k2) {
|
|
4421
|
-
if (k2 === void 0) k2 = k;
|
|
4422
|
-
o[k2] = m[k];
|
|
4423
|
-
});
|
|
4424
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4425
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4426
|
-
} : function(o, v) {
|
|
4427
|
-
o["default"] = v;
|
|
4428
|
-
});
|
|
4429
|
-
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4430
|
-
var ownKeys = function(o) {
|
|
4431
|
-
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4432
|
-
var ar = [];
|
|
4433
|
-
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4434
|
-
return ar;
|
|
4435
|
-
};
|
|
4436
|
-
return ownKeys(o);
|
|
4437
|
-
};
|
|
4438
|
-
return function(mod) {
|
|
4439
|
-
if (mod && mod.__esModule) return mod;
|
|
4440
|
-
var result = {};
|
|
4441
|
-
if (mod != null) {
|
|
4442
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4443
|
-
}
|
|
4444
|
-
__setModuleDefault(result, mod);
|
|
4445
|
-
return result;
|
|
4446
|
-
};
|
|
4447
|
-
}();
|
|
4448
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4449
|
-
exports.recordTurnStart = recordTurnStart;
|
|
4450
|
-
exports.consumeTurnDurationMs = consumeTurnDurationMs;
|
|
4451
|
-
var fs5 = __importStar(__require("fs"));
|
|
4452
|
-
var path4 = __importStar(__require("path"));
|
|
4453
|
-
var tokenStore_1 = require_tokenStore();
|
|
4454
|
-
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path4.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
4455
|
-
function turnFile(agent, sessionId) {
|
|
4456
|
-
return path4.join(stateDir(), `${sanitize(agent)}-turn-${sanitize(sessionId)}`);
|
|
4457
|
-
}
|
|
4458
|
-
function sanitize(value) {
|
|
4459
|
-
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
4460
|
-
}
|
|
4461
|
-
function recordTurnStart(agent, sessionId, now = Date.now()) {
|
|
4462
|
-
if (!sessionId)
|
|
4463
|
-
return;
|
|
4464
|
-
try {
|
|
4465
|
-
fs5.mkdirSync(stateDir(), { recursive: true });
|
|
4466
|
-
fs5.writeFileSync(turnFile(agent, sessionId), String(now), { encoding: "utf8", mode: 384 });
|
|
4467
|
-
} catch {
|
|
4468
|
-
}
|
|
4469
|
-
}
|
|
4470
|
-
function consumeTurnDurationMs(agent, sessionId, now = Date.now()) {
|
|
4471
|
-
if (!sessionId)
|
|
4472
|
-
return void 0;
|
|
4473
|
-
const file = turnFile(agent, sessionId);
|
|
4474
|
-
try {
|
|
4475
|
-
const started = Number(fs5.readFileSync(file, "utf8").trim());
|
|
4476
|
-
fs5.rmSync(file, { force: true });
|
|
4477
|
-
if (!Number.isFinite(started) || started <= 0 || started > now)
|
|
4478
|
-
return void 0;
|
|
4479
|
-
return now - started;
|
|
4480
|
-
} catch {
|
|
4481
|
-
return void 0;
|
|
4482
|
-
}
|
|
4483
|
-
}
|
|
4484
|
-
}
|
|
4485
|
-
});
|
|
4486
|
-
|
|
4487
|
-
// ../packages/tool-kit/out/liveBus.js
|
|
4488
|
-
var require_liveBus = __commonJS({
|
|
4489
|
-
"../packages/tool-kit/out/liveBus.js"(exports) {
|
|
5520
|
+
});
|
|
5521
|
+
|
|
5522
|
+
// ../packages/tool-kit/out/turnState.js
|
|
5523
|
+
var require_turnState = __commonJS({
|
|
5524
|
+
"../packages/tool-kit/out/turnState.js"(exports) {
|
|
4490
5525
|
"use strict";
|
|
4491
5526
|
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4492
5527
|
if (k2 === void 0) k2 = k;
|
|
@@ -4526,134 +5561,40 @@ var require_liveBus = __commonJS({
|
|
|
4526
5561
|
};
|
|
4527
5562
|
}();
|
|
4528
5563
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4529
|
-
exports.
|
|
4530
|
-
exports.
|
|
4531
|
-
exports.liveBusSocketPath = liveBusSocketPath;
|
|
4532
|
-
exports.bucketPromptSize = bucketPromptSize2;
|
|
4533
|
-
exports.emitLiveSignal = emitLiveSignal2;
|
|
5564
|
+
exports.recordTurnStart = recordTurnStart;
|
|
5565
|
+
exports.consumeTurnDurationMs = consumeTurnDurationMs;
|
|
4534
5566
|
var fs5 = __importStar(__require("fs"));
|
|
4535
|
-
var net = __importStar(__require("net"));
|
|
4536
|
-
var os3 = __importStar(__require("os"));
|
|
4537
5567
|
var path4 = __importStar(__require("path"));
|
|
4538
|
-
var
|
|
4539
|
-
var
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
4543
|
-
function liveBusSocketCandidates() {
|
|
4544
|
-
const override = process.env.ASCENDA_LIVE_BUS_SOCKET;
|
|
4545
|
-
if (override)
|
|
4546
|
-
return [override];
|
|
4547
|
-
const home = os3.homedir();
|
|
4548
|
-
return [
|
|
4549
|
-
path4.join(home, ".ascenda", "live.sock"),
|
|
4550
|
-
path4.join(home, "Library", "Containers", APP_BUNDLE_ID, "Data", ".ascenda", "live.sock"),
|
|
4551
|
-
path4.join(home, "Library", "Containers", SAVER_HOST_BUNDLE_ID, "Data", "l.sock")
|
|
4552
|
-
];
|
|
4553
|
-
}
|
|
4554
|
-
function existingSocketCandidates() {
|
|
4555
|
-
const candidates = liveBusSocketCandidates();
|
|
4556
|
-
if (process.env.ASCENDA_LIVE_BUS_SOCKET)
|
|
4557
|
-
return candidates;
|
|
4558
|
-
return candidates.filter((candidate) => {
|
|
4559
|
-
try {
|
|
4560
|
-
return fs5.statSync(candidate).isSocket();
|
|
4561
|
-
} catch {
|
|
4562
|
-
return false;
|
|
4563
|
-
}
|
|
4564
|
-
});
|
|
4565
|
-
}
|
|
4566
|
-
function liveBusSocketPath() {
|
|
4567
|
-
return existingSocketCandidates()[0] ?? liveBusSocketCandidates()[0];
|
|
5568
|
+
var tokenStore_1 = require_tokenStore();
|
|
5569
|
+
var stateDir = () => process.env.ASCENDA_STATE_DIR ?? path4.join((0, tokenStore_1.ascendaHome)(), "state");
|
|
5570
|
+
function turnFile(agent, sessionId) {
|
|
5571
|
+
return path4.join(stateDir(), `${sanitize(agent)}-turn-${sanitize(sessionId)}`);
|
|
4568
5572
|
}
|
|
4569
|
-
function
|
|
4570
|
-
|
|
4571
|
-
if (length <= 280)
|
|
4572
|
-
return "s";
|
|
4573
|
-
if (length <= 2e3)
|
|
4574
|
-
return "m";
|
|
4575
|
-
if (length <= 8e3)
|
|
4576
|
-
return "l";
|
|
4577
|
-
return "xl";
|
|
5573
|
+
function sanitize(value) {
|
|
5574
|
+
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
4578
5575
|
}
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
5576
|
+
function recordTurnStart(agent, sessionId, now = Date.now()) {
|
|
5577
|
+
if (!sessionId)
|
|
5578
|
+
return;
|
|
5579
|
+
try {
|
|
5580
|
+
fs5.mkdirSync(stateDir(), { recursive: true });
|
|
5581
|
+
fs5.writeFileSync(turnFile(agent, sessionId), String(now), { encoding: "utf8", mode: 384 });
|
|
5582
|
+
} catch {
|
|
5583
|
+
}
|
|
4587
5584
|
}
|
|
4588
|
-
function
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
}
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
}
|
|
4602
|
-
socket = void 0;
|
|
4603
|
-
};
|
|
4604
|
-
const done = () => {
|
|
4605
|
-
if (settled)
|
|
4606
|
-
return;
|
|
4607
|
-
settled = true;
|
|
4608
|
-
clearTimeout(timer);
|
|
4609
|
-
drop();
|
|
4610
|
-
resolve2();
|
|
4611
|
-
};
|
|
4612
|
-
const timer = setTimeout(done, WRITE_TIMEOUT_MS);
|
|
4613
|
-
if (typeof timer.unref === "function")
|
|
4614
|
-
timer.unref();
|
|
4615
|
-
const tryFrom = (index) => {
|
|
4616
|
-
if (settled)
|
|
4617
|
-
return;
|
|
4618
|
-
if (index >= candidates.length) {
|
|
4619
|
-
done();
|
|
4620
|
-
return;
|
|
4621
|
-
}
|
|
4622
|
-
let attempt;
|
|
4623
|
-
try {
|
|
4624
|
-
attempt = net.createConnection(candidates[index]);
|
|
4625
|
-
} catch {
|
|
4626
|
-
tryFrom(index + 1);
|
|
4627
|
-
return;
|
|
4628
|
-
}
|
|
4629
|
-
socket = attempt;
|
|
4630
|
-
if (typeof attempt.unref === "function")
|
|
4631
|
-
attempt.unref();
|
|
4632
|
-
let connected = false;
|
|
4633
|
-
attempt.on("error", (error) => {
|
|
4634
|
-
if (settled || socket !== attempt)
|
|
4635
|
-
return;
|
|
4636
|
-
if (!connected && error.code && NOBODY_LISTENING.has(error.code)) {
|
|
4637
|
-
drop();
|
|
4638
|
-
tryFrom(index + 1);
|
|
4639
|
-
return;
|
|
4640
|
-
}
|
|
4641
|
-
done();
|
|
4642
|
-
});
|
|
4643
|
-
attempt.on("connect", () => {
|
|
4644
|
-
if (settled || socket !== attempt)
|
|
4645
|
-
return;
|
|
4646
|
-
connected = true;
|
|
4647
|
-
try {
|
|
4648
|
-
attempt.write(`${JSON.stringify(onTheWire(signal))}
|
|
4649
|
-
`, done);
|
|
4650
|
-
} catch {
|
|
4651
|
-
done();
|
|
4652
|
-
}
|
|
4653
|
-
});
|
|
4654
|
-
};
|
|
4655
|
-
tryFrom(0);
|
|
4656
|
-
});
|
|
5585
|
+
function consumeTurnDurationMs(agent, sessionId, now = Date.now()) {
|
|
5586
|
+
if (!sessionId)
|
|
5587
|
+
return void 0;
|
|
5588
|
+
const file = turnFile(agent, sessionId);
|
|
5589
|
+
try {
|
|
5590
|
+
const started = Number(fs5.readFileSync(file, "utf8").trim());
|
|
5591
|
+
fs5.rmSync(file, { force: true });
|
|
5592
|
+
if (!Number.isFinite(started) || started <= 0 || started > now)
|
|
5593
|
+
return void 0;
|
|
5594
|
+
return now - started;
|
|
5595
|
+
} catch {
|
|
5596
|
+
return void 0;
|
|
5597
|
+
}
|
|
4657
5598
|
}
|
|
4658
5599
|
}
|
|
4659
5600
|
});
|
|
@@ -4798,13 +5739,14 @@ var require_agentProcess = __commonJS({
|
|
|
4798
5739
|
});
|
|
4799
5740
|
|
|
4800
5741
|
// ../packages/tool-kit/out/index.js
|
|
4801
|
-
var
|
|
5742
|
+
var require_out3 = __commonJS({
|
|
4802
5743
|
"../packages/tool-kit/out/index.js"(exports) {
|
|
4803
5744
|
"use strict";
|
|
4804
5745
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4805
|
-
exports.
|
|
4806
|
-
exports.
|
|
4807
|
-
exports.
|
|
5746
|
+
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;
|
|
5747
|
+
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;
|
|
5748
|
+
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;
|
|
5749
|
+
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;
|
|
4808
5750
|
var commandClassifier_1 = require_commandClassifier();
|
|
4809
5751
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
4810
5752
|
return commandClassifier_1.classifyCommand;
|
|
@@ -4905,19 +5847,41 @@ var require_out2 = __commonJS({
|
|
|
4905
5847
|
Object.defineProperty(exports, "TOKEN_RENEW_LEAD_MS", { enumerable: true, get: function() {
|
|
4906
5848
|
return eventSender_1.TOKEN_RENEW_LEAD_MS;
|
|
4907
5849
|
} });
|
|
5850
|
+
Object.defineProperty(exports, "buildEventBody", { enumerable: true, get: function() {
|
|
5851
|
+
return eventSender_1.buildEventBody;
|
|
5852
|
+
} });
|
|
4908
5853
|
Object.defineProperty(exports, "buildEventPayload", { enumerable: true, get: function() {
|
|
4909
5854
|
return eventSender_1.buildEventPayload;
|
|
4910
5855
|
} });
|
|
5856
|
+
var agentEvent_1 = require_agentEvent();
|
|
5857
|
+
Object.defineProperty(exports, "toAgentEvent", { enumerable: true, get: function() {
|
|
5858
|
+
return agentEvent_1.toAgentEvent;
|
|
5859
|
+
} });
|
|
4911
5860
|
var eventLog_1 = require_eventLog();
|
|
4912
5861
|
Object.defineProperty(exports, "EVENT_LOG_ENV_VAR", { enumerable: true, get: function() {
|
|
4913
5862
|
return eventLog_1.EVENT_LOG_ENV_VAR;
|
|
4914
5863
|
} });
|
|
5864
|
+
Object.defineProperty(exports, "EVENT_LOG_OFF", { enumerable: true, get: function() {
|
|
5865
|
+
return eventLog_1.EVENT_LOG_OFF;
|
|
5866
|
+
} });
|
|
4915
5867
|
Object.defineProperty(exports, "appendEventLog", { enumerable: true, get: function() {
|
|
4916
5868
|
return eventLog_1.appendEventLog;
|
|
4917
5869
|
} });
|
|
5870
|
+
Object.defineProperty(exports, "defaultEventLogPath", { enumerable: true, get: function() {
|
|
5871
|
+
return eventLog_1.defaultEventLogPath;
|
|
5872
|
+
} });
|
|
5873
|
+
Object.defineProperty(exports, "describeEventLog", { enumerable: true, get: function() {
|
|
5874
|
+
return eventLog_1.describeEventLog;
|
|
5875
|
+
} });
|
|
4918
5876
|
Object.defineProperty(exports, "expandUserPath", { enumerable: true, get: function() {
|
|
4919
5877
|
return eventLog_1.expandUserPath;
|
|
4920
5878
|
} });
|
|
5879
|
+
Object.defineProperty(exports, "parseEventLogFlag", { enumerable: true, get: function() {
|
|
5880
|
+
return eventLog_1.parseEventLogFlag;
|
|
5881
|
+
} });
|
|
5882
|
+
Object.defineProperty(exports, "resolveEventLog", { enumerable: true, get: function() {
|
|
5883
|
+
return eventLog_1.resolveEventLog;
|
|
5884
|
+
} });
|
|
4921
5885
|
Object.defineProperty(exports, "resolveEventLogPath", { enumerable: true, get: function() {
|
|
4922
5886
|
return eventLog_1.resolveEventLogPath;
|
|
4923
5887
|
} });
|
|
@@ -4994,6 +5958,9 @@ var require_out2 = __commonJS({
|
|
|
4994
5958
|
Object.defineProperty(exports, "writeHostCredentials", { enumerable: true, get: function() {
|
|
4995
5959
|
return credentials_1.writeHostCredentials;
|
|
4996
5960
|
} });
|
|
5961
|
+
Object.defineProperty(exports, "writeEventLogSetting", { enumerable: true, get: function() {
|
|
5962
|
+
return credentials_1.writeEventLogSetting;
|
|
5963
|
+
} });
|
|
4997
5964
|
Object.defineProperty(exports, "writeMachineCredentials", { enumerable: true, get: function() {
|
|
4998
5965
|
return credentials_1.writeMachineCredentials;
|
|
4999
5966
|
} });
|
|
@@ -5154,6 +6121,9 @@ var require_out2 = __commonJS({
|
|
|
5154
6121
|
Object.defineProperty(exports, "emitLiveSignal", { enumerable: true, get: function() {
|
|
5155
6122
|
return liveBus_1.emitLiveSignal;
|
|
5156
6123
|
} });
|
|
6124
|
+
Object.defineProperty(exports, "deliverLine", { enumerable: true, get: function() {
|
|
6125
|
+
return liveBus_1.deliverLine;
|
|
6126
|
+
} });
|
|
5157
6127
|
Object.defineProperty(exports, "bucketPromptSize", { enumerable: true, get: function() {
|
|
5158
6128
|
return liveBus_1.bucketPromptSize;
|
|
5159
6129
|
} });
|
|
@@ -5166,6 +6136,85 @@ var require_out2 = __commonJS({
|
|
|
5166
6136
|
Object.defineProperty(exports, "LIVE_BUS_BACKGROUND_TRUST_MS", { enumerable: true, get: function() {
|
|
5167
6137
|
return liveBus_1.LIVE_BUS_BACKGROUND_TRUST_MS;
|
|
5168
6138
|
} });
|
|
6139
|
+
var saverHandoff_1 = require_saverHandoff();
|
|
6140
|
+
Object.defineProperty(exports, "holdForSaver", { enumerable: true, get: function() {
|
|
6141
|
+
return saverHandoff_1.holdForSaver;
|
|
6142
|
+
} });
|
|
6143
|
+
Object.defineProperty(exports, "heldForSaver", { enumerable: true, get: function() {
|
|
6144
|
+
return saverHandoff_1.heldForSaver;
|
|
6145
|
+
} });
|
|
6146
|
+
Object.defineProperty(exports, "probeSocket", { enumerable: true, get: function() {
|
|
6147
|
+
return saverHandoff_1.probeSocket;
|
|
6148
|
+
} });
|
|
6149
|
+
Object.defineProperty(exports, "readSaverStatuses", { enumerable: true, get: function() {
|
|
6150
|
+
return saverHandoff_1.readSaverStatuses;
|
|
6151
|
+
} });
|
|
6152
|
+
Object.defineProperty(exports, "saverContainerDir", { enumerable: true, get: function() {
|
|
6153
|
+
return saverHandoff_1.saverContainerDir;
|
|
6154
|
+
} });
|
|
6155
|
+
Object.defineProperty(exports, "saverReplayPath", { enumerable: true, get: function() {
|
|
6156
|
+
return saverHandoff_1.saverReplayPath;
|
|
6157
|
+
} });
|
|
6158
|
+
Object.defineProperty(exports, "saverStatusDir", { enumerable: true, get: function() {
|
|
6159
|
+
return saverHandoff_1.saverStatusDir;
|
|
6160
|
+
} });
|
|
6161
|
+
Object.defineProperty(exports, "saverSupportDir", { enumerable: true, get: function() {
|
|
6162
|
+
return saverHandoff_1.saverSupportDir;
|
|
6163
|
+
} });
|
|
6164
|
+
Object.defineProperty(exports, "SAVER_REPLAY_WINDOW_MS", { enumerable: true, get: function() {
|
|
6165
|
+
return saverHandoff_1.SAVER_REPLAY_WINDOW_MS;
|
|
6166
|
+
} });
|
|
6167
|
+
var terminalStyle_1 = require_terminalStyle();
|
|
6168
|
+
Object.defineProperty(exports, "colourEnabled", { enumerable: true, get: function() {
|
|
6169
|
+
return terminalStyle_1.colourEnabled;
|
|
6170
|
+
} });
|
|
6171
|
+
Object.defineProperty(exports, "terminalStyle", { enumerable: true, get: function() {
|
|
6172
|
+
return terminalStyle_1.terminalStyle;
|
|
6173
|
+
} });
|
|
6174
|
+
var hookRunner_1 = require_hookRunner();
|
|
6175
|
+
Object.defineProperty(exports, "describeAge", { enumerable: true, get: function() {
|
|
6176
|
+
return hookRunner_1.describeAge;
|
|
6177
|
+
} });
|
|
6178
|
+
Object.defineProperty(exports, "hookLauncherScript", { enumerable: true, get: function() {
|
|
6179
|
+
return hookRunner_1.hookLauncherScript;
|
|
6180
|
+
} });
|
|
6181
|
+
Object.defineProperty(exports, "hookRunnerCommand", { enumerable: true, get: function() {
|
|
6182
|
+
return hookRunner_1.hookRunnerCommand;
|
|
6183
|
+
} });
|
|
6184
|
+
Object.defineProperty(exports, "hookRunnerPaths", { enumerable: true, get: function() {
|
|
6185
|
+
return hookRunner_1.hookRunnerPaths;
|
|
6186
|
+
} });
|
|
6187
|
+
Object.defineProperty(exports, "installHookRunner", { enumerable: true, get: function() {
|
|
6188
|
+
return hookRunner_1.installHookRunner;
|
|
6189
|
+
} });
|
|
6190
|
+
Object.defineProperty(exports, "lastHookPath", { enumerable: true, get: function() {
|
|
6191
|
+
return hookRunner_1.lastHookPath;
|
|
6192
|
+
} });
|
|
6193
|
+
Object.defineProperty(exports, "readLastHook", { enumerable: true, get: function() {
|
|
6194
|
+
return hookRunner_1.readLastHook;
|
|
6195
|
+
} });
|
|
6196
|
+
Object.defineProperty(exports, "removeHookRunner", { enumerable: true, get: function() {
|
|
6197
|
+
return hookRunner_1.removeHookRunner;
|
|
6198
|
+
} });
|
|
6199
|
+
Object.defineProperty(exports, "resolveHookNode", { enumerable: true, get: function() {
|
|
6200
|
+
return hookRunner_1.resolveHookNode;
|
|
6201
|
+
} });
|
|
6202
|
+
Object.defineProperty(exports, "stampLastHook", { enumerable: true, get: function() {
|
|
6203
|
+
return hookRunner_1.stampLastHook;
|
|
6204
|
+
} });
|
|
6205
|
+
Object.defineProperty(exports, "tidyHomePath", { enumerable: true, get: function() {
|
|
6206
|
+
return hookRunner_1.tidyHomePath;
|
|
6207
|
+
} });
|
|
6208
|
+
var liveSignalDoctor_1 = require_liveSignalDoctor();
|
|
6209
|
+
Object.defineProperty(exports, "DOCTOR_VALUE_COLUMN", { enumerable: true, get: function() {
|
|
6210
|
+
return liveSignalDoctor_1.DOCTOR_VALUE_COLUMN;
|
|
6211
|
+
} });
|
|
6212
|
+
Object.defineProperty(exports, "doctorRow", { enumerable: true, get: function() {
|
|
6213
|
+
return liveSignalDoctor_1.doctorRow;
|
|
6214
|
+
} });
|
|
6215
|
+
Object.defineProperty(exports, "liveSignalDoctorLines", { enumerable: true, get: function() {
|
|
6216
|
+
return liveSignalDoctor_1.liveSignalDoctorLines;
|
|
6217
|
+
} });
|
|
5169
6218
|
var hookSet_1 = require_hookSet();
|
|
5170
6219
|
Object.defineProperty(exports, "HOOK_SET_FLAG", { enumerable: true, get: function() {
|
|
5171
6220
|
return hookSet_1.HOOK_SET_FLAG;
|
|
@@ -5324,10 +6373,20 @@ var init_types = __esm({
|
|
|
5324
6373
|
|
|
5325
6374
|
// src/paths.ts
|
|
5326
6375
|
import * as fs2 from "fs";
|
|
6376
|
+
import * as os2 from "os";
|
|
5327
6377
|
import * as path2 from "path";
|
|
5328
6378
|
function hookBinPath() {
|
|
5329
6379
|
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook");
|
|
5330
6380
|
}
|
|
6381
|
+
function hookBundlePath() {
|
|
6382
|
+
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook.mjs");
|
|
6383
|
+
}
|
|
6384
|
+
function hookNodeRecordPath() {
|
|
6385
|
+
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook.node");
|
|
6386
|
+
}
|
|
6387
|
+
function hookNoNodePath() {
|
|
6388
|
+
return path2.join((0, import_tool_kit5.ascendaHome)(), "bin", "ascenda-claude-hook.no-node");
|
|
6389
|
+
}
|
|
5331
6390
|
function readCredentials() {
|
|
5332
6391
|
const credentials = (0, import_tool_kit5.readMachineCredentials)();
|
|
5333
6392
|
if (!credentials) return void 0;
|
|
@@ -5346,12 +6405,18 @@ function removeCredentials() {
|
|
|
5346
6405
|
}
|
|
5347
6406
|
fs2.rmSync((0, import_tool_kit5.credentialsFilePath)(), { force: true });
|
|
5348
6407
|
}
|
|
6408
|
+
function selfCommand() {
|
|
6409
|
+
if (process.platform === "win32") return "npx @ascenda-one/claude-code-hooks";
|
|
6410
|
+
const home = os2.homedir();
|
|
6411
|
+
const bin = hookBinPath();
|
|
6412
|
+
return bin.startsWith(`${home}/`) ? `~${bin.slice(home.length)}` : bin;
|
|
6413
|
+
}
|
|
5349
6414
|
var import_tool_kit5, import_tool_kit6;
|
|
5350
6415
|
var init_paths = __esm({
|
|
5351
6416
|
"src/paths.ts"() {
|
|
5352
6417
|
"use strict";
|
|
5353
|
-
import_tool_kit5 = __toESM(
|
|
5354
|
-
import_tool_kit6 = __toESM(
|
|
6418
|
+
import_tool_kit5 = __toESM(require_out3(), 1);
|
|
6419
|
+
import_tool_kit6 = __toESM(require_out3(), 1);
|
|
5355
6420
|
}
|
|
5356
6421
|
});
|
|
5357
6422
|
|
|
@@ -5427,7 +6492,7 @@ var import_tool_kit7, DEFAULT_API_BASE_URL, MissingInstallationIdError;
|
|
|
5427
6492
|
var init_config = __esm({
|
|
5428
6493
|
"src/config.ts"() {
|
|
5429
6494
|
"use strict";
|
|
5430
|
-
import_tool_kit7 = __toESM(
|
|
6495
|
+
import_tool_kit7 = __toESM(require_out3(), 1);
|
|
5431
6496
|
init_paths();
|
|
5432
6497
|
init_types();
|
|
5433
6498
|
DEFAULT_API_BASE_URL = "https://api.ascenda.one";
|
|
@@ -5445,19 +6510,57 @@ var init_config = __esm({
|
|
|
5445
6510
|
}
|
|
5446
6511
|
});
|
|
5447
6512
|
|
|
6513
|
+
// src/hookHealth.ts
|
|
6514
|
+
function stampLastHook(event, now = /* @__PURE__ */ new Date()) {
|
|
6515
|
+
(0, import_tool_kit8.stampLastHook)(TOOL, event, now);
|
|
6516
|
+
}
|
|
6517
|
+
function readLastHook() {
|
|
6518
|
+
return (0, import_tool_kit8.readLastHook)(TOOL);
|
|
6519
|
+
}
|
|
6520
|
+
function resolveHookNode() {
|
|
6521
|
+
return (0, import_tool_kit8.resolveHookNode)(hookBinPath());
|
|
6522
|
+
}
|
|
6523
|
+
var import_tool_kit8, import_tool_kit9, TOOL;
|
|
6524
|
+
var init_hookHealth = __esm({
|
|
6525
|
+
"src/hookHealth.ts"() {
|
|
6526
|
+
"use strict";
|
|
6527
|
+
import_tool_kit8 = __toESM(require_out3(), 1);
|
|
6528
|
+
init_paths();
|
|
6529
|
+
import_tool_kit9 = __toESM(require_out3(), 1);
|
|
6530
|
+
TOOL = "claude_code";
|
|
6531
|
+
}
|
|
6532
|
+
});
|
|
6533
|
+
|
|
6534
|
+
// src/launcher.ts
|
|
6535
|
+
var import_tool_kit10, LAUNCHER_OPTIONS, LAUNCHER_SCRIPT;
|
|
6536
|
+
var init_launcher = __esm({
|
|
6537
|
+
"src/launcher.ts"() {
|
|
6538
|
+
"use strict";
|
|
6539
|
+
import_tool_kit10 = __toESM(require_out3(), 1);
|
|
6540
|
+
LAUNCHER_OPTIONS = {
|
|
6541
|
+
binaryName: "ascenda-claude-hook",
|
|
6542
|
+
setupCommand: "npx @ascenda-one/claude-code-hooks setup",
|
|
6543
|
+
loudEvent: "SessionStart"
|
|
6544
|
+
};
|
|
6545
|
+
LAUNCHER_SCRIPT = (0, import_tool_kit10.hookLauncherScript)(LAUNCHER_OPTIONS);
|
|
6546
|
+
}
|
|
6547
|
+
});
|
|
6548
|
+
|
|
5448
6549
|
// src/setup.ts
|
|
5449
6550
|
var setup_exports = {};
|
|
5450
6551
|
__export(setup_exports, {
|
|
5451
6552
|
HOOK_SET: () => HOOK_SET,
|
|
6553
|
+
REGISTERED_EVENT_COUNT: () => REGISTERED_EVENT_COUNT,
|
|
5452
6554
|
SENDS: () => SENDS,
|
|
5453
6555
|
findStaleHookCommands: () => findStaleHookCommands,
|
|
5454
6556
|
ourHookSets: () => ourHookSets,
|
|
6557
|
+
registrationSummary: () => registrationSummary,
|
|
5455
6558
|
runSetup: () => runSetup,
|
|
5456
6559
|
writeSettings: () => writeSettings
|
|
5457
6560
|
});
|
|
5458
6561
|
import * as crypto from "crypto";
|
|
5459
6562
|
import * as fs3 from "fs";
|
|
5460
|
-
import * as
|
|
6563
|
+
import * as os3 from "os";
|
|
5461
6564
|
import * as path3 from "path";
|
|
5462
6565
|
async function runSetup(argv) {
|
|
5463
6566
|
let options;
|
|
@@ -5474,17 +6577,21 @@ async function runSetup(argv) {
|
|
|
5474
6577
|
if (options.action === "status") return await printStatus(options);
|
|
5475
6578
|
if (options.action === "uninstall") return uninstall(options);
|
|
5476
6579
|
const apiBaseUrl = (options.apiBaseUrl ?? readCredentials()?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
console.log(`
|
|
5480
|
-
|
|
6580
|
+
const ui = (0, import_tool_kit11.terminalStyle)();
|
|
6581
|
+
const row = (tone, label, value) => console.log(` ${ui.mark(tone)} ${label.padEnd(12)} ${value}`);
|
|
6582
|
+
const detail = (label, value) => console.log(ui.dim(` ${label.padEnd(12)} ${value}`));
|
|
6583
|
+
console.log(`${ui.bold("Ascenda setup")} ${ui.dim(`\xB7 Claude Code \xB7 ${apiBaseUrl}`)}`);
|
|
6584
|
+
if (options.pair) console.log(`
|
|
6585
|
+
${(0, import_tool_kit11.renderSetupDisclosure)({ sends: SENDS, displayName: "Claude Code" })}
|
|
5481
6586
|
`);
|
|
6587
|
+
else console.log("");
|
|
5482
6588
|
const identity = await resolveIdentity(apiBaseUrl, options);
|
|
5483
6589
|
const unpaired = identity.pairing === "local-only";
|
|
5484
|
-
|
|
5485
|
-
if (unpaired) console.log(` installation ${identity.toolInstallationId} (recorded, so a later pair attaches to it)`);
|
|
6590
|
+
const chosenLocal = unpaired && !options.pair;
|
|
5486
6591
|
const binary = installBinary(options.dryRun);
|
|
5487
|
-
|
|
6592
|
+
const node = options.dryRun || process.platform === "win32" ? void 0 : resolveHookNode();
|
|
6593
|
+
if (node?.problem) row("bad", "hook binary", `${tidyHome(binary)}, but ${node.problem}. Install Node 20 or newer, then run setup again`);
|
|
6594
|
+
else row("ok", "hook binary", `${tidyHome(binary)}${node?.version ? ui.dim(` (Node ${node.version})`) : ""}`);
|
|
5488
6595
|
if (!options.dryRun) {
|
|
5489
6596
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5490
6597
|
writeCredentials({
|
|
@@ -5495,40 +6602,85 @@ ${(0, import_tool_kit8.renderSetupDisclosure)({ sends: SENDS, displayName: "Clau
|
|
|
5495
6602
|
// picks up.
|
|
5496
6603
|
...unpaired ? { localOnly: true, installedAt: now } : { pairedAt: now }
|
|
5497
6604
|
});
|
|
6605
|
+
if (options.eventLog !== void 0) (0, import_tool_kit11.writeEventLogSetting)(options.eventLog);
|
|
6606
|
+
}
|
|
6607
|
+
if (isHomeProject(options)) {
|
|
6608
|
+
detail("scope", "user (a project install in the home folder only loads when Claude Code starts there)");
|
|
6609
|
+
options.scope = "user";
|
|
5498
6610
|
}
|
|
5499
|
-
console.log(` credentials ${(0, import_tool_kit6.credentialsFilePath)()}`);
|
|
5500
6611
|
const settingsFile = settingsPath(options);
|
|
5501
6612
|
const before = ourHookSets(readSettingsFile(settingsFile));
|
|
5502
6613
|
const written = writeSettings(settingsFile, binary, options.dryRun);
|
|
5503
6614
|
if (written === null) return 1;
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
6615
|
+
const reach = options.scope === "user" ? "every project" : "this project only";
|
|
6616
|
+
row("ok", "hooks", `${tidyHome(settingsFile)} ${ui.dim(`(${HOOK_EVENTS.length} events, ${reach}${written ? "" : ", already current"})`)}`);
|
|
6617
|
+
const changes = (0, import_tool_kit11.describeHookSetChanges)((0, import_tool_kit11.hookSetChanges)(before, HOOK_EVENTS), HOOK_SET);
|
|
6618
|
+
if (changes) detail("", changes);
|
|
6619
|
+
const otherFiles = /* @__PURE__ */ new Set([
|
|
6620
|
+
settingsPath({ ...options, scope: options.scope === "user" ? "project" : "user" }),
|
|
6621
|
+
// The home folder's project file, where a project-scope setup run from
|
|
6622
|
+
// `~` used to put them.
|
|
6623
|
+
path3.join(os3.homedir(), ".claude", "settings.local.json")
|
|
6624
|
+
]);
|
|
6625
|
+
otherFiles.delete(settingsFile);
|
|
6626
|
+
for (const otherFile of otherFiles) {
|
|
6627
|
+
if (ourHookSets(readSettingsFile(otherFile)).size === 0) continue;
|
|
6628
|
+
if (options.dryRun) {
|
|
6629
|
+
row("info", "moved", `would remove the copy in ${tidyHome(otherFile)}, so each event runs once`);
|
|
6630
|
+
} else if (removeOurHooks(otherFile)) {
|
|
6631
|
+
row("ok", "moved", `removed the copy in ${tidyHome(otherFile)}, so each event runs once ${ui.dim("(backup beside it)")}`);
|
|
6632
|
+
} else {
|
|
6633
|
+
row("warn", "note", `${tidyHome(otherFile)} registers these hooks too, so each event runs twice.`);
|
|
6634
|
+
detail("", "Remove the ascenda-claude-hook entries from one of the two files.");
|
|
6635
|
+
}
|
|
5511
6636
|
}
|
|
6637
|
+
if (chosenLocal) {
|
|
6638
|
+
row("info", "pairing", `none, as asked ${ui.dim("(--no-pair)")}`);
|
|
6639
|
+
} else if (unpaired) {
|
|
6640
|
+
row("warn", "pairing", `not paired: ${identity.reason}`);
|
|
6641
|
+
if (identity.hint) detail("", identity.hint);
|
|
6642
|
+
} else {
|
|
6643
|
+
row("ok", "pairing", `${identity.toolInstallationId}${ui.dim(identity.pairing === "new" ? " (new)" : " (existing)")}`);
|
|
6644
|
+
}
|
|
6645
|
+
if (unpaired) detail("installation", `${identity.toolInstallationId} (kept, so pairing later attaches to it)`);
|
|
6646
|
+
detail("credentials", tidyHome((0, import_tool_kit6.credentialsFilePath)()));
|
|
6647
|
+
const eventLog = (0, import_tool_kit11.resolveEventLog)({ localOnly: unpaired });
|
|
6648
|
+
if (eventLog.path) row("ok", "events", `${tidyHome(eventLog.path)} ${ui.dim("(on this machine only)")}`);
|
|
6649
|
+
else if (options.eventLog !== void 0) row("info", "events", "off");
|
|
5512
6650
|
if (options.dryRun) {
|
|
5513
|
-
console.log("\nDry run
|
|
6651
|
+
console.log("\nDry run. Nothing was written.");
|
|
5514
6652
|
return 0;
|
|
5515
6653
|
}
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
console.log("
|
|
5522
|
-
console.log(
|
|
6654
|
+
const self = selfCommand();
|
|
6655
|
+
const next = (label, value) => console.log(` ${ui.bold(label.padEnd(6))} ${value}`);
|
|
6656
|
+
console.log("");
|
|
6657
|
+
if (chosenLocal) {
|
|
6658
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Ready.")} The screen saver and the Ascenda app's live view work now.`);
|
|
6659
|
+
console.log(" They run on this machine and need no account or pairing.");
|
|
6660
|
+
if (eventLog.path) console.log(` Every event is also written to ${tidyHome(eventLog.path)}, for you or any tool to read.`);
|
|
6661
|
+
} else if (unpaired) {
|
|
6662
|
+
console.log(`${ui.mark("warn")} ${ui.bold("Installed, not paired.")} The screen saver and the live view work now.`);
|
|
6663
|
+
console.log(` Your sessions won't reach Ascenda's servers until pairing completes.`);
|
|
5523
6664
|
} else {
|
|
5524
|
-
console.log("
|
|
6665
|
+
console.log(`${ui.mark("ok")} ${ui.bold("Done.")} Paired, and the hooks are installed.`);
|
|
6666
|
+
}
|
|
6667
|
+
console.log("");
|
|
6668
|
+
next("Next", `${restartLine(options)} Then type ${ui.cyan("/hooks")}: Ascenda's are under ${options.scope === "user" ? "User" : "Local"}.`);
|
|
6669
|
+
next("Check", ui.cyan(`${self} doctor`));
|
|
6670
|
+
if (unpaired) next(chosenLocal ? "Pair" : "Retry", `${ui.cyan(`${self} pair`)}${chosenLocal ? ui.dim(" (optional)") : ""}`);
|
|
6671
|
+
if (chosenLocal) {
|
|
6672
|
+
console.log("");
|
|
6673
|
+
console.log(ui.dim(" Pairing sends the details below to Ascenda's servers, under the account the"));
|
|
6674
|
+
console.log(ui.dim(" Ascenda app is signed in to when you confirm the code, so your sessions appear"));
|
|
6675
|
+
console.log(ui.dim(" in the app. Until you pair, nothing leaves this machine."));
|
|
6676
|
+
console.log("");
|
|
6677
|
+
console.log(ui.dim((0, import_tool_kit11.renderSetupDisclosure)({ sends: SENDS, displayName: "Claude Code" }).split("\n").map((line) => ` ${line}`).join("\n")));
|
|
5525
6678
|
}
|
|
5526
|
-
console.log(`Check anytime: npx @ascenda-one/claude-code-hooks status`);
|
|
5527
6679
|
return 0;
|
|
5528
6680
|
}
|
|
5529
6681
|
function parseArgs(argv) {
|
|
5530
6682
|
const options = {
|
|
5531
|
-
scope: "
|
|
6683
|
+
scope: "user",
|
|
5532
6684
|
projectDir: process.env.CLAUDE_PROJECT_DIR ?? process.cwd(),
|
|
5533
6685
|
dryRun: false,
|
|
5534
6686
|
pair: true,
|
|
@@ -5576,6 +6728,12 @@ function parseArgs(argv) {
|
|
|
5576
6728
|
case "--project-dir":
|
|
5577
6729
|
options.projectDir = path3.resolve(next());
|
|
5578
6730
|
break;
|
|
6731
|
+
case "--event-log": {
|
|
6732
|
+
const { value, consumed } = (0, import_tool_kit11.parseEventLogFlag)(argv, i);
|
|
6733
|
+
options.eventLog = value;
|
|
6734
|
+
i += consumed;
|
|
6735
|
+
break;
|
|
6736
|
+
}
|
|
5579
6737
|
case "--no-pair":
|
|
5580
6738
|
// `--no-pairing` is the spelling the CLI agents' setup landed under
|
|
5581
6739
|
// first, and the one their README still showed for a day. Both parse
|
|
@@ -5599,13 +6757,16 @@ ${USAGE}`);
|
|
|
5599
6757
|
}
|
|
5600
6758
|
return options;
|
|
5601
6759
|
}
|
|
6760
|
+
function isHomeProject(options) {
|
|
6761
|
+
return options.scope === "project" && path3.resolve(options.projectDir) === path3.resolve(os3.homedir());
|
|
6762
|
+
}
|
|
5602
6763
|
async function resolveIdentity(apiBaseUrl, options) {
|
|
5603
6764
|
const existingId = options.toolInstallationId ?? readCredentials()?.toolInstallationId;
|
|
5604
6765
|
if (existingId && options.token) {
|
|
5605
|
-
if (!options.dryRun) (0,
|
|
6766
|
+
if (!options.dryRun) (0, import_tool_kit11.persistEventWriteToken)((0, import_tool_kit11.defaultTokenFilePath)(existingId), options.token);
|
|
5606
6767
|
return { toolInstallationId: existingId, pairing: "existing" };
|
|
5607
6768
|
}
|
|
5608
|
-
if (existingId && (0,
|
|
6769
|
+
if (existingId && (0, import_tool_kit11.readTokenFile)((0, import_tool_kit11.defaultTokenFilePath)(existingId))) {
|
|
5609
6770
|
return { toolInstallationId: existingId, pairing: "existing" };
|
|
5610
6771
|
}
|
|
5611
6772
|
const toolInstallationId = existingId ?? (options.dryRun ? `${ASCENDA_TOOL_TYPE}:<minted at run time>` : `${ASCENDA_TOOL_TYPE}:${crypto.randomUUID()}`);
|
|
@@ -5617,7 +6778,7 @@ async function resolveIdentity(apiBaseUrl, options) {
|
|
|
5617
6778
|
}
|
|
5618
6779
|
let session;
|
|
5619
6780
|
try {
|
|
5620
|
-
session = await (0,
|
|
6781
|
+
session = await (0, import_tool_kit11.createPairingSession)(apiBaseUrl, toolInstallationId, ASCENDA_TOOL_TYPE, `Claude Code on ${os3.hostname()}`);
|
|
5621
6782
|
} catch (error) {
|
|
5622
6783
|
return {
|
|
5623
6784
|
toolInstallationId,
|
|
@@ -5628,7 +6789,7 @@ async function resolveIdentity(apiBaseUrl, options) {
|
|
|
5628
6789
|
}
|
|
5629
6790
|
const outcome = await pollForToken(apiBaseUrl, session.pairingSessionId, session.code, session.expiresAt);
|
|
5630
6791
|
if ("reason" in outcome) return { toolInstallationId, pairing: "local-only", reason: outcome.reason };
|
|
5631
|
-
(0,
|
|
6792
|
+
(0, import_tool_kit11.persistEventWriteToken)((0, import_tool_kit11.defaultTokenFilePath)(toolInstallationId), outcome.token);
|
|
5632
6793
|
return { toolInstallationId, pairing: "new" };
|
|
5633
6794
|
}
|
|
5634
6795
|
async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
@@ -5638,7 +6799,7 @@ async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
|
5638
6799
|
while (Date.now() < deadline) {
|
|
5639
6800
|
let status;
|
|
5640
6801
|
try {
|
|
5641
|
-
status = await (0,
|
|
6802
|
+
status = await (0, import_tool_kit11.getPairingStatus)(apiBaseUrl, pairingSessionId);
|
|
5642
6803
|
failures = 0;
|
|
5643
6804
|
} catch (error) {
|
|
5644
6805
|
if (++failures >= POLL_ERROR_TOLERANCE) {
|
|
@@ -5659,19 +6820,18 @@ async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
|
5659
6820
|
}
|
|
5660
6821
|
return { reason: "no confirmation within 5 minutes" };
|
|
5661
6822
|
}
|
|
6823
|
+
function tidyHome(file) {
|
|
6824
|
+
const home = os3.homedir();
|
|
6825
|
+
return file.startsWith(`${home}/`) ? `~${file.slice(home.length)}` : file;
|
|
6826
|
+
}
|
|
6827
|
+
function restartLine(options) {
|
|
6828
|
+
return options.scope === "user" ? "Restart Claude Code to load the hooks." : "Restart Claude Code in this project to load the hooks.";
|
|
6829
|
+
}
|
|
5662
6830
|
function installBinary(dryRun) {
|
|
5663
|
-
|
|
5664
|
-
if (dryRun) return target;
|
|
5665
|
-
const source = process.argv[1];
|
|
5666
|
-
fs3.mkdirSync(path3.dirname(target), { recursive: true });
|
|
5667
|
-
if (path3.resolve(source) !== path3.resolve(target)) {
|
|
5668
|
-
fs3.copyFileSync(source, target);
|
|
5669
|
-
}
|
|
5670
|
-
if (process.platform !== "win32") fs3.chmodSync(target, 493);
|
|
5671
|
-
return target;
|
|
6831
|
+
return (0, import_tool_kit11.installHookRunner)({ ...LAUNCHER_OPTIONS, dryRun });
|
|
5672
6832
|
}
|
|
5673
6833
|
function settingsPath(options) {
|
|
5674
|
-
return options.scope === "user" ? path3.join(
|
|
6834
|
+
return options.scope === "user" ? path3.join(os3.homedir(), ".claude", "settings.json") : path3.join(options.projectDir, ".claude", "settings.local.json");
|
|
5675
6835
|
}
|
|
5676
6836
|
function writeSettings(settingsFile, binary, dryRun) {
|
|
5677
6837
|
let settings = {};
|
|
@@ -5692,7 +6852,7 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
5692
6852
|
const hooks = { ...settings.hooks ?? {} };
|
|
5693
6853
|
for (const event of HOOK_EVENTS) {
|
|
5694
6854
|
const kept = (hooks[event] ?? []).filter((group) => !isOurs(group));
|
|
5695
|
-
hooks[event] = [...kept, { hooks: [{ type: "command", command: `${command} ${event}${(0,
|
|
6855
|
+
hooks[event] = [...kept, { hooks: [{ type: "command", command: `${command} ${event}${(0, import_tool_kit11.hookSetArgument)(HOOK_SET)}`, timeout: HOOK_TIMEOUT_SECONDS }] }];
|
|
5696
6856
|
}
|
|
5697
6857
|
const updated = { ...settings, hooks };
|
|
5698
6858
|
const serialised = `${JSON.stringify(updated, null, 2)}
|
|
@@ -5710,7 +6870,26 @@ ${serialised}`);
|
|
|
5710
6870
|
return true;
|
|
5711
6871
|
}
|
|
5712
6872
|
function hookCommand(binary) {
|
|
5713
|
-
return
|
|
6873
|
+
return (0, import_tool_kit11.hookRunnerCommand)(binary);
|
|
6874
|
+
}
|
|
6875
|
+
function removeOurHooks(settingsFile) {
|
|
6876
|
+
try {
|
|
6877
|
+
const settings = JSON.parse(fs3.readFileSync(settingsFile, "utf8"));
|
|
6878
|
+
const hooks = { ...settings.hooks ?? {} };
|
|
6879
|
+
for (const event of Object.keys(hooks)) {
|
|
6880
|
+
const kept = hooks[event].filter((group) => !isOurs(group));
|
|
6881
|
+
if (kept.length) hooks[event] = kept;
|
|
6882
|
+
else delete hooks[event];
|
|
6883
|
+
}
|
|
6884
|
+
const updated = { ...settings, hooks };
|
|
6885
|
+
if (!Object.keys(hooks).length) delete updated.hooks;
|
|
6886
|
+
fs3.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
6887
|
+
fs3.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
6888
|
+
`, "utf8");
|
|
6889
|
+
return true;
|
|
6890
|
+
} catch {
|
|
6891
|
+
return false;
|
|
6892
|
+
}
|
|
5714
6893
|
}
|
|
5715
6894
|
function isOurs(group) {
|
|
5716
6895
|
return (group.hooks ?? []).some((entry) => typeof entry.command === "string" && entry.command.includes(HOOK_MARKER));
|
|
@@ -5743,7 +6922,7 @@ function ourHookSets(settings) {
|
|
|
5743
6922
|
if (!isOurs(group)) continue;
|
|
5744
6923
|
for (const entry of group.hooks ?? []) {
|
|
5745
6924
|
if (typeof entry?.command !== "string") continue;
|
|
5746
|
-
const set = (0,
|
|
6925
|
+
const set = (0, import_tool_kit11.hookSetOfCommand)(entry.command);
|
|
5747
6926
|
sets.set(event, Math.min(set, sets.get(event) ?? set));
|
|
5748
6927
|
}
|
|
5749
6928
|
}
|
|
@@ -5754,11 +6933,26 @@ function countRegistered(settingsFile, binary) {
|
|
|
5754
6933
|
const settings = readSettingsFile(settingsFile);
|
|
5755
6934
|
return { settings, registered: HOOK_EVENTS.filter((event) => (settings.hooks?.[event] ?? []).some(isOurs)).length };
|
|
5756
6935
|
}
|
|
6936
|
+
function registrationSummary(projectDir) {
|
|
6937
|
+
const binary = hookBinPath();
|
|
6938
|
+
const files = /* @__PURE__ */ new Map([
|
|
6939
|
+
[settingsPath({ scope: "user", projectDir }), "user"],
|
|
6940
|
+
[settingsPath({ scope: "project", projectDir }), "project"],
|
|
6941
|
+
[path3.join(os3.homedir(), ".claude", "settings.local.json"), "project"]
|
|
6942
|
+
]);
|
|
6943
|
+
const found = [];
|
|
6944
|
+
for (const [file, scope] of files) {
|
|
6945
|
+
const { registered } = countRegistered(file, binary);
|
|
6946
|
+
if (registered === 0) continue;
|
|
6947
|
+
found.push({ file, scope, registered, homeProject: path3.resolve(file) === path3.resolve(os3.homedir(), ".claude", "settings.local.json") });
|
|
6948
|
+
}
|
|
6949
|
+
return found;
|
|
6950
|
+
}
|
|
5757
6951
|
async function printStatus(options) {
|
|
5758
6952
|
const credentials = readCredentials();
|
|
5759
6953
|
const settingsFile = settingsPath(options);
|
|
5760
6954
|
const binary = hookBinPath();
|
|
5761
|
-
const tokenFile = credentials?.toolInstallationId ? (0,
|
|
6955
|
+
const tokenFile = credentials?.toolInstallationId ? (0, import_tool_kit11.defaultTokenFilePath)(credentials.toolInstallationId) : void 0;
|
|
5762
6956
|
const unpaired = localOnlyInstall(credentials);
|
|
5763
6957
|
const here = countRegistered(settingsFile, binary);
|
|
5764
6958
|
const settings = here.settings;
|
|
@@ -5767,15 +6961,22 @@ async function printStatus(options) {
|
|
|
5767
6961
|
const otherFile = settingsPath(otherScope);
|
|
5768
6962
|
const elsewhere = registered === 0 && otherFile !== settingsFile ? countRegistered(otherFile, binary) : void 0;
|
|
5769
6963
|
const stale = findStaleHookCommands(settings, binary);
|
|
5770
|
-
console.log(`version ${(0,
|
|
6964
|
+
console.log(`version ${(0, import_tool_kit11.describeCollectorVersion)()}`);
|
|
5771
6965
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
5772
6966
|
console.log(`pairing ${describePairing(credentials, unpaired)}`);
|
|
5773
|
-
const fileToken = Boolean(tokenFile && (0,
|
|
6967
|
+
const fileToken = Boolean(tokenFile && (0, import_tool_kit11.readTokenFile)(tokenFile));
|
|
5774
6968
|
const token = fileToken || Boolean(envOverride("ASCENDA_EVENT_WRITE_TOKEN"));
|
|
5775
6969
|
console.log(`token ${fileToken ? "present" : token ? "from ASCENDA_EVENT_WRITE_TOKEN (no file)" : unpaired ? "\u2014 none until this install is paired" : "\u2014 missing"}`);
|
|
5776
6970
|
console.log(`delivery ${token ? "active" : unpaired ? "inactive \u2014 nothing is sent, and nothing is queued for later" : "\u2014 no token for this pairing, so nothing can be sent"}`);
|
|
5777
6971
|
console.log("local features active \u2014 the session prompts and the live socket signal need no pairing");
|
|
6972
|
+
console.log(`event log ${(0, import_tool_kit11.describeEventLog)((0, import_tool_kit11.resolveEventLog)({ localOnly: unpaired }), "npx @ascenda-one/claude-code-hooks setup")}`);
|
|
5778
6973
|
console.log(`hook binary ${fs3.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
6974
|
+
const node = process.platform === "win32" ? void 0 : resolveHookNode();
|
|
6975
|
+
if (node) {
|
|
6976
|
+
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"})`);
|
|
6977
|
+
}
|
|
6978
|
+
const last = readLastHook();
|
|
6979
|
+
console.log(last ? `last hook ${last.event}, ${(0, import_tool_kit9.describeAge)(Date.now() - Date.parse(last.at))}` : "last hook \u2014 none has run yet. Start Claude Code (restart it if it was open during setup), then check /hooks");
|
|
5779
6980
|
console.log(`hooks ${registered}/${HOOK_EVENTS.length} registered in ${settingsFile}`);
|
|
5780
6981
|
if (elsewhere && elsewhere.registered > 0) {
|
|
5781
6982
|
console.log(` ${elsewhere.registered}/${HOOK_EVENTS.length} found in ${otherFile} (--scope ${otherScope.scope})`);
|
|
@@ -5790,22 +6991,22 @@ async function printStatus(options) {
|
|
|
5790
6991
|
for (const command of stale) console.log(` ${command}`);
|
|
5791
6992
|
console.log(` Remove them from ${settingsFile} by hand; setup cannot tell them from a hook you wrote.`);
|
|
5792
6993
|
}
|
|
5793
|
-
const tokenValue = unpaired ? void 0 : (tokenFile ? (0,
|
|
6994
|
+
const tokenValue = unpaired ? void 0 : (tokenFile ? (0, import_tool_kit11.readTokenFile)(tokenFile) : void 0) ?? envOverride("ASCENDA_EVENT_WRITE_TOKEN") ?? void 0;
|
|
5794
6995
|
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? credentials?.apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
5795
6996
|
const [initiativeLines, notices] = await Promise.all([
|
|
5796
|
-
(0,
|
|
5797
|
-
(0,
|
|
6997
|
+
(0, import_tool_kit11.initiativesStatusLines)({ apiBaseUrl, eventWriteToken: tokenValue, pairCommand: `${selfCommand()} pair` }),
|
|
6998
|
+
(0, import_tool_kit11.studyNoticeStatus)({ apiBaseUrl, eventWriteToken: tokenValue, commandPrefix: "npx @ascenda-one/claude-code-hooks" })
|
|
5798
6999
|
]);
|
|
5799
7000
|
console.log("");
|
|
5800
7001
|
for (const line of initiativeLines) console.log(line);
|
|
5801
7002
|
for (const line of notices.lines) console.log(line);
|
|
5802
7003
|
if (process.stdout.isTTY) await notices.markShown();
|
|
5803
7004
|
if (unpaired) {
|
|
5804
|
-
console.log("\
|
|
5805
|
-
console.log(
|
|
7005
|
+
console.log("\nNot paired, which the screen saver and the live view don't need.");
|
|
7006
|
+
console.log(`To send your sessions to Ascenda's servers, so they appear in the app: ${selfCommand()} pair`);
|
|
5806
7007
|
}
|
|
5807
7008
|
const wired = registered === HOOK_EVENTS.length || options.scope === "project" && elsewhere?.registered === HOOK_EVENTS.length;
|
|
5808
|
-
const healthy = credentials?.toolInstallationId && wired && fs3.existsSync(binary) && !stale.length;
|
|
7009
|
+
const healthy = credentials?.toolInstallationId && wired && fs3.existsSync(binary) && !stale.length && !node?.problem;
|
|
5809
7010
|
return healthy ? 0 : 1;
|
|
5810
7011
|
}
|
|
5811
7012
|
function describePairing(credentials, unpaired) {
|
|
@@ -5818,44 +7019,33 @@ function uninstall(options) {
|
|
|
5818
7019
|
const unpaired = localOnlyInstall();
|
|
5819
7020
|
const settingsFile = settingsPath(options);
|
|
5820
7021
|
if (fs3.existsSync(settingsFile)) {
|
|
5821
|
-
|
|
5822
|
-
const settings = JSON.parse(fs3.readFileSync(settingsFile, "utf8"));
|
|
5823
|
-
const hooks = { ...settings.hooks ?? {} };
|
|
5824
|
-
for (const event of Object.keys(hooks)) {
|
|
5825
|
-
const kept = hooks[event].filter((group) => !isOurs(group));
|
|
5826
|
-
if (kept.length) hooks[event] = kept;
|
|
5827
|
-
else delete hooks[event];
|
|
5828
|
-
}
|
|
5829
|
-
const updated = { ...settings, hooks };
|
|
5830
|
-
if (!Object.keys(hooks).length) delete updated.hooks;
|
|
5831
|
-
fs3.copyFileSync(settingsFile, `${settingsFile}.ascenda-backup`);
|
|
5832
|
-
fs3.writeFileSync(settingsFile, `${JSON.stringify(updated, null, 2)}
|
|
5833
|
-
`, "utf8");
|
|
5834
|
-
console.log(`hooks removed from ${settingsFile}`);
|
|
5835
|
-
} catch {
|
|
7022
|
+
if (!removeOurHooks(settingsFile)) {
|
|
5836
7023
|
console.error(`could not parse ${settingsFile} \u2014 remove the ascenda hook entries by hand`);
|
|
5837
7024
|
return 1;
|
|
5838
7025
|
}
|
|
7026
|
+
console.log(`hooks removed from ${settingsFile}`);
|
|
5839
7027
|
}
|
|
5840
|
-
const
|
|
5841
|
-
|
|
5842
|
-
fs3.rmSync(
|
|
5843
|
-
console.log(`removed ${
|
|
7028
|
+
for (const file of [hookBinPath(), hookBundlePath(), hookNodeRecordPath(), hookNoNodePath()]) {
|
|
7029
|
+
if (!fs3.existsSync(file)) continue;
|
|
7030
|
+
fs3.rmSync(file);
|
|
7031
|
+
if (file === hookBinPath() || file === hookBundlePath()) console.log(`removed ${file}`);
|
|
5844
7032
|
}
|
|
5845
7033
|
const credentialsFile2 = (0, import_tool_kit6.credentialsFilePath)();
|
|
5846
7034
|
if (fs3.existsSync(credentialsFile2)) {
|
|
5847
7035
|
removeCredentials();
|
|
5848
7036
|
console.log(fs3.existsSync(credentialsFile2) ? `cleared the Claude Code pairing from ${credentialsFile2} (other tools' pairings kept)` : `removed ${credentialsFile2}`);
|
|
5849
7037
|
}
|
|
5850
|
-
console.log(unpaired ? "this install was never paired, so there is no token here and nothing to revoke" : `tokens left in ${path3.join((0,
|
|
7038
|
+
console.log(unpaired ? "this install was never paired, so there is no token here and nothing to revoke" : `tokens left in ${path3.join((0, import_tool_kit11.ascendaHome)(), "tokens")} \u2014 revoke in the Ascenda app to invalidate them`);
|
|
5851
7039
|
return 0;
|
|
5852
7040
|
}
|
|
5853
|
-
var
|
|
7041
|
+
var import_tool_kit11, HOOK_EVENTS, HOOK_SET, HOOK_TIMEOUT_SECONDS, HOOK_MARKER, SENDS, USAGE, POLL_ERROR_TOLERANCE, REGISTERED_EVENT_COUNT;
|
|
5854
7042
|
var init_setup = __esm({
|
|
5855
7043
|
"src/setup.ts"() {
|
|
5856
7044
|
"use strict";
|
|
5857
|
-
|
|
7045
|
+
import_tool_kit11 = __toESM(require_out3(), 1);
|
|
5858
7046
|
init_config();
|
|
7047
|
+
init_hookHealth();
|
|
7048
|
+
init_launcher();
|
|
5859
7049
|
init_paths();
|
|
5860
7050
|
init_types();
|
|
5861
7051
|
HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PreCompact", "PostCompact", "Stop", "StopFailure", "Notification", "SessionEnd", "SubagentStart", "SubagentStop"];
|
|
@@ -5883,24 +7073,28 @@ Options
|
|
|
5883
7073
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
5884
7074
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
5885
7075
|
--no-pair install without pairing: local features on, nothing sent
|
|
7076
|
+
--event-log [path|off] keep every event in a local JSONL file (default ~/.ascenda/events.jsonl).
|
|
7077
|
+
On by default when not paired; machine-wide, shared by every agent
|
|
5886
7078
|
(--no-pairing is accepted too)
|
|
5887
|
-
--scope project
|
|
7079
|
+
--scope user|project where hooks are registered (default user: every project)
|
|
5888
7080
|
--project-dir <path> project root for --scope project (default cwd)
|
|
5889
7081
|
--dry-run print what would change, write nothing
|
|
5890
7082
|
-h, --help
|
|
5891
7083
|
`;
|
|
5892
7084
|
POLL_ERROR_TOLERANCE = 3;
|
|
7085
|
+
REGISTERED_EVENT_COUNT = HOOK_EVENTS.length;
|
|
5893
7086
|
}
|
|
5894
7087
|
});
|
|
5895
7088
|
|
|
5896
7089
|
// src/cli.ts
|
|
5897
|
-
var
|
|
7090
|
+
var import_tool_kit14 = __toESM(require_out3(), 1);
|
|
7091
|
+
var import_tool_kit15 = __toESM(require_out3(), 1);
|
|
5898
7092
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
5899
7093
|
import * as fs4 from "node:fs";
|
|
5900
7094
|
|
|
5901
7095
|
// src/ascendaClient.ts
|
|
5902
|
-
var import_tool_kit = __toESM(
|
|
5903
|
-
var import_tool_kit2 = __toESM(
|
|
7096
|
+
var import_tool_kit = __toESM(require_out3(), 1);
|
|
7097
|
+
var import_tool_kit2 = __toESM(require_out3(), 1);
|
|
5904
7098
|
var AscendaClient = class {
|
|
5905
7099
|
sender;
|
|
5906
7100
|
constructor(config) {
|
|
@@ -5935,11 +7129,11 @@ var AscendaClient = class {
|
|
|
5935
7129
|
};
|
|
5936
7130
|
|
|
5937
7131
|
// src/mapClaudeEvent.ts
|
|
5938
|
-
var import_tool_kit4 = __toESM(
|
|
7132
|
+
var import_tool_kit4 = __toESM(require_out3(), 1);
|
|
5939
7133
|
init_types();
|
|
5940
7134
|
|
|
5941
7135
|
// src/safeExtract.ts
|
|
5942
|
-
var import_tool_kit3 = __toESM(
|
|
7136
|
+
var import_tool_kit3 = __toESM(require_out3(), 1);
|
|
5943
7137
|
|
|
5944
7138
|
// src/mapClaudeEvent.ts
|
|
5945
7139
|
function mapClaudeEvent(hookName, input) {
|
|
@@ -6267,6 +7461,8 @@ function liveEventFor(hookName, input) {
|
|
|
6267
7461
|
return "stop";
|
|
6268
7462
|
case "StopFailure":
|
|
6269
7463
|
return "halted";
|
|
7464
|
+
case "SessionEnd":
|
|
7465
|
+
return "halted";
|
|
6270
7466
|
case "Notification":
|
|
6271
7467
|
return notificationLiveEvent(input);
|
|
6272
7468
|
default:
|
|
@@ -6426,6 +7622,32 @@ function readSetting(file, key) {
|
|
|
6426
7622
|
init_config();
|
|
6427
7623
|
init_paths();
|
|
6428
7624
|
init_types();
|
|
7625
|
+
init_hookHealth();
|
|
7626
|
+
|
|
7627
|
+
// src/liveDoctor.ts
|
|
7628
|
+
var import_tool_kit12 = __toESM(require_out3(), 1);
|
|
7629
|
+
init_paths();
|
|
7630
|
+
var import_tool_kit13 = __toESM(require_out3(), 1);
|
|
7631
|
+
import * as os4 from "os";
|
|
7632
|
+
async function localSignalLines(projectDir = process.cwd()) {
|
|
7633
|
+
const { registrationSummary: registrationSummary2, REGISTERED_EVENT_COUNT: REGISTERED_EVENT_COUNT2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
|
|
7634
|
+
return (0, import_tool_kit12.liveSignalDoctorLines)({
|
|
7635
|
+
displayName: "Claude Code",
|
|
7636
|
+
tool: "claude_code",
|
|
7637
|
+
launcher: process.platform === "win32" ? void 0 : hookBinPath(),
|
|
7638
|
+
registrations: registrationSummary2(projectDir).map((entry) => ({ ...entry, file: tidy(entry.file) })),
|
|
7639
|
+
eventCount: REGISTERED_EVENT_COUNT2,
|
|
7640
|
+
selfCommand: selfCommand(),
|
|
7641
|
+
setupCommand: "npx @ascenda-one/claude-code-hooks setup",
|
|
7642
|
+
lookHint: "type /hooks"
|
|
7643
|
+
});
|
|
7644
|
+
}
|
|
7645
|
+
function tidy(file) {
|
|
7646
|
+
const home = os4.homedir();
|
|
7647
|
+
return file.startsWith(`${home}/`) ? `~${file.slice(home.length)}` : file;
|
|
7648
|
+
}
|
|
7649
|
+
|
|
7650
|
+
// src/cli.ts
|
|
6429
7651
|
var INTENTION_INVITE = "Ascenda tip: if it's natural, you can ask what would make this session count before diving in \u2014 one line is enough. Not a required step, and skip it entirely if the user is already mid-task.";
|
|
6430
7652
|
var MILESTONE_DEBRIEF_INVITE = "Ascenda tip: that finished a piece of work. If the moment suits, it's worth a short debrief \u2014 what moved, what's still unresolved, and what you'd do differently next time. One or two lines. Skip it if they're already onto the next thing.";
|
|
6431
7653
|
async function runPair() {
|
|
@@ -6441,10 +7663,10 @@ async function runPair() {
|
|
|
6441
7663
|
const { SENDS: SENDS2 } = isClaudeCode ? await Promise.resolve().then(() => (init_setup(), setup_exports)) : { SENDS: [] };
|
|
6442
7664
|
await writeStdout(
|
|
6443
7665
|
`
|
|
6444
|
-
${(0,
|
|
7666
|
+
${(0, import_tool_kit14.renderSetupDisclosure)({ sends: SENDS2, displayName: isClaudeCode ? "Claude Code" : toolType })}
|
|
6445
7667
|
`
|
|
6446
7668
|
);
|
|
6447
|
-
const session = await (0,
|
|
7669
|
+
const session = await (0, import_tool_kit14.createPairingSession)(apiBaseUrl, toolInstallationId, toolType, toolType === ASCENDA_TOOL_TYPE ? "Claude Code" : toolType);
|
|
6448
7670
|
const code = session.deviceCode ?? session.code;
|
|
6449
7671
|
await writeStdout(
|
|
6450
7672
|
`
|
|
@@ -6458,7 +7680,7 @@ Waiting for confirmation (expires ${session.expiresAt})...
|
|
|
6458
7680
|
const deadline = Date.now() + 11 * 60 * 1e3;
|
|
6459
7681
|
while (Date.now() < deadline) {
|
|
6460
7682
|
await new Promise((resolve2) => setTimeout(resolve2, 3e3));
|
|
6461
|
-
const status = await (0,
|
|
7683
|
+
const status = await (0, import_tool_kit14.getPairingStatus)(apiBaseUrl, session.pairingSessionId);
|
|
6462
7684
|
if (status.status === "pending") continue;
|
|
6463
7685
|
if (status.status !== "paired") {
|
|
6464
7686
|
process.stderr.write(`Pairing ${status.status}. Run the command again for a fresh code.
|
|
@@ -6474,8 +7696,8 @@ Waiting for confirmation (expires ${session.expiresAt})...
|
|
|
6474
7696
|
process.exitCode = 1;
|
|
6475
7697
|
return;
|
|
6476
7698
|
}
|
|
6477
|
-
const tokenFilePath = (0,
|
|
6478
|
-
(0,
|
|
7699
|
+
const tokenFilePath = (0, import_tool_kit14.defaultTokenFilePath)(pairedId);
|
|
7700
|
+
(0, import_tool_kit14.persistEventWriteToken)(tokenFilePath, status.eventWriteToken);
|
|
6479
7701
|
writeCredentials({ apiBaseUrl, toolInstallationId: pairedId, pairedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
6480
7702
|
await writeStdout(
|
|
6481
7703
|
`Paired. Write token saved to ${tokenFilePath}
|
|
@@ -6505,7 +7727,7 @@ async function runJoin(argv) {
|
|
|
6505
7727
|
`);
|
|
6506
7728
|
return 1;
|
|
6507
7729
|
}
|
|
6508
|
-
return (0,
|
|
7730
|
+
return (0, import_tool_kit14.runStudyJoin)({ apiBaseUrl, eventWriteToken, displayName: "Claude Code", joinCode });
|
|
6509
7731
|
}
|
|
6510
7732
|
async function runObject(argv) {
|
|
6511
7733
|
let apiBaseUrl;
|
|
@@ -6517,7 +7739,7 @@ async function runObject(argv) {
|
|
|
6517
7739
|
`);
|
|
6518
7740
|
return 1;
|
|
6519
7741
|
}
|
|
6520
|
-
return (0,
|
|
7742
|
+
return (0, import_tool_kit14.runStudyObjection)({
|
|
6521
7743
|
apiBaseUrl,
|
|
6522
7744
|
eventWriteToken,
|
|
6523
7745
|
commandPrefix: "npx @ascenda-one/claude-code-hooks",
|
|
@@ -6560,6 +7782,7 @@ async function main() {
|
|
|
6560
7782
|
);
|
|
6561
7783
|
}
|
|
6562
7784
|
const hookName = command;
|
|
7785
|
+
stampLastHook(hookName);
|
|
6563
7786
|
const input = await readJsonFromStdin();
|
|
6564
7787
|
const contextParts = [];
|
|
6565
7788
|
if (hookName === "SessionStart" && isNewSessionStart(input) && process.env.ASCENDA_DISABLE_INTENTION_INVITE !== "true") {
|
|
@@ -6574,15 +7797,15 @@ async function main() {
|
|
|
6574
7797
|
await writeStdout(JSON.stringify({
|
|
6575
7798
|
hookSpecificOutput: { hookEventName: hookName, additionalContext: contextParts.join("\n\n") }
|
|
6576
7799
|
}));
|
|
6577
|
-
if (pending) (0,
|
|
7800
|
+
if (pending) (0, import_tool_kit14.markFailureNotified)(pending.stateFilePath, pending.state);
|
|
6578
7801
|
}
|
|
6579
7802
|
await emitLive(hookName, input);
|
|
6580
7803
|
const mappedEvents = mapClaudeEvent(hookName, input);
|
|
6581
7804
|
if (!mappedEvents.length) return;
|
|
6582
|
-
const workContext = (0,
|
|
7805
|
+
const workContext = (0, import_tool_kit14.deriveWorkContext)((0, import_tool_kit14.getString)(input, ["cwd"]) ?? process.cwd());
|
|
6583
7806
|
if (workContext) {
|
|
6584
|
-
(0,
|
|
6585
|
-
(0,
|
|
7807
|
+
(0, import_tool_kit14.recordWorkContext)(workContext);
|
|
7808
|
+
(0, import_tool_kit14.recordForgeProjectAlias)(workContext);
|
|
6586
7809
|
}
|
|
6587
7810
|
let config;
|
|
6588
7811
|
try {
|
|
@@ -6590,19 +7813,19 @@ async function main() {
|
|
|
6590
7813
|
} catch (error) {
|
|
6591
7814
|
const unpaired = localOnlyInstall();
|
|
6592
7815
|
if (!unpaired && error instanceof MissingInstallationIdError) journalSkippedSend(error);
|
|
6593
|
-
const logFile = (0,
|
|
7816
|
+
const logFile = (0, import_tool_kit14.resolveEventLogPath)({ localOnly: unpaired });
|
|
6594
7817
|
if (!logFile) {
|
|
6595
7818
|
if (unpaired) return;
|
|
6596
7819
|
throw error;
|
|
6597
7820
|
}
|
|
6598
7821
|
for (const event of mappedEvents) {
|
|
6599
|
-
logUnsent(logFile, event, workContext, (0,
|
|
7822
|
+
logUnsent(logFile, event, workContext, (0, import_tool_kit14.getString)(input, ["session_id", "sessionId"]) ?? null);
|
|
6600
7823
|
}
|
|
6601
7824
|
return;
|
|
6602
7825
|
}
|
|
6603
7826
|
config.workspaceHash ??= workContext?.workspaceHash ?? null;
|
|
6604
7827
|
config.projectHash ??= workContext?.projectHash ?? null;
|
|
6605
|
-
config.sessionId ??= (0,
|
|
7828
|
+
config.sessionId ??= (0, import_tool_kit14.getString)(input, ["session_id", "sessionId"]) ?? null;
|
|
6606
7829
|
const client = new AscendaClient(config);
|
|
6607
7830
|
if (hookName === "SessionEnd") {
|
|
6608
7831
|
for (const event of mappedEvents) {
|
|
@@ -6618,7 +7841,7 @@ async function main() {
|
|
|
6618
7841
|
}
|
|
6619
7842
|
}
|
|
6620
7843
|
function journalSkippedSend(error) {
|
|
6621
|
-
(0,
|
|
7844
|
+
(0, import_tool_kit14.recordSendOutcome)(resolveStateFilePath(), (0, import_tool_kit14.unresolvedToolInstallationId)(ASCENDA_TOOL_TYPE), "skipped_no_installation_id", {
|
|
6622
7845
|
detail: error.candidates.length === 0 ? "no ASCENDA_TOOL_INSTALLATION_ID, no credentials.json pairing, no claude_code token file" : `no ASCENDA_TOOL_INSTALLATION_ID, no credentials.json pairing, ${error.candidates.length} claude_code token files (${error.candidates.join(", ")})`
|
|
6623
7846
|
});
|
|
6624
7847
|
}
|
|
@@ -6637,25 +7860,25 @@ async function emitLive(hookName, input) {
|
|
|
6637
7860
|
}
|
|
6638
7861
|
if (!event) return;
|
|
6639
7862
|
try {
|
|
6640
|
-
const prompt = event === "prompt_submitted" ? (0,
|
|
6641
|
-
const promptSource = event === "prompt_submitted" ? (0,
|
|
7863
|
+
const prompt = event === "prompt_submitted" ? (0, import_tool_kit14.getString)(input, ["prompt", "userPrompt", "message"]) ?? (0, import_tool_kit14.getNestedString)(input, [["payload", "prompt"], ["payload", "message"]]) : void 0;
|
|
7864
|
+
const promptSource = event === "prompt_submitted" ? (0, import_tool_kit14.getString)(input, ["promptSource", "prompt_source"]) : void 0;
|
|
6642
7865
|
const queued = promptSource === void 0 ? void 0 : promptSource === "queued";
|
|
6643
7866
|
const backgroundTasks = event === "stop" ? countBackgroundTasks(input) : void 0;
|
|
6644
|
-
const errorKind = hookName === "StopFailure" && event === "halted" ? (0,
|
|
7867
|
+
const errorKind = hookName === "StopFailure" && event === "halted" ? (0, import_tool_kit14.getString)(input, ["error"]) === "rate_limit" ? "rate_limit" : "error" : void 0;
|
|
6645
7868
|
const resumesAt = errorKind === "rate_limit" ? usageLimitResumesAt(input) : void 0;
|
|
6646
|
-
const agent = (0,
|
|
6647
|
-
const hookSet = (0,
|
|
6648
|
-
const viaPlugin = (0,
|
|
6649
|
-
await (0,
|
|
7869
|
+
const agent = (0, import_tool_kit14.findAgentProcess)(import_tool_kit14.AGENT_PROCESS.claude_code);
|
|
7870
|
+
const hookSet = (0, import_tool_kit14.readHookSet)(process.argv);
|
|
7871
|
+
const viaPlugin = (0, import_tool_kit14.readViaPlugin)(process.env);
|
|
7872
|
+
await (0, import_tool_kit14.emitLiveSignal)({
|
|
6650
7873
|
tool: process.env.ASCENDA_TOOL_TYPE ?? "claude_code",
|
|
6651
7874
|
// Concurrent sessions must count as separate streams for the X gauge.
|
|
6652
7875
|
// Without a session id every window collapses into one, so fall back to
|
|
6653
7876
|
// this process's parent — still per-session in practice, since Claude
|
|
6654
7877
|
// Code spawns hooks from the session process.
|
|
6655
|
-
session: (0,
|
|
6656
|
-
...(0,
|
|
7878
|
+
session: (0, import_tool_kit14.getString)(input, ["session_id", "sessionId"]) ?? process.env.ASCENDA_SESSION_ID ?? `ppid-${process.ppid}`,
|
|
7879
|
+
...(0, import_tool_kit14.livePidFields)(agent),
|
|
6657
7880
|
event,
|
|
6658
|
-
...prompt !== void 0 ? { sizeBucket: (0,
|
|
7881
|
+
...prompt !== void 0 ? { sizeBucket: (0, import_tool_kit14.bucketPromptSize)(prompt) } : {},
|
|
6659
7882
|
...queued !== void 0 ? { queued } : {},
|
|
6660
7883
|
...backgroundTasks !== void 0 ? { backgroundTasks } : {},
|
|
6661
7884
|
...hookSet !== void 0 ? { hookSet } : {},
|
|
@@ -6667,13 +7890,13 @@ async function emitLive(hookName, input) {
|
|
|
6667
7890
|
}
|
|
6668
7891
|
}
|
|
6669
7892
|
function usageLimitResumesAt(input) {
|
|
6670
|
-
const projectDir = process.env.CLAUDE_PROJECT_DIR ?? (0,
|
|
7893
|
+
const projectDir = process.env.CLAUDE_PROJECT_DIR ?? (0, import_tool_kit14.getString)(input, ["cwd"]);
|
|
6671
7894
|
if (!autoContinueEnabled({ projectDir })) return void 0;
|
|
6672
7895
|
const now = /* @__PURE__ */ new Date();
|
|
6673
7896
|
const texts = [
|
|
6674
|
-
(0,
|
|
6675
|
-
(0,
|
|
6676
|
-
(0,
|
|
7897
|
+
(0, import_tool_kit14.getString)(input, ["error_details"]),
|
|
7898
|
+
(0, import_tool_kit14.getNestedString)(input, [["error_details", "message"]]),
|
|
7899
|
+
(0, import_tool_kit14.getString)(input, ["last_assistant_message"])
|
|
6677
7900
|
];
|
|
6678
7901
|
for (const text of texts) {
|
|
6679
7902
|
const at = resumesAtFor(text, now);
|
|
@@ -6700,8 +7923,8 @@ function pendingFailureNotice(hookName) {
|
|
|
6700
7923
|
return void 0;
|
|
6701
7924
|
}
|
|
6702
7925
|
const stateFilePath = resolveStateFilePath(toolInstallationId);
|
|
6703
|
-
const state = (0,
|
|
6704
|
-
if (!(0,
|
|
7926
|
+
const state = (0, import_tool_kit14.readCollectorState)(stateFilePath);
|
|
7927
|
+
if (!(0, import_tool_kit14.shouldAnnounceFailure)(state) || !state) return void 0;
|
|
6705
7928
|
const since = state.lastSuccessAt ? `since ${state.lastSuccessAt}` : "and has never succeeded on this machine";
|
|
6706
7929
|
return {
|
|
6707
7930
|
text: `Ascenda note: work telemetry has not been reaching Ascenda ${since} (${describeOutcome(state)}). Your work is unaffected and nothing was lost from this session. Run \`npx @ascenda-one/claude-code-hooks doctor\` for details, or \`npx @ascenda-one/claude-code-hooks pair\` to reconnect. This note appears once.`,
|
|
@@ -6732,9 +7955,27 @@ function writeStdout(text) {
|
|
|
6732
7955
|
});
|
|
6733
7956
|
}
|
|
6734
7957
|
async function runDoctor() {
|
|
6735
|
-
const
|
|
6736
|
-
const
|
|
7958
|
+
const ui = (0, import_tool_kit15.terminalStyle)();
|
|
7959
|
+
const lines = [ui.bold("Ascenda doctor"), ""];
|
|
7960
|
+
try {
|
|
7961
|
+
lines.push(...await localSignalLines(process.env.CLAUDE_PROJECT_DIR ?? process.cwd()), "");
|
|
7962
|
+
} catch (error) {
|
|
7963
|
+
lines.push(` Live signal (could not be checked: ${error instanceof Error ? error.message : String(error)})`, "");
|
|
7964
|
+
}
|
|
6737
7965
|
const unpaired = localOnlyInstall();
|
|
7966
|
+
lines.push(` ${ui.bold("Local events")} ${(0, import_tool_kit14.describeEventLog)((0, import_tool_kit14.resolveEventLog)({ localOnly: unpaired }), "npx @ascenda-one/claude-code-hooks setup")}`, "");
|
|
7967
|
+
lines.push(unpaired ? ` ${ui.bold("Account sync")} ${ui.dim("(optional; this install isn't paired)")}` : ` ${ui.bold("Account sync")} ${ui.dim("(Telemetry)")}`);
|
|
7968
|
+
const telemetryStart = lines.length;
|
|
7969
|
+
const finish = async () => {
|
|
7970
|
+
if (unpaired) {
|
|
7971
|
+
const kept = lines.slice(telemetryStart).filter((line) => !isTelemetryRow(line) || /^ (Installation id|Mode) /.test(line));
|
|
7972
|
+
lines.splice(telemetryStart, lines.length - telemetryStart, ...kept);
|
|
7973
|
+
}
|
|
7974
|
+
for (let i = telemetryStart; i < lines.length; i++) lines[i] = markTelemetryLine(ui, lines[i], unpaired);
|
|
7975
|
+
await writeStdout(`${lines.join("\n")}
|
|
7976
|
+
`);
|
|
7977
|
+
};
|
|
7978
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
6738
7979
|
lines.push(` API base URL ${apiBaseUrl}`);
|
|
6739
7980
|
let resolved;
|
|
6740
7981
|
try {
|
|
@@ -6742,22 +7983,21 @@ async function runDoctor() {
|
|
|
6742
7983
|
} catch (error) {
|
|
6743
7984
|
lines.push(` Installation id (unresolved \u2014 ${error instanceof Error ? error.message : String(error)})`);
|
|
6744
7985
|
lines.push(...skippedSendLines(void 0));
|
|
6745
|
-
lines.push("", " Not paired on this machine. Run:",
|
|
6746
|
-
await
|
|
6747
|
-
`);
|
|
7986
|
+
lines.push("", " Not paired on this machine. Run:", ` ${selfCommand()} pair`);
|
|
7987
|
+
await finish();
|
|
6748
7988
|
return;
|
|
6749
7989
|
}
|
|
6750
7990
|
const { toolInstallationId } = resolved;
|
|
6751
7991
|
lines.push(` Installation id ${toolInstallationId}`);
|
|
6752
7992
|
lines.push(` Id source ${describeIdSource(resolved)}`);
|
|
6753
|
-
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0,
|
|
7993
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, import_tool_kit14.defaultTokenFilePath)(toolInstallationId);
|
|
6754
7994
|
lines.push(` Token file ${tokenFilePath}`);
|
|
6755
7995
|
lines.push(` Token ${describeToken(tokenFilePath, unpaired)}`);
|
|
6756
7996
|
const hasToken = fs4.existsSync(tokenFilePath) || Boolean(process.env.ASCENDA_EVENT_WRITE_TOKEN);
|
|
6757
|
-
lines.push(` Mode ${unpaired ? "
|
|
7997
|
+
lines.push(` Mode ${unpaired ? "not paired. The live signal works; nothing is sent to Ascenda's servers" : hasToken ? "paired \u2014 local features and telemetry active" : "paired, but no token on this machine \u2014 local features active, nothing can be sent"}`);
|
|
6758
7998
|
const stateFilePath = resolveStateFilePath(toolInstallationId);
|
|
6759
7999
|
lines.push(` Journal ${stateFilePath}`);
|
|
6760
|
-
const state = (0,
|
|
8000
|
+
const state = (0, import_tool_kit14.readCollectorState)(stateFilePath);
|
|
6761
8001
|
if (!state) {
|
|
6762
8002
|
lines.push(unpaired ? " Last outcome (none \u2014 nothing is sent from an install with no pairing)" : " Last outcome (no journal yet \u2014 no send attempted since this version was installed)");
|
|
6763
8003
|
} else {
|
|
@@ -6774,19 +8014,28 @@ async function runDoctor() {
|
|
|
6774
8014
|
if (unpaired) {
|
|
6775
8015
|
lines.push(
|
|
6776
8016
|
"",
|
|
6777
|
-
"
|
|
6778
|
-
"
|
|
6779
|
-
"
|
|
6780
|
-
|
|
8017
|
+
" Not paired, which is fine: the screen saver, the live view and the local",
|
|
8018
|
+
" event log work without it. Nothing leaves this machine and nothing is queued.",
|
|
8019
|
+
" To send your sessions to Ascenda's servers, so they appear in the app:",
|
|
8020
|
+
` ${ui.cyan(`${selfCommand()} pair`)}`
|
|
6781
8021
|
);
|
|
6782
|
-
await
|
|
6783
|
-
`);
|
|
8022
|
+
await finish();
|
|
6784
8023
|
return;
|
|
6785
8024
|
}
|
|
6786
8025
|
lines.push("", " Live round trip...");
|
|
6787
8026
|
lines.push(` ${await liveRoundTrip()}`);
|
|
6788
|
-
await
|
|
6789
|
-
|
|
8027
|
+
await finish();
|
|
8028
|
+
}
|
|
8029
|
+
function isTelemetryRow(line) {
|
|
8030
|
+
return line.length > 24 && line.startsWith(" ") && line[2] !== " " && line[22] === " " && line[23] === " " && line[24] !== " ";
|
|
8031
|
+
}
|
|
8032
|
+
function markTelemetryLine(ui, line, unpaired) {
|
|
8033
|
+
if (!isTelemetryRow(line)) return unpaired ? ui.dim(line) : line;
|
|
8034
|
+
const label = line.slice(2, 24).trim();
|
|
8035
|
+
const value = line.slice(24);
|
|
8036
|
+
const failed = /FAILED|missing|no token for|rejected/.test(value);
|
|
8037
|
+
const row = (0, import_tool_kit13.doctorRow)(ui, failed ? "bad" : /^(paired —|OK)/.test(value) ? "ok" : "info", label, value);
|
|
8038
|
+
return unpaired ? ui.dim(row) : row;
|
|
6790
8039
|
}
|
|
6791
8040
|
async function liveRoundTrip() {
|
|
6792
8041
|
let config;
|
|
@@ -6806,13 +8055,13 @@ function describeIdSource(resolved) {
|
|
|
6806
8055
|
case "credentials":
|
|
6807
8056
|
return "credentials file (~/.ascenda/credentials.json)";
|
|
6808
8057
|
case "disk":
|
|
6809
|
-
return `disk (token file ${(0,
|
|
8058
|
+
return `disk (token file ${(0, import_tool_kit14.defaultTokenFilePath)(resolved.toolInstallationId)})`;
|
|
6810
8059
|
}
|
|
6811
8060
|
}
|
|
6812
8061
|
function skippedSendLines(alreadyShown) {
|
|
6813
8062
|
const stateFilePath = resolveStateFilePath();
|
|
6814
8063
|
if (stateFilePath === alreadyShown) return [];
|
|
6815
|
-
const state = (0,
|
|
8064
|
+
const state = (0, import_tool_kit14.readCollectorState)(stateFilePath);
|
|
6816
8065
|
if (!state) return [];
|
|
6817
8066
|
const since = state.failingSince ? ` since ${state.failingSince}` : "";
|
|
6818
8067
|
return [
|
|
@@ -6824,17 +8073,17 @@ function skippedSendLines(alreadyShown) {
|
|
|
6824
8073
|
function outboxLines(toolInstallationId, state) {
|
|
6825
8074
|
const outboxFilePath = resolveOutboxFilePath(toolInstallationId);
|
|
6826
8075
|
const lines = [` Outbox ${outboxFilePath}`];
|
|
6827
|
-
const summary = (0,
|
|
8076
|
+
const summary = (0, import_tool_kit14.readOutboxSummary)(outboxFilePath);
|
|
6828
8077
|
if (!summary || summary.depth === 0) {
|
|
6829
8078
|
lines.push(" Outbox depth 0 (nothing waiting)");
|
|
6830
8079
|
} else {
|
|
6831
|
-
const oldest = summary.oldestQueuedAt ? ` \u2014 oldest queued ${summary.oldestQueuedAt} (${
|
|
8080
|
+
const oldest = summary.oldestQueuedAt ? ` \u2014 oldest queued ${summary.oldestQueuedAt} (${describeAge2(summary.oldestQueuedAt)} ago)` : "";
|
|
6832
8081
|
lines.push(` Outbox depth ${summary.depth} waiting${oldest}`);
|
|
6833
8082
|
}
|
|
6834
8083
|
if (summary && summary.unreadableLines > 0) {
|
|
6835
8084
|
lines.push(` Outbox unreadable ${summary.unreadableLines} line(s) did not parse \u2014 discarded and journaled on the next hook`);
|
|
6836
8085
|
}
|
|
6837
|
-
lines.push(` Outbox drain ${(0,
|
|
8086
|
+
lines.push(` Outbox drain ${(0, import_tool_kit14.outboxDrainEnabled)() ? "on (queued events are replayed, oldest first)" : "off \u2014 queued events are kept and bounded, not sent"} \u2014 ${import_tool_kit14.OUTBOX_DRAIN_ENV_VAR}`);
|
|
6838
8087
|
const discarded = state?.outboxDiscarded;
|
|
6839
8088
|
if (discarded) {
|
|
6840
8089
|
const reasons = Object.entries(discarded.lastReasons).map(([reason, count]) => `${count} ${reason}`).join(", ");
|
|
@@ -6843,7 +8092,7 @@ function outboxLines(toolInstallationId, state) {
|
|
|
6843
8092
|
}
|
|
6844
8093
|
return lines;
|
|
6845
8094
|
}
|
|
6846
|
-
function
|
|
8095
|
+
function describeAge2(isoTimestamp) {
|
|
6847
8096
|
const ms = Date.now() - Date.parse(isoTimestamp);
|
|
6848
8097
|
if (!Number.isFinite(ms) || ms < 0) return "0m";
|
|
6849
8098
|
const minutes = Math.floor(ms / 6e4);
|
|
@@ -6866,7 +8115,7 @@ function describeToken(tokenFilePath, unpaired) {
|
|
|
6866
8115
|
}
|
|
6867
8116
|
}
|
|
6868
8117
|
function logUnsent(logFile, event, workContext, sessionId) {
|
|
6869
|
-
const payload = (0,
|
|
8118
|
+
const payload = (0, import_tool_kit14.buildEventPayload)({
|
|
6870
8119
|
toolInstallationId: `${ASCENDA_TOOL_TYPE}:unpaired`,
|
|
6871
8120
|
source: "claude_code",
|
|
6872
8121
|
// The payload's session, same as a delivered row — this log exists so
|
|
@@ -6877,7 +8126,7 @@ function logUnsent(logFile, event, workContext, sessionId) {
|
|
|
6877
8126
|
workspaceHash: envOverride("ASCENDA_WORKSPACE_HASH") ?? workContext?.workspaceHash ?? null,
|
|
6878
8127
|
projectHash: envOverride("ASCENDA_PROJECT_HASH") ?? workContext?.projectHash ?? null
|
|
6879
8128
|
}, event);
|
|
6880
|
-
(0,
|
|
8129
|
+
(0, import_tool_kit14.appendEventLog)(logFile, { loggedAt: (/* @__PURE__ */ new Date()).toISOString(), delivery: "not_sent", payload });
|
|
6881
8130
|
}
|
|
6882
8131
|
async function readJsonFromStdin() {
|
|
6883
8132
|
const chunks = [];
|