@ascenda-one/claude-code-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 +191 -0
- package/dist/ascendaClient.js +23 -0
- package/dist/ascendaClient.js.map +1 -0
- package/dist/cli.js +1109 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js +35 -0
- package/dist/config.js.map +1 -0
- package/dist/mapClaudeEvent.js +194 -0
- package/dist/mapClaudeEvent.js.map +1 -0
- package/dist/safeExtract.js +2 -0
- package/dist/safeExtract.js.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/examples/sample-post-tool-use-bash-test-failed.json +6 -0
- package/examples/sample-post-tool-use-edit.json +6 -0
- package/examples/sample-pre-compact-auto.json +1 -0
- package/examples/sample-user-prompt-correction.json +1 -0
- package/examples/settings.local.json +12 -0
- package/package.json +34 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1109 @@
|
|
|
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 = classifyGitAction2;
|
|
74
|
+
exports.isReworkGitAction = isReworkGitAction2;
|
|
75
|
+
function classifyGitAction2(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 isReworkGitAction2(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 = classifyWorkMilestone2;
|
|
109
|
+
exports.invitesDebrief = invitesDebrief2;
|
|
110
|
+
function classifyWorkMilestone2(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 invitesDebrief2(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 = bucketLinesChanged2;
|
|
136
|
+
exports.bucketDurationMs = bucketDurationMs2;
|
|
137
|
+
function bucketLinesChanged2(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 = getNumber2;
|
|
203
|
+
exports.getNested = getNested2;
|
|
204
|
+
exports.getNestedString = getNestedString2;
|
|
205
|
+
exports.getNestedNumber = getNestedNumber2;
|
|
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 getNumber2(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 getNested2(input, path) {
|
|
225
|
+
let current = input;
|
|
226
|
+
for (const segment of path) {
|
|
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 path of paths) {
|
|
235
|
+
const value = getNested2(input, path);
|
|
236
|
+
if (typeof value === "string" && value.trim())
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
return void 0;
|
|
240
|
+
}
|
|
241
|
+
function getNestedNumber2(input, paths) {
|
|
242
|
+
for (const path of paths) {
|
|
243
|
+
const value = getNested2(input, path);
|
|
244
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
return void 0;
|
|
248
|
+
}
|
|
249
|
+
function inferOutcome2(input) {
|
|
250
|
+
const exitCode = getNumber2(input, ["exitCode", "exit_code", "status"]) ?? getNestedNumber2(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 AscendaApiError2 = 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 = AscendaApiError2;
|
|
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 AscendaApiError2(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 AscendaApiError2(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 AscendaApiError2(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 AscendaApiError2(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 fs = __importStar(__require("fs"));
|
|
470
|
+
var os = __importStar(__require("os"));
|
|
471
|
+
var path = __importStar(__require("path"));
|
|
472
|
+
function defaultTokenFilePath2(toolInstallationId) {
|
|
473
|
+
return path.join(os.homedir(), ".ascenda", "tokens", sanitizeFilePart(toolInstallationId));
|
|
474
|
+
}
|
|
475
|
+
function persistEventWriteToken2(tokenFilePath, token) {
|
|
476
|
+
const dir = path.dirname(tokenFilePath);
|
|
477
|
+
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
478
|
+
fs.writeFileSync(tokenFilePath, token, { encoding: "utf8", mode: 384 });
|
|
479
|
+
if (process.platform !== "win32") {
|
|
480
|
+
fs.chmodSync(dir, 448);
|
|
481
|
+
fs.chmodSync(tokenFilePath, 384);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function readTokenFile2(tokenFilePath) {
|
|
485
|
+
try {
|
|
486
|
+
if (!fs.existsSync(tokenFilePath))
|
|
487
|
+
return void 0;
|
|
488
|
+
const value = fs.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 fs = __importStar(__require("fs"));
|
|
680
|
+
var os = __importStar(__require("os"));
|
|
681
|
+
var path = __importStar(__require("path"));
|
|
682
|
+
function machineSaltFilePath() {
|
|
683
|
+
return path.join(os.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 = path.dirname(saltFilePath);
|
|
691
|
+
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
692
|
+
let salt;
|
|
693
|
+
try {
|
|
694
|
+
salt = crypto.randomBytes(32).toString("hex");
|
|
695
|
+
fs.writeFileSync(saltFilePath, salt, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
696
|
+
} catch (error) {
|
|
697
|
+
if (error.code !== "EEXIST")
|
|
698
|
+
throw error;
|
|
699
|
+
salt = fs.readFileSync(saltFilePath, "utf8").trim();
|
|
700
|
+
}
|
|
701
|
+
if (process.platform !== "win32") {
|
|
702
|
+
fs.chmodSync(dir, 448);
|
|
703
|
+
fs.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/ascendaClient.ts
|
|
829
|
+
var import_tool_kit = __toESM(require_out2(), 1);
|
|
830
|
+
var import_tool_kit2 = __toESM(require_out2(), 1);
|
|
831
|
+
var AscendaClient = class {
|
|
832
|
+
sender;
|
|
833
|
+
constructor(config) {
|
|
834
|
+
this.sender = new import_tool_kit.AscendaEventSender({
|
|
835
|
+
apiBaseUrl: config.apiBaseUrl,
|
|
836
|
+
toolInstallationId: config.toolInstallationId,
|
|
837
|
+
source: "claude_code",
|
|
838
|
+
eventWriteToken: config.eventWriteToken,
|
|
839
|
+
tokenFilePath: config.tokenFilePath,
|
|
840
|
+
sessionId: config.sessionId,
|
|
841
|
+
workspaceHash: config.workspaceHash
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
async send(mapped) {
|
|
845
|
+
return this.sender.send(mapped);
|
|
846
|
+
}
|
|
847
|
+
async renewEventToken() {
|
|
848
|
+
return this.sender.renewEventToken();
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
// src/config.ts
|
|
853
|
+
var import_tool_kit3 = __toESM(require_out2(), 1);
|
|
854
|
+
|
|
855
|
+
// src/types.ts
|
|
856
|
+
var import_tool_contract = __toESM(require_out(), 1);
|
|
857
|
+
var ASCENDA_TOOL_TYPE = "claude_code";
|
|
858
|
+
|
|
859
|
+
// src/config.ts
|
|
860
|
+
function loadConfigFromEnv() {
|
|
861
|
+
const apiBaseUrl = (process.env.ASCENDA_API_BASE_URL ?? "https://api.ascenda.one").replace(/\/$/, "");
|
|
862
|
+
const toolInstallationIdRaw = process.env.ASCENDA_TOOL_INSTALLATION_ID;
|
|
863
|
+
if (!toolInstallationIdRaw) throw new Error("Missing ASCENDA_TOOL_INSTALLATION_ID");
|
|
864
|
+
const toolInstallationId = normalizeToolInstallationId(toolInstallationIdRaw);
|
|
865
|
+
const tokenFilePath = process.env.ASCENDA_EVENT_WRITE_TOKEN_FILE ?? (0, import_tool_kit3.defaultTokenFilePath)(toolInstallationId);
|
|
866
|
+
const fileToken = (0, import_tool_kit3.readTokenFile)(tokenFilePath);
|
|
867
|
+
const eventWriteToken = fileToken ?? process.env.ASCENDA_EVENT_WRITE_TOKEN;
|
|
868
|
+
if (!eventWriteToken) throw new Error("Missing ASCENDA_EVENT_WRITE_TOKEN (or token file)");
|
|
869
|
+
if (!fileToken) (0, import_tool_kit3.persistEventWriteToken)(tokenFilePath, eventWriteToken);
|
|
870
|
+
return {
|
|
871
|
+
apiBaseUrl,
|
|
872
|
+
toolInstallationId,
|
|
873
|
+
eventWriteToken,
|
|
874
|
+
tokenFilePath,
|
|
875
|
+
sessionId: process.env.ASCENDA_SESSION_ID ?? null,
|
|
876
|
+
workspaceHash: process.env.ASCENDA_WORKSPACE_HASH ?? null
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
function normalizeToolInstallationId(value) {
|
|
880
|
+
const trimmed = value.trim();
|
|
881
|
+
if (trimmed.includes(":")) return trimmed;
|
|
882
|
+
if (trimmed.startsWith("claude_tool_")) return `${ASCENDA_TOOL_TYPE}:${trimmed.slice("claude_tool_".length)}`;
|
|
883
|
+
return `${ASCENDA_TOOL_TYPE}:${trimmed}`;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// src/mapClaudeEvent.ts
|
|
887
|
+
var import_tool_kit5 = __toESM(require_out2(), 1);
|
|
888
|
+
|
|
889
|
+
// src/safeExtract.ts
|
|
890
|
+
var import_tool_kit4 = __toESM(require_out2(), 1);
|
|
891
|
+
|
|
892
|
+
// src/mapClaudeEvent.ts
|
|
893
|
+
function mapClaudeEvent(hookName, input) {
|
|
894
|
+
switch (hookName) {
|
|
895
|
+
case "SessionStart":
|
|
896
|
+
return mapSessionStart(input);
|
|
897
|
+
case "UserPromptSubmit":
|
|
898
|
+
return mapUserPromptSubmit(input);
|
|
899
|
+
case "PreToolUse":
|
|
900
|
+
return mapPreToolUse(input);
|
|
901
|
+
case "PostToolUse":
|
|
902
|
+
return mapPostToolUse(input);
|
|
903
|
+
case "PreCompact":
|
|
904
|
+
return mapPreCompact(input);
|
|
905
|
+
case "PostCompact":
|
|
906
|
+
return [{ eventType: "context_pressure_high", severity: "medium", metadata: { trigger: "inferred", reason: "context_limit" } }];
|
|
907
|
+
case "Stop":
|
|
908
|
+
return mapStop(input);
|
|
909
|
+
// No catalog event for notifications; skip to avoid unclassified noise.
|
|
910
|
+
case "Notification":
|
|
911
|
+
return [];
|
|
912
|
+
default:
|
|
913
|
+
return [];
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
function isNewSessionStart(input) {
|
|
917
|
+
const source = (0, import_tool_kit4.getString)(input, ["source"]);
|
|
918
|
+
return !source || source === "startup" || source === "resume";
|
|
919
|
+
}
|
|
920
|
+
function milestoneInviting(input) {
|
|
921
|
+
if ((0, import_tool_kit4.inferOutcome)(input) === "failure") return false;
|
|
922
|
+
const command = (0, import_tool_kit4.getString)(input, ["command"]) ?? (0, import_tool_kit4.getNestedString)(input, [["tool_input", "command"], ["input", "command"], ["parameters", "command"]]);
|
|
923
|
+
return (0, import_tool_kit5.invitesDebrief)((0, import_tool_kit5.classifyWorkMilestone)(command));
|
|
924
|
+
}
|
|
925
|
+
function mapSessionStart(input) {
|
|
926
|
+
if (!isNewSessionStart(input)) return [];
|
|
927
|
+
return [{ eventType: "create_focus_session", severity: "low", metadata: { activity: "session_started" } }];
|
|
928
|
+
}
|
|
929
|
+
function mapUserPromptSubmit(input) {
|
|
930
|
+
const prompt = (0, import_tool_kit4.getString)(input, ["prompt", "userPrompt", "message"]) ?? (0, import_tool_kit4.getNestedString)(input, [["payload", "prompt"], ["payload", "message"]]);
|
|
931
|
+
const events = [{ eventType: "ai_prompt_submitted", severity: "low", metadata: { promptClass: "unknown" } }];
|
|
932
|
+
if ((0, import_tool_kit4.looksLikeCorrection)(prompt)) {
|
|
933
|
+
events.push({ eventType: "ai_correction_prompt", severity: "medium", metadata: { reason: "repeated_reprompting", trigger: "inferred" } });
|
|
934
|
+
}
|
|
935
|
+
return events;
|
|
936
|
+
}
|
|
937
|
+
function mapPreToolUse(input) {
|
|
938
|
+
return [{ eventType: "ai_tool_call_started", severity: "low", metadata: { toolName: sanitiseToolName(getToolName(input)) } }];
|
|
939
|
+
}
|
|
940
|
+
function mapPostToolUse(input) {
|
|
941
|
+
const toolName = getToolName(input);
|
|
942
|
+
const safeToolName = sanitiseToolName(toolName);
|
|
943
|
+
const outcome = (0, import_tool_kit4.inferOutcome)(input);
|
|
944
|
+
const durationMs = (0, import_tool_kit4.getNumber)(input, ["durationMs", "duration_ms", "elapsedMs"]) ?? (0, import_tool_kit4.getNestedNumber)(input, [["tool_response", "durationMs"], ["result", "durationMs"]]);
|
|
945
|
+
const command = (0, import_tool_kit4.getString)(input, ["command"]) ?? (0, import_tool_kit4.getNestedString)(input, [["tool_input", "command"], ["input", "command"], ["parameters", "command"]]);
|
|
946
|
+
const commandClass = (0, import_tool_kit5.classifyCommand)(command);
|
|
947
|
+
const gitAction = outcome === "failure" ? void 0 : (0, import_tool_kit5.classifyGitAction)(command);
|
|
948
|
+
const milestoneKind = outcome === "failure" ? void 0 : (0, import_tool_kit5.classifyWorkMilestone)(command);
|
|
949
|
+
if (outcome === "failure") {
|
|
950
|
+
if (toolName?.toLowerCase() === "bash" && (0, import_tool_kit5.isVerificationCommand)(commandClass)) {
|
|
951
|
+
return [{ eventType: "compile_error", severity: "medium", metadata: { toolName: safeToolName, commandClass, outcome, durationBucket: (0, import_tool_kit4.bucketDurationMs)(durationMs), reason: "test_failure" } }];
|
|
952
|
+
}
|
|
953
|
+
return [{ eventType: "ai_tool_call_failed", severity: "medium", metadata: { toolName: safeToolName, commandClass, outcome, durationBucket: (0, import_tool_kit4.bucketDurationMs)(durationMs), reason: "tool_failure" } }];
|
|
954
|
+
}
|
|
955
|
+
if (isWriteTool(toolName)) {
|
|
956
|
+
const linesChanged = computeLinesChanged(toolName, input);
|
|
957
|
+
return [{
|
|
958
|
+
eventType: toolName?.toLowerCase() === "write" ? "ai_file_write" : "ai_file_edit",
|
|
959
|
+
severity: "low",
|
|
960
|
+
metadata: {
|
|
961
|
+
toolName: safeToolName,
|
|
962
|
+
outcome,
|
|
963
|
+
durationBucket: (0, import_tool_kit4.bucketDurationMs)(durationMs),
|
|
964
|
+
// The boundary C2/the macOS work-self-report card triggers on: at
|
|
965
|
+
// "200+" this is the "substantial accepted change" moment. No
|
|
966
|
+
// second event type exists for this — the bucket on the existing
|
|
967
|
+
// creation event *is* the boundary, deliberately, since the write
|
|
968
|
+
// already happened; there is nothing else to mark.
|
|
969
|
+
...linesChanged !== void 0 ? { linesChangedBucket: (0, import_tool_kit4.bucketLinesChanged)(linesChanged) } : {}
|
|
970
|
+
}
|
|
971
|
+
}];
|
|
972
|
+
}
|
|
973
|
+
if (toolName?.toLowerCase() === "bash" && (0, import_tool_kit5.isVerificationCommand)(commandClass)) {
|
|
974
|
+
return [{ eventType: "editor_verification_activity", severity: "low", metadata: { toolName: safeToolName, commandClass, outcome, durationBucket: (0, import_tool_kit4.bucketDurationMs)(durationMs), activity: "ai_test_or_build_run" } }];
|
|
975
|
+
}
|
|
976
|
+
return [{
|
|
977
|
+
eventType: "ai_tool_call_completed",
|
|
978
|
+
severity: "low",
|
|
979
|
+
metadata: {
|
|
980
|
+
toolName: safeToolName,
|
|
981
|
+
commandClass,
|
|
982
|
+
outcome,
|
|
983
|
+
durationBucket: (0, import_tool_kit4.bucketDurationMs)(durationMs),
|
|
984
|
+
// The boundary and rework signal both ride this existing event rather
|
|
985
|
+
// than minting a type: the backend already reads `gitAction` off any
|
|
986
|
+
// event, and a commit is not a different *kind* of thing happening, it
|
|
987
|
+
// is a fact about the tool call that just happened.
|
|
988
|
+
...gitAction !== void 0 ? { gitAction } : {},
|
|
989
|
+
...(0, import_tool_kit5.isReworkGitAction)(gitAction) ? { activity: "rework_reversion" } : {},
|
|
990
|
+
// Same reasoning as `gitAction` above, one grain coarser: a milestone is
|
|
991
|
+
// a fact about the tool call that just happened, not a different kind of
|
|
992
|
+
// event. It rides here so the record carries the work's own rhythm —
|
|
993
|
+
// ticket closed, PR merged — beside the keystroke boundaries (H1).
|
|
994
|
+
...milestoneKind !== void 0 ? { milestoneKind } : {}
|
|
995
|
+
}
|
|
996
|
+
}];
|
|
997
|
+
}
|
|
998
|
+
function mapPreCompact(input) {
|
|
999
|
+
const trigger = (0, import_tool_kit4.getString)(input, ["trigger", "reason", "compactType", "type"]) ?? (0, import_tool_kit4.getNestedString)(input, [["payload", "trigger"], ["payload", "reason"]]);
|
|
1000
|
+
const isManual = trigger?.toLowerCase().includes("manual") ?? false;
|
|
1001
|
+
return [{ eventType: isManual ? "context_compression_manual" : "context_compression_auto", severity: isManual ? "medium" : "high", metadata: { trigger: isManual ? "manual" : "auto", reason: "context_limit" } }];
|
|
1002
|
+
}
|
|
1003
|
+
function mapStop(input) {
|
|
1004
|
+
const durationMs = (0, import_tool_kit4.getNumber)(input, ["durationMs", "duration_ms", "elapsedMs"]) ?? (0, import_tool_kit4.getNestedNumber)(input, [["session", "durationMs"], ["payload", "durationMs"]]);
|
|
1005
|
+
const durationBucket = (0, import_tool_kit4.bucketDurationMs)(durationMs);
|
|
1006
|
+
if (durationBucket === "30-60m" || durationBucket === "60m+") {
|
|
1007
|
+
return [{ eventType: "agent_loop_long", severity: durationBucket === "60m+" ? "high" : "medium", metadata: { durationBucket, reason: "long_session", trigger: "inferred" } }];
|
|
1008
|
+
}
|
|
1009
|
+
return [];
|
|
1010
|
+
}
|
|
1011
|
+
function getToolName(input) {
|
|
1012
|
+
return (0, import_tool_kit4.getString)(input, ["toolName", "tool_name", "name"]) ?? (0, import_tool_kit4.getNestedString)(input, [["tool", "name"], ["tool_use", "name"], ["payload", "toolName"]]);
|
|
1013
|
+
}
|
|
1014
|
+
function computeLinesChanged(toolName, input) {
|
|
1015
|
+
const toolInput = (0, import_tool_kit4.getNested)(input, ["tool_input"]) ?? (0, import_tool_kit4.getNested)(input, ["input"]) ?? (0, import_tool_kit4.getNested)(input, ["parameters"]);
|
|
1016
|
+
if (!toolInput || typeof toolInput !== "object") return void 0;
|
|
1017
|
+
const record = toolInput;
|
|
1018
|
+
switch (toolName?.toLowerCase()) {
|
|
1019
|
+
case "write": {
|
|
1020
|
+
const content = record["content"];
|
|
1021
|
+
return typeof content === "string" ? countLines(content) : void 0;
|
|
1022
|
+
}
|
|
1023
|
+
case "edit": {
|
|
1024
|
+
const oldStr = record["old_string"];
|
|
1025
|
+
const newStr = record["new_string"];
|
|
1026
|
+
if (typeof oldStr !== "string" || typeof newStr !== "string") return void 0;
|
|
1027
|
+
return Math.max(countLines(oldStr), countLines(newStr));
|
|
1028
|
+
}
|
|
1029
|
+
case "multiedit": {
|
|
1030
|
+
const edits = record["edits"];
|
|
1031
|
+
if (!Array.isArray(edits)) return void 0;
|
|
1032
|
+
let total = 0;
|
|
1033
|
+
let sawOne = false;
|
|
1034
|
+
for (const edit of edits) {
|
|
1035
|
+
if (!edit || typeof edit !== "object") continue;
|
|
1036
|
+
const oldStr = edit["old_string"];
|
|
1037
|
+
const newStr = edit["new_string"];
|
|
1038
|
+
if (typeof oldStr !== "string" || typeof newStr !== "string") continue;
|
|
1039
|
+
sawOne = true;
|
|
1040
|
+
total += Math.max(countLines(oldStr), countLines(newStr));
|
|
1041
|
+
}
|
|
1042
|
+
return sawOne ? total : void 0;
|
|
1043
|
+
}
|
|
1044
|
+
default:
|
|
1045
|
+
return void 0;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function countLines(text) {
|
|
1049
|
+
return text.length === 0 ? 0 : text.split("\n").length;
|
|
1050
|
+
}
|
|
1051
|
+
function isWriteTool(toolName) {
|
|
1052
|
+
const value = toolName?.toLowerCase();
|
|
1053
|
+
return value === "write" || value === "edit" || value === "multiedit";
|
|
1054
|
+
}
|
|
1055
|
+
function sanitiseToolName(toolName) {
|
|
1056
|
+
if (!toolName) return "unknown";
|
|
1057
|
+
return toolName.replace(/[^a-zA-Z0-9_-]/g, "").slice(0, 40) || "unknown";
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// src/cli.ts
|
|
1061
|
+
var INTENTION_INVITE = "Ascenda tip: if it's natural, you can ask what would make this session count before diving in \u2014 one line is enough. Not a required step, and skip it entirely if the user is already mid-task.";
|
|
1062
|
+
var MILESTONE_DEBRIEF_INVITE = "Ascenda tip: that finished a piece of work. If the moment suits, it's worth a short debrief \u2014 what moved, what's still unresolved, and what you'd do differently next time. One or two lines. Skip it if they're already onto the next thing.";
|
|
1063
|
+
async function main() {
|
|
1064
|
+
const hookName = process.argv[2];
|
|
1065
|
+
if (!hookName) throw new Error("Usage: ascenda-claude-hook <ClaudeHookEventName>");
|
|
1066
|
+
const input = await readJsonFromStdin();
|
|
1067
|
+
if (hookName === "SessionStart" && isNewSessionStart(input) && process.env.ASCENDA_DISABLE_INTENTION_INVITE !== "true") {
|
|
1068
|
+
process.stdout.write(JSON.stringify({
|
|
1069
|
+
hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: INTENTION_INVITE }
|
|
1070
|
+
}));
|
|
1071
|
+
}
|
|
1072
|
+
if (hookName === "PostToolUse" && milestoneInviting(input) && process.env.ASCENDA_DISABLE_MILESTONE_DEBRIEF !== "true") {
|
|
1073
|
+
process.stdout.write(JSON.stringify({
|
|
1074
|
+
hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: MILESTONE_DEBRIEF_INVITE }
|
|
1075
|
+
}));
|
|
1076
|
+
}
|
|
1077
|
+
const config = loadConfigFromEnv();
|
|
1078
|
+
const client = new AscendaClient(config);
|
|
1079
|
+
const mappedEvents = mapClaudeEvent(hookName, input);
|
|
1080
|
+
for (const event of mappedEvents) {
|
|
1081
|
+
const result = await client.send(event);
|
|
1082
|
+
if (result === "consent_missing") {
|
|
1083
|
+
console.error("Ascenda telemetry rejected: renew IDE telemetry consent in the Ascenda app.");
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
if (result === "auth_failed") {
|
|
1087
|
+
console.error("Ascenda telemetry rejected: event write token invalid or revoked. Re-pair via the VS Code/Cursor extension.");
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
if (result !== "accepted") {
|
|
1091
|
+
console.error(`Ascenda telemetry rejected: ${result}`);
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
async function readJsonFromStdin() {
|
|
1097
|
+
const chunks = [];
|
|
1098
|
+
for await (const chunk of process.stdin) {
|
|
1099
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
1100
|
+
}
|
|
1101
|
+
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
1102
|
+
if (!raw) return {};
|
|
1103
|
+
const parsed = JSON.parse(raw);
|
|
1104
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
1105
|
+
return parsed;
|
|
1106
|
+
}
|
|
1107
|
+
main().catch((error) => {
|
|
1108
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
1109
|
+
}).finally(() => process.exit(0));
|