rl-workspaces 0.0.0-stage → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +735 -2
  3. package/bin/rl +54 -0
  4. package/config.example.zsh +9 -0
  5. package/dist/access.js +40 -0
  6. package/dist/activity.js +90 -0
  7. package/dist/agent-claude.js +16 -0
  8. package/dist/agent-codex.js +22 -0
  9. package/dist/agent-launch.js +74 -0
  10. package/dist/agent-presets.js +70 -0
  11. package/dist/agent-registry.js +8 -0
  12. package/dist/agent-resume.js +96 -0
  13. package/dist/agent-runner.js +386 -0
  14. package/dist/agent-workflows.js +275 -0
  15. package/dist/agents.js +73 -0
  16. package/dist/automation-config.js +381 -0
  17. package/dist/base.js +66 -0
  18. package/dist/cleanup-path.js +33 -0
  19. package/dist/cli.js +57 -0
  20. package/dist/codex-sessions.js +188 -0
  21. package/dist/command-context.js +67 -0
  22. package/dist/common.js +262 -0
  23. package/dist/delete.js +113 -0
  24. package/dist/display.js +134 -0
  25. package/dist/doctor.js +145 -0
  26. package/dist/git-safety.js +24 -0
  27. package/dist/git-workflow.js +89 -0
  28. package/dist/help.js +726 -0
  29. package/dist/hooks.js +159 -0
  30. package/dist/json.js +34 -0
  31. package/dist/mcp.js +336 -0
  32. package/dist/picker.js +182 -0
  33. package/dist/pr-discovery.js +223 -0
  34. package/dist/pr-update.js +419 -0
  35. package/dist/pr-workflow.js +161 -0
  36. package/dist/repos.js +537 -0
  37. package/dist/review-policy.js +150 -0
  38. package/dist/session-workflows.js +650 -0
  39. package/dist/session.js +12 -0
  40. package/dist/state.js +250 -0
  41. package/dist/storage.js +366 -0
  42. package/dist/store.js +379 -0
  43. package/dist/summary.js +164 -0
  44. package/dist/task-state.js +65 -0
  45. package/dist/task.js +192 -0
  46. package/dist/templates.js +4 -0
  47. package/dist/workflow-collaboration.js +531 -0
  48. package/dist/workflow-config.js +177 -0
  49. package/dist/workflow.js +211 -0
  50. package/lib/rl.zsh +329 -0
  51. package/node_modules/graceful-fs/LICENSE +15 -0
  52. package/node_modules/graceful-fs/README.md +143 -0
  53. package/node_modules/graceful-fs/clone.js +23 -0
  54. package/node_modules/graceful-fs/graceful-fs.js +448 -0
  55. package/node_modules/graceful-fs/legacy-streams.js +118 -0
  56. package/node_modules/graceful-fs/package.json +53 -0
  57. package/node_modules/graceful-fs/polyfills.js +355 -0
  58. package/node_modules/proper-lockfile/LICENSE +21 -0
  59. package/node_modules/proper-lockfile/README.md +183 -0
  60. package/node_modules/proper-lockfile/index.js +40 -0
  61. package/node_modules/proper-lockfile/lib/adapter.js +85 -0
  62. package/node_modules/proper-lockfile/lib/lockfile.js +342 -0
  63. package/node_modules/proper-lockfile/lib/mtime-precision.js +55 -0
  64. package/node_modules/proper-lockfile/package.json +71 -0
  65. package/node_modules/retry/.npmignore +3 -0
  66. package/node_modules/retry/.travis.yml +15 -0
  67. package/node_modules/retry/License +21 -0
  68. package/node_modules/retry/Makefile +18 -0
  69. package/node_modules/retry/README.md +227 -0
  70. package/node_modules/retry/equation.gif +0 -0
  71. package/node_modules/retry/example/dns.js +31 -0
  72. package/node_modules/retry/example/stop.js +40 -0
  73. package/node_modules/retry/index.js +1 -0
  74. package/node_modules/retry/lib/retry.js +100 -0
  75. package/node_modules/retry/lib/retry_operation.js +158 -0
  76. package/node_modules/retry/package.json +32 -0
  77. package/node_modules/retry/test/common.js +10 -0
  78. package/node_modules/retry/test/integration/test-forever.js +24 -0
  79. package/node_modules/retry/test/integration/test-retry-operation.js +258 -0
  80. package/node_modules/retry/test/integration/test-retry-wrap.js +101 -0
  81. package/node_modules/retry/test/integration/test-timeouts.js +69 -0
  82. package/node_modules/signal-exit/LICENSE.txt +16 -0
  83. package/node_modules/signal-exit/README.md +39 -0
  84. package/node_modules/signal-exit/index.js +202 -0
  85. package/node_modules/signal-exit/package.json +38 -0
  86. package/node_modules/signal-exit/signals.js +53 -0
  87. package/package.json +57 -4
  88. package/shell/rl.zsh +11 -0
package/lib/rl.zsh ADDED
@@ -0,0 +1,329 @@
1
+ # Shared implementation for the executable and optional zsh integration.
2
+ _rl_state() {
3
+ command node "${${functions_source[_rl_state]}:A:h:h}/dist/cli.js" state \
4
+ --repo "$repo_root" --state-dir "$state_dir" "$@"
5
+ }
6
+
7
+ _rl_repos() {
8
+ command node "${${functions_source[_rl_repos]}:A:h:h}/dist/cli.js" repos \
9
+ --state-dir "$state_dir" --base-dir "$base_dir" --legacy-root "$repo_root" \
10
+ --legacy-name "$repo_name" --legacy-base "$default_base" --selection "$selected_repo" "$@"
11
+ }
12
+
13
+ _rl_enter() {
14
+ _rl_state adopt --worktree "$1" --base "${base:-$default_base}" --quiet || return 1
15
+ _rl_change_directory "$1"
16
+ }
17
+
18
+ _rl_change_directory() {
19
+ local previous="$PWD"
20
+ builtin cd -- "$1" || return 1
21
+ if [[ "${RL_INTERNAL_SHELL:-0}" == 1 ]]; then
22
+ typeset -g RL_PREVIOUS_WORKSPACE="$previous"
23
+ elif [[ -n "${RL_SHELL_OUTPUT:-}" ]]; then
24
+ print -rn -- "$PWD" > "$RL_SHELL_OUTPUT"
25
+ else
26
+ print -r -- "$PWD"
27
+ fi
28
+ }
29
+
30
+ _rl_recover_directory() {
31
+ [[ -d "$PWD" ]] && return 0
32
+ builtin cd -- "$repo_root" || return 1
33
+ if [[ -n "${RL_SHELL_OUTPUT:-}" ]]; then
34
+ print -rn -- "$PWD" > "$RL_SHELL_OUTPUT"
35
+ fi
36
+ }
37
+
38
+ _rl_help() {
39
+ command node "${${functions_source[_rl_help]}:A:h:h}/dist/help.js" "$@"
40
+ }
41
+
42
+ _rl_main() {
43
+ emulate -L zsh
44
+ # Help is independent of repository routing, config files, and agent tools.
45
+ local -a help_args=("$@")
46
+ [[ "$help_args[1]" == --repo ]] && help_args=("${help_args[@]:2}")
47
+ [[ "$help_args[1]" == --repo=* ]] && help_args=("${help_args[@]:1}")
48
+ local help_arg
49
+ if [[ "$help_args[1]" == help ]]; then
50
+ _rl_help "${help_args[@]}"
51
+ return
52
+ fi
53
+ for help_arg in "${help_args[@]}"; do
54
+ [[ "$help_arg" == -- ]] && break
55
+ if [[ "$help_arg" == --help || "$help_arg" == -h ]]; then
56
+ _rl_help "${help_args[@]}"
57
+ return
58
+ fi
59
+ done
60
+ if (( ${#help_args} == 1 )) && [[ "$help_args[1]" == (agent|workflow|policy|repo|git|notes|session|config) ]]; then
61
+ _rl_help "${help_args[@]}"
62
+ return
63
+ fi
64
+
65
+ # Canonical command families; older spellings remain compatibility aliases.
66
+ # Preserve a leading repository selector while normalizing the public command.
67
+ local -a routing_prefix=()
68
+ if [[ "$1" == --repo ]]; then
69
+ routing_prefix=("$1" "$2")
70
+ shift 2
71
+ elif [[ "$1" == --repo=* ]]; then
72
+ routing_prefix=("$1")
73
+ shift
74
+ fi
75
+ case "$1:$2" in
76
+ git:merge) argv=("$2" "${@:3}") ;;
77
+ agent:sessions) argv=(session list "${@:3}") ;;
78
+ agent:save) argv=(session save "${@:3}") ;;
79
+ agent:handoff) argv=(handoff "${@:3}") ;;
80
+ agent:mcp) argv=(mcp "${@:3}") ;;
81
+ storage:clean) argv=(clean "${@:3}") ;;
82
+ setup:init|setup:show) argv=(config "$2" "${@:3}") ;;
83
+ setup:adopt) argv=(adopt "${@:3}") ;;
84
+ setup:run) argv=(setup "${@:3}") ;;
85
+ setup:shell)
86
+ command "${${functions_source[_rl_main]}:A:h:h}/bin/rl" init "${@:3}"
87
+ return ;;
88
+ notes:summary) argv=(summary "${@:3}") ;;
89
+ notes:show|notes:path|notes:set|notes:append)
90
+ local note_kind="${3:-context}"
91
+ if [[ "$note_kind" != context && "$note_kind" != progress ]]; then
92
+ print -u2 -r -- "Unknown document: $note_kind. Use context or progress."
93
+ _rl_help notes "$2" >&2
94
+ return 1
95
+ fi
96
+ argv=("$note_kind" "$2" "${@:4}") ;;
97
+ esac
98
+ if [[ "$1" == git || "$1" == notes ]]; then
99
+ print -u2 -r -- "Unknown $1 command: $2"
100
+ print -u2 -r -- "Run rl help $1 for available commands."
101
+ return 1
102
+ fi
103
+ argv=("${routing_prefix[@]}" "$@")
104
+ local config_file="${RL_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/rl/config.zsh}"
105
+ # Configuration is trusted zsh code, scoped to this invocation.
106
+ local -x RL_REPO_ROOT="${RL_REPO_ROOT-}" RL_WORKTREE_DIR="${RL_WORKTREE_DIR-}"
107
+ local -x RL_REPO_NAME="${RL_REPO_NAME-}" RL_DEFAULT_BASE="${RL_DEFAULT_BASE-}"
108
+ local -x RL_STATE_DIR="${RL_STATE_DIR-}"
109
+ local env_selection_present=${+RL_REPO}
110
+ local -x RL_REPO="${RL_REPO-}"
111
+ local env_root="$RL_REPO_ROOT" env_dir="$RL_WORKTREE_DIR"
112
+ local env_name="$RL_REPO_NAME" env_base="$RL_DEFAULT_BASE"
113
+ local env_state="$RL_STATE_DIR"
114
+ local env_selection="$RL_REPO"
115
+ if [[ -f "$config_file" ]]; then
116
+ source "$config_file" || return 1
117
+ elif [[ -n "${RL_CONFIG:-}" ]]; then
118
+ print -u2 -r -- "Configuration not found: $config_file"
119
+ return 1
120
+ fi
121
+ local repo_root="${env_root:-$RL_REPO_ROOT}"
122
+ if [[ -z "$repo_root" ]]; then
123
+ # Resolve only the current repository; the first NUL-delimited worktree
124
+ # record identifies its main checkout, including from a linked worktree.
125
+ local -a current_repository
126
+ current_repository=("${(@0)$(command env -u GIT_DIR -u GIT_WORK_TREE -u GIT_COMMON_DIR -u GIT_INDEX_FILE \
127
+ git -C "$PWD" worktree list --porcelain -z 2>/dev/null)}")
128
+ if [[ "$current_repository[1]" == 'worktree '* ]]; then
129
+ repo_root="${current_repository[1]#worktree }"
130
+ else
131
+ # Repository-management commands can run outside Git; registered defaults
132
+ # are resolved below before workspace commands use this placeholder.
133
+ repo_root="$PWD"
134
+ fi
135
+ fi
136
+ local base_dir="${env_dir:-${RL_WORKTREE_DIR:-$HOME/.rl/worktrees}}"
137
+ local repo_name="${env_name:-${RL_REPO_NAME:-${repo_root:t}}}"
138
+ local default_base="${env_base:-${RL_DEFAULT_BASE:-origin/test}}"
139
+ local state_dir="${env_state:-${RL_STATE_DIR:-$HOME/.rl/instances}}"
140
+ local selected_repo="$RL_REPO"
141
+ (( env_selection_present )) && selected_repo="$env_selection"
142
+ [[ "$repo_root" = /* && "$base_dir" = /* && "$state_dir" = /* ]] || {
143
+ print -u2 'Repository, worktree, and state directories must be absolute paths.'
144
+ return 1
145
+ }
146
+ [[ -n "$repo_name" && "$repo_name" != */* && "$repo_name" != . && "$repo_name" != .. ]] || {
147
+ print -u2 'RL_REPO_NAME must be a single directory name.'
148
+ return 1
149
+ }
150
+
151
+ if [[ "$1" == --repo ]]; then
152
+ [[ -n "$2" ]] || { print -u2 'Usage: rl --repo <alias> <command>'; return 1; }
153
+ selected_repo="$2"
154
+ shift 2
155
+ elif [[ "$1" == --repo=* ]]; then
156
+ selected_repo="${1#--repo=}"
157
+ [[ -n "$selected_repo" ]] || { print -u2 'Repository alias is required'; return 1; }
158
+ shift
159
+ fi
160
+ local command="$1"
161
+ local name worktree branch base existing_worktree
162
+
163
+ if [[ "$command" == repo ]]; then
164
+ _rl_repos "$@"
165
+ return
166
+ fi
167
+ if [[ "$command" == checkout ]]; then
168
+ local destination_file destination checkout_result
169
+ destination_file=$(mktemp "${TMPDIR:-/tmp}/rl-checkout.XXXXXXXX") || return 1
170
+ {
171
+ _rl_repos "$@" --output-path "$destination_file"
172
+ checkout_result=$?
173
+ destination=$(<"$destination_file")
174
+ if (( checkout_result == 0 )) && [[ -n "$destination" ]]; then
175
+ _rl_change_directory "$destination" || return 1
176
+ fi
177
+ return $checkout_result
178
+ } always {
179
+ command rm -f -- "$destination_file"
180
+ }
181
+ fi
182
+ if [[ "$command" == list ]]; then
183
+ shift
184
+ if (( ${argv[(Ie)--all]} )); then
185
+ _rl_repos status "$@"
186
+ else
187
+ _rl_repos status --list "$@"
188
+ fi
189
+ return
190
+ fi
191
+ if [[ "$command" == status ]] && (( ! ${argv[(Ie)--workspace]} )); then
192
+ _rl_repos "$@"
193
+ return
194
+ fi
195
+ if [[ -f "$state_dir/repositories.json" || -n "$selected_repo" ]]; then
196
+ local resolved
197
+ local -a repository_fields
198
+ resolved=$(_rl_repos resolve) || return 1
199
+ repository_fields=("${(@f)resolved}")
200
+ [[ ${#repository_fields} == 4 ]] || { print -u2 'Invalid resolved repository'; return 1; }
201
+ repo_root="$repository_fields[1]"
202
+ repo_name="$repository_fields[2]"
203
+ default_base="$repository_fields[3]"
204
+ fi
205
+
206
+ if [[ "$command" == pr && "$2" == update ]]; then
207
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" pr-update \
208
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
209
+ --default-base "$default_base" "$@"
210
+ return
211
+ fi
212
+ if [[ "$command" == pr && ( "$2" == checks || "$2" == checkout ) ]]; then
213
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" pr \
214
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
215
+ --default-base "$default_base" "$@"
216
+ return
217
+ fi
218
+ case "$command" in
219
+ storage|clean)
220
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" storage \
221
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
222
+ --default-base "$default_base" "$@"
223
+ return ;;
224
+ pause)
225
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" task \
226
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
227
+ --default-base "$default_base" "$@"
228
+ return ;;
229
+ merge)
230
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" git \
231
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
232
+ --default-base "$default_base" "$@"
233
+ local git_result=$?
234
+ _rl_recover_directory || return 1
235
+ return $git_result ;;
236
+ workflow|policy)
237
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" automation \
238
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
239
+ --default-base "$default_base" "$@"
240
+ return ;;
241
+ agent|handoff)
242
+ if [[ "$command" == agent && ( "$2" == list || "$2" == show || "$2" == add || "$2" == set ) ]]; then
243
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" automation \
244
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
245
+ --default-base "$default_base" "$@"
246
+ return
247
+ fi
248
+ [[ "$command" == agent ]] && shift
249
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" agent \
250
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
251
+ --default-base "$default_base" "$@"
252
+ return ;;
253
+ mcp)
254
+ shift
255
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" mcp \
256
+ --repo "$repo_root" --state-dir "$state_dir" "$@"
257
+ return ;;
258
+ summary)
259
+ shift
260
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" summary \
261
+ --repo "$repo_root" --state-dir "$state_dir" --default-base "$default_base" "$@"
262
+ return ;;
263
+ adopt|doctor|status|instances|resume|session|context|progress|pr)
264
+ _rl_state "$@"
265
+ return ;;
266
+ esac
267
+
268
+ case "$command" in
269
+ switch|new|open|continue)
270
+ if [[ "$command" == switch && "$2" == - ]]; then
271
+ [[ -n "${RL_PREVIOUS_WORKSPACE:-}" ]] || { print -u2 'No previous workspace in this shell'; return 1; }
272
+ argv[2]="$RL_PREVIOUS_WORKSPACE"
273
+ fi
274
+ local destination_file destination workflow_result
275
+ local workflow_command=workflow
276
+ [[ "$command" == continue ]] && workflow_command=task
277
+ destination_file=$(mktemp "${TMPDIR:-/tmp}/rl-switch.XXXXXXXX") || return 1
278
+ {
279
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" "$workflow_command" \
280
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
281
+ --default-base "$default_base" --output-path "$destination_file" "$@"
282
+ workflow_result=$?
283
+ destination=$(<"$destination_file")
284
+ if [[ -n "$destination" ]]; then
285
+ _rl_change_directory "$destination" || return 1
286
+ fi
287
+ return $workflow_result
288
+ } always {
289
+ command rm -f -- "$destination_file"
290
+ }
291
+ ;;
292
+ path|exec|setup|config)
293
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" workflow \
294
+ --repo "$repo_root" --state-dir "$state_dir" --base-dir "$base_dir/$repo_name" \
295
+ --default-base "$default_base" "$@"
296
+ return ;;
297
+ esac
298
+
299
+ if [[ "$command" == "delete" ]]; then
300
+ shift
301
+ command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" delete \
302
+ --repo "$repo_root" --state-dir "$state_dir" \
303
+ --base-dir "$base_dir/$repo_name" --default-base "$default_base" "$@"
304
+ local delete_result=$?
305
+ # With shell integration, leave a deleted current directory gracefully.
306
+ _rl_recover_directory || return 1
307
+ return $delete_result
308
+ fi
309
+
310
+ # ------------------------------------------------------------
311
+ # rl
312
+ #
313
+ # Interactive worktree picker
314
+ # ------------------------------------------------------------
315
+ if [[ -z "$command" ]]; then
316
+ worktree=$(command node "${${functions_source[_rl_main]}:A:h:h}/dist/cli.js" picker \
317
+ --repo "$repo_root" --state-dir "$state_dir" \
318
+ --base-dir "$base_dir/$repo_name" --default-base "$default_base") || return $?
319
+ if [[ -n "$worktree" ]]; then
320
+ _rl_enter "$worktree"
321
+ fi
322
+
323
+ return
324
+ fi
325
+
326
+ print -u2 -r -- "Unknown command: $command"
327
+ print -u2 'Run rl help for available commands.'
328
+ return 1
329
+ }
@@ -0,0 +1,15 @@
1
+ The ISC License
2
+
3
+ Copyright (c) 2011-2022 Isaac Z. Schlueter, Ben Noordhuis, and Contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,143 @@
1
+ # graceful-fs
2
+
3
+ graceful-fs functions as a drop-in replacement for the fs module,
4
+ making various improvements.
5
+
6
+ The improvements are meant to normalize behavior across different
7
+ platforms and environments, and to make filesystem access more
8
+ resilient to errors.
9
+
10
+ ## Improvements over [fs module](https://nodejs.org/api/fs.html)
11
+
12
+ * Queues up `open` and `readdir` calls, and retries them once
13
+ something closes if there is an EMFILE error from too many file
14
+ descriptors.
15
+ * fixes `lchmod` for Node versions prior to 0.6.2.
16
+ * implements `fs.lutimes` if possible. Otherwise it becomes a noop.
17
+ * ignores `EINVAL` and `EPERM` errors in `chown`, `fchown` or
18
+ `lchown` if the user isn't root.
19
+ * makes `lchmod` and `lchown` become noops, if not available.
20
+ * retries reading a file if `read` results in EAGAIN error.
21
+
22
+ On Windows, it retries renaming a file for up to one second if `EACCESS`
23
+ or `EPERM` error occurs, likely because antivirus software has locked
24
+ the directory.
25
+
26
+ ## USAGE
27
+
28
+ ```javascript
29
+ // use just like fs
30
+ var fs = require('graceful-fs')
31
+
32
+ // now go and do stuff with it...
33
+ fs.readFile('some-file-or-whatever', (err, data) => {
34
+ // Do stuff here.
35
+ })
36
+ ```
37
+
38
+ ## Sync methods
39
+
40
+ This module cannot intercept or handle `EMFILE` or `ENFILE` errors from sync
41
+ methods. If you use sync methods which open file descriptors then you are
42
+ responsible for dealing with any errors.
43
+
44
+ This is a known limitation, not a bug.
45
+
46
+ ## Global Patching
47
+
48
+ If you want to patch the global fs module (or any other fs-like
49
+ module) you can do this:
50
+
51
+ ```javascript
52
+ // Make sure to read the caveat below.
53
+ var realFs = require('fs')
54
+ var gracefulFs = require('graceful-fs')
55
+ gracefulFs.gracefulify(realFs)
56
+ ```
57
+
58
+ This should only ever be done at the top-level application layer, in
59
+ order to delay on EMFILE errors from any fs-using dependencies. You
60
+ should **not** do this in a library, because it can cause unexpected
61
+ delays in other parts of the program.
62
+
63
+ ## Changes
64
+
65
+ This module is fairly stable at this point, and used by a lot of
66
+ things. That being said, because it implements a subtle behavior
67
+ change in a core part of the node API, even modest changes can be
68
+ extremely breaking, and the versioning is thus biased towards
69
+ bumping the major when in doubt.
70
+
71
+ The main change between major versions has been switching between
72
+ providing a fully-patched `fs` module vs monkey-patching the node core
73
+ builtin, and the approach by which a non-monkey-patched `fs` was
74
+ created.
75
+
76
+ The goal is to trade `EMFILE` errors for slower fs operations. So, if
77
+ you try to open a zillion files, rather than crashing, `open`
78
+ operations will be queued up and wait for something else to `close`.
79
+
80
+ There are advantages to each approach. Monkey-patching the fs means
81
+ that no `EMFILE` errors can possibly occur anywhere in your
82
+ application, because everything is using the same core `fs` module,
83
+ which is patched. However, it can also obviously cause undesirable
84
+ side-effects, especially if the module is loaded multiple times.
85
+
86
+ Implementing a separate-but-identical patched `fs` module is more
87
+ surgical (and doesn't run the risk of patching multiple times), but
88
+ also imposes the challenge of keeping in sync with the core module.
89
+
90
+ The current approach loads the `fs` module, and then creates a
91
+ lookalike object that has all the same methods, except a few that are
92
+ patched. It is safe to use in all versions of Node from 0.8 through
93
+ 7.0.
94
+
95
+ ### v4
96
+
97
+ * Do not monkey-patch the fs module. This module may now be used as a
98
+ drop-in dep, and users can opt into monkey-patching the fs builtin
99
+ if their app requires it.
100
+
101
+ ### v3
102
+
103
+ * Monkey-patch fs, because the eval approach no longer works on recent
104
+ node.
105
+ * fixed possible type-error throw if rename fails on windows
106
+ * verify that we *never* get EMFILE errors
107
+ * Ignore ENOSYS from chmod/chown
108
+ * clarify that graceful-fs must be used as a drop-in
109
+
110
+ ### v2.1.0
111
+
112
+ * Use eval rather than monkey-patching fs.
113
+ * readdir: Always sort the results
114
+ * win32: requeue a file if error has an OK status
115
+
116
+ ### v2.0
117
+
118
+ * A return to monkey patching
119
+ * wrap process.cwd
120
+
121
+ ### v1.1
122
+
123
+ * wrap readFile
124
+ * Wrap fs.writeFile.
125
+ * readdir protection
126
+ * Don't clobber the fs builtin
127
+ * Handle fs.read EAGAIN errors by trying again
128
+ * Expose the curOpen counter
129
+ * No-op lchown/lchmod if not implemented
130
+ * fs.rename patch only for win32
131
+ * Patch fs.rename to handle AV software on Windows
132
+ * Close #4 Chown should not fail on einval or eperm if non-root
133
+ * Fix isaacs/fstream#1 Only wrap fs one time
134
+ * Fix #3 Start at 1024 max files, then back off on EMFILE
135
+ * lutimes that doens't blow up on Linux
136
+ * A full on-rewrite using a queue instead of just swallowing the EMFILE error
137
+ * Wrap Read/Write streams as well
138
+
139
+ ### 1.0
140
+
141
+ * Update engines for node 0.6
142
+ * Be lstat-graceful on Windows
143
+ * first
@@ -0,0 +1,23 @@
1
+ 'use strict'
2
+
3
+ module.exports = clone
4
+
5
+ var getPrototypeOf = Object.getPrototypeOf || function (obj) {
6
+ return obj.__proto__
7
+ }
8
+
9
+ function clone (obj) {
10
+ if (obj === null || typeof obj !== 'object')
11
+ return obj
12
+
13
+ if (obj instanceof Object)
14
+ var copy = { __proto__: getPrototypeOf(obj) }
15
+ else
16
+ var copy = Object.create(null)
17
+
18
+ Object.getOwnPropertyNames(obj).forEach(function (key) {
19
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
20
+ })
21
+
22
+ return copy
23
+ }