setting up slop app

This commit is contained in:
2026-02-21 14:06:32 -05:00
parent 7e06facc28
commit d37426401a
8 changed files with 5007 additions and 14 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
credentials.toml

View File

@@ -24,7 +24,6 @@ def is_absolute_with_drive(entry: str) -> bool:
def resolve_paths(base_dir: Path, entry: str) -> list[Path]: def resolve_paths(base_dir: Path, entry: str) -> list[Path]:
has_drive = is_absolute_with_drive(entry) has_drive = is_absolute_with_drive(entry)
is_wildcard = "*" in entry is_wildcard = "*" in entry
if is_wildcard: if is_wildcard:
root = Path(entry) if has_drive else base_dir / entry root = Path(entry) if has_drive else base_dir / entry
matches = [Path(p) for p in glob.glob(str(root), recursive=True) if Path(p).is_file()] matches = [Path(p) for p in glob.glob(str(root), recursive=True) if Path(p).is_file()]
@@ -34,7 +33,13 @@ def resolve_paths(base_dir: Path, entry: str) -> list[Path]:
return [Path(entry)] return [Path(entry)]
return [(base_dir / entry).resolve()] return [(base_dir / entry).resolve()]
def build_markdown(base_dir: Path, files: list[str]) -> str: def build_discussion_section(history: list[str]) -> str:
sections = []
for i, paste in enumerate(history, start=1):
sections.append(f"### Discussion Excerpt {i}\n\n{paste.strip()}")
return "\n\n---\n\n".join(sections)
def build_files_section(base_dir: Path, files: list[str]) -> str:
sections = [] sections = []
for entry in files: for entry in files:
paths = resolve_paths(base_dir, entry) paths = resolve_paths(base_dir, entry)
@@ -50,27 +55,56 @@ def build_markdown(base_dir: Path, files: list[str]) -> str:
content = f"ERROR: file not found: {path}" content = f"ERROR: file not found: {path}"
except Exception as e: except Exception as e:
content = f"ERROR: {e}" content = f"ERROR: {e}"
original = entry if not ("*" in entry) else str(path) original = entry if "*" not in entry else str(path)
sections.append(f"### `{original}`\n\n```{lang}\n{content}\n```") sections.append(f"### `{original}`\n\n```{lang}\n{content}\n```")
return "\n\n---\n\n".join(sections) return "\n\n---\n\n".join(sections)
def main(): def build_screenshots_section(base_dir: Path, screenshots: list[str]) -> str:
config_path = Path("config.toml") sections = []
with config_path.open("rb") as f: for entry in screenshots:
config = tomllib.load(f) paths = resolve_paths(base_dir, entry)
if not paths:
sections.append(f"### `{entry}`\n\n_ERROR: no files matched: {entry}_")
continue
for path in paths:
original = entry if "*" not in entry else str(path)
if not path.exists():
sections.append(f"### `{original}`\n\n_ERROR: file not found: {path}_")
continue
sections.append(f"### `{original}`\n\n![{path.name}]({path.as_posix()})")
return "\n\n---\n\n".join(sections)
def build_markdown(base_dir: Path, files: list[str], screenshot_base_dir: Path, screenshots: list[str], history: list[str]) -> str:
parts = []
if history:
parts.append("## Discussion History\n\n" + build_discussion_section(history))
if files:
parts.append("## Files\n\n" + build_files_section(base_dir, files))
if screenshots:
parts.append("## Screenshots\n\n" + build_screenshots_section(screenshot_base_dir, screenshots))
return "\n\n---\n\n".join(parts)
def run(config: dict) -> tuple[str, Path]:
namespace = config["output"]["namespace"] namespace = config["output"]["namespace"]
output_dir = Path(config["output"]["output_dir"]) output_dir = Path(config["output"]["output_dir"])
base_dir = Path(config["files"]["base_dir"]) base_dir = Path(config["files"]["base_dir"])
files = config["files"].get("paths", []) files = config["files"].get("paths", [])
screenshot_base_dir = Path(config.get("screenshots", {}).get("base_dir", "."))
screenshots = config.get("screenshots", {}).get("paths", [])
history = config.get("discussion", {}).get("history", [])
output_dir.mkdir(parents=True, exist_ok=True) output_dir.mkdir(parents=True, exist_ok=True)
increment = find_next_increment(output_dir, namespace) increment = find_next_increment(output_dir, namespace)
output_file = output_dir / f"{namespace}_{increment:03d}.md" output_file = output_dir / f"{namespace}_{increment:03d}.md"
markdown = build_markdown(base_dir, files, screenshot_base_dir, screenshots, history)
markdown = build_markdown(base_dir, files)
output_file.write_text(markdown, encoding="utf-8") output_file.write_text(markdown, encoding="utf-8")
return markdown, output_file
def main():
with open("config.toml", "rb") as f:
import tomllib
config = tomllib.load(f)
markdown, output_file = run(config)
print(f"Written: {output_file}") print(f"Written: {output_file}")
if __name__ == "__main__": if __name__ == "__main__":

4323
colorforth_bootslop_001.md Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -16,3 +16,14 @@ paths = [
"GEMINI.md", "GEMINI.md",
"CONVENTIONS.md" "CONVENTIONS.md"
] ]
[screenshots]
base_dir = "C:/Users/Ed/scoop/apps/sharex/current/ShareX/Screenshots/2026-02"
paths = [
]
[discussion]
history = [
]

38
gemini.py Normal file
View File

@@ -0,0 +1,38 @@
# gemini.py
import tomllib
from pathlib import Path
import google.generativeai as genai
_cache = None
_model = None
_chat = None
def _load_key() -> str:
with open("credentials.toml", "rb") as f:
return tomllib.load(f)["gemini"]["api_key"]
def _ensure_model():
global _model
if _model is None:
genai.configure(api_key=_load_key())
_model = genai.GenerativeModel("gemini-1.5-pro")
def _ensure_chat():
global _chat
if _chat is None:
_ensure_model()
_chat = _model.start_chat(history=[])
def send(md_content: str, user_message: str) -> str:
global _cache, _chat
_ensure_chat()
full_message = f"<context>\n{md_content}\n</context>\n\n{user_message}"
response = _chat.send_message(full_message)
return response.text
def reset_session():
global _cache, _model, _chat
_cache = None
_model = None
_chat = None

575
gui.py Normal file
View File

@@ -0,0 +1,575 @@
# gui.py
import tomllib
import tomli_w
import imgui
import pygame
from imgui.integrations.pygame import PygameRenderer
from pathlib import Path
from tkinter import filedialog, Tk
import threading
import aggregate
import gemini
CONFIG_PATH = Path("config.toml")
def load_config() -> dict:
with open(CONFIG_PATH, "rb") as f:
return tomllib.load(f)
def save_config(config: dict):
with open(CONFIG_PATH, "wb") as f:
tomli_w.dump(config, f)
def hide_tk_root() -> Tk:
root = Tk()
root.withdraw()
root.wm_attributes("-topmost", True)
return root
class State:
def __init__(self):
self.config = load_config()
self.namespace_buf = self.config["output"]["namespace"]
self.output_dir_buf = self.config["output"]["output_dir"]
self.files_base_dir_buf = self.config["files"]["base_dir"]
self.screenshots_base_dir_buf = self.config.get("screenshots", {}).get("base_dir", ".")
self.files = list(self.config["files"].get("paths", []))
self.screenshots = list(self.config.get("screenshots", {}).get("paths", []))
self.history = list(self.config.get("discussion", {}).get("history", []))
self.history_edit_bufs = [h for h in self.history]
self.gemini_input_buf = ""
self.gemini_response = ""
self.gemini_status = "idle"
self.last_md = ""
self.last_md_path = None
self.send_thread = None
def flush_to_config(self):
self.config["output"]["namespace"] = self.namespace_buf
self.config["output"]["output_dir"] = self.output_dir_buf
self.config["files"]["base_dir"] = self.files_base_dir_buf
if "screenshots" not in self.config:
self.config["screenshots"] = {}
self.config["screenshots"]["base_dir"] = self.screenshots_base_dir_buf
self.config["files"]["paths"] = self.files
self.config["screenshots"]["paths"] = self.screenshots
self.config["discussion"] = {"history": self.history_edit_bufs}
def sync_history_bufs(self):
while len(self.history_edit_bufs) < len(self.history):
self.history_edit_bufs.append("")
self.history_edit_bufs = self.history_edit_bufs[:len(self.history)]
def draw_config_panel(state: State):
imgui.begin("Config")
changed, val = imgui.input_text("Namespace", state.namespace_buf, 256)
if changed:
state.namespace_buf = val
changed, val = imgui.input_text("Output Dir", state.output_dir_buf, 512)
if changed:
state.output_dir_buf = val
if imgui.button("Save Config"):
state.flush_to_config()
save_config(state.config)
imgui.end()
def draw_files_panel(state: State):
imgui.begin("Files")
changed, val = imgui.input_text("Base Dir##files", state.files_base_dir_buf, 512)
if changed:
state.files_base_dir_buf = val
if imgui.button("Browse Base Dir##files"):
root = hide_tk_root()
d = filedialog.askdirectory(title="Select Files Base Dir")
root.destroy()
if d:
state.files_base_dir_buf = d
imgui.separator()
to_remove = None
for i, f in enumerate(state.files):
imgui.text(f)
imgui.same_line()
if imgui.button(f"Remove##file{i}"):
to_remove = i
if to_remove is not None:
state.files.pop(to_remove)
if imgui.button("Add File"):
root = hide_tk_root()
paths = filedialog.askopenfilenames(title="Select Files")
root.destroy()
for p in paths:
if p not in state.files:
state.files.append(p)
if imgui.button("Add Wildcard##files"):
root = hide_tk_root()
d = filedialog.askdirectory(title="Select Dir for Wildcard")
root.destroy()
if d:
state.files.append(str(Path(d) / "**" / "*"))
imgui.end()
def draw_screenshots_panel(state: State):
imgui.begin("Screenshots")
changed, val = imgui.input_text("Base Dir##shots", state.screenshots_base_dir_buf, 512)
if changed:
state.screenshots_base_dir_buf = val
if imgui.button("Browse Base Dir##shots"):
root = hide_tk_root()
d = filedialog.askdirectory(title="Select Screenshots Base Dir")
root.destroy()
if d:
state.screenshots_base_dir_buf = d
imgui.separator()
to_remove = None
for i, s in enumerate(state.screenshots):
imgui.text(s)
imgui.same_line()
if imgui.button(f"Remove##shot{i}"):
to_remove = i
if to_remove is not None:
state.screenshots.pop(to_remove)
if imgui.button("Add Screenshot"):
root = hide_tk_root()
paths = filedialog.askopenfilenames(
title="Select Screenshots",
filetypes=[("Images", "*.png *.jpg *.jpeg *.gif *.bmp *.webp"), ("All", "*.*")]
)
root.destroy()
for p in paths:
if p not in state.screenshots:
state.screenshots.append(p)
imgui.end()
def draw_discussion_panel(state: State):
imgui.begin("Discussion History")
if imgui.button("Add Excerpt"):
state.history.append("")
state.history_edit_bufs.append("")
imgui.separator()
state.sync_history_bufs()
to_remove = None
for i in range(len(state.history)):
imgui.text(f"Excerpt {i + 1}")
imgui.same_line()
if imgui.button(f"Remove##hist{i}"):
to_remove = i
continue
changed, val = imgui.input_text_multiline(
f"##histbuf{i}",
state.history_edit_bufs[i],
2048,
width=-1,
height=120
)
if changed:
state.history_edit_bufs[i] = val
imgui.separator()
if to_remove is not None:
state.history.pop(to_remove)
state.history_edit_bufs.pop(to_remove)
imgui.end()
def draw_gemini_panel(state: State):
imgui.begin("Gemini")
imgui.text(f"Status: {state.gemini_status}")
if state.last_md_path:
imgui.text(f"Last MD: {state.last_md_path}")
imgui.separator()
changed, val = imgui.input_text_multiline(
"##gemini_input",
state.gemini_input_buf,
4096,
width=-1,
height=100
)
if changed:
state.gemini_input_buf = val
is_sending = state.send_thread is not None and state.send_thread.is_alive()
if is_sending:
imgui.begin_disabled()
if imgui.button("Generate MD + Send"):
state.flush_to_config()
save_config(state.config)
md, path = aggregate.run(state.config)
state.last_md = md
state.last_md_path = path
state.gemini_status = "sending..."
user_msg = state.gemini_input_buf
def do_send():
try:
response = gemini.send(state.last_md, user_msg)
state.gemini_response = response
state.gemini_status = "done"
except Exception as e:
state.gemini_response = f"ERROR: {e}"
state.gemini_status = "error"
state.send_thread = threading.Thread(target=do_send, daemon=True)
state.send_thread.start()
if is_sending:
imgui.end_disabled()
imgui.same_line()
if imgui.button("Generate MD Only"):
state.flush_to_config()
save_config(state.config)
md, path = aggregate.run(state.config)
state.last_md = md
state.last_md_path = path
state.gemini_status = "md generated"
imgui.same_line()
if imgui.button("Reset Session"):
gemini.reset_session()
state.gemini_status = "session reset"
state.gemini_response = ""
imgui.separator()
imgui.text("Response:")
imgui.input_text_multiline(
"##gemini_response",
state.gemini_response,
max_value_length=65536,
width=-1,
height=-1,
flags=imgui.INPUT_TEXT_READ_ONLY
)
imgui.end()
def main():
pygame.init()
screen = pygame.display.set_mode(
(1280, 720),
pygame.RESIZABLE
)
pygame.display.set_caption("manual slop")
imgui.create_context()
io = imgui.get_io()
io.display_size = (1280, 720)
renderer = PygameRenderer()
state = State()
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return
if event.type == pygame.VIDEORESIZE:
io.display_size = (event.w, event.h)
renderer.process_event(event)
imgui.new_frame()
vp = imgui.get_main_viewport()
imgui.set_next_window_position(vp.pos.x, vp.pos.y)
imgui.set_next_window_size(vp.size.x, vp.size.y)
imgui.begin(
"##root",
flags=(
imgui.WINDOW_NO_TITLE_BAR
| imgui.WINDOW_NO_RESIZE
| imgui.WINDOW_NO_MOVE
| imgui.WINDOW_NO_SCROLLBAR
| imgui.WINDOW_NO_SAVED_SETTINGS
)
)
avail_w, avail_h = imgui.get_content_region_available()
col_w = avail_w / 4
imgui.begin_child("##left", width=col_w, height=avail_h, border=True)
draw_config_panel_inline(state)
imgui.separator()
draw_files_panel_inline(state)
imgui.end_child()
imgui.same_line()
imgui.begin_child("##mid", width=col_w, height=avail_h, border=True)
draw_screenshots_panel_inline(state)
imgui.end_child()
imgui.same_line()
imgui.begin_child("##right_top", width=col_w, height=avail_h, border=True)
draw_discussion_panel_inline(state)
imgui.end_child()
imgui.same_line()
imgui.begin_child("##gemini", width=col_w, height=avail_h, border=True)
draw_gemini_panel_inline(state)
imgui.end_child()
imgui.end()
screen.fill((30, 30, 30))
imgui.render()
renderer.render(imgui.get_draw_data())
pygame.display.flip()
clock.tick(30)
def draw_config_panel_inline(state: State):
imgui.text("Config")
imgui.separator()
changed, val = imgui.input_text("Namespace", state.namespace_buf, 256)
if changed:
state.namespace_buf = val
changed, val = imgui.input_text("Output Dir", state.output_dir_buf, 512)
if changed:
state.output_dir_buf = val
if imgui.button("Browse Output Dir"):
root = hide_tk_root()
d = filedialog.askdirectory(title="Select Output Dir")
root.destroy()
if d:
state.output_dir_buf = d
if imgui.button("Save Config"):
state.flush_to_config()
save_config(state.config)
def draw_files_panel_inline(state: State):
imgui.text("Files")
imgui.separator()
changed, val = imgui.input_text("Base Dir##files", state.files_base_dir_buf, 512)
if changed:
state.files_base_dir_buf = val
if imgui.button("Browse Base Dir##files"):
root = hide_tk_root()
d = filedialog.askdirectory(title="Select Files Base Dir")
root.destroy()
if d:
state.files_base_dir_buf = d
imgui.separator()
to_remove = None
for i, f in enumerate(state.files):
imgui.text(f[:40] + "..." if len(f) > 40 else f)
imgui.same_line()
if imgui.button(f"x##file{i}"):
to_remove = i
if to_remove is not None:
state.files.pop(to_remove)
if imgui.button("Add File(s)##files"):
root = hide_tk_root()
paths = filedialog.askopenfilenames(title="Select Files")
root.destroy()
for p in paths:
if p not in state.files:
state.files.append(p)
if imgui.button("Add Wildcard##files"):
root = hide_tk_root()
d = filedialog.askdirectory(title="Select Dir for Wildcard")
root.destroy()
if d:
state.files.append(str(Path(d) / "**" / "*"))
def draw_screenshots_panel_inline(state: State):
imgui.text("Screenshots")
imgui.separator()
changed, val = imgui.input_text("Base Dir##shots", state.screenshots_base_dir_buf, 512)
if changed:
state.screenshots_base_dir_buf = val
if imgui.button("Browse Base Dir##shots"):
root = hide_tk_root()
d = filedialog.askdirectory(title="Select Screenshots Base Dir")
root.destroy()
if d:
state.screenshots_base_dir_buf = d
imgui.separator()
to_remove = None
for i, s in enumerate(state.screenshots):
imgui.text(s[:40] + "..." if len(s) > 40 else s)
imgui.same_line()
if imgui.button(f"x##shot{i}"):
to_remove = i
if to_remove is not None:
state.screenshots.pop(to_remove)
if imgui.button("Add Screenshot(s)"):
root = hide_tk_root()
paths = filedialog.askopenfilenames(
title="Select Screenshots",
filetypes=[("Images", "*.png *.jpg *.jpeg *.gif *.bmp *.webp"), ("All", "*.*")]
)
root.destroy()
for p in paths:
if p not in state.screenshots:
state.screenshots.append(p)
def draw_discussion_panel_inline(state: State):
imgui.text("Discussion History")
imgui.separator()
if imgui.button("Add Excerpt"):
state.history.append("")
state.history_edit_bufs.append("")
imgui.separator()
state.sync_history_bufs()
to_remove = None
for i in range(len(state.history)):
imgui.text(f"Excerpt {i + 1}")
imgui.same_line()
if imgui.button(f"x##hist{i}"):
to_remove = i
continue
changed, val = imgui.input_text_multiline(
f"##histbuf{i}",
state.history_edit_bufs[i],
2048,
width=-1,
height=120
)
if changed:
state.history_edit_bufs[i] = val
imgui.separator()
if to_remove is not None:
state.history.pop(to_remove)
state.history_edit_bufs.pop(to_remove)
def draw_gemini_panel_inline(state: State):
imgui.text("Gemini")
imgui.separator()
imgui.text(f"Status: {state.gemini_status}")
if state.last_md_path:
imgui.text(f"Last MD: {str(state.last_md_path)[:40]}")
imgui.separator()
changed, val = imgui.input_text_multiline(
"##gemini_input",
state.gemini_input_buf,
4096,
width=-1,
height=120
)
if changed:
state.gemini_input_buf = val
is_sending = state.send_thread is not None and state.send_thread.is_alive()
if is_sending:
imgui.begin_disabled()
if imgui.button("Generate + Send"):
state.flush_to_config()
save_config(state.config)
md, path = aggregate.run(state.config)
state.last_md = md
state.last_md_path = path
state.gemini_status = "sending..."
user_msg = state.gemini_input_buf
def do_send():
try:
response = gemini.send(state.last_md, user_msg)
state.gemini_response = response
state.gemini_status = "done"
except Exception as e:
state.gemini_response = f"ERROR: {e}"
state.gemini_status = "error"
state.send_thread = threading.Thread(target=do_send, daemon=True)
state.send_thread.start()
if is_sending:
imgui.end_disabled()
imgui.same_line()
if imgui.button("MD Only"):
state.flush_to_config()
save_config(state.config)
md, path = aggregate.run(state.config)
state.last_md = md
state.last_md_path = path
state.gemini_status = "md generated"
imgui.same_line()
if imgui.button("Reset"):
gemini.reset_session()
state.gemini_status = "session reset"
state.gemini_response = ""
imgui.separator()
imgui.text("Response:")
_, _ = imgui.input_text_multiline(
"##gemini_response",
state.gemini_response,
max_value_length=65536,
width=-1,
height=-1,
flags=imgui.INPUT_TEXT_READ_ONLY
)
if __name__ == "__main__":
main()

View File

@@ -1,8 +1,11 @@
# pyproject.toml # pyproject.toml
[project] [project]
name = "aggregator" name = "manual_slop"
version = "0.1.0" version = "0.1.0"
requires-python = ">=3.11" requires-python = ">=3.11"
dependencies = [
[project.scripts] "imgui[pygame]",
aggregate = "aggregate:main" "pygame",
"google-generativeai",
"tomli-w"
]

8
uv.lock generated Normal file
View File

@@ -0,0 +1,8 @@
version = 1
revision = 3
requires-python = ">=3.11"
[[package]]
name = "aggregator"
version = "0.1.0"
source = { virtual = "." }