You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/quickstart.md
+66-10Lines changed: 66 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ To interact with the Hide server, we need to create a client. We can do this by
13
13
```python
14
14
import hide
15
15
from hide.devcontainer.model import ImageDevContainer
16
-
from hide.model import Repository
16
+
from hide.model importFileUpdateType, UdiffUpdate, Repository
17
17
from hide.toolkit import Toolkit
18
18
19
19
hide_client = hide.Client()
@@ -70,7 +70,11 @@ Creating a project can take some time. Under the hood, Hide clones the repositor
70
70
Having created a project, we can now start working with it. You could notice that the devcontainer [configuration](https://github.com/artmoskvin/tiny-math-service/blob/main/.devcontainer.json) for the [Tiny Math Service](https://github.com/artmoskvin/tiny-math-service) contains a `customizations` section that defines a custom task called `test`. We can use this task to run tests for our project:
71
71
72
72
```python
73
-
result = hide_client.run_task(project.id, alias="test")
73
+
result = hide_client.run_task(
74
+
project_id=project.id,
75
+
alias="test"
76
+
)
77
+
74
78
print(result.stdOut)
75
79
```
76
80
@@ -79,7 +83,11 @@ The print statement will output the test results.
79
83
Aliases are convenient when referring to frequently used commands. Running tasks is powered by Task API which also allows us to run arbitrary shell commands by providing the `command` parameter:
80
84
81
85
```python
82
-
result = hide_client.run_task(project.id, command="pwd")
86
+
result = hide_client.run_task(
87
+
project_id=project.id,
88
+
command="pwd"
89
+
)
90
+
83
91
print(result.stdOut)
84
92
```
85
93
@@ -90,36 +98,84 @@ The tasks are executed from the project root so the print statement will output
90
98
We can also read and update files in the project. For example, we can read the `maths.py` file and add a new endpoint in it. First, let's read the file:
91
99
92
100
```python
93
-
result = hide_client.get_file(project.id, path="my_tiny_service/api/routers/maths.py")
101
+
result = hide_client.get_file(
102
+
project_id=project.id,
103
+
path="my_tiny_service/api/routers/maths.py"
104
+
)
105
+
94
106
print(result.content)
95
107
```
96
108
97
109
This will print the content of the `maths.py` file.
98
110
99
-
Coding agents often update files by generating diffs. Therefore it can be important to include line numbers when reading files. With Hide, we can include line numbers by setting the `show_line_numbers` parameter to `True`:
111
+
Coding agents often update files by adding/replacing lines or by applying unified diffs. Therefore it can be important to include line numbers when reading files. With Hide, we can include line numbers when reading files by setting the `show_line_numbers` parameter to `True`:
This will print the content of the `maths.py` file with line numbers.
110
124
111
-
By default, Hide will show the first 100 lines of the file. We can change this by setting the `start_line` and `num_lines` parameters:
125
+
By default, Hide returns the first 100 lines of the file. We can change this by setting the `start_line` and `num_lines` parameters:
112
126
113
127
```python
114
128
result = hide_client.get_file(
115
-
project.id,
129
+
project_id=project.id,
116
130
path="my_tiny_service/api/routers/maths.py",
117
131
show_line_numbers=True,
118
132
start_line=10,
119
-
num_lines=20,
133
+
num_lines=200,
134
+
)
135
+
136
+
print(result.content)
137
+
```
138
+
139
+
This will print the content of the `maths.py` file with 200 lines starting from line 10.
140
+
141
+
Updating files can be done in three ways: by replacing the entire file, by updating lines, or by applying unified diffs. For this quickstart we will use the unified diff option:
Copy file name to clipboardExpand all lines: docs/usage/files.md
+107-9Lines changed: 107 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,23 +98,125 @@ To specify a range of lines, set the `startLine` and `numLines` parameters:
98
98
99
99
### Updating a File
100
100
101
-
To update the contents of an existing file:
101
+
Updating files can be done in three ways: by replacing the entire file, by updating lines, or by applying unified diffs. We will look at each of these in the next sections.
102
+
103
+
#### Replacing the entire file
104
+
105
+
To replace the entire file, we can use the update type `overwrite` and provide the new content as the `content` parameter:
106
+
107
+
=== "python"
108
+
109
+
```python
110
+
from hide.model import FileUpdateType, OverwriteUpdate
This will update the contents of the file `example.txt` in your project's root directory to `Updated content!`. This API call will effectively overwrite the existing file.
173
+
This will update the lines from line 1 to 3 with the new content.
174
+
175
+
#### Applying unified diffs
176
+
177
+
To apply unified diffs, we can use the update type `udiff` and provide the patch as the `patch` parameter:
178
+
179
+
=== "python"
180
+
181
+
```python
182
+
from hide.model import FileUpdateType, UdiffUpdate
183
+
184
+
result = hide_client.update_file(
185
+
project_id="my-project",
186
+
path="path/to/file.py",
187
+
type=FileUpdateType.UDIFF,
188
+
udiff=UdiffUpdate(
189
+
patch="""--- path/to/file.py
190
+
+++ path/to/file.py
191
+
@@ -1,2 +1,2 @@
192
+
def hello_world():
193
+
- print('Hello, World!')
194
+
+ print('Hello, World!!!')
195
+
"""
196
+
)
197
+
)
198
+
```
199
+
200
+
=== "curl"
201
+
202
+
```bash
203
+
curl -X PUT http://localhost:8080/projects/my-project/files/path/to/file.py \
204
+
-H "Content-Type: application/json" \
205
+
-d '{
206
+
"type": "udiff",
207
+
"udiff": {
208
+
"patch": """--- path/to/file.py
209
+
+++ path/to/file.py
210
+
@@ -1,2 +1,2 @@
211
+
def hello_world():
212
+
- print('Hello, World!')
213
+
+ print('Hello, World!!!')
214
+
"""
215
+
}
216
+
}'
217
+
```
218
+
219
+
This will apply the unified diff to the file and update the lines accordingly.
118
220
119
221
### Deleting a File
120
222
@@ -134,10 +236,6 @@ To delete a specific file:
134
236
135
237
This will delete the file `example.txt` in your project's root directory.
136
238
137
-
### :construction: Applying Diffs
138
-
139
-
Coming soon
140
-
141
239
## Error Handling
142
240
143
241
The API uses standard HTTP status codes to indicate the success or failure of requests:
0 commit comments