@k-leumas/queque-cli 0.7.1 → 0.8.1
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/README.md +11 -0
- package/dist/cli/app.js +1917 -262
- package/dist/cli/app.js.map +1 -1
- package/package.json +4 -1
- package/shell/zsh/queque.zsh +28 -1
package/dist/cli/app.js
CHANGED
|
@@ -270,7 +270,7 @@ var sleep;
|
|
|
270
270
|
var init_sleep = __esm({
|
|
271
271
|
"node_modules/.pnpm/@anthropic-ai+sdk@0.92.0_zod@4.1.5/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs"() {
|
|
272
272
|
"use strict";
|
|
273
|
-
sleep = (ms) => new Promise((
|
|
273
|
+
sleep = (ms) => new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
274
274
|
}
|
|
275
275
|
});
|
|
276
276
|
|
|
@@ -1059,8 +1059,8 @@ var init_api_promise = __esm({
|
|
|
1059
1059
|
init_parse();
|
|
1060
1060
|
APIPromise = class _APIPromise extends Promise {
|
|
1061
1061
|
constructor(client, responsePromise, parseResponse = defaultParseResponse) {
|
|
1062
|
-
super((
|
|
1063
|
-
|
|
1062
|
+
super((resolve6) => {
|
|
1063
|
+
resolve6(null);
|
|
1064
1064
|
});
|
|
1065
1065
|
this.responsePromise = responsePromise;
|
|
1066
1066
|
this.parseResponse = parseResponse;
|
|
@@ -3242,12 +3242,12 @@ var init_BetaMessageStream = __esm({
|
|
|
3242
3242
|
}
|
|
3243
3243
|
return this._emit("error", new AnthropicError(String(error43)));
|
|
3244
3244
|
});
|
|
3245
|
-
__classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((
|
|
3246
|
-
__classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise,
|
|
3245
|
+
__classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((resolve6, reject) => {
|
|
3246
|
+
__classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise, resolve6, "f");
|
|
3247
3247
|
__classPrivateFieldSet(this, _BetaMessageStream_rejectConnectedPromise, reject, "f");
|
|
3248
3248
|
}), "f");
|
|
3249
|
-
__classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((
|
|
3250
|
-
__classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise,
|
|
3249
|
+
__classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((resolve6, reject) => {
|
|
3250
|
+
__classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise, resolve6, "f");
|
|
3251
3251
|
__classPrivateFieldSet(this, _BetaMessageStream_rejectEndPromise, reject, "f");
|
|
3252
3252
|
}), "f");
|
|
3253
3253
|
__classPrivateFieldGet(this, _BetaMessageStream_connectedPromise, "f").catch(() => {
|
|
@@ -3417,11 +3417,11 @@ var init_BetaMessageStream = __esm({
|
|
|
3417
3417
|
* const message = await stream.emitted('message') // rejects if the stream errors
|
|
3418
3418
|
*/
|
|
3419
3419
|
emitted(event) {
|
|
3420
|
-
return new Promise((
|
|
3420
|
+
return new Promise((resolve6, reject) => {
|
|
3421
3421
|
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
|
3422
3422
|
if (event !== "error")
|
|
3423
3423
|
this.once("error", reject);
|
|
3424
|
-
this.once(event,
|
|
3424
|
+
this.once(event, resolve6);
|
|
3425
3425
|
});
|
|
3426
3426
|
}
|
|
3427
3427
|
async done() {
|
|
@@ -3764,7 +3764,7 @@ var init_BetaMessageStream = __esm({
|
|
|
3764
3764
|
if (done) {
|
|
3765
3765
|
return { value: void 0, done: true };
|
|
3766
3766
|
}
|
|
3767
|
-
return new Promise((
|
|
3767
|
+
return new Promise((resolve6, reject) => readQueue.push({ resolve: resolve6, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
|
|
3768
3768
|
}
|
|
3769
3769
|
const chunk = pushQueue.shift();
|
|
3770
3770
|
return { value: chunk, done: false };
|
|
@@ -3837,13 +3837,13 @@ Wrap your summary in <summary></summary> tags.`;
|
|
|
3837
3837
|
|
|
3838
3838
|
// node_modules/.pnpm/@anthropic-ai+sdk@0.92.0_zod@4.1.5/node_modules/@anthropic-ai/sdk/lib/tools/BetaToolRunner.mjs
|
|
3839
3839
|
function promiseWithResolvers() {
|
|
3840
|
-
let
|
|
3840
|
+
let resolve6;
|
|
3841
3841
|
let reject;
|
|
3842
3842
|
const promise2 = new Promise((res, rej) => {
|
|
3843
|
-
|
|
3843
|
+
resolve6 = res;
|
|
3844
3844
|
reject = rej;
|
|
3845
3845
|
});
|
|
3846
|
-
return { promise: promise2, resolve:
|
|
3846
|
+
return { promise: promise2, resolve: resolve6, reject };
|
|
3847
3847
|
}
|
|
3848
3848
|
async function generateToolResponse(params, lastMessage = params.messages.at(-1), requestOptions) {
|
|
3849
3849
|
if (!lastMessage || lastMessage.role !== "assistant" || !lastMessage.content || typeof lastMessage.content === "string") {
|
|
@@ -5441,12 +5441,12 @@ var init_MessageStream = __esm({
|
|
|
5441
5441
|
}
|
|
5442
5442
|
return this._emit("error", new AnthropicError(String(error43)));
|
|
5443
5443
|
});
|
|
5444
|
-
__classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((
|
|
5445
|
-
__classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise,
|
|
5444
|
+
__classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((resolve6, reject) => {
|
|
5445
|
+
__classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise, resolve6, "f");
|
|
5446
5446
|
__classPrivateFieldSet(this, _MessageStream_rejectConnectedPromise, reject, "f");
|
|
5447
5447
|
}), "f");
|
|
5448
|
-
__classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((
|
|
5449
|
-
__classPrivateFieldSet(this, _MessageStream_resolveEndPromise,
|
|
5448
|
+
__classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((resolve6, reject) => {
|
|
5449
|
+
__classPrivateFieldSet(this, _MessageStream_resolveEndPromise, resolve6, "f");
|
|
5450
5450
|
__classPrivateFieldSet(this, _MessageStream_rejectEndPromise, reject, "f");
|
|
5451
5451
|
}), "f");
|
|
5452
5452
|
__classPrivateFieldGet(this, _MessageStream_connectedPromise, "f").catch(() => {
|
|
@@ -5616,11 +5616,11 @@ var init_MessageStream = __esm({
|
|
|
5616
5616
|
* const message = await stream.emitted('message') // rejects if the stream errors
|
|
5617
5617
|
*/
|
|
5618
5618
|
emitted(event) {
|
|
5619
|
-
return new Promise((
|
|
5619
|
+
return new Promise((resolve6, reject) => {
|
|
5620
5620
|
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
5621
5621
|
if (event !== "error")
|
|
5622
5622
|
this.once("error", reject);
|
|
5623
|
-
this.once(event,
|
|
5623
|
+
this.once(event, resolve6);
|
|
5624
5624
|
});
|
|
5625
5625
|
}
|
|
5626
5626
|
async done() {
|
|
@@ -5938,7 +5938,7 @@ var init_MessageStream = __esm({
|
|
|
5938
5938
|
if (done) {
|
|
5939
5939
|
return { value: void 0, done: true };
|
|
5940
5940
|
}
|
|
5941
|
-
return new Promise((
|
|
5941
|
+
return new Promise((resolve6, reject) => readQueue.push({ resolve: resolve6, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
|
|
5942
5942
|
}
|
|
5943
5943
|
const chunk = pushQueue.shift();
|
|
5944
5944
|
return { value: chunk, done: false };
|
|
@@ -7727,21 +7727,21 @@ var require_react_development = __commonJS({
|
|
|
7727
7727
|
);
|
|
7728
7728
|
actScopeDepth = prevActScopeDepth;
|
|
7729
7729
|
}
|
|
7730
|
-
function recursivelyFlushAsyncActWork(returnValue,
|
|
7730
|
+
function recursivelyFlushAsyncActWork(returnValue, resolve6, reject) {
|
|
7731
7731
|
var queue = ReactSharedInternals.actQueue;
|
|
7732
7732
|
if (null !== queue)
|
|
7733
7733
|
if (0 !== queue.length)
|
|
7734
7734
|
try {
|
|
7735
7735
|
flushActQueue(queue);
|
|
7736
7736
|
enqueueTask(function() {
|
|
7737
|
-
return recursivelyFlushAsyncActWork(returnValue,
|
|
7737
|
+
return recursivelyFlushAsyncActWork(returnValue, resolve6, reject);
|
|
7738
7738
|
});
|
|
7739
7739
|
return;
|
|
7740
7740
|
} catch (error43) {
|
|
7741
7741
|
ReactSharedInternals.thrownErrors.push(error43);
|
|
7742
7742
|
}
|
|
7743
7743
|
else ReactSharedInternals.actQueue = null;
|
|
7744
|
-
0 < ReactSharedInternals.thrownErrors.length ? (queue = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(queue)) :
|
|
7744
|
+
0 < ReactSharedInternals.thrownErrors.length ? (queue = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(queue)) : resolve6(returnValue);
|
|
7745
7745
|
}
|
|
7746
7746
|
function flushActQueue(queue) {
|
|
7747
7747
|
if (!isFlushing) {
|
|
@@ -7928,7 +7928,7 @@ var require_react_development = __commonJS({
|
|
|
7928
7928
|
));
|
|
7929
7929
|
});
|
|
7930
7930
|
return {
|
|
7931
|
-
then: function(
|
|
7931
|
+
then: function(resolve6, reject) {
|
|
7932
7932
|
didAwaitActCall = true;
|
|
7933
7933
|
thenable.then(
|
|
7934
7934
|
function(returnValue) {
|
|
@@ -7938,7 +7938,7 @@ var require_react_development = __commonJS({
|
|
|
7938
7938
|
flushActQueue(queue), enqueueTask(function() {
|
|
7939
7939
|
return recursivelyFlushAsyncActWork(
|
|
7940
7940
|
returnValue,
|
|
7941
|
-
|
|
7941
|
+
resolve6,
|
|
7942
7942
|
reject
|
|
7943
7943
|
);
|
|
7944
7944
|
});
|
|
@@ -7952,7 +7952,7 @@ var require_react_development = __commonJS({
|
|
|
7952
7952
|
ReactSharedInternals.thrownErrors.length = 0;
|
|
7953
7953
|
reject(_thrownError);
|
|
7954
7954
|
}
|
|
7955
|
-
} else
|
|
7955
|
+
} else resolve6(returnValue);
|
|
7956
7956
|
},
|
|
7957
7957
|
function(error43) {
|
|
7958
7958
|
popActScope(prevActQueue, prevActScopeDepth);
|
|
@@ -7974,15 +7974,15 @@ var require_react_development = __commonJS({
|
|
|
7974
7974
|
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
7975
7975
|
throw callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
7976
7976
|
return {
|
|
7977
|
-
then: function(
|
|
7977
|
+
then: function(resolve6, reject) {
|
|
7978
7978
|
didAwaitActCall = true;
|
|
7979
7979
|
0 === prevActScopeDepth ? (ReactSharedInternals.actQueue = queue, enqueueTask(function() {
|
|
7980
7980
|
return recursivelyFlushAsyncActWork(
|
|
7981
7981
|
returnValue$jscomp$0,
|
|
7982
|
-
|
|
7982
|
+
resolve6,
|
|
7983
7983
|
reject
|
|
7984
7984
|
);
|
|
7985
|
-
})) :
|
|
7985
|
+
})) : resolve6(returnValue$jscomp$0);
|
|
7986
7986
|
}
|
|
7987
7987
|
};
|
|
7988
7988
|
};
|
|
@@ -10066,8 +10066,8 @@ var require_react_reconciler_production = __commonJS({
|
|
|
10066
10066
|
currentEntangledActionThenable = {
|
|
10067
10067
|
status: "pending",
|
|
10068
10068
|
value: void 0,
|
|
10069
|
-
then: function(
|
|
10070
|
-
entangledListeners.push(
|
|
10069
|
+
then: function(resolve6) {
|
|
10070
|
+
entangledListeners.push(resolve6);
|
|
10071
10071
|
}
|
|
10072
10072
|
};
|
|
10073
10073
|
}
|
|
@@ -10090,8 +10090,8 @@ var require_react_reconciler_production = __commonJS({
|
|
|
10090
10090
|
status: "pending",
|
|
10091
10091
|
value: null,
|
|
10092
10092
|
reason: null,
|
|
10093
|
-
then: function(
|
|
10094
|
-
listeners.push(
|
|
10093
|
+
then: function(resolve6) {
|
|
10094
|
+
listeners.push(resolve6);
|
|
10095
10095
|
}
|
|
10096
10096
|
};
|
|
10097
10097
|
thenable.then(
|
|
@@ -19690,8 +19690,8 @@ var require_react_reconciler_development = __commonJS({
|
|
|
19690
19690
|
currentEntangledActionThenable = {
|
|
19691
19691
|
status: "pending",
|
|
19692
19692
|
value: void 0,
|
|
19693
|
-
then: function(
|
|
19694
|
-
entangledListeners.push(
|
|
19693
|
+
then: function(resolve6) {
|
|
19694
|
+
entangledListeners.push(resolve6);
|
|
19695
19695
|
}
|
|
19696
19696
|
};
|
|
19697
19697
|
}
|
|
@@ -19714,8 +19714,8 @@ var require_react_reconciler_development = __commonJS({
|
|
|
19714
19714
|
status: "pending",
|
|
19715
19715
|
value: null,
|
|
19716
19716
|
reason: null,
|
|
19717
|
-
then: function(
|
|
19718
|
-
listeners.push(
|
|
19717
|
+
then: function(resolve6) {
|
|
19718
|
+
listeners.push(resolve6);
|
|
19719
19719
|
}
|
|
19720
19720
|
};
|
|
19721
19721
|
thenable.then(
|
|
@@ -33237,9 +33237,9 @@ var require_websocket = __commonJS({
|
|
|
33237
33237
|
var EventEmitter3 = __require("events");
|
|
33238
33238
|
var https = __require("https");
|
|
33239
33239
|
var http = __require("http");
|
|
33240
|
-
var
|
|
33240
|
+
var net6 = __require("net");
|
|
33241
33241
|
var tls = __require("tls");
|
|
33242
|
-
var { randomBytes:
|
|
33242
|
+
var { randomBytes: randomBytes3, createHash: createHash2 } = __require("crypto");
|
|
33243
33243
|
var { Duplex, Readable } = __require("stream");
|
|
33244
33244
|
var { URL: URL2 } = __require("url");
|
|
33245
33245
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -33769,7 +33769,7 @@ var require_websocket = __commonJS({
|
|
|
33769
33769
|
}
|
|
33770
33770
|
}
|
|
33771
33771
|
const defaultPort = isSecure ? 443 : 80;
|
|
33772
|
-
const key =
|
|
33772
|
+
const key = randomBytes3(16).toString("base64");
|
|
33773
33773
|
const request = isSecure ? https.request : http.request;
|
|
33774
33774
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
33775
33775
|
let perMessageDeflate;
|
|
@@ -33971,12 +33971,12 @@ var require_websocket = __commonJS({
|
|
|
33971
33971
|
}
|
|
33972
33972
|
function netConnect(options) {
|
|
33973
33973
|
options.path = options.socketPath;
|
|
33974
|
-
return
|
|
33974
|
+
return net6.connect(options);
|
|
33975
33975
|
}
|
|
33976
33976
|
function tlsConnect(options) {
|
|
33977
33977
|
options.path = void 0;
|
|
33978
33978
|
if (!options.servername && options.servername !== "") {
|
|
33979
|
-
options.servername =
|
|
33979
|
+
options.servername = net6.isIP(options.host) ? "" : options.host;
|
|
33980
33980
|
}
|
|
33981
33981
|
return tls.connect(options);
|
|
33982
33982
|
}
|
|
@@ -34757,22 +34757,22 @@ var init_devtools = __esm({
|
|
|
34757
34757
|
init_devtools_window_polyfill();
|
|
34758
34758
|
init_wrapper();
|
|
34759
34759
|
init_react_devtools_core();
|
|
34760
|
-
isDevToolsReachable = async () => new Promise((
|
|
34760
|
+
isDevToolsReachable = async () => new Promise((resolve6) => {
|
|
34761
34761
|
const socket = new wrapper_default("ws://localhost:8097");
|
|
34762
34762
|
const timeout = setTimeout(() => {
|
|
34763
34763
|
socket.terminate();
|
|
34764
|
-
|
|
34764
|
+
resolve6(false);
|
|
34765
34765
|
}, 2e3);
|
|
34766
34766
|
timeout.unref();
|
|
34767
34767
|
socket.on("open", () => {
|
|
34768
34768
|
clearTimeout(timeout);
|
|
34769
34769
|
socket.terminate();
|
|
34770
|
-
|
|
34770
|
+
resolve6(true);
|
|
34771
34771
|
});
|
|
34772
34772
|
socket.on("error", () => {
|
|
34773
34773
|
clearTimeout(timeout);
|
|
34774
34774
|
socket.terminate();
|
|
34775
|
-
|
|
34775
|
+
resolve6(false);
|
|
34776
34776
|
});
|
|
34777
34777
|
});
|
|
34778
34778
|
if (await isDevToolsReachable()) {
|
|
@@ -38971,7 +38971,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
38971
38971
|
const _normalized = cached(() => normalizeDef(def));
|
|
38972
38972
|
const generateFastpass = (shape) => {
|
|
38973
38973
|
const doc = new Doc(["shape", "payload", "ctx"]);
|
|
38974
|
-
const
|
|
38974
|
+
const normalized2 = _normalized.value;
|
|
38975
38975
|
const parseStr = (key) => {
|
|
38976
38976
|
const k = esc(key);
|
|
38977
38977
|
return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
@@ -38979,11 +38979,11 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
38979
38979
|
doc.write(`const input = payload.value;`);
|
|
38980
38980
|
const ids = /* @__PURE__ */ Object.create(null);
|
|
38981
38981
|
let counter = 0;
|
|
38982
|
-
for (const key of
|
|
38982
|
+
for (const key of normalized2.keys) {
|
|
38983
38983
|
ids[key] = `key_${counter++}`;
|
|
38984
38984
|
}
|
|
38985
38985
|
doc.write(`const newResult = {}`);
|
|
38986
|
-
for (const key of
|
|
38986
|
+
for (const key of normalized2.keys) {
|
|
38987
38987
|
const id = ids[key];
|
|
38988
38988
|
const k = esc(key);
|
|
38989
38989
|
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
@@ -48094,10 +48094,18 @@ var effortSchema = external_exports.preprocess(
|
|
|
48094
48094
|
(value) => typeof value === "string" ? value.trim().toLowerCase() : value,
|
|
48095
48095
|
external_exports.enum(EFFORT_LEVELS)
|
|
48096
48096
|
).optional().catch(void 0);
|
|
48097
|
+
var telemetryConfigSchema = external_exports.object({
|
|
48098
|
+
enabled: external_exports.boolean().optional(),
|
|
48099
|
+
asked: external_exports.boolean().optional(),
|
|
48100
|
+
installId: external_exports.uuid().optional()
|
|
48101
|
+
});
|
|
48097
48102
|
var qqConfigFileSchema = external_exports.object({
|
|
48098
48103
|
effort: effortSchema,
|
|
48099
48104
|
privacy: privacyConfigSchema,
|
|
48100
|
-
safety: safetyConfigSchema
|
|
48105
|
+
safety: safetyConfigSchema,
|
|
48106
|
+
// A malformed telemetry block becomes undefined instead of failing the whole file, which
|
|
48107
|
+
// would also drop the privacy, safety and effort keys (same lenient rule as effort).
|
|
48108
|
+
telemetry: telemetryConfigSchema.optional().catch(void 0)
|
|
48101
48109
|
});
|
|
48102
48110
|
var cachedConfig = null;
|
|
48103
48111
|
function defaultConfigPath() {
|
|
@@ -49063,7 +49071,7 @@ function runClaudeTurn(options) {
|
|
|
49063
49071
|
})
|
|
49064
49072
|
);
|
|
49065
49073
|
}
|
|
49066
|
-
return new Promise((
|
|
49074
|
+
return new Promise((resolve6, reject) => {
|
|
49067
49075
|
let settled = false;
|
|
49068
49076
|
let sawInit = false;
|
|
49069
49077
|
let sawDelta = false;
|
|
@@ -49214,7 +49222,7 @@ function runClaudeTurn(options) {
|
|
|
49214
49222
|
return;
|
|
49215
49223
|
}
|
|
49216
49224
|
onStage?.("result");
|
|
49217
|
-
finish(() =>
|
|
49225
|
+
finish(() => resolve6(parsed.data.result ?? ""));
|
|
49218
49226
|
};
|
|
49219
49227
|
if (!prewarmed && child.pid !== void 0) {
|
|
49220
49228
|
onStage?.("spawned", { pid: child.pid });
|
|
@@ -49537,6 +49545,141 @@ function logTurnStage(stage, detail, ms, warm) {
|
|
|
49537
49545
|
void appendDebugLog("provider", STAGE_LOG_NAMES[stage], fields);
|
|
49538
49546
|
}
|
|
49539
49547
|
|
|
49548
|
+
// src/contracts/telemetry.ts
|
|
49549
|
+
var ERROR_KINDS = [
|
|
49550
|
+
"auth_missing",
|
|
49551
|
+
"key_rejected",
|
|
49552
|
+
"key_refused",
|
|
49553
|
+
"provider_missing",
|
|
49554
|
+
"provider_timeout",
|
|
49555
|
+
"provider_failed",
|
|
49556
|
+
"response_truncated",
|
|
49557
|
+
"parse_failed",
|
|
49558
|
+
"pin_invalid",
|
|
49559
|
+
"socket_failed",
|
|
49560
|
+
"tty_unavailable",
|
|
49561
|
+
"unknown"
|
|
49562
|
+
];
|
|
49563
|
+
var PROVIDER_KINDS = ["claude-sdk", "claude-cli", "openai", "ollama", "unknown"];
|
|
49564
|
+
var QUERY_OUTCOMES = ["accepted", "escaped", "error"];
|
|
49565
|
+
var OS_KINDS = ["darwin", "linux", "other"];
|
|
49566
|
+
var ARCH_KINDS = ["x64", "arm64", "other"];
|
|
49567
|
+
var DISTRO_IDS = [
|
|
49568
|
+
"macos",
|
|
49569
|
+
"ubuntu",
|
|
49570
|
+
"debian",
|
|
49571
|
+
"fedora",
|
|
49572
|
+
"arch",
|
|
49573
|
+
"alpine",
|
|
49574
|
+
"other"
|
|
49575
|
+
];
|
|
49576
|
+
var TELEMETRY_LIB = "queque";
|
|
49577
|
+
var MAX_CANDIDATES = 5;
|
|
49578
|
+
var errorKind = external_exports.enum(ERROR_KINDS);
|
|
49579
|
+
var providerKind = external_exports.enum(PROVIDER_KINDS);
|
|
49580
|
+
var queryOutcomeFields = {
|
|
49581
|
+
outcome: external_exports.enum(QUERY_OUTCOMES),
|
|
49582
|
+
candidate_count: external_exports.number().int().min(0).max(MAX_CANDIDATES),
|
|
49583
|
+
provider: providerKind,
|
|
49584
|
+
/** Present exactly when outcome is `error` (refinement below). */
|
|
49585
|
+
error_kind: errorKind.optional()
|
|
49586
|
+
};
|
|
49587
|
+
var errorFields = {
|
|
49588
|
+
error_kind: errorKind,
|
|
49589
|
+
provider: providerKind
|
|
49590
|
+
};
|
|
49591
|
+
var environmentFields = {
|
|
49592
|
+
os: external_exports.enum(OS_KINDS),
|
|
49593
|
+
arch: external_exports.enum(ARCH_KINDS),
|
|
49594
|
+
distro: external_exports.enum(DISTRO_IDS),
|
|
49595
|
+
/** zsh major.minor only: `5.9`, never `5.9-dev-1` or a build string. */
|
|
49596
|
+
zsh: external_exports.union([external_exports.string().regex(/^\d{1,2}\.\d{1,2}$/), external_exports.literal("unknown")]),
|
|
49597
|
+
node_major: external_exports.number().int().min(18).max(99),
|
|
49598
|
+
zellij: external_exports.boolean()
|
|
49599
|
+
};
|
|
49600
|
+
var commonFields = {
|
|
49601
|
+
/** The random install UUID (D-06); never derived from host, user or network identifiers. */
|
|
49602
|
+
distinct_id: external_exports.uuid(),
|
|
49603
|
+
/** No PostHog person profile for an anonymous install. */
|
|
49604
|
+
$process_person_profile: external_exports.literal(false),
|
|
49605
|
+
$geoip_disable: external_exports.literal(true),
|
|
49606
|
+
$lib: external_exports.literal(TELEMETRY_LIB),
|
|
49607
|
+
$lib_version: external_exports.string().max(40).regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z.]+)?$/)
|
|
49608
|
+
};
|
|
49609
|
+
var ERROR_KIND_MISMATCH = {
|
|
49610
|
+
message: "error_kind is allowed exactly when outcome is error",
|
|
49611
|
+
path: ["error_kind"]
|
|
49612
|
+
};
|
|
49613
|
+
function errorKindMatchesOutcome(value) {
|
|
49614
|
+
return value.outcome === "error" === (value.error_kind !== void 0);
|
|
49615
|
+
}
|
|
49616
|
+
var queryOutcomePayloadSchema = external_exports.strictObject(queryOutcomeFields).refine(errorKindMatchesOutcome, ERROR_KIND_MISMATCH);
|
|
49617
|
+
var errorPayloadSchema = external_exports.strictObject(errorFields);
|
|
49618
|
+
var environmentPayloadSchema = external_exports.strictObject(environmentFields);
|
|
49619
|
+
var telemetryCommonPropertiesSchema = external_exports.strictObject(commonFields);
|
|
49620
|
+
var queryOutcomeWirePropertiesSchema = external_exports.strictObject({ ...commonFields, ...queryOutcomeFields }).refine(errorKindMatchesOutcome, ERROR_KIND_MISMATCH);
|
|
49621
|
+
var errorWirePropertiesSchema = external_exports.strictObject({ ...commonFields, ...errorFields });
|
|
49622
|
+
var environmentWirePropertiesSchema = external_exports.strictObject({
|
|
49623
|
+
...commonFields,
|
|
49624
|
+
...environmentFields
|
|
49625
|
+
});
|
|
49626
|
+
var clientTelemetryEventSchema = external_exports.discriminatedUnion("event", [
|
|
49627
|
+
external_exports.strictObject({ event: external_exports.literal("qq_query_outcome"), properties: queryOutcomePayloadSchema }),
|
|
49628
|
+
external_exports.strictObject({ event: external_exports.literal("qq_error"), properties: errorPayloadSchema }),
|
|
49629
|
+
external_exports.strictObject({ event: external_exports.literal("qq_environment"), properties: environmentPayloadSchema })
|
|
49630
|
+
]);
|
|
49631
|
+
var timestamp = external_exports.iso.datetime();
|
|
49632
|
+
var telemetryWireEventSchema = external_exports.discriminatedUnion("event", [
|
|
49633
|
+
external_exports.strictObject({
|
|
49634
|
+
event: external_exports.literal("qq_query_outcome"),
|
|
49635
|
+
timestamp,
|
|
49636
|
+
properties: queryOutcomeWirePropertiesSchema
|
|
49637
|
+
}),
|
|
49638
|
+
external_exports.strictObject({
|
|
49639
|
+
event: external_exports.literal("qq_error"),
|
|
49640
|
+
timestamp,
|
|
49641
|
+
properties: errorWirePropertiesSchema
|
|
49642
|
+
}),
|
|
49643
|
+
external_exports.strictObject({
|
|
49644
|
+
event: external_exports.literal("qq_environment"),
|
|
49645
|
+
timestamp,
|
|
49646
|
+
properties: environmentWirePropertiesSchema
|
|
49647
|
+
})
|
|
49648
|
+
]);
|
|
49649
|
+
var TELEMETRY_BATCH_MAX = 100;
|
|
49650
|
+
var telemetryBatchSchema = external_exports.strictObject({
|
|
49651
|
+
api_key: external_exports.string().max(200).regex(/^phc_[A-Za-z0-9_]+$/),
|
|
49652
|
+
batch: external_exports.array(telemetryWireEventSchema).min(1).max(TELEMETRY_BATCH_MAX)
|
|
49653
|
+
});
|
|
49654
|
+
|
|
49655
|
+
// src/providers/error-kind.ts
|
|
49656
|
+
var KINDS = new Set(ERROR_KINDS);
|
|
49657
|
+
function withErrorKind(error43, kind) {
|
|
49658
|
+
Object.defineProperty(error43, "errorKind", {
|
|
49659
|
+
value: kind,
|
|
49660
|
+
enumerable: false,
|
|
49661
|
+
configurable: true,
|
|
49662
|
+
writable: true
|
|
49663
|
+
});
|
|
49664
|
+
return error43;
|
|
49665
|
+
}
|
|
49666
|
+
function errorKindOf(error43) {
|
|
49667
|
+
if (!(error43 instanceof Error)) {
|
|
49668
|
+
return "unknown";
|
|
49669
|
+
}
|
|
49670
|
+
const tag = error43.errorKind;
|
|
49671
|
+
if (typeof tag === "string" && KINDS.has(tag)) {
|
|
49672
|
+
return tag;
|
|
49673
|
+
}
|
|
49674
|
+
if (error43.message === TRUNCATED_RESPONSE_MESSAGE) {
|
|
49675
|
+
return "response_truncated";
|
|
49676
|
+
}
|
|
49677
|
+
if (error43.message === UNPARSEABLE_RESPONSE_MESSAGE) {
|
|
49678
|
+
return "parse_failed";
|
|
49679
|
+
}
|
|
49680
|
+
return "unknown";
|
|
49681
|
+
}
|
|
49682
|
+
|
|
49540
49683
|
// src/providers/claude-default.ts
|
|
49541
49684
|
var TOTAL_BUDGET_MS = 25e3;
|
|
49542
49685
|
var AUTH_FAILURE_RE = /not logged in|login expired|please run \/login|failed to authenticate|oauth (token|session)/i;
|
|
@@ -49581,18 +49724,18 @@ function lookupApiKey() {
|
|
|
49581
49724
|
}
|
|
49582
49725
|
function hardError(error43) {
|
|
49583
49726
|
if (error43 instanceof Error && error43.message === TRUNCATED_RESPONSE_MESSAGE) {
|
|
49584
|
-
return error43;
|
|
49727
|
+
return withErrorKind(error43, "response_truncated");
|
|
49585
49728
|
}
|
|
49586
49729
|
if (isEnoent(error43)) {
|
|
49587
|
-
return new Error(ENOENT_MESSAGE);
|
|
49730
|
+
return withErrorKind(new Error(ENOENT_MESSAGE), "provider_missing");
|
|
49588
49731
|
}
|
|
49589
49732
|
if (isTimeoutOrKilled(error43)) {
|
|
49590
|
-
return new Error(TIMEOUT_MESSAGE);
|
|
49733
|
+
return withErrorKind(new Error(TIMEOUT_MESSAGE), "provider_timeout");
|
|
49591
49734
|
}
|
|
49592
49735
|
if (isAuthFailure(error43)) {
|
|
49593
|
-
return new Error(D13_MESSAGE);
|
|
49736
|
+
return withErrorKind(new Error(D13_MESSAGE), "auth_missing");
|
|
49594
49737
|
}
|
|
49595
|
-
return new Error(CLI_FAILED_MESSAGE);
|
|
49738
|
+
return withErrorKind(new Error(CLI_FAILED_MESSAGE), "provider_failed");
|
|
49596
49739
|
}
|
|
49597
49740
|
function sdkError(error43) {
|
|
49598
49741
|
if (isAbortError(error43)) {
|
|
@@ -49600,10 +49743,10 @@ function sdkError(error43) {
|
|
|
49600
49743
|
}
|
|
49601
49744
|
const status = errorField(error43, "status");
|
|
49602
49745
|
if (status === 401) {
|
|
49603
|
-
return new Error(SDK_KEY_REJECTED_MESSAGE);
|
|
49746
|
+
return withErrorKind(new Error(SDK_KEY_REJECTED_MESSAGE), "key_rejected");
|
|
49604
49747
|
}
|
|
49605
49748
|
if (status === 403) {
|
|
49606
|
-
return new Error(SDK_KEY_REFUSED_MESSAGE);
|
|
49749
|
+
return withErrorKind(new Error(SDK_KEY_REFUSED_MESSAGE), "key_refused");
|
|
49607
49750
|
}
|
|
49608
49751
|
return error43;
|
|
49609
49752
|
}
|
|
@@ -58166,8 +58309,8 @@ var kittyModifiers = {
|
|
|
58166
58309
|
var noop2 = () => {
|
|
58167
58310
|
};
|
|
58168
58311
|
var textEncoder = new TextEncoder();
|
|
58169
|
-
var yieldImmediate = async () => new Promise((
|
|
58170
|
-
setImmediate(
|
|
58312
|
+
var yieldImmediate = async () => new Promise((resolve6) => {
|
|
58313
|
+
setImmediate(resolve6);
|
|
58171
58314
|
});
|
|
58172
58315
|
var kittyQueryEscapeByte = 27;
|
|
58173
58316
|
var kittyQueryOpenBracketByte = 91;
|
|
@@ -58384,8 +58527,8 @@ var Ink = class {
|
|
|
58384
58527
|
};
|
|
58385
58528
|
}
|
|
58386
58529
|
this.initKittyKeyboard();
|
|
58387
|
-
this.exitPromise = new Promise((
|
|
58388
|
-
this.resolveExitPromise =
|
|
58530
|
+
this.exitPromise = new Promise((resolve6, reject) => {
|
|
58531
|
+
this.resolveExitPromise = resolve6;
|
|
58389
58532
|
this.rejectExitPromise = reject;
|
|
58390
58533
|
});
|
|
58391
58534
|
void this.exitPromise.catch(noop2);
|
|
@@ -58696,9 +58839,9 @@ var Ink = class {
|
|
|
58696
58839
|
settleThrottle(this.throttledOnRender, canWriteToStdout);
|
|
58697
58840
|
settleThrottle(this.throttledLog, canWriteToStdout);
|
|
58698
58841
|
if (canWriteToStdout && hasWritableState) {
|
|
58699
|
-
await new Promise((
|
|
58842
|
+
await new Promise((resolve6) => {
|
|
58700
58843
|
this.options.stdout.write("", () => {
|
|
58701
|
-
|
|
58844
|
+
resolve6();
|
|
58702
58845
|
});
|
|
58703
58846
|
});
|
|
58704
58847
|
return;
|
|
@@ -58784,8 +58927,8 @@ var Ink = class {
|
|
|
58784
58927
|
async awaitNextRender() {
|
|
58785
58928
|
if (!this.nextRenderCommit) {
|
|
58786
58929
|
let resolveRender;
|
|
58787
|
-
const promise2 = new Promise((
|
|
58788
|
-
resolveRender =
|
|
58930
|
+
const promise2 = new Promise((resolve6) => {
|
|
58931
|
+
resolveRender = resolve6;
|
|
58789
58932
|
});
|
|
58790
58933
|
this.nextRenderCommit = { promise: promise2, resolve: resolveRender };
|
|
58791
58934
|
}
|
|
@@ -59829,6 +59972,21 @@ var ipcRequestSchema = external_exports.discriminatedUnion("kind", [
|
|
|
59829
59972
|
// Old daemons ignore the unknown kind, so the caller falls back to signalling listeners.
|
|
59830
59973
|
external_exports.object({
|
|
59831
59974
|
kind: external_exports.literal("shutdown")
|
|
59975
|
+
}),
|
|
59976
|
+
// One anonymous telemetry event for the daemon buffer (phase 10, D-07). Fire-and-forget:
|
|
59977
|
+
// the daemon never replies. Old daemons ignore the unknown kind and keep running. The
|
|
59978
|
+
// event schema is strict, so an event with any field outside the allow list is ignored.
|
|
59979
|
+
external_exports.object({
|
|
59980
|
+
kind: external_exports.literal("telemetry-event"),
|
|
59981
|
+
event: clientTelemetryEventSchema
|
|
59982
|
+
}),
|
|
59983
|
+
// `qq telemetry show` (D-12): replied with `telemetry-buffer`.
|
|
59984
|
+
external_exports.object({
|
|
59985
|
+
kind: external_exports.literal("telemetry-show")
|
|
59986
|
+
}),
|
|
59987
|
+
// `qq telemetry off`: drops the buffer and the last sent body; replied with `telemetry-buffer`.
|
|
59988
|
+
external_exports.object({
|
|
59989
|
+
kind: external_exports.literal("telemetry-reset")
|
|
59832
59990
|
})
|
|
59833
59991
|
]);
|
|
59834
59992
|
var ipcResponseSchema = external_exports.discriminatedUnion("kind", [
|
|
@@ -59842,7 +60000,11 @@ var ipcResponseSchema = external_exports.discriminatedUnion("kind", [
|
|
|
59842
60000
|
// Daemon resolves the adapter from provider.json on every fetch (Phase 8, 08-03).
|
|
59843
60001
|
// A routing change, not an envelope shape change: a daemon without it sends every
|
|
59844
60002
|
// prompt to Claude even when the user pinned a local provider.
|
|
59845
|
-
providerPin: external_exports.literal(true).optional()
|
|
60003
|
+
providerPin: external_exports.literal(true).optional(),
|
|
60004
|
+
// Daemon buffers `telemetry-event` and answers `telemetry-show`/`telemetry-reset` (phase
|
|
60005
|
+
// 10). Informational only: ensureDaemon never replaces a daemon for lacking it, because
|
|
60006
|
+
// telemetry is optional and replacement goes through replaceStaleListener.
|
|
60007
|
+
telemetry: external_exports.literal(true).optional()
|
|
59846
60008
|
}),
|
|
59847
60009
|
external_exports.object({
|
|
59848
60010
|
kind: external_exports.literal("session-ready"),
|
|
@@ -59867,11 +60029,22 @@ var ipcResponseSchema = external_exports.discriminatedUnion("kind", [
|
|
|
59867
60029
|
}),
|
|
59868
60030
|
external_exports.object({
|
|
59869
60031
|
kind: external_exports.literal("fetch-error"),
|
|
59870
|
-
message: external_exports.string()
|
|
60032
|
+
message: external_exports.string(),
|
|
60033
|
+
// What failed, as an enum classified where the error object exists (phase 10, D-10), so
|
|
60034
|
+
// the client reports errors without reading message text. Optional for old daemons; an
|
|
60035
|
+
// unknown value from a newer daemon is filtered to undefined, not a rejected reply.
|
|
60036
|
+
errorKind: external_exports.enum(ERROR_KINDS).optional().catch(void 0)
|
|
59871
60037
|
}),
|
|
59872
60038
|
// Sent before the daemon closes its server for a `shutdown` request (WR-07).
|
|
59873
60039
|
external_exports.object({
|
|
59874
60040
|
kind: external_exports.literal("shutdown-accepted")
|
|
60041
|
+
}),
|
|
60042
|
+
// Reply to `telemetry-show` and `telemetry-reset` (D-12): `pending` is byte for byte the
|
|
60043
|
+
// body the next flush would send, `lastSent` the last body sent (memory only).
|
|
60044
|
+
external_exports.object({
|
|
60045
|
+
kind: external_exports.literal("telemetry-buffer"),
|
|
60046
|
+
pending: external_exports.string().nullable(),
|
|
60047
|
+
lastSent: external_exports.string().nullable()
|
|
59875
60048
|
})
|
|
59876
60049
|
]);
|
|
59877
60050
|
|
|
@@ -59900,24 +60073,24 @@ var POLL_INTERVAL_MS = 50;
|
|
|
59900
60073
|
var POLL_MAX_ATTEMPTS = 40;
|
|
59901
60074
|
var SHUTDOWN_ACK_TIMEOUT_MS = 500;
|
|
59902
60075
|
function tryConnect(socketPath2) {
|
|
59903
|
-
return new Promise((
|
|
60076
|
+
return new Promise((resolve6) => {
|
|
59904
60077
|
const timer = setTimeout(() => {
|
|
59905
60078
|
client.destroy();
|
|
59906
|
-
|
|
60079
|
+
resolve6(false);
|
|
59907
60080
|
}, CONNECT_TIMEOUT_MS);
|
|
59908
60081
|
const client = net.createConnection(socketPath2, () => {
|
|
59909
60082
|
clearTimeout(timer);
|
|
59910
60083
|
client.destroy();
|
|
59911
|
-
|
|
60084
|
+
resolve6(true);
|
|
59912
60085
|
});
|
|
59913
60086
|
client.on("error", () => {
|
|
59914
60087
|
clearTimeout(timer);
|
|
59915
|
-
|
|
60088
|
+
resolve6(false);
|
|
59916
60089
|
});
|
|
59917
60090
|
});
|
|
59918
60091
|
}
|
|
59919
60092
|
function pingDaemonFetchCap(socketPath2) {
|
|
59920
|
-
return new Promise((
|
|
60093
|
+
return new Promise((resolve6) => {
|
|
59921
60094
|
let settled = false;
|
|
59922
60095
|
let buf = "";
|
|
59923
60096
|
let timer;
|
|
@@ -59930,7 +60103,7 @@ function pingDaemonFetchCap(socketPath2) {
|
|
|
59930
60103
|
clearTimeout(timer);
|
|
59931
60104
|
}
|
|
59932
60105
|
client.destroy();
|
|
59933
|
-
|
|
60106
|
+
resolve6(result);
|
|
59934
60107
|
};
|
|
59935
60108
|
const client = net.createConnection(socketPath2);
|
|
59936
60109
|
timer = setTimeout(() => {
|
|
@@ -59967,7 +60140,7 @@ function pingDaemonFetchCap(socketPath2) {
|
|
|
59967
60140
|
});
|
|
59968
60141
|
}
|
|
59969
60142
|
function requestDaemonShutdown(socketPath2) {
|
|
59970
|
-
return new Promise((
|
|
60143
|
+
return new Promise((resolve6) => {
|
|
59971
60144
|
let settled = false;
|
|
59972
60145
|
let buf = "";
|
|
59973
60146
|
let timer;
|
|
@@ -59980,7 +60153,7 @@ function requestDaemonShutdown(socketPath2) {
|
|
|
59980
60153
|
clearTimeout(timer);
|
|
59981
60154
|
}
|
|
59982
60155
|
client.destroy();
|
|
59983
|
-
|
|
60156
|
+
resolve6(accepted);
|
|
59984
60157
|
};
|
|
59985
60158
|
const client = net.createConnection(socketPath2);
|
|
59986
60159
|
timer = setTimeout(() => {
|
|
@@ -60018,6 +60191,14 @@ async function waitForSocket(socketPath2, maxAttempts = POLL_MAX_ATTEMPTS) {
|
|
|
60018
60191
|
}
|
|
60019
60192
|
return false;
|
|
60020
60193
|
}
|
|
60194
|
+
function parseLsofPidList(output, selfPid) {
|
|
60195
|
+
const lines = output.split("\n").map((line) => line.trim()).filter((line) => line !== "");
|
|
60196
|
+
if (!lines.every((line) => /^\d+$/.test(line))) {
|
|
60197
|
+
void appendDebugLog("daemon", "lsof output ignored", { lines: lines.length });
|
|
60198
|
+
return [];
|
|
60199
|
+
}
|
|
60200
|
+
return lines.map(Number).filter((n) => n > 0 && n !== selfPid);
|
|
60201
|
+
}
|
|
60021
60202
|
function listenerPids(socketPath2) {
|
|
60022
60203
|
try {
|
|
60023
60204
|
const out = execFileSync2("lsof", ["-t", socketPath2], {
|
|
@@ -60025,13 +60206,13 @@ function listenerPids(socketPath2) {
|
|
|
60025
60206
|
timeout: 1e3,
|
|
60026
60207
|
stdio: ["ignore", "pipe", "ignore"]
|
|
60027
60208
|
});
|
|
60028
|
-
return out
|
|
60209
|
+
return parseLsofPidList(out, process.pid);
|
|
60029
60210
|
} catch {
|
|
60030
60211
|
return [];
|
|
60031
60212
|
}
|
|
60032
60213
|
}
|
|
60033
60214
|
function sleep2(ms) {
|
|
60034
|
-
return new Promise((
|
|
60215
|
+
return new Promise((resolve6) => setTimeout(resolve6, ms));
|
|
60035
60216
|
}
|
|
60036
60217
|
async function replaceStaleListener(socketPath2) {
|
|
60037
60218
|
void appendDebugLog("daemon", "replacing stale daemon", { socketPath: socketPath2 });
|
|
@@ -60142,7 +60323,7 @@ function requestDaemonFetch(socketPath2, envelope, timeoutMs = FETCH_TIMEOUT_MS,
|
|
|
60142
60323
|
if (signal?.aborted) {
|
|
60143
60324
|
return Promise.reject(abortError());
|
|
60144
60325
|
}
|
|
60145
|
-
return new Promise((
|
|
60326
|
+
return new Promise((resolve6, reject) => {
|
|
60146
60327
|
const client = net2.createConnection(socketPath2);
|
|
60147
60328
|
let buf = "";
|
|
60148
60329
|
let settled = false;
|
|
@@ -60163,7 +60344,7 @@ function requestDaemonFetch(socketPath2, envelope, timeoutMs = FETCH_TIMEOUT_MS,
|
|
|
60163
60344
|
reject(error43);
|
|
60164
60345
|
return;
|
|
60165
60346
|
}
|
|
60166
|
-
|
|
60347
|
+
resolve6(candidates);
|
|
60167
60348
|
};
|
|
60168
60349
|
const ackTimer = setTimeout(() => {
|
|
60169
60350
|
if (!accepted) {
|
|
@@ -60198,7 +60379,9 @@ function requestDaemonFetch(socketPath2, envelope, timeoutMs = FETCH_TIMEOUT_MS,
|
|
|
60198
60379
|
}
|
|
60199
60380
|
if (response.data.kind === "fetch-error") {
|
|
60200
60381
|
accepted = true;
|
|
60201
|
-
|
|
60382
|
+
const error43 = new Error(response.data.message);
|
|
60383
|
+
const { errorKind: errorKind2 } = response.data;
|
|
60384
|
+
finish(errorKind2 ? withErrorKind(error43, errorKind2) : error43);
|
|
60202
60385
|
return;
|
|
60203
60386
|
}
|
|
60204
60387
|
finish(new IpcTransportError("unexpected daemon fetch response"));
|
|
@@ -60263,8 +60446,205 @@ async function fetchCandidatesForUi(socketPath2, envelope, options = {}) {
|
|
|
60263
60446
|
throw error43;
|
|
60264
60447
|
}
|
|
60265
60448
|
void appendDebugLog("client", "daemon fetch fallback", { message: error43.message });
|
|
60266
|
-
|
|
60449
|
+
let adapter;
|
|
60450
|
+
try {
|
|
60451
|
+
adapter = resolveProviderAdapter();
|
|
60452
|
+
} catch (resolution) {
|
|
60453
|
+
throw resolution instanceof Error ? withErrorKind(resolution, "pin_invalid") : withErrorKind(new Error(String(resolution)), "pin_invalid");
|
|
60454
|
+
}
|
|
60455
|
+
return adapter.fetchCandidates(envelope, options);
|
|
60456
|
+
}
|
|
60457
|
+
}
|
|
60458
|
+
|
|
60459
|
+
// src/shared/telemetry-config.ts
|
|
60460
|
+
import { randomBytes as randomBytes2, randomUUID } from "crypto";
|
|
60461
|
+
import {
|
|
60462
|
+
accessSync,
|
|
60463
|
+
chmodSync as chmodSync2,
|
|
60464
|
+
constants as constants2,
|
|
60465
|
+
lstatSync,
|
|
60466
|
+
mkdirSync as mkdirSync2,
|
|
60467
|
+
readFileSync as readFileSync5,
|
|
60468
|
+
readlinkSync,
|
|
60469
|
+
realpathSync,
|
|
60470
|
+
renameSync as renameSync2,
|
|
60471
|
+
statSync as statSync2,
|
|
60472
|
+
unlinkSync as unlinkSync3,
|
|
60473
|
+
writeFileSync as writeFileSync2
|
|
60474
|
+
} from "fs";
|
|
60475
|
+
import { dirname as dirname4, resolve as resolve4 } from "path";
|
|
60476
|
+
var DEFAULT_STATE = { enabled: false, asked: false };
|
|
60477
|
+
var TelemetryConfigWriteError = class extends Error {
|
|
60478
|
+
path;
|
|
60479
|
+
constructor(path5, reason) {
|
|
60480
|
+
super(`queque: cannot update ${path5}: ${reason}. No changes made.`);
|
|
60481
|
+
this.name = "TelemetryConfigWriteError";
|
|
60482
|
+
this.path = path5;
|
|
60483
|
+
}
|
|
60484
|
+
};
|
|
60485
|
+
function normalized(value) {
|
|
60486
|
+
return value?.trim().toLowerCase();
|
|
60487
|
+
}
|
|
60488
|
+
function flagSet(value) {
|
|
60489
|
+
const flag = normalized(value);
|
|
60490
|
+
return flag !== void 0 && flag !== "" && flag !== "0" && flag !== "false";
|
|
60491
|
+
}
|
|
60492
|
+
function telemetryBlockedBy(env3 = process.env) {
|
|
60493
|
+
if (flagSet(env3.DO_NOT_TRACK)) {
|
|
60494
|
+
return "DO_NOT_TRACK";
|
|
60495
|
+
}
|
|
60496
|
+
const qqTelemetry = normalized(env3.QQ_TELEMETRY);
|
|
60497
|
+
if (qqTelemetry === "0" || qqTelemetry === "false" || qqTelemetry === "off") {
|
|
60498
|
+
return "QQ_TELEMETRY";
|
|
60499
|
+
}
|
|
60500
|
+
if (flagSet(env3.CI)) {
|
|
60501
|
+
return "CI";
|
|
60502
|
+
}
|
|
60503
|
+
return null;
|
|
60504
|
+
}
|
|
60505
|
+
function isJsonObject(value) {
|
|
60506
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
60507
|
+
}
|
|
60508
|
+
function readTelemetryState(path5 = defaultConfigPath()) {
|
|
60509
|
+
let parsed;
|
|
60510
|
+
try {
|
|
60511
|
+
parsed = JSON.parse(readFileSync5(path5, "utf8"));
|
|
60512
|
+
} catch {
|
|
60513
|
+
return { ...DEFAULT_STATE };
|
|
60514
|
+
}
|
|
60515
|
+
if (!isJsonObject(parsed)) {
|
|
60516
|
+
return { ...DEFAULT_STATE };
|
|
60517
|
+
}
|
|
60518
|
+
const block = telemetryConfigSchema.safeParse(parsed.telemetry);
|
|
60519
|
+
if (!block.success) {
|
|
60520
|
+
return { ...DEFAULT_STATE };
|
|
60521
|
+
}
|
|
60522
|
+
const state = {
|
|
60523
|
+
enabled: block.data.enabled ?? false,
|
|
60524
|
+
asked: block.data.asked ?? false
|
|
60525
|
+
};
|
|
60526
|
+
if (block.data.installId !== void 0) {
|
|
60527
|
+
state.installId = block.data.installId;
|
|
60528
|
+
}
|
|
60529
|
+
return state;
|
|
60530
|
+
}
|
|
60531
|
+
function readRawConfig(path5) {
|
|
60532
|
+
let text;
|
|
60533
|
+
try {
|
|
60534
|
+
text = readFileSync5(path5, "utf8");
|
|
60535
|
+
} catch (error43) {
|
|
60536
|
+
const code = error43.code;
|
|
60537
|
+
if (code === "ENOENT") {
|
|
60538
|
+
return {};
|
|
60539
|
+
}
|
|
60540
|
+
throw new TelemetryConfigWriteError(path5, `cannot read the file (${code ?? "unknown error"})`);
|
|
60541
|
+
}
|
|
60542
|
+
let parsed;
|
|
60543
|
+
try {
|
|
60544
|
+
parsed = JSON.parse(text);
|
|
60545
|
+
} catch {
|
|
60546
|
+
throw new TelemetryConfigWriteError(path5, "the file is not valid JSON; fix or remove it first");
|
|
60547
|
+
}
|
|
60548
|
+
if (!isJsonObject(parsed)) {
|
|
60549
|
+
throw new TelemetryConfigWriteError(
|
|
60550
|
+
path5,
|
|
60551
|
+
"the file is not a JSON object; fix or remove it first"
|
|
60552
|
+
);
|
|
60553
|
+
}
|
|
60554
|
+
return parsed;
|
|
60555
|
+
}
|
|
60556
|
+
function writeTarget(path5) {
|
|
60557
|
+
try {
|
|
60558
|
+
return realpathSync(path5);
|
|
60559
|
+
} catch {
|
|
60560
|
+
}
|
|
60561
|
+
try {
|
|
60562
|
+
if (lstatSync(path5).isSymbolicLink()) {
|
|
60563
|
+
return resolve4(dirname4(path5), readlinkSync(path5));
|
|
60564
|
+
}
|
|
60565
|
+
} catch {
|
|
60267
60566
|
}
|
|
60567
|
+
return path5;
|
|
60568
|
+
}
|
|
60569
|
+
function nearestExistingDir(dir) {
|
|
60570
|
+
let current2 = dir;
|
|
60571
|
+
for (; ; ) {
|
|
60572
|
+
try {
|
|
60573
|
+
if (statSync2(current2).isDirectory()) {
|
|
60574
|
+
return current2;
|
|
60575
|
+
}
|
|
60576
|
+
return void 0;
|
|
60577
|
+
} catch (error43) {
|
|
60578
|
+
if (error43.code !== "ENOENT") {
|
|
60579
|
+
return void 0;
|
|
60580
|
+
}
|
|
60581
|
+
}
|
|
60582
|
+
const parent = dirname4(current2);
|
|
60583
|
+
if (parent === current2) {
|
|
60584
|
+
return void 0;
|
|
60585
|
+
}
|
|
60586
|
+
current2 = parent;
|
|
60587
|
+
}
|
|
60588
|
+
}
|
|
60589
|
+
function telemetryStateWritable(path5 = defaultConfigPath()) {
|
|
60590
|
+
try {
|
|
60591
|
+
readRawConfig(path5);
|
|
60592
|
+
const dir = nearestExistingDir(dirname4(writeTarget(path5)));
|
|
60593
|
+
if (dir === void 0) {
|
|
60594
|
+
return false;
|
|
60595
|
+
}
|
|
60596
|
+
accessSync(dir, constants2.W_OK | constants2.X_OK);
|
|
60597
|
+
return true;
|
|
60598
|
+
} catch {
|
|
60599
|
+
return false;
|
|
60600
|
+
}
|
|
60601
|
+
}
|
|
60602
|
+
function writeTelemetryState(next, path5) {
|
|
60603
|
+
const raw = readRawConfig(path5);
|
|
60604
|
+
const block = { enabled: next.enabled, asked: next.asked };
|
|
60605
|
+
if (next.installId !== void 0) {
|
|
60606
|
+
block.installId = next.installId;
|
|
60607
|
+
}
|
|
60608
|
+
raw.telemetry = block;
|
|
60609
|
+
const target = writeTarget(path5);
|
|
60610
|
+
mkdirSync2(dirname4(target), { recursive: true, mode: 448 });
|
|
60611
|
+
const temp = `${target}.${process.pid}.${randomBytes2(4).toString("hex")}.tmp`;
|
|
60612
|
+
try {
|
|
60613
|
+
writeFileSync2(temp, `${JSON.stringify(raw, null, 2)}
|
|
60614
|
+
`, { mode: 384, flag: "wx" });
|
|
60615
|
+
chmodSync2(temp, 384);
|
|
60616
|
+
renameSync2(temp, target);
|
|
60617
|
+
} catch (error43) {
|
|
60618
|
+
try {
|
|
60619
|
+
unlinkSync3(temp);
|
|
60620
|
+
} catch {
|
|
60621
|
+
}
|
|
60622
|
+
throw error43;
|
|
60623
|
+
}
|
|
60624
|
+
}
|
|
60625
|
+
function setTelemetryEnabled(enabled2, path5 = defaultConfigPath()) {
|
|
60626
|
+
const current2 = readTelemetryState(path5);
|
|
60627
|
+
const next = enabled2 ? {
|
|
60628
|
+
enabled: true,
|
|
60629
|
+
asked: true,
|
|
60630
|
+
installId: current2.enabled && current2.installId ? current2.installId : randomUUID()
|
|
60631
|
+
} : { enabled: false, asked: true };
|
|
60632
|
+
writeTelemetryState(next, path5);
|
|
60633
|
+
return next;
|
|
60634
|
+
}
|
|
60635
|
+
function markTelemetryAsked(answer, path5 = defaultConfigPath()) {
|
|
60636
|
+
return setTelemetryEnabled(answer, path5);
|
|
60637
|
+
}
|
|
60638
|
+
function effectiveTelemetry(env3 = process.env, path5 = defaultConfigPath()) {
|
|
60639
|
+
const reason = telemetryBlockedBy(env3);
|
|
60640
|
+
if (reason) {
|
|
60641
|
+
return { on: false, reason };
|
|
60642
|
+
}
|
|
60643
|
+
const state = readTelemetryState(path5);
|
|
60644
|
+
if (!state.enabled || !state.installId) {
|
|
60645
|
+
return { on: false, reason: "disabled" };
|
|
60646
|
+
}
|
|
60647
|
+
return { on: true, installId: state.installId };
|
|
60268
60648
|
}
|
|
60269
60649
|
|
|
60270
60650
|
// src/shared/command-words.ts
|
|
@@ -61330,7 +61710,7 @@ function CandidateSelect({
|
|
|
61330
61710
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { dimColor: true, children: legend.slice(MISSING_TOOL_MARK.length) })
|
|
61331
61711
|
] }),
|
|
61332
61712
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ControlsLine, {}),
|
|
61333
|
-
process.env.QQ_DEV_ROOT != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { justifyContent: "flex-end", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: "yellow", children: `dev v${"0.
|
|
61713
|
+
process.env.QQ_DEV_ROOT != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Box_default, { justifyContent: "flex-end", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text, { color: "yellow", children: `dev v${"0.8.1"} ${"1068235"}` }) })
|
|
61334
61714
|
] });
|
|
61335
61715
|
}
|
|
61336
61716
|
|
|
@@ -61397,6 +61777,232 @@ async function writeShellResult(resultFile, result) {
|
|
|
61397
61777
|
}
|
|
61398
61778
|
}
|
|
61399
61779
|
|
|
61780
|
+
// src/client/telemetry-consent.ts
|
|
61781
|
+
var CONSENT_PROMPT = "QueQue: send anonymous usage and error counts (no commands, prompts or paths)? [y/N] ";
|
|
61782
|
+
var CONSENT_TIMEOUT_MS = 3e4;
|
|
61783
|
+
var ERASE_LINE = "\r\x1B[2K";
|
|
61784
|
+
var ERASE_ROW_ABOVE = "\x1B[1A\x1B[2K";
|
|
61785
|
+
function shouldAskTelemetryConsent(input) {
|
|
61786
|
+
return input.outcome === "accepted" && !input.state.asked && input.blockedBy === null && input.hasTty;
|
|
61787
|
+
}
|
|
61788
|
+
function eraseSequence(columns) {
|
|
61789
|
+
const width = columns !== void 0 && Number.isFinite(columns) && columns > 0 ? columns : 0;
|
|
61790
|
+
const rows = width > 0 ? Math.max(1, Math.ceil(CONSENT_PROMPT.length / width)) : 1;
|
|
61791
|
+
return `${ERASE_LINE}${ERASE_ROW_ABOVE.repeat(rows - 1)}`;
|
|
61792
|
+
}
|
|
61793
|
+
function askTelemetryConsent(io, timeoutMs = CONSENT_TIMEOUT_MS) {
|
|
61794
|
+
const { input, output } = io;
|
|
61795
|
+
return new Promise((resolve6) => {
|
|
61796
|
+
try {
|
|
61797
|
+
input.setRawMode(true);
|
|
61798
|
+
} catch {
|
|
61799
|
+
resolve6(false);
|
|
61800
|
+
return;
|
|
61801
|
+
}
|
|
61802
|
+
let settled = false;
|
|
61803
|
+
let timer;
|
|
61804
|
+
const settle = (answer) => {
|
|
61805
|
+
if (settled) return;
|
|
61806
|
+
settled = true;
|
|
61807
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
61808
|
+
input.off("data", onData);
|
|
61809
|
+
try {
|
|
61810
|
+
input.setRawMode(false);
|
|
61811
|
+
} catch {
|
|
61812
|
+
}
|
|
61813
|
+
try {
|
|
61814
|
+
input.pause();
|
|
61815
|
+
} catch {
|
|
61816
|
+
}
|
|
61817
|
+
try {
|
|
61818
|
+
output.write(eraseSequence(output.columns));
|
|
61819
|
+
} catch {
|
|
61820
|
+
}
|
|
61821
|
+
resolve6(answer);
|
|
61822
|
+
};
|
|
61823
|
+
const onData = (chunk) => {
|
|
61824
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
61825
|
+
const key = text.charAt(0);
|
|
61826
|
+
settle(key === "y" || key === "Y");
|
|
61827
|
+
};
|
|
61828
|
+
try {
|
|
61829
|
+
output.write(CONSENT_PROMPT);
|
|
61830
|
+
input.once("data", onData);
|
|
61831
|
+
input.resume();
|
|
61832
|
+
} catch {
|
|
61833
|
+
settle(false);
|
|
61834
|
+
return;
|
|
61835
|
+
}
|
|
61836
|
+
timer = setTimeout(() => settle(false), timeoutMs);
|
|
61837
|
+
});
|
|
61838
|
+
}
|
|
61839
|
+
|
|
61840
|
+
// src/client/telemetry-events.ts
|
|
61841
|
+
import * as net3 from "net";
|
|
61842
|
+
|
|
61843
|
+
// src/providers/provider-kind.ts
|
|
61844
|
+
function resolveProviderKind(deps = {}) {
|
|
61845
|
+
const loadPin = deps.loadPin ?? loadProviderPin;
|
|
61846
|
+
const hasApiKey = deps.hasApiKey ?? (() => lookupApiKey() !== void 0);
|
|
61847
|
+
try {
|
|
61848
|
+
const state = loadPin();
|
|
61849
|
+
if (state.kind === "invalid") {
|
|
61850
|
+
return "unknown";
|
|
61851
|
+
}
|
|
61852
|
+
if (state.kind === "pinned" && state.pin.provider !== "claude") {
|
|
61853
|
+
return state.pin.provider;
|
|
61854
|
+
}
|
|
61855
|
+
return hasApiKey() ? "claude-sdk" : "claude-cli";
|
|
61856
|
+
} catch {
|
|
61857
|
+
return "unknown";
|
|
61858
|
+
}
|
|
61859
|
+
}
|
|
61860
|
+
|
|
61861
|
+
// src/shared/environment-shape.ts
|
|
61862
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
61863
|
+
var LINUX_DISTRO_IDS = new Set(
|
|
61864
|
+
DISTRO_IDS.filter((id) => id !== "macos" && id !== "other")
|
|
61865
|
+
);
|
|
61866
|
+
function defaultReadOsRelease() {
|
|
61867
|
+
try {
|
|
61868
|
+
return readFileSync6("/etc/os-release", "utf8");
|
|
61869
|
+
} catch {
|
|
61870
|
+
return null;
|
|
61871
|
+
}
|
|
61872
|
+
}
|
|
61873
|
+
function osKind(platform2) {
|
|
61874
|
+
return platform2 === "darwin" || platform2 === "linux" ? platform2 : "other";
|
|
61875
|
+
}
|
|
61876
|
+
function archKind(arch) {
|
|
61877
|
+
return arch === "x64" || arch === "arm64" ? arch : "other";
|
|
61878
|
+
}
|
|
61879
|
+
function linuxDistro(osRelease) {
|
|
61880
|
+
if (osRelease === null) {
|
|
61881
|
+
return "other";
|
|
61882
|
+
}
|
|
61883
|
+
const match = /^ID=(.*)$/m.exec(osRelease);
|
|
61884
|
+
const id = match?.[1]?.trim().replace(/^(["'])(.*)\1$/, "$2").toLowerCase();
|
|
61885
|
+
return id !== void 0 && LINUX_DISTRO_IDS.has(id) ? id : "other";
|
|
61886
|
+
}
|
|
61887
|
+
function zshMajorMinor(version3) {
|
|
61888
|
+
const match = /^(\d{1,2})\.(\d{1,2})(?![0-9])/.exec(version3?.trim() ?? "");
|
|
61889
|
+
return match ? `${match[1]}.${match[2]}` : "unknown";
|
|
61890
|
+
}
|
|
61891
|
+
function nodeMajor(version3) {
|
|
61892
|
+
const match = /^v?(\d+)\./.exec(version3);
|
|
61893
|
+
return match ? Number(match[1]) : null;
|
|
61894
|
+
}
|
|
61895
|
+
function collectEnvironmentShape(input = {}) {
|
|
61896
|
+
const env3 = input.env ?? process.env;
|
|
61897
|
+
const os4 = osKind(input.platform ?? process.platform);
|
|
61898
|
+
const distro = os4 === "darwin" ? "macos" : os4 === "linux" ? linuxDistro((input.readOsRelease ?? defaultReadOsRelease)()) : "other";
|
|
61899
|
+
const major = nodeMajor(input.nodeVersion ?? process.version);
|
|
61900
|
+
if (major === null) {
|
|
61901
|
+
return null;
|
|
61902
|
+
}
|
|
61903
|
+
const result = environmentPayloadSchema.safeParse({
|
|
61904
|
+
os: os4,
|
|
61905
|
+
arch: archKind(input.arch ?? process.arch),
|
|
61906
|
+
distro,
|
|
61907
|
+
// The widget exports QQ_ZSH_VERSION="$ZSH_VERSION"; $ZSH_VERSION itself is not exported.
|
|
61908
|
+
zsh: zshMajorMinor(env3.QQ_ZSH_VERSION),
|
|
61909
|
+
node_major: major,
|
|
61910
|
+
zellij: env3.ZELLIJ !== void 0
|
|
61911
|
+
});
|
|
61912
|
+
return result.success ? result.data : null;
|
|
61913
|
+
}
|
|
61914
|
+
|
|
61915
|
+
// src/client/telemetry-events.ts
|
|
61916
|
+
var TELEMETRY_CLIENT_SEND_MS = 250;
|
|
61917
|
+
var CANDIDATE_COUNT_MAX = 5;
|
|
61918
|
+
function clampCount(count) {
|
|
61919
|
+
if (!Number.isFinite(count)) {
|
|
61920
|
+
return 0;
|
|
61921
|
+
}
|
|
61922
|
+
return Math.min(CANDIDATE_COUNT_MAX, Math.max(0, Math.trunc(count)));
|
|
61923
|
+
}
|
|
61924
|
+
function buildQueryOutcomeEvent(record2, provider) {
|
|
61925
|
+
return clientTelemetryEventSchema.parse({
|
|
61926
|
+
event: "qq_query_outcome",
|
|
61927
|
+
properties: {
|
|
61928
|
+
outcome: record2.outcome,
|
|
61929
|
+
candidate_count: clampCount(record2.candidateCount),
|
|
61930
|
+
provider,
|
|
61931
|
+
...record2.outcome === "error" ? { error_kind: record2.errorKind ?? "unknown" } : {}
|
|
61932
|
+
}
|
|
61933
|
+
});
|
|
61934
|
+
}
|
|
61935
|
+
function buildErrorEvent(kind, provider) {
|
|
61936
|
+
return clientTelemetryEventSchema.parse({
|
|
61937
|
+
event: "qq_error",
|
|
61938
|
+
properties: { error_kind: kind, provider }
|
|
61939
|
+
});
|
|
61940
|
+
}
|
|
61941
|
+
function buildEnvironmentEvent(shape) {
|
|
61942
|
+
return clientTelemetryEventSchema.parse({ event: "qq_environment", properties: shape });
|
|
61943
|
+
}
|
|
61944
|
+
function sendTelemetryEvents(socketPath2, events, timeoutMs = TELEMETRY_CLIENT_SEND_MS) {
|
|
61945
|
+
return new Promise((resolve6) => {
|
|
61946
|
+
if (events.length === 0) {
|
|
61947
|
+
resolve6();
|
|
61948
|
+
return;
|
|
61949
|
+
}
|
|
61950
|
+
let socket;
|
|
61951
|
+
let settled = false;
|
|
61952
|
+
const finish = () => {
|
|
61953
|
+
if (settled) return;
|
|
61954
|
+
settled = true;
|
|
61955
|
+
clearTimeout(timer);
|
|
61956
|
+
socket?.destroy();
|
|
61957
|
+
resolve6();
|
|
61958
|
+
};
|
|
61959
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
61960
|
+
try {
|
|
61961
|
+
socket = net3.createConnection(socketPath2);
|
|
61962
|
+
} catch {
|
|
61963
|
+
finish();
|
|
61964
|
+
return;
|
|
61965
|
+
}
|
|
61966
|
+
socket.on("error", finish);
|
|
61967
|
+
socket.on("close", finish);
|
|
61968
|
+
socket.once("connect", () => {
|
|
61969
|
+
const lines = events.map((event) => `${JSON.stringify({ kind: "telemetry-event", event })}
|
|
61970
|
+
`).join("");
|
|
61971
|
+
socket?.end(lines);
|
|
61972
|
+
});
|
|
61973
|
+
});
|
|
61974
|
+
}
|
|
61975
|
+
async function reportClientTelemetry(input) {
|
|
61976
|
+
try {
|
|
61977
|
+
if (!effectiveTelemetry(input.env, input.statePath).on) {
|
|
61978
|
+
return;
|
|
61979
|
+
}
|
|
61980
|
+
const provider = input.provider ? input.provider() : resolveProviderKind();
|
|
61981
|
+
const shape = input.environment ? input.environment() : collectEnvironmentShape({ env: input.env });
|
|
61982
|
+
const errors = input.errors ?? [];
|
|
61983
|
+
const events = [];
|
|
61984
|
+
if (shape) {
|
|
61985
|
+
events.push(buildEnvironmentEvent(shape));
|
|
61986
|
+
}
|
|
61987
|
+
for (const kind of errors) {
|
|
61988
|
+
events.push(buildErrorEvent(kind, provider));
|
|
61989
|
+
}
|
|
61990
|
+
if (input.record) {
|
|
61991
|
+
events.push(buildQueryOutcomeEvent(input.record, provider));
|
|
61992
|
+
}
|
|
61993
|
+
if (events.length === 0) {
|
|
61994
|
+
return;
|
|
61995
|
+
}
|
|
61996
|
+
await (input.send ?? sendTelemetryEvents)(input.socketPath, events);
|
|
61997
|
+
void appendDebugLog("client", "telemetry reported", {
|
|
61998
|
+
events: events.length,
|
|
61999
|
+
errors: errors.length,
|
|
62000
|
+
outcome: input.record !== void 0
|
|
62001
|
+
});
|
|
62002
|
+
} catch {
|
|
62003
|
+
}
|
|
62004
|
+
}
|
|
62005
|
+
|
|
61400
62006
|
// src/client/tool-handoff.ts
|
|
61401
62007
|
import { readFile } from "fs/promises";
|
|
61402
62008
|
import * as path3 from "path";
|
|
@@ -61608,10 +62214,12 @@ async function runForegroundClient(args) {
|
|
|
61608
62214
|
shellPid: request.shellPid
|
|
61609
62215
|
});
|
|
61610
62216
|
const toolInventory = resultMode === "llm" ? await readToolHandoff(path4.dirname(requestFile)) : null;
|
|
62217
|
+
const telemetryErrors = [];
|
|
61611
62218
|
try {
|
|
61612
62219
|
await ensureDaemon(socketPath2);
|
|
61613
62220
|
void appendDebugLog("client", "daemon ensured", { socketPath: socketPath2 });
|
|
61614
62221
|
} catch (error43) {
|
|
62222
|
+
telemetryErrors.push("socket_failed");
|
|
61615
62223
|
void appendDebugLog("client", "daemon ensure failed", {
|
|
61616
62224
|
message: error43 instanceof Error ? error43.message : String(error43)
|
|
61617
62225
|
});
|
|
@@ -61632,172 +62240,213 @@ async function runForegroundClient(args) {
|
|
|
61632
62240
|
let ttyReadStream;
|
|
61633
62241
|
let ttyWriteStream;
|
|
61634
62242
|
let takeover;
|
|
62243
|
+
let outcome;
|
|
62244
|
+
let shownCount = 0;
|
|
61635
62245
|
try {
|
|
61636
|
-
|
|
61637
|
-
try {
|
|
61638
|
-
ttyReadStream = new tty3.ReadStream(ttyHandle.fd);
|
|
61639
|
-
ttyWriteStream = new tty3.WriteStream(ttyHandle.fd);
|
|
61640
|
-
} catch {
|
|
61641
|
-
}
|
|
61642
|
-
}
|
|
61643
|
-
if (!ttyReadStream || !ttyWriteStream) {
|
|
61644
|
-
const msg = "\r\nqueque: could not open terminal for interactive input\r\n";
|
|
62246
|
+
try {
|
|
61645
62247
|
if (ttyHandle) {
|
|
61646
62248
|
try {
|
|
61647
|
-
|
|
62249
|
+
ttyReadStream = new tty3.ReadStream(ttyHandle.fd);
|
|
62250
|
+
ttyWriteStream = new tty3.WriteStream(ttyHandle.fd);
|
|
61648
62251
|
} catch {
|
|
61649
62252
|
}
|
|
61650
62253
|
}
|
|
61651
|
-
|
|
61652
|
-
|
|
61653
|
-
|
|
61654
|
-
if (inZellij) {
|
|
61655
|
-
takeover = armInstantFrameTakeover(ttyWriteStream, PANE_SURFACE_CLEAR);
|
|
61656
|
-
} else {
|
|
61657
|
-
ttyWriteStream.write(inlineScrollReserve(MODAL_VIEWPORT_LINES));
|
|
61658
|
-
takeover = armInstantFrameTakeover(ttyWriteStream, INLINE_SURFACE_CLEAR);
|
|
61659
|
-
}
|
|
61660
|
-
try {
|
|
61661
|
-
ttyReadStream.setRawMode(true);
|
|
61662
|
-
ttyReadStream.setRawMode(false);
|
|
61663
|
-
} catch {
|
|
61664
|
-
const msg = "\r\nqueque: terminal does not support interactive mode\r\nRun ?? from an interactive ZSH session.\r\n";
|
|
61665
|
-
ttyWriteStream.write(msg);
|
|
61666
|
-
await writeShellResult(resultFile, {
|
|
61667
|
-
kind: "error",
|
|
61668
|
-
message: "queque: terminal does not support interactive mode \u2014 run ?? from an interactive shell"
|
|
61669
|
-
});
|
|
61670
|
-
return;
|
|
61671
|
-
}
|
|
61672
|
-
const decision = classifyIntent({ ...request, intent: "unknown", confidence: 0 });
|
|
61673
|
-
void appendDebugLog("client", "intent classified", {
|
|
61674
|
-
intent: decision.intent,
|
|
61675
|
-
signals: decision.signals
|
|
61676
|
-
});
|
|
61677
|
-
const normalized = {
|
|
61678
|
-
...request,
|
|
61679
|
-
intent: decision.intent,
|
|
61680
|
-
confidence: decision.confidence
|
|
61681
|
-
};
|
|
61682
|
-
const envelope = withInstalledToolsChunk(await gatherContext(normalized), toolInventory);
|
|
61683
|
-
void appendDebugLog("client", "context gathered", {
|
|
61684
|
-
extraCount: envelope.extras.length
|
|
61685
|
-
});
|
|
61686
|
-
await new Promise((resolve5) => {
|
|
61687
|
-
let unmount;
|
|
61688
|
-
let resolved = false;
|
|
61689
|
-
const fetchAbort = new AbortController();
|
|
61690
|
-
const streamed = [];
|
|
61691
|
-
const buildCandidateElement = (candidates, errorState, listState = "complete") => import_react36.default.createElement(CandidateSelect, {
|
|
61692
|
-
candidates,
|
|
61693
|
-
initialQuery: request.lbuffer,
|
|
61694
|
-
error: errorState,
|
|
61695
|
-
listState,
|
|
61696
|
-
onSelect: async (command, explanation) => {
|
|
61697
|
-
if (resolved) return;
|
|
61698
|
-
resolved = true;
|
|
61699
|
-
fetchAbort.abort();
|
|
61700
|
-
const { lbuffer, rbuffer } = buildShellBuffers(command, explanation);
|
|
61701
|
-
await writeShellResult(resultFile, {
|
|
61702
|
-
kind: "replace-buffer",
|
|
61703
|
-
lbuffer,
|
|
61704
|
-
rbuffer,
|
|
61705
|
-
query: request.lbuffer
|
|
61706
|
-
});
|
|
61707
|
-
unmount?.();
|
|
61708
|
-
},
|
|
61709
|
-
onCancel: async () => {
|
|
61710
|
-
if (resolved) return;
|
|
61711
|
-
resolved = true;
|
|
61712
|
-
fetchAbort.abort();
|
|
61713
|
-
await writeShellResult(resultFile, { kind: "cancel" });
|
|
61714
|
-
unmount?.();
|
|
61715
|
-
},
|
|
61716
|
-
onLayoutLinesChange: inZellij ? syncZellijFloatingPaneHeight : void 0
|
|
61717
|
-
});
|
|
61718
|
-
const renderOptions = ttyReadStream && ttyWriteStream ? { stdin: ttyReadStream, stdout: ttyWriteStream, interactive: true } : { interactive: true };
|
|
61719
|
-
const app = render_default(buildCandidateElement(null), renderOptions);
|
|
61720
|
-
const clearScrollReserve = () => {
|
|
61721
|
-
if (ttyWriteStream && !inZellij) {
|
|
62254
|
+
if (!ttyReadStream || !ttyWriteStream) {
|
|
62255
|
+
const msg = "\r\nqueque: could not open terminal for interactive input\r\n";
|
|
62256
|
+
if (ttyHandle) {
|
|
61722
62257
|
try {
|
|
61723
|
-
|
|
62258
|
+
await ttyHandle.write(msg);
|
|
61724
62259
|
} catch {
|
|
61725
62260
|
}
|
|
61726
62261
|
}
|
|
62262
|
+
await writeShellResult(resultFile, { kind: "error", message: msg.trim() });
|
|
62263
|
+
outcome = { outcome: "error", candidateCount: 0, errorKind: "tty_unavailable" };
|
|
62264
|
+
return;
|
|
62265
|
+
}
|
|
62266
|
+
if (inZellij) {
|
|
62267
|
+
takeover = armInstantFrameTakeover(ttyWriteStream, PANE_SURFACE_CLEAR);
|
|
62268
|
+
} else {
|
|
62269
|
+
ttyWriteStream.write(inlineScrollReserve(MODAL_VIEWPORT_LINES));
|
|
62270
|
+
takeover = armInstantFrameTakeover(ttyWriteStream, INLINE_SURFACE_CLEAR);
|
|
62271
|
+
}
|
|
62272
|
+
try {
|
|
62273
|
+
ttyReadStream.setRawMode(true);
|
|
62274
|
+
ttyReadStream.setRawMode(false);
|
|
62275
|
+
} catch {
|
|
62276
|
+
const msg = "\r\nqueque: terminal does not support interactive mode\r\nRun ?? from an interactive ZSH session.\r\n";
|
|
62277
|
+
ttyWriteStream.write(msg);
|
|
62278
|
+
await writeShellResult(resultFile, {
|
|
62279
|
+
kind: "error",
|
|
62280
|
+
message: "queque: terminal does not support interactive mode \u2014 run ?? from an interactive shell"
|
|
62281
|
+
});
|
|
62282
|
+
outcome = { outcome: "error", candidateCount: 0, errorKind: "tty_unavailable" };
|
|
62283
|
+
return;
|
|
62284
|
+
}
|
|
62285
|
+
const decision = classifyIntent({
|
|
62286
|
+
...request,
|
|
62287
|
+
intent: "unknown",
|
|
62288
|
+
confidence: 0
|
|
62289
|
+
});
|
|
62290
|
+
void appendDebugLog("client", "intent classified", {
|
|
62291
|
+
intent: decision.intent,
|
|
62292
|
+
signals: decision.signals
|
|
62293
|
+
});
|
|
62294
|
+
const normalized2 = {
|
|
62295
|
+
...request,
|
|
62296
|
+
intent: decision.intent,
|
|
62297
|
+
confidence: decision.confidence
|
|
61727
62298
|
};
|
|
61728
|
-
const
|
|
61729
|
-
|
|
61730
|
-
|
|
61731
|
-
|
|
61732
|
-
|
|
61733
|
-
|
|
61734
|
-
|
|
61735
|
-
|
|
61736
|
-
|
|
61737
|
-
|
|
61738
|
-
|
|
61739
|
-
|
|
61740
|
-
|
|
61741
|
-
|
|
61742
|
-
|
|
61743
|
-
|
|
61744
|
-
|
|
61745
|
-
|
|
61746
|
-
|
|
61747
|
-
|
|
61748
|
-
|
|
61749
|
-
|
|
61750
|
-
|
|
61751
|
-
|
|
61752
|
-
|
|
61753
|
-
|
|
61754
|
-
|
|
61755
|
-
|
|
61756
|
-
|
|
61757
|
-
|
|
61758
|
-
|
|
61759
|
-
|
|
61760
|
-
|
|
61761
|
-
|
|
61762
|
-
|
|
61763
|
-
|
|
62299
|
+
const envelope = withInstalledToolsChunk(await gatherContext(normalized2), toolInventory);
|
|
62300
|
+
void appendDebugLog("client", "context gathered", {
|
|
62301
|
+
extraCount: envelope.extras.length
|
|
62302
|
+
});
|
|
62303
|
+
await new Promise((resolve6) => {
|
|
62304
|
+
let unmount;
|
|
62305
|
+
let resolved = false;
|
|
62306
|
+
const fetchAbort = new AbortController();
|
|
62307
|
+
const streamed = [];
|
|
62308
|
+
const buildCandidateElement = (candidates, errorState, listState = "complete") => import_react36.default.createElement(CandidateSelect, {
|
|
62309
|
+
candidates,
|
|
62310
|
+
initialQuery: request.lbuffer,
|
|
62311
|
+
error: errorState,
|
|
62312
|
+
listState,
|
|
62313
|
+
onSelect: async (command, explanation) => {
|
|
62314
|
+
if (resolved) return;
|
|
62315
|
+
resolved = true;
|
|
62316
|
+
outcome = { outcome: "accepted", candidateCount: shownCount };
|
|
62317
|
+
fetchAbort.abort();
|
|
62318
|
+
const { lbuffer, rbuffer } = buildShellBuffers(command, explanation);
|
|
62319
|
+
await writeShellResult(resultFile, {
|
|
62320
|
+
kind: "replace-buffer",
|
|
62321
|
+
lbuffer,
|
|
62322
|
+
rbuffer,
|
|
62323
|
+
query: request.lbuffer
|
|
62324
|
+
});
|
|
62325
|
+
unmount?.();
|
|
62326
|
+
},
|
|
62327
|
+
onCancel: async () => {
|
|
62328
|
+
if (resolved) return;
|
|
62329
|
+
resolved = true;
|
|
62330
|
+
outcome = { outcome: "escaped", candidateCount: shownCount };
|
|
62331
|
+
fetchAbort.abort();
|
|
62332
|
+
await writeShellResult(resultFile, { kind: "cancel" });
|
|
62333
|
+
unmount?.();
|
|
62334
|
+
},
|
|
62335
|
+
onLayoutLinesChange: inZellij ? syncZellijFloatingPaneHeight : void 0
|
|
61764
62336
|
});
|
|
61765
|
-
|
|
61766
|
-
|
|
61767
|
-
|
|
61768
|
-
|
|
61769
|
-
|
|
61770
|
-
|
|
61771
|
-
|
|
61772
|
-
|
|
61773
|
-
|
|
61774
|
-
|
|
61775
|
-
|
|
61776
|
-
|
|
61777
|
-
|
|
62337
|
+
const renderOptions = ttyReadStream && ttyWriteStream ? { stdin: ttyReadStream, stdout: ttyWriteStream, interactive: true } : { interactive: true };
|
|
62338
|
+
const app = render_default(buildCandidateElement(null), renderOptions);
|
|
62339
|
+
const clearScrollReserve = () => {
|
|
62340
|
+
if (ttyWriteStream && !inZellij) {
|
|
62341
|
+
try {
|
|
62342
|
+
ttyWriteStream.write(INLINE_SURFACE_CLEAR);
|
|
62343
|
+
} catch {
|
|
62344
|
+
}
|
|
62345
|
+
}
|
|
62346
|
+
};
|
|
62347
|
+
const cleanupOnSignal = () => {
|
|
62348
|
+
fetchAbort.abort();
|
|
62349
|
+
app.unmount();
|
|
62350
|
+
clearScrollReserve();
|
|
62351
|
+
process.exit(0);
|
|
62352
|
+
};
|
|
62353
|
+
process.once("SIGHUP", cleanupOnSignal);
|
|
62354
|
+
process.once("SIGTERM", cleanupOnSignal);
|
|
62355
|
+
unmount = (skipClear = false) => {
|
|
62356
|
+
process.off("SIGHUP", cleanupOnSignal);
|
|
62357
|
+
process.off("SIGTERM", cleanupOnSignal);
|
|
62358
|
+
app.unmount();
|
|
62359
|
+
if (!skipClear) clearScrollReserve();
|
|
62360
|
+
resolve6();
|
|
62361
|
+
};
|
|
62362
|
+
const onCandidate = (candidate) => {
|
|
62363
|
+
if (resolved) return;
|
|
62364
|
+
streamed.push(candidate);
|
|
62365
|
+
shownCount = streamed.length;
|
|
62366
|
+
if (streamed.length === 1) {
|
|
62367
|
+
void appendDebugLog("client", "first candidate received");
|
|
62368
|
+
}
|
|
61778
62369
|
app.rerender(
|
|
61779
62370
|
buildCandidateElement(
|
|
61780
62371
|
annotateCandidates([...streamed], toolInventory),
|
|
61781
62372
|
void 0,
|
|
61782
|
-
"
|
|
62373
|
+
"arriving"
|
|
61783
62374
|
)
|
|
61784
62375
|
);
|
|
61785
|
-
|
|
61786
|
-
}
|
|
61787
|
-
|
|
61788
|
-
|
|
61789
|
-
|
|
61790
|
-
|
|
61791
|
-
|
|
62376
|
+
};
|
|
62377
|
+
fetchCandidatesForUi(socketPath2, envelope, { signal: fetchAbort.signal, onCandidate }).then((candidates) => {
|
|
62378
|
+
if (resolved) return;
|
|
62379
|
+
const displayCandidates = annotateCandidates(candidates, toolInventory);
|
|
62380
|
+
shownCount = displayCandidates.length;
|
|
62381
|
+
void appendDebugLog("client", "candidates received", {
|
|
62382
|
+
count: candidates.length,
|
|
62383
|
+
streamed: streamed.length,
|
|
62384
|
+
flagged: displayCandidates.filter((c) => c.missingTools !== void 0).length
|
|
62385
|
+
});
|
|
62386
|
+
app.rerender(buildCandidateElement(displayCandidates, void 0, "complete"));
|
|
62387
|
+
}).catch(async (err) => {
|
|
62388
|
+
if (isAbortError(err)) {
|
|
62389
|
+
void appendDebugLog("client", "fetch aborted");
|
|
62390
|
+
return;
|
|
62391
|
+
}
|
|
62392
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
62393
|
+
void appendDebugLog("client", "llm request failed", { message });
|
|
62394
|
+
if (resolved) return;
|
|
62395
|
+
if (streamed.length > 0) {
|
|
62396
|
+
telemetryErrors.push(errorKindOf(err));
|
|
62397
|
+
void appendDebugLog("client", "llm request failed after rows", {
|
|
62398
|
+
count: streamed.length
|
|
62399
|
+
});
|
|
62400
|
+
app.rerender(
|
|
62401
|
+
buildCandidateElement(
|
|
62402
|
+
annotateCandidates([...streamed], toolInventory),
|
|
62403
|
+
void 0,
|
|
62404
|
+
"partial"
|
|
62405
|
+
)
|
|
62406
|
+
);
|
|
62407
|
+
return;
|
|
62408
|
+
}
|
|
62409
|
+
resolved = true;
|
|
62410
|
+
outcome = { outcome: "error", candidateCount: 0, errorKind: errorKindOf(err) };
|
|
62411
|
+
takeover?.clearNow();
|
|
62412
|
+
const errorMsg = formatFifoError(message);
|
|
62413
|
+
await writeShellResult(resultFile, { kind: "error", message: errorMsg });
|
|
62414
|
+
unmount?.(true);
|
|
62415
|
+
});
|
|
61792
62416
|
});
|
|
61793
|
-
|
|
61794
|
-
|
|
61795
|
-
|
|
61796
|
-
|
|
61797
|
-
|
|
61798
|
-
|
|
61799
|
-
|
|
61800
|
-
|
|
62417
|
+
void appendDebugLog("client", "wrote llm result", { resultFile });
|
|
62418
|
+
} catch (error43) {
|
|
62419
|
+
const message = error43 instanceof Error ? error43.message : String(error43);
|
|
62420
|
+
void appendDebugLog("client", "llm request failed", { message });
|
|
62421
|
+
takeover?.clearNow();
|
|
62422
|
+
const errorMsg = formatFifoError(message);
|
|
62423
|
+
await writeShellResult(resultFile, { kind: "error", message: errorMsg });
|
|
62424
|
+
outcome = { outcome: "error", candidateCount: 0, errorKind: errorKindOf(error43) };
|
|
62425
|
+
}
|
|
62426
|
+
} finally {
|
|
62427
|
+
if (outcome?.outcome === "accepted" && !inZellij && ttyReadStream && ttyWriteStream) {
|
|
62428
|
+
const ask = shouldAskTelemetryConsent({
|
|
62429
|
+
outcome: outcome.outcome,
|
|
62430
|
+
state: readTelemetryState(),
|
|
62431
|
+
blockedBy: telemetryBlockedBy(),
|
|
62432
|
+
hasTty: true
|
|
62433
|
+
}) && telemetryStateWritable();
|
|
62434
|
+
if (ask) {
|
|
62435
|
+
const answer = await askTelemetryConsent({
|
|
62436
|
+
input: ttyReadStream,
|
|
62437
|
+
output: ttyWriteStream
|
|
62438
|
+
});
|
|
62439
|
+
try {
|
|
62440
|
+
markTelemetryAsked(answer);
|
|
62441
|
+
await appendDebugLog("client", "consent saved", { enabled: answer });
|
|
62442
|
+
} catch (error43) {
|
|
62443
|
+
await appendDebugLog("client", "consent not saved", {
|
|
62444
|
+
error: error43 instanceof Error ? error43.name : "unknown"
|
|
62445
|
+
});
|
|
62446
|
+
}
|
|
62447
|
+
}
|
|
62448
|
+
}
|
|
62449
|
+
await reportClientTelemetry({ socketPath: socketPath2, record: outcome, errors: telemetryErrors });
|
|
61801
62450
|
}
|
|
61802
62451
|
} else {
|
|
61803
62452
|
await writeShellResult(resultFile, { kind: "cancel" });
|
|
@@ -61831,11 +62480,11 @@ async function clientCommand(options) {
|
|
|
61831
62480
|
}
|
|
61832
62481
|
|
|
61833
62482
|
// src/daemon/server.ts
|
|
61834
|
-
import * as
|
|
62483
|
+
import * as net4 from "net";
|
|
61835
62484
|
function startDaemonServer(socketPath2, options = {}) {
|
|
61836
|
-
return new Promise((
|
|
62485
|
+
return new Promise((resolve6, reject) => {
|
|
61837
62486
|
const MAX_BUF_BYTES = 256 * 1024;
|
|
61838
|
-
const server =
|
|
62487
|
+
const server = net4.createServer((socket) => {
|
|
61839
62488
|
let buf = "";
|
|
61840
62489
|
const connectionAbort = new AbortController();
|
|
61841
62490
|
socket.setEncoding("utf8");
|
|
@@ -61879,11 +62528,30 @@ function startDaemonServer(socketPath2, options = {}) {
|
|
|
61879
62528
|
fetchCandidates: true,
|
|
61880
62529
|
installedTools: true,
|
|
61881
62530
|
streamCandidates: true,
|
|
61882
|
-
providerPin: true
|
|
62531
|
+
providerPin: true,
|
|
62532
|
+
telemetry: true
|
|
61883
62533
|
});
|
|
61884
62534
|
void appendDebugLog("daemon", "replied pong");
|
|
61885
62535
|
break;
|
|
61886
62536
|
}
|
|
62537
|
+
case "telemetry-event": {
|
|
62538
|
+
options.telemetry?.enqueue(req.event);
|
|
62539
|
+
break;
|
|
62540
|
+
}
|
|
62541
|
+
case "telemetry-show":
|
|
62542
|
+
case "telemetry-reset": {
|
|
62543
|
+
const { telemetry } = options;
|
|
62544
|
+
if (req.kind === "telemetry-reset") {
|
|
62545
|
+
telemetry?.reset();
|
|
62546
|
+
}
|
|
62547
|
+
const snapshot = telemetry?.snapshot() ?? { pending: null, lastSent: null };
|
|
62548
|
+
writeJson({ kind: "telemetry-buffer", ...snapshot });
|
|
62549
|
+
void appendDebugLog("daemon", "replied telemetry-buffer", {
|
|
62550
|
+
pending: snapshot.pending !== null,
|
|
62551
|
+
lastSent: snapshot.lastSent !== null
|
|
62552
|
+
});
|
|
62553
|
+
break;
|
|
62554
|
+
}
|
|
61887
62555
|
case "shutdown": {
|
|
61888
62556
|
const { onShutdown } = options;
|
|
61889
62557
|
if (!onShutdown) {
|
|
@@ -61925,9 +62593,11 @@ function startDaemonServer(socketPath2, options = {}) {
|
|
|
61925
62593
|
writeJson({ kind: "candidate", candidate: row.data });
|
|
61926
62594
|
void appendDebugLog("daemon", "replied candidate", { index });
|
|
61927
62595
|
} : void 0;
|
|
62596
|
+
let resolved = false;
|
|
61928
62597
|
void Promise.resolve().then(() => {
|
|
61929
62598
|
bootstrapBuiltins();
|
|
61930
62599
|
const adapter = resolveProviderAdapter();
|
|
62600
|
+
resolved = true;
|
|
61931
62601
|
return adapter.fetchCandidates(envelope, {
|
|
61932
62602
|
signal: connectionAbort.signal,
|
|
61933
62603
|
onCandidate
|
|
@@ -61947,8 +62617,9 @@ function startDaemonServer(socketPath2, options = {}) {
|
|
|
61947
62617
|
return;
|
|
61948
62618
|
}
|
|
61949
62619
|
const message = error43 instanceof Error ? error43.message : String(error43);
|
|
61950
|
-
|
|
61951
|
-
|
|
62620
|
+
const errorKind2 = resolved ? errorKindOf(error43) : "pin_invalid";
|
|
62621
|
+
writeJson({ kind: "fetch-error", message, errorKind: errorKind2 });
|
|
62622
|
+
void appendDebugLog("daemon", "replied fetch-error", { message, errorKind: errorKind2 });
|
|
61952
62623
|
});
|
|
61953
62624
|
break;
|
|
61954
62625
|
}
|
|
@@ -61964,11 +62635,230 @@ function startDaemonServer(socketPath2, options = {}) {
|
|
|
61964
62635
|
server.on("error", reject);
|
|
61965
62636
|
server.listen(socketPath2, () => {
|
|
61966
62637
|
void appendDebugLog("daemon", "listening", { socketPath: socketPath2 });
|
|
61967
|
-
|
|
62638
|
+
resolve6(server);
|
|
61968
62639
|
});
|
|
61969
62640
|
});
|
|
61970
62641
|
}
|
|
61971
62642
|
|
|
62643
|
+
// src/shared/telemetry-endpoint.ts
|
|
62644
|
+
var PROJECT_KEY = /^phc_[A-Za-z0-9_]+$/;
|
|
62645
|
+
function resolveTelemetryEndpoint(env3 = process.env) {
|
|
62646
|
+
const key = usableSecret(env3.QQ_TELEMETRY_KEY) ?? "";
|
|
62647
|
+
if (!PROJECT_KEY.test(key)) {
|
|
62648
|
+
return null;
|
|
62649
|
+
}
|
|
62650
|
+
const host = usableSecret(env3.QQ_TELEMETRY_HOST) ?? "https://eu.i.posthog.com";
|
|
62651
|
+
let url2;
|
|
62652
|
+
try {
|
|
62653
|
+
url2 = new URL(host);
|
|
62654
|
+
} catch {
|
|
62655
|
+
return null;
|
|
62656
|
+
}
|
|
62657
|
+
if (url2.protocol !== "https:" && url2.protocol !== "http:") {
|
|
62658
|
+
return null;
|
|
62659
|
+
}
|
|
62660
|
+
if (url2.username !== "" || url2.password !== "") {
|
|
62661
|
+
return null;
|
|
62662
|
+
}
|
|
62663
|
+
return { host: host.replace(/\/+$/, ""), key };
|
|
62664
|
+
}
|
|
62665
|
+
|
|
62666
|
+
// src/daemon/telemetry-buffer.ts
|
|
62667
|
+
var TELEMETRY_FLUSH_INTERVAL_MS = 6e4;
|
|
62668
|
+
var TELEMETRY_FLUSH_THRESHOLD = 20;
|
|
62669
|
+
var TELEMETRY_BUFFER_CAP = TELEMETRY_BATCH_MAX;
|
|
62670
|
+
var TELEMETRY_SEND_TIMEOUT_MS = 3e3;
|
|
62671
|
+
var TELEMETRY_SHUTDOWN_WAIT_MS = 1e3;
|
|
62672
|
+
async function sendBatch(host, body, fetchImpl = fetch) {
|
|
62673
|
+
const url2 = `${host.replace(/\/+$/, "")}/batch/`;
|
|
62674
|
+
try {
|
|
62675
|
+
const response = await fetchImpl(url2, {
|
|
62676
|
+
method: "POST",
|
|
62677
|
+
headers: { "Content-Type": "application/json" },
|
|
62678
|
+
body,
|
|
62679
|
+
signal: AbortSignal.timeout(TELEMETRY_SEND_TIMEOUT_MS)
|
|
62680
|
+
});
|
|
62681
|
+
void appendDebugLog("daemon", "telemetry sent", { status: response.status });
|
|
62682
|
+
} catch (error43) {
|
|
62683
|
+
const reason = error43 instanceof Error ? error43.name : "unknown";
|
|
62684
|
+
void appendDebugLog("daemon", "telemetry send failed", { reason });
|
|
62685
|
+
}
|
|
62686
|
+
}
|
|
62687
|
+
function stableJson(value) {
|
|
62688
|
+
const sorted = {};
|
|
62689
|
+
for (const key of Object.keys(value).sort()) {
|
|
62690
|
+
sorted[key] = value[key];
|
|
62691
|
+
}
|
|
62692
|
+
return JSON.stringify(sorted);
|
|
62693
|
+
}
|
|
62694
|
+
function createTelemetryBuffer(deps = {}) {
|
|
62695
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
62696
|
+
const now = deps.now ?? Date.now;
|
|
62697
|
+
const readState = deps.readState ?? (() => readTelemetryState());
|
|
62698
|
+
const env3 = deps.env ?? (() => process.env);
|
|
62699
|
+
const endpointFor = deps.endpoint ?? resolveTelemetryEndpoint;
|
|
62700
|
+
const version3 = deps.version ?? "0.8.1";
|
|
62701
|
+
let events = [];
|
|
62702
|
+
let lastSent = null;
|
|
62703
|
+
let lastEnvironment = null;
|
|
62704
|
+
let inFlight = null;
|
|
62705
|
+
let timer = null;
|
|
62706
|
+
const gate = () => {
|
|
62707
|
+
const currentEnv = env3();
|
|
62708
|
+
const blocked = telemetryBlockedBy(currentEnv);
|
|
62709
|
+
if (blocked) {
|
|
62710
|
+
return { open: false, reason: blocked };
|
|
62711
|
+
}
|
|
62712
|
+
const state = readState();
|
|
62713
|
+
if (!state.enabled || !state.installId) {
|
|
62714
|
+
return { open: false, reason: "disabled" };
|
|
62715
|
+
}
|
|
62716
|
+
const endpoint = endpointFor(currentEnv);
|
|
62717
|
+
if (!endpoint) {
|
|
62718
|
+
return { open: false, reason: "no-endpoint" };
|
|
62719
|
+
}
|
|
62720
|
+
return { open: true, installId: state.installId, endpoint };
|
|
62721
|
+
};
|
|
62722
|
+
const sendable = (installId) => events.filter((event) => event.properties.distinct_id === installId);
|
|
62723
|
+
const serialize = (key, batch) => JSON.stringify({ api_key: key, batch });
|
|
62724
|
+
const wrap = (event, installId) => ({
|
|
62725
|
+
event: event.event,
|
|
62726
|
+
timestamp: new Date(now()).toISOString(),
|
|
62727
|
+
properties: {
|
|
62728
|
+
distinct_id: installId,
|
|
62729
|
+
$process_person_profile: false,
|
|
62730
|
+
$geoip_disable: true,
|
|
62731
|
+
$lib: TELEMETRY_LIB,
|
|
62732
|
+
$lib_version: version3,
|
|
62733
|
+
...event.properties
|
|
62734
|
+
}
|
|
62735
|
+
});
|
|
62736
|
+
const flushNow = async () => {
|
|
62737
|
+
while (inFlight) {
|
|
62738
|
+
await inFlight;
|
|
62739
|
+
}
|
|
62740
|
+
if (events.length === 0) {
|
|
62741
|
+
return;
|
|
62742
|
+
}
|
|
62743
|
+
const current2 = gate();
|
|
62744
|
+
if (!current2.open) {
|
|
62745
|
+
void appendDebugLog("daemon", "telemetry dropped", {
|
|
62746
|
+
reason: current2.reason,
|
|
62747
|
+
count: events.length
|
|
62748
|
+
});
|
|
62749
|
+
events = [];
|
|
62750
|
+
return;
|
|
62751
|
+
}
|
|
62752
|
+
const batch = sendable(current2.installId);
|
|
62753
|
+
const stale = events.length - batch.length;
|
|
62754
|
+
events = [];
|
|
62755
|
+
if (stale > 0) {
|
|
62756
|
+
void appendDebugLog("daemon", "telemetry dropped", {
|
|
62757
|
+
reason: "install-changed",
|
|
62758
|
+
count: stale
|
|
62759
|
+
});
|
|
62760
|
+
}
|
|
62761
|
+
if (batch.length === 0) {
|
|
62762
|
+
return;
|
|
62763
|
+
}
|
|
62764
|
+
const body = serialize(current2.endpoint.key, batch);
|
|
62765
|
+
if (!telemetryBatchSchema.safeParse(JSON.parse(body)).success) {
|
|
62766
|
+
void appendDebugLog("daemon", "telemetry dropped", {
|
|
62767
|
+
reason: "invalid-batch",
|
|
62768
|
+
count: batch.length
|
|
62769
|
+
});
|
|
62770
|
+
return;
|
|
62771
|
+
}
|
|
62772
|
+
lastSent = body;
|
|
62773
|
+
void appendDebugLog("daemon", "telemetry flushed", { count: batch.length });
|
|
62774
|
+
const send = sendBatch(current2.endpoint.host, body, fetchImpl);
|
|
62775
|
+
inFlight = send;
|
|
62776
|
+
try {
|
|
62777
|
+
await send;
|
|
62778
|
+
} finally {
|
|
62779
|
+
inFlight = null;
|
|
62780
|
+
}
|
|
62781
|
+
if (events.length >= TELEMETRY_FLUSH_THRESHOLD) {
|
|
62782
|
+
void flushNow();
|
|
62783
|
+
}
|
|
62784
|
+
};
|
|
62785
|
+
const enqueue = (input) => {
|
|
62786
|
+
const current2 = gate();
|
|
62787
|
+
if (!current2.open) {
|
|
62788
|
+
void appendDebugLog("daemon", "telemetry dropped", { reason: current2.reason, count: 1 });
|
|
62789
|
+
return false;
|
|
62790
|
+
}
|
|
62791
|
+
const parsed = clientTelemetryEventSchema.safeParse(input);
|
|
62792
|
+
if (!parsed.success) {
|
|
62793
|
+
void appendDebugLog("daemon", "telemetry dropped", { reason: "invalid-event", count: 1 });
|
|
62794
|
+
return false;
|
|
62795
|
+
}
|
|
62796
|
+
const event = parsed.data;
|
|
62797
|
+
let environmentKey = null;
|
|
62798
|
+
if (event.event === "qq_environment") {
|
|
62799
|
+
environmentKey = `${current2.installId}:${stableJson(event.properties)}`;
|
|
62800
|
+
if (environmentKey === lastEnvironment) {
|
|
62801
|
+
return false;
|
|
62802
|
+
}
|
|
62803
|
+
}
|
|
62804
|
+
const wire = telemetryWireEventSchema.safeParse(wrap(event, current2.installId));
|
|
62805
|
+
if (!wire.success) {
|
|
62806
|
+
void appendDebugLog("daemon", "telemetry dropped", { reason: "invalid-wire", count: 1 });
|
|
62807
|
+
return false;
|
|
62808
|
+
}
|
|
62809
|
+
if (events.length >= TELEMETRY_BUFFER_CAP) {
|
|
62810
|
+
void appendDebugLog("daemon", "telemetry dropped", { reason: "buffer-full", count: 1 });
|
|
62811
|
+
return false;
|
|
62812
|
+
}
|
|
62813
|
+
events.push(wire.data);
|
|
62814
|
+
if (environmentKey !== null) {
|
|
62815
|
+
lastEnvironment = environmentKey;
|
|
62816
|
+
}
|
|
62817
|
+
void appendDebugLog("daemon", "telemetry buffered", { count: events.length });
|
|
62818
|
+
if (events.length >= TELEMETRY_FLUSH_THRESHOLD && !inFlight) {
|
|
62819
|
+
void flushNow();
|
|
62820
|
+
}
|
|
62821
|
+
return true;
|
|
62822
|
+
};
|
|
62823
|
+
const snapshot = () => {
|
|
62824
|
+
const current2 = gate();
|
|
62825
|
+
if (!current2.open) {
|
|
62826
|
+
return { pending: null, lastSent };
|
|
62827
|
+
}
|
|
62828
|
+
const batch = sendable(current2.installId);
|
|
62829
|
+
return {
|
|
62830
|
+
pending: batch.length === 0 ? null : serialize(current2.endpoint.key, batch),
|
|
62831
|
+
lastSent
|
|
62832
|
+
};
|
|
62833
|
+
};
|
|
62834
|
+
return {
|
|
62835
|
+
enqueue,
|
|
62836
|
+
flush: flushNow,
|
|
62837
|
+
snapshot,
|
|
62838
|
+
reset: () => {
|
|
62839
|
+
events = [];
|
|
62840
|
+
lastSent = null;
|
|
62841
|
+
lastEnvironment = null;
|
|
62842
|
+
void appendDebugLog("daemon", "telemetry reset");
|
|
62843
|
+
},
|
|
62844
|
+
start: () => {
|
|
62845
|
+
if (timer) {
|
|
62846
|
+
return;
|
|
62847
|
+
}
|
|
62848
|
+
timer = setInterval(() => {
|
|
62849
|
+
void flushNow();
|
|
62850
|
+
}, TELEMETRY_FLUSH_INTERVAL_MS);
|
|
62851
|
+
timer.unref();
|
|
62852
|
+
},
|
|
62853
|
+
stop: () => {
|
|
62854
|
+
if (timer) {
|
|
62855
|
+
clearInterval(timer);
|
|
62856
|
+
timer = null;
|
|
62857
|
+
}
|
|
62858
|
+
}
|
|
62859
|
+
};
|
|
62860
|
+
}
|
|
62861
|
+
|
|
61972
62862
|
// src/cli/commands/daemon.ts
|
|
61973
62863
|
function trackConnections(server) {
|
|
61974
62864
|
const connections = /* @__PURE__ */ new Set();
|
|
@@ -61980,17 +62870,40 @@ function trackConnections(server) {
|
|
|
61980
62870
|
});
|
|
61981
62871
|
return connections;
|
|
61982
62872
|
}
|
|
62873
|
+
function startFinalFlush(telemetry) {
|
|
62874
|
+
if (!telemetry) {
|
|
62875
|
+
return Promise.resolve();
|
|
62876
|
+
}
|
|
62877
|
+
telemetry.stop();
|
|
62878
|
+
let flush;
|
|
62879
|
+
try {
|
|
62880
|
+
flush = telemetry.flush().catch(() => void 0);
|
|
62881
|
+
} catch {
|
|
62882
|
+
flush = Promise.resolve();
|
|
62883
|
+
}
|
|
62884
|
+
return new Promise((resolve6) => {
|
|
62885
|
+
const timer = setTimeout(resolve6, TELEMETRY_SHUTDOWN_WAIT_MS);
|
|
62886
|
+
timer.unref?.();
|
|
62887
|
+
void flush.then(() => {
|
|
62888
|
+
clearTimeout(timer);
|
|
62889
|
+
resolve6();
|
|
62890
|
+
});
|
|
62891
|
+
});
|
|
62892
|
+
}
|
|
61983
62893
|
function shutdownDaemon(server, connections, options = {}) {
|
|
61984
62894
|
const exit = options.exit ?? (() => process.exit(0));
|
|
61985
62895
|
const graceMs = options.graceMs ?? SIGKILL_GRACE_MS + 100;
|
|
61986
62896
|
disablePrewarm();
|
|
62897
|
+
const finalFlush = startFinalFlush(options.telemetry);
|
|
61987
62898
|
const inFlight = connections.size;
|
|
61988
62899
|
server.close(() => {
|
|
61989
|
-
|
|
61990
|
-
|
|
61991
|
-
|
|
61992
|
-
|
|
61993
|
-
|
|
62900
|
+
void finalFlush.then(() => {
|
|
62901
|
+
if (inFlight === 0) {
|
|
62902
|
+
exit();
|
|
62903
|
+
return;
|
|
62904
|
+
}
|
|
62905
|
+
setTimeout(exit, graceMs);
|
|
62906
|
+
});
|
|
61994
62907
|
});
|
|
61995
62908
|
for (const socket of connections) {
|
|
61996
62909
|
socket.destroy();
|
|
@@ -62005,13 +62918,18 @@ async function daemonCommand(options) {
|
|
|
62005
62918
|
return;
|
|
62006
62919
|
}
|
|
62007
62920
|
let onShutdownRequest = () => void 0;
|
|
62008
|
-
const
|
|
62921
|
+
const telemetry = createTelemetryBuffer();
|
|
62922
|
+
telemetry.start();
|
|
62923
|
+
const server = await startDaemonServer(sock, {
|
|
62924
|
+
onShutdown: () => onShutdownRequest(),
|
|
62925
|
+
telemetry
|
|
62926
|
+
});
|
|
62009
62927
|
const connections = trackConnections(server);
|
|
62010
62928
|
void appendDebugLog("daemon", "server started", { socket: sock });
|
|
62011
62929
|
enablePrewarm();
|
|
62012
62930
|
const shutdown = () => {
|
|
62013
62931
|
void appendDebugLog("daemon", "shutdown", { socket: sock, inFlight: connections.size });
|
|
62014
|
-
shutdownDaemon(server, connections);
|
|
62932
|
+
shutdownDaemon(server, connections, { telemetry });
|
|
62015
62933
|
};
|
|
62016
62934
|
onShutdownRequest = shutdown;
|
|
62017
62935
|
process.once("SIGTERM", shutdown);
|
|
@@ -62020,26 +62938,130 @@ async function daemonCommand(options) {
|
|
|
62020
62938
|
});
|
|
62021
62939
|
}
|
|
62022
62940
|
|
|
62023
|
-
// src/cli/commands/
|
|
62941
|
+
// src/cli/commands/doctor.ts
|
|
62024
62942
|
import { spawn as spawn4 } from "child_process";
|
|
62025
|
-
import {
|
|
62026
|
-
|
|
62027
|
-
|
|
62028
|
-
|
|
62943
|
+
import {
|
|
62944
|
+
accessSync as accessSync2,
|
|
62945
|
+
constants as constants3,
|
|
62946
|
+
lstatSync as lstatSync2,
|
|
62947
|
+
mkdtempSync,
|
|
62948
|
+
readFileSync as readFileSync8,
|
|
62949
|
+
rmSync,
|
|
62950
|
+
statSync as statSync3
|
|
62951
|
+
} from "fs";
|
|
62952
|
+
import { homedir as homedir7 } from "os";
|
|
62953
|
+
import { join as join6 } from "path";
|
|
62954
|
+
|
|
62955
|
+
// src/contracts/doctor.ts
|
|
62956
|
+
var DOCTOR_CHECK_IDS = [
|
|
62957
|
+
"zsh",
|
|
62958
|
+
"jq",
|
|
62959
|
+
"tmp",
|
|
62960
|
+
"socket",
|
|
62961
|
+
"daemon",
|
|
62962
|
+
"integration",
|
|
62963
|
+
"binding",
|
|
62964
|
+
"term",
|
|
62965
|
+
"locale",
|
|
62966
|
+
"provider",
|
|
62967
|
+
"node",
|
|
62968
|
+
"telemetry"
|
|
62969
|
+
];
|
|
62970
|
+
var DOCTOR_STATUSES = ["ok", "warn", "fail"];
|
|
62971
|
+
var DOCTOR_PLATFORMS = ["darwin", "linux", "other"];
|
|
62972
|
+
var DOCTOR_TEXT_MAX = 200;
|
|
62973
|
+
var doctorCheckSchema = external_exports.strictObject({
|
|
62974
|
+
id: external_exports.enum(DOCTOR_CHECK_IDS),
|
|
62975
|
+
status: external_exports.enum(DOCTOR_STATUSES),
|
|
62976
|
+
summary: external_exports.string().max(DOCTOR_TEXT_MAX),
|
|
62977
|
+
hint: external_exports.string().max(DOCTOR_TEXT_MAX).optional()
|
|
62978
|
+
});
|
|
62979
|
+
var doctorReportSchema = external_exports.strictObject({
|
|
62980
|
+
version: external_exports.literal(1),
|
|
62981
|
+
ok: external_exports.boolean(),
|
|
62982
|
+
qqVersion: external_exports.string(),
|
|
62983
|
+
platform: external_exports.enum(DOCTOR_PLATFORMS),
|
|
62984
|
+
checks: external_exports.array(doctorCheckSchema)
|
|
62985
|
+
});
|
|
62986
|
+
function doctorExitCode(report) {
|
|
62987
|
+
return report.checks.some((check3) => check3.status === "fail") ? 1 : 0;
|
|
62988
|
+
}
|
|
62989
|
+
|
|
62990
|
+
// src/providers/detect.ts
|
|
62991
|
+
import { execSync } from "child_process";
|
|
62992
|
+
import * as fsp4 from "fs/promises";
|
|
62993
|
+
import * as os3 from "os";
|
|
62994
|
+
function claudeOnPath() {
|
|
62995
|
+
try {
|
|
62996
|
+
execSync("which claude", { stdio: "pipe" });
|
|
62997
|
+
return true;
|
|
62998
|
+
} catch {
|
|
62999
|
+
return false;
|
|
63000
|
+
}
|
|
63001
|
+
}
|
|
63002
|
+
async function claudeAuthFileExists() {
|
|
63003
|
+
const home = os3.homedir();
|
|
63004
|
+
const candidates = [`${home}/.claude/.credentials.json`, `${home}/.claude/credentials.json`];
|
|
63005
|
+
for (const p of candidates) {
|
|
63006
|
+
try {
|
|
63007
|
+
await fsp4.stat(p);
|
|
63008
|
+
return true;
|
|
63009
|
+
} catch {
|
|
63010
|
+
}
|
|
63011
|
+
}
|
|
63012
|
+
return false;
|
|
63013
|
+
}
|
|
63014
|
+
async function claudeAuthPresent() {
|
|
63015
|
+
if (process.env.CLAUDE_CODE_OAUTH_TOKEN || process.env.ANTHROPIC_AUTH_TOKEN) {
|
|
63016
|
+
return true;
|
|
63017
|
+
}
|
|
63018
|
+
if (process.platform === "darwin") {
|
|
63019
|
+
return true;
|
|
63020
|
+
}
|
|
63021
|
+
return claudeAuthFileExists();
|
|
63022
|
+
}
|
|
63023
|
+
async function ollamaHealthy() {
|
|
63024
|
+
try {
|
|
63025
|
+
const res = await fetch("http://localhost:11434/api/tags", {
|
|
63026
|
+
signal: AbortSignal.timeout(300)
|
|
63027
|
+
});
|
|
63028
|
+
return res.ok;
|
|
63029
|
+
} catch {
|
|
63030
|
+
return false;
|
|
63031
|
+
}
|
|
63032
|
+
}
|
|
63033
|
+
async function detectProvider() {
|
|
63034
|
+
if (process.env.ANTHROPIC_API_KEY || readEnvValueFromDotEnvLocal("ANTHROPIC_API_KEY")) {
|
|
63035
|
+
return { kind: "anthropic-key" };
|
|
63036
|
+
}
|
|
63037
|
+
if (claudeOnPath() && await claudeAuthPresent()) {
|
|
63038
|
+
return { kind: "claude-cli" };
|
|
63039
|
+
}
|
|
63040
|
+
if (await ollamaHealthy()) {
|
|
63041
|
+
return { kind: "ollama", baseUrl: "http://localhost:11434" };
|
|
63042
|
+
}
|
|
63043
|
+
if (process.env.OPENAI_API_KEY) {
|
|
63044
|
+
return { kind: "openai-key" };
|
|
63045
|
+
}
|
|
63046
|
+
return {
|
|
63047
|
+
kind: "none",
|
|
63048
|
+
message: "queque: no AI provider configured\nChecked (in order):\n 1. ANTHROPIC_API_KEY env var or ~/.env.local\n 2. Claude CLI (claude on PATH + credentials file or macOS Keychain login)\n 3. Ollama at http://localhost:11434\n 4. OPENAI_API_KEY env var\nSet one of the above and re-trigger ??"
|
|
63049
|
+
};
|
|
63050
|
+
}
|
|
62029
63051
|
|
|
62030
63052
|
// src/cli/commands/init.ts
|
|
62031
|
-
import { appendFileSync, existsSync as existsSync4, readFileSync as
|
|
62032
|
-
import { homedir as
|
|
62033
|
-
import { dirname as
|
|
63053
|
+
import { appendFileSync, existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
|
|
63054
|
+
import { homedir as homedir6 } from "os";
|
|
63055
|
+
import { dirname as dirname6, join as join5, resolve as resolve5 } from "path";
|
|
62034
63056
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
62035
|
-
var __dirname =
|
|
63057
|
+
var __dirname = dirname6(fileURLToPath2(import.meta.url));
|
|
62036
63058
|
var HOMEBREW_PREFIXES = ["/opt/homebrew", "/usr/local", "/home/linuxbrew/.linuxbrew"];
|
|
62037
63059
|
function _resolveScriptPath(shell) {
|
|
62038
63060
|
for (const prefix of HOMEBREW_PREFIXES) {
|
|
62039
|
-
const p =
|
|
63061
|
+
const p = resolve5(prefix, "share", "queque", `queque.${shell}`);
|
|
62040
63062
|
if (existsSync4(p)) return p;
|
|
62041
63063
|
}
|
|
62042
|
-
return
|
|
63064
|
+
return resolve5(__dirname, "../../shell", shell, `queque.${shell}`);
|
|
62043
63065
|
}
|
|
62044
63066
|
function hasShellIntegration(existing, shell) {
|
|
62045
63067
|
if (/# queque shell integration/.test(existing)) {
|
|
@@ -62055,10 +63077,10 @@ function initCommand(shell) {
|
|
|
62055
63077
|
console.error(`Unsupported shell: '${shell}'. Supported: ${supportedShells.join(", ")}`);
|
|
62056
63078
|
process.exit(1);
|
|
62057
63079
|
}
|
|
62058
|
-
const zshrc = join5(
|
|
63080
|
+
const zshrc = join5(homedir6(), ".zshrc");
|
|
62059
63081
|
const scriptPath = _resolveScriptPath(shell);
|
|
62060
63082
|
const snippet = `source "${scriptPath}"`;
|
|
62061
|
-
const existing = existsSync4(zshrc) ?
|
|
63083
|
+
const existing = existsSync4(zshrc) ? readFileSync7(zshrc, "utf8") : "";
|
|
62062
63084
|
if (hasShellIntegration(existing, shell)) {
|
|
62063
63085
|
console.error("queque: shell integration already present in ~/.zshrc");
|
|
62064
63086
|
process.exit(0);
|
|
@@ -62070,7 +63092,462 @@ ${snippet}
|
|
|
62070
63092
|
console.log("queque: added shell integration to ~/.zshrc \u2014 run: source ~/.zshrc");
|
|
62071
63093
|
}
|
|
62072
63094
|
|
|
63095
|
+
// src/cli/commands/doctor.ts
|
|
63096
|
+
var ZSH_FAIL_BELOW = "5.0";
|
|
63097
|
+
var ZSH_WARN_BELOW = "5.8";
|
|
63098
|
+
var SOCKET_PATH_MAX_BYTES = { linux: 107, darwin: 103 };
|
|
63099
|
+
var SOCKET_PATH_MAX_DEFAULT = 107;
|
|
63100
|
+
var NODE_WARN_BELOW_MAJOR = 24;
|
|
63101
|
+
var QQ_WIDGET = "qq-question-widget";
|
|
63102
|
+
var ZSH_VERSION_TIMEOUT_MS = 3e3;
|
|
63103
|
+
var ZSH_BINDINGS_TIMEOUT_MS = 5e3;
|
|
63104
|
+
var EXIT_GRACE_MS = 100;
|
|
63105
|
+
var MAX_CAPTURE_CHARS = 64 * 1024;
|
|
63106
|
+
function whichOnPath(name, pathEnv) {
|
|
63107
|
+
for (const dir of (pathEnv ?? "").split(":")) {
|
|
63108
|
+
if (!dir) {
|
|
63109
|
+
continue;
|
|
63110
|
+
}
|
|
63111
|
+
const candidate = join6(dir, name);
|
|
63112
|
+
try {
|
|
63113
|
+
if (statSync3(candidate).isFile()) {
|
|
63114
|
+
accessSync2(candidate, constants3.X_OK);
|
|
63115
|
+
return candidate;
|
|
63116
|
+
}
|
|
63117
|
+
} catch {
|
|
63118
|
+
}
|
|
63119
|
+
}
|
|
63120
|
+
return null;
|
|
63121
|
+
}
|
|
63122
|
+
function captureStdout(command, args, timeoutMs, env3) {
|
|
63123
|
+
return new Promise((resolve6) => {
|
|
63124
|
+
let stdout = "";
|
|
63125
|
+
let settled = false;
|
|
63126
|
+
let child;
|
|
63127
|
+
let grace;
|
|
63128
|
+
const finish = (value) => {
|
|
63129
|
+
if (settled) {
|
|
63130
|
+
return;
|
|
63131
|
+
}
|
|
63132
|
+
settled = true;
|
|
63133
|
+
clearTimeout(timer);
|
|
63134
|
+
if (grace !== void 0) {
|
|
63135
|
+
clearTimeout(grace);
|
|
63136
|
+
}
|
|
63137
|
+
child?.stdout?.destroy();
|
|
63138
|
+
child?.stderr?.destroy();
|
|
63139
|
+
resolve6(value);
|
|
63140
|
+
};
|
|
63141
|
+
const timer = setTimeout(() => {
|
|
63142
|
+
child?.kill("SIGKILL");
|
|
63143
|
+
finish(null);
|
|
63144
|
+
}, timeoutMs);
|
|
63145
|
+
try {
|
|
63146
|
+
child = spawn4(command, args, { env: env3, stdio: ["ignore", "pipe", "pipe"] });
|
|
63147
|
+
} catch {
|
|
63148
|
+
finish(null);
|
|
63149
|
+
return;
|
|
63150
|
+
}
|
|
63151
|
+
child.stdout?.setEncoding("utf8");
|
|
63152
|
+
child.stdout?.on("data", (chunk) => {
|
|
63153
|
+
if (stdout.length < MAX_CAPTURE_CHARS) {
|
|
63154
|
+
stdout += chunk;
|
|
63155
|
+
}
|
|
63156
|
+
});
|
|
63157
|
+
child.stderr?.resume();
|
|
63158
|
+
child.on("error", () => finish(null));
|
|
63159
|
+
child.on("close", () => finish(stdout));
|
|
63160
|
+
child.on("exit", () => {
|
|
63161
|
+
grace = setTimeout(() => finish(stdout), EXIT_GRACE_MS);
|
|
63162
|
+
});
|
|
63163
|
+
});
|
|
63164
|
+
}
|
|
63165
|
+
var BINDING_LINE = /^__qq_(emacs|viins)__ (.*)$/gm;
|
|
63166
|
+
var BOUND_WIDGET = /^"\?" ([A-Za-z0-9_.:+-]{1,64})$/;
|
|
63167
|
+
function parseZshBindings(output) {
|
|
63168
|
+
const result = { emacs: null, viins: null };
|
|
63169
|
+
let seen = false;
|
|
63170
|
+
for (const match of output.matchAll(BINDING_LINE)) {
|
|
63171
|
+
seen = true;
|
|
63172
|
+
const keymap = match[1];
|
|
63173
|
+
const widget = BOUND_WIDGET.exec(match[2]?.trim() ?? "");
|
|
63174
|
+
result[keymap] = widget?.[1] ?? null;
|
|
63175
|
+
}
|
|
63176
|
+
return seen ? result : null;
|
|
63177
|
+
}
|
|
63178
|
+
var BINDINGS_SCRIPT = `print -r -- "__qq_emacs__ $(bindkey -M emacs '?')"; print -r -- "__qq_viins__ $(bindkey -M viins '?')"`;
|
|
63179
|
+
function probeTmpDir() {
|
|
63180
|
+
try {
|
|
63181
|
+
if (!statSync3("/tmp").isDirectory()) {
|
|
63182
|
+
return false;
|
|
63183
|
+
}
|
|
63184
|
+
accessSync2("/tmp", constants3.W_OK);
|
|
63185
|
+
const dir = mkdtempSync("/tmp/qq-doctor-");
|
|
63186
|
+
rmSync(dir, { recursive: true, force: true });
|
|
63187
|
+
return true;
|
|
63188
|
+
} catch {
|
|
63189
|
+
return false;
|
|
63190
|
+
}
|
|
63191
|
+
}
|
|
63192
|
+
function lstatOwner(path5) {
|
|
63193
|
+
try {
|
|
63194
|
+
return lstatSync2(path5).uid;
|
|
63195
|
+
} catch {
|
|
63196
|
+
return null;
|
|
63197
|
+
}
|
|
63198
|
+
}
|
|
63199
|
+
function defaultDoctorDeps() {
|
|
63200
|
+
const env3 = process.env;
|
|
63201
|
+
const homeDir = homedir7();
|
|
63202
|
+
return {
|
|
63203
|
+
env: env3,
|
|
63204
|
+
platform: process.platform,
|
|
63205
|
+
homeDir,
|
|
63206
|
+
uid: process.getuid?.() ?? 0,
|
|
63207
|
+
socketPath: socketPath(),
|
|
63208
|
+
nodeVersion: process.versions.node,
|
|
63209
|
+
qqVersion: "0.8.1",
|
|
63210
|
+
which: (name) => whichOnPath(name, env3.PATH),
|
|
63211
|
+
zshVersion: async () => {
|
|
63212
|
+
const out = await captureStdout(
|
|
63213
|
+
"zsh",
|
|
63214
|
+
["-fc", "print -r -- $ZSH_VERSION"],
|
|
63215
|
+
ZSH_VERSION_TIMEOUT_MS,
|
|
63216
|
+
env3
|
|
63217
|
+
);
|
|
63218
|
+
return out?.trim() || null;
|
|
63219
|
+
},
|
|
63220
|
+
zshBindings: async () => {
|
|
63221
|
+
const out = await captureStdout("zsh", ["-ic", BINDINGS_SCRIPT], ZSH_BINDINGS_TIMEOUT_MS, {
|
|
63222
|
+
...env3,
|
|
63223
|
+
QQ_DAEMON_PREWARMED: "1"
|
|
63224
|
+
});
|
|
63225
|
+
return out === null ? null : parseZshBindings(out);
|
|
63226
|
+
},
|
|
63227
|
+
readZshrc: () => {
|
|
63228
|
+
try {
|
|
63229
|
+
return readFileSync8(join6(homeDir, ".zshrc"), "utf8");
|
|
63230
|
+
} catch {
|
|
63231
|
+
return null;
|
|
63232
|
+
}
|
|
63233
|
+
},
|
|
63234
|
+
probeTmp: probeTmpDir,
|
|
63235
|
+
socketOwner: lstatOwner,
|
|
63236
|
+
pingDaemon: pingDaemonFetchCap,
|
|
63237
|
+
socketConnectable: tryConnect,
|
|
63238
|
+
loadProviderPin,
|
|
63239
|
+
detectProvider,
|
|
63240
|
+
telemetryStatus: () => ({
|
|
63241
|
+
blockedBy: telemetryBlockedBy(env3),
|
|
63242
|
+
state: readTelemetryState(),
|
|
63243
|
+
keyPresent: resolveTelemetryEndpoint(env3) !== null
|
|
63244
|
+
})
|
|
63245
|
+
};
|
|
63246
|
+
}
|
|
63247
|
+
var VERSION_PREFIX = /^\d+(?:\.\d+)*/;
|
|
63248
|
+
function versionParts(text) {
|
|
63249
|
+
const match = VERSION_PREFIX.exec(text.trim());
|
|
63250
|
+
return match ? match[0].split(".").map(Number) : null;
|
|
63251
|
+
}
|
|
63252
|
+
function versionBelow(version3, threshold) {
|
|
63253
|
+
const floor = threshold.split(".").map(Number);
|
|
63254
|
+
for (let i = 0; i < Math.max(version3.length, floor.length); i++) {
|
|
63255
|
+
const a = version3[i] ?? 0;
|
|
63256
|
+
const b = floor[i] ?? 0;
|
|
63257
|
+
if (a !== b) {
|
|
63258
|
+
return a < b;
|
|
63259
|
+
}
|
|
63260
|
+
}
|
|
63261
|
+
return false;
|
|
63262
|
+
}
|
|
63263
|
+
var ok = (id, summary) => ({ id, status: "ok", summary });
|
|
63264
|
+
var warn = (id, summary, hint) => ({
|
|
63265
|
+
id,
|
|
63266
|
+
status: "warn",
|
|
63267
|
+
summary,
|
|
63268
|
+
hint
|
|
63269
|
+
});
|
|
63270
|
+
var fail = (id, summary, hint) => ({
|
|
63271
|
+
id,
|
|
63272
|
+
status: "fail",
|
|
63273
|
+
summary,
|
|
63274
|
+
hint
|
|
63275
|
+
});
|
|
63276
|
+
var ZSH_INSTALL_HINT = `install zsh ${ZSH_WARN_BELOW} or newer`;
|
|
63277
|
+
async function checkZsh(deps) {
|
|
63278
|
+
if (deps.which("zsh") === null) {
|
|
63279
|
+
return fail("zsh", "zsh not found on PATH", ZSH_INSTALL_HINT);
|
|
63280
|
+
}
|
|
63281
|
+
const raw = await deps.zshVersion();
|
|
63282
|
+
const parts = raw === null ? null : versionParts(raw);
|
|
63283
|
+
if (parts === null) {
|
|
63284
|
+
return warn("zsh", "zsh is on PATH but its version could not be read", ZSH_INSTALL_HINT);
|
|
63285
|
+
}
|
|
63286
|
+
const version3 = parts.join(".");
|
|
63287
|
+
if (versionBelow(parts, ZSH_FAIL_BELOW)) {
|
|
63288
|
+
return fail("zsh", `zsh ${version3} is older than ${ZSH_FAIL_BELOW}`, ZSH_INSTALL_HINT);
|
|
63289
|
+
}
|
|
63290
|
+
if (versionBelow(parts, ZSH_WARN_BELOW)) {
|
|
63291
|
+
return warn(
|
|
63292
|
+
"zsh",
|
|
63293
|
+
`zsh ${version3} is untested (oldest tested is ${ZSH_WARN_BELOW})`,
|
|
63294
|
+
ZSH_INSTALL_HINT
|
|
63295
|
+
);
|
|
63296
|
+
}
|
|
63297
|
+
return ok("zsh", `zsh ${version3}`);
|
|
63298
|
+
}
|
|
63299
|
+
function checkJq(deps) {
|
|
63300
|
+
if (deps.which("jq") === null) {
|
|
63301
|
+
return fail(
|
|
63302
|
+
"jq",
|
|
63303
|
+
"jq not found on PATH (the ?? widget builds and parses JSON with it)",
|
|
63304
|
+
"install jq with your package manager"
|
|
63305
|
+
);
|
|
63306
|
+
}
|
|
63307
|
+
return ok("jq", "jq found");
|
|
63308
|
+
}
|
|
63309
|
+
function checkTmp(deps) {
|
|
63310
|
+
if (!deps.probeTmp()) {
|
|
63311
|
+
return fail(
|
|
63312
|
+
"tmp",
|
|
63313
|
+
"/tmp is not a writable directory",
|
|
63314
|
+
"make /tmp a writable directory (chmod 1777 /tmp)"
|
|
63315
|
+
);
|
|
63316
|
+
}
|
|
63317
|
+
return ok("tmp", "/tmp is writable");
|
|
63318
|
+
}
|
|
63319
|
+
function checkSocket(deps) {
|
|
63320
|
+
const limit = deps.platform === "linux" || deps.platform === "darwin" ? SOCKET_PATH_MAX_BYTES[deps.platform] : SOCKET_PATH_MAX_DEFAULT;
|
|
63321
|
+
const bytes = Buffer.byteLength(deps.socketPath);
|
|
63322
|
+
if (bytes > limit) {
|
|
63323
|
+
return fail(
|
|
63324
|
+
"socket",
|
|
63325
|
+
`daemon socket path is ${bytes} bytes, over the ${limit}-byte limit`,
|
|
63326
|
+
"report this as a QueQue bug: the socket path must be shorter"
|
|
63327
|
+
);
|
|
63328
|
+
}
|
|
63329
|
+
const owner = deps.socketOwner(deps.socketPath);
|
|
63330
|
+
if (owner !== null && owner !== deps.uid) {
|
|
63331
|
+
return fail(
|
|
63332
|
+
"socket",
|
|
63333
|
+
`${deps.socketPath} is owned by another user`,
|
|
63334
|
+
`remove ${deps.socketPath} (as its owner or root), then retry ??`
|
|
63335
|
+
);
|
|
63336
|
+
}
|
|
63337
|
+
return ok("socket", `daemon socket ${deps.socketPath}`);
|
|
63338
|
+
}
|
|
63339
|
+
async function checkDaemon(deps) {
|
|
63340
|
+
let state;
|
|
63341
|
+
try {
|
|
63342
|
+
state = await deps.pingDaemon(deps.socketPath);
|
|
63343
|
+
} catch {
|
|
63344
|
+
state = "unknown";
|
|
63345
|
+
}
|
|
63346
|
+
if (state === "yes") {
|
|
63347
|
+
return ok("daemon", "daemon running");
|
|
63348
|
+
}
|
|
63349
|
+
if (state === "no") {
|
|
63350
|
+
return warn(
|
|
63351
|
+
"daemon",
|
|
63352
|
+
"daemon outdated; replaced on the next ??",
|
|
63353
|
+
"nothing to do, or run `qq daemon --ensure` now"
|
|
63354
|
+
);
|
|
63355
|
+
}
|
|
63356
|
+
let connectable = false;
|
|
63357
|
+
try {
|
|
63358
|
+
connectable = await deps.socketConnectable(deps.socketPath);
|
|
63359
|
+
} catch {
|
|
63360
|
+
connectable = false;
|
|
63361
|
+
}
|
|
63362
|
+
if (connectable) {
|
|
63363
|
+
return warn(
|
|
63364
|
+
"daemon",
|
|
63365
|
+
`a process accepts connections on ${deps.socketPath} but does not answer the daemon ping`,
|
|
63366
|
+
`stop the process holding ${deps.socketPath} (lsof -t ${deps.socketPath}); the next ?? starts a fresh daemon`
|
|
63367
|
+
);
|
|
63368
|
+
}
|
|
63369
|
+
return ok("daemon", "daemon not running; starts on the next ??");
|
|
63370
|
+
}
|
|
63371
|
+
function checkIntegration(deps) {
|
|
63372
|
+
if (!hasShellIntegration(deps.readZshrc() ?? "", "zsh")) {
|
|
63373
|
+
return warn("integration", "~/.zshrc does not load QueQue", "qq init zsh && source ~/.zshrc");
|
|
63374
|
+
}
|
|
63375
|
+
return ok("integration", "~/.zshrc loads QueQue");
|
|
63376
|
+
}
|
|
63377
|
+
async function checkBinding(deps) {
|
|
63378
|
+
let bindings;
|
|
63379
|
+
try {
|
|
63380
|
+
bindings = await deps.zshBindings();
|
|
63381
|
+
} catch {
|
|
63382
|
+
bindings = null;
|
|
63383
|
+
}
|
|
63384
|
+
const hint = "qq init zsh && source ~/.zshrc, then check plugins that rebind ?";
|
|
63385
|
+
if (bindings === null) {
|
|
63386
|
+
return warn("binding", "could not read the ? key bindings from an interactive zsh", hint);
|
|
63387
|
+
}
|
|
63388
|
+
for (const keymap of ["emacs", "viins"]) {
|
|
63389
|
+
const widget = bindings[keymap];
|
|
63390
|
+
if (widget === null) {
|
|
63391
|
+
return warn("binding", `? has no readable binding in the ${keymap} keymap`, hint);
|
|
63392
|
+
}
|
|
63393
|
+
if (widget !== QQ_WIDGET) {
|
|
63394
|
+
return warn("binding", `? is bound to ${widget} in the ${keymap} keymap`, hint);
|
|
63395
|
+
}
|
|
63396
|
+
}
|
|
63397
|
+
return ok("binding", `? is bound to ${QQ_WIDGET} in emacs and viins`);
|
|
63398
|
+
}
|
|
63399
|
+
function checkTerm(deps) {
|
|
63400
|
+
const term = deps.env.TERM;
|
|
63401
|
+
const hint = "run ?? in a terminal emulator that sets TERM (e.g. xterm-256color)";
|
|
63402
|
+
if (!term) {
|
|
63403
|
+
return warn("term", "TERM is not set", hint);
|
|
63404
|
+
}
|
|
63405
|
+
if (term === "dumb") {
|
|
63406
|
+
return warn("term", "TERM is dumb", hint);
|
|
63407
|
+
}
|
|
63408
|
+
return ok("term", "TERM is set");
|
|
63409
|
+
}
|
|
63410
|
+
function checkLocale(deps) {
|
|
63411
|
+
const names = ["LC_ALL", "LC_CTYPE", "LANG"];
|
|
63412
|
+
const source = names.find((name) => deps.env[name]);
|
|
63413
|
+
const value = source ? deps.env[source] : void 0;
|
|
63414
|
+
if (source && value && /utf-?8/i.test(value)) {
|
|
63415
|
+
return ok("locale", `locale is UTF-8 (from ${source})`);
|
|
63416
|
+
}
|
|
63417
|
+
return warn(
|
|
63418
|
+
"locale",
|
|
63419
|
+
source ? `locale is not UTF-8 (from ${source}); non-ASCII text may render badly` : "no locale set (LC_ALL, LC_CTYPE, LANG); non-ASCII text may render badly",
|
|
63420
|
+
"export LANG=en_US.UTF-8 (or another UTF-8 locale)"
|
|
63421
|
+
);
|
|
63422
|
+
}
|
|
63423
|
+
var PROVIDER_HINT = "run `claude /login`, set ANTHROPIC_API_KEY, or run `qq init provider`";
|
|
63424
|
+
var DETECTED_NAMES = {
|
|
63425
|
+
"anthropic-key": "Claude (ANTHROPIC_API_KEY)",
|
|
63426
|
+
"claude-cli": "Claude CLI login",
|
|
63427
|
+
ollama: "Ollama",
|
|
63428
|
+
"openai-key": "OpenAI (OPENAI_API_KEY)"
|
|
63429
|
+
};
|
|
63430
|
+
async function checkProvider(deps) {
|
|
63431
|
+
let pin;
|
|
63432
|
+
try {
|
|
63433
|
+
pin = deps.loadProviderPin();
|
|
63434
|
+
} catch {
|
|
63435
|
+
pin = { kind: "invalid", path: "", message: "" };
|
|
63436
|
+
}
|
|
63437
|
+
if (pin.kind === "pinned") {
|
|
63438
|
+
return ok("provider", `provider pinned to ${pin.pin.provider}`);
|
|
63439
|
+
}
|
|
63440
|
+
if (pin.kind === "invalid") {
|
|
63441
|
+
return warn("provider", "provider pin is invalid", "run `qq init provider` to rewrite it");
|
|
63442
|
+
}
|
|
63443
|
+
let detected;
|
|
63444
|
+
try {
|
|
63445
|
+
detected = await deps.detectProvider();
|
|
63446
|
+
} catch {
|
|
63447
|
+
return warn("provider", "could not detect an AI provider", PROVIDER_HINT);
|
|
63448
|
+
}
|
|
63449
|
+
if (detected.kind === "none") {
|
|
63450
|
+
return warn("provider", "no AI provider configured", PROVIDER_HINT);
|
|
63451
|
+
}
|
|
63452
|
+
return ok("provider", `provider detected: ${DETECTED_NAMES[detected.kind]}`);
|
|
63453
|
+
}
|
|
63454
|
+
function checkNode(deps) {
|
|
63455
|
+
const parts = versionParts(deps.nodeVersion);
|
|
63456
|
+
if (parts === null) {
|
|
63457
|
+
return warn(
|
|
63458
|
+
"node",
|
|
63459
|
+
"Node version could not be read",
|
|
63460
|
+
`install Node ${NODE_WARN_BELOW_MAJOR} LTS`
|
|
63461
|
+
);
|
|
63462
|
+
}
|
|
63463
|
+
const version3 = parts.join(".");
|
|
63464
|
+
if ((parts[0] ?? 0) < NODE_WARN_BELOW_MAJOR) {
|
|
63465
|
+
return warn(
|
|
63466
|
+
"node",
|
|
63467
|
+
`Node ${version3} is older than ${NODE_WARN_BELOW_MAJOR}`,
|
|
63468
|
+
`install Node ${NODE_WARN_BELOW_MAJOR} LTS`
|
|
63469
|
+
);
|
|
63470
|
+
}
|
|
63471
|
+
return ok("node", `Node ${version3}`);
|
|
63472
|
+
}
|
|
63473
|
+
function checkTelemetry(deps) {
|
|
63474
|
+
let status;
|
|
63475
|
+
try {
|
|
63476
|
+
status = deps.telemetryStatus();
|
|
63477
|
+
} catch {
|
|
63478
|
+
return ok("telemetry", "telemetry state could not be read (treated as off)");
|
|
63479
|
+
}
|
|
63480
|
+
if (status.blockedBy !== null) {
|
|
63481
|
+
return ok("telemetry", `telemetry off (${status.blockedBy} is set)`);
|
|
63482
|
+
}
|
|
63483
|
+
if (!status.state.enabled || status.state.installId === void 0) {
|
|
63484
|
+
return ok("telemetry", status.state.asked ? "telemetry off" : "telemetry off (not asked yet)");
|
|
63485
|
+
}
|
|
63486
|
+
return ok(
|
|
63487
|
+
"telemetry",
|
|
63488
|
+
status.keyPresent ? "telemetry on" : "telemetry on (no project key in this build: nothing is sent)"
|
|
63489
|
+
);
|
|
63490
|
+
}
|
|
63491
|
+
function reportPlatform(platform2) {
|
|
63492
|
+
return platform2 === "darwin" || platform2 === "linux" ? platform2 : "other";
|
|
63493
|
+
}
|
|
63494
|
+
async function runDoctorChecks(deps = defaultDoctorDeps()) {
|
|
63495
|
+
const [zsh, daemon, binding, provider] = await Promise.all([
|
|
63496
|
+
checkZsh(deps),
|
|
63497
|
+
checkDaemon(deps),
|
|
63498
|
+
checkBinding(deps),
|
|
63499
|
+
checkProvider(deps)
|
|
63500
|
+
]);
|
|
63501
|
+
const checks = [
|
|
63502
|
+
zsh,
|
|
63503
|
+
checkJq(deps),
|
|
63504
|
+
checkTmp(deps),
|
|
63505
|
+
checkSocket(deps),
|
|
63506
|
+
daemon,
|
|
63507
|
+
checkIntegration(deps),
|
|
63508
|
+
binding,
|
|
63509
|
+
checkTerm(deps),
|
|
63510
|
+
checkLocale(deps),
|
|
63511
|
+
provider,
|
|
63512
|
+
checkNode(deps),
|
|
63513
|
+
checkTelemetry(deps)
|
|
63514
|
+
];
|
|
63515
|
+
return doctorReportSchema.parse({
|
|
63516
|
+
version: 1,
|
|
63517
|
+
ok: !checks.some((check3) => check3.status === "fail"),
|
|
63518
|
+
qqVersion: deps.qqVersion,
|
|
63519
|
+
platform: reportPlatform(deps.platform),
|
|
63520
|
+
checks
|
|
63521
|
+
});
|
|
63522
|
+
}
|
|
63523
|
+
var STATUS_MARKS = { ok: "\u2713", warn: "\u26A0", fail: "\u2717" };
|
|
63524
|
+
function formatDoctorReport(report) {
|
|
63525
|
+
const lines = report.checks.map((check3) => {
|
|
63526
|
+
const line = `${STATUS_MARKS[check3.status]} ${check3.summary}`;
|
|
63527
|
+
return check3.status !== "ok" && check3.hint ? `${line} \u2014 fix: ${check3.hint}` : line;
|
|
63528
|
+
});
|
|
63529
|
+
const problems = report.checks.filter((check3) => check3.status !== "ok").length;
|
|
63530
|
+
lines.push(
|
|
63531
|
+
problems === 0 ? "qq doctor: no problems found" : `qq doctor: ${problems} problem${problems === 1 ? "" : "s"} found`
|
|
63532
|
+
);
|
|
63533
|
+
return `${lines.join("\n")}
|
|
63534
|
+
`;
|
|
63535
|
+
}
|
|
63536
|
+
async function doctorCommand(options, deps) {
|
|
63537
|
+
const report = await runDoctorChecks(deps ?? defaultDoctorDeps());
|
|
63538
|
+
process.stdout.write(
|
|
63539
|
+
options.json ? `${JSON.stringify(report, null, 2)}
|
|
63540
|
+
` : formatDoctorReport(report)
|
|
63541
|
+
);
|
|
63542
|
+
process.exitCode = doctorExitCode(report);
|
|
63543
|
+
}
|
|
63544
|
+
|
|
62073
63545
|
// src/cli/commands/init-provider.ts
|
|
63546
|
+
import { spawn as spawn5 } from "child_process";
|
|
63547
|
+
import { closeSync, openSync } from "fs";
|
|
63548
|
+
import { homedir as homedir8 } from "os";
|
|
63549
|
+
import { createInterface } from "readline";
|
|
63550
|
+
import * as tty4 from "tty";
|
|
62074
63551
|
var PROVIDER_MENU = [
|
|
62075
63552
|
{
|
|
62076
63553
|
id: "claude",
|
|
@@ -62093,7 +63570,7 @@ function openDownloadUrl(url2) {
|
|
|
62093
63570
|
}
|
|
62094
63571
|
const opener = process.platform === "darwin" ? "open" : "xdg-open";
|
|
62095
63572
|
try {
|
|
62096
|
-
const child =
|
|
63573
|
+
const child = spawn5(opener, [url2], { stdio: "ignore", detached: true });
|
|
62097
63574
|
child.on("error", () => void 0);
|
|
62098
63575
|
child.unref();
|
|
62099
63576
|
} catch {
|
|
@@ -62181,7 +63658,7 @@ function describeCurrent(prompter, state) {
|
|
|
62181
63658
|
}
|
|
62182
63659
|
}
|
|
62183
63660
|
function openAiKeyPresent() {
|
|
62184
|
-
return (usableSecret(process.env.OPENAI_API_KEY) ?? usableSecret(readEnvValueFromDotEnvLocal("OPENAI_API_KEY",
|
|
63661
|
+
return (usableSecret(process.env.OPENAI_API_KEY) ?? usableSecret(readEnvValueFromDotEnvLocal("OPENAI_API_KEY", homedir8()))) !== void 0;
|
|
62185
63662
|
}
|
|
62186
63663
|
function keptPinFields(state) {
|
|
62187
63664
|
if (state.kind !== "pinned") {
|
|
@@ -62329,8 +63806,8 @@ async function runProviderPicker(io, deps = {}) {
|
|
|
62329
63806
|
}
|
|
62330
63807
|
}
|
|
62331
63808
|
function endStream(stream) {
|
|
62332
|
-
return new Promise((
|
|
62333
|
-
stream.end(() =>
|
|
63809
|
+
return new Promise((resolve6) => {
|
|
63810
|
+
stream.end(() => resolve6());
|
|
62334
63811
|
});
|
|
62335
63812
|
}
|
|
62336
63813
|
function openTerminal() {
|
|
@@ -62370,6 +63847,178 @@ async function dispatchInit(shell, handlers = { provider: providerInitCommand, s
|
|
|
62370
63847
|
handlers.shell(shell);
|
|
62371
63848
|
}
|
|
62372
63849
|
|
|
63850
|
+
// src/cli/commands/telemetry.ts
|
|
63851
|
+
import * as net5 from "net";
|
|
63852
|
+
var DAEMON_REQUEST_TIMEOUT_MS = 500;
|
|
63853
|
+
var USAGE = "usage: qq telemetry [status|on|off|show]";
|
|
63854
|
+
var DAEMON_NOT_RUNNING = "daemon not running: nothing buffered";
|
|
63855
|
+
var NO_KEY_NOTE = "note: this build has no project key, so nothing is sent";
|
|
63856
|
+
function requestDaemonOnce(socketPath2, request, timeoutMs = DAEMON_REQUEST_TIMEOUT_MS) {
|
|
63857
|
+
return new Promise((resolve6) => {
|
|
63858
|
+
let settled = false;
|
|
63859
|
+
let buf = "";
|
|
63860
|
+
const done = (response) => {
|
|
63861
|
+
if (settled) {
|
|
63862
|
+
return;
|
|
63863
|
+
}
|
|
63864
|
+
settled = true;
|
|
63865
|
+
clearTimeout(timer);
|
|
63866
|
+
client.destroy();
|
|
63867
|
+
resolve6(response);
|
|
63868
|
+
};
|
|
63869
|
+
const client = net5.createConnection(socketPath2);
|
|
63870
|
+
const timer = setTimeout(() => {
|
|
63871
|
+
done(null);
|
|
63872
|
+
}, timeoutMs);
|
|
63873
|
+
client.on("connect", () => {
|
|
63874
|
+
client.write(`${JSON.stringify(request)}
|
|
63875
|
+
`);
|
|
63876
|
+
});
|
|
63877
|
+
client.on("data", (chunk) => {
|
|
63878
|
+
buf += chunk.toString();
|
|
63879
|
+
const nl = buf.indexOf("\n");
|
|
63880
|
+
if (nl === -1) {
|
|
63881
|
+
return;
|
|
63882
|
+
}
|
|
63883
|
+
let parsed;
|
|
63884
|
+
try {
|
|
63885
|
+
parsed = JSON.parse(buf.slice(0, nl));
|
|
63886
|
+
} catch {
|
|
63887
|
+
done(null);
|
|
63888
|
+
return;
|
|
63889
|
+
}
|
|
63890
|
+
const response = ipcResponseSchema.safeParse(parsed);
|
|
63891
|
+
done(response.success ? response.data : null);
|
|
63892
|
+
});
|
|
63893
|
+
client.on("error", () => {
|
|
63894
|
+
done(null);
|
|
63895
|
+
});
|
|
63896
|
+
client.on("close", () => {
|
|
63897
|
+
done(null);
|
|
63898
|
+
});
|
|
63899
|
+
});
|
|
63900
|
+
}
|
|
63901
|
+
function defaultTelemetryCliDeps() {
|
|
63902
|
+
const socket = socketPath();
|
|
63903
|
+
return {
|
|
63904
|
+
env: process.env,
|
|
63905
|
+
socketPath: socket,
|
|
63906
|
+
endpoint: () => resolveTelemetryEndpoint(process.env),
|
|
63907
|
+
requestDaemon: (request) => requestDaemonOnce(socket, request),
|
|
63908
|
+
out: (text) => {
|
|
63909
|
+
process.stdout.write(text);
|
|
63910
|
+
},
|
|
63911
|
+
err: (text) => {
|
|
63912
|
+
process.stderr.write(text);
|
|
63913
|
+
}
|
|
63914
|
+
};
|
|
63915
|
+
}
|
|
63916
|
+
function endpointHost(deps, endpoint) {
|
|
63917
|
+
const raw = endpoint?.host ?? usableSecret(deps.env.QQ_TELEMETRY_HOST) ?? "https://eu.i.posthog.com";
|
|
63918
|
+
try {
|
|
63919
|
+
const url2 = new URL(raw);
|
|
63920
|
+
if ((url2.protocol === "https:" || url2.protocol === "http:") && url2.host !== "") {
|
|
63921
|
+
return url2.host;
|
|
63922
|
+
}
|
|
63923
|
+
} catch {
|
|
63924
|
+
}
|
|
63925
|
+
return "not configured";
|
|
63926
|
+
}
|
|
63927
|
+
function printStatus(deps, configPath) {
|
|
63928
|
+
const blockedBy = telemetryBlockedBy(deps.env);
|
|
63929
|
+
const state = readTelemetryState(configPath);
|
|
63930
|
+
const configOn = state.enabled && state.installId !== void 0;
|
|
63931
|
+
const endpoint = deps.endpoint();
|
|
63932
|
+
const lines = [`telemetry: ${blockedBy === null && configOn ? "on" : "off"}`];
|
|
63933
|
+
if (blockedBy !== null) {
|
|
63934
|
+
lines.push(`reason: ${blockedBy} is set (it overrides the config)`);
|
|
63935
|
+
} else if (!configOn) {
|
|
63936
|
+
lines.push("reason: not turned on (run `qq telemetry on`)");
|
|
63937
|
+
}
|
|
63938
|
+
lines.push(
|
|
63939
|
+
`config: ${configOn ? "on" : "off"}`,
|
|
63940
|
+
`asked: ${state.asked ? "yes" : "no"}`,
|
|
63941
|
+
`project key: ${endpoint === null ? "absent in this build (nothing is sent)" : "present"}`,
|
|
63942
|
+
`endpoint: ${endpointHost(deps, endpoint)}`
|
|
63943
|
+
);
|
|
63944
|
+
deps.out(`${lines.join("\n")}
|
|
63945
|
+
`);
|
|
63946
|
+
}
|
|
63947
|
+
function turnOn(deps, configPath) {
|
|
63948
|
+
setTelemetryEnabled(true, configPath);
|
|
63949
|
+
const lines = ["telemetry: on"];
|
|
63950
|
+
const blockedBy = telemetryBlockedBy(deps.env);
|
|
63951
|
+
if (blockedBy !== null) {
|
|
63952
|
+
lines.push(`note: ${blockedBy} is set, so telemetry stays off until it is unset`);
|
|
63953
|
+
}
|
|
63954
|
+
if (deps.endpoint() === null) {
|
|
63955
|
+
lines.push(NO_KEY_NOTE);
|
|
63956
|
+
}
|
|
63957
|
+
lines.push("see what would be sent: qq telemetry show");
|
|
63958
|
+
deps.out(`${lines.join("\n")}
|
|
63959
|
+
`);
|
|
63960
|
+
}
|
|
63961
|
+
async function turnOff(deps, configPath) {
|
|
63962
|
+
setTelemetryEnabled(false, configPath);
|
|
63963
|
+
const reply = await deps.requestDaemon({ kind: "telemetry-reset" });
|
|
63964
|
+
const lines = ["telemetry: off", "install id deleted"];
|
|
63965
|
+
if (reply?.kind === "telemetry-buffer") {
|
|
63966
|
+
lines.push("daemon buffer cleared");
|
|
63967
|
+
}
|
|
63968
|
+
deps.out(`${lines.join("\n")}
|
|
63969
|
+
`);
|
|
63970
|
+
}
|
|
63971
|
+
async function show(deps) {
|
|
63972
|
+
const reply = await deps.requestDaemon({ kind: "telemetry-show" });
|
|
63973
|
+
if (reply === null) {
|
|
63974
|
+
deps.out(`${DAEMON_NOT_RUNNING}
|
|
63975
|
+
`);
|
|
63976
|
+
return;
|
|
63977
|
+
}
|
|
63978
|
+
if (reply.kind !== "telemetry-buffer") {
|
|
63979
|
+
deps.out("the daemon did not return a telemetry buffer (it may be outdated): nothing shown\n");
|
|
63980
|
+
return;
|
|
63981
|
+
}
|
|
63982
|
+
deps.out(`pending:
|
|
63983
|
+
${reply.pending ?? "(none)"}
|
|
63984
|
+
last sent:
|
|
63985
|
+
${reply.lastSent ?? "(none)"}
|
|
63986
|
+
`);
|
|
63987
|
+
}
|
|
63988
|
+
async function telemetryCommand(action, deps = defaultTelemetryCliDeps()) {
|
|
63989
|
+
const configPath = deps.configPath ?? defaultConfigPath();
|
|
63990
|
+
try {
|
|
63991
|
+
switch (action ?? "status") {
|
|
63992
|
+
case "status":
|
|
63993
|
+
printStatus(deps, configPath);
|
|
63994
|
+
return;
|
|
63995
|
+
case "on":
|
|
63996
|
+
turnOn(deps, configPath);
|
|
63997
|
+
return;
|
|
63998
|
+
case "off":
|
|
63999
|
+
await turnOff(deps, configPath);
|
|
64000
|
+
return;
|
|
64001
|
+
case "show":
|
|
64002
|
+
await show(deps);
|
|
64003
|
+
return;
|
|
64004
|
+
default:
|
|
64005
|
+
deps.err(`qq telemetry: unknown telemetry action
|
|
64006
|
+
${USAGE}
|
|
64007
|
+
`);
|
|
64008
|
+
process.exitCode = 1;
|
|
64009
|
+
return;
|
|
64010
|
+
}
|
|
64011
|
+
} catch (error43) {
|
|
64012
|
+
if (error43 instanceof TelemetryConfigWriteError) {
|
|
64013
|
+
deps.err(`${error43.message}
|
|
64014
|
+
`);
|
|
64015
|
+
process.exitCode = 1;
|
|
64016
|
+
return;
|
|
64017
|
+
}
|
|
64018
|
+
throw error43;
|
|
64019
|
+
}
|
|
64020
|
+
}
|
|
64021
|
+
|
|
62373
64022
|
// src/cli/main.ts
|
|
62374
64023
|
function requiredOption(name, value) {
|
|
62375
64024
|
if (!value) {
|
|
@@ -62416,6 +64065,12 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
62416
64065
|
).action(async (shell) => {
|
|
62417
64066
|
await dispatchInit(shell);
|
|
62418
64067
|
});
|
|
64068
|
+
cli.command("doctor", "Check this machine for problems that stop ??").option("--json", "Print the report as JSON").action(async (options) => {
|
|
64069
|
+
await doctorCommand({ json: options.json });
|
|
64070
|
+
});
|
|
64071
|
+
cli.command("telemetry [action]", "Anonymous usage and error counts: status, on, off or show").action(async (action) => {
|
|
64072
|
+
await telemetryCommand(action);
|
|
64073
|
+
});
|
|
62419
64074
|
cli.command("daemon").option("--socket <path>", "Unix socket path for the daemon").option("--ensure", "Ensure the daemon is running before returning").action(async (options) => {
|
|
62420
64075
|
await daemonCommand(options);
|
|
62421
64076
|
});
|