pi-advisor-flow 0.12.1-dev.2 → 0.12.1-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/dist/index.js +104 -8
- package/package.json +8 -5
- package/scripts/check-bun-version.mjs +67 -0
- package/src/herdr-shared.ts +137 -7
package/CHANGELOG.md
CHANGED
|
@@ -12,8 +12,10 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
12
12
|
|
|
13
13
|
### Changed
|
|
14
14
|
|
|
15
|
+
- Improved Herdr display reliability by serializing Advisor metadata reports per source, retrying metadata after failed delivery, and avoiding duplicate notification retries after payloads are written.
|
|
15
16
|
- Jev/Decisions provider selection moved out of the consultation-filter row into its own row, so the provider can be configured and verified without enabling screening. The filter row now only switches the filter on and off, and it refuses to enable while no provider resolves. `AdvisorSettingsSelectorOptions` gained `onJevFilter` and `onJevProvider` for the two rows; the combined `onJevSetup` is deprecated and is still called when neither is supplied.
|
|
16
17
|
- Updated Pi development dependencies to 1.1.0 and refreshed transitive dependency versions.
|
|
18
|
+
- Updated `@types/node` to 26.6.5, `bun-types` to 1.4.3, Knip to 6.41.0, and pinned CI to Bun 1.4.3. Switched the typecheck script from `tsc` to `bun check` and added a contributor install guard requiring Bun 1.4.3 or newer.
|
|
17
19
|
|
|
18
20
|
## 0.12.0 - 2026-10-07
|
|
19
21
|
|
package/dist/index.js
CHANGED
|
@@ -1687,6 +1687,109 @@ var safeEmitBlocked = (active, label = "Advisor blocked") => {
|
|
|
1687
1687
|
};
|
|
1688
1688
|
var isControlCharacter = (character) => character <= "\x1F" || character === "";
|
|
1689
1689
|
var cleanNotification = (value, max) => [...redactSecrets(value)].map((character) => isControlCharacter(character) ? " " : character).join("").replaceAll(/\s+/gu, " ").trim().slice(0, max);
|
|
1690
|
+
var FIRST_ATTEMPT_TIMEOUT_MS = 500;
|
|
1691
|
+
var RETRY_ATTEMPT_TIMEOUT_MS = 1500;
|
|
1692
|
+
var MAX_PENDING_NOTIFICATIONS = 16;
|
|
1693
|
+
var reportQueues = new Map;
|
|
1694
|
+
var isMetadataRequest = (request) => request.method === "pane.report_metadata";
|
|
1695
|
+
var reportQueueKey = (request) => isMetadataRequest(request) ? request.params.source : NOTIFICATION_SOURCE;
|
|
1696
|
+
var sendRequestAttempt = (endpoint, request, timeoutMs) => {
|
|
1697
|
+
const deferred = Promise.withResolvers();
|
|
1698
|
+
let settled = false;
|
|
1699
|
+
let wrote = false;
|
|
1700
|
+
let timeout;
|
|
1701
|
+
let socket;
|
|
1702
|
+
const finish = (responded) => {
|
|
1703
|
+
if (settled) {
|
|
1704
|
+
return;
|
|
1705
|
+
}
|
|
1706
|
+
settled = true;
|
|
1707
|
+
if (timeout) {
|
|
1708
|
+
clearTimeout(timeout);
|
|
1709
|
+
}
|
|
1710
|
+
socket?.destroy();
|
|
1711
|
+
deferred.resolve({ responded, wrote });
|
|
1712
|
+
};
|
|
1713
|
+
try {
|
|
1714
|
+
socket = net.createConnection(endpoint);
|
|
1715
|
+
socket.once("connect", () => {
|
|
1716
|
+
wrote = true;
|
|
1717
|
+
try {
|
|
1718
|
+
socket?.write(`${JSON.stringify(request)}
|
|
1719
|
+
`);
|
|
1720
|
+
} catch {
|
|
1721
|
+
finish(false);
|
|
1722
|
+
}
|
|
1723
|
+
});
|
|
1724
|
+
socket.once("data", () => finish(true));
|
|
1725
|
+
socket.once("end", () => finish(false));
|
|
1726
|
+
socket.once("error", () => finish(false));
|
|
1727
|
+
socket.once("close", () => finish(false));
|
|
1728
|
+
timeout = setTimeout(() => finish(false), timeoutMs);
|
|
1729
|
+
timeout.unref?.();
|
|
1730
|
+
} catch {
|
|
1731
|
+
finish(false);
|
|
1732
|
+
}
|
|
1733
|
+
return deferred.promise;
|
|
1734
|
+
};
|
|
1735
|
+
var sendQueuedReport = async ({ endpoint, request }) => {
|
|
1736
|
+
const first = await sendRequestAttempt(endpoint, request, FIRST_ATTEMPT_TIMEOUT_MS);
|
|
1737
|
+
if (first.responded) {
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1740
|
+
if (!isMetadataRequest(request) && first.wrote) {
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
await sendRequestAttempt(endpoint, request, RETRY_ATTEMPT_TIMEOUT_MS);
|
|
1744
|
+
};
|
|
1745
|
+
var drainReportQueue = async (key, queue) => {
|
|
1746
|
+
if (queue.active) {
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1749
|
+
queue.active = true;
|
|
1750
|
+
try {
|
|
1751
|
+
while (queue.reports.length > 0) {
|
|
1752
|
+
const report = queue.reports.shift();
|
|
1753
|
+
if (report) {
|
|
1754
|
+
try {
|
|
1755
|
+
await sendQueuedReport(report);
|
|
1756
|
+
} catch {
|
|
1757
|
+
continue;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
} finally {
|
|
1762
|
+
queue.active = false;
|
|
1763
|
+
if (queue.reports.length === 0) {
|
|
1764
|
+
reportQueues.delete(key);
|
|
1765
|
+
} else {
|
|
1766
|
+
drainReportQueue(key, queue);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
var enqueueReport = (report) => {
|
|
1771
|
+
const key = reportQueueKey(report.request);
|
|
1772
|
+
let queue = reportQueues.get(key);
|
|
1773
|
+
if (!queue) {
|
|
1774
|
+
queue = { active: false, reports: [] };
|
|
1775
|
+
reportQueues.set(key, queue);
|
|
1776
|
+
}
|
|
1777
|
+
if (isMetadataRequest(report.request)) {
|
|
1778
|
+
if (queue.active) {
|
|
1779
|
+
queue.reports = [report];
|
|
1780
|
+
} else {
|
|
1781
|
+
queue.reports.push(report);
|
|
1782
|
+
}
|
|
1783
|
+
} else {
|
|
1784
|
+
if (queue.reports.length >= MAX_PENDING_NOTIFICATIONS) {
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
queue.reports.push(report);
|
|
1788
|
+
}
|
|
1789
|
+
if (!queue.active) {
|
|
1790
|
+
drainReportQueue(key, queue);
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1690
1793
|
var sendToHerdr = (request) => {
|
|
1691
1794
|
if (process.env.HERDR_ENV !== "1") {
|
|
1692
1795
|
return;
|
|
@@ -1697,14 +1800,7 @@ var sendToHerdr = (request) => {
|
|
|
1697
1800
|
return;
|
|
1698
1801
|
}
|
|
1699
1802
|
const endpoint = process.platform === "win32" ? `\\\\.\\pipe\\${socketPath}` : socketPath;
|
|
1700
|
-
|
|
1701
|
-
const timeout = setTimeout(() => socket.destroy(), 500);
|
|
1702
|
-
timeout.unref?.();
|
|
1703
|
-
socket.once("connect", () => socket.write(`${JSON.stringify(request)}
|
|
1704
|
-
`));
|
|
1705
|
-
socket.once("data", () => socket.destroy());
|
|
1706
|
-
socket.once("error", () => socket.destroy());
|
|
1707
|
-
socket.once("close", () => clearTimeout(timeout));
|
|
1803
|
+
enqueueReport({ endpoint, request });
|
|
1708
1804
|
};
|
|
1709
1805
|
var createHerdrNotificationRequest = (title, body) => ({
|
|
1710
1806
|
id: `${NOTIFICATION_SOURCE}:${nextSequence()}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-advisor-flow",
|
|
3
|
-
"version": "0.12.1-dev.
|
|
3
|
+
"version": "0.12.1-dev.3",
|
|
4
4
|
"description": "Advanced Executor/Advisor flow for Pi, fully configurable and extendable.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"advisor",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dist",
|
|
23
23
|
"extensions",
|
|
24
24
|
"src",
|
|
25
|
+
"scripts/check-bun-version.mjs",
|
|
25
26
|
"CHANGELOG.md",
|
|
26
27
|
"LICENSE",
|
|
27
28
|
"README.md"
|
|
@@ -42,12 +43,13 @@
|
|
|
42
43
|
"lint:fix": "oxlint --fix",
|
|
43
44
|
"prepack": "bun run build >/dev/null",
|
|
44
45
|
"package:check": "node scripts/check-package.mjs",
|
|
46
|
+
"preinstall": "node scripts/check-bun-version.mjs",
|
|
45
47
|
"prepare": "husky",
|
|
46
48
|
"socket": "bunx socket optimize",
|
|
47
49
|
"test": "bun test && bun run test:node-loader",
|
|
48
50
|
"test:bench": "bun --config=./bunfig.bench.toml test ./bench/test/",
|
|
49
51
|
"test:node-loader": "node --test test/default-resource-loader.node.mjs",
|
|
50
|
-
"typecheck": "
|
|
52
|
+
"typecheck": "bun check",
|
|
51
53
|
"format:check": "oxfmt --check"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
@@ -55,11 +57,11 @@
|
|
|
55
57
|
"@earendil-works/pi-coding-agent": "1.1.0",
|
|
56
58
|
"@earendil-works/pi-tui": "1.1.0",
|
|
57
59
|
"@oxlint/plugins": "1.87.0",
|
|
58
|
-
"@types/node": "^26.6.
|
|
60
|
+
"@types/node": "^26.6.5",
|
|
59
61
|
"@typesafe-ai/sdk": "^0.6.0",
|
|
60
|
-
"bun-types": "1.4.
|
|
62
|
+
"bun-types": "1.4.3",
|
|
61
63
|
"husky": "^9.1.7",
|
|
62
|
-
"knip": "6.
|
|
64
|
+
"knip": "6.41.0",
|
|
63
65
|
"lint-staged": "^17.6.0",
|
|
64
66
|
"oxfmt": "0.72.0",
|
|
65
67
|
"oxlint": "1.87.0",
|
|
@@ -107,6 +109,7 @@
|
|
|
107
109
|
"oxfmt"
|
|
108
110
|
]
|
|
109
111
|
},
|
|
112
|
+
"packageManager": "bun@1.4.3",
|
|
110
113
|
"pi": {
|
|
111
114
|
"extensions": [
|
|
112
115
|
"./dist/index.js"
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const projectRoot = resolve(fileURLToPath(new URL("..", import.meta.url)));
|
|
6
|
+
if (!existsSync(resolve(projectRoot, "bun.lock"))) {
|
|
7
|
+
process.exit(0);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const localPrefix = process.env.npm_config_local_prefix;
|
|
11
|
+
if (localPrefix && resolve(localPrefix) !== projectRoot) {
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const packageJson = JSON.parse(
|
|
16
|
+
readFileSync(resolve(projectRoot, "package.json"), "utf-8")
|
|
17
|
+
);
|
|
18
|
+
const minimumVersion = /^bun@(?<version>\d+\.\d+\.\d+)$/u.exec(
|
|
19
|
+
packageJson.packageManager ?? ""
|
|
20
|
+
)?.groups?.version;
|
|
21
|
+
const currentVersion = /^bun\/(?<version>[^\s]+)/u.exec(
|
|
22
|
+
process.env.npm_config_user_agent ?? ""
|
|
23
|
+
)?.groups?.version;
|
|
24
|
+
|
|
25
|
+
const isAtLeast = (version, minimum) => {
|
|
26
|
+
const current =
|
|
27
|
+
/^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<prerelease>[^\s]+))?$/u.exec(
|
|
28
|
+
version
|
|
29
|
+
)?.groups;
|
|
30
|
+
const required =
|
|
31
|
+
/^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<prerelease>[^\s]+))?$/u.exec(
|
|
32
|
+
minimum
|
|
33
|
+
)?.groups;
|
|
34
|
+
if (!current || !required) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const currentParts = [current.major, current.minor, current.patch].map(
|
|
39
|
+
Number
|
|
40
|
+
);
|
|
41
|
+
const requiredParts = [required.major, required.minor, required.patch].map(
|
|
42
|
+
Number
|
|
43
|
+
);
|
|
44
|
+
for (let index = 0; index < currentParts.length; index += 1) {
|
|
45
|
+
const difference = currentParts[index] - requiredParts[index];
|
|
46
|
+
if (difference !== 0) {
|
|
47
|
+
return difference > 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return !current.prerelease || Boolean(required.prerelease);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
!minimumVersion ||
|
|
56
|
+
!currentVersion ||
|
|
57
|
+
!isAtLeast(currentVersion, minimumVersion)
|
|
58
|
+
) {
|
|
59
|
+
console.error(
|
|
60
|
+
`This repository requires Bun ${minimumVersion ?? "1.4.3"} or newer; found ${currentVersion ?? "a non-Bun package manager"}.`
|
|
61
|
+
);
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
} else {
|
|
64
|
+
console.log(
|
|
65
|
+
`Bun ${currentVersion} meets the repository minimum ${minimumVersion}.`
|
|
66
|
+
);
|
|
67
|
+
}
|
package/src/herdr-shared.ts
CHANGED
|
@@ -73,6 +73,142 @@ export const cleanNotification = (value: string, max: number) =>
|
|
|
73
73
|
.trim()
|
|
74
74
|
.slice(0, max);
|
|
75
75
|
|
|
76
|
+
interface HerdrAttempt {
|
|
77
|
+
responded: boolean;
|
|
78
|
+
wrote: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface QueuedReport {
|
|
82
|
+
endpoint: string;
|
|
83
|
+
request: HerdrRequest;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface ReportQueue {
|
|
87
|
+
active: boolean;
|
|
88
|
+
reports: QueuedReport[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const FIRST_ATTEMPT_TIMEOUT_MS = 500;
|
|
92
|
+
const RETRY_ATTEMPT_TIMEOUT_MS = 1500;
|
|
93
|
+
const MAX_PENDING_NOTIFICATIONS = 16;
|
|
94
|
+
const reportQueues = new Map<string, ReportQueue>();
|
|
95
|
+
|
|
96
|
+
const isMetadataRequest = (request: HerdrRequest) =>
|
|
97
|
+
request.method === "pane.report_metadata";
|
|
98
|
+
|
|
99
|
+
const reportQueueKey = (request: HerdrRequest) =>
|
|
100
|
+
isMetadataRequest(request) ? request.params.source : NOTIFICATION_SOURCE;
|
|
101
|
+
|
|
102
|
+
const sendRequestAttempt = (
|
|
103
|
+
endpoint: string,
|
|
104
|
+
request: HerdrRequest,
|
|
105
|
+
timeoutMs: number
|
|
106
|
+
): Promise<HerdrAttempt> => {
|
|
107
|
+
const deferred = Promise.withResolvers<HerdrAttempt>();
|
|
108
|
+
let settled = false;
|
|
109
|
+
let wrote = false;
|
|
110
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
111
|
+
let socket: net.Socket | undefined;
|
|
112
|
+
|
|
113
|
+
const finish = (responded: boolean) => {
|
|
114
|
+
if (settled) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
settled = true;
|
|
118
|
+
if (timeout) {
|
|
119
|
+
clearTimeout(timeout);
|
|
120
|
+
}
|
|
121
|
+
socket?.destroy();
|
|
122
|
+
deferred.resolve({ responded, wrote });
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
socket = net.createConnection(endpoint);
|
|
127
|
+
socket.once("connect", () => {
|
|
128
|
+
wrote = true;
|
|
129
|
+
try {
|
|
130
|
+
socket?.write(`${JSON.stringify(request)}\n`);
|
|
131
|
+
} catch {
|
|
132
|
+
finish(false);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
socket.once("data", () => finish(true));
|
|
136
|
+
socket.once("end", () => finish(false));
|
|
137
|
+
socket.once("error", () => finish(false));
|
|
138
|
+
socket.once("close", () => finish(false));
|
|
139
|
+
timeout = setTimeout(() => finish(false), timeoutMs);
|
|
140
|
+
timeout.unref?.();
|
|
141
|
+
} catch {
|
|
142
|
+
finish(false);
|
|
143
|
+
}
|
|
144
|
+
return deferred.promise;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const sendQueuedReport = async ({ endpoint, request }: QueuedReport) => {
|
|
148
|
+
const first = await sendRequestAttempt(
|
|
149
|
+
endpoint,
|
|
150
|
+
request,
|
|
151
|
+
FIRST_ATTEMPT_TIMEOUT_MS
|
|
152
|
+
);
|
|
153
|
+
if (first.responded) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!isMetadataRequest(request) && first.wrote) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
await sendRequestAttempt(endpoint, request, RETRY_ATTEMPT_TIMEOUT_MS);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const drainReportQueue = async (key: string, queue: ReportQueue) => {
|
|
163
|
+
if (queue.active) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
queue.active = true;
|
|
167
|
+
try {
|
|
168
|
+
while (queue.reports.length > 0) {
|
|
169
|
+
const report = queue.reports.shift();
|
|
170
|
+
if (report) {
|
|
171
|
+
try {
|
|
172
|
+
await sendQueuedReport(report);
|
|
173
|
+
} catch {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} finally {
|
|
179
|
+
queue.active = false;
|
|
180
|
+
if (queue.reports.length === 0) {
|
|
181
|
+
reportQueues.delete(key);
|
|
182
|
+
} else {
|
|
183
|
+
void drainReportQueue(key, queue);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const enqueueReport = (report: QueuedReport) => {
|
|
189
|
+
const key = reportQueueKey(report.request);
|
|
190
|
+
let queue = reportQueues.get(key);
|
|
191
|
+
if (!queue) {
|
|
192
|
+
queue = { active: false, reports: [] };
|
|
193
|
+
reportQueues.set(key, queue);
|
|
194
|
+
}
|
|
195
|
+
if (isMetadataRequest(report.request)) {
|
|
196
|
+
if (queue.active) {
|
|
197
|
+
queue.reports = [report];
|
|
198
|
+
} else {
|
|
199
|
+
queue.reports.push(report);
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
if (queue.reports.length >= MAX_PENDING_NOTIFICATIONS) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
queue.reports.push(report);
|
|
206
|
+
}
|
|
207
|
+
if (!queue.active) {
|
|
208
|
+
void drainReportQueue(key, queue);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
76
212
|
export const sendToHerdr: Report = (request) => {
|
|
77
213
|
if (process.env.HERDR_ENV !== "1") {
|
|
78
214
|
return;
|
|
@@ -84,13 +220,7 @@ export const sendToHerdr: Report = (request) => {
|
|
|
84
220
|
}
|
|
85
221
|
const endpoint =
|
|
86
222
|
process.platform === "win32" ? `\\\\.\\pipe\\${socketPath}` : socketPath;
|
|
87
|
-
|
|
88
|
-
const timeout = setTimeout(() => socket.destroy(), 500);
|
|
89
|
-
timeout.unref?.();
|
|
90
|
-
socket.once("connect", () => socket.write(`${JSON.stringify(request)}\n`));
|
|
91
|
-
socket.once("data", () => socket.destroy());
|
|
92
|
-
socket.once("error", () => socket.destroy());
|
|
93
|
-
socket.once("close", () => clearTimeout(timeout));
|
|
223
|
+
enqueueReport({ endpoint, request });
|
|
94
224
|
};
|
|
95
225
|
|
|
96
226
|
export const createHerdrNotificationRequest = (
|