teamsmith 0.2.0 → 0.3.1

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 (163) hide show
  1. package/README.md +4 -4
  2. package/package.json +1 -1
  3. package/skills/teamsmith/CHANGELOG.md +69 -0
  4. package/skills/teamsmith/SKILL.md +20 -13
  5. package/skills/teamsmith/extension/team-inbox-watch.ts +5 -3
  6. package/skills/teamsmith/extension/team-notify.ts +37 -6
  7. package/skills/teamsmith/extension/team.ts +438 -0
  8. package/skills/teamsmith/references/config.md +39 -6
  9. package/skills/teamsmith/references/migration.md +197 -47
  10. package/skills/teamsmith/references/protocol.md +201 -30
  11. package/skills/teamsmith/references/troubleshooting.md +130 -10
  12. package/skills/teamsmith/references/workflows.md +36 -2
  13. package/skills/teamsmith/scripts/lib/cmd-agents.sh +318 -23
  14. package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +2 -2
  15. package/skills/teamsmith/scripts/lib/cmd-config.sh +349 -67
  16. package/skills/teamsmith/scripts/lib/cmd-draft.sh +4 -4
  17. package/skills/teamsmith/scripts/lib/cmd-help.sh +677 -0
  18. package/skills/teamsmith/scripts/lib/cmd-init.sh +157 -5
  19. package/skills/teamsmith/scripts/lib/cmd-interrupt.sh +461 -0
  20. package/skills/teamsmith/scripts/lib/cmd-meeting.sh +2 -25
  21. package/skills/teamsmith/scripts/lib/cmd-project.sh +30 -103
  22. package/skills/teamsmith/scripts/lib/cmd-reap.sh +277 -0
  23. package/skills/teamsmith/scripts/lib/cmd-reply.sh +3 -3
  24. package/skills/teamsmith/scripts/lib/cmd-review.sh +182 -32
  25. package/skills/teamsmith/scripts/lib/cmd-status.sh +234 -21
  26. package/skills/teamsmith/scripts/lib/cmd-update.sh +36 -7
  27. package/skills/teamsmith/scripts/lib/cmd-watch.sh +564 -46
  28. package/skills/teamsmith/scripts/lib/common.sh +1004 -245
  29. package/skills/teamsmith/scripts/lib/gate-lock.sh +582 -0
  30. package/skills/teamsmith/scripts/panel/draft-send.sh +11 -1
  31. package/skills/teamsmith/scripts/panel/panel.js +211 -211
  32. package/skills/teamsmith/scripts/panel/src/App.tsx +58 -21
  33. package/skills/teamsmith/scripts/panel/src/clipboard.ts +12 -5
  34. package/skills/teamsmith/scripts/panel/src/compose.ts +6 -3
  35. package/skills/teamsmith/scripts/panel/src/data.ts +51 -5
  36. package/skills/teamsmith/scripts/panel/src/layout.ts +209 -69
  37. package/skills/teamsmith/scripts/panel/src/main.tsx +37 -8
  38. package/skills/teamsmith/scripts/panel/src/strings/en.ts +39 -29
  39. package/skills/teamsmith/scripts/panel/src/strings/zh.ts +41 -31
  40. package/skills/teamsmith/scripts/panel/src/types.ts +28 -3
  41. package/skills/teamsmith/scripts/replies.mjs +4 -1
  42. package/skills/teamsmith/scripts/shim/killall +10 -0
  43. package/skills/teamsmith/scripts/shim/pgrep +10 -0
  44. package/skills/teamsmith/scripts/shim/pidof +10 -0
  45. package/skills/teamsmith/scripts/shim/pkill +10 -0
  46. package/skills/teamsmith/scripts/shim/signal-gate +108 -31
  47. package/skills/teamsmith/scripts/shim/tmux +18 -0
  48. package/skills/teamsmith/scripts/strings/commands.tsv +86 -0
  49. package/skills/teamsmith/scripts/strings/help.en.tsv +503 -0
  50. package/skills/teamsmith/scripts/strings/help.zh.tsv +489 -0
  51. package/skills/teamsmith/scripts/team +19 -6
  52. package/skills/teamsmith/templates/AGENTS.section.md.tmpl +8 -1
  53. package/skills/teamsmith/templates/config.sh.tmpl +20 -1
  54. package/skills/teamsmith/templates/pm-prompt.md.tmpl +21 -0
  55. package/skills/teamsmith/tests/README.md +31 -0
  56. package/skills/teamsmith/tests/bg-ledger-harness.mjs +464 -40
  57. package/skills/teamsmith/tests/bg-ledger.sh +168 -10
  58. package/skills/teamsmith/tests/checkout-shape-probe.sh +83 -54
  59. package/skills/teamsmith/tests/config-cli.sh +184 -32
  60. package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +7 -1
  61. package/skills/teamsmith/tests/fixtures/p287/lint-good.sh.in +3 -0
  62. package/skills/teamsmith/tests/fixtures/p287/lint-hardcoded.sh.in +3 -0
  63. package/skills/teamsmith/tests/fixtures/p287/lint-no-ns.sh.in +3 -0
  64. package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +18 -6
  65. package/skills/teamsmith/tests/flip-m33.sh +5 -3
  66. package/skills/teamsmith/tests/flip-p158.sh +2 -1
  67. package/skills/teamsmith/tests/flip-p308-skip-not-pass.sh +151 -0
  68. package/skills/teamsmith/tests/flip-p310-lock.sh +210 -0
  69. package/skills/teamsmith/tests/flip-p310-socket.sh +125 -0
  70. package/skills/teamsmith/tests/gate-guard.sh +52 -79
  71. package/skills/teamsmith/tests/help-surface.sh +1664 -0
  72. package/skills/teamsmith/tests/install-shape.sh +359 -22
  73. package/skills/teamsmith/tests/key-replies-pty.sh +9 -10
  74. package/skills/teamsmith/tests/key-replies-ui.sh +2 -8
  75. package/skills/teamsmith/tests/key-replies.sh +281 -28
  76. package/skills/teamsmith/tests/ledger-ban.sh +5 -4
  77. package/skills/teamsmith/tests/ledger-claim.sh +2 -1
  78. package/skills/teamsmith/tests/lib/bounded-spin.sh +90 -0
  79. package/skills/teamsmith/tests/lib/model-policy.sh +4 -0
  80. package/skills/teamsmith/tests/lib/model-routing-flips.py +51 -0
  81. package/skills/teamsmith/tests/lib/pty-wait.sh +21 -111
  82. package/skills/teamsmith/tests/lib/reply-fixture.sh +4 -9
  83. package/skills/teamsmith/tests/lib/section-guard.sh +316 -164
  84. package/skills/teamsmith/tests/lib/tmp-root.sh +139 -27
  85. package/skills/teamsmith/tests/lib/tmux-cap.sh +10 -1
  86. package/skills/teamsmith/tests/lib/tmux-iso.sh +31 -13
  87. package/skills/teamsmith/tests/loop-inventory.tsv +83 -77
  88. package/skills/teamsmith/tests/panel-b2.sh +430 -352
  89. package/skills/teamsmith/tests/panel-b3-stub.sh +112 -4
  90. package/skills/teamsmith/tests/panel-b3.sh +314 -62
  91. package/skills/teamsmith/tests/panel-choices.sh +11 -6
  92. package/skills/teamsmith/tests/panel-cpu.sh +43 -130
  93. package/skills/teamsmith/tests/panel-p21.sh +251 -265
  94. package/skills/teamsmith/tests/panel-snapshots.sh +41 -225
  95. package/skills/teamsmith/tests/panel-strings.mjs +33 -18
  96. package/skills/teamsmith/tests/perf.sh +187 -396
  97. package/skills/teamsmith/tests/routes.sh +440 -117
  98. package/skills/teamsmith/tests/seat-interrupt.sh +1012 -0
  99. package/skills/teamsmith/tests/seat-visibility.sh +675 -0
  100. package/skills/teamsmith/tests/section-guard.sh +13 -102
  101. package/skills/teamsmith/tests/section-needs-audit.sh +24 -7
  102. package/skills/teamsmith/tests/section-paths.tsv +32 -18
  103. package/skills/teamsmith/tests/section-select.sh +371 -19
  104. package/skills/teamsmith/tests/signal-gate.sh +249 -27
  105. package/skills/teamsmith/tests/signal-lint-legacy.txt +4 -1
  106. package/skills/teamsmith/tests/slash-team-e2e.sh +323 -0
  107. package/skills/teamsmith/tests/slash-team.sh +617 -0
  108. package/skills/teamsmith/tests/slice-coverage.sh +206 -0
  109. package/skills/teamsmith/tests/smoke.sh +3595 -788
  110. package/skills/teamsmith/tests/task-model-routing.sh +530 -15
  111. package/skills/teamsmith/tests/team-bg-stop.sh +18 -10
  112. package/skills/teamsmith/tests/tmp-hygiene.sh +782 -45
  113. package/skills/teamsmith/tests/tmux-identity-leak.sh +773 -0
  114. package/skills/teamsmith/tests/tmux-lint-legacy.txt +12 -18
  115. package/skills/teamsmith/tests/upgrade-recipe.sh +537 -0
  116. package/skills/teamsmith/tests/workflow-entry.sh +207 -0
  117. package/skills/teamsmith-init/SKILL.md +12 -12
  118. package/skills/teamsmith-init/references/bootstrap.md +3 -3
  119. package/skills/teamsmith/tests/flip-glue.sh +0 -162
  120. package/skills/teamsmith/tests/flip-m12-26c.sh +0 -129
  121. package/skills/teamsmith/tests/flip-m12.sh +0 -185
  122. package/skills/teamsmith/tests/flip-m16.sh +0 -166
  123. package/skills/teamsmith/tests/flip-m17.sh +0 -204
  124. package/skills/teamsmith/tests/flip-m34.sh +0 -96
  125. package/skills/teamsmith/tests/flip-m37.sh +0 -185
  126. package/skills/teamsmith/tests/flip-m4.3.sh +0 -375
  127. package/skills/teamsmith/tests/flip-m43.sh +0 -128
  128. package/skills/teamsmith/tests/flip-m45.sh +0 -244
  129. package/skills/teamsmith/tests/flip-m46.sh +0 -238
  130. package/skills/teamsmith/tests/flip-m48.sh +0 -304
  131. package/skills/teamsmith/tests/flip-m6.2.sh +0 -205
  132. package/skills/teamsmith/tests/flip-m6.3.sh +0 -283
  133. package/skills/teamsmith/tests/flip-m6.4.sh +0 -267
  134. package/skills/teamsmith/tests/flip-m6.5.sh +0 -113
  135. package/skills/teamsmith/tests/flip-m7.1.sh +0 -135
  136. package/skills/teamsmith/tests/flip-m7.2.sh +0 -321
  137. package/skills/teamsmith/tests/flip-p144.sh +0 -112
  138. package/skills/teamsmith/tests/flip-p156.sh +0 -133
  139. package/skills/teamsmith/tests/flip-p160.sh +0 -182
  140. package/skills/teamsmith/tests/flip-p171.sh +0 -249
  141. package/skills/teamsmith/tests/flip-p18.1.sh +0 -95
  142. package/skills/teamsmith/tests/flip-p20.sh +0 -286
  143. package/skills/teamsmith/tests/flip-p201.sh +0 -249
  144. package/skills/teamsmith/tests/flip-p210.sh +0 -239
  145. package/skills/teamsmith/tests/flip-p211.sh +0 -152
  146. package/skills/teamsmith/tests/flip-p217.sh +0 -288
  147. package/skills/teamsmith/tests/flip-p22.sh +0 -123
  148. package/skills/teamsmith/tests/flip-p23.sh +0 -239
  149. package/skills/teamsmith/tests/flip-p25.sh +0 -165
  150. package/skills/teamsmith/tests/flip-p71.sh +0 -184
  151. package/skills/teamsmith/tests/flip-p72.sh +0 -202
  152. package/skills/teamsmith/tests/load-experiment.sh +0 -290
  153. package/skills/teamsmith/tests/panel-cpu-premise.sh +0 -173
  154. package/skills/teamsmith/tests/panel-flip-m54.sh +0 -207
  155. package/skills/teamsmith/tests/panel-flip-p123.sh +0 -278
  156. package/skills/teamsmith/tests/panel-flip-p125.sh +0 -318
  157. package/skills/teamsmith/tests/panel-flip-p128.sh +0 -259
  158. package/skills/teamsmith/tests/panel-keyprobe-stub.sh +0 -41
  159. package/skills/teamsmith/tests/panel-keyprobe.sh +0 -82
  160. package/skills/teamsmith/tests/panel-knobs.sh +0 -83
  161. package/skills/teamsmith/tests/section-budgets.tsv +0 -154
  162. package/skills/teamsmith/tests/team-bg-flip.sh +0 -239
  163. package/skills/teamsmith/tests/team-inbox-watch-flip.sh +0 -191
@@ -0,0 +1,677 @@
1
+ #!/usr/bin/env bash
2
+ # teamsmith · the help surface (change: cli-help · help-surface#The help surface is a level-0 menu…)
3
+ #
4
+ # One renderer for three levels: the level-0 menu, a group page (level 1) and a command page
5
+ # (level 2). Everything it prints comes from the command manifest (scripts/strings/commands.tsv) and
6
+ # the two parallel prose tables (scripts/strings/help.<lang>.tsv) — there is no second source.
7
+ #
8
+ # team_help_route <explicit-help> [argv…] the routing `scripts/team` calls before the contract is read
9
+ # team_help_menu level 0: what teamsmith is, the groups, a beginner set
10
+ # team_help_group_page <id> level 1: one group's commands
11
+ # team_help_command_page <name> [<asked>] level 2: one command's own page
12
+ #
13
+ # Layout: a fixed ladder, enforced here and checked by tests/help-surface.sh —
14
+ # 0 headers (`── <title> ──…`) and the lead lines of a fragment
15
+ # 2 a command usage line (an entry)
16
+ # 4 a wrapped usage continuation
17
+ # 6 a command's description block (hanging: every line in the column of the first)
18
+ # 10 an argument's flag column, an example block
19
+ # 32 an argument's description column (the only level deeper than ten; continuations align here)
20
+ # 14 a concept name
21
+ # 28 a concept's definition column
22
+ # Wrapping is done here, never by hand; a continuation is never shallower than the line it continues.
23
+ # Width: 100 display cells (a CJK-wide character counts two); TEAM_HELP_WIDTH overrides it, and an
24
+ # invalid value prints one warning and falls back. Both knobs are read from the environment only —
25
+ # the help paths never load the project contract, so they work in a directory that is not a project.
26
+
27
+ TEAM_HELP_DEFAULT_WIDTH=100
28
+ TEAM_HELP_ARG_COL=32
29
+ TEAM_HELP_TERM_COL=28
30
+ # The condition token a `needs-yes:<condition>` authorization may carry (closed set).
31
+ TEAM_HELP_AUTH_CONDITIONS="TEAM_CONFIRM_WRITES"
32
+
33
+ # The closed placeholder set: interpolation into the prose goes through these and nothing else.
34
+ # Every member has a substitution site in this file — {project} and {meeting_ttl} in team_help_subst,
35
+ # {token}/{sub}/{cmd} in team_help_refuse and in the alias line, {undo_cmd} in team_help_undo_text.
36
+ # `{effect}` and `{faces}` are deliberately NOT here: the claim sentence is composed in bash
37
+ # (team_help_effect_text + team_help_face_list), no code path substitutes them, and declaring a
38
+ # placeholder nothing resolves would let a value print it literally and still pass the check below.
39
+ # A `{…}` token outside this set would be printed literally, so a table carrying one is a defect
40
+ # rather than a rendering — and the set must not drift the other way either: a placeholder no table
41
+ # mentions is a claim the surface does not keep. Both directions are checked in team_help_load.
42
+ TEAM_HELP_PLACEHOLDERS="{project} {meeting_ttl} {token} {sub} {cmd} {undo_cmd}"
43
+
44
+ # ---------------------------------------------------------------- display width
45
+ # Locale-independent by construction: one read pinned to LC_ALL=C gives the raw bytes, and the
46
+ # UTF-8 decoding plus the 0/1/2-cell decision are integer arithmetic on code points. Nothing here
47
+ # may consult the caller's locale: the previous brace ranges written as $'\uXXXX' degraded to
48
+ # literal bytes outside a UTF-8 locale (they swallowed ASCII) and ${s:i:1} sliced bytes, so one CJK
49
+ # character counted three cells, a page wrapped differently, and a page could be cut in the middle
50
+ # of a character (the zh surface printed invalid UTF-8 under LC_ALL=C).
51
+ #
52
+ # Cost note: the wrap used to fork once per word (a subshell for the cell count, plus the counter
53
+ # itself), which made a single page cost seconds. Both walks below take the bytes once and stay in
54
+ # the shell, so a page's wrapping costs one walk per block instead of one subprocess per word.
55
+ team_help_byte_values() { # <text> → space-separated byte values (one locale-pinned read)
56
+ LC_ALL=C printf '%s' "$1" | LC_ALL=C od -An -tu1 -v | tr -s ' \n' ' '
57
+ }
58
+
59
+ team_help_byte_len() { # <text> → its length in bytes
60
+ local LC_ALL=C
61
+ printf '%s' "${#1}"
62
+ }
63
+
64
+ team_help_slice_bytes() { # <text> <byte-offset> <byte-count> → those bytes
65
+ local LC_ALL=C
66
+ printf '%s' "${1:$2:$3}"
67
+ }
68
+
69
+ # team_help_cp_cells <code point> → sets _TH_CELLS to 0, 1 or 2. A setter, not a printer: this is
70
+ # the hot loop and a subshell per code point is exactly the cost that has to stay out of it.
71
+ _TH_CELLS=1
72
+ team_help_cp_cells() {
73
+ local cp="$1" r
74
+ case "$cp" in ''|*[!0-9]*) _TH_CELLS=1; return 0 ;; esac
75
+ for r in 768-879 1155-1161 4448-4607 8203-8207 65024-65039; do
76
+ if [ "$cp" -ge "${r%-*}" ] && [ "$cp" -le "${r#*-}" ]; then _TH_CELLS=0; return 0; fi
77
+ done
78
+ for r in 4352-4447 11904-12350 12353-13311 13312-19903 19968-40959 40960-42191 \
79
+ 44032-55203 63744-64255 65072-65103 65280-65312 65504-65510 \
80
+ 127744-128591 129280-129535 131072-262141; do
81
+ if [ "$cp" -ge "${r%-*}" ] && [ "$cp" -le "${r#*-}" ]; then _TH_CELLS=2; return 0; fi
82
+ done
83
+ _TH_CELLS=1
84
+ }
85
+
86
+ team_help_char_width() { # <one code point> → 0, 1 or 2 display cells
87
+ team_help_cp_cells "$1"
88
+ printf '%s' "$_TH_CELLS"
89
+ }
90
+
91
+ # team_help_decode <b1> <b2> <b3> <b4> → sets _TH_CP and _TH_STEP (1..4) for one code point.
92
+ # A malformed byte is its own code point and counts one cell, so a broken table can never make the
93
+ # counter lose bytes.
94
+ _TH_CP=0; _TH_STEP=1
95
+ team_help_decode() {
96
+ local b1="$1" b2="$2" b3="$3" b4="$4"
97
+ _TH_CP="$b1"; _TH_STEP=1
98
+ if [ "$b1" -ge 194 ] && [ "$b1" -le 223 ] && [ "$b2" -ge 128 ] && [ "$b2" -le 191 ]; then
99
+ _TH_CP=$((((b1 & 31) << 6) | (b2 & 63))); _TH_STEP=2
100
+ elif [ "$b1" -ge 224 ] && [ "$b1" -le 239 ] && [ "$b2" -ge 128 ] && [ "$b2" -le 191 ] \
101
+ && [ "$b3" -ge 128 ] && [ "$b3" -le 191 ]; then
102
+ _TH_CP=$((((b1 & 15) << 12) | ((b2 & 63) << 6) | (b3 & 63))); _TH_STEP=3
103
+ elif [ "$b1" -ge 240 ] && [ "$b1" -le 244 ] && [ "$b2" -ge 128 ] && [ "$b2" -le 191 ] \
104
+ && [ "$b3" -ge 128 ] && [ "$b3" -le 191 ] && [ "$b4" -ge 128 ] && [ "$b4" -le 191 ]; then
105
+ _TH_CP=$((((b1 & 7) << 18) | ((b2 & 63) << 12) | ((b3 & 63) << 6) | (b4 & 63))); _TH_STEP=4
106
+ fi
107
+ }
108
+
109
+ # team_help_cps <text> → one line per code point: "<byte-offset> <cells>"
110
+ team_help_cps() {
111
+ local i=0 n
112
+ local -a b=()
113
+ read -r -a b <<< "$(team_help_byte_values "$1")"
114
+ n=${#b[@]}
115
+ while [ "$i" -lt "$n" ]; do
116
+ team_help_decode "${b[$i]}" "${b[$((i + 1))]:-0}" "${b[$((i + 2))]:-0}" "${b[$((i + 3))]:-0}"
117
+ team_help_cp_cells "$_TH_CP"
118
+ printf '%s %s\n' "$i" "$_TH_CELLS"
119
+ i=$((i + _TH_STEP))
120
+ done
121
+ }
122
+
123
+ # team_help_words <text> → one line per whitespace-separated word: "<byte-offset> <byte-count>
124
+ # <cells> <word>". The split is the one `read -r -a` does (space, tab and newline), and the word
125
+ # travels with its own bytes so the caller needs no second pass.
126
+ team_help_words() {
127
+ local LC_ALL=C # the slices below are byte slices, so the word keeps its own bytes
128
+ local i=0 n cells=0 wstart=-1
129
+ local -a b=()
130
+ read -r -a b <<< "$(team_help_byte_values "$1")"
131
+ n=${#b[@]}
132
+ while [ "$i" -lt "$n" ]; do
133
+ team_help_decode "${b[$i]}" "${b[$((i + 1))]:-0}" "${b[$((i + 2))]:-0}" "${b[$((i + 3))]:-0}"
134
+ if [ "$_TH_CP" = 32 ] || [ "$_TH_CP" = 9 ] || [ "$_TH_CP" = 10 ]; then
135
+ if [ "$wstart" -ge 0 ]; then
136
+ printf '%s %s %s %s\n' "$wstart" "$((i - wstart))" "$cells" "${1:$wstart:$((i - wstart))}"
137
+ wstart=-1; cells=0
138
+ fi
139
+ else
140
+ team_help_cp_cells "$_TH_CP"
141
+ [ "$wstart" -ge 0 ] || { wstart=$i; cells=0; }
142
+ cells=$((cells + _TH_CELLS))
143
+ fi
144
+ i=$((i + _TH_STEP))
145
+ done
146
+ if [ "$wstart" -ge 0 ]; then
147
+ printf '%s %s %s %s\n' "$wstart" "$((n - wstart))" "$cells" "${1:$wstart:$((n - wstart))}"
148
+ fi
149
+ }
150
+
151
+ team_help_cells() { # <text> → display cells (a CJK-wide character counts two)
152
+ local off cells total=0
153
+ while read -r off cells; do total=$((total + cells)); done < <(team_help_cps "$1")
154
+ printf '%s\n' "$total"
155
+ }
156
+
157
+ # ---------------------------------------------------------------- knobs (environment only)
158
+ team_help_lang() {
159
+ case "${TEAM_LANG:-}" in
160
+ ''|en|EN|en_US|en-US) printf 'en\n' ;;
161
+ zh|ZH|zh_CN|zh-CN|zh_TW|zh-Hans|zh-Hant) printf 'zh\n' ;;
162
+ *) printf 'en\n' ;;
163
+ esac
164
+ }
165
+
166
+ team_help_width() {
167
+ case "${TEAM_HELP_WIDTH:-}" in
168
+ ''|0|*[!0-9]*) printf '%s\n' "$TEAM_HELP_DEFAULT_WIDTH" ;;
169
+ *) printf '%s\n' "$TEAM_HELP_WIDTH" ;;
170
+ esac
171
+ }
172
+
173
+ # One visible warning line per invalid knob; the help path's status is unchanged.
174
+ team_help_warn_knobs() {
175
+ case "${TEAM_LANG:-}" in
176
+ ''|en|EN|en_US|en-US|zh|ZH|zh_CN|zh-CN|zh_TW|zh-Hans|zh-Hant) ;;
177
+ *) printf 'teamsmith: TEAM_LANG=%s is not a known language (en, zh); printing English\n' "$TEAM_LANG" >&2 ;;
178
+ esac
179
+ case "${TEAM_HELP_WIDTH:-}" in
180
+ '') ;;
181
+ 0|*[!0-9]*) printf 'teamsmith: TEAM_HELP_WIDTH=%s is not a positive integer; using %s\n' \
182
+ "$TEAM_HELP_WIDTH" "$TEAM_HELP_DEFAULT_WIDTH" >&2 ;;
183
+ esac
184
+ }
185
+
186
+ # ---------------------------------------------------------------- manifest + prose tables (load once)
187
+ declare -a _TH_NAMES=() _TH_GROUP=() _TH_USAGE=() _TH_FLAGS=() _TH_SUBS=() _TH_ALIASES=() \
188
+ _TH_TERMS=() _TH_FACES=() _TH_EFFECT=() _TH_AUTH=() _TH_UNDO=() _TH_CLAIMS=() _TH_PROBE=() _TH_EXAMPLE=()
189
+ declare -a _TH_GROUPS=() _TH_BEGIN=()
190
+ declare -A _TH_IDX=() _TH_EN=() _TH_ZH=()
191
+ _TH_LOADED=0
192
+
193
+ # team_help_tokens_of <file> <kind> <label> → "<line>\t<source>\t<token>" for every `{…}` token in
194
+ # the file. The tables are read whole: a token in a value is what could be printed literally, and a
195
+ # token in the file's own header is the declaration that file makes about the set it may use — both
196
+ # are the table's text, and the two directions below are judged over the same text.
197
+ team_help_tokens_of() {
198
+ awk -F'\t' -v kind="$2" -v label="$3" '
199
+ NF == 0 { next }
200
+ {
201
+ comment = ($0 ~ /^#/)
202
+ for (i = 1; i <= NF; i++) {
203
+ f = $i
204
+ while (match(f, /\{[^{}]*\}/)) {
205
+ tok = substr(f, RSTART, RLENGTH)
206
+ if (comment) {
207
+ printf "%d\t%s header comment\t%s\n", NR, label, tok
208
+ } else if (kind == "manifest") {
209
+ name = (i == 2) ? "name" : (i == 3) ? "group" : (i == 4) ? "usage" : (i == 5) ? "flags" \
210
+ : (i == 6) ? "subs" : (i == 7) ? "aliases" : (i == 8) ? "terms" : (i == 9) ? "faces" \
211
+ : (i == 10) ? "effect" : (i == 11) ? "auth" : (i == 12) ? "undo" : (i == 13) ? "claims" \
212
+ : (i == 14) ? "probe" : (i == 15) ? "example" : ("col" i)
213
+ printf "%d\t%s %s %s\t%s\n", NR, label, name, $2, tok
214
+ } else {
215
+ printf "%d\t%s %s\t%s\n", NR, label, $1, tok
216
+ }
217
+ f = substr(f, RSTART + RLENGTH)
218
+ }
219
+ }
220
+ }
221
+ ' "$1"
222
+ }
223
+
224
+ team_help_load() {
225
+ [ "${_TH_LOADED:-0}" = "1" ] && return 0
226
+ local dir file line i=0
227
+ local -a col=()
228
+ dir="$TEAM_SKILL_DIR/scripts/strings"
229
+ file="$dir/commands.tsv"
230
+ if [ ! -f "$file" ]; then
231
+ printf 'teamsmith: the help surface is missing its manifest: %s\n' "$file" >&2
232
+ return 1
233
+ fi
234
+ while IFS= read -r line; do
235
+ case "$line" in ''|'#'*) continue ;; esac
236
+ IFS=$'\t' read -r -a col <<< "$line"
237
+ case "${col[0]}" in
238
+ group) _TH_GROUPS+=("${col[1]}") ;;
239
+ begin) _TH_BEGIN=("${col[@]:1}") ;;
240
+ cmd)
241
+ _TH_NAMES+=("${col[1]}"); _TH_GROUP+=("${col[2]}"); _TH_USAGE+=("${col[3]}")
242
+ _TH_FLAGS+=("${col[4]}"); _TH_SUBS+=("${col[5]}"); _TH_ALIASES+=("${col[6]}")
243
+ _TH_TERMS+=("${col[7]}"); _TH_FACES+=("${col[8]}"); _TH_EFFECT+=("${col[9]}")
244
+ _TH_AUTH+=("${col[10]}"); _TH_UNDO+=("${col[11]}"); _TH_CLAIMS+=("${col[12]}")
245
+ _TH_PROBE+=("${col[13]}"); _TH_EXAMPLE+=("${col[14]}")
246
+ _TH_IDX["${col[1]}"]=$i
247
+ i=$((i + 1)) ;;
248
+ esac
249
+ done < "$file"
250
+ local lang
251
+ for lang in en zh; do
252
+ file="$dir/help.$lang.tsv"
253
+ [ -f "$file" ] || continue
254
+ while IFS=$'\t' read -r line; do
255
+ case "$line" in ''|'#'*) continue ;; esac
256
+ local key="${line%%$'\t'*}" val="${line#*$'\t'}"
257
+ if [ "$lang" = "en" ]; then _TH_EN["$key"]="$val"; else _TH_ZH["$key"]="$val"; fi
258
+ done < "$file"
259
+ done
260
+ # G4 · the declared set and the tokens in the tree must be equal in both directions
261
+ local _line _src _tok _bad=0 _p
262
+ local -A _seen=()
263
+ while IFS=$'\t' read -r _line _src _tok; do
264
+ [ -n "$_tok" ] || continue
265
+ _seen["$_tok"]=1
266
+ case " $TEAM_HELP_PLACEHOLDERS " in
267
+ *" $_tok "*) ;;
268
+ *) printf 'teamsmith: the help tables carry an undeclared placeholder %s (%s, line %s)\n' \
269
+ "$_tok" "$_src" "$_line" >&2
270
+ _bad=1 ;;
271
+ esac
272
+ done < <( { team_help_tokens_of "$dir/commands.tsv" manifest commands.tsv
273
+ team_help_tokens_of "$dir/help.en.tsv" prose help.en.tsv
274
+ team_help_tokens_of "$dir/help.zh.tsv" prose help.zh.tsv; } )
275
+ for _p in $TEAM_HELP_PLACEHOLDERS; do
276
+ [ -n "${_seen[$_p]+x}" ] || {
277
+ printf 'teamsmith: the declared placeholder %s appears in none of the help tables\n' "$_p" >&2
278
+ _bad=1
279
+ }
280
+ done
281
+ [ "$_bad" = "0" ] || return 1
282
+ _TH_LOADED=1
283
+ return 0
284
+ }
285
+
286
+ team_help_cmd_i() { # <name> → manifest index
287
+ team_help_load || return 1
288
+ [ -n "${_TH_IDX[$1]+x}" ] || return 1
289
+ printf '%s\n' "${_TH_IDX[$1]}"
290
+ }
291
+
292
+ team_help_primary() { # <token> → the primary name when <token> is an alias
293
+ team_help_load || return 1
294
+ local i a
295
+ for i in "${!_TH_NAMES[@]}"; do
296
+ for a in ${_TH_ALIASES[$i]}; do
297
+ [ "$a" = "$1" ] && { printf '%s\n' "${_TH_NAMES[$i]}"; return 0; }
298
+ done
299
+ done
300
+ return 1
301
+ }
302
+
303
+ team_help_group_exists() {
304
+ team_help_load || return 1
305
+ local g
306
+ for g in "${_TH_GROUPS[@]}"; do [ "$g" = "$1" ] && return 0; done
307
+ return 1
308
+ }
309
+
310
+ team_help_sub_known() { # <cmd> <sub>
311
+ team_help_load || return 1
312
+ local i
313
+ i="$(team_help_cmd_i "$1")" || return 1
314
+ local s
315
+ for s in ${_TH_SUBS[$i]}; do [ "$s" = "$2" ] && return 0; done
316
+ return 1
317
+ }
318
+
319
+ # ---------------------------------------------------------------- prose lookup (missing key visible)
320
+ # A key the selected table lacks prints one marker that carries the key id, and the other table's
321
+ # value when it has one; an empty value is never printed.
322
+ team_help_marker() { printf '«missing key: %s»' "$1"; }
323
+
324
+ # team_help_have <lang> <key> → "x" when that table carries a non-empty value for the key
325
+ team_help_have() {
326
+ local lang="$1" key="$2" v
327
+ if [ "$lang" = "zh" ]; then v="${_TH_ZH[$key]:-}"; else v="${_TH_EN[$key]:-}"; fi
328
+ [ -n "$v" ] && printf 'x'
329
+ return 0
330
+ }
331
+
332
+ team_help_raw() { # <lang> <key> → that table's value (may be empty)
333
+ if [ "$1" = "zh" ]; then printf '%s' "${_TH_ZH[$2]:-}"; else printf '%s' "${_TH_EN[$2]:-}"; fi
334
+ }
335
+
336
+ team_help_txt() { # <key>
337
+ team_help_load || return 1
338
+ local key="$1" lang other
339
+ lang="$(team_help_lang)"
340
+ if [ "$lang" = "zh" ]; then other=en; else other=zh; fi
341
+ if [ -n "$(team_help_have "$lang" "$key")" ]; then
342
+ team_help_raw "$lang" "$key"
343
+ return 0
344
+ fi
345
+ printf '%s' "$(team_help_marker "$key")"
346
+ if [ -n "$(team_help_have "$other" "$key")" ]; then
347
+ printf ' %s' "$(team_help_raw "$other" "$key")"
348
+ fi
349
+ return 0
350
+ }
351
+
352
+ # team_help_subst <text> → declared placeholders resolved ({project} {meeting_ttl} are the prose
353
+ # ones; {effect} {faces} {undo_cmd} belong to the claim sentences and are substituted by their caller).
354
+ team_help_subst() {
355
+ local s="$1"
356
+ s="${s//\{project\}/${TEAM_PROJECT:-}}"
357
+ s="${s//\{meeting_ttl\}/$(team_meeting_ttl_default 2>/dev/null || printf 72)}"
358
+ printf '%s' "$s"
359
+ }
360
+
361
+ # ---------------------------------------------------------------- flow (the only place that wraps)
362
+ team_help_puts() { # <indent> <text…> — one already-built line
363
+ local ind="$1"; shift
364
+ [ $# -gt 0 ] || return 0
365
+ printf '%*s%s\n' "$ind" '' "$*"
366
+ }
367
+
368
+ # team_help_wrap <first-avail> <cont-avail> <text…> — prints bare wrapped lines (no indent)
369
+ team_help_wrap() {
370
+ local avail="$1" next="$2"; shift 2
371
+ [ $# -gt 0 ] || return 0
372
+ local text="$*" line cells off len cw wrd
373
+ line=""; cells=0
374
+ while read -r off len cw wrd; do
375
+ [ -n "$wrd" ] || continue
376
+ if [ -n "$line" ] && [ $((cells + 1 + cw)) -le "$avail" ]; then
377
+ line="$line $wrd"; cells=$((cells + 1 + cw)); continue
378
+ fi
379
+ if [ -n "$line" ]; then printf '%s\n' "$line"; line=""; cells=0; avail="$next"; fi
380
+ if [ "$cw" -le "$avail" ]; then line="$wrd"; cells=$cw; continue; fi
381
+ # a word longer than the line (CJK prose has no spaces): break it at code-point boundaries
382
+ local soff scw seg=0 chunkc=0
383
+ while read -r soff scw; do
384
+ if [ $((chunkc + scw)) -gt "$avail" ] && [ "$soff" -gt "$seg" ]; then
385
+ printf '%s\n' "$(team_help_slice_bytes "$wrd" "$seg" "$((soff - seg))")"
386
+ avail="$next"; seg="$soff"; chunkc=0
387
+ fi
388
+ chunkc=$((chunkc + scw))
389
+ done < <(team_help_cps "$wrd")
390
+ line="$(team_help_slice_bytes "$wrd" "$seg" "$(( $(team_help_byte_len "$wrd") - seg ))")"
391
+ cells="$chunkc"
392
+ done < <(team_help_words "$text")
393
+ [ -n "$line" ] && printf '%s\n' "$line"
394
+ return 0
395
+ }
396
+
397
+ # team_help_flow <first-indent> <hang-indent> <text…> — a hanging block
398
+ team_help_flow() {
399
+ local find="$1" hind="$2"; shift 2
400
+ local w; w="$(team_help_width)"
401
+ local line first=1
402
+ while IFS= read -r line; do
403
+ if [ "$first" = 1 ]; then team_help_puts "$find" "$line"; first=0
404
+ else team_help_puts "$hind" "$line"; fi
405
+ done < <(team_help_wrap $((w - find)) $((w - hind)) "$@")
406
+ return 0
407
+ }
408
+
409
+ # team_help_item <label> <label-indent> <text-col> <text…> — an argument or a concept entry:
410
+ # the label sits at its own column, the text at the (deeper) text column, continuations align there.
411
+ team_help_item() {
412
+ local label="$1" lind="$2" col="$3"; shift 3
413
+ local w pad line first=1
414
+ w="$(team_help_width)"
415
+ pad=$((col - lind - $(team_help_cells "$label")))
416
+ if [ "$pad" -lt 2 ]; then
417
+ # the label is as wide as the description column (e.g. --allow-unresolved-branch): the text
418
+ # starts on the next line at the description column instead of running on from the label
419
+ printf '%*s%s\n' "$lind" '' "$label"
420
+ team_help_flow "$col" "$col" "$@"
421
+ return 0
422
+ fi
423
+ printf -v pad '%*s' "$pad" ''
424
+ while IFS= read -r line; do
425
+ if [ "$first" = 1 ]; then
426
+ printf '%*s%s%s%s\n' "$lind" '' "$label" "$pad" "$line"; first=0
427
+ else
428
+ team_help_puts "$col" "$line"
429
+ fi
430
+ done < <(team_help_wrap $((w - col)) $((w - col)) "$@")
431
+ return 0
432
+ }
433
+
434
+ team_help_rule() { # <title> — a column-0 section header, padded to the width
435
+ local title="$1" w bar pad
436
+ w="$(team_help_width)"
437
+ pad=$((w - 4 - $(team_help_cells "$title")))
438
+ [ "$pad" -lt 2 ] && pad=2
439
+ printf -v bar '%*s' "$pad" ''
440
+ printf '%s%s\n' "── $title " "${bar// /─}"
441
+ }
442
+
443
+ team_help_blank() { printf '\n'; }
444
+
445
+ # ---------------------------------------------------------------- derived claim sentences
446
+ team_help_face_list() { # <faces>
447
+ local f out=""
448
+ for f in $1; do
449
+ [ -n "$out" ] && out="$out$(team_help_txt claim.list-sep)"
450
+ out="$out$(team_help_txt "face.$f")"
451
+ done
452
+ printf '%s' "$out"
453
+ }
454
+
455
+ team_help_effect_text() { # <effect> <faces>
456
+ local eff="$1" faces="$2" out
457
+ case "$eff" in
458
+ read-only) out="$(team_help_txt claim.effect.read-only)" ;;
459
+ starts-process)
460
+ out="$(team_help_txt claim.effect.starts-process)"
461
+ [ -n "$faces" ] && out="$out$(team_help_txt claim.extra-sep)$(team_help_txt claim.effect.and-writes)$(team_help_face_list "$faces")" ;;
462
+ writes-*)
463
+ out="$(team_help_txt claim.effect.writes)$(team_help_face_list "$faces")" ;;
464
+ *) out="$(team_help_marker "claim.effect.$eff")" ;;
465
+ esac
466
+ printf '%s' "$out"
467
+ }
468
+
469
+ team_help_auth_text() { # <auth>
470
+ local auth="$1" out
471
+ case "$auth" in
472
+ none) out="$(team_help_txt claim.auth.none)" ;;
473
+ needs-yes) out="$(team_help_txt claim.auth.needs-yes)" ;;
474
+ needs-yes:*)
475
+ out="$(team_help_txt claim.auth.needs-yes) $(team_help_txt claim.auth.when) ${auth#needs-yes:}" ;;
476
+ *) out="$(team_help_marker "claim.auth.$auth")" ;;
477
+ esac
478
+ printf '%s' "$out"
479
+ }
480
+
481
+ team_help_undo_text() { # <undo>
482
+ local undo="$1" out cmd
483
+ case "$undo" in
484
+ idempotent) out="$(team_help_txt claim.undo.idempotent)" ;;
485
+ undo-by-*) cmd="${undo#undo-by-}"; out="$(team_help_txt claim.undo.undo-by)"; out="${out//\{undo_cmd\}/$cmd}" ;;
486
+ not-reversible:*) out="$(team_help_txt claim.undo.not-reversible)" ;;
487
+ *) out="$(team_help_marker "claim.undo.$undo")" ;;
488
+ esac
489
+ printf '%s' "$out"
490
+ }
491
+
492
+ # ---------------------------------------------------------------- level 0 (the menu)
493
+ team_help_menu() {
494
+ team_help_load || return 1
495
+ local w; w="$(team_help_width)"
496
+ team_help_flow 0 0 "$(team_help_subst "$(team_help_txt menu.lead)")"
497
+ team_help_blank
498
+ team_help_puts 0 "$(team_help_txt menu.groups)"
499
+ local g
500
+ for g in "${_TH_GROUPS[@]}"; do
501
+ local title purpose cells pad line
502
+ title="$(team_help_txt "group.$g.title")"
503
+ purpose="$(team_help_subst "$(team_help_txt "group.$g.purpose")")"
504
+ cells="$(team_help_cells "$g")"
505
+ pad=$((12 - 2 - cells)); [ "$pad" -lt 1 ] && pad=1
506
+ printf -v pad '%*s' "$pad" ''
507
+ line="$g$pad$purpose"
508
+ if [ "$(team_help_cells " $line")" -le "$(team_help_width)" ]; then
509
+ team_help_puts 2 "$line"
510
+ else
511
+ team_help_flow 2 6 "$g — $purpose"
512
+ fi
513
+ done
514
+ team_help_blank
515
+ team_help_rule "$(team_help_txt part.start.title)"
516
+ local name i
517
+ for name in "${_TH_BEGIN[@]}"; do
518
+ i="$(team_help_cmd_i "$name")" || continue
519
+ local frag; frag="${_TH_USAGE[$i]%% ;; *}"
520
+ team_help_flow 2 4 "$(team_help_subst "$frag")"
521
+ team_help_flow 6 6 "$(team_help_subst "$(team_help_txt "cmd.$name.title")")"
522
+ done
523
+ team_help_blank
524
+ team_help_flow 0 0 "$(team_help_subst "$(team_help_txt menu.deeper)")"
525
+ return 0
526
+ }
527
+
528
+ # ---------------------------------------------------------------- level 1 (a group page)
529
+ team_help_group_page() { # <group id>
530
+ team_help_load || return 1
531
+ local g="$1" title purpose
532
+ title="$(team_help_txt "group.$g.title")"
533
+ purpose="$(team_help_subst "$(team_help_txt "group.$g.purpose")")"
534
+ team_help_flow 0 0 "teamsmith · $title — $purpose"
535
+ team_help_blank
536
+ team_help_rule "$title"
537
+ local i name
538
+ for i in "${!_TH_NAMES[@]}"; do
539
+ [ "${_TH_GROUP[$i]}" = "$g" ] || continue
540
+ name="${_TH_NAMES[$i]}"
541
+ team_help_flow 2 4 "$(team_help_subst "${_TH_USAGE[$i]%% ;; *}")"
542
+ team_help_flow 6 6 "$(team_help_subst "$(team_help_txt "cmd.$name.what")")"
543
+ done
544
+ team_help_blank
545
+ team_help_flow 0 0 "$(team_help_subst "$(team_help_txt menu.deeper)")"
546
+ return 0
547
+ }
548
+
549
+ # ---------------------------------------------------------------- level 2 (a command page)
550
+ team_help_command_page() { # <name> [<asked token>]
551
+ team_help_load || return 1
552
+ local name="$1" asked="${2:-}" i
553
+ i="$(team_help_cmd_i "$name")" || return 1
554
+ local title; title="$(team_help_txt "cmd.$name.title")"
555
+ team_help_flow 0 0 "teamsmith · $name — $title"
556
+ team_help_blank
557
+ team_help_rule "$(team_help_txt part.usage.title)"
558
+ local plain="${_TH_USAGE[$i]// ;; /;;;}"
559
+ local f
560
+ while [ -n "$plain" ]; do
561
+ if [ "${plain#*;;;}" != "$plain" ]; then f="${plain%%;;;*}"; plain="${plain#*;;;}"; else f="$plain"; plain=""; fi
562
+ team_help_flow 2 4 "$(team_help_subst "$f")"
563
+ done
564
+ # the description block (hanging at column 6)
565
+ local what when example read write see extra
566
+ what="$(team_help_subst "$(team_help_txt "cmd.$name.what")")"
567
+ when="$(team_help_subst "$(team_help_txt "cmd.$name.when")")"
568
+ example="$(team_help_subst "$(team_help_txt "cmd.$name.example")")"
569
+ read="$(team_help_subst "$(team_help_txt "cmd.$name.read")")"
570
+ write="$(team_help_subst "$(team_help_txt "cmd.$name.write")")"
571
+ see="$(team_help_subst "$(team_help_txt "cmd.$name.see")")"
572
+ local sep; sep="$(team_help_txt part.sep)"
573
+ team_help_flow 6 6 "$(team_help_txt part.what.title)$sep$what"
574
+ team_help_flow 6 6 "$(team_help_txt part.when.title)$sep$when"
575
+ local fl
576
+ # a command with no flags prints no argument row: the `-` placeholder is a manifest column value,
577
+ # never a flag name (printing it produced `«missing key: cmd.<name>.arg.-»` on 14 pages). The part
578
+ # itself is never left empty: a flagless command says so.
579
+ if [ "${_TH_FLAGS[$i]}" = "-" ] || [ -z "${_TH_FLAGS[$i]}" ]; then
580
+ team_help_flow 6 6 "$(team_help_txt part.arguments.title)$sep$(team_help_txt part.arguments.none)"
581
+ else
582
+ team_help_flow 6 6 "$(team_help_txt part.arguments.title)$sep"
583
+ for fl in ${_TH_FLAGS[$i]}; do
584
+ [ "$fl" = "-" ] && continue
585
+ team_help_item "$fl" 10 "$TEAM_HELP_ARG_COL" "$(team_help_subst "$(team_help_txt "cmd.$name.arg.$fl")")"
586
+ done
587
+ fi
588
+ team_help_flow 6 6 "$(team_help_txt part.example.title)$sep"
589
+ team_help_flow 10 10 "$example"
590
+ team_help_flow 6 6 "$(team_help_txt part.read.title)$sep$read"
591
+ team_help_flow 6 6 "$(team_help_txt part.write.title)$sep$write"
592
+ local eff faces
593
+ eff="${_TH_EFFECT[$i]}"; faces="${_TH_FACES[$i]}"
594
+ [ "$faces" = "-" ] && faces=""
595
+ extra="$(team_help_txt "cmd.$name.effect")"; extra="$(team_help_subst "$extra")"
596
+ local line; line="$(team_help_effect_text "$eff" "$faces")"
597
+ [ -n "$extra" ] && [ "$extra" != "$(team_help_marker "cmd.$name.effect")" ] && line="$line. $extra"
598
+ team_help_flow 6 6 "$(team_help_txt part.side-effects.title)$sep$line"
599
+ extra="$(team_help_txt "cmd.$name.auth")"; extra="$(team_help_subst "$extra")"
600
+ line="$(team_help_auth_text "${_TH_AUTH[$i]}")"
601
+ [ -n "$extra" ] && [ "$extra" != "$(team_help_marker "cmd.$name.auth")" ] && line="$line. $extra"
602
+ team_help_flow 6 6 "$(team_help_txt part.authorization.title)$sep$line"
603
+ extra="$(team_help_txt "cmd.$name.undo")"; extra="$(team_help_subst "$extra")"
604
+ line="$(team_help_undo_text "${_TH_UNDO[$i]}")"
605
+ [ -n "$extra" ] && [ "$extra" != "$(team_help_marker "cmd.$name.undo")" ] && line="$line. $extra"
606
+ team_help_flow 6 6 "$(team_help_txt part.undo.title)$sep$line"
607
+ local aliases="${_TH_ALIASES[$i]}"
608
+ if [ "$aliases" != "-" ] && [ -n "$aliases" ]; then
609
+ team_help_flow 6 6 "$(team_help_txt part.aliases.title)$sep$aliases — $(team_help_txt part.aliases.note)"
610
+ fi
611
+ if [ -n "$asked" ] && [ "$asked" != "$name" ]; then
612
+ local al; al="$(team_help_txt part.aliases.alias)"; al="${al//\{cmd\}/$name}"
613
+ team_help_flow 6 6 "$(team_help_txt part.aliases.title)$sep$asked — $al"
614
+ fi
615
+ local t
616
+ if [ "${_TH_TERMS[$i]}" = "-" ] || [ -z "${_TH_TERMS[$i]}" ]; then
617
+ team_help_flow 6 6 "$(team_help_txt part.concepts.title)$sep$(team_help_txt part.concepts.none)"
618
+ else
619
+ team_help_flow 6 6 "$(team_help_txt part.concepts.title)$sep"
620
+ for t in ${_TH_TERMS[$i]}; do
621
+ team_help_item "$t" 14 "$TEAM_HELP_TERM_COL" "$(team_help_subst "$(team_help_txt "term.$t.def")")"
622
+ done
623
+ fi
624
+ team_help_flow 6 6 "$(team_help_txt part.see.title)$sep$see"
625
+ team_help_blank
626
+ team_help_flow 0 0 "$(team_help_subst "$(team_help_txt menu.deeper)")"
627
+ return 0
628
+ }
629
+
630
+ # ---------------------------------------------------------------- refusals
631
+ team_help_refuse() { # <token> [<parent command>]
632
+ local token="$1" parent="${2:-}" line
633
+ if [ -n "$parent" ]; then
634
+ line="$(team_help_txt refuse.sub)"; line="${line//\{sub\}/$token}"; line="${line//\{cmd\}/$parent}"
635
+ else
636
+ line="$(team_help_txt refuse.unknown)"; line="${line//\{token\}/$token}"
637
+ fi
638
+ printf 'teamsmith: %s\n' "$line" >&2
639
+ printf 'teamsmith: %s\n' "$(team_help_subst "$(team_help_txt refuse.hint)")" >&2
640
+ return 2
641
+ }
642
+
643
+ # ---------------------------------------------------------------- routing (before the contract)
644
+ # team_help_route <explicit-help 0|1> [argv…]
645
+ # 0: argv[0] is the literal `help`; the token after it selects a group or a command.
646
+ # 1: `-h`/`--help` appeared anywhere in the argv; argv is the command path asked about.
647
+ team_help_route() {
648
+ team_help_warn_knobs
649
+ team_help_load || return 1
650
+ local explicit="$1"; shift
651
+ local token="" primary="" cmd="" sub=""
652
+ if [ "$explicit" = "1" ]; then
653
+ case "$#" in
654
+ 0) team_help_menu; return 0 ;;
655
+ 1) token="$1"
656
+ if primary="$(team_help_primary "$token")"; then team_help_command_page "$primary" "$token"; return 0; fi
657
+ if team_help_cmd_i "$token" >/dev/null 2>&1; then team_help_command_page "$token"; return 0; fi
658
+ team_help_refuse "$token"; return $? ;;
659
+ *) cmd="$1"; sub="$2"
660
+ if primary="$(team_help_primary "$cmd")"; then cmd="$primary"; fi
661
+ if ! team_help_cmd_i "$cmd" >/dev/null 2>&1; then team_help_refuse "$cmd"; return $?; fi
662
+ if team_help_sub_known "$cmd" "$sub"; then team_help_command_page "$cmd"; return 0; fi
663
+ team_help_command_page "$cmd"
664
+ team_help_refuse "$sub" "$cmd"; return $? ;;
665
+ esac
666
+ fi
667
+ # `team help [<token>]`: drop the literal `help`
668
+ shift || true
669
+ case "$#" in
670
+ 0) team_help_menu; return 0 ;;
671
+ *) local token="${1:-}" primary
672
+ if team_help_group_exists "$token"; then team_help_group_page "$token"; return 0; fi
673
+ if primary="$(team_help_primary "$token")"; then team_help_command_page "$primary" "$token"; return 0; fi
674
+ if team_help_cmd_i "$token" >/dev/null 2>&1; then team_help_command_page "$token"; return 0; fi
675
+ team_help_refuse "$token"; return $? ;;
676
+ esac
677
+ }