comfy-ts 0.2.0 → 0.4.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.
Files changed (161) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +363 -0
  3. package/dist/cli.js +764 -0
  4. package/dist/cli.js.map +1 -0
  5. package/dist/index.cjs +4171 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.cts +9910 -0
  8. package/dist/index.d.ts +9894 -58
  9. package/dist/index.js +4092 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/log-CdfgILde.js +10 -0
  12. package/dist/log-CdfgILde.js.map +1 -0
  13. package/dist/run-tui-SDSJo1Qf.js +3896 -0
  14. package/dist/run-tui-SDSJo1Qf.js.map +1 -0
  15. package/package.json +103 -75
  16. package/src/cli/comfy-ts-cli.ts +36 -0
  17. package/src/cli/gen.ts +47 -0
  18. package/src/cli/outline.ts +82 -0
  19. package/src/cli/tui/components/DraftsOverlay.tsx +44 -0
  20. package/src/cli/tui/components/EditField.tsx +27 -0
  21. package/src/cli/tui/components/Header.tsx +56 -0
  22. package/src/cli/tui/components/HostPanel.tsx +37 -0
  23. package/src/cli/tui/components/LogsPanel.tsx +23 -0
  24. package/src/cli/tui/components/LorasOverlay.tsx +49 -0
  25. package/src/cli/tui/components/OverlayList.tsx +25 -0
  26. package/src/cli/tui/components/PickerOverlays.tsx +66 -0
  27. package/src/cli/tui/components/PreviewPanel.tsx +78 -0
  28. package/src/cli/tui/components/PromptOverlay.tsx +16 -0
  29. package/src/cli/tui/components/StatusBar.tsx +171 -0
  30. package/src/cli/tui/components/TextOverlay.tsx +72 -0
  31. package/src/cli/tui/components/TreePanel.tsx +51 -0
  32. package/src/cli/tui/components/TuiApp.tsx +246 -0
  33. package/src/cli/tui/components/VarsPanel.tsx +86 -0
  34. package/src/cli/tui/findDefinedWorkflow.ts +16 -0
  35. package/src/cli/tui/keys.ts +20 -0
  36. package/src/cli/tui/protocolImagePainter.ts +95 -0
  37. package/src/cli/tui/run-tui.tsx +76 -0
  38. package/src/cli/tui/state/DraftsSt.ts +273 -0
  39. package/src/cli/tui/state/EditorSt.ts +289 -0
  40. package/src/cli/tui/state/ExecSt.ts +173 -0
  41. package/src/cli/tui/state/HostSt.ts +230 -0
  42. package/src/cli/tui/state/LogsSt.ts +107 -0
  43. package/src/cli/tui/state/LorasSt.ts +185 -0
  44. package/src/cli/tui/state/PickerSt.ts +112 -0
  45. package/src/cli/tui/state/PreviewSt.ts +288 -0
  46. package/src/cli/tui/state/QueueSt.ts +59 -0
  47. package/src/cli/tui/state/SettingsSt.ts +100 -0
  48. package/src/cli/tui/state/TreeSt.ts +122 -0
  49. package/src/cli/tui/state/TuiSt.ts +175 -0
  50. package/src/cli/tui/state/WorkflowsSt.ts +93 -0
  51. package/src/cli/tui-env.ts +8 -0
  52. package/src/errors/InvalidPromptError.ts +12 -0
  53. package/src/graph/ComfyNode.ts +403 -0
  54. package/src/graph/ComfyNodeID.ts +28 -0
  55. package/src/graph/ComfyNodeOutput.ts +16 -0
  56. package/src/graph/NodeSlotSize.ts +4 -0
  57. package/src/graph/autoValue.ts +17 -0
  58. package/src/host/ComfyHost.ts +690 -0
  59. package/src/host/ComfyInstallType.ts +15 -0
  60. package/src/host/ComfyManager.ts +232 -0
  61. package/src/host/ComfyUploader.ts +110 -0
  62. package/src/host/ComfyWorkflowBuilder.ts +60 -0
  63. package/src/host/Requirements.ts +55 -0
  64. package/src/host/ResilientWebsocket.ts +147 -0
  65. package/src/host/loraManagerApi.ts +98 -0
  66. package/src/image-utils/_getPngMetadata.ts +53 -0
  67. package/src/image-utils/_getWebpMetadata.ts +38 -0
  68. package/src/image-utils/_parseExifData.ts +53 -0
  69. package/src/index.ts +89 -0
  70. package/src/litegraph/LiteGraphGroup.ts +22 -0
  71. package/src/litegraph/LiteGraphJSON.ts +46 -0
  72. package/src/litegraph/LiteGraphLink.ts +23 -0
  73. package/src/litegraph/LiteGraphLinkID.ts +6 -0
  74. package/src/litegraph/LiteGraphNode.ts +69 -0
  75. package/src/litegraph/LiteGraphNodeInput.ts +27 -0
  76. package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
  77. package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
  78. package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
  79. package/src/manager/ComfyRegistry.ts +124 -0
  80. package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
  81. package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
  82. package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
  83. package/src/manager/generated/KnownModel_Base.ts +126 -0
  84. package/src/manager/generated/KnownModel_FileName.ts +2287 -0
  85. package/src/manager/generated/KnownModel_Name.ts +2287 -0
  86. package/src/manager/generated/KnownModel_SavePath.ts +263 -0
  87. package/src/manager/generated/KnownModel_Type.ts +97 -0
  88. package/src/manager/json/alter-list.json +224 -0
  89. package/src/manager/json/custom-node-list.extra.ts +13 -0
  90. package/src/manager/json/custom-node-list.json +21948 -0
  91. package/src/manager/json/extension-node-map.json +31282 -0
  92. package/src/manager/json/github-stats.json +12602 -0
  93. package/src/manager/json/model-list.extra.ts +26 -0
  94. package/src/manager/json/model-list.json +5052 -0
  95. package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
  96. package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
  97. package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
  98. package/src/manager/loaders/step4_model-list-loader.ts +159 -0
  99. package/src/manager/script-update-manager.bun.ts +18 -0
  100. package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
  101. package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
  102. package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
  103. package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
  104. package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
  105. package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
  106. package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
  107. package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
  108. package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
  109. package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
  110. package/src/runner/ComfyExecution.ts +301 -0
  111. package/src/runner/ComfyExecutionStatus.ts +2 -0
  112. package/src/runner/ComfyWorkflow.ts +395 -0
  113. package/src/runner/ComfyWorkflowLayout.ts +96 -0
  114. package/src/runner/ComfyWsApi.ts +170 -0
  115. package/src/runner/MediaImage.ts +262 -0
  116. package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
  117. package/src/sdk-generator/ComfySchema.ts +369 -0
  118. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
  119. package/src/sdk-generator/Primitives.ts +76 -0
  120. package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
  121. package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
  122. package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
  123. package/src/sdk-generator/comfy-api-json.ts +16 -0
  124. package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
  125. package/src/sdk-generator/comfyui-types.ts +56 -0
  126. package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
  127. package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
  128. package/src/ssh-host-manager/ssh-config.windows.md +32 -0
  129. package/src/ssh-host-manager/ssh-manager.ts +114 -0
  130. package/src/state.ts +136 -0
  131. package/src/types/comfy-sdk.ts +106 -0
  132. package/src/types/index.ts +55 -0
  133. package/src/utils/CodeBuffer.ts +61 -0
  134. package/src/utils/ComfyColors.ts +38 -0
  135. package/src/utils/ansi.ts +33 -0
  136. package/src/utils/ansiImage.ts +36 -0
  137. package/src/utils/bang.ts +39 -0
  138. package/src/utils/deepCopyNaive.ts +1 -0
  139. package/src/utils/downloadFile.ts +77 -0
  140. package/src/utils/escapeJSKey.ts +32 -0
  141. package/src/utils/exhaust.ts +4 -0
  142. package/src/utils/extractErrorMessage.ts +11 -0
  143. package/src/utils/fuzzyMatch.ts +8 -0
  144. package/src/utils/githubRegexes.ts +2 -0
  145. package/src/utils/hashArrayBuffer.ts +6 -0
  146. package/src/utils/log.ts +9 -0
  147. package/src/utils/loraTag.ts +10 -0
  148. package/src/utils/mojibake.ts +60 -0
  149. package/src/utils/printArkResultInConsole.ts +16 -0
  150. package/src/utils/softValidate.ts +8 -0
  151. package/src/utils/stringifyReadable.ts +32 -0
  152. package/src/utils/toposort.ts +59 -0
  153. package/src/utils/tryExtracting.ts +41 -0
  154. package/src/utils/writeFile.ts +16 -0
  155. package/src/vars/ComfyVars.ts +531 -0
  156. package/src/vars/DefinedWorkflow.ts +112 -0
  157. package/src/vars/loraKeywords.ts +56 -0
  158. package/dist/index.d.mts +0 -74
  159. package/dist/index.mjs +0 -3
  160. package/dist/index.mjs.map +0 -1
  161. package/readme.md +0 -40
package/package.json CHANGED
@@ -1,78 +1,106 @@
1
1
  {
2
- "name": "comfy-ts",
3
- "version": "0.2.0",
4
- "description": "Type safe generative AI pipeline cration and execution using ComfyUI",
5
- "keywords": [
6
- "AI",
7
- "modern"
8
- ],
9
- "author": "Rémi Vion <vion.remi@gmail.com>",
10
- "license": "MIT",
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/rvion/comfy-ts.git"
14
- },
15
- "bugs": {
16
- "url": "https://github.com/rvion/comfy-ts/issues"
17
- },
18
- "homepage": "https://rvion.github.io/comfy-ts",
19
- "main": "./dist/index.js",
20
- "module": "./dist/index.mjs",
21
- "types": "./dist/index.d.ts",
22
- "exports": {
23
- ".": {
2
+ "name": "comfy-ts",
3
+ "version": "0.4.0",
4
+ "description": "Type-safe generative AI pipeline creation and execution using ComfyUI",
5
+ "keywords": [
6
+ "comfyui",
7
+ "AI",
8
+ "typescript",
9
+ "codegen",
10
+ "stable-diffusion"
11
+ ],
12
+ "author": "Rémi Vion <vion.remi@gmail.com>",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/rvion/comfy-ts.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/rvion/comfy-ts/issues"
20
+ },
21
+ "homepage": "https://github.com/rvion/comfy-ts",
22
+ "type": "module",
23
+ "main": "./dist/index.cjs",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "bin": {
27
+ "comfy-ts": "./dist/cli.js"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "import": {
24
32
  "types": "./dist/index.d.ts",
25
- "import": "./dist/index.mjs",
26
- "require": "./dist/index.js"
27
- }
28
- },
29
- "files": [
30
- "dist",
31
- "README.md",
32
- "LICENSE"
33
- ],
34
- "scripts": {
35
- "build": "tsup",
36
- "build:watch": "tsup --watch",
37
- "dev": "tsup --watch --onSuccess 'npm run test:watch'",
38
- "test": "vitest run",
39
- "test:watch": "vitest",
40
- "test:coverage": "vitest run --coverage",
41
- "lint": "eslint src --ext .ts,.tsx",
42
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
43
- "format": "prettier --write src/**/*.ts",
44
- "format:check": "prettier --check src/**/*.ts",
45
- "docs": "typedoc",
46
- "docs:serve": "python -m http.server 8080 -d docs",
47
- "api-extract": "api-extractor run --local",
48
- "changeset": "changeset",
49
- "version": "changeset version",
50
- "release": "npm run build && changeset publish",
51
- "prepare": "husky install",
52
- "prepublishOnly": "npm run lint && npm run test && npm run build"
53
- },
54
- "engines": {
55
- "node": ">=18.0.0"
56
- },
57
- "devDependencies": {
58
- "@actions/core": "^1.11.1",
59
- "@actions/github": "^6.0.1",
60
- "@changesets/cli": "^2.29.4",
61
- "@microsoft/api-extractor": "^7.52.8",
62
- "@types/node": "^22.15.21",
63
- "@typescript-eslint/eslint-plugin": "^8.32.1",
64
- "@typescript-eslint/parser": "^8.32.1",
65
- "@vitest/coverage-v8": "^3.1.4",
66
- "conventional-changelog-cli": "^5.0.0",
67
- "eslint": "^9.27.0",
68
- "eslint-config-prettier": "^10.1.5",
69
- "eslint-plugin-prettier": "^5.4.0",
70
- "husky": "^9.1.7",
71
- "prettier": "^3.5.3",
72
- "tsup": "^8.5.0",
73
- "typedoc": "^0.28.5",
74
- "typedoc-plugin-markdown": "^4.6.3",
75
- "typescript": "^5.8.3",
76
- "vitest": "^3.1.4"
77
- }
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ },
40
+ "./src/*": "./src/*"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "src",
45
+ "README.md",
46
+ "LICENSE"
47
+ ],
48
+ "scripts": {
49
+ "build": "tsdown",
50
+ "build:watch": "tsdown --watch",
51
+ "test": "bun test",
52
+ "test:watch": "bun test --watch",
53
+ "typecheck": "tsc --noEmit",
54
+ "typecheck:lib": "tsc -p tsconfig.lib.json",
55
+ "lint": "oxlint src examples scripts tests",
56
+ "format": "oxfmt src examples scripts tests",
57
+ "format:check": "oxfmt --check src examples scripts tests",
58
+ "imports:check": "rvt imports --check",
59
+ "imports:fix": "rvt imports --fix",
60
+ "cycles": "rvt cycles 1",
61
+ "rename": "rvt rename",
62
+ "ci": "bun run typecheck:lib && bun run lint && bun run format:check && bun run imports:check && bun test",
63
+ "ci:local": "bun run ci && bun run typecheck",
64
+ "gen:manager": "bun src/manager/script-update-manager.bun.ts",
65
+ "gen:sdk": "bun scripts/gen-sdk-from-cache.ts",
66
+ "sdk:outline": "bun scripts/sdk-outline.ts",
67
+ "hooks:install": "git config core.hooksPath .githooks",
68
+ "prepublishOnly": "bun run ci && bun run build",
69
+ "tui": "bun src/cli/comfy-ts-cli.ts tui"
70
+ },
71
+ "rvt": {
72
+ "skip": [
73
+ ".rv-private",
74
+ "tmp",
75
+ ".comfy-ts"
76
+ ]
77
+ },
78
+ "engines": {
79
+ "bun": ">=1.1.0",
80
+ "node": ">=20.0.0"
81
+ },
82
+ "dependencies": {
83
+ "arktype": "^2.2.3",
84
+ "image-meta": "^0.2.2",
85
+ "ink": "^7.1.1",
86
+ "mobx": "^6.16.1",
87
+ "mobx-react-lite": "^4.1.1",
88
+ "nanoid": "^6.0.0",
89
+ "pathe": "^2.0.3",
90
+ "react": "^19.2.8",
91
+ "react-dom": "^19.2.8",
92
+ "sharp": "^0.35.3",
93
+ "ws": "^8.21.1"
94
+ },
95
+ "devDependencies": {
96
+ "@types/bun": "^1.3.14",
97
+ "@types/react": "^19.2.17",
98
+ "@types/ws": "^8.18.1",
99
+ "oxfmt": "^0.60.0",
100
+ "oxlint": "^1.75.0",
101
+ "oxlint-tsgolint": "^7.0.2001",
102
+ "rvlib-ts-tools": "^0.2.0",
103
+ "tsdown": "^0.22.14",
104
+ "typescript": "^7.0.2"
105
+ }
78
106
  }
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ // sidekick CLI: `bunx comfy-ts <command>` — codegen without writing any code
3
+ import { runGen } from 'src/cli/gen.ts'
4
+ import { runOutline } from 'src/cli/outline.ts'
5
+
6
+ const HELP = `comfy-ts — typed SDK codegen for ComfyUI
7
+
8
+ Usage:
9
+ comfy-ts gen --id <host-id> [--host http://127.0.0.1:8188]
10
+ fetch object_info + embeddings from a live ComfyUI host and write
11
+ .comfy-ts/hosts/<host-id>/{object_info.json,embeddings.json,sdk.d.ts}
12
+
13
+ comfy-ts outline [file] [--lines N] [--section Name]
14
+ outline a generated sdk.d.ts (defaults to the first one in .comfy-ts/hosts/)
15
+
16
+ comfy-ts tui [dir | workflow-module.ts]
17
+ interactive tweak & re-run over **/*.cflow.ts modules (exporting
18
+ host.defineWorkflow(...)); no arg scans cwd, a file arg preselects it
19
+
20
+ comfy-ts help
21
+ `
22
+
23
+ async function main(): Promise<number> {
24
+ const [cmd, ...rest] = process.argv.slice(2)
25
+ if (cmd === 'gen') return runGen(rest)
26
+ if (cmd === 'outline') return runOutline(rest)
27
+ if (cmd === 'tui') {
28
+ // lazy import: keeps ink/react out of the codegen paths
29
+ const { runTui } = await import('src/cli/tui/run-tui.tsx')
30
+ return runTui(rest)
31
+ }
32
+ console.log(HELP)
33
+ return cmd == null || cmd === 'help' ? 0 : 1
34
+ }
35
+
36
+ process.exitCode = await main()
package/src/cli/gen.ts ADDED
@@ -0,0 +1,47 @@
1
+ // fetch a live host's schema and generate its typed sdk
2
+ import { mkdirSync, writeFileSync } from 'node:fs'
3
+ import { join } from 'pathe'
4
+ import { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'
5
+ import type { ComfySchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'
6
+ import { readableStringify } from 'src/utils/stringifyReadable.ts'
7
+
8
+ export async function runGen(args: string[]): Promise<number> {
9
+ const getFlag = (name: string): string | null => {
10
+ const ix = args.indexOf(`--${name}`)
11
+ return ix >= 0 ? (args[ix + 1] ?? null) : null
12
+ }
13
+ const hostUrl = getFlag('host') ?? 'http://127.0.0.1:8188'
14
+ const id = getFlag('id')
15
+ if (id == null) {
16
+ console.error('[comfy-ts gen] 🔴 --id <host-id> is required (it names .comfy-ts/hosts/<id>/)')
17
+ return 1
18
+ }
19
+
20
+ // prefer /api/* (canonical prefix; custom nodes like lora-manager hijack the bare routes)
21
+ const fetchJSON = async <T>(route: string): Promise<T> => {
22
+ for (const url of [`${hostUrl}/api${route}`, `${hostUrl}${route}`]) {
23
+ console.log(`[comfy-ts gen] fetching ${url} …`)
24
+ const res = await fetch(url)
25
+ if (!res.ok) continue
26
+ if (!(res.headers.get('content-type') ?? '').includes('json')) continue
27
+ return (await res.json()) as T
28
+ }
29
+ throw new Error(`GET ${route} failed on ${hostUrl} (tried /api${route} and ${route})`)
30
+ }
31
+
32
+ const spec = await fetchJSON<ComfySchemaJSON>('/object_info')
33
+ const embeddings = await fetchJSON<string[]>('/embeddings').catch(() => [] as string[])
34
+
35
+ const dir = join(process.cwd(), '.comfy-ts', 'hosts', id)
36
+ mkdirSync(dir, { recursive: true })
37
+ writeFileSync(join(dir, 'object_info.json'), readableStringify(spec, 4), 'utf8')
38
+ writeFileSync(join(dir, 'embeddings.json'), JSON.stringify(embeddings), 'utf8')
39
+
40
+ const parsed = new ComfySchema({ spec, embeddings })
41
+ const dts = parsed.codegenDTS({ hostId: id })
42
+ const outPath = join(dir, 'sdk.d.ts')
43
+ writeFileSync(outPath, dts, 'utf8')
44
+ console.log(`[comfy-ts gen] 🟢 ${outPath} (${parsed.nodes.length} nodes, ${(dts.length / 1024).toFixed(0)}kB)`)
45
+ console.log(`[comfy-ts gen] add ".comfy-ts/hosts/**/sdk.d.ts" to your tsconfig "include" to activate the types`)
46
+ return 0
47
+ }
@@ -0,0 +1,82 @@
1
+ // outline a generated sdk.d.ts without reading 2MB blind
2
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
3
+ import { join } from 'pathe'
4
+
5
+ type Section = { name: string; kind: string; start: number; end: number; depth: number }
6
+
7
+ function findDefaultSdk(): string | null {
8
+ const hostsDir = join(process.cwd(), '.comfy-ts', 'hosts')
9
+ if (!existsSync(hostsDir)) return null
10
+ for (const id of readdirSync(hostsDir)) {
11
+ const p = join(hostsDir, id, 'sdk.d.ts')
12
+ if (existsSync(p)) return p
13
+ }
14
+ return null
15
+ }
16
+
17
+ export function runOutline(args: string[]): number {
18
+ const linesFlagIx = args.indexOf('--lines')
19
+ const maxLines = linesFlagIx >= 0 ? Number(args[linesFlagIx + 1] ?? 10) : null
20
+ const sectionFlagIx = args.indexOf('--section')
21
+ const wantedSection = sectionFlagIx >= 0 ? args[sectionFlagIx + 1] : null
22
+ const flagValueIxs = new Set([linesFlagIx + 1, sectionFlagIx + 1].filter((ix) => ix > 0))
23
+ const fileArg = args.find((a, ix) => !a.startsWith('--') && !flagValueIxs.has(ix))
24
+
25
+ const file = fileArg ?? findDefaultSdk()
26
+ if (file == null || !existsSync(file)) {
27
+ console.error('[sdk-outline] 🔴 no sdk.d.ts found; pass a path explicitly')
28
+ return 1
29
+ }
30
+
31
+ const lines = readFileSync(file, 'utf8').split('\n')
32
+
33
+ // scan: track brace depth, record interface/type/namespace declarations up to depth 3
34
+ const sections: Section[] = []
35
+ const stack: Section[] = []
36
+ let depth = 0
37
+ const declRe = /^\s*(?:export\s+)?(interface|namespace|type)\s+([A-Za-z0-9_$]+)/
38
+ for (let i = 0; i < lines.length; i++) {
39
+ const line = lines[i] ?? ''
40
+ const m = depth <= 3 ? declRe.exec(line) : null
41
+ const opens = (line.match(/{/g) ?? []).length
42
+ const closes = (line.match(/}/g) ?? []).length
43
+ if (m && (opens > 0 || m[1] === 'type')) {
44
+ const sec: Section = { name: m[2] ?? '?', kind: m[1] ?? '?', start: i + 1, end: i + 1, depth }
45
+ sections.push(sec)
46
+ if (opens > closes) stack.push(sec)
47
+ }
48
+ depth += opens - closes
49
+ while (stack.length > 0 && depth <= (stack[stack.length - 1]?.depth ?? 0)) {
50
+ const closed = stack.pop()
51
+ if (closed) closed.end = i + 1
52
+ }
53
+ // type aliases (no braces): extend until next decl at same depth
54
+ const last = sections[sections.length - 1]
55
+ if (last && last.kind === 'type' && stack[stack.length - 1] !== last) last.end = Math.max(last.end, i)
56
+ }
57
+
58
+ if (wantedSection) {
59
+ const sec = sections.find((s) => s.name === wantedSection)
60
+ if (sec == null) {
61
+ console.error(
62
+ `[sdk-outline] 🔴 section "${wantedSection}" not found. Available: ${sections.map((s) => s.name).join(', ')}`,
63
+ )
64
+ return 1
65
+ }
66
+ const body = lines.slice(sec.start - 1, maxLines ? Math.min(sec.end, sec.start - 1 + maxLines) : sec.end)
67
+ console.log(body.join('\n'))
68
+ if (maxLines && sec.end - sec.start + 1 > maxLines)
69
+ console.log(`… (${sec.end - sec.start + 1 - maxLines} more lines, ends at line ${sec.end})`)
70
+ } else {
71
+ console.log(`${file} — ${lines.length} lines\n`)
72
+ for (const s of sections) {
73
+ const indent = ' '.repeat(s.depth)
74
+ console.log(`${indent}${s.kind} ${s.name} [${s.start}-${s.end}] (${s.end - s.start + 1} lines)`)
75
+ if (maxLines) {
76
+ const body = lines.slice(s.start - 1, s.start - 1 + maxLines)
77
+ console.log(body.map((l) => `${indent} │ ${l.trim()}`).join('\n'))
78
+ }
79
+ }
80
+ }
81
+ return 0
82
+ }
@@ -0,0 +1,44 @@
1
+ import { Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { OverlayList } from 'src/cli/tui/components/OverlayList.tsx'
4
+ import { DRAFT_OP_HINTS, KeyHints } from 'src/cli/tui/components/StatusBar.tsx'
5
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
6
+
7
+ /** modal draft picker: row 0 creates a new draft, the rest load existing ones */
8
+ export const DraftsOverlay = observer((p: { st: TuiSt }) => {
9
+ const s = p.st
10
+ const d = s.drafts
11
+ const rows = [
12
+ {
13
+ key: '·new·',
14
+ node: (
15
+ <Text key="·new·" inverse={d.ix === 0}>
16
+ {d.ix === 0 ? '▸ ' : ' '}new draft
17
+ </Text>
18
+ ),
19
+ },
20
+ ...d.list.map((name, ix) => ({
21
+ key: name,
22
+ node: (
23
+ <Text key={name} inverse={ix + 1 === d.ix}>
24
+ {ix + 1 === d.ix ? '▸ ' : ' '}
25
+ {name === d.active ? '● ' : ' '}
26
+ {name}
27
+ </Text>
28
+ ),
29
+ })),
30
+ ]
31
+ return (
32
+ <OverlayList
33
+ title={
34
+ <>
35
+ drafts <Text color="gray">· {s.wf.spec.id ?? 'workflow'}</Text>
36
+ </>
37
+ }
38
+ selectedIx={d.ix}
39
+ lines={s.overlayLines}
40
+ rows={rows}
41
+ footer={<KeyHints hints={DRAFT_OP_HINTS} />}
42
+ />
43
+ )
44
+ })
@@ -0,0 +1,27 @@
1
+ import { Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
+
5
+ const EDIT_WINDOW = 56
6
+
7
+ /** inline single-line editor rendering (numbers, custom prompts) */
8
+ export const EditField = observer((p: { st: TuiSt }) => {
9
+ const ed = p.st.editor
10
+ // code-point slicing (cursor counts code points, see EditorSt.cursor)
11
+ const cs = [...ed.buffer]
12
+ // sliding window so the caret stays visible in long buffers
13
+ const windowStart = Math.max(0, Math.min(ed.cursor - Math.floor(EDIT_WINDOW * 0.7), cs.length - EDIT_WINDOW))
14
+ const before = cs.slice(windowStart, ed.cursor).join('')
15
+ const at = cs[ed.cursor] ?? ' '
16
+ const after = cs.slice(ed.cursor + 1, windowStart + EDIT_WINDOW).join('')
17
+ const color = ed.invalid ? 'red' : 'yellow'
18
+ return (
19
+ <Text color={color}>
20
+ {windowStart > 0 ? '…' : ''}
21
+ {before}
22
+ <Text inverse>{at}</Text>
23
+ {after}
24
+ {windowStart + EDIT_WINDOW < cs.length ? '…' : ''}
25
+ </Text>
26
+ )
27
+ })
@@ -0,0 +1,56 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { ReactNode } from 'react'
4
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
5
+
6
+ const HeaderBox = (p: { title?: string; children: ReactNode }): ReactNode => (
7
+ <Box borderStyle="round" borderColor="gray" paddingX={1} flexDirection="column" flexShrink={0}>
8
+ {p.title != null && (
9
+ // marginTop -1 lifts the label onto the border line: the box key IS its title
10
+ <Box marginTop={-1}>
11
+ <Text color="gray">{p.title}</Text>
12
+ </Box>
13
+ )}
14
+ <Box>{p.children}</Box>
15
+ </Box>
16
+ )
17
+
18
+ /** labeled header boxes: brand · (w)orkflow · (d)raft · (h)ost — the keys open each surface */
19
+ export const Header = observer((p: { st: TuiSt }) => {
20
+ const s = p.st
21
+ return (
22
+ <Box flexDirection="row">
23
+ <HeaderBox>
24
+ <Text bold color="magenta">
25
+ comfy-ts
26
+ </Text>
27
+ </HeaderBox>
28
+ <HeaderBox title="(w)orkflow">
29
+ <Text bold color="yellow">
30
+ {s.wf.spec.id ?? 'workflow'}
31
+ </Text>
32
+ </HeaderBox>
33
+ <HeaderBox title="(d)raft">
34
+ <Text bold color="cyan">
35
+ {s.drafts.active ?? 'default'}
36
+ </Text>
37
+ </HeaderBox>
38
+ <HeaderBox title="(h)ost">
39
+ <Text>
40
+ <Text color={s.host.status === 'up' ? 'green' : s.host.status === 'down' ? 'red' : 'gray'}>● </Text>
41
+ <Text bold color="green">
42
+ {s.wf.host.data.id}
43
+ </Text>
44
+ <Text color="gray">
45
+ {' '}
46
+ ({s.wf.host.data.host}:{s.wf.host.data.port})
47
+ </Text>
48
+ {/* while down, show the probe loop living: spinner in flight, countdown between tries */}
49
+ {s.host.status === 'down' && (
50
+ <Text color="red"> {s.host.probing ? s.host.spinner : `↻ ${s.host.retryInS}s`}</Text>
51
+ )}
52
+ </Text>
53
+ </HeaderBox>
54
+ </Box>
55
+ )
56
+ })
@@ -0,0 +1,37 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
+
5
+ /** host stats + maintenance actions (mode 'host', key `h`) */
6
+ export const HostPanel = observer((p: { st: TuiSt }) => {
7
+ const s = p.st
8
+ const h = s.host
9
+ return (
10
+ <Box borderStyle="double" paddingX={1} flexDirection="column">
11
+ <Text bold>
12
+ host · <Text color="green">{h.host.data.id}</Text>{' '}
13
+ <Text color="gray">
14
+ ({h.host.data.host}:{h.host.data.port})
15
+ </Text>
16
+ </Text>
17
+ {h.stats.map((row) => (
18
+ <Text key={row.label}>
19
+ <Text color="gray">{row.label.padEnd(12)}</Text>
20
+ {row.value}
21
+ </Text>
22
+ ))}
23
+ <Text> </Text>
24
+ {h.actions.map((action, ix) => {
25
+ const sel = ix === h.ix
26
+ const busy = h.running === action.key
27
+ return (
28
+ <Text key={action.key} inverse={sel} color={busy ? 'yellow' : undefined}>
29
+ {sel ? '▸ ' : ' '}
30
+ {action.label}
31
+ {busy ? ' …' : ''}
32
+ </Text>
33
+ )
34
+ })}
35
+ </Box>
36
+ )
37
+ })
@@ -0,0 +1,23 @@
1
+ import { Box, Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
4
+
5
+ const ERROR_RE = /error|exception|traceback|failed/i
6
+
7
+ /** last server console lines (LogsSt), below the vars panel */
8
+ export const LogsPanel = observer((p: { st: TuiSt }) => {
9
+ const rows = p.st.logs.tail(p.st.termRows < 30 ? 4 : 8)
10
+ if (rows.length === 0) return null
11
+ return (
12
+ <Box borderStyle="round" borderColor="gray" paddingX={1} flexDirection="column" flexShrink={0}>
13
+ <Box marginTop={-1}>
14
+ <Text color="gray">comfy host logs</Text>
15
+ </Box>
16
+ {rows.map((line, ix) => (
17
+ <Text key={ix} color={ERROR_RE.test(line) ? 'red' : 'gray'} wrap="truncate-end">
18
+ {line}
19
+ </Text>
20
+ ))}
21
+ </Box>
22
+ )
23
+ })
@@ -0,0 +1,49 @@
1
+ import { Text } from 'ink'
2
+ import { observer } from 'mobx-react-lite'
3
+ import { basename } from 'pathe'
4
+ import { OverlayList } from 'src/cli/tui/components/OverlayList.tsx'
5
+ import { getLoraKeyword } from 'src/vars/loraKeywords.ts'
6
+ import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
7
+
8
+ /** modal multi-select: tick/untick loras, filter, bulk ops, step strengths */
9
+ export const LorasOverlay = observer((p: { st: TuiSt }) => {
10
+ const s = p.st
11
+ const lo = s.loras
12
+ const lv = lo.selectedVar
13
+ if (lv == null) return null
14
+ const names = lo.filteredNames
15
+ return (
16
+ <OverlayList
17
+ title={
18
+ <>
19
+ {s.selected?.[1].label ?? s.selected?.[0]} <Text color="gray">{lv.display()}</Text>
20
+ </>
21
+ }
22
+ extraHeader={<Text color="yellow">filter: {lo.filter}▌</Text>}
23
+ selectedIx={lo.ix}
24
+ lines={s.overlayLines}
25
+ rows={names.map((name, ix) => {
26
+ const on = lv.isOn(name)
27
+ const keyword = getLoraKeyword(name)
28
+ return {
29
+ key: name,
30
+ node: (
31
+ // checked = whole row green with a bold checkmark (emoji checkboxes read identical at cell size)
32
+ <Text key={name} inverse={ix === lo.ix} bold={on} color={on ? 'green' : 'gray'}>
33
+ {ix === lo.ix ? '▸ ' : ' '}
34
+ {on ? '✔' : '·'} {basename(name.replaceAll('\\', '/'))}
35
+ {on ? ` ${lv.strengthLabel(name)}` : ''}
36
+ {keyword !== '' && (
37
+ <Text color="gray" dimColor bold={false}>
38
+ {' kw: '}
39
+ {keyword}
40
+ </Text>
41
+ )}
42
+ </Text>
43
+ ),
44
+ }
45
+ })}
46
+ footer={names.length === 0 ? <Text color="red">no match</Text> : undefined}
47
+ />
48
+ )
49
+ })
@@ -0,0 +1,25 @@
1
+ import { Box, Text } from 'ink'
2
+ import type { ReactNode } from 'react'
3
+
4
+ /** generic modal list: title + rows windowed around the selected index */
5
+ export const OverlayList = (p: {
6
+ title: ReactNode
7
+ rows: { key: string; node: ReactNode }[]
8
+ selectedIx: number
9
+ lines: number
10
+ extraHeader?: ReactNode
11
+ footer?: ReactNode
12
+ }): ReactNode => {
13
+ const winStart = Math.max(0, Math.min(p.selectedIx - Math.floor(p.lines / 2), p.rows.length - p.lines))
14
+ const visible = p.rows.slice(winStart, winStart + p.lines)
15
+ return (
16
+ <Box borderStyle="double" paddingX={1} flexDirection="column">
17
+ <Text bold>{p.title}</Text>
18
+ {p.extraHeader}
19
+ {winStart > 0 && <Text color="gray">…</Text>}
20
+ {visible.map((r) => r.node)}
21
+ {winStart + p.lines < p.rows.length && <Text color="gray">…</Text>}
22
+ {p.footer}
23
+ </Box>
24
+ )
25
+ }