Skip to content

Commit a24fe75

Browse files
authored
conn updates 4 (#1726)
1 parent 1ded7bd commit a24fe75

17 files changed

Lines changed: 330 additions & 208 deletions

File tree

cmd/wsh/cmd/wshcmd-ai.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ func aiRun(cmd *cobra.Command, args []string) (rtnErr error) {
142142
if message.Len() == 0 {
143143
return fmt.Errorf("message is empty")
144144
}
145-
if message.Len() > 10*1024 {
146-
return fmt.Errorf("current max message size is 10k")
145+
if message.Len() > 50*1024 {
146+
return fmt.Errorf("current max message size is 50k")
147147
}
148148

149149
messageData := wshrpc.AiMessageData{

cmd/wsh/cmd/wshcmd-rcfiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var rcfilesCmd = &cobra.Command{
1919
Run: func(cmd *cobra.Command, args []string) {
2020
err := wshutil.InstallRcFiles()
2121
if err != nil {
22-
WriteStderr(err.Error())
22+
WriteStderr("%s\n", err.Error())
2323
return
2424
}
2525
},

cmd/wsh/cmd/wshcmd-setbg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func setBgRun(cmd *cobra.Command, args []string) (rtnErr error) {
162162
if err != nil {
163163
return fmt.Errorf("error formatting metadata: %v", err)
164164
}
165-
WriteStdout(string(jsonBytes) + "\n")
165+
WriteStdout("%s\n", string(jsonBytes))
166166
return nil
167167
}
168168

frontend/app/view/preview/preview.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ import "./preview.scss";
3838
const MaxFileSize = 1024 * 1024 * 10; // 10MB
3939
const MaxCSVSize = 1024 * 1024 * 1; // 1MB
4040

41+
// TODO drive this using config
42+
const BOOKMARKS: { label: string; path: string }[] = [
43+
{ label: "Home", path: "~" },
44+
{ label: "Desktop", path: "~/Desktop" },
45+
{ label: "Downloads", path: "~/Downloads" },
46+
{ label: "Documents", path: "~/Documents" },
47+
{ label: "Root", path: "/" },
48+
];
49+
4150
type SpecializedViewProps = {
4251
model: PreviewModel;
4352
parentRef: React.RefObject<HTMLDivElement>;
@@ -185,27 +194,10 @@ export class PreviewModel implements ViewModel {
185194
elemtype: "iconbutton",
186195
icon: "folder-open",
187196
longClick: (e: React.MouseEvent<any>) => {
188-
const menuItems: ContextMenuItem[] = [];
189-
menuItems.push({
190-
label: "Go to Home",
191-
click: () => this.goHistory("~"),
192-
});
193-
menuItems.push({
194-
label: "Go to Desktop",
195-
click: () => this.goHistory("~/Desktop"),
196-
});
197-
menuItems.push({
198-
label: "Go to Downloads",
199-
click: () => this.goHistory("~/Downloads"),
200-
});
201-
menuItems.push({
202-
label: "Go to Documents",
203-
click: () => this.goHistory("~/Documents"),
204-
});
205-
menuItems.push({
206-
label: "Go to Root",
207-
click: () => this.goHistory("/"),
208-
});
197+
const menuItems: ContextMenuItem[] = BOOKMARKS.map((bookmark) => ({
198+
label: `Go to ${bookmark.label} (${bookmark.path})`,
199+
click: () => this.goHistory(bookmark.path),
200+
}));
209201
ContextMenuModel.showContextMenu(menuItems, e);
210202
},
211203
};

frontend/app/view/waveai/waveai.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ const ChatWindow = memo(
523523
const handleNewMessage = useCallback(
524524
throttle(100, (messagesLen: number) => {
525525
if (osRef.current?.osInstance()) {
526-
console.log("handleNewMessage", messagesLen, isUserScrolling.current);
527526
const { viewport } = osRef.current.osInstance().elements();
528527
if (prevMessagesLenRef.current !== messagesLen || !isUserScrolling.current) {
529528
viewport.scrollTo({

frontend/types/gotypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ declare global {
304304
"conn:askbeforewshinstall"?: boolean;
305305
"conn:overrideconfig"?: boolean;
306306
"conn:wshpath"?: string;
307+
"conn:shellpath"?: string;
307308
"display:hidden"?: boolean;
308309
"display:order"?: number;
309310
"term:*"?: boolean;

pkg/blockcontroller/blockcontroller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,18 +369,18 @@ func (bc *BlockController) setupAndStartShellProcess(rc *RunShellOpts, blockMeta
369369
cmdOpts.Env[wshutil.WaveJwtTokenVarName] = jwtStr
370370
}
371371
if !conn.WshEnabled.Load() {
372-
shellProc, err = shellexec.StartRemoteShellProcNoWsh(rc.TermSize, cmdStr, cmdOpts, conn)
372+
shellProc, err = shellexec.StartRemoteShellProcNoWsh(ctx, rc.TermSize, cmdStr, cmdOpts, conn)
373373
if err != nil {
374374
return nil, err
375375
}
376376
} else {
377-
shellProc, err = shellexec.StartRemoteShellProc(rc.TermSize, cmdStr, cmdOpts, conn)
377+
shellProc, err = shellexec.StartRemoteShellProc(ctx, rc.TermSize, cmdStr, cmdOpts, conn)
378378
if err != nil {
379379
conn.SetWshError(err)
380380
conn.WshEnabled.Store(false)
381381
log.Printf("error starting remote shell proc with wsh: %v", err)
382382
log.Print("attempting install without wsh")
383-
shellProc, err = shellexec.StartRemoteShellProcNoWsh(rc.TermSize, cmdStr, cmdOpts, conn)
383+
shellProc, err = shellexec.StartRemoteShellProcNoWsh(ctx, rc.TermSize, cmdStr, cmdOpts, conn)
384384
if err != nil {
385385
return nil, err
386386
}
@@ -408,7 +408,7 @@ func (bc *BlockController) setupAndStartShellProcess(rc *RunShellOpts, blockMeta
408408
if len(blockMeta.GetStringList(waveobj.MetaKey_TermLocalShellOpts)) > 0 {
409409
cmdOpts.ShellOpts = append([]string{}, blockMeta.GetStringList(waveobj.MetaKey_TermLocalShellOpts)...)
410410
}
411-
shellProc, err = shellexec.StartShellProc(rc.TermSize, cmdStr, cmdOpts)
411+
shellProc, err = shellexec.StartLocalShellProc(rc.TermSize, cmdStr, cmdOpts)
412412
if err != nil {
413413
return nil, err
414414
}

pkg/genconn/quote.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ package genconn
66
import "regexp"
77

88
var (
9-
safePattern = regexp.MustCompile(`^[a-zA-Z0-9_/.-]+$`)
10-
11-
needsEscape = map[byte]bool{
12-
'"': true,
13-
'\\': true,
14-
'$': true,
15-
'`': true,
16-
}
9+
safePattern = regexp.MustCompile(`^[a-zA-Z0-9_/.-]+$`)
10+
psSafePattern = regexp.MustCompile(`^[a-zA-Z0-9_.-]+$`)
1711
)
1812

13+
// TODO: fish quoting is slightly different
14+
// specifically \` will cause an inconsistency between fish and bash/zsh :/
15+
// might need a specific fish quoting function, and an explicit fish shell detection
1916
func HardQuote(s string) string {
2017
if s == "" {
2118
return "\"\""
@@ -29,10 +26,42 @@ func HardQuote(s string) string {
2926
buf = append(buf, '"')
3027

3128
for i := 0; i < len(s); i++ {
32-
if needsEscape[s[i]] {
33-
buf = append(buf, '\\')
29+
switch s[i] {
30+
case '"', '\\', '$', '`':
31+
buf = append(buf, '\\', s[i])
32+
case '\n':
33+
buf = append(buf, '\\', '\n')
34+
default:
35+
buf = append(buf, s[i])
3436
}
35-
buf = append(buf, s[i])
37+
}
38+
39+
buf = append(buf, '"')
40+
return string(buf)
41+
}
42+
43+
func HardQuotePowerShell(s string) string {
44+
if s == "" {
45+
return "\"\""
46+
}
47+
48+
if psSafePattern.MatchString(s) {
49+
return s
50+
}
51+
52+
buf := make([]byte, 0, len(s)+5)
53+
buf = append(buf, '"')
54+
55+
for i := 0; i < len(s); i++ {
56+
c := s[i]
57+
// In PowerShell, backtick (`) is the escape character
58+
switch c {
59+
case '"', '`', '$':
60+
buf = append(buf, '`')
61+
case '\n':
62+
buf = append(buf, '`', 'n') // PowerShell uses `n for newline
63+
}
64+
buf = append(buf, c)
3665
}
3766

3867
buf = append(buf, '"')

pkg/genconn/ssh-impl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package genconn
66
import (
77
"fmt"
88
"io"
9+
"log"
910
"sync"
1011

1112
"golang.org/x/crypto/ssh"
@@ -41,6 +42,7 @@ type SSHProcessController struct {
4142

4243
// MakeSSHCmdClient creates a new instance of SSHCmdClient
4344
func MakeSSHCmdClient(client *ssh.Client, cmdSpec CommandSpec) (*SSHProcessController, error) {
45+
log.Printf("SSH-NEWSESSION (cmdclient)\n")
4446
session, err := client.NewSession()
4547
if err != nil {
4648
return nil, fmt.Errorf("failed to create SSH session: %w", err)

0 commit comments

Comments
 (0)