@ascenda-one/gemini-hooks 0.1.28 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1252 -20
- package/dist/cli.js.map +1 -1
- package/dist/liveSignal.js +6 -0
- package/dist/liveSignal.js.map +1 -1
- package/dist/setup.js +18 -5
- package/dist/setup.js.map +1 -1
- package/examples/settings.json +18 -7
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -720,6 +720,10 @@ var require_out = __commonJS({
|
|
|
720
720
|
// One constant word, from the agent itself. The session sentence names it.
|
|
721
721
|
sessionEndReason: "session",
|
|
722
722
|
interruptionKind: "waiting",
|
|
723
|
+
// Claude Code's own opaque id for one subagent, and the class it belongs
|
|
724
|
+
// to. Never the agent's name or anything it was asked.
|
|
725
|
+
subagentId: "subagents",
|
|
726
|
+
subagentClass: "subagents",
|
|
723
727
|
// Free text by type, and written by no hook mapper — the IDE extension's
|
|
724
728
|
// test signal is the only producer. The setup disclosure's third refusal
|
|
725
729
|
// line says as much, and tool-kit's guard test fails if a mapper starts.
|
|
@@ -768,6 +772,8 @@ var require_out = __commonJS({
|
|
|
768
772
|
"runtime",
|
|
769
773
|
"sessionEndReason",
|
|
770
774
|
"interruptionKind",
|
|
775
|
+
"subagentId",
|
|
776
|
+
"subagentClass",
|
|
771
777
|
"simulated",
|
|
772
778
|
"relatedEventType",
|
|
773
779
|
"skillVersion",
|
|
@@ -815,6 +821,12 @@ var require_out = __commonJS({
|
|
|
815
821
|
// `ai_prompt_submitted` closes. Neutral so a marker sent once per turn
|
|
816
822
|
// doesn't weigh on any workload leg.
|
|
817
823
|
ai_turn_completed: "neutral",
|
|
824
|
+
// A subagent began or finished under a session. Boundaries, not work: the
|
|
825
|
+
// subagent's own tool calls and edits arrive as their own events and carry
|
|
826
|
+
// their own categories. A reader pairs these on `subagentId` to count how
|
|
827
|
+
// many agents ran at once; neutral so that count weighs on no workload leg.
|
|
828
|
+
subagent_started: "neutral",
|
|
829
|
+
subagent_stopped: "neutral",
|
|
818
830
|
// The agent stopped and is waiting on the person: Claude Code's
|
|
819
831
|
// `Notification`, Codex's `PermissionRequest`. Supervision, beside the other
|
|
820
832
|
// oversight overhead, because that is what it is — time the person spends
|
|
@@ -949,7 +961,7 @@ var require_collectorVersion = __commonJS({
|
|
|
949
961
|
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
950
962
|
exports.describeCollectorVersion = describeCollectorVersion;
|
|
951
963
|
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
952
|
-
exports.COLLECTOR_VERSION = "0.1.
|
|
964
|
+
exports.COLLECTOR_VERSION = "0.1.33" ? "0.1.33" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
953
965
|
function describeCollectorVersion(version = exports.COLLECTOR_VERSION) {
|
|
954
966
|
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
955
967
|
}
|
|
@@ -1051,6 +1063,12 @@ var require_http = __commonJS({
|
|
|
1051
1063
|
exports.AscendaApiError = void 0;
|
|
1052
1064
|
exports.createPairingSession = createPairingSession;
|
|
1053
1065
|
exports.getPairingStatus = getPairingStatus;
|
|
1066
|
+
exports.startStudyJoin = startStudyJoin;
|
|
1067
|
+
exports.getStudyJoinStatus = getStudyJoinStatus;
|
|
1068
|
+
exports.readInitiatives = readInitiatives;
|
|
1069
|
+
exports.readStudyNotices = readStudyNotices;
|
|
1070
|
+
exports.setStudyObjection = setStudyObjection;
|
|
1071
|
+
exports.markStudyNoticeShown = markStudyNoticeShown;
|
|
1054
1072
|
exports.renewToolToken = renewToolToken;
|
|
1055
1073
|
exports.isRetryableStatus = isRetryableStatus;
|
|
1056
1074
|
exports.postToolEvent = postToolEvent;
|
|
@@ -1087,6 +1105,108 @@ var require_http = __commonJS({
|
|
|
1087
1105
|
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
1088
1106
|
return await response.json();
|
|
1089
1107
|
}
|
|
1108
|
+
async function startStudyJoin(apiBaseUrl, eventWriteToken, joinCode, mode) {
|
|
1109
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions`, {
|
|
1110
|
+
method: "POST",
|
|
1111
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1112
|
+
body: JSON.stringify({ joinCode, mode })
|
|
1113
|
+
});
|
|
1114
|
+
if (!response.ok)
|
|
1115
|
+
throw await apiError(response);
|
|
1116
|
+
return await response.json();
|
|
1117
|
+
}
|
|
1118
|
+
async function getStudyJoinStatus(apiBaseUrl, eventWriteToken, joinSessionId) {
|
|
1119
|
+
const response = await fetch(`${apiBaseUrl}/v1/org-study-join-sessions/${encodeURIComponent(joinSessionId)}/status`, {
|
|
1120
|
+
method: "GET",
|
|
1121
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` }
|
|
1122
|
+
});
|
|
1123
|
+
if (!response.ok)
|
|
1124
|
+
throw await apiError(response);
|
|
1125
|
+
return await response.json();
|
|
1126
|
+
}
|
|
1127
|
+
async function readInitiatives(apiBaseUrl, eventWriteToken, signal) {
|
|
1128
|
+
let response;
|
|
1129
|
+
try {
|
|
1130
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/initiatives`, {
|
|
1131
|
+
method: "GET",
|
|
1132
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1133
|
+
signal
|
|
1134
|
+
});
|
|
1135
|
+
} catch (error) {
|
|
1136
|
+
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1137
|
+
}
|
|
1138
|
+
if (response.status === 401)
|
|
1139
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1140
|
+
if (!response.ok)
|
|
1141
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1142
|
+
let body;
|
|
1143
|
+
try {
|
|
1144
|
+
body = await response.json();
|
|
1145
|
+
} catch {
|
|
1146
|
+
return { kind: "failed", reason: "the reply was not readable" };
|
|
1147
|
+
}
|
|
1148
|
+
if (!Array.isArray(body))
|
|
1149
|
+
return { kind: "failed", reason: "the reply was not a list" };
|
|
1150
|
+
return { kind: "ok", initiatives: body };
|
|
1151
|
+
}
|
|
1152
|
+
async function readStudyNotices(apiBaseUrl, eventWriteToken, signal) {
|
|
1153
|
+
let response;
|
|
1154
|
+
try {
|
|
1155
|
+
response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices`, {
|
|
1156
|
+
method: "GET",
|
|
1157
|
+
headers: { Accept: "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
1158
|
+
signal
|
|
1159
|
+
});
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
return { kind: "failed", reason: error instanceof Error && error.name === "TimeoutError" ? "the request timed out" : "the server could not be reached" };
|
|
1162
|
+
}
|
|
1163
|
+
if (response.status === 404)
|
|
1164
|
+
return { kind: "absent" };
|
|
1165
|
+
if (response.status === 401)
|
|
1166
|
+
return { kind: "rejected", httpStatus: 401 };
|
|
1167
|
+
if (!response.ok)
|
|
1168
|
+
return { kind: "failed", reason: `the server answered HTTP ${response.status}` };
|
|
1169
|
+
let body;
|
|
1170
|
+
try {
|
|
1171
|
+
body = await response.json();
|
|
1172
|
+
} catch {
|
|
1173
|
+
return { kind: "absent" };
|
|
1174
|
+
}
|
|
1175
|
+
if (!Array.isArray(body))
|
|
1176
|
+
return { kind: "absent" };
|
|
1177
|
+
return { kind: "ok", notices: body };
|
|
1178
|
+
}
|
|
1179
|
+
async function setStudyObjection(apiBaseUrl, eventWriteToken, code, objected) {
|
|
1180
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(String(code))}/objection`, {
|
|
1181
|
+
method: objected ? "POST" : "DELETE",
|
|
1182
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` }
|
|
1183
|
+
});
|
|
1184
|
+
if (!response.ok)
|
|
1185
|
+
throw await apiError(response);
|
|
1186
|
+
}
|
|
1187
|
+
async function markStudyNoticeShown(apiBaseUrl, eventWriteToken, organisationId, code, signal) {
|
|
1188
|
+
try {
|
|
1189
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-installations/study-notices/${encodeURIComponent(organisationId)}/${encodeURIComponent(String(code))}/shown`, {
|
|
1190
|
+
method: "POST",
|
|
1191
|
+
headers: { Authorization: `Bearer ${eventWriteToken}` },
|
|
1192
|
+
signal
|
|
1193
|
+
});
|
|
1194
|
+
return response.ok;
|
|
1195
|
+
} catch {
|
|
1196
|
+
return false;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
async function apiError(response) {
|
|
1200
|
+
const body = await response.text();
|
|
1201
|
+
let errorCode;
|
|
1202
|
+
try {
|
|
1203
|
+
const parsed = JSON.parse(body);
|
|
1204
|
+
errorCode = parsed.code ?? parsed.error;
|
|
1205
|
+
} catch {
|
|
1206
|
+
errorCode = void 0;
|
|
1207
|
+
}
|
|
1208
|
+
return new AscendaApiError(response.status, errorCode, body);
|
|
1209
|
+
}
|
|
1090
1210
|
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
1091
1211
|
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
1092
1212
|
method: "POST",
|
|
@@ -1229,9 +1349,12 @@ var require_tokenStore = __commonJS({
|
|
|
1229
1349
|
};
|
|
1230
1350
|
}();
|
|
1231
1351
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1352
|
+
exports.EVENT_TOKEN_TTL_MS = void 0;
|
|
1232
1353
|
exports.ascendaHome = ascendaHome;
|
|
1233
1354
|
exports.defaultTokenFilePath = defaultTokenFilePath;
|
|
1355
|
+
exports.tokenExpiryFilePath = tokenExpiryFilePath;
|
|
1234
1356
|
exports.persistEventWriteToken = persistEventWriteToken;
|
|
1357
|
+
exports.readTokenExpiry = readTokenExpiry;
|
|
1235
1358
|
exports.listPersistedToolInstallationIds = listPersistedToolInstallationIds;
|
|
1236
1359
|
exports.readTokenFile = readTokenFile;
|
|
1237
1360
|
exports.sanitizeFilePart = sanitizeFilePart;
|
|
@@ -1244,7 +1367,10 @@ var require_tokenStore = __commonJS({
|
|
|
1244
1367
|
function defaultTokenFilePath(toolInstallationId) {
|
|
1245
1368
|
return path2.join(ascendaHome(), "tokens", sanitizeFilePart(toolInstallationId));
|
|
1246
1369
|
}
|
|
1247
|
-
function
|
|
1370
|
+
function tokenExpiryFilePath(tokenFilePath) {
|
|
1371
|
+
return path2.join(path2.dirname(tokenFilePath), "expiry", path2.basename(tokenFilePath));
|
|
1372
|
+
}
|
|
1373
|
+
function persistEventWriteToken(tokenFilePath, token, expiresAt) {
|
|
1248
1374
|
const dir = path2.dirname(tokenFilePath);
|
|
1249
1375
|
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1250
1376
|
fs.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
@@ -1252,6 +1378,30 @@ var require_tokenStore = __commonJS({
|
|
|
1252
1378
|
fs.chmodSync(dir, 448);
|
|
1253
1379
|
fs.chmodSync(tokenFilePath, 384);
|
|
1254
1380
|
}
|
|
1381
|
+
const expiryFile = tokenExpiryFilePath(tokenFilePath);
|
|
1382
|
+
try {
|
|
1383
|
+
if (expiresAt && Number.isFinite(Date.parse(expiresAt))) {
|
|
1384
|
+
fs.mkdirSync(path2.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
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
exports.EVENT_TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
1393
|
+
function readTokenExpiry(tokenFilePath) {
|
|
1394
|
+
try {
|
|
1395
|
+
const recorded = Date.parse(fs.readFileSync(tokenExpiryFilePath(tokenFilePath), "utf8").trim());
|
|
1396
|
+
if (Number.isFinite(recorded))
|
|
1397
|
+
return recorded;
|
|
1398
|
+
} catch {
|
|
1399
|
+
}
|
|
1400
|
+
try {
|
|
1401
|
+
return fs.statSync(tokenFilePath).mtimeMs + exports.EVENT_TOKEN_TTL_MS;
|
|
1402
|
+
} catch {
|
|
1403
|
+
return void 0;
|
|
1404
|
+
}
|
|
1255
1405
|
}
|
|
1256
1406
|
function listPersistedToolInstallationIds(toolType) {
|
|
1257
1407
|
const prefix = `${sanitizeFilePart(toolType)}_`;
|
|
@@ -1698,7 +1848,7 @@ var require_eventSender = __commonJS({
|
|
|
1698
1848
|
"../packages/tool-kit/out/eventSender.js"(exports) {
|
|
1699
1849
|
"use strict";
|
|
1700
1850
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1701
|
-
exports.AscendaEventSender = exports.AscendaSemanticEventError = void 0;
|
|
1851
|
+
exports.AscendaEventSender = exports.TOKEN_RENEW_LEAD_MS = exports.AscendaSemanticEventError = void 0;
|
|
1702
1852
|
exports.buildEventPayload = buildEventPayload;
|
|
1703
1853
|
var afterHours_1 = require_afterHours();
|
|
1704
1854
|
var tool_contract_1 = require_out();
|
|
@@ -1739,6 +1889,7 @@ var require_eventSender = __commonJS({
|
|
|
1739
1889
|
}
|
|
1740
1890
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
1741
1891
|
var RETRY_DELAY_MS = 250;
|
|
1892
|
+
exports.TOKEN_RENEW_LEAD_MS = 21 * 24 * 60 * 60 * 1e3;
|
|
1742
1893
|
var AscendaEventSender = class {
|
|
1743
1894
|
config;
|
|
1744
1895
|
eventWriteToken;
|
|
@@ -1746,6 +1897,8 @@ var require_eventSender = __commonJS({
|
|
|
1746
1897
|
lastDrain;
|
|
1747
1898
|
/** One outbox pass per sender, i.e. per hook process. The hook is on the user's critical path. */
|
|
1748
1899
|
outboxServiced = false;
|
|
1900
|
+
/** One look at the token's expiry per sender, for the same reason. */
|
|
1901
|
+
expiryChecked = false;
|
|
1749
1902
|
/** Resolved once, so every clock read in one pass sees the same instant. */
|
|
1750
1903
|
time;
|
|
1751
1904
|
constructor(config) {
|
|
@@ -1869,6 +2022,7 @@ var require_eventSender = __commonJS({
|
|
|
1869
2022
|
* hook during an outage to one bounded round trip instead of three.
|
|
1870
2023
|
*/
|
|
1871
2024
|
async post(payload) {
|
|
2025
|
+
await this.renewIfExpiring();
|
|
1872
2026
|
const halted = await this.serviceOutbox();
|
|
1873
2027
|
let outcome;
|
|
1874
2028
|
let queued = false;
|
|
@@ -2074,21 +2228,49 @@ var require_eventSender = __commonJS({
|
|
|
2074
2228
|
return;
|
|
2075
2229
|
(0, eventLog_1.appendEventLog)(logFile, { loggedAt: (/* @__PURE__ */ new Date()).toISOString(), delivery, payload, ...outbox ? { outbox } : {} });
|
|
2076
2230
|
}
|
|
2077
|
-
/**
|
|
2231
|
+
/**
|
|
2232
|
+
* Renews ahead of expiry, at most once per sender. Waiting for the 401
|
|
2233
|
+
* doesn't work: by then the token has expired, and the server won't renew
|
|
2234
|
+
* an expired token.
|
|
2235
|
+
*/
|
|
2236
|
+
async renewIfExpiring() {
|
|
2237
|
+
if (this.expiryChecked || this.config.renewToken === false)
|
|
2238
|
+
return;
|
|
2239
|
+
this.expiryChecked = true;
|
|
2240
|
+
const expiresAt = (0, tokenStore_1.readTokenExpiry)(this.config.tokenFilePath);
|
|
2241
|
+
if (expiresAt === void 0 || this.time.now() < expiresAt - exports.TOKEN_RENEW_LEAD_MS)
|
|
2242
|
+
return;
|
|
2243
|
+
await this.renewEventToken();
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Never throws: a renewal that errors is a failed renewal, not a failed turn.
|
|
2247
|
+
*
|
|
2248
|
+
* A refused renewal usually means another process got there first. Hooks
|
|
2249
|
+
* and the MCP server share one token file, and renewing revokes the token
|
|
2250
|
+
* it replaces, so the loser holds a revoked token while the winner's
|
|
2251
|
+
* replacement is already on disk. Adopting that counts as a renewal.
|
|
2252
|
+
*/
|
|
2078
2253
|
async renewEventToken() {
|
|
2079
2254
|
if (this.config.renewToken === false)
|
|
2080
2255
|
return false;
|
|
2081
2256
|
try {
|
|
2082
2257
|
const renewed = await (0, http_1.renewToolToken)(this.config.apiBaseUrl, this.eventWriteToken, this.signal());
|
|
2083
2258
|
if (!renewed)
|
|
2084
|
-
return
|
|
2259
|
+
return this.adoptPersistedToken();
|
|
2085
2260
|
this.eventWriteToken = renewed.eventWriteToken;
|
|
2086
|
-
(0, tokenStore_1.persistEventWriteToken)(this.config.tokenFilePath, renewed.eventWriteToken);
|
|
2261
|
+
(0, tokenStore_1.persistEventWriteToken)(this.config.tokenFilePath, renewed.eventWriteToken, renewed.expiresAt);
|
|
2087
2262
|
return true;
|
|
2088
2263
|
} catch {
|
|
2089
2264
|
return false;
|
|
2090
2265
|
}
|
|
2091
2266
|
}
|
|
2267
|
+
adoptPersistedToken() {
|
|
2268
|
+
const persisted = (0, tokenStore_1.readTokenFile)(this.config.tokenFilePath);
|
|
2269
|
+
if (!persisted || persisted === this.eventWriteToken)
|
|
2270
|
+
return false;
|
|
2271
|
+
this.eventWriteToken = persisted;
|
|
2272
|
+
return true;
|
|
2273
|
+
}
|
|
2092
2274
|
signal() {
|
|
2093
2275
|
return AbortSignal.timeout(this.config.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
2094
2276
|
}
|
|
@@ -2971,6 +3153,477 @@ var require_hookAdapter = __commonJS({
|
|
|
2971
3153
|
}
|
|
2972
3154
|
});
|
|
2973
3155
|
|
|
3156
|
+
// ../packages/tool-kit/out/hookSet.js
|
|
3157
|
+
var require_hookSet = __commonJS({
|
|
3158
|
+
"../packages/tool-kit/out/hookSet.js"(exports) {
|
|
3159
|
+
"use strict";
|
|
3160
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3161
|
+
exports.UNVERSIONED_HOOK_SET = exports.HOOK_SET_FLAG = void 0;
|
|
3162
|
+
exports.hookSetArgument = hookSetArgument;
|
|
3163
|
+
exports.readHookSet = readHookSet2;
|
|
3164
|
+
exports.isHookSet = isHookSet;
|
|
3165
|
+
exports.readViaPlugin = readViaPlugin;
|
|
3166
|
+
exports.hookSetOfCommand = hookSetOfCommand;
|
|
3167
|
+
exports.hookSetChanges = hookSetChanges;
|
|
3168
|
+
exports.describeHookSetChanges = describeHookSetChanges;
|
|
3169
|
+
exports.HOOK_SET_FLAG = "--hook-set";
|
|
3170
|
+
exports.UNVERSIONED_HOOK_SET = 1;
|
|
3171
|
+
function hookSetArgument(hookSet) {
|
|
3172
|
+
return hookSet === void 0 ? "" : ` ${exports.HOOK_SET_FLAG} ${hookSet}`;
|
|
3173
|
+
}
|
|
3174
|
+
function readHookSet2(argv) {
|
|
3175
|
+
const index = argv.indexOf(exports.HOOK_SET_FLAG);
|
|
3176
|
+
if (index === -1)
|
|
3177
|
+
return void 0;
|
|
3178
|
+
const raw = argv[index + 1];
|
|
3179
|
+
if (raw === void 0 || !/^[1-9]\d*$/.test(raw))
|
|
3180
|
+
return void 0;
|
|
3181
|
+
const value = Number(raw);
|
|
3182
|
+
return isHookSet(value) ? value : void 0;
|
|
3183
|
+
}
|
|
3184
|
+
function isHookSet(value) {
|
|
3185
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
3186
|
+
}
|
|
3187
|
+
function readViaPlugin(env) {
|
|
3188
|
+
return env.CLAUDE_PLUGIN_ROOT ? true : void 0;
|
|
3189
|
+
}
|
|
3190
|
+
function hookSetOfCommand(command) {
|
|
3191
|
+
const match = command.match(/--hook-set\s+(\d+)/);
|
|
3192
|
+
return match ? Number(match[1]) : exports.UNVERSIONED_HOOK_SET;
|
|
3193
|
+
}
|
|
3194
|
+
function hookSetChanges(before, events) {
|
|
3195
|
+
const added = events.filter((event) => !before.has(event));
|
|
3196
|
+
const sets = [...before.values()];
|
|
3197
|
+
return sets.length ? { added, previousSet: Math.min(...sets) } : { added };
|
|
3198
|
+
}
|
|
3199
|
+
function describeHookSetChanges(changes, hookSet) {
|
|
3200
|
+
if (changes.previousSet === void 0)
|
|
3201
|
+
return void 0;
|
|
3202
|
+
const parts = [];
|
|
3203
|
+
if (changes.added.length)
|
|
3204
|
+
parts.push(`added ${changes.added.join(", ")}`);
|
|
3205
|
+
if (changes.previousSet < hookSet)
|
|
3206
|
+
parts.push(`hook set ${changes.previousSet} \u2192 ${hookSet}`);
|
|
3207
|
+
return parts.length ? `upgraded: ${parts.join("; ")}` : void 0;
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
});
|
|
3211
|
+
|
|
3212
|
+
// ../packages/tool-kit/out/studyJoin.js
|
|
3213
|
+
var require_studyJoin = __commonJS({
|
|
3214
|
+
"../packages/tool-kit/out/studyJoin.js"(exports) {
|
|
3215
|
+
"use strict";
|
|
3216
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
3217
|
+
if (k2 === void 0) k2 = k;
|
|
3218
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3219
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3220
|
+
desc = { enumerable: true, get: function() {
|
|
3221
|
+
return m[k];
|
|
3222
|
+
} };
|
|
3223
|
+
}
|
|
3224
|
+
Object.defineProperty(o, k2, desc);
|
|
3225
|
+
} : function(o, m, k, k2) {
|
|
3226
|
+
if (k2 === void 0) k2 = k;
|
|
3227
|
+
o[k2] = m[k];
|
|
3228
|
+
});
|
|
3229
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
3230
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
3231
|
+
} : function(o, v) {
|
|
3232
|
+
o["default"] = v;
|
|
3233
|
+
});
|
|
3234
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
3235
|
+
var ownKeys = function(o) {
|
|
3236
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
3237
|
+
var ar = [];
|
|
3238
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
3239
|
+
return ar;
|
|
3240
|
+
};
|
|
3241
|
+
return ownKeys(o);
|
|
3242
|
+
};
|
|
3243
|
+
return function(mod) {
|
|
3244
|
+
if (mod && mod.__esModule) return mod;
|
|
3245
|
+
var result = {};
|
|
3246
|
+
if (mod != null) {
|
|
3247
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
3248
|
+
}
|
|
3249
|
+
__setModuleDefault(result, mod);
|
|
3250
|
+
return result;
|
|
3251
|
+
};
|
|
3252
|
+
}();
|
|
3253
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3254
|
+
exports.runStudyJoin = runStudyJoin;
|
|
3255
|
+
exports.formatWindow = formatWindow;
|
|
3256
|
+
var readline = __importStar(__require("node:readline"));
|
|
3257
|
+
var http_1 = require_http();
|
|
3258
|
+
var STUDY_JOIN_MODE = "report";
|
|
3259
|
+
var POLL_INTERVAL_MS = 3e3;
|
|
3260
|
+
var POLL_TIMEOUT_MS = 11 * 60 * 1e3;
|
|
3261
|
+
async function runStudyJoin(ctx) {
|
|
3262
|
+
const stdin = ctx.stdin ?? process.stdin;
|
|
3263
|
+
const stdout = ctx.stdout ?? process.stdout;
|
|
3264
|
+
const stderr = ctx.stderr ?? process.stderr;
|
|
3265
|
+
const print = (line) => stdout.write(`${line}
|
|
3266
|
+
`);
|
|
3267
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
3268
|
+
stderr.write("join needs an interactive terminal (stdin and stdout). Run it directly, not from a script or a pipe.\n");
|
|
3269
|
+
return 0;
|
|
3270
|
+
}
|
|
3271
|
+
if (!ctx.joinCode) {
|
|
3272
|
+
stderr.write("Usage: join <code>\n");
|
|
3273
|
+
return 1;
|
|
3274
|
+
}
|
|
3275
|
+
let start;
|
|
3276
|
+
try {
|
|
3277
|
+
start = await (0, http_1.startStudyJoin)(ctx.apiBaseUrl, ctx.eventWriteToken, ctx.joinCode, STUDY_JOIN_MODE);
|
|
3278
|
+
} catch (error) {
|
|
3279
|
+
stderr.write(`${describeStartError(error)}
|
|
3280
|
+
`);
|
|
3281
|
+
return 1;
|
|
3282
|
+
}
|
|
3283
|
+
print("");
|
|
3284
|
+
print(`${start.organisationName}: ${describeStudyKind(start.studyKind)}`);
|
|
3285
|
+
print(formatWindow(start.windowStartUtc, start.windowEndUtc));
|
|
3286
|
+
print("");
|
|
3287
|
+
print("Report (30 days) grants:");
|
|
3288
|
+
for (const grant of start.grants)
|
|
3289
|
+
print(` ${describeGrant(grant)}`);
|
|
3290
|
+
print("");
|
|
3291
|
+
print("Study mode needs the Ascenda app. Open the app to join that way instead.");
|
|
3292
|
+
print("");
|
|
3293
|
+
print("Join in:");
|
|
3294
|
+
print(" 1) Report (30 days)");
|
|
3295
|
+
print(" 2) Not now");
|
|
3296
|
+
print("");
|
|
3297
|
+
const answer = await askChoice(stdin, stdout);
|
|
3298
|
+
if (!/^(1|report)$/i.test(answer)) {
|
|
3299
|
+
print("Not now.");
|
|
3300
|
+
return 0;
|
|
3301
|
+
}
|
|
3302
|
+
print("");
|
|
3303
|
+
print(`Confirm in the Ascenda app with code ${start.deviceCode}`);
|
|
3304
|
+
print(`Waiting for confirmation (expires ${formatLocalTime(start.expiresAt)})...`);
|
|
3305
|
+
const pollIntervalMs = ctx.pollIntervalMs ?? POLL_INTERVAL_MS;
|
|
3306
|
+
const deadline = Math.min(Date.parse(start.expiresAt) || Date.now() + POLL_TIMEOUT_MS, Date.now() + POLL_TIMEOUT_MS);
|
|
3307
|
+
while (Date.now() < deadline) {
|
|
3308
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
3309
|
+
let poll;
|
|
3310
|
+
try {
|
|
3311
|
+
poll = await (0, http_1.getStudyJoinStatus)(ctx.apiBaseUrl, ctx.eventWriteToken, start.joinSessionId);
|
|
3312
|
+
} catch (error) {
|
|
3313
|
+
if (isRetryablePollError(error))
|
|
3314
|
+
continue;
|
|
3315
|
+
stderr.write(`${describeStartError(error)}
|
|
3316
|
+
`);
|
|
3317
|
+
return 1;
|
|
3318
|
+
}
|
|
3319
|
+
if (poll.status === "pending")
|
|
3320
|
+
continue;
|
|
3321
|
+
if (poll.status === "confirmed") {
|
|
3322
|
+
const granted = poll.granted ?? [];
|
|
3323
|
+
if (granted.length === 0) {
|
|
3324
|
+
print("");
|
|
3325
|
+
print("Nothing was granted. Run join again, or check with your organisation.");
|
|
3326
|
+
return 1;
|
|
3327
|
+
}
|
|
3328
|
+
print("");
|
|
3329
|
+
print("Joined. Granted:");
|
|
3330
|
+
for (const grant of granted)
|
|
3331
|
+
print(` ${describeGrant(grant)}`);
|
|
3332
|
+
print("");
|
|
3333
|
+
print("Each of these can be turned off separately, in the app's consent settings.");
|
|
3334
|
+
print("The organisation sees group counts, never who joined.");
|
|
3335
|
+
return 0;
|
|
3336
|
+
}
|
|
3337
|
+
if (poll.status === "expired") {
|
|
3338
|
+
print("");
|
|
3339
|
+
print("This code expired before it was confirmed. Run join again for a fresh code.");
|
|
3340
|
+
return 1;
|
|
3341
|
+
}
|
|
3342
|
+
if (poll.refusedReason === "grant_failed") {
|
|
3343
|
+
print("");
|
|
3344
|
+
print("Join failed partway through. Some grants may not have gone through.");
|
|
3345
|
+
const granted = poll.granted ?? [];
|
|
3346
|
+
if (granted.length > 0) {
|
|
3347
|
+
print("");
|
|
3348
|
+
print("Granted before the failure:");
|
|
3349
|
+
for (const grant of granted)
|
|
3350
|
+
print(` ${describeGrant(grant)}`);
|
|
3351
|
+
print("");
|
|
3352
|
+
print("Each of these can be turned off separately, in the app's consent settings.");
|
|
3353
|
+
}
|
|
3354
|
+
print("Run join again, or check with your organisation.");
|
|
3355
|
+
return 1;
|
|
3356
|
+
}
|
|
3357
|
+
print("");
|
|
3358
|
+
print(describeRefusal(poll.refusedReason));
|
|
3359
|
+
return 1;
|
|
3360
|
+
}
|
|
3361
|
+
print("");
|
|
3362
|
+
print("Timed out waiting for confirmation. Run join again for a fresh code.");
|
|
3363
|
+
return 1;
|
|
3364
|
+
}
|
|
3365
|
+
function isRetryablePollError(error) {
|
|
3366
|
+
if (error instanceof http_1.AscendaApiError)
|
|
3367
|
+
return error.status >= 500 && error.status <= 599;
|
|
3368
|
+
return true;
|
|
3369
|
+
}
|
|
3370
|
+
function askChoice(stdin, stdout) {
|
|
3371
|
+
return new Promise((resolve) => {
|
|
3372
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
3373
|
+
let settled = false;
|
|
3374
|
+
const finish = (value) => {
|
|
3375
|
+
if (settled)
|
|
3376
|
+
return;
|
|
3377
|
+
settled = true;
|
|
3378
|
+
rl.close();
|
|
3379
|
+
resolve(value.trim());
|
|
3380
|
+
};
|
|
3381
|
+
rl.question("Choice [Not now]: ", finish);
|
|
3382
|
+
rl.once("close", () => finish(""));
|
|
3383
|
+
});
|
|
3384
|
+
}
|
|
3385
|
+
function formatLocalTime(iso) {
|
|
3386
|
+
const date = new Date(iso);
|
|
3387
|
+
if (Number.isNaN(date.getTime()))
|
|
3388
|
+
return iso;
|
|
3389
|
+
return new Intl.DateTimeFormat(void 0, { day: "numeric", month: "short", hour: "numeric", minute: "2-digit" }).format(date);
|
|
3390
|
+
}
|
|
3391
|
+
function formatWindow(startUtc, endUtc) {
|
|
3392
|
+
const start = new Date(startUtc);
|
|
3393
|
+
const end = new Date(endUtc);
|
|
3394
|
+
const sameYear = start.getUTCFullYear() === end.getUTCFullYear();
|
|
3395
|
+
const dayMonth = { day: "numeric", month: "short", timeZone: "UTC" };
|
|
3396
|
+
const withYear = { ...dayMonth, year: "numeric" };
|
|
3397
|
+
const startFmt = new Intl.DateTimeFormat("en-GB", sameYear ? dayMonth : withYear);
|
|
3398
|
+
const endFmt = new Intl.DateTimeFormat("en-GB", withYear);
|
|
3399
|
+
return `${startFmt.format(start)} \u2013 ${endFmt.format(end)}`;
|
|
3400
|
+
}
|
|
3401
|
+
var GRANT_SENTENCES = {
|
|
3402
|
+
501: "AI assistant data processing consent",
|
|
3403
|
+
507: "Import of the AI-work history already on your machine"
|
|
3404
|
+
};
|
|
3405
|
+
function describeGrant(grant) {
|
|
3406
|
+
return GRANT_SENTENCES[grant.code] ?? humanise(grant.name);
|
|
3407
|
+
}
|
|
3408
|
+
var STUDY_KIND_SENTENCES = {
|
|
3409
|
+
Report30: "a 30-day report",
|
|
3410
|
+
Study90: "a 90-day study"
|
|
3411
|
+
};
|
|
3412
|
+
function describeStudyKind(studyKind) {
|
|
3413
|
+
return STUDY_KIND_SENTENCES[studyKind] ?? humanise(studyKind);
|
|
3414
|
+
}
|
|
3415
|
+
function humanise(name) {
|
|
3416
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").trim() || name;
|
|
3417
|
+
}
|
|
3418
|
+
var REFUSED_REASON_MESSAGES = {
|
|
3419
|
+
study_no_longer_live: "That study is no longer open to join.",
|
|
3420
|
+
withdrawn: "You're no longer an active participant in that study.",
|
|
3421
|
+
// Handled as its own branch above, with its granted list, before this
|
|
3422
|
+
// table is ever consulted — present so the type stays exhaustive, and as
|
|
3423
|
+
// a plain fallback should something call this function with it directly.
|
|
3424
|
+
grant_failed: "Join failed partway through. Some grants may not have gone through.",
|
|
3425
|
+
declined: "You declined in the app. Nothing was granted.",
|
|
3426
|
+
not_enrolled: "That study couldn't enrol you, so nothing was granted."
|
|
3427
|
+
};
|
|
3428
|
+
function describeRefusal(refusedReason) {
|
|
3429
|
+
if (refusedReason && REFUSED_REASON_MESSAGES[refusedReason])
|
|
3430
|
+
return REFUSED_REASON_MESSAGES[refusedReason];
|
|
3431
|
+
return "The join didn't go through. Nothing new was granted.";
|
|
3432
|
+
}
|
|
3433
|
+
var START_ERROR_MESSAGES = {
|
|
3434
|
+
join_code_not_found: "That code is not a study anyone can join. Check it and try again.",
|
|
3435
|
+
unknown_mode: "This tool only offers Report mode from the command line.",
|
|
3436
|
+
no_live_study: "There's nothing open to join with that code right now.",
|
|
3437
|
+
too_many_open_sessions: "This tool has too many joins waiting to be confirmed. Confirm one, or let one expire, then try again.",
|
|
3438
|
+
unknown_session: "That join can no longer be found. Run join again for a fresh code."
|
|
3439
|
+
};
|
|
3440
|
+
function describeStartError(error) {
|
|
3441
|
+
if (error instanceof http_1.AscendaApiError) {
|
|
3442
|
+
if (error.errorCode && START_ERROR_MESSAGES[error.errorCode])
|
|
3443
|
+
return START_ERROR_MESSAGES[error.errorCode];
|
|
3444
|
+
if (error.status === 401)
|
|
3445
|
+
return "This tool's pairing was rejected. Re-pair it, then try again.";
|
|
3446
|
+
return `Could not reach the join code (HTTP ${error.status}).`;
|
|
3447
|
+
}
|
|
3448
|
+
return error instanceof Error ? error.message : String(error);
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
});
|
|
3452
|
+
|
|
3453
|
+
// ../packages/tool-kit/out/initiatives.js
|
|
3454
|
+
var require_initiatives = __commonJS({
|
|
3455
|
+
"../packages/tool-kit/out/initiatives.js"(exports) {
|
|
3456
|
+
"use strict";
|
|
3457
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3458
|
+
exports.INITIATIVE_COPY = void 0;
|
|
3459
|
+
exports.initiativesStatusLines = initiativesStatusLines;
|
|
3460
|
+
exports.renderInitiatives = renderInitiatives;
|
|
3461
|
+
var http_1 = require_http();
|
|
3462
|
+
var studyJoin_1 = require_studyJoin();
|
|
3463
|
+
var READ_TIMEOUT_MS = 5e3;
|
|
3464
|
+
exports.INITIATIVE_COPY = {
|
|
3465
|
+
outcomes: {
|
|
3466
|
+
moved_as_declared: "Moved the way declared, beyond the cohort's own variation",
|
|
3467
|
+
moved_against_declared: "Moved the other way, beyond the cohort's own variation",
|
|
3468
|
+
moved_no_direction_declared: "Moved beyond the cohort's own variation; no direction was declared",
|
|
3469
|
+
within_own_variation: "No further from the baseline than the cohort's own week-to-week variation",
|
|
3470
|
+
withheld: "Withheld"
|
|
3471
|
+
},
|
|
3472
|
+
withheldReasons: {
|
|
3473
|
+
cohort_below_minimum: "the cohort was too small to report on when the scoring window closed",
|
|
3474
|
+
below_minimum_cohort: "the cohort was too small to report on when the scoring window closed",
|
|
3475
|
+
below_minimum_cohort_size: "the cohort was too small to report on when the scoring window closed",
|
|
3476
|
+
baseline_withheld: "the baseline was withheld"
|
|
3477
|
+
}
|
|
3478
|
+
};
|
|
3479
|
+
var OUTCOME_EMPTY = "Not stated";
|
|
3480
|
+
var OUTCOME_UNKNOWN = "An outcome this app does not recognise";
|
|
3481
|
+
var WITHHELD_UNKNOWN = "Withheld, for a reason this version of the app doesn't name yet.";
|
|
3482
|
+
var DIRECTION_WORDS = {
|
|
3483
|
+
up: "Expected to rise",
|
|
3484
|
+
down: "Expected to fall",
|
|
3485
|
+
none_declared: "No direction declared"
|
|
3486
|
+
};
|
|
3487
|
+
var DIRECTION_UNKNOWN = "A direction this app does not recognise";
|
|
3488
|
+
async function initiativesStatusLines(ctx) {
|
|
3489
|
+
const heading = "Changes your organisation has published to you";
|
|
3490
|
+
if (!ctx.eventWriteToken) {
|
|
3491
|
+
return [heading, " Not checked: this install holds no token, so nothing was fetched."];
|
|
3492
|
+
}
|
|
3493
|
+
const read = await (0, http_1.readInitiatives)(ctx.apiBaseUrl, ctx.eventWriteToken, AbortSignal.timeout(ctx.fetchTimeoutMs ?? READ_TIMEOUT_MS));
|
|
3494
|
+
if (read.kind === "rejected") {
|
|
3495
|
+
return [
|
|
3496
|
+
heading,
|
|
3497
|
+
` Couldn't check: the server turned this install's request down. If that keeps happening, pair again with \`${ctx.pairCommand}\`.`
|
|
3498
|
+
];
|
|
3499
|
+
}
|
|
3500
|
+
if (read.kind === "failed") {
|
|
3501
|
+
return [heading, ` Couldn't check: ${read.reason}. Run status again to retry.`];
|
|
3502
|
+
}
|
|
3503
|
+
return [heading, ...renderInitiatives(read.initiatives)];
|
|
3504
|
+
}
|
|
3505
|
+
function renderInitiatives(entries, copy = exports.INITIATIVE_COPY) {
|
|
3506
|
+
if (entries.length === 0)
|
|
3507
|
+
return [" None published to you."];
|
|
3508
|
+
const lines = [];
|
|
3509
|
+
let unreadable = 0;
|
|
3510
|
+
for (const entry of entries) {
|
|
3511
|
+
const initiative = asInitiative(entry);
|
|
3512
|
+
if (!initiative) {
|
|
3513
|
+
unreadable += 1;
|
|
3514
|
+
continue;
|
|
3515
|
+
}
|
|
3516
|
+
lines.push(...renderOne(initiative, copy));
|
|
3517
|
+
}
|
|
3518
|
+
if (unreadable > 0) {
|
|
3519
|
+
lines.push(` ${unreadable === 1 ? "1 entry" : `${unreadable} entries`} in the list couldn't be read by this version of the tool.`);
|
|
3520
|
+
}
|
|
3521
|
+
return lines;
|
|
3522
|
+
}
|
|
3523
|
+
function renderOne(initiative, copy) {
|
|
3524
|
+
const lines = [` ${initiative.organisationName}: ${initiative.title}`];
|
|
3525
|
+
lines.push(` ${describeStatus(initiative)}`);
|
|
3526
|
+
if (initiative.summaryForCohort) {
|
|
3527
|
+
for (const line of initiative.summaryForCohort.split(/\r?\n/))
|
|
3528
|
+
lines.push(` ${line}`);
|
|
3529
|
+
}
|
|
3530
|
+
if (initiative.direction)
|
|
3531
|
+
lines.push(` ${DIRECTION_WORDS[initiative.direction] ?? DIRECTION_UNKNOWN}`);
|
|
3532
|
+
lines.push(` Scoring window: ${formatWindowOrRaw(initiative.scoringStartUtc, initiative.scoringEndUtc)}`);
|
|
3533
|
+
if (initiative.result)
|
|
3534
|
+
lines.push(...renderResult(initiative.result, initiative.measureUnit, copy));
|
|
3535
|
+
lines.push("");
|
|
3536
|
+
return lines;
|
|
3537
|
+
}
|
|
3538
|
+
function describeStatus(initiative) {
|
|
3539
|
+
switch (initiative.status) {
|
|
3540
|
+
case "published":
|
|
3541
|
+
return "Published, not scored yet.";
|
|
3542
|
+
case "scored":
|
|
3543
|
+
return "Scored.";
|
|
3544
|
+
case "withdrawn":
|
|
3545
|
+
return initiative.withdrawnUtc ? `Withdrawn on ${formatDay(initiative.withdrawnUtc)}. It won't be scored.` : "Withdrawn. It won't be scored.";
|
|
3546
|
+
default:
|
|
3547
|
+
return "Status not recognised.";
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
function renderResult(result, unit, copy) {
|
|
3551
|
+
const lines = [];
|
|
3552
|
+
const show = (n) => unit ? `${figure(n)} ${unit}` : figure(n);
|
|
3553
|
+
if (result.value === null) {
|
|
3554
|
+
const why = copy.withheldReasons[result.withheldReason ?? ""];
|
|
3555
|
+
lines.push(` ${why ? `Withheld: ${why}.` : WITHHELD_UNKNOWN}`);
|
|
3556
|
+
return lines;
|
|
3557
|
+
}
|
|
3558
|
+
lines.push(` Result: ${show(result.value)}`);
|
|
3559
|
+
lines.push(` ${movementLine(result)}`);
|
|
3560
|
+
lines.push(` ${result.outcome ? copy.outcomes[result.outcome] ?? OUTCOME_UNKNOWN : OUTCOME_EMPTY}`);
|
|
3561
|
+
return lines;
|
|
3562
|
+
}
|
|
3563
|
+
function movementLine(result) {
|
|
3564
|
+
if (result.outcome === "within_own_variation")
|
|
3565
|
+
return "No material change against frozen baseline";
|
|
3566
|
+
if (result.delta === null)
|
|
3567
|
+
return "No reading";
|
|
3568
|
+
if (result.delta > 0)
|
|
3569
|
+
return `Up ${figure(result.delta)} against frozen baseline`;
|
|
3570
|
+
if (result.delta < 0)
|
|
3571
|
+
return `Down ${figure(Math.abs(result.delta))} against frozen baseline`;
|
|
3572
|
+
return "No change against frozen baseline";
|
|
3573
|
+
}
|
|
3574
|
+
function figure(n) {
|
|
3575
|
+
return String(Number(n.toPrecision(12)));
|
|
3576
|
+
}
|
|
3577
|
+
function asInitiative(value) {
|
|
3578
|
+
if (!value || typeof value !== "object")
|
|
3579
|
+
return void 0;
|
|
3580
|
+
const o = value;
|
|
3581
|
+
if (typeof o.title !== "string" || typeof o.status !== "string")
|
|
3582
|
+
return void 0;
|
|
3583
|
+
return {
|
|
3584
|
+
id: typeof o.id === "string" ? o.id : "",
|
|
3585
|
+
organisationName: typeof o.organisationName === "string" ? o.organisationName : "Your organisation",
|
|
3586
|
+
title: o.title,
|
|
3587
|
+
summaryForCohort: typeof o.summaryForCohort === "string" ? o.summaryForCohort : "",
|
|
3588
|
+
measureUnit: typeof o.measureUnit === "string" ? o.measureUnit : null,
|
|
3589
|
+
scoringStartUtc: typeof o.scoringStartUtc === "string" ? o.scoringStartUtc : "",
|
|
3590
|
+
scoringEndUtc: typeof o.scoringEndUtc === "string" ? o.scoringEndUtc : "",
|
|
3591
|
+
withdrawnUtc: typeof o.withdrawnUtc === "string" ? o.withdrawnUtc : null,
|
|
3592
|
+
status: o.status,
|
|
3593
|
+
direction: typeof o.direction === "string" ? o.direction : null,
|
|
3594
|
+
result: asResult(o.result)
|
|
3595
|
+
};
|
|
3596
|
+
}
|
|
3597
|
+
function asResult(value) {
|
|
3598
|
+
if (!value || typeof value !== "object")
|
|
3599
|
+
return null;
|
|
3600
|
+
const r = value;
|
|
3601
|
+
const num = (x) => typeof x === "number" && Number.isFinite(x) ? x : null;
|
|
3602
|
+
return {
|
|
3603
|
+
scoredAtUtc: typeof r.scoredAtUtc === "string" ? r.scoredAtUtc : "",
|
|
3604
|
+
value: num(r.value),
|
|
3605
|
+
baselineValue: num(r.baselineValue),
|
|
3606
|
+
delta: num(r.delta),
|
|
3607
|
+
movement: typeof r.movement === "string" ? r.movement : null,
|
|
3608
|
+
outcome: typeof r.outcome === "string" ? r.outcome : "",
|
|
3609
|
+
withheldReason: typeof r.withheldReason === "string" ? r.withheldReason : null,
|
|
3610
|
+
basis: typeof r.basis === "string" ? r.basis : null
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3613
|
+
function formatWindowOrRaw(startUtc, endUtc) {
|
|
3614
|
+
if (Number.isNaN(Date.parse(startUtc)) || Number.isNaN(Date.parse(endUtc)))
|
|
3615
|
+
return "not given";
|
|
3616
|
+
return (0, studyJoin_1.formatWindow)(startUtc, endUtc);
|
|
3617
|
+
}
|
|
3618
|
+
function formatDay(iso) {
|
|
3619
|
+
const date = new Date(iso);
|
|
3620
|
+
if (Number.isNaN(date.getTime()))
|
|
3621
|
+
return iso;
|
|
3622
|
+
return new Intl.DateTimeFormat("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" }).format(date);
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
});
|
|
3626
|
+
|
|
2974
3627
|
// ../packages/tool-kit/out/setupDisclosure.js
|
|
2975
3628
|
var require_setupDisclosure = __commonJS({
|
|
2976
3629
|
"../packages/tool-kit/out/setupDisclosure.js"(exports) {
|
|
@@ -2991,6 +3644,7 @@ var require_setupDisclosure = __commonJS({
|
|
|
2991
3644
|
edits: "roughly how much a file changed, as a bucket, and whether you edited it after the agent wrote it",
|
|
2992
3645
|
context: "how full the context window got",
|
|
2993
3646
|
waiting: "that your agent stopped and waited for you, as one word: permission_request, idle_prompt, or other",
|
|
3647
|
+
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",
|
|
2994
3648
|
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"
|
|
2995
3649
|
};
|
|
2996
3650
|
exports.ALWAYS_SENT = ["session", "counts", "tools", "outcome", "repo", "clock"];
|
|
@@ -3016,6 +3670,211 @@ var require_setupDisclosure = __commonJS({
|
|
|
3016
3670
|
}
|
|
3017
3671
|
});
|
|
3018
3672
|
|
|
3673
|
+
// ../packages/tool-kit/out/studyNotices.js
|
|
3674
|
+
var require_studyNotices = __commonJS({
|
|
3675
|
+
"../packages/tool-kit/out/studyNotices.js"(exports) {
|
|
3676
|
+
"use strict";
|
|
3677
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3678
|
+
exports.NOTICED_PURPOSES = void 0;
|
|
3679
|
+
exports.studyNoticeStatus = studyNoticeStatus;
|
|
3680
|
+
exports.renderStudyNotices = renderStudyNotices;
|
|
3681
|
+
exports.runStudyObjection = runStudyObjection;
|
|
3682
|
+
var http_1 = require_http();
|
|
3683
|
+
var READ_TIMEOUT_MS = 5e3;
|
|
3684
|
+
var NOTICE_LABEL = "Counted unless you object";
|
|
3685
|
+
var PROCESSOR = "Ascenda";
|
|
3686
|
+
exports.NOTICED_PURPOSES = [
|
|
3687
|
+
{ code: 501, slug: "telemetry", title: "Live tool telemetry" },
|
|
3688
|
+
{ code: 507, slug: "import", title: "One-time import of past AI work" },
|
|
3689
|
+
{ code: 11, slug: "work-patterns", title: "Work-pattern axes in the group figures" }
|
|
3690
|
+
];
|
|
3691
|
+
var BASIS_WORDS = {
|
|
3692
|
+
legitimate_interests: "legitimate interests",
|
|
3693
|
+
collective_agreement: "a collective agreement"
|
|
3694
|
+
};
|
|
3695
|
+
async function studyNoticeStatus(ctx) {
|
|
3696
|
+
const nothing = { lines: [], markShown: async () => {
|
|
3697
|
+
} };
|
|
3698
|
+
const token = ctx.eventWriteToken;
|
|
3699
|
+
if (!token)
|
|
3700
|
+
return nothing;
|
|
3701
|
+
const read = await (0, http_1.readStudyNotices)(ctx.apiBaseUrl, token, AbortSignal.timeout(ctx.fetchTimeoutMs ?? READ_TIMEOUT_MS));
|
|
3702
|
+
if (read.kind !== "ok")
|
|
3703
|
+
return nothing;
|
|
3704
|
+
const lines = renderStudyNotices(read.notices, ctx.commandPrefix, ctx.now);
|
|
3705
|
+
if (lines.length === 0)
|
|
3706
|
+
return nothing;
|
|
3707
|
+
const unshown = shownPurposes(read.notices).filter((n) => !n.noticeFromUtc && n.organisationId);
|
|
3708
|
+
return {
|
|
3709
|
+
lines,
|
|
3710
|
+
markShown: async () => {
|
|
3711
|
+
const signal = AbortSignal.timeout(ctx.fetchTimeoutMs ?? READ_TIMEOUT_MS);
|
|
3712
|
+
await Promise.all(unshown.map((n) => (0, http_1.markStudyNoticeShown)(ctx.apiBaseUrl, token, n.organisationId, n.code, signal)));
|
|
3713
|
+
}
|
|
3714
|
+
};
|
|
3715
|
+
}
|
|
3716
|
+
function shownPurposes(entries) {
|
|
3717
|
+
return entries.map(asNotice).filter((n) => n !== void 0 && exports.NOTICED_PURPOSES.some((p) => p.code === n.code));
|
|
3718
|
+
}
|
|
3719
|
+
function renderStudyNotices(entries, commandPrefix, now = /* @__PURE__ */ new Date()) {
|
|
3720
|
+
const body = [];
|
|
3721
|
+
let unreadable = 0;
|
|
3722
|
+
for (const entry of entries) {
|
|
3723
|
+
const notice = asNotice(entry);
|
|
3724
|
+
const purpose = notice && exports.NOTICED_PURPOSES.find((p) => p.code === notice.code);
|
|
3725
|
+
if (!notice || !purpose) {
|
|
3726
|
+
unreadable += 1;
|
|
3727
|
+
continue;
|
|
3728
|
+
}
|
|
3729
|
+
body.push(...renderOne(notice, purpose, commandPrefix, now));
|
|
3730
|
+
}
|
|
3731
|
+
if (body.length === 0)
|
|
3732
|
+
return [];
|
|
3733
|
+
if (unreadable > 0) {
|
|
3734
|
+
body.push(` ${unreadable === 1 ? "1 entry" : `${unreadable} entries`} in the list couldn't be read by this version of the tool.`);
|
|
3735
|
+
}
|
|
3736
|
+
return ["", "Your organisation's study", ...body];
|
|
3737
|
+
}
|
|
3738
|
+
function renderOne(notice, purpose, commandPrefix, now) {
|
|
3739
|
+
const org = notice.organisationName;
|
|
3740
|
+
const command = `${commandPrefix} object ${purpose.slug}`;
|
|
3741
|
+
const lines = [` ${org}: ${purpose.title}`];
|
|
3742
|
+
lines.push(` ${notice.label || NOTICE_LABEL}`);
|
|
3743
|
+
lines.push(` ${basisLine(notice)}`);
|
|
3744
|
+
if (notice.signatoryName)
|
|
3745
|
+
lines.push(` Recorded by ${notice.signatoryName}.`);
|
|
3746
|
+
lines.push(` ${notice.processor || PROCESSOR} processes this for ${org}.`);
|
|
3747
|
+
if (notice.objected === true) {
|
|
3748
|
+
lines.push(" You objected. You are left out from the next report on.");
|
|
3749
|
+
lines.push(` To undo: ${command} --undo`);
|
|
3750
|
+
} else if (notice.objected === false) {
|
|
3751
|
+
lines.push(" You haven't objected.");
|
|
3752
|
+
if (notice.noticeFromUtc && isDate(notice.noticeFromUtc)) {
|
|
3753
|
+
const starts = notice.countingFromUtc && isDate(notice.countingFromUtc) ? notice.countingFromUtc : new Date(Date.parse(notice.noticeFromUtc) + NOTICE_PERIOD_MS).toISOString();
|
|
3754
|
+
if (Date.parse(starts) > now.getTime()) {
|
|
3755
|
+
lines.push(` Notice given ${formatDay(notice.noticeFromUtc)}. Counting starts ${formatDay(starts)}.`);
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
lines.push(` To object: ${command}. No reason is asked. You are left out from the next report on, and earlier reports stay as they were.`);
|
|
3759
|
+
} else {
|
|
3760
|
+
lines.push(" This version of the tool couldn't read whether you've objected. Run status again.");
|
|
3761
|
+
lines.push(` To object: ${command}`);
|
|
3762
|
+
lines.push(` To undo: ${command} --undo`);
|
|
3763
|
+
}
|
|
3764
|
+
lines.push("");
|
|
3765
|
+
return lines;
|
|
3766
|
+
}
|
|
3767
|
+
function basisLine(notice) {
|
|
3768
|
+
const words = notice.basisLabel ?? BASIS_WORDS[notice.basis];
|
|
3769
|
+
const head = words ? `${notice.organisationName}'s basis is ${words}.` : `${notice.organisationName}'s basis is one this version of the tool can't name.`;
|
|
3770
|
+
const dated = notice.documentDate && isDate(notice.documentDate) ? formatDay(notice.documentDate) : null;
|
|
3771
|
+
const ref = notice.documentReference ? `ref ${notice.documentReference}` : null;
|
|
3772
|
+
const title = notice.documentTitle ? dated ? `${notice.documentTitle} (${dated})` : notice.documentTitle : null;
|
|
3773
|
+
const document = [title, ref].filter((part) => Boolean(part)).join(", ");
|
|
3774
|
+
return document ? `${head} Document: ${document}.` : head;
|
|
3775
|
+
}
|
|
3776
|
+
var NOTICE_PERIOD_MS = 14 * 24 * 60 * 60 * 1e3;
|
|
3777
|
+
function asNotice(value) {
|
|
3778
|
+
if (!value || typeof value !== "object")
|
|
3779
|
+
return void 0;
|
|
3780
|
+
const o = value;
|
|
3781
|
+
if (typeof o.code !== "number")
|
|
3782
|
+
return void 0;
|
|
3783
|
+
if (typeof o.mode === "string" && o.mode.trim().toLowerCase() !== "notice")
|
|
3784
|
+
return void 0;
|
|
3785
|
+
const str = (x) => typeof x === "string" && x.trim() ? x : null;
|
|
3786
|
+
return {
|
|
3787
|
+
organisationId: str(o.organisationId),
|
|
3788
|
+
organisationName: str(o.organisationName) ?? "Your organisation",
|
|
3789
|
+
code: o.code,
|
|
3790
|
+
name: str(o.name),
|
|
3791
|
+
label: str(o.label),
|
|
3792
|
+
processor: str(o.processor),
|
|
3793
|
+
basis: typeof o.basis === "string" ? o.basis : "",
|
|
3794
|
+
basisLabel: str(o.basisLabel),
|
|
3795
|
+
documentTitle: str(o.documentTitle),
|
|
3796
|
+
documentDate: str(o.documentDate),
|
|
3797
|
+
documentReference: str(o.documentReference),
|
|
3798
|
+
signatoryName: str(o.signatoryName),
|
|
3799
|
+
objected: typeof o.objected === "boolean" ? o.objected : null,
|
|
3800
|
+
objectedAtUtc: str(o.objectedAtUtc),
|
|
3801
|
+
noticeFromUtc: str(o.noticeFromUtc),
|
|
3802
|
+
countingFromUtc: str(o.countingFromUtc)
|
|
3803
|
+
};
|
|
3804
|
+
}
|
|
3805
|
+
async function runStudyObjection(ctx) {
|
|
3806
|
+
const stdin = ctx.stdin ?? process.stdin;
|
|
3807
|
+
const stdout = ctx.stdout ?? process.stdout;
|
|
3808
|
+
const stderr = ctx.stderr ?? process.stderr;
|
|
3809
|
+
const print = (line) => stdout.write(`${line}
|
|
3810
|
+
`);
|
|
3811
|
+
if (!stdin.isTTY || !stdout.isTTY) {
|
|
3812
|
+
stderr.write("object needs an interactive terminal (stdin and stdout). Run it directly, not from a script or a pipe.\n");
|
|
3813
|
+
return 1;
|
|
3814
|
+
}
|
|
3815
|
+
const undo = ctx.argv.includes("--undo");
|
|
3816
|
+
const rest = ctx.argv.filter((a) => a !== "--undo");
|
|
3817
|
+
const purpose = rest.length === 1 ? exports.NOTICED_PURPOSES.find((p) => p.slug === rest[0]) : void 0;
|
|
3818
|
+
if (!purpose) {
|
|
3819
|
+
stderr.write(objectionUsage(ctx.commandPrefix));
|
|
3820
|
+
return 1;
|
|
3821
|
+
}
|
|
3822
|
+
if (!ctx.eventWriteToken) {
|
|
3823
|
+
stderr.write(`This install isn't paired, so there's nothing to object to. Pair with \`${ctx.pairCommand}\`.
|
|
3824
|
+
`);
|
|
3825
|
+
return 1;
|
|
3826
|
+
}
|
|
3827
|
+
const command = `${ctx.commandPrefix} object ${purpose.slug}`;
|
|
3828
|
+
try {
|
|
3829
|
+
await (0, http_1.setStudyObjection)(ctx.apiBaseUrl, ctx.eventWriteToken, purpose.code, !undo);
|
|
3830
|
+
} catch (error) {
|
|
3831
|
+
stderr.write(`${describeObjectionError(error, purpose, undo, ctx.pairCommand)}
|
|
3832
|
+
`);
|
|
3833
|
+
return 1;
|
|
3834
|
+
}
|
|
3835
|
+
if (undo) {
|
|
3836
|
+
print(`Objection withdrawn: ${purpose.title}.`);
|
|
3837
|
+
print("You're counted again from the next report.");
|
|
3838
|
+
print(`To object again: ${command}`);
|
|
3839
|
+
} else {
|
|
3840
|
+
print(`Objected: ${purpose.title}.`);
|
|
3841
|
+
print("You objected. You are left out from the next report on, and earlier reports stay as they were.");
|
|
3842
|
+
print(`To undo: ${command} --undo`);
|
|
3843
|
+
}
|
|
3844
|
+
return 0;
|
|
3845
|
+
}
|
|
3846
|
+
function objectionUsage(commandPrefix) {
|
|
3847
|
+
const lines = [`Usage: ${commandPrefix} object <purpose> [--undo]`, "", "Purposes:"];
|
|
3848
|
+
for (const p of exports.NOTICED_PURPOSES)
|
|
3849
|
+
lines.push(` ${p.slug.padEnd(14)}${p.title}`);
|
|
3850
|
+
lines.push("", "status shows which of these your organisation counts unless you object.");
|
|
3851
|
+
return `${lines.join("\n")}
|
|
3852
|
+
`;
|
|
3853
|
+
}
|
|
3854
|
+
function describeObjectionError(error, purpose, undo, pairCommand) {
|
|
3855
|
+
if (error instanceof http_1.AscendaApiError) {
|
|
3856
|
+
if (error.status === 404 && error.errorCode === "not_noticed") {
|
|
3857
|
+
return undo ? `Your organisation doesn't count you for ${purpose.title} unless you object, so there's no objection to undo.` : `Your organisation doesn't count you for ${purpose.title} unless you object, so there's nothing to object to.`;
|
|
3858
|
+
}
|
|
3859
|
+
if (error.status === 401)
|
|
3860
|
+
return `The server turned this install's request down. If that keeps happening, pair again with \`${pairCommand}\`.`;
|
|
3861
|
+
if (error.status === 404)
|
|
3862
|
+
return "This server doesn't take objections yet. Nothing changed.";
|
|
3863
|
+
return `Couldn't record that (HTTP ${error.status}). Nothing changed. Run it again to retry.`;
|
|
3864
|
+
}
|
|
3865
|
+
return "Couldn't reach the server. Nothing changed. Run it again to retry.";
|
|
3866
|
+
}
|
|
3867
|
+
function isDate(iso) {
|
|
3868
|
+
return !Number.isNaN(Date.parse(iso));
|
|
3869
|
+
}
|
|
3870
|
+
var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
3871
|
+
function formatDay(iso) {
|
|
3872
|
+
const date = new Date(iso);
|
|
3873
|
+
return `${date.getUTCDate()} ${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}`;
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
});
|
|
3877
|
+
|
|
3019
3878
|
// ../packages/tool-kit/out/cliAgentSetup.js
|
|
3020
3879
|
var require_cliAgentSetup = __commonJS({
|
|
3021
3880
|
"../packages/tool-kit/out/cliAgentSetup.js"(exports) {
|
|
@@ -3062,6 +3921,7 @@ var require_cliAgentSetup = __commonJS({
|
|
|
3062
3921
|
exports.cliAgentHookBinPath = cliAgentHookBinPath;
|
|
3063
3922
|
exports.runCliAgentSetup = runCliAgentSetup2;
|
|
3064
3923
|
exports.writeHookSettings = writeHookSettings;
|
|
3924
|
+
exports.registeredHookSets = registeredHookSets;
|
|
3065
3925
|
exports.findStaleHookCommands = findStaleHookCommands;
|
|
3066
3926
|
var crypto = __importStar(__require("crypto"));
|
|
3067
3927
|
var fs = __importStar(__require("fs"));
|
|
@@ -3071,9 +3931,14 @@ var require_cliAgentSetup = __commonJS({
|
|
|
3071
3931
|
var credentials_1 = require_credentials();
|
|
3072
3932
|
var hookAdapter_1 = require_hookAdapter();
|
|
3073
3933
|
var http_1 = require_http();
|
|
3934
|
+
var hookSet_1 = require_hookSet();
|
|
3935
|
+
var initiatives_1 = require_initiatives();
|
|
3074
3936
|
var setupDisclosure_1 = require_setupDisclosure();
|
|
3937
|
+
var stateStore_1 = require_stateStore();
|
|
3938
|
+
var studyJoin_1 = require_studyJoin();
|
|
3939
|
+
var studyNotices_1 = require_studyNotices();
|
|
3075
3940
|
var tokenStore_1 = require_tokenStore();
|
|
3076
|
-
var MANAGEMENT_COMMANDS = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "-h", "--help"]);
|
|
3941
|
+
var MANAGEMENT_COMMANDS = /* @__PURE__ */ new Set(["setup", "install", "status", "uninstall", "join", "object", "-h", "--help"]);
|
|
3077
3942
|
function isCliAgentManagementCommand2(argument) {
|
|
3078
3943
|
return argument !== void 0 && MANAGEMENT_COMMANDS.has(argument);
|
|
3079
3944
|
}
|
|
@@ -3086,6 +3951,8 @@ var require_cliAgentSetup = __commonJS({
|
|
|
3086
3951
|
npx ${spec.packageName} setup [options]
|
|
3087
3952
|
npx ${spec.packageName} status
|
|
3088
3953
|
npx ${spec.packageName} uninstall
|
|
3954
|
+
npx ${spec.packageName} join <code>
|
|
3955
|
+
npx ${spec.packageName} object <purpose> [--undo]
|
|
3089
3956
|
|
|
3090
3957
|
Options
|
|
3091
3958
|
--api-base-url <url> ingest host (default ${hookAdapter_1.DEFAULT_API_BASE_URL})
|
|
@@ -3100,6 +3967,10 @@ Options
|
|
|
3100
3967
|
`;
|
|
3101
3968
|
}
|
|
3102
3969
|
async function runCliAgentSetup2(argv, spec) {
|
|
3970
|
+
if (argv[0] === "join")
|
|
3971
|
+
return runCliAgentStudyJoin(argv.slice(1), spec);
|
|
3972
|
+
if (argv[0] === "object")
|
|
3973
|
+
return runCliAgentStudyObjection(argv.slice(1), spec);
|
|
3103
3974
|
let options;
|
|
3104
3975
|
try {
|
|
3105
3976
|
options = parseArgs(argv, spec);
|
|
@@ -3112,7 +3983,7 @@ Options
|
|
|
3112
3983
|
return 0;
|
|
3113
3984
|
}
|
|
3114
3985
|
if (options.action === "status")
|
|
3115
|
-
return printStatus(options, spec);
|
|
3986
|
+
return await printStatus(options, spec);
|
|
3116
3987
|
if (options.action === "uninstall")
|
|
3117
3988
|
return uninstall(options, spec);
|
|
3118
3989
|
const apiBaseUrl = (options.apiBaseUrl ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
@@ -3149,10 +4020,14 @@ ${(0, setupDisclosure_1.renderSetupDisclosure)({ sends: spec.sends, displayName:
|
|
|
3149
4020
|
}
|
|
3150
4021
|
console.log(` credentials ${(0, credentials_1.credentialsFilePath)()} (tools.${spec.host})`);
|
|
3151
4022
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
4023
|
+
const before = registeredHookSets(readSettings(settingsFile), spec);
|
|
3152
4024
|
const written = writeHookSettings(settingsFile, binary, spec, options.dryRun);
|
|
3153
4025
|
if (written === null)
|
|
3154
4026
|
return 1;
|
|
3155
4027
|
console.log(` hooks ${settingsFile} (${spec.hookEvents.length} events${written ? "" : ", already current"})`);
|
|
4028
|
+
const changes = spec.hookSet === void 0 ? void 0 : (0, hookSet_1.describeHookSetChanges)((0, hookSet_1.hookSetChanges)(before, spec.hookEvents), spec.hookSet);
|
|
4029
|
+
if (changes)
|
|
4030
|
+
console.log(` ${changes}`);
|
|
3156
4031
|
if (options.dryRun) {
|
|
3157
4032
|
console.log("\nDry run \u2014 nothing was written.");
|
|
3158
4033
|
return 0;
|
|
@@ -3240,6 +4115,45 @@ ${usage(spec)}`);
|
|
|
3240
4115
|
}
|
|
3241
4116
|
return options;
|
|
3242
4117
|
}
|
|
4118
|
+
async function runCliAgentStudyJoin(argv, spec) {
|
|
4119
|
+
const joinCode = argv[0];
|
|
4120
|
+
if (!joinCode || joinCode.startsWith("-")) {
|
|
4121
|
+
console.error(`Usage: npx ${spec.packageName} join <code>`);
|
|
4122
|
+
return 1;
|
|
4123
|
+
}
|
|
4124
|
+
const pairing = resolvePairedToken(spec);
|
|
4125
|
+
if (!pairing)
|
|
4126
|
+
return 1;
|
|
4127
|
+
return (0, studyJoin_1.runStudyJoin)({ ...pairing, displayName: spec.displayName, joinCode });
|
|
4128
|
+
}
|
|
4129
|
+
async function runCliAgentStudyObjection(argv, spec) {
|
|
4130
|
+
const pairing = resolvePairedToken(spec);
|
|
4131
|
+
if (!pairing)
|
|
4132
|
+
return 1;
|
|
4133
|
+
return (0, studyNotices_1.runStudyObjection)({
|
|
4134
|
+
...pairing,
|
|
4135
|
+
commandPrefix: `npx ${spec.packageName}`,
|
|
4136
|
+
pairCommand: `npx ${spec.packageName} setup`,
|
|
4137
|
+
argv
|
|
4138
|
+
});
|
|
4139
|
+
}
|
|
4140
|
+
function resolvePairedToken(spec) {
|
|
4141
|
+
const setupCommand = `npx ${spec.packageName} setup`;
|
|
4142
|
+
let toolInstallationId;
|
|
4143
|
+
try {
|
|
4144
|
+
({ toolInstallationId } = (0, hookAdapter_1.resolveCliAgentInstallationId)(spec.toolType, { host: spec.host, setupCommand }));
|
|
4145
|
+
} catch (error) {
|
|
4146
|
+
console.error(error instanceof hookAdapter_1.MissingInstallationIdError ? error.message : error instanceof Error ? error.message : String(error));
|
|
4147
|
+
return void 0;
|
|
4148
|
+
}
|
|
4149
|
+
const eventWriteToken = (0, tokenStore_1.readTokenFile)(process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, tokenStore_1.defaultTokenFilePath)(toolInstallationId)) ?? process.env.ASCENDA_EVENT_WRITE_TOKEN;
|
|
4150
|
+
if (!eventWriteToken) {
|
|
4151
|
+
console.error(`Not paired: no write token for ${toolInstallationId}. Run: ${setupCommand}`);
|
|
4152
|
+
return void 0;
|
|
4153
|
+
}
|
|
4154
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? (0, credentials_1.readHostCredentials)(spec.host)?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
4155
|
+
return { apiBaseUrl, eventWriteToken };
|
|
4156
|
+
}
|
|
3243
4157
|
async function resolveIdentity(apiBaseUrl, options, spec) {
|
|
3244
4158
|
const existingId = options.toolInstallationId ?? (0, credentials_1.readHostCredentials)(spec.host)?.toolInstallationId;
|
|
3245
4159
|
if (existingId && options.token) {
|
|
@@ -3247,8 +4161,13 @@ ${usage(spec)}`);
|
|
|
3247
4161
|
(0, tokenStore_1.persistEventWriteToken)((0, tokenStore_1.defaultTokenFilePath)(existingId), options.token);
|
|
3248
4162
|
return { toolInstallationId: existingId, paired: false };
|
|
3249
4163
|
}
|
|
3250
|
-
|
|
3251
|
-
|
|
4164
|
+
const existingToken = existingId ? (0, tokenStore_1.readTokenFile)((0, tokenStore_1.defaultTokenFilePath)(existingId)) : void 0;
|
|
4165
|
+
if (existingId && existingToken) {
|
|
4166
|
+
const check = await checkSavedToken(apiBaseUrl, existingId, existingToken);
|
|
4167
|
+
if (check === "keep")
|
|
4168
|
+
return { toolInstallationId: existingId, paired: false };
|
|
4169
|
+
console.log(`
|
|
4170
|
+
The saved token for ${existingId} isn't accepted any more. Pairing again.`);
|
|
3252
4171
|
}
|
|
3253
4172
|
if (options.dryRun) {
|
|
3254
4173
|
return { toolInstallationId: existingId ?? `${spec.toolType}:<paired at run time>`, paired: false };
|
|
@@ -3269,6 +4188,18 @@ Could not reach ${apiBaseUrl} to pair: ${error instanceof Error ? error.message
|
|
|
3269
4188
|
(0, tokenStore_1.persistEventWriteToken)((0, tokenStore_1.defaultTokenFilePath)(toolInstallationId), token);
|
|
3270
4189
|
return { toolInstallationId, paired: true };
|
|
3271
4190
|
}
|
|
4191
|
+
var TOKEN_CHECK_TIMEOUT_MS = 5e3;
|
|
4192
|
+
async function checkSavedToken(apiBaseUrl, toolInstallationId, token) {
|
|
4193
|
+
const read = await (0, http_1.readInitiatives)(apiBaseUrl, token, AbortSignal.timeout(TOKEN_CHECK_TIMEOUT_MS));
|
|
4194
|
+
if (read.kind === "rejected")
|
|
4195
|
+
return "repair";
|
|
4196
|
+
if (read.kind === "failed" && (0, stateStore_1.readCollectorState)((0, stateStore_1.defaultStateFilePath)(toolInstallationId))?.lastOutcome === "auth_failed") {
|
|
4197
|
+
console.log(`
|
|
4198
|
+
Couldn't check the saved token (${read.reason}), and the last send was refused.`);
|
|
4199
|
+
console.log(" Keeping it for now. Run setup again once the server is reachable.");
|
|
4200
|
+
}
|
|
4201
|
+
return "keep";
|
|
4202
|
+
}
|
|
3272
4203
|
async function pollForToken(apiBaseUrl, pairingSessionId, code, expiresAt) {
|
|
3273
4204
|
const deadline = Math.min(Date.parse(expiresAt) || Date.now() + 3e5, Date.now() + 3e5);
|
|
3274
4205
|
let announced = false;
|
|
@@ -3320,7 +4251,7 @@ ${settingsFile} is not valid JSON. Fix or move it, then run setup again.`);
|
|
|
3320
4251
|
}
|
|
3321
4252
|
}
|
|
3322
4253
|
}
|
|
3323
|
-
const command = hookCommand(binary);
|
|
4254
|
+
const command = hookCommand(binary, spec);
|
|
3324
4255
|
const hooks = { ...settings.hooks ?? {} };
|
|
3325
4256
|
for (const event of spec.hookEvents) {
|
|
3326
4257
|
const kept = (hooks[event] ?? []).filter((entry) => !isOurs(entry, spec));
|
|
@@ -3343,8 +4274,20 @@ ${serialised}`);
|
|
|
3343
4274
|
fs.writeFileSync(settingsFile, serialised, "utf8");
|
|
3344
4275
|
return true;
|
|
3345
4276
|
}
|
|
3346
|
-
function hookCommand(binary) {
|
|
3347
|
-
return `"${process.execPath}" "${binary}"`;
|
|
4277
|
+
function hookCommand(binary, spec) {
|
|
4278
|
+
return `"${process.execPath}" "${binary}"${(0, hookSet_1.hookSetArgument)(spec.hookSet)}`;
|
|
4279
|
+
}
|
|
4280
|
+
function registeredHookSets(settings, spec) {
|
|
4281
|
+
const sets = /* @__PURE__ */ new Map();
|
|
4282
|
+
for (const [event, entries] of Object.entries(settings.hooks ?? {})) {
|
|
4283
|
+
for (const entry of entries ?? []) {
|
|
4284
|
+
if (!isOurs(entry, spec))
|
|
4285
|
+
continue;
|
|
4286
|
+
const set = (0, hookSet_1.hookSetOfCommand)(spec.settings.commandOf(entry));
|
|
4287
|
+
sets.set(event, Math.min(set, sets.get(event) ?? set));
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
return sets;
|
|
3348
4291
|
}
|
|
3349
4292
|
function isOurs(entry, spec) {
|
|
3350
4293
|
const command = spec.settings.commandOf(entry);
|
|
@@ -3371,7 +4314,7 @@ ${serialised}`);
|
|
|
3371
4314
|
return {};
|
|
3372
4315
|
}
|
|
3373
4316
|
}
|
|
3374
|
-
function printStatus(options, spec) {
|
|
4317
|
+
async function printStatus(options, spec) {
|
|
3375
4318
|
const credentials = (0, credentials_1.readHostCredentials)(spec.host);
|
|
3376
4319
|
const settingsFile = spec.settings.settingsPath(options.scope, options.projectDir);
|
|
3377
4320
|
const binary = cliAgentHookBinPath(spec.binaryName);
|
|
@@ -3386,12 +4329,30 @@ ${serialised}`);
|
|
|
3386
4329
|
console.log(`token ${localOnly ? "\u2014 none needed until this install is paired" : tokenFile && (0, tokenStore_1.readTokenFile)(tokenFile) ? "present" : "\u2014 missing"}`);
|
|
3387
4330
|
console.log(`hook binary ${fs.existsSync(binary) ? binary : "\u2014 not installed"}`);
|
|
3388
4331
|
console.log(`hooks ${registered}/${spec.hookEvents.length} registered in ${settingsFile}`);
|
|
4332
|
+
if (spec.hookSet !== void 0 && registered > 0) {
|
|
4333
|
+
const sets = [...registeredHookSets(settings, spec).values()];
|
|
4334
|
+
const oldest = Math.min(...sets);
|
|
4335
|
+
console.log(oldest < spec.hookSet ? `hook set ${oldest}, this version registers ${spec.hookSet}. Upgrade: npx ${spec.packageName} setup${options.scope === "user" ? " --scope user" : ""}` : `hook set ${spec.hookSet} (current)`);
|
|
4336
|
+
}
|
|
3389
4337
|
if (stale.length) {
|
|
3390
4338
|
console.log(`stale hooks ${stale.length} not pointing at the installed binary \u2014 each one fails silently per event:`);
|
|
3391
4339
|
for (const command of stale)
|
|
3392
4340
|
console.log(` ${command}`);
|
|
3393
4341
|
console.log(` Remove them from ${settingsFile} by hand; setup cannot tell them from a hook you wrote.`);
|
|
3394
4342
|
}
|
|
4343
|
+
const tokenValue = localOnly ? void 0 : (tokenFile ? (0, tokenStore_1.readTokenFile)(tokenFile) : void 0) ?? (process.env.ASCENDA_EVENT_WRITE_TOKEN?.trim() || void 0);
|
|
4344
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? credentials?.apiBaseUrl ?? hookAdapter_1.DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
4345
|
+
const [initiativeLines, notices] = await Promise.all([
|
|
4346
|
+
(0, initiatives_1.initiativesStatusLines)({ apiBaseUrl, eventWriteToken: tokenValue, pairCommand: `npx ${spec.packageName} setup` }),
|
|
4347
|
+
(0, studyNotices_1.studyNoticeStatus)({ apiBaseUrl, eventWriteToken: tokenValue, commandPrefix: `npx ${spec.packageName}` })
|
|
4348
|
+
]);
|
|
4349
|
+
console.log("");
|
|
4350
|
+
for (const line of initiativeLines)
|
|
4351
|
+
console.log(line);
|
|
4352
|
+
for (const line of notices.lines)
|
|
4353
|
+
console.log(line);
|
|
4354
|
+
if (process.stdout.isTTY)
|
|
4355
|
+
await notices.markShown();
|
|
3395
4356
|
const paired = localOnly || credentials?.toolInstallationId !== void 0;
|
|
3396
4357
|
const healthy = paired && registered === spec.hookEvents.length && fs.existsSync(binary) && !stale.length;
|
|
3397
4358
|
return healthy ? 0 : 1;
|
|
@@ -3558,6 +4519,7 @@ var require_liveBus = __commonJS({
|
|
|
3558
4519
|
};
|
|
3559
4520
|
}();
|
|
3560
4521
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4522
|
+
exports.LIVE_BUS_BACKGROUND_TRUST_MS = void 0;
|
|
3561
4523
|
exports.liveBusSocketCandidates = liveBusSocketCandidates;
|
|
3562
4524
|
exports.liveBusSocketPath = liveBusSocketPath;
|
|
3563
4525
|
exports.bucketPromptSize = bucketPromptSize2;
|
|
@@ -3566,7 +4528,9 @@ var require_liveBus = __commonJS({
|
|
|
3566
4528
|
var net = __importStar(__require("net"));
|
|
3567
4529
|
var os2 = __importStar(__require("os"));
|
|
3568
4530
|
var path2 = __importStar(__require("path"));
|
|
4531
|
+
var hookSet_1 = require_hookSet();
|
|
3569
4532
|
var WRITE_TIMEOUT_MS = 50;
|
|
4533
|
+
exports.LIVE_BUS_BACKGROUND_TRUST_MS = 60 * 60 * 1e3;
|
|
3570
4534
|
var APP_BUNDLE_ID = "one.ascenda.ascendaMissionControl";
|
|
3571
4535
|
var SAVER_HOST_BUNDLE_ID = "com.apple.ScreenSaver.Engine.legacyScreenSaver";
|
|
3572
4536
|
function liveBusSocketCandidates() {
|
|
@@ -3606,6 +4570,14 @@ var require_liveBus = __commonJS({
|
|
|
3606
4570
|
return "xl";
|
|
3607
4571
|
}
|
|
3608
4572
|
var NOBODY_LISTENING = /* @__PURE__ */ new Set(["ECONNREFUSED", "ENOENT"]);
|
|
4573
|
+
function onTheWire(signal) {
|
|
4574
|
+
const out = { ...signal };
|
|
4575
|
+
if ("hookSet" in out && !(0, hookSet_1.isHookSet)(out.hookSet))
|
|
4576
|
+
delete out.hookSet;
|
|
4577
|
+
if ("viaPlugin" in out && out.viaPlugin !== true)
|
|
4578
|
+
delete out.viaPlugin;
|
|
4579
|
+
return out;
|
|
4580
|
+
}
|
|
3609
4581
|
function emitLiveSignal2(signal) {
|
|
3610
4582
|
return new Promise((resolve) => {
|
|
3611
4583
|
const candidates = existingSocketCandidates();
|
|
@@ -3666,7 +4638,7 @@ var require_liveBus = __commonJS({
|
|
|
3666
4638
|
return;
|
|
3667
4639
|
connected = true;
|
|
3668
4640
|
try {
|
|
3669
|
-
attempt.write(`${JSON.stringify(signal)}
|
|
4641
|
+
attempt.write(`${JSON.stringify(onTheWire(signal))}
|
|
3670
4642
|
`, done);
|
|
3671
4643
|
} catch {
|
|
3672
4644
|
done();
|
|
@@ -3679,14 +4651,153 @@ var require_liveBus = __commonJS({
|
|
|
3679
4651
|
}
|
|
3680
4652
|
});
|
|
3681
4653
|
|
|
4654
|
+
// ../packages/tool-kit/out/agentProcess.js
|
|
4655
|
+
var require_agentProcess = __commonJS({
|
|
4656
|
+
"../packages/tool-kit/out/agentProcess.js"(exports) {
|
|
4657
|
+
"use strict";
|
|
4658
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4659
|
+
if (k2 === void 0) k2 = k;
|
|
4660
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4661
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4662
|
+
desc = { enumerable: true, get: function() {
|
|
4663
|
+
return m[k];
|
|
4664
|
+
} };
|
|
4665
|
+
}
|
|
4666
|
+
Object.defineProperty(o, k2, desc);
|
|
4667
|
+
} : function(o, m, k, k2) {
|
|
4668
|
+
if (k2 === void 0) k2 = k;
|
|
4669
|
+
o[k2] = m[k];
|
|
4670
|
+
});
|
|
4671
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4672
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4673
|
+
} : function(o, v) {
|
|
4674
|
+
o["default"] = v;
|
|
4675
|
+
});
|
|
4676
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4677
|
+
var ownKeys = function(o) {
|
|
4678
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4679
|
+
var ar = [];
|
|
4680
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4681
|
+
return ar;
|
|
4682
|
+
};
|
|
4683
|
+
return ownKeys(o);
|
|
4684
|
+
};
|
|
4685
|
+
return function(mod) {
|
|
4686
|
+
if (mod && mod.__esModule) return mod;
|
|
4687
|
+
var result = {};
|
|
4688
|
+
if (mod != null) {
|
|
4689
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4690
|
+
}
|
|
4691
|
+
__setModuleDefault(result, mod);
|
|
4692
|
+
return result;
|
|
4693
|
+
};
|
|
4694
|
+
}();
|
|
4695
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4696
|
+
exports.psArgsLookup = exports.psLookup = exports.AGENT_PROCESS = void 0;
|
|
4697
|
+
exports.scriptMarkerIn = scriptMarkerIn;
|
|
4698
|
+
exports.findAgentProcess = findAgentProcess2;
|
|
4699
|
+
exports.findAgentPid = findAgentPid;
|
|
4700
|
+
exports.livePidFields = livePidFields2;
|
|
4701
|
+
var child_process_1 = __require("child_process");
|
|
4702
|
+
var path2 = __importStar(__require("path"));
|
|
4703
|
+
exports.AGENT_PROCESS = {
|
|
4704
|
+
claude_code: {
|
|
4705
|
+
executable: (command) => path2.basename(command) === "claude" || /\/claude\/versions\/[^/]+$/.test(command) || /\/@anthropic-ai\/claude-code\/bin\/claude\.exe$/.test(command),
|
|
4706
|
+
scriptMarkers: ["@anthropic-ai/claude-code"]
|
|
4707
|
+
},
|
|
4708
|
+
codex: {
|
|
4709
|
+
executable: (command) => /^codex(-(aarch64|x86_64)-apple-darwin)?$/.test(path2.basename(command)),
|
|
4710
|
+
args: (args) => !/\s(app-server|mcp-server)(\s|$)/.test(args)
|
|
4711
|
+
},
|
|
4712
|
+
gemini_cli: {
|
|
4713
|
+
executable: () => false,
|
|
4714
|
+
args: (args) => !/\s--(experimental-)?acp(\s|=|$)/.test(args),
|
|
4715
|
+
scriptMarkers: ["@google/gemini-cli"]
|
|
4716
|
+
}
|
|
4717
|
+
};
|
|
4718
|
+
var SCRIPT_RUNTIME = /^(node|bun|deno)$/;
|
|
4719
|
+
function scriptMarkerIn(args, markers) {
|
|
4720
|
+
return markers.find((marker) => args.includes(`/${marker}/`));
|
|
4721
|
+
}
|
|
4722
|
+
var MAX_DEPTH = 6;
|
|
4723
|
+
var PS_TIMEOUT_MS = 100;
|
|
4724
|
+
function ps(columns, pid) {
|
|
4725
|
+
try {
|
|
4726
|
+
const result = (0, child_process_1.spawnSync)("/bin/ps", ["-o", columns, "-p", String(pid)], {
|
|
4727
|
+
encoding: "utf8",
|
|
4728
|
+
timeout: PS_TIMEOUT_MS
|
|
4729
|
+
});
|
|
4730
|
+
if (result.status !== 0 || typeof result.stdout !== "string")
|
|
4731
|
+
return void 0;
|
|
4732
|
+
const line = result.stdout.trim();
|
|
4733
|
+
return line === "" ? void 0 : line;
|
|
4734
|
+
} catch {
|
|
4735
|
+
return void 0;
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
var psLookup = (pid) => {
|
|
4739
|
+
const line = ps("ppid=,comm=", pid);
|
|
4740
|
+
const match = line ? /^(\d+)\s+(.+)$/.exec(line) : null;
|
|
4741
|
+
return match ? { ppid: Number(match[1]), command: match[2] } : void 0;
|
|
4742
|
+
};
|
|
4743
|
+
exports.psLookup = psLookup;
|
|
4744
|
+
var psArgsLookup = (pid) => ps("args=", pid);
|
|
4745
|
+
exports.psArgsLookup = psArgsLookup;
|
|
4746
|
+
function findAgentProcess2(rule, options = {}) {
|
|
4747
|
+
if (!rule)
|
|
4748
|
+
return void 0;
|
|
4749
|
+
if ((options.platform ?? process.platform) !== "darwin")
|
|
4750
|
+
return void 0;
|
|
4751
|
+
const lookup = options.lookup ?? exports.psLookup;
|
|
4752
|
+
const argsLookup = options.argsLookup ?? exports.psArgsLookup;
|
|
4753
|
+
const markers = rule.scriptMarkers ?? [];
|
|
4754
|
+
let pid = options.startPid ?? process.ppid;
|
|
4755
|
+
for (let depth = 0; depth < MAX_DEPTH && pid > 1; depth++) {
|
|
4756
|
+
const info = lookup(pid);
|
|
4757
|
+
if (!info)
|
|
4758
|
+
return void 0;
|
|
4759
|
+
if (pid !== process.pid) {
|
|
4760
|
+
if (rule.executable(info.command)) {
|
|
4761
|
+
return accepts(rule, rule.args ? argsLookup(pid) : "") ? { pid, match: "executable" } : void 0;
|
|
4762
|
+
}
|
|
4763
|
+
if (markers.length > 0 && SCRIPT_RUNTIME.test(path2.basename(info.command))) {
|
|
4764
|
+
const args = argsLookup(pid);
|
|
4765
|
+
const marker = args === void 0 ? void 0 : scriptMarkerIn(args, markers);
|
|
4766
|
+
if (marker !== void 0) {
|
|
4767
|
+
return accepts(rule, args) ? { pid, match: "path", marker } : void 0;
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
}
|
|
4771
|
+
pid = info.ppid;
|
|
4772
|
+
}
|
|
4773
|
+
return void 0;
|
|
4774
|
+
}
|
|
4775
|
+
function accepts(rule, args) {
|
|
4776
|
+
if (!rule.args)
|
|
4777
|
+
return true;
|
|
4778
|
+
return args !== void 0 && rule.args(args);
|
|
4779
|
+
}
|
|
4780
|
+
function findAgentPid(rule, options = {}) {
|
|
4781
|
+
return findAgentProcess2(rule, options)?.pid;
|
|
4782
|
+
}
|
|
4783
|
+
function livePidFields2(match) {
|
|
4784
|
+
if (!match)
|
|
4785
|
+
return {};
|
|
4786
|
+
if (match.match === "executable")
|
|
4787
|
+
return { pid: match.pid };
|
|
4788
|
+
return { pid: match.pid, pidMatch: "path", pidMarker: match.marker };
|
|
4789
|
+
}
|
|
4790
|
+
}
|
|
4791
|
+
});
|
|
4792
|
+
|
|
3682
4793
|
// ../packages/tool-kit/out/index.js
|
|
3683
4794
|
var require_out2 = __commonJS({
|
|
3684
4795
|
"../packages/tool-kit/out/index.js"(exports) {
|
|
3685
4796
|
"use strict";
|
|
3686
4797
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3687
|
-
exports.
|
|
3688
|
-
exports.
|
|
3689
|
-
exports.isRetryableStatus = exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = exports.getPairingStatus = exports.createPairingSession = exports.AscendaApiError = exports.liveBusSocketCandidates = exports.liveBusSocketPath = exports.bucketPromptSize = exports.emitLiveSignal = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = void 0;
|
|
4798
|
+
exports.FREE_TEXT_KEYS = exports.FAMILY_SENTENCES = exports.ALWAYS_SENT = exports.writeHookSettings = exports.runCliAgentSetup = exports.registeredHookSets = exports.isCliAgentManagementCommand = exports.findStaleHookCommands = exports.cliAgentHookBinPath = exports.resolveContextHashes = exports.resolveCliAgentInstallationId = exports.loadCliAgentConfig = exports.deliverHookEvents = exports.MissingInstallationIdError = exports.DEFAULT_API_BASE_URL = exports.resolveEventLogPath = exports.expandUserPath = exports.appendEventLog = exports.EVENT_LOG_ENV_VAR = exports.buildEventPayload = 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;
|
|
4799
|
+
exports.recordWorkContextAlias = exports.recordWorkContext = exports.readBranchName = exports.normalizeBranchName = exports.deriveBranchHashForCwd = exports.deriveBranchHash = exports.deriveWorkContext = exports.hashWithMachineSalt = 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.writeHostCredentials = exports.removeHostCredentials = exports.readMachineCredentials = exports.readHostCredentials = exports.isLocalOnlyHostInstall = exports.credentialsFilePath = exports.renderSetupDisclosure = exports.REFUSALS = void 0;
|
|
4800
|
+
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 = exports.hookSetArgument = exports.describeHookSetChanges = exports.UNVERSIONED_HOOK_SET = exports.HOOK_SET_FLAG = exports.LIVE_BUS_BACKGROUND_TRUST_MS = exports.liveBusSocketCandidates = exports.liveBusSocketPath = exports.bucketPromptSize = exports.emitLiveSignal = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = exports.readForgeFullName = exports.parseForgeFullName = exports.forgeProjectHash = exports.workContextRegistryFilePath = exports.readWorkContextRegistry = void 0;
|
|
3690
4801
|
var commandClassifier_1 = require_commandClassifier();
|
|
3691
4802
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
3692
4803
|
return commandClassifier_1.classifyCommand;
|
|
@@ -3784,6 +4895,9 @@ var require_out2 = __commonJS({
|
|
|
3784
4895
|
Object.defineProperty(exports, "AscendaSemanticEventError", { enumerable: true, get: function() {
|
|
3785
4896
|
return eventSender_1.AscendaSemanticEventError;
|
|
3786
4897
|
} });
|
|
4898
|
+
Object.defineProperty(exports, "TOKEN_RENEW_LEAD_MS", { enumerable: true, get: function() {
|
|
4899
|
+
return eventSender_1.TOKEN_RENEW_LEAD_MS;
|
|
4900
|
+
} });
|
|
3787
4901
|
Object.defineProperty(exports, "buildEventPayload", { enumerable: true, get: function() {
|
|
3788
4902
|
return eventSender_1.buildEventPayload;
|
|
3789
4903
|
} });
|
|
@@ -3829,6 +4943,9 @@ var require_out2 = __commonJS({
|
|
|
3829
4943
|
Object.defineProperty(exports, "isCliAgentManagementCommand", { enumerable: true, get: function() {
|
|
3830
4944
|
return cliAgentSetup_1.isCliAgentManagementCommand;
|
|
3831
4945
|
} });
|
|
4946
|
+
Object.defineProperty(exports, "registeredHookSets", { enumerable: true, get: function() {
|
|
4947
|
+
return cliAgentSetup_1.registeredHookSets;
|
|
4948
|
+
} });
|
|
3832
4949
|
Object.defineProperty(exports, "runCliAgentSetup", { enumerable: true, get: function() {
|
|
3833
4950
|
return cliAgentSetup_1.runCliAgentSetup;
|
|
3834
4951
|
} });
|
|
@@ -3884,6 +5001,9 @@ var require_out2 = __commonJS({
|
|
|
3884
5001
|
return turnState_1.recordTurnStart;
|
|
3885
5002
|
} });
|
|
3886
5003
|
var tokenStore_1 = require_tokenStore();
|
|
5004
|
+
Object.defineProperty(exports, "EVENT_TOKEN_TTL_MS", { enumerable: true, get: function() {
|
|
5005
|
+
return tokenStore_1.EVENT_TOKEN_TTL_MS;
|
|
5006
|
+
} });
|
|
3887
5007
|
Object.defineProperty(exports, "ascendaHome", { enumerable: true, get: function() {
|
|
3888
5008
|
return tokenStore_1.ascendaHome;
|
|
3889
5009
|
} });
|
|
@@ -3896,9 +5016,15 @@ var require_out2 = __commonJS({
|
|
|
3896
5016
|
Object.defineProperty(exports, "persistEventWriteToken", { enumerable: true, get: function() {
|
|
3897
5017
|
return tokenStore_1.persistEventWriteToken;
|
|
3898
5018
|
} });
|
|
5019
|
+
Object.defineProperty(exports, "readTokenExpiry", { enumerable: true, get: function() {
|
|
5020
|
+
return tokenStore_1.readTokenExpiry;
|
|
5021
|
+
} });
|
|
3899
5022
|
Object.defineProperty(exports, "readTokenFile", { enumerable: true, get: function() {
|
|
3900
5023
|
return tokenStore_1.readTokenFile;
|
|
3901
5024
|
} });
|
|
5025
|
+
Object.defineProperty(exports, "tokenExpiryFilePath", { enumerable: true, get: function() {
|
|
5026
|
+
return tokenStore_1.tokenExpiryFilePath;
|
|
5027
|
+
} });
|
|
3902
5028
|
var stateStore_1 = require_stateStore();
|
|
3903
5029
|
Object.defineProperty(exports, "defaultStateFilePath", { enumerable: true, get: function() {
|
|
3904
5030
|
return stateStore_1.defaultStateFilePath;
|
|
@@ -4030,6 +5156,59 @@ var require_out2 = __commonJS({
|
|
|
4030
5156
|
Object.defineProperty(exports, "liveBusSocketCandidates", { enumerable: true, get: function() {
|
|
4031
5157
|
return liveBus_1.liveBusSocketCandidates;
|
|
4032
5158
|
} });
|
|
5159
|
+
Object.defineProperty(exports, "LIVE_BUS_BACKGROUND_TRUST_MS", { enumerable: true, get: function() {
|
|
5160
|
+
return liveBus_1.LIVE_BUS_BACKGROUND_TRUST_MS;
|
|
5161
|
+
} });
|
|
5162
|
+
var hookSet_1 = require_hookSet();
|
|
5163
|
+
Object.defineProperty(exports, "HOOK_SET_FLAG", { enumerable: true, get: function() {
|
|
5164
|
+
return hookSet_1.HOOK_SET_FLAG;
|
|
5165
|
+
} });
|
|
5166
|
+
Object.defineProperty(exports, "UNVERSIONED_HOOK_SET", { enumerable: true, get: function() {
|
|
5167
|
+
return hookSet_1.UNVERSIONED_HOOK_SET;
|
|
5168
|
+
} });
|
|
5169
|
+
Object.defineProperty(exports, "describeHookSetChanges", { enumerable: true, get: function() {
|
|
5170
|
+
return hookSet_1.describeHookSetChanges;
|
|
5171
|
+
} });
|
|
5172
|
+
Object.defineProperty(exports, "hookSetArgument", { enumerable: true, get: function() {
|
|
5173
|
+
return hookSet_1.hookSetArgument;
|
|
5174
|
+
} });
|
|
5175
|
+
Object.defineProperty(exports, "hookSetChanges", { enumerable: true, get: function() {
|
|
5176
|
+
return hookSet_1.hookSetChanges;
|
|
5177
|
+
} });
|
|
5178
|
+
Object.defineProperty(exports, "hookSetOfCommand", { enumerable: true, get: function() {
|
|
5179
|
+
return hookSet_1.hookSetOfCommand;
|
|
5180
|
+
} });
|
|
5181
|
+
Object.defineProperty(exports, "isHookSet", { enumerable: true, get: function() {
|
|
5182
|
+
return hookSet_1.isHookSet;
|
|
5183
|
+
} });
|
|
5184
|
+
Object.defineProperty(exports, "readHookSet", { enumerable: true, get: function() {
|
|
5185
|
+
return hookSet_1.readHookSet;
|
|
5186
|
+
} });
|
|
5187
|
+
Object.defineProperty(exports, "readViaPlugin", { enumerable: true, get: function() {
|
|
5188
|
+
return hookSet_1.readViaPlugin;
|
|
5189
|
+
} });
|
|
5190
|
+
var agentProcess_1 = require_agentProcess();
|
|
5191
|
+
Object.defineProperty(exports, "AGENT_PROCESS", { enumerable: true, get: function() {
|
|
5192
|
+
return agentProcess_1.AGENT_PROCESS;
|
|
5193
|
+
} });
|
|
5194
|
+
Object.defineProperty(exports, "findAgentPid", { enumerable: true, get: function() {
|
|
5195
|
+
return agentProcess_1.findAgentPid;
|
|
5196
|
+
} });
|
|
5197
|
+
Object.defineProperty(exports, "findAgentProcess", { enumerable: true, get: function() {
|
|
5198
|
+
return agentProcess_1.findAgentProcess;
|
|
5199
|
+
} });
|
|
5200
|
+
Object.defineProperty(exports, "livePidFields", { enumerable: true, get: function() {
|
|
5201
|
+
return agentProcess_1.livePidFields;
|
|
5202
|
+
} });
|
|
5203
|
+
Object.defineProperty(exports, "psArgsLookup", { enumerable: true, get: function() {
|
|
5204
|
+
return agentProcess_1.psArgsLookup;
|
|
5205
|
+
} });
|
|
5206
|
+
Object.defineProperty(exports, "psLookup", { enumerable: true, get: function() {
|
|
5207
|
+
return agentProcess_1.psLookup;
|
|
5208
|
+
} });
|
|
5209
|
+
Object.defineProperty(exports, "scriptMarkerIn", { enumerable: true, get: function() {
|
|
5210
|
+
return agentProcess_1.scriptMarkerIn;
|
|
5211
|
+
} });
|
|
4033
5212
|
var http_1 = require_http();
|
|
4034
5213
|
Object.defineProperty(exports, "AscendaApiError", { enumerable: true, get: function() {
|
|
4035
5214
|
return http_1.AscendaApiError;
|
|
@@ -4040,6 +5219,9 @@ var require_out2 = __commonJS({
|
|
|
4040
5219
|
Object.defineProperty(exports, "getPairingStatus", { enumerable: true, get: function() {
|
|
4041
5220
|
return http_1.getPairingStatus;
|
|
4042
5221
|
} });
|
|
5222
|
+
Object.defineProperty(exports, "getStudyJoinStatus", { enumerable: true, get: function() {
|
|
5223
|
+
return http_1.getStudyJoinStatus;
|
|
5224
|
+
} });
|
|
4043
5225
|
Object.defineProperty(exports, "renewToolToken", { enumerable: true, get: function() {
|
|
4044
5226
|
return http_1.renewToolToken;
|
|
4045
5227
|
} });
|
|
@@ -4055,6 +5237,48 @@ var require_out2 = __commonJS({
|
|
|
4055
5237
|
Object.defineProperty(exports, "isRetryableStatus", { enumerable: true, get: function() {
|
|
4056
5238
|
return http_1.isRetryableStatus;
|
|
4057
5239
|
} });
|
|
5240
|
+
Object.defineProperty(exports, "readInitiatives", { enumerable: true, get: function() {
|
|
5241
|
+
return http_1.readInitiatives;
|
|
5242
|
+
} });
|
|
5243
|
+
Object.defineProperty(exports, "readStudyNotices", { enumerable: true, get: function() {
|
|
5244
|
+
return http_1.readStudyNotices;
|
|
5245
|
+
} });
|
|
5246
|
+
Object.defineProperty(exports, "markStudyNoticeShown", { enumerable: true, get: function() {
|
|
5247
|
+
return http_1.markStudyNoticeShown;
|
|
5248
|
+
} });
|
|
5249
|
+
Object.defineProperty(exports, "setStudyObjection", { enumerable: true, get: function() {
|
|
5250
|
+
return http_1.setStudyObjection;
|
|
5251
|
+
} });
|
|
5252
|
+
Object.defineProperty(exports, "startStudyJoin", { enumerable: true, get: function() {
|
|
5253
|
+
return http_1.startStudyJoin;
|
|
5254
|
+
} });
|
|
5255
|
+
var initiatives_1 = require_initiatives();
|
|
5256
|
+
Object.defineProperty(exports, "INITIATIVE_COPY", { enumerable: true, get: function() {
|
|
5257
|
+
return initiatives_1.INITIATIVE_COPY;
|
|
5258
|
+
} });
|
|
5259
|
+
Object.defineProperty(exports, "initiativesStatusLines", { enumerable: true, get: function() {
|
|
5260
|
+
return initiatives_1.initiativesStatusLines;
|
|
5261
|
+
} });
|
|
5262
|
+
Object.defineProperty(exports, "renderInitiatives", { enumerable: true, get: function() {
|
|
5263
|
+
return initiatives_1.renderInitiatives;
|
|
5264
|
+
} });
|
|
5265
|
+
var studyNotices_1 = require_studyNotices();
|
|
5266
|
+
Object.defineProperty(exports, "NOTICED_PURPOSES", { enumerable: true, get: function() {
|
|
5267
|
+
return studyNotices_1.NOTICED_PURPOSES;
|
|
5268
|
+
} });
|
|
5269
|
+
Object.defineProperty(exports, "renderStudyNotices", { enumerable: true, get: function() {
|
|
5270
|
+
return studyNotices_1.renderStudyNotices;
|
|
5271
|
+
} });
|
|
5272
|
+
Object.defineProperty(exports, "runStudyObjection", { enumerable: true, get: function() {
|
|
5273
|
+
return studyNotices_1.runStudyObjection;
|
|
5274
|
+
} });
|
|
5275
|
+
Object.defineProperty(exports, "studyNoticeStatus", { enumerable: true, get: function() {
|
|
5276
|
+
return studyNotices_1.studyNoticeStatus;
|
|
5277
|
+
} });
|
|
5278
|
+
var studyJoin_1 = require_studyJoin();
|
|
5279
|
+
Object.defineProperty(exports, "runStudyJoin", { enumerable: true, get: function() {
|
|
5280
|
+
return studyJoin_1.runStudyJoin;
|
|
5281
|
+
} });
|
|
4058
5282
|
}
|
|
4059
5283
|
});
|
|
4060
5284
|
|
|
@@ -4167,6 +5391,8 @@ function liveSignalFor(hookName, input) {
|
|
|
4167
5391
|
return { event: "compaction" };
|
|
4168
5392
|
case "AfterAgent":
|
|
4169
5393
|
return { event: "stop" };
|
|
5394
|
+
case "Notification":
|
|
5395
|
+
return (0, import_tool_kit2.getString)(input, ["notification_type"]) === "ToolPermission" ? { event: "awaiting" } : void 0;
|
|
4170
5396
|
default:
|
|
4171
5397
|
return void 0;
|
|
4172
5398
|
}
|
|
@@ -4175,7 +5401,8 @@ function liveSignalFor(hookName, input) {
|
|
|
4175
5401
|
// src/setup.ts
|
|
4176
5402
|
import * as os from "os";
|
|
4177
5403
|
import * as path from "path";
|
|
4178
|
-
var HOOK_EVENTS = ["SessionStart", "SessionEnd", "BeforeAgent", "AfterAgent", "BeforeTool", "AfterTool", "PreCompress"];
|
|
5404
|
+
var HOOK_EVENTS = ["SessionStart", "SessionEnd", "BeforeAgent", "AfterAgent", "BeforeTool", "AfterTool", "PreCompress", "Notification"];
|
|
5405
|
+
var HOOK_SET = 2;
|
|
4179
5406
|
var HOOK_TIMEOUT_SECONDS = 5;
|
|
4180
5407
|
var SETUP = {
|
|
4181
5408
|
host: GEMINI_HOST,
|
|
@@ -4184,6 +5411,7 @@ var SETUP = {
|
|
|
4184
5411
|
packageName: "@ascenda-one/gemini-hooks",
|
|
4185
5412
|
binaryName: "ascenda-gemini-hook",
|
|
4186
5413
|
hookEvents: HOOK_EVENTS,
|
|
5414
|
+
hookSet: HOOK_SET,
|
|
4187
5415
|
restartHint: "Restart Gemini CLI to load the hooks.",
|
|
4188
5416
|
// Nothing beyond the shared set: Gemini's hooks expose no posture, no
|
|
4189
5417
|
// model, no git action and no context figure.
|
|
@@ -4230,7 +5458,9 @@ async function main() {
|
|
|
4230
5458
|
async function emitLive(hookName, input, sessionId) {
|
|
4231
5459
|
const body = liveSignalFor(hookName, input);
|
|
4232
5460
|
if (!body) return;
|
|
5461
|
+
const hookSet = (0, import_tool_kit3.readHookSet)(process.argv);
|
|
4233
5462
|
try {
|
|
5463
|
+
const agent = (0, import_tool_kit3.findAgentProcess)(import_tool_kit3.AGENT_PROCESS.gemini_cli);
|
|
4234
5464
|
await (0, import_tool_kit3.emitLiveSignal)({
|
|
4235
5465
|
// This host's own name, not the shared `cli_agent` tool type the cloud
|
|
4236
5466
|
// path files these events under. The app keys one decaying envelope per
|
|
@@ -4245,7 +5475,9 @@ async function emitLive(hookName, input, sessionId) {
|
|
|
4245
5475
|
// this process's parent — still per-session in practice, since the hook
|
|
4246
5476
|
// is spawned from the session process.
|
|
4247
5477
|
session: sessionId ?? `ppid-${process.ppid}`,
|
|
4248
|
-
...
|
|
5478
|
+
...(0, import_tool_kit3.livePidFields)(agent),
|
|
5479
|
+
...body,
|
|
5480
|
+
...hookSet !== void 0 ? { hookSet } : {}
|
|
4249
5481
|
});
|
|
4250
5482
|
} catch {
|
|
4251
5483
|
}
|