File size: 4,674 Bytes
39e315a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | import { c as _c } from "react-compiler-runtime";
import { basename, relative } from 'path';
import React, { useMemo } from 'react';
import type { z } from 'zod/v4';
import { Text } from '../../../ink.js';
import { FileWriteTool } from '../../../tools/FileWriteTool/FileWriteTool.js';
import { getCwd } from '../../../utils/cwd.js';
import { isENOENT } from '../../../utils/errors.js';
import { readFileSync } from '../../../utils/fileRead.js';
import { FilePermissionDialog } from '../FilePermissionDialog/FilePermissionDialog.js';
import { createSingleEditDiffConfig, type FileEdit, type IDEDiffSupport } from '../FilePermissionDialog/ideDiffConfig.js';
import type { PermissionRequestProps } from '../PermissionRequest.js';
import { FileWriteToolDiff } from './FileWriteToolDiff.js';
type FileWriteToolInput = z.infer<typeof FileWriteTool.inputSchema>;
const ideDiffSupport: IDEDiffSupport<FileWriteToolInput> = {
getConfig: (input: FileWriteToolInput) => {
let oldContent: string;
try {
oldContent = readFileSync(input.file_path);
} catch (e) {
if (!isENOENT(e)) throw e;
oldContent = '';
}
return createSingleEditDiffConfig(input.file_path, oldContent, input.content, false // For file writes, we replace the entire content
);
},
applyChanges: (input: FileWriteToolInput, modifiedEdits: FileEdit[]) => {
const firstEdit = modifiedEdits[0];
if (firstEdit) {
return {
...input,
content: firstEdit.new_string
};
}
return input;
}
};
export function FileWritePermissionRequest(props) {
const $ = _c(30);
const parseInput = _temp;
let t0;
if ($[0] !== props.toolUseConfirm.input) {
t0 = parseInput(props.toolUseConfirm.input);
$[0] = props.toolUseConfirm.input;
$[1] = t0;
} else {
t0 = $[1];
}
const parsed = t0;
const {
file_path,
content
} = parsed;
let t1;
if ($[2] !== file_path) {
;
try {
t1 = {
fileExists: true,
oldContent: readFileSync(file_path)
};
} catch (t2) {
const e = t2;
if (!isENOENT(e)) {
throw e;
}
let t3;
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
t3 = {
fileExists: false,
oldContent: ""
};
$[4] = t3;
} else {
t3 = $[4];
}
t1 = t3;
}
$[2] = file_path;
$[3] = t1;
} else {
t1 = $[3];
}
const {
fileExists,
oldContent
} = t1;
const actionText = fileExists ? "overwrite" : "create";
const t2 = props.toolUseConfirm;
const t3 = props.toolUseContext;
const t4 = props.onDone;
const t5 = props.onReject;
const t6 = props.workerBadge;
const t7 = fileExists ? "Overwrite file" : "Create file";
let t8;
if ($[5] !== file_path) {
t8 = relative(getCwd(), file_path);
$[5] = file_path;
$[6] = t8;
} else {
t8 = $[6];
}
let t9;
if ($[7] !== file_path) {
t9 = basename(file_path);
$[7] = file_path;
$[8] = t9;
} else {
t9 = $[8];
}
let t10;
if ($[9] !== t9) {
t10 = <Text bold={true}>{t9}</Text>;
$[9] = t9;
$[10] = t10;
} else {
t10 = $[10];
}
let t11;
if ($[11] !== actionText || $[12] !== t10) {
t11 = <Text>Do you want to {actionText} {t10}?</Text>;
$[11] = actionText;
$[12] = t10;
$[13] = t11;
} else {
t11 = $[13];
}
let t12;
if ($[14] !== content || $[15] !== fileExists || $[16] !== file_path || $[17] !== oldContent) {
t12 = <FileWriteToolDiff file_path={file_path} content={content} fileExists={fileExists} oldContent={oldContent} />;
$[14] = content;
$[15] = fileExists;
$[16] = file_path;
$[17] = oldContent;
$[18] = t12;
} else {
t12 = $[18];
}
let t13;
if ($[19] !== file_path || $[20] !== props.onDone || $[21] !== props.onReject || $[22] !== props.toolUseConfirm || $[23] !== props.toolUseContext || $[24] !== props.workerBadge || $[25] !== t11 || $[26] !== t12 || $[27] !== t7 || $[28] !== t8) {
t13 = <FilePermissionDialog toolUseConfirm={t2} toolUseContext={t3} onDone={t4} onReject={t5} workerBadge={t6} title={t7} subtitle={t8} question={t11} content={t12} path={file_path} completionType="write_file_single" parseInput={parseInput} ideDiffSupport={ideDiffSupport} />;
$[19] = file_path;
$[20] = props.onDone;
$[21] = props.onReject;
$[22] = props.toolUseConfirm;
$[23] = props.toolUseContext;
$[24] = props.workerBadge;
$[25] = t11;
$[26] = t12;
$[27] = t7;
$[28] = t8;
$[29] = t13;
} else {
t13 = $[29];
}
return t13;
}
function _temp(input) {
return FileWriteTool.inputSchema.parse(input);
}
|