MCPcopy Create free account
hub / github.com/anus-dev/ANUS / getUpdatedParams

Function getUpdatedParams

packages/core/src/tools/modifiable-tool.ts:83–121  ·  view source on GitHub ↗
(
  tmpOldPath: string,
  tempNewPath: string,
  originalParams: ToolParams,
  modifyContext: ModifyContext<ToolParams>,
)

Source from the content-addressed store, hash-verified

81}
82
83function getUpdatedParams<ToolParams>(
84 tmpOldPath: string,
85 tempNewPath: string,
86 originalParams: ToolParams,
87 modifyContext: ModifyContext<ToolParams>,
88): { updatedParams: ToolParams; updatedDiff: string } {
89 let oldContent = '';
90 let newContent = '';
91
92 try {
93 oldContent = fs.readFileSync(tmpOldPath, 'utf8');
94 } catch (err) {
95 if (!isNodeError(err) || err.code !== 'ENOENT') throw err;
96 oldContent = '';
97 }
98
99 try {
100 newContent = fs.readFileSync(tempNewPath, 'utf8');
101 } catch (err) {
102 if (!isNodeError(err) || err.code !== 'ENOENT') throw err;
103 newContent = '';
104 }
105
106 const updatedParams = modifyContext.createUpdatedParams(
107 oldContent,
108 newContent,
109 originalParams,
110 );
111 const updatedDiff = Diff.createPatch(
112 path.basename(modifyContext.getFilePath(originalParams)),
113 oldContent,
114 newContent,
115 'Current',
116 'Proposed',
117 DEFAULT_DIFF_OPTIONS,
118 );
119
120 return { updatedParams, updatedDiff };
121}
122
123function deleteTempFiles(oldPath: string, newPath: string): void {
124 try {

Callers 1

modifyWithEditorFunction · 0.85

Calls 1

isNodeErrorFunction · 0.85

Tested by

no test coverage detected