@ascenda-one/codex-hooks 0.1.38 → 0.1.39
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 +322 -84
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -922,7 +922,10 @@ var require_out = __commonJS({
|
|
|
922
922
|
importSchema: "transport",
|
|
923
923
|
// The version of the Ascenda collector that sent this event. Names the
|
|
924
924
|
// build, and nothing about the work it observed.
|
|
925
|
-
collectorVersion: "transport"
|
|
925
|
+
collectorVersion: "transport",
|
|
926
|
+
// The operating system the collector runs on, from a closed list. Names
|
|
927
|
+
// the machine's system, and nothing about the work it observed.
|
|
928
|
+
collectorPlatform: "transport"
|
|
926
929
|
};
|
|
927
930
|
exports.EVENT_METADATA_FIELDS = [
|
|
928
931
|
"language",
|
|
@@ -966,7 +969,8 @@ var require_out = __commonJS({
|
|
|
966
969
|
"importKey",
|
|
967
970
|
"extractionId",
|
|
968
971
|
"importSchema",
|
|
969
|
-
"collectorVersion"
|
|
972
|
+
"collectorVersion",
|
|
973
|
+
"collectorPlatform"
|
|
970
974
|
];
|
|
971
975
|
exports.DELIVERY_ENVELOPE_KEYS = ["toolInstallationId", "idempotencyKey"];
|
|
972
976
|
function joinEventPayload(envelope, body) {
|
|
@@ -1170,6 +1174,79 @@ var require_payload = __commonJS({
|
|
|
1170
1174
|
}
|
|
1171
1175
|
});
|
|
1172
1176
|
|
|
1177
|
+
// ../packages/tool-kit/out/collectorPlatform.js
|
|
1178
|
+
var require_collectorPlatform = __commonJS({
|
|
1179
|
+
"../packages/tool-kit/out/collectorPlatform.js"(exports) {
|
|
1180
|
+
"use strict";
|
|
1181
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1182
|
+
if (k2 === void 0) k2 = k;
|
|
1183
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1184
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1185
|
+
desc = { enumerable: true, get: function() {
|
|
1186
|
+
return m[k];
|
|
1187
|
+
} };
|
|
1188
|
+
}
|
|
1189
|
+
Object.defineProperty(o, k2, desc);
|
|
1190
|
+
} : function(o, m, k, k2) {
|
|
1191
|
+
if (k2 === void 0) k2 = k;
|
|
1192
|
+
o[k2] = m[k];
|
|
1193
|
+
});
|
|
1194
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
1195
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1196
|
+
} : function(o, v) {
|
|
1197
|
+
o["default"] = v;
|
|
1198
|
+
});
|
|
1199
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
1200
|
+
var ownKeys = function(o) {
|
|
1201
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
1202
|
+
var ar = [];
|
|
1203
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
1204
|
+
return ar;
|
|
1205
|
+
};
|
|
1206
|
+
return ownKeys(o);
|
|
1207
|
+
};
|
|
1208
|
+
return function(mod) {
|
|
1209
|
+
if (mod && mod.__esModule) return mod;
|
|
1210
|
+
var result = {};
|
|
1211
|
+
if (mod != null) {
|
|
1212
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
1213
|
+
}
|
|
1214
|
+
__setModuleDefault(result, mod);
|
|
1215
|
+
return result;
|
|
1216
|
+
};
|
|
1217
|
+
}();
|
|
1218
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1219
|
+
exports.COLLECTOR_PLATFORM = void 0;
|
|
1220
|
+
exports.detectCollectorPlatform = detectCollectorPlatform;
|
|
1221
|
+
var os2 = __importStar(__require("os"));
|
|
1222
|
+
function detectCollectorPlatform(probe = {}) {
|
|
1223
|
+
const platform = probe.platform ?? process.platform;
|
|
1224
|
+
switch (platform) {
|
|
1225
|
+
case "darwin":
|
|
1226
|
+
case "win32":
|
|
1227
|
+
return platform;
|
|
1228
|
+
case "linux": {
|
|
1229
|
+
const env = probe.env ?? process.env;
|
|
1230
|
+
if (env.WSL_DISTRO_NAME || env.WSL_INTEROP)
|
|
1231
|
+
return "wsl";
|
|
1232
|
+
const release = probe.release ?? safeRelease();
|
|
1233
|
+
return /microsoft/i.test(release) ? "wsl" : "linux";
|
|
1234
|
+
}
|
|
1235
|
+
default:
|
|
1236
|
+
return "other";
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function safeRelease() {
|
|
1240
|
+
try {
|
|
1241
|
+
return os2.release();
|
|
1242
|
+
} catch {
|
|
1243
|
+
return "";
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
exports.COLLECTOR_PLATFORM = detectCollectorPlatform();
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1173
1250
|
// ../packages/tool-kit/out/collectorVersion.js
|
|
1174
1251
|
var require_collectorVersion = __commonJS({
|
|
1175
1252
|
"../packages/tool-kit/out/collectorVersion.js"(exports) {
|
|
@@ -1178,7 +1255,7 @@ var require_collectorVersion = __commonJS({
|
|
|
1178
1255
|
exports.COLLECTOR_VERSION = exports.UNRELEASED_COLLECTOR_VERSION = void 0;
|
|
1179
1256
|
exports.describeCollectorVersion = describeCollectorVersion;
|
|
1180
1257
|
exports.UNRELEASED_COLLECTOR_VERSION = "unreleased";
|
|
1181
|
-
exports.COLLECTOR_VERSION = "0.1.
|
|
1258
|
+
exports.COLLECTOR_VERSION = "0.1.39" ? "0.1.39" : exports.UNRELEASED_COLLECTOR_VERSION;
|
|
1182
1259
|
function describeCollectorVersion(version = exports.COLLECTOR_VERSION) {
|
|
1183
1260
|
return version === exports.UNRELEASED_COLLECTOR_VERSION ? `${version} (built from a checkout, not a release)` : version;
|
|
1184
1261
|
}
|
|
@@ -2306,14 +2383,14 @@ var require_http = __commonJS({
|
|
|
2306
2383
|
}
|
|
2307
2384
|
};
|
|
2308
2385
|
exports.AscendaApiError = AscendaApiError;
|
|
2309
|
-
async function createPairingSession(apiBaseUrl, toolInstallationId, toolType, displayName) {
|
|
2386
|
+
async function createPairingSession(apiBaseUrl, toolInstallationId, toolType, displayName, orgJoinCode) {
|
|
2310
2387
|
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions`, {
|
|
2311
2388
|
method: "POST",
|
|
2312
2389
|
headers: { "Content-Type": "application/json" },
|
|
2313
|
-
body: JSON.stringify({ toolInstallationId, toolType, displayName })
|
|
2390
|
+
body: JSON.stringify({ toolInstallationId, toolType, displayName, ...orgJoinCode ? { orgJoinCode, mode: "report" } : {} })
|
|
2314
2391
|
});
|
|
2315
2392
|
if (!response.ok)
|
|
2316
|
-
throw
|
|
2393
|
+
throw await apiError(response);
|
|
2317
2394
|
return await response.json();
|
|
2318
2395
|
}
|
|
2319
2396
|
async function getPairingStatus(apiBaseUrl, pairingSessionId) {
|
|
@@ -2563,6 +2640,7 @@ var require_eventSender = __commonJS({
|
|
|
2563
2640
|
var tokenStore_1 = require_tokenStore();
|
|
2564
2641
|
var stateStore_1 = require_stateStore();
|
|
2565
2642
|
var payload_1 = require_payload();
|
|
2643
|
+
var collectorPlatform_1 = require_collectorPlatform();
|
|
2566
2644
|
var collectorVersion_1 = require_collectorVersion();
|
|
2567
2645
|
var AscendaSemanticEventError = class extends Error {
|
|
2568
2646
|
constructor(message) {
|
|
@@ -2590,7 +2668,7 @@ var require_eventSender = __commonJS({
|
|
|
2590
2668
|
return (0, tool_contract_1.joinEventPayload)({ toolInstallationId: identity.toolInstallationId, idempotencyKey: (0, payload_1.mintIdempotencyKey)() }, buildEventBody(identity, mapped));
|
|
2591
2669
|
}
|
|
2592
2670
|
function withCollectorVersion(metadata) {
|
|
2593
|
-
return { ...metadata, collectorVersion: collectorVersion_1.COLLECTOR_VERSION };
|
|
2671
|
+
return { ...metadata, collectorVersion: collectorVersion_1.COLLECTOR_VERSION, collectorPlatform: collectorPlatform_1.COLLECTOR_PLATFORM };
|
|
2594
2672
|
}
|
|
2595
2673
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
2596
2674
|
var RETRY_DELAY_MS = 250;
|
|
@@ -3968,62 +4046,6 @@ var require_confirmLinks = __commonJS({
|
|
|
3968
4046
|
}
|
|
3969
4047
|
});
|
|
3970
4048
|
|
|
3971
|
-
// ../packages/tool-kit/out/hookSet.js
|
|
3972
|
-
var require_hookSet = __commonJS({
|
|
3973
|
-
"../packages/tool-kit/out/hookSet.js"(exports) {
|
|
3974
|
-
"use strict";
|
|
3975
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3976
|
-
exports.UNVERSIONED_HOOK_SET = exports.HOOK_SET_FLAG = void 0;
|
|
3977
|
-
exports.hookSetArgument = hookSetArgument;
|
|
3978
|
-
exports.readHookSet = readHookSet;
|
|
3979
|
-
exports.isHookSet = isHookSet;
|
|
3980
|
-
exports.readViaPlugin = readViaPlugin;
|
|
3981
|
-
exports.hookSetOfCommand = hookSetOfCommand;
|
|
3982
|
-
exports.hookSetChanges = hookSetChanges;
|
|
3983
|
-
exports.describeHookSetChanges = describeHookSetChanges;
|
|
3984
|
-
exports.HOOK_SET_FLAG = "--hook-set";
|
|
3985
|
-
exports.UNVERSIONED_HOOK_SET = 1;
|
|
3986
|
-
function hookSetArgument(hookSet) {
|
|
3987
|
-
return hookSet === void 0 ? "" : ` ${exports.HOOK_SET_FLAG} ${hookSet}`;
|
|
3988
|
-
}
|
|
3989
|
-
function readHookSet(argv) {
|
|
3990
|
-
const index = argv.indexOf(exports.HOOK_SET_FLAG);
|
|
3991
|
-
if (index === -1)
|
|
3992
|
-
return void 0;
|
|
3993
|
-
const raw = argv[index + 1];
|
|
3994
|
-
if (raw === void 0 || !/^[1-9]\d*$/.test(raw))
|
|
3995
|
-
return void 0;
|
|
3996
|
-
const value = Number(raw);
|
|
3997
|
-
return isHookSet(value) ? value : void 0;
|
|
3998
|
-
}
|
|
3999
|
-
function isHookSet(value) {
|
|
4000
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
4001
|
-
}
|
|
4002
|
-
function readViaPlugin(env) {
|
|
4003
|
-
return env.CLAUDE_PLUGIN_ROOT ? true : void 0;
|
|
4004
|
-
}
|
|
4005
|
-
function hookSetOfCommand(command) {
|
|
4006
|
-
const match = command.match(/--hook-set\s+(\d+)/);
|
|
4007
|
-
return match ? Number(match[1]) : exports.UNVERSIONED_HOOK_SET;
|
|
4008
|
-
}
|
|
4009
|
-
function hookSetChanges(before, events) {
|
|
4010
|
-
const added = events.filter((event) => !before.has(event));
|
|
4011
|
-
const sets = [...before.values()];
|
|
4012
|
-
return sets.length ? { added, previousSet: Math.min(...sets) } : { added };
|
|
4013
|
-
}
|
|
4014
|
-
function describeHookSetChanges(changes, hookSet) {
|
|
4015
|
-
if (changes.previousSet === void 0)
|
|
4016
|
-
return void 0;
|
|
4017
|
-
const parts = [];
|
|
4018
|
-
if (changes.added.length)
|
|
4019
|
-
parts.push(`added ${changes.added.join(", ")}`);
|
|
4020
|
-
if (changes.previousSet < hookSet)
|
|
4021
|
-
parts.push(`hook set ${changes.previousSet} \u2192 ${hookSet}`);
|
|
4022
|
-
return parts.length ? `upgraded: ${parts.join("; ")}` : void 0;
|
|
4023
|
-
}
|
|
4024
|
-
}
|
|
4025
|
-
});
|
|
4026
|
-
|
|
4027
4049
|
// ../packages/tool-kit/out/studyJoin.js
|
|
4028
4050
|
var require_studyJoin = __commonJS({
|
|
4029
4051
|
"../packages/tool-kit/out/studyJoin.js"(exports) {
|
|
@@ -4070,6 +4092,7 @@ var require_studyJoin = __commonJS({
|
|
|
4070
4092
|
exports.formatWindow = formatWindow;
|
|
4071
4093
|
exports.describeStudyGrant = describeStudyGrant;
|
|
4072
4094
|
exports.describeStudyKind = describeStudyKind;
|
|
4095
|
+
exports.describeRefusal = describeRefusal;
|
|
4073
4096
|
var readline = __importStar(__require("node:readline"));
|
|
4074
4097
|
var confirmLinks_1 = require_confirmLinks();
|
|
4075
4098
|
var http_1 = require_http();
|
|
@@ -4286,6 +4309,182 @@ var require_studyJoin = __commonJS({
|
|
|
4286
4309
|
}
|
|
4287
4310
|
});
|
|
4288
4311
|
|
|
4312
|
+
// ../packages/tool-kit/out/pairingStudyJoin.js
|
|
4313
|
+
var require_pairingStudyJoin = __commonJS({
|
|
4314
|
+
"../packages/tool-kit/out/pairingStudyJoin.js"(exports) {
|
|
4315
|
+
"use strict";
|
|
4316
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4317
|
+
if (k2 === void 0) k2 = k;
|
|
4318
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4319
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4320
|
+
desc = { enumerable: true, get: function() {
|
|
4321
|
+
return m[k];
|
|
4322
|
+
} };
|
|
4323
|
+
}
|
|
4324
|
+
Object.defineProperty(o, k2, desc);
|
|
4325
|
+
} : function(o, m, k, k2) {
|
|
4326
|
+
if (k2 === void 0) k2 = k;
|
|
4327
|
+
o[k2] = m[k];
|
|
4328
|
+
});
|
|
4329
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
4330
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
4331
|
+
} : function(o, v) {
|
|
4332
|
+
o["default"] = v;
|
|
4333
|
+
});
|
|
4334
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
4335
|
+
var ownKeys = function(o) {
|
|
4336
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
4337
|
+
var ar = [];
|
|
4338
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
4339
|
+
return ar;
|
|
4340
|
+
};
|
|
4341
|
+
return ownKeys(o);
|
|
4342
|
+
};
|
|
4343
|
+
return function(mod) {
|
|
4344
|
+
if (mod && mod.__esModule) return mod;
|
|
4345
|
+
var result = {};
|
|
4346
|
+
if (mod != null) {
|
|
4347
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
4348
|
+
}
|
|
4349
|
+
__setModuleDefault(result, mod);
|
|
4350
|
+
return result;
|
|
4351
|
+
};
|
|
4352
|
+
}();
|
|
4353
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4354
|
+
exports.PAIR_JOIN_OUTCOME_FILE_ENV = exports.PAIR_ORG_JOIN_CODE_ENV = void 0;
|
|
4355
|
+
exports.createPairingAttempt = createPairingAttempt;
|
|
4356
|
+
exports.pairingAttemptLines = pairingAttemptLines;
|
|
4357
|
+
exports.settleStudyJoin = settleStudyJoin;
|
|
4358
|
+
exports.writePairingJoinOutcome = writePairingJoinOutcome;
|
|
4359
|
+
exports.pairingJoinOutcome = pairingJoinOutcome;
|
|
4360
|
+
var fs2 = __importStar(__require("node:fs"));
|
|
4361
|
+
var confirmLinks_1 = require_confirmLinks();
|
|
4362
|
+
var studyJoin_1 = require_studyJoin();
|
|
4363
|
+
var http_1 = require_http();
|
|
4364
|
+
exports.PAIR_ORG_JOIN_CODE_ENV = "ASCENDA_PAIR_ORG_JOIN_CODE";
|
|
4365
|
+
exports.PAIR_JOIN_OUTCOME_FILE_ENV = "ASCENDA_PAIR_JOIN_OUTCOME_FILE";
|
|
4366
|
+
var CREATE_REFUSALS = {
|
|
4367
|
+
join_code_not_found: "That code is not a study anyone can join. Check it and try again.",
|
|
4368
|
+
no_live_study: "There's nothing open to join with that code right now.",
|
|
4369
|
+
unknown_mode: "This tool only offers Report mode from the command line."
|
|
4370
|
+
};
|
|
4371
|
+
var JOIN_SETTLE_MS = 6e4;
|
|
4372
|
+
async function createPairingAttempt(apiBaseUrl, toolInstallationId, toolType, displayName, env = process.env) {
|
|
4373
|
+
const orgJoinCode = env[exports.PAIR_ORG_JOIN_CODE_ENV]?.trim();
|
|
4374
|
+
if (!orgJoinCode)
|
|
4375
|
+
return { session: await (0, http_1.createPairingSession)(apiBaseUrl, toolInstallationId, toolType, displayName), carriesJoin: false };
|
|
4376
|
+
let refusal;
|
|
4377
|
+
try {
|
|
4378
|
+
const session = await (0, http_1.createPairingSession)(apiBaseUrl, toolInstallationId, toolType, displayName, orgJoinCode);
|
|
4379
|
+
return { session, carriesJoin: session.studyJoin !== void 0 };
|
|
4380
|
+
} catch (error) {
|
|
4381
|
+
if (!(error instanceof http_1.AscendaApiError) || error.status >= 500)
|
|
4382
|
+
throw error;
|
|
4383
|
+
refusal = error.errorCode ? CREATE_REFUSALS[error.errorCode] : void 0;
|
|
4384
|
+
}
|
|
4385
|
+
return { session: await (0, http_1.createPairingSession)(apiBaseUrl, toolInstallationId, toolType, displayName), carriesJoin: false, refusal };
|
|
4386
|
+
}
|
|
4387
|
+
function pairingAttemptLines(attempt) {
|
|
4388
|
+
const { session } = attempt;
|
|
4389
|
+
const join3 = attempt.carriesJoin ? session.studyJoin : void 0;
|
|
4390
|
+
if (!join3)
|
|
4391
|
+
return (0, confirmLinks_1.pairingConfirmLines)(session.qrUrl, session.code);
|
|
4392
|
+
return [
|
|
4393
|
+
`This also joins ${join3.organisationName} (${(0, studyJoin_1.formatWindow)(join3.windowStartUtc, join3.windowEndUtc)}). The page shows what you'd share before you confirm.`,
|
|
4394
|
+
`Open this link to confirm: ${session.qrUrl}`
|
|
4395
|
+
];
|
|
4396
|
+
}
|
|
4397
|
+
async function settleStudyJoin(apiBaseUrl, pairingSessionId, last, wait = 1e3) {
|
|
4398
|
+
let current = last;
|
|
4399
|
+
const deadline = Date.now() + JOIN_SETTLE_MS;
|
|
4400
|
+
while (current && current.status === "pending" && Date.now() < deadline) {
|
|
4401
|
+
await new Promise((resolve3) => setTimeout(resolve3, wait));
|
|
4402
|
+
let status;
|
|
4403
|
+
try {
|
|
4404
|
+
status = await (0, http_1.getPairingStatus)(apiBaseUrl, pairingSessionId);
|
|
4405
|
+
} catch {
|
|
4406
|
+
continue;
|
|
4407
|
+
}
|
|
4408
|
+
current = status.studyJoin ?? current;
|
|
4409
|
+
}
|
|
4410
|
+
return current;
|
|
4411
|
+
}
|
|
4412
|
+
function writePairingJoinOutcome(outcome, env = process.env) {
|
|
4413
|
+
const file = env[exports.PAIR_JOIN_OUTCOME_FILE_ENV]?.trim();
|
|
4414
|
+
if (!file)
|
|
4415
|
+
return;
|
|
4416
|
+
try {
|
|
4417
|
+
fs2.writeFileSync(file, `${JSON.stringify(outcome)}
|
|
4418
|
+
`, { mode: 384 });
|
|
4419
|
+
} catch {
|
|
4420
|
+
}
|
|
4421
|
+
}
|
|
4422
|
+
function pairingJoinOutcome(attempt, pairing, studyJoin) {
|
|
4423
|
+
if (!attempt)
|
|
4424
|
+
return { join: "none", pairing };
|
|
4425
|
+
if (attempt.refusal)
|
|
4426
|
+
return { join: "refused", pairing, message: attempt.refusal };
|
|
4427
|
+
return { join: attempt.carriesJoin ? "carried" : "not_carried", pairing, studyJoin };
|
|
4428
|
+
}
|
|
4429
|
+
}
|
|
4430
|
+
});
|
|
4431
|
+
|
|
4432
|
+
// ../packages/tool-kit/out/hookSet.js
|
|
4433
|
+
var require_hookSet = __commonJS({
|
|
4434
|
+
"../packages/tool-kit/out/hookSet.js"(exports) {
|
|
4435
|
+
"use strict";
|
|
4436
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4437
|
+
exports.UNVERSIONED_HOOK_SET = exports.HOOK_SET_FLAG = void 0;
|
|
4438
|
+
exports.hookSetArgument = hookSetArgument;
|
|
4439
|
+
exports.readHookSet = readHookSet;
|
|
4440
|
+
exports.isHookSet = isHookSet;
|
|
4441
|
+
exports.readViaPlugin = readViaPlugin;
|
|
4442
|
+
exports.hookSetOfCommand = hookSetOfCommand;
|
|
4443
|
+
exports.hookSetChanges = hookSetChanges;
|
|
4444
|
+
exports.describeHookSetChanges = describeHookSetChanges;
|
|
4445
|
+
exports.HOOK_SET_FLAG = "--hook-set";
|
|
4446
|
+
exports.UNVERSIONED_HOOK_SET = 1;
|
|
4447
|
+
function hookSetArgument(hookSet) {
|
|
4448
|
+
return hookSet === void 0 ? "" : ` ${exports.HOOK_SET_FLAG} ${hookSet}`;
|
|
4449
|
+
}
|
|
4450
|
+
function readHookSet(argv) {
|
|
4451
|
+
const index = argv.indexOf(exports.HOOK_SET_FLAG);
|
|
4452
|
+
if (index === -1)
|
|
4453
|
+
return void 0;
|
|
4454
|
+
const raw = argv[index + 1];
|
|
4455
|
+
if (raw === void 0 || !/^[1-9]\d*$/.test(raw))
|
|
4456
|
+
return void 0;
|
|
4457
|
+
const value = Number(raw);
|
|
4458
|
+
return isHookSet(value) ? value : void 0;
|
|
4459
|
+
}
|
|
4460
|
+
function isHookSet(value) {
|
|
4461
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
4462
|
+
}
|
|
4463
|
+
function readViaPlugin(env) {
|
|
4464
|
+
return env.CLAUDE_PLUGIN_ROOT ? true : void 0;
|
|
4465
|
+
}
|
|
4466
|
+
function hookSetOfCommand(command) {
|
|
4467
|
+
const match = command.match(/--hook-set\s+(\d+)/);
|
|
4468
|
+
return match ? Number(match[1]) : exports.UNVERSIONED_HOOK_SET;
|
|
4469
|
+
}
|
|
4470
|
+
function hookSetChanges(before, events) {
|
|
4471
|
+
const added = events.filter((event) => !before.has(event));
|
|
4472
|
+
const sets = [...before.values()];
|
|
4473
|
+
return sets.length ? { added, previousSet: Math.min(...sets) } : { added };
|
|
4474
|
+
}
|
|
4475
|
+
function describeHookSetChanges(changes, hookSet) {
|
|
4476
|
+
if (changes.previousSet === void 0)
|
|
4477
|
+
return void 0;
|
|
4478
|
+
const parts = [];
|
|
4479
|
+
if (changes.added.length)
|
|
4480
|
+
parts.push(`added ${changes.added.join(", ")}`);
|
|
4481
|
+
if (changes.previousSet < hookSet)
|
|
4482
|
+
parts.push(`hook set ${changes.previousSet} \u2192 ${hookSet}`);
|
|
4483
|
+
return parts.length ? `upgraded: ${parts.join("; ")}` : void 0;
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
});
|
|
4487
|
+
|
|
4289
4488
|
// ../packages/tool-kit/out/initiatives.js
|
|
4290
4489
|
var require_initiatives = __commonJS({
|
|
4291
4490
|
"../packages/tool-kit/out/initiatives.js"(exports) {
|
|
@@ -5638,8 +5837,8 @@ var require_cliAgentSetup = __commonJS({
|
|
|
5638
5837
|
var credentials_1 = require_credentials();
|
|
5639
5838
|
var eventLog_1 = require_eventLog();
|
|
5640
5839
|
var hookAdapter_1 = require_hookAdapter();
|
|
5641
|
-
var confirmLinks_1 = require_confirmLinks();
|
|
5642
5840
|
var http_1 = require_http();
|
|
5841
|
+
var pairingStudyJoin_1 = require_pairingStudyJoin();
|
|
5643
5842
|
var hookSet_1 = require_hookSet();
|
|
5644
5843
|
var initiatives_1 = require_initiatives();
|
|
5645
5844
|
var settingsFile_1 = require_settingsFile();
|
|
@@ -5964,16 +6163,19 @@ ${usage(spec)}`);
|
|
|
5964
6163
|
return { toolInstallationId: existingId ?? `${spec.toolType}:<paired at run time>`, paired: false };
|
|
5965
6164
|
}
|
|
5966
6165
|
const toolInstallationId = existingId ?? `${spec.toolType}:${crypto.randomUUID()}`;
|
|
5967
|
-
let
|
|
6166
|
+
let attempt;
|
|
5968
6167
|
try {
|
|
5969
|
-
|
|
6168
|
+
attempt = await (0, pairingStudyJoin_1.createPairingAttempt)(apiBaseUrl, toolInstallationId, spec.toolType, `${spec.displayName} on ${os2.hostname()}`);
|
|
5970
6169
|
} catch (error) {
|
|
5971
6170
|
console.error(`
|
|
5972
6171
|
Could not reach ${apiBaseUrl} to pair: ${error instanceof Error ? error.message : String(error)}`);
|
|
5973
6172
|
console.error("Start the local dev server and use --local, or pass --api-base-url for your backend.");
|
|
5974
6173
|
return void 0;
|
|
5975
6174
|
}
|
|
5976
|
-
|
|
6175
|
+
if (attempt.refusal)
|
|
6176
|
+
console.log(`
|
|
6177
|
+
${attempt.refusal} Pairing without the study.`);
|
|
6178
|
+
const token = await pollForToken(apiBaseUrl, attempt);
|
|
5977
6179
|
if (!token)
|
|
5978
6180
|
return void 0;
|
|
5979
6181
|
(0, tokenStore_1.persistEventWriteToken)((0, tokenStore_1.defaultTokenFilePath)(toolInstallationId), token);
|
|
@@ -5991,28 +6193,32 @@ Could not reach ${apiBaseUrl} to pair: ${error instanceof Error ? error.message
|
|
|
5991
6193
|
}
|
|
5992
6194
|
return "keep";
|
|
5993
6195
|
}
|
|
5994
|
-
async function pollForToken(apiBaseUrl,
|
|
5995
|
-
const
|
|
5996
|
-
|
|
6196
|
+
async function pollForToken(apiBaseUrl, attempt) {
|
|
6197
|
+
const { session } = attempt;
|
|
6198
|
+
const deadline = Math.min(Date.parse(session.expiresAt) || Date.now() + 3e5, Date.now() + 3e5);
|
|
6199
|
+
let studyJoin;
|
|
6200
|
+
console.log("");
|
|
6201
|
+
for (const line of (0, pairingStudyJoin_1.pairingAttemptLines)(attempt))
|
|
6202
|
+
console.log(` ${line}`);
|
|
6203
|
+
console.log(" Waiting...");
|
|
5997
6204
|
while (Date.now() < deadline) {
|
|
5998
|
-
const status = await (0, http_1.getPairingStatus)(apiBaseUrl, pairingSessionId);
|
|
5999
|
-
|
|
6205
|
+
const status = await (0, http_1.getPairingStatus)(apiBaseUrl, session.pairingSessionId);
|
|
6206
|
+
studyJoin = status.studyJoin ?? studyJoin;
|
|
6207
|
+
if (status.status === "paired" && status.eventWriteToken) {
|
|
6208
|
+
studyJoin = await (0, pairingStudyJoin_1.settleStudyJoin)(apiBaseUrl, session.pairingSessionId, studyJoin);
|
|
6209
|
+
(0, pairingStudyJoin_1.writePairingJoinOutcome)((0, pairingStudyJoin_1.pairingJoinOutcome)(attempt, "paired", studyJoin));
|
|
6000
6210
|
return status.eventWriteToken;
|
|
6211
|
+
}
|
|
6001
6212
|
if (status.status === "expired" || status.status === "cancelled") {
|
|
6002
6213
|
console.error(`
|
|
6003
6214
|
Pairing ${status.status}. Run setup again.`);
|
|
6215
|
+
(0, pairingStudyJoin_1.writePairingJoinOutcome)((0, pairingStudyJoin_1.pairingJoinOutcome)(attempt, status.status, studyJoin));
|
|
6004
6216
|
return void 0;
|
|
6005
6217
|
}
|
|
6006
|
-
if (!announced) {
|
|
6007
|
-
console.log("");
|
|
6008
|
-
for (const line of (0, confirmLinks_1.pairingConfirmLines)(qrUrl, code))
|
|
6009
|
-
console.log(` ${line}`);
|
|
6010
|
-
console.log(" Waiting...");
|
|
6011
|
-
announced = true;
|
|
6012
|
-
}
|
|
6013
6218
|
await new Promise((resolve3) => setTimeout(resolve3, 2e3));
|
|
6014
6219
|
}
|
|
6015
6220
|
console.error("\nPairing timed out. Run setup again.");
|
|
6221
|
+
(0, pairingStudyJoin_1.writePairingJoinOutcome)((0, pairingStudyJoin_1.pairingJoinOutcome)(attempt, "gave_up", studyJoin));
|
|
6016
6222
|
return void 0;
|
|
6017
6223
|
}
|
|
6018
6224
|
function installBinary(spec, dryRun) {
|
|
@@ -6739,11 +6945,11 @@ var require_out3 = __commonJS({
|
|
|
6739
6945
|
"../packages/tool-kit/out/index.js"(exports) {
|
|
6740
6946
|
"use strict";
|
|
6741
6947
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6742
|
-
exports.
|
|
6743
|
-
exports.
|
|
6744
|
-
exports.
|
|
6745
|
-
exports.
|
|
6746
|
-
exports.studyJoinConfirmUrl = exports.pairingConfirmUrl = exports.pairingConfirmLines = exports.runStudyJoin = exports.formatWindow = exports.describeStudyGrant = exports.describeStudyKind = exports.studyNoticeStatus = exports.runStudyObjection = exports.renderStudyNotices = exports.NOTICED_PURPOSES = exports.renderInitiatives = exports.initiativesStatusLines = exports.INITIATIVE_COPY = exports.startStudyJoin = exports.setStudyObjection = exports.markStudyNoticeShown = void 0;
|
|
6948
|
+
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.startBackgroundFlush = exports.runOutboxFlush = exports.hookDeliveryInline = exports.flushLockPath = exports.OUTBOX_FLUSH_COMMAND = exports.HOOK_DELIVERY_ENV_VAR = exports.FLUSH_LOCK_FRESH_MS = exports.describeCollectorVersion = exports.UNRELEASED_COLLECTOR_VERSION = exports.COLLECTOR_VERSION = exports.detectCollectorPlatform = exports.COLLECTOR_PLATFORM = 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.shellCommandFacts = exports.invitesDebrief = exports.classifyMcpWorkMilestone = exports.classifyWorkMilestone = exports.isReworkGitAction = exports.classifyGitAction = exports.isVerificationCommand = exports.classifyCommand = void 0;
|
|
6949
|
+
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.readTurnPromptId = exports.consumeTurnDurationMs = exports.writeTopLevelCredentials = exports.writeMachineCredentials = exports.writeRepoKeysSetting = 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.trustProblemLines = exports.runCliAgentSetup = exports.registeredHookSets = exports.ourHookPositions = exports.isCliAgentManagementCommand = exports.findStaleHookCommands = exports.cliAgentHookBinPath = exports.resolveContextHashes = exports.resolveCliAgentInstallationId = exports.withPromptId = exports.withForgeKeys = exports.loadCliAgentConfig = exports.flushHookOutbox = exports.deliverHookEvents = exports.MissingInstallationIdError = exports.DEFAULT_API_BASE_URL = exports.resolveEventLogPath = exports.resolveEventLog = exports.parseEventLogFlag = void 0;
|
|
6950
|
+
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.repoKeysEnabled = exports.deriveForgeKeysForCwd = exports.REPO_KEYS_ENV_VAR = exports.recordForgeProjectAlias = exports.forgeFullNameFromConfig = exports.readForgeFullName = exports.parseForgeFullName = exports.forgeBranchKey = exports.forgeRepoKey = exports.forgeProjectHash = exports.workContextRegistryFilePath = exports.readWorkContextRegistry = 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 = void 0;
|
|
6951
|
+
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.liveSignalDoctorLines = exports.doctorRow = exports.DOCTOR_VALUE_COLUMN = exports.pluginBundlePaths = exports.installPluginBundle = exports.describePluginBundleOutcome = exports.replaceSettingsFile = exports.writeAtomically = exports.tidyHomePath = exports.stampLastHook = exports.resolveHookNode = exports.removeHookRunner = exports.readLastHook = exports.lastHookPath = exports.isDowngrade = exports.installHookRunner = exports.hookRunnerPaths = exports.hookRunnerCommand = exports.hookLauncherScript = exports.describeAge = exports.terminalStyle = exports.colourEnabled = exports.SAVER_REPLAY_WINDOW_MS = exports.saverSupportDir = exports.saverStatusDir = void 0;
|
|
6952
|
+
exports.writePairingJoinOutcome = exports.settleStudyJoin = exports.pairingJoinOutcome = exports.pairingAttemptLines = exports.createPairingAttempt = exports.PAIR_ORG_JOIN_CODE_ENV = exports.PAIR_JOIN_OUTCOME_FILE_ENV = exports.studyJoinConfirmUrl = exports.pairingConfirmUrl = exports.pairingConfirmLines = exports.runStudyJoin = exports.formatWindow = exports.describeStudyGrant = exports.describeStudyKind = exports.describeStudyJoinRefusal = 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 = void 0;
|
|
6747
6953
|
var commandClassifier_1 = require_commandClassifier();
|
|
6748
6954
|
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
6749
6955
|
return commandClassifier_1.classifyCommand;
|
|
@@ -6831,6 +7037,13 @@ var require_out3 = __commonJS({
|
|
|
6831
7037
|
Object.defineProperty(exports, "mintIdempotencyKey", { enumerable: true, get: function() {
|
|
6832
7038
|
return payload_1.mintIdempotencyKey;
|
|
6833
7039
|
} });
|
|
7040
|
+
var collectorPlatform_1 = require_collectorPlatform();
|
|
7041
|
+
Object.defineProperty(exports, "COLLECTOR_PLATFORM", { enumerable: true, get: function() {
|
|
7042
|
+
return collectorPlatform_1.COLLECTOR_PLATFORM;
|
|
7043
|
+
} });
|
|
7044
|
+
Object.defineProperty(exports, "detectCollectorPlatform", { enumerable: true, get: function() {
|
|
7045
|
+
return collectorPlatform_1.detectCollectorPlatform;
|
|
7046
|
+
} });
|
|
6834
7047
|
var collectorVersion_1 = require_collectorVersion();
|
|
6835
7048
|
Object.defineProperty(exports, "COLLECTOR_VERSION", { enumerable: true, get: function() {
|
|
6836
7049
|
return collectorVersion_1.COLLECTOR_VERSION;
|
|
@@ -7415,6 +7628,9 @@ var require_out3 = __commonJS({
|
|
|
7415
7628
|
return studyNotices_1.studyNoticeStatus;
|
|
7416
7629
|
} });
|
|
7417
7630
|
var studyJoin_1 = require_studyJoin();
|
|
7631
|
+
Object.defineProperty(exports, "describeStudyJoinRefusal", { enumerable: true, get: function() {
|
|
7632
|
+
return studyJoin_1.describeRefusal;
|
|
7633
|
+
} });
|
|
7418
7634
|
Object.defineProperty(exports, "describeStudyKind", { enumerable: true, get: function() {
|
|
7419
7635
|
return studyJoin_1.describeStudyKind;
|
|
7420
7636
|
} });
|
|
@@ -7437,6 +7653,28 @@ var require_out3 = __commonJS({
|
|
|
7437
7653
|
Object.defineProperty(exports, "studyJoinConfirmUrl", { enumerable: true, get: function() {
|
|
7438
7654
|
return confirmLinks_1.studyJoinConfirmUrl;
|
|
7439
7655
|
} });
|
|
7656
|
+
var pairingStudyJoin_1 = require_pairingStudyJoin();
|
|
7657
|
+
Object.defineProperty(exports, "PAIR_JOIN_OUTCOME_FILE_ENV", { enumerable: true, get: function() {
|
|
7658
|
+
return pairingStudyJoin_1.PAIR_JOIN_OUTCOME_FILE_ENV;
|
|
7659
|
+
} });
|
|
7660
|
+
Object.defineProperty(exports, "PAIR_ORG_JOIN_CODE_ENV", { enumerable: true, get: function() {
|
|
7661
|
+
return pairingStudyJoin_1.PAIR_ORG_JOIN_CODE_ENV;
|
|
7662
|
+
} });
|
|
7663
|
+
Object.defineProperty(exports, "createPairingAttempt", { enumerable: true, get: function() {
|
|
7664
|
+
return pairingStudyJoin_1.createPairingAttempt;
|
|
7665
|
+
} });
|
|
7666
|
+
Object.defineProperty(exports, "pairingAttemptLines", { enumerable: true, get: function() {
|
|
7667
|
+
return pairingStudyJoin_1.pairingAttemptLines;
|
|
7668
|
+
} });
|
|
7669
|
+
Object.defineProperty(exports, "pairingJoinOutcome", { enumerable: true, get: function() {
|
|
7670
|
+
return pairingStudyJoin_1.pairingJoinOutcome;
|
|
7671
|
+
} });
|
|
7672
|
+
Object.defineProperty(exports, "settleStudyJoin", { enumerable: true, get: function() {
|
|
7673
|
+
return pairingStudyJoin_1.settleStudyJoin;
|
|
7674
|
+
} });
|
|
7675
|
+
Object.defineProperty(exports, "writePairingJoinOutcome", { enumerable: true, get: function() {
|
|
7676
|
+
return pairingStudyJoin_1.writePairingJoinOutcome;
|
|
7677
|
+
} });
|
|
7440
7678
|
}
|
|
7441
7679
|
});
|
|
7442
7680
|
|
package/package.json
CHANGED