comfy-ts 2.18.1 → 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/dist/web.d.ts CHANGED
@@ -12262,16 +12262,9 @@ declare const types$1: import("arktype").Module<{
12262
12262
  };
12263
12263
  PromptID: PromptID;
12264
12264
  PromptRelated_WsMsg: {
12265
- type: "progress";
12266
- data: {
12267
- value: number;
12268
- max: number;
12269
- };
12270
- } | {
12271
- type: "executing";
12265
+ type: "execution_start";
12272
12266
  data: {
12273
12267
  prompt_id: PromptID;
12274
- node?: ComfyNodeId | null | undefined;
12275
12268
  };
12276
12269
  } | {
12277
12270
  type: "execution_cached";
@@ -12280,9 +12273,16 @@ declare const types$1: import("arktype").Module<{
12280
12273
  prompt_id: PromptID;
12281
12274
  };
12282
12275
  } | {
12283
- type: "execution_start";
12276
+ type: "executing";
12284
12277
  data: {
12285
12278
  prompt_id: PromptID;
12279
+ node?: ComfyNodeId | null | undefined;
12280
+ };
12281
+ } | {
12282
+ type: "progress";
12283
+ data: {
12284
+ value: number;
12285
+ max: number;
12286
12286
  };
12287
12287
  } | {
12288
12288
  type: "progress_state";
@@ -12361,16 +12361,9 @@ declare const types$1: import("arktype").Module<{
12361
12361
  data: string;
12362
12362
  };
12363
12363
  WsMsg: {
12364
- type: "progress";
12365
- data: {
12366
- value: number;
12367
- max: number;
12368
- };
12369
- } | {
12370
- type: "executing";
12364
+ type: "execution_start";
12371
12365
  data: {
12372
12366
  prompt_id: PromptID;
12373
- node?: ComfyNodeId | null | undefined;
12374
12367
  };
12375
12368
  } | {
12376
12369
  type: "execution_cached";
@@ -12379,9 +12372,16 @@ declare const types$1: import("arktype").Module<{
12379
12372
  prompt_id: PromptID;
12380
12373
  };
12381
12374
  } | {
12382
- type: "execution_start";
12375
+ type: "executing";
12383
12376
  data: {
12384
12377
  prompt_id: PromptID;
12378
+ node?: ComfyNodeId | null | undefined;
12379
+ };
12380
+ } | {
12381
+ type: "progress";
12382
+ data: {
12383
+ value: number;
12384
+ max: number;
12385
12385
  };
12386
12386
  } | {
12387
12387
  type: "progress_state";
package/dist/web.js CHANGED
@@ -101,7 +101,7 @@ function getComfyStorage() {
101
101
  }
102
102
  //#endregion
103
103
  //#region package.json
104
- var version = "2.18.1";
104
+ var version = "2.19.0";
105
105
  //#endregion
106
106
  //#region src/litegraph/LiteGraphLinkID.ts
107
107
  const asLiteGraphLinkID = (id) => id;
@@ -1,24 +1,30 @@
1
1
  # comfy-ts examples
2
2
 
3
- Every `*.cflow.ts` file here is a runnable workflow module: run it directly with bun, or browse them all in the TUI (`bunx comfy-ts tui` lists them under "comfy-ts examples", tweak vars, ⌃R to run).
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` — the didactic sequence against a LOCAL ComfyUI host (edit the `comfy.host({...})` line to point at yours, then 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/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.
13
- - `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`.
14
- - `comfy-cloud/<family>-<mode>.cflow.ts` — the model zoo: one clean example per model family × mode (`t2i`, `i2i`, `t2v`, `i2v`, `t2a`), each mirroring an official ComfyUI template (flux, qwen-image, z-image, wan, hidream, ace-step, …). All share `comfy-cloud/cloudHost.ts`.
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 — only `run()` needs the key:
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 — start with a small t2i.
30
+ Cloud runs bill compute to your account. Start with a small t2i.
@@ -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. Types sharpen once a generated sdk.d.ts is in scope.
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.18.1",
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 50+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
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": {
@@ -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
@@ -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
+ }
@@ -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
@@ -1,38 +0,0 @@
1
- import { fileURLToPath } from "node:url";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import { dirname, join } from "pathe";
4
- //#region src/exampleAssets.ts
5
- /**
6
- * the examples/ folder shipped in the npm tarball, resolved from THIS module's
7
- * own location (NEVER cwd): walking up to the nearest NAMED package.json finds
8
- * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from
9
- * this repo's src/. Returns null when the examples are absent (a consumer may
10
- * prune the folder) or when the nearest named package is not comfy-ts (the lib
11
- * was inlined into someone else's bundle — its examples are not on disk); no
12
- * package.json all the way up is a broken install and throws.
13
- */
14
- function bundledExamplesDir(moduleUrl = import.meta.url) {
15
- let dir = dirname(fileURLToPath(moduleUrl));
16
- let prev = "";
17
- while (dir !== prev) {
18
- const pkgPath = join(dir, "package.json");
19
- if (existsSync(pkgPath)) {
20
- let pkg = {};
21
- try {
22
- pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
23
- } catch {}
24
- if (pkg.name === "comfy-ts") {
25
- const examples = join(dir, "examples");
26
- return existsSync(examples) ? examples : null;
27
- }
28
- if (pkg.name != null) return null;
29
- }
30
- prev = dir;
31
- dir = dirname(dir);
32
- }
33
- throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`);
34
- }
35
- //#endregion
36
- export { bundledExamplesDir as t };
37
-
38
- //# sourceMappingURL=exampleAssets-BfWzygoM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exampleAssets-BfWzygoM.js","names":[],"sources":["../src/exampleAssets.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { dirname, join } from 'pathe'\n\n/**\n * the examples/ folder shipped in the npm tarball, resolved from THIS module's\n * own location (NEVER cwd): walking up to the nearest NAMED package.json finds\n * <pkg>/examples both from a consumer's node_modules/comfy-ts/dist/ and from\n * this repo's src/. Returns null when the examples are absent (a consumer may\n * prune the folder) or when the nearest named package is not comfy-ts (the lib\n * was inlined into someone else's bundle — its examples are not on disk); no\n * package.json all the way up is a broken install and throws.\n */\nexport function bundledExamplesDir(moduleUrl: string = import.meta.url): string | null {\n let dir = dirname(fileURLToPath(moduleUrl))\n let prev = ''\n while (dir !== prev) {\n const pkgPath = join(dir, 'package.json')\n if (existsSync(pkgPath)) {\n let pkg: { name?: string } = {}\n try {\n pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))\n } catch {\n // a malformed package.json on the walk (someone's broken fixture\n // dir) must not take the whole TUI down; treat as unnamed\n }\n if (pkg.name === 'comfy-ts') {\n const examples = join(dir, 'examples')\n return existsSync(examples) ? examples : null\n }\n if (pkg.name != null) return null\n }\n prev = dir\n dir = dirname(dir)\n }\n throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`)\n}\n\n/**\n * absolute path of a bundled `examples/images/` input image, e.g.\n * `exampleImagePath('bear_1024x1024.jpg')` — the out-of-the-box default for\n * i2i/i2v example image vars, valid from this repo AND from a consumer's\n * node_modules/comfy-ts/. Loud throw naming the path when the file is missing\n * or the package's examples/ folder was pruned.\n */\nexport function exampleImagePath(name: string): string {\n return bundledExampleFile('images', name)\n}\n\n/** the same for a bundled `examples/media/` audio or video file, e.g.\n * `exampleMediaPath('sine_440hz_3s.flac')` — the default of audio and video example vars */\nexport function exampleMediaPath(name: string): string {\n return bundledExampleFile('media', name)\n}\n\nfunction bundledExampleFile(folder: 'images' | 'media', name: string): string {\n const examples = bundledExamplesDir()\n if (examples == null) {\n throw new Error(\n `[comfy-ts] cannot resolve bundled example file '${name}': the package's examples/ folder is not on disk`,\n )\n }\n const abs = join(examples, folder, name)\n if (!existsSync(abs)) throw new Error(`[comfy-ts] bundled example file not found: ${abs}`)\n return abs\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,mBAAmB,YAAoB,OAAO,KAAK,KAAoB;CACpF,IAAI,MAAM,QAAQ,cAAc,SAAS,CAAC;CAC1C,IAAI,OAAO;CACX,OAAO,QAAQ,MAAM;EAClB,MAAM,UAAU,KAAK,KAAK,cAAc;EACxC,IAAI,WAAW,OAAO,GAAG;GACtB,IAAI,MAAyB,CAAC;GAC9B,IAAI;IACD,MAAM,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC;GACjD,QAAQ,CAGR;GACA,IAAI,IAAI,SAAS,YAAY;IAC1B,MAAM,WAAW,KAAK,KAAK,UAAU;IACrC,OAAO,WAAW,QAAQ,IAAI,WAAW;GAC5C;GACA,IAAI,IAAI,QAAQ,MAAM,OAAO;EAChC;EACA,OAAO;EACP,MAAM,QAAQ,GAAG;CACpB;CACA,MAAM,IAAI,MAAM,oDAAoD,cAAc,SAAS,GAAG;AACjG"}