csquad 0.4.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShunL12324
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # C Squad
2
+
3
+ Run Claude Code and Codex as one team in your terminal. Tell Master what to do;
4
+ it recruits members, assigns tasks, and brings back their results. A tmux
5
+ workspace shows each member's terminal and a shared task board.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install -g csquad
11
+ csquad doctor
12
+ csquad start --name my-team --engine claude
13
+ ```
14
+
15
+ Use `--engine codex` for a Codex Master. You can also run `npx csquad`.
16
+
17
+ Supports macOS and Linux on x64 and arm64. On Windows, install and run inside
18
+ WSL 2. This package includes the native Go binaries: no compiler, install
19
+ scripts, or additional binary downloads are needed.
20
+
21
+ Install system dependencies first:
22
+
23
+ ```sh
24
+ # macOS
25
+ brew install tmux git
26
+
27
+ # Ubuntu / Debian / WSL 2
28
+ sudo apt install tmux procps git
29
+ ```
30
+
31
+ Install and sign in to Claude Code or Codex separately. Agents use your native
32
+ engine configuration and accounts. By default, C Squad bypasses native agent
33
+ permission prompts; this is configurable.
34
+
35
+ ## Update or remove
36
+
37
+ ```sh
38
+ npm install -g csquad@latest
39
+ npm uninstall -g csquad
40
+ ```
41
+
42
+ Stop teams before upgrading. Uninstalling preserves user configuration and
43
+ project recovery data. Use one installation channel to avoid conflicting
44
+ copies of `csquad` on PATH.
45
+
46
+ [Documentation and demo](https://github.com/ShunL12324/c-squad#readme) ·
47
+ [Installation and shell completion](https://github.com/ShunL12324/c-squad/blob/main/docs/usage.md)
48
+
49
+ MIT licensed. Independent of OpenAI and Anthropic.
package/bin/csquad ADDED
@@ -0,0 +1,30 @@
1
+ #!/bin/sh
2
+ # npm links this launcher into PATH. Resolve that link before locating binaries.
3
+ set -eu
4
+ launcher=$0
5
+ while [ -L "$launcher" ]; do
6
+ base=$(CDPATH= cd -P -- "$(dirname -- "$launcher")" && pwd)
7
+ target=$(readlink "$launcher")
8
+ case "$target" in
9
+ /*) launcher=$target ;;
10
+ *) launcher=$base/$target ;;
11
+ esac
12
+ done
13
+ base=$(CDPATH= cd -P -- "$(dirname -- "$launcher")" && pwd)
14
+ case "$(uname -s)" in
15
+ Darwin) platform=darwin ;;
16
+ Linux) platform=linux ;;
17
+ *) echo 'csquad: unsupported OS; on Windows, install inside WSL 2.' >&2; exit 1 ;;
18
+ esac
19
+ case "$(uname -m)" in
20
+ x86_64|amd64) arch=amd64 ;;
21
+ arm64|aarch64) arch=arm64 ;;
22
+ *) echo 'csquad: supported CPU architectures are x64 and arm64.' >&2; exit 1 ;;
23
+ esac
24
+ binary=$base/../native/$platform-$arch/csquad
25
+ if [ ! -x "$binary" ]; then
26
+ echo 'csquad: packaged binary is missing; reinstall with npm install -g csquad.' >&2
27
+ exit 1
28
+ fi
29
+ # Replace the launcher so the native CLI owns the terminal and receives signals.
30
+ exec "$binary" "$@"
@@ -0,0 +1,212 @@
1
+ #compdef csquad
2
+ compdef _csquad csquad
3
+
4
+ # zsh completion for csquad -*- shell-script -*-
5
+
6
+ __csquad_debug()
7
+ {
8
+ local file="$BASH_COMP_DEBUG_FILE"
9
+ if [[ -n ${file} ]]; then
10
+ echo "$*" >> "${file}"
11
+ fi
12
+ }
13
+
14
+ _csquad()
15
+ {
16
+ local shellCompDirectiveError=1
17
+ local shellCompDirectiveNoSpace=2
18
+ local shellCompDirectiveNoFileComp=4
19
+ local shellCompDirectiveFilterFileExt=8
20
+ local shellCompDirectiveFilterDirs=16
21
+ local shellCompDirectiveKeepOrder=32
22
+
23
+ local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
24
+ local -a completions
25
+
26
+ __csquad_debug "\n========= starting completion logic =========="
27
+ __csquad_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}"
28
+
29
+ # The user could have moved the cursor backwards on the command-line.
30
+ # We need to trigger completion from the $CURRENT location, so we need
31
+ # to truncate the command-line ($words) up to the $CURRENT location.
32
+ # (We cannot use $CURSOR as its value does not work when a command is an alias.)
33
+ words=("${=words[1,CURRENT]}")
34
+ __csquad_debug "Truncated words[*]: ${words[*]},"
35
+
36
+ lastParam=${words[-1]}
37
+ lastChar=${lastParam[-1]}
38
+ __csquad_debug "lastParam: ${lastParam}, lastChar: ${lastChar}"
39
+
40
+ # For zsh, when completing a flag with an = (e.g., csquad -n=<TAB>)
41
+ # completions must be prefixed with the flag
42
+ setopt local_options BASH_REMATCH
43
+ if [[ "${lastParam}" =~ '-.*=' ]]; then
44
+ # We are dealing with a flag with an =
45
+ flagPrefix="-P ${BASH_REMATCH}"
46
+ fi
47
+
48
+ # Prepare the command to obtain completions
49
+ requestComp="${words[1]} __complete ${words[2,-1]}"
50
+ if [ "${lastChar}" = "" ]; then
51
+ # If the last parameter is complete (there is a space following it)
52
+ # We add an extra empty parameter so we can indicate this to the go completion code.
53
+ __csquad_debug "Adding extra empty parameter"
54
+ requestComp="${requestComp} \"\""
55
+ fi
56
+
57
+ __csquad_debug "About to call: eval ${requestComp}"
58
+
59
+ # Use eval to handle any environment variables and such
60
+ out=$(eval ${requestComp} 2>/dev/null)
61
+ __csquad_debug "completion output: ${out}"
62
+
63
+ # Extract the directive integer following a : from the last line
64
+ local lastLine
65
+ while IFS='\n' read -r line; do
66
+ lastLine=${line}
67
+ done < <(printf "%s\n" "${out[@]}")
68
+ __csquad_debug "last line: ${lastLine}"
69
+
70
+ if [ "${lastLine[1]}" = : ]; then
71
+ directive=${lastLine[2,-1]}
72
+ # Remove the directive including the : and the newline
73
+ local suffix
74
+ (( suffix=${#lastLine}+2))
75
+ out=${out[1,-$suffix]}
76
+ else
77
+ # There is no directive specified. Leave $out as is.
78
+ __csquad_debug "No directive found. Setting do default"
79
+ directive=0
80
+ fi
81
+
82
+ __csquad_debug "directive: ${directive}"
83
+ __csquad_debug "completions: ${out}"
84
+ __csquad_debug "flagPrefix: ${flagPrefix}"
85
+
86
+ if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
87
+ __csquad_debug "Completion received error. Ignoring completions."
88
+ return
89
+ fi
90
+
91
+ local activeHelpMarker="_activeHelp_ "
92
+ local endIndex=${#activeHelpMarker}
93
+ local startIndex=$((${#activeHelpMarker}+1))
94
+ local hasActiveHelp=0
95
+ while IFS='\n' read -r comp; do
96
+ # Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
97
+ if [ "${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
98
+ __csquad_debug "ActiveHelp found: $comp"
99
+ comp="${comp[$startIndex,-1]}"
100
+ if [ -n "$comp" ]; then
101
+ compadd -x "${comp}"
102
+ __csquad_debug "ActiveHelp will need delimiter"
103
+ hasActiveHelp=1
104
+ fi
105
+
106
+ continue
107
+ fi
108
+
109
+ if [ -n "$comp" ]; then
110
+ # If requested, completions are returned with a description.
111
+ # The description is preceded by a TAB character.
112
+ # For zsh's _describe, we need to use a : instead of a TAB.
113
+ # We first need to escape any : as part of the completion itself.
114
+ comp=${comp//:/\\:}
115
+
116
+ local tab="$(printf '\t')"
117
+ comp=${comp//$tab/:}
118
+
119
+ __csquad_debug "Adding completion: ${comp}"
120
+ completions+=${comp}
121
+ lastComp=$comp
122
+ fi
123
+ done < <(printf "%s\n" "${out[@]}")
124
+
125
+ # Add a delimiter after the activeHelp statements, but only if:
126
+ # - there are completions following the activeHelp statements, or
127
+ # - file completion will be performed (so there will be choices after the activeHelp)
128
+ if [ $hasActiveHelp -eq 1 ]; then
129
+ if [ ${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
130
+ __csquad_debug "Adding activeHelp delimiter"
131
+ compadd -x "--"
132
+ hasActiveHelp=0
133
+ fi
134
+ fi
135
+
136
+ if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
137
+ __csquad_debug "Activating nospace."
138
+ noSpace="-S ''"
139
+ fi
140
+
141
+ if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
142
+ __csquad_debug "Activating keep order."
143
+ keepOrder="-V"
144
+ fi
145
+
146
+ if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
147
+ # File extension filtering
148
+ local filteringCmd
149
+ filteringCmd='_files'
150
+ for filter in ${completions[@]}; do
151
+ if [ ${filter[1]} != '*' ]; then
152
+ # zsh requires a glob pattern to do file filtering
153
+ filter="\*.$filter"
154
+ fi
155
+ filteringCmd+=" -g $filter"
156
+ done
157
+ filteringCmd+=" ${flagPrefix}"
158
+
159
+ __csquad_debug "File filtering command: $filteringCmd"
160
+ _arguments '*:filename:'"$filteringCmd"
161
+ elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
162
+ # File completion for directories only
163
+ local subdir
164
+ subdir="${completions[1]}"
165
+ if [ -n "$subdir" ]; then
166
+ __csquad_debug "Listing directories in $subdir"
167
+ pushd "${subdir}" >/dev/null 2>&1
168
+ else
169
+ __csquad_debug "Listing directories in ."
170
+ fi
171
+
172
+ local result
173
+ _arguments '*:dirname:_files -/'" ${flagPrefix}"
174
+ result=$?
175
+ if [ -n "$subdir" ]; then
176
+ popd >/dev/null 2>&1
177
+ fi
178
+ return $result
179
+ else
180
+ __csquad_debug "Calling _describe"
181
+ if eval _describe $keepOrder "completions" completions $flagPrefix $noSpace; then
182
+ __csquad_debug "_describe found some completions"
183
+
184
+ # Return the success of having called _describe
185
+ return 0
186
+ else
187
+ __csquad_debug "_describe did not find completions."
188
+ __csquad_debug "Checking if we should do file completion."
189
+ if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
190
+ __csquad_debug "deactivating file completion"
191
+
192
+ # We must return an error code here to let zsh know that there were no
193
+ # completions found by _describe; this is what will trigger other
194
+ # matching algorithms to attempt to find completions.
195
+ # For example zsh can match letters in the middle of words.
196
+ return 1
197
+ else
198
+ # Perform file completion
199
+ __csquad_debug "Activating file completion"
200
+
201
+ # We must return the result of this command, so it must be the
202
+ # last command, or else we must store its result to return it.
203
+ _arguments '*:filename:_files'" ${flagPrefix}"
204
+ fi
205
+ fi
206
+ fi
207
+ }
208
+
209
+ # don't run the completion function when being source-ed or eval-ed
210
+ if [ "$funcstack[1]" = "_csquad" ]; then
211
+ _csquad
212
+ fi
@@ -0,0 +1,426 @@
1
+ # bash completion V2 for csquad -*- shell-script -*-
2
+
3
+ __csquad_debug()
4
+ {
5
+ if [[ -n ${BASH_COMP_DEBUG_FILE-} ]]; then
6
+ echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
7
+ fi
8
+ }
9
+
10
+ # Macs have bash3 for which the bash-completion package doesn't include
11
+ # _init_completion. This is a minimal version of that function.
12
+ __csquad_init_completion()
13
+ {
14
+ COMPREPLY=()
15
+ _get_comp_words_by_ref "$@" cur prev words cword
16
+ }
17
+
18
+ # This function calls the csquad program to obtain the completion
19
+ # results and the directive. It fills the 'out' and 'directive' vars.
20
+ __csquad_get_completion_results() {
21
+ local requestComp lastParam lastChar args
22
+
23
+ # Prepare the command to request completions for the program.
24
+ # Calling ${words[0]} instead of directly csquad allows handling aliases
25
+ args=("${words[@]:1}")
26
+ requestComp="${words[0]} __complete ${args[*]}"
27
+
28
+ lastParam=${words[$((${#words[@]}-1))]}
29
+ lastChar=${lastParam:$((${#lastParam}-1)):1}
30
+ __csquad_debug "lastParam ${lastParam}, lastChar ${lastChar}"
31
+
32
+ if [[ -z ${cur} && ${lastChar} != = ]]; then
33
+ # If the last parameter is complete (there is a space following it)
34
+ # We add an extra empty parameter so we can indicate this to the go method.
35
+ __csquad_debug "Adding extra empty parameter"
36
+ requestComp="${requestComp} ''"
37
+ fi
38
+
39
+ # When completing a flag with an = (e.g., csquad -n=<TAB>)
40
+ # bash focuses on the part after the =, so we need to remove
41
+ # the flag part from $cur
42
+ if [[ ${cur} == -*=* ]]; then
43
+ cur="${cur#*=}"
44
+ fi
45
+
46
+ __csquad_debug "Calling ${requestComp}"
47
+ # Use eval to handle any environment variables and such
48
+ out=$(eval "${requestComp}" 2>/dev/null)
49
+
50
+ # Extract the directive integer at the very end of the output following a colon (:)
51
+ directive=${out##*:}
52
+ # Remove the directive
53
+ out=${out%:*}
54
+ if [[ ${directive} == "${out}" ]]; then
55
+ # There is not directive specified
56
+ directive=0
57
+ fi
58
+ __csquad_debug "The completion directive is: ${directive}"
59
+ __csquad_debug "The completions are: ${out}"
60
+ }
61
+
62
+ __csquad_process_completion_results() {
63
+ local shellCompDirectiveError=1
64
+ local shellCompDirectiveNoSpace=2
65
+ local shellCompDirectiveNoFileComp=4
66
+ local shellCompDirectiveFilterFileExt=8
67
+ local shellCompDirectiveFilterDirs=16
68
+ local shellCompDirectiveKeepOrder=32
69
+
70
+ if (((directive & shellCompDirectiveError) != 0)); then
71
+ # Error code. No completion.
72
+ __csquad_debug "Received error from custom completion go code"
73
+ return
74
+ else
75
+ if (((directive & shellCompDirectiveNoSpace) != 0)); then
76
+ if [[ $(type -t compopt) == builtin ]]; then
77
+ __csquad_debug "Activating no space"
78
+ compopt -o nospace
79
+ else
80
+ __csquad_debug "No space directive not supported in this version of bash"
81
+ fi
82
+ fi
83
+ if (((directive & shellCompDirectiveKeepOrder) != 0)); then
84
+ if [[ $(type -t compopt) == builtin ]]; then
85
+ # no sort isn't supported for bash less than < 4.4
86
+ if [[ ${BASH_VERSINFO[0]} -lt 4 || ( ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 4 ) ]]; then
87
+ __csquad_debug "No sort directive not supported in this version of bash"
88
+ else
89
+ __csquad_debug "Activating keep order"
90
+ compopt -o nosort
91
+ fi
92
+ else
93
+ __csquad_debug "No sort directive not supported in this version of bash"
94
+ fi
95
+ fi
96
+ if (((directive & shellCompDirectiveNoFileComp) != 0)); then
97
+ if [[ $(type -t compopt) == builtin ]]; then
98
+ __csquad_debug "Activating no file completion"
99
+ compopt +o default
100
+ else
101
+ __csquad_debug "No file completion directive not supported in this version of bash"
102
+ fi
103
+ fi
104
+ fi
105
+
106
+ # Separate activeHelp from normal completions
107
+ local completions=()
108
+ local activeHelp=()
109
+ __csquad_extract_activeHelp
110
+
111
+ if (((directive & shellCompDirectiveFilterFileExt) != 0)); then
112
+ # File extension filtering
113
+ local fullFilter="" filter filteringCmd
114
+
115
+ # Do not use quotes around the $completions variable or else newline
116
+ # characters will be kept.
117
+ for filter in ${completions[*]}; do
118
+ fullFilter+="$filter|"
119
+ done
120
+
121
+ filteringCmd="_filedir $fullFilter"
122
+ __csquad_debug "File filtering command: $filteringCmd"
123
+ $filteringCmd
124
+ elif (((directive & shellCompDirectiveFilterDirs) != 0)); then
125
+ # File completion for directories only
126
+
127
+ local subdir
128
+ subdir=${completions[0]}
129
+ if [[ -n $subdir ]]; then
130
+ __csquad_debug "Listing directories in $subdir"
131
+ pushd "$subdir" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return
132
+ else
133
+ __csquad_debug "Listing directories in ."
134
+ _filedir -d
135
+ fi
136
+ else
137
+ __csquad_handle_completion_types
138
+ fi
139
+
140
+ __csquad_handle_special_char "$cur" :
141
+ __csquad_handle_special_char "$cur" =
142
+
143
+ # Print the activeHelp statements before we finish
144
+ __csquad_handle_activeHelp
145
+ }
146
+
147
+ __csquad_handle_activeHelp() {
148
+ # Print the activeHelp statements
149
+ if ((${#activeHelp[*]} != 0)); then
150
+ if [ -z $COMP_TYPE ]; then
151
+ # Bash v3 does not set the COMP_TYPE variable.
152
+ printf "\n";
153
+ printf "%s\n" "${activeHelp[@]}"
154
+ printf "\n"
155
+ __csquad_reprint_commandLine
156
+ return
157
+ fi
158
+
159
+ # Only print ActiveHelp on the second TAB press
160
+ if [ $COMP_TYPE -eq 63 ]; then
161
+ printf "\n"
162
+ printf "%s\n" "${activeHelp[@]}"
163
+
164
+ if ((${#COMPREPLY[*]} == 0)); then
165
+ # When there are no completion choices from the program, file completion
166
+ # may kick in if the program has not disabled it; in such a case, we want
167
+ # to know if any files will match what the user typed, so that we know if
168
+ # there will be completions presented, so that we know how to handle ActiveHelp.
169
+ # To find out, we actually trigger the file completion ourselves;
170
+ # the call to _filedir will fill COMPREPLY if files match.
171
+ if (((directive & shellCompDirectiveNoFileComp) == 0)); then
172
+ __csquad_debug "Listing files"
173
+ _filedir
174
+ fi
175
+ fi
176
+
177
+ if ((${#COMPREPLY[*]} != 0)); then
178
+ # If there are completion choices to be shown, print a delimiter.
179
+ # Re-printing the command-line will automatically be done
180
+ # by the shell when it prints the completion choices.
181
+ printf -- "--"
182
+ else
183
+ # When there are no completion choices at all, we need
184
+ # to re-print the command-line since the shell will
185
+ # not be doing it itself.
186
+ __csquad_reprint_commandLine
187
+ fi
188
+ elif [ $COMP_TYPE -eq 37 ] || [ $COMP_TYPE -eq 42 ]; then
189
+ # For completion type: menu-complete/menu-complete-backward and insert-completions
190
+ # the completions are immediately inserted into the command-line, so we first
191
+ # print the activeHelp message and reprint the command-line since the shell won't.
192
+ printf "\n"
193
+ printf "%s\n" "${activeHelp[@]}"
194
+
195
+ __csquad_reprint_commandLine
196
+ fi
197
+ fi
198
+ }
199
+
200
+ __csquad_reprint_commandLine() {
201
+ # The prompt format is only available from bash 4.4.
202
+ # We test if it is available before using it.
203
+ if (x=${PS1@P}) 2> /dev/null; then
204
+ printf "%s" "${PS1@P}${COMP_LINE[@]}"
205
+ else
206
+ # Can't print the prompt. Just print the
207
+ # text the user had typed, it is workable enough.
208
+ printf "%s" "${COMP_LINE[@]}"
209
+ fi
210
+ }
211
+
212
+ # Separate activeHelp lines from real completions.
213
+ # Fills the $activeHelp and $completions arrays.
214
+ __csquad_extract_activeHelp() {
215
+ local activeHelpMarker="_activeHelp_ "
216
+ local endIndex=${#activeHelpMarker}
217
+
218
+ while IFS='' read -r comp; do
219
+ [[ -z $comp ]] && continue
220
+
221
+ if [[ ${comp:0:endIndex} == $activeHelpMarker ]]; then
222
+ comp=${comp:endIndex}
223
+ __csquad_debug "ActiveHelp found: $comp"
224
+ if [[ -n $comp ]]; then
225
+ activeHelp+=("$comp")
226
+ fi
227
+ else
228
+ # Not an activeHelp line but a normal completion
229
+ completions+=("$comp")
230
+ fi
231
+ done <<<"${out}"
232
+ }
233
+
234
+ __csquad_handle_completion_types() {
235
+ __csquad_debug "__csquad_handle_completion_types: COMP_TYPE is $COMP_TYPE"
236
+
237
+ case $COMP_TYPE in
238
+ 37|42)
239
+ # Type: menu-complete/menu-complete-backward and insert-completions
240
+ # If the user requested inserting one completion at a time, or all
241
+ # completions at once on the command-line we must remove the descriptions.
242
+ # https://github.com/spf13/cobra/issues/1508
243
+
244
+ # If there are no completions, we don't need to do anything
245
+ (( ${#completions[@]} == 0 )) && return 0
246
+
247
+ local tab=$'\t'
248
+
249
+ # Strip any description and escape the completion to handled special characters
250
+ IFS=$'\n' read -ra completions -d '' < <(printf "%q\n" "${completions[@]%%$tab*}")
251
+
252
+ # Only consider the completions that match
253
+ IFS=$'\n' read -ra COMPREPLY -d '' < <(IFS=$'\n'; compgen -W "${completions[*]}" -- "${cur}")
254
+
255
+ # compgen looses the escaping so we need to escape all completions again since they will
256
+ # all be inserted on the command-line.
257
+ IFS=$'\n' read -ra COMPREPLY -d '' < <(printf "%q\n" "${COMPREPLY[@]}")
258
+ ;;
259
+
260
+ *)
261
+ # Type: complete (normal completion)
262
+ __csquad_handle_standard_completion_case
263
+ ;;
264
+ esac
265
+ }
266
+
267
+ __csquad_handle_standard_completion_case() {
268
+ local tab=$'\t'
269
+
270
+ # If there are no completions, we don't need to do anything
271
+ (( ${#completions[@]} == 0 )) && return 0
272
+
273
+ # Short circuit to optimize if we don't have descriptions
274
+ if [[ "${completions[*]}" != *$tab* ]]; then
275
+ # First, escape the completions to handle special characters
276
+ IFS=$'\n' read -ra completions -d '' < <(printf "%q\n" "${completions[@]}")
277
+ # Only consider the completions that match what the user typed
278
+ IFS=$'\n' read -ra COMPREPLY -d '' < <(IFS=$'\n'; compgen -W "${completions[*]}" -- "${cur}")
279
+
280
+ # compgen looses the escaping so, if there is only a single completion, we need to
281
+ # escape it again because it will be inserted on the command-line. If there are multiple
282
+ # completions, we don't want to escape them because they will be printed in a list
283
+ # and we don't want to show escape characters in that list.
284
+ if (( ${#COMPREPLY[@]} == 1 )); then
285
+ COMPREPLY[0]=$(printf "%q" "${COMPREPLY[0]}")
286
+ fi
287
+ return 0
288
+ fi
289
+
290
+ local longest=0
291
+ local compline
292
+ # Look for the longest completion so that we can format things nicely
293
+ while IFS='' read -r compline; do
294
+ [[ -z $compline ]] && continue
295
+
296
+ # Before checking if the completion matches what the user typed,
297
+ # we need to strip any description and escape the completion to handle special
298
+ # characters because those escape characters are part of what the user typed.
299
+ # Don't call "printf" in a sub-shell because it will be much slower
300
+ # since we are in a loop.
301
+ printf -v comp "%q" "${compline%%$tab*}" &>/dev/null || comp=$(printf "%q" "${compline%%$tab*}")
302
+
303
+ # Only consider the completions that match
304
+ [[ $comp == "$cur"* ]] || continue
305
+
306
+ # The completions matches. Add it to the list of full completions including
307
+ # its description. We don't escape the completion because it may get printed
308
+ # in a list if there are more than one and we don't want show escape characters
309
+ # in that list.
310
+ COMPREPLY+=("$compline")
311
+
312
+ # Strip any description before checking the length, and again, don't escape
313
+ # the completion because this length is only used when printing the completions
314
+ # in a list and we don't want show escape characters in that list.
315
+ comp=${compline%%$tab*}
316
+ if ((${#comp}>longest)); then
317
+ longest=${#comp}
318
+ fi
319
+ done < <(printf "%s\n" "${completions[@]}")
320
+
321
+ # If there is a single completion left, remove the description text and escape any special characters
322
+ if ((${#COMPREPLY[*]} == 1)); then
323
+ __csquad_debug "COMPREPLY[0]: ${COMPREPLY[0]}"
324
+ COMPREPLY[0]=$(printf "%q" "${COMPREPLY[0]%%$tab*}")
325
+ __csquad_debug "Removed description from single completion, which is now: ${COMPREPLY[0]}"
326
+ else
327
+ # Format the descriptions
328
+ __csquad_format_comp_descriptions $longest
329
+ fi
330
+ }
331
+
332
+ __csquad_handle_special_char()
333
+ {
334
+ local comp="$1"
335
+ local char=$2
336
+ if [[ "$comp" == *${char}* && "$COMP_WORDBREAKS" == *${char}* ]]; then
337
+ local word=${comp%"${comp##*${char}}"}
338
+ local idx=${#COMPREPLY[*]}
339
+ while ((--idx >= 0)); do
340
+ COMPREPLY[idx]=${COMPREPLY[idx]#"$word"}
341
+ done
342
+ fi
343
+ }
344
+
345
+ __csquad_format_comp_descriptions()
346
+ {
347
+ local tab=$'\t'
348
+ local comp desc maxdesclength
349
+ local longest=$1
350
+
351
+ local i ci
352
+ for ci in ${!COMPREPLY[*]}; do
353
+ comp=${COMPREPLY[ci]}
354
+ # Properly format the description string which follows a tab character if there is one
355
+ if [[ "$comp" == *$tab* ]]; then
356
+ __csquad_debug "Original comp: $comp"
357
+ desc=${comp#*$tab}
358
+ comp=${comp%%$tab*}
359
+
360
+ # $COLUMNS stores the current shell width.
361
+ # Remove an extra 4 because we add 2 spaces and 2 parentheses.
362
+ maxdesclength=$(( COLUMNS - longest - 4 ))
363
+
364
+ # Make sure we can fit a description of at least 8 characters
365
+ # if we are to align the descriptions.
366
+ if ((maxdesclength > 8)); then
367
+ # Add the proper number of spaces to align the descriptions
368
+ for ((i = ${#comp} ; i < longest ; i++)); do
369
+ comp+=" "
370
+ done
371
+ else
372
+ # Don't pad the descriptions so we can fit more text after the completion
373
+ maxdesclength=$(( COLUMNS - ${#comp} - 4 ))
374
+ fi
375
+
376
+ # If there is enough space for any description text,
377
+ # truncate the descriptions that are too long for the shell width
378
+ if ((maxdesclength > 0)); then
379
+ if ((${#desc} > maxdesclength)); then
380
+ desc=${desc:0:$(( maxdesclength - 1 ))}
381
+ desc+="…"
382
+ fi
383
+ comp+=" ($desc)"
384
+ fi
385
+ COMPREPLY[ci]=$comp
386
+ __csquad_debug "Final comp: $comp"
387
+ fi
388
+ done
389
+ }
390
+
391
+ __start_csquad()
392
+ {
393
+ local cur prev words cword split
394
+
395
+ COMPREPLY=()
396
+
397
+ # Call _init_completion from the bash-completion package
398
+ # to prepare the arguments properly
399
+ if declare -F _init_completion >/dev/null 2>&1; then
400
+ _init_completion -n =: || return
401
+ else
402
+ __csquad_init_completion -n =: || return
403
+ fi
404
+
405
+ __csquad_debug
406
+ __csquad_debug "========= starting completion logic =========="
407
+ __csquad_debug "cur is ${cur}, words[*] is ${words[*]}, #words[@] is ${#words[@]}, cword is $cword"
408
+
409
+ # The user could have moved the cursor backwards on the command-line.
410
+ # We need to trigger completion from the $cword location, so we need
411
+ # to truncate the command-line ($words) up to the $cword location.
412
+ words=("${words[@]:0:$cword+1}")
413
+ __csquad_debug "Truncated words[*]: ${words[*]},"
414
+
415
+ local out directive
416
+ __csquad_get_completion_results
417
+ __csquad_process_completion_results
418
+ }
419
+
420
+ if [[ $(type -t compopt) = "builtin" ]]; then
421
+ complete -o default -F __start_csquad csquad
422
+ else
423
+ complete -o default -o nospace -F __start_csquad csquad
424
+ fi
425
+
426
+ # ex: ts=4 sw=4 et filetype=sh
@@ -0,0 +1,235 @@
1
+ # fish completion for csquad -*- shell-script -*-
2
+
3
+ function __csquad_debug
4
+ set -l file "$BASH_COMP_DEBUG_FILE"
5
+ if test -n "$file"
6
+ echo "$argv" >> $file
7
+ end
8
+ end
9
+
10
+ function __csquad_perform_completion
11
+ __csquad_debug "Starting __csquad_perform_completion"
12
+
13
+ # Extract all args except the last one
14
+ set -l args (commandline -opc)
15
+ # Extract the last arg and escape it in case it is a space
16
+ set -l lastArg (string escape -- (commandline -ct))
17
+
18
+ __csquad_debug "args: $args"
19
+ __csquad_debug "last arg: $lastArg"
20
+
21
+ # Disable ActiveHelp which is not supported for fish shell
22
+ set -l requestComp "CSQUAD_ACTIVE_HELP=0 $args[1] __complete $args[2..-1] $lastArg"
23
+
24
+ __csquad_debug "Calling $requestComp"
25
+ set -l results (eval $requestComp 2> /dev/null)
26
+
27
+ # Some programs may output extra empty lines after the directive.
28
+ # Let's ignore them or else it will break completion.
29
+ # Ref: https://github.com/spf13/cobra/issues/1279
30
+ for line in $results[-1..1]
31
+ if test (string trim -- $line) = ""
32
+ # Found an empty line, remove it
33
+ set results $results[1..-2]
34
+ else
35
+ # Found non-empty line, we have our proper output
36
+ break
37
+ end
38
+ end
39
+
40
+ set -l comps $results[1..-2]
41
+ set -l directiveLine $results[-1]
42
+
43
+ # For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
44
+ # completions must be prefixed with the flag
45
+ set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
46
+
47
+ __csquad_debug "Comps: $comps"
48
+ __csquad_debug "DirectiveLine: $directiveLine"
49
+ __csquad_debug "flagPrefix: $flagPrefix"
50
+
51
+ for comp in $comps
52
+ printf "%s%s\n" "$flagPrefix" "$comp"
53
+ end
54
+
55
+ printf "%s\n" "$directiveLine"
56
+ end
57
+
58
+ # this function limits calls to __csquad_perform_completion, by caching the result behind $__csquad_perform_completion_once_result
59
+ function __csquad_perform_completion_once
60
+ __csquad_debug "Starting __csquad_perform_completion_once"
61
+
62
+ if test -n "$__csquad_perform_completion_once_result"
63
+ __csquad_debug "Seems like a valid result already exists, skipping __csquad_perform_completion"
64
+ return 0
65
+ end
66
+
67
+ set --global __csquad_perform_completion_once_result (__csquad_perform_completion)
68
+ if test -z "$__csquad_perform_completion_once_result"
69
+ __csquad_debug "No completions, probably due to a failure"
70
+ return 1
71
+ end
72
+
73
+ __csquad_debug "Performed completions and set __csquad_perform_completion_once_result"
74
+ return 0
75
+ end
76
+
77
+ # this function is used to clear the $__csquad_perform_completion_once_result variable after completions are run
78
+ function __csquad_clear_perform_completion_once_result
79
+ __csquad_debug ""
80
+ __csquad_debug "========= clearing previously set __csquad_perform_completion_once_result variable =========="
81
+ set --erase __csquad_perform_completion_once_result
82
+ __csquad_debug "Successfully erased the variable __csquad_perform_completion_once_result"
83
+ end
84
+
85
+ function __csquad_requires_order_preservation
86
+ __csquad_debug ""
87
+ __csquad_debug "========= checking if order preservation is required =========="
88
+
89
+ __csquad_perform_completion_once
90
+ if test -z "$__csquad_perform_completion_once_result"
91
+ __csquad_debug "Error determining if order preservation is required"
92
+ return 1
93
+ end
94
+
95
+ set -l directive (string sub --start 2 $__csquad_perform_completion_once_result[-1])
96
+ __csquad_debug "Directive is: $directive"
97
+
98
+ set -l shellCompDirectiveKeepOrder 32
99
+ set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
100
+ __csquad_debug "Keeporder is: $keeporder"
101
+
102
+ if test $keeporder -ne 0
103
+ __csquad_debug "This does require order preservation"
104
+ return 0
105
+ end
106
+
107
+ __csquad_debug "This doesn't require order preservation"
108
+ return 1
109
+ end
110
+
111
+
112
+ # This function does two things:
113
+ # - Obtain the completions and store them in the global __csquad_comp_results
114
+ # - Return false if file completion should be performed
115
+ function __csquad_prepare_completions
116
+ __csquad_debug ""
117
+ __csquad_debug "========= starting completion logic =========="
118
+
119
+ # Start fresh
120
+ set --erase __csquad_comp_results
121
+
122
+ __csquad_perform_completion_once
123
+ __csquad_debug "Completion results: $__csquad_perform_completion_once_result"
124
+
125
+ if test -z "$__csquad_perform_completion_once_result"
126
+ __csquad_debug "No completion, probably due to a failure"
127
+ # Might as well do file completion, in case it helps
128
+ return 1
129
+ end
130
+
131
+ set -l directive (string sub --start 2 $__csquad_perform_completion_once_result[-1])
132
+ set --global __csquad_comp_results $__csquad_perform_completion_once_result[1..-2]
133
+
134
+ __csquad_debug "Completions are: $__csquad_comp_results"
135
+ __csquad_debug "Directive is: $directive"
136
+
137
+ set -l shellCompDirectiveError 1
138
+ set -l shellCompDirectiveNoSpace 2
139
+ set -l shellCompDirectiveNoFileComp 4
140
+ set -l shellCompDirectiveFilterFileExt 8
141
+ set -l shellCompDirectiveFilterDirs 16
142
+
143
+ if test -z "$directive"
144
+ set directive 0
145
+ end
146
+
147
+ set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
148
+ if test $compErr -eq 1
149
+ __csquad_debug "Received error directive: aborting."
150
+ # Might as well do file completion, in case it helps
151
+ return 1
152
+ end
153
+
154
+ set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
155
+ set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
156
+ if test $filefilter -eq 1; or test $dirfilter -eq 1
157
+ __csquad_debug "File extension filtering or directory filtering not supported"
158
+ # Do full file completion instead
159
+ return 1
160
+ end
161
+
162
+ set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
163
+ set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
164
+
165
+ __csquad_debug "nospace: $nospace, nofiles: $nofiles"
166
+
167
+ # If we want to prevent a space, or if file completion is NOT disabled,
168
+ # we need to count the number of valid completions.
169
+ # To do so, we will filter on prefix as the completions we have received
170
+ # may not already be filtered so as to allow fish to match on different
171
+ # criteria than the prefix.
172
+ if test $nospace -ne 0; or test $nofiles -eq 0
173
+ set -l prefix (commandline -t | string escape --style=regex)
174
+ __csquad_debug "prefix: $prefix"
175
+
176
+ set -l completions (string match -r -- "^$prefix.*" $__csquad_comp_results)
177
+ set --global __csquad_comp_results $completions
178
+ __csquad_debug "Filtered completions are: $__csquad_comp_results"
179
+
180
+ # Important not to quote the variable for count to work
181
+ set -l numComps (count $__csquad_comp_results)
182
+ __csquad_debug "numComps: $numComps"
183
+
184
+ if test $numComps -eq 1; and test $nospace -ne 0
185
+ # We must first split on \t to get rid of the descriptions to be
186
+ # able to check what the actual completion will be.
187
+ # We don't need descriptions anyway since there is only a single
188
+ # real completion which the shell will expand immediately.
189
+ set -l split (string split --max 1 \t $__csquad_comp_results[1])
190
+
191
+ # Fish won't add a space if the completion ends with any
192
+ # of the following characters: @=/:.,
193
+ set -l lastChar (string sub -s -1 -- $split)
194
+ if not string match -r -q "[@=/:.,]" -- "$lastChar"
195
+ # In other cases, to support the "nospace" directive we trick the shell
196
+ # by outputting an extra, longer completion.
197
+ __csquad_debug "Adding second completion to perform nospace directive"
198
+ set --global __csquad_comp_results $split[1] $split[1].
199
+ __csquad_debug "Completions are now: $__csquad_comp_results"
200
+ end
201
+ end
202
+
203
+ if test $numComps -eq 0; and test $nofiles -eq 0
204
+ # To be consistent with bash and zsh, we only trigger file
205
+ # completion when there are no other completions
206
+ __csquad_debug "Requesting file completion"
207
+ return 1
208
+ end
209
+ end
210
+
211
+ return 0
212
+ end
213
+
214
+ # Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
215
+ # so we can properly delete any completions provided by another script.
216
+ # Only do this if the program can be found, or else fish may print some errors; besides,
217
+ # the existing completions will only be loaded if the program can be found.
218
+ if type -q "csquad"
219
+ # The space after the program name is essential to trigger completion for the program
220
+ # and not completion of the program name itself.
221
+ # Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
222
+ complete --do-complete "csquad " > /dev/null 2>&1
223
+ end
224
+
225
+ # Remove any pre-existing completions for the program since we will be handling all of them.
226
+ complete -c csquad -e
227
+
228
+ # this will get called after the two calls below and clear the $__csquad_perform_completion_once_result global
229
+ complete -c csquad -n '__csquad_clear_perform_completion_once_result'
230
+ # The call to __csquad_prepare_completions will setup __csquad_comp_results
231
+ # which provides the program's completion choices.
232
+ # If this doesn't require order preservation, we don't use the -k flag
233
+ complete -c csquad -n 'not __csquad_requires_order_preservation && __csquad_prepare_completions' -f -a '$__csquad_comp_results'
234
+ # otherwise we use the -k flag
235
+ complete -k -c csquad -n '__csquad_requires_order_preservation && __csquad_prepare_completions' -f -a '$__csquad_comp_results'
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "csquad",
3
+ "version": "0.4.0",
4
+ "description": "Coordinate Claude Code and Codex teams in tmux",
5
+ "license": "MIT",
6
+ "author": "ShunL12324",
7
+ "homepage": "https://github.com/ShunL12324/c-squad#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ShunL12324/c-squad.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/ShunL12324/c-squad/issues"
14
+ },
15
+ "keywords": [
16
+ "claude-code",
17
+ "codex",
18
+ "agents",
19
+ "tmux",
20
+ "cli"
21
+ ],
22
+ "bin": {
23
+ "csquad": "bin/csquad"
24
+ },
25
+ "os": [
26
+ "darwin",
27
+ "linux"
28
+ ],
29
+ "cpu": [
30
+ "x64",
31
+ "arm64"
32
+ ],
33
+ "files": [
34
+ "bin/",
35
+ "native/",
36
+ "completions/",
37
+ "LICENSE",
38
+ "README.md"
39
+ ],
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "registry": "https://registry.npmjs.org/"
43
+ }
44
+ }