@ascenda-one/codex-hooks 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +97 -0
- package/dist/cli.js +1045 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js +39 -0
- package/dist/config.js.map +1 -0
- package/dist/mapCodexEvent.js +86 -0
- package/dist/mapCodexEvent.js.map +1 -0
- package/dist/turnState.js +41 -0
- package/dist/turnState.js.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/examples/hooks.json +11 -0
- package/examples/sample-post-tool-use-bash.json +9 -0
- package/package.json +33 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1045 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
16
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
34
|
+
|
|
35
|
+
// ../packages/tool-kit/out/commandClassifier.js
|
|
36
|
+
var require_commandClassifier = __commonJS({
|
|
37
|
+
"../packages/tool-kit/out/commandClassifier.js"(exports) {
|
|
38
|
+
"use strict";
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.classifyCommand = classifyCommand2;
|
|
41
|
+
exports.isVerificationCommand = isVerificationCommand2;
|
|
42
|
+
function classifyCommand2(command) {
|
|
43
|
+
if (!command)
|
|
44
|
+
return "unknown";
|
|
45
|
+
const value = command.toLowerCase().trim();
|
|
46
|
+
if (/\b(test|jest|vitest|mocha|pytest|rspec|go test|cargo test|dotnet test|xcodebuild test)\b/.test(value) || /\bnpm\s+(run\s+)?test\b/.test(value) || /\byarn\s+test\b/.test(value) || /\bpnpm\s+(run\s+)?test\b/.test(value))
|
|
47
|
+
return "test";
|
|
48
|
+
if (/\b(lint|eslint|ruff|flake8|pylint|rubocop)\b/.test(value) || /\bnpm\s+(run\s+)?lint\b/.test(value))
|
|
49
|
+
return "lint";
|
|
50
|
+
if (/\b(tsc|typecheck|mypy|pyright|sorbet|flow)\b/.test(value) || /\bnpm\s+(run\s+)?typecheck\b/.test(value))
|
|
51
|
+
return "typecheck";
|
|
52
|
+
if (/\b(build|webpack|vite build|next build|turbo build|cargo build|go build|dotnet build|xcodebuild)\b/.test(value) || /\bnpm\s+(run\s+)?build\b/.test(value))
|
|
53
|
+
return "build";
|
|
54
|
+
if (/\b(git)\b/.test(value))
|
|
55
|
+
return "git";
|
|
56
|
+
if (/\b(npm install|yarn install|pnpm install|bun install|pip install|poetry install|bundle install)\b/.test(value))
|
|
57
|
+
return "install";
|
|
58
|
+
if (/\b(npm start|npm run dev|yarn dev|pnpm dev|next dev|vite|node|python|tsx|ts-node)\b/.test(value))
|
|
59
|
+
return "run";
|
|
60
|
+
return "unknown";
|
|
61
|
+
}
|
|
62
|
+
function isVerificationCommand2(commandClass) {
|
|
63
|
+
return commandClass === "test" || commandClass === "lint" || commandClass === "typecheck" || commandClass === "build";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// ../packages/tool-kit/out/gitActionClassifier.js
|
|
69
|
+
var require_gitActionClassifier = __commonJS({
|
|
70
|
+
"../packages/tool-kit/out/gitActionClassifier.js"(exports) {
|
|
71
|
+
"use strict";
|
|
72
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
|
+
exports.classifyGitAction = classifyGitAction;
|
|
74
|
+
exports.isReworkGitAction = isReworkGitAction;
|
|
75
|
+
function classifyGitAction(command) {
|
|
76
|
+
if (!command)
|
|
77
|
+
return void 0;
|
|
78
|
+
const value = command.toLowerCase().trim();
|
|
79
|
+
if (!/\bgit\b/.test(value))
|
|
80
|
+
return void 0;
|
|
81
|
+
if (/\bgit\s+commit\b[^\n]*--amend\b/.test(value))
|
|
82
|
+
return "amend";
|
|
83
|
+
if (/\bgit\s+revert\b/.test(value))
|
|
84
|
+
return "revert";
|
|
85
|
+
if (/\bgit\s+reset\b[^\n]*--hard\b/.test(value))
|
|
86
|
+
return "reset_hard";
|
|
87
|
+
if (/\bgit\s+restore\b/.test(value) && !/--staged\b/.test(value))
|
|
88
|
+
return "restore";
|
|
89
|
+
if (/\bgit\s+checkout\b[^\n]*\s--\s/.test(value))
|
|
90
|
+
return "restore";
|
|
91
|
+
if (/\bgit\s+push\b/.test(value))
|
|
92
|
+
return "push";
|
|
93
|
+
if (/\bgit\s+commit\b/.test(value))
|
|
94
|
+
return "commit";
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
function isReworkGitAction(action) {
|
|
98
|
+
return action === "revert" || action === "reset_hard" || action === "restore";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// ../packages/tool-kit/out/workMilestoneClassifier.js
|
|
104
|
+
var require_workMilestoneClassifier = __commonJS({
|
|
105
|
+
"../packages/tool-kit/out/workMilestoneClassifier.js"(exports) {
|
|
106
|
+
"use strict";
|
|
107
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
108
|
+
exports.classifyWorkMilestone = classifyWorkMilestone;
|
|
109
|
+
exports.invitesDebrief = invitesDebrief;
|
|
110
|
+
function classifyWorkMilestone(command) {
|
|
111
|
+
if (!command)
|
|
112
|
+
return void 0;
|
|
113
|
+
const value = command.toLowerCase().trim();
|
|
114
|
+
if (!/\bgh\b/.test(value))
|
|
115
|
+
return void 0;
|
|
116
|
+
if (/\bgh\s+pr\s+merge\b/.test(value))
|
|
117
|
+
return "pr_merged";
|
|
118
|
+
if (/\bgh\s+issue\s+close\b/.test(value))
|
|
119
|
+
return "issue_closed";
|
|
120
|
+
if (/\bgh\s+pr\s+create\b/.test(value))
|
|
121
|
+
return "pr_opened";
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
124
|
+
function invitesDebrief(kind) {
|
|
125
|
+
return kind === "pr_merged" || kind === "issue_closed";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// ../packages/tool-kit/out/buckets.js
|
|
131
|
+
var require_buckets = __commonJS({
|
|
132
|
+
"../packages/tool-kit/out/buckets.js"(exports) {
|
|
133
|
+
"use strict";
|
|
134
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
135
|
+
exports.bucketLinesChanged = bucketLinesChanged;
|
|
136
|
+
exports.bucketDurationMs = bucketDurationMs2;
|
|
137
|
+
function bucketLinesChanged(count) {
|
|
138
|
+
if (count <= 0)
|
|
139
|
+
return "0";
|
|
140
|
+
if (count <= 10)
|
|
141
|
+
return "1-10";
|
|
142
|
+
if (count <= 50)
|
|
143
|
+
return "10-50";
|
|
144
|
+
if (count <= 200)
|
|
145
|
+
return "50-200";
|
|
146
|
+
return "200+";
|
|
147
|
+
}
|
|
148
|
+
function bucketDurationMs2(durationMs) {
|
|
149
|
+
if (typeof durationMs !== "number" || !Number.isFinite(durationMs) || durationMs < 0)
|
|
150
|
+
return void 0;
|
|
151
|
+
const minutes = durationMs / 6e4;
|
|
152
|
+
if (minutes <= 1)
|
|
153
|
+
return "0-1m";
|
|
154
|
+
if (minutes <= 5)
|
|
155
|
+
return "1-5m";
|
|
156
|
+
if (minutes <= 10)
|
|
157
|
+
return "5-10m";
|
|
158
|
+
if (minutes <= 30)
|
|
159
|
+
return "10-30m";
|
|
160
|
+
if (minutes <= 60)
|
|
161
|
+
return "30-60m";
|
|
162
|
+
return "60m+";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// ../packages/tool-kit/out/afterHours.js
|
|
168
|
+
var require_afterHours = __commonJS({
|
|
169
|
+
"../packages/tool-kit/out/afterHours.js"(exports) {
|
|
170
|
+
"use strict";
|
|
171
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
172
|
+
exports.isAfterHours = isAfterHours;
|
|
173
|
+
function isAfterHours(now = /* @__PURE__ */ new Date(), start = "19:00", end = "07:00") {
|
|
174
|
+
const currentMinutes = now.getHours() * 60 + now.getMinutes();
|
|
175
|
+
const startMinutes = parseTimeToMinutes(start, 19 * 60);
|
|
176
|
+
const endMinutes = parseTimeToMinutes(end, 7 * 60);
|
|
177
|
+
if (startMinutes === endMinutes)
|
|
178
|
+
return false;
|
|
179
|
+
if (startMinutes < endMinutes)
|
|
180
|
+
return currentMinutes >= startMinutes && currentMinutes < endMinutes;
|
|
181
|
+
return currentMinutes >= startMinutes || currentMinutes < endMinutes;
|
|
182
|
+
}
|
|
183
|
+
function parseTimeToMinutes(value, fallback) {
|
|
184
|
+
const match = /^(\d{1,2}):(\d{2})$/.exec(value.trim());
|
|
185
|
+
if (!match)
|
|
186
|
+
return fallback;
|
|
187
|
+
const hours = Number(match[1]);
|
|
188
|
+
const minutes = Number(match[2]);
|
|
189
|
+
if (Number.isNaN(hours) || Number.isNaN(minutes))
|
|
190
|
+
return fallback;
|
|
191
|
+
return Math.max(0, Math.min(23, hours)) * 60 + Math.max(0, Math.min(59, minutes));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// ../packages/tool-kit/out/payload.js
|
|
197
|
+
var require_payload = __commonJS({
|
|
198
|
+
"../packages/tool-kit/out/payload.js"(exports) {
|
|
199
|
+
"use strict";
|
|
200
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
201
|
+
exports.getString = getString2;
|
|
202
|
+
exports.getNumber = getNumber;
|
|
203
|
+
exports.getNested = getNested;
|
|
204
|
+
exports.getNestedString = getNestedString2;
|
|
205
|
+
exports.getNestedNumber = getNestedNumber;
|
|
206
|
+
exports.inferOutcome = inferOutcome2;
|
|
207
|
+
exports.looksLikeCorrection = looksLikeCorrection2;
|
|
208
|
+
function getString2(input, keys) {
|
|
209
|
+
for (const key of keys) {
|
|
210
|
+
const value = input[key];
|
|
211
|
+
if (typeof value === "string" && value.trim())
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
return void 0;
|
|
215
|
+
}
|
|
216
|
+
function getNumber(input, keys) {
|
|
217
|
+
for (const key of keys) {
|
|
218
|
+
const value = input[key];
|
|
219
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
return void 0;
|
|
223
|
+
}
|
|
224
|
+
function getNested(input, path2) {
|
|
225
|
+
let current = input;
|
|
226
|
+
for (const segment of path2) {
|
|
227
|
+
if (!current || typeof current !== "object")
|
|
228
|
+
return void 0;
|
|
229
|
+
current = current[segment];
|
|
230
|
+
}
|
|
231
|
+
return current;
|
|
232
|
+
}
|
|
233
|
+
function getNestedString2(input, paths) {
|
|
234
|
+
for (const path2 of paths) {
|
|
235
|
+
const value = getNested(input, path2);
|
|
236
|
+
if (typeof value === "string" && value.trim())
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
241
|
+
function getNestedNumber(input, paths) {
|
|
242
|
+
for (const path2 of paths) {
|
|
243
|
+
const value = getNested(input, path2);
|
|
244
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
return void 0;
|
|
248
|
+
}
|
|
249
|
+
function inferOutcome2(input) {
|
|
250
|
+
const exitCode = getNumber(input, ["exitCode", "exit_code", "status"]) ?? getNestedNumber(input, [["tool_response", "exitCode"], ["tool_response", "exit_code"], ["result", "exitCode"], ["result", "exit_code"]]);
|
|
251
|
+
if (typeof exitCode === "number")
|
|
252
|
+
return exitCode === 0 ? "success" : "failure";
|
|
253
|
+
const error = getString2(input, ["error", "errorMessage"]) ?? getNestedString2(input, [["tool_response", "error"], ["result", "error"]]);
|
|
254
|
+
if (error)
|
|
255
|
+
return "failure";
|
|
256
|
+
return "unknown";
|
|
257
|
+
}
|
|
258
|
+
function looksLikeCorrection2(text) {
|
|
259
|
+
if (!text)
|
|
260
|
+
return false;
|
|
261
|
+
return /\b(wrong|incorrect|try again|fix|not what i asked|that's not|that is not|redo|regenerate|you missed|doesn't work|does not work)\b/i.test(text);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// ../packages/tool-contract/out/index.js
|
|
267
|
+
var require_out = __commonJS({
|
|
268
|
+
"../packages/tool-contract/out/index.js"(exports) {
|
|
269
|
+
"use strict";
|
|
270
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
271
|
+
exports.ASCENDA_SEMANTIC_PROVENANCE = exports.ASCENDA_COLLABORATION_CONSENT_SCOPE = exports.ASCENDA_SEMANTIC_CONSENT_SCOPE = exports.ASCENDA_PROVENANCE = exports.ASCENDA_CONSENT_SCOPE = exports.EVENT_WORKLOAD_CATEGORY = exports.COLLABORATION_EVENT_TYPES = exports.SEMANTIC_WORK_SIGNAL_EVENT_TYPES = void 0;
|
|
272
|
+
exports.SEMANTIC_WORK_SIGNAL_EVENT_TYPES = [
|
|
273
|
+
"approach_churn_detected",
|
|
274
|
+
"goal_drift_detected",
|
|
275
|
+
"progress_stalled",
|
|
276
|
+
"progress_recovered",
|
|
277
|
+
"session_intention_declared",
|
|
278
|
+
"scope_change_declared"
|
|
279
|
+
];
|
|
280
|
+
exports.COLLABORATION_EVENT_TYPES = [
|
|
281
|
+
"review_requested_of_me",
|
|
282
|
+
"review_given",
|
|
283
|
+
"pull_request_opened"
|
|
284
|
+
];
|
|
285
|
+
exports.EVENT_WORKLOAD_CATEGORY = {
|
|
286
|
+
create_focus_session: "creation",
|
|
287
|
+
ai_prompt_submitted: "creation",
|
|
288
|
+
ai_generation_completed: "creation",
|
|
289
|
+
ai_file_write: "creation",
|
|
290
|
+
ai_file_edit: "creation",
|
|
291
|
+
editor_verification_activity: "verification",
|
|
292
|
+
compile_diagnostic: "verification",
|
|
293
|
+
editor_correction_activity: "supervision",
|
|
294
|
+
ai_correction_prompt: "supervision",
|
|
295
|
+
supervis_meeting_load: "supervision",
|
|
296
|
+
ai_tool_call_started: "supervision",
|
|
297
|
+
ai_tool_call_completed: "supervision",
|
|
298
|
+
ai_tool_call_failed: "supervision",
|
|
299
|
+
// Collaboration (the report's §4.2 collaboration family). Both review
|
|
300
|
+
// events are supervision: being asked to check work, and checking it, are
|
|
301
|
+
// the load the report's "verification overload" concern is about — the one
|
|
302
|
+
// that concentrates on senior engineers as a team adopts AI. Opening a pull
|
|
303
|
+
// request is creation: it is the point your own work leaves your hands.
|
|
304
|
+
review_requested_of_me: "supervision",
|
|
305
|
+
review_given: "supervision",
|
|
306
|
+
pull_request_opened: "creation",
|
|
307
|
+
context_pressure_high: "risk",
|
|
308
|
+
agent_loop_long: "risk",
|
|
309
|
+
after_hours_ai_session: "risk",
|
|
310
|
+
compile_error: "risk",
|
|
311
|
+
tool_failure: "risk",
|
|
312
|
+
recovery_offline_period: "neutral",
|
|
313
|
+
context_compression_manual: "neutral",
|
|
314
|
+
context_compression_auto: "neutral",
|
|
315
|
+
editor_activity: "neutral",
|
|
316
|
+
// Semantic (agent-observed) — see SEMANTIC_WORK_SIGNAL_EVENT_TYPES.
|
|
317
|
+
approach_churn_detected: "risk",
|
|
318
|
+
goal_drift_detected: "risk",
|
|
319
|
+
progress_stalled: "risk",
|
|
320
|
+
progress_recovered: "neutral",
|
|
321
|
+
session_intention_declared: "neutral",
|
|
322
|
+
scope_change_declared: "neutral"
|
|
323
|
+
};
|
|
324
|
+
exports.ASCENDA_CONSENT_SCOPE = "ide_telemetry";
|
|
325
|
+
exports.ASCENDA_PROVENANCE = "ai_work_telemetry";
|
|
326
|
+
exports.ASCENDA_SEMANTIC_CONSENT_SCOPE = "semantic_work_signals";
|
|
327
|
+
exports.ASCENDA_COLLABORATION_CONSENT_SCOPE = "workflow_telemetry";
|
|
328
|
+
exports.ASCENDA_SEMANTIC_PROVENANCE = "semantic_work_signals";
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// ../packages/tool-kit/out/http.js
|
|
333
|
+
var require_http = __commonJS({
|
|
334
|
+
"../packages/tool-kit/out/http.js"(exports) {
|
|
335
|
+
"use strict";
|
|
336
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
337
|
+
exports.AscendaApiError = void 0;
|
|
338
|
+
exports.createPairingSession = createPairingSession;
|
|
339
|
+
exports.getPairingStatus = getPairingStatus;
|
|
340
|
+
exports.renewToolToken = renewToolToken;
|
|
341
|
+
exports.postToolEvent = postToolEvent;
|
|
342
|
+
exports.postToolEventsBatch = postToolEventsBatch;
|
|
343
|
+
exports.parseIngestResponse = parseIngestResponse;
|
|
344
|
+
var AscendaApiError = class extends Error {
|
|
345
|
+
status;
|
|
346
|
+
errorCode;
|
|
347
|
+
constructor(status, errorCode, body) {
|
|
348
|
+
super(body ?? `Ascenda API error ${status}`);
|
|
349
|
+
this.status = status;
|
|
350
|
+
this.errorCode = errorCode;
|
|
351
|
+
this.name = "AscendaApiError";
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
exports.AscendaApiError = AscendaApiError;
|
|
355
|
+
async function createPairingSession(apiBaseUrl, toolInstallationId, toolType, displayName) {
|
|
356
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions`, {
|
|
357
|
+
method: "POST",
|
|
358
|
+
headers: { "Content-Type": "application/json" },
|
|
359
|
+
body: JSON.stringify({ toolInstallationId, toolType, displayName })
|
|
360
|
+
});
|
|
361
|
+
if (!response.ok)
|
|
362
|
+
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
363
|
+
return await response.json();
|
|
364
|
+
}
|
|
365
|
+
async function getPairingStatus(apiBaseUrl, pairingSessionId) {
|
|
366
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-pairing-sessions/${encodeURIComponent(pairingSessionId)}/status`, {
|
|
367
|
+
method: "GET",
|
|
368
|
+
headers: { Accept: "application/json" }
|
|
369
|
+
});
|
|
370
|
+
if (!response.ok)
|
|
371
|
+
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
372
|
+
return await response.json();
|
|
373
|
+
}
|
|
374
|
+
async function renewToolToken(apiBaseUrl, eventWriteToken, signal) {
|
|
375
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-events/renew-token`, {
|
|
376
|
+
method: "POST",
|
|
377
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
378
|
+
signal
|
|
379
|
+
});
|
|
380
|
+
if (response.status === 401)
|
|
381
|
+
return null;
|
|
382
|
+
if (!response.ok)
|
|
383
|
+
throw new AscendaApiError(response.status, void 0, await response.text());
|
|
384
|
+
return await response.json();
|
|
385
|
+
}
|
|
386
|
+
async function postToolEvent(apiBaseUrl, eventWriteToken, payload, signal) {
|
|
387
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-events`, {
|
|
388
|
+
method: "POST",
|
|
389
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
390
|
+
body: JSON.stringify(payload),
|
|
391
|
+
signal
|
|
392
|
+
});
|
|
393
|
+
return parseIngestResponse(response);
|
|
394
|
+
}
|
|
395
|
+
async function postToolEventsBatch(apiBaseUrl, eventWriteToken, payloads) {
|
|
396
|
+
const response = await fetch(`${apiBaseUrl}/v1/tool-events/batch`, {
|
|
397
|
+
method: "POST",
|
|
398
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${eventWriteToken}` },
|
|
399
|
+
body: JSON.stringify({ events: payloads })
|
|
400
|
+
});
|
|
401
|
+
return parseIngestResponse(response);
|
|
402
|
+
}
|
|
403
|
+
async function parseIngestResponse(response) {
|
|
404
|
+
if (response.ok)
|
|
405
|
+
return "accepted";
|
|
406
|
+
const body = await response.text();
|
|
407
|
+
let errorCode;
|
|
408
|
+
try {
|
|
409
|
+
errorCode = JSON.parse(body).error;
|
|
410
|
+
} catch {
|
|
411
|
+
errorCode = void 0;
|
|
412
|
+
}
|
|
413
|
+
if (response.status === 401)
|
|
414
|
+
return "auth_failed";
|
|
415
|
+
if (response.status === 403 && errorCode === "consent_missing_or_expired")
|
|
416
|
+
return "consent_missing";
|
|
417
|
+
if (response.status === 400 || response.status === 422)
|
|
418
|
+
return "validation_failed";
|
|
419
|
+
throw new AscendaApiError(response.status, errorCode, body);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// ../packages/tool-kit/out/tokenStore.js
|
|
425
|
+
var require_tokenStore = __commonJS({
|
|
426
|
+
"../packages/tool-kit/out/tokenStore.js"(exports) {
|
|
427
|
+
"use strict";
|
|
428
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
429
|
+
if (k2 === void 0) k2 = k;
|
|
430
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
431
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
432
|
+
desc = { enumerable: true, get: function() {
|
|
433
|
+
return m[k];
|
|
434
|
+
} };
|
|
435
|
+
}
|
|
436
|
+
Object.defineProperty(o, k2, desc);
|
|
437
|
+
} : function(o, m, k, k2) {
|
|
438
|
+
if (k2 === void 0) k2 = k;
|
|
439
|
+
o[k2] = m[k];
|
|
440
|
+
});
|
|
441
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
442
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
443
|
+
} : function(o, v) {
|
|
444
|
+
o["default"] = v;
|
|
445
|
+
});
|
|
446
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
447
|
+
var ownKeys = function(o) {
|
|
448
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
449
|
+
var ar = [];
|
|
450
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
451
|
+
return ar;
|
|
452
|
+
};
|
|
453
|
+
return ownKeys(o);
|
|
454
|
+
};
|
|
455
|
+
return function(mod) {
|
|
456
|
+
if (mod && mod.__esModule) return mod;
|
|
457
|
+
var result = {};
|
|
458
|
+
if (mod != null) {
|
|
459
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
460
|
+
}
|
|
461
|
+
__setModuleDefault(result, mod);
|
|
462
|
+
return result;
|
|
463
|
+
};
|
|
464
|
+
}();
|
|
465
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
466
|
+
exports.defaultTokenFilePath = defaultTokenFilePath2;
|
|
467
|
+
exports.persistEventWriteToken = persistEventWriteToken2;
|
|
468
|
+
exports.readTokenFile = readTokenFile2;
|
|
469
|
+
var fs2 = __importStar(__require("fs"));
|
|
470
|
+
var os2 = __importStar(__require("os"));
|
|
471
|
+
var path2 = __importStar(__require("path"));
|
|
472
|
+
function defaultTokenFilePath2(toolInstallationId) {
|
|
473
|
+
return path2.join(os2.homedir(), ".ascenda", "tokens", sanitizeFilePart(toolInstallationId));
|
|
474
|
+
}
|
|
475
|
+
function persistEventWriteToken2(tokenFilePath, token) {
|
|
476
|
+
const dir = path2.dirname(tokenFilePath);
|
|
477
|
+
fs2.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
478
|
+
fs2.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
479
|
+
if (process.platform !== "win32") {
|
|
480
|
+
fs2.chmodSync(dir, 448);
|
|
481
|
+
fs2.chmodSync(tokenFilePath, 384);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function readTokenFile2(tokenFilePath) {
|
|
485
|
+
try {
|
|
486
|
+
if (!fs2.existsSync(tokenFilePath))
|
|
487
|
+
return void 0;
|
|
488
|
+
const value = fs2.readFileSync(tokenFilePath, "utf8").trim();
|
|
489
|
+
return value || void 0;
|
|
490
|
+
} catch {
|
|
491
|
+
return void 0;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function sanitizeFilePart(value) {
|
|
495
|
+
return value.replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// ../packages/tool-kit/out/eventSender.js
|
|
501
|
+
var require_eventSender = __commonJS({
|
|
502
|
+
"../packages/tool-kit/out/eventSender.js"(exports) {
|
|
503
|
+
"use strict";
|
|
504
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
505
|
+
exports.AscendaEventSender = exports.AscendaSemanticEventError = void 0;
|
|
506
|
+
var tool_contract_1 = require_out();
|
|
507
|
+
var http_1 = require_http();
|
|
508
|
+
var tokenStore_1 = require_tokenStore();
|
|
509
|
+
var AscendaSemanticEventError = class extends Error {
|
|
510
|
+
constructor(message) {
|
|
511
|
+
super(message);
|
|
512
|
+
this.name = "AscendaSemanticEventError";
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
exports.AscendaSemanticEventError = AscendaSemanticEventError;
|
|
516
|
+
var AscendaEventSender2 = class {
|
|
517
|
+
config;
|
|
518
|
+
eventWriteToken;
|
|
519
|
+
constructor(config) {
|
|
520
|
+
this.config = config;
|
|
521
|
+
this.eventWriteToken = config.eventWriteToken;
|
|
522
|
+
}
|
|
523
|
+
async send(mapped) {
|
|
524
|
+
const payload = {
|
|
525
|
+
toolInstallationId: this.config.toolInstallationId,
|
|
526
|
+
source: this.config.source,
|
|
527
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
528
|
+
sessionId: this.config.sessionId ?? void 0,
|
|
529
|
+
workspaceHash: this.config.workspaceHash ?? void 0,
|
|
530
|
+
consentScope: tool_contract_1.ASCENDA_CONSENT_SCOPE,
|
|
531
|
+
provenance: tool_contract_1.ASCENDA_PROVENANCE,
|
|
532
|
+
privacyMode: "metadata_only",
|
|
533
|
+
...mapped,
|
|
534
|
+
metadata: mapped.metadata ?? {}
|
|
535
|
+
};
|
|
536
|
+
return this.post(payload);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Sends one of the six agent-observed types (dark-flow-gap-analysis §2.1).
|
|
540
|
+
* Distinct from {@link send} rather than an option on it, because the
|
|
541
|
+
* differences are non-negotiable, not caller preference:
|
|
542
|
+
*
|
|
543
|
+
* - `consentScope`/`provenance` are always the semantic pair — a lease on
|
|
544
|
+
* `ide_telemetry` alone does not cover these.
|
|
545
|
+
* - `severity` is always `"low"`. The emitter has no baseline to judge
|
|
546
|
+
* against; an elevated reading can only come from the backend's own
|
|
547
|
+
* z-scored evaluation, never from this payload.
|
|
548
|
+
* - `metadata.skillVersion` is required by the type, not merely
|
|
549
|
+
* documented, and checked again here in case a caller building the
|
|
550
|
+
* object dynamically bypasses the type system.
|
|
551
|
+
*
|
|
552
|
+
* Rejects locally (never reaches the network) for an eventType outside
|
|
553
|
+
* {@link SEMANTIC_WORK_SIGNAL_EVENT_TYPES} or a missing/blank
|
|
554
|
+
* `skillVersion` — a malformed semantic event is a bug in the caller, not
|
|
555
|
+
* something the backend should have to catch.
|
|
556
|
+
*/
|
|
557
|
+
async sendSemanticSignal(mapped) {
|
|
558
|
+
if (!tool_contract_1.SEMANTIC_WORK_SIGNAL_EVENT_TYPES.includes(mapped.eventType)) {
|
|
559
|
+
throw new AscendaSemanticEventError(`"${mapped.eventType}" is not a semantic work-signal type. Use send() for a deterministic host event.`);
|
|
560
|
+
}
|
|
561
|
+
if (!mapped.metadata.skillVersion || !mapped.metadata.skillVersion.trim()) {
|
|
562
|
+
throw new AscendaSemanticEventError(`metadata.skillVersion is required for semantic event "${mapped.eventType}".`);
|
|
563
|
+
}
|
|
564
|
+
const payload = {
|
|
565
|
+
toolInstallationId: this.config.toolInstallationId,
|
|
566
|
+
source: this.config.source,
|
|
567
|
+
eventType: mapped.eventType,
|
|
568
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
569
|
+
severity: "low",
|
|
570
|
+
sessionId: this.config.sessionId ?? void 0,
|
|
571
|
+
workspaceHash: this.config.workspaceHash ?? void 0,
|
|
572
|
+
consentScope: tool_contract_1.ASCENDA_SEMANTIC_CONSENT_SCOPE,
|
|
573
|
+
provenance: tool_contract_1.ASCENDA_SEMANTIC_PROVENANCE,
|
|
574
|
+
privacyMode: "metadata_only",
|
|
575
|
+
metadata: mapped.metadata
|
|
576
|
+
};
|
|
577
|
+
return this.post(payload);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Sends a collaboration event under `workflow_telemetry`.
|
|
581
|
+
*
|
|
582
|
+
* A separate method rather than an option on {@link send}, for the same
|
|
583
|
+
* reason {@link sendSemanticSignal} is: the consent scope is a property of
|
|
584
|
+
* what the event *is*, and an options bag would let the wrong one be passed
|
|
585
|
+
* by accident. Rejects locally for anything outside
|
|
586
|
+
* {@link COLLABORATION_EVENT_TYPES}.
|
|
587
|
+
*/
|
|
588
|
+
async sendCollaborationSignal(mapped) {
|
|
589
|
+
if (!tool_contract_1.COLLABORATION_EVENT_TYPES.includes(mapped.eventType)) {
|
|
590
|
+
throw new AscendaSemanticEventError(`"${mapped.eventType}" is not a collaboration event type. Use send() for a deterministic host event.`);
|
|
591
|
+
}
|
|
592
|
+
const payload = {
|
|
593
|
+
toolInstallationId: this.config.toolInstallationId,
|
|
594
|
+
source: this.config.source,
|
|
595
|
+
eventType: mapped.eventType,
|
|
596
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
597
|
+
severity: "low",
|
|
598
|
+
sessionId: this.config.sessionId ?? void 0,
|
|
599
|
+
workspaceHash: this.config.workspaceHash ?? void 0,
|
|
600
|
+
consentScope: tool_contract_1.ASCENDA_COLLABORATION_CONSENT_SCOPE,
|
|
601
|
+
provenance: tool_contract_1.ASCENDA_PROVENANCE,
|
|
602
|
+
privacyMode: "metadata_only",
|
|
603
|
+
metadata: mapped.metadata ?? {}
|
|
604
|
+
};
|
|
605
|
+
return this.post(payload);
|
|
606
|
+
}
|
|
607
|
+
async post(payload) {
|
|
608
|
+
let result = await (0, http_1.postToolEvent)(this.config.apiBaseUrl, this.eventWriteToken, payload, this.signal());
|
|
609
|
+
if (result === "auth_failed") {
|
|
610
|
+
const renewed = await this.renewEventToken();
|
|
611
|
+
if (!renewed)
|
|
612
|
+
return "auth_failed";
|
|
613
|
+
result = await (0, http_1.postToolEvent)(this.config.apiBaseUrl, this.eventWriteToken, payload, this.signal());
|
|
614
|
+
}
|
|
615
|
+
return result;
|
|
616
|
+
}
|
|
617
|
+
async renewEventToken() {
|
|
618
|
+
const renewed = await (0, http_1.renewToolToken)(this.config.apiBaseUrl, this.eventWriteToken, this.signal());
|
|
619
|
+
if (!renewed)
|
|
620
|
+
return false;
|
|
621
|
+
this.eventWriteToken = renewed.eventWriteToken;
|
|
622
|
+
(0, tokenStore_1.persistEventWriteToken)(this.config.tokenFilePath, renewed.eventWriteToken);
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
signal() {
|
|
626
|
+
return this.config.timeoutMs ? AbortSignal.timeout(this.config.timeoutMs) : void 0;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
exports.AscendaEventSender = AscendaEventSender2;
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
// ../packages/tool-kit/out/salt.js
|
|
634
|
+
var require_salt = __commonJS({
|
|
635
|
+
"../packages/tool-kit/out/salt.js"(exports) {
|
|
636
|
+
"use strict";
|
|
637
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
638
|
+
if (k2 === void 0) k2 = k;
|
|
639
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
640
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
641
|
+
desc = { enumerable: true, get: function() {
|
|
642
|
+
return m[k];
|
|
643
|
+
} };
|
|
644
|
+
}
|
|
645
|
+
Object.defineProperty(o, k2, desc);
|
|
646
|
+
} : function(o, m, k, k2) {
|
|
647
|
+
if (k2 === void 0) k2 = k;
|
|
648
|
+
o[k2] = m[k];
|
|
649
|
+
});
|
|
650
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? function(o, v) {
|
|
651
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
652
|
+
} : function(o, v) {
|
|
653
|
+
o["default"] = v;
|
|
654
|
+
});
|
|
655
|
+
var __importStar = exports && exports.__importStar || /* @__PURE__ */ function() {
|
|
656
|
+
var ownKeys = function(o) {
|
|
657
|
+
ownKeys = Object.getOwnPropertyNames || function(o2) {
|
|
658
|
+
var ar = [];
|
|
659
|
+
for (var k in o2) if (Object.prototype.hasOwnProperty.call(o2, k)) ar[ar.length] = k;
|
|
660
|
+
return ar;
|
|
661
|
+
};
|
|
662
|
+
return ownKeys(o);
|
|
663
|
+
};
|
|
664
|
+
return function(mod) {
|
|
665
|
+
if (mod && mod.__esModule) return mod;
|
|
666
|
+
var result = {};
|
|
667
|
+
if (mod != null) {
|
|
668
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
669
|
+
}
|
|
670
|
+
__setModuleDefault(result, mod);
|
|
671
|
+
return result;
|
|
672
|
+
};
|
|
673
|
+
}();
|
|
674
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
675
|
+
exports.machineSaltFilePath = machineSaltFilePath;
|
|
676
|
+
exports.readOrCreateMachineSalt = readOrCreateMachineSalt;
|
|
677
|
+
exports.hashWithMachineSalt = hashWithMachineSalt;
|
|
678
|
+
var crypto = __importStar(__require("crypto"));
|
|
679
|
+
var fs2 = __importStar(__require("fs"));
|
|
680
|
+
var os2 = __importStar(__require("os"));
|
|
681
|
+
var path2 = __importStar(__require("path"));
|
|
682
|
+
function machineSaltFilePath() {
|
|
683
|
+
return path2.join(os2.homedir(), ".ascenda", "salt");
|
|
684
|
+
}
|
|
685
|
+
var cache = /* @__PURE__ */ new Map();
|
|
686
|
+
function readOrCreateMachineSalt(saltFilePath = machineSaltFilePath()) {
|
|
687
|
+
const hit = cache.get(saltFilePath);
|
|
688
|
+
if (hit)
|
|
689
|
+
return hit;
|
|
690
|
+
const dir = path2.dirname(saltFilePath);
|
|
691
|
+
fs2.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
692
|
+
let salt;
|
|
693
|
+
try {
|
|
694
|
+
salt = crypto.randomBytes(32).toString("hex");
|
|
695
|
+
fs2.writeFileSync(saltFilePath, salt, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
696
|
+
} catch (error) {
|
|
697
|
+
if (error.code !== "EEXIST")
|
|
698
|
+
throw error;
|
|
699
|
+
salt = fs2.readFileSync(saltFilePath, "utf8").trim();
|
|
700
|
+
}
|
|
701
|
+
if (process.platform !== "win32") {
|
|
702
|
+
fs2.chmodSync(dir, 448);
|
|
703
|
+
fs2.chmodSync(saltFilePath, 384);
|
|
704
|
+
}
|
|
705
|
+
cache.set(saltFilePath, salt);
|
|
706
|
+
return salt;
|
|
707
|
+
}
|
|
708
|
+
function hashWithMachineSalt(value, saltFilePath) {
|
|
709
|
+
if (!value)
|
|
710
|
+
return null;
|
|
711
|
+
return crypto.createHash("sha256").update(readOrCreateMachineSalt(saltFilePath)).update("\0").update(value).digest("hex").slice(0, 16);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
// ../packages/tool-kit/out/index.js
|
|
717
|
+
var require_out2 = __commonJS({
|
|
718
|
+
"../packages/tool-kit/out/index.js"(exports) {
|
|
719
|
+
"use strict";
|
|
720
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
721
|
+
exports.parseIngestResponse = exports.postToolEventsBatch = exports.postToolEvent = exports.renewToolToken = exports.getPairingStatus = exports.createPairingSession = exports.AscendaApiError = exports.hashWithMachineSalt = exports.readOrCreateMachineSalt = exports.machineSaltFilePath = exports.readTokenFile = exports.persistEventWriteToken = exports.defaultTokenFilePath = exports.AscendaSemanticEventError = exports.AscendaEventSender = exports.looksLikeCorrection = exports.inferOutcome = exports.getNestedNumber = exports.getNestedString = exports.getNested = exports.getNumber = exports.getString = exports.isAfterHours = exports.bucketDurationMs = exports.bucketLinesChanged = exports.invitesDebrief = exports.classifyWorkMilestone = exports.isReworkGitAction = exports.classifyGitAction = exports.isVerificationCommand = exports.classifyCommand = void 0;
|
|
722
|
+
var commandClassifier_1 = require_commandClassifier();
|
|
723
|
+
Object.defineProperty(exports, "classifyCommand", { enumerable: true, get: function() {
|
|
724
|
+
return commandClassifier_1.classifyCommand;
|
|
725
|
+
} });
|
|
726
|
+
Object.defineProperty(exports, "isVerificationCommand", { enumerable: true, get: function() {
|
|
727
|
+
return commandClassifier_1.isVerificationCommand;
|
|
728
|
+
} });
|
|
729
|
+
var gitActionClassifier_1 = require_gitActionClassifier();
|
|
730
|
+
Object.defineProperty(exports, "classifyGitAction", { enumerable: true, get: function() {
|
|
731
|
+
return gitActionClassifier_1.classifyGitAction;
|
|
732
|
+
} });
|
|
733
|
+
Object.defineProperty(exports, "isReworkGitAction", { enumerable: true, get: function() {
|
|
734
|
+
return gitActionClassifier_1.isReworkGitAction;
|
|
735
|
+
} });
|
|
736
|
+
var workMilestoneClassifier_1 = require_workMilestoneClassifier();
|
|
737
|
+
Object.defineProperty(exports, "classifyWorkMilestone", { enumerable: true, get: function() {
|
|
738
|
+
return workMilestoneClassifier_1.classifyWorkMilestone;
|
|
739
|
+
} });
|
|
740
|
+
Object.defineProperty(exports, "invitesDebrief", { enumerable: true, get: function() {
|
|
741
|
+
return workMilestoneClassifier_1.invitesDebrief;
|
|
742
|
+
} });
|
|
743
|
+
var buckets_1 = require_buckets();
|
|
744
|
+
Object.defineProperty(exports, "bucketLinesChanged", { enumerable: true, get: function() {
|
|
745
|
+
return buckets_1.bucketLinesChanged;
|
|
746
|
+
} });
|
|
747
|
+
Object.defineProperty(exports, "bucketDurationMs", { enumerable: true, get: function() {
|
|
748
|
+
return buckets_1.bucketDurationMs;
|
|
749
|
+
} });
|
|
750
|
+
var afterHours_1 = require_afterHours();
|
|
751
|
+
Object.defineProperty(exports, "isAfterHours", { enumerable: true, get: function() {
|
|
752
|
+
return afterHours_1.isAfterHours;
|
|
753
|
+
} });
|
|
754
|
+
var payload_1 = require_payload();
|
|
755
|
+
Object.defineProperty(exports, "getString", { enumerable: true, get: function() {
|
|
756
|
+
return payload_1.getString;
|
|
757
|
+
} });
|
|
758
|
+
Object.defineProperty(exports, "getNumber", { enumerable: true, get: function() {
|
|
759
|
+
return payload_1.getNumber;
|
|
760
|
+
} });
|
|
761
|
+
Object.defineProperty(exports, "getNested", { enumerable: true, get: function() {
|
|
762
|
+
return payload_1.getNested;
|
|
763
|
+
} });
|
|
764
|
+
Object.defineProperty(exports, "getNestedString", { enumerable: true, get: function() {
|
|
765
|
+
return payload_1.getNestedString;
|
|
766
|
+
} });
|
|
767
|
+
Object.defineProperty(exports, "getNestedNumber", { enumerable: true, get: function() {
|
|
768
|
+
return payload_1.getNestedNumber;
|
|
769
|
+
} });
|
|
770
|
+
Object.defineProperty(exports, "inferOutcome", { enumerable: true, get: function() {
|
|
771
|
+
return payload_1.inferOutcome;
|
|
772
|
+
} });
|
|
773
|
+
Object.defineProperty(exports, "looksLikeCorrection", { enumerable: true, get: function() {
|
|
774
|
+
return payload_1.looksLikeCorrection;
|
|
775
|
+
} });
|
|
776
|
+
var eventSender_1 = require_eventSender();
|
|
777
|
+
Object.defineProperty(exports, "AscendaEventSender", { enumerable: true, get: function() {
|
|
778
|
+
return eventSender_1.AscendaEventSender;
|
|
779
|
+
} });
|
|
780
|
+
Object.defineProperty(exports, "AscendaSemanticEventError", { enumerable: true, get: function() {
|
|
781
|
+
return eventSender_1.AscendaSemanticEventError;
|
|
782
|
+
} });
|
|
783
|
+
var tokenStore_1 = require_tokenStore();
|
|
784
|
+
Object.defineProperty(exports, "defaultTokenFilePath", { enumerable: true, get: function() {
|
|
785
|
+
return tokenStore_1.defaultTokenFilePath;
|
|
786
|
+
} });
|
|
787
|
+
Object.defineProperty(exports, "persistEventWriteToken", { enumerable: true, get: function() {
|
|
788
|
+
return tokenStore_1.persistEventWriteToken;
|
|
789
|
+
} });
|
|
790
|
+
Object.defineProperty(exports, "readTokenFile", { enumerable: true, get: function() {
|
|
791
|
+
return tokenStore_1.readTokenFile;
|
|
792
|
+
} });
|
|
793
|
+
var salt_1 = require_salt();
|
|
794
|
+
Object.defineProperty(exports, "machineSaltFilePath", { enumerable: true, get: function() {
|
|
795
|
+
return salt_1.machineSaltFilePath;
|
|
796
|
+
} });
|
|
797
|
+
Object.defineProperty(exports, "readOrCreateMachineSalt", { enumerable: true, get: function() {
|
|
798
|
+
return salt_1.readOrCreateMachineSalt;
|
|
799
|
+
} });
|
|
800
|
+
Object.defineProperty(exports, "hashWithMachineSalt", { enumerable: true, get: function() {
|
|
801
|
+
return salt_1.hashWithMachineSalt;
|
|
802
|
+
} });
|
|
803
|
+
var http_1 = require_http();
|
|
804
|
+
Object.defineProperty(exports, "AscendaApiError", { enumerable: true, get: function() {
|
|
805
|
+
return http_1.AscendaApiError;
|
|
806
|
+
} });
|
|
807
|
+
Object.defineProperty(exports, "createPairingSession", { enumerable: true, get: function() {
|
|
808
|
+
return http_1.createPairingSession;
|
|
809
|
+
} });
|
|
810
|
+
Object.defineProperty(exports, "getPairingStatus", { enumerable: true, get: function() {
|
|
811
|
+
return http_1.getPairingStatus;
|
|
812
|
+
} });
|
|
813
|
+
Object.defineProperty(exports, "renewToolToken", { enumerable: true, get: function() {
|
|
814
|
+
return http_1.renewToolToken;
|
|
815
|
+
} });
|
|
816
|
+
Object.defineProperty(exports, "postToolEvent", { enumerable: true, get: function() {
|
|
817
|
+
return http_1.postToolEvent;
|
|
818
|
+
} });
|
|
819
|
+
Object.defineProperty(exports, "postToolEventsBatch", { enumerable: true, get: function() {
|
|
820
|
+
return http_1.postToolEventsBatch;
|
|
821
|
+
} });
|
|
822
|
+
Object.defineProperty(exports, "parseIngestResponse", { enumerable: true, get: function() {
|
|
823
|
+
return http_1.parseIngestResponse;
|
|
824
|
+
} });
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
// src/cli.ts
|
|
829
|
+
var import_tool_kit3 = __toESM(require_out2(), 1);
|
|
830
|
+
|
|
831
|
+
// src/config.ts
|
|
832
|
+
var import_tool_kit = __toESM(require_out2(), 1);
|
|
833
|
+
|
|
834
|
+
// src/types.ts
|
|
835
|
+
var ASCENDA_TOOL_TYPE = "cli_agent";
|
|
836
|
+
var CODEX_HOST = "codex";
|
|
837
|
+
|
|
838
|
+
// src/config.ts
|
|
839
|
+
function loadConfigFromEnv(sessionIdFromHook) {
|
|
840
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
841
|
+
const toolInstallationIdRaw = process.env.ASCENDA_TOOL_INSTALLATION_ID;
|
|
842
|
+
if (!toolInstallationIdRaw) throw new Error("Missing ASCENDA_TOOL_INSTALLATION_ID");
|
|
843
|
+
const toolInstallationId = normalizeToolInstallationId(toolInstallationIdRaw);
|
|
844
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, import_tool_kit.defaultTokenFilePath)(toolInstallationId);
|
|
845
|
+
const fileToken = (0, import_tool_kit.readTokenFile)(tokenFilePath);
|
|
846
|
+
const eventWriteToken = fileToken ?? process.env.ASCENDA_EVENT_WRITE_TOKEN;
|
|
847
|
+
if (!eventWriteToken) throw new Error("Missing ASCENDA_EVENT_WRITE_TOKEN (or token file)");
|
|
848
|
+
if (!fileToken) (0, import_tool_kit.persistEventWriteToken)(tokenFilePath, eventWriteToken);
|
|
849
|
+
return {
|
|
850
|
+
apiBaseUrl,
|
|
851
|
+
toolInstallationId,
|
|
852
|
+
eventWriteToken,
|
|
853
|
+
tokenFilePath,
|
|
854
|
+
sessionId: process.env.ASCENDA_SESSION_ID ?? sessionIdFromHook ?? null,
|
|
855
|
+
workspaceHash: process.env.ASCENDA_WORKSPACE_HASH ?? null,
|
|
856
|
+
// Codex awaits command hooks; fail fast rather than stall the agent's turn.
|
|
857
|
+
timeoutMs: parsePositiveInt(process.env.ASCENDA_HTTP_TIMEOUT_MS) ?? 3e3
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
function normalizeToolInstallationId(value) {
|
|
861
|
+
const trimmed = value.trim();
|
|
862
|
+
if (trimmed.includes(":")) return trimmed;
|
|
863
|
+
return `${ASCENDA_TOOL_TYPE}:${trimmed}`;
|
|
864
|
+
}
|
|
865
|
+
function parsePositiveInt(value) {
|
|
866
|
+
const n = Number(value);
|
|
867
|
+
return Number.isInteger(n) && n > 0 ? n : void 0;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/mapCodexEvent.ts
|
|
871
|
+
var import_tool_kit2 = __toESM(require_out2(), 1);
|
|
872
|
+
function mapCodexEvent(hookName, input, turnDurationMs) {
|
|
873
|
+
switch (hookName) {
|
|
874
|
+
case "SessionStart":
|
|
875
|
+
return mapSessionStart(input);
|
|
876
|
+
case "UserPromptSubmit":
|
|
877
|
+
return mapUserPromptSubmit(input);
|
|
878
|
+
case "PreToolUse":
|
|
879
|
+
return [{ eventType: "ai_tool_call_started", severity: "low", metadata: withHost({ toolName: sanitiseToolName(getToolName(input)) }) }];
|
|
880
|
+
case "PostToolUse":
|
|
881
|
+
return mapPostToolUse(input);
|
|
882
|
+
case "PreCompact":
|
|
883
|
+
return mapPreCompact(input);
|
|
884
|
+
case "PostCompact":
|
|
885
|
+
return [{ eventType: "context_pressure_high", severity: "medium", metadata: withHost({ trigger: "inferred", reason: "context_limit" }) }];
|
|
886
|
+
case "Stop":
|
|
887
|
+
return mapStop(turnDurationMs);
|
|
888
|
+
// No catalog events for approvals or subagent lifecycle; skip to avoid unclassified noise.
|
|
889
|
+
case "PermissionRequest":
|
|
890
|
+
case "SubagentStart":
|
|
891
|
+
case "SubagentStop":
|
|
892
|
+
return [];
|
|
893
|
+
default:
|
|
894
|
+
return [];
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
function mapSessionStart(input) {
|
|
898
|
+
const source = (0, import_tool_kit2.getString)(input, ["source"]);
|
|
899
|
+
if (source && source !== "startup" && source !== "resume") return [];
|
|
900
|
+
return [{ eventType: "create_focus_session", severity: "low", metadata: withHost({ activity: "session_started" }) }];
|
|
901
|
+
}
|
|
902
|
+
function mapUserPromptSubmit(input) {
|
|
903
|
+
const prompt = (0, import_tool_kit2.getString)(input, ["prompt", "userPrompt", "message"]) ?? (0, import_tool_kit2.getNestedString)(input, [["payload", "prompt"]]);
|
|
904
|
+
const events = [{ eventType: "ai_prompt_submitted", severity: "low", metadata: withHost({ promptClass: "unknown" }) }];
|
|
905
|
+
if ((0, import_tool_kit2.looksLikeCorrection)(prompt)) {
|
|
906
|
+
events.push({ eventType: "ai_correction_prompt", severity: "medium", metadata: withHost({ reason: "repeated_reprompting", trigger: "inferred" }) });
|
|
907
|
+
}
|
|
908
|
+
return events;
|
|
909
|
+
}
|
|
910
|
+
function mapPostToolUse(input) {
|
|
911
|
+
const toolName = getToolName(input);
|
|
912
|
+
const safeToolName = sanitiseToolName(toolName);
|
|
913
|
+
const outcome = (0, import_tool_kit2.inferOutcome)(input);
|
|
914
|
+
const command = (0, import_tool_kit2.getString)(input, ["command"]) ?? (0, import_tool_kit2.getNestedString)(input, [["tool_input", "command"], ["input", "command"]]);
|
|
915
|
+
const commandClass = (0, import_tool_kit2.classifyCommand)(command);
|
|
916
|
+
const lowered = toolName?.toLowerCase();
|
|
917
|
+
const isShell = lowered === "bash" || lowered === "shell" || lowered === "local_shell";
|
|
918
|
+
if (outcome === "failure") {
|
|
919
|
+
if (isShell && (0, import_tool_kit2.isVerificationCommand)(commandClass)) {
|
|
920
|
+
return [{ eventType: "compile_error", severity: "medium", metadata: withHost({ toolName: safeToolName, commandClass, outcome, reason: "test_failure" }) }];
|
|
921
|
+
}
|
|
922
|
+
return [{ eventType: "ai_tool_call_failed", severity: "medium", metadata: withHost({ toolName: safeToolName, commandClass, outcome, reason: "tool_failure" }) }];
|
|
923
|
+
}
|
|
924
|
+
if (lowered === "apply_patch") {
|
|
925
|
+
return [{ eventType: "ai_file_edit", severity: "low", metadata: withHost({ toolName: safeToolName, outcome }) }];
|
|
926
|
+
}
|
|
927
|
+
if (isShell && (0, import_tool_kit2.isVerificationCommand)(commandClass)) {
|
|
928
|
+
return [{ eventType: "editor_verification_activity", severity: "low", metadata: withHost({ toolName: safeToolName, commandClass, outcome, activity: "ai_test_or_build_run" }) }];
|
|
929
|
+
}
|
|
930
|
+
return [{ eventType: "ai_tool_call_completed", severity: "low", metadata: withHost({ toolName: safeToolName, commandClass, outcome }) }];
|
|
931
|
+
}
|
|
932
|
+
function mapPreCompact(input) {
|
|
933
|
+
const trigger = (0, import_tool_kit2.getString)(input, ["trigger", "reason"]);
|
|
934
|
+
const isManual = trigger?.toLowerCase().includes("manual") ?? false;
|
|
935
|
+
return [{ eventType: isManual ? "context_compression_manual" : "context_compression_auto", severity: isManual ? "medium" : "high", metadata: withHost({ trigger: isManual ? "manual" : "auto", reason: "context_limit" }) }];
|
|
936
|
+
}
|
|
937
|
+
function mapStop(turnDurationMs) {
|
|
938
|
+
const durationBucket = (0, import_tool_kit2.bucketDurationMs)(turnDurationMs);
|
|
939
|
+
if (durationBucket === "30-60m" || durationBucket === "60m+") {
|
|
940
|
+
return [{ eventType: "agent_loop_long", severity: durationBucket === "60m+" ? "high" : "medium", metadata: withHost({ durationBucket, reason: "long_session", trigger: "inferred" }) }];
|
|
941
|
+
}
|
|
942
|
+
return [];
|
|
943
|
+
}
|
|
944
|
+
function getToolName(input) {
|
|
945
|
+
return (0, import_tool_kit2.getString)(input, ["tool_name", "toolName", "name"]);
|
|
946
|
+
}
|
|
947
|
+
function sanitiseToolName(toolName) {
|
|
948
|
+
if (!toolName) return "unknown";
|
|
949
|
+
return toolName.replace(/[^a-zA-Z0-9_-]/g, "").slice(0, 40) || "unknown";
|
|
950
|
+
}
|
|
951
|
+
function withHost(metadata) {
|
|
952
|
+
return { host: CODEX_HOST, ...metadata };
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// src/turnState.ts
|
|
956
|
+
import * as fs from "fs";
|
|
957
|
+
import * as os from "os";
|
|
958
|
+
import * as path from "path";
|
|
959
|
+
var STATE_DIR = () => process.env.ASCENDA_STATE_DIR ?? path.join(os.homedir(), ".ascenda", "state");
|
|
960
|
+
function turnFile(sessionId) {
|
|
961
|
+
return path.join(STATE_DIR(), `codex-turn-${sessionId.replace(/[^a-zA-Z0-9._-]/g, "_")}`);
|
|
962
|
+
}
|
|
963
|
+
function recordTurnStart(sessionId, now = Date.now()) {
|
|
964
|
+
if (!sessionId) return;
|
|
965
|
+
try {
|
|
966
|
+
fs.mkdirSync(STATE_DIR(), { recursive: true });
|
|
967
|
+
fs.writeFileSync(turnFile(sessionId), String(now), { encoding: "utf8", mode: 384 });
|
|
968
|
+
} catch {
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
function consumeTurnDurationMs(sessionId, now = Date.now()) {
|
|
972
|
+
if (!sessionId) return void 0;
|
|
973
|
+
const file = turnFile(sessionId);
|
|
974
|
+
try {
|
|
975
|
+
const started = Number(fs.readFileSync(file, "utf8").trim());
|
|
976
|
+
fs.rmSync(file, { force: true });
|
|
977
|
+
if (!Number.isFinite(started) || started <= 0 || started > now) return void 0;
|
|
978
|
+
return now - started;
|
|
979
|
+
} catch {
|
|
980
|
+
return void 0;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// src/cli.ts
|
|
985
|
+
async function main() {
|
|
986
|
+
const hookName = process.argv[2];
|
|
987
|
+
if (!hookName) {
|
|
988
|
+
console.error("Usage: ascenda-codex-hook <CodexHookEventName>");
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const input = await readJsonFromStdin();
|
|
992
|
+
const sessionId = typeof input.session_id === "string" ? input.session_id : void 0;
|
|
993
|
+
let turnDurationMs;
|
|
994
|
+
if (hookName === "UserPromptSubmit") recordTurnStart(sessionId);
|
|
995
|
+
if (hookName === "Stop") turnDurationMs = consumeTurnDurationMs(sessionId);
|
|
996
|
+
const mappedEvents = mapCodexEvent(hookName, input, turnDurationMs);
|
|
997
|
+
if (mappedEvents.length === 0) return;
|
|
998
|
+
const config = loadConfigFromEnv(sessionId);
|
|
999
|
+
const sender = new import_tool_kit3.AscendaEventSender({
|
|
1000
|
+
apiBaseUrl: config.apiBaseUrl,
|
|
1001
|
+
toolInstallationId: config.toolInstallationId,
|
|
1002
|
+
source: "cli_agent",
|
|
1003
|
+
eventWriteToken: config.eventWriteToken,
|
|
1004
|
+
tokenFilePath: config.tokenFilePath,
|
|
1005
|
+
sessionId: config.sessionId,
|
|
1006
|
+
workspaceHash: config.workspaceHash,
|
|
1007
|
+
timeoutMs: config.timeoutMs
|
|
1008
|
+
});
|
|
1009
|
+
for (const event of mappedEvents) {
|
|
1010
|
+
const result = await sender.send(event);
|
|
1011
|
+
if (result === "consent_missing") {
|
|
1012
|
+
emitSystemMessage("Ascenda telemetry paused: renew IDE telemetry consent in the Ascenda app.");
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
if (result === "auth_failed") {
|
|
1016
|
+
emitSystemMessage("Ascenda telemetry paused: connection revoked or expired. Re-pair via an Ascenda IDE extension or pairing-sim.");
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
if (result !== "accepted") {
|
|
1020
|
+
console.error(`Ascenda telemetry rejected: ${result}`);
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
function emitSystemMessage(message) {
|
|
1026
|
+
console.log(JSON.stringify({ continue: true, systemMessage: message, suppressOutput: true }));
|
|
1027
|
+
}
|
|
1028
|
+
async function readJsonFromStdin() {
|
|
1029
|
+
const chunks = [];
|
|
1030
|
+
for await (const chunk of process.stdin) {
|
|
1031
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
1032
|
+
}
|
|
1033
|
+
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
1034
|
+
if (!raw) return {};
|
|
1035
|
+
try {
|
|
1036
|
+
const parsed = JSON.parse(raw);
|
|
1037
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
1038
|
+
return parsed;
|
|
1039
|
+
} catch {
|
|
1040
|
+
return {};
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
main().catch((error) => {
|
|
1044
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
1045
|
+
}).finally(() => process.exit(0));
|