gssh-agent 1.0.3 → 1.0.5

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.
@@ -0,0 +1,36 @@
1
+ package rpc
2
+
3
+ import (
4
+ "encoding/json"
5
+ "testing"
6
+
7
+ "gssh/internal/protocol"
8
+ )
9
+
10
+ func TestHandle_InvalidJSON(t *testing.T) {
11
+ handler := NewHandler(nil)
12
+
13
+ invalidJSON := []byte(`{invalid json`)
14
+
15
+ respBytes, err := handler.Handle(invalidJSON)
16
+ if err != nil {
17
+ t.Fatalf("Handle returned unexpected error: %v", err)
18
+ }
19
+
20
+ var resp protocol.Response
21
+ if err := json.Unmarshal(respBytes, &resp); err != nil {
22
+ t.Fatalf("Failed to unmarshal response: %v", err)
23
+ }
24
+
25
+ if resp.Error == nil {
26
+ t.Fatal("Expected error in response, got nil")
27
+ }
28
+
29
+ if resp.Error.Code != -32700 {
30
+ t.Errorf("Expected error code -32700, got %d", resp.Error.Code)
31
+ }
32
+
33
+ if resp.Error.Message != "Parse error" {
34
+ t.Errorf("Expected error message 'Parse error', got '%s'", resp.Error.Message)
35
+ }
36
+ }
package/plan.md ADDED
@@ -0,0 +1,4 @@
1
+ 1. **Create `pkg/rpc/handler_test.go`:** I will create a test file in the `pkg/rpc` directory.
2
+ 2. **Add test for invalid JSON:** I will add a test `TestHandle_InvalidJSON` that initializes a new `Handler` and calls `Handle` with an invalid JSON byte slice. It will assert that the returned error JSON structure matches the JSON-RPC error response for parse errors (`code: -32700`).
3
+ 3. **Run pre-commit steps:** Complete pre commit steps to ensure proper testing, verifications, reviews and reflections are done.
4
+ 4. **Submit change:** Once everything works and tests pass, I will submit the change.
package/skill.md CHANGED
@@ -4,13 +4,20 @@ description: "Manage SSH sessions with gssh CLI for agents"
4
4
  allowed-tools: Read, Write, Glob, Grep, Bash
5
5
  triggers:
6
6
  - gssh
7
- - ssh session
8
- - ssh 连接
9
- - ssh 管理
10
- - sftp
11
- - scp 文件传输
12
7
  ---
13
8
 
9
+ ## 安装
10
+
11
+ ```bash
12
+ npm install -g gssh-agent
13
+ ```
14
+
15
+ ## 启动
16
+
17
+ ```bash
18
+ gssh-daemon
19
+ ```
20
+
14
21
  ## 连接认证
15
22
 
16
23
  ```bash
@@ -27,9 +34,11 @@ gssh connect -u user -h host -i ~/.ssh/id_rsa
27
34
  |------|------|
28
35
  | `connect` | 建立 SSH 连接 |
29
36
  | `exec` | 执行命令 |
30
- | `scp` | 文件传输 |
37
+ | `scp` / `sync` | 文件传输与同步 |
31
38
  | `sftp` | SFTP 操作 |
32
39
  | `forward` | 端口转发 |
40
+ | `forwards`| 列出所有端口转发 |
41
+ | `forward-close`| 关闭端口转发 |
33
42
  | `list` | 列出 session |
34
43
  | `use` | 切换默认 session |
35
44
 
@@ -39,18 +48,29 @@ gssh connect -u user -h host -i ~/.ssh/id_rsa
39
48
  # 普通命令
40
49
  gssh exec "ls -la"
41
50
 
51
+ # 带超时命令
52
+ gssh exec -t 10 "ls -la"
53
+
42
54
  # sudo 命令
43
55
  gssh exec -S password "sudo systemctl restart nginx"
56
+
57
+ # 后台运行(推荐格式)
58
+ gssh exec "nohup python3 app.py > /dev/null 2>&1 &"
59
+ gssh exec "python3 app.py &"
60
+
61
+ 推荐使用 `nohup command > /dev/null 2>&1 &` 格式,可确保命令立即返回且不阻塞。
44
62
  ```
45
63
 
46
64
  ## 文件传输
47
65
 
48
66
  ```bash
49
- # 上传本地 -> 远程
67
+ # 上传本地文件/文件夹 -> 远程
50
68
  gssh scp -put local.txt /remote/path/
69
+ gssh sync -put local_dir /remote/path/
51
70
 
52
- # 下载远程 -> 本地
71
+ # 下载远程文件/文件夹 -> 本地
53
72
  gssh scp -get /remote/file.txt ./
73
+ gssh sync -get /remote/dir ./
54
74
 
55
75
  # SFTP 目录操作
56
76
  gssh sftp -c ls -p /home/user
@@ -66,6 +86,12 @@ gssh forward -l 8080 -r 80
66
86
 
67
87
  # 远程转发: remote:9000 -> localhost:3000
68
88
  gssh forward -R -l 9000 -r 3000
89
+
90
+ # 列出所有端口转发
91
+ gssh forwards
92
+
93
+ # 关闭端口转发
94
+ gssh forward-close <forward_id>
69
95
  ```
70
96
 
71
97
  ## Session 管理
package/bin/daemon DELETED
Binary file
package/bin/gssh-daemon DELETED
Binary file