@blackbelt-technology/pi-dashboard-extension 0.5.4 → 0.6.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/LICENSE +201 -0
- package/.pi/skills/browser/SKILL.md +105 -0
- package/.pi/skills/browser/UPSTREAM.md +46 -0
- package/.pi/skills/browser/references/electron.md +351 -0
- package/.pi/skills/browser/references/web.md +2789 -0
- package/.pi/skills/browser/scripts/detect-dashboard.sh +55 -0
- package/.pi/skills/doctor/AGENTS.md +27 -0
- package/.pi/skills/doctor/SKILL.md +89 -0
- package/.pi/skills/doctor/_lib/checks.ts +177 -0
- package/.pi/skills/doctor/_lib/derive-tokens.ts +43 -0
- package/.pi/skills/doctor/_lib/front-matter.ts +122 -0
- package/.pi/skills/doctor/_lib/index.ts +14 -0
- package/.pi/skills/doctor/_lib/knowledge-hash.ts +74 -0
- package/.pi/skills/doctor/_lib/provenance.ts +50 -0
- package/.pi/skills/doctor/_lib/regenerate.ts +100 -0
- package/.pi/skills/doctor/_lib/router.ts +155 -0
- package/.pi/skills/doctor/_lib/server-tier.ts +62 -0
- package/.pi/skills/doctor/modules/build-reload.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/build-reload.md +51 -0
- package/.pi/skills/doctor/modules/env-node.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/env-node.md +49 -0
- package/.pi/skills/doctor/modules/install-topology.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/install-topology.md +53 -0
- package/.pi/skills/doctor/modules/model-resolution.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/model-resolution.md +53 -0
- package/.pi/skills/doctor/modules/peers.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/peers.md +57 -0
- package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/pi-resolution.md +60 -0
- package/.pi/skills/doctor/modules/plugins-bridges.knowledge.hash +1 -0
- package/.pi/skills/doctor/modules/plugins-bridges.md +56 -0
- package/.pi/skills/pi-dashboard/SKILL.md +68 -0
- package/.pi/skills/pi-dashboard/commands/README.md +45 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-flow-abort.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-flow-auto.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-git-branches.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-git-init.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-git-stash-pop.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-list-models.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-peer-list.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-peer-scan.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-pin-list.md +5 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-proposal-archive.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-proposal-attach.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-proposal-detach.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-config.md +5 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-health.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-off.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-on.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-server-tunnel-status.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-abort-all.md +14 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-abort.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-diff.md +11 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-fork.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-hide.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-info.md +11 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-kill.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-list-active.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-list-here.md +8 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-list.md +6 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-model.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-rename.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-resume.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-spawn.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-tell.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-thinking.md +10 -0
- package/.pi/skills/pi-dashboard/commands/dashboard-session-unhide.md +10 -0
- package/.pi/skills/pi-dashboard/references/api-reference.md +30 -0
- package/.pi/skills/pi-dashboard/references/recipes.md +38 -0
- package/.pi/skills/pi-dashboard/references/slash-commands.md +71 -0
- package/.pi/skills/pi-dashboard/scripts/dashboard-api.sh +6 -0
- package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +217 -0
- package/.pi/skills/project-init/SKILL.md +279 -0
- package/.pi/skills/project-init/dox-doctrine.md +104 -0
- package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +111 -0
- package/.pi/skills/project-init/profiles/coding/profile.json +5 -0
- package/.pi/skills/project-init/profiles/coding/prompts/plan-change.md +5 -0
- package/.pi/skills/project-init/profiles/coding/prompts/tdd-loop.md +6 -0
- package/.pi/skills/project-init/profiles/coding/settings.json.tmpl +9 -0
- package/.pi/skills/project-init/profiles/docs/AGENTS.md.tmpl +37 -0
- package/.pi/skills/project-init/profiles/docs/profile.json +4 -0
- package/.pi/skills/project-init/profiles/docs/prompts/draft-page.md +5 -0
- package/.pi/skills/project-init/profiles/docs/settings.json.tmpl +9 -0
- package/package.json +12 -4
- package/src/AGENTS.md +56 -0
- package/src/__tests__/abort-latch.test.ts +97 -0
- package/src/__tests__/agent-settled.test.ts +82 -0
- package/src/__tests__/artifact-roots.test.ts +83 -0
- package/src/__tests__/ask-user-attachments.test.ts +106 -0
- package/src/__tests__/ask-user-tool.test.ts +90 -27
- package/src/__tests__/auto-session-namer.test.ts +339 -0
- package/src/__tests__/bridge-default-model-apply.test.ts +242 -0
- package/src/__tests__/bridge-default-model-gate.test.ts +6 -3
- package/src/__tests__/bridge-followup-mutation.test.ts +217 -0
- package/src/__tests__/bridge-followup-queue-drain.test.ts +266 -0
- package/src/__tests__/bridge-hasui-flip.test.ts +109 -0
- package/src/__tests__/bridge-no-queue-mutation.test.ts +112 -0
- package/src/__tests__/bridge-plugin-emit-event.test.ts +44 -0
- package/src/__tests__/bridge-shutdown-reset.test.ts +57 -136
- package/src/__tests__/bridge-slash-command-routing.test.ts +7 -7
- package/src/__tests__/bridge-stop-after-turn.test.ts +72 -0
- package/src/__tests__/bridge-system-followup.test.ts +163 -0
- package/src/__tests__/bridge-thinking-level-select.test.ts +68 -0
- package/src/__tests__/browser-skill-registered.test.ts +84 -0
- package/src/__tests__/build-provider-catalogue.test.ts +35 -1
- package/src/__tests__/command-handler.test.ts +331 -35
- package/src/__tests__/commit-draft.test.ts +100 -0
- package/src/__tests__/connection-dropped-frames.test.ts +78 -0
- package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +128 -0
- package/src/__tests__/cwd-missing-probe.test.ts +82 -0
- package/src/__tests__/dashboard-commands-shipped.test.ts +53 -0
- package/src/__tests__/dashboard-context-injector.test.ts +190 -0
- package/src/__tests__/doctor/checks.test.ts +121 -0
- package/src/__tests__/doctor/modules.test.ts +64 -0
- package/src/__tests__/doctor/provenance-hash.test.ts +94 -0
- package/src/__tests__/doctor/router.test.ts +143 -0
- package/src/__tests__/empty-actionable-guard-config.test.ts +32 -0
- package/src/__tests__/empty-actionable-guard.test.ts +73 -0
- package/src/__tests__/enrich-model-metadata.test.ts +21 -0
- package/src/__tests__/extension-slash-command-detection.test.ts +37 -1
- package/src/__tests__/filter-enabled-models.test.ts +151 -0
- package/src/__tests__/fixtures/turn-actionability-fixtures.ts +69 -0
- package/src/__tests__/git-info-status.test.ts +73 -0
- package/src/__tests__/git-poll.test.ts +69 -0
- package/src/__tests__/markdown-image-inliner.test.ts +37 -0
- package/src/__tests__/model-resolve.test.ts +379 -0
- package/src/__tests__/pi-version-tracker.test.ts +109 -0
- package/src/__tests__/process-scanner.test.ts +112 -22
- package/src/__tests__/project-init-detect-stack.test.ts +61 -0
- package/src/__tests__/project-init-dox-kb-config.test.ts +53 -0
- package/src/__tests__/project-init-profiles.test.ts +84 -0
- package/src/__tests__/project-init-scaffold.test.ts +139 -0
- package/src/__tests__/project-init-seed-doctrine.test.ts +100 -0
- package/src/__tests__/project-trust.test.ts +92 -0
- package/src/__tests__/prompt-expander.test.ts +191 -1
- package/src/__tests__/provider-register-reload.test.ts +36 -6
- package/src/__tests__/provider-register-thinking-levels.test.ts +51 -0
- package/src/__tests__/retry-tracker.test.ts +75 -70
- package/src/__tests__/role-manager.test.ts +585 -0
- package/src/__tests__/role-model-tools-registry-readiness.test.ts +114 -0
- package/src/__tests__/role-model-tools.test.ts +229 -0
- package/src/__tests__/search-files-completeness.test.ts +111 -0
- package/src/__tests__/search-files-ranking.test.ts +168 -0
- package/src/__tests__/server-auto-start.test.ts +121 -4
- package/src/__tests__/server-launcher-launch.test.ts +24 -6
- package/src/__tests__/server-launcher.test.ts +19 -2
- package/src/__tests__/session-sync.test.ts +36 -0
- package/src/__tests__/subagent-frame-buffer.test.ts +239 -0
- package/src/__tests__/tool-result-image-inliner.test.ts +206 -0
- package/src/__tests__/tui-prompt-adapter.test.ts +70 -64
- package/src/__tests__/turn-actionability.test.ts +86 -0
- package/src/__tests__/vcs-info.test.ts +145 -4
- package/src/__tests__/visibility-intent.test.ts +43 -0
- package/src/abort-latch.ts +55 -0
- package/src/abort-latch.ts.AGENTS.md +3 -0
- package/src/agent-settled.ts +72 -0
- package/src/agent-settled.ts.AGENTS.md +3 -0
- package/src/artifact-roots.ts +73 -0
- package/src/artifact-roots.ts.AGENTS.md +3 -0
- package/src/ask-user-attachments.ts +121 -0
- package/src/ask-user-attachments.ts.AGENTS.md +3 -0
- package/src/ask-user-tool.ts +56 -58
- package/src/ask-user-tool.ts.AGENTS.md +3 -0
- package/src/auto-session-namer.ts +334 -0
- package/src/auto-session-namer.ts.AGENTS.md +3 -0
- package/src/bridge-context.ts +86 -8
- package/src/bridge-context.ts.AGENTS.md +3 -0
- package/src/bridge-default-model-gate.ts +22 -6
- package/src/bridge-default-model-gate.ts.AGENTS.md +3 -0
- package/src/bridge.ts +1241 -360
- package/src/bridge.ts.AGENTS.md +3 -0
- package/src/canvas-tool.ts +107 -0
- package/src/command-handler.ts +490 -51
- package/src/command-handler.ts.AGENTS.md +3 -0
- package/src/commit-draft-agent.ts +114 -0
- package/src/commit-draft-agent.ts.AGENTS.md +3 -0
- package/src/commit-draft.ts +136 -0
- package/src/commit-draft.ts.AGENTS.md +3 -0
- package/src/connection.ts +32 -1
- package/src/connection.ts.AGENTS.md +3 -0
- package/src/dashboard-context-injector.ts +124 -0
- package/src/dashboard-context-injector.ts.AGENTS.md +3 -0
- package/src/dashboard-default-adapter.ts.AGENTS.md +3 -0
- package/src/dev-build.ts.AGENTS.md +3 -0
- package/src/empty-actionable-guard-config.ts +32 -0
- package/src/empty-actionable-guard-config.ts.AGENTS.md +3 -0
- package/src/empty-actionable-guard.ts +90 -0
- package/src/empty-actionable-guard.ts.AGENTS.md +3 -0
- package/src/event-forwarder.ts.AGENTS.md +3 -0
- package/src/flow-event-wiring.ts +4 -14
- package/src/flow-event-wiring.ts.AGENTS.md +3 -0
- package/src/git-link-builder.ts.AGENTS.md +3 -0
- package/src/git-poll.ts +38 -0
- package/src/git-poll.ts.AGENTS.md +3 -0
- package/src/hasui-flip.ts +56 -0
- package/src/hasui-flip.ts.AGENTS.md +3 -0
- package/src/markdown-image-inliner.ts +45 -2
- package/src/markdown-image-inliner.ts.AGENTS.md +3 -0
- package/src/model-tracker.ts +145 -19
- package/src/model-tracker.ts.AGENTS.md +3 -0
- package/src/multiselect-decode.ts.AGENTS.md +3 -0
- package/src/multiselect-list.ts.AGENTS.md +3 -0
- package/src/multiselect-polyfill.ts.AGENTS.md +3 -0
- package/src/process-metrics.ts.AGENTS.md +3 -0
- package/src/process-scanner.ts +114 -103
- package/src/process-scanner.ts.AGENTS.md +3 -0
- package/src/project-init/AGENTS.md +12 -0
- package/src/project-init/detect-stack.ts +146 -0
- package/src/project-init/dox-kb-config.ts +47 -0
- package/src/project-init/profiles.ts +135 -0
- package/src/project-init/scaffold.ts +192 -0
- package/src/project-init/seed-doctrine.ts +95 -0
- package/src/project-trust.ts +63 -0
- package/src/project-trust.ts.AGENTS.md +3 -0
- package/src/prompt-bus.ts +10 -1
- package/src/prompt-bus.ts.AGENTS.md +3 -0
- package/src/prompt-expander.ts +238 -37
- package/src/prompt-expander.ts.AGENTS.md +3 -0
- package/src/provider-register.ts +323 -54
- package/src/provider-register.ts.AGENTS.md +3 -0
- package/src/retry-tracker.ts +64 -39
- package/src/retry-tracker.ts.AGENTS.md +3 -0
- package/src/role-manager.ts +436 -0
- package/src/role-manager.ts.AGENTS.md +3 -0
- package/src/role-model-tools.ts +301 -0
- package/src/role-model-tools.ts.AGENTS.md +3 -0
- package/src/server-auto-start.ts +59 -23
- package/src/server-auto-start.ts.AGENTS.md +3 -0
- package/src/server-launcher.ts +56 -16
- package/src/server-launcher.ts.AGENTS.md +3 -0
- package/src/session-sync.ts +111 -15
- package/src/session-sync.ts.AGENTS.md +3 -0
- package/src/slash-dispatch.ts +13 -11
- package/src/slash-dispatch.ts.AGENTS.md +3 -0
- package/src/source-detector.ts.AGENTS.md +3 -0
- package/src/subagent-frame-buffer.ts +220 -0
- package/src/subagent-frame-buffer.ts.AGENTS.md +3 -0
- package/src/tool-result-image-inliner.ts +204 -0
- package/src/tool-result-image-inliner.ts.AGENTS.md +3 -0
- package/src/tui-prompt-adapter.ts +123 -0
- package/src/tui-prompt-adapter.ts.AGENTS.md +3 -0
- package/src/turn-actionability.ts +117 -0
- package/src/turn-actionability.ts.AGENTS.md +3 -0
- package/src/ui-modules.ts.AGENTS.md +3 -0
- package/src/vcs-info.ts +91 -129
- package/src/vcs-info.ts.AGENTS.md +3 -0
- package/src/visibility-intent.ts +34 -0
- package/src/visibility-intent.ts.AGENTS.md +3 -0
- package/src/__tests__/bridge-retry-ordering.test.ts +0 -148
- package/src/__tests__/bridge-shadow-queue-drain.test.ts +0 -221
- package/src/__tests__/fixtures/usage-limit-error-strings.ts +0 -127
- package/src/__tests__/usage-limit-orderer.test.ts +0 -117
- package/src/__tests__/vcs-info-jj.test.ts +0 -145
- package/src/usage-limit-orderer.ts +0 -93
package/src/vcs-info.ts
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* VCS info gathering — detects git branch/remote/PR
|
|
2
|
+
* VCS info gathering — detects git branch/remote/PR and worktree state.
|
|
3
3
|
* Delegates to shared platform tool modules so there's no inline execSync
|
|
4
4
|
* and every call benefits from the runner's safety defaults (windowsHide,
|
|
5
5
|
* timeout, tolerated exit codes).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* subprocess is spawned. Only sessions inside a jj repo pay the probe cost.
|
|
9
|
-
*
|
|
10
|
-
* See changes: platform-command-executor, add-jj-workspace-plugin.
|
|
7
|
+
* See change: platform-command-executor.
|
|
11
8
|
*/
|
|
12
|
-
import { existsSync } from "node:fs";
|
|
13
9
|
import path from "node:path";
|
|
14
10
|
import * as git from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
15
|
-
import
|
|
16
|
-
import { getDefaultRegistry } from "@blackbelt-technology/pi-dashboard-shared/tool-registry/index.js";
|
|
17
|
-
import type { JjState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
11
|
+
import type { GitStatus, GitWorktreeInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
18
12
|
import { buildGitLinks, type GitLinks } from "./git-link-builder.js";
|
|
19
13
|
|
|
20
14
|
export interface GitInfo {
|
|
@@ -22,6 +16,36 @@ export interface GitInfo {
|
|
|
22
16
|
gitBranchUrl?: string;
|
|
23
17
|
gitPrNumber?: number;
|
|
24
18
|
gitPrUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Worktree identity (mainPath, name) when cwd is a git worktree.
|
|
21
|
+
* Undefined for the main checkout and for any cwd where the rev-parse
|
|
22
|
+
* pair fails. Never carries `base` — that field is post-create
|
|
23
|
+
* metadata supplied by the server.
|
|
24
|
+
*/
|
|
25
|
+
gitWorktree?: GitWorktreeInfo;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Detect whether `cwd` is a git repository as a tri-state.
|
|
30
|
+
*
|
|
31
|
+
* Uses the `git.isGitRepo()` `Result` (NOT `isGitRepoOr`) to distinguish
|
|
32
|
+
* *confirmed non-git* from *unknown*:
|
|
33
|
+
* - `ok` → the boolean value (`git rev-parse --is-inside-work-tree`);
|
|
34
|
+
* - `error kind:"exit" code:128` → `false` (git ran and definitively
|
|
35
|
+
* reported "not a repository");
|
|
36
|
+
* - any other failure (missing binary, timeout, signal, other exit code)
|
|
37
|
+
* → `undefined` (unknown).
|
|
38
|
+
*
|
|
39
|
+
* Returns `undefined` — never `false` — on an inconclusive probe so a real
|
|
40
|
+
* git repo whose probe failed never loses its truthy signal (the client
|
|
41
|
+
* gate hides the `+Worktree` button only on a confirmed `false`).
|
|
42
|
+
* See change: gate-session-worktree-button-on-git.
|
|
43
|
+
*/
|
|
44
|
+
export function detectIsGitRepo(cwd: string): boolean | undefined {
|
|
45
|
+
const res = git.isGitRepo({ cwd });
|
|
46
|
+
if (res.ok) return res.value;
|
|
47
|
+
if (res.error.kind === "exit" && res.error.code === 128) return false;
|
|
48
|
+
return undefined;
|
|
25
49
|
}
|
|
26
50
|
|
|
27
51
|
/** Detect the current git branch. Returns short SHA for detached HEAD. */
|
|
@@ -45,6 +69,62 @@ export function detectPrNumber(cwd: string): number | undefined {
|
|
|
45
69
|
return git.prNumberOr({ cwd });
|
|
46
70
|
}
|
|
47
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Detect whether `cwd` is a git worktree (not the main checkout).
|
|
74
|
+
*
|
|
75
|
+
* Uses the canonical signal: `git rev-parse --git-common-dir` resolves
|
|
76
|
+
* to a path OUTSIDE `git rev-parse --show-toplevel` when the cwd is a
|
|
77
|
+
* worktree (because `--git-common-dir` points back at the main repo's
|
|
78
|
+
* `.git/`, while `--show-toplevel` is the worktree's own root).
|
|
79
|
+
*
|
|
80
|
+
* Returns `undefined` when:
|
|
81
|
+
* - either rev-parse invocation fails (not a repo, git missing,
|
|
82
|
+
* permission, etc.),
|
|
83
|
+
* - the cwd IS the main checkout (`commonDir` is inside `topLevel`).
|
|
84
|
+
*
|
|
85
|
+
* Resolution is path-prefix based with case-folding on Windows/macOS
|
|
86
|
+
* via the shared platform helpers; relative `commonDir` outputs (which
|
|
87
|
+
* happen on some git versions when cwd === main repo) are normalised
|
|
88
|
+
* to absolute via `path.resolve(cwd, commonDir)`.
|
|
89
|
+
*/
|
|
90
|
+
export function detectWorktree(cwd: string): GitWorktreeInfo | undefined {
|
|
91
|
+
const commonDirRaw = git.commonDirOr({ cwd });
|
|
92
|
+
const topLevel = git.toplevelOr({ cwd });
|
|
93
|
+
if (!commonDirRaw || !topLevel) return undefined;
|
|
94
|
+
|
|
95
|
+
// Normalise commonDir: when it's relative (`.git`), resolve against cwd.
|
|
96
|
+
// When absolute, leave as-is.
|
|
97
|
+
const commonDirAbs = path.isAbsolute(commonDirRaw)
|
|
98
|
+
? commonDirRaw
|
|
99
|
+
: path.resolve(cwd, commonDirRaw);
|
|
100
|
+
|
|
101
|
+
// Main checkout: commonDir == <toplevel>/.git (or anywhere inside toplevel).
|
|
102
|
+
// Worktree: commonDir == <main-repo>/.git, which is NOT inside the
|
|
103
|
+
// worktree's toplevel.
|
|
104
|
+
const topWithSep = topLevel.endsWith(path.sep) ? topLevel : topLevel + path.sep;
|
|
105
|
+
const insideToplevel =
|
|
106
|
+
commonDirAbs === topLevel || commonDirAbs.startsWith(topWithSep);
|
|
107
|
+
if (insideToplevel) return undefined;
|
|
108
|
+
|
|
109
|
+
// `commonDir` for a worktree is `<main-repo>/.git` — the parent dir is
|
|
110
|
+
// the main worktree root.
|
|
111
|
+
const mainPath = path.dirname(commonDirAbs);
|
|
112
|
+
const name = path.basename(cwd);
|
|
113
|
+
return { mainPath, name };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Gather working-tree dirtiness + upstream drift for `cwd` via one
|
|
118
|
+
* `git status --porcelain=v2 --branch` call. Returns `undefined` on an
|
|
119
|
+
* inconclusive probe (git missing, not a repo, timeout) so the broadcast
|
|
120
|
+
* omits the field rather than sending a false all-clean status.
|
|
121
|
+
* See change: add-session-uncommitted-indicator-and-commit.
|
|
122
|
+
*/
|
|
123
|
+
export function gatherGitStatus(cwd: string): GitStatus | undefined {
|
|
124
|
+
const res = git.gitStatusV2({ cwd });
|
|
125
|
+
return res.ok ? res.value : undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
48
128
|
/** Gather all git info for a directory. Returns undefined if not a git repo. */
|
|
49
129
|
export function gatherGitInfo(cwd: string): GitInfo | undefined {
|
|
50
130
|
const branch = detectBranch(cwd);
|
|
@@ -52,6 +132,7 @@ export function gatherGitInfo(cwd: string): GitInfo | undefined {
|
|
|
52
132
|
|
|
53
133
|
const remoteUrl = detectRemoteUrl(cwd);
|
|
54
134
|
const prNumber = detectPrNumber(cwd);
|
|
135
|
+
const gitWorktree = detectWorktree(cwd);
|
|
55
136
|
|
|
56
137
|
const links: GitLinks = remoteUrl ? buildGitLinks(remoteUrl, branch, prNumber) : {};
|
|
57
138
|
|
|
@@ -60,125 +141,6 @@ export function gatherGitInfo(cwd: string): GitInfo | undefined {
|
|
|
60
141
|
gitBranchUrl: links.branchUrl,
|
|
61
142
|
gitPrNumber: prNumber,
|
|
62
143
|
gitPrUrl: links.prUrl,
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ── Jujutsu probing ────────────────────────────────────────────────────────
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Module-level cache: result of resolving `jj` once per process. The tool
|
|
70
|
-
* registry already memoizes resolutions, but reading it on every probe tick
|
|
71
|
-
* adds noise to traces. Single read on first probe, sticky for the process.
|
|
72
|
-
*/
|
|
73
|
-
let jjAvailable: boolean | undefined;
|
|
74
|
-
|
|
75
|
-
function isJjResolvable(): boolean {
|
|
76
|
-
if (jjAvailable !== undefined) return jjAvailable;
|
|
77
|
-
try {
|
|
78
|
-
const reg = getDefaultRegistry();
|
|
79
|
-
const res = reg.resolve("jj");
|
|
80
|
-
jjAvailable = res.ok;
|
|
81
|
-
} catch {
|
|
82
|
-
jjAvailable = false;
|
|
83
|
-
}
|
|
84
|
-
return jjAvailable;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Test-only hook to reset the jj-availability cache.
|
|
89
|
-
* Production code MUST NOT call this.
|
|
90
|
-
*/
|
|
91
|
-
export function _resetJjAvailableForTests(): void {
|
|
92
|
-
jjAvailable = undefined;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Gather jj workspace state for a directory.
|
|
97
|
-
* Returns `undefined` when:
|
|
98
|
-
* - `jj` is not resolvable via the tool registry, OR
|
|
99
|
-
* - `.jj/` does not exist in cwd (fast path, no subprocess spawn).
|
|
100
|
-
*
|
|
101
|
-
* Returns a populated `JjState` when both conditions are met. Errors during
|
|
102
|
-
* `jj` invocation surface in `lastError` rather than throwing; the rest of
|
|
103
|
-
* the fields fall back to undefined / empty.
|
|
104
|
-
*
|
|
105
|
-
* Per spec scenario "Non-jj cwd incurs no jj subprocess cost".
|
|
106
|
-
*/
|
|
107
|
-
export function gatherJjInfo(cwd: string): JjState | undefined {
|
|
108
|
-
if (!isJjResolvable()) return undefined;
|
|
109
|
-
if (!existsSync(path.join(cwd, ".jj"))) return undefined;
|
|
110
|
-
|
|
111
|
-
const isColocated = existsSync(path.join(cwd, ".git"));
|
|
112
|
-
|
|
113
|
-
// Resolve workspace name + root. Errors are caught and surfaced via
|
|
114
|
-
// lastError so callers always get *some* JjState rather than nothing.
|
|
115
|
-
let workspaceName: string | undefined;
|
|
116
|
-
let workspaceRoot: string | undefined;
|
|
117
|
-
let lastError: string | undefined;
|
|
118
|
-
|
|
119
|
-
const rootResult = jj.workspaceRoot({ cwd });
|
|
120
|
-
if (rootResult.ok) {
|
|
121
|
-
workspaceRoot = rootResult.value;
|
|
122
|
-
} else if (rootResult.error.kind !== "not-found") {
|
|
123
|
-
lastError = describeJjError(rootResult.error);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Workspace name: parse `jj workspace list` and match by working-copy
|
|
127
|
-
// path. The CLI does not include the path in list output, so we fall
|
|
128
|
-
// back to identifying the workspace via the `<name>@` revset matching
|
|
129
|
-
// the workspace root. For now: if there's only one workspace, use
|
|
130
|
-
// its name; otherwise default to "default" if found, else first entry.
|
|
131
|
-
// (Multi-workspace name disambiguation tracked as Phase 4 follow-up.)
|
|
132
|
-
const listResult = jj.workspaceList({ cwd });
|
|
133
|
-
if (listResult.ok) {
|
|
134
|
-
const entries = jj.parseWorkspaceList(listResult.value);
|
|
135
|
-
if (entries.length === 1) {
|
|
136
|
-
workspaceName = entries[0]?.name;
|
|
137
|
-
} else if (entries.length > 1) {
|
|
138
|
-
workspaceName = entries.find((e) => e.name === "default")?.name
|
|
139
|
-
?? entries[0]?.name;
|
|
140
|
-
}
|
|
141
|
-
} else if (listResult.error.kind !== "not-found" && !lastError) {
|
|
142
|
-
lastError = describeJjError(listResult.error);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
isJjRepo: true,
|
|
147
|
-
isColocated,
|
|
148
|
-
workspaceName,
|
|
149
|
-
workspaceRoot,
|
|
150
|
-
lastError,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function describeJjError(
|
|
155
|
-
error: { kind: string; [k: string]: unknown },
|
|
156
|
-
): string {
|
|
157
|
-
if (error.kind === "timeout") return "jj probe timed out";
|
|
158
|
-
if (error.kind === "exit") {
|
|
159
|
-
const stderr = typeof error.stderr === "string" ? error.stderr.trim() : "";
|
|
160
|
-
return stderr.split("\n")[0] || `jj exited ${String(error.code)}`;
|
|
161
|
-
}
|
|
162
|
-
if (error.kind === "spawn-failure") {
|
|
163
|
-
return typeof error.message === "string" ? error.message : "spawn failed";
|
|
164
|
-
}
|
|
165
|
-
return error.kind;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ── Combined VCS gather ────────────────────────────────────────────────────
|
|
169
|
-
|
|
170
|
-
export interface VcsInfo {
|
|
171
|
-
git?: GitInfo;
|
|
172
|
-
jj?: JjState;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Convenience helper that gathers both git and jj info in one call.
|
|
177
|
-
* Used by the bridge's per-session 30 s probe tick.
|
|
178
|
-
*/
|
|
179
|
-
export function gatherVcsInfo(cwd: string): VcsInfo {
|
|
180
|
-
return {
|
|
181
|
-
git: gatherGitInfo(cwd),
|
|
182
|
-
jj: gatherJjInfo(cwd),
|
|
144
|
+
gitWorktree,
|
|
183
145
|
};
|
|
184
146
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# vcs-info.ts — index
|
|
2
|
+
|
|
3
|
+
Gathers git branch/remote/PR/worktree info via shared platform git helpers. Exports `GitInfo`, `detectBranch`, `detectRemoteUrl`, `detectPrNumber`, `detectWorktree`, `detectIsGitRepo`, `gatherGitInfo`. `detectWorktree` compares `--git-common-dir` vs `--show-toplevel`. `detectIsGitRepo` returns tri-state `boolean\|undefined` from `git.isGitRepo()` Result: ok→value, exit-128→false, else→undefined (never false on inconclusive probe); attached to `session_register` (session-sync.ts, bridge.ts). Builds links via `buildGitLinks`. Returns undefined if not a repo. Exports `gatherGitStatus(cwd)` → `GitStatus\|undefined` via shared `git.gitStatusV2` (`git status --porcelain=v2 --branch`). See changes: gate-session-worktree-button-on-git, add-session-uncommitted-indicator-and-commit.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the optional `session_register` visibility fields the bridge
|
|
3
|
+
* forwards to the server (fact-forwarding only; the server decides what to
|
|
4
|
+
* do with them). See change: auto-hide-headless-worker-sessions.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Map the bridge's environment to an explicit visibility override.
|
|
9
|
+
* `PI_DASHBOARD_VISIBLE` wins over `PI_DASHBOARD_HIDDEN` (explicit show beats
|
|
10
|
+
* hide). Absent ⇒ undefined (server falls back to its auto-hide heuristic).
|
|
11
|
+
*/
|
|
12
|
+
export function resolveVisibilityIntent(
|
|
13
|
+
env: NodeJS.ProcessEnv,
|
|
14
|
+
): "hidden" | "visible" | undefined {
|
|
15
|
+
if (env.PI_DASHBOARD_VISIBLE) return "visible";
|
|
16
|
+
if (env.PI_DASHBOARD_HIDDEN) return "hidden";
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build the optional `{ hasUI?, visibilityIntent? }` slice of a
|
|
22
|
+
* `session_register` payload. Fields are omitted (not set to undefined) when
|
|
23
|
+
* absent so legacy/back-compat behavior is preserved on the wire.
|
|
24
|
+
*/
|
|
25
|
+
export function buildVisibilityRegisterFields(
|
|
26
|
+
hasUI: boolean | undefined,
|
|
27
|
+
env: NodeJS.ProcessEnv,
|
|
28
|
+
): { hasUI?: boolean; visibilityIntent?: "hidden" | "visible" } {
|
|
29
|
+
const fields: { hasUI?: boolean; visibilityIntent?: "hidden" | "visible" } = {};
|
|
30
|
+
if (hasUI !== undefined) fields.hasUI = hasUI;
|
|
31
|
+
const intent = resolveVisibilityIntent(env);
|
|
32
|
+
if (intent) fields.visibilityIntent = intent;
|
|
33
|
+
return fields;
|
|
34
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# visibility-intent.ts — index
|
|
2
|
+
|
|
3
|
+
Resolves `session_register` visibility fields. Exports `resolveVisibilityIntent`, `buildVisibilityRegisterFields`. `PI_DASHBOARD_VISIBLE` beats `PI_DASHBOARD_HIDDEN`; absent ⇒ undefined (server auto-hide heuristic). Emits `{ hasUI?, visibilityIntent? }` slice omitting absent fields. See change auto-hide-headless-worker-sessions.
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bridge wire-ordering invariant for synthesized retry events.
|
|
3
|
-
*
|
|
4
|
-
* Verifies that the bridge updates `RetryTracker` + `UsageLimitOrderer` state
|
|
5
|
-
* SYNCHRONOUSLY when handling `message_end`, so that a back-to-back `agent_end`
|
|
6
|
-
* (fired in the same event-loop tick by pi-coding-agent) observes the
|
|
7
|
-
* up-to-date state.
|
|
8
|
-
*
|
|
9
|
-
* Pre-fix bug: the synthesizer state lived inside `setTimeout(0)` (intended
|
|
10
|
-
* for entryId capture per `fix-per-message-fork`), so `agent_end` was
|
|
11
|
-
* processed BEFORE the trackers had been updated, the orderer's pending
|
|
12
|
-
* flag was never set, and `auto_retry_start` shipped on the wire AFTER
|
|
13
|
-
* `agent_end` — leaving the dashboard's `retryState` stuck (yellow + red
|
|
14
|
-
* banners both visible).
|
|
15
|
-
*
|
|
16
|
-
* See change: fix-retry-banner-stuck-on-limit-exceeded.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { describe, it, expect } from "vitest";
|
|
20
|
-
import { RetryTracker } from "../retry-tracker.js";
|
|
21
|
-
import { UsageLimitOrderer } from "../usage-limit-orderer.js";
|
|
22
|
-
|
|
23
|
-
interface WireEvent {
|
|
24
|
-
eventType: string;
|
|
25
|
-
data?: Record<string, unknown>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Simulates the bridge's synthesizer pipeline as it runs synchronously
|
|
30
|
-
* inside the message_end / agent_end handlers, capturing all wire sends
|
|
31
|
-
* in order.
|
|
32
|
-
*/
|
|
33
|
-
class BridgeSim {
|
|
34
|
-
readonly wire: WireEvent[] = [];
|
|
35
|
-
private tracker = new RetryTracker();
|
|
36
|
-
private orderer = new UsageLimitOrderer();
|
|
37
|
-
|
|
38
|
-
/** Mirrors bridge.ts message_end handler synthesizer block. */
|
|
39
|
-
onMessageEnd(sessionId: string, message: { role: string; stopReason?: string; errorMessage?: string }): void {
|
|
40
|
-
const synthetic = this.tracker.observeMessageEnd(sessionId, message);
|
|
41
|
-
if (synthetic) {
|
|
42
|
-
if (synthetic.eventType === "auto_retry_start") {
|
|
43
|
-
this.orderer.noteRetryStart(sessionId);
|
|
44
|
-
} else {
|
|
45
|
-
this.orderer.noteRetryEnd(sessionId);
|
|
46
|
-
}
|
|
47
|
-
this.wire.push({ eventType: synthetic.eventType, data: synthetic.data });
|
|
48
|
-
}
|
|
49
|
-
// The actual message_end body send is deferred via setTimeout(0) in the
|
|
50
|
-
// real bridge for entryId capture; for ordering tests we only care about
|
|
51
|
-
// the synthetic events relative to agent_end.
|
|
52
|
-
this.wire.push({ eventType: "message_end" });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Mirrors bridge.ts agent_end handler synthesizer block. */
|
|
56
|
-
onAgentEnd(sessionId: string, agentEnd: { messages?: Array<Record<string, unknown>> }): void {
|
|
57
|
-
const orderedSynth = this.orderer.maybeSynthesize(sessionId, agentEnd);
|
|
58
|
-
if (orderedSynth) {
|
|
59
|
-
this.wire.push({ eventType: orderedSynth.eventType, data: orderedSynth.data });
|
|
60
|
-
this.tracker.noteAbort(sessionId);
|
|
61
|
-
} else {
|
|
62
|
-
const trackerSynth = this.tracker.observeAgentEnd(sessionId, agentEnd);
|
|
63
|
-
if (trackerSynth) {
|
|
64
|
-
this.wire.push({ eventType: trackerSynth.eventType, data: trackerSynth.data });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
this.wire.push({ eventType: "agent_end" });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe("Bridge retry-event wire ordering", () => {
|
|
72
|
-
it("agent_end fired back-to-back after retryable message_end observes pending retry", () => {
|
|
73
|
-
const sim = new BridgeSim();
|
|
74
|
-
const sessionId = "s1";
|
|
75
|
-
const errorMsg = "429 too many requests";
|
|
76
|
-
|
|
77
|
-
// Pi fires both events synchronously back-to-back.
|
|
78
|
-
sim.onMessageEnd(sessionId, { role: "assistant", stopReason: "error", errorMessage: errorMsg });
|
|
79
|
-
sim.onAgentEnd(sessionId, {
|
|
80
|
-
messages: [{ role: "assistant", stopReason: "error", errorMessage: errorMsg }],
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const types = sim.wire.map((e) => e.eventType);
|
|
84
|
-
// auto_retry_start must precede message_end, which must precede the
|
|
85
|
-
// agent_end-side synthesis. Since the same retryable error is the
|
|
86
|
-
// terminal message, retryTracker.observeAgentEnd surfaces a final
|
|
87
|
-
// auto_retry_end{success:false, finalError:errorMsg} BEFORE agent_end.
|
|
88
|
-
expect(types).toEqual([
|
|
89
|
-
"auto_retry_start",
|
|
90
|
-
"message_end",
|
|
91
|
-
"auto_retry_end",
|
|
92
|
-
"agent_end",
|
|
93
|
-
]);
|
|
94
|
-
// auto_retry_start MUST come before agent_end on the wire.
|
|
95
|
-
const startIdx = types.indexOf("auto_retry_start");
|
|
96
|
-
const agentEndIdx = types.indexOf("agent_end");
|
|
97
|
-
expect(startIdx).toBeLessThan(agentEndIdx);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("Gemini monthly-spending-cap error orders auto_retry_end before agent_end", () => {
|
|
101
|
-
const sim = new BridgeSim();
|
|
102
|
-
const sessionId = "s2";
|
|
103
|
-
// Real fixture from ~/.pi/agent/sessions/...BME-szakdoga.../*.jsonl line 363
|
|
104
|
-
const errorMsg = JSON.stringify({
|
|
105
|
-
error: {
|
|
106
|
-
message:
|
|
107
|
-
"Your project has exceeded its monthly spending cap. Please go to AI Studio at https://ai.studio/spend to manage your project spend cap.",
|
|
108
|
-
status: "RESOURCE_EXHAUSTED",
|
|
109
|
-
},
|
|
110
|
-
code: 429,
|
|
111
|
-
status: "Too Many Requests",
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
sim.onMessageEnd(sessionId, { role: "assistant", stopReason: "error", errorMessage: errorMsg });
|
|
115
|
-
sim.onAgentEnd(sessionId, {
|
|
116
|
-
messages: [{ role: "assistant", stopReason: "error", errorMessage: errorMsg }],
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const types = sim.wire.map((e) => e.eventType);
|
|
120
|
-
expect(types).toEqual([
|
|
121
|
-
"auto_retry_start",
|
|
122
|
-
"message_end",
|
|
123
|
-
"auto_retry_end",
|
|
124
|
-
"agent_end",
|
|
125
|
-
]);
|
|
126
|
-
// The synthetic auto_retry_end MUST come from the usage-limit orderer
|
|
127
|
-
// (not the retry-tracker fallback) because the broadened
|
|
128
|
-
// USAGE_LIMIT_PATTERN matches "monthly spending cap" / RESOURCE_EXHAUSTED.
|
|
129
|
-
const retryEnd = sim.wire.find((e) => e.eventType === "auto_retry_end")!;
|
|
130
|
-
expect(retryEnd.data).toMatchObject({ success: false, finalError: errorMsg });
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("non-retryable message_end produces no synthesis (only message_end on wire)", () => {
|
|
134
|
-
const sim = new BridgeSim();
|
|
135
|
-
sim.onMessageEnd("s3", {
|
|
136
|
-
role: "assistant",
|
|
137
|
-
stopReason: "error",
|
|
138
|
-
errorMessage: "prompt is too long: 300000 tokens > 200000 maximum",
|
|
139
|
-
});
|
|
140
|
-
expect(sim.wire.map((e) => e.eventType)).toEqual(["message_end"]);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("successful message_end with no prior retry produces no synthesis", () => {
|
|
144
|
-
const sim = new BridgeSim();
|
|
145
|
-
sim.onMessageEnd("s4", { role: "assistant", stopReason: "end_turn" });
|
|
146
|
-
expect(sim.wire.map((e) => e.eventType)).toEqual(["message_end"]);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the bridge's per-entry shadow-queue drain on user message_start.
|
|
3
|
-
*
|
|
4
|
-
* Pi mirrors this exact algorithm internally (see
|
|
5
|
-
* `@earendil-works/pi-coding-agent/dist/core/agent-session.js`
|
|
6
|
-
* `_processAgentEvent`, around line 270-292):
|
|
7
|
-
*
|
|
8
|
-
* if (event.type === "message_start" && event.message.role === "user") {
|
|
9
|
-
* const text = _getUserMessageText(event.message);
|
|
10
|
-
* const steeringIdx = _steeringMessages.indexOf(text);
|
|
11
|
-
* if (steeringIdx !== -1) {
|
|
12
|
-
* _steeringMessages.splice(steeringIdx, 1);
|
|
13
|
-
* _emitQueueUpdate();
|
|
14
|
-
* } else {
|
|
15
|
-
* const followUpIdx = _followUpMessages.indexOf(text);
|
|
16
|
-
* if (followUpIdx !== -1) {
|
|
17
|
-
* _followUpMessages.splice(followUpIdx, 1);
|
|
18
|
-
* _emitQueueUpdate();
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* Pre-fix bug: bridge bulk-cleared `bridgeFollowUp = []` at every `agent_end`
|
|
24
|
-
* and `bridgeSteering = []` at every `turn_end`. With pi's `mode:"all"`
|
|
25
|
-
* (default), pi drains all queued follow-ups across multiple turns before
|
|
26
|
-
* emitting the final `agent_end`. The dashboard saw the entire queue stay
|
|
27
|
-
* visible for the whole drain window, then disappear all at once at the
|
|
28
|
-
* end — instead of shrinking one entry per drain as the user observes them
|
|
29
|
-
* being processed.
|
|
30
|
-
*
|
|
31
|
-
* Fix: bridge mirrors pi's per-entry matcher on user `message_start`. Bulk
|
|
32
|
-
* clears at `agent_end` / `turn_end` are removed (would otherwise wipe
|
|
33
|
-
* entries the user added DURING a drain).
|
|
34
|
-
*
|
|
35
|
-
* See change: add-followup-edit-and-steer-cancel (per-entry-drain scenario).
|
|
36
|
-
*/
|
|
37
|
-
import { describe, it, expect } from "vitest";
|
|
38
|
-
|
|
39
|
-
interface ShadowQueue {
|
|
40
|
-
steering: string[];
|
|
41
|
-
followUp: string[];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Pure mirror of the per-entry drain matcher as it lives in bridge.ts'
|
|
46
|
-
* `message_start` handler. If production drifts from this shape, the
|
|
47
|
-
* test should drift in lockstep.
|
|
48
|
-
*/
|
|
49
|
-
function makeShadowDrainMatcher() {
|
|
50
|
-
const queue: ShadowQueue = { steering: [], followUp: [] };
|
|
51
|
-
const emits: ShadowQueue[] = [];
|
|
52
|
-
function emit() {
|
|
53
|
-
emits.push({ steering: [...queue.steering], followUp: [...queue.followUp] });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Mirrors pi's `_getUserMessageText` exactly. */
|
|
57
|
-
function getUserMessageText(message: { role: string; content: unknown }): string {
|
|
58
|
-
if (message.role !== "user") return "";
|
|
59
|
-
const content = message.content;
|
|
60
|
-
if (typeof content === "string") return content;
|
|
61
|
-
if (!Array.isArray(content)) return "";
|
|
62
|
-
return content
|
|
63
|
-
.filter((c: any) => c && c.type === "text")
|
|
64
|
-
.map((c: any) => c.text ?? "")
|
|
65
|
-
.join("");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Call when pi emits a user `message_start`. Mirrors pi's internal logic. */
|
|
69
|
-
function onUserMessageStart(message: { role: string; content: unknown }): void {
|
|
70
|
-
const text = getUserMessageText(message);
|
|
71
|
-
if (!text) return;
|
|
72
|
-
const steeringIdx = queue.steering.indexOf(text);
|
|
73
|
-
if (steeringIdx !== -1) {
|
|
74
|
-
queue.steering.splice(steeringIdx, 1);
|
|
75
|
-
emit();
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const followUpIdx = queue.followUp.indexOf(text);
|
|
79
|
-
if (followUpIdx !== -1) {
|
|
80
|
-
queue.followUp.splice(followUpIdx, 1);
|
|
81
|
-
emit();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
queue,
|
|
87
|
-
emits,
|
|
88
|
-
onUserMessageStart,
|
|
89
|
-
recordSteer: (t: string) => { queue.steering.push(t); emit(); },
|
|
90
|
-
recordFollowup: (t: string) => { queue.followUp.push(t); emit(); },
|
|
91
|
-
snapshotQueue: () => ({ steering: [...queue.steering], followUp: [...queue.followUp] }),
|
|
92
|
-
snapshotEmits: () => emits.map((e) => ({ steering: [...e.steering], followUp: [...e.followUp] })),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
describe("Bridge shadow-queue per-entry drain on user message_start", () => {
|
|
97
|
-
it("removes the matching follow-up entry when pi drains it, leaves the rest", () => {
|
|
98
|
-
const m = makeShadowDrainMatcher();
|
|
99
|
-
m.recordFollowup("a");
|
|
100
|
-
m.recordFollowup("b");
|
|
101
|
-
m.recordFollowup("c");
|
|
102
|
-
expect(m.snapshotQueue().followUp).toEqual(["a", "b", "c"]);
|
|
103
|
-
|
|
104
|
-
// Pi drains "a" first.
|
|
105
|
-
m.onUserMessageStart({ role: "user", content: "a" });
|
|
106
|
-
expect(m.snapshotQueue().followUp).toEqual(["b", "c"]);
|
|
107
|
-
|
|
108
|
-
// Then "b".
|
|
109
|
-
m.onUserMessageStart({ role: "user", content: "b" });
|
|
110
|
-
expect(m.snapshotQueue().followUp).toEqual(["c"]);
|
|
111
|
-
|
|
112
|
-
// Then "c".
|
|
113
|
-
m.onUserMessageStart({ role: "user", content: "c" });
|
|
114
|
-
expect(m.snapshotQueue().followUp).toEqual([]);
|
|
115
|
-
|
|
116
|
-
// One emit per drain (plus the three initial record emits).
|
|
117
|
-
expect(m.emits).toHaveLength(6);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("removes the matching steering entry when pi drains it", () => {
|
|
121
|
-
const m = makeShadowDrainMatcher();
|
|
122
|
-
m.recordSteer("focus on X");
|
|
123
|
-
m.recordSteer("ignore Y");
|
|
124
|
-
expect(m.snapshotQueue().steering).toEqual(["focus on X", "ignore Y"]);
|
|
125
|
-
|
|
126
|
-
m.onUserMessageStart({ role: "user", content: "focus on X" });
|
|
127
|
-
expect(m.snapshotQueue().steering).toEqual(["ignore Y"]);
|
|
128
|
-
expect(m.snapshotQueue().followUp).toEqual([]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("steering queue checked BEFORE follow-up when same text is in both", () => {
|
|
132
|
-
const m = makeShadowDrainMatcher();
|
|
133
|
-
m.recordSteer("hello");
|
|
134
|
-
m.recordFollowup("hello");
|
|
135
|
-
|
|
136
|
-
m.onUserMessageStart({ role: "user", content: "hello" });
|
|
137
|
-
// Steering entry consumed, follow-up untouched.
|
|
138
|
-
expect(m.snapshotQueue().steering).toEqual([]);
|
|
139
|
-
expect(m.snapshotQueue().followUp).toEqual(["hello"]);
|
|
140
|
-
|
|
141
|
-
// Second drain consumes the follow-up.
|
|
142
|
-
m.onUserMessageStart({ role: "user", content: "hello" });
|
|
143
|
-
expect(m.snapshotQueue().followUp).toEqual([]);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("non-matching user message_start is a no-op (no queue mutation, no emit)", () => {
|
|
147
|
-
const m = makeShadowDrainMatcher();
|
|
148
|
-
m.recordFollowup("queued");
|
|
149
|
-
const baselineEmits = m.emits.length;
|
|
150
|
-
|
|
151
|
-
// Fresh user send not in any queue (e.g., the user typed something
|
|
152
|
-
// new on an idle session, or a steer was added by a non-dashboard
|
|
153
|
-
// consumer).
|
|
154
|
-
m.onUserMessageStart({ role: "user", content: "fresh send" });
|
|
155
|
-
expect(m.snapshotQueue().followUp).toEqual(["queued"]);
|
|
156
|
-
expect(m.emits.length).toBe(baselineEmits);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("user message_start with array content joins text blocks (matches pi's _getUserMessageText)", () => {
|
|
160
|
-
const m = makeShadowDrainMatcher();
|
|
161
|
-
m.recordFollowup("describe this");
|
|
162
|
-
|
|
163
|
-
m.onUserMessageStart({
|
|
164
|
-
role: "user",
|
|
165
|
-
content: [
|
|
166
|
-
{ type: "text", text: "describe " },
|
|
167
|
-
{ type: "image", data: "<base64>", mimeType: "image/png" },
|
|
168
|
-
{ type: "text", text: "this" },
|
|
169
|
-
],
|
|
170
|
-
});
|
|
171
|
-
expect(m.snapshotQueue().followUp).toEqual([]);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("ignores non-user message_start (assistant role does not touch the queue)", () => {
|
|
175
|
-
const m = makeShadowDrainMatcher();
|
|
176
|
-
m.recordFollowup("a");
|
|
177
|
-
const baselineEmits = m.emits.length;
|
|
178
|
-
|
|
179
|
-
m.onUserMessageStart({ role: "assistant", content: "a" });
|
|
180
|
-
expect(m.snapshotQueue().followUp).toEqual(["a"]);
|
|
181
|
-
expect(m.emits.length).toBe(baselineEmits);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it("removes only the FIRST occurrence on duplicate text (FIFO)", () => {
|
|
185
|
-
const m = makeShadowDrainMatcher();
|
|
186
|
-
m.recordFollowup("dup");
|
|
187
|
-
m.recordFollowup("other");
|
|
188
|
-
m.recordFollowup("dup");
|
|
189
|
-
expect(m.snapshotQueue().followUp).toEqual(["dup", "other", "dup"]);
|
|
190
|
-
|
|
191
|
-
m.onUserMessageStart({ role: "user", content: "dup" });
|
|
192
|
-
// First "dup" removed; second one still queued (FIFO).
|
|
193
|
-
expect(m.snapshotQueue().followUp).toEqual(["other", "dup"]);
|
|
194
|
-
|
|
195
|
-
m.onUserMessageStart({ role: "user", content: "dup" });
|
|
196
|
-
expect(m.snapshotQueue().followUp).toEqual(["other"]);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it("entries added DURING drain are preserved (no bulk wipe)", () => {
|
|
200
|
-
const m = makeShadowDrainMatcher();
|
|
201
|
-
m.recordFollowup("a");
|
|
202
|
-
m.recordFollowup("b");
|
|
203
|
-
|
|
204
|
-
// Pi drains "a"
|
|
205
|
-
m.onUserMessageStart({ role: "user", content: "a" });
|
|
206
|
-
expect(m.snapshotQueue().followUp).toEqual(["b"]);
|
|
207
|
-
|
|
208
|
-
// User adds a new entry "c" while pi is still draining
|
|
209
|
-
m.recordFollowup("c");
|
|
210
|
-
expect(m.snapshotQueue().followUp).toEqual(["b", "c"]);
|
|
211
|
-
|
|
212
|
-
// Pi drains "b"
|
|
213
|
-
m.onUserMessageStart({ role: "user", content: "b" });
|
|
214
|
-
// "c" must still be present
|
|
215
|
-
expect(m.snapshotQueue().followUp).toEqual(["c"]);
|
|
216
|
-
|
|
217
|
-
// Eventually pi drains "c"
|
|
218
|
-
m.onUserMessageStart({ role: "user", content: "c" });
|
|
219
|
-
expect(m.snapshotQueue().followUp).toEqual([]);
|
|
220
|
-
});
|
|
221
|
-
});
|