@linxin666/dsh-ssh 0.4.7 → 0.4.9

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/src/routes.ts CHANGED
@@ -130,8 +130,11 @@ const maxUploadBytes = deps.maxUploadBytes ?? MAX_UPLOAD_BYTES
130
130
  // Connection-relevant changes invalidate the pooled connection:
131
131
  // without this the pool would keep running commands on the old
132
132
  // host/credentials until the idle sweep (up to 30 min later).
133
+ // Agent forwarding belongs here too: it is fixed per connection
134
+ // (ssh2 negotiates it when the channel opens), so toggling it must
135
+ // reconnect or the new setting silently never takes effect.
133
136
  const patch = body as Record<string, unknown>
134
- if (['host', 'port', 'user', 'auth', 'proxyJump', 'proxyCommand'].some(key => patch[key] !== undefined)) {
137
+ if (['host', 'port', 'user', 'auth', 'proxyJump', 'proxyCommand', 'forwardAgent'].some(key => patch[key] !== undefined)) {
135
138
  engine.dropAlias(alias)
136
139
  }
137
140
  writeJson(res, 200, { host: store.summarize(entry) })
package/src/store.ts CHANGED
@@ -72,6 +72,9 @@ export function validateHostPayload(payload: unknown): string | undefined {
72
72
  if (p.tags !== undefined && (!Array.isArray(p.tags) || p.tags.some(x => typeof x !== 'string'))) {
73
73
  return 'tags must be an array of strings'
74
74
  }
75
+ if (p.forwardAgent !== undefined && typeof p.forwardAgent !== 'boolean') {
76
+ return 'forwardAgent must be a boolean'
77
+ }
75
78
  return undefined
76
79
  }
77
80
 
@@ -136,6 +139,9 @@ export class HostStore {
136
139
  ...(entry.environment !== undefined ? { environment: entry.environment } : {}),
137
140
  tags: [...entry.tags],
138
141
  ...(entry.location !== undefined ? { location: entry.location } : {}),
142
+ // Always a definite boolean, unlike the conditional optional fields:
143
+ // the tool bridge rejects undefined-valued JSON properties.
144
+ forwardAgent: entry.forwardAgent === true,
139
145
  createdAt: entry.createdAt,
140
146
  updatedAt: entry.updatedAt,
141
147
  }
@@ -171,6 +177,9 @@ export class HostStore {
171
177
  environment: payload.environment?.trim() || undefined,
172
178
  tags: [...(payload.tags ?? [])].map(tag => tag.trim()).filter(tag => tag !== ''),
173
179
  location: payload.location?.trim() || undefined,
180
+ // Stored only when enabled, so a store file written without agent
181
+ // forwarding stays byte-identical to the pre-feature format.
182
+ forwardAgent: payload.forwardAgent === true ? true : undefined,
174
183
  createdAt: now,
175
184
  updatedAt: now,
176
185
  }
@@ -201,6 +210,9 @@ export class HostStore {
201
210
  if (patch.proxyCommand !== undefined && typeof patch.proxyCommand !== 'string') {
202
211
  throw new Error('proxyCommand must be a string when provided')
203
212
  }
213
+ if (patch.forwardAgent !== undefined && typeof patch.forwardAgent !== 'boolean') {
214
+ throw new Error('forwardAgent must be a boolean')
215
+ }
204
216
  // The mutual exclusion is checked on the MERGED view: a patch that only
205
217
  // adds one transport must not slip past a stored value of the other.
206
218
  const mergedProxyCommand = patch.proxyCommand !== undefined
@@ -250,6 +262,8 @@ export class HostStore {
250
262
  if (patch.environment !== undefined) entry.environment = patch.environment.trim() || undefined
251
263
  if (patch.tags !== undefined) entry.tags = [...patch.tags].map(tag => tag.trim()).filter(tag => tag !== '')
252
264
  if (patch.location !== undefined) entry.location = patch.location.trim() || undefined
265
+ // PATCH semantics: an omitted key keeps the stored value, false clears it.
266
+ if (patch.forwardAgent !== undefined) entry.forwardAgent = patch.forwardAgent === true ? true : undefined
253
267
  entry.updatedAt = Date.now()
254
268
  this.save(file)
255
269
  return entry
@@ -326,6 +340,7 @@ export class HostStore {
326
340
  environment: block.props.environment,
327
341
  tags: (block.props.tags ?? '').split(',').map(tag => tag.trim()).filter(tag => tag !== ''),
328
342
  location: block.props.location,
343
+ forwardAgent: parseForwardAgentValue(block.props.forwardagent),
329
344
  }
330
345
  try {
331
346
  this.create(payload)
@@ -411,6 +426,17 @@ export function normalizeProxyCommand(raw: string | undefined): string | undefin
411
426
  return trimmed
412
427
  }
413
428
 
429
+ /**
430
+ * Read an ssh_config `ForwardAgent` value into the stored boolean flag. Only
431
+ * an explicit yes/true/on enables forwarding; an absent value, no/false/off,
432
+ * and anything unrecognized leave it off instead of failing the import — an
433
+ * unknown keyword must never cost the user the whole Host block.
434
+ */
435
+ export function parseForwardAgentValue(raw: string | undefined): boolean {
436
+ const value = raw?.trim().toLowerCase()
437
+ return value === 'yes' || value === 'true' || value === 'on'
438
+ }
439
+
414
440
  /** Expand a leading `~` in a filesystem path. */
415
441
  export function expandHome(path: string): string {
416
442
  if (path === '~') return homedir()
@@ -32,6 +32,7 @@
32
32
  export const PLUGIN_TOOL_SECTION_ORDERS = {
33
33
  ssh: 150,
34
34
  'task-board': 200,
35
+ agents: 220,
35
36
  } as const
36
37
 
37
38
  /** One plugin id keyed by {@link PLUGIN_TOOL_SECTION_ORDERS}. */
package/src/tools.ts CHANGED
@@ -28,6 +28,7 @@ export interface AgentHostRow {
28
28
  keyReady: boolean
29
29
  proxyJump: string[]
30
30
  proxyCommandConfigured: boolean
31
+ forwardAgent: boolean
31
32
  description?: string
32
33
  environment?: string
33
34
  tags: string[]
@@ -52,11 +53,14 @@ function renderHosts(hosts: AgentHostRow[]): string {
52
53
  host.user,
53
54
  host.auth,
54
55
  host.proxyJump.length > 0 ? 'jump:' + host.proxyJump.join(',') : host.proxyCommandConfigured ? 'proxy-command' : '-',
56
+ // Forwarding is a security-relevant opt-in (the remote can sign with this
57
+ // machine's agent), so the model must see it in the table, not only in JSON.
58
+ host.forwardAgent ? 'yes' : '-',
55
59
  host.environment ?? '-',
56
60
  (host.tags.length > 0 ? host.tags.join(',') : '-'),
57
61
  host.description ?? '',
58
62
  ].join(' | '))
59
- return ['alias | host | port | user | auth | proxy | environment | tags | description', '--- | --- | --- | --- | --- | --- | --- | --- | ---', ...rows].join('\n')
63
+ return ['alias | host | port | user | auth | proxy | forward | environment | tags | description', '--- | --- | --- | --- | --- | --- | --- | --- | --- | ---', ...rows].join('\n')
60
64
  }
61
65
 
62
66
  /** Render one exec result (mirrors the bash-tool exit-code convention). */
@@ -91,7 +95,7 @@ function renderTunnel(tunnel: TunnelInfo): string {
91
95
  export function sshListTool(engine: SshEngine) {
92
96
  return defineTool({
93
97
  name: 'ssh_list',
94
- description: 'List configured SSH hosts (alias, host, user, auth, environment, tags, description). Use ssh_exec etc. with the alias.',
98
+ description: 'List configured SSH hosts (alias, host, user, auth, agent forwarding, environment, tags, description). Use ssh_exec etc. with the alias.',
95
99
  parameters: {
96
100
  query: { type: 'string', description: 'Optional fuzzy match against alias, description, host, and tags.' },
97
101
  },
@@ -115,6 +119,7 @@ export function sshListTool(engine: SshEngine) {
115
119
  keyReady: { type: 'boolean', required: true },
116
120
  proxyJump: { type: 'array', items: { type: 'string' }, required: true },
117
121
  proxyCommandConfigured: { type: 'boolean', required: true },
122
+ forwardAgent: { type: 'boolean', required: true },
118
123
  description: { type: 'string' },
119
124
  environment: { type: 'string' },
120
125
  tags: { type: 'array', items: { type: 'string' }, required: true },
@@ -144,7 +149,7 @@ export function sshExecTool(engine: SshEngine) {
144
149
  parameters: {
145
150
  alias: { type: 'string', required: true, description: 'Host alias from ssh_list.' },
146
151
  command: { type: 'string', required: true, description: 'The shell command to run remotely.' },
147
- timeoutMs: { type: 'integer', description: 'Timeout in milliseconds (default 60000).' },
152
+ timeoutMs: { type: 'integer', description: 'Remote command execution timeout in milliseconds (default 60000); it starts after the connection is ready. The connection and authentication ceiling is the dsh-ssh connectTimeoutMs setting, not this argument.' },
148
153
  },
149
154
  output: {
150
155
  schema: {
@@ -362,7 +367,7 @@ export function sshClusterTool(engine: SshEngine) {
362
367
  aliases: { type: 'array', items: { type: 'string' }, description: 'Optional alias filter; at least one of aliases, environment, or tags is required.' },
363
368
  environment: { type: 'string', description: 'Optional environment filter; at least one selector is required.' },
364
369
  tags: { type: 'array', items: { type: 'string' }, description: 'Optional ALL-tags filter; at least one selector is required.' },
365
- timeoutMs: { type: 'integer', description: 'Per-host timeout in milliseconds.' },
370
+ timeoutMs: { type: 'integer', description: 'Per-host command execution timeout in milliseconds (default 60000); it does not extend the connection and authentication ceiling (the dsh-ssh connectTimeoutMs setting).' },
366
371
  maxWorkers: { type: 'integer', description: 'Concurrency cap (default 8).' },
367
372
  },
368
373
  output: {