aboutsummaryrefslogtreecommitdiffstats
path: root/docs/superpowers/specs/2026-11-17-video-transcript-design.md
blob: 3d8b0e3daf645a6987c1abbd514d037d657f4edf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Video transcript tool: design

Date: 2026-11-17. Status: implemented, live checked 2026-11-17 (AGENTS.md).

## Goal

Ask the assistant to transcribe a video, local or a public URL (YouTube,
social media, any page yt-dlp can read), and get the transcript as a
Markdown file in the assistant's output folder. The model sees the start
and the path; to summarize or question the whole text, the user attaches
the file.

Two parts: an output folder setting shared by the daemon, its tools and
the canvas, then the tool itself.

## Part 1: output folder setting

Today the canvas alone decides where written files go:
`$(xdg-user-dir DOCUMENTS)/Assistant`, falling back to
`~/Documents/Assistant` (`quickshell/desktop/assistant/Assistant.qml`).
Tools cannot see it.

### Daemon (`assistant.py`)

- `DEFAULTS["out_dir"] = ""`. Empty means `xdg-user-dir DOCUMENTS` +
  `/Assistant`, and `~/Documents/Assistant` when that answers `$HOME`
  (no documents folder set), the canvas's current rule. A set value must
  be absolute, `~` expanded; anything else is refused at load like other
  bad config values.
- Resolved once at startup into `CFG["out_dir"]`. Not created until
  something writes there.
- `run_tool` adds `ASSISTANT_DIR=<out_dir>` to every tool's environment,
  next to `CFG["env"]`.
- `hello` carries `out_dir`.

### Keystone (quickshell repo)

- `desktop/modules/assistant/AssistantPage.qml`: an "Output folder" text
  field, `setKey("out_dir", quoted path)`, `null` when cleared. The
  placeholder shows the XDG default. Applied at the daemon's next
  restart, like every config key.
- `desktop/assistant/Assistant.qml`: `outDir` comes from `hello`; the
  `xdg-user-dir` Process goes. One rule, in the daemon.

### Check

`--test`: default resolution, a configured value, a relative value
refused, `ASSISTANT_DIR` reaching a tool, `out_dir` in `hello`.

## Part 2: the tool

`examples/tools/video.toml` and `examples/tools/video.sh`, installed to
`~/.config/desktop-assistant/tools/`.

```toml
description = "Transcribe the speech in a video, a local file or a public URL (YouTube, social media, web pages). Writes the full transcript to a Markdown file and opens it. Returns the file's path and the start of the text only: you have NOT read the whole transcript, so to summarize or answer questions about it, ask the user to attach the file. Videos over 30 minutes are refused until the user agrees: tell them the length and that it takes a few minutes, then call again with long=1."
command = ["video.sh", "{source}", "{long}"]
cloud = ["hetzner"]
timeout = 1800

[params.source]
type = "string"
description = "Absolute path of a local video, from its file block or the user's words, or an http(s) URL."

[params.long]
type = "string"
description = "1 only after the user agreed to transcribe a video over 30 minutes; empty otherwise."
```

### Flow

1. **Source.** An absolute existing path is local; `http://` or
   `https://` is a URL; anything else is an error. URLs are passed to
   yt-dlp as one argv element after `--`, never to a shell.
2. **Length and title.** Local: `ffprobe` duration, title is the file
   name. URL: `yt-dlp --print duration --print title --no-playlist`.
   Over 30 minutes without `long=1`: print `long: <title>, <mm:ss>.
   Ask the user before transcribing.` and exit 0, nothing written.
   A source with no audio stream is an error.
3. **Subtitles first (URL only).** `yt-dlp --write-subs --sub-langs
   'it.*,en.*' --sub-format vtt --skip-download`: if the uploader
   provided subtitles, their text (cue timings and markup stripped) is
   the transcript, in seconds. Auto-generated subtitles are not used:
   their rolling cues repeat every line, and whisper turbo is better.
4. **Audio.** URL: `yt-dlp -f bestaudio --no-playlist -o` into a fresh
   `mktemp -d` under `$XDG_RUNTIME_DIR`, removed on exit (trap). Local:
   the file itself.
5. **Transcribe.** `whisper-cli -m
   /data/voice-models/whisper/ggml-large-v3-turbo-q5_0.bin -ng -t 8 -l auto
   -np -otxt -of <tmp>/t -f <audio>`. whisper reads through ffmpeg, so
   any container works; beam 5 is its default.
   - **CPU, no GPU** (`-ng`): no VRAM, so it can never push the loaded
     model out of the Arc or fail beside it. Measured 2026-11-17 on the
     9700X: a 120 s clip in 13.2 s wall (about 0.11x real time, so ~7 min
     for an hour), ~1 GB RSS; a 10 s clip 10.6 s, mostly model load.
     8 threads beat 16 (11.98 s on the 10 s clip).
     On a real talk (20:03, live check) 218 s: ~0.18x, ~11 min an hour.
   - Not the daemon's Gemma `input_audio` path: capped at 60 s by the
     ubatch, so long audio needs cutting at silences, which can still
     drift language between pieces; it needs an audio-capable model
     loaded and holds llama-server for the whole run.
6. **Write.** `$ASSISTANT_DIR/<slug>.md`, slug from the title (lowercase,
   `[a-z0-9-]`, 60 chars max), `-2`, `-3`... if taken. Content:

   ```markdown
   # <title>

   Source: <path or URL>
   Duration: <mm:ss>. Transcribed <date> with <whisper large-v3-turbo | uploader subtitles>.

   <text, one paragraph per whisper segment line>
   ```

   Opened with `xdg-open`, detached.
7. **Output.** Path line first, so `run_tool`'s 2000-character cap can
   never cut it:

   ```
   transcript: <path> (<N> words, <mm:ss>, <source of text>)
   start, not the whole text:
   <first ~1500 characters>
   ```

### Errors

One line, nothing written: bad source, private or unavailable video
(yt-dlp's last stderr line), no audio stream, whisper failure,
unwritable output folder. Login-only videos are not supported: no
cookies are passed.

### Daemon change: stop kills a running tool

Today a stop drops a running tool's result but lets the process run
(a `ponytail:` ceiling); harmless for 10 s tools, not for a 7-minute
transcription. `run_tool` puts its `Popen` in `inflight["tool"]` while it
waits, the way `inflight["conn"]` holds the llama-server connection, and
clears it after. `interrupt()` sends `SIGKILL` to that process group
(`start_new_session` already gives each tool its own), so whisper,
ffmpeg and yt-dlp die with the script. `video.sh`'s `trap` cannot run on
`SIGKILL`: its temp dir lives under `$XDG_RUNTIME_DIR` and is named
`video-*`, and the script removes stale ones older than a day at start.
A half-written transcript cannot exist: the `.md` is written in one step
after whisper finishes. `--test`: a `sleep 30` tool, stopped, is gone
within a second and its child too.

### Daemon change: video attachments

`kind_of` returns `video` for `video/*` MIME types. `attach()` adds only
`--- video: <name> (<abs path>) ---`, like an image block without the
image: the model gets the path for the tool, nothing else. Chip kind
`video`; the canvas shows an unknown kind as a plain file chip (to check).

### Check

`test-video.sh`, like `test-clone.sh`: an espeak-ng sentence in an
mp4 (Opus: this ffmpeg has no AAC encoder) through the real whisper,
twice for the slug collision; an mkv with no audio; a relative and a
missing path; a real 31-minute silent webm for the refusal; a stale
temp folder removed, a fresh one kept. yt-dlp is a stub driven by
environment variables: uploader subtitles in it and en (the spoken
language picked, header, NOTE, tags and repeated cues stripped), no
subtitles (audio through whisper), an unavailable video, an unknown
length, a long one, and 400 cues whose output stays under the cap
with the path line first.

whisper drops the last word of a clip that ends on it, even with 2 s of
silence after (espeak's "tool." in the test); real videos rarely end
mid-sentence.

### Live check

Through a second daemon on a scratch socket, config and data dir, Gemma:

- A local video, it and en, "trascrivi questo video" with the file
  attached and with the path typed.
- A YouTube video with uploader subtitles, one without, one over 30
  minutes (refused, asked, then done).
- A public video from one social site.
- Then attach the written file and ask for a summary.
- Stop mid-transcription: no whisper or yt-dlp left running, no `.md`.
- Measure: wall time per minute of a real single-language video on the
  CPU (the 120 s measurement was a repeated it/en sample, whose last
  30 s window came out garbled from the mixed languages).

## Not doing

- Subtitle languages other than it and en (user's choice).
- Raising the 2000-character tool cap: the attach step covers it. Add a
  per-tool `limit` key if the two steps get tedious.
- Auto-generated subtitles, cookies for login-only videos, playlists,
  timestamps in the transcript, translation.
- Updating yt-dlp: packaging, `my-slackbuilds`.