kash-shell 0.3.10__py3-none-any.whl → 0.3.12__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.
- kash/actions/core/format_markdown_template.py +2 -5
- kash/actions/core/markdownify.py +2 -4
- kash/actions/core/readability.py +2 -4
- kash/actions/core/render_as_html.py +30 -11
- kash/actions/core/show_webpage.py +6 -11
- kash/actions/core/strip_html.py +4 -8
- kash/actions/core/{webpage_config.py → tabbed_webpage_config.py} +5 -3
- kash/actions/core/{webpage_generate.py → tabbed_webpage_generate.py} +5 -4
- kash/commands/base/basic_file_commands.py +21 -3
- kash/commands/base/files_command.py +29 -10
- kash/commands/extras/parse_uv_lock.py +12 -3
- kash/commands/workspace/selection_commands.py +1 -1
- kash/commands/workspace/workspace_commands.py +2 -3
- kash/config/colors.py +2 -2
- kash/config/env_settings.py +2 -42
- kash/config/logger.py +30 -25
- kash/config/logger_basic.py +6 -6
- kash/config/settings.py +23 -7
- kash/config/setup.py +33 -5
- kash/config/text_styles.py +25 -22
- kash/embeddings/cosine.py +12 -4
- kash/embeddings/embeddings.py +16 -6
- kash/embeddings/text_similarity.py +10 -4
- kash/exec/__init__.py +3 -0
- kash/exec/action_decorators.py +10 -25
- kash/exec/action_exec.py +43 -23
- kash/exec/llm_transforms.py +6 -3
- kash/exec/preconditions.py +10 -12
- kash/exec/resolve_args.py +4 -0
- kash/exec/runtime_settings.py +134 -0
- kash/exec/shell_callable_action.py +5 -3
- kash/file_storage/file_store.py +37 -38
- kash/file_storage/item_file_format.py +6 -3
- kash/file_storage/store_filenames.py +6 -3
- kash/help/function_param_info.py +1 -1
- kash/llm_utils/init_litellm.py +16 -0
- kash/llm_utils/llm_api_keys.py +6 -2
- kash/llm_utils/llm_completion.py +11 -4
- kash/local_server/local_server_routes.py +1 -7
- kash/mcp/mcp_cli.py +3 -2
- kash/mcp/mcp_server_routes.py +11 -12
- kash/media_base/transcription_deepgram.py +15 -2
- kash/model/__init__.py +1 -1
- kash/model/actions_model.py +6 -54
- kash/model/exec_model.py +79 -0
- kash/model/items_model.py +102 -35
- kash/model/operations_model.py +38 -15
- kash/model/paths_model.py +2 -0
- kash/shell/output/shell_output.py +10 -8
- kash/shell/shell_main.py +2 -2
- kash/shell/utils/exception_printing.py +2 -2
- kash/shell/utils/shell_function_wrapper.py +15 -15
- kash/text_handling/doc_normalization.py +16 -8
- kash/text_handling/markdown_render.py +1 -0
- kash/text_handling/markdown_utils.py +105 -2
- kash/utils/common/format_utils.py +2 -8
- kash/utils/common/function_inspect.py +360 -110
- kash/utils/common/inflection.py +22 -0
- kash/utils/common/task_stack.py +4 -15
- kash/utils/errors.py +14 -9
- kash/utils/file_utils/file_ext.py +4 -0
- kash/utils/file_utils/file_formats_model.py +32 -1
- kash/utils/file_utils/file_sort_filter.py +10 -3
- kash/web_gen/__init__.py +0 -4
- kash/web_gen/simple_webpage.py +52 -0
- kash/web_gen/tabbed_webpage.py +23 -16
- kash/web_gen/template_render.py +37 -2
- kash/web_gen/templates/base_styles.css.jinja +84 -59
- kash/web_gen/templates/base_webpage.html.jinja +85 -67
- kash/web_gen/templates/item_view.html.jinja +47 -37
- kash/web_gen/templates/simple_webpage.html.jinja +24 -0
- kash/web_gen/templates/tabbed_webpage.html.jinja +42 -32
- kash/workspaces/__init__.py +12 -3
- kash/workspaces/workspace_dirs.py +58 -0
- kash/workspaces/workspace_importing.py +1 -1
- kash/workspaces/workspaces.py +26 -90
- {kash_shell-0.3.10.dist-info → kash_shell-0.3.12.dist-info}/METADATA +7 -7
- {kash_shell-0.3.10.dist-info → kash_shell-0.3.12.dist-info}/RECORD +81 -76
- kash/shell/utils/argparse_utils.py +0 -20
- kash/utils/lang_utils/inflection.py +0 -18
- {kash_shell-0.3.10.dist-info → kash_shell-0.3.12.dist-info}/WHEEL +0 -0
- {kash_shell-0.3.10.dist-info → kash_shell-0.3.12.dist-info}/entry_points.txt +0 -0
- {kash_shell-0.3.10.dist-info → kash_shell-0.3.12.dist-info}/licenses/LICENSE +0 -0
|
@@ -4,7 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
from kash.config.logger import get_logger
|
|
5
5
|
from kash.exec import kash_action
|
|
6
6
|
from kash.exec.preconditions import is_markdown
|
|
7
|
-
from kash.model import ONE_OR_MORE_ARGS, ActionInput, ActionResult,
|
|
7
|
+
from kash.model import ONE_OR_MORE_ARGS, ActionInput, ActionResult, Param
|
|
8
8
|
from kash.utils.common.type_utils import not_none
|
|
9
9
|
from kash.utils.errors import InvalidInput
|
|
10
10
|
|
|
@@ -84,9 +84,6 @@ def format_markdown_template(
|
|
|
84
84
|
# Format the body using the mapped items.
|
|
85
85
|
body = template.format(**item_map)
|
|
86
86
|
|
|
87
|
-
result_item = items[0].derived_copy(
|
|
88
|
-
type=ItemType.doc,
|
|
89
|
-
body=body,
|
|
90
|
-
)
|
|
87
|
+
result_item = items[0].derived_copy(body=body)
|
|
91
88
|
|
|
92
89
|
return ActionResult([result_item])
|
kash/actions/core/markdownify.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from kash.config.logger import get_logger
|
|
2
2
|
from kash.exec import kash_action
|
|
3
3
|
from kash.exec.preconditions import has_html_body, is_url_item
|
|
4
|
-
from kash.model import Format, Item
|
|
4
|
+
from kash.model import Format, Item
|
|
5
5
|
from kash.model.params_model import common_params
|
|
6
6
|
from kash.web_content.file_cache_utils import get_url_html
|
|
7
7
|
from kash.web_content.web_extract_readabilipy import extract_text_readabilipy
|
|
@@ -26,7 +26,5 @@ def markdownify(item: Item, refetch: bool = False) -> Item:
|
|
|
26
26
|
page_data = extract_text_readabilipy(url, html_content)
|
|
27
27
|
markdown_content = markdownify_convert(page_data.clean_html)
|
|
28
28
|
|
|
29
|
-
output_item = item.derived_copy(
|
|
30
|
-
type=ItemType.doc, format=Format.markdown, body=markdown_content
|
|
31
|
-
)
|
|
29
|
+
output_item = item.derived_copy(format=Format.markdown, body=markdown_content)
|
|
32
30
|
return output_item
|
kash/actions/core/readability.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from kash.config.logger import get_logger
|
|
2
2
|
from kash.exec import kash_action
|
|
3
3
|
from kash.exec.preconditions import has_html_body, is_url_item
|
|
4
|
-
from kash.model import Format, Item
|
|
4
|
+
from kash.model import Format, Item
|
|
5
5
|
from kash.model.params_model import common_params
|
|
6
6
|
from kash.web_content.file_cache_utils import get_url_html
|
|
7
7
|
from kash.web_content.web_extract_readabilipy import extract_text_readabilipy
|
|
@@ -23,8 +23,6 @@ def readability(item: Item, refetch: bool = False) -> Item:
|
|
|
23
23
|
url, html_content = get_url_html(item, expiration_sec=expiration_sec)
|
|
24
24
|
page_data = extract_text_readabilipy(url, html_content)
|
|
25
25
|
|
|
26
|
-
output_item = item.derived_copy(
|
|
27
|
-
type=ItemType.doc, format=Format.html, body=page_data.clean_html
|
|
28
|
-
)
|
|
26
|
+
output_item = item.derived_copy(format=Format.html, body=page_data.clean_html)
|
|
29
27
|
|
|
30
28
|
return output_item
|
|
@@ -1,18 +1,37 @@
|
|
|
1
|
-
from kash.actions.core.
|
|
2
|
-
from kash.actions.core.
|
|
1
|
+
from kash.actions.core.tabbed_webpage_config import tabbed_webpage_config
|
|
2
|
+
from kash.actions.core.tabbed_webpage_generate import tabbed_webpage_generate
|
|
3
3
|
from kash.exec import kash_action
|
|
4
|
-
from kash.exec.preconditions import
|
|
5
|
-
from kash.
|
|
4
|
+
from kash.exec.preconditions import has_full_html_page_body, has_html_body, has_simple_text_body
|
|
5
|
+
from kash.exec_model.args_model import ONE_OR_MORE_ARGS
|
|
6
|
+
from kash.model import ActionInput, ActionResult, Param
|
|
7
|
+
from kash.model.items_model import ItemType
|
|
8
|
+
from kash.utils.file_utils.file_formats_model import Format
|
|
9
|
+
from kash.web_gen.simple_webpage import simple_webpage_render
|
|
6
10
|
|
|
7
11
|
|
|
8
12
|
@kash_action(
|
|
9
|
-
|
|
13
|
+
expected_args=ONE_OR_MORE_ARGS,
|
|
14
|
+
precondition=(has_html_body | has_simple_text_body) & ~has_full_html_page_body,
|
|
15
|
+
params=(Param("add_title", "Add a title to the page body.", type=bool),),
|
|
10
16
|
)
|
|
11
|
-
def render_as_html(input: ActionInput) -> ActionResult:
|
|
17
|
+
def render_as_html(input: ActionInput, add_title: bool = False) -> ActionResult:
|
|
12
18
|
"""
|
|
13
|
-
Convert text, Markdown, or HTML to pretty, formatted HTML using
|
|
14
|
-
page template.
|
|
19
|
+
Convert text, Markdown, or HTML to pretty, formatted HTML using a clean
|
|
20
|
+
and simple page template. Supports GFM-flavored Markdown tables and footnotes.
|
|
21
|
+
|
|
22
|
+
If it's a single input, the output is a simple HTML page.
|
|
23
|
+
If it's multiple inputs, the output is a tabbed HTML page.
|
|
24
|
+
|
|
25
|
+
This adds a header, footer, etc. so should be used on a plain document or HTML basic
|
|
26
|
+
page, not a full HTML page with header and body already present.
|
|
15
27
|
"""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
if len(input.items) == 1:
|
|
29
|
+
input_item = input.items[0]
|
|
30
|
+
html_body = simple_webpage_render(input_item, add_title_h1=add_title)
|
|
31
|
+
result_item = input_item.derived_copy(
|
|
32
|
+
type=ItemType.export, format=Format.html, body=html_body
|
|
33
|
+
)
|
|
34
|
+
return ActionResult([result_item])
|
|
35
|
+
else:
|
|
36
|
+
config_result = tabbed_webpage_config(input)
|
|
37
|
+
return tabbed_webpage_generate(ActionInput(items=config_result.items), add_title=add_title)
|
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
from kash.actions.core.
|
|
2
|
-
from kash.actions.core.webpage_generate import webpage_generate
|
|
1
|
+
from kash.actions.core.render_as_html import render_as_html
|
|
3
2
|
from kash.commands.base.show_command import show
|
|
4
|
-
from kash.config.logger import get_logger
|
|
5
3
|
from kash.exec import kash_action
|
|
6
|
-
from kash.exec.preconditions import
|
|
4
|
+
from kash.exec.preconditions import has_full_html_page_body, has_html_body, has_simple_text_body
|
|
5
|
+
from kash.exec_model.args_model import ONE_OR_MORE_ARGS
|
|
7
6
|
from kash.exec_model.commands_model import Command
|
|
8
7
|
from kash.exec_model.shell_model import ShellResult
|
|
9
8
|
from kash.model import ActionInput, ActionResult
|
|
10
9
|
|
|
11
|
-
log = get_logger(__name__)
|
|
12
|
-
|
|
13
10
|
|
|
14
11
|
@kash_action(
|
|
15
|
-
|
|
12
|
+
expected_args=ONE_OR_MORE_ARGS,
|
|
13
|
+
precondition=(has_html_body | has_simple_text_body) & ~has_full_html_page_body,
|
|
16
14
|
)
|
|
17
15
|
def show_webpage(input: ActionInput) -> ActionResult:
|
|
18
16
|
"""
|
|
19
17
|
Show text, Markdown, or HTML as a nicely formatted webpage.
|
|
20
18
|
"""
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
log.message("Configured web page: %s", config_result)
|
|
24
|
-
result = webpage_generate(ActionInput(items=config_result.items))
|
|
19
|
+
result = render_as_html(input)
|
|
25
20
|
|
|
26
21
|
# Automatically show the result.
|
|
27
22
|
result.shell_result = ShellResult(display_command=Command.assemble(show))
|
kash/actions/core/strip_html.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
from kash.config.logger import get_logger
|
|
2
2
|
from kash.exec import kash_action
|
|
3
|
-
from kash.exec.preconditions import has_html_body,
|
|
4
|
-
from kash.model import Format, Item
|
|
3
|
+
from kash.exec.preconditions import has_html_body, has_simple_text_body
|
|
4
|
+
from kash.model import Format, Item
|
|
5
5
|
from kash.utils.common.format_utils import html_to_plaintext
|
|
6
6
|
from kash.utils.errors import InvalidInput
|
|
7
7
|
|
|
8
8
|
log = get_logger(__name__)
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
@kash_action(precondition=has_html_body |
|
|
11
|
+
@kash_action(precondition=has_html_body | has_simple_text_body)
|
|
12
12
|
def strip_html(item: Item) -> Item:
|
|
13
13
|
"""
|
|
14
14
|
Strip HTML tags from HTML or Markdown. This is a simple filter, simply searching
|
|
@@ -19,10 +19,6 @@ def strip_html(item: Item) -> Item:
|
|
|
19
19
|
raise InvalidInput("Item must have a body")
|
|
20
20
|
|
|
21
21
|
clean_body = html_to_plaintext(item.body)
|
|
22
|
-
output_item = item.derived_copy(
|
|
23
|
-
type=ItemType.doc,
|
|
24
|
-
format=Format.markdown,
|
|
25
|
-
body=clean_body,
|
|
26
|
-
)
|
|
22
|
+
output_item = item.derived_copy(format=Format.markdown, body=clean_body)
|
|
27
23
|
|
|
28
24
|
return output_item
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from kash.config.logger import get_logger
|
|
2
2
|
from kash.exec import kash_action
|
|
3
|
+
from kash.exec_model.args_model import ONE_OR_MORE_ARGS
|
|
3
4
|
from kash.model import ActionInput, ActionResult, Param
|
|
4
5
|
from kash.utils.errors import InvalidInput
|
|
5
6
|
from kash.web_gen import tabbed_webpage
|
|
@@ -8,15 +9,16 @@ log = get_logger(__name__)
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
@kash_action(
|
|
12
|
+
expected_args=ONE_OR_MORE_ARGS,
|
|
11
13
|
params=(
|
|
12
14
|
Param(
|
|
13
15
|
name="clean_headings",
|
|
14
16
|
type=bool,
|
|
15
17
|
description="Use an LLM to clean up headings.",
|
|
16
18
|
),
|
|
17
|
-
)
|
|
19
|
+
),
|
|
18
20
|
)
|
|
19
|
-
def
|
|
21
|
+
def tabbed_webpage_config(input: ActionInput, clean_headings: bool = False) -> ActionResult:
|
|
20
22
|
"""
|
|
21
23
|
Set up a web page config with optional tabs for each page of content. Uses first item as the page title.
|
|
22
24
|
"""
|
|
@@ -24,6 +26,6 @@ def webpage_config(input: ActionInput, clean_headings: bool = False) -> ActionRe
|
|
|
24
26
|
if not item.body:
|
|
25
27
|
raise InvalidInput(f"Item must have a body: {item}")
|
|
26
28
|
|
|
27
|
-
config_item = tabbed_webpage.
|
|
29
|
+
config_item = tabbed_webpage.tabbed_webpage_config(input.items, clean_headings)
|
|
28
30
|
|
|
29
31
|
return ActionResult([config_item])
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from kash.config.logger import get_logger
|
|
2
2
|
from kash.exec import kash_action
|
|
3
3
|
from kash.exec.preconditions import is_config
|
|
4
|
-
from kash.model import ONE_ARG, ActionInput, ActionResult, FileExt, Format, Item, ItemType
|
|
4
|
+
from kash.model import ONE_ARG, ActionInput, ActionResult, FileExt, Format, Item, ItemType, Param
|
|
5
5
|
from kash.web_gen import tabbed_webpage
|
|
6
6
|
|
|
7
7
|
log = get_logger(__name__)
|
|
@@ -10,13 +10,14 @@ log = get_logger(__name__)
|
|
|
10
10
|
@kash_action(
|
|
11
11
|
expected_args=ONE_ARG,
|
|
12
12
|
precondition=is_config,
|
|
13
|
+
params=(Param("add_title", "Add a title to the page body.", type=bool),),
|
|
13
14
|
)
|
|
14
|
-
def
|
|
15
|
+
def tabbed_webpage_generate(input: ActionInput, add_title: bool = False) -> ActionResult:
|
|
15
16
|
"""
|
|
16
|
-
Generate a web page from a
|
|
17
|
+
Generate a tabbed web page from a config item for the tabbed template.
|
|
17
18
|
"""
|
|
18
19
|
config_item = input.items[0]
|
|
19
|
-
html = tabbed_webpage.
|
|
20
|
+
html = tabbed_webpage.tabbed_webpage_generate(config_item, add_title_h1=add_title)
|
|
20
21
|
|
|
21
22
|
webpage_item = Item(
|
|
22
23
|
title=config_item.title,
|
|
@@ -2,7 +2,7 @@ import os
|
|
|
2
2
|
|
|
3
3
|
from frontmatter_format import fmf_read_raw, fmf_strip_frontmatter
|
|
4
4
|
from prettyfmt import fmt_lines
|
|
5
|
-
from strif import copyfile_atomic
|
|
5
|
+
from strif import atomic_output_file, copyfile_atomic
|
|
6
6
|
|
|
7
7
|
from kash.config.logger import get_logger
|
|
8
8
|
from kash.config.text_styles import STYLE_EMPH
|
|
@@ -28,10 +28,10 @@ log = get_logger(__name__)
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
@kash_command
|
|
31
|
-
def
|
|
31
|
+
def clipboard_copy(path: str | None = None, raw: bool = False) -> None:
|
|
32
32
|
"""
|
|
33
33
|
Copy the contents of a file (or the first file in the selection) to the OS-native
|
|
34
|
-
clipboard.
|
|
34
|
+
clipboard. Similar to `pbcopy` on macOS.
|
|
35
35
|
|
|
36
36
|
:param raw: Copy the full exact contents of the file. Otherwise frontmatter is omitted.
|
|
37
37
|
"""
|
|
@@ -39,6 +39,8 @@ def cbcopy(path: str | None = None, raw: bool = False) -> None:
|
|
|
39
39
|
import pyperclip
|
|
40
40
|
|
|
41
41
|
input_paths = assemble_path_args(path)
|
|
42
|
+
if not input_paths:
|
|
43
|
+
raise InvalidInput("No path provided")
|
|
42
44
|
input_path = input_paths[0]
|
|
43
45
|
|
|
44
46
|
format = detect_file_format(input_path)
|
|
@@ -69,6 +71,22 @@ def cbcopy(path: str | None = None, raw: bool = False) -> None:
|
|
|
69
71
|
)
|
|
70
72
|
|
|
71
73
|
|
|
74
|
+
@kash_command
|
|
75
|
+
def clipboard_paste(path: str = "untitled_paste.txt") -> None:
|
|
76
|
+
"""
|
|
77
|
+
Paste the contents of the OS-native clipboard into a new file.
|
|
78
|
+
"""
|
|
79
|
+
# TODO: Get this to work for images!
|
|
80
|
+
# And can we convert rich text to Markdown?
|
|
81
|
+
import pyperclip
|
|
82
|
+
|
|
83
|
+
contents = pyperclip.paste()
|
|
84
|
+
with atomic_output_file(path, backup_suffix=".{timestamp}.bak") as f:
|
|
85
|
+
f.write_text(contents)
|
|
86
|
+
|
|
87
|
+
print_status("Pasted clipboard contents to:\n%s", fmt_lines([fmt_loc(path)]))
|
|
88
|
+
|
|
89
|
+
|
|
72
90
|
@kash_command
|
|
73
91
|
def edit(path: str | None = None, all: bool = False) -> None:
|
|
74
92
|
"""
|
|
@@ -75,6 +75,10 @@ def _print_listing_tallies(
|
|
|
75
75
|
cprint("(use --no_max to remove cutoff)", style=STYLE_HINT)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
DEFAULT_MAX_PER_GROUP = 50
|
|
79
|
+
"""Default maximum number of files to display per group."""
|
|
80
|
+
|
|
81
|
+
|
|
78
82
|
@kash_command
|
|
79
83
|
def files(
|
|
80
84
|
*paths: str,
|
|
@@ -108,9 +112,11 @@ def files(
|
|
|
108
112
|
and grouping.
|
|
109
113
|
|
|
110
114
|
:param overview: Recurse a couple levels and show files, but not too many.
|
|
111
|
-
Same as `--groupby=parent --depth=2 --max_per_group=
|
|
115
|
+
Same as `--groupby=parent --depth=2 --max_per_group=100 --omit_dirs`
|
|
116
|
+
except also scales down `max_per_group` to 25 or 50 if there are many files.
|
|
112
117
|
:param recent: Only shows the most recently modified files in each directory.
|
|
113
|
-
Same as `--sort=modified --reverse --groupby=parent --max_per_group=
|
|
118
|
+
Same as `--sort=modified --reverse --groupby=parent --max_per_group=100`
|
|
119
|
+
except also scales down `max_per_group` to 25 or 50 if there are many files.
|
|
114
120
|
:param recursive: List all files recursively. Same as `--depth=-1`.
|
|
115
121
|
:param flat: Show files in a flat list, rather than grouped by parent directory.
|
|
116
122
|
Same as `--groupby=flat`.
|
|
@@ -179,16 +185,17 @@ def files(
|
|
|
179
185
|
# Within workspaces, we show more files by default since they are always in
|
|
180
186
|
# subdirectories.
|
|
181
187
|
overview = True # Handled next.
|
|
188
|
+
cap_per_group = False
|
|
182
189
|
if overview:
|
|
183
|
-
max_per_group = 10 if max_per_group <= 0 else max_per_group
|
|
184
190
|
groupby = GroupByOption.parent if groupby is None else groupby
|
|
185
191
|
depth = 2 if depth is None else depth
|
|
192
|
+
cap_per_group = True
|
|
186
193
|
omit_dirs = True
|
|
187
194
|
if recent:
|
|
188
|
-
max_per_group = 10 if max_per_group <= 0 else max_per_group
|
|
189
195
|
groupby = GroupByOption.parent if groupby is None else groupby
|
|
190
196
|
depth = 2 if depth is None else depth
|
|
191
197
|
sort = SortOption.modified if sort is None else sort
|
|
198
|
+
cap_per_group = True
|
|
192
199
|
reverse = True
|
|
193
200
|
if flat:
|
|
194
201
|
groupby = GroupByOption.flat
|
|
@@ -291,6 +298,18 @@ def files(
|
|
|
291
298
|
|
|
292
299
|
return ShellResult(show_selection=True)
|
|
293
300
|
|
|
301
|
+
# Unless max_per_group is explicit, use heuristics to limit per group if
|
|
302
|
+
# there are lots of groups and lots of files per group.
|
|
303
|
+
# Default is max 100 per group but if we have 4 * 100 items, cut to 25.
|
|
304
|
+
# If we have 2 * 100 items, cut to 50.
|
|
305
|
+
final_max_pg = DEFAULT_MAX_PER_GROUP if cap_per_group else max_per_group
|
|
306
|
+
max_pg_explicit = max_per_group > 0
|
|
307
|
+
if not max_pg_explicit:
|
|
308
|
+
group_lens = [len(group_df) for group_df in grouped]
|
|
309
|
+
for ratio in [2, 4]:
|
|
310
|
+
if sum(group_lens) > ratio * DEFAULT_MAX_PER_GROUP:
|
|
311
|
+
final_max_pg = int(DEFAULT_MAX_PER_GROUP / ratio)
|
|
312
|
+
|
|
294
313
|
total_displayed = 0
|
|
295
314
|
total_displayed_size = 0
|
|
296
315
|
now = datetime.now(UTC)
|
|
@@ -312,8 +331,8 @@ def files(
|
|
|
312
331
|
text_wrap=Wrap.NONE,
|
|
313
332
|
)
|
|
314
333
|
|
|
315
|
-
if
|
|
316
|
-
display_df = group_df.head(
|
|
334
|
+
if final_max_pg > 0:
|
|
335
|
+
display_df = group_df.head(final_max_pg)
|
|
317
336
|
else:
|
|
318
337
|
display_df = group_df
|
|
319
338
|
|
|
@@ -378,9 +397,9 @@ def files(
|
|
|
378
397
|
total_displayed_size += row.size
|
|
379
398
|
|
|
380
399
|
# Indicate if items are omitted.
|
|
381
|
-
if groupby and
|
|
400
|
+
if groupby and final_max_pg > 0 and len(group_df) > final_max_pg:
|
|
382
401
|
cprint(
|
|
383
|
-
f"{indent}… and {len(group_df) -
|
|
402
|
+
f"{indent}… and {len(group_df) - final_max_pg} more files",
|
|
384
403
|
style=COLOR_EXTRA,
|
|
385
404
|
text_wrap=Wrap.NONE,
|
|
386
405
|
)
|
|
@@ -388,9 +407,9 @@ def files(
|
|
|
388
407
|
if group_name:
|
|
389
408
|
PrintHooks.spacer()
|
|
390
409
|
|
|
391
|
-
if not groupby and
|
|
410
|
+
if not groupby and final_max_pg > 0 and items_matching > final_max_pg:
|
|
392
411
|
cprint(
|
|
393
|
-
f"{indent}… and {items_matching -
|
|
412
|
+
f"{indent}… and {items_matching - final_max_pg} more files",
|
|
394
413
|
style=COLOR_EXTRA,
|
|
395
414
|
text_wrap=Wrap.NONE,
|
|
396
415
|
)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import subprocess
|
|
2
4
|
import tomllib
|
|
3
5
|
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
4
7
|
|
|
5
|
-
import pandas as pd
|
|
6
8
|
from packaging.tags import Tag, sys_tags
|
|
7
9
|
from packaging.utils import parse_wheel_filename
|
|
8
10
|
from prettyfmt import fmt_size_dual
|
|
@@ -13,6 +15,9 @@ from kash.config.text_styles import COLOR_STATUS
|
|
|
13
15
|
from kash.exec import kash_command
|
|
14
16
|
from kash.shell.output.shell_output import cprint
|
|
15
17
|
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from pandas import DataFrame
|
|
20
|
+
|
|
16
21
|
log = get_logger(__name__)
|
|
17
22
|
|
|
18
23
|
|
|
@@ -49,13 +54,15 @@ def get_platform() -> str:
|
|
|
49
54
|
return next(sys_tags()).platform
|
|
50
55
|
|
|
51
56
|
|
|
52
|
-
def parse_uv_lock(lock_path: Path) ->
|
|
57
|
+
def parse_uv_lock(lock_path: Path) -> DataFrame:
|
|
53
58
|
"""
|
|
54
59
|
Return one row per package from a uv.lock file, selecting the best
|
|
55
60
|
matching wheel for the current interpreter or falling back to the sdist.
|
|
56
61
|
|
|
57
62
|
Columns: name, version, registry, file_type, url, hash, size, filename.
|
|
58
63
|
"""
|
|
64
|
+
from pandas import DataFrame
|
|
65
|
+
|
|
59
66
|
with open(lock_path, "rb") as f:
|
|
60
67
|
data = tomllib.load(f)
|
|
61
68
|
|
|
@@ -88,7 +95,7 @@ def parse_uv_lock(lock_path: Path) -> pd.DataFrame:
|
|
|
88
95
|
}
|
|
89
96
|
)
|
|
90
97
|
|
|
91
|
-
return
|
|
98
|
+
return DataFrame(rows)
|
|
92
99
|
|
|
93
100
|
|
|
94
101
|
def uv_runtime_packages(
|
|
@@ -141,6 +148,8 @@ def uv_dep_info(
|
|
|
141
148
|
By default, filters to show only 'main' dependencies from pyproject.toml.
|
|
142
149
|
Helpful for looking at sizes of dependencies.
|
|
143
150
|
"""
|
|
151
|
+
import pandas as pd
|
|
152
|
+
|
|
144
153
|
uv_lock_path = Path(uv_lock)
|
|
145
154
|
pyproject_path = Path(pyproject)
|
|
146
155
|
|
|
@@ -10,8 +10,8 @@ from kash.exec_model.shell_model import ShellResult
|
|
|
10
10
|
from kash.model.paths_model import StorePath
|
|
11
11
|
from kash.shell.ui.shell_results import shell_print_selection_history
|
|
12
12
|
from kash.utils.common.format_utils import fmt_loc
|
|
13
|
+
from kash.utils.common.inflection import plural
|
|
13
14
|
from kash.utils.errors import InvalidInput
|
|
14
|
-
from kash.utils.lang_utils.inflection import plural
|
|
15
15
|
from kash.workspaces import Selection, current_ws
|
|
16
16
|
|
|
17
17
|
log = get_logger(__name__)
|
|
@@ -51,6 +51,7 @@ from kash.shell.output.shell_output import (
|
|
|
51
51
|
)
|
|
52
52
|
from kash.shell.utils.native_utils import tail_file
|
|
53
53
|
from kash.utils.common.format_utils import fmt_loc
|
|
54
|
+
from kash.utils.common.inflection import plural
|
|
54
55
|
from kash.utils.common.obj_replace import remove_values
|
|
55
56
|
from kash.utils.common.parse_key_vals import parse_key_value
|
|
56
57
|
from kash.utils.common.type_utils import not_none
|
|
@@ -58,7 +59,6 @@ from kash.utils.common.url import Url, is_url
|
|
|
58
59
|
from kash.utils.errors import InvalidInput
|
|
59
60
|
from kash.utils.file_formats.chat_format import tail_chat_history
|
|
60
61
|
from kash.utils.file_utils.dir_info import is_nonempty_dir
|
|
61
|
-
from kash.utils.lang_utils.inflection import plural
|
|
62
62
|
from kash.web_content.file_cache_utils import cache_file
|
|
63
63
|
from kash.workspaces import (
|
|
64
64
|
current_ws,
|
|
@@ -285,7 +285,7 @@ def init_workspace(path: str | None = None) -> None:
|
|
|
285
285
|
@kash_command
|
|
286
286
|
def workspace(workspace_name: str | None = None) -> None:
|
|
287
287
|
"""
|
|
288
|
-
If no args are given,
|
|
288
|
+
If no args are given, show current workspace info.
|
|
289
289
|
If a workspace name is given, change to that workspace, creating it if it doesn't exist.
|
|
290
290
|
"""
|
|
291
291
|
if workspace_name:
|
|
@@ -302,7 +302,6 @@ def workspace(workspace_name: str | None = None) -> None:
|
|
|
302
302
|
ws.log_workspace_info()
|
|
303
303
|
else:
|
|
304
304
|
ws = current_ws(silent=True)
|
|
305
|
-
os.chdir(ws.base_dir)
|
|
306
305
|
ws.log_workspace_info()
|
|
307
306
|
|
|
308
307
|
|
kash/config/colors.py
CHANGED
|
@@ -136,8 +136,8 @@ web_light_translucent = SimpleNamespace(
|
|
|
136
136
|
bg=hsl_to_hex("hsla(44, 6%, 100%, 0.75)"),
|
|
137
137
|
bg_solid=hsl_to_hex("hsla(44, 6%, 100%, 1)"),
|
|
138
138
|
bg_header=hsl_to_hex("hsla(188, 42%, 70%, 0.2)"),
|
|
139
|
-
bg_alt=hsl_to_hex("hsla(
|
|
140
|
-
bg_alt_solid=hsl_to_hex("hsla(
|
|
139
|
+
bg_alt=hsl_to_hex("hsla(39, 24%, 90%, 0.3)"),
|
|
140
|
+
bg_alt_solid=hsl_to_hex("hsla(39, 24%, 97%, 1)"),
|
|
141
141
|
text=hsl_to_hex("hsl(188, 39%, 11%)"),
|
|
142
142
|
border=hsl_to_hex("hsl(188, 8%, 50%)"),
|
|
143
143
|
border_hint=hsl_to_hex("hsla(188, 8%, 72%, 0.7)"),
|
kash/config/env_settings.py
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
from enum import Enum
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import overload
|
|
1
|
+
from clideps.env_vars.env_enum import EnvEnum
|
|
5
2
|
|
|
6
3
|
|
|
7
|
-
class KashEnv(
|
|
4
|
+
class KashEnv(EnvEnum):
|
|
8
5
|
"""
|
|
9
6
|
Environment variable settings for kash. None are required, but these may be
|
|
10
7
|
used to override default values.
|
|
@@ -33,40 +30,3 @@ class KashEnv(str, Enum):
|
|
|
33
30
|
|
|
34
31
|
KASH_USER_AGENT = "KASH_USER_AGENT"
|
|
35
32
|
"""The user agent to use for HTTP requests."""
|
|
36
|
-
|
|
37
|
-
@overload
|
|
38
|
-
def read_str(self) -> str | None: ...
|
|
39
|
-
|
|
40
|
-
@overload
|
|
41
|
-
def read_str(self, default: str) -> str: ...
|
|
42
|
-
|
|
43
|
-
def read_str(self, default: str | None = None) -> str | None:
|
|
44
|
-
"""
|
|
45
|
-
Get the value of the environment variable from the environment (with
|
|
46
|
-
optional default).
|
|
47
|
-
"""
|
|
48
|
-
return os.environ.get(self.value, default)
|
|
49
|
-
|
|
50
|
-
@overload
|
|
51
|
-
def read_path(self) -> Path | None: ...
|
|
52
|
-
|
|
53
|
-
@overload
|
|
54
|
-
def read_path(self, default: Path) -> Path: ...
|
|
55
|
-
|
|
56
|
-
def read_path(self, default: Path | None = None) -> Path | None:
|
|
57
|
-
"""
|
|
58
|
-
Get the value of the environment variable as a resolved path (with
|
|
59
|
-
optional default).
|
|
60
|
-
"""
|
|
61
|
-
value = os.environ.get(self.value)
|
|
62
|
-
if value:
|
|
63
|
-
return Path(value).expanduser().resolve()
|
|
64
|
-
else:
|
|
65
|
-
return default.expanduser().resolve() if default else None
|
|
66
|
-
|
|
67
|
-
def read_bool(self, default: bool = False) -> bool:
|
|
68
|
-
"""
|
|
69
|
-
Get the value of the environment variable as a boolean.
|
|
70
|
-
"""
|
|
71
|
-
value = str(os.environ.get(self.value, default) or "").lower()
|
|
72
|
-
return bool(value and value != "0" and value != "false" and value != "no")
|
kash/config/logger.py
CHANGED
|
@@ -55,6 +55,10 @@ class LogSettings:
|
|
|
55
55
|
log_objects_dir: Path
|
|
56
56
|
log_file_path: Path
|
|
57
57
|
|
|
58
|
+
@property
|
|
59
|
+
def is_quiet(self) -> bool:
|
|
60
|
+
return self.log_console_level >= LogLevel.error
|
|
61
|
+
|
|
58
62
|
|
|
59
63
|
LOG_NAME_GLOBAL = "workspace"
|
|
60
64
|
|
|
@@ -83,6 +87,13 @@ def get_log_settings() -> LogSettings:
|
|
|
83
87
|
return _log_settings.copy()
|
|
84
88
|
|
|
85
89
|
|
|
90
|
+
def is_console_quiet() -> bool:
|
|
91
|
+
"""
|
|
92
|
+
Whether to suppress non-logging console output.
|
|
93
|
+
"""
|
|
94
|
+
return global_settings().console_quiet
|
|
95
|
+
|
|
96
|
+
|
|
86
97
|
def make_valid_log_name(name: str) -> str:
|
|
87
98
|
name = str(name).strip().rstrip("/").removesuffix(".log")
|
|
88
99
|
name = re.sub(r"[^\w-]", "_", name)
|
|
@@ -244,14 +255,6 @@ def _do_logging_setup(log_settings: LogSettings):
|
|
|
244
255
|
|
|
245
256
|
# Manually adjust logging for a few packages, removing previous verbose default handlers.
|
|
246
257
|
|
|
247
|
-
try:
|
|
248
|
-
import litellm
|
|
249
|
-
from litellm import _logging # noqa: F401
|
|
250
|
-
|
|
251
|
-
litellm.suppress_debug_info = True # Suppress overly prominent exception messages.
|
|
252
|
-
except ImportError:
|
|
253
|
-
pass
|
|
254
|
-
|
|
255
258
|
log_levels = {
|
|
256
259
|
None: INFO,
|
|
257
260
|
"LiteLLM": INFO,
|
|
@@ -276,10 +279,12 @@ def prefix(line: str, emoji: str = "", warn_emoji: str = "") -> str:
|
|
|
276
279
|
return " ".join(filter(None, [prefix, emojis, line]))
|
|
277
280
|
|
|
278
281
|
|
|
279
|
-
def prefix_args(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
282
|
+
def prefix_args(
|
|
283
|
+
msg: object, *other_args: object, emoji: str = "", warn_emoji: str = ""
|
|
284
|
+
) -> tuple[str, *tuple[object, ...]]:
|
|
285
|
+
"""Prefixes the string representation of msg and returns it with other_args."""
|
|
286
|
+
prefixed_msg = prefix(str(msg), emoji, warn_emoji)
|
|
287
|
+
return (prefixed_msg,) + other_args
|
|
283
288
|
|
|
284
289
|
|
|
285
290
|
class CustomLogger(logging.Logger):
|
|
@@ -290,29 +295,29 @@ class CustomLogger(logging.Logger):
|
|
|
290
295
|
"""
|
|
291
296
|
|
|
292
297
|
@override
|
|
293
|
-
def debug(self, *args, **kwargs):
|
|
294
|
-
super().debug(*prefix_args(args), **kwargs)
|
|
298
|
+
def debug(self, msg: object, *args: object, **kwargs: Any) -> None:
|
|
299
|
+
super().debug(*prefix_args(msg, *args), **kwargs)
|
|
295
300
|
|
|
296
301
|
@override
|
|
297
|
-
def info(self, *args, **kwargs):
|
|
298
|
-
super().info(*prefix_args(args), **kwargs)
|
|
302
|
+
def info(self, msg: object, *args: object, **kwargs: Any) -> None:
|
|
303
|
+
super().info(*prefix_args(msg, *args), **kwargs)
|
|
299
304
|
|
|
300
305
|
@override
|
|
301
|
-
def warning(self, *args, **kwargs):
|
|
302
|
-
super().warning(*prefix_args(args, warn_emoji=EMOJI_WARN), **kwargs)
|
|
306
|
+
def warning(self, msg: object, *args: object, **kwargs: Any) -> None:
|
|
307
|
+
super().warning(*prefix_args(msg, *args, warn_emoji=EMOJI_WARN), **kwargs)
|
|
303
308
|
|
|
304
309
|
@override
|
|
305
|
-
def error(self, *args, **kwargs):
|
|
306
|
-
super().error(*prefix_args(args, warn_emoji=EMOJI_ERROR), **kwargs)
|
|
310
|
+
def error(self, msg: object, *args: object, **kwargs: Any) -> None:
|
|
311
|
+
super().error(*prefix_args(msg, *args, warn_emoji=EMOJI_ERROR), **kwargs)
|
|
307
312
|
|
|
308
|
-
def log_at(self, level: LogLevel, *args, **kwargs):
|
|
313
|
+
def log_at(self, level: LogLevel, *args: object, **kwargs: Any) -> None:
|
|
309
314
|
getattr(self, level.name)(*args, **kwargs)
|
|
310
315
|
|
|
311
|
-
def message(self, *args, **kwargs):
|
|
316
|
+
def message(self, msg: object, *args: object, **kwargs: Any) -> None:
|
|
312
317
|
"""
|
|
313
318
|
An informative message that should appear even if log level is set to warning.
|
|
314
319
|
"""
|
|
315
|
-
super().warning(*prefix_args(args), **kwargs)
|
|
320
|
+
super().warning(*prefix_args(msg, *args), **kwargs)
|
|
316
321
|
|
|
317
322
|
def save_object(
|
|
318
323
|
self,
|
|
@@ -321,7 +326,7 @@ class CustomLogger(logging.Logger):
|
|
|
321
326
|
obj: Any,
|
|
322
327
|
level: LogLevel = LogLevel.info,
|
|
323
328
|
file_ext: str = "txt",
|
|
324
|
-
):
|
|
329
|
+
) -> None:
|
|
325
330
|
"""
|
|
326
331
|
Save an object to a file in the log directory. Useful for details too large to
|
|
327
332
|
log normally but useful for debugging.
|
|
@@ -342,7 +347,7 @@ class CustomLogger(logging.Logger):
|
|
|
342
347
|
|
|
343
348
|
self.log_at(level, "%s %s saved: %s", EMOJI_SAVED, description, path)
|
|
344
349
|
|
|
345
|
-
def dump_stack(self, all_threads: bool = True, level: LogLevel = LogLevel.info):
|
|
350
|
+
def dump_stack(self, all_threads: bool = True, level: LogLevel = LogLevel.info) -> None:
|
|
346
351
|
self.log_at(level, "Stack trace dump:\n%s", current_stack_traces(all_threads))
|
|
347
352
|
|
|
348
353
|
def __repr__(self):
|