@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
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the bridge's shadow-queue streaming gate.
|
|
3
|
-
*
|
|
4
|
-
* Repro for the bug "STEERING (1) appears on the very first message to an
|
|
5
|
-
* idle session". The fix has TWO layers:
|
|
6
|
-
*
|
|
7
|
-
* 1. Capture-before-send (primary gate): at the call site of
|
|
8
|
-
* `pi.sendUserMessage`, the caller MUST snapshot
|
|
9
|
-
* `isAgentStreaming` BEFORE invoking sendUserMessage. Pi flips
|
|
10
|
-
* idle→streaming synchronously inside sendUserMessage by emitting
|
|
11
|
-
* `agent_start`, whose handler in bridge.ts flips the flag in its
|
|
12
|
-
* first sync line. Checking the flag AFTER the send always reads
|
|
13
|
-
* true — the original bug. Tests `record*Sent + wasStreaming`
|
|
14
|
-
* encode that contract.
|
|
15
|
-
*
|
|
16
|
-
* 2. Internal gate (defense in depth): `recordSteerSent` /
|
|
17
|
-
* `recordFollowupSent` themselves re-check `isStreaming()` so a
|
|
18
|
-
* caller that forgets to capture pre-send still doesn't corrupt
|
|
19
|
-
* the shadow queue.
|
|
20
|
-
*
|
|
21
|
-
* See change: add-followup-edit-and-steer-cancel.
|
|
22
|
-
*/
|
|
23
|
-
import { describe, it, expect, vi } from "vitest";
|
|
24
|
-
|
|
25
|
-
interface ShadowQueue {
|
|
26
|
-
steering: string[];
|
|
27
|
-
followUp: string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Pure version of the gate as it lives in bridge.ts. Mirrors the closure
|
|
32
|
-
* logic 1:1; if the production code drifts from this shape, this test
|
|
33
|
-
* should drift in lockstep.
|
|
34
|
-
*/
|
|
35
|
-
function makeShadowRecorder(opts: {
|
|
36
|
-
isStreaming: () => boolean;
|
|
37
|
-
onEmit: (snapshot: ShadowQueue) => void;
|
|
38
|
-
}) {
|
|
39
|
-
const queue: ShadowQueue = { steering: [], followUp: [] };
|
|
40
|
-
function emit() { opts.onEmit({ steering: [...queue.steering], followUp: [...queue.followUp] }); }
|
|
41
|
-
function recordSteer(text: string) {
|
|
42
|
-
if (!opts.isStreaming()) return;
|
|
43
|
-
queue.steering.push(text);
|
|
44
|
-
emit();
|
|
45
|
-
}
|
|
46
|
-
function recordFollowup(text: string) {
|
|
47
|
-
if (!opts.isStreaming()) return;
|
|
48
|
-
queue.followUp = [text];
|
|
49
|
-
emit();
|
|
50
|
-
}
|
|
51
|
-
function clearSteer() { queue.steering = []; emit(); }
|
|
52
|
-
function clearFollowup() { queue.followUp = []; emit(); }
|
|
53
|
-
function drainSteerOnTurnEnd() { if (queue.steering.length > 0) { queue.steering = []; emit(); } }
|
|
54
|
-
function drainFollowupOnAgentEnd() { if (queue.followUp.length > 0) { queue.followUp = []; emit(); } }
|
|
55
|
-
return { recordSteer, recordFollowup, clearSteer, clearFollowup, drainSteerOnTurnEnd, drainFollowupOnAgentEnd, snapshot: () => ({ ...queue, steering: [...queue.steering], followUp: [...queue.followUp] }) };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
describe("bridge shadow queue: streaming gate", () => {
|
|
59
|
-
it("recordSteer is a no-op when isStreaming === false (idle first message)", () => {
|
|
60
|
-
let streaming = false;
|
|
61
|
-
const onEmit = vi.fn();
|
|
62
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
63
|
-
|
|
64
|
-
r.recordSteer("hello");
|
|
65
|
-
|
|
66
|
-
expect(r.snapshot().steering).toEqual([]);
|
|
67
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("recordFollowup is a no-op when isStreaming === false (idle first message)", () => {
|
|
71
|
-
let streaming = false;
|
|
72
|
-
const onEmit = vi.fn();
|
|
73
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
74
|
-
|
|
75
|
-
r.recordFollowup("after done");
|
|
76
|
-
|
|
77
|
-
expect(r.snapshot().followUp).toEqual([]);
|
|
78
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("recordSteer appends + emits when streaming", () => {
|
|
82
|
-
let streaming = true;
|
|
83
|
-
const onEmit = vi.fn();
|
|
84
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
85
|
-
|
|
86
|
-
r.recordSteer("A");
|
|
87
|
-
r.recordSteer("B");
|
|
88
|
-
|
|
89
|
-
expect(r.snapshot().steering).toEqual(["A", "B"]);
|
|
90
|
-
expect(onEmit).toHaveBeenCalledTimes(2);
|
|
91
|
-
expect(onEmit.mock.calls[1][0]).toEqual({ steering: ["A", "B"], followUp: [] });
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("recordFollowup replaces slot + emits when streaming (capacity 1)", () => {
|
|
95
|
-
let streaming = true;
|
|
96
|
-
const onEmit = vi.fn();
|
|
97
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
98
|
-
|
|
99
|
-
r.recordFollowup("first");
|
|
100
|
-
r.recordFollowup("second");
|
|
101
|
-
|
|
102
|
-
expect(r.snapshot().followUp).toEqual(["second"]);
|
|
103
|
-
expect(onEmit).toHaveBeenCalledTimes(2);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("bridge shadow queue: drain boundaries", () => {
|
|
108
|
-
it("turn_end drains steering only (followUp untouched)", () => {
|
|
109
|
-
let streaming = true;
|
|
110
|
-
const onEmit = vi.fn();
|
|
111
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
112
|
-
r.recordSteer("s1");
|
|
113
|
-
r.recordFollowup("f1");
|
|
114
|
-
onEmit.mockClear();
|
|
115
|
-
|
|
116
|
-
r.drainSteerOnTurnEnd();
|
|
117
|
-
|
|
118
|
-
expect(r.snapshot()).toEqual({ steering: [], followUp: ["f1"] });
|
|
119
|
-
expect(onEmit).toHaveBeenCalledTimes(1);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("agent_end drains followUp only (steering untouched)", () => {
|
|
123
|
-
let streaming = true;
|
|
124
|
-
const onEmit = vi.fn();
|
|
125
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
126
|
-
r.recordSteer("s1");
|
|
127
|
-
r.recordFollowup("f1");
|
|
128
|
-
onEmit.mockClear();
|
|
129
|
-
|
|
130
|
-
r.drainFollowupOnAgentEnd();
|
|
131
|
-
|
|
132
|
-
expect(r.snapshot()).toEqual({ steering: ["s1"], followUp: [] });
|
|
133
|
-
expect(onEmit).toHaveBeenCalledTimes(1);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("turn_end on empty steering does NOT emit (idempotent / no spurious broadcasts)", () => {
|
|
137
|
-
const onEmit = vi.fn();
|
|
138
|
-
const r = makeShadowRecorder({ isStreaming: () => true, onEmit });
|
|
139
|
-
|
|
140
|
-
r.drainSteerOnTurnEnd();
|
|
141
|
-
|
|
142
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("agent_end on empty followUp does NOT emit", () => {
|
|
146
|
-
const onEmit = vi.fn();
|
|
147
|
-
const r = makeShadowRecorder({ isStreaming: () => true, onEmit });
|
|
148
|
-
|
|
149
|
-
r.drainFollowupOnAgentEnd();
|
|
150
|
-
|
|
151
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe("bridge shadow queue: clears", () => {
|
|
156
|
-
it("clearSteer wipes + emits regardless of streaming state", () => {
|
|
157
|
-
let streaming = false;
|
|
158
|
-
const onEmit = vi.fn();
|
|
159
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
160
|
-
// Populate via a streaming-on phase, then go idle and clear.
|
|
161
|
-
streaming = true; r.recordSteer("x"); streaming = false; onEmit.mockClear();
|
|
162
|
-
|
|
163
|
-
r.clearSteer();
|
|
164
|
-
|
|
165
|
-
expect(r.snapshot().steering).toEqual([]);
|
|
166
|
-
expect(onEmit).toHaveBeenCalledTimes(1);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("clearFollowup wipes + emits regardless of streaming state", () => {
|
|
170
|
-
let streaming = false;
|
|
171
|
-
const onEmit = vi.fn();
|
|
172
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
173
|
-
streaming = true; r.recordFollowup("y"); streaming = false; onEmit.mockClear();
|
|
174
|
-
|
|
175
|
-
r.clearFollowup();
|
|
176
|
-
|
|
177
|
-
expect(r.snapshot().followUp).toEqual([]);
|
|
178
|
-
expect(onEmit).toHaveBeenCalledTimes(1);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe("bridge shadow queue: capture-before-send semantics (PRIMARY gate)", () => {
|
|
183
|
-
// Simulates the command-handler / sessionPrompt call sites where the bug
|
|
184
|
-
// originally lived. The fix: capture streaming state into a local var
|
|
185
|
-
// BEFORE calling pi.sendUserMessage. The internal recordX gate is a
|
|
186
|
-
// safety net only.
|
|
187
|
-
|
|
188
|
-
/** Stand-in for the simplified call-site logic in command-handler.ts. */
|
|
189
|
-
function send(opts: {
|
|
190
|
-
text: string;
|
|
191
|
-
delivery: "steer" | "followUp";
|
|
192
|
-
isStreaming: () => boolean;
|
|
193
|
-
piSendUserMessage: () => void; // simulates the synchronous agent_start flip
|
|
194
|
-
onSteer: (text: string) => void;
|
|
195
|
-
onFollowup: (text: string) => void;
|
|
196
|
-
}) {
|
|
197
|
-
const wasStreaming = opts.isStreaming();
|
|
198
|
-
opts.piSendUserMessage();
|
|
199
|
-
if (wasStreaming) {
|
|
200
|
-
if (opts.delivery === "steer") opts.onSteer(opts.text);
|
|
201
|
-
else opts.onFollowup(opts.text);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
it("idle send DOES NOT record even when pi flips isStreaming synchronously inside sendUserMessage", () => {
|
|
206
|
-
let streaming = false;
|
|
207
|
-
const onEmit = vi.fn();
|
|
208
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
209
|
-
|
|
210
|
-
send({
|
|
211
|
-
text: "first message",
|
|
212
|
-
delivery: "steer",
|
|
213
|
-
isStreaming: () => streaming,
|
|
214
|
-
// Pi receives the message, fires agent_start synchronously, which
|
|
215
|
-
// flips `streaming` to true. This was the original bug.
|
|
216
|
-
piSendUserMessage: () => { streaming = true; },
|
|
217
|
-
onSteer: r.recordSteer,
|
|
218
|
-
onFollowup: r.recordFollowup,
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
expect(r.snapshot()).toEqual({ steering: [], followUp: [] });
|
|
222
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("streaming send DOES record (chip appears for mid-turn steer)", () => {
|
|
226
|
-
let streaming = true;
|
|
227
|
-
const onEmit = vi.fn();
|
|
228
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
229
|
-
|
|
230
|
-
send({
|
|
231
|
-
text: "redirect",
|
|
232
|
-
delivery: "steer",
|
|
233
|
-
isStreaming: () => streaming,
|
|
234
|
-
piSendUserMessage: () => { /* still streaming */ },
|
|
235
|
-
onSteer: r.recordSteer,
|
|
236
|
-
onFollowup: r.recordFollowup,
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
expect(r.snapshot().steering).toEqual(["redirect"]);
|
|
240
|
-
expect(onEmit).toHaveBeenCalledTimes(1);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("idle followUp also DOES NOT record (same race shape)", () => {
|
|
244
|
-
let streaming = false;
|
|
245
|
-
const onEmit = vi.fn();
|
|
246
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
247
|
-
|
|
248
|
-
send({
|
|
249
|
-
text: "after done",
|
|
250
|
-
delivery: "followUp",
|
|
251
|
-
isStreaming: () => streaming,
|
|
252
|
-
piSendUserMessage: () => { streaming = true; },
|
|
253
|
-
onSteer: r.recordSteer,
|
|
254
|
-
onFollowup: r.recordFollowup,
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
expect(r.snapshot()).toEqual({ steering: [], followUp: [] });
|
|
258
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
describe("bridge shadow queue: realistic follow-up scenario", () => {
|
|
263
|
-
it("send followUp while idle (first message of session) shows no chip", () => {
|
|
264
|
-
let streaming = false;
|
|
265
|
-
const onEmit = vi.fn();
|
|
266
|
-
const r = makeShadowRecorder({ isStreaming: () => streaming, onEmit });
|
|
267
|
-
|
|
268
|
-
// User sends their initial prompt; pi starts a new turn directly,
|
|
269
|
-
// it doesn't queue. The bridge must NOT record a chip.
|
|
270
|
-
r.recordFollowup("kick off the task");
|
|
271
|
-
|
|
272
|
-
expect(r.snapshot().followUp).toEqual([]);
|
|
273
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
274
|
-
|
|
275
|
-
// Pi fires agent_start → streaming flips on.
|
|
276
|
-
streaming = true;
|
|
277
|
-
|
|
278
|
-
// User adds a follow-up mid-stream → chip appears.
|
|
279
|
-
r.recordFollowup("when you finish, run the tests");
|
|
280
|
-
expect(r.snapshot().followUp).toEqual(["when you finish, run the tests"]);
|
|
281
|
-
expect(onEmit).toHaveBeenCalledTimes(1);
|
|
282
|
-
|
|
283
|
-
// Agent finishes → followUp drains.
|
|
284
|
-
r.drainFollowupOnAgentEnd();
|
|
285
|
-
expect(r.snapshot().followUp).toEqual([]);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it("rapid edit (steering still active) replaces slot atomically", () => {
|
|
289
|
-
const onEmit = vi.fn();
|
|
290
|
-
const r = makeShadowRecorder({ isStreaming: () => true, onEmit });
|
|
291
|
-
|
|
292
|
-
r.recordFollowup("v1");
|
|
293
|
-
r.recordFollowup("v2");
|
|
294
|
-
r.recordFollowup("v3");
|
|
295
|
-
|
|
296
|
-
expect(r.snapshot().followUp).toEqual(["v3"]);
|
|
297
|
-
expect(onEmit).toHaveBeenCalledTimes(3);
|
|
298
|
-
});
|
|
299
|
-
});
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the bridge's shutdown extension command.
|
|
3
|
-
*
|
|
4
|
-
* Negative-assertion model: pi's ExtensionAPI does NOT expose
|
|
5
|
-
* clearSteeringQueue / clearFollowUpQueue to extensions (verified through
|
|
6
|
-
* pi 0.76.0). The bridge therefore SHALL NOT call them. Shadow queues
|
|
7
|
-
* persist across shutdown because pi's real queues persist until process
|
|
8
|
-
* exit. No final queue_update is emitted.
|
|
9
|
-
*
|
|
10
|
-
* Pure-model mirror of bridge.ts `shutdown` extension command.
|
|
11
|
-
*
|
|
12
|
-
* Spec: openspec/specs/mid-turn-prompt-queue/spec.md — requirement
|
|
13
|
-
* "Session shutdown invokes cachedCtx.shutdown directly".
|
|
14
|
-
*
|
|
15
|
-
* See change: honest-mid-turn-queue-surface.
|
|
16
|
-
*/
|
|
17
|
-
import { describe, it, expect, vi } from "vitest";
|
|
18
|
-
|
|
19
|
-
interface ShadowQueue {
|
|
20
|
-
steering: string[];
|
|
21
|
-
followUp: string[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface PiLike {
|
|
25
|
-
// Defined as optional so tests can verify they are NEVER invoked even
|
|
26
|
-
// when present on the pi object (e.g. if a future pi version adds them
|
|
27
|
-
// back to the ExtensionAPI surface — the dashboard's current honest
|
|
28
|
-
// policy is to ignore them).
|
|
29
|
-
clearSteeringQueue?: () => void;
|
|
30
|
-
clearFollowUpQueue?: () => void;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface CachedCtxLike {
|
|
34
|
-
shutdown?: () => void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Pure version of the shutdown extension command. Mirrors bridge.ts 1:1.
|
|
39
|
-
*/
|
|
40
|
-
function makeShutdown(opts: {
|
|
41
|
-
pi: PiLike;
|
|
42
|
-
cachedCtx: CachedCtxLike | null;
|
|
43
|
-
queue: ShadowQueue;
|
|
44
|
-
onEmit: (snapshot: { steering: string[]; followUp: string[] }) => void;
|
|
45
|
-
onProcessExit: () => void;
|
|
46
|
-
callLog: string[];
|
|
47
|
-
}) {
|
|
48
|
-
return () => {
|
|
49
|
-
// Pi exposes no clear*Queue to extensions; shadow stays as-is.
|
|
50
|
-
if (opts.cachedCtx?.shutdown) {
|
|
51
|
-
opts.callLog.push("cachedCtx.shutdown");
|
|
52
|
-
opts.cachedCtx.shutdown();
|
|
53
|
-
}
|
|
54
|
-
opts.callLog.push("setTimeout(process.exit)");
|
|
55
|
-
opts.onProcessExit();
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
describe("bridge shutdown: invokes cachedCtx.shutdown directly", () => {
|
|
60
|
-
it("non-empty shadows: shadows stay populated, no clear*, no emit", () => {
|
|
61
|
-
const queue: ShadowQueue = { steering: ["focus on X"], followUp: ["run tests"] };
|
|
62
|
-
const onEmit = vi.fn();
|
|
63
|
-
const clearSteer = vi.fn();
|
|
64
|
-
const clearFollow = vi.fn();
|
|
65
|
-
const pi: PiLike = { clearSteeringQueue: clearSteer, clearFollowUpQueue: clearFollow };
|
|
66
|
-
const cachedCtx: CachedCtxLike = { shutdown: vi.fn() };
|
|
67
|
-
|
|
68
|
-
makeShutdown({ pi, cachedCtx, queue, onEmit, onProcessExit: vi.fn(), callLog: [] })();
|
|
69
|
-
|
|
70
|
-
// Shadows preserved — pi's real queues also persist until process exit
|
|
71
|
-
expect(queue.steering).toEqual(["focus on X"]);
|
|
72
|
-
expect(queue.followUp).toEqual(["run tests"]);
|
|
73
|
-
// Bridge does NOT call pi.clear* — they are no-ops via the ExtensionAPI
|
|
74
|
-
expect(clearSteer).not.toHaveBeenCalled();
|
|
75
|
-
expect(clearFollow).not.toHaveBeenCalled();
|
|
76
|
-
// No misleading "queues drained" emission
|
|
77
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("empty shadows: still no clear*, no emit, still runs cachedCtx.shutdown + safety net", () => {
|
|
81
|
-
const queue: ShadowQueue = { steering: [], followUp: [] };
|
|
82
|
-
const onEmit = vi.fn();
|
|
83
|
-
const clearSteer = vi.fn();
|
|
84
|
-
const clearFollow = vi.fn();
|
|
85
|
-
const pi: PiLike = { clearSteeringQueue: clearSteer, clearFollowUpQueue: clearFollow };
|
|
86
|
-
const cachedShutdown = vi.fn();
|
|
87
|
-
const onProcessExit = vi.fn();
|
|
88
|
-
|
|
89
|
-
makeShutdown({
|
|
90
|
-
pi,
|
|
91
|
-
cachedCtx: { shutdown: cachedShutdown },
|
|
92
|
-
queue,
|
|
93
|
-
onEmit,
|
|
94
|
-
onProcessExit,
|
|
95
|
-
callLog: [],
|
|
96
|
-
})();
|
|
97
|
-
|
|
98
|
-
expect(clearSteer).not.toHaveBeenCalled();
|
|
99
|
-
expect(clearFollow).not.toHaveBeenCalled();
|
|
100
|
-
expect(onEmit).not.toHaveBeenCalled();
|
|
101
|
-
expect(cachedShutdown).toHaveBeenCalledTimes(1);
|
|
102
|
-
expect(onProcessExit).toHaveBeenCalledTimes(1);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("pi version with clear* methods present: still NOT called (honest policy)", () => {
|
|
106
|
-
// Even if a future pi build re-adds the methods to the ExtensionAPI,
|
|
107
|
-
// the current bridge SHALL NOT call them. A future OpenSpec change
|
|
108
|
-
// (restore-mid-turn-queue-mutation) would re-introduce calls together
|
|
109
|
-
// with the protocol + UI affordances.
|
|
110
|
-
const queue: ShadowQueue = { steering: ["a"], followUp: ["b"] };
|
|
111
|
-
const clearSteer = vi.fn();
|
|
112
|
-
const clearFollow = vi.fn();
|
|
113
|
-
const pi: PiLike = { clearSteeringQueue: clearSteer, clearFollowUpQueue: clearFollow };
|
|
114
|
-
|
|
115
|
-
makeShutdown({
|
|
116
|
-
pi,
|
|
117
|
-
cachedCtx: { shutdown: vi.fn() },
|
|
118
|
-
queue,
|
|
119
|
-
onEmit: vi.fn(),
|
|
120
|
-
onProcessExit: vi.fn(),
|
|
121
|
-
callLog: [],
|
|
122
|
-
})();
|
|
123
|
-
|
|
124
|
-
expect(clearSteer).not.toHaveBeenCalled();
|
|
125
|
-
expect(clearFollow).not.toHaveBeenCalled();
|
|
126
|
-
expect(queue).toEqual({ steering: ["a"], followUp: ["b"] });
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("order of operations: cachedCtx.shutdown → setTimeout(process.exit) only", () => {
|
|
130
|
-
const queue: ShadowQueue = { steering: ["a"], followUp: ["b"] };
|
|
131
|
-
const callLog: string[] = [];
|
|
132
|
-
const pi: PiLike = { clearSteeringQueue: vi.fn(), clearFollowUpQueue: vi.fn() };
|
|
133
|
-
const cachedCtx: CachedCtxLike = { shutdown: vi.fn() };
|
|
134
|
-
|
|
135
|
-
makeShutdown({ pi, cachedCtx, queue, onEmit: vi.fn(), onProcessExit: vi.fn(), callLog })();
|
|
136
|
-
|
|
137
|
-
expect(callLog).toEqual([
|
|
138
|
-
"cachedCtx.shutdown",
|
|
139
|
-
"setTimeout(process.exit)",
|
|
140
|
-
]);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("cachedCtx is null: safety-net process.exit still fires", () => {
|
|
144
|
-
const queue: ShadowQueue = { steering: ["a"], followUp: [] };
|
|
145
|
-
const onProcessExit = vi.fn();
|
|
146
|
-
const pi: PiLike = { clearSteeringQueue: vi.fn(), clearFollowUpQueue: vi.fn() };
|
|
147
|
-
|
|
148
|
-
makeShutdown({
|
|
149
|
-
pi,
|
|
150
|
-
cachedCtx: null,
|
|
151
|
-
queue,
|
|
152
|
-
onEmit: vi.fn(),
|
|
153
|
-
onProcessExit,
|
|
154
|
-
callLog: [],
|
|
155
|
-
})();
|
|
156
|
-
|
|
157
|
-
expect(onProcessExit).toHaveBeenCalledTimes(1);
|
|
158
|
-
});
|
|
159
|
-
});
|