8000 coder ssh strategy finally working · coder/vscode-coder@be1e137 · GitHub
[go: up one dir, main page]

Skip to content

Commit be1e137

Browse files
committed
coder ssh strategy finally working
1 parent 063b27e commit be1e137

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@
211211
"when": "coder.authenticated"
212212
},
213213
{
214-
"command": "coder.openAITask",
215-
"title": "Coder: Open AI Task",
214+
"command": "coder.openAppStatus",
215+
"title": "Coder: Open App Status",
216216
"icon": "$(robot)",
217217
"when": "coder.authenticated"
218218
}
@@ -244,7 +244,7 @@
244244
"group": "navigation"
245245
},
246246
{
247-
"command": "coder.openAITask",
247+
"command": "coder.openAppStatus",
248248
"when": "coder.authenticated && view == myWorkspaces",
249249
"group": "navigation"
250250
}
@@ -280,11 +280,6 @@
280280
"command": "coder.createWorkspace",
281281
"group": "remote_11_ssh_coder@2",
282282
"when": "coder.authenticated"
283-
},
284-
{
285-
"command": "coder.openAITask",
286-
"group": "remote_11_ssh_coder@3",
287-
"when": "coder.authenticated"
288283
}
289284
]
290285
}

src/commands.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,32 @@ export class Commands {
412412
status?: string
413413
url?: string
414414
agent_name?: string
415+
command?: string
416+
workspace_name?: string
415417
}): Promise<void> {
418+
// Launch and run command in terminal if command is provided
419+
if (app.command) {
420+
const terminal = vscode.window.createTerminal(`${app.name || "Application"} Status`)
421+
terminal.show(false)
422+
vscode.commands.executeCommand("workbench.action.toggleMaximizedPanel")
423+
// If workspace_name is provided, run coder ssh before the command
424+
if (app.workspace_name) {
425+
terminal.sendText(`coder ssh ${app.workspace_name}`)
426+
// Sleep for 5 seconds
427+
await new Promise((resolve) => setTimeout(resolve, 5000))
428+
terminal.sendText(app.command)
429+
} else {
430+
terminal.sendText("need workspace name")
431+
}
432+
return
433+
}
416434
// Check if app has a URL to open
417435
if (app.url) {
418436
await vscode.env.openExternal(vscode.Uri.parse(app.url))
419437
return
420438
}
421439

422-
// If no URL, show information about the app status
440+
// If no URL or command, show information about the app status
423441
vscode.window.showInformationMessage(`${app.name || "Application"}: ${app.status || "Running"}`, {
424442
detail: `Agent: ${app.agent_name || "Unknown"}`,
425443
})

src/workspacesProvider.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ export class WorkspaceProvider implements vscode.TreeDataProvider<vscode.TreeIte
168168
url: app.url,
169169
agent_id: agent.id,
170170
agent_name: agent.name,
171+
command: app.command,
172+
workspace_name: workspace.name,
171173
}))
172174
}
173175
})
@@ -253,21 +255,25 @@ export class WorkspaceProvider implements vscode.TreeDataProvider<vscode.TreeIte
253255

254256
// Add app status section with collapsible header
255257
if (element.agent.apps && element.agent.apps.length > 0) {
256-
let needsAttention = []
258+
const needsAttention = []
257259
for (const app of element.agent.apps) {
258260
if (app.statuses && app.statuses.length > 0) {
259261
for (const status of app.statuses) {
260262
if (status.needs_user_attention) {
261-
needsAttention.push(new AppStatusTreeItem(status))
263+
needsAttention.push(
264+
new AppStatusTreeItem({
265+
name: status.message,
266+
command: app.command,
267+
status: status.state,
268+
workspace_name: element.workspaceName,
269+
}),
270+
)
262271
}
263272
}
264273
}
265274
}
266275

267-
const appStatusSection = new SectionTreeItem(
268-
"Applications in need of attention",
269-
needsAttention,
270-
)
276+
const appStatusSection = new SectionTreeItem("Applications in need of attention", needsAttention)
271277
items.push(appStatusSection)
272278
}
273279

@@ -372,17 +378,15 @@ class AgentMetadataTreeItem extends vscode.TreeItem {
372378
class AppStatusTreeItem extends vscode.TreeItem {
373379
constructor(
374380
public readonly app: {
375-
name?: string
376-
display_name?: string
381+
name: string
377382
status?: string
378-
icon?: string
379383
url?: string
380-
agent_id?: string
381-
agent_name?: string
384+
command?: string
385+
workspace_name?: string
382386
},
383387
) {
384-
super(app.icon || "$(pulse)", vscode.TreeItemCollapsibleState.None)
385-
this.description = app.status || "Running"
388+
super(app.name, vscode.TreeItemCollapsibleState.None)
389+
this.description = app.status
386390
this.contextValue = "coderAppStatus"
387391

388392
// Add command to handle clicking on the app
@@ -449,7 +453,16 @@ class AgentTreeItem extends OpenableTreeItem {
449453
}
450454

451455
export class WorkspaceTreeItem extends OpenableTreeItem {
452-
public appStatus: { name: string; status: string; icon?: string }[] = []
456+
public appStatus: {
457+
name: string
458+
status: string
459+
icon?: string
460+
url?: string
461+
agent_id?: string
462+
agent_name?: string
463+
command?: string
464+
workspace_name?: string
465+
}[] = []
453466

454467
constructor(
455468
public readonly workspace: Workspace,

0 commit comments

Comments
 (0)
0