comfy-ts 2.18.0 → 2.19.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 +140 -95
- package/claude-code/.claude-plugin/plugin.json +9 -0
- package/claude-code/skills/convert/SKILL.md +25 -0
- package/claude-code/skills/guide/SKILL.md +21 -0
- package/claude-code/skills/run/SKILL.md +12 -0
- package/claude-code/skills/setup/SKILL.md +15 -0
- package/claude-code/skills/workflow/SKILL.md +19 -0
- package/dist/cli.js +219 -6
- package/dist/cli.js.map +1 -1
- package/dist/{state-DgwWhZWb.js → exampleAssets-CE4PUy3n.js} +206 -58
- package/dist/exampleAssets-CE4PUy3n.js.map +1 -0
- package/dist/index.cjs +173 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -8
- package/dist/index.d.ts +37 -8
- package/dist/index.js +173 -59
- package/dist/index.js.map +1 -1
- package/dist/{run-run-Wn7H72Zg.js → run-run-C_yXY0vl.js} +2 -3
- package/dist/{run-run-Wn7H72Zg.js.map → run-run-C_yXY0vl.js.map} +1 -1
- package/dist/{run-tui-VWSj1D_j.js → run-tui-B3dsftdB.js} +2 -3
- package/dist/{run-tui-VWSj1D_j.js.map → run-tui-B3dsftdB.js.map} +1 -1
- package/dist/web.d.ts +55 -26
- package/dist/web.js +164 -55
- package/dist/web.js.map +1 -1
- package/examples/README.md +17 -11
- package/guide-for-agents.md +4 -1
- package/package.json +3 -2
- package/src/cli/comfy-ts-cli.ts +8 -0
- package/src/cli/skill.ts +207 -0
- package/src/exampleAssets.ts +10 -4
- package/src/host/ComfyHost.ts +6 -36
- package/src/host/ComfyManager.ts +168 -42
- package/src/litegraph/expandSubgraphs.ts +58 -4
- package/src/litegraph/normalizeWorkflow.ts +6 -1
- package/src/manager/installedView.ts +2 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +25 -11
- package/dist/exampleAssets-BfWzygoM.js +0 -38
- package/dist/exampleAssets-BfWzygoM.js.map +0 -1
- package/dist/state-DgwWhZWb.js.map +0 -1
package/examples/README.md
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
# comfy-ts examples
|
|
2
2
|
|
|
3
|
-
Every `*.cflow.ts` file here is a runnable workflow module
|
|
3
|
+
Every `*.cflow.ts` file here is a runnable workflow module. Run it directly with bun, run it headless with `bunx comfy-ts run <name>`, or browse them all in the TUI (`bunx comfy-ts tui` lists them under "comfy-ts examples": tweak vars, ⌃R to run).
|
|
4
4
|
|
|
5
5
|
## Layout
|
|
6
6
|
|
|
7
|
-
- `rvion/01…04-*.cflow.ts
|
|
8
|
-
- `rvion/05-comfy-cloud.cflow.ts
|
|
9
|
-
- `rvion/06-qwen-image-edit.cflow.ts
|
|
10
|
-
- `rvion/07-local-llm-text-gen.cflow.ts
|
|
11
|
-
- `rvion/08-qwen-image-21-t2i.cflow.ts` / `rvion/09-qwen-image-21-edit.cflow.ts
|
|
12
|
-
- `rvion/
|
|
13
|
-
- `rvion/
|
|
14
|
-
- `
|
|
7
|
+
- `rvion/01…04-*.cflow.ts`: the didactic sequence against a LOCAL ComfyUI host. Edit the `comfy.host({...})` line to point at yours, and the first run generates a typed SDK for it.
|
|
8
|
+
- `rvion/05-comfy-cloud.cflow.ts`: the same t2i against [Comfy Cloud](https://cloud.comfy.org). No local GPU needed: the typed catalog ships committed at `comfy-cloud/sdk.d.ts`.
|
|
9
|
+
- `rvion/06-qwen-image-edit.cflow.ts`: image editing (qwen image edit 2511) against the same local host.
|
|
10
|
+
- `rvion/07-local-llm-text-gen.cflow.ts`: a local LLM, no image. Core's `TextGenerate` runs a chat model loaded through `CLIPLoader`, and the text comes back in `execution.text`. `--sweep` reports which text encoders on your host actually generate.
|
|
11
|
+
- `rvion/08-qwen-image-21-t2i.cflow.ts` / `rvion/09-qwen-image-21-edit.cflow.ts`: Qwen Image 2.1 (ComfyUI ≥ 0.37) against the same local host: text to image, and instruction editing of one reference image (its `remove background` preset is the official background-removal template).
|
|
12
|
+
- `rvion/10-anima-t2i.cflow.ts`: Anima text to image. Turbo, aesthetic, base, or base + turbo lora as one choice, an anima lora stack, an optional RMBG cutout. The model file is a `v.model` choice over the anima files on your host.
|
|
13
|
+
- `rvion/11-yue2-t2a.cflow.ts`: YuE2 text to music. The first prompt line is the style and the rest is the lyrics. ABC planning is a choice (full, melody, off), and the plan shows as a text result next to the song.
|
|
14
|
+
- `rvion/12-stable-audio-3-t2a.cflow.ts`: Stable Audio 3 Medium: music, instruments, sound effects or one-shots from one description. With `reprompt` on, a local Qwen3.5 2B first rewrites the description with the official template's instructions for the chosen category.
|
|
15
|
+
- `rvion/13-ace-step-15-xl-t2a.cflow.ts`: ACE-Step 1.5 XL: a song with vocals from a caption and lyrics, with the turbo, sft or base model, and bpm, key, beats per bar and language as settings.
|
|
16
|
+
- `rvion/14-video-soundtrack.cflow.ts`: a new soundtrack on a video. The frames of one file and the audio of another are muxed back at the fps you pick. Core nodes only. `exampleMediaPath()` resolves the bundled sample video and audio it defaults to.
|
|
17
|
+
- `rvion/15-tts-voice-clone.cflow.ts`: text to speech in a cloned voice (needs the [TTS-Audio-Suite](https://github.com/diodiogod/TTS-Audio-Suite) custom node pack on the host). Pick an engine (Chatterbox Multilingual v3 by default, Qwen3-TTS, Fish Audio S2 Pro, CosyVoice3, OmniVoice) and a language, drop a voice clip and write its transcript, and the text comes back as audio in `execution.audios`. A short synthetic English voice ships in `media/`, so it runs out of the box.
|
|
18
|
+
- `rvion/16-tts-voice-design.cflow.ts`: a new voice from a written description (needs TTS-Audio-Suite, Qwen3-TTS VoiceDesign). It speaks one sample line in that voice, and the clip plus that line are what `15-tts-voice-clone` takes as `voice` and `transcript`. From the command line the flow is two runs: `comfy-ts run tts-voice-design --description "…" --line "…" --out voices/sailor.flac` writes the clip and `voices/sailor.txt`, then `comfy-ts run tts-voice-clone --voice voices/sailor.flac --prompt "…" --out lines/001.flac` speaks any line in it.
|
|
19
|
+
- `comfy-cloud/<family>-<mode>.cflow.ts`: the model zoo, 73 files for 43 model families. One clean example per model family × mode (`t2i`, `i2i`, `t2v`, `i2v`, `t2a`), each mirroring an official ComfyUI template (flux, qwen-image, z-image, wan, ltx, hidream, ace-step, stable-audio, …). A suffix after the mode names a variant of the same family (`flux2-t2i-dev`). All share `comfy-cloud/cloudHost.ts`. The full list by mode is in the [main README](../README.md#the-model-zoo-73-cloud-workflows-43-model-families).
|
|
20
|
+
- `web/`: the browser entry `comfy-ts/web` in a runnable page (`bun examples/web/serve.ts`).
|
|
15
21
|
|
|
16
22
|
## Cloud API key
|
|
17
23
|
|
|
18
|
-
Cloud examples read `COMFY_CLOUD_API_KEY` (create one at cloud.comfy.org, paid tiers). Without it everything still loads and typechecks
|
|
24
|
+
Cloud examples read `COMFY_CLOUD_API_KEY` (create one at cloud.comfy.org, paid tiers). Without it everything still loads and typechecks: only `run()` needs the key.
|
|
19
25
|
|
|
20
26
|
```sh
|
|
21
27
|
COMFY_CLOUD_API_KEY=… bun examples/rvion/05-comfy-cloud.cflow.ts "a fox in the snow" 42
|
|
22
28
|
```
|
|
23
29
|
|
|
24
|
-
Cloud runs bill compute to your account
|
|
30
|
+
Cloud runs bill compute to your account. Start with a small t2i.
|
package/guide-for-agents.md
CHANGED
|
@@ -21,7 +21,7 @@ You are working in a project that uses `comfy-ts`, a type-safe ComfyUI companion
|
|
|
21
21
|
|
|
22
22
|
4. Gitignore `.comfy-ts/` entirely. It is local state: host schema dumps (often ~10MB, they describe that machine's models and paths), run outputs, TUI drafts and settings, lora keywords, preview cache. Everything in it is regenerable. (Exception: a private repo may commit `hosts/` to get typed CI.)
|
|
23
23
|
|
|
24
|
-
Before the first codegen the builder falls back to permissive base types, so code compiles either way.
|
|
24
|
+
Before the first codegen the builder falls back to permissive base types, so code compiles either way when `noUncheckedIndexedAccess` is off. With that flag on, every `b.Node(...)` call is an error until a generated sdk.d.ts is in scope, so run the codegen first. Types sharpen once the generated sdk is in scope.
|
|
25
25
|
|
|
26
26
|
## The workflow pattern: defineWorkflow + vars + build
|
|
27
27
|
|
|
@@ -97,8 +97,11 @@ bunx comfy-ts outline [file] [--section Name] [--lines N] # inspect a sdk.d.ts
|
|
|
97
97
|
bunx comfy-ts loras [--id <host-id>] [--host http://…] # mirror lora metadata (optional ComfyUI-Lora-Manager extension)
|
|
98
98
|
bunx comfy-ts tui [dir | module.cflow.ts] # interactive tweak & re-run
|
|
99
99
|
bunx comfy-ts run <name | module.cflow.ts> [--draft <name>] [--<var> <value>…] [--out <path>] [--json] # one generation, headless
|
|
100
|
+
bunx comfy-ts skill install [--user | --dir <skills-dir>] [--force] # Claude Code skills for this project
|
|
100
101
|
```
|
|
101
102
|
|
|
103
|
+
`comfy-ts skill install` gives Claude Code five slash commands in the project: `/comfy-ts-setup`, `/comfy-ts-workflow` (write a module), `/comfy-ts-convert` (a ComfyUI JSON into a module), `/comfy-ts-run` (one generation) and `/comfy-ts-guide` (questions, and the background Claude loads on its own). They follow this guide and never copy it. A rerun after an upgrade updates them, and a skill file you edited is kept unless you pass `--force`. Without npm, the same skills come as a Claude Code plugin: `/plugin marketplace add rvion/comfy-ts`, then `/plugin install comfy-ts@comfy-ts` (commands `/comfy-ts:setup` and so on).
|
|
104
|
+
|
|
102
105
|
`comfy-ts run` is how an agent generates: the module is found in the cwd, then in the bundled examples, by key or a unique part of it (`folder/name` narrows, like `rvion/anima`). Every var is a flag (`--prompt "…" --seed 7 --image in.png`, `--<var>-file` reads a text var from a file), `--out` says where the output goes, and `--json` prints one line with every output path. `comfy-ts run <name> --help` lists the vars. Every flag is a var name the module declares. A media var declared with `sidecarText: someTextVar` fills that text var from `<file>.txt` beside the file it is given (a voice clip's transcript, example 15).
|
|
103
106
|
|
|
104
107
|
`comfy-ts loras` writes `.comfy-ts/hosts/<id>/loras.json`: per lora, the model's real name, its civitai trigger words, tags, base model and preview url, stored raw. It is what makes `v.prompt(text, { loraKeywordsFrom: lorasVar })` inject a lora's trigger words with nothing typed by hand, and what lets the TUI find a lora by its human name. Read it yourself (`getLoraInfo`, `getLoraTriggerWords`, `getLoraDisplayName`) when a user asks which lora to pick. Absent extension or no sync yet: every getter answers empty, nothing breaks.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comfy-ts",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and
|
|
3
|
+
"version": "2.19.0",
|
|
4
|
+
"description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 80+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"comfyui",
|
|
7
7
|
"generative-ai",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"extra",
|
|
64
64
|
"README.md",
|
|
65
65
|
"guide-for-agents.md",
|
|
66
|
+
"claude-code",
|
|
66
67
|
"LICENSE"
|
|
67
68
|
],
|
|
68
69
|
"scripts": {
|
package/src/cli/comfy-ts-cli.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
5
5
|
import { runGen } from 'src/cli/gen.ts'
|
|
6
6
|
import { runLoras } from 'src/cli/loras.ts'
|
|
7
7
|
import { runOutline } from 'src/cli/outline.ts'
|
|
8
|
+
import { runSkill } from 'src/cli/skill.ts'
|
|
8
9
|
|
|
9
10
|
const HELP = `comfy-ts — typed SDK codegen for ComfyUI
|
|
10
11
|
|
|
@@ -48,6 +49,12 @@ Usage:
|
|
|
48
49
|
dir keeps the server's names). \`comfy-ts run <name> --help\` lists the vars,
|
|
49
50
|
\`comfy-ts run\` lists the modules. --json prints one line with the paths
|
|
50
51
|
|
|
52
|
+
comfy-ts skill install [--user | --dir <skills-dir>] [--force]
|
|
53
|
+
copy the comfy-ts Claude Code skills into .claude/skills/ of the cwd
|
|
54
|
+
(--user: your personal skills folder): /comfy-ts-guide, -setup,
|
|
55
|
+
-workflow, -convert, -run. A file you edited is never overwritten
|
|
56
|
+
without --force. \`comfy-ts skill --help\` says more
|
|
57
|
+
|
|
51
58
|
comfy-ts help
|
|
52
59
|
`
|
|
53
60
|
|
|
@@ -56,6 +63,7 @@ async function main(): Promise<number> {
|
|
|
56
63
|
if (cmd === 'gen') return runGen(rest)
|
|
57
64
|
if (cmd === 'outline') return runOutline(rest)
|
|
58
65
|
if (cmd === 'loras') return runLoras(rest)
|
|
66
|
+
if (cmd === 'skill') return runSkill(rest)
|
|
59
67
|
if (cmd === 'tui' || cmd === 'serve' || cmd === 'run') {
|
|
60
68
|
// .cflow.ts workflow modules need bun: node refuses to strip types under
|
|
61
69
|
// node_modules, exactly where the packaged examples live — and the bin's
|
package/src/cli/skill.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// `comfy-ts skill install`: copy the Claude Code skills of claude-code/skills/ into a skills folder.
|
|
2
|
+
// the record file holds the hash of every file the install wrote: it is what tells an untouched
|
|
3
|
+
// file (safe to update) from one the user edited (never overwritten without --force)
|
|
4
|
+
import { createHash } from 'node:crypto'
|
|
5
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { homedir } from 'node:os'
|
|
7
|
+
import { dirname, join, relative, resolve } from 'pathe'
|
|
8
|
+
import { comfyTsPackageDir } from 'src/exampleAssets.ts'
|
|
9
|
+
|
|
10
|
+
export const SKILL_PREFIX = 'comfy-ts-'
|
|
11
|
+
export const SKILL_RECORD_FILE = '.comfy-ts-skills.json'
|
|
12
|
+
|
|
13
|
+
export const SKILL_USAGE = `comfy-ts skill install [--user | --dir <skills-dir>] [--force]
|
|
14
|
+
copy the comfy-ts Claude Code skills into .claude/skills/ of the cwd (--user: your personal
|
|
15
|
+
skills folder, --dir: that folder): /comfy-ts-guide, /comfy-ts-setup, /comfy-ts-workflow,
|
|
16
|
+
/comfy-ts-convert, /comfy-ts-run. A rerun updates what it wrote; a file you edited is never
|
|
17
|
+
overwritten without --force. The same skills ship as a Claude Code plugin:
|
|
18
|
+
/plugin marketplace add rvion/comfy-ts, then /plugin install comfy-ts@comfy-ts`
|
|
19
|
+
|
|
20
|
+
export type SkillAction = 'created' | 'unchanged' | 'updated' | 'overwritten' | 'removed' | 'kept' | 'conflict'
|
|
21
|
+
export type SkillLine = { action: SkillAction; file: string }
|
|
22
|
+
export type SkillReport = { ok: boolean; lines: SkillLine[]; commands: string[] }
|
|
23
|
+
type SkillRecord = { version: string; files: Record<string, string> }
|
|
24
|
+
|
|
25
|
+
/** claude-code/skills/ of the installed package, resolved from this module, never from the cwd */
|
|
26
|
+
export function skillSourceDir(): string {
|
|
27
|
+
const pkgDir = comfyTsPackageDir(import.meta.url)
|
|
28
|
+
if (pkgDir == null) throw new Error('cannot find the comfy-ts package this command runs from')
|
|
29
|
+
const dir = join(pkgDir, 'claude-code', 'skills')
|
|
30
|
+
if (!existsSync(dir)) throw new Error(`the comfy-ts package has no skills folder at ${dir}`)
|
|
31
|
+
return dir
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const sha256 = (bytes: Buffer): string => createHash('sha256').update(bytes).digest('hex')
|
|
35
|
+
|
|
36
|
+
/** every file under a skill folder, as paths relative to it */
|
|
37
|
+
function filesUnder(dir: string, prefix = ''): string[] {
|
|
38
|
+
const out: string[] = []
|
|
39
|
+
for (const name of readdirSync(dir).sort()) {
|
|
40
|
+
const abs = join(dir, name)
|
|
41
|
+
if (statSync(abs).isDirectory()) out.push(...filesUnder(abs, `${prefix}${name}/`))
|
|
42
|
+
else out.push(`${prefix}${name}`)
|
|
43
|
+
}
|
|
44
|
+
return out
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readRecord(path: string): SkillRecord | null {
|
|
48
|
+
if (!existsSync(path)) return null
|
|
49
|
+
let parsed: unknown
|
|
50
|
+
try {
|
|
51
|
+
parsed = JSON.parse(readFileSync(path, 'utf8'))
|
|
52
|
+
} catch (e) {
|
|
53
|
+
throw new Error(`${path} is not valid json (${e instanceof Error ? e.message : String(e)}): fix or delete it`, {
|
|
54
|
+
cause: e,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
if (typeof parsed !== 'object' || parsed == null || !('files' in parsed)) {
|
|
58
|
+
throw new Error(`${path} has no "files" map: fix or delete it`)
|
|
59
|
+
}
|
|
60
|
+
const files = parsed.files
|
|
61
|
+
if (typeof files !== 'object' || files == null) throw new Error(`${path} has no "files" map: fix or delete it`)
|
|
62
|
+
const out: Record<string, string> = {}
|
|
63
|
+
for (const [k, v] of Object.entries(files)) if (typeof v === 'string') out[k] = v
|
|
64
|
+
const version = 'version' in parsed && typeof parsed.version === 'string' ? parsed.version : ''
|
|
65
|
+
return { version, files: out }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function packageVersion(pkgDir: string): string {
|
|
69
|
+
const parsed: unknown = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8'))
|
|
70
|
+
if (typeof parsed === 'object' && parsed != null && 'version' in parsed && typeof parsed.version === 'string') {
|
|
71
|
+
return parsed.version
|
|
72
|
+
}
|
|
73
|
+
throw new Error(`${join(pkgDir, 'package.json')} has no version`)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* plan, then write only when nothing conflicts (or `force`): a conflict anywhere writes nothing,
|
|
78
|
+
* so a refused install never leaves half an update behind
|
|
79
|
+
*/
|
|
80
|
+
export function installSkills(p: { from: string; to: string; force: boolean; version: string }): SkillReport {
|
|
81
|
+
const recordPath = join(p.to, SKILL_RECORD_FILE)
|
|
82
|
+
const record = readRecord(recordPath)
|
|
83
|
+
const source = new Map<string, Buffer>()
|
|
84
|
+
const commands: string[] = []
|
|
85
|
+
for (const skill of readdirSync(p.from).sort()) {
|
|
86
|
+
if (!statSync(join(p.from, skill)).isDirectory()) continue
|
|
87
|
+
commands.push(`/${SKILL_PREFIX}${skill}`)
|
|
88
|
+
for (const f of filesUnder(join(p.from, skill))) {
|
|
89
|
+
source.set(`${SKILL_PREFIX}${skill}/${f}`, readFileSync(join(p.from, skill, f)))
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const lines: SkillLine[] = []
|
|
94
|
+
const writes: string[] = []
|
|
95
|
+
const removals: string[] = []
|
|
96
|
+
for (const [rel, bytes] of source) {
|
|
97
|
+
const abs = join(p.to, rel)
|
|
98
|
+
if (!existsSync(abs)) {
|
|
99
|
+
lines.push({ action: 'created', file: abs })
|
|
100
|
+
writes.push(rel)
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
const onDisk = readFileSync(abs)
|
|
104
|
+
if (onDisk.equals(bytes)) lines.push({ action: 'unchanged', file: abs })
|
|
105
|
+
else if (record?.files[rel] === sha256(onDisk)) {
|
|
106
|
+
lines.push({ action: 'updated', file: abs })
|
|
107
|
+
writes.push(rel)
|
|
108
|
+
} else if (p.force) {
|
|
109
|
+
lines.push({ action: 'overwritten', file: abs })
|
|
110
|
+
writes.push(rel)
|
|
111
|
+
} else lines.push({ action: 'conflict', file: abs })
|
|
112
|
+
}
|
|
113
|
+
for (const [rel, hash] of Object.entries(record?.files ?? {})) {
|
|
114
|
+
const abs = join(p.to, rel)
|
|
115
|
+
if (source.has(rel) || !existsSync(abs)) continue
|
|
116
|
+
if (sha256(readFileSync(abs)) === hash) {
|
|
117
|
+
lines.push({ action: 'removed', file: abs })
|
|
118
|
+
removals.push(rel)
|
|
119
|
+
} else lines.push({ action: 'kept', file: abs })
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (lines.some((l) => l.action === 'conflict')) return { ok: false, lines, commands }
|
|
123
|
+
|
|
124
|
+
for (const rel of writes) {
|
|
125
|
+
const abs = join(p.to, rel)
|
|
126
|
+
mkdirSync(dirname(abs), { recursive: true })
|
|
127
|
+
writeFileSync(abs, source.get(rel) ?? Buffer.alloc(0))
|
|
128
|
+
}
|
|
129
|
+
for (const rel of removals) {
|
|
130
|
+
const abs = join(p.to, rel)
|
|
131
|
+
rmSync(abs)
|
|
132
|
+
// the skill folder goes too once it is empty, so no dead slash command stays listed
|
|
133
|
+
const dir = dirname(abs)
|
|
134
|
+
if (readdirSync(dir).length === 0) rmdirSync(dir)
|
|
135
|
+
}
|
|
136
|
+
const files: Record<string, string> = {}
|
|
137
|
+
for (const [rel, bytes] of source) files[rel] = sha256(bytes)
|
|
138
|
+
mkdirSync(p.to, { recursive: true })
|
|
139
|
+
writeFileSync(recordPath, `${JSON.stringify({ version: p.version, files }, null, 3)}\n`)
|
|
140
|
+
return { ok: true, lines, commands }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const MARK: Record<SkillAction, string> = {
|
|
144
|
+
created: '+',
|
|
145
|
+
unchanged: '=',
|
|
146
|
+
updated: '~',
|
|
147
|
+
overwritten: '!',
|
|
148
|
+
removed: '-',
|
|
149
|
+
kept: '?',
|
|
150
|
+
conflict: '✗',
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function runSkill(
|
|
154
|
+
args: string[],
|
|
155
|
+
p: { cwd?: string; env?: Record<string, string | undefined>; log?: (line: string) => void } = {},
|
|
156
|
+
): number {
|
|
157
|
+
const log = p.log ?? console.log
|
|
158
|
+
const cwd = p.cwd ?? process.cwd()
|
|
159
|
+
const env = p.env ?? process.env
|
|
160
|
+
const sub = args[0]
|
|
161
|
+
const rest = args.slice(1)
|
|
162
|
+
if (sub == null || sub === 'help' || sub === '--help' || rest.includes('--help')) {
|
|
163
|
+
log(SKILL_USAGE)
|
|
164
|
+
return 0
|
|
165
|
+
}
|
|
166
|
+
if (sub !== 'install') throw new Error(`unknown skill command "${sub}"\n${SKILL_USAGE}`)
|
|
167
|
+
|
|
168
|
+
let user = false
|
|
169
|
+
let force = false
|
|
170
|
+
let dir: string | null = null
|
|
171
|
+
for (let i = 0; i < rest.length; i++) {
|
|
172
|
+
const a = rest[i]
|
|
173
|
+
if (a === '--user') user = true
|
|
174
|
+
else if (a === '--force') force = true
|
|
175
|
+
else if (a === '--dir') {
|
|
176
|
+
const v = rest[++i]
|
|
177
|
+
if (v == null || v.startsWith('--')) throw new Error('--dir needs a value')
|
|
178
|
+
dir = v
|
|
179
|
+
} else throw new Error(`unknown argument "${a}"\n${SKILL_USAGE}`)
|
|
180
|
+
}
|
|
181
|
+
if (user && dir != null) throw new Error('--user and --dir name two targets: pass one')
|
|
182
|
+
|
|
183
|
+
const configDir = env.CLAUDE_CONFIG_DIR ?? join(env.HOME ?? homedir(), '.claude')
|
|
184
|
+
const to = dir != null ? resolve(cwd, dir) : user ? join(configDir, 'skills') : join(cwd, '.claude', 'skills')
|
|
185
|
+
const from = skillSourceDir()
|
|
186
|
+
const version = packageVersion(dirname(dirname(from)))
|
|
187
|
+
const show = (abs: string): string => {
|
|
188
|
+
const rel = relative(cwd, abs)
|
|
189
|
+
return rel.startsWith('..') ? abs : rel
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const report = installSkills({ from, to, force, version })
|
|
193
|
+
log(`[comfy-ts skill] comfy-ts ${version} skills → ${show(to)}`)
|
|
194
|
+
for (const l of report.lines) log(` ${MARK[l.action]} ${l.action.padEnd(11)} ${show(l.file)}`)
|
|
195
|
+
if (!report.ok) {
|
|
196
|
+
const n = report.lines.filter((l) => l.action === 'conflict').length
|
|
197
|
+
log(
|
|
198
|
+
`[comfy-ts skill] 🔴 ${n} file(s) changed since comfy-ts wrote them (✗ above): nothing was written. Keep your edits, or rerun with --force to overwrite them`,
|
|
199
|
+
)
|
|
200
|
+
return 1
|
|
201
|
+
}
|
|
202
|
+
const kept = report.lines.filter((l) => l.action === 'kept').length
|
|
203
|
+
if (kept > 0) log(`[comfy-ts skill] ${kept} file(s) no longer shipped were kept because you edited them (? above)`)
|
|
204
|
+
log(`[comfy-ts skill] 🟢 Claude Code commands: ${report.commands.join(' ')}`)
|
|
205
|
+
log(`[comfy-ts skill] a session started before this skills folder existed needs /reload-skills`)
|
|
206
|
+
return 0
|
|
207
|
+
}
|
package/src/exampleAssets.ts
CHANGED
|
@@ -12,6 +12,15 @@ import { dirname, join } from 'pathe'
|
|
|
12
12
|
* package.json all the way up is a broken install and throws.
|
|
13
13
|
*/
|
|
14
14
|
export function bundledExamplesDir(moduleUrl: string = import.meta.url): string | null {
|
|
15
|
+
const pkgDir = comfyTsPackageDir(moduleUrl)
|
|
16
|
+
if (pkgDir == null) return null
|
|
17
|
+
const examples = join(pkgDir, 'examples')
|
|
18
|
+
return existsSync(examples) ? examples : null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** the comfy-ts package root (the folder of its package.json), by the same walk: null when the
|
|
22
|
+
* nearest named package is another one, a throw when no package.json is found at all */
|
|
23
|
+
export function comfyTsPackageDir(moduleUrl: string = import.meta.url): string | null {
|
|
15
24
|
let dir = dirname(fileURLToPath(moduleUrl))
|
|
16
25
|
let prev = ''
|
|
17
26
|
while (dir !== prev) {
|
|
@@ -24,10 +33,7 @@ export function bundledExamplesDir(moduleUrl: string = import.meta.url): string
|
|
|
24
33
|
// a malformed package.json on the walk (someone's broken fixture
|
|
25
34
|
// dir) must not take the whole TUI down; treat as unnamed
|
|
26
35
|
}
|
|
27
|
-
if (pkg.name === 'comfy-ts')
|
|
28
|
-
const examples = join(dir, 'examples')
|
|
29
|
-
return existsSync(examples) ? examples : null
|
|
30
|
-
}
|
|
36
|
+
if (pkg.name === 'comfy-ts') return dir
|
|
31
37
|
if (pkg.name != null) return null
|
|
32
38
|
}
|
|
33
39
|
prev = dir
|
package/src/host/ComfyHost.ts
CHANGED
|
@@ -163,42 +163,12 @@ export class ComfyHost<ID extends string = string> {
|
|
|
163
163
|
this.schema = new ComfySchema({ embeddings: [], spec: {} })
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
/**
|
|
167
|
-
matchRequirements = (requirements: Requirements[]): boolean =>
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const plugins: ComfyManagerPluginInfo[] = repo.plugins_byNodeKey.get(req.nodeName) ?? []
|
|
173
|
-
if (!plugins.find((i) => this.manager.isPluginInstalled(i.title))) {
|
|
174
|
-
// console.log(`[❌ A] ${JSON.stringify(req)} NOT MATCHED`)
|
|
175
|
-
return false
|
|
176
|
-
}
|
|
177
|
-
} else if (req.type === 'customNodesByTitle') {
|
|
178
|
-
const plugin: ComfyManagerPluginInfo | undefined = repo.plugins_byTitle.get(req.title)
|
|
179
|
-
if (plugin == null) continue
|
|
180
|
-
if (!this.manager.isPluginInstalled(plugin.title)) {
|
|
181
|
-
// console.log(`[❌ B] ${JSON.stringify(req)} NOT MATCHED`)
|
|
182
|
-
return false
|
|
183
|
-
}
|
|
184
|
-
} else if (req.type === 'customNodesByURI') {
|
|
185
|
-
const plugin: ComfyManagerPluginInfo | undefined = repo.plugins_byFile.get(req.uri)
|
|
186
|
-
if (plugin == null) continue
|
|
187
|
-
if (!this.manager.isPluginInstalled(plugin.title)) {
|
|
188
|
-
// console.log(`[❌ C] ${JSON.stringify(req)} NOT MATCHED`)
|
|
189
|
-
return false
|
|
190
|
-
}
|
|
191
|
-
} else if (req.type === 'modelInManager') {
|
|
192
|
-
if (!this.manager.isModelInstalled(req.modelName)) {
|
|
193
|
-
// console.log(`[❌ D] ${JSON.stringify(req)} NOT MATCHED`)
|
|
194
|
-
return false
|
|
195
|
-
}
|
|
196
|
-
} else {
|
|
197
|
-
// exhaust(req.type)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return true
|
|
201
|
-
}
|
|
166
|
+
/** false only when a requirement is known missing; an undecided one passes with a warning (manager.matchRequirements) */
|
|
167
|
+
matchRequirements = (requirements: Requirements[]): boolean => this.manager.matchRequirements(requirements)
|
|
168
|
+
|
|
169
|
+
/** `missing` (known not installed, the only ones to queue for install) and `undecided` (the lists cannot say) */
|
|
170
|
+
checkRequirements = (requirements: Requirements[]): { missing: Requirements[]; undecided: Requirements[] } =>
|
|
171
|
+
this.manager.checkRequirements(requirements)
|
|
202
172
|
|
|
203
173
|
// ----- Rotating srever logs -----
|
|
204
174
|
|