@ascenda-one/github-collector 0.1.34 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/cli.js +618 -376
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -629,9 +629,11 @@ var require_out = __commonJS({
|
|
|
629
629
|
"../packages/tool-contract/out/index.js"(exports) {
|
|
630
630
|
"use strict";
|
|
631
631
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
632
|
-
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;
|
|
632
|
+
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;
|
|
633
633
|
exports.combineDisjointHalves = combineDisjointHalves;
|
|
634
634
|
exports.requireComparableQuantities = requireComparableQuantities;
|
|
635
|
+
exports.joinEventPayload = joinEventPayload;
|
|
636
|
+
exports.splitEventPayload = splitEventPayload;
|
|
635
637
|
exports.ASCENDA_TELEMETRY_SOURCES = [
|
|
636
638
|
"vscode_extension",
|
|
637
639
|
"cursor_mcp",
|
|
@@ -783,6 +785,24 @@ var require_out = __commonJS({
|
|
|
783
785
|
"importSchema",
|
|
784
786
|
"collectorVersion"
|
|
785
787
|
];
|
|
788
|
+
exports.DELIVERY_ENVELOPE_KEYS = ["toolInstallationId", "idempotencyKey"];
|
|
789
|
+
function joinEventPayload(envelope, body) {
|
|
790
|
+
const payload = { toolInstallationId: envelope.toolInstallationId };
|
|
791
|
+
for (const [key, value] of Object.entries(body)) {
|
|
792
|
+
payload[key] = value;
|
|
793
|
+
if (key === "occurredAt" && envelope.idempotencyKey !== void 0) {
|
|
794
|
+
payload.idempotencyKey = envelope.idempotencyKey;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
return payload;
|
|
798
|
+
}
|
|
799
|
+
function splitEventPayload(payload) {
|
|
800
|
+
const { toolInstallationId, idempotencyKey, ...body } = payload;
|
|
801
|
+
const envelope = { toolInstallationId };
|
|
802
|
+
if (idempotencyKey !== void 0)
|
|
803
|
+
envelope.idempotencyKey = idempotencyKey;
|
|
804
|
+
return { envelope, body };
|
|
805
|
+
}
|
|
786
806
|
exports.IDEMPOTENCY_KEY_MAX_LENGTH = 128;
|
|
787
807
|
exports.TOOL_EVENT_DELIVERED_STATUSES = ["accepted", "duplicate"];
|
|
788
808
|
exports.EVENT_WORKLOAD_CATEGORY = {
|
|
@@ -961,13 +981,387 @@ var require_collectorVersion = __commonJS({
|
|
|
961
981
|
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
962
982
|
exports.describeCollectorVersion = describeCollectorVersion;
|
|
963
983
|
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
964
|
-
exports.COLLECTOR_VERSION = "0.1.
|
|
984
|
+
exports.COLLECTOR_VERSION = "0.1.35" ? "0.1.35" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
965
985
|
function describeCollectorVersion(version = exports.COLLECTOR_VERSION) {
|
|
966
986
|
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
967
987
|
}
|
|
968
988
|
}
|
|
969
989
|
});
|
|
970
990
|
|
|
991
|
+
// ../packages/agent-events/out/index.js
|
|
992
|
+
var require_out2 = __commonJS({
|
|
993
|
+
"../packages/agent-events/out/index.js"(exports) {
|
|
994
|
+
"use strict";
|
|
995
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
996
|
+
exports.KNOWN_AGENTS = exports.AGENT_EVENT_KINDS = exports.AGENT_EVENT_SCHEMA = void 0;
|
|
997
|
+
exports.isAgentEventV0 = isAgentEventV0;
|
|
998
|
+
exports.parseEventLogLine = parseEventLogLine;
|
|
999
|
+
exports.normaliseKind = normaliseKind;
|
|
1000
|
+
exports.AGENT_EVENT_SCHEMA = "agent-event/v0";
|
|
1001
|
+
exports.AGENT_EVENT_KINDS = [
|
|
1002
|
+
"session.started",
|
|
1003
|
+
"session.ended",
|
|
1004
|
+
"prompt.submitted",
|
|
1005
|
+
"tool.started",
|
|
1006
|
+
"tool.completed",
|
|
1007
|
+
"tool.failed",
|
|
1008
|
+
"turn.completed",
|
|
1009
|
+
"agent.waiting",
|
|
1010
|
+
"context.compacted",
|
|
1011
|
+
"subagent.started",
|
|
1012
|
+
"subagent.stopped",
|
|
1013
|
+
"other"
|
|
1014
|
+
];
|
|
1015
|
+
exports.KNOWN_AGENTS = ["claude_code", "codex", "cursor", "gemini_cli", "windsurf", "vscode"];
|
|
1016
|
+
function isAgentEventV0(value) {
|
|
1017
|
+
if (!value || typeof value !== "object")
|
|
1018
|
+
return false;
|
|
1019
|
+
const e = value;
|
|
1020
|
+
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";
|
|
1021
|
+
}
|
|
1022
|
+
function parseEventLogLine(line) {
|
|
1023
|
+
if (!line.trim())
|
|
1024
|
+
return void 0;
|
|
1025
|
+
try {
|
|
1026
|
+
const parsed = JSON.parse(line);
|
|
1027
|
+
return isAgentEventV0(parsed?.event) ? parsed.event : void 0;
|
|
1028
|
+
} catch {
|
|
1029
|
+
return void 0;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
function normaliseKind(kind) {
|
|
1033
|
+
return exports.AGENT_EVENT_KINDS.includes(kind) ? kind : "other";
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
|
|
1038
|
+
// ../packages/tool-kit/out/agentEvent.js
|
|
1039
|
+
var require_agentEvent = __commonJS({
|
|
1040
|
+
"../packages/tool-kit/out/agentEvent.js"(exports) {
|
|
1041
|
+
"use strict";
|
|
1042
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1043
|
+
exports.toAgentEvent = toAgentEvent;
|
|
1044
|
+
var agent_events_1 = require_out2();
|
|
1045
|
+
var KIND_BY_TYPE = {
|
|
1046
|
+
create_focus_session: "session.started",
|
|
1047
|
+
recovery_offline_period: "session.ended",
|
|
1048
|
+
ai_prompt_submitted: "prompt.submitted",
|
|
1049
|
+
ai_tool_call_started: "tool.started",
|
|
1050
|
+
ai_tool_call_completed: "tool.completed",
|
|
1051
|
+
ai_file_write: "tool.completed",
|
|
1052
|
+
ai_file_edit: "tool.completed",
|
|
1053
|
+
editor_verification_activity: "tool.completed",
|
|
1054
|
+
ai_tool_call_failed: "tool.failed",
|
|
1055
|
+
compile_error: "tool.failed",
|
|
1056
|
+
tool_failure: "tool.failed",
|
|
1057
|
+
ai_turn_completed: "turn.completed",
|
|
1058
|
+
supervision_interruption: "agent.waiting",
|
|
1059
|
+
context_compression_manual: "context.compacted",
|
|
1060
|
+
context_compression_auto: "context.compacted",
|
|
1061
|
+
subagent_started: "subagent.started",
|
|
1062
|
+
subagent_stopped: "subagent.stopped"
|
|
1063
|
+
};
|
|
1064
|
+
function agentOf(payload) {
|
|
1065
|
+
const host = stringField(payload.metadata?.host);
|
|
1066
|
+
if (host)
|
|
1067
|
+
return host;
|
|
1068
|
+
return payload.source === "vscode_extension" ? "vscode" : payload.source;
|
|
1069
|
+
}
|
|
1070
|
+
function stringField(value) {
|
|
1071
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1072
|
+
}
|
|
1073
|
+
function toAgentEvent(payload) {
|
|
1074
|
+
const metadata = payload.metadata ?? {};
|
|
1075
|
+
const kind = KIND_BY_TYPE[payload.eventType] ?? "other";
|
|
1076
|
+
const tool = kind.startsWith("tool.") ? stringField(metadata.toolName) : void 0;
|
|
1077
|
+
const outcome = stringField(metadata.outcome);
|
|
1078
|
+
return {
|
|
1079
|
+
schema: agent_events_1.AGENT_EVENT_SCHEMA,
|
|
1080
|
+
id: payload.idempotencyKey ?? `${payload.toolInstallationId}:${payload.occurredAt}:${payload.eventType}`,
|
|
1081
|
+
time: payload.occurredAt,
|
|
1082
|
+
// `+ 0` turns the -0 a UTC machine computes into 0, which is what JSON
|
|
1083
|
+
// writes anyway; without it the event in memory and the one on disk differ.
|
|
1084
|
+
...typeof payload.utcOffsetMinutes === "number" ? { utcOffsetMinutes: payload.utcOffsetMinutes + 0 } : {},
|
|
1085
|
+
agent: agentOf(payload),
|
|
1086
|
+
kind,
|
|
1087
|
+
...stringField(payload.sessionId) ? { sessionId: payload.sessionId } : {},
|
|
1088
|
+
...stringField(metadata.subagentId) ? { subagentId: metadata.subagentId } : {},
|
|
1089
|
+
...tool ? { tool } : {},
|
|
1090
|
+
...outcome && outcome !== "unknown" ? { outcome } : {},
|
|
1091
|
+
...stringField(metadata.durationBucket) ? { durationBucket: metadata.durationBucket } : {},
|
|
1092
|
+
...stringField(payload.projectHash) ? { projectHash: payload.projectHash } : {},
|
|
1093
|
+
...stringField(metadata.collectorVersion) ? { collectorVersion: metadata.collectorVersion } : {},
|
|
1094
|
+
sourceType: payload.eventType
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
// ../packages/tool-kit/out/tokenStore.js
|
|
1101
|
+
var require_tokenStore = __commonJS({
|
|
1102
|
+
"../packages/tool-kit/out/tokenStore.js"(exports) {
|
|
1103
|
+
"use strict";
|
|
1104
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1105
|
+
if (k2 === void 0) k2 = k;
|
|
1106
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1107
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1108
|
+
desc = { enumerable: true, get: function() {
|
|
1109
|
+
return m[k];
|
|
1110
|
+
} };
|
|
1111
|
+
}
|
|
1112
|
+
Object.defineProperty(o, k2, desc);
|
|
1113
|
+
} : function(o, m, k, k2) {
|
|
1114
|
+
if (k2 === void 0) k2 = k;
|
|
1115
|
+
o[k2] = m[k];
|
|
1116
|
+
});
|
|
1117
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1118
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1119
|
+
} : function(o, v) {
|
|
1120
|
+
o["default"] = v;
|
|
1121
|
+
});
|
|
1122
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1123
|
+
var ownKeys = function(o) {
|
|
1124
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1125
|
+
var ar = [];
|
|
1126
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1127
|
+
return ar;
|
|
1128
|
+
};
|
|
1129
|
+
return ownKeys(o);
|
|
1130
|
+
};
|
|
1131
|
+
return function(mod) {
|
|
1132
|
+
if (mod && mod.__esModule) return mod;
|
|
1133
|
+
var result = {};
|
|
1134
|
+
if (mod != null) {
|
|
1135
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1136
|
+
}
|
|
1137
|
+
__setModuleDefault(result, mod);
|
|
1138
|
+
return result;
|
|
1139
|
+
};
|
|
1140
|
+
}();
|
|
1141
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1142
|
+
exports.EVENT_TOKEN_TTL_MS = void 0;
|
|
1143
|
+
exports.ascendaHome = ascendaHome;
|
|
1144
|
+
exports.defaultTokenFilePath = defaultTokenFilePath2;
|
|
1145
|
+
exports.tokenExpiryFilePath = tokenExpiryFilePath;
|
|
1146
|
+
exports.persistEventWriteToken = persistEventWriteToken2;
|
|
1147
|
+
exports.readTokenExpiry = readTokenExpiry;
|
|
1148
|
+
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds;
|
|
1149
|
+
exports.readTokenFile = readTokenFile2;
|
|
1150
|
+
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1151
|
+
var fs = __importStar(__require("fs"));
|
|
1152
|
+
var os = __importStar(__require("os"));
|
|
1153
|
+
var path = __importStar(__require("path"));
|
|
1154
|
+
function ascendaHome(home = os.homedir()) {
|
|
1155
|
+
return process.env.ASCENDA_HOME ?? path.join(home, ".ascenda");
|
|
1156
|
+
}
|
|
1157
|
+
function defaultTokenFilePath2(toolInstallationId) {
|
|
1158
|
+
return path.join(ascendaHome(), "tokens", sanitizeFilePart(toolInstallationId));
|
|
1159
|
+
}
|
|
1160
|
+
function tokenExpiryFilePath(tokenFilePath) {
|
|
1161
|
+
return path.join(path.dirname(tokenFilePath), "expiry", path.basename(tokenFilePath));
|
|
1162
|
+
}
|
|
1163
|
+
function persistEventWriteToken2(tokenFilePath, token, expiresAt) {
|
|
1164
|
+
const dir = path.dirname(tokenFilePath);
|
|
1165
|
+
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1166
|
+
fs.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
1167
|
+
if (process.platform !== "win32") {
|
|
1168
|
+
fs.chmodSync(dir, 448);
|
|
1169
|
+
fs.chmodSync(tokenFilePath, 384);
|
|
1170
|
+
}
|
|
1171
|
+
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1172
|
+
try {
|
|
1173
|
+
if (expiresAt && Number.isFinite(Date.parse(expiresAt))) {
|
|
1174
|
+
fs.mkdirSync(path.dirname(expiryFile), { recursive: true, mode: 448 });
|
|
1175
|
+
fs.writeFileSync(expiryFile, expiresAt, { encoding: "utf8", mode: 384 });
|
|
1176
|
+
} else {
|
|
1177
|
+
fs.rmSync(expiryFile, { force: true });
|
|
1178
|
+
}
|
|
1179
|
+
} catch {
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
exports.EVENT_TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1183
|
+
function readTokenExpiry(tokenFilePath) {
|
|
1184
|
+
try {
|
|
1185
|
+
const recorded = Date.parse(fs.readFileSync(tokenExpiryFilePath(tokenFilePath), "utf8").trim());
|
|
1186
|
+
if (Number.isFinite(recorded))
|
|
1187
|
+
return recorded;
|
|
1188
|
+
} catch {
|
|
1189
|
+
}
|
|
1190
|
+
try {
|
|
1191
|
+
return fs.statSync(tokenFilePath).mtimeMs + exports.EVENT_TOKEN_TTL_MS;
|
|
1192
|
+
} catch {
|
|
1193
|
+
return void 0;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
function listPersistedToolInstallationIds(toolType) {
|
|
1197
|
+
const prefix = `${sanitizeFilePart(toolType)}_`;
|
|
1198
|
+
const dir = path.join(ascendaHome(), "tokens");
|
|
1199
|
+
let names;
|
|
1200
|
+
try {
|
|
1201
|
+
names = fs.readdirSync(dir);
|
|
1202
|
+
} catch {
|
|
1203
|
+
return [];
|
|
1204
|
+
}
|
|
1205
|
+
const ids = [];
|
|
1206
|
+
for (const name of names.sort()) {
|
|
1207
|
+
if (!name.startsWith(prefix) || name.length === prefix.length)
|
|
1208
|
+
continue;
|
|
1209
|
+
const file = path.join(dir, name);
|
|
1210
|
+
try {
|
|
1211
|
+
if (!fs.statSync(file).isFile())
|
|
1212
|
+
continue;
|
|
1213
|
+
} catch {
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
if (readTokenFile2(file) === void 0)
|
|
1217
|
+
continue;
|
|
1218
|
+
ids.push(`${toolType}:${name.slice(prefix.length)}`);
|
|
1219
|
+
}
|
|
1220
|
+
return ids;
|
|
1221
|
+
}
|
|
1222
|
+
function readTokenFile2(tokenFilePath) {
|
|
1223
|
+
try {
|
|
1224
|
+
if (!fs.existsSync(tokenFilePath))
|
|
1225
|
+
return void 0;
|
|
1226
|
+
const value = fs.readFileSync(tokenFilePath, "utf8").trim();
|
|
1227
|
+
return value || void 0;
|
|
1228
|
+
} catch {
|
|
1229
|
+
return void 0;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function sanitizeFilePart(value) {
|
|
1233
|
+
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
|
|
1238
|
+
// ../packages/tool-kit/out/credentials.js
|
|
1239
|
+
var require_credentials = __commonJS({
|
|
1240
|
+
"../packages/tool-kit/out/credentials.js"(exports) {
|
|
1241
|
+
"use strict";
|
|
1242
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1243
|
+
if (k2 === void 0) k2 = k;
|
|
1244
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1245
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1246
|
+
desc = { enumerable: true, get: function() {
|
|
1247
|
+
return m[k];
|
|
1248
|
+
} };
|
|
1249
|
+
}
|
|
1250
|
+
Object.defineProperty(o, k2, desc);
|
|
1251
|
+
} : function(o, m, k, k2) {
|
|
1252
|
+
if (k2 === void 0) k2 = k;
|
|
1253
|
+
o[k2] = m[k];
|
|
1254
|
+
});
|
|
1255
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1256
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1257
|
+
} : function(o, v) {
|
|
1258
|
+
o["default"] = v;
|
|
1259
|
+
});
|
|
1260
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1261
|
+
var ownKeys = function(o) {
|
|
1262
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1263
|
+
var ar = [];
|
|
1264
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1265
|
+
return ar;
|
|
1266
|
+
};
|
|
1267
|
+
return ownKeys(o);
|
|
1268
|
+
};
|
|
1269
|
+
return function(mod) {
|
|
1270
|
+
if (mod && mod.__esModule) return mod;
|
|
1271
|
+
var result = {};
|
|
1272
|
+
if (mod != null) {
|
|
1273
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1274
|
+
}
|
|
1275
|
+
__setModuleDefault(result, mod);
|
|
1276
|
+
return result;
|
|
1277
|
+
};
|
|
1278
|
+
}();
|
|
1279
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1280
|
+
exports.credentialsFilePath = credentialsFilePath;
|
|
1281
|
+
exports.readMachineCredentials = readMachineCredentials;
|
|
1282
|
+
exports.writeMachineCredentials = writeMachineCredentials;
|
|
1283
|
+
exports.writeTopLevelCredentials = writeTopLevelCredentials;
|
|
1284
|
+
exports.writeEventLogSetting = writeEventLogSetting;
|
|
1285
|
+
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
1286
|
+
exports.readHostCredentials = readHostCredentials;
|
|
1287
|
+
exports.writeHostCredentials = writeHostCredentials;
|
|
1288
|
+
exports.removeHostCredentials = removeHostCredentials;
|
|
1289
|
+
var fs = __importStar(__require("fs"));
|
|
1290
|
+
var path = __importStar(__require("path"));
|
|
1291
|
+
var tokenStore_1 = require_tokenStore();
|
|
1292
|
+
function credentialsFilePath() {
|
|
1293
|
+
return path.join((0, tokenStore_1.ascendaHome)(), "credentials.json");
|
|
1294
|
+
}
|
|
1295
|
+
function readMachineCredentials() {
|
|
1296
|
+
try {
|
|
1297
|
+
const raw = fs.readFileSync(credentialsFilePath(), "utf8").trim();
|
|
1298
|
+
if (!raw)
|
|
1299
|
+
return void 0;
|
|
1300
|
+
const parsed = JSON.parse(raw);
|
|
1301
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
1302
|
+
return void 0;
|
|
1303
|
+
return parsed;
|
|
1304
|
+
} catch {
|
|
1305
|
+
return void 0;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
function writeMachineCredentials(credentials) {
|
|
1309
|
+
const file = credentialsFilePath();
|
|
1310
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 448 });
|
|
1311
|
+
fs.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
1312
|
+
`, { encoding: "utf8", mode: 384 });
|
|
1313
|
+
if (process.platform !== "win32") {
|
|
1314
|
+
fs.chmodSync(path.dirname(file), 448);
|
|
1315
|
+
fs.chmodSync(file, 384);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
function writeTopLevelCredentials(credentials) {
|
|
1319
|
+
const existing = readMachineCredentials();
|
|
1320
|
+
const eventLogPath = credentials.eventLogPath ?? existing?.eventLogPath;
|
|
1321
|
+
writeMachineCredentials({
|
|
1322
|
+
...credentials,
|
|
1323
|
+
...eventLogPath ? { eventLogPath } : {},
|
|
1324
|
+
...existing?.tools ? { tools: existing.tools } : {}
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
function writeEventLogSetting(value) {
|
|
1328
|
+
const existing = readMachineCredentials() ?? {};
|
|
1329
|
+
writeMachineCredentials({ ...existing, eventLogPath: value });
|
|
1330
|
+
}
|
|
1331
|
+
function isLocalOnlyHostInstall(host, hasToken) {
|
|
1332
|
+
const credentials = readHostCredentials(host);
|
|
1333
|
+
if (!credentials?.localOnly)
|
|
1334
|
+
return false;
|
|
1335
|
+
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
1336
|
+
return false;
|
|
1337
|
+
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
1338
|
+
}
|
|
1339
|
+
function readHostCredentials(host) {
|
|
1340
|
+
const entry = readMachineCredentials()?.tools?.[host];
|
|
1341
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
1342
|
+
return void 0;
|
|
1343
|
+
return entry;
|
|
1344
|
+
}
|
|
1345
|
+
function writeHostCredentials(host, credentials) {
|
|
1346
|
+
const existing = readMachineCredentials() ?? {};
|
|
1347
|
+
writeMachineCredentials({ ...existing, tools: { ...existing.tools ?? {}, [host]: credentials } });
|
|
1348
|
+
}
|
|
1349
|
+
function removeHostCredentials(host) {
|
|
1350
|
+
const existing = readMachineCredentials();
|
|
1351
|
+
if (!existing?.tools || !(host in existing.tools))
|
|
1352
|
+
return;
|
|
1353
|
+
const tools = { ...existing.tools };
|
|
1354
|
+
delete tools[host];
|
|
1355
|
+
const next = { ...existing };
|
|
1356
|
+
if (Object.keys(tools).length)
|
|
1357
|
+
next.tools = tools;
|
|
1358
|
+
else
|
|
1359
|
+
delete next.tools;
|
|
1360
|
+
writeMachineCredentials(next);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
|
|
971
1365
|
// ../packages/tool-kit/out/eventLog.js
|
|
972
1366
|
var require_eventLog = __commonJS({
|
|
973
1367
|
"../packages/tool-kit/out/eventLog.js"(exports) {
|
|
@@ -1010,14 +1404,22 @@ var require_eventLog = __commonJS({
|
|
|
1010
1404
|
};
|
|
1011
1405
|
}();
|
|
1012
1406
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1013
|
-
exports.EVENT_LOG_ENV_VAR = void 0;
|
|
1407
|
+
exports.EVENT_LOG_OFF = exports.EVENT_LOG_ENV_VAR = void 0;
|
|
1014
1408
|
exports.expandUserPath = expandUserPath;
|
|
1409
|
+
exports.defaultEventLogPath = defaultEventLogPath;
|
|
1410
|
+
exports.resolveEventLog = resolveEventLog;
|
|
1015
1411
|
exports.resolveEventLogPath = resolveEventLogPath;
|
|
1412
|
+
exports.describeEventLog = describeEventLog;
|
|
1413
|
+
exports.parseEventLogFlag = parseEventLogFlag;
|
|
1016
1414
|
exports.appendEventLog = appendEventLog;
|
|
1017
1415
|
var fs = __importStar(__require("fs"));
|
|
1018
1416
|
var os = __importStar(__require("os"));
|
|
1019
1417
|
var path = __importStar(__require("path"));
|
|
1418
|
+
var agentEvent_1 = require_agentEvent();
|
|
1419
|
+
var credentials_1 = require_credentials();
|
|
1420
|
+
var tokenStore_1 = require_tokenStore();
|
|
1020
1421
|
exports.EVENT_LOG_ENV_VAR = "ASCENDA_EVENT_LOG_FILE";
|
|
1422
|
+
exports.EVENT_LOG_OFF = "off";
|
|
1021
1423
|
var MAX_BYTES = 5 * 1024 * 1024;
|
|
1022
1424
|
function expandUserPath(configured) {
|
|
1023
1425
|
const value = configured?.trim();
|
|
@@ -1029,15 +1431,55 @@ var require_eventLog = __commonJS({
|
|
|
1029
1431
|
return path.join(os.homedir(), value.slice(2));
|
|
1030
1432
|
return path.resolve(value);
|
|
1031
1433
|
}
|
|
1032
|
-
function
|
|
1033
|
-
return
|
|
1434
|
+
function defaultEventLogPath() {
|
|
1435
|
+
return path.join((0, tokenStore_1.ascendaHome)(), "events.jsonl");
|
|
1436
|
+
}
|
|
1437
|
+
function resolveEventLog(options = {}) {
|
|
1438
|
+
for (const [source, raw] of [
|
|
1439
|
+
["env", process.env[exports.EVENT_LOG_ENV_VAR]],
|
|
1440
|
+
["credentials", (0, credentials_1.readMachineCredentials)()?.eventLogPath]
|
|
1441
|
+
]) {
|
|
1442
|
+
const value = raw?.trim();
|
|
1443
|
+
if (!value)
|
|
1444
|
+
continue;
|
|
1445
|
+
if (value.toLowerCase() === exports.EVENT_LOG_OFF)
|
|
1446
|
+
return { path: void 0, source: "disabled" };
|
|
1447
|
+
return { path: expandUserPath(value), source };
|
|
1448
|
+
}
|
|
1449
|
+
if (options.localOnly)
|
|
1450
|
+
return { path: defaultEventLogPath(), source: "unpaired-default" };
|
|
1451
|
+
return { path: void 0, source: "off" };
|
|
1452
|
+
}
|
|
1453
|
+
function resolveEventLogPath(options = {}) {
|
|
1454
|
+
return resolveEventLog(options).path;
|
|
1455
|
+
}
|
|
1456
|
+
function describeEventLog(setting, command) {
|
|
1457
|
+
switch (setting.source) {
|
|
1458
|
+
case "env":
|
|
1459
|
+
return `${setting.path} (from ${exports.EVENT_LOG_ENV_VAR})`;
|
|
1460
|
+
case "credentials":
|
|
1461
|
+
return `${setting.path} (set by ${command} --event-log)`;
|
|
1462
|
+
case "unpaired-default":
|
|
1463
|
+
return `${setting.path} (on because this install isn't paired; ${command} --event-log off to stop)`;
|
|
1464
|
+
case "disabled":
|
|
1465
|
+
return `off (turned off; ${command} --event-log to turn it on)`;
|
|
1466
|
+
case "off":
|
|
1467
|
+
return `off (${command} --event-log to keep a local copy of every event)`;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
function parseEventLogFlag(argv, index) {
|
|
1471
|
+
const peek = argv[index + 1];
|
|
1472
|
+
if (peek !== void 0 && !peek.startsWith("-"))
|
|
1473
|
+
return { value: peek, consumed: 1 };
|
|
1474
|
+
return { value: defaultEventLogPath(), consumed: 0 };
|
|
1034
1475
|
}
|
|
1035
1476
|
function appendEventLog(logFilePath, entry) {
|
|
1036
1477
|
try {
|
|
1037
1478
|
rotateIfLarge(logFilePath);
|
|
1038
1479
|
const dir = path.dirname(logFilePath);
|
|
1039
1480
|
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1040
|
-
|
|
1481
|
+
const line = { ...entry, event: entry.event ?? (0, agentEvent_1.toAgentEvent)(entry.payload) };
|
|
1482
|
+
fs.appendFileSync(logFilePath, `${JSON.stringify(line)}
|
|
1041
1483
|
`, { encoding: "utf8", mode: 384 });
|
|
1042
1484
|
if (process.platform !== "win32")
|
|
1043
1485
|
fs.chmodSync(logFilePath, 384);
|
|
@@ -1210,237 +1652,99 @@ var require_http = __commonJS({
|
|
|
1210
1652
|
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
1211
1653
|
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
1212
1654
|
method: "POST",
|
|
1213
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1214
|
-
signal
|
|
1215
|
-
});
|
|
1216
|
-
if (response.status === 401)
|
|
1217
|
-
return null;
|
|
1218
|
-
if (!response.ok)
|
|
1219
|
-
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1220
|
-
return await response.json();
|
|
1221
|
-
}
|
|
1222
|
-
function isDeliveredStatus(value) {
|
|
1223
|
-
return typeof value === "string" && tool_contract_1.TOOL_EVENT_DELIVERED_STATUSES.includes(value);
|
|
1224
|
-
}
|
|
1225
|
-
function readSuccessBody(body) {
|
|
1226
|
-
let parsed;
|
|
1227
|
-
try {
|
|
1228
|
-
parsed = JSON.parse(body);
|
|
1229
|
-
} catch {
|
|
1230
|
-
return { duplicates: 0 };
|
|
1231
|
-
}
|
|
1232
|
-
if (!parsed || typeof parsed !== "object")
|
|
1233
|
-
return { duplicates: 0 };
|
|
1234
|
-
const single = parsed.status;
|
|
1235
|
-
if (isDeliveredStatus(single))
|
|
1236
|
-
return { duplicates: single === "duplicate" ? 1 : 0 };
|
|
1237
|
-
const raw = parsed.results;
|
|
1238
|
-
if (!Array.isArray(raw))
|
|
1239
|
-
return { duplicates: 0 };
|
|
1240
|
-
const results = [];
|
|
1241
|
-
for (const item of raw) {
|
|
1242
|
-
if (!item || typeof item !== "object")
|
|
1243
|
-
continue;
|
|
1244
|
-
const { index, status, reason } = item;
|
|
1245
|
-
if (typeof index !== "number" || typeof status !== "string")
|
|
1246
|
-
continue;
|
|
1247
|
-
results.push({ index, status, ...typeof reason === "string" ? { reason } : {} });
|
|
1248
|
-
}
|
|
1249
|
-
return { duplicates: results.filter((item) => item.status === "duplicate").length, results };
|
|
1250
|
-
}
|
|
1251
|
-
function isRetryableStatus(status) {
|
|
1252
|
-
return status === 408 || status === 429 || status !== void 0 && status >= 500 && status <= 599;
|
|
1253
|
-
}
|
|
1254
|
-
async function postToolEvent(apiBaseUrl, eventWriteToken, payload, signal) {
|
|
1255
|
-
return sendIngest(`${apiBaseUrl}/v1/tool-events`, eventWriteToken, JSON.stringify(payload), signal);
|
|
1256
|
-
}
|
|
1257
|
-
async function postToolEventsBatch(apiBaseUrl, eventWriteToken, payloads, signal) {
|
|
1258
|
-
return sendIngest(`${apiBaseUrl}/v1/tool-events/batch`, eventWriteToken, JSON.stringify({ events: payloads }), signal);
|
|
1259
|
-
}
|
|
1260
|
-
async function sendIngest(url, eventWriteToken, body, signal) {
|
|
1261
|
-
try {
|
|
1262
|
-
const response = await fetch(url, {
|
|
1263
|
-
method: "POST",
|
|
1264
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1265
|
-
body,
|
|
1266
|
-
signal
|
|
1267
|
-
});
|
|
1268
|
-
return parseIngestResponse(response);
|
|
1269
|
-
} catch (error) {
|
|
1270
|
-
return {
|
|
1271
|
-
result: "transport_error",
|
|
1272
|
-
detail: error instanceof Error ? `${error.name}: ${error.message}` : String(error)
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
async function parseIngestResponse(response) {
|
|
1277
|
-
if (response.ok) {
|
|
1278
|
-
const outcome = { result: "accepted", httpStatus: response.status };
|
|
1279
|
-
let read = { duplicates: 0 };
|
|
1280
|
-
try {
|
|
1281
|
-
read = readSuccessBody(await response.text());
|
|
1282
|
-
} catch {
|
|
1283
|
-
read = { duplicates: 0 };
|
|
1284
|
-
}
|
|
1285
|
-
return {
|
|
1286
|
-
...outcome,
|
|
1287
|
-
...read.duplicates > 0 ? { duplicates: read.duplicates } : {},
|
|
1288
|
-
...read.results !== void 0 ? { results: read.results } : {}
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
const body = await response.text();
|
|
1292
|
-
let errorCode;
|
|
1293
|
-
try {
|
|
1294
|
-
errorCode = JSON.parse(body).error;
|
|
1295
|
-
} catch {
|
|
1296
|
-
errorCode = void 0;
|
|
1297
|
-
}
|
|
1298
|
-
const base2 = { httpStatus: response.status, errorCode, detail: body || void 0 };
|
|
1299
|
-
if (response.status === 401)
|
|
1300
|
-
return { ...base2, result: "auth_failed" };
|
|
1301
|
-
if (response.status === 403 && errorCode === "consent_missing_or_expired")
|
|
1302
|
-
return { ...base2, result: "consent_missing" };
|
|
1303
|
-
if (response.status === 400 || response.status === 422)
|
|
1304
|
-
return { ...base2, result: "validation_failed" };
|
|
1305
|
-
return { ...base2, result: "transport_error" };
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1309
|
-
|
|
1310
|
-
// ../packages/tool-kit/out/tokenStore.js
|
|
1311
|
-
var require_tokenStore = __commonJS({
|
|
1312
|
-
"../packages/tool-kit/out/tokenStore.js"(exports) {
|
|
1313
|
-
"use strict";
|
|
1314
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1315
|
-
if (k2 === void 0) k2 = k;
|
|
1316
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1317
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1318
|
-
desc = { enumerable: true, get: function() {
|
|
1319
|
-
return m[k];
|
|
1320
|
-
} };
|
|
1321
|
-
}
|
|
1322
|
-
Object.defineProperty(o, k2, desc);
|
|
1323
|
-
} : function(o, m, k, k2) {
|
|
1324
|
-
if (k2 === void 0) k2 = k;
|
|
1325
|
-
o[k2] = m[k];
|
|
1326
|
-
});
|
|
1327
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1328
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1329
|
-
} : function(o, v) {
|
|
1330
|
-
o["default"] = v;
|
|
1331
|
-
});
|
|
1332
|
-
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1333
|
-
var ownKeys = function(o) {
|
|
1334
|
-
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1335
|
-
var ar = [];
|
|
1336
|
-
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1337
|
-
return ar;
|
|
1338
|
-
};
|
|
1339
|
-
return ownKeys(o);
|
|
1340
|
-
};
|
|
1341
|
-
return function(mod) {
|
|
1342
|
-
if (mod && mod.__esModule) return mod;
|
|
1343
|
-
var result = {};
|
|
1344
|
-
if (mod != null) {
|
|
1345
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1346
|
-
}
|
|
1347
|
-
__setModuleDefault(result, mod);
|
|
1348
|
-
return result;
|
|
1349
|
-
};
|
|
1350
|
-
}();
|
|
1351
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1352
|
-
exports.EVENT_TOKEN_TTL_MS = void 0;
|
|
1353
|
-
exports.ascendaHome = ascendaHome;
|
|
1354
|
-
exports.defaultTokenFilePath = defaultTokenFilePath2;
|
|
1355
|
-
exports.tokenExpiryFilePath = tokenExpiryFilePath;
|
|
1356
|
-
exports.persistEventWriteToken = persistEventWriteToken2;
|
|
1357
|
-
exports.readTokenExpiry = readTokenExpiry;
|
|
1358
|
-
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds;
|
|
1359
|
-
exports.readTokenFile = readTokenFile2;
|
|
1360
|
-
exports.sanitizeFilePart = sanitizeFilePart;
|
|
1361
|
-
var fs = __importStar(__require("fs"));
|
|
1362
|
-
var os = __importStar(__require("os"));
|
|
1363
|
-
var path = __importStar(__require("path"));
|
|
1364
|
-
function ascendaHome(home = os.homedir()) {
|
|
1365
|
-
return process.env.ASCENDA_HOME ?? path.join(home, ".ascenda");
|
|
1366
|
-
}
|
|
1367
|
-
function defaultTokenFilePath2(toolInstallationId) {
|
|
1368
|
-
return path.join(ascendaHome(), "tokens", sanitizeFilePart(toolInstallationId));
|
|
1369
|
-
}
|
|
1370
|
-
function tokenExpiryFilePath(tokenFilePath) {
|
|
1371
|
-
return path.join(path.dirname(tokenFilePath), "expiry", path.basename(tokenFilePath));
|
|
1372
|
-
}
|
|
1373
|
-
function persistEventWriteToken2(tokenFilePath, token, expiresAt) {
|
|
1374
|
-
const dir = path.dirname(tokenFilePath);
|
|
1375
|
-
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1376
|
-
fs.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
1377
|
-
if (process.platform !== "win32") {
|
|
1378
|
-
fs.chmodSync(dir, 448);
|
|
1379
|
-
fs.chmodSync(tokenFilePath, 384);
|
|
1380
|
-
}
|
|
1381
|
-
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1382
|
-
try {
|
|
1383
|
-
if (expiresAt && Number.isFinite(Date.parse(expiresAt))) {
|
|
1384
|
-
fs.mkdirSync(path.dirname(expiryFile), { recursive: true, mode: 448 });
|
|
1385
|
-
fs.writeFileSync(expiryFile, expiresAt, { encoding: "utf8", mode: 384 });
|
|
1386
|
-
} else {
|
|
1387
|
-
fs.rmSync(expiryFile, { force: true });
|
|
1388
|
-
}
|
|
1389
|
-
} catch {
|
|
1390
|
-
}
|
|
1655
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1656
|
+
signal
|
|
1657
|
+
});
|
|
1658
|
+
if (response.status === 401)
|
|
1659
|
+
return null;
|
|
1660
|
+
if (!response.ok)
|
|
1661
|
+
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1662
|
+
return await response.json();
|
|
1391
1663
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1664
|
+
function isDeliveredStatus(value) {
|
|
1665
|
+
return typeof value === "string" && tool_contract_1.TOOL_EVENT_DELIVERED_STATUSES.includes(value);
|
|
1666
|
+
}
|
|
1667
|
+
function readSuccessBody(body) {
|
|
1668
|
+
let parsed;
|
|
1394
1669
|
try {
|
|
1395
|
-
|
|
1396
|
-
if (Number.isFinite(recorded))
|
|
1397
|
-
return recorded;
|
|
1670
|
+
parsed = JSON.parse(body);
|
|
1398
1671
|
} catch {
|
|
1672
|
+
return { duplicates: 0 };
|
|
1399
1673
|
}
|
|
1400
|
-
|
|
1401
|
-
return
|
|
1402
|
-
|
|
1403
|
-
|
|
1674
|
+
if (!parsed || typeof parsed !== "object")
|
|
1675
|
+
return { duplicates: 0 };
|
|
1676
|
+
const single = parsed.status;
|
|
1677
|
+
if (isDeliveredStatus(single))
|
|
1678
|
+
return { duplicates: single === "duplicate" ? 1 : 0 };
|
|
1679
|
+
const raw = parsed.results;
|
|
1680
|
+
if (!Array.isArray(raw))
|
|
1681
|
+
return { duplicates: 0 };
|
|
1682
|
+
const results = [];
|
|
1683
|
+
for (const item of raw) {
|
|
1684
|
+
if (!item || typeof item !== "object")
|
|
1685
|
+
continue;
|
|
1686
|
+
const { index, status, reason } = item;
|
|
1687
|
+
if (typeof index !== "number" || typeof status !== "string")
|
|
1688
|
+
continue;
|
|
1689
|
+
results.push({ index, status, ...typeof reason === "string" ? { reason } : {} });
|
|
1404
1690
|
}
|
|
1691
|
+
return { duplicates: results.filter((item) => item.status === "duplicate").length, results };
|
|
1405
1692
|
}
|
|
1406
|
-
function
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1693
|
+
function isRetryableStatus(status) {
|
|
1694
|
+
return status === 408 || status === 429 || status !== void 0 && status >= 500 && status <= 599;
|
|
1695
|
+
}
|
|
1696
|
+
async function postToolEvent(apiBaseUrl, eventWriteToken, payload, signal) {
|
|
1697
|
+
return sendIngest(`${apiBaseUrl}/v1/tool-events`, eventWriteToken, JSON.stringify(payload), signal);
|
|
1698
|
+
}
|
|
1699
|
+
async function postToolEventsBatch(apiBaseUrl, eventWriteToken, payloads, signal) {
|
|
1700
|
+
return sendIngest(`${apiBaseUrl}/v1/tool-events/batch`, eventWriteToken, JSON.stringify({ events: payloads }), signal);
|
|
1701
|
+
}
|
|
1702
|
+
async function sendIngest(url, eventWriteToken, body, signal) {
|
|
1410
1703
|
try {
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1704
|
+
const response = await fetch(url, {
|
|
1705
|
+
method: "POST",
|
|
1706
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1707
|
+
body,
|
|
1708
|
+
signal
|
|
1709
|
+
});
|
|
1710
|
+
return parseIngestResponse(response);
|
|
1711
|
+
} catch (error) {
|
|
1712
|
+
return {
|
|
1713
|
+
result: "transport_error",
|
|
1714
|
+
detail: error instanceof Error ? `${error.name}: ${error.message}` : String(error)
|
|
1715
|
+
};
|
|
1414
1716
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1717
|
+
}
|
|
1718
|
+
async function parseIngestResponse(response) {
|
|
1719
|
+
if (response.ok) {
|
|
1720
|
+
const outcome = { result: "accepted", httpStatus: response.status };
|
|
1721
|
+
let read = { duplicates: 0 };
|
|
1420
1722
|
try {
|
|
1421
|
-
|
|
1422
|
-
continue;
|
|
1723
|
+
read = readSuccessBody(await response.text());
|
|
1423
1724
|
} catch {
|
|
1424
|
-
|
|
1725
|
+
read = { duplicates: 0 };
|
|
1425
1726
|
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1727
|
+
return {
|
|
1728
|
+
...outcome,
|
|
1729
|
+
...read.duplicates > 0 ? { duplicates: read.duplicates } : {},
|
|
1730
|
+
...read.results !== void 0 ? { results: read.results } : {}
|
|
1731
|
+
};
|
|
1429
1732
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
function readTokenFile2(tokenFilePath) {
|
|
1733
|
+
const body = await response.text();
|
|
1734
|
+
let errorCode;
|
|
1433
1735
|
try {
|
|
1434
|
-
|
|
1435
|
-
return void 0;
|
|
1436
|
-
const value = fs.readFileSync(tokenFilePath, "utf8").trim();
|
|
1437
|
-
return value || void 0;
|
|
1736
|
+
errorCode = JSON.parse(body).error;
|
|
1438
1737
|
} catch {
|
|
1439
|
-
|
|
1738
|
+
errorCode = void 0;
|
|
1440
1739
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1740
|
+
const base2 = { httpStatus: response.status, errorCode, detail: body || void 0 };
|
|
1741
|
+
if (response.status === 401)
|
|
1742
|
+
return { ...base2, result: "auth_failed" };
|
|
1743
|
+
if (response.status === 403 && errorCode === "consent_missing_or_expired")
|
|
1744
|
+
return { ...base2, result: "consent_missing" };
|
|
1745
|
+
if (response.status === 400 || response.status === 422)
|
|
1746
|
+
return { ...base2, result: "validation_failed" };
|
|
1747
|
+
return { ...base2, result: "transport_error" };
|
|
1444
1748
|
}
|
|
1445
1749
|
}
|
|
1446
1750
|
});
|
|
@@ -1849,6 +2153,7 @@ var require_eventSender = __commonJS({
|
|
|
1849
2153
|
"use strict";
|
|
1850
2154
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1851
2155
|
exports.AscendaEventSender = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = void 0;
|
|
2156
|
+
exports.buildEventBody = buildEventBody;
|
|
1852
2157
|
exports.buildEventPayload = buildEventPayload;
|
|
1853
2158
|
var afterHours_1 = require_afterHours();
|
|
1854
2159
|
var tool_contract_1 = require_out();
|
|
@@ -1867,12 +2172,10 @@ var require_eventSender = __commonJS({
|
|
|
1867
2172
|
}
|
|
1868
2173
|
};
|
|
1869
2174
|
exports.AscendaSemanticEventError = AscendaSemanticEventError;
|
|
1870
|
-
function
|
|
2175
|
+
function buildEventBody(identity, mapped) {
|
|
1871
2176
|
return {
|
|
1872
|
-
toolInstallationId: identity.toolInstallationId,
|
|
1873
2177
|
source: identity.source,
|
|
1874
2178
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1875
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
1876
2179
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
1877
2180
|
sessionId: identity.sessionId ?? void 0,
|
|
1878
2181
|
workspaceHash: identity.workspaceHash ?? void 0,
|
|
@@ -1884,6 +2187,9 @@ var require_eventSender = __commonJS({
|
|
|
1884
2187
|
metadata: withCollectorVersion(mapped.metadata)
|
|
1885
2188
|
};
|
|
1886
2189
|
}
|
|
2190
|
+
function buildEventPayload(identity, mapped) {
|
|
2191
|
+
return (0, tool_contract_1.joinEventPayload)({ toolInstallationId: identity.toolInstallationId, idempotencyKey: (0, payload_1.mintIdempotencyKey)() }, buildEventBody(identity, mapped));
|
|
2192
|
+
}
|
|
1887
2193
|
function withCollectorVersion(metadata) {
|
|
1888
2194
|
return { ...metadata, collectorVersion: collectorVersion_1.COLLECTOR_VERSION };
|
|
1889
2195
|
}
|
|
@@ -1959,12 +2265,10 @@ var require_eventSender = __commonJS({
|
|
|
1959
2265
|
if (!mapped.metadata.skillVersion || !mapped.metadata.skillVersion.trim()) {
|
|
1960
2266
|
throw new AscendaSemanticEventError(`metadata.skillVersion is required for semantic event "${mapped.eventType}".`);
|
|
1961
2267
|
}
|
|
1962
|
-
const
|
|
1963
|
-
toolInstallationId: this.config.toolInstallationId,
|
|
2268
|
+
const body = {
|
|
1964
2269
|
source: this.config.source,
|
|
1965
2270
|
eventType: mapped.eventType,
|
|
1966
2271
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1967
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
1968
2272
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
1969
2273
|
severity: "low",
|
|
1970
2274
|
sessionId: this.config.sessionId ?? void 0,
|
|
@@ -1975,7 +2279,7 @@ var require_eventSender = __commonJS({
|
|
|
1975
2279
|
privacyMode: "metadata_only",
|
|
1976
2280
|
metadata: withCollectorVersion(mapped.metadata)
|
|
1977
2281
|
};
|
|
1978
|
-
return this.post(
|
|
2282
|
+
return this.post((0, tool_contract_1.joinEventPayload)(this.envelope(), body));
|
|
1979
2283
|
}
|
|
1980
2284
|
/**
|
|
1981
2285
|
* Sends a collaboration event under `workflow_telemetry`.
|
|
@@ -1990,12 +2294,10 @@ var require_eventSender = __commonJS({
|
|
|
1990
2294
|
if (!tool_contract_1.COLLABORATION_EVENT_TYPES.includes(mapped.eventType)) {
|
|
1991
2295
|
throw new AscendaSemanticEventError(`"${mapped.eventType}" is not a collaboration event type. Use send() for a deterministic host event.`);
|
|
1992
2296
|
}
|
|
1993
|
-
const
|
|
1994
|
-
toolInstallationId: this.config.toolInstallationId,
|
|
2297
|
+
const body = {
|
|
1995
2298
|
source: this.config.source,
|
|
1996
2299
|
eventType: mapped.eventType,
|
|
1997
2300
|
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1998
|
-
idempotencyKey: (0, payload_1.mintIdempotencyKey)(),
|
|
1999
2301
|
utcOffsetMinutes: (0, afterHours_1.utcOffsetMinutesAt)(/* @__PURE__ */ new Date()),
|
|
2000
2302
|
severity: "low",
|
|
2001
2303
|
sessionId: this.config.sessionId ?? void 0,
|
|
@@ -2006,7 +2308,11 @@ var require_eventSender = __commonJS({
|
|
|
2006
2308
|
privacyMode: "metadata_only",
|
|
2007
2309
|
metadata: withCollectorVersion(mapped.metadata)
|
|
2008
2310
|
};
|
|
2009
|
-
return this.post(
|
|
2311
|
+
return this.post((0, tool_contract_1.joinEventPayload)(this.envelope(), body));
|
|
2312
|
+
}
|
|
2313
|
+
/** A fresh envelope per event: the key belongs to the event, so every retry of it reuses this one. */
|
|
2314
|
+
envelope() {
|
|
2315
|
+
return { toolInstallationId: this.config.toolInstallationId, idempotencyKey: (0, payload_1.mintIdempotencyKey)() };
|
|
2010
2316
|
}
|
|
2011
2317
|
/**
|
|
2012
2318
|
* The single choke point every event passes through, and therefore the only
|
|
@@ -2426,123 +2732,6 @@ var require_contextRegistry = __commonJS({
|
|
|
2426
2732
|
}
|
|
2427
2733
|
});
|
|
2428
2734
|
|
|
2429
|
-
// ../packages/tool-kit/out/credentials.js
|
|
2430
|
-
var require_credentials = __commonJS({
|
|
2431
|
-
"../packages/tool-kit/out/credentials.js"(exports) {
|
|
2432
|
-
"use strict";
|
|
2433
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
2434
|
-
if (k2 === void 0) k2 = k;
|
|
2435
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
2436
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
2437
|
-
desc = { enumerable: true, get: function() {
|
|
2438
|
-
return m[k];
|
|
2439
|
-
} };
|
|
2440
|
-
}
|
|
2441
|
-
Object.defineProperty(o, k2, desc);
|
|
2442
|
-
} : function(o, m, k, k2) {
|
|
2443
|
-
if (k2 === void 0) k2 = k;
|
|
2444
|
-
o[k2] = m[k];
|
|
2445
|
-
});
|
|
2446
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
2447
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
2448
|
-
} : function(o, v) {
|
|
2449
|
-
o["default"] = v;
|
|
2450
|
-
});
|
|
2451
|
-
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
2452
|
-
var ownKeys = function(o) {
|
|
2453
|
-
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
2454
|
-
var ar = [];
|
|
2455
|
-
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
2456
|
-
return ar;
|
|
2457
|
-
};
|
|
2458
|
-
return ownKeys(o);
|
|
2459
|
-
};
|
|
2460
|
-
return function(mod) {
|
|
2461
|
-
if (mod && mod.__esModule) return mod;
|
|
2462
|
-
var result = {};
|
|
2463
|
-
if (mod != null) {
|
|
2464
|
-
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
2465
|
-
}
|
|
2466
|
-
__setModuleDefault(result, mod);
|
|
2467
|
-
return result;
|
|
2468
|
-
};
|
|
2469
|
-
}();
|
|
2470
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2471
|
-
exports.credentialsFilePath = credentialsFilePath;
|
|
2472
|
-
exports.readMachineCredentials = readMachineCredentials;
|
|
2473
|
-
exports.writeMachineCredentials = writeMachineCredentials;
|
|
2474
|
-
exports.writeTopLevelCredentials = writeTopLevelCredentials;
|
|
2475
|
-
exports.isLocalOnlyHostInstall = isLocalOnlyHostInstall;
|
|
2476
|
-
exports.readHostCredentials = readHostCredentials;
|
|
2477
|
-
exports.writeHostCredentials = writeHostCredentials;
|
|
2478
|
-
exports.removeHostCredentials = removeHostCredentials;
|
|
2479
|
-
var fs = __importStar(__require("fs"));
|
|
2480
|
-
var path = __importStar(__require("path"));
|
|
2481
|
-
var tokenStore_1 = require_tokenStore();
|
|
2482
|
-
function credentialsFilePath() {
|
|
2483
|
-
return path.join((0, tokenStore_1.ascendaHome)(), "credentials.json");
|
|
2484
|
-
}
|
|
2485
|
-
function readMachineCredentials() {
|
|
2486
|
-
try {
|
|
2487
|
-
const raw = fs.readFileSync(credentialsFilePath(), "utf8").trim();
|
|
2488
|
-
if (!raw)
|
|
2489
|
-
return void 0;
|
|
2490
|
-
const parsed = JSON.parse(raw);
|
|
2491
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
2492
|
-
return void 0;
|
|
2493
|
-
return parsed;
|
|
2494
|
-
} catch {
|
|
2495
|
-
return void 0;
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
function writeMachineCredentials(credentials) {
|
|
2499
|
-
const file = credentialsFilePath();
|
|
2500
|
-
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 448 });
|
|
2501
|
-
fs.writeFileSync(file, `${JSON.stringify(credentials, null, 2)}
|
|
2502
|
-
`, { encoding: "utf8", mode: 384 });
|
|
2503
|
-
if (process.platform !== "win32") {
|
|
2504
|
-
fs.chmodSync(path.dirname(file), 448);
|
|
2505
|
-
fs.chmodSync(file, 384);
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
function writeTopLevelCredentials(credentials) {
|
|
2509
|
-
const existing = readMachineCredentials();
|
|
2510
|
-
writeMachineCredentials({ ...credentials, ...existing?.tools ? { tools: existing.tools } : {} });
|
|
2511
|
-
}
|
|
2512
|
-
function isLocalOnlyHostInstall(host, hasToken) {
|
|
2513
|
-
const credentials = readHostCredentials(host);
|
|
2514
|
-
if (!credentials?.localOnly)
|
|
2515
|
-
return false;
|
|
2516
|
-
if (process.env.ASCENDA_EVENT_WRITE_TOKEN)
|
|
2517
|
-
return false;
|
|
2518
|
-
return !(credentials.toolInstallationId && hasToken(credentials.toolInstallationId));
|
|
2519
|
-
}
|
|
2520
|
-
function readHostCredentials(host) {
|
|
2521
|
-
const entry = readMachineCredentials()?.tools?.[host];
|
|
2522
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
2523
|
-
return void 0;
|
|
2524
|
-
return entry;
|
|
2525
|
-
}
|
|
2526
|
-
function writeHostCredentials(host, credentials) {
|
|
2527
|
-
const existing = readMachineCredentials() ?? {};
|
|
2528
|
-
writeMachineCredentials({ ...existing, tools: { ...existing.tools ?? {}, [host]: credentials } });
|
|
2529
|
-
}
|
|
2530
|
-
function removeHostCredentials(host) {
|
|
2531
|
-
const existing = readMachineCredentials();
|
|
2532
|
-
if (!existing?.tools || !(host in existing.tools))
|
|
2533
|
-
return;
|
|
2534
|
-
const tools = { ...existing.tools };
|
|
2535
|
-
delete tools[host];
|
|
2536
|
-
const next = { ...existing };
|
|
2537
|
-
if (Object.keys(tools).length)
|
|
2538
|
-
next.tools = tools;
|
|
2539
|
-
else
|
|
2540
|
-
delete next.tools;
|
|
2541
|
-
writeMachineCredentials(next);
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
});
|
|
2545
|
-
|
|
2546
2735
|
// ../packages/tool-kit/out/forgeProject.js
|
|
2547
2736
|
var require_forgeProject = __commonJS({
|
|
2548
2737
|
"../packages/tool-kit/out/forgeProject.js"(exports) {
|
|
@@ -3086,8 +3275,12 @@ var require_hookAdapter = __commonJS({
|
|
|
3086
3275
|
return;
|
|
3087
3276
|
const notice = options.onNotice ?? ((message) => console.error(message));
|
|
3088
3277
|
const hasToken = (id) => (0, tokenStore_1.readTokenFile)(process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0;
|
|
3089
|
-
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken))
|
|
3278
|
+
if (options.host && (0, credentials_1.isLocalOnlyHostInstall)(options.host, hasToken)) {
|
|
3279
|
+
const logFile = (0, eventLog_1.resolveEventLogPath)({ localOnly: true });
|
|
3280
|
+
if (logFile)
|
|
3281
|
+
logUnsent(logFile, events, options);
|
|
3090
3282
|
return;
|
|
3283
|
+
}
|
|
3091
3284
|
let config;
|
|
3092
3285
|
try {
|
|
3093
3286
|
config = loadCliAgentConfig(options.toolType, options.sessionId, options.cwd, options);
|
|
@@ -3097,20 +3290,7 @@ var require_hookAdapter = __commonJS({
|
|
|
3097
3290
|
const logFile = (0, eventLog_1.resolveEventLogPath)();
|
|
3098
3291
|
if (!logFile)
|
|
3099
3292
|
throw error;
|
|
3100
|
-
|
|
3101
|
-
for (const event of events) {
|
|
3102
|
-
(0, eventLog_1.appendEventLog)(logFile, {
|
|
3103
|
-
loggedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3104
|
-
delivery: "not_sent",
|
|
3105
|
-
payload: (0, eventSender_1.buildEventPayload)({
|
|
3106
|
-
toolInstallationId: `${options.toolType}:unpaired`,
|
|
3107
|
-
source: options.source,
|
|
3108
|
-
sessionId: options.sessionId ?? null,
|
|
3109
|
-
workspaceHash: contextHashes.workspaceHash,
|
|
3110
|
-
projectHash: contextHashes.projectHash
|
|
3111
|
-
}, event)
|
|
3112
|
-
});
|
|
3113
|
-
}
|
|
3293
|
+
logUnsent(logFile, events, options);
|
|
3114
3294
|
return;
|
|
3115
3295
|
}
|
|
3116
3296
|
const sender = new eventSender_1.AscendaEventSender({
|
|
@@ -3140,6 +3320,22 @@ var require_hookAdapter = __commonJS({
|
|
|
3140
3320
|
return;
|
|
3141
3321
|
}
|
|
3142
3322
|
}
|
|
3323
|
+
function logUnsent(logFile, events, options) {
|
|
3324
|
+
const contextHashes = resolveContextHashes(options.cwd);
|
|
3325
|
+
for (const event of events) {
|
|
3326
|
+
(0, eventLog_1.appendEventLog)(logFile, {
|
|
3327
|
+
loggedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3328
|
+
delivery: "not_sent",
|
|
3329
|
+
payload: (0, eventSender_1.buildEventPayload)({
|
|
3330
|
+
toolInstallationId: `${options.toolType}:unpaired`,
|
|
3331
|
+
source: options.source,
|
|
3332
|
+
sessionId: process.env.ASCENDA_SESSION_ID?.trim() || options.sessionId || null,
|
|
3333
|
+
workspaceHash: contextHashes.workspaceHash,
|
|
3334
|
+
projectHash: contextHashes.projectHash
|
|
3335
|
+
}, event)
|
|
3336
|
+
});
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3143
3339
|
function journalSkippedSend(host, error) {
|
|
3144
3340
|
const who = host ? `${host}: ` : "";
|
|
3145
3341
|
(0, stateStore_1.recordSendOutcome)((0, stateStore_1.unresolvedStateFilePath)(error.toolType), (0, stateStore_1.unresolvedToolInstallationId)(error.toolType), "skipped_no_installation_id", {
|
|
@@ -4696,6 +4892,7 @@ var require_cliAgentSetup = __commonJS({
|
|
|
4696
4892
|
var path = __importStar(__require("path"));
|
|
4697
4893
|
var collectorVersion_1 = require_collectorVersion();
|
|
4698
4894
|
var credentials_1 = require_credentials();
|
|
4895
|
+
var eventLog_1 = require_eventLog();
|
|
4699
4896
|
var hookAdapter_1 = require_hookAdapter();
|
|
4700
4897
|
var http_1 = require_http();
|
|
4701
4898
|
var hookSet_1 = require_hookSet();
|
|
@@ -4734,6 +4931,8 @@ Options
|
|
|
4734
4931
|
--tool-installation-id <id> reuse an existing pairing instead of creating one
|
|
4735
4932
|
--token <eventWriteToken> reuse an existing token (stored 0600, never printed)
|
|
4736
4933
|
--no-pair install without pairing: local features on, nothing sent
|
|
4934
|
+
--event-log [path|off] keep every event in a local JSONL file (default ~/.ascenda/events.jsonl).
|
|
4935
|
+
On by default when not paired; machine-wide, shared by every agent
|
|
4737
4936
|
--scope user|project where hooks are registered (default user: every project)
|
|
4738
4937
|
--project-dir <path> project root for --scope project (default cwd)
|
|
4739
4938
|
--dry-run print what would change, write nothing
|
|
@@ -4788,6 +4987,8 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
4788
4987
|
toolInstallationId,
|
|
4789
4988
|
...identity ? { pairedAt: now } : { localOnly: true, installedAt: now }
|
|
4790
4989
|
});
|
|
4990
|
+
if (options.eventLog !== void 0)
|
|
4991
|
+
(0, credentials_1.writeEventLogSetting)(options.eventLog);
|
|
4791
4992
|
}
|
|
4792
4993
|
if (isHomeProject(options)) {
|
|
4793
4994
|
detail("scope", "user (a project install in the home folder only loads when the agent starts there)");
|
|
@@ -4822,6 +5023,11 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
4822
5023
|
else
|
|
4823
5024
|
row("warn", "pairing", "not paired: pairing did not finish");
|
|
4824
5025
|
detail("credentials", `${(0, hookRunner_1.tidyHomePath)((0, credentials_1.credentialsFilePath)(), os.homedir())} (tools.${spec.host})`);
|
|
5026
|
+
const eventLog = (0, eventLog_1.resolveEventLog)({ localOnly: !identity });
|
|
5027
|
+
if (eventLog.path)
|
|
5028
|
+
row("ok", "events", `${(0, hookRunner_1.tidyHomePath)(eventLog.path, os.homedir())} ${ui.dim("(on this machine only)")}`);
|
|
5029
|
+
else if (options.eventLog !== void 0)
|
|
5030
|
+
row("info", "events", "off");
|
|
4825
5031
|
if (options.dryRun) {
|
|
4826
5032
|
console.log("\nDry run. Nothing was written.");
|
|
4827
5033
|
return 0;
|
|
@@ -4832,6 +5038,8 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
4832
5038
|
if (chosenLocal) {
|
|
4833
5039
|
console.log(`${ui.mark("ok")} ${ui.bold("Ready.")} The screen saver and the Ascenda app's live view work now.`);
|
|
4834
5040
|
console.log(" They run on this machine and need no account or pairing.");
|
|
5041
|
+
if (eventLog.path)
|
|
5042
|
+
console.log(` Every event is also written to ${(0, hookRunner_1.tidyHomePath)(eventLog.path, os.homedir())}, for you or any tool to read.`);
|
|
4835
5043
|
} else if (!identity) {
|
|
4836
5044
|
console.log(`${ui.mark("warn")} ${ui.bold("Installed, not paired.")} The screen saver and the live view work now.`);
|
|
4837
5045
|
console.log(" Your sessions won't reach Ascenda's servers until pairing completes.");
|
|
@@ -4914,6 +5122,12 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
4914
5122
|
case "--dry-run":
|
|
4915
5123
|
options.dryRun = true;
|
|
4916
5124
|
break;
|
|
5125
|
+
case "--event-log": {
|
|
5126
|
+
const { value, consumed } = (0, eventLog_1.parseEventLogFlag)(argv, i);
|
|
5127
|
+
options.eventLog = value;
|
|
5128
|
+
i += consumed;
|
|
5129
|
+
break;
|
|
5130
|
+
}
|
|
4917
5131
|
case "--no-pair":
|
|
4918
5132
|
// `--no-pairing` is the spelling this landed under first. Both appeared
|
|
4919
5133
|
// only in an unreleased changelog, so this alias exists to spare anyone
|
|
@@ -5136,6 +5350,7 @@ ${serialised}`);
|
|
|
5136
5350
|
console.log(`api base url ${credentials?.apiBaseUrl ?? "\u2014 not configured"}`);
|
|
5137
5351
|
console.log(`pairing ${credentials?.toolInstallationId ?? "\u2014 not paired"}${localOnly ? " (installed, not paired \u2014 local features active, telemetry inactive)" : ""}`);
|
|
5138
5352
|
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
5353
|
+
console.log(`event log ${(0, eventLog_1.describeEventLog)((0, eventLog_1.resolveEventLog)({ localOnly }), `npx ${spec.packageName} setup`)}`);
|
|
5139
5354
|
console.log(`hook binary ${fs.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
5140
5355
|
const node = process.platform === "win32" ? void 0 : (0, hookRunner_1.resolveHookNode)(binary);
|
|
5141
5356
|
if (node) {
|
|
@@ -5219,6 +5434,8 @@ ${serialised}`);
|
|
|
5219
5434
|
lines.push(` Live signal (could not be checked: ${error instanceof Error ? error.message : String(error)})`);
|
|
5220
5435
|
}
|
|
5221
5436
|
lines.push("", ...accountLines(ui, spec));
|
|
5437
|
+
const localOnly = (0, credentials_1.isLocalOnlyHostInstall)(spec.host, (id) => (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(id)) !== void 0);
|
|
5438
|
+
lines.push("", ` ${ui.bold("Local events")} ${(0, eventLog_1.describeEventLog)((0, eventLog_1.resolveEventLog)({ localOnly }), `npx ${spec.packageName} setup`)}`);
|
|
5222
5439
|
console.log(lines.join("\n"));
|
|
5223
5440
|
return 0;
|
|
5224
5441
|
}
|
|
@@ -5232,9 +5449,9 @@ ${serialised}`);
|
|
|
5232
5449
|
` ${ui.bold("Account sync")} ${ui.dim("(optional; this install isn't paired)")}`,
|
|
5233
5450
|
...id ? [ui.dim(row("info", "Installation id", id))] : [],
|
|
5234
5451
|
"",
|
|
5235
|
-
" Not paired, which is fine: the screen saver
|
|
5236
|
-
" without it. Nothing leaves this machine and nothing is queued.
|
|
5237
|
-
" sessions to Ascenda's servers, so they appear in the app:",
|
|
5452
|
+
" Not paired, which is fine: the screen saver, the live view and the local",
|
|
5453
|
+
" event log work without it. Nothing leaves this machine and nothing is queued.",
|
|
5454
|
+
" To send your sessions to Ascenda's servers, so they appear in the app:",
|
|
5238
5455
|
` ${ui.cyan(`${cliAgentSelfCommand(spec)} setup`)}`
|
|
5239
5456
|
];
|
|
5240
5457
|
}
|
|
@@ -5515,14 +5732,14 @@ var require_agentProcess = __commonJS({
|
|
|
5515
5732
|
});
|
|
5516
5733
|
|
|
5517
5734
|
// ../packages/tool-kit/out/index.js
|
|
5518
|
-
var
|
|
5735
|
+
var require_out3 = __commonJS({
|
|
5519
5736
|
"../packages/tool-kit/out/index.js"(exports) {
|
|
5520
5737
|
"use strict";
|
|
5521
5738
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5522
|
-
exports.
|
|
5523
|
-
exports.
|
|
5524
|
-
exports.
|
|
5525
|
-
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 = void 0;
|
|
5739
|
+
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;
|
|
5740
|
+
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;
|
|
5741
|
+
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;
|
|
5742
|
+
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;
|
|
5526
5743
|
var commandClassifier_1 = require_commandClassifier();
|
|
5527
5744
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
5528
5745
|
return commandClassifier_1.classifyCommand;
|
|
@@ -5623,19 +5840,41 @@ var require_out2 = __commonJS({
|
|
|
5623
5840
|
Object.defineProperty(exports, "TOKEN_RENEW_LEAD_MS", { enumerable: true, get: function() {
|
|
5624
5841
|
return eventSender_1.TOKEN_RENEW_LEAD_MS;
|
|
5625
5842
|
} });
|
|
5843
|
+
Object.defineProperty(exports, "buildEventBody", { enumerable: true, get: function() {
|
|
5844
|
+
return eventSender_1.buildEventBody;
|
|
5845
|
+
} });
|
|
5626
5846
|
Object.defineProperty(exports, "buildEventPayload", { enumerable: true, get: function() {
|
|
5627
5847
|
return eventSender_1.buildEventPayload;
|
|
5628
5848
|
} });
|
|
5849
|
+
var agentEvent_1 = require_agentEvent();
|
|
5850
|
+
Object.defineProperty(exports, "toAgentEvent", { enumerable: true, get: function() {
|
|
5851
|
+
return agentEvent_1.toAgentEvent;
|
|
5852
|
+
} });
|
|
5629
5853
|
var eventLog_1 = require_eventLog();
|
|
5630
5854
|
Object.defineProperty(exports, "EVENT_LOG_ENV_VAR", { enumerable: true, get: function() {
|
|
5631
5855
|
return eventLog_1.EVENT_LOG_ENV_VAR;
|
|
5632
5856
|
} });
|
|
5857
|
+
Object.defineProperty(exports, "EVENT_LOG_OFF", { enumerable: true, get: function() {
|
|
5858
|
+
return eventLog_1.EVENT_LOG_OFF;
|
|
5859
|
+
} });
|
|
5633
5860
|
Object.defineProperty(exports, "appendEventLog", { enumerable: true, get: function() {
|
|
5634
5861
|
return eventLog_1.appendEventLog;
|
|
5635
5862
|
} });
|
|
5863
|
+
Object.defineProperty(exports, "defaultEventLogPath", { enumerable: true, get: function() {
|
|
5864
|
+
return eventLog_1.defaultEventLogPath;
|
|
5865
|
+
} });
|
|
5866
|
+
Object.defineProperty(exports, "describeEventLog", { enumerable: true, get: function() {
|
|
5867
|
+
return eventLog_1.describeEventLog;
|
|
5868
|
+
} });
|
|
5636
5869
|
Object.defineProperty(exports, "expandUserPath", { enumerable: true, get: function() {
|
|
5637
5870
|
return eventLog_1.expandUserPath;
|
|
5638
5871
|
} });
|
|
5872
|
+
Object.defineProperty(exports, "parseEventLogFlag", { enumerable: true, get: function() {
|
|
5873
|
+
return eventLog_1.parseEventLogFlag;
|
|
5874
|
+
} });
|
|
5875
|
+
Object.defineProperty(exports, "resolveEventLog", { enumerable: true, get: function() {
|
|
5876
|
+
return eventLog_1.resolveEventLog;
|
|
5877
|
+
} });
|
|
5639
5878
|
Object.defineProperty(exports, "resolveEventLogPath", { enumerable: true, get: function() {
|
|
5640
5879
|
return eventLog_1.resolveEventLogPath;
|
|
5641
5880
|
} });
|
|
@@ -5712,6 +5951,9 @@ var require_out2 = __commonJS({
|
|
|
5712
5951
|
Object.defineProperty(exports, "writeHostCredentials", { enumerable: true, get: function() {
|
|
5713
5952
|
return credentials_1.writeHostCredentials;
|
|
5714
5953
|
} });
|
|
5954
|
+
Object.defineProperty(exports, "writeEventLogSetting", { enumerable: true, get: function() {
|
|
5955
|
+
return credentials_1.writeEventLogSetting;
|
|
5956
|
+
} });
|
|
5715
5957
|
Object.defineProperty(exports, "writeMachineCredentials", { enumerable: true, get: function() {
|
|
5716
5958
|
return credentials_1.writeMachineCredentials;
|
|
5717
5959
|
} });
|
|
@@ -6090,11 +6332,11 @@ var require_out2 = __commonJS({
|
|
|
6090
6332
|
});
|
|
6091
6333
|
|
|
6092
6334
|
// src/cli.ts
|
|
6093
|
-
var import_tool_kit3 = __toESM(
|
|
6335
|
+
var import_tool_kit3 = __toESM(require_out3(), 1);
|
|
6094
6336
|
import { readFile } from "node:fs/promises";
|
|
6095
6337
|
|
|
6096
6338
|
// src/config.ts
|
|
6097
|
-
var import_tool_kit = __toESM(
|
|
6339
|
+
var import_tool_kit = __toESM(require_out3(), 1);
|
|
6098
6340
|
var ASCENDA_TOOL_TYPE = "github_collector";
|
|
6099
6341
|
function loadConfigFromEnv() {
|
|
6100
6342
|
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
@@ -6120,7 +6362,7 @@ function normalizeToolInstallationId(value) {
|
|
|
6120
6362
|
}
|
|
6121
6363
|
|
|
6122
6364
|
// src/mapForgeEvent.ts
|
|
6123
|
-
var import_tool_kit2 = __toESM(
|
|
6365
|
+
var import_tool_kit2 = __toESM(require_out3(), 1);
|
|
6124
6366
|
function mapForgeEvent(eventName, payload, viewerLogin) {
|
|
6125
6367
|
if (!eventName || !viewerLogin) return [];
|
|
6126
6368
|
const action = str(payload["action"]);
|