@fitchmultz/pi-ask-question 0.6.3 → 0.6.5
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/CHANGELOG.md +31 -3
- package/extensions/ask-question.ts +999 -706
- package/extensions/lib/question-observer.ts +58 -17
- package/package.json +10 -2
|
@@ -17,7 +17,7 @@ type Waiting = Target & {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
function record(data: unknown): Record<string, unknown> | undefined {
|
|
20
|
-
return data !== null && typeof data === "object" ? data as Record<string, unknown> : undefined;
|
|
20
|
+
return data !== null && typeof data === "object" ? (data as Record<string, unknown>) : undefined;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function validId(value: unknown): value is string {
|
|
@@ -41,25 +41,46 @@ export function createQuestionObserver(pi: ExtensionAPI) {
|
|
|
41
41
|
const unsubscribeQuery = pi.events.on("pi-ask-question:query", (data) => {
|
|
42
42
|
const query = record(data);
|
|
43
43
|
if (!query || !validId(query.queryId)) return;
|
|
44
|
-
const waiting =
|
|
44
|
+
const waiting =
|
|
45
|
+
query.protocolVersion === protocolVersion && mode === "tui" ? current?.() : undefined;
|
|
45
46
|
pi.events.emit("pi-ask-question:snapshot", {
|
|
46
|
-
queryId: query.queryId,
|
|
47
|
+
queryId: query.queryId,
|
|
48
|
+
...identity(),
|
|
49
|
+
mode,
|
|
47
50
|
status: query.protocolVersion !== protocolVersion || mode !== "tui" ? "unsupported" : "idle",
|
|
48
51
|
...waiting,
|
|
49
52
|
});
|
|
50
53
|
});
|
|
51
54
|
const unsubscribeLookup = pi.events.on("pi-ask-question:lookup", (data) => {
|
|
52
55
|
const query = record(data);
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
if (
|
|
57
|
+
!query ||
|
|
58
|
+
!validId(query.queryId) ||
|
|
59
|
+
!validId(query.requestId) ||
|
|
60
|
+
typeof query.promptId !== "string"
|
|
61
|
+
)
|
|
62
|
+
return;
|
|
63
|
+
const status =
|
|
64
|
+
query.protocolVersion !== protocolVersion || mode !== "tui"
|
|
65
|
+
? "unsupported"
|
|
66
|
+
: query.ownerGeneration !== ownerGeneration || query.nativeRoot !== nativeRoot
|
|
67
|
+
? "stale"
|
|
68
|
+
: undefined;
|
|
69
|
+
const receipt = status
|
|
70
|
+
? undefined
|
|
71
|
+
: accepted.get(JSON.stringify([query.promptId, query.requestId]));
|
|
57
72
|
pi.events.emit("pi-ask-question:lookup-result", {
|
|
58
|
-
queryId: query.queryId,
|
|
59
|
-
|
|
73
|
+
queryId: query.queryId,
|
|
74
|
+
...identity(),
|
|
75
|
+
promptId: query.promptId,
|
|
76
|
+
requestId: query.requestId,
|
|
77
|
+
status: status ?? (receipt ? "answered" : "unknown"),
|
|
78
|
+
...receipt,
|
|
60
79
|
});
|
|
61
80
|
});
|
|
62
|
-
pi.on("session_start", (_event, ctx) => {
|
|
81
|
+
pi.on("session_start", (_event, ctx) => {
|
|
82
|
+
identify(ctx);
|
|
83
|
+
});
|
|
63
84
|
pi.on("session_shutdown", () => {
|
|
64
85
|
current = undefined;
|
|
65
86
|
accepted.clear();
|
|
@@ -72,20 +93,40 @@ export function createQuestionObserver(pi: ExtensionAPI) {
|
|
|
72
93
|
identity,
|
|
73
94
|
watch(getState: () => Waiting | undefined) {
|
|
74
95
|
current = getState;
|
|
75
|
-
return () => {
|
|
96
|
+
return () => {
|
|
97
|
+
if (current === getState) current = undefined;
|
|
98
|
+
};
|
|
76
99
|
},
|
|
77
100
|
matches(request: Record<string, unknown>, deadline: number) {
|
|
78
101
|
// Existing unversioned clients keep their original prompt/revision contract.
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
|
|
102
|
+
return (
|
|
103
|
+
request.protocolVersion === undefined ||
|
|
104
|
+
(request.protocolVersion === protocolVersion &&
|
|
105
|
+
request.ownerGeneration === ownerGeneration &&
|
|
106
|
+
request.nativeRoot === nativeRoot &&
|
|
107
|
+
request.deadline === deadline)
|
|
108
|
+
);
|
|
82
109
|
},
|
|
83
110
|
accept(target: Target, requestId: string, answer: string | string[]) {
|
|
84
111
|
const answerFingerprint = createHash("sha256")
|
|
85
|
-
.update(
|
|
86
|
-
|
|
112
|
+
.update(
|
|
113
|
+
JSON.stringify([
|
|
114
|
+
protocolVersion,
|
|
115
|
+
ownerGeneration,
|
|
116
|
+
nativeRoot,
|
|
117
|
+
target.promptId,
|
|
118
|
+
target.questionId,
|
|
119
|
+
target.revision,
|
|
120
|
+
target.deadline,
|
|
121
|
+
answer,
|
|
122
|
+
]),
|
|
123
|
+
)
|
|
87
124
|
.digest("hex");
|
|
88
|
-
accepted.set(JSON.stringify([target.promptId, requestId]), {
|
|
125
|
+
accepted.set(JSON.stringify([target.promptId, requestId]), {
|
|
126
|
+
...target,
|
|
127
|
+
requestId,
|
|
128
|
+
answerFingerprint,
|
|
129
|
+
});
|
|
89
130
|
if (accepted.size > 1024) accepted.delete(accepted.keys().next().value!);
|
|
90
131
|
},
|
|
91
132
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fitchmultz/pi-ask-question",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "Pi extension that adds an interactive ask_question tool and /grill-me pressure-test mode",
|
|
5
5
|
"author": "Mitch Fultz (https://github.com/fitchmultz)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,8 +31,13 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"test": "node --test tests/*.test.ts",
|
|
33
33
|
"typecheck": "tsc --noEmit",
|
|
34
|
+
"lint": "oxlint --deny-warnings .",
|
|
35
|
+
"lint:agent": "oxlint --deny-warnings --format=agent .",
|
|
36
|
+
"lint:fix": "oxlint --fix .",
|
|
37
|
+
"format": "oxfmt --write .",
|
|
38
|
+
"format:check": "oxfmt --check .",
|
|
34
39
|
"check:compat": "npm run check",
|
|
35
|
-
"check": "npm test && npm run typecheck && npm pack --dry-run",
|
|
40
|
+
"check": "npm test && npm run typecheck && npm run format:check && npm pack --dry-run",
|
|
36
41
|
"prepublishOnly": "npm run check"
|
|
37
42
|
},
|
|
38
43
|
"files": [
|
|
@@ -66,6 +71,9 @@
|
|
|
66
71
|
"@earendil-works/pi-coding-agent": "1.4.0",
|
|
67
72
|
"@earendil-works/pi-tui": "1.4.0",
|
|
68
73
|
"@types/node": "24.19.1",
|
|
74
|
+
"oxfmt": "0.75.0",
|
|
75
|
+
"oxlint": "1.90.0",
|
|
76
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
69
77
|
"typebox": "1.3.34",
|
|
70
78
|
"typescript": "7.0.2"
|
|
71
79
|
},
|