@blackbelt-technology/pi-dashboard-extension 0.4.5 → 0.5.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/package.json +2 -2
- package/src/__tests__/build-provider-catalogue.test.ts +176 -0
- package/src/__tests__/markdown-image-inliner.test.ts +355 -0
- package/src/__tests__/openspec-activity-detector.test.ts +68 -0
- package/src/__tests__/prompt-bus.test.ts +44 -0
- package/src/__tests__/prompt-expander.test.ts +45 -0
- package/src/__tests__/server-launcher.test.ts +24 -1
- package/src/__tests__/vcs-info-jj.test.ts +145 -0
- package/src/__tests__/{git-info.test.ts → vcs-info.test.ts} +6 -6
- package/src/bridge-context.ts +7 -0
- package/src/bridge.ts +142 -4
- package/src/command-handler.ts +6 -0
- package/src/markdown-image-inliner.ts +268 -0
- package/src/model-tracker.ts +35 -1
- package/src/prompt-bus.ts +4 -3
- package/src/prompt-expander.ts +50 -2
- package/src/provider-register.ts +117 -0
- package/src/server-launcher.ts +18 -1
- package/src/session-sync.ts +6 -1
- package/src/vcs-info.ts +184 -0
- package/src/git-info.ts +0 -55
package/src/vcs-info.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VCS info gathering — detects git branch/remote/PR AND jj workspace state.
|
|
3
|
+
* Delegates to shared platform tool modules so there's no inline execSync
|
|
4
|
+
* and every call benefits from the runner's safety defaults (windowsHide,
|
|
5
|
+
* timeout, tolerated exit codes).
|
|
6
|
+
*
|
|
7
|
+
* jj probing is fast-path-gated: when `<cwd>/.jj/` doesn't exist, NO `jj`
|
|
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.
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import * as git from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
15
|
+
import * as jj from "@blackbelt-technology/pi-dashboard-shared/platform/jj.js";
|
|
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";
|
|
18
|
+
import { buildGitLinks, type GitLinks } from "./git-link-builder.js";
|
|
19
|
+
|
|
20
|
+
export interface GitInfo {
|
|
21
|
+
gitBranch: string;
|
|
22
|
+
gitBranchUrl?: string;
|
|
23
|
+
gitPrNumber?: number;
|
|
24
|
+
gitPrUrl?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Detect the current git branch. Returns short SHA for detached HEAD. */
|
|
28
|
+
export function detectBranch(cwd: string): string | undefined {
|
|
29
|
+
const ref = git.currentBranchOr({ cwd });
|
|
30
|
+
if (!ref) return undefined;
|
|
31
|
+
if (ref === "HEAD") {
|
|
32
|
+
// Detached HEAD — return short commit SHA
|
|
33
|
+
return git.headShaOr({ cwd, short: true }) ?? "HEAD";
|
|
34
|
+
}
|
|
35
|
+
return ref;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Detect the remote origin URL. */
|
|
39
|
+
export function detectRemoteUrl(cwd: string): string | undefined {
|
|
40
|
+
return git.remoteUrlOr({ cwd });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Detect the PR number via gh CLI (best effort). */
|
|
44
|
+
export function detectPrNumber(cwd: string): number | undefined {
|
|
45
|
+
return git.prNumberOr({ cwd });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Gather all git info for a directory. Returns undefined if not a git repo. */
|
|
49
|
+
export function gatherGitInfo(cwd: string): GitInfo | undefined {
|
|
50
|
+
const branch = detectBranch(cwd);
|
|
51
|
+
if (!branch) return undefined;
|
|
52
|
+
|
|
53
|
+
const remoteUrl = detectRemoteUrl(cwd);
|
|
54
|
+
const prNumber = detectPrNumber(cwd);
|
|
55
|
+
|
|
56
|
+
const links: GitLinks = remoteUrl ? buildGitLinks(remoteUrl, branch, prNumber) : {};
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
gitBranch: branch,
|
|
60
|
+
gitBranchUrl: links.branchUrl,
|
|
61
|
+
gitPrNumber: prNumber,
|
|
62
|
+
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),
|
|
183
|
+
};
|
|
184
|
+
}
|
package/src/git-info.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Git info gathering — detects branch, remote URL, and PR number.
|
|
3
|
-
* Delegates to the shared git tool module so there's no inline execSync
|
|
4
|
-
* and every call benefits from the runner's safety defaults (windowsHide,
|
|
5
|
-
* timeout, tolerated exit codes).
|
|
6
|
-
* See change: platform-command-executor.
|
|
7
|
-
*/
|
|
8
|
-
import * as git from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
9
|
-
import { buildGitLinks, type GitLinks } from "./git-link-builder.js";
|
|
10
|
-
|
|
11
|
-
export interface GitInfo {
|
|
12
|
-
gitBranch: string;
|
|
13
|
-
gitBranchUrl?: string;
|
|
14
|
-
gitPrNumber?: number;
|
|
15
|
-
gitPrUrl?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Detect the current git branch. Returns short SHA for detached HEAD. */
|
|
19
|
-
export function detectBranch(cwd: string): string | undefined {
|
|
20
|
-
const ref = git.currentBranchOr({ cwd });
|
|
21
|
-
if (!ref) return undefined;
|
|
22
|
-
if (ref === "HEAD") {
|
|
23
|
-
// Detached HEAD — return short commit SHA
|
|
24
|
-
return git.headShaOr({ cwd, short: true }) ?? "HEAD";
|
|
25
|
-
}
|
|
26
|
-
return ref;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Detect the remote origin URL. */
|
|
30
|
-
export function detectRemoteUrl(cwd: string): string | undefined {
|
|
31
|
-
return git.remoteUrlOr({ cwd });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Detect the PR number via gh CLI (best effort). */
|
|
35
|
-
export function detectPrNumber(cwd: string): number | undefined {
|
|
36
|
-
return git.prNumberOr({ cwd });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Gather all git info for a directory. Returns undefined if not a git repo. */
|
|
40
|
-
export function gatherGitInfo(cwd: string): GitInfo | undefined {
|
|
41
|
-
const branch = detectBranch(cwd);
|
|
42
|
-
if (!branch) return undefined;
|
|
43
|
-
|
|
44
|
-
const remoteUrl = detectRemoteUrl(cwd);
|
|
45
|
-
const prNumber = detectPrNumber(cwd);
|
|
46
|
-
|
|
47
|
-
const links: GitLinks = remoteUrl ? buildGitLinks(remoteUrl, branch, prNumber) : {};
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
gitBranch: branch,
|
|
51
|
-
gitBranchUrl: links.branchUrl,
|
|
52
|
-
gitPrNumber: prNumber,
|
|
53
|
-
gitPrUrl: links.prUrl,
|
|
54
|
-
};
|
|
55
|
-
}
|