fablecut 1.19.0 → 1.20.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/CLAUDE.md +62 -4
- package/README.md +1 -0
- package/app.js +71 -38
- package/delivery.js +12 -7
- package/focus.js +165 -0
- package/index.html +2 -0
- package/manifest.json +59 -0
- package/mcp-server.js +54 -1
- package/package.json +2 -1
- package/paths.js +4 -3
- package/select-menu.js +295 -0
- package/server.js +76 -7
- package/style.css +245 -1
- package/workflows.js +153 -0
package/style.css
CHANGED
|
@@ -4233,7 +4233,8 @@ input[type="range"].cq-hue {
|
|
|
4233
4233
|
padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
|
|
4234
4234
|
background: var(--panel); font-size: 12px; min-width: 0;
|
|
4235
4235
|
}
|
|
4236
|
-
|
|
4236
|
+
/* an output left out dims, but its checkbox doesn't: it is how you put the output back */
|
|
4237
|
+
.dlv-batch-list li.off > :not(input[type="checkbox"]) { opacity: .55; }
|
|
4237
4238
|
.dlv-batch-list input[type="checkbox"] { accent-color: var(--accent); flex: none; }
|
|
4238
4239
|
.dlv-batch-list .bo-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
|
4239
4240
|
.dlv-batch-list .bo-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
@@ -4530,6 +4531,249 @@ body { background: var(--bg); }
|
|
|
4530
4531
|
.track:nth-child(even):not(.drop-hint) { background-color: #ffffff05; } /* a drop target keeps its highlight */
|
|
4531
4532
|
.insp-section { background: var(--panel-sub); border-radius: 6px; padding: 8px 10px; margin: 0 0 10px; }
|
|
4532
4533
|
|
|
4534
|
+
/* ── Select menus (select-menu.js): our chevron on the box, a themed list ── */
|
|
4535
|
+
/* the same selects select-menu.js themes (isThemed): single choice, no size or size="1", not data-native */
|
|
4536
|
+
select:not([multiple]):not([data-native]):is(:not([size]), [size="1"]) {
|
|
4537
|
+
appearance: none;
|
|
4538
|
+
-webkit-appearance: none;
|
|
4539
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b8b93' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
|
4540
|
+
background-repeat: no-repeat;
|
|
4541
|
+
background-position: right 7px center;
|
|
4542
|
+
background-size: 9px 6px;
|
|
4543
|
+
padding-right: 22px !important;
|
|
4544
|
+
cursor: pointer;
|
|
4545
|
+
text-overflow: ellipsis;
|
|
4546
|
+
}
|
|
4547
|
+
select:not([multiple]):not([data-native]):is(:not([size]), [size="1"]):hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
|
|
4548
|
+
select.fc-open { border-color: var(--accent) !important; }
|
|
4549
|
+
select:disabled { cursor: not-allowed; }
|
|
4550
|
+
select:focus { outline: none; }
|
|
4551
|
+
/* the keyboard outline wins over panels that drop the outline on :focus (.dlv-f in Export) */
|
|
4552
|
+
select:focus-visible, .dlv-f select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
4553
|
+
|
|
4554
|
+
.fc-select-list {
|
|
4555
|
+
position: fixed;
|
|
4556
|
+
z-index: 10000;
|
|
4557
|
+
overflow-y: auto;
|
|
4558
|
+
overscroll-behavior: contain;
|
|
4559
|
+
padding: 4px;
|
|
4560
|
+
background: var(--panel-head);
|
|
4561
|
+
border: 1px solid var(--border);
|
|
4562
|
+
border-radius: 7px;
|
|
4563
|
+
box-shadow: 0 10px 28px rgba(0, 0, 0, .55);
|
|
4564
|
+
font: 12px/1.35 "Segoe UI", system-ui, sans-serif;
|
|
4565
|
+
color: var(--text);
|
|
4566
|
+
animation: fc-select-in .09s ease-out;
|
|
4567
|
+
scrollbar-width: thin;
|
|
4568
|
+
}
|
|
4569
|
+
.fc-select-list.up { animation-name: fc-select-in-up; }
|
|
4570
|
+
@keyframes fc-select-in { from { opacity: 0; transform: translateY(-3px); } }
|
|
4571
|
+
@keyframes fc-select-in-up { from { opacity: 0; transform: translateY(3px); } }
|
|
4572
|
+
.fc-select-opt {
|
|
4573
|
+
position: relative;
|
|
4574
|
+
padding: 5px 10px 5px 24px;
|
|
4575
|
+
border-radius: 4px;
|
|
4576
|
+
white-space: nowrap;
|
|
4577
|
+
overflow: hidden;
|
|
4578
|
+
text-overflow: ellipsis;
|
|
4579
|
+
cursor: pointer;
|
|
4580
|
+
}
|
|
4581
|
+
.fc-select-opt.in-group { padding-left: 30px; }
|
|
4582
|
+
.fc-select-opt.active { background: color-mix(in srgb, var(--accent) 28%, transparent); color: #fff; }
|
|
4583
|
+
.fc-select-opt.selected { color: #cfc8ff; }
|
|
4584
|
+
.fc-select-opt.selected::before {
|
|
4585
|
+
content: "";
|
|
4586
|
+
position: absolute;
|
|
4587
|
+
left: 9px;
|
|
4588
|
+
top: 50%;
|
|
4589
|
+
width: 6px;
|
|
4590
|
+
height: 6px;
|
|
4591
|
+
margin-top: -3px;
|
|
4592
|
+
border-radius: 50%;
|
|
4593
|
+
background: var(--accent);
|
|
4594
|
+
}
|
|
4595
|
+
.fc-select-opt.in-group.selected::before { left: 15px; }
|
|
4596
|
+
.fc-select-opt.disabled { opacity: .4; cursor: default; }
|
|
4597
|
+
.fc-select-group {
|
|
4598
|
+
padding: 7px 10px 3px;
|
|
4599
|
+
font-size: 10.5px;
|
|
4600
|
+
font-weight: 600;
|
|
4601
|
+
letter-spacing: .4px;
|
|
4602
|
+
text-transform: uppercase;
|
|
4603
|
+
color: var(--dim);
|
|
4604
|
+
}
|
|
4605
|
+
.fc-select-group:not(:first-child) { margin-top: 3px; border-top: 1px solid var(--border); }
|
|
4606
|
+
.fc-select-empty { padding: 6px 10px; color: var(--dim); }
|
|
4607
|
+
|
|
4608
|
+
/* touch: rows big enough for a finger (desktop stays compact) */
|
|
4609
|
+
@media (pointer: coarse) {
|
|
4610
|
+
.fc-select-opt { padding-top: 14px; padding-bottom: 14px; }
|
|
4611
|
+
}
|
|
4612
|
+
/* forced colours: the keyboard's row (what Enter picks) stands apart from the current choice */
|
|
4613
|
+
@media (forced-colors: active) {
|
|
4614
|
+
.fc-select-opt.active { outline: 2px solid Highlight; outline-offset: -2px; background: Highlight; color: HighlightText; }
|
|
4615
|
+
.fc-select-opt.selected::before { background: CanvasText; }
|
|
4616
|
+
.fc-select-opt.active.selected::before { background: HighlightText; }
|
|
4617
|
+
select:focus-visible, .dlv-f select:focus-visible { outline-color: Highlight; }
|
|
4618
|
+
}
|
|
4619
|
+
|
|
4620
|
+
/* ── Form controls in the editor's theme ──
|
|
4621
|
+
On/off settings draw as switches; checkboxes that pick items from a list
|
|
4622
|
+
(export batch outputs, snap targets, dialog options) stay checkboxes in the
|
|
4623
|
+
theme. Horizontal sliders get a thin track and a round accent thumb, and
|
|
4624
|
+
text / number fields light their border with the accent while focused.
|
|
4625
|
+
Pure CSS: the controls stay native inputs, so .checked / .value / input /
|
|
4626
|
+
change behave as before. The vertical mixer faders keep the native look
|
|
4627
|
+
(they rely on writing-mode). */
|
|
4628
|
+
|
|
4629
|
+
/* Checkboxes everywhere: a themed box with a tick */
|
|
4630
|
+
input[type=checkbox] {
|
|
4631
|
+
appearance: none;
|
|
4632
|
+
-webkit-appearance: none;
|
|
4633
|
+
position: relative;
|
|
4634
|
+
flex: none;
|
|
4635
|
+
width: 15px;
|
|
4636
|
+
height: 15px;
|
|
4637
|
+
margin: 0;
|
|
4638
|
+
border-radius: 4px;
|
|
4639
|
+
background: var(--well);
|
|
4640
|
+
border: 1px solid var(--border);
|
|
4641
|
+
cursor: pointer;
|
|
4642
|
+
vertical-align: middle;
|
|
4643
|
+
transition: background .14s, border-color .14s;
|
|
4644
|
+
}
|
|
4645
|
+
input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
|
|
4646
|
+
input[type=checkbox]:checked::before {
|
|
4647
|
+
content: "";
|
|
4648
|
+
position: absolute;
|
|
4649
|
+
left: 4px;
|
|
4650
|
+
top: 1px;
|
|
4651
|
+
width: 4px;
|
|
4652
|
+
height: 8px;
|
|
4653
|
+
border: solid #fff;
|
|
4654
|
+
border-width: 0 2px 2px 0;
|
|
4655
|
+
transform: rotate(45deg);
|
|
4656
|
+
}
|
|
4657
|
+
input[type=checkbox]:indeterminate { background: var(--accent); border-color: var(--accent); }
|
|
4658
|
+
input[type=checkbox]:indeterminate::before {
|
|
4659
|
+
content: "";
|
|
4660
|
+
position: absolute;
|
|
4661
|
+
left: 3px;
|
|
4662
|
+
top: 6px;
|
|
4663
|
+
width: 7px;
|
|
4664
|
+
height: 2px;
|
|
4665
|
+
background: #fff;
|
|
4666
|
+
/* checked and indeterminate together: drop the tick's border and turn, so the bar stays flat */
|
|
4667
|
+
border: 0;
|
|
4668
|
+
transform: none;
|
|
4669
|
+
}
|
|
4670
|
+
input[type=checkbox]:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
|
|
4671
|
+
input[type=checkbox]:disabled { opacity: .45; cursor: not-allowed; }
|
|
4672
|
+
/* an unchecked batch output: a border you can find on the dark panel (--border is ~1.4:1 there) */
|
|
4673
|
+
.dlv-batch-list input[type=checkbox]:not(:checked) { border-color: var(--dim); }
|
|
4674
|
+
input[type=checkbox]:focus { outline: none; }
|
|
4675
|
+
input[type=checkbox]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
4676
|
+
|
|
4677
|
+
/* On/off settings: a switch. Inspector props, the Settings dialog, an effect's
|
|
4678
|
+
on / bypass, a qualifier's on. Same specificity as .insp-row input[type=checkbox]
|
|
4679
|
+
(3380) and later in the file, so no !important. */
|
|
4680
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox] {
|
|
4681
|
+
width: 28px;
|
|
4682
|
+
height: 16px;
|
|
4683
|
+
border-radius: 999px;
|
|
4684
|
+
}
|
|
4685
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]::before,
|
|
4686
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]:checked::before,
|
|
4687
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]:indeterminate::before {
|
|
4688
|
+
content: "";
|
|
4689
|
+
position: absolute;
|
|
4690
|
+
top: 2px;
|
|
4691
|
+
left: 2px;
|
|
4692
|
+
width: 10px;
|
|
4693
|
+
height: 10px;
|
|
4694
|
+
border: 0;
|
|
4695
|
+
border-radius: 50%;
|
|
4696
|
+
background: var(--dim);
|
|
4697
|
+
transform: none;
|
|
4698
|
+
transition: transform .14s ease, background .14s;
|
|
4699
|
+
}
|
|
4700
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]:checked::before { transform: translateX(12px); background: #fff; }
|
|
4701
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]:indeterminate::before { transform: translateX(6px); background: #fff; }
|
|
4702
|
+
|
|
4703
|
+
input[type=range]:not(.mix-fader) {
|
|
4704
|
+
appearance: none;
|
|
4705
|
+
-webkit-appearance: none;
|
|
4706
|
+
height: 18px;
|
|
4707
|
+
background: transparent;
|
|
4708
|
+
cursor: pointer;
|
|
4709
|
+
min-width: 0;
|
|
4710
|
+
}
|
|
4711
|
+
input[type=range]:not(.mix-fader):focus { outline: none; }
|
|
4712
|
+
input[type=range]:not(.mix-fader):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
|
|
4713
|
+
input[type=range]:not(.mix-fader)::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--panel-2); }
|
|
4714
|
+
input[type=range]:not(.mix-fader)::-moz-range-track { height: 4px; border-radius: 2px; background: var(--panel-2); }
|
|
4715
|
+
input[type=range]:not(.mix-fader)::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
|
|
4716
|
+
input[type=range]:not(.mix-fader)::-webkit-slider-thumb {
|
|
4717
|
+
-webkit-appearance: none;
|
|
4718
|
+
width: 12px;
|
|
4719
|
+
height: 12px;
|
|
4720
|
+
margin-top: -4px;
|
|
4721
|
+
border-radius: 50%;
|
|
4722
|
+
background: #e8e6ff;
|
|
4723
|
+
border: 2px solid var(--accent);
|
|
4724
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
|
|
4725
|
+
transition: transform .1s;
|
|
4726
|
+
}
|
|
4727
|
+
input[type=range]:not(.mix-fader)::-moz-range-thumb {
|
|
4728
|
+
width: 9px;
|
|
4729
|
+
height: 9px;
|
|
4730
|
+
border-radius: 50%;
|
|
4731
|
+
background: #e8e6ff;
|
|
4732
|
+
border: 2px solid var(--accent);
|
|
4733
|
+
}
|
|
4734
|
+
input[type=range]:not(.mix-fader):hover::-webkit-slider-thumb,
|
|
4735
|
+
input[type=range]:not(.mix-fader):active::-webkit-slider-thumb { transform: scale(1.2); }
|
|
4736
|
+
input[type=range]:not(.mix-fader):focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent); }
|
|
4737
|
+
input[type=range]:not(.mix-fader):disabled { opacity: .45; cursor: not-allowed; }
|
|
4738
|
+
/* the qualifier's hue slider shows the hue wheel as its track (the rule above
|
|
4739
|
+
would otherwise replace its gradient: same specificity, later in the file) */
|
|
4740
|
+
input[type="range"].cq-hue:not(.mix-fader) {
|
|
4741
|
+
background: linear-gradient(90deg, #f33, #ff3, #3f3, #3ff, #33f, #f3f, #f33);
|
|
4742
|
+
border-radius: 3px;
|
|
4743
|
+
height: 6px;
|
|
4744
|
+
}
|
|
4745
|
+
input[type="range"].cq-hue::-webkit-slider-runnable-track { background: transparent; }
|
|
4746
|
+
input[type="range"].cq-hue::-moz-range-track { background: transparent; }
|
|
4747
|
+
input[type="range"].cq-hue::-moz-range-progress { background: transparent; }
|
|
4748
|
+
|
|
4749
|
+
input[type=number], input[type=text], input[type=search], input[type=url] { color-scheme: dark; }
|
|
4750
|
+
input[type=number]:focus, input[type=text]:focus, input[type=search]:focus, input[type=url]:focus, textarea:focus {
|
|
4751
|
+
border-color: var(--accent) !important;
|
|
4752
|
+
}
|
|
4753
|
+
input[type=number]:focus:not(:focus-visible), input[type=text]:focus:not(:focus-visible), input[type=search]:focus:not(:focus-visible),
|
|
4754
|
+
input[type=url]:focus:not(:focus-visible), textarea:focus:not(:focus-visible) { outline: none; }
|
|
4755
|
+
|
|
4756
|
+
/* Windows High Contrast / forced colours: the system repaints backgrounds, so
|
|
4757
|
+
give the switch knob and the focus rings system colours that stay visible */
|
|
4758
|
+
@media (forced-colors: active) {
|
|
4759
|
+
input[type=checkbox] { border-color: CanvasText; }
|
|
4760
|
+
input[type=checkbox]:checked, input[type=checkbox]:indeterminate { background: Highlight; border-color: Highlight; }
|
|
4761
|
+
input[type=checkbox]:checked::before { border-color: HighlightText; forced-color-adjust: none; }
|
|
4762
|
+
input[type=checkbox]:indeterminate::before { background: HighlightText; forced-color-adjust: none; }
|
|
4763
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]::before { background: CanvasText; forced-color-adjust: none; }
|
|
4764
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]:checked::before,
|
|
4765
|
+
:is(.insp-row, .settings-row, .fx-head, .cq-on) input[type=checkbox]:indeterminate::before { background: HighlightText; }
|
|
4766
|
+
input[type=checkbox]:focus-visible,
|
|
4767
|
+
input[type=range]:not(.mix-fader):focus-visible { outline-color: Highlight; }
|
|
4768
|
+
/* the track's fill is replaced by the canvas colour: outline it so it stays visible.
|
|
4769
|
+
Separate rules: a browser drops a whole rule with a pseudo-element it doesn't know */
|
|
4770
|
+
input[type=range]:not(.mix-fader)::-webkit-slider-runnable-track { border: 1px solid CanvasText; }
|
|
4771
|
+
input[type=range]:not(.mix-fader)::-moz-range-track { border: 1px solid CanvasText; }
|
|
4772
|
+
input[type=number]:focus, input[type=text]:focus, input[type=search]:focus, input[type=url]:focus, textarea:focus { outline: 2px solid Highlight; }
|
|
4773
|
+
}
|
|
4774
|
+
input[type=number]::-webkit-inner-spin-button { opacity: .35; }
|
|
4775
|
+
input[type=number]:hover::-webkit-inner-spin-button { opacity: .8; }
|
|
4776
|
+
|
|
4533
4777
|
/* ── Command search (Ctrl/Cmd+K) ── */
|
|
4534
4778
|
#cmdkOverlay { align-items: flex-start; padding-top: 12vh; }
|
|
4535
4779
|
.cmdk {
|
package/workflows.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/* FableCut saved workflows. Zero dependencies. Required by the server, the MCP
|
|
2
|
+
server and the tests.
|
|
3
|
+
|
|
4
|
+
A WORKFLOW is a recipe an agent can repeat on another project: a name, what
|
|
5
|
+
it is for, and its steps in order. Each step is plain language ("Normalize the
|
|
6
|
+
voice to -16 LUFS"), and may carry the tool call that did it last time:
|
|
7
|
+
{ id, name, description?, tags?, steps: [{ text, call?: { tool, args } }], created, updated }
|
|
8
|
+
The agent reads the steps and does them again, using its own judgement where
|
|
9
|
+
the footage differs (which clips, where the cuts go); a call is a worked
|
|
10
|
+
example, not a script to replay blindly. Saved as library/workflows/<id>.json,
|
|
11
|
+
shared by every project. */
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
const LIMITS = { name: 80, description: 600, step: 1000, steps: 50, tags: 12, tag: 32, args: 20000 };
|
|
15
|
+
// trimmed again after the cut, so a slug of a slug is the same slug (the file name is the id)
|
|
16
|
+
const slug = (s) => String(s || "").toLowerCase().replace(/[^a-z0-9]+/g, "-").slice(0, 60).replace(/^-+|-+$/g, "");
|
|
17
|
+
/** A text field as a trimmed string; "" when absent; null when it isn't text at all. */
|
|
18
|
+
const clean = (s) => (s == null ? "" : typeof s === "string" || typeof s === "number" ? String(s).replace(/\r\n?/g, "\n").trim() : null);
|
|
19
|
+
|
|
20
|
+
/** A checked copy of a workflow. strict: throw on anything wrong (saving);
|
|
21
|
+
* otherwise return null (reading files, where a bad one is skipped).
|
|
22
|
+
* tools: the tool names a call may use (default: any fablecut_ tool but this one). */
|
|
23
|
+
function normalizeWorkflow(w, strict, tools) {
|
|
24
|
+
if (strict) return checkWorkflow(w, true, tools);
|
|
25
|
+
// reading files: anything odd in one skips that file, never the whole listing
|
|
26
|
+
try { return checkWorkflow(w, false, tools); } catch { return null; }
|
|
27
|
+
}
|
|
28
|
+
function checkWorkflow(w, strict, tools) {
|
|
29
|
+
const bad = (msg) => { if (strict) throw new Error("workflow: " + msg); return null; };
|
|
30
|
+
if (!w || typeof w !== "object" || Array.isArray(w)) return bad("expected an object {name, steps}");
|
|
31
|
+
const name = clean(w.name);
|
|
32
|
+
if (name === null) return bad("name is text");
|
|
33
|
+
if (!name) return bad("name is required");
|
|
34
|
+
if (name.length > LIMITS.name) return bad(`name is longer than ${LIMITS.name} characters`);
|
|
35
|
+
const id = slug(typeof w.id === "string" && w.id ? w.id : name);
|
|
36
|
+
if (!id) return bad("name needs a letter or digit");
|
|
37
|
+
const description = clean(w.description);
|
|
38
|
+
if (description === null) return bad("description is text");
|
|
39
|
+
if (description.length > LIMITS.description) return bad(`description is longer than ${LIMITS.description} characters`);
|
|
40
|
+
if (!Array.isArray(w.steps) || !w.steps.length) return bad("steps: at least one step");
|
|
41
|
+
if (w.steps.length > LIMITS.steps) return bad(`at most ${LIMITS.steps} steps`);
|
|
42
|
+
const steps = [];
|
|
43
|
+
for (let i = 0; i < w.steps.length; i++) {
|
|
44
|
+
const s = typeof w.steps[i] === "string" ? { text: w.steps[i] } : w.steps[i];
|
|
45
|
+
const at = `step ${i + 1}`;
|
|
46
|
+
if (!s || typeof s !== "object") return bad(`${at}: expected {text, call?}`);
|
|
47
|
+
const text = clean(s.text);
|
|
48
|
+
if (text === null) return bad(`${at}: text is text`);
|
|
49
|
+
if (!text) return bad(`${at}: text is required (say what the step does)`);
|
|
50
|
+
if (text.length > LIMITS.step) return bad(`${at}: text is longer than ${LIMITS.step} characters`);
|
|
51
|
+
const step = { text };
|
|
52
|
+
if (s.call != null) {
|
|
53
|
+
const c = s.call;
|
|
54
|
+
if (typeof c !== "object" || Array.isArray(c)) return bad(`${at}: call is {tool, args}`);
|
|
55
|
+
const tool = String(c.tool || "");
|
|
56
|
+
const allowed = tools ? tools.includes(tool) : /^fablecut_[a-z_]+$/.test(tool);
|
|
57
|
+
if (!allowed || tool === "fablecut_workflows") return bad(`${at}: call.tool "${tool}" is not a FableCut tool${tools ? " (" + tools.join(", ") + ")" : ""}`);
|
|
58
|
+
const args = c.args == null ? {} : c.args;
|
|
59
|
+
if (typeof args !== "object" || Array.isArray(args)) return bad(`${at}: call.args is an object`);
|
|
60
|
+
if (JSON.stringify(args).length > LIMITS.args) return bad(`${at}: call.args is larger than ${LIMITS.args} characters`);
|
|
61
|
+
step.call = { tool, args: JSON.parse(JSON.stringify(args)) };
|
|
62
|
+
}
|
|
63
|
+
steps.push(step);
|
|
64
|
+
}
|
|
65
|
+
const out = { id, name };
|
|
66
|
+
if (description) out.description = description;
|
|
67
|
+
if (w.tags != null) {
|
|
68
|
+
if (!Array.isArray(w.tags)) return bad("tags is a list of words");
|
|
69
|
+
if (w.tags.some((t) => clean(t) === null)) return bad("tags are words");
|
|
70
|
+
const tags = [...new Set(w.tags.map(clean).filter(Boolean))];
|
|
71
|
+
if (tags.length > LIMITS.tags) return bad(`at most ${LIMITS.tags} tags`);
|
|
72
|
+
if (tags.some((t) => t.length > LIMITS.tag)) return bad(`a tag is longer than ${LIMITS.tag} characters`);
|
|
73
|
+
if (tags.length) out.tags = tags;
|
|
74
|
+
}
|
|
75
|
+
out.steps = steps;
|
|
76
|
+
if (typeof w.created === "string") out.created = w.created;
|
|
77
|
+
if (typeof w.updated === "string") out.updated = w.updated;
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The workflows in readSaved("workflows") entries ({file, data}); bad files are skipped. Each
|
|
82
|
+
* remembers the file it came from (not enumerable, so it never shows in JSON), so delete
|
|
83
|
+
* removes that file even when its name isn't exactly the id. */
|
|
84
|
+
function fromFiles(entries) {
|
|
85
|
+
const out = [];
|
|
86
|
+
for (const x of entries || []) {
|
|
87
|
+
const w = normalizeWorkflow(x && x.data);
|
|
88
|
+
if (!w) continue;
|
|
89
|
+
Object.defineProperty(w, "file", { value: x.file, enumerable: false });
|
|
90
|
+
out.push(w);
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** After saving workflow `id` as <id>.json: the other files that held that id (an older or
|
|
96
|
+
* hand-written file under another name), to remove so one workflow stays one file. */
|
|
97
|
+
function staleFiles(all, id) {
|
|
98
|
+
// exact names: "PODCAST.JSON" is a file of its own on a case-sensitive disk; removeStale
|
|
99
|
+
// checks the file's identity, so on Windows / macOS it is never the file just written
|
|
100
|
+
return all.filter((w) => w.id === id && w.file && w.file !== id + ".json").map((w) => w.file);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Remove the stale files of workflow `id` from `dir` (fs and path passed in, so this module
|
|
104
|
+
* stays free of I/O). Each is read again first and removed only while it still holds that
|
|
105
|
+
* workflow and is not the file just written: another process may have saved a different one
|
|
106
|
+
* under that name since the listing was read. */
|
|
107
|
+
function removeStale(dir, all, id, fs, path) {
|
|
108
|
+
const dest = path.join(dir, id + ".json");
|
|
109
|
+
let destStat = null;
|
|
110
|
+
try { destStat = fs.statSync(dest); } catch { }
|
|
111
|
+
for (const f of staleFiles(all, id)) {
|
|
112
|
+
const p = path.join(dir, path.basename(f));
|
|
113
|
+
try {
|
|
114
|
+
const st = fs.statSync(p);
|
|
115
|
+
if (destStat && st.dev === destStat.dev && (st.ino !== 0 ? st.ino === destStat.ino : f.toLowerCase() === (id + ".json").toLowerCase())) continue;
|
|
116
|
+
const w = normalizeWorkflow(JSON.parse(fs.readFileSync(p, "utf8").replace(/^/, "")));
|
|
117
|
+
if (w && w.id === id) fs.rmSync(p, { force: true });
|
|
118
|
+
} catch { }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The tool names in a .mcpb manifest ({tools:[{name}]}), or null when it can't be read. */
|
|
123
|
+
function manifestTools(manifest) {
|
|
124
|
+
const t = manifest && Array.isArray(manifest.tools) ? manifest.tools.map((x) => x && x.name).filter((n) => typeof n === "string") : [];
|
|
125
|
+
return t.length ? t : null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Find a saved workflow by id or name (case-insensitive). */
|
|
129
|
+
function findWorkflow(list, key) {
|
|
130
|
+
const k = String(key || "").trim().toLowerCase();
|
|
131
|
+
if (!k) return null;
|
|
132
|
+
return list.find((w) => w.id === k) || list.find((w) => w.name.toLowerCase() === k) || list.find((w) => w.id === slug(k)) || null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** One line per workflow, for listings. */
|
|
136
|
+
function workflowLine(w) {
|
|
137
|
+
return `${w.id} — "${w.name}", ${w.steps.length} step${w.steps.length === 1 ? "" : "s"}` +
|
|
138
|
+
(w.tags ? ` #${w.tags.join(" #")}` : "") + (w.description ? `: ${w.description.length > 140 ? w.description.slice(0, 140) + "…" : w.description}` : "");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The whole workflow as text an agent follows. */
|
|
142
|
+
function describeWorkflow(w) {
|
|
143
|
+
const lines = [`Workflow "${w.name}" (${w.id})` + (w.tags ? ` #${w.tags.join(" #")}` : "")];
|
|
144
|
+
if (w.description) lines.push(w.description);
|
|
145
|
+
lines.push("");
|
|
146
|
+
w.steps.forEach((s, i) => {
|
|
147
|
+
lines.push(`${i + 1}. ${s.text}`);
|
|
148
|
+
if (s.call) lines.push(` last time: ${s.call.tool} ${JSON.stringify(s.call.args)}`);
|
|
149
|
+
});
|
|
150
|
+
return lines.join("\n");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = { LIMITS, slug, normalizeWorkflow, fromFiles, staleFiles, removeStale, manifestTools, findWorkflow, workflowLine, describeWorkflow };
|