npcsh 1.1.17__py3-none-any.whl → 1.1.19__py3-none-any.whl

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 (197) hide show
  1. npcsh/_state.py +122 -91
  2. npcsh/alicanto.py +2 -2
  3. npcsh/benchmark/__init__.py +8 -2
  4. npcsh/benchmark/npcsh_agent.py +87 -22
  5. npcsh/benchmark/runner.py +85 -43
  6. npcsh/benchmark/templates/install-npcsh.sh.j2 +35 -0
  7. npcsh/build.py +2 -4
  8. npcsh/completion.py +2 -6
  9. npcsh/config.py +2 -3
  10. npcsh/conversation_viewer.py +389 -0
  11. npcsh/corca.py +0 -1
  12. npcsh/diff_viewer.py +452 -0
  13. npcsh/execution.py +0 -1
  14. npcsh/guac.py +0 -1
  15. npcsh/mcp_helpers.py +2 -3
  16. npcsh/mcp_server.py +5 -10
  17. npcsh/npc.py +10 -11
  18. npcsh/npc_team/jinxs/bin/benchmark.jinx +1 -1
  19. npcsh/npc_team/jinxs/bin/config_tui.jinx +299 -0
  20. npcsh/npc_team/jinxs/bin/memories.jinx +316 -0
  21. npcsh/npc_team/jinxs/bin/setup.jinx +240 -0
  22. npcsh/npc_team/jinxs/bin/sync.jinx +143 -150
  23. npcsh/npc_team/jinxs/bin/team_tui.jinx +327 -0
  24. npcsh/npc_team/jinxs/incognide/add_tab.jinx +1 -1
  25. npcsh/npc_team/jinxs/incognide/close_pane.jinx +1 -1
  26. npcsh/npc_team/jinxs/incognide/close_tab.jinx +1 -1
  27. npcsh/npc_team/jinxs/incognide/confirm.jinx +1 -1
  28. npcsh/npc_team/jinxs/incognide/focus_pane.jinx +1 -1
  29. npcsh/npc_team/jinxs/incognide/list_panes.jinx +1 -1
  30. npcsh/npc_team/jinxs/incognide/navigate.jinx +1 -1
  31. npcsh/npc_team/jinxs/incognide/notify.jinx +1 -1
  32. npcsh/npc_team/jinxs/incognide/open_pane.jinx +1 -1
  33. npcsh/npc_team/jinxs/incognide/read_pane.jinx +1 -1
  34. npcsh/npc_team/jinxs/incognide/run_terminal.jinx +1 -1
  35. npcsh/npc_team/jinxs/incognide/send_message.jinx +1 -1
  36. npcsh/npc_team/jinxs/incognide/split_pane.jinx +1 -1
  37. npcsh/npc_team/jinxs/incognide/switch_npc.jinx +1 -1
  38. npcsh/npc_team/jinxs/incognide/switch_tab.jinx +1 -1
  39. npcsh/npc_team/jinxs/incognide/write_file.jinx +1 -1
  40. npcsh/npc_team/jinxs/incognide/zen_mode.jinx +1 -1
  41. npcsh/npc_team/jinxs/lib/core/search/db_search.jinx +321 -17
  42. npcsh/npc_team/jinxs/lib/core/search/file_search.jinx +312 -67
  43. npcsh/npc_team/jinxs/lib/core/search/kg_search.jinx +366 -44
  44. npcsh/npc_team/jinxs/lib/core/search/mem_review.jinx +73 -0
  45. npcsh/npc_team/jinxs/lib/core/search/mem_search.jinx +328 -20
  46. npcsh/npc_team/jinxs/lib/core/search/web_search.jinx +242 -10
  47. npcsh/npc_team/jinxs/lib/core/sleep.jinx +22 -11
  48. npcsh/npc_team/jinxs/lib/core/sql.jinx +10 -6
  49. npcsh/npc_team/jinxs/lib/research/paper_search.jinx +387 -76
  50. npcsh/npc_team/jinxs/lib/research/semantic_scholar.jinx +372 -55
  51. npcsh/npc_team/jinxs/lib/utils/jinxs.jinx +299 -144
  52. npcsh/npc_team/jinxs/modes/alicanto.jinx +356 -0
  53. npcsh/npc_team/jinxs/modes/arxiv.jinx +720 -0
  54. npcsh/npc_team/jinxs/modes/corca.jinx +430 -0
  55. npcsh/npc_team/jinxs/modes/guac.jinx +542 -0
  56. npcsh/npc_team/jinxs/modes/plonk.jinx +379 -0
  57. npcsh/npc_team/jinxs/modes/pti.jinx +357 -0
  58. npcsh/npc_team/jinxs/modes/reattach.jinx +291 -0
  59. npcsh/npc_team/jinxs/modes/spool.jinx +350 -0
  60. npcsh/npc_team/jinxs/modes/wander.jinx +455 -0
  61. npcsh/npc_team/jinxs/{bin → modes}/yap.jinx +13 -7
  62. npcsh/npcsh.py +7 -4
  63. npcsh/plonk.py +0 -1
  64. npcsh/pti.py +0 -1
  65. npcsh/routes.py +1 -3
  66. npcsh/spool.py +0 -1
  67. npcsh/ui.py +0 -1
  68. npcsh/wander.py +0 -1
  69. npcsh/yap.py +0 -1
  70. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/add_tab.jinx +1 -1
  71. npcsh-1.1.19.data/data/npcsh/npc_team/alicanto.jinx +356 -0
  72. npcsh-1.1.19.data/data/npcsh/npc_team/arxiv.jinx +720 -0
  73. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/benchmark.jinx +1 -1
  74. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/close_pane.jinx +1 -1
  75. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/close_tab.jinx +1 -1
  76. npcsh-1.1.19.data/data/npcsh/npc_team/config_tui.jinx +299 -0
  77. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/confirm.jinx +1 -1
  78. npcsh-1.1.19.data/data/npcsh/npc_team/corca.jinx +430 -0
  79. npcsh-1.1.19.data/data/npcsh/npc_team/db_search.jinx +348 -0
  80. npcsh-1.1.19.data/data/npcsh/npc_team/file_search.jinx +339 -0
  81. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/focus_pane.jinx +1 -1
  82. npcsh-1.1.19.data/data/npcsh/npc_team/guac.jinx +542 -0
  83. npcsh-1.1.19.data/data/npcsh/npc_team/jinxs.jinx +331 -0
  84. npcsh-1.1.19.data/data/npcsh/npc_team/kg_search.jinx +418 -0
  85. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/list_panes.jinx +1 -1
  86. npcsh-1.1.19.data/data/npcsh/npc_team/mem_review.jinx +73 -0
  87. npcsh-1.1.19.data/data/npcsh/npc_team/mem_search.jinx +388 -0
  88. npcsh-1.1.19.data/data/npcsh/npc_team/memories.jinx +316 -0
  89. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/navigate.jinx +1 -1
  90. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/notify.jinx +1 -1
  91. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/open_pane.jinx +1 -1
  92. npcsh-1.1.19.data/data/npcsh/npc_team/paper_search.jinx +412 -0
  93. npcsh-1.1.19.data/data/npcsh/npc_team/plonk.jinx +379 -0
  94. npcsh-1.1.19.data/data/npcsh/npc_team/pti.jinx +357 -0
  95. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/read_pane.jinx +1 -1
  96. npcsh-1.1.19.data/data/npcsh/npc_team/reattach.jinx +291 -0
  97. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/run_terminal.jinx +1 -1
  98. npcsh-1.1.19.data/data/npcsh/npc_team/semantic_scholar.jinx +386 -0
  99. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/send_message.jinx +1 -1
  100. npcsh-1.1.19.data/data/npcsh/npc_team/setup.jinx +240 -0
  101. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/sleep.jinx +22 -11
  102. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/split_pane.jinx +1 -1
  103. npcsh-1.1.19.data/data/npcsh/npc_team/spool.jinx +350 -0
  104. npcsh-1.1.19.data/data/npcsh/npc_team/sql.jinx +20 -0
  105. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/switch_npc.jinx +1 -1
  106. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/switch_tab.jinx +1 -1
  107. npcsh-1.1.19.data/data/npcsh/npc_team/sync.jinx +223 -0
  108. npcsh-1.1.19.data/data/npcsh/npc_team/team_tui.jinx +327 -0
  109. npcsh-1.1.19.data/data/npcsh/npc_team/wander.jinx +455 -0
  110. npcsh-1.1.19.data/data/npcsh/npc_team/web_search.jinx +283 -0
  111. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/write_file.jinx +1 -1
  112. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/yap.jinx +13 -7
  113. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/zen_mode.jinx +1 -1
  114. {npcsh-1.1.17.dist-info → npcsh-1.1.19.dist-info}/METADATA +110 -14
  115. npcsh-1.1.19.dist-info/RECORD +244 -0
  116. {npcsh-1.1.17.dist-info → npcsh-1.1.19.dist-info}/WHEEL +1 -1
  117. {npcsh-1.1.17.dist-info → npcsh-1.1.19.dist-info}/entry_points.txt +4 -3
  118. npcsh/npc_team/jinxs/bin/spool.jinx +0 -161
  119. npcsh/npc_team/jinxs/bin/wander.jinx +0 -242
  120. npcsh/npc_team/jinxs/lib/research/arxiv.jinx +0 -76
  121. npcsh-1.1.17.data/data/npcsh/npc_team/arxiv.jinx +0 -76
  122. npcsh-1.1.17.data/data/npcsh/npc_team/db_search.jinx +0 -44
  123. npcsh-1.1.17.data/data/npcsh/npc_team/file_search.jinx +0 -94
  124. npcsh-1.1.17.data/data/npcsh/npc_team/jinxs.jinx +0 -176
  125. npcsh-1.1.17.data/data/npcsh/npc_team/kg_search.jinx +0 -96
  126. npcsh-1.1.17.data/data/npcsh/npc_team/mem_search.jinx +0 -80
  127. npcsh-1.1.17.data/data/npcsh/npc_team/paper_search.jinx +0 -101
  128. npcsh-1.1.17.data/data/npcsh/npc_team/semantic_scholar.jinx +0 -69
  129. npcsh-1.1.17.data/data/npcsh/npc_team/spool.jinx +0 -161
  130. npcsh-1.1.17.data/data/npcsh/npc_team/sql.jinx +0 -16
  131. npcsh-1.1.17.data/data/npcsh/npc_team/sync.jinx +0 -230
  132. npcsh-1.1.17.data/data/npcsh/npc_team/wander.jinx +0 -242
  133. npcsh-1.1.17.data/data/npcsh/npc_team/web_search.jinx +0 -51
  134. npcsh-1.1.17.dist-info/RECORD +0 -219
  135. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/alicanto.npc +0 -0
  136. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/alicanto.png +0 -0
  137. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/browser_action.jinx +0 -0
  138. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/browser_screenshot.jinx +0 -0
  139. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/build.jinx +0 -0
  140. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/chat.jinx +0 -0
  141. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/click.jinx +0 -0
  142. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/close_browser.jinx +0 -0
  143. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/cmd.jinx +0 -0
  144. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/compile.jinx +0 -0
  145. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/compress.jinx +0 -0
  146. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/convene.jinx +0 -0
  147. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/corca.npc +0 -0
  148. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/corca.png +0 -0
  149. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/corca_example.png +0 -0
  150. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/delegate.jinx +0 -0
  151. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/edit_file.jinx +0 -0
  152. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/frederic.npc +0 -0
  153. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/frederic4.png +0 -0
  154. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/guac.npc +0 -0
  155. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/guac.png +0 -0
  156. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/help.jinx +0 -0
  157. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/incognide.jinx +0 -0
  158. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/init.jinx +0 -0
  159. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/kadiefa.npc +0 -0
  160. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/kadiefa.png +0 -0
  161. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/key_press.jinx +0 -0
  162. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/launch_app.jinx +0 -0
  163. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/load_file.jinx +0 -0
  164. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/npcsh.ctx +0 -0
  165. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/npcsh_sibiji.png +0 -0
  166. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/nql.jinx +0 -0
  167. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/open_browser.jinx +0 -0
  168. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/ots.jinx +0 -0
  169. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/paste.jinx +0 -0
  170. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/plonk.npc +0 -0
  171. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/plonk.png +0 -0
  172. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/plonkjr.npc +0 -0
  173. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/plonkjr.png +0 -0
  174. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/python.jinx +0 -0
  175. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/roll.jinx +0 -0
  176. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/sample.jinx +0 -0
  177. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/screenshot.jinx +0 -0
  178. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/search.jinx +0 -0
  179. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/serve.jinx +0 -0
  180. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/set.jinx +0 -0
  181. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/sh.jinx +0 -0
  182. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/shh.jinx +0 -0
  183. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/sibiji.npc +0 -0
  184. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/sibiji.png +0 -0
  185. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/spool.png +0 -0
  186. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/switch.jinx +0 -0
  187. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/switches.jinx +0 -0
  188. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/teamviz.jinx +0 -0
  189. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/trigger.jinx +0 -0
  190. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/type_text.jinx +0 -0
  191. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/usage.jinx +0 -0
  192. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/verbose.jinx +0 -0
  193. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/vixynt.jinx +0 -0
  194. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/wait.jinx +0 -0
  195. {npcsh-1.1.17.data → npcsh-1.1.19.data}/data/npcsh/npc_team/yap.png +0 -0
  196. {npcsh-1.1.17.dist-info → npcsh-1.1.19.dist-info}/licenses/LICENSE +0 -0
  197. {npcsh-1.1.17.dist-info → npcsh-1.1.19.dist-info}/top_level.txt +0 -0
@@ -21,7 +21,7 @@ steps:
21
21
  npc_name_input = {{ npc_name | default("") | tojson }}.strip() or None
22
22
 
23
23
  if not model:
24
- model = npc.model if npc and npc.model
24
+ model = npc.model if npc and npc.model else ""
25
25
  if not provider:
26
26
  provider = npc.provider if npc and npc.provider else "anthropic"
27
27
 
@@ -1,4 +1,4 @@
1
- jinx_name: studio.close_pane
1
+ jinx_name: studio_close_pane
2
2
  description: Close a pane in NPC Studio. Use paneId="active" or omit to close the active pane.
3
3
  inputs:
4
4
  - paneId: "active"
@@ -1,4 +1,4 @@
1
- jinx_name: studio.close_tab
1
+ jinx_name: studio_close_tab
2
2
  description: Close a specific tab in a pane.
3
3
  inputs:
4
4
  - paneId: "active"
@@ -0,0 +1,299 @@
1
+ jinx_name: config_tui
2
+ description: Interactive TUI editor for npcsh configuration (~/.npcshrc)
3
+ inputs: []
4
+ steps:
5
+ - name: config_editor
6
+ engine: python
7
+ code: |
8
+ import os
9
+ import sys
10
+ import tty
11
+ import termios
12
+ import select
13
+ from pathlib import Path
14
+
15
+ if not sys.stdin.isatty():
16
+ context['output'] = "Config TUI requires an interactive terminal."
17
+ return
18
+
19
+ # ========== Config Items ==========
20
+ CONFIG_ITEMS = [
21
+ {'key': 'NPCSH_CHAT_MODEL', 'label': 'Chat Model', 'type': 'text', 'shortcut': 'model'},
22
+ {'key': 'NPCSH_CHAT_PROVIDER', 'label': 'Chat Provider', 'type': 'text', 'shortcut': 'provider'},
23
+ {'key': 'NPCSH_VISION_MODEL', 'label': 'Vision Model', 'type': 'text'},
24
+ {'key': 'NPCSH_VISION_PROVIDER', 'label': 'Vision Provider', 'type': 'text'},
25
+ {'key': 'NPCSH_EMBEDDING_MODEL', 'label': 'Embedding Model', 'type': 'text'},
26
+ {'key': 'NPCSH_EMBEDDING_PROVIDER', 'label': 'Embedding Provider', 'type': 'text'},
27
+ {'key': 'NPCSH_REASONING_MODEL', 'label': 'Reasoning Model', 'type': 'text'},
28
+ {'key': 'NPCSH_REASONING_PROVIDER', 'label': 'Reasoning Provider', 'type': 'text'},
29
+ {'key': 'NPCSH_DEFAULT_MODE', 'label': 'Default Mode', 'type': 'choice', 'choices': ['agent', 'chat', 'code']},
30
+ {'key': 'NPCSH_STREAM_OUTPUT', 'label': 'Stream Output', 'type': 'toggle'},
31
+ {'key': 'NPCSH_BUILD_KG', 'label': 'Build Knowledge Graph', 'type': 'toggle'},
32
+ {'key': 'NPCSH_SEARCH_PROVIDER', 'label': 'Search Provider', 'type': 'choice', 'choices': ['duckduckgo', 'google', 'bing']},
33
+ ]
34
+
35
+ # ========== State ==========
36
+ class ConfigState:
37
+ def __init__(self):
38
+ self.selected_idx = 0
39
+ self.scroll_offset = 0
40
+ self.editing = False
41
+ self.edit_buffer = ""
42
+ self.edit_cursor = 0
43
+ self.values = {}
44
+ self.modified = set()
45
+ self.status = ""
46
+
47
+ state = ConfigState()
48
+
49
+ # ========== Helpers ==========
50
+ def get_size():
51
+ try:
52
+ s = os.get_terminal_size()
53
+ return s.columns, s.lines
54
+ except:
55
+ return 80, 24
56
+
57
+ def load_values():
58
+ """Load current values from environment and npcshrc."""
59
+ for item in CONFIG_ITEMS:
60
+ key = item['key']
61
+ # First try environment
62
+ value = os.environ.get(key, '')
63
+ if not value:
64
+ # Try reading from npcshrc
65
+ npcshrc = Path.home() / '.npcshrc'
66
+ if npcshrc.exists():
67
+ with open(npcshrc) as f:
68
+ for line in f:
69
+ if line.strip().startswith(f'export {key}='):
70
+ value = line.split('=', 1)[1].strip().strip('"').strip("'")
71
+ break
72
+ state.values[key] = value
73
+
74
+ def save_values():
75
+ """Save modified values to ~/.npcshrc."""
76
+ from npcsh.config import set_npcsh_config_value
77
+ for key in state.modified:
78
+ set_npcsh_config_value(key, state.values[key])
79
+ state.modified.clear()
80
+ state.status = "Saved!"
81
+
82
+ def format_value(item, value):
83
+ """Format value for display."""
84
+ if item['type'] == 'toggle':
85
+ return '\033[32mON\033[0m' if value in ('1', 'true', 'True', True) else '\033[31mOFF\033[0m'
86
+ elif not value:
87
+ return '\033[90m(not set)\033[0m'
88
+ return value
89
+
90
+ # ========== Rendering ==========
91
+ def render_screen():
92
+ width, height = get_size()
93
+ out = []
94
+ out.append("\033[2J\033[H")
95
+
96
+ # Header
97
+ header = " NPCSH Configuration "
98
+ out.append(f"\033[1;1H\033[44;37;1m{'=' * width}\033[0m")
99
+ out.append(f"\033[1;{(width - len(header)) // 2}H\033[44;37;1m{header}\033[0m")
100
+
101
+ # Config items
102
+ visible_height = height - 6
103
+ visible = CONFIG_ITEMS[state.scroll_offset:state.scroll_offset + visible_height]
104
+
105
+ label_width = max(len(item['label']) for item in CONFIG_ITEMS) + 2
106
+ value_width = width - label_width - 10
107
+
108
+ for i, item in enumerate(visible):
109
+ row = 3 + i
110
+ idx = i + state.scroll_offset
111
+ key = item['key']
112
+ value = state.values.get(key, '')
113
+ display_value = format_value(item, value)
114
+
115
+ # Indicator for modified
116
+ mod_indicator = '*' if key in state.modified else ' '
117
+
118
+ if idx == state.selected_idx:
119
+ if state.editing:
120
+ # Show edit mode
121
+ out.append(f"\033[{row};2H\033[47;30m{item['label']:<{label_width}}\033[0m")
122
+ # Edit buffer with cursor
123
+ cursor_pos = min(state.edit_cursor, len(state.edit_buffer))
124
+ before = state.edit_buffer[:cursor_pos]
125
+ after = state.edit_buffer[cursor_pos:]
126
+ out.append(f"\033[{row};{label_width+4}H{before}\033[7m \033[0m{after}")
127
+ else:
128
+ out.append(f"\033[{row};2H\033[47;30m{mod_indicator}{item['label']:<{label_width}} {display_value[:value_width]}\033[0m")
129
+ else:
130
+ out.append(f"\033[{row};2H{mod_indicator}{item['label']:<{label_width}} {display_value[:value_width]}")
131
+
132
+ # Type indicator
133
+ type_hint = {'text': '[e]', 'toggle': '[t]', 'choice': '[c]'}.get(item['type'], '')
134
+ out.append(f"\033[{row};{width-4}H\033[90m{type_hint}\033[0m")
135
+
136
+ # Status line
137
+ if state.status:
138
+ out.append(f"\033[{height-2};2H\033[33m{state.status}\033[0m")
139
+
140
+ # Footer
141
+ if state.editing:
142
+ footer = "[Enter] Save [Esc] Cancel"
143
+ else:
144
+ footer = "[j/k] Navigate [e] Edit [t] Toggle [s] Save All [q] Quit"
145
+ out.append(f"\033[{height};1H\033[90m{footer[:width]}\033[0m")
146
+
147
+ sys.stdout.write(''.join(out))
148
+ sys.stdout.flush()
149
+
150
+ # ========== Input Handling ==========
151
+ def handle_input(c):
152
+ if state.editing:
153
+ return handle_edit_input(c)
154
+
155
+ if c == 'q':
156
+ if state.modified:
157
+ state.status = "Unsaved changes! Press 's' to save or 'q' again to discard."
158
+ return True
159
+ return False
160
+
161
+ if c == '\x1b': # Escape sequence
162
+ if select.select([sys.stdin], [], [], 0.05)[0]:
163
+ c2 = sys.stdin.read(1)
164
+ if c2 == '[':
165
+ c3 = sys.stdin.read(1)
166
+ if c3 == 'A': # Up
167
+ move_up()
168
+ elif c3 == 'B': # Down
169
+ move_down()
170
+ return True
171
+
172
+ if c == 'k':
173
+ move_up()
174
+ elif c == 'j':
175
+ move_down()
176
+ elif c == 'e' or c == '\r' or c == '\n':
177
+ start_edit()
178
+ elif c == 't':
179
+ toggle_value()
180
+ elif c == 'c':
181
+ cycle_choice()
182
+ elif c == 's':
183
+ save_values()
184
+
185
+ return True
186
+
187
+ def handle_edit_input(c):
188
+ if c == '\x1b': # Escape - cancel edit
189
+ state.editing = False
190
+ state.edit_buffer = ""
191
+ state.status = "Edit cancelled"
192
+ return True
193
+
194
+ if c == '\r' or c == '\n': # Enter - save edit
195
+ key = CONFIG_ITEMS[state.selected_idx]['key']
196
+ state.values[key] = state.edit_buffer
197
+ state.modified.add(key)
198
+ state.editing = False
199
+ state.edit_buffer = ""
200
+ state.status = f"Changed {key}"
201
+ return True
202
+
203
+ if c == '\x7f' or c == '\x08': # Backspace
204
+ if state.edit_cursor > 0:
205
+ state.edit_buffer = state.edit_buffer[:state.edit_cursor-1] + state.edit_buffer[state.edit_cursor:]
206
+ state.edit_cursor -= 1
207
+ return True
208
+
209
+ if c >= ' ' and c <= '~': # Printable
210
+ state.edit_buffer = state.edit_buffer[:state.edit_cursor] + c + state.edit_buffer[state.edit_cursor:]
211
+ state.edit_cursor += 1
212
+ return True
213
+
214
+ return True
215
+
216
+ def move_up():
217
+ state.selected_idx = max(0, state.selected_idx - 1)
218
+ if state.selected_idx < state.scroll_offset:
219
+ state.scroll_offset = state.selected_idx
220
+ state.status = ""
221
+
222
+ def move_down():
223
+ _, height = get_size()
224
+ visible_height = height - 6
225
+ state.selected_idx = min(len(CONFIG_ITEMS) - 1, state.selected_idx + 1)
226
+ if state.selected_idx >= state.scroll_offset + visible_height:
227
+ state.scroll_offset = state.selected_idx - visible_height + 1
228
+ state.status = ""
229
+
230
+ def start_edit():
231
+ item = CONFIG_ITEMS[state.selected_idx]
232
+ if item['type'] == 'toggle':
233
+ toggle_value()
234
+ elif item['type'] == 'choice':
235
+ cycle_choice()
236
+ else:
237
+ key = item['key']
238
+ state.edit_buffer = state.values.get(key, '')
239
+ state.edit_cursor = len(state.edit_buffer)
240
+ state.editing = True
241
+ state.status = "Editing... Enter to save, Esc to cancel"
242
+
243
+ def toggle_value():
244
+ item = CONFIG_ITEMS[state.selected_idx]
245
+ if item['type'] != 'toggle':
246
+ return
247
+ key = item['key']
248
+ current = state.values.get(key, '0')
249
+ new_value = '0' if current in ('1', 'true', 'True') else '1'
250
+ state.values[key] = new_value
251
+ state.modified.add(key)
252
+ state.status = f"Toggled {item['label']}"
253
+
254
+ def cycle_choice():
255
+ item = CONFIG_ITEMS[state.selected_idx]
256
+ if item['type'] != 'choice':
257
+ return
258
+ key = item['key']
259
+ choices = item.get('choices', [])
260
+ if not choices:
261
+ return
262
+ current = state.values.get(key, '')
263
+ try:
264
+ idx = choices.index(current)
265
+ next_idx = (idx + 1) % len(choices)
266
+ except ValueError:
267
+ next_idx = 0
268
+ state.values[key] = choices[next_idx]
269
+ state.modified.add(key)
270
+ state.status = f"Changed to {choices[next_idx]}"
271
+
272
+ # ========== Main Loop ==========
273
+ load_values()
274
+
275
+ fd = sys.stdin.fileno()
276
+ old_settings = termios.tcgetattr(fd)
277
+
278
+ try:
279
+ tty.setcbreak(fd)
280
+ sys.stdout.write('\033[?25l') # Hide cursor
281
+
282
+ render_screen()
283
+
284
+ while True:
285
+ c = sys.stdin.read(1)
286
+ if not handle_input(c):
287
+ break
288
+ render_screen()
289
+
290
+ finally:
291
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
292
+ sys.stdout.write('\033[?25h') # Show cursor
293
+ sys.stdout.write('\033[2J\033[H') # Clear screen
294
+ sys.stdout.flush()
295
+
296
+ if state.modified:
297
+ context['output'] = f"Exited with unsaved changes: {', '.join(state.modified)}"
298
+ else:
299
+ context['output'] = "Configuration editor closed."
@@ -1,4 +1,4 @@
1
- jinx_name: studio.confirm
1
+ jinx_name: studio_confirm
2
2
  description: Show a confirmation dialog and return the user's choice.
3
3
  inputs:
4
4
  - message: ""