Skip to content

Commit

Permalink
Update version number, add changelog (#759)
Browse files Browse the repository at this point in the history
* Update version number, add changelog

* Suppress terminal window on windows

Prior to this change, launching the viewer on Windows would result in a visible terminal window and a failure to communicate with it.

* add context menu commands to log tree

* don't print log_images

---------

Co-authored-by: aisi-inspect <[email protected]>
Co-authored-by: jjallaire-aisi <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent a428520 commit 3d53ebf
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/inspect_ai/_display/rich.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def task_config(profile: TaskProfile, generate_config: bool = True) -> str:
config_print.append(
f"{name}: {','.join([approver['name'] for approver in value['approvers']])}"
)
elif name not in ["limit", "model"]:
elif name not in ["limit", "model", "log_images"]:
config_print.append(f"{name}: {value}")
values = ", ".join(config_print)
if values:
Expand Down
15 changes: 15 additions & 0 deletions src/inspect_ai/_view/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ async def api_log_size(request: web.Request) -> web.Response:

return await log_size_response(file)

@routes.get("/api/log-delete/{log}")
async def api_log_delete(request: web.Request) -> web.Response:
# log file requested
file = request.match_info["log"]
file = urllib.parse.unquote(file)
validate_log_file_request(file)

return await log_delete_response(file)

@routes.get("/api/log-bytes/{log}")
async def api_log_bytes(request: web.Request) -> web.Response:
# log file requested
Expand Down Expand Up @@ -208,6 +217,12 @@ async def log_size_response(log_file: str) -> web.Response:
return web.json_response(info.size)


async def log_delete_response(log_file: str) -> web.Response:
fs = filesystem(log_file)
fs.rm(log_file)
return web.json_response(True)


async def log_bytes_response(log_file: str, start: int, end: int) -> web.Response:
# build headers
content_length = end - start + 1
Expand Down
9 changes: 9 additions & 0 deletions tools/vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.3.37

This version includes a signficant rework of the overall workflow for interacting with Inspect. You can view the most up to date documentation on using the VS Code extension [here](https://inspect.ai-safety-institute.org.uk/vscode.html). Changes include:

- The Inspect sidebar now includes a section which allows you to browse and open log files in the viewer.
- The Inspect Viewer is no longer opened automatically when an evaluation is completed. Instead a notification is available to open the viewer.
- New open log directory command allows you to select a log directory and open the Inspect Viewer for that directory
- Support for the new Inspect `eval` log format. More information [here](https://inspect.ai-safety-institute.org.uk/eval-logs.html#sec-log-format).

## 0.3.36

- Show Inspect version in status bar
Expand Down
32 changes: 31 additions & 1 deletion tools/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": {
"name": "UK AI Safety Institute"
},
"version": "0.3.36",
"version": "0.3.37",
"license": "MIT",
"homepage": "https://inspect.ai-safety-institute.org.uk/",
"repository": {
Expand Down Expand Up @@ -125,6 +125,21 @@
"category": "Inspect",
"enablement": "workspaceFolderCount != 0"
},
{
"command": "inspect.logListingRevealInExplorer",
"title": "Reveal in Explorer",
"enablement": "workspaceFolderCount != 0"
},
{
"command": "inspect.logListingOpenInJSONEditor",
"title": "Open in JSON Editor",
"enablement": "workspaceFolderCount != 0"
},
{
"command": "inspect.logListingDeleteLogFile",
"title": "Delete Log File...",
"enablement": "workspaceFolderCount != 0"
},
{
"command": "inspect.logListingReveal",
"title": "Reveal Log Listing",
Expand Down Expand Up @@ -326,6 +341,21 @@
"command": "inspect.runSelectedTask",
"group": "inline",
"when": "view == inspect_ai.task-outline-view && viewItem == runnable"
},
{
"command": "inspect.logListingRevealInExplorer",
"group": "navigation",
"when": "view == inspect_ai.logs-view && viewItem =~ /file\\+local/"
},
{
"command": "inspect.logListingOpenInJSONEditor",
"group": "navigation@100",
"when": "view == inspect_ai.logs-view && viewItem =~ /file\\+local\\+json/"
},
{
"command": "inspect.logListingDeleteLogFile",
"group": "1_modification",
"when": "view == inspect_ai.logs-view && inspect_ai.haveEvalLogFormat && viewItem =~ /file/"
}
],
"commandPalette": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function activateActivityBar(
const [outlineCommands, treeDataProvider] = await activateTaskOutline(context, inspectEvalMgr, workspaceTaskMgr, activeTaskManager, inspectManager, inspectLogviewManager);
context.subscriptions.push(treeDataProvider);

const [logsCommands, logsDispose] = activateLogListing(context, workspaceEnvMgr, inspectViewServer, logsWatcher);
const [logsCommands, logsDispose] = await activateLogListing(context, workspaceEnvMgr, inspectViewServer, logsWatcher);
context.subscriptions.push(...logsDispose);

const envProvider = new EnvConfigurationProvider(context.extensionUri, workspaceEnvMgr, workspaceStateMgr, inspectManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export class LogTreeDataProvider implements TreeDataProvider<LogNode>, vscode.Di

getTreeItem(element: LogNode): TreeItem {

// determine some context value attributes
const contextValue: string[] = [element.type];
contextValue.push(
this.logListing_?.uriForNode(element)?.scheme === "file"
? "local"
: "remote"
);
contextValue.push(element.name.endsWith(".eval") ? "eval" : "json");

// base tree item
const treeItem: TreeItem = {
id: element.name,
Expand All @@ -59,6 +68,7 @@ export class LogTreeDataProvider implements TreeDataProvider<LogNode>, vscode.Di
collapsibleState: element.type === "dir"
? TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None,
contextValue: contextValue.join("+")
};

// make file display nicer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,34 @@ import { Command } from '../../../core/command';
import { LogTreeDataProvider } from './log-listing-data';

import { WorkspaceEnvManager } from "../../workspace/workspace-env-provider";
import { LogListing } from './log-listing';
import { LogListing, LogNode } from './log-listing';
import { InspectViewServer } from '../../inspect/inspect-view-server';
import { activeWorkspaceFolder } from '../../../core/workspace';
import { getRelativeUri, prettyUriPath } from '../../../core/uri';
import { InspectLogsWatcher } from '../../inspect/inspect-logs-watcher';
import { selectLogDirectory } from './log-directory-selector';
import { Uri } from 'vscode';
import { hasMinimumInspectVersion } from '../../../inspect/version';
import { kInspectEvalLogFormatVersion } from '../../inspect/inspect-constants';


export function activateLogListing(
export async function activateLogListing(
context: vscode.ExtensionContext,
envManager: WorkspaceEnvManager,
viewServer: InspectViewServer,
logsWatcher: InspectLogsWatcher
): [Command[], vscode.Disposable[]] {
): Promise<[Command[], vscode.Disposable[]]> {

const kLogListingDir = "inspect_ai.logListingDir";
const disposables: vscode.Disposable[] = [];

await vscode.commands.executeCommand(
"setContext",
"inspect_ai.haveEvalLogFormat",
hasMinimumInspectVersion(kInspectEvalLogFormatVersion)
);


// create tree data provider and tree
const treeDataProvider = new LogTreeDataProvider(context, viewServer);
disposables.push(treeDataProvider);
Expand Down Expand Up @@ -97,6 +106,44 @@ export function activateLogListing(
treeDataProvider.refresh();
}));

// Register Reveal in Explorer command
disposables.push(vscode.commands.registerCommand('inspect.logListingRevealInExplorer', async (node: LogNode) => {
const logUri = treeDataProvider.getLogListing()?.uriForNode(node);
if (logUri) {
await vscode.commands.executeCommand('revealInExplorer', logUri);
}
}));

// Register Open in JSON Editor... command
disposables.push(vscode.commands.registerCommand('inspect.logListingOpenInJSONEditor', async (node: LogNode) => {
const logUri = treeDataProvider.getLogListing()?.uriForNode(node);
if (logUri) {
await vscode.commands.executeCommand('vscode.open', logUri, <vscode.TextDocumentShowOptions>{ preview: true });
}
}));

// Register delete log file command
disposables.push(vscode.commands.registerCommand('inspect.logListingDeleteLogFile', async (node: LogNode) => {
const logUri = treeDataProvider.getLogListing()?.uriForNode(node);
if (logUri) {
const result = await vscode.window.showInformationMessage(
'Delete Log File',
{
modal: true,
detail: `Are you sure you want to delete the log file at ${prettyUriPath(logUri)}?`
},
{ title: 'Delete', isCloseAffordance: false },
{ title: 'Cancel', isCloseAffordance: true }
);

if (result?.title === 'Delete') {
await viewServer.evalLogDelete(logUri.toString());
treeDataProvider.refresh();
}

}
}));

// refresh when a log in our directory changes
disposables.push(logsWatcher.onInspectLogCreated((e) => {
const treeLogDir = treeDataProvider.getLogListing()?.logDir();
Expand Down
13 changes: 12 additions & 1 deletion tools/vscode/src/providers/inspect/inspect-view-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ export class InspectViewServer implements Disposable {
}
}

public async evalLogDelete(
file: string
): Promise<number> {

if (this.haveInspectEvalLogFormat()) {
return Number(await this.api_json(`/api/log-delete/${encodeURIComponent(file)}`));
} else {
throw new Error("evalLogDelete not implemented");
}
}

public async evalLogBytes(
file: string,
start: number,
Expand Down Expand Up @@ -126,7 +137,7 @@ export class InspectViewServer implements Disposable {
"COLUMNS": "150",
"INSPECT_VIEW_AUTHORIZATION_TOKEN": this.serverAuthToken_,
},
shell: os.platform() === "win32"
windowsHide: true
};

// forward output to channel and resolve promise
Expand Down

0 comments on commit 3d53ebf

Please sign in to comment.