@blackbelt-technology/pi-dashboard-extension 0.5.3 → 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 +50 -0
- package/src/__tests__/bridge-followup-chat-order.test.ts +215 -0
- package/src/__tests__/bridge-followup-multi-entry.test.ts +202 -0
- 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-queue-update-forward.test.ts +77 -0
- package/src/__tests__/bridge-shadow-queue-gate.test.ts +299 -0
- package/src/__tests__/bridge-shutdown-reset.test.ts +159 -0
- package/src/__tests__/bridge-slash-command-routing.test.ts +127 -31
- 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 +427 -29
- 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__/source-detector.test.ts +15 -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 +48 -0
- package/src/bridge-default-model-gate.ts.AGENTS.md +3 -0
- package/src/bridge.ts +1373 -213
- package/src/bridge.ts.AGENTS.md +3 -0
- package/src/canvas-tool.ts +107 -0
- package/src/command-handler.ts +527 -42
- 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 +5 -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 +25 -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 +32 -15
- package/src/slash-dispatch.ts.AGENTS.md +3 -0
- package/src/source-detector.ts +13 -5
- 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__/usage-limit-orderer.test.ts +0 -105
- package/src/__tests__/vcs-info-jj.test.ts +0 -145
- package/src/usage-limit-orderer.ts +0 -76
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-result image inliner for the bridge (Fix B).
|
|
3
|
+
*
|
|
4
|
+
* At `tool_execution_end`, a CLI tool (e.g. the `browser` skill's `screenshot`
|
|
5
|
+
* command run via `bash`) surfaces its output as a TEXT result that references
|
|
6
|
+
* a saved image by absolute path — e.g. `Screenshot saved: /…/shot.png`. The
|
|
7
|
+
* dashboard linkifies that path; clicking it 403s for an out-of-repo artifact.
|
|
8
|
+
*
|
|
9
|
+
* This module detects absolute paths to existing local image files in a tool
|
|
10
|
+
* result and inlines their bytes as `type:"image"` content blocks — the same
|
|
11
|
+
* shape the `Read`-tool inline path already produces and the client already
|
|
12
|
+
* renders. The consumed path is stripped from the text so the dashboard shows
|
|
13
|
+
* exactly one inline image (not an image plus a dead link). Over-cap /
|
|
14
|
+
* non-existent / non-image paths are left as text and fall back to the
|
|
15
|
+
* artifact-serving route (Fix A).
|
|
16
|
+
*
|
|
17
|
+
* Pure: all I/O goes through the injected `readFile` callback (same one the
|
|
18
|
+
* markdown inliner uses), so tests drive every branch with memory fixtures.
|
|
19
|
+
*
|
|
20
|
+
* See change: inline-agent-screenshot-artifacts.
|
|
21
|
+
*/
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import {
|
|
24
|
+
inlineLocalImagePath,
|
|
25
|
+
MAX_PER_IMAGE_BYTES,
|
|
26
|
+
MAX_PER_MESSAGE_BYTES,
|
|
27
|
+
type ReadFileOutcome,
|
|
28
|
+
} from "./markdown-image-inliner.js";
|
|
29
|
+
|
|
30
|
+
/** Default cap on images inlined per tool result (decision D2). */
|
|
31
|
+
export const MAX_IMAGES_PER_RESULT = 4;
|
|
32
|
+
|
|
33
|
+
/** Recognized image extensions (matches the inliner's MIME allowlist). */
|
|
34
|
+
const IMAGE_EXT = "png|jpe?g|gif|webp|svg|avif|bmp";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Matches an absolute path ending in a recognized image extension.
|
|
38
|
+
* POSIX: `/…/name.png`. Windows: `C:\…\name.png` or `C:/…/name.png`.
|
|
39
|
+
* Path runs stop at whitespace — screenshot artifact paths have no spaces.
|
|
40
|
+
*/
|
|
41
|
+
const ABS_IMAGE_PATH_RE = new RegExp(
|
|
42
|
+
`(?:[A-Za-z]:[\\\\/]|/)[^\\s)"']+\\.(?:${IMAGE_EXT})`,
|
|
43
|
+
"gi",
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
/** An inlined image content block (same shape the client reducer extracts). */
|
|
47
|
+
export interface ImageContentBlock {
|
|
48
|
+
type: "image";
|
|
49
|
+
data: string;
|
|
50
|
+
mimeType: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface InlineToolResultImagesOptions {
|
|
54
|
+
/** Synchronous file-read callback (same shape as the markdown inliner). */
|
|
55
|
+
readFile: (absolutePath: string) => ReadFileOutcome;
|
|
56
|
+
/** Override the per-image cap. Default `MAX_PER_IMAGE_BYTES`. */
|
|
57
|
+
maxPerImageBytes?: number;
|
|
58
|
+
/** Override the per-result cumulative cap. Default `MAX_PER_MESSAGE_BYTES`. */
|
|
59
|
+
maxPerMessageBytes?: number;
|
|
60
|
+
/** Override the per-result image-count cap. Default `MAX_IMAGES_PER_RESULT`. */
|
|
61
|
+
maxImagesPerResult?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Containment gate. When provided, a candidate path is inlined only if this
|
|
64
|
+
* predicate returns true (the bridge wires it to the artifact-root allowlist
|
|
65
|
+
* so arbitrary tool-echoed paths are NOT read/inlined). Disallowed paths are
|
|
66
|
+
* left as text → artifact-serving fallback. When omitted, no path restriction.
|
|
67
|
+
*/
|
|
68
|
+
isAllowedPath?: (absPath: string) => boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface InlineToolResultImagesResult {
|
|
72
|
+
/**
|
|
73
|
+
* Rewritten result. When at least one image is inlined, this is a
|
|
74
|
+
* content-block array `[{type:"text",text}, {type:"image",…}, …]`. When
|
|
75
|
+
* nothing is inlined, the original `result` is returned unchanged.
|
|
76
|
+
*/
|
|
77
|
+
result: unknown;
|
|
78
|
+
/** Number of images inlined. */
|
|
79
|
+
inlinedCount: number;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Decoded byte length of a base64 string, accounting for `=` padding. */
|
|
83
|
+
function base64DecodedBytes(b64: string): number {
|
|
84
|
+
if (b64.length === 0) return 0;
|
|
85
|
+
const padding = b64.endsWith("==") ? 2 : b64.endsWith("=") ? 1 : 0;
|
|
86
|
+
return Math.floor((b64.length * 3) / 4) - padding;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Extract a single display string from a tool result (string or content array). */
|
|
90
|
+
function resultToText(result: unknown): string {
|
|
91
|
+
if (typeof result === "string") return result;
|
|
92
|
+
if (result && typeof result === "object" && !Array.isArray(result)) {
|
|
93
|
+
const content = (result as Record<string, unknown>).content;
|
|
94
|
+
if (Array.isArray(content)) {
|
|
95
|
+
return content
|
|
96
|
+
.filter((c: any) => c?.type === "text" && typeof c.text === "string")
|
|
97
|
+
.map((c: any) => c.text as string)
|
|
98
|
+
.join("\n");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return "";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Scan a tool result for absolute image paths that resolve to existing files
|
|
106
|
+
* and inline them as `type:"image"` content blocks. Returns the (possibly
|
|
107
|
+
* rewritten) result and the number of images inlined.
|
|
108
|
+
*/
|
|
109
|
+
export function inlineToolResultImages(
|
|
110
|
+
result: unknown,
|
|
111
|
+
opts: InlineToolResultImagesOptions,
|
|
112
|
+
): InlineToolResultImagesResult {
|
|
113
|
+
const text = resultToText(result);
|
|
114
|
+
if (!text) return { result, inlinedCount: 0 };
|
|
115
|
+
|
|
116
|
+
const maxImages = opts.maxImagesPerResult ?? MAX_IMAGES_PER_RESULT;
|
|
117
|
+
const maxPerMessage = opts.maxPerMessageBytes ?? MAX_PER_MESSAGE_BYTES;
|
|
118
|
+
|
|
119
|
+
// Collect unique absolute image-path candidates in first-seen order.
|
|
120
|
+
const candidates: string[] = [];
|
|
121
|
+
const seen = new Set<string>();
|
|
122
|
+
ABS_IMAGE_PATH_RE.lastIndex = 0;
|
|
123
|
+
let m: RegExpExecArray | null;
|
|
124
|
+
while ((m = ABS_IMAGE_PATH_RE.exec(text)) !== null) {
|
|
125
|
+
const p = m[0];
|
|
126
|
+
if (!path.isAbsolute(p) || seen.has(p)) continue;
|
|
127
|
+
seen.add(p);
|
|
128
|
+
candidates.push(p);
|
|
129
|
+
}
|
|
130
|
+
if (candidates.length === 0) return { result, inlinedCount: 0 };
|
|
131
|
+
|
|
132
|
+
// Base64 payloads already present as image blocks in the ORIGINAL result.
|
|
133
|
+
// The MCP `browser` tool returns a text block (`Screenshot saved: /…png`)
|
|
134
|
+
// AND a native `type:"image"` block for that same screenshot. Inlining the
|
|
135
|
+
// path-referenced file would append a byte-identical second copy — rendered
|
|
136
|
+
// side-by-side in the chat ("on parallel"). We skip such duplicates below but
|
|
137
|
+
// still strip the now-redundant path from the text. Genuinely different
|
|
138
|
+
// images (native image + a path to a DIFFERENT file) are unaffected.
|
|
139
|
+
const existingImageData = new Set<string>();
|
|
140
|
+
if (result && typeof result === "object" && Array.isArray((result as Record<string, unknown>).content)) {
|
|
141
|
+
for (const c of (result as Record<string, unknown>).content as any[]) {
|
|
142
|
+
if (c?.type === "image" && typeof c.data === "string") existingImageData.add(c.data);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const blocks: ImageContentBlock[] = [];
|
|
147
|
+
const consumedPaths: string[] = [];
|
|
148
|
+
let bytesInThisResult = 0;
|
|
149
|
+
|
|
150
|
+
for (const absPath of candidates) {
|
|
151
|
+
if (blocks.length >= maxImages) break;
|
|
152
|
+
// Containment gate BEFORE any disk read: skip paths outside the allowlist.
|
|
153
|
+
if (opts.isAllowedPath && !opts.isAllowedPath(absPath)) continue;
|
|
154
|
+
const outcome = inlineLocalImagePath(absPath, {
|
|
155
|
+
readFile: opts.readFile,
|
|
156
|
+
maxPerImageBytes: opts.maxPerImageBytes,
|
|
157
|
+
});
|
|
158
|
+
if ("ok" in outcome) continue; // ReadFileError: missing / non-image / too-large → leave as text
|
|
159
|
+
// Already carried natively by the result (byte-identical): strip the path
|
|
160
|
+
// so it isn't linkified, but do NOT append a duplicate image block.
|
|
161
|
+
if (existingImageData.has(outcome.data)) {
|
|
162
|
+
consumedPaths.push(absPath);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
// Per-result cumulative budget (padding-aware decoded byte count).
|
|
166
|
+
const size = base64DecodedBytes(outcome.data);
|
|
167
|
+
if (bytesInThisResult + size > maxPerMessage) continue; // over budget → leave as text
|
|
168
|
+
bytesInThisResult += size;
|
|
169
|
+
blocks.push({ type: "image", data: outcome.data, mimeType: outcome.mimeType });
|
|
170
|
+
consumedPaths.push(absPath);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Nothing inlined AND nothing to strip → return the result untouched.
|
|
174
|
+
if (blocks.length === 0 && consumedPaths.length === 0) return { result, inlinedCount: 0 };
|
|
175
|
+
|
|
176
|
+
// Strip each consumed path so it is NOT also linkified (D5).
|
|
177
|
+
const stripPaths = (s: string): string => {
|
|
178
|
+
let out = s;
|
|
179
|
+
for (const p of consumedPaths) out = out.split(p).join("");
|
|
180
|
+
return out;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// Preserve the original result shape: when it already carried a content
|
|
184
|
+
// array, keep every block (incl. non-text / metadata) and only strip paths
|
|
185
|
+
// inside text blocks, then append the new image blocks. A bare string result
|
|
186
|
+
// becomes a single stripped text block plus the images.
|
|
187
|
+
let content: unknown[];
|
|
188
|
+
if (result && typeof result === "object" && Array.isArray((result as Record<string, unknown>).content)) {
|
|
189
|
+
const orig = (result as Record<string, unknown>).content as any[];
|
|
190
|
+
content = [
|
|
191
|
+
...orig.map((c) =>
|
|
192
|
+
c?.type === "text" && typeof c.text === "string" ? { ...c, text: stripPaths(c.text) } : c,
|
|
193
|
+
),
|
|
194
|
+
...blocks,
|
|
195
|
+
];
|
|
196
|
+
} else {
|
|
197
|
+
content = [{ type: "text", text: stripPaths(text) }, ...blocks];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
result: { content },
|
|
202
|
+
inlinedCount: blocks.length,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# tool-result-image-inliner.ts — index
|
|
2
|
+
|
|
3
|
+
Bridge Fix B tool-result image inliner. On `tool_execution_end` scans result text for absolute image paths (png/jpg/jpeg/gif/webp/svg/avif/bmp) resolving to existing files. Inlines via `inlineLocalImagePath` as `type:"image"` content blocks. Caps: `MAX_IMAGES_PER_RESULT=4`, `MAX_PER_IMAGE_BYTES`, `MAX_PER_MESSAGE_BYTES`. Strips consumed path from text (no dead link, D5). Over-cap/missing/non-image left as text → falls back to artifact route. Pure; `readFile` injected. Exports `inlineToolResultImages`, `ImageContentBlock`, `MAX_IMAGES_PER_RESULT`. Adds `isAllowedPath` gate (artifact-root containment) before disk read; preserves pre-existing non-text content blocks; padding-aware base64 byte budget. Byte-dedup: skips appending an image whose bytes match an image block already in the result (e.g. MCP `browser` returns text + native image for same screenshot) → strips path, no side-by-side duplicate; genuinely-different images still inline. See change: inline-agent-screenshot-artifacts, fix-duplicate-inlined-screenshot.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PromptAdapter,
|
|
3
|
+
PromptBus,
|
|
4
|
+
PromptRequest,
|
|
5
|
+
PromptResponse,
|
|
6
|
+
} from "./prompt-bus.js";
|
|
7
|
+
|
|
8
|
+
export interface TuiPromptUi {
|
|
9
|
+
select?: (
|
|
10
|
+
question: string,
|
|
11
|
+
options: string[],
|
|
12
|
+
extra?: { signal?: AbortSignal },
|
|
13
|
+
) => Promise<string | undefined>;
|
|
14
|
+
input?: (
|
|
15
|
+
question: string,
|
|
16
|
+
placeholder?: string,
|
|
17
|
+
extra?: { signal?: AbortSignal },
|
|
18
|
+
) => Promise<string | undefined>;
|
|
19
|
+
confirm?: (
|
|
20
|
+
question: string,
|
|
21
|
+
message: string,
|
|
22
|
+
extra?: { signal?: AbortSignal },
|
|
23
|
+
) => Promise<boolean>;
|
|
24
|
+
editor?: (
|
|
25
|
+
question: string,
|
|
26
|
+
prefill?: string,
|
|
27
|
+
extra?: { signal?: AbortSignal },
|
|
28
|
+
) => Promise<string | undefined>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function promptMessage(prompt: PromptRequest): string {
|
|
32
|
+
return typeof prompt.metadata?.message === "string"
|
|
33
|
+
? prompt.metadata.message
|
|
34
|
+
: "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Create the PromptBus adapter that presents supported prompts in Pi's TUI. */
|
|
38
|
+
export function createTuiPromptAdapter(
|
|
39
|
+
ui: TuiPromptUi,
|
|
40
|
+
bus: Pick<PromptBus, "respond">,
|
|
41
|
+
): PromptAdapter {
|
|
42
|
+
const activeControllers = new Map<string, AbortController>();
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
name: "tui",
|
|
46
|
+
|
|
47
|
+
onRequest(prompt) {
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
activeControllers.set(prompt.id, controller);
|
|
50
|
+
|
|
51
|
+
const present = async (): Promise<void> => {
|
|
52
|
+
try {
|
|
53
|
+
let answer: string | boolean | undefined;
|
|
54
|
+
|
|
55
|
+
if (prompt.type === "select" && prompt.options && ui.select) {
|
|
56
|
+
answer = await ui.select(prompt.question, prompt.options, {
|
|
57
|
+
signal: controller.signal,
|
|
58
|
+
});
|
|
59
|
+
} else if (prompt.type === "input" && ui.input) {
|
|
60
|
+
answer = await ui.input(
|
|
61
|
+
prompt.question,
|
|
62
|
+
prompt.defaultValue || "",
|
|
63
|
+
{ signal: controller.signal },
|
|
64
|
+
);
|
|
65
|
+
} else if (prompt.type === "confirm" && ui.confirm) {
|
|
66
|
+
answer = await ui.confirm(prompt.question, promptMessage(prompt), {
|
|
67
|
+
signal: controller.signal,
|
|
68
|
+
});
|
|
69
|
+
} else if (prompt.type === "editor" && ui.editor) {
|
|
70
|
+
answer = await ui.editor(
|
|
71
|
+
prompt.question,
|
|
72
|
+
prompt.defaultValue || "",
|
|
73
|
+
{ signal: controller.signal },
|
|
74
|
+
);
|
|
75
|
+
} else {
|
|
76
|
+
// There is intentionally no multiselect arm. Pi 0.70 RPC mode's
|
|
77
|
+
// ctx.ui.custom is a no-op and would auto-cancel the dashboard UI.
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!controller.signal.aborted) {
|
|
82
|
+
const answerString = typeof answer === "boolean"
|
|
83
|
+
? (answer ? "true" : "false")
|
|
84
|
+
: answer;
|
|
85
|
+
bus.respond({
|
|
86
|
+
id: prompt.id,
|
|
87
|
+
answer: answerString ?? undefined,
|
|
88
|
+
cancelled: answerString == null,
|
|
89
|
+
source: "tui",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
if (!controller.signal.aborted) {
|
|
94
|
+
bus.respond({ id: prompt.id, cancelled: true, source: "tui" });
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
activeControllers.delete(prompt.id);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
void present();
|
|
102
|
+
return {};
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
onResponse(response: PromptResponse) {
|
|
106
|
+
if (response.source !== "tui") {
|
|
107
|
+
const controller = activeControllers.get(response.id);
|
|
108
|
+
if (controller) {
|
|
109
|
+
controller.abort();
|
|
110
|
+
activeControllers.delete(response.id);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
onCancel(id) {
|
|
116
|
+
const controller = activeControllers.get(id);
|
|
117
|
+
if (controller) {
|
|
118
|
+
controller.abort();
|
|
119
|
+
activeControllers.delete(id);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# tui-prompt-adapter.ts — index
|
|
2
|
+
|
|
3
|
+
Production PromptBus adapter for Pi's TUI. Exports `createTuiPromptAdapter(ui, bus)` and `TuiPromptUi`. Presents select/input/confirm/editor through captured unpatched `ctx.ui` methods (registered before `ctx.ui` is patched). Forwards confirm `metadata.message` as the rendered second arg (empty string when absent) so terminal confirm dialogs keep the context the dashboard already shows. Boolean confirm → `"true"`/`"false"` string; null answer → cancelled. Aborts its dialog when another adapter answers first or on cancel via a per-prompt `AbortController` map. Intentionally has no multiselect arm — pi 0.70 RPC mode's `ctx.ui.custom` is a no-op and would auto-cancel the dashboard-rendered dialog (see change: fix-multiselect-tui-arm-self-cancel); multiselect is handled by the bus-routed `ctx.ui.multiselect` patch + `DashboardDefaultAdapter`. See change: fix-confirm-context-in-pi-tui (PR #286).
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* classifyTurnActionability — pure, provider-agnostic classification of an
|
|
3
|
+
* assistant turn's terminal shape.
|
|
4
|
+
*
|
|
5
|
+
* Captured defect (live): `google-vertex/gemini-2.5-pro` on a heavy first
|
|
6
|
+
* agentic turn returned `content = [thinking]` only — zero text parts, no
|
|
7
|
+
* tool call, `stopReason = "stop"`, `error = {}` — and pi/dashboard treated
|
|
8
|
+
* that clean-but-empty completion as finished, idling the session silently.
|
|
9
|
+
* This function labels that shape `empty-actionable` so the bridge guard can
|
|
10
|
+
* continue-or-surface instead of idling.
|
|
11
|
+
*
|
|
12
|
+
* Classification depends on TURN SHAPE ONLY (stop reason + content parts +
|
|
13
|
+
* error presence), never on provider identity — the guard applies to any
|
|
14
|
+
* reasoning-capable model that can emit reasoning-then-stop.
|
|
15
|
+
*
|
|
16
|
+
* See change: fix-gemini-subagent-silent-tool-schema-failure.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export type TurnActionability = "normal" | "empty-actionable" | "truncated" | "error";
|
|
20
|
+
|
|
21
|
+
/** Minimal shape plucked from a pi assistant message (message_end / agent_end). */
|
|
22
|
+
export interface ClassifiableTurn {
|
|
23
|
+
role?: string;
|
|
24
|
+
stopReason?: string;
|
|
25
|
+
/** pi content: an array of parts, or (some providers) a bare string. */
|
|
26
|
+
content?: unknown;
|
|
27
|
+
/** Present on a terminal error turn. */
|
|
28
|
+
errorMessage?: string;
|
|
29
|
+
/** pi may attach an `error` object; `{}` counts as no error. */
|
|
30
|
+
error?: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Stop reasons that indicate the provider truncated output (ran out of the
|
|
35
|
+
* token budget). Handled separately from empty-actionable — a truncation is
|
|
36
|
+
* not a clean completion. pi-ai emits `"length"`; other adapters may surface
|
|
37
|
+
* `max_tokens`/`maxTokens`.
|
|
38
|
+
*/
|
|
39
|
+
const TRUNCATION_STOP_REASONS: ReadonlySet<string> = new Set(["length", "max_tokens", "maxTokens"]);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Content-part `type` values that count as a tool call. pi emits `"toolCall"`;
|
|
43
|
+
* the others are accepted defensively so a normalized/adapter variant is never
|
|
44
|
+
* misread as empty.
|
|
45
|
+
*/
|
|
46
|
+
const TOOL_CALL_PART_TYPES: ReadonlySet<string> = new Set([
|
|
47
|
+
"toolCall",
|
|
48
|
+
"tool_call",
|
|
49
|
+
"toolUse",
|
|
50
|
+
"tool_use",
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
/** True when `error` carries an actual error (non-null object with keys, or a non-empty string). */
|
|
54
|
+
function hasErrorObject(error: unknown): boolean {
|
|
55
|
+
if (error == null) return false;
|
|
56
|
+
if (typeof error === "string") return error.length > 0;
|
|
57
|
+
if (typeof error === "object") return Object.keys(error as object).length > 0;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* True when the turn's content contains a visible text part (non-empty after
|
|
63
|
+
* trim) OR a bare non-empty string. Whitespace-only text is NOT visible.
|
|
64
|
+
*/
|
|
65
|
+
function hasVisibleText(content: unknown): boolean {
|
|
66
|
+
if (typeof content === "string") return content.trim().length > 0;
|
|
67
|
+
if (!Array.isArray(content)) return false;
|
|
68
|
+
return content.some((part) => {
|
|
69
|
+
if (!part || typeof part !== "object") return false;
|
|
70
|
+
const p = part as { type?: string; text?: unknown };
|
|
71
|
+
return p.type === "text" && typeof p.text === "string" && p.text.trim().length > 0;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** True when the turn's content contains a tool-call part. */
|
|
76
|
+
function hasToolCall(content: unknown): boolean {
|
|
77
|
+
if (!Array.isArray(content)) return false;
|
|
78
|
+
return content.some((part) => {
|
|
79
|
+
if (!part || typeof part !== "object") return false;
|
|
80
|
+
const p = part as { type?: string };
|
|
81
|
+
return typeof p.type === "string" && TOOL_CALL_PART_TYPES.has(p.type);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Classify an assistant turn.
|
|
87
|
+
*
|
|
88
|
+
* - `error` — terminal error (`stopReason === "error"` OR an error object/message present).
|
|
89
|
+
* - `truncated` — `stopReason` is a truncation reason (`length`/`max_tokens`).
|
|
90
|
+
* - `empty-actionable` — terminal non-error stop with NO visible text AND NO tool call
|
|
91
|
+
* (thinking-only or wholly empty content).
|
|
92
|
+
* - `normal` — has visible text or a tool call (untouched by the guard).
|
|
93
|
+
*
|
|
94
|
+
* Error precedence beats truncation beats empty-actionable. A turn with visible
|
|
95
|
+
* text or a tool call is always `normal` regardless of stop reason.
|
|
96
|
+
*/
|
|
97
|
+
export function classifyTurnActionability(turn: ClassifiableTurn | undefined | null): TurnActionability {
|
|
98
|
+
if (!turn) return "normal";
|
|
99
|
+
|
|
100
|
+
const errored =
|
|
101
|
+
turn.stopReason === "error" ||
|
|
102
|
+
(typeof turn.errorMessage === "string" && turn.errorMessage.length > 0) ||
|
|
103
|
+
hasErrorObject(turn.error);
|
|
104
|
+
if (errored) return "error";
|
|
105
|
+
|
|
106
|
+
// A turn that actually produced output (text or a tool call) is normal,
|
|
107
|
+
// even if the stop reason is a truncation — the visible output stands.
|
|
108
|
+
if (hasVisibleText(turn.content) || hasToolCall(turn.content)) return "normal";
|
|
109
|
+
|
|
110
|
+
if (typeof turn.stopReason === "string" && TRUNCATION_STOP_REASONS.has(turn.stopReason)) {
|
|
111
|
+
return "truncated";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// No visible text, no tool call, no error, not a truncation → the clean-but-
|
|
115
|
+
// empty completion (thinking-only or empty). This is the captured defect.
|
|
116
|
+
return "empty-actionable";
|
|
117
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# turn-actionability.ts — index
|
|
2
|
+
|
|
3
|
+
Pure provider-agnostic classifier. Exports `classifyTurnActionability(turn)` → `normal`/`empty-actionable`/`truncated`/`error`, `ClassifiableTurn`, `TurnActionability`. `empty-actionable` = terminal non-error stop, no visible text part, no tool call (thinking-only/empty). Error precedence > truncation (`length`/`max_tokens`) > empty-actionable; text/toolCall part → normal regardless of stop reason. Shape-only, no provider id. See change: fix-gemini-subagent-silent-tool-schema-failure.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# ui-modules.ts — index
|
|
2
|
+
|
|
3
|
+
Extension UI system bridge side. Exports `refreshUiModules`, `subscribeUiInvalidate`, `handleUiManagement`, `INVALIDATE_RATE_CAP_PER_SEC`, `UiModulesBridgeCtx`, `UiManagementInbound`. Synchronous `ui:list-modules` probe → `ui_modules_list` + `ext_ui_decorator` messages. Last-write-wins dedup. 20/sec `ui:invalidate` throttle. `ui_management` re-emit with `_reply` → `ui_data_list`.
|