@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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the bridge's artifact-root allowlist (Fix B containment).
|
|
3
|
+
* See change: inline-agent-screenshot-artifacts.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from "vitest";
|
|
6
|
+
import { resolveArtifactRoots, isUnderArtifactRoot } from "../artifact-roots.js";
|
|
7
|
+
|
|
8
|
+
/** realpathSync stub: returns mapped value, throws ENOENT for unknown paths. */
|
|
9
|
+
function fakeRealpath(map: Record<string, string>) {
|
|
10
|
+
return (p: string): string => {
|
|
11
|
+
if (p in map) return map[p];
|
|
12
|
+
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("resolveArtifactRoots", () => {
|
|
17
|
+
it("includes the default agent-browser tmp dir when it resolves", () => {
|
|
18
|
+
const roots = resolveArtifactRoots({
|
|
19
|
+
homedir: "/home/pi",
|
|
20
|
+
env: {},
|
|
21
|
+
realpathSync: fakeRealpath({ "/home/pi/.agent-browser/tmp": "/home/pi/.agent-browser/tmp" }),
|
|
22
|
+
});
|
|
23
|
+
expect(roots).toEqual(["/home/pi/.agent-browser/tmp"]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("adds AGENT_BROWSER_SCREENSHOT_DIR when set", () => {
|
|
27
|
+
const roots = resolveArtifactRoots({
|
|
28
|
+
homedir: "/home/pi",
|
|
29
|
+
env: { AGENT_BROWSER_SCREENSHOT_DIR: "/shots" },
|
|
30
|
+
realpathSync: fakeRealpath({
|
|
31
|
+
"/home/pi/.agent-browser/tmp": "/home/pi/.agent-browser/tmp",
|
|
32
|
+
"/shots": "/real/shots",
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
expect(roots).toEqual(["/home/pi/.agent-browser/tmp", "/real/shots"]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("drops roots that do not resolve (missing dir)", () => {
|
|
39
|
+
const roots = resolveArtifactRoots({
|
|
40
|
+
homedir: "/home/pi",
|
|
41
|
+
env: {},
|
|
42
|
+
realpathSync: fakeRealpath({}), // nothing resolves
|
|
43
|
+
});
|
|
44
|
+
expect(roots).toEqual([]);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("isUnderArtifactRoot", () => {
|
|
49
|
+
const roots = ["/home/pi/.agent-browser/tmp"];
|
|
50
|
+
const rp = fakeRealpath({
|
|
51
|
+
"/home/pi/.agent-browser/tmp/shot.png": "/home/pi/.agent-browser/tmp/shot.png",
|
|
52
|
+
"/home/pi/.agent-browser/tmp/sub/a.png": "/home/pi/.agent-browser/tmp/sub/a.png",
|
|
53
|
+
"/etc/passwd.png": "/etc/passwd.png",
|
|
54
|
+
"/home/pi/secret.png": "/home/pi/secret.png",
|
|
55
|
+
// symlink escape: realpath resolves outside the root
|
|
56
|
+
"/home/pi/.agent-browser/tmp/evil.png": "/etc/shadow.png",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("accepts a file directly inside a root", () => {
|
|
60
|
+
expect(isUnderArtifactRoot("/home/pi/.agent-browser/tmp/shot.png", roots, rp)).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("accepts a nested file", () => {
|
|
64
|
+
expect(isUnderArtifactRoot("/home/pi/.agent-browser/tmp/sub/a.png", roots, rp)).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("rejects a path outside every root", () => {
|
|
68
|
+
expect(isUnderArtifactRoot("/etc/passwd.png", roots, rp)).toBe(false);
|
|
69
|
+
expect(isUnderArtifactRoot("/home/pi/secret.png", roots, rp)).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("rejects a symlink whose realpath escapes the root", () => {
|
|
73
|
+
expect(isUnderArtifactRoot("/home/pi/.agent-browser/tmp/evil.png", roots, rp)).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("rejects a non-existent path (realpath throws)", () => {
|
|
77
|
+
expect(isUnderArtifactRoot("/home/pi/.agent-browser/tmp/missing.png", roots, rp)).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("rejects everything when the root list is empty", () => {
|
|
81
|
+
expect(isUnderArtifactRoot("/home/pi/.agent-browser/tmp/shot.png", [], rp)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
attachmentDirForSession,
|
|
7
|
+
extensionForMime,
|
|
8
|
+
hashBytes,
|
|
9
|
+
persistAttachment,
|
|
10
|
+
cleanupAttachmentsForSession,
|
|
11
|
+
MAX_PER_IMAGE_BYTES,
|
|
12
|
+
} from "../ask-user-attachments.js";
|
|
13
|
+
|
|
14
|
+
// Each test runs under a throwaway HOME so writes never touch the real ~/.pi.
|
|
15
|
+
let tmpHome: string;
|
|
16
|
+
let origHome: string | undefined;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
origHome = process.env.HOME;
|
|
20
|
+
tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "pi-attach-test-"));
|
|
21
|
+
process.env.HOME = tmpHome;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
process.env.HOME = origHome;
|
|
26
|
+
fs.rmSync(tmpHome, { recursive: true, force: true });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const b64 = (s: string) => Buffer.from(s).toString("base64");
|
|
30
|
+
|
|
31
|
+
describe("ask-user-attachments", () => {
|
|
32
|
+
it("maps MIME to extension via the allowlist", () => {
|
|
33
|
+
expect(extensionForMime("image/png")).toBe(".png");
|
|
34
|
+
expect(extensionForMime("image/jpeg")).toBe(".jpg");
|
|
35
|
+
expect(extensionForMime("image/gif")).toBe(".gif");
|
|
36
|
+
expect(extensionForMime("image/webp")).toBe(".webp");
|
|
37
|
+
expect(extensionForMime("application/pdf")).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("hashBytes is deterministic and 16 hex chars", () => {
|
|
41
|
+
const h1 = hashBytes(Buffer.from("hello"));
|
|
42
|
+
const h2 = hashBytes(Buffer.from("hello"));
|
|
43
|
+
expect(h1).toBe(h2);
|
|
44
|
+
expect(h1).toMatch(/^[0-9a-f]{16}$/);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("persists an image and lazily creates the per-session dir", () => {
|
|
48
|
+
const sessionId = "sess-1";
|
|
49
|
+
const dir = attachmentDirForSession(sessionId);
|
|
50
|
+
expect(fs.existsSync(dir)).toBe(false);
|
|
51
|
+
|
|
52
|
+
const res = persistAttachment({
|
|
53
|
+
sessionId,
|
|
54
|
+
image: { type: "image", data: b64("PNGDATA"), mimeType: "image/png" },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(res).not.toBeNull();
|
|
58
|
+
expect(res!.path.endsWith(".png")).toBe(true);
|
|
59
|
+
expect(res!.mimeType).toBe("image/png");
|
|
60
|
+
expect(res!.bytes).toBe(Buffer.from("PNGDATA").length);
|
|
61
|
+
expect(fs.existsSync(res!.path)).toBe(true);
|
|
62
|
+
expect(fs.existsSync(dir)).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("dedups by hash — same bytes write once", () => {
|
|
66
|
+
const sessionId = "sess-2";
|
|
67
|
+
const image = { type: "image" as const, data: b64("SAME"), mimeType: "image/png" };
|
|
68
|
+
const a = persistAttachment({ sessionId, image })!;
|
|
69
|
+
const mtimeA = fs.statSync(a.path).mtimeMs;
|
|
70
|
+
const b = persistAttachment({ sessionId, image })!;
|
|
71
|
+
expect(b.path).toBe(a.path);
|
|
72
|
+
// No rewrite — mtime unchanged.
|
|
73
|
+
expect(fs.statSync(b.path).mtimeMs).toBe(mtimeA);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("drops unsupported MIME types", () => {
|
|
77
|
+
const res = persistAttachment({
|
|
78
|
+
sessionId: "sess-3",
|
|
79
|
+
image: { type: "image", data: b64("X"), mimeType: "application/pdf" },
|
|
80
|
+
});
|
|
81
|
+
expect(res).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("drops images over the per-image cap", () => {
|
|
85
|
+
const big = Buffer.alloc(MAX_PER_IMAGE_BYTES + 1).toString("base64");
|
|
86
|
+
const res = persistAttachment({
|
|
87
|
+
sessionId: "sess-4",
|
|
88
|
+
image: { type: "image", data: big, mimeType: "image/png" },
|
|
89
|
+
});
|
|
90
|
+
expect(res).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("cleanup removes the session directory and tolerates a missing one", () => {
|
|
94
|
+
const sessionId = "sess-5";
|
|
95
|
+
persistAttachment({
|
|
96
|
+
sessionId,
|
|
97
|
+
image: { type: "image", data: b64("Y"), mimeType: "image/png" },
|
|
98
|
+
});
|
|
99
|
+
const dir = attachmentDirForSession(sessionId);
|
|
100
|
+
expect(fs.existsSync(dir)).toBe(true);
|
|
101
|
+
cleanupAttachmentsForSession(sessionId);
|
|
102
|
+
expect(fs.existsSync(dir)).toBe(false);
|
|
103
|
+
// Second call is a no-op (no throw).
|
|
104
|
+
expect(() => cleanupAttachmentsForSession(sessionId)).not.toThrow();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -184,6 +184,64 @@ describe("registerAskUserTool", () => {
|
|
|
184
184
|
});
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
describe("image attachments (multiline paste)", () => {
|
|
188
|
+
function getTool() {
|
|
189
|
+
const pi = createMockPi();
|
|
190
|
+
registerAskUserTool(pi as any);
|
|
191
|
+
return pi.registerTool.mock.calls[0][0];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
it("standalone input prefers ctx.ui.inputWithImages and surfaces attachment paths", async () => {
|
|
195
|
+
const tool = getTool();
|
|
196
|
+
const inputWithImages = vi.fn().mockResolvedValue({
|
|
197
|
+
value: "see attached",
|
|
198
|
+
attachments: [{ path: "/home/u/.pi/dashboard/attachments/s/abc.png", mimeType: "image/png", bytes: 42 }],
|
|
199
|
+
});
|
|
200
|
+
const ctx = { ui: { inputWithImages, input: vi.fn().mockResolvedValue("unused") } };
|
|
201
|
+
const res = await tool.execute("id", { method: "input", title: "Paste" }, undefined, undefined, ctx);
|
|
202
|
+
expect(inputWithImages).toHaveBeenCalledTimes(1);
|
|
203
|
+
expect(ctx.ui.input).not.toHaveBeenCalled();
|
|
204
|
+
expect(res.content[0].text).toContain('"attachments"');
|
|
205
|
+
expect(res.content[0].text).toContain("abc.png");
|
|
206
|
+
expect(res.details.result).toEqual({
|
|
207
|
+
value: "see attached",
|
|
208
|
+
attachments: [{ path: "/home/u/.pi/dashboard/attachments/s/abc.png", mimeType: "image/png", bytes: 42 }],
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("standalone input falls back to ctx.ui.input (text-only) when inputWithImages absent", async () => {
|
|
213
|
+
const tool = getTool();
|
|
214
|
+
const ctx = { ui: { input: vi.fn().mockResolvedValue("plain text") } };
|
|
215
|
+
const res = await tool.execute("id", { method: "input", title: "Q" }, undefined, undefined, ctx);
|
|
216
|
+
expect(ctx.ui.input).toHaveBeenCalledTimes(1);
|
|
217
|
+
expect(res.content[0].text).toBe('User responded: "plain text"');
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("batch input answer with attachments flows into the summary + details", async () => {
|
|
221
|
+
const tool = getTool();
|
|
222
|
+
const batch = vi.fn().mockResolvedValue([
|
|
223
|
+
{ value: "the error", attachments: [{ path: "/a/x.png", mimeType: "image/png", bytes: 9 }] },
|
|
224
|
+
{ confirmed: true },
|
|
225
|
+
]);
|
|
226
|
+
const ctx = { ui: { batch } };
|
|
227
|
+
const res = await tool.execute(
|
|
228
|
+
"id",
|
|
229
|
+
{ method: "batch", title: "Qs", questions: [
|
|
230
|
+
{ method: "input", title: "Paste the error" },
|
|
231
|
+
{ method: "confirm", title: "Proceed?" },
|
|
232
|
+
] },
|
|
233
|
+
undefined,
|
|
234
|
+
undefined,
|
|
235
|
+
ctx,
|
|
236
|
+
);
|
|
237
|
+
expect(batch).toHaveBeenCalledTimes(1);
|
|
238
|
+
// input entry carries the {value, attachments} object; confirm stays boolean.
|
|
239
|
+
expect(res.details.results[0]).toEqual({ value: "the error", attachments: [{ path: "/a/x.png", mimeType: "image/png", bytes: 9 }] });
|
|
240
|
+
expect(res.details.results[1]).toBe(true);
|
|
241
|
+
expect(res.content[0].text).toContain("x.png");
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
187
245
|
describe("prepareArguments", () => {
|
|
188
246
|
function getTool() {
|
|
189
247
|
const pi = createMockPi();
|
|
@@ -377,28 +435,30 @@ describe("registerAskUserTool", () => {
|
|
|
377
435
|
});
|
|
378
436
|
|
|
379
437
|
describe("batch execution", () => {
|
|
380
|
-
function getToolAndMockCtx() {
|
|
438
|
+
function getToolAndMockCtx(batchImpl?: any) {
|
|
381
439
|
const pi = createMockPi();
|
|
382
440
|
registerAskUserTool(pi as any);
|
|
383
441
|
const tool = pi.registerTool.mock.calls[0][0];
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
442
|
+
const batch =
|
|
443
|
+
batchImpl ??
|
|
444
|
+
vi.fn().mockResolvedValue([
|
|
445
|
+
{ value: "hello" },
|
|
446
|
+
{ value: "A" },
|
|
447
|
+
{ confirmed: true },
|
|
448
|
+
]);
|
|
390
449
|
const ctx = {
|
|
391
450
|
ui: {
|
|
392
451
|
confirm: vi.fn().mockResolvedValue(true),
|
|
393
452
|
select: vi.fn().mockResolvedValue("A"),
|
|
394
453
|
input: vi.fn().mockResolvedValue("hello"),
|
|
395
|
-
custom,
|
|
454
|
+
custom: vi.fn(),
|
|
455
|
+
batch,
|
|
396
456
|
},
|
|
397
457
|
};
|
|
398
458
|
return { tool, ctx };
|
|
399
459
|
}
|
|
400
460
|
|
|
401
|
-
it("
|
|
461
|
+
it("issues exactly ONE ctx.ui.batch request with all questions (no per-question dispatch)", async () => {
|
|
402
462
|
const { tool, ctx } = getToolAndMockCtx();
|
|
403
463
|
const result = await tool.execute(
|
|
404
464
|
"id",
|
|
@@ -415,37 +475,41 @@ describe("registerAskUserTool", () => {
|
|
|
415
475
|
undefined,
|
|
416
476
|
ctx,
|
|
417
477
|
);
|
|
418
|
-
expect(ctx.ui.
|
|
419
|
-
|
|
420
|
-
expect(ctx.ui.
|
|
478
|
+
expect(ctx.ui.batch).toHaveBeenCalledTimes(1);
|
|
479
|
+
// No per-question dispatch.
|
|
480
|
+
expect(ctx.ui.input).not.toHaveBeenCalled();
|
|
481
|
+
expect(ctx.ui.select).not.toHaveBeenCalled();
|
|
482
|
+
expect(ctx.ui.confirm).not.toHaveBeenCalled();
|
|
483
|
+
// questions[] passed through to the single request.
|
|
484
|
+
const passedQuestions = ctx.ui.batch.mock.calls[0][1];
|
|
485
|
+
expect(passedQuestions).toHaveLength(3);
|
|
486
|
+
expect(passedQuestions[1]).toMatchObject({ method: "select", options: ["TS", "Py"] });
|
|
487
|
+
// Answers mapped index-aligned to the legacy result shape.
|
|
421
488
|
expect(result.details.method).toBe("batch");
|
|
422
489
|
expect(result.details.results).toEqual(["hello", "A", true]);
|
|
423
490
|
expect(result.details.cancelled).toBe(false);
|
|
424
491
|
});
|
|
425
492
|
|
|
426
|
-
it("
|
|
427
|
-
const {
|
|
428
|
-
|
|
493
|
+
it("maps a multiselect sub-question answer to {values} → string[]", async () => {
|
|
494
|
+
const batch = vi.fn().mockResolvedValue([{ values: ["ESLint", "Vitest"] }]);
|
|
495
|
+
const { tool, ctx } = getToolAndMockCtx(batch);
|
|
496
|
+
const result = await tool.execute(
|
|
429
497
|
"id",
|
|
430
498
|
{
|
|
431
499
|
method: "batch",
|
|
432
500
|
title: "Setup",
|
|
433
|
-
questions: [{ method: "
|
|
501
|
+
questions: [{ method: "multiselect", title: "Tooling", options: ["ESLint", "Vitest", "Husky"] }],
|
|
434
502
|
},
|
|
435
503
|
undefined,
|
|
436
504
|
undefined,
|
|
437
505
|
ctx,
|
|
438
506
|
);
|
|
439
|
-
|
|
440
|
-
expect(firstCallTitle).toContain("Setup");
|
|
441
|
-
expect(firstCallTitle).toContain("Name?");
|
|
507
|
+
expect(result.details.results).toEqual([["ESLint", "Vitest"]]);
|
|
442
508
|
});
|
|
443
509
|
|
|
444
|
-
it("
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
ctx.ui.input.mockResolvedValueOnce("first");
|
|
448
|
-
ctx.ui.select.mockResolvedValueOnce(undefined); // cancel
|
|
510
|
+
it("returns a cancel summary with cancelled=true when ctx.ui.batch resolves undefined", async () => {
|
|
511
|
+
const batch = vi.fn().mockResolvedValue(undefined);
|
|
512
|
+
const { tool, ctx } = getToolAndMockCtx(batch);
|
|
449
513
|
const result = await tool.execute(
|
|
450
514
|
"id",
|
|
451
515
|
{
|
|
@@ -454,7 +518,6 @@ describe("registerAskUserTool", () => {
|
|
|
454
518
|
questions: [
|
|
455
519
|
{ method: "input", title: "Q1" },
|
|
456
520
|
{ method: "select", title: "Q2", options: ["a", "b"] },
|
|
457
|
-
{ method: "confirm", title: "Q3" },
|
|
458
521
|
],
|
|
459
522
|
},
|
|
460
523
|
undefined,
|
|
@@ -462,8 +525,8 @@ describe("registerAskUserTool", () => {
|
|
|
462
525
|
ctx,
|
|
463
526
|
);
|
|
464
527
|
expect(result.details.cancelled).toBe(true);
|
|
465
|
-
expect(result.details.results).toEqual([
|
|
466
|
-
expect(
|
|
528
|
+
expect(result.details.results).toEqual([]);
|
|
529
|
+
expect(result.content[0].text).toMatch(/cancelled batch/i);
|
|
467
530
|
});
|
|
468
531
|
|
|
469
532
|
it("surfaces __normalizations warnings in details.warnings", async () => {
|