@linxin666/dsh-ssh 0.4.22 → 0.4.23

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.
@@ -82,6 +82,8 @@ export async function startTunnel(
82
82
  const onLinkClosed = (): void => { abortTunnel(engine, id) }
83
83
  const detachLink = (): void => { client.off('close', onLinkClosed) }
84
84
  const server = createServer((socket) => {
85
+ // Install this before requesting the SSH channel so early errors stay local.
86
+ socket.on('error', () => { destroyQuietly(socket) })
85
87
  sockets.add(socket)
86
88
  socket.on('close', () => { sockets.delete(socket) })
87
89
  // The link can die between taking the record above and this connection.
@@ -103,14 +105,13 @@ export async function startTunnel(
103
105
  destroyQuietly(stream)
104
106
  return
105
107
  }
106
- // Both ends of the pipe can die independently; destroy the pair so an
107
- // unhandled 'error' event can never crash the host process.
108
+ // Either close or a channel error tears down the pair. A socket error
109
+ // destroys the socket and triggers the same cleanup through close.
108
110
  const destroy = (): void => {
109
111
  destroyQuietly(socket)
110
112
  try { stream.close() } catch { /* gone */ }
111
113
  }
112
114
  stream.on('error', destroy)
113
- socket.on('error', destroy)
114
115
  stream.on('close', destroy)
115
116
  socket.on('close', destroy)
116
117
  stream.pipe(socket).pipe(stream)
package/src/routes.ts CHANGED
@@ -10,14 +10,11 @@
10
10
  import { closeSync, createReadStream, createWriteStream, mkdirSync, openSync } from 'node:fs'
11
11
  import { unlink } from 'node:fs/promises'
12
12
  import type { IncomingMessage, ServerResponse } from 'node:http'
13
- import { basename, join } from 'node:path'
13
+ import { join, posix } from 'node:path'
14
14
  import { tmpdir } from 'node:os'
15
15
  import { randomBytes } from 'node:crypto'
16
16
  import { WebSocketServer } from 'ws'
17
17
  import type { WebRoute, WebUpgradeRoute } from '@deepseek-ai/dsh-host-webserver'
18
-
19
- type AuthAwareWebRoute = WebRoute & { readonly auth: 'anonymous' }
20
- type AuthAwareWebUpgradeRoute = WebUpgradeRoute & { readonly auth: 'anonymous' }
21
18
  import type { SshEngine } from './engine.ts'
22
19
  import { hasClusterSelector } from './engine/cluster.ts'
23
20
  import { TerminalSessionRegistry } from './engine/terminal-sessions.ts'
@@ -502,7 +499,7 @@ const maxUploadBytes = deps.maxUploadBytes ?? MAX_UPLOAD_BYTES
502
499
  res.writeHead(200, {
503
500
  'content-type': 'application/octet-stream',
504
501
  'content-length': String(outcome.bytes),
505
- 'content-disposition': `attachment; filename="${safeAttachmentFilename(basename(remotePath))}"`,
502
+ 'content-disposition': `attachment; filename="${safeAttachmentFilename(posix.basename(remotePath))}"`,
506
503
  'referrer-policy': 'no-referrer',
507
504
  })
508
505
  await new Promise<void>((resolve, reject) => {
@@ -597,8 +594,8 @@ const maxUploadBytes = deps.maxUploadBytes ?? MAX_UPLOAD_BYTES
597
594
  }
598
595
 
599
596
  return {
600
- routes: routes.map((route): AuthAwareWebRoute => ({ ...route, auth: 'anonymous' })),
601
- upgrade: { ...upgrade, auth: 'anonymous' } as AuthAwareWebUpgradeRoute,
597
+ routes: routes.map((route): WebRoute => ({ ...route, auth: 'anonymous' })),
598
+ upgrade: { ...upgrade, auth: 'anonymous' },
602
599
  terminalSessions,
603
600
  }
604
601
  }
@@ -63,11 +63,15 @@ export interface SectionScopeContext {
63
63
  }
64
64
 
65
65
  /**
66
- * Build a section provider that renders \`text\` only while at least one of
67
- * \`toolNames\` is visible to the rendering scope.
66
+ * Build a section provider that renders `text` only while at least one of
67
+ * `toolNames` is visible to the rendering scope.
68
68
  *
69
69
  * The native convention: a tool that a restriction, a preset, or a missing
70
70
  * registry removed must not leave guidance behind telling the model to call it.
71
+ * Under a 0.2.3-alpha.3+ PTC root registry (`PtcToolRegistry`), `tools.get(name,
72
+ * scope)` exposes only the `run_code` transport while binding registered tools
73
+ * inside programs; when `run_code` is active in the rendering scope, fall back
74
+ * to checking the unscoped registry so guidance does not vanish under PTC.
71
75
  * An unreadable registry renders the text unchanged — guidance that outlives a
72
76
  * momentary read failure is recoverable; guidance for a tool that is gone is
73
77
  * not.
@@ -91,6 +95,17 @@ export function visibleToolText(
91
95
  return text
92
96
  }
93
97
  }
98
+ if (context.scope !== undefined && toolNames.length > 0) {
99
+ try {
100
+ if (tools.get('run_code', context.scope) !== undefined) {
101
+ for (const name of toolNames) {
102
+ if (tools.get(name) !== undefined) return text
103
+ }
104
+ }
105
+ } catch {
106
+ return text
107
+ }
108
+ }
94
109
  return ''
95
110
  }
96
111
  }
package/src/tools.ts CHANGED
@@ -96,6 +96,7 @@ function renderTunnel(tunnel: TunnelInfo): string {
96
96
  export function sshListTool(engine: SshEngine) {
97
97
  return defineTool({
98
98
  name: 'ssh_list',
99
+ environment: 'independent',
99
100
  description: 'List configured SSH hosts (alias, host, user, auth, agent forwarding, environment, tags, description). Use ssh_exec etc. with the alias.',
100
101
  parameters: {
101
102
  query: { type: 'string', description: 'Optional fuzzy match against alias, description, host, and tags.' },
@@ -146,6 +147,7 @@ export function sshListTool(engine: SshEngine) {
146
147
  export function sshExecTool(engine: SshEngine) {
147
148
  return defineTool({
148
149
  name: 'ssh_exec',
150
+ environment: 'explicit',
149
151
  description: 'Execute a shell command on a REMOTE SSH host by alias; the command runs on the remote host, never on this machine. For commands on this machine, use the local bash tool. Prefer combining independent read-only queries into one command.',
150
152
  parameters: {
151
153
  alias: { type: 'string', required: true, description: 'Host alias from ssh_list.' },
@@ -362,6 +364,7 @@ export function sshTunnelTool(engine: SshEngine) {
362
364
  export function sshClusterTool(engine: SshEngine) {
363
365
  return defineTool({
364
366
  name: 'ssh_cluster',
367
+ environment: 'explicit',
365
368
  description: 'Run one command concurrently across selected SSH hosts; at least one aliases, environment, or tags filter is required.',
366
369
  parameters: {
367
370
  command: { type: 'string', required: true, description: 'The shell command to run on every matched host.' },