Merge remote-tracking branch 'public-gh/master' into paperclip-company-import-export
* public-gh/master: fix: address greptile follow-up feedback docs: clarify quickstart npx usage Add guarded dev restart handling Fix PAP-576 settings toggles and transcript default Add username log censor setting fix: use standard toggle component for permission controls # Conflicts: # server/src/routes/agents.ts # ui/src/pages/AgentDetail.tsx
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
import type { TranscriptEntry } from "./types.js";
|
||||
|
||||
export const REDACTED_HOME_PATH_USER = "[]";
|
||||
export const REDACTED_HOME_PATH_USER = "*";
|
||||
|
||||
export interface HomePathRedactionOptions {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
function maskHomePathUserSegment(value: string) {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return REDACTED_HOME_PATH_USER;
|
||||
return `${trimmed[0]}${"*".repeat(Math.max(1, Array.from(trimmed).length - 1))}`;
|
||||
}
|
||||
|
||||
const HOME_PATH_PATTERNS = [
|
||||
{
|
||||
regex: /\/Users\/[^/\\\s]+/g,
|
||||
replace: `/Users/${REDACTED_HOME_PATH_USER}`,
|
||||
regex: /\/Users\/([^/\\\s]+)/g,
|
||||
replace: (_match: string, user: string) => `/Users/${maskHomePathUserSegment(user)}`,
|
||||
},
|
||||
{
|
||||
regex: /\/home\/[^/\\\s]+/g,
|
||||
replace: `/home/${REDACTED_HOME_PATH_USER}`,
|
||||
regex: /\/home\/([^/\\\s]+)/g,
|
||||
replace: (_match: string, user: string) => `/home/${maskHomePathUserSegment(user)}`,
|
||||
},
|
||||
{
|
||||
regex: /([A-Za-z]:\\Users\\)[^\\/\s]+/g,
|
||||
replace: `$1${REDACTED_HOME_PATH_USER}`,
|
||||
regex: /([A-Za-z]:\\Users\\)([^\\/\s]+)/g,
|
||||
replace: (_match: string, prefix: string, user: string) => `${prefix}${maskHomePathUserSegment(user)}`,
|
||||
},
|
||||
] as const;
|
||||
|
||||
@@ -23,7 +33,8 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
|
||||
return proto === Object.prototype || proto === null;
|
||||
}
|
||||
|
||||
export function redactHomePathUserSegments(text: string): string {
|
||||
export function redactHomePathUserSegments(text: string, opts?: HomePathRedactionOptions): string {
|
||||
if (opts?.enabled === false) return text;
|
||||
let result = text;
|
||||
for (const pattern of HOME_PATH_PATTERNS) {
|
||||
result = result.replace(pattern.regex, pattern.replace);
|
||||
@@ -31,12 +42,12 @@ export function redactHomePathUserSegments(text: string): string {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function redactHomePathUserSegmentsInValue<T>(value: T): T {
|
||||
export function redactHomePathUserSegmentsInValue<T>(value: T, opts?: HomePathRedactionOptions): T {
|
||||
if (typeof value === "string") {
|
||||
return redactHomePathUserSegments(value) as T;
|
||||
return redactHomePathUserSegments(value, opts) as T;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((entry) => redactHomePathUserSegmentsInValue(entry)) as T;
|
||||
return value.map((entry) => redactHomePathUserSegmentsInValue(entry, opts)) as T;
|
||||
}
|
||||
if (!isPlainObject(value)) {
|
||||
return value;
|
||||
@@ -44,12 +55,12 @@ export function redactHomePathUserSegmentsInValue<T>(value: T): T {
|
||||
|
||||
const redacted: Record<string, unknown> = {};
|
||||
for (const [key, entry] of Object.entries(value)) {
|
||||
redacted[key] = redactHomePathUserSegmentsInValue(entry);
|
||||
redacted[key] = redactHomePathUserSegmentsInValue(entry, opts);
|
||||
}
|
||||
return redacted as T;
|
||||
}
|
||||
|
||||
export function redactTranscriptEntryPaths(entry: TranscriptEntry): TranscriptEntry {
|
||||
export function redactTranscriptEntryPaths(entry: TranscriptEntry, opts?: HomePathRedactionOptions): TranscriptEntry {
|
||||
switch (entry.kind) {
|
||||
case "assistant":
|
||||
case "thinking":
|
||||
@@ -57,23 +68,27 @@ export function redactTranscriptEntryPaths(entry: TranscriptEntry): TranscriptEn
|
||||
case "stderr":
|
||||
case "system":
|
||||
case "stdout":
|
||||
return { ...entry, text: redactHomePathUserSegments(entry.text) };
|
||||
return { ...entry, text: redactHomePathUserSegments(entry.text, opts) };
|
||||
case "tool_call":
|
||||
return { ...entry, name: redactHomePathUserSegments(entry.name), input: redactHomePathUserSegmentsInValue(entry.input) };
|
||||
return {
|
||||
...entry,
|
||||
name: redactHomePathUserSegments(entry.name, opts),
|
||||
input: redactHomePathUserSegmentsInValue(entry.input, opts),
|
||||
};
|
||||
case "tool_result":
|
||||
return { ...entry, content: redactHomePathUserSegments(entry.content) };
|
||||
return { ...entry, content: redactHomePathUserSegments(entry.content, opts) };
|
||||
case "init":
|
||||
return {
|
||||
...entry,
|
||||
model: redactHomePathUserSegments(entry.model),
|
||||
sessionId: redactHomePathUserSegments(entry.sessionId),
|
||||
model: redactHomePathUserSegments(entry.model, opts),
|
||||
sessionId: redactHomePathUserSegments(entry.sessionId, opts),
|
||||
};
|
||||
case "result":
|
||||
return {
|
||||
...entry,
|
||||
text: redactHomePathUserSegments(entry.text),
|
||||
subtype: redactHomePathUserSegments(entry.subtype),
|
||||
errors: entry.errors.map((error) => redactHomePathUserSegments(error)),
|
||||
text: redactHomePathUserSegments(entry.text, opts),
|
||||
subtype: redactHomePathUserSegments(entry.subtype, opts),
|
||||
errors: entry.errors.map((error) => redactHomePathUserSegments(error, opts)),
|
||||
};
|
||||
default:
|
||||
return entry;
|
||||
|
||||
Reference in New Issue
Block a user