Switch to double quotes and reformat codebase with Biome

This commit is contained in:
Mohamed Boudra
2026-03-21 20:22:15 +07:00
parent ab40786882
commit f6579dbeb4
805 changed files with 38132 additions and 40175 deletions
+73 -75
View File
@@ -1,165 +1,163 @@
import type { Command } from 'commander'
import type { AgentPermissionRequest } from '@getpaseo/server'
import { connectToDaemon, getDaemonHost } from '../../utils/client.js'
import type { CommandOptions, ListResult, OutputSchema, CommandError } from '../../output/index.js'
import type { Command } from "commander";
import type { AgentPermissionRequest } from "@getpaseo/server";
import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
import type { CommandOptions, ListResult, OutputSchema, CommandError } from "../../output/index.js";
/** Permission response item for display */
export interface PermissionResponseItem {
requestId: string
agentId: string
agentShortId: string
name: string
result: string
requestId: string;
agentId: string;
agentShortId: string;
name: string;
result: string;
}
/** Schema for permit allow/deny output */
export const permitResponseSchema: OutputSchema<PermissionResponseItem> = {
idField: 'requestId',
idField: "requestId",
columns: [
{ header: 'REQUEST ID', field: 'requestId', width: 12 },
{ header: 'AGENT', field: 'agentShortId', width: 10 },
{ header: 'TOOL', field: 'name', width: 20 },
{ header: "REQUEST ID", field: "requestId", width: 12 },
{ header: "AGENT", field: "agentShortId", width: 10 },
{ header: "TOOL", field: "name", width: 20 },
{
header: 'RESULT',
field: 'result',
header: "RESULT",
field: "result",
width: 10,
color: (value) => {
if (value === 'allowed') return 'green'
if (value === 'denied') return 'red'
return undefined
if (value === "allowed") return "green";
if (value === "denied") return "red";
return undefined;
},
},
],
}
};
export type PermitAllowResult = ListResult<PermissionResponseItem>
export type PermitAllowResult = ListResult<PermissionResponseItem>;
export interface PermitAllowOptions extends CommandOptions {
all?: boolean
input?: string
host?: string
all?: boolean;
input?: string;
host?: string;
}
export async function runAllowCommand(
agentIdOrPrefix: string,
reqId: string | undefined,
options: PermitAllowOptions,
_command: Command
_command: Command,
): Promise<PermitAllowResult> {
const host = getDaemonHost({ host: options.host })
const host = getDaemonHost({ host: options.host });
// No validation needed - if no reqId provided, allow all by default
// Parse input JSON if provided
let updatedInput: Record<string, unknown> | undefined
let updatedInput: Record<string, unknown> | undefined;
if (options.input) {
try {
updatedInput = JSON.parse(options.input)
updatedInput = JSON.parse(options.input);
} catch (err) {
const error: CommandError = {
code: 'INVALID_JSON',
code: "INVALID_JSON",
message: `Invalid JSON for --input: ${err instanceof Error ? err.message : String(err)}`,
details: 'Provide valid JSON, e.g., --input \'{"key": "value"}\'',
}
throw error
};
throw error;
}
}
let client
let client;
try {
client = await connectToDaemon({ host: options.host })
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'DAEMON_NOT_RUNNING',
code: "DAEMON_NOT_RUNNING",
message: `Cannot connect to daemon at ${host}: ${message}`,
details: 'Start the daemon with: paseo daemon start',
}
throw error
details: "Start the daemon with: paseo daemon start",
};
throw error;
}
try {
const fetchResult = await client.fetchAgent(agentIdOrPrefix)
const fetchResult = await client.fetchAgent(agentIdOrPrefix);
if (!fetchResult) {
await client.close()
await client.close();
const error: CommandError = {
code: 'AGENT_NOT_FOUND',
code: "AGENT_NOT_FOUND",
message: `Agent not found: ${agentIdOrPrefix}`,
details: 'Use "paseo ls" to list available agents',
}
throw error
};
throw error;
}
const agent = fetchResult.agent
const resolvedAgentId = agent.id
const agent = fetchResult.agent;
const resolvedAgentId = agent.id;
// Get pending permissions for this agent
const pendingPermissions = agent.pendingPermissions || []
const pendingPermissions = agent.pendingPermissions || [];
if (pendingPermissions.length === 0) {
await client.close()
await client.close();
const error: CommandError = {
code: 'NO_PENDING_PERMISSIONS',
code: "NO_PENDING_PERMISSIONS",
message: `No pending permissions for agent ${agent.id.slice(0, 7)}`,
}
throw error
};
throw error;
}
// Determine which permissions to allow
let permissionsToAllow: AgentPermissionRequest[]
let permissionsToAllow: AgentPermissionRequest[];
if (!reqId || options.all) {
// Default: allow all pending permissions if no req_id specified
// --all flag is kept as an explicit alias for clarity
permissionsToAllow = pendingPermissions
permissionsToAllow = pendingPermissions;
} else {
// Find permission by ID prefix
const permission = pendingPermissions.find(
(p) => p.id === reqId || p.id.startsWith(reqId!)
)
const permission = pendingPermissions.find((p) => p.id === reqId || p.id.startsWith(reqId!));
if (!permission) {
await client.close()
await client.close();
const error: CommandError = {
code: 'PERMISSION_NOT_FOUND',
code: "PERMISSION_NOT_FOUND",
message: `Permission request not found: ${reqId}`,
details: `Available requests: ${pendingPermissions.map((p) => p.id.slice(0, 8)).join(', ')}`,
}
throw error
details: `Available requests: ${pendingPermissions.map((p) => p.id.slice(0, 8)).join(", ")}`,
};
throw error;
}
permissionsToAllow = [permission]
permissionsToAllow = [permission];
}
// Allow permissions
const results: PermissionResponseItem[] = []
const results: PermissionResponseItem[] = [];
for (const permission of permissionsToAllow) {
await client.respondToPermission(resolvedAgentId, permission.id, {
behavior: 'allow',
behavior: "allow",
...(updatedInput ? { updatedInput } : {}),
})
});
results.push({
requestId: permission.id.slice(0, 8),
agentId: resolvedAgentId,
agentShortId: resolvedAgentId.slice(0, 7),
name: permission.name,
result: 'allowed',
})
result: "allowed",
});
}
await client.close()
await client.close();
return {
type: 'list',
type: "list",
data: results,
schema: permitResponseSchema,
}
};
} catch (err) {
await client.close().catch(() => {})
await client.close().catch(() => {});
// Re-throw CommandErrors
if (err && typeof err === 'object' && 'code' in err) {
throw err
if (err && typeof err === "object" && "code" in err) {
throw err;
}
const message = err instanceof Error ? err.message : String(err)
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'ALLOW_PERMISSION_FAILED',
code: "ALLOW_PERMISSION_FAILED",
message: `Failed to allow permission: ${message}`,
}
throw error
};
throw error;
}
}
+60 -62
View File
@@ -1,130 +1,128 @@
import type { Command } from 'commander'
import type { AgentPermissionRequest } from '@getpaseo/server'
import { connectToDaemon, getDaemonHost } from '../../utils/client.js'
import type { CommandOptions, ListResult, CommandError } from '../../output/index.js'
import { permitResponseSchema, type PermissionResponseItem } from './allow.js'
import type { Command } from "commander";
import type { AgentPermissionRequest } from "@getpaseo/server";
import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
import type { CommandOptions, ListResult, CommandError } from "../../output/index.js";
import { permitResponseSchema, type PermissionResponseItem } from "./allow.js";
export type PermitDenyResult = ListResult<PermissionResponseItem>
export type PermitDenyResult = ListResult<PermissionResponseItem>;
export interface PermitDenyOptions extends CommandOptions {
all?: boolean
message?: string
interrupt?: boolean
host?: string
all?: boolean;
message?: string;
interrupt?: boolean;
host?: string;
}
export async function runDenyCommand(
agentIdOrPrefix: string,
reqId: string | undefined,
options: PermitDenyOptions,
_command: Command
_command: Command,
): Promise<PermitDenyResult> {
const host = getDaemonHost({ host: options.host })
const host = getDaemonHost({ host: options.host });
// Validate arguments
if (!options.all && !reqId) {
const error: CommandError = {
code: 'MISSING_ARGUMENT',
message: 'Request ID is required unless --all is specified',
details: 'Usage: paseo permit deny <agent> <req_id> or paseo permit deny <agent> --all',
}
throw error
code: "MISSING_ARGUMENT",
message: "Request ID is required unless --all is specified",
details: "Usage: paseo permit deny <agent> <req_id> or paseo permit deny <agent> --all",
};
throw error;
}
let client
let client;
try {
client = await connectToDaemon({ host: options.host })
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'DAEMON_NOT_RUNNING',
code: "DAEMON_NOT_RUNNING",
message: `Cannot connect to daemon at ${host}: ${message}`,
details: 'Start the daemon with: paseo daemon start',
}
throw error
details: "Start the daemon with: paseo daemon start",
};
throw error;
}
try {
const fetchResult = await client.fetchAgent(agentIdOrPrefix)
const fetchResult = await client.fetchAgent(agentIdOrPrefix);
if (!fetchResult) {
await client.close()
await client.close();
const error: CommandError = {
code: 'AGENT_NOT_FOUND',
code: "AGENT_NOT_FOUND",
message: `Agent not found: ${agentIdOrPrefix}`,
details: 'Use "paseo ls" to list available agents',
}
throw error
};
throw error;
}
const agent = fetchResult.agent
const resolvedAgentId = agent.id
const agent = fetchResult.agent;
const resolvedAgentId = agent.id;
// Get pending permissions for this agent
const pendingPermissions = agent.pendingPermissions || []
const pendingPermissions = agent.pendingPermissions || [];
if (pendingPermissions.length === 0) {
await client.close()
await client.close();
const error: CommandError = {
code: 'NO_PENDING_PERMISSIONS',
code: "NO_PENDING_PERMISSIONS",
message: `No pending permissions for agent ${agent.id.slice(0, 7)}`,
}
throw error
};
throw error;
}
// Determine which permissions to deny
let permissionsToDeny: AgentPermissionRequest[]
let permissionsToDeny: AgentPermissionRequest[];
if (options.all) {
permissionsToDeny = pendingPermissions
permissionsToDeny = pendingPermissions;
} else {
// Find permission by ID prefix
const permission = pendingPermissions.find(
(p) => p.id === reqId || p.id.startsWith(reqId!)
)
const permission = pendingPermissions.find((p) => p.id === reqId || p.id.startsWith(reqId!));
if (!permission) {
await client.close()
await client.close();
const error: CommandError = {
code: 'PERMISSION_NOT_FOUND',
code: "PERMISSION_NOT_FOUND",
message: `Permission request not found: ${reqId}`,
details: `Available requests: ${pendingPermissions.map((p) => p.id.slice(0, 8)).join(', ')}`,
}
throw error
details: `Available requests: ${pendingPermissions.map((p) => p.id.slice(0, 8)).join(", ")}`,
};
throw error;
}
permissionsToDeny = [permission]
permissionsToDeny = [permission];
}
// Deny permissions
const results: PermissionResponseItem[] = []
const results: PermissionResponseItem[] = [];
for (const permission of permissionsToDeny) {
await client.respondToPermission(resolvedAgentId, permission.id, {
behavior: 'deny',
behavior: "deny",
...(options.message ? { message: options.message } : {}),
...(options.interrupt ? { interrupt: true } : {}),
})
});
results.push({
requestId: permission.id.slice(0, 8),
agentId: resolvedAgentId,
agentShortId: resolvedAgentId.slice(0, 7),
name: permission.name,
result: 'denied',
})
result: "denied",
});
}
await client.close()
await client.close();
return {
type: 'list',
type: "list",
data: results,
schema: permitResponseSchema,
}
};
} catch (err) {
await client.close().catch(() => {})
await client.close().catch(() => {});
// Re-throw CommandErrors
if (err && typeof err === 'object' && 'code' in err) {
throw err
if (err && typeof err === "object" && "code" in err) {
throw err;
}
const message = err instanceof Error ? err.message : String(err)
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'DENY_PERMISSION_FAILED',
code: "DENY_PERMISSION_FAILED",
message: `Failed to deny permission: ${message}`,
}
throw error
};
throw error;
}
}
+27 -29
View File
@@ -1,39 +1,37 @@
import { Command } from 'commander'
import { runLsCommand } from './ls.js'
import { runAllowCommand } from './allow.js'
import { runDenyCommand } from './deny.js'
import { withOutput } from '../../output/index.js'
import { addJsonAndDaemonHostOptions } from '../../utils/command-options.js'
import { Command } from "commander";
import { runLsCommand } from "./ls.js";
import { runAllowCommand } from "./allow.js";
import { runDenyCommand } from "./deny.js";
import { withOutput } from "../../output/index.js";
import { addJsonAndDaemonHostOptions } from "../../utils/command-options.js";
export function createPermitCommand(): Command {
const permit = new Command('permit').description('Manage permission requests')
const permit = new Command("permit").description("Manage permission requests");
addJsonAndDaemonHostOptions(
permit.command("ls").description("List all pending permissions"),
).action(withOutput(runLsCommand));
addJsonAndDaemonHostOptions(
permit
.command('ls')
.description('List all pending permissions')
).action(withOutput(runLsCommand))
.command("allow")
.description("Allow a permission request")
.argument("<agent>", "Agent ID (or prefix)")
.argument("[req_id]", "Permission request ID (optional if --all)")
.option("--all", "Allow all pending permissions for this agent")
.option("--input <json>", "Modified input parameters (JSON)"),
).action(withOutput(runAllowCommand));
addJsonAndDaemonHostOptions(
permit
.command('allow')
.description('Allow a permission request')
.argument('<agent>', 'Agent ID (or prefix)')
.argument('[req_id]', 'Permission request ID (optional if --all)')
.option('--all', 'Allow all pending permissions for this agent')
.option('--input <json>', 'Modified input parameters (JSON)')
).action(withOutput(runAllowCommand))
.command("deny")
.description("Deny a permission request")
.argument("<agent>", "Agent ID (or prefix)")
.argument("[req_id]", "Permission request ID (optional if --all)")
.option("--all", "Deny all pending permissions for this agent")
.option("--message <msg>", "Denial reason message")
.option("--interrupt", "Stop agent after denial"),
).action(withOutput(runDenyCommand));
addJsonAndDaemonHostOptions(
permit
.command('deny')
.description('Deny a permission request')
.argument('<agent>', 'Agent ID (or prefix)')
.argument('[req_id]', 'Permission request ID (optional if --all)')
.option('--all', 'Deny all pending permissions for this agent')
.option('--message <msg>', 'Denial reason message')
.option('--interrupt', 'Stop agent after denial')
).action(withOutput(runDenyCommand))
return permit
return permit;
}
+47 -41
View File
@@ -1,88 +1,94 @@
import type { Command } from 'commander'
import type { AgentPermissionRequest, AgentSnapshotPayload } from '@getpaseo/server'
import { connectToDaemon, getDaemonHost } from '../../utils/client.js'
import type { CommandOptions, ListResult, OutputSchema, CommandError } from '../../output/index.js'
import type { Command } from "commander";
import type { AgentPermissionRequest, AgentSnapshotPayload } from "@getpaseo/server";
import { connectToDaemon, getDaemonHost } from "../../utils/client.js";
import type { CommandOptions, ListResult, OutputSchema, CommandError } from "../../output/index.js";
/** Permission list item for display */
export interface PermissionListItem {
id: string
agentId: string
agentShortId: string
name: string
description: string
id: string;
agentId: string;
agentShortId: string;
name: string;
description: string;
}
/** Schema for permit ls output */
export const permitLsSchema: OutputSchema<PermissionListItem> = {
idField: 'id',
idField: "id",
columns: [
{ header: 'AGENT', field: 'agentShortId', width: 12 },
{ header: 'REQ_ID', field: 'id', width: 12 },
{ header: 'TOOL', field: 'name', width: 20 },
{ header: 'DESCRIPTION', field: 'description', width: 50 },
{ header: "AGENT", field: "agentShortId", width: 12 },
{ header: "REQ_ID", field: "id", width: 12 },
{ header: "TOOL", field: "name", width: 20 },
{ header: "DESCRIPTION", field: "description", width: 50 },
],
}
};
/** Transform agent snapshot + permission to list item */
function toListItem(agent: AgentSnapshotPayload, permission: AgentPermissionRequest): PermissionListItem {
function toListItem(
agent: AgentSnapshotPayload,
permission: AgentPermissionRequest,
): PermissionListItem {
return {
id: permission.id.slice(0, 8),
agentId: agent.id,
agentShortId: agent.id.slice(0, 7),
name: permission.name,
description: permission.description ?? '-',
}
description: permission.description ?? "-",
};
}
export type PermitLsResult = ListResult<PermissionListItem>
export type PermitLsResult = ListResult<PermissionListItem>;
export interface PermitLsOptions extends CommandOptions {
host?: string
host?: string;
}
export async function runLsCommand(options: PermitLsOptions, _command: Command): Promise<PermitLsResult> {
const host = getDaemonHost({ host: options.host })
export async function runLsCommand(
options: PermitLsOptions,
_command: Command,
): Promise<PermitLsResult> {
const host = getDaemonHost({ host: options.host });
let client
let client;
try {
client = await connectToDaemon({ host: options.host })
client = await connectToDaemon({ host: options.host });
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'DAEMON_NOT_RUNNING',
code: "DAEMON_NOT_RUNNING",
message: `Cannot connect to daemon at ${host}: ${message}`,
details: 'Start the daemon with: paseo daemon start',
}
throw error
details: "Start the daemon with: paseo daemon start",
};
throw error;
}
try {
const agentsPayload = await client.fetchAgents({ filter: { includeArchived: true } })
const agents = agentsPayload.entries.map((entry) => entry.agent)
await client.close()
const agentsPayload = await client.fetchAgents({ filter: { includeArchived: true } });
const agents = agentsPayload.entries.map((entry) => entry.agent);
await client.close();
// Collect all pending permissions from all agents
const items: PermissionListItem[] = []
const items: PermissionListItem[] = [];
for (const agent of agents) {
if (agent.pendingPermissions && agent.pendingPermissions.length > 0) {
for (const permission of agent.pendingPermissions) {
items.push(toListItem(agent, permission))
items.push(toListItem(agent, permission));
}
}
}
return {
type: 'list',
type: "list",
data: items,
schema: permitLsSchema,
}
};
} catch (err) {
await client.close().catch(() => {})
const message = err instanceof Error ? err.message : String(err)
await client.close().catch(() => {});
const message = err instanceof Error ? err.message : String(err);
const error: CommandError = {
code: 'LIST_PERMISSIONS_FAILED',
code: "LIST_PERMISSIONS_FAILED",
message: `Failed to list permissions: ${message}`,
}
throw error
};
throw error;
}
}