@blackbelt-technology/pi-dashboard-extension 0.7.0 → 0.9.0
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/.pi/skills/browser/SKILL.md +84 -29
- package/.pi/skills/browser/UPSTREAM.md +13 -1
- package/.pi/skills/browser/references/challenge.md +183 -0
- package/.pi/skills/browser/references/dashboard-relay.md +150 -0
- package/.pi/skills/browser/references/electron.agent.md +57 -0
- package/.pi/skills/browser/references/own-browser.md +305 -0
- package/.pi/skills/browser/references/web.agent.md +323 -0
- package/.pi/skills/browser/scripts/check-panerelay.sh +157 -0
- package/.pi/skills/doctor/SKILL.md +4 -9
- package/.pi/skills/doctor/_lib/checks.ts +133 -54
- package/.pi/skills/doctor/_lib/derive-tokens.ts +5 -0
- package/.pi/skills/doctor/modules/apple-tools.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/apple-tools.md +52 -0
- package/.pi/skills/doctor/modules/mcp-builtin.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/mcp-builtin.md +61 -0
- package/.pi/skills/doctor/modules/oauth-redirect-base.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/oauth-redirect-base.md +71 -0
- package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -1
- package/.pi/skills/doctor/modules/pi-resolution.md +21 -1
- package/.pi/skills/doctor/modules/plugins-bridges.md +14 -1
- package/.pi/skills/pi-dashboard/SKILL.md +10 -3
- package/.pi/skills/pi-dashboard/references/api-reference.agent.md +69 -0
- package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +4 -4
- package/.pi/skills/project-init/SKILL.md +41 -34
- package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +0 -23
- package/.pi/skills/project-init/profiles/docs/profile.json +1 -1
- package/README.md +19 -0
- package/agents/DoxTriage.md +80 -0
- package/package.json +30 -16
- package/src/ask-user-tool.ts +4 -0
- package/src/auto-session-namer.ts +486 -70
- package/src/autostart-guard.ts +99 -0
- package/src/autostart-lock.ts +258 -0
- package/src/bridge-activation.ts +26 -0
- package/src/bridge-context.ts +106 -23
- package/src/bridge-default-model-gate.ts +38 -0
- package/src/bridge-polling.ts +148 -0
- package/src/bridge-ticket-client.ts +105 -0
- package/src/bridge.ts +1760 -350
- package/src/canvas-tool.ts +5 -0
- package/src/command-handler.ts +392 -71
- package/src/connect-target.ts +130 -0
- package/src/connection.ts +846 -17
- package/src/custom-entry-forward.ts +92 -0
- package/src/endpoint-resolution.ts +253 -0
- package/src/event-forwarder.ts +42 -0
- package/src/extension-identity.ts +59 -0
- package/src/flow-event-wiring.ts +125 -3
- package/src/followup-buffer.ts +217 -0
- package/src/git-dir-watcher.ts +79 -0
- package/src/git-poll.ts +45 -12
- package/src/git-probe-scheduler.ts +119 -0
- package/src/git-tracker.ts +284 -0
- package/src/instance-verification.ts +156 -0
- package/src/local-token-header.ts +44 -0
- package/src/mcp-token-delivery.ts +147 -0
- package/src/message-update-coalescer.ts +340 -0
- package/src/model-refresh.ts +95 -0
- package/src/model-tracker.ts +118 -35
- package/src/notify-proxy.ts +36 -0
- package/src/path-gate/decide.ts +149 -0
- package/src/path-gate/grant-cache.ts +71 -0
- package/src/path-gate/grant-link.ts +108 -0
- package/src/path-gate/handler.ts +307 -0
- package/src/path-gate/index.ts +155 -0
- package/src/path-gate/resolve.ts +126 -0
- package/src/path-gate/roots.ts +137 -0
- package/src/path-gate/suppression.ts +27 -0
- package/src/pending-prompt-emitter.ts +59 -0
- package/src/pi-env.d.ts +6 -10
- package/src/pi-retry-settings.ts +91 -0
- package/src/plugin-request-client.ts +114 -0
- package/src/poll-cost.ts +40 -0
- package/src/pr-status.ts +338 -0
- package/src/process-metrics.ts +77 -1
- package/src/process-scan-scheduler.ts +137 -0
- package/src/process-scanner.ts +226 -247
- package/src/project-init/dox-kb-config.ts +3 -0
- package/src/project-init/scaffold.ts +1 -4
- package/src/project-init/seed-doctrine.ts +23 -60
- package/src/prompt-bus.ts +13 -0
- package/src/provider-register.ts +92 -21
- package/src/remote-registration-gate.ts +102 -0
- package/src/retry-tracker.ts +258 -86
- package/src/role-manager.ts +38 -91
- package/src/role-model-tools.ts +44 -3
- package/src/server-auto-start.ts +331 -20
- package/src/server-launcher.ts +70 -34
- package/src/server-pin-store.ts +92 -0
- package/src/session-move.ts +275 -0
- package/src/session-sync.ts +75 -20
- package/src/slash-dispatch.ts +66 -81
- package/src/subagent-fanout-admission.ts +234 -0
- package/src/subagent-forward-sites.ts +69 -0
- package/src/subagent-frame-buffer.ts +24 -3
- package/src/subagent-frame-strip.ts +109 -0
- package/src/subagent-saturation.ts +196 -0
- package/src/subagent-tick-throttle.ts +250 -0
- package/src/terminal-reload.ts +298 -0
- package/src/transcript-backfill.ts +151 -0
- package/src/transport-diagnostics.ts +76 -0
- package/src/tui-prompt-adapter.ts +13 -1
- package/src/turn-actionability.ts +20 -0
- package/src/ui-stale-guard.ts +58 -0
- package/src/usage-drain.ts +167 -0
- package/src/vcs-info.ts +261 -63
- package/.pi/skills/doctor/AGENTS.md +0 -27
- package/.pi/skills/project-init/dox-doctrine.md +0 -104
- package/src/AGENTS.md +0 -57
- package/src/__tests__/abort-latch.test.ts +0 -97
- package/src/__tests__/agent-settled.test.ts +0 -82
- package/src/__tests__/artifact-roots.test.ts +0 -83
- package/src/__tests__/ask-user-attachments.test.ts +0 -106
- package/src/__tests__/ask-user-schema-discriminator.test.ts +0 -141
- package/src/__tests__/ask-user-tool.test.ts +0 -571
- package/src/__tests__/auto-session-namer.test.ts +0 -339
- package/src/__tests__/bridge-default-model-apply.test.ts +0 -242
- package/src/__tests__/bridge-default-model-gate.test.ts +0 -50
- package/src/__tests__/bridge-entry-id-pi-070.test.ts +0 -174
- package/src/__tests__/bridge-followup-chat-order.test.ts +0 -215
- package/src/__tests__/bridge-followup-multi-entry.test.ts +0 -202
- package/src/__tests__/bridge-followup-mutation.test.ts +0 -217
- package/src/__tests__/bridge-followup-queue-drain.test.ts +0 -266
- package/src/__tests__/bridge-hasui-flip.test.ts +0 -109
- package/src/__tests__/bridge-no-queue-mutation.test.ts +0 -112
- package/src/__tests__/bridge-plugin-emit-event.test.ts +0 -44
- package/src/__tests__/bridge-queue-update-forward.test.ts +0 -77
- package/src/__tests__/bridge-resume-disconnect.test.ts +0 -333
- package/src/__tests__/bridge-shadow-queue-gate.test.ts +0 -299
- package/src/__tests__/bridge-shutdown-reset.test.ts +0 -159
- package/src/__tests__/bridge-slash-command-routing.test.ts +0 -458
- package/src/__tests__/bridge-stop-after-turn.test.ts +0 -72
- package/src/__tests__/bridge-system-followup.test.ts +0 -163
- package/src/__tests__/bridge-thinking-level-select.test.ts +0 -68
- package/src/__tests__/browser-skill-registered.test.ts +0 -84
- package/src/__tests__/build-provider-catalogue.test.ts +0 -210
- package/src/__tests__/command-handler.test.ts +0 -1180
- package/src/__tests__/commit-draft.test.ts +0 -100
- package/src/__tests__/connection-dropped-frames.test.ts +0 -78
- package/src/__tests__/connection-suppress-auto-start.test.ts +0 -97
- package/src/__tests__/connection.test.ts +0 -344
- package/src/__tests__/credentials-updated.test.ts +0 -26
- package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +0 -128
- package/src/__tests__/cwd-missing-probe.test.ts +0 -82
- package/src/__tests__/dashboard-commands-shipped.test.ts +0 -53
- package/src/__tests__/dashboard-context-injector.test.ts +0 -190
- package/src/__tests__/dashboard-default-adapter.test.ts +0 -77
- package/src/__tests__/dev-build.test.ts +0 -79
- package/src/__tests__/doctor/checks.test.ts +0 -121
- package/src/__tests__/doctor/modules.test.ts +0 -64
- package/src/__tests__/doctor/provenance-hash.test.ts +0 -94
- package/src/__tests__/doctor/router.test.ts +0 -143
- package/src/__tests__/empty-actionable-guard-config.test.ts +0 -32
- package/src/__tests__/empty-actionable-guard.test.ts +0 -73
- package/src/__tests__/enrich-model-metadata.test.ts +0 -222
- package/src/__tests__/event-forwarder.test.ts +0 -119
- package/src/__tests__/extension-slash-command-detection.test.ts +0 -143
- package/src/__tests__/filter-enabled-models.test.ts +0 -151
- package/src/__tests__/fixtures/turn-actionability-fixtures.ts +0 -69
- package/src/__tests__/fork-entryid-timing.test.ts +0 -88
- package/src/__tests__/git-info-status.test.ts +0 -73
- package/src/__tests__/git-link-builder.test.ts +0 -102
- package/src/__tests__/git-poll.test.ts +0 -69
- package/src/__tests__/markdown-image-inliner.test.ts +0 -392
- package/src/__tests__/model-resolve.test.ts +0 -379
- package/src/__tests__/multiselect-dashboard-routing.test.ts +0 -203
- package/src/__tests__/multiselect-list.test.ts +0 -137
- package/src/__tests__/multiselect-polyfill.test.ts +0 -92
- package/src/__tests__/no-session-replacement-calls.test.ts +0 -99
- package/src/__tests__/no-tui-multiselect-arm-regression.test.ts +0 -81
- package/src/__tests__/openspec-activity-detector.test.ts +0 -337
- package/src/__tests__/openspec-cli-shim.test.ts +0 -145
- package/src/__tests__/openspec-poller.test.ts +0 -124
- package/src/__tests__/pi-version-tracker.test.ts +0 -109
- package/src/__tests__/process-metrics.test.ts +0 -47
- package/src/__tests__/process-scanner-kill.test.ts +0 -61
- package/src/__tests__/process-scanner.test.ts +0 -292
- package/src/__tests__/project-init-detect-stack.test.ts +0 -61
- package/src/__tests__/project-init-dox-kb-config.test.ts +0 -53
- package/src/__tests__/project-init-profiles.test.ts +0 -84
- package/src/__tests__/project-init-scaffold.test.ts +0 -139
- package/src/__tests__/project-init-seed-doctrine.test.ts +0 -100
- package/src/__tests__/project-trust.test.ts +0 -92
- package/src/__tests__/prompt-bus-wiring.test.ts +0 -791
- package/src/__tests__/prompt-bus.test.ts +0 -513
- package/src/__tests__/prompt-expander.test.ts +0 -398
- package/src/__tests__/provider-register-native-models.test.ts +0 -182
- package/src/__tests__/provider-register-reload.test.ts +0 -498
- package/src/__tests__/provider-register-thinking-levels.test.ts +0 -104
- package/src/__tests__/retry-tracker.test.ts +0 -152
- package/src/__tests__/role-manager.test.ts +0 -585
- package/src/__tests__/role-model-tools-registry-readiness.test.ts +0 -114
- package/src/__tests__/role-model-tools.test.ts +0 -229
- package/src/__tests__/search-files-completeness.test.ts +0 -111
- package/src/__tests__/search-files-ranking.test.ts +0 -168
- package/src/__tests__/server-auto-start.test.ts +0 -375
- package/src/__tests__/server-launcher-launch.test.ts +0 -96
- package/src/__tests__/server-launcher.test.ts +0 -101
- package/src/__tests__/server-probe.test.ts +0 -25
- package/src/__tests__/session-switch.test.ts +0 -139
- package/src/__tests__/session-sync.test.ts +0 -243
- package/src/__tests__/single-derivation-guard.test.ts +0 -39
- package/src/__tests__/source-detector.test.ts +0 -88
- package/src/__tests__/stats-extractor.test.ts +0 -92
- package/src/__tests__/subagent-frame-buffer.test.ts +0 -239
- package/src/__tests__/tool-result-image-inliner.test.ts +0 -206
- package/src/__tests__/tui-prompt-adapter.test.ts +0 -213
- package/src/__tests__/turn-actionability.test.ts +0 -86
- package/src/__tests__/ui-decorators.test.ts +0 -309
- package/src/__tests__/ui-modules.test.ts +0 -293
- package/src/__tests__/vcs-info.test.ts +0 -265
- package/src/__tests__/visibility-intent.test.ts +0 -43
- package/src/__tests__/watchdog.test.ts +0 -161
- package/src/abort-latch.ts.AGENTS.md +0 -3
- package/src/agent-settled.ts +0 -72
- package/src/agent-settled.ts.AGENTS.md +0 -3
- package/src/artifact-roots.ts.AGENTS.md +0 -3
- package/src/ask-user-attachments.ts.AGENTS.md +0 -3
- package/src/ask-user-tool.ts.AGENTS.md +0 -3
- package/src/auto-session-namer.ts.AGENTS.md +0 -3
- package/src/bridge-context.ts.AGENTS.md +0 -3
- package/src/bridge-default-model-gate.ts.AGENTS.md +0 -3
- package/src/bridge.ts.AGENTS.md +0 -3
- package/src/command-handler.ts.AGENTS.md +0 -3
- package/src/commit-draft-agent.ts.AGENTS.md +0 -3
- package/src/commit-draft.ts.AGENTS.md +0 -3
- package/src/connection.ts.AGENTS.md +0 -3
- package/src/dashboard-context-injector.ts.AGENTS.md +0 -3
- package/src/dashboard-default-adapter.ts.AGENTS.md +0 -3
- package/src/dev-build.ts.AGENTS.md +0 -3
- package/src/empty-actionable-guard-config.ts.AGENTS.md +0 -3
- package/src/empty-actionable-guard.ts.AGENTS.md +0 -3
- package/src/event-forwarder.ts.AGENTS.md +0 -3
- package/src/flow-event-wiring.ts.AGENTS.md +0 -3
- package/src/git-link-builder.ts.AGENTS.md +0 -3
- package/src/git-poll.ts.AGENTS.md +0 -3
- package/src/hasui-flip.ts.AGENTS.md +0 -3
- package/src/markdown-image-inliner.ts.AGENTS.md +0 -3
- package/src/model-tracker.ts.AGENTS.md +0 -3
- package/src/multiselect-decode.ts.AGENTS.md +0 -3
- package/src/multiselect-list.ts.AGENTS.md +0 -3
- package/src/multiselect-polyfill.ts.AGENTS.md +0 -3
- package/src/openspec-cli-shim.ts.AGENTS.md +0 -7
- package/src/process-metrics.ts.AGENTS.md +0 -3
- package/src/process-scanner.ts.AGENTS.md +0 -3
- package/src/project-init/AGENTS.md +0 -12
- package/src/project-trust.ts.AGENTS.md +0 -3
- package/src/prompt-bus.ts.AGENTS.md +0 -3
- package/src/prompt-expander.ts.AGENTS.md +0 -3
- package/src/provider-register.ts.AGENTS.md +0 -3
- package/src/retry-tracker.ts.AGENTS.md +0 -3
- package/src/role-manager.ts.AGENTS.md +0 -3
- package/src/role-model-tools.ts.AGENTS.md +0 -3
- package/src/server-auto-start.ts.AGENTS.md +0 -3
- package/src/server-launcher.ts.AGENTS.md +0 -3
- package/src/session-sync.ts.AGENTS.md +0 -3
- package/src/slash-dispatch.ts.AGENTS.md +0 -3
- package/src/source-detector.ts.AGENTS.md +0 -3
- package/src/subagent-frame-buffer.ts.AGENTS.md +0 -3
- package/src/tool-result-image-inliner.ts.AGENTS.md +0 -3
- package/src/tui-prompt-adapter.ts.AGENTS.md +0 -3
- package/src/turn-actionability.ts.AGENTS.md +0 -3
- package/src/ui-modules.ts.AGENTS.md +0 -3
- package/src/vcs-info.ts.AGENTS.md +0 -3
- package/src/visibility-intent.ts.AGENTS.md +0 -3
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root set for the agent path gate (D2): workspace (cwd + bound checkout roots),
|
|
3
|
+
* built-in read-only roots (pi agent dir, skills, pi docs, loaded context files)
|
|
4
|
+
* and built-in read+write roots (tmpdir, `/tmp`, session dir). All real-pathed once.
|
|
5
|
+
*
|
|
6
|
+
* The checkout probe starts at `session_start` and is bounded; a decision that
|
|
7
|
+
* needs it waits up to `PROBE_BOUND_MS`, else falls back to cwd only (fail closed).
|
|
8
|
+
* See change: ask-agent-file-access-in-chat.
|
|
9
|
+
*/
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import nodePath from "node:path";
|
|
13
|
+
import { checkoutRootsAsync, isBoundCheckoutAsync } from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
14
|
+
import { samePath } from "@blackbelt-technology/pi-dashboard-shared/platform/paths.js";
|
|
15
|
+
import type { GateRoots } from "./decide.js";
|
|
16
|
+
|
|
17
|
+
/** Same per-probe budget `file-read-containment` uses. */
|
|
18
|
+
const PROBE_TIMEOUT_MS = 2_000;
|
|
19
|
+
/** How long a decision waits for the checkout probe before using cwd only. */
|
|
20
|
+
const PROBE_BOUND_MS = 3_000;
|
|
21
|
+
|
|
22
|
+
export interface PiResources {
|
|
23
|
+
agentDir: string;
|
|
24
|
+
docsDir?: string;
|
|
25
|
+
skillDirs: string[];
|
|
26
|
+
contextFiles: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function realpathOr(p: string): string {
|
|
30
|
+
try {
|
|
31
|
+
return fs.realpathSync(p);
|
|
32
|
+
} catch {
|
|
33
|
+
return p;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Bound checkout roots of `cwd`; `[]` on any failure (never throws). */
|
|
38
|
+
async function probeCheckoutRoots(cwd: string): Promise<string[]> {
|
|
39
|
+
try {
|
|
40
|
+
const roots = await checkoutRootsAsync({ cwd, timeout: PROBE_TIMEOUT_MS });
|
|
41
|
+
if (!roots) return [];
|
|
42
|
+
const cands: string[] = [];
|
|
43
|
+
for (const c of [roots.thisCheckout, roots.mainCheckout]) {
|
|
44
|
+
if (c && !cands.some((s) => samePath(s, c))) cands.push(c);
|
|
45
|
+
}
|
|
46
|
+
const bound: string[] = [];
|
|
47
|
+
for (const c of cands) {
|
|
48
|
+
if (await isBoundCheckoutAsync(c, roots.commonDir, { timeout: PROBE_TIMEOUT_MS })) bound.push(realpathOr(c));
|
|
49
|
+
}
|
|
50
|
+
return bound;
|
|
51
|
+
} catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Race a promise against a bound; resolves `fallback` on timeout. */
|
|
57
|
+
export function withBound<T>(p: Promise<T>, ms: number, fallback: T): Promise<T> {
|
|
58
|
+
return new Promise<T>((resolve) => {
|
|
59
|
+
const t = setTimeout(() => resolve(fallback), ms);
|
|
60
|
+
t.unref?.();
|
|
61
|
+
p.then(
|
|
62
|
+
(v) => { clearTimeout(t); resolve(v); },
|
|
63
|
+
() => { clearTimeout(t); resolve(fallback); },
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface RootsProviderOptions {
|
|
69
|
+
getCwd: () => string;
|
|
70
|
+
getSessionDir: () => string | undefined;
|
|
71
|
+
getPiResources: () => PiResources;
|
|
72
|
+
probe?: (cwd: string) => Promise<string[]>;
|
|
73
|
+
probeBoundMs?: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export class RootsProvider {
|
|
77
|
+
private probePromise: Promise<string[]> | null = null;
|
|
78
|
+
private probeCwd: string | null = null;
|
|
79
|
+
private settled: string[] | null = null;
|
|
80
|
+
private probeGen = 0;
|
|
81
|
+
private cachedKey = "";
|
|
82
|
+
private cachedStatic: Omit<GateRoots, "grants" | "workspace"> | null = null;
|
|
83
|
+
|
|
84
|
+
constructor(private readonly opts: RootsProviderOptions) {}
|
|
85
|
+
|
|
86
|
+
/** Start (or restart for a new cwd) the bounded checkout probe. */
|
|
87
|
+
startProbe(cwdArg?: string): void {
|
|
88
|
+
const cwd = cwdArg ?? this.opts.getCwd();
|
|
89
|
+
if (this.probeCwd === cwd && this.probePromise !== null) return;
|
|
90
|
+
// Generation: a superseded probe (cwd changed while it ran) may still resolve
|
|
91
|
+
// later — it must never publish its checkout root for the NEW cwd.
|
|
92
|
+
const gen = ++this.probeGen;
|
|
93
|
+
this.probeCwd = cwd;
|
|
94
|
+
this.settled = null;
|
|
95
|
+
const probe = this.opts.probe ?? probeCheckoutRoots;
|
|
96
|
+
this.probePromise = withBound(probe(cwd), this.opts.probeBoundMs ?? PROBE_BOUND_MS, [] as string[]).then((r) => {
|
|
97
|
+
if (gen === this.probeGen) this.settled = r;
|
|
98
|
+
return r;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Workspace + built-ins. Awaits the probe only when it has not settled yet. */
|
|
103
|
+
async roots(grants: readonly string[], needsCheckout: boolean, cwdArg?: string): Promise<GateRoots> {
|
|
104
|
+
const cwd = cwdArg ?? this.opts.getCwd();
|
|
105
|
+
this.startProbe(cwd);
|
|
106
|
+
// The probe in flight belongs to `cwd` (startProbe above). Use only a result that
|
|
107
|
+
// was published for THIS cwd's generation; anything else means "not known yet".
|
|
108
|
+
const mine = this.probePromise as Promise<string[]>;
|
|
109
|
+
const gen = this.probeGen;
|
|
110
|
+
let checkout: string[] = this.settled ?? [];
|
|
111
|
+
if (this.settled === null && needsCheckout) {
|
|
112
|
+
const r = await mine;
|
|
113
|
+
checkout = gen === this.probeGen && this.probeCwd === cwd ? r : [];
|
|
114
|
+
}
|
|
115
|
+
const workspace = [realpathOr(cwd), ...checkout];
|
|
116
|
+
return { workspace, grants, ...this.staticRoots() };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** True when probe has settled (in-root latency budget applies from then). */
|
|
120
|
+
get probeSettled(): boolean {
|
|
121
|
+
return this.settled !== null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private staticRoots(): Omit<GateRoots, "grants" | "workspace"> {
|
|
125
|
+
const res = this.opts.getPiResources();
|
|
126
|
+
const sessionDir = this.opts.getSessionDir();
|
|
127
|
+
const key = JSON.stringify([res, sessionDir]);
|
|
128
|
+
if (this.cachedStatic && key === this.cachedKey) return this.cachedStatic;
|
|
129
|
+
const ro = [res.agentDir, res.docsDir, ...res.skillDirs, ...res.contextFiles]
|
|
130
|
+
.filter((x): x is string => !!x)
|
|
131
|
+
.map(realpathOr);
|
|
132
|
+
const rw = [os.tmpdir(), ...(nodePath.sep === "/" ? ["/tmp"] : []), ...(sessionDir ? [sessionDir] : [])].map(realpathOr);
|
|
133
|
+
this.cachedKey = key;
|
|
134
|
+
this.cachedStatic = { readOnly: ro, readWrite: rw };
|
|
135
|
+
return this.cachedStatic;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session "recently denied" map (D5): after a Deny / dismiss / timeout, any
|
|
3
|
+
* gated call under the same lexical parent directory is blocked without a prompt
|
|
4
|
+
* for 120 s. Keyed on the lexical parent, so a not-yet-existing `/w/newproj1/a`
|
|
5
|
+
* keys `/w/newproj1`, never the shared ancestor `/w`.
|
|
6
|
+
* See change: ask-agent-file-access-in-chat.
|
|
7
|
+
*/
|
|
8
|
+
const SUPPRESSION_MS = 120_000;
|
|
9
|
+
|
|
10
|
+
export class Suppression {
|
|
11
|
+
private denied = new Map<string, number>();
|
|
12
|
+
constructor(private readonly now: () => number = Date.now) {}
|
|
13
|
+
|
|
14
|
+
deny(key: string): void {
|
|
15
|
+
this.denied.set(key, this.now() + SUPPRESSION_MS);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
isSuppressed(key: string): boolean {
|
|
19
|
+
const until = this.denied.get(key);
|
|
20
|
+
if (until === undefined) return false;
|
|
21
|
+
if (this.now() >= until) {
|
|
22
|
+
this.denied.delete(key);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pending-prompt-emitter — the ONE emitter for re-sending every prompt the
|
|
3
|
+
* bridge's PromptBus is still awaiting an answer for.
|
|
4
|
+
*
|
|
5
|
+
* Two entry points share it so their frames cannot drift (D7):
|
|
6
|
+
* - the bridge's `onReconnect` replay (no token — every subscriber rebuilds),
|
|
7
|
+
* - the `prompt_resync_request` handler (echoes the requester token so the
|
|
8
|
+
* server unicasts each frame to the browser that asked).
|
|
9
|
+
*
|
|
10
|
+
* Frame shape is byte-identical to the bus's own `onDashboardRequest` emit:
|
|
11
|
+
* the original prompt id, resolved component and placement ride along, so a
|
|
12
|
+
* re-emitted prompt dedups against an already-rendered dialog on the client.
|
|
13
|
+
*
|
|
14
|
+
* An empty pending set emits nothing and raises no error (E10); entries whose
|
|
15
|
+
* component never resolved are skipped by `getPendingRequests()` itself —
|
|
16
|
+
* those were never routed to a dashboard, so excluding them is correct, not a
|
|
17
|
+
* gap (D6).
|
|
18
|
+
*
|
|
19
|
+
* See change: fix-pending-prompt-lost-on-replay (design D6/D7).
|
|
20
|
+
*/
|
|
21
|
+
import type { PromptBus } from "./prompt-bus.js";
|
|
22
|
+
|
|
23
|
+
/** The bridge's outbound frame sink (`connection.send` in practice). */
|
|
24
|
+
export type SendPromptFrame = (msg: Record<string, unknown>) => void;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Emit one `prompt_request` per pending prompt. When `resyncRequestId` is
|
|
28
|
+
* given it is echoed as `__resyncRequestId` on EVERY frame — the server's
|
|
29
|
+
* non-consuming requester lookup (peek) routes each of them to the requester.
|
|
30
|
+
* Returns how many frames were emitted.
|
|
31
|
+
*/
|
|
32
|
+
export function emitPendingPrompts(
|
|
33
|
+
promptBus: PromptBus,
|
|
34
|
+
send: SendPromptFrame,
|
|
35
|
+
sessionId: string,
|
|
36
|
+
resyncRequestId?: string,
|
|
37
|
+
): number {
|
|
38
|
+
let emitted = 0;
|
|
39
|
+
for (const { request, component, placement } of promptBus.getPendingRequests()) {
|
|
40
|
+
send({
|
|
41
|
+
type: "prompt_request",
|
|
42
|
+
sessionId,
|
|
43
|
+
promptId: request.id,
|
|
44
|
+
prompt: {
|
|
45
|
+
type: request.type,
|
|
46
|
+
question: request.question,
|
|
47
|
+
options: request.options,
|
|
48
|
+
defaultValue: request.defaultValue,
|
|
49
|
+
pipeline: request.pipeline,
|
|
50
|
+
metadata: request.metadata,
|
|
51
|
+
},
|
|
52
|
+
component,
|
|
53
|
+
placement,
|
|
54
|
+
...(resyncRequestId ? { __resyncRequestId: resyncRequestId } : {}),
|
|
55
|
+
});
|
|
56
|
+
emitted++;
|
|
57
|
+
}
|
|
58
|
+
return emitted;
|
|
59
|
+
}
|
package/src/pi-env.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ declare module "@earendil-works/pi-coding-agent" {
|
|
|
17
17
|
export interface ExtensionAPI {
|
|
18
18
|
on(event: string, handler: (...args: any[]) => any): void;
|
|
19
19
|
getCommands(): any[];
|
|
20
|
+
sendMessage<T = unknown>(
|
|
21
|
+
message: { customType: string; content: string; display: boolean; details?: T },
|
|
22
|
+
options?: { triggerTurn?: boolean; deliverAs?: "steer" | "followUp" | "nextTurn" },
|
|
23
|
+
): void;
|
|
20
24
|
sendUserMessage(message: string | any[]): void;
|
|
21
25
|
setSessionName(name: string): void;
|
|
22
26
|
getSessionName(): string | undefined;
|
|
@@ -24,21 +28,13 @@ declare module "@earendil-works/pi-coding-agent" {
|
|
|
24
28
|
registerTool(tool: any): void;
|
|
25
29
|
registerProvider(name: string, config: any): void;
|
|
26
30
|
unregisterProvider(name: string): void;
|
|
31
|
+
/** Append a durable custom entry to the session record (not sent to the LLM). */
|
|
32
|
+
appendEntry<T = unknown>(customType: string, data?: T): void;
|
|
27
33
|
exec(command: string, args: string[], options?: { timeout?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
28
34
|
events: EventBus;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
// Legacy fork — re-exports the same ExtensionAPI shape so existing installs still type-check.
|
|
33
|
-
declare module "@mariozechner/pi-coding-agent" {
|
|
34
|
-
export type ExtensionAPI = import("@earendil-works/pi-coding-agent").ExtensionAPI;
|
|
35
|
-
export type ModelRegistry = import("@earendil-works/pi-coding-agent").ModelRegistry;
|
|
36
|
-
export type EventBus = import("@earendil-works/pi-coding-agent").EventBus;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
38
|
declare module "@earendil-works/pi-ai" {
|
|
40
39
|
export function StringEnum<T extends readonly string[]>(values: T, schema?: Record<string, unknown>): any;
|
|
41
40
|
}
|
|
42
|
-
declare module "@mariozechner/pi-ai" {
|
|
43
|
-
export function StringEnum<T extends readonly string[]>(values: T, schema?: Record<string, unknown>): any;
|
|
44
|
-
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-retry-settings — READ-ONLY reader for pi's own agent-level retry policy.
|
|
3
|
+
*
|
|
4
|
+
* The bridge needs `retry.maxRetries` and `retry.baseDelayMs` purely to render
|
|
5
|
+
* the retry surface (attempt count + computed countdown). It NEVER writes these
|
|
6
|
+
* — only the dashboard's Retry settings surface does (capability
|
|
7
|
+
* `pi-retry-settings`). This module is the read half.
|
|
8
|
+
*
|
|
9
|
+
* Precedence mirrors pi's own settings merge: project `<cwd>/.pi/settings.json`
|
|
10
|
+
* overrides global `~/.pi/agent/settings.json`. Absent files / absent `retry`
|
|
11
|
+
* block → pi's defaults (`maxRetries: 3`, `baseDelayMs: 2000`). A file that
|
|
12
|
+
* exists but cannot be parsed → `baseDelayMs: 0`, which the surface renders as
|
|
13
|
+
* an elapsed-only waiting state rather than a bogus countdown.
|
|
14
|
+
*
|
|
15
|
+
* See change: retry-forever-with-stop-control (design D5, spec
|
|
16
|
+
* `bridge-retry-observability`).
|
|
17
|
+
*/
|
|
18
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
19
|
+
import { homedir } from "node:os";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
|
|
22
|
+
export interface PiRetrySettings {
|
|
23
|
+
/** pi's `retry.enabled`; default true. When false pi never retries at all. */
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
maxRetries: number;
|
|
26
|
+
baseDelayMs: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** pi's own defaults, applied when no `retry` block is present. */
|
|
30
|
+
export const PI_RETRY_DEFAULTS: PiRetrySettings = {
|
|
31
|
+
enabled: true,
|
|
32
|
+
maxRetries: 3,
|
|
33
|
+
baseDelayMs: 2000,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
interface ReadDeps {
|
|
37
|
+
/** Override for tests. Defaults to `os.homedir()`. */
|
|
38
|
+
home?: string;
|
|
39
|
+
/** Session cwd for the project-scoped override. Defaults to `process.cwd()`. */
|
|
40
|
+
cwd?: string;
|
|
41
|
+
/** Override file reader for tests. */
|
|
42
|
+
readFile?: (path: string) => string;
|
|
43
|
+
/** Override existence check for tests. */
|
|
44
|
+
fileExists?: (path: string) => boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Pull `retry.{enabled,maxRetries,baseDelayMs}` from one parsed settings blob. */
|
|
48
|
+
function extract(raw: unknown): Partial<PiRetrySettings> {
|
|
49
|
+
if (!raw || typeof raw !== "object") return {};
|
|
50
|
+
const retry = (raw as { retry?: unknown }).retry;
|
|
51
|
+
if (!retry || typeof retry !== "object") return {};
|
|
52
|
+
const out: Partial<PiRetrySettings> = {};
|
|
53
|
+
const en = (retry as { enabled?: unknown }).enabled;
|
|
54
|
+
const mr = (retry as { maxRetries?: unknown }).maxRetries;
|
|
55
|
+
const bd = (retry as { baseDelayMs?: unknown }).baseDelayMs;
|
|
56
|
+
if (typeof en === "boolean") out.enabled = en;
|
|
57
|
+
if (typeof mr === "number" && Number.isFinite(mr)) out.maxRetries = mr;
|
|
58
|
+
if (typeof bd === "number" && Number.isFinite(bd)) out.baseDelayMs = bd;
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Read pi's effective retry policy. Never throws — a parse failure degrades to
|
|
64
|
+
* `baseDelayMs: 0` (elapsed-only) rather than surfacing an error.
|
|
65
|
+
*/
|
|
66
|
+
export function readPiRetrySettings(deps: ReadDeps = {}): PiRetrySettings {
|
|
67
|
+
const home = deps.home ?? homedir();
|
|
68
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
69
|
+
const read = deps.readFile ?? ((p: string) => readFileSync(p, "utf-8"));
|
|
70
|
+
const exists = deps.fileExists ?? existsSync;
|
|
71
|
+
|
|
72
|
+
const globalPath = join(home, ".pi", "agent", "settings.json");
|
|
73
|
+
const projectPath = join(cwd, ".pi", "settings.json");
|
|
74
|
+
|
|
75
|
+
let merged: PiRetrySettings = { ...PI_RETRY_DEFAULTS };
|
|
76
|
+
let parseFailed = false;
|
|
77
|
+
|
|
78
|
+
for (const path of [globalPath, projectPath]) {
|
|
79
|
+
if (!exists(path)) continue;
|
|
80
|
+
try {
|
|
81
|
+
merged = { ...merged, ...extract(JSON.parse(read(path))) };
|
|
82
|
+
} catch {
|
|
83
|
+
parseFailed = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// A file existed but could not be parsed → we cannot trust the delay math;
|
|
88
|
+
// render elapsed-only instead of a fabricated countdown.
|
|
89
|
+
if (parseFailed) return { enabled: merged.enabled, maxRetries: merged.maxRetries, baseDelayMs: 0 };
|
|
90
|
+
return merged;
|
|
91
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge half of the private plugin request/reply lane.
|
|
3
|
+
*
|
|
4
|
+
* While the bridge is connected it installs a Promise-returning function at
|
|
5
|
+
* `globalThis[Symbol.for("pi-dashboard.pluginRequest")]`. A plugin bridge
|
|
6
|
+
* entry calls it; the request travels as `plugin_request` on the bridge
|
|
7
|
+
* socket and resolves when the matching `plugin_reply` arrives. The reply
|
|
8
|
+
* resolves a Promise held only by the caller — `pi.events` is never touched,
|
|
9
|
+
* so other extensions can neither observe nor forge it.
|
|
10
|
+
*
|
|
11
|
+
* No pi dependency (same shape as mcp-token-delivery.ts).
|
|
12
|
+
* See change: expose-plugin-credential-and-oauth-seams (D7).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { randomUUID } from "node:crypto";
|
|
16
|
+
|
|
17
|
+
export const PLUGIN_REQUEST_SYMBOL = Symbol.for("pi-dashboard.pluginRequest");
|
|
18
|
+
const PLUGIN_REQUEST_TIMEOUT_MS = 15_000;
|
|
19
|
+
export const PLUGIN_REQUEST_MAX_BYTES = 256 * 1024;
|
|
20
|
+
|
|
21
|
+
type PluginLaneReply =
|
|
22
|
+
| { ok: true; result: unknown }
|
|
23
|
+
| { ok: false; error: string };
|
|
24
|
+
|
|
25
|
+
export type PluginRequestFn = (
|
|
26
|
+
pluginId: string,
|
|
27
|
+
messageType: string,
|
|
28
|
+
payload?: unknown,
|
|
29
|
+
) => Promise<PluginLaneReply>;
|
|
30
|
+
|
|
31
|
+
export interface PluginRequestClientDeps {
|
|
32
|
+
/** Sends one frame on the OPEN bridge socket; `false` = not sent (never buffered). */
|
|
33
|
+
send: (msg: unknown) => boolean;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
newId?: () => string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface PluginRequestClient {
|
|
39
|
+
request: PluginRequestFn;
|
|
40
|
+
/** Feed an inbound `plugin_reply`. Unknown / late ids are dropped. */
|
|
41
|
+
handleReply(msg: { requestId?: unknown; ok?: unknown; result?: unknown; error?: unknown }): void;
|
|
42
|
+
/** Resolve every pending call with `error` (socket closed). */
|
|
43
|
+
failAll(error: string): void;
|
|
44
|
+
pendingCount(): number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createPluginRequestClient(deps: PluginRequestClientDeps): PluginRequestClient {
|
|
48
|
+
const timeoutMs = deps.timeoutMs ?? PLUGIN_REQUEST_TIMEOUT_MS;
|
|
49
|
+
const newId = deps.newId ?? randomUUID;
|
|
50
|
+
const pending = new Map<string, { resolve: (r: PluginLaneReply) => void; timer: NodeJS.Timeout }>();
|
|
51
|
+
|
|
52
|
+
const settle = (id: string, reply: PluginLaneReply): void => {
|
|
53
|
+
const entry = pending.get(id);
|
|
54
|
+
if (!entry) return;
|
|
55
|
+
pending.delete(id);
|
|
56
|
+
clearTimeout(entry.timer);
|
|
57
|
+
entry.resolve(reply);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
request(pluginId, messageType, payload) {
|
|
62
|
+
let json: string | undefined;
|
|
63
|
+
try {
|
|
64
|
+
json = JSON.stringify(payload === undefined ? null : payload);
|
|
65
|
+
} catch {
|
|
66
|
+
return Promise.resolve({ ok: false, error: "request_not_serializable" });
|
|
67
|
+
}
|
|
68
|
+
if (Buffer.byteLength(json ?? "null", "utf-8") > PLUGIN_REQUEST_MAX_BYTES) {
|
|
69
|
+
return Promise.resolve({ ok: false, error: "request_too_large" });
|
|
70
|
+
}
|
|
71
|
+
const requestId = newId();
|
|
72
|
+
return new Promise<PluginLaneReply>((resolve) => {
|
|
73
|
+
const timer = setTimeout(() => settle(requestId, { ok: false, error: "timeout" }), timeoutMs);
|
|
74
|
+
timer.unref?.();
|
|
75
|
+
pending.set(requestId, { resolve, timer });
|
|
76
|
+
let sent = false;
|
|
77
|
+
try {
|
|
78
|
+
sent = deps.send({
|
|
79
|
+
type: "plugin_request",
|
|
80
|
+
requestId,
|
|
81
|
+
pluginId,
|
|
82
|
+
messageType,
|
|
83
|
+
payload: JSON.parse(json ?? "null"),
|
|
84
|
+
});
|
|
85
|
+
} catch {
|
|
86
|
+
sent = false;
|
|
87
|
+
}
|
|
88
|
+
if (!sent) settle(requestId, { ok: false, error: "disconnected" });
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
handleReply(msg) {
|
|
92
|
+
if (typeof msg.requestId !== "string") return;
|
|
93
|
+
settle(
|
|
94
|
+
msg.requestId,
|
|
95
|
+
msg.ok === true
|
|
96
|
+
? { ok: true, result: msg.result }
|
|
97
|
+
: { ok: false, error: typeof msg.error === "string" ? msg.error : "error" },
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
failAll(error) {
|
|
101
|
+
for (const id of [...pending.keys()]) settle(id, { ok: false, error });
|
|
102
|
+
},
|
|
103
|
+
pendingCount: () => pending.size,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Install `fn` at the global symbol; returns an uninstaller that only removes OUR fn. */
|
|
108
|
+
export function installPluginRequest(fn: PluginRequestFn): () => void {
|
|
109
|
+
const g = globalThis as Record<symbol, unknown>;
|
|
110
|
+
g[PLUGIN_REQUEST_SYMBOL] = fn;
|
|
111
|
+
return () => {
|
|
112
|
+
if (g[PLUGIN_REQUEST_SYMBOL] === fn) delete g[PLUGIN_REQUEST_SYMBOL];
|
|
113
|
+
};
|
|
114
|
+
}
|
package/src/poll-cost.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Poll-cost counters (change: optimize-polling-hot-paths). A plain counter
|
|
3
|
+
* object incremented from the EXISTING scan/git call sites and spread into
|
|
4
|
+
* the heartbeat `metrics`. Cumulative for the bridge's lifetime; the server
|
|
5
|
+
* sums each field across live sessions on `/api/health`.
|
|
6
|
+
*/
|
|
7
|
+
export interface PollCost {
|
|
8
|
+
pollProcScanRuns: number;
|
|
9
|
+
pollProcScanSpawns: number;
|
|
10
|
+
pollProcScanMs: number;
|
|
11
|
+
pollGitProbesTick: number;
|
|
12
|
+
pollGitProbesTool: number;
|
|
13
|
+
pollGitProbesWatch: number;
|
|
14
|
+
pollGitProbesRefresh: number;
|
|
15
|
+
pollGitSpawns: number;
|
|
16
|
+
pollGitMs: number;
|
|
17
|
+
pollGitWatchersAttached: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const pollCost: PollCost = {
|
|
21
|
+
pollProcScanRuns: 0,
|
|
22
|
+
pollProcScanSpawns: 0,
|
|
23
|
+
pollProcScanMs: 0,
|
|
24
|
+
pollGitProbesTick: 0,
|
|
25
|
+
pollGitProbesTool: 0,
|
|
26
|
+
pollGitProbesWatch: 0,
|
|
27
|
+
pollGitProbesRefresh: 0,
|
|
28
|
+
pollGitSpawns: 0,
|
|
29
|
+
pollGitMs: 0,
|
|
30
|
+
pollGitWatchersAttached: 0,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function incPollCost(key: keyof PollCost, by = 1): void {
|
|
34
|
+
pollCost[key] += by;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Test-only reset. */
|
|
38
|
+
export function __resetPollCostForTests(): void {
|
|
39
|
+
for (const k of Object.keys(pollCost) as (keyof PollCost)[]) pollCost[k] = 0;
|
|
40
|
+
}
|