refactor: trim file transfer helper exports

This commit is contained in:
Peter Steinberger
2026-05-01 18:10:32 +01:00
parent c17af6bb9d
commit 5bed76d734
6 changed files with 23 additions and 23 deletions

View File

@@ -3,10 +3,10 @@ import crypto from "node:crypto";
import fs from "node:fs/promises";
import path from "node:path";
export const DIR_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024;
export const DIR_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
const DIR_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024;
const DIR_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
export type DirFetchParams = {
type DirFetchParams = {
path?: unknown;
maxBytes?: unknown;
includeDotfiles?: unknown;
@@ -14,7 +14,7 @@ export type DirFetchParams = {
preflightOnly?: unknown;
};
export type DirFetchOk = {
type DirFetchOk = {
ok: true;
path: string;
tarBase64: string;
@@ -25,7 +25,7 @@ export type DirFetchOk = {
preflightOnly?: boolean;
};
export type DirFetchErrCode =
type DirFetchErrCode =
| "INVALID_PATH"
| "NOT_FOUND"
| "IS_FILE"
@@ -33,14 +33,14 @@ export type DirFetchErrCode =
| "SYMLINK_REDIRECT"
| "READ_ERROR";
export type DirFetchErr = {
type DirFetchErr = {
ok: false;
code: DirFetchErrCode;
message: string;
canonicalPath?: string;
};
export type DirFetchResult = DirFetchOk | DirFetchErr;
type DirFetchResult = DirFetchOk | DirFetchErr;
function clampMaxBytes(input: unknown): number {
if (typeof input !== "number" || !Number.isFinite(input) || input <= 0) {

View File

@@ -5,14 +5,14 @@ import { mimeFromExtension } from "../shared/mime.js";
export const DIR_LIST_DEFAULT_MAX_ENTRIES = 200;
export const DIR_LIST_HARD_MAX_ENTRIES = 5000;
export type DirListParams = {
type DirListParams = {
path?: unknown;
pageToken?: unknown;
maxEntries?: unknown;
followSymlinks?: unknown;
};
export type DirListEntry = {
type DirListEntry = {
name: string;
path: string;
size: number;
@@ -21,7 +21,7 @@ export type DirListEntry = {
mtime: number;
};
export type DirListOk = {
type DirListOk = {
ok: true;
path: string;
entries: DirListEntry[];
@@ -29,7 +29,7 @@ export type DirListOk = {
truncated: boolean;
};
export type DirListErrCode =
type DirListErrCode =
| "INVALID_PATH"
| "NOT_FOUND"
| "PERMISSION_DENIED"
@@ -37,14 +37,14 @@ export type DirListErrCode =
| "SYMLINK_REDIRECT"
| "READ_ERROR";
export type DirListErr = {
type DirListErr = {
ok: false;
code: DirListErrCode;
message: string;
canonicalPath?: string;
};
export type DirListResult = DirListOk | DirListErr;
type DirListResult = DirListOk | DirListErr;
function clampMaxEntries(input: unknown): number {
if (typeof input !== "number" || !Number.isFinite(input) || input <= 0) {

View File

@@ -7,14 +7,14 @@ import { EXTENSION_MIME } from "../shared/mime.js";
export const FILE_FETCH_HARD_MAX_BYTES = 16 * 1024 * 1024;
export const FILE_FETCH_DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
export type FileFetchParams = {
type FileFetchParams = {
path?: unknown;
maxBytes?: unknown;
followSymlinks?: unknown;
preflightOnly?: unknown;
};
export type FileFetchOk = {
type FileFetchOk = {
ok: true;
path: string;
size: number;
@@ -24,7 +24,7 @@ export type FileFetchOk = {
preflightOnly?: boolean;
};
export type FileFetchErrCode =
type FileFetchErrCode =
| "INVALID_PATH"
| "NOT_FOUND"
| "PERMISSION_DENIED"
@@ -34,14 +34,14 @@ export type FileFetchErrCode =
| "SYMLINK_REDIRECT"
| "READ_ERROR";
export type FileFetchErr = {
type FileFetchErr = {
ok: false;
code: FileFetchErrCode;
message: string;
canonicalPath?: string;
};
export type FileFetchResult = FileFetchOk | FileFetchErr;
type FileFetchResult = FileFetchOk | FileFetchErr;
function detectMimeType(filePath: string): string {
if (process.platform !== "win32") {

View File

@@ -14,7 +14,7 @@ import path from "node:path";
export type FileTransferAuditOp = "file.fetch" | "dir.list" | "dir.fetch" | "file.write";
export type FileTransferAuditDecision =
type FileTransferAuditDecision =
| "allowed"
| "allowed:once"
| "allowed:always"
@@ -25,7 +25,7 @@ export type FileTransferAuditDecision =
| "denied:symlink_escape"
| "error";
export type FileTransferAuditRecord = {
type FileTransferAuditRecord = {
timestamp: string;
op: FileTransferAuditOp;
nodeId: string;

View File

@@ -2,7 +2,7 @@
// Every tool returns the same { ok: false, code, message, canonicalPath? }
// shape so the model can reason about errors uniformly.
export type FileTransferErrCode =
type FileTransferErrCode =
// Path-shape errors (caller's fault)
| "INVALID_PATH"
| "INVALID_BASE64"
@@ -27,7 +27,7 @@ export type FileTransferErrCode =
| "POLICY_DENIED"
| "NO_POLICY";
export type FileTransferErr = {
type FileTransferErr = {
ok: false;
code: FileTransferErrCode;
message: string;

View File

@@ -1,7 +1,7 @@
// Shared param-validation helpers used by all four agent tools.
// Goal: identical validation behavior + identical error shapes everywhere.
export type GatewayCallOptions = {
type GatewayCallOptions = {
gatewayUrl?: string;
gatewayToken?: string;
timeoutMs?: number;