@clipy/cli 0.8.5 → 0.9.0
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.
- package/README.md +38 -4
- package/dist/context/ffmpeg.js +179 -0
- package/dist/context/frames.js +97 -0
- package/dist/context/importCmd.js +609 -0
- package/dist/context/probe.js +53 -0
- package/dist/context/readCmd.js +30 -0
- package/dist/context/videoFetch.js +154 -0
- package/dist/context/ytdlp.js +219 -0
- package/dist/context-core/arec.js +192 -0
- package/dist/context-core/captions.js +191 -0
- package/dist/context-core/classify.js +209 -0
- package/dist/context-core/index.js +5 -0
- package/dist/context-core/types.js +13 -0
- package/dist/index.js +115 -8
- package/dist/skill.js +69 -14
- package/package.json +4 -2
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// GENERATED from lib/context-core — do not edit here
|
|
2
|
+
/**
|
|
3
|
+
* Caption parsers. Every one produces raw `TranscriptSegment[]`; run the
|
|
4
|
+
* result through `normalizeSegments` (or `buildNormalizedTranscript`) before
|
|
5
|
+
* anything else consumes it.
|
|
6
|
+
*/
|
|
7
|
+
/** Shortest fragment worth keeping on its own; anything below merges. */
|
|
8
|
+
const MIN_SEGMENT_MS = 300;
|
|
9
|
+
const TIMESTAMP = /(?:(\d+):)?(\d{1,2}):(\d{2})[.,](\d{1,3})/;
|
|
10
|
+
function parseTimestamp(raw) {
|
|
11
|
+
const m = TIMESTAMP.exec(raw.trim());
|
|
12
|
+
if (!m)
|
|
13
|
+
return null;
|
|
14
|
+
const hours = m[1] ? Number(m[1]) : 0;
|
|
15
|
+
const minutes = Number(m[2]);
|
|
16
|
+
const seconds = Number(m[3]);
|
|
17
|
+
const millis = Number(m[4].padEnd(3, '0'));
|
|
18
|
+
return ((hours * 60 + minutes) * 60 + seconds) * 1000 + millis;
|
|
19
|
+
}
|
|
20
|
+
/** Strips inline karaoke markup (`<c>`, `<00:00:01.000>`) and entities. */
|
|
21
|
+
function cleanCueText(raw) {
|
|
22
|
+
return raw
|
|
23
|
+
.replace(/<[^>]*>/g, '')
|
|
24
|
+
.replace(/ /gi, ' ')
|
|
25
|
+
.replace(/&/gi, '&')
|
|
26
|
+
.replace(/</gi, '<')
|
|
27
|
+
.replace(/>/gi, '>')
|
|
28
|
+
.replace(/'|'/gi, "'")
|
|
29
|
+
.replace(/"/gi, '"')
|
|
30
|
+
.replace(/\s+/g, ' ')
|
|
31
|
+
.trim();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* YouTube auto-captions ship a rolling window: each cue repeats the tail of the
|
|
35
|
+
* previous one and appends a new line. Emitting them verbatim triples the
|
|
36
|
+
* transcript, so a cue that merely re-states what we already emitted is
|
|
37
|
+
* trimmed to its new remainder (and dropped entirely if there is none).
|
|
38
|
+
*/
|
|
39
|
+
function dedupeRolling(text, previous) {
|
|
40
|
+
if (!text)
|
|
41
|
+
return '';
|
|
42
|
+
if (!previous)
|
|
43
|
+
return text;
|
|
44
|
+
if (text === previous)
|
|
45
|
+
return '';
|
|
46
|
+
if (text.startsWith(previous))
|
|
47
|
+
return text.slice(previous.length).trim();
|
|
48
|
+
if (previous.endsWith(text))
|
|
49
|
+
return '';
|
|
50
|
+
// Partial overlap: the longest suffix of `previous` that prefixes `text`.
|
|
51
|
+
const max = Math.min(previous.length, text.length);
|
|
52
|
+
for (let len = max; len >= 8; len -= 1) {
|
|
53
|
+
if (previous.endsWith(text.slice(0, len)))
|
|
54
|
+
return text.slice(len).trim();
|
|
55
|
+
}
|
|
56
|
+
return text;
|
|
57
|
+
}
|
|
58
|
+
export function parseVtt(text) {
|
|
59
|
+
const lines = text.replace(/\r/g, '').split('\n');
|
|
60
|
+
const segments = [];
|
|
61
|
+
let previous = '';
|
|
62
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
63
|
+
const line = lines[i];
|
|
64
|
+
if (!line.includes('-->'))
|
|
65
|
+
continue;
|
|
66
|
+
const [rawStart, rawRest] = line.split('-->');
|
|
67
|
+
const startMs = parseTimestamp(rawStart);
|
|
68
|
+
// Cue settings (align:, position:, …) trail the end timestamp.
|
|
69
|
+
const endMs = parseTimestamp(rawRest ?? '');
|
|
70
|
+
if (startMs === null || endMs === null)
|
|
71
|
+
continue;
|
|
72
|
+
const body = [];
|
|
73
|
+
let j = i + 1;
|
|
74
|
+
for (; j < lines.length; j += 1) {
|
|
75
|
+
const next = lines[j];
|
|
76
|
+
if (!next.trim() || next.includes('-->'))
|
|
77
|
+
break;
|
|
78
|
+
body.push(next);
|
|
79
|
+
}
|
|
80
|
+
i = j - 1;
|
|
81
|
+
const cleaned = cleanCueText(body.join(' '));
|
|
82
|
+
const deduped = dedupeRolling(cleaned, previous);
|
|
83
|
+
if (cleaned)
|
|
84
|
+
previous = cleaned;
|
|
85
|
+
if (!deduped)
|
|
86
|
+
continue;
|
|
87
|
+
segments.push({ startMs, endMs, text: deduped });
|
|
88
|
+
}
|
|
89
|
+
return segments;
|
|
90
|
+
}
|
|
91
|
+
export function parseSrt(text) {
|
|
92
|
+
const blocks = text.replace(/\r/g, '').split(/\n{2,}/);
|
|
93
|
+
const segments = [];
|
|
94
|
+
for (const block of blocks) {
|
|
95
|
+
const lines = block.split('\n').filter((l) => l.trim().length > 0);
|
|
96
|
+
if (lines.length === 0)
|
|
97
|
+
continue;
|
|
98
|
+
const timingIndex = lines.findIndex((l) => l.includes('-->'));
|
|
99
|
+
if (timingIndex === -1)
|
|
100
|
+
continue;
|
|
101
|
+
const [rawStart, rawEnd] = lines[timingIndex].split('-->');
|
|
102
|
+
const startMs = parseTimestamp(rawStart);
|
|
103
|
+
const endMs = parseTimestamp(rawEnd ?? '');
|
|
104
|
+
if (startMs === null || endMs === null)
|
|
105
|
+
continue;
|
|
106
|
+
const body = cleanCueText(lines.slice(timingIndex + 1).join(' '));
|
|
107
|
+
if (!body)
|
|
108
|
+
continue;
|
|
109
|
+
segments.push({ startMs, endMs, text: body });
|
|
110
|
+
}
|
|
111
|
+
return segments;
|
|
112
|
+
}
|
|
113
|
+
export function parseYoutubeJson3(json) {
|
|
114
|
+
if (!json || typeof json !== 'object')
|
|
115
|
+
return [];
|
|
116
|
+
const events = json.events;
|
|
117
|
+
if (!Array.isArray(events))
|
|
118
|
+
return [];
|
|
119
|
+
const segments = [];
|
|
120
|
+
for (const raw of events) {
|
|
121
|
+
if (!raw || typeof raw !== 'object')
|
|
122
|
+
continue;
|
|
123
|
+
const startMs = Number(raw.tStartMs);
|
|
124
|
+
if (!Number.isFinite(startMs))
|
|
125
|
+
continue;
|
|
126
|
+
const durationMs = Number(raw.dDurationMs);
|
|
127
|
+
if (!Array.isArray(raw.segs))
|
|
128
|
+
continue;
|
|
129
|
+
const body = cleanCueText(raw.segs
|
|
130
|
+
.map((s) => (s && typeof s.utf8 === 'string' ? s.utf8 : ''))
|
|
131
|
+
.join(''));
|
|
132
|
+
// Newline-only events are paragraph breaks, not speech.
|
|
133
|
+
if (!body)
|
|
134
|
+
continue;
|
|
135
|
+
segments.push({
|
|
136
|
+
startMs,
|
|
137
|
+
endMs: startMs + (Number.isFinite(durationMs) ? durationMs : 0),
|
|
138
|
+
text: body,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return segments;
|
|
142
|
+
}
|
|
143
|
+
export function normalizeSegments(segments, opts = {}) {
|
|
144
|
+
const duration = opts.durationMs;
|
|
145
|
+
const cleaned = segments
|
|
146
|
+
.map((seg) => ({
|
|
147
|
+
startMs: Math.max(0, Math.round(seg.startMs)),
|
|
148
|
+
endMs: Math.max(0, Math.round(seg.endMs)),
|
|
149
|
+
text: seg.text.replace(/\s+/g, ' ').trim(),
|
|
150
|
+
}))
|
|
151
|
+
.filter((seg) => seg.text.length > 0)
|
|
152
|
+
.map((seg) => {
|
|
153
|
+
const startMs = duration ? Math.min(seg.startMs, duration) : seg.startMs;
|
|
154
|
+
let endMs = duration ? Math.min(seg.endMs, duration) : seg.endMs;
|
|
155
|
+
if (endMs < startMs)
|
|
156
|
+
endMs = startMs;
|
|
157
|
+
return { startMs, endMs, text: seg.text };
|
|
158
|
+
})
|
|
159
|
+
.sort((a, b) => a.startMs - b.startMs);
|
|
160
|
+
const merged = [];
|
|
161
|
+
for (const seg of cleaned) {
|
|
162
|
+
const previous = merged[merged.length - 1];
|
|
163
|
+
const tiny = seg.endMs - seg.startMs < MIN_SEGMENT_MS;
|
|
164
|
+
// Only fold a fragment into a neighbour it actually abuts — merging across
|
|
165
|
+
// a gap would attribute speech to a timestamp where none happened.
|
|
166
|
+
if (previous && tiny && seg.startMs - previous.endMs <= MIN_SEGMENT_MS) {
|
|
167
|
+
merged[merged.length - 1] = {
|
|
168
|
+
startMs: previous.startMs,
|
|
169
|
+
endMs: Math.max(previous.endMs, seg.endMs),
|
|
170
|
+
text: `${previous.text} ${seg.text}`,
|
|
171
|
+
};
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
merged.push(seg);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
segments: merged,
|
|
178
|
+
plaintext: merged.map((s) => s.text).join(' ').trim(),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export function buildNormalizedTranscript(segments, opts) {
|
|
182
|
+
const { segments: normalized, plaintext } = normalizeSegments(segments, {
|
|
183
|
+
durationMs: opts.durationMs,
|
|
184
|
+
});
|
|
185
|
+
return {
|
|
186
|
+
...(opts.language ? { language: opts.language } : {}),
|
|
187
|
+
source: opts.source,
|
|
188
|
+
segments: normalized,
|
|
189
|
+
plaintext,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// GENERATED from lib/context-core — do not edit here
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic transcript-sufficiency classifier.
|
|
4
|
+
*
|
|
5
|
+
* Every signal here comes from docs/research/2026-07-27-video-transcript-
|
|
6
|
+
* sufficiency-study.md: 16 real YouTube videos scored by hand, whose core
|
|
7
|
+
* finding is that genre does not predict whether a transcript stands alone —
|
|
8
|
+
* *verbalization discipline* does. A speaker who dictates values, commands and
|
|
9
|
+
* code aloud produces a self-sufficient transcript; one who defers to the
|
|
10
|
+
* screen ("copy this", "the guide is in the description") does not. Both are
|
|
11
|
+
* detectable from text alone with cheap regexes, per window, with no model.
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_WINDOW_MS = 300_000;
|
|
14
|
+
/** How far past a deictic phrase a literal value redeems it (~5 tokens). */
|
|
15
|
+
const REDEMPTION_CHARS = 45;
|
|
16
|
+
const EXCERPT_PAD = 40;
|
|
17
|
+
/** Deixis that points at the screen rather than naming what it points at. */
|
|
18
|
+
const DEICTIC = /\b(?:copy (?:this|that)|paste (?:it|that|this)|right here|over here|like this|as you can see|click (?:on )?(?:this|here)|let me show you|this one here|this right here|down here|up here)\b/gi;
|
|
19
|
+
/**
|
|
20
|
+
* Literal values a listener could act on without seeing the screen: numbers
|
|
21
|
+
* with units, hex colours, spoken code syntax, dotted identifiers, flags.
|
|
22
|
+
*/
|
|
23
|
+
const VALUE_TOKEN = /\b\d+(?:\.\d+)?\s?(?:px|%|em|rem|ms|s|mb|gb|kb)\b|#[0-9a-f]{3,8}\b|\b(?:const|let|var|function|return|import|export|async|await|interface|class)\b|=>|\bnpm |\bnpx |\bsudo |\bgit |\bdocker |\bcurl |--[a-z][a-z-]+|\b[a-z_][\w-]*\.[a-z_][\w-]{1,}\b|\b\d+(?:\.\d+){1,}\b/gi;
|
|
24
|
+
const EXTERNAL_REFERENCE = /\b(?:in the description|linked below|link (?:is )?below|download the (?:guide|file|template|repo)|check my course|grab the (?:file|template))\b/gi;
|
|
25
|
+
const DASHBOARD_VOCAB = /\b(?:dropdown|drop down|panel|dashboard|click continue|select your plan|sidebar|toolbar|tab)\b/gi;
|
|
26
|
+
const RECAP = /\b(?:let'?s recap|to recap|to summari[sz]e|in summary|what we learned|so to review)\b/gi;
|
|
27
|
+
/**
|
|
28
|
+
* ASR mangles shell commands ("pseudo mpm install d gpm2" = `sudo npm install
|
|
29
|
+
* -g pm2`). Where one is being spoken, a frame is worth having even though the
|
|
30
|
+
* transcript nominally "contains" the command.
|
|
31
|
+
*/
|
|
32
|
+
const GARBLED_COMMAND = /\b(?:pseudo|p ?s ?e ?u ?d ?o|mpm install|npm install d |engine ?x|yuntu|get clone)\b/gi;
|
|
33
|
+
function sliceWindows(t, windowMs) {
|
|
34
|
+
const slices = [];
|
|
35
|
+
for (const seg of t.segments) {
|
|
36
|
+
const index = Math.floor(seg.startMs / windowMs);
|
|
37
|
+
let slice = slices[slices.length - 1];
|
|
38
|
+
if (!slice || slice.startMs !== index * windowMs) {
|
|
39
|
+
slice = {
|
|
40
|
+
startMs: index * windowMs,
|
|
41
|
+
endMs: (index + 1) * windowMs,
|
|
42
|
+
text: '',
|
|
43
|
+
offsets: [],
|
|
44
|
+
offsetMs: [],
|
|
45
|
+
};
|
|
46
|
+
slices.push(slice);
|
|
47
|
+
}
|
|
48
|
+
if (slice.text)
|
|
49
|
+
slice.text += ' ';
|
|
50
|
+
slice.offsets.push(slice.text.length);
|
|
51
|
+
slice.offsetMs.push(seg.startMs);
|
|
52
|
+
slice.text += seg.text;
|
|
53
|
+
slice.endMs = Math.max(slice.endMs, seg.endMs);
|
|
54
|
+
}
|
|
55
|
+
return slices;
|
|
56
|
+
}
|
|
57
|
+
function timestampAt(slice, offset) {
|
|
58
|
+
let ms = slice.offsetMs[0] ?? slice.startMs;
|
|
59
|
+
for (let i = 0; i < slice.offsets.length; i += 1) {
|
|
60
|
+
if (slice.offsets[i] > offset)
|
|
61
|
+
break;
|
|
62
|
+
ms = slice.offsetMs[i];
|
|
63
|
+
}
|
|
64
|
+
return ms;
|
|
65
|
+
}
|
|
66
|
+
function excerptAt(text, start, end) {
|
|
67
|
+
return text
|
|
68
|
+
.slice(Math.max(0, start - EXCERPT_PAD), Math.min(text.length, end + EXCERPT_PAD))
|
|
69
|
+
.trim();
|
|
70
|
+
}
|
|
71
|
+
function matches(re, text) {
|
|
72
|
+
const out = [];
|
|
73
|
+
re.lastIndex = 0;
|
|
74
|
+
let m = re.exec(text);
|
|
75
|
+
while (m) {
|
|
76
|
+
out.push({ index: m.index, length: m[0].length });
|
|
77
|
+
if (m.index === re.lastIndex)
|
|
78
|
+
re.lastIndex += 1;
|
|
79
|
+
m = re.exec(text);
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function clamp01(n) {
|
|
84
|
+
return Math.max(0, Math.min(1, n));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Thresholds below are calibrated against the study corpus (scripts/context-
|
|
88
|
+
* core/selftest.ts asserts the direction on the real transcripts): podcasts and
|
|
89
|
+
* rhetorical talks must land on 'transcript'; the dashboard-heavy VPS deploy
|
|
90
|
+
* walkthrough ("copy this", "guide in the description") must land on 'visual'.
|
|
91
|
+
*/
|
|
92
|
+
const PENALTY_PER_BARE_DEIXIS = 0.055;
|
|
93
|
+
const PENALTY_PER_EXTERNAL_REF = 0.14;
|
|
94
|
+
const PENALTY_PER_GARBLED = 0.05;
|
|
95
|
+
const PENALTY_DASHBOARD_DENSITY = 0.9;
|
|
96
|
+
const REDEEM_PER_VALUE_TOKEN = 0.02;
|
|
97
|
+
const REDEEM_CAP = 0.2;
|
|
98
|
+
const RECAP_BONUS = 0.08;
|
|
99
|
+
const PROFILE_OVERALL_FLOOR = 0.55;
|
|
100
|
+
const PROFILE_WINDOW_FLOOR = 0.35;
|
|
101
|
+
export function classifyTranscript(t, opts = {}) {
|
|
102
|
+
const windowMs = opts.windowMs ?? DEFAULT_WINDOW_MS;
|
|
103
|
+
const slices = sliceWindows(t, windowMs);
|
|
104
|
+
if (slices.length === 0) {
|
|
105
|
+
return {
|
|
106
|
+
overallScore: 0,
|
|
107
|
+
recommendedProfile: 'visual',
|
|
108
|
+
windows: [],
|
|
109
|
+
gaps: [
|
|
110
|
+
{
|
|
111
|
+
timestampMs: 0,
|
|
112
|
+
reason: 'no_speech',
|
|
113
|
+
excerpt: '',
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const windows = [];
|
|
119
|
+
const gaps = [];
|
|
120
|
+
const pushGap = (timestampMs, reason, excerpt) => {
|
|
121
|
+
const last = gaps[gaps.length - 1];
|
|
122
|
+
// A cluster of "copy this … paste this" inside a few seconds is one gap.
|
|
123
|
+
if (last && last.reason === reason && timestampMs - last.timestampMs < 15_000) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
gaps.push({ timestampMs, reason, excerpt });
|
|
127
|
+
};
|
|
128
|
+
for (const slice of slices) {
|
|
129
|
+
const words = slice.text.split(/\s+/).filter(Boolean).length;
|
|
130
|
+
if (words === 0)
|
|
131
|
+
continue;
|
|
132
|
+
const valueTokens = matches(VALUE_TOKEN, slice.text);
|
|
133
|
+
const deictics = matches(DEICTIC, slice.text);
|
|
134
|
+
const externals = matches(EXTERNAL_REFERENCE, slice.text);
|
|
135
|
+
const dashboards = matches(DASHBOARD_VOCAB, slice.text);
|
|
136
|
+
const recaps = matches(RECAP, slice.text);
|
|
137
|
+
const garbled = matches(GARBLED_COMMAND, slice.text);
|
|
138
|
+
const bare = deictics.filter((d) => {
|
|
139
|
+
const end = d.index + d.length;
|
|
140
|
+
const lookahead = slice.text.slice(end, end + REDEMPTION_CHARS);
|
|
141
|
+
return !matches(VALUE_TOKEN, lookahead).length;
|
|
142
|
+
});
|
|
143
|
+
const per1k = 1000 / words;
|
|
144
|
+
const valueDensity = valueTokens.length * per1k;
|
|
145
|
+
const deicticDensity = bare.length * per1k;
|
|
146
|
+
const dashboardDensity = dashboards.length * per1k;
|
|
147
|
+
// Capped deliberately: dictated values redeem a window that also contains
|
|
148
|
+
// some deixis, but must not be able to fully mask a window that is mostly
|
|
149
|
+
// "copy this" — the study's finding is that both can coexist in one window.
|
|
150
|
+
const redemption = Math.min(REDEEM_CAP, valueDensity * REDEEM_PER_VALUE_TOKEN);
|
|
151
|
+
let score = 1 +
|
|
152
|
+
redemption +
|
|
153
|
+
(recaps.length > 0 ? RECAP_BONUS : 0) -
|
|
154
|
+
deicticDensity * PENALTY_PER_BARE_DEIXIS -
|
|
155
|
+
externals.length * per1k * PENALTY_PER_EXTERNAL_REF -
|
|
156
|
+
garbled.length * per1k * PENALTY_PER_GARBLED -
|
|
157
|
+
clamp01(dashboardDensity / 20) * PENALTY_DASHBOARD_DENSITY;
|
|
158
|
+
score = clamp01(score);
|
|
159
|
+
const signals = [];
|
|
160
|
+
if (bare.length)
|
|
161
|
+
signals.push(`bare_deixis:${bare.length}`);
|
|
162
|
+
if (valueTokens.length)
|
|
163
|
+
signals.push(`value_tokens:${valueTokens.length}`);
|
|
164
|
+
if (externals.length)
|
|
165
|
+
signals.push(`external_reference:${externals.length}`);
|
|
166
|
+
if (dashboards.length)
|
|
167
|
+
signals.push(`dashboard_vocab:${dashboards.length}`);
|
|
168
|
+
if (recaps.length)
|
|
169
|
+
signals.push(`recap:${recaps.length}`);
|
|
170
|
+
if (garbled.length)
|
|
171
|
+
signals.push(`garbled_command:${garbled.length}`);
|
|
172
|
+
windows.push({
|
|
173
|
+
startMs: slice.startMs,
|
|
174
|
+
endMs: slice.endMs,
|
|
175
|
+
score,
|
|
176
|
+
deicticCount: bare.length,
|
|
177
|
+
valueTokenCount: valueTokens.length,
|
|
178
|
+
signals,
|
|
179
|
+
});
|
|
180
|
+
const flagged = [
|
|
181
|
+
...bare.map((m) => ({ ...m, reason: 'bare_deixis' })),
|
|
182
|
+
...externals.map((m) => ({ ...m, reason: 'external_reference' })),
|
|
183
|
+
...garbled.map((m) => ({ ...m, reason: 'garbled_command' })),
|
|
184
|
+
].sort((a, b) => a.index - b.index);
|
|
185
|
+
for (const hit of flagged) {
|
|
186
|
+
pushGap(timestampAt(slice, hit.index), hit.reason, excerptAt(slice.text, hit.index, hit.index + hit.length));
|
|
187
|
+
}
|
|
188
|
+
// Dashboard vocabulary only earns a gap when it dominates the window; the
|
|
189
|
+
// word "tab" in passing is not evidence of a screen-bound step.
|
|
190
|
+
if (dashboardDensity >= 8 && dashboards.length >= 3) {
|
|
191
|
+
const hit = dashboards[0];
|
|
192
|
+
pushGap(timestampAt(slice, hit.index), 'dashboard_ui', excerptAt(slice.text, hit.index, hit.index + hit.length));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const totalMs = windows.reduce((sum, w) => sum + (w.endMs - w.startMs), 0);
|
|
196
|
+
const overallScore = totalMs > 0
|
|
197
|
+
? windows.reduce((sum, w) => sum + w.score * (w.endMs - w.startMs), 0) / totalMs
|
|
198
|
+
: 0;
|
|
199
|
+
const worst = windows.reduce((min, w) => Math.min(min, w.score), 1);
|
|
200
|
+
const recommendedProfile = overallScore < PROFILE_OVERALL_FLOOR || worst < PROFILE_WINDOW_FLOOR
|
|
201
|
+
? 'visual'
|
|
202
|
+
: 'transcript';
|
|
203
|
+
return {
|
|
204
|
+
overallScore: Math.round(overallScore * 1000) / 1000,
|
|
205
|
+
recommendedProfile,
|
|
206
|
+
windows,
|
|
207
|
+
gaps: gaps.sort((a, b) => a.timestampMs - b.timestampMs),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// GENERATED from lib/context-core — do not edit here
|
|
2
|
+
/**
|
|
3
|
+
* The frozen contract for the Clipy context bundle ("any video → agent
|
|
4
|
+
* context").
|
|
5
|
+
*
|
|
6
|
+
* This module — and everything else in lib/context-core — is consumed by three
|
|
7
|
+
* separate builds: the Next.js server, the Chrome extension (Vite) and the CLI
|
|
8
|
+
* (plain tsc, which copies this directory verbatim). It therefore has zero
|
|
9
|
+
* runtime dependencies, imports nothing from node builtins or the rest of the
|
|
10
|
+
* repo, and never touches `process`/`Buffer`. Hashing is always injected or
|
|
11
|
+
* caller-provided.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,8 @@ import { createServer } from "node:net";
|
|
|
27
27
|
import { createServer as createHttpServer } from "node:http";
|
|
28
28
|
import { CLIPY_SKILL_MD } from "./skill.js";
|
|
29
29
|
import { browserLogin, shouldUseManualLogin } from "./browserLogin.js";
|
|
30
|
+
import { cmdContextImport } from "./context/importCmd.js";
|
|
31
|
+
import { cmdContextRead } from "./context/readCmd.js";
|
|
30
32
|
import { BridgeUnavailableError, bridgeRequest, inspectBridge, listSources, readBridgeInfo, resolveCaptureSource, windowLabel, probeSocketOpenable, probeBridgeHandshake, bridgeInfoFromFile, bridgeAppOutdated, MIN_BRIDGE_APP_VERSION, describeWindow, describeDisplay, } from "./macBridge.js";
|
|
31
33
|
// Exit quietly when stdout/stderr close early (e.g. `clipy list | head`).
|
|
32
34
|
for (const stream of [process.stdout, process.stderr]) {
|
|
@@ -293,6 +295,22 @@ ${c.bold("RECORDINGS")}
|
|
|
293
295
|
summary <id> [--json] AI summary: TL;DR, key points, action items
|
|
294
296
|
moments <id> [--json] Key moments (timestamps + captions + click coords)
|
|
295
297
|
context <id> Full agent-context bundle as markdown
|
|
298
|
+
context import <youtube-url|file> [--transcript <f>] [--output <dir>]
|
|
299
|
+
Compile ANY video into a local Clipy context
|
|
300
|
+
bundle (recording.md + manifest.json +
|
|
301
|
+
transcript.json). YouTube captions are fetched
|
|
302
|
+
on your machine — no media leaves it. Local
|
|
303
|
+
files need --transcript <.vtt|.srt|.json>
|
|
304
|
+
--language <code> Caption language preference (default en)
|
|
305
|
+
--title <t> Override the bundle title
|
|
306
|
+
--tag <t> Tag for --sync (repeatable) · --folder <name>
|
|
307
|
+
--sync Also upload the derived bundle to your private library.
|
|
308
|
+
The server classifies it and, when the transcript is not
|
|
309
|
+
enough, names the timestamps worth a picture; those frames
|
|
310
|
+
are then extracted locally and added to the bundle
|
|
311
|
+
--no-frames With --sync: take the verdict but never download media
|
|
312
|
+
--json Print {bundlePath, profile, classification, frames, …}
|
|
313
|
+
context read <bundle-path> Print a local bundle's recording.md
|
|
296
314
|
download <id> [-o <path>] Download the MP4
|
|
297
315
|
open <id> Open the share page in your browser
|
|
298
316
|
wait <id> [--for transcript|summary|both] [--timeout <sec>]
|
|
@@ -2478,17 +2496,52 @@ function echoedAudio(startResult) {
|
|
|
2478
2496
|
return null;
|
|
2479
2497
|
return { includeSystemAudio: a.includeSystemAudio, includeMic: a.includeMic };
|
|
2480
2498
|
}
|
|
2499
|
+
/**
|
|
2500
|
+
* Bridge protocol version that introduced agent audio control — an honoured
|
|
2501
|
+
* `audio` object and a mic that defaults OFF. Mirrors PROTOCOL_VERSION in
|
|
2502
|
+
* desktop/src-tauri/src/agent_bridge.rs, whose own comment is the contract:
|
|
2503
|
+
* below this, the app silently ignores the field and records with ITS defaults.
|
|
2504
|
+
*/
|
|
2505
|
+
const AUDIO_PROTOCOL_VERSION = 2;
|
|
2506
|
+
/**
|
|
2507
|
+
* Warn BEFORE `start` when the running app can't honour the audio request.
|
|
2508
|
+
* The timing is the entire point. The echo check below can only report what
|
|
2509
|
+
* happened once the mic has already been live for the length of the recording,
|
|
2510
|
+
* and a privacy flag must not fail open for that long. The discovery file
|
|
2511
|
+
* carries protocolVersion, so we can say it while the camera is still off.
|
|
2512
|
+
*
|
|
2513
|
+
* Returns true when it fired, so the post-start check doesn't say it twice.
|
|
2514
|
+
*/
|
|
2515
|
+
function warnAudioUncontrollable(protocolVersion, requested, emit) {
|
|
2516
|
+
if (protocolVersion >= AUDIO_PROTOCOL_VERSION)
|
|
2517
|
+
return false;
|
|
2518
|
+
emit(c.yellow(`warning: this Clipy app speaks bridge protocol v${protocolVersion} and cannot apply audio settings ` +
|
|
2519
|
+
`(needs v${AUDIO_PROTOCOL_VERSION}) — it will record with the APP's own defaults, so your ` +
|
|
2520
|
+
`MICROPHONE MAY BE RECORDING. Update the Clipy app (https://clipy.online/download) to make ` +
|
|
2521
|
+
`"${describeAudio(requested)}" take effect.`));
|
|
2522
|
+
return true;
|
|
2523
|
+
}
|
|
2481
2524
|
/**
|
|
2482
2525
|
* Report the audio that was actually applied, and warn loudly when the app did
|
|
2483
2526
|
* not confirm it. The dangerous direction is the silent one: on a desktop build
|
|
2484
2527
|
* that ignores the audio field, "mic off" is what we asked for and MIC ON is what
|
|
2485
2528
|
* happens — so an unconfirmed request is a privacy warning, not a footnote.
|
|
2529
|
+
*
|
|
2530
|
+
* This is the second of two gates. `warnAudioUncontrollable` catches the known
|
|
2531
|
+
* case from the version alone before recording starts; this catches the app that
|
|
2532
|
+
* claims the protocol but doesn't echo, which is an anomaly rather than an old
|
|
2533
|
+
* build. Both fail closed toward "assume the mic is live".
|
|
2486
2534
|
*/
|
|
2487
|
-
function reportAudio(requested, applied, emit) {
|
|
2535
|
+
function reportAudio(requested, applied, emit, alreadyWarned = false) {
|
|
2536
|
+
// Same reasoning as warnAudioUncontrollable's emitter: the informational line
|
|
2537
|
+
// may be suppressed under --json, the privacy warning may not.
|
|
2538
|
+
const warn = (m) => process.stderr.write(`${m}\n`);
|
|
2488
2539
|
if (!applied) {
|
|
2489
|
-
|
|
2490
|
-
`
|
|
2491
|
-
|
|
2540
|
+
if (!alreadyWarned) {
|
|
2541
|
+
warn(c.yellow(`warning: this Clipy app did not confirm the audio settings, so it may be recording with its ` +
|
|
2542
|
+
`own defaults and your MICROPHONE MAY BE RECORDING. ` +
|
|
2543
|
+
`Update the Clipy app (https://clipy.online/download) to make "${describeAudio(requested)}" take effect.`));
|
|
2544
|
+
}
|
|
2492
2545
|
return requested;
|
|
2493
2546
|
}
|
|
2494
2547
|
emit(`${c.dim("audio:")} ${describeAudio(applied)}`);
|
|
@@ -2522,6 +2575,10 @@ async function cmdRecordMac(opts) {
|
|
|
2522
2575
|
if (opts.recordingKind) {
|
|
2523
2576
|
log(c.yellow(`note: --type is not applied to --source mac-screen recordings yet (needs a Clipy app update)`));
|
|
2524
2577
|
}
|
|
2578
|
+
// Before the camera turns on, not after — see warnAudioUncontrollable().
|
|
2579
|
+
// Deliberately NOT `log`: a "your mic may be live" warning must survive
|
|
2580
|
+
// --json, and stderr never corrupts the JSON on stdout.
|
|
2581
|
+
const audioUncontrollable = warnAudioUncontrollable(info.protocolVersion, opts.audio, (m) => process.stderr.write(`${m}\n`));
|
|
2525
2582
|
const notes = resolveNarrationNotes(opts.notes, [0]);
|
|
2526
2583
|
const startResult = await bridgeRequest(info, "start", {
|
|
2527
2584
|
// Explicit, never implicit: an absent field would fall through to the app's
|
|
@@ -2536,7 +2593,7 @@ async function cmdRecordMac(opts) {
|
|
|
2536
2593
|
notes: notes.map((n) => ({ startMs: n.startMs, text: n.text })),
|
|
2537
2594
|
...(target ? { source: target.source } : {}),
|
|
2538
2595
|
});
|
|
2539
|
-
const appliedAudio = reportAudio(opts.audio, echoedAudio(startResult), log);
|
|
2596
|
+
const appliedAudio = reportAudio(opts.audio, echoedAudio(startResult), log, audioUncontrollable);
|
|
2540
2597
|
log(`${c.dim(`recording for ${opts.forSec}s…`)}`);
|
|
2541
2598
|
await new Promise((r) => setTimeout(r, opts.forSec * 1000));
|
|
2542
2599
|
log(`${c.dim("stopping + uploading…")}`);
|
|
@@ -2616,6 +2673,8 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
2616
2673
|
if (opts.recordingKind && !opts.json) {
|
|
2617
2674
|
process.stderr.write(`${c.yellow("note: --type is not applied to --source mac-screen recordings yet (needs a Clipy app update)")}\n`);
|
|
2618
2675
|
}
|
|
2676
|
+
// Before the camera turns on, not after — see warnAudioUncontrollable().
|
|
2677
|
+
const audioUncontrollable = warnAudioUncontrollable(info.protocolVersion, opts.audio, (m) => process.stderr.write(`${m}\n`));
|
|
2619
2678
|
const startResult = await bridgeRequest(info, "start", {
|
|
2620
2679
|
// Explicit, never implicit — see reportAudio(): an absent field falls
|
|
2621
2680
|
// through to the app's interactive defaults (mic ON) on older builds.
|
|
@@ -2627,7 +2686,7 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
2627
2686
|
...(target ? { source: target.source } : {}),
|
|
2628
2687
|
});
|
|
2629
2688
|
writeSessionState(file, macSessionState(info, maxSec));
|
|
2630
|
-
const appliedAudio = reportAudio(opts.audio, echoedAudio(startResult), (m) => process.stderr.write(`${m}\n`));
|
|
2689
|
+
const appliedAudio = reportAudio(opts.audio, echoedAudio(startResult), (m) => process.stderr.write(`${m}\n`), audioUncontrollable);
|
|
2631
2690
|
if (opts.json) {
|
|
2632
2691
|
printJson({
|
|
2633
2692
|
state: "recording",
|
|
@@ -4042,6 +4101,8 @@ function cmdGuide(json) {
|
|
|
4042
4101
|
cmdDoc("summary", "clipy summary <id> [--json]", "AI summary: TL;DR, key points, action items"),
|
|
4043
4102
|
cmdDoc("moments", "clipy moments <id> [--json]", "Key moments: timestamps, captions, click coords"),
|
|
4044
4103
|
cmdDoc("context", "clipy context <id>", "Full agent-context bundle as markdown"),
|
|
4104
|
+
cmdDoc("context import", "clipy context import <youtube-url|local-file> [--transcript <f>] [--output <dir>] [--language <code>] [--title <t>] [--tag <t>]… [--folder <name>] [--sync] [--json]", "Compile ANY video into a local Clipy context bundle — a directory holding recording.md (the agent-facing document, with the untrusted-content warning and [MM:SS] transcript sections), manifest.json (provenance, versions, sufficiency report) and transcript.json. YouTube URLs resolve on YOUR machine via a Clipy-managed yt-dlp (auto-installed into ~/.clipy/bin on first use, with a disclosure); creator captions are preferred over auto-captions and NO media is downloaded. Local files need --transcript <.vtt|.srt|Clipy transcript JSON> and are probed with ffprobe. A deterministic classifier scores how well the transcript stands alone and lists the timestamps where it is blind — v1 emits the transcript profile only, so those gaps are the honest statement of what the bundle cannot show. Reruns over the same source are idempotent. --sync additionally uploads the DERIVED bundle (never source media) to your private library.", ["--transcript", "--output", "--language", "--title", "--tag", "--folder", "--sync", "--json"]),
|
|
4105
|
+
cmdDoc("context read", "clipy context read <bundle-path>", "Print a local bundle's recording.md to stdout — plain, unpaged, uncoloured, for an agent to read directly."),
|
|
4045
4106
|
cmdDoc("download", "clipy download <id> [-o path]", "Download the MP4"),
|
|
4046
4107
|
cmdDoc("open", "clipy open <id>", "Open the share page in a browser"),
|
|
4047
4108
|
cmdDoc("wait", "clipy wait <id> [--for transcript|summary|both] [--timeout sec]", "Block until artifacts are ready"),
|
|
@@ -4174,6 +4235,14 @@ async function main() {
|
|
|
4174
4235
|
viewports: { type: "string" },
|
|
4175
4236
|
max: { type: "string" },
|
|
4176
4237
|
replace: { type: "string" },
|
|
4238
|
+
transcript: { type: "string" },
|
|
4239
|
+
language: { type: "string" },
|
|
4240
|
+
folder: { type: "string" },
|
|
4241
|
+
tag: { type: "string", multiple: true },
|
|
4242
|
+
sync: { type: "boolean", default: false },
|
|
4243
|
+
// Opt out of Phase 2: sync and take the server's verdict, but never
|
|
4244
|
+
// download media or write frames.
|
|
4245
|
+
"no-frames": { type: "boolean", default: false },
|
|
4177
4246
|
source: { type: "string" },
|
|
4178
4247
|
window: { type: "string" },
|
|
4179
4248
|
display: { type: "string" },
|
|
@@ -4327,11 +4396,49 @@ async function main() {
|
|
|
4327
4396
|
die("usage: clipy moments <id|url> [--json]", 2);
|
|
4328
4397
|
await cmdMoments(ctx, rest[0], json);
|
|
4329
4398
|
return;
|
|
4330
|
-
case "context":
|
|
4399
|
+
case "context": {
|
|
4400
|
+
// `import` and `read` are reserved literals — they shadow any recording id
|
|
4401
|
+
// by that name, which is why they can never be confused for one.
|
|
4402
|
+
if (rest[0] === "import") {
|
|
4403
|
+
if (!rest[1])
|
|
4404
|
+
die("usage: clipy context import <youtube-url|local-file> [--transcript <f>] [--output <dir>] [--sync]", 2);
|
|
4405
|
+
try {
|
|
4406
|
+
await cmdContextImport(rest[1], {
|
|
4407
|
+
apiUrl: ctx.apiUrl,
|
|
4408
|
+
apiKey: ctx.apiKey,
|
|
4409
|
+
cliVersion: VERSION,
|
|
4410
|
+
transcriptPath: values.transcript,
|
|
4411
|
+
outputDir: values.output,
|
|
4412
|
+
language: values.language,
|
|
4413
|
+
title: values.title,
|
|
4414
|
+
tags: values.tag ?? [],
|
|
4415
|
+
folder: values.folder,
|
|
4416
|
+
sync: Boolean(values.sync),
|
|
4417
|
+
frames: !values["no-frames"],
|
|
4418
|
+
json,
|
|
4419
|
+
});
|
|
4420
|
+
}
|
|
4421
|
+
catch (e) {
|
|
4422
|
+
die(e.message);
|
|
4423
|
+
}
|
|
4424
|
+
return;
|
|
4425
|
+
}
|
|
4426
|
+
if (rest[0] === "read") {
|
|
4427
|
+
if (!rest[1])
|
|
4428
|
+
die("usage: clipy context read <bundle-path>", 2);
|
|
4429
|
+
try {
|
|
4430
|
+
cmdContextRead(rest[1]);
|
|
4431
|
+
}
|
|
4432
|
+
catch (e) {
|
|
4433
|
+
die(e.message);
|
|
4434
|
+
}
|
|
4435
|
+
return;
|
|
4436
|
+
}
|
|
4331
4437
|
if (!rest[0])
|
|
4332
|
-
die("usage: clipy context <id|url>", 2);
|
|
4438
|
+
die("usage: clipy context <id|url> | clipy context import <url|file> | clipy context read <bundle-path>", 2);
|
|
4333
4439
|
await cmdContext(ctx, rest[0]);
|
|
4334
4440
|
return;
|
|
4441
|
+
}
|
|
4335
4442
|
case "download":
|
|
4336
4443
|
if (!rest[0])
|
|
4337
4444
|
die("usage: clipy download <id|url> [-o <path>]", 2);
|