paseo-dsh 0.2.18 → 0.2.19

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/index.client.tsx CHANGED
@@ -1,6 +1,15 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
2
  import { contributeStreamStats } from "./client/stream-stats";
3
+ import { contributeTimelineSettings } from "./client/settings-screen";
4
+ import { contributeTimeline } from "./client/timeline";
3
5
 
4
6
  export default function contribute(client: PluginClientContext) {
5
- return contributeStreamStats(client);
7
+ const cleanups = [
8
+ contributeStreamStats(client),
9
+ contributeTimeline(client),
10
+ contributeTimelineSettings(client),
11
+ ];
12
+ return () => {
13
+ for (const cleanup of cleanups) cleanup();
14
+ };
6
15
  }
package/index.server.ts CHANGED
@@ -1,4 +1,8 @@
1
+ import { readFile, stat } from "node:fs/promises";
2
+ import { extname, isAbsolute, resolve } from "node:path";
1
3
  import type { PluginServerContext } from "@getpaseo/plugin/server";
4
+ import { imagePreviewRpc } from "./shared/image-preview";
5
+ import { timelineStyleSettings } from "./shared/settings";
2
6
  import { ensurePaseoProfile } from "./server/bootstrap";
3
7
  import { createDshProvider } from "./server/provider";
4
8
 
@@ -11,6 +15,21 @@ import { createDshProvider } from "./server/provider";
11
15
  * a filesystem failure is logged and the provider still registers, so the
12
16
  * failure surfaces as an honest error when a session tries to start `dsh`.
13
17
  */
18
+ const MAX_IMAGE_BYTES = 12 * 1024 * 1024;
19
+ const HARD_MAX_IMAGE_BYTES = 64 * 1024 * 1024;
20
+
21
+ const IMAGE_MIME: Readonly<Record<string, string>> = {
22
+ ".png": "image/png",
23
+ ".jpg": "image/jpeg",
24
+ ".jpeg": "image/jpeg",
25
+ ".gif": "image/gif",
26
+ ".webp": "image/webp",
27
+ ".avif": "image/avif",
28
+ ".bmp": "image/bmp",
29
+ ".ico": "image/x-icon",
30
+ ".svg": "image/svg+xml",
31
+ };
32
+
14
33
  export default function contribute(server: PluginServerContext) {
15
34
  try {
16
35
  const provisioned = ensurePaseoProfile();
@@ -24,6 +43,44 @@ export default function contribute(server: PluginServerContext) {
24
43
  );
25
44
  }
26
45
 
46
+ server.registerSettings(timelineStyleSettings);
47
+ server.handle(imagePreviewRpc, async (input) => {
48
+ const empty = { dataUri: null, mime: null, error: null, bytes: null, limit: MAX_IMAGE_BYTES, tooLarge: false };
49
+ const absolute = isAbsolute(input.path) ? input.path : resolve(input.cwd || process.cwd(), input.path);
50
+ const mime = IMAGE_MIME[extname(absolute).toLowerCase()];
51
+ if (mime === undefined) {
52
+ return { ...empty, error: "不支持的图片格式" };
53
+ }
54
+ try {
55
+ const entry = await stat(absolute);
56
+ if (!entry.isFile()) return { ...empty, mime, error: "不是文件" };
57
+ if (entry.size > HARD_MAX_IMAGE_BYTES) {
58
+ return { ...empty, mime, bytes: entry.size, error: "图片超过 64MB 硬上限,无法预览" };
59
+ }
60
+ if (entry.size > MAX_IMAGE_BYTES && input.allowLarge !== true) {
61
+ return {
62
+ ...empty,
63
+ mime,
64
+ bytes: entry.size,
65
+ tooLarge: true,
66
+ error: `图片较大(${(entry.size / 1024 / 1024).toFixed(1)}MB,超过 12MB 预览上限)`,
67
+ };
68
+ }
69
+ const bytes = await readFile(absolute);
70
+ return {
71
+ ...empty,
72
+ dataUri: `data:${mime};base64,${bytes.toString("base64")}`,
73
+ mime,
74
+ bytes: bytes.byteLength,
75
+ };
76
+ } catch (error) {
77
+ return {
78
+ ...empty,
79
+ mime,
80
+ error: error instanceof Error ? error.message : String(error),
81
+ };
82
+ }
83
+ });
27
84
  server.registerProvider(createDshProvider());
28
85
  return () => {};
29
86
  }
package/lib/doctor.mjs CHANGED
@@ -15,6 +15,7 @@ import { existsSync, readFileSync } from "node:fs";
15
15
  import { homedir } from "node:os";
16
16
  import { dirname, join } from "node:path";
17
17
  import { fileURLToPath } from "node:url";
18
+ import { resolveDshCommand } from "../server/dsh-command.mjs";
18
19
 
19
20
  const HERE = dirname(fileURLToPath(import.meta.url));
20
21
 
@@ -41,6 +42,10 @@ function run(cmd, args) {
41
42
 
42
43
  function findPaseo() {
43
44
  // Prefer the app-bundled CLI: a `paseo` on PATH is often a stale npm install.
45
+ if (process.env.PASEO_CLI) {
46
+ const version = run(process.env.PASEO_CLI, ["--version"]);
47
+ if (version !== undefined) return { cmd: process.env.PASEO_CLI, version };
48
+ }
44
49
  const bundled = "/Applications/Paseo.app/Contents/Resources/bin/paseo";
45
50
  if (existsSync(bundled)) {
46
51
  const v = run(bundled, ["--version"]);
@@ -72,7 +77,8 @@ export function runDoctor() {
72
77
  process.stdout.write(`\n${DIM}paseo-dsh doctor (plugin ${pluginVersion})${RESET}\n\n`);
73
78
 
74
79
  // 1. CLIs
75
- const dshVersion = run("dsh", ["--version"]);
80
+ const dsh = resolveDshCommand(process.env.DSH_BINARY ?? "dsh");
81
+ const dshVersion = run(dsh.command, [...dsh.args, "--version"]);
76
82
  if (dshVersion === undefined) {
77
83
  report("fail", "dsh on PATH", "install the official DeepSeek Harness and put `dsh` on the daemon's PATH");
78
84
  } else {
@@ -88,7 +94,13 @@ export function runDoctor() {
88
94
 
89
95
  const paseo = findPaseo();
90
96
  if (paseo === undefined) {
91
- report("fail", "paseo CLI not found", "expected `paseo` on PATH or /Applications/Paseo.app");
97
+ report(
98
+ process.platform === "win32" ? "warn" : "fail",
99
+ "paseo CLI version not checked",
100
+ process.platform === "win32"
101
+ ? "the Windows desktop app can run without a PATH CLI; verify its version in the app (Paseo >= 0.9.2)"
102
+ : "expected `paseo` on PATH, PASEO_CLI, or /Applications/Paseo.app",
103
+ );
92
104
  } else if (Number(paseo.version.match(/\d+\.(\d+)/)?.[1] ?? 0) < 9) {
93
105
  report("warn", `paseo ${paseo.version}`, "needs Paseo >= 0.9.2 for the direct provider plugin API");
94
106
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-dsh",
3
- "version": "0.2.18",
3
+ "version": "0.2.19",
4
4
  "description": "DeepSeek Harness (dsh) as a native Paseo provider: question cards, plan mode, thinking levels, steering, images and a real slash menu. 把 DeepSeek Harness 接成 Paseo 原生 provider。",
5
5
  "keywords": [
6
6
  "paseo",
@@ -25,6 +25,7 @@
25
25
  "files": [
26
26
  "paseo-plugin.json",
27
27
  "index.server.ts",
28
+ "shared/",
28
29
  "server/",
29
30
  "lib/",
30
31
  "bin/",
@@ -32,13 +33,15 @@
32
33
  "README.md",
33
34
  "OVERVIEW.md",
34
35
  "LICENSE",
36
+ "THIRD-PARTY-NOTICES.md",
35
37
  "index.client.tsx",
36
38
  "client/"
37
39
  ],
38
40
  "scripts": {
39
41
  "generate": "node scripts/generate-bridge-assets.mjs",
40
42
  "prepack": "node scripts/generate-bridge-assets.mjs",
41
- "typecheck": "tsc --noEmit"
43
+ "typecheck": "tsc --noEmit",
44
+ "test:process": "node --test test/process.test.cjs"
42
45
  },
43
46
  "peerDependencies": {
44
47
  "@getpaseo/plugin": ">=0.9.2"
@@ -0,0 +1,7 @@
1
+ import type { ProcessEnv } from "node:process";
2
+
3
+ export function resolveDshCommand(
4
+ binary: string,
5
+ env?: ProcessEnv,
6
+ cwd?: string,
7
+ ): { command: string; args: string[] };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Resolve the official Windows npm launcher to its Node entrypoint.
3
+ * No command shell is inserted, so stdio, argv and child termination stay native.
4
+ */
5
+ import { existsSync, readFileSync } from "node:fs";
6
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
7
+
8
+ export function resolveDshCommand(binary, env = process.env, cwd = process.cwd()) {
9
+ const unchanged = { command: binary, args: [] };
10
+ if (process.platform !== "win32" || !/^dsh(?:\.cmd|\.ps1)?$/i.test(basename(binary))) return unchanged;
11
+
12
+ const explicit = /[/\\]/.test(binary);
13
+ // Node uses the first case-insensitive PATH key in lexicographic order.
14
+ const pathKey = Object.keys(env).sort().find(key => key.toLowerCase() === "path");
15
+ const directories = explicit
16
+ ? [dirname(resolve(cwd, binary))]
17
+ : (env[pathKey] ?? "").split(";").map(value => resolve(cwd, value.replace(/^"|"$/g, "")));
18
+
19
+ for (const directory of directories) {
20
+ // Preserve a native executable that would take precedence over an npm shim.
21
+ if (!explicit && (existsSync(join(directory, "dsh.exe")) || existsSync(join(directory, "dsh.com")))) return unchanged;
22
+ if (!existsSync(explicit ? resolve(cwd, binary) : join(directory, "dsh.cmd"))) continue;
23
+ const packageDir = join(directory, "node_modules", "@deepseek-ai", "dsh");
24
+ try {
25
+ const pkg = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8"));
26
+ const bin = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.dsh;
27
+ if (pkg.name !== "@deepseek-ai/dsh" || typeof bin !== "string") return unchanged;
28
+ const entry = resolve(packageDir, bin);
29
+ const local = relative(packageDir, entry);
30
+ if (isAbsolute(local) || local === ".." || local.startsWith(".." + sep) || !existsSync(entry)) return unchanged;
31
+ // Match npm's launcher: use node.exe beside the shim, otherwise Node on PATH.
32
+ const node = join(directory, "node.exe");
33
+ return { command: existsSync(node) ? node : "node.exe", args: [entry] };
34
+ } catch {
35
+ // Leave missing or unrecognized installations to the normal spawn error.
36
+ return unchanged;
37
+ }
38
+ }
39
+ return unchanged;
40
+ }
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
11
11
  import { existsSync } from "node:fs";
12
+ import { resolveDshCommand } from "./dsh-command.mjs";
12
13
 
13
14
  /** Provider/model/thinking route pinned for the life of one process. */
14
15
  export interface DshRoute {
@@ -158,14 +159,10 @@ export interface DshProcessOptions extends DshProcessHandlers {
158
159
  initializeRoute?: boolean;
159
160
  }
160
161
 
161
- const BINARY_CANDIDATES = [
162
- process.env.DSH_BINARY,
163
- "dsh",
164
- `${process.env.HOME ?? ""}/.local/bin/dsh`,
165
- ].filter((value): value is string => typeof value === "string" && value.length > 0);
166
-
167
- function resolveBinary(): string {
168
- for (const candidate of BINARY_CANDIDATES) {
162
+ function resolveBinary(env: NodeJS.ProcessEnv): string {
163
+ const candidates = [env.DSH_BINARY, "dsh", `${env.HOME ?? ""}/.local/bin/dsh`]
164
+ .filter((value): value is string => typeof value === "string" && value.length > 0);
165
+ for (const candidate of candidates) {
169
166
  if (candidate.includes("/") && existsSync(candidate)) return candidate;
170
167
  if (!candidate.includes("/")) return candidate;
171
168
  }
@@ -205,10 +202,12 @@ export class DshProcess {
205
202
  }
206
203
 
207
204
  async #start(): Promise<void> {
208
- const child = spawn(resolveBinary(), ["--profile", process.env.DSH_PASEO_PROFILE ?? "paseo"], {
205
+ const env = { ...process.env, ...this.#options.env };
206
+ const launch = resolveDshCommand(resolveBinary(env), env, this.#options.cwd);
207
+ const child = spawn(launch.command, [...launch.args, "--profile", env.DSH_PASEO_PROFILE ?? "paseo"], {
209
208
  cwd: this.#options.cwd,
210
209
  stdio: ["pipe", "pipe", "pipe"],
211
- env: { ...process.env, ...this.#options.env },
210
+ env,
212
211
  });
213
212
  this.#child = child;
214
213
 
@@ -69,6 +69,7 @@ function toolDetail(name: string, input: Record<string, unknown>, output?: strin
69
69
  };
70
70
  }
71
71
  case "read":
72
+ case "read_image":
72
73
  return {
73
74
  type: "read",
74
75
  filePath: filePath ?? "",
@@ -103,6 +104,7 @@ function toolDetail(name: string, input: Record<string, unknown>, output?: strin
103
104
  ...(output === undefined ? {} : { content: output }),
104
105
  };
105
106
  case "web_fetch":
107
+ case "webfetch":
106
108
  return {
107
109
  type: "fetch",
108
110
  url: stringField(input, "url") ?? "",
@@ -0,0 +1,28 @@
1
+ import { defineRpc } from "@getpaseo/plugin";
2
+ import { z } from "zod";
3
+
4
+ /**
5
+ * Reads an image file so the timeline can draw it. The bytes never travel
6
+ * through the provider timeline, so the daemon side loads the file and returns
7
+ * a data URI (or the reason it cannot be shown).
8
+ *
9
+ * Files above the soft limit are reported as `tooLarge` so the client can ask
10
+ * the reader before paying the base64/WebSocket cost; `allowLarge` bypasses it
11
+ * up to the daemon's hard ceiling.
12
+ */
13
+ export const imagePreviewRpc = defineRpc({
14
+ name: "file.image",
15
+ input: z.object({
16
+ cwd: z.string(),
17
+ path: z.string(),
18
+ allowLarge: z.boolean().optional(),
19
+ }),
20
+ output: z.object({
21
+ dataUri: z.string().nullable(),
22
+ mime: z.string().nullable(),
23
+ error: z.string().nullable(),
24
+ bytes: z.number().nullable(),
25
+ limit: z.number().nullable(),
26
+ tooLarge: z.boolean(),
27
+ }),
28
+ });
@@ -0,0 +1,93 @@
1
+ import { defineSettings } from "@getpaseo/plugin";
2
+ import { z } from "zod";
3
+
4
+ /**
5
+ * Host-scoped presentation knobs for the DSH timeline rows and the tool drawer.
6
+ *
7
+ * The timeline row's own margin stacks on top of the host item spacing (Paseo
8
+ * already puts 16px between timeline items), so negative values tighten the
9
+ * visible gap while positive values widen it.
10
+ */
11
+ export const timelineStyleSettings = defineSettings({
12
+ id: "timeline-style",
13
+ scope: "host",
14
+ version: 3,
15
+ migrate(values, fromVersion) {
16
+ if (!isRecord(values)) return values;
17
+ const { liveToolRowMarginY: _dropped, liveRowMarginY, ...rest } = values;
18
+ if (fromVersion < 2) {
19
+ rest["liveReasoningRowMarginY"] = typeof liveRowMarginY === "number" ? liveRowMarginY : 8;
20
+ }
21
+ return rest;
22
+ },
23
+ schema: z.object({
24
+ toolRowMarginY: z.number().min(-16).max(24).default(-8),
25
+ liveReasoningRowMarginY: z.number().min(-16).max(24).default(8),
26
+ toolRowPaddingY: z.number().min(0).max(12).default(0),
27
+ toolRowMinHeight: z.number().min(12).max(64).default(16),
28
+ toolRowGap: z.number().min(0).max(24).default(6),
29
+ commandMaxHeightRatio: z.number().min(0.1).max(0.6).default(0.25),
30
+ commandMinHeight: z.number().min(60).max(360).default(120),
31
+ }),
32
+ });
33
+
34
+ function isRecord(value: unknown): value is Record<string, unknown> {
35
+ return typeof value === "object" && value !== null && !Array.isArray(value);
36
+ }
37
+
38
+ export type TimelineStyleValues = z.output<typeof timelineStyleSettings.schema>;
39
+ export type TimelineStyleKey = keyof TimelineStyleValues;
40
+
41
+ export const TIMELINE_STYLE_DEFAULTS: TimelineStyleValues = {
42
+ toolRowMarginY: -8,
43
+ liveReasoningRowMarginY: 8,
44
+ toolRowPaddingY: 0,
45
+ toolRowMinHeight: 16,
46
+ toolRowGap: 6,
47
+ commandMaxHeightRatio: 0.25,
48
+ commandMinHeight: 120,
49
+ };
50
+
51
+ export interface TimelineStyleField {
52
+ key: TimelineStyleKey;
53
+ label: string;
54
+ hint: string;
55
+ }
56
+
57
+ export const TIMELINE_STYLE_FIELDS: readonly TimelineStyleField[] = [
58
+ {
59
+ key: "toolRowMarginY",
60
+ label: "工具之间的额外间距",
61
+ hint: "叠加在宿主固定 16px 之上,可填负数:8 → 约 24px,-8 → 约 8px,-16 → 约 0px。范围 -16 ~ 24。",
62
+ },
63
+ {
64
+ key: "liveReasoningRowMarginY",
65
+ label: "正在输出的思考行额外间距",
66
+ hint: "只作用于正在流式输出的思考行。默认 8,负值可能重叠。",
67
+ },
68
+ {
69
+ key: "toolRowPaddingY",
70
+ label: "工具行上下内边距(行内留白)",
71
+ hint: "只改行内留白,不改工具之间的距离;要缩小行间距请改上面的“工具之间的额外间距”。范围 0 ~ 12。",
72
+ },
73
+ {
74
+ key: "toolRowMinHeight",
75
+ label: "工具行最小高度",
76
+ hint: "整行至少多高;配合内边距 0 可压到接近图标高度(约 17px)。范围 12 ~ 64。",
77
+ },
78
+ {
79
+ key: "toolRowGap",
80
+ label: "图标与文字的水平间距",
81
+ hint: "图标、动词、目标之间。范围 0 ~ 24。",
82
+ },
83
+ {
84
+ key: "commandMaxHeightRatio",
85
+ label: "命令块最大高度(窗口占比)",
86
+ hint: "0.25 表示最多占窗口高度的四分之一;超过后命令块内部滚动,输出区始终保留。范围 0.1 ~ 0.6。",
87
+ },
88
+ {
89
+ key: "commandMinHeight",
90
+ label: "命令块最小高度上限",
91
+ hint: "窗口很小时仍给命令块保留的高度(像素)。范围 60 ~ 360。",
92
+ },
93
+ ];