@nodetool-ai/cli-sketch 0.0.0-stage → 0.8.9-beta.1
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 +12 -2
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/commands/sketch-render.d.ts +46 -0
- package/dist/commands/sketch-render.d.ts.map +1 -0
- package/dist/commands/sketch-render.js +131 -0
- package/dist/commands/sketch-render.js.map +1 -0
- package/dist/commands/sketch-validation-output.d.ts +7 -0
- package/dist/commands/sketch-validation-output.d.ts.map +1 -0
- package/dist/commands/sketch-validation-output.js +5 -0
- package/dist/commands/sketch-validation-output.js.map +1 -0
- package/dist/commands/sketch-versions.d.ts +66 -0
- package/dist/commands/sketch-versions.d.ts.map +1 -0
- package/dist/commands/sketch-versions.js +108 -0
- package/dist/commands/sketch-versions.js.map +1 -0
- package/dist/commands/sketch.d.ts +22 -0
- package/dist/commands/sketch.d.ts.map +1 -0
- package/dist/commands/sketch.js +101 -0
- package/dist/commands/sketch.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/nodetool.d.ts +3 -0
- package/dist/nodetool.d.ts.map +1 -0
- package/dist/nodetool.js +4 -0
- package/dist/nodetool.js.map +1 -0
- package/dist/sketch-debug/harness.d.ts +101 -0
- package/dist/sketch-debug/harness.d.ts.map +1 -0
- package/dist/sketch-debug/harness.js +118 -0
- package/dist/sketch-debug/harness.js.map +1 -0
- package/dist/sketch-debug/index.d.ts +9 -0
- package/dist/sketch-debug/index.d.ts.map +1 -0
- package/dist/sketch-debug/index.js +9 -0
- package/dist/sketch-debug/index.js.map +1 -0
- package/dist/sketch-debug/interactions.d.ts +19 -0
- package/dist/sketch-debug/interactions.d.ts.map +1 -0
- package/dist/sketch-debug/interactions.js +17 -0
- package/dist/sketch-debug/interactions.js.map +1 -0
- package/dist/sketch-debug/target.d.ts +48 -0
- package/dist/sketch-debug/target.d.ts.map +1 -0
- package/dist/sketch-debug/target.js +115 -0
- package/dist/sketch-debug/target.js.map +1 -0
- package/package.json +61 -4
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sketch commands
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sketch authoring, rendering and version commands.
|
|
4
|
+
|
|
5
|
+
Install this independent command feature through the default CLI:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
nodetool packs add cli-sketch --yes
|
|
9
|
+
nodetool sketch --help
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Commands do not install missing features automatically. See the
|
|
13
|
+
[command reference](../../docs/cli.md#install-command-features).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-10-31T09:11:52.589Z
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { ImageDocumentRecord } from "../sketch-debug/target.js";
|
|
3
|
+
export interface SketchRenderCliOptions {
|
|
4
|
+
out?: string;
|
|
5
|
+
format?: string;
|
|
6
|
+
width?: string;
|
|
7
|
+
height?: string;
|
|
8
|
+
background?: string;
|
|
9
|
+
layer?: string;
|
|
10
|
+
mask?: boolean;
|
|
11
|
+
json?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** A positive integer flag, or undefined when it was not given. */
|
|
14
|
+
export declare function parseDimension(name: string, value: string | undefined): number | undefined;
|
|
15
|
+
/** `<name>.png` or `<name>.psd` beside the working directory. */
|
|
16
|
+
export declare function defaultOutputPath(ref: string, format: "png" | "psd", label: string | undefined): string;
|
|
17
|
+
/** What `sketch render` wrote, as `--json` prints it. */
|
|
18
|
+
export interface SketchRenderReport {
|
|
19
|
+
target: {
|
|
20
|
+
kind: "file" | "id";
|
|
21
|
+
ref: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
};
|
|
24
|
+
out: string;
|
|
25
|
+
format: "png" | "psd";
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
canvas_width: number;
|
|
29
|
+
canvas_height: number;
|
|
30
|
+
bytes: number;
|
|
31
|
+
layer_id?: string;
|
|
32
|
+
layers: Array<{
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
type: string;
|
|
36
|
+
drawn: boolean;
|
|
37
|
+
issue?: string;
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
40
|
+
/** Resolve the target, render it, and write the output file. */
|
|
41
|
+
export declare function runSketchRender(ref: string, opts: SketchRenderCliOptions, deps: {
|
|
42
|
+
loadDocument: (id: string) => Promise<ImageDocumentRecord | null>;
|
|
43
|
+
loadImageBytes?: (uri: string) => Promise<Uint8Array>;
|
|
44
|
+
}): Promise<SketchRenderReport>;
|
|
45
|
+
export declare function registerSketchRenderCommand(sketch: Command, loadDocument: () => Promise<(id: string) => Promise<ImageDocumentRecord | null>>): void;
|
|
46
|
+
//# sourceMappingURL=sketch-render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-render.d.ts","sourceRoot":"","sources":["../../src/commands/sketch-render.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGrE,MAAM,WAAW,sBAAsB;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAA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E,MAAM,OAAO,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC,GAC/E,IAAI,CAoCN"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `nodetool sketch render` — render a sketch to a PNG or a layered PSD with
|
|
3
|
+
* the editor's compositing rules, from an image-document JSON file or an
|
|
4
|
+
* `image_documents` row id.
|
|
5
|
+
*
|
|
6
|
+
* The renderer is `@nodetool-ai/agents/sketch-render`, the one behind the
|
|
7
|
+
* `render_sketch` capability. Layer images stored as `asset://` resolve
|
|
8
|
+
* through the local asset store, which opens only when a layer needs it.
|
|
9
|
+
*/
|
|
10
|
+
import { writeFileSync } from "node:fs";
|
|
11
|
+
import { printCommandError } from "@nodetool-ai/pack-manager/command-errors";
|
|
12
|
+
import { trimHyphens } from "@nodetool-ai/cli-common/trimHyphens";
|
|
13
|
+
/** A positive integer flag, or undefined when it was not given. */
|
|
14
|
+
export function parseDimension(name, value) {
|
|
15
|
+
if (value === undefined) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const parsed = Number(value);
|
|
19
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
20
|
+
throw new Error(`--${name} must be a positive whole number of pixels, not "${value}".`);
|
|
21
|
+
}
|
|
22
|
+
return parsed;
|
|
23
|
+
}
|
|
24
|
+
/** `<name>.png` or `<name>.psd` beside the working directory. */
|
|
25
|
+
export function defaultOutputPath(ref, format, label) {
|
|
26
|
+
const base = trimHyphens((label ?? ref.replace(/\.json$/i, "").split(/[\\/]/).pop() ?? "sketch")
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.replace(/[^a-z0-9]+/g, "-"));
|
|
29
|
+
return `${base || "sketch"}.${format}`;
|
|
30
|
+
}
|
|
31
|
+
/** Bytes for an `asset://` or http(s) layer image, via a local processing context. */
|
|
32
|
+
async function localImageLoader() {
|
|
33
|
+
let context;
|
|
34
|
+
const open = async () => {
|
|
35
|
+
const { initDb } = await import("@nodetool-ai/models");
|
|
36
|
+
const { getDefaultAssetsPath, getDefaultDbPath } = await import("@nodetool-ai/config");
|
|
37
|
+
const { ProcessingContext } = await import("@nodetool-ai/runtime");
|
|
38
|
+
const { FileStorageAdapter } = await import("@nodetool-ai/storage");
|
|
39
|
+
initDb(getDefaultDbPath());
|
|
40
|
+
return new ProcessingContext({
|
|
41
|
+
jobId: `sketch-render-${Date.now()}`,
|
|
42
|
+
workflowId: null,
|
|
43
|
+
userId: "1",
|
|
44
|
+
storage: new FileStorageAdapter(getDefaultAssetsPath())
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
return async (uri) => {
|
|
48
|
+
const { loadMediaRefBytes } = await import("@nodetool-ai/runtime");
|
|
49
|
+
context ??= open();
|
|
50
|
+
const bytes = await loadMediaRefBytes({ type: "image", uri }, await context, {
|
|
51
|
+
allowLocalFile: false
|
|
52
|
+
});
|
|
53
|
+
if (!bytes || bytes.length === 0) {
|
|
54
|
+
throw new Error(`${uri} could not be read`);
|
|
55
|
+
}
|
|
56
|
+
return bytes;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Resolve the target, render it, and write the output file. */
|
|
60
|
+
export async function runSketchRender(ref, opts, deps) {
|
|
61
|
+
const format = opts.format ?? "png";
|
|
62
|
+
if (format !== "png" && format !== "psd") {
|
|
63
|
+
throw new Error(`--format must be png or psd, not "${format}".`);
|
|
64
|
+
}
|
|
65
|
+
const { resolveSketchTarget } = await import("../sketch-debug/target.js");
|
|
66
|
+
const { renderSketch } = await import("@nodetool-ai/agents/sketch-render");
|
|
67
|
+
const resolved = await resolveSketchTarget(ref, { loadDocument: deps.loadDocument });
|
|
68
|
+
const options = {
|
|
69
|
+
format,
|
|
70
|
+
width: parseDimension("width", opts.width),
|
|
71
|
+
height: parseDimension("height", opts.height),
|
|
72
|
+
background: opts.background,
|
|
73
|
+
layerId: opts.layer,
|
|
74
|
+
mask: opts.mask === true,
|
|
75
|
+
loadImageBytes: deps.loadImageBytes
|
|
76
|
+
};
|
|
77
|
+
const result = await renderSketch(resolved.raw, options);
|
|
78
|
+
const out = opts.out ?? defaultOutputPath(ref, format, resolved.target.name);
|
|
79
|
+
writeFileSync(out, result.bytes);
|
|
80
|
+
const report = {
|
|
81
|
+
target: resolved.target,
|
|
82
|
+
out,
|
|
83
|
+
format: result.format,
|
|
84
|
+
width: result.width,
|
|
85
|
+
height: result.height,
|
|
86
|
+
canvas_width: result.canvasWidth,
|
|
87
|
+
canvas_height: result.canvasHeight,
|
|
88
|
+
bytes: result.bytes.length,
|
|
89
|
+
layers: result.layers
|
|
90
|
+
};
|
|
91
|
+
if (result.layerId) {
|
|
92
|
+
report.layer_id = result.layerId;
|
|
93
|
+
}
|
|
94
|
+
return report;
|
|
95
|
+
}
|
|
96
|
+
export function registerSketchRenderCommand(sketch, loadDocument) {
|
|
97
|
+
sketch
|
|
98
|
+
.command("render <sketch_id_or_file>")
|
|
99
|
+
.description("Render a sketch to a PNG, or a layered PSD, with the editor's compositing rules: visibility and groups, opacity, blend modes, transforms, effects, vector layers and placed images. Takes an image-document JSON file or an image_documents row id")
|
|
100
|
+
.option("-o, --out <file>", "Output file (default: <sketch name>.png or .psd in the working directory)")
|
|
101
|
+
.option("--format <format>", "png or psd", "png")
|
|
102
|
+
.option("--width <px>", "Output width. Alone, the height keeps the canvas aspect ratio. PNG only")
|
|
103
|
+
.option("--height <px>", "Output height. Alone, the width keeps the canvas aspect ratio. PNG only")
|
|
104
|
+
.option("--background <color>", "CSS color under the image (default: transparent). PNG only")
|
|
105
|
+
.option("--layer <layer_id>", "Render one layer alone, without its opacity or blend mode. PNG only")
|
|
106
|
+
.option("--mask", "Render the inpainting mask layer. PNG only")
|
|
107
|
+
.option("--json", "Print the render report as JSON")
|
|
108
|
+
.action(async (ref, opts) => {
|
|
109
|
+
try {
|
|
110
|
+
const report = await runSketchRender(ref, opts, {
|
|
111
|
+
loadDocument: await loadDocument(),
|
|
112
|
+
loadImageBytes: await localImageLoader()
|
|
113
|
+
});
|
|
114
|
+
const issues = report.layers.filter((layer) => layer.issue);
|
|
115
|
+
if (opts.json) {
|
|
116
|
+
console.log(JSON.stringify(report, null, 2));
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log(`Wrote ${report.out} (${report.width}x${report.height} ${report.format.toUpperCase()}, ${report.bytes} bytes)`);
|
|
120
|
+
for (const layer of issues) {
|
|
121
|
+
console.log(` ${layer.name || layer.id}: ${layer.issue}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
process.exit(issues.some((layer) => !layer.drawn) ? 1 : 0);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
process.exit(printCommandError(e, opts.json));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=sketch-render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-render.js","sourceRoot":"","sources":["../../src/commands/sketch-render.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAalE,mEAAmE;AACnE,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,KAAyB;IACpE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,KAAK,IAAI,oDAAoD,KAAK,IAAI,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,MAAM,C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ACX,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Human-readable rendering of a `SketchValidation`, shared by
|
|
3
|
+
* `sketch validate` and `sketch versions restore`.
|
|
4
|
+
*/
|
|
5
|
+
import type { SketchValidation } from "@nodetool-ai/execution/sketch-debug";
|
|
6
|
+
export declare function renderSketchValidation(validation: SketchValidation): string[];
|
|
7
|
+
//# sourceMappingURL=sketch-validation-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-validation-output.d.ts","sourceRoot":"","sources":["../../src/commands/sketch-validation-output.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,qCAAqC,CAAC;AAG7C,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,gBAAgB,GAAG,MAAM,EAAE,CAI7E"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { issueLocation, renderValidation } from "@nodetool-ai/cli-common/commands/validation-output";
|
|
2
|
+
export function renderSketchValidation(validation) {
|
|
3
|
+
return renderValidation(validation, (issue) => issue.layerId != null ? ` [layer ${issue.layerId}]` : issueLocation(issue));
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=sketch-validation-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-validation-output.js","sourceRoot":"","sources":["../../src/commands/sketch-validation-output.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AAErG,MAAM,UAAU,sBAAsB,CAAC,UAA4B;IACjE,OAAO,gBAAgB,CAAC,UAAU,EAAE,CAAC,KAAuB,EAAE,EAAE,CAC9D,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,WAAW,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAC3E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `nodetool sketch versions` — the version-history half of the sketch
|
|
3
|
+
* commands. The commands themselves live in `version-commands.ts`; this file
|
|
4
|
+
* is the image document's row shapes, database seam, columns and messages.
|
|
5
|
+
*
|
|
6
|
+
* Image documents keep immutable snapshots: manual saves, autosaves the server
|
|
7
|
+
* writes at most every five minutes, and the pre-restore snapshot that makes a
|
|
8
|
+
* restore undoable. The history is read and written directly against the local
|
|
9
|
+
* database, so an agent can work without a server.
|
|
10
|
+
*/
|
|
11
|
+
import type { Command } from "commander";
|
|
12
|
+
import type { SketchValidation } from "@nodetool-ai/execution/sketch-debug";
|
|
13
|
+
import { type JsonValue, type VersionCommandDeps, type VersionStore } from "@nodetool-ai/cli-common/commands/version-commands";
|
|
14
|
+
export { parseVersionDocument, parseVersionNumber } from "@nodetool-ai/cli-common/commands/version-commands";
|
|
15
|
+
/** An `image_documents` row as these commands need it. */
|
|
16
|
+
export interface ImageDocumentRow {
|
|
17
|
+
id: string;
|
|
18
|
+
user_id: string;
|
|
19
|
+
name?: string | null;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
background_color: string;
|
|
23
|
+
updated_at: string;
|
|
24
|
+
document: string;
|
|
25
|
+
}
|
|
26
|
+
/** An `image_document_versions` row. */
|
|
27
|
+
export interface SketchVersionRow {
|
|
28
|
+
id: string;
|
|
29
|
+
image_document_id: string;
|
|
30
|
+
version: number;
|
|
31
|
+
name: string | null;
|
|
32
|
+
save_type: string;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
background_color: string;
|
|
36
|
+
created_at: string;
|
|
37
|
+
document: string;
|
|
38
|
+
}
|
|
39
|
+
export type SketchVersionStore = VersionStore<ImageDocumentRow, SketchVersionRow>;
|
|
40
|
+
/** The list-item shape, matching the tRPC router's `sketchVersionListItem`. */
|
|
41
|
+
export interface SketchVersionListItem {
|
|
42
|
+
id: string;
|
|
43
|
+
version: number;
|
|
44
|
+
name: string | null;
|
|
45
|
+
saveType: string;
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
backgroundColor: string;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
}
|
|
51
|
+
export declare function toVersionListItem(row: SketchVersionRow): SketchVersionListItem;
|
|
52
|
+
/** One table row per version: what it is, when it was taken, what it holds. */
|
|
53
|
+
export declare function versionTableRows(items: SketchVersionListItem[]): Record<string, unknown>[];
|
|
54
|
+
/** Layer and binding counts of whatever a version stored. */
|
|
55
|
+
export declare function documentCounts(document: JsonValue | undefined): {
|
|
56
|
+
layers: number;
|
|
57
|
+
bindings: number;
|
|
58
|
+
};
|
|
59
|
+
interface SketchValidateMeta {
|
|
60
|
+
width?: number;
|
|
61
|
+
height?: number;
|
|
62
|
+
backgroundColor?: string;
|
|
63
|
+
}
|
|
64
|
+
export type SketchVersionsDeps = VersionCommandDeps<ImageDocumentRow, SketchVersionRow, SketchValidation, SketchValidateMeta>;
|
|
65
|
+
export declare function registerSketchVersionsCommands(sketch: Command, deps?: SketchVersionsDeps): void;
|
|
66
|
+
//# sourceMappingURL=sketch-versions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-versions.d.ts","sourceRoot":"","sources":["../../src/commands/sketch-versions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,kBAAkB,EAEvB,KAAK,YAAY,EAClB,MAAM,mDAAmD,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE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7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAE3B;AAaD,6DAA6D;AAC7D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,GAAG,SAAS;IAI1D,MAAM;IACN,QAAQ;EAEX;AAED,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA4FD,MAAM,MAAM,kBAAkB,GAAG,kBAAkB,CACjD,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,CACnB,CAAC;AAEF,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,OAAO,EACf,IAAI,GAAE,kBAAuB,GAC5B,IAAI,CAKN"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { renderSketchValidation } from "./sketch-validation-output.js";
|
|
2
|
+
import { countArray, registerVersionCommands } from "@nodetool-ai/cli-common/commands/version-commands";
|
|
3
|
+
export { parseVersionDocument, parseVersionNumber } from "@nodetool-ai/cli-common/commands/version-commands";
|
|
4
|
+
export function toVersionListItem(row) {
|
|
5
|
+
return {
|
|
6
|
+
id: row.id,
|
|
7
|
+
version: row.version,
|
|
8
|
+
name: row.name ?? null,
|
|
9
|
+
saveType: row.save_type,
|
|
10
|
+
width: row.width,
|
|
11
|
+
height: row.height,
|
|
12
|
+
backgroundColor: row.background_color,
|
|
13
|
+
createdAt: row.created_at
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** One table row per version: what it is, when it was taken, what it holds. */
|
|
17
|
+
export function versionTableRows(items) {
|
|
18
|
+
return items.map(tableRow);
|
|
19
|
+
}
|
|
20
|
+
function tableRow(v) {
|
|
21
|
+
return {
|
|
22
|
+
version: v.version,
|
|
23
|
+
saveType: v.saveType,
|
|
24
|
+
name: v.name ?? "",
|
|
25
|
+
createdAt: v.createdAt,
|
|
26
|
+
resolution: `${v.width}x${v.height}`,
|
|
27
|
+
background: v.backgroundColor
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Layer and binding counts of whatever a version stored. */
|
|
31
|
+
export function documentCounts(document) {
|
|
32
|
+
const doc = (document ?? {});
|
|
33
|
+
const sketch = (doc.sketch ?? {});
|
|
34
|
+
return {
|
|
35
|
+
layers: countArray(sketch.layers),
|
|
36
|
+
bindings: countArray(doc.layerBindings)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function defaultValidate(document, meta) {
|
|
40
|
+
const { validateSketchDocument } = await import("@nodetool-ai/execution/sketch-debug");
|
|
41
|
+
return validateSketchDocument(document, meta);
|
|
42
|
+
}
|
|
43
|
+
async function defaultStore() {
|
|
44
|
+
const { initDb, ImageDocument, ImageDocumentVersion } = await import("@nodetool-ai/models");
|
|
45
|
+
const { getDefaultDbPath } = await import("@nodetool-ai/config");
|
|
46
|
+
initDb(getDefaultDbPath());
|
|
47
|
+
return {
|
|
48
|
+
load: async (id) => await ImageDocument.findById(id),
|
|
49
|
+
listVersions: async (imageDocumentId, opts) => await ImageDocumentVersion.listForDocument(imageDocumentId, opts),
|
|
50
|
+
findVersion: async (imageDocumentId, version) => await ImageDocumentVersion.findByVersion(imageDocumentId, version),
|
|
51
|
+
snapshot: async (doc, opts) => await ImageDocumentVersion.snapshot(doc, opts),
|
|
52
|
+
restore: async (doc, version) => await ImageDocument.updateFieldsIfUnchanged(doc.id, doc.updated_at, {
|
|
53
|
+
document: version.document,
|
|
54
|
+
width: version.width,
|
|
55
|
+
height: version.height,
|
|
56
|
+
background_color: version.background_color
|
|
57
|
+
}),
|
|
58
|
+
deleteVersion: async (imageDocumentId, version) => {
|
|
59
|
+
const row = await ImageDocumentVersion.findByVersion(imageDocumentId, version);
|
|
60
|
+
if (row)
|
|
61
|
+
await row.delete();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const spec = {
|
|
66
|
+
idArg: "image_document_id",
|
|
67
|
+
idKey: "imageDocumentId",
|
|
68
|
+
descriptions: {
|
|
69
|
+
group: "Inspect and restore the snapshot history of an image document (manual saves, autosaves, pre-restore snapshots)",
|
|
70
|
+
list: "List a sketch's versions, newest first",
|
|
71
|
+
show: "Print one version's metadata and the document it stored",
|
|
72
|
+
create: "Snapshot the sketch as it stands now (a manual save)",
|
|
73
|
+
restore: "Restore a version onto the sketch. The pre-restore state is snapshotted first, and the restored document is validated against the current schema — a restore whose document no longer validates exits non-zero",
|
|
74
|
+
delete: "Delete one version from a sketch's history",
|
|
75
|
+
restoreJson: "Print the restore result as JSON"
|
|
76
|
+
},
|
|
77
|
+
notFoundDocument: (id) => `Image document not found: ${id}`,
|
|
78
|
+
notFoundVersion: (id, version) => `Sketch version not found: ${id} v${version}`,
|
|
79
|
+
conflict: "Document was modified since last read",
|
|
80
|
+
confirmDelete: (id, version) => `Delete v${version} of sketch ${id}?`,
|
|
81
|
+
deleted: (id, version) => `✅ Deleted v${version} of sketch ${id}`,
|
|
82
|
+
toItem: toVersionListItem,
|
|
83
|
+
tableRow,
|
|
84
|
+
counts: documentCounts,
|
|
85
|
+
showSummary: (counts) => `\n ${counts.layers} layer(s), ${counts.bindings} binding(s)`,
|
|
86
|
+
restoreSummary: (id, version, counts, row) => `✅ Restored v${version} onto ${id}: ${counts.layers} layer(s), ${counts.bindings} binding(s), ${row.width}x${row.height} on ${row.background_color}`,
|
|
87
|
+
restoreJsonExtra: (doc) => ({
|
|
88
|
+
document: {
|
|
89
|
+
id: doc.id,
|
|
90
|
+
width: doc.width,
|
|
91
|
+
height: doc.height,
|
|
92
|
+
backgroundColor: doc.background_color
|
|
93
|
+
}
|
|
94
|
+
}),
|
|
95
|
+
validateMeta: (row) => ({
|
|
96
|
+
width: row.width,
|
|
97
|
+
height: row.height,
|
|
98
|
+
backgroundColor: row.background_color
|
|
99
|
+
}),
|
|
100
|
+
renderValidation: renderSketchValidation
|
|
101
|
+
};
|
|
102
|
+
export function registerSketchVersionsCommands(sketch, deps = {}) {
|
|
103
|
+
registerVersionCommands(sketch, spec, deps, {
|
|
104
|
+
store: defaultStore,
|
|
105
|
+
validate: defaultValidate
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=sketch-versions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch-versions.js","sourceRoot":"","sources":["../../src/commands/sketch-versions.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EACL,UAAU,EACV,uBAAuB,EAKxB,MAAM,mDAAmD,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AA6C7G,MAAM,UAAU,iBAAiB,CAC/B,GAAqB;IAErB,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI;QACtB,QAAQ,EAAE,GAAG,CAAC,SAAS;QACvB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,eAAe,EAAE,GAAG,CAAC,gBAAgB;QACrC,SAAS,EAAE,GAAG,CAAC,UAAU;KAC1B,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAC9B,KAA8B;IAE9B,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,QAAQ,CAAC,CAAwB;IACxC,OAAO;QACL,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE;QAClB,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,UAAU,EAAE,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,EA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sketch
|
|
3
|
+
* harness commands.
|
|
4
|
+
*
|
|
5
|
+
* `validate` checks an image document statically: layers a binding points at,
|
|
6
|
+
* fields a round trip through the schema would strip, canvas and layer values
|
|
7
|
+
* nothing can composite. `debug` additionally replays a scripted `--interact`
|
|
8
|
+
* edit session against the headless `ui_sketch_*` bridge and writes a bundle.
|
|
9
|
+
* Both take an image-document JSON file or an `image_documents` row id, and so
|
|
10
|
+
* does `render` (sketch-render.ts), which writes a PNG or a layered PSD.
|
|
11
|
+
* `versions` (sketch-versions.ts) reads and restores a document's snapshot
|
|
12
|
+
* history.
|
|
13
|
+
*
|
|
14
|
+
* Heavy dependencies (the database, the validator core, the bridge) are
|
|
15
|
+
* imported lazily inside each action, so command registration stays light and
|
|
16
|
+
* unit-testable.
|
|
17
|
+
*/
|
|
18
|
+
import type { Command } from "commander";
|
|
19
|
+
import { renderSketchValidation } from "./sketch-validation-output.js";
|
|
20
|
+
export { renderSketchValidation };
|
|
21
|
+
export declare function registerSketchCommands(program: Command): void;
|
|
22
|
+
//# sourceMappingURL=sketch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch.d.ts","sourceRoot":"","sources":["../../src/commands/sketch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAIvE,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAuClC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAwF7D"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { printCommandError } from "@nodetool-ai/pack-manager/command-errors";
|
|
2
|
+
import { printDebugSummary } from "@nodetool-ai/cli-common/commands/debug-summary-output";
|
|
3
|
+
import { renderSketchValidation } from "./sketch-validation-output.js";
|
|
4
|
+
import { registerSketchRenderCommand } from "./sketch-render.js";
|
|
5
|
+
import { registerSketchVersionsCommands } from "./sketch-versions.js";
|
|
6
|
+
export { renderSketchValidation };
|
|
7
|
+
/** Read an image document row through the local database. */
|
|
8
|
+
async function documentLoader() {
|
|
9
|
+
const { initDb, ImageDocument } = await import("@nodetool-ai/models");
|
|
10
|
+
const { getDefaultDbPath } = await import("@nodetool-ai/config");
|
|
11
|
+
let ready = false;
|
|
12
|
+
return async (id) => {
|
|
13
|
+
if (!ready) {
|
|
14
|
+
initDb(getDefaultDbPath());
|
|
15
|
+
ready = true;
|
|
16
|
+
}
|
|
17
|
+
const row = await ImageDocument.findById(id);
|
|
18
|
+
return row
|
|
19
|
+
? {
|
|
20
|
+
id: row.id,
|
|
21
|
+
name: row.name,
|
|
22
|
+
width: row.width,
|
|
23
|
+
height: row.height,
|
|
24
|
+
background_color: row.background_color,
|
|
25
|
+
document: row.document
|
|
26
|
+
}
|
|
27
|
+
: null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function registerSketchCommands(program) {
|
|
31
|
+
const sketch = program
|
|
32
|
+
.command("sketch")
|
|
33
|
+
.description("Work with sketches (image documents)");
|
|
34
|
+
sketch
|
|
35
|
+
.command("validate <sketch_id_or_file>")
|
|
36
|
+
.description("Validate an image document without rendering it: bindings on missing layers, fields a schema round trip would strip, canvas and layer values nothing can composite. Takes an image-document JSON file or an image_documents row id")
|
|
37
|
+
.option("--json", "Print the full SketchValidation as JSON")
|
|
38
|
+
.option("--warnings-as-errors", "Exit non-zero when there are warnings (not just errors)")
|
|
39
|
+
.action(async (ref, opts) => {
|
|
40
|
+
try {
|
|
41
|
+
const { runSketchValidate } = await import("../sketch-debug/index.js");
|
|
42
|
+
const { target, validation } = await runSketchValidate(ref, {
|
|
43
|
+
loadDocument: await documentLoader()
|
|
44
|
+
});
|
|
45
|
+
if (opts.json) {
|
|
46
|
+
console.log(JSON.stringify({ target, validation }, null, 2));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.log(renderSketchValidation(validation).join("\n"));
|
|
50
|
+
}
|
|
51
|
+
const failed = !validation.ok ||
|
|
52
|
+
(opts.warningsAsErrors === true && validation.warnings.length > 0);
|
|
53
|
+
process.exit(failed ? 1 : 0);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
process.exit(printCommandError(e, opts.json));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
sketch
|
|
60
|
+
.command("debug <sketch_id_or_file>")
|
|
61
|
+
.description("Replay a scripted edit session against a sketch headlessly and collect a debug bundle (the document, the report, every step's result)")
|
|
62
|
+
.option("--interact <json>", 'Scripted steps: [{"tool":"add_layer","input":{"name":"Glow"}}] — the ui_sketch_ prefix is optional')
|
|
63
|
+
.option("--out <dir>", "Bundle output directory (default: nodetool-debug/sketch-<id>-<timestamp>)")
|
|
64
|
+
.option("--json", "Print the full SketchDebugReport as JSON to stdout")
|
|
65
|
+
.action(async (ref, opts) => {
|
|
66
|
+
try {
|
|
67
|
+
const { parseInteractionScript, runSketchDebug } = await import("../sketch-debug/index.js");
|
|
68
|
+
const interact = opts.interact
|
|
69
|
+
? parseInteractionScript(opts.interact)
|
|
70
|
+
: undefined;
|
|
71
|
+
const debugOptions = {};
|
|
72
|
+
if (interact) {
|
|
73
|
+
debugOptions.interact = interact;
|
|
74
|
+
}
|
|
75
|
+
if (opts.out) {
|
|
76
|
+
debugOptions.outDir = opts.out;
|
|
77
|
+
}
|
|
78
|
+
const { report, bundleDir } = await runSketchDebug(ref, debugOptions, {
|
|
79
|
+
loadDocument: await documentLoader(),
|
|
80
|
+
onLog: (line) => console.error(line)
|
|
81
|
+
});
|
|
82
|
+
if (opts.json) {
|
|
83
|
+
console.log(JSON.stringify(report, null, 2));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
printDebugSummary(report, bundleDir, {
|
|
87
|
+
label: "sketch",
|
|
88
|
+
meta: `${report.meta.layerCount} layer(s), ${report.meta.bindingCount} binding(s), ${report.meta.width}x${report.meta.height}`,
|
|
89
|
+
file: "sketch.json"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
process.exit(report.verdict.ok ? 0 : 1);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
process.exit(printCommandError(e, opts.json));
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
registerSketchRenderCommand(sketch, documentLoader);
|
|
99
|
+
registerSketchVersionsCommands(sketch);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=sketch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sketch.js","sourceRoot":"","sources":["../../src/commands/sketch.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uDAAuD,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAalC,6DAA6D;AAC7D,KAAK,UAAU,cAAc;IAG3B,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACtE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACjE,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,OAAO,KAAK,EAAE,EAAU,EAAE,EAAE;QAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAC3B,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC7C,OAAO,G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EAAE;gBACpE,YAAY,EAAE,MAAM,cAAc,EAAE;gBACpC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;aACrC,CAAC,CAAC;YAEH,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE;oBACnC,KAAK,EAAE,QAAQ;oBACf,IAAI,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,cAAc,MAAM,CAAC,IAAI,CAAC,YAAY,gBAAgB,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE;oBAC9H,IAAI,EAAE,aAAa;iBACpB,CAAC,CAAC;YACL,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,2BAA2B,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACpD,8BAA8B,CAAC,MAAM,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Run the independently installed cli-sketch command group. */
|
|
2
|
+
export declare function run(argv?: readonly string[]): Promise<void>;
|
|
3
|
+
export declare const descriptor: {
|
|
4
|
+
readonly id: "cli-sketch";
|
|
5
|
+
readonly apiVersion: 1;
|
|
6
|
+
readonly requires: readonly [];
|
|
7
|
+
readonly capabilities: readonly ["cli:sketch"];
|
|
8
|
+
};
|
|
9
|
+
export declare const feature: {
|
|
10
|
+
descriptor: {
|
|
11
|
+
readonly id: "cli-sketch";
|
|
12
|
+
readonly apiVersion: 1;
|
|
13
|
+
readonly requires: readonly [];
|
|
14
|
+
readonly capabilities: readonly ["cli:sketch"];
|
|
15
|
+
};
|
|
16
|
+
run: typeof run;
|
|
17
|
+
};
|
|
18
|
+
export default feature;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,gEAAgE;AAChE,wBAAsB,GAAG,CAAC,IAAI,GAAE,SAAS,MAAM,EAA0B,GAAG,OAAO,CAAC,IAAI,CAAC,CAKxF;AAED,eAAO,MAAM,UAAU;aAAK,EAAE,EAAE,YAAY;aAAE,UAAU,EAAE,CAAC;aAAE,QAAQ;aAAM,YAAY,YAAG,YAAY;CAAY,CAAC;AACnH,eAAO,MAAM,OAAO;;qBADY,YAAY;6BAAc,CAAC;;yCAA+B,YAAY;;;CAC5D,CAAC;eAC5B,OAAO"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { initializeCliRuntime } from "@nodetool-ai/cli-common/runtime-env";
|
|
3
|
+
import { registerSketchCommands } from "./commands/sketch.js";
|
|
4
|
+
/** Run the independently installed cli-sketch command group. */
|
|
5
|
+
export async function run(argv = process.argv.slice(2)) {
|
|
6
|
+
initializeCliRuntime(import.meta.url);
|
|
7
|
+
const program = new Command("nodetool");
|
|
8
|
+
registerSketchCommands(program);
|
|
9
|
+
await program.parseAsync([...argv], { from: "user" });
|
|
10
|
+
}
|
|
11
|
+
export const descriptor = { id: "cli-sketch", apiVersion: 1, requires: [], capabilities: ["cli:sketch"] };
|
|
12
|
+
export const feature = { descriptor, run };
|
|
13
|
+
export default feature;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,IAAI,GAAsB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,oBAAoB,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAChC,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC,YAAY,CAAC,EAAW,CAAC;AACnH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;AAC3C,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodetool.d.ts","sourceRoot":"","sources":["../src/nodetool.ts"],"names":[],"mappings":""}
|
package/dist/nodetool.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodetool.js","sourceRoot":"","sources":["../src/nodetool.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,KAAK,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sketch debug harness: the CLI host around the shared validator.
|
|
3
|
+
*
|
|
4
|
+
* `runSketchValidate` is the cheap pre-flight — load an image document, check
|
|
5
|
+
* it, report. `runSketchDebug` additionally replays a scripted edit session
|
|
6
|
+
* against the headless `ui_sketch_*` bridge (the one the tool-loop eval
|
|
7
|
+
* drives), validates the document the session left behind, and writes a
|
|
8
|
+
* self-contained bundle.
|
|
9
|
+
*
|
|
10
|
+
* Everything that could pull in a heavy package is injected with a lazy
|
|
11
|
+
* default: the validator core (`@nodetool-ai/execution/sketch-debug`) and the
|
|
12
|
+
* bridge factory (`@nodetool-ai/agents`). Tests supply their own and load
|
|
13
|
+
* neither.
|
|
14
|
+
*/
|
|
15
|
+
import type { SketchDebugReport, SketchInteractionRecord, SketchValidation } from "@nodetool-ai/execution/sketch-debug";
|
|
16
|
+
import type { SketchInteractionStep } from "./interactions.js";
|
|
17
|
+
import { type ResolvedSketchTarget, type SketchCanvasSettings, type SketchTargetDeps } from "./target.js";
|
|
18
|
+
/** The pieces of the shared core this host calls. */
|
|
19
|
+
export interface SketchDebugCore {
|
|
20
|
+
validateSketchDocument: (raw: unknown, meta?: SketchCanvasSettings) => SketchValidation | Promise<SketchValidation>;
|
|
21
|
+
buildSketchDebugReport: (input: {
|
|
22
|
+
target: SketchDebugReport["target"];
|
|
23
|
+
document: unknown;
|
|
24
|
+
meta?: SketchCanvasSettings;
|
|
25
|
+
interactions?: SketchInteractionRecord[];
|
|
26
|
+
finalState?: unknown;
|
|
27
|
+
finalDocument?: unknown;
|
|
28
|
+
}) => SketchDebugReport | Promise<SketchDebugReport>;
|
|
29
|
+
renderSketchReportMarkdown: (report: SketchDebugReport) => string;
|
|
30
|
+
}
|
|
31
|
+
/** The bridge surface this host drives — one tool per `ui_sketch_*` name. */
|
|
32
|
+
export interface SketchBridgeTool {
|
|
33
|
+
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* HOLDOUT (anti-slop/no-unknown-returns): a `ui_sketch_*` tool answers in
|
|
36
|
+
* the open tool-result domain, and the bridge that implements this lives in
|
|
37
|
+
* `@nodetool-ai/agents`.
|
|
38
|
+
*/
|
|
39
|
+
execute: (args: Record<string, unknown>) => Promise<unknown>;
|
|
40
|
+
}
|
|
41
|
+
/** One layer of the bridge's snapshot. */
|
|
42
|
+
export interface SketchBridgeLayer {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
type: "raster" | "mask" | "group";
|
|
46
|
+
visible: boolean;
|
|
47
|
+
opacity: number;
|
|
48
|
+
blendMode: string;
|
|
49
|
+
hasBinding?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/** The bridge's snapshot after a session (`SketchBridgeFinalState`). */
|
|
52
|
+
export interface SketchBridgeSnapshot {
|
|
53
|
+
width?: number;
|
|
54
|
+
height?: number;
|
|
55
|
+
backgroundColor?: string;
|
|
56
|
+
activeLayerId?: string | null;
|
|
57
|
+
layers?: SketchBridgeLayer[];
|
|
58
|
+
}
|
|
59
|
+
export interface SketchBridge {
|
|
60
|
+
tools: SketchBridgeTool[];
|
|
61
|
+
finalState: () => SketchBridgeSnapshot;
|
|
62
|
+
}
|
|
63
|
+
export type CreateSketchBridge = (initial: {
|
|
64
|
+
name?: string;
|
|
65
|
+
width?: number;
|
|
66
|
+
height?: number;
|
|
67
|
+
layers?: {
|
|
68
|
+
name: string;
|
|
69
|
+
type?: "raster" | "mask";
|
|
70
|
+
}[];
|
|
71
|
+
}) => SketchBridge | Promise<SketchBridge>;
|
|
72
|
+
export interface SketchDebugDeps extends SketchTargetDeps {
|
|
73
|
+
/** Defaults to `@nodetool-ai/execution/sketch-debug`. */
|
|
74
|
+
core?: SketchDebugCore;
|
|
75
|
+
/** Defaults to `createSketchToolBridge` from `@nodetool-ai/agents`. */
|
|
76
|
+
createBridge?: CreateSketchBridge;
|
|
77
|
+
onLog?: (line: string) => void;
|
|
78
|
+
}
|
|
79
|
+
export interface SketchDebugOptions {
|
|
80
|
+
interact?: SketchInteractionStep[];
|
|
81
|
+
outDir?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface SketchValidateResult {
|
|
84
|
+
target: ResolvedSketchTarget["target"];
|
|
85
|
+
validation: SketchValidation;
|
|
86
|
+
}
|
|
87
|
+
export interface SketchDebugResult {
|
|
88
|
+
report: SketchDebugReport;
|
|
89
|
+
bundleDir: string;
|
|
90
|
+
}
|
|
91
|
+
/** Load a sketch and validate it — no bridge, no bundle. */
|
|
92
|
+
export declare function runSketchValidate(ref: string, deps: SketchDebugDeps): Promise<SketchValidateResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Replay `--interact` against the headless bridge and write the bundle.
|
|
95
|
+
*
|
|
96
|
+
* A failing step is recorded and the script continues: a run that stops at the
|
|
97
|
+
* first error hides every problem behind it, and the report is what the caller
|
|
98
|
+
* came for.
|
|
99
|
+
*/
|
|
100
|
+
export declare function runSketchDebug(ref: string, options: SketchDebugOptions, deps: SketchDebugDeps): Promise<SketchDebugResult>;
|
|
101
|
+
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/sketch-debug/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAA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AAE,MAAM,EACX,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,oBAAoB,CAAC,CAQ/B;AA4ED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,kBAAkB,EAC3B,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,iBAAiB,CAAC,CA8D5B"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { runInteractionSteps } from "@nodetool-ai/cli-common/interaction-script";
|
|
2
|
+
import { writeDebugBundle } from "@nodetool-ai/cli-common/debug-bundle";
|
|
3
|
+
import { resolveSketchTarget } from "./target.js";
|
|
4
|
+
async function loadCore() {
|
|
5
|
+
const core = await import("@nodetool-ai/execution/sketch-debug");
|
|
6
|
+
return {
|
|
7
|
+
validateSketchDocument: (raw, meta) => core.validateSketchDocument(raw, meta),
|
|
8
|
+
buildSketchDebugReport: (input) => core.buildSketchDebugReport(input),
|
|
9
|
+
renderSketchReportMarkdown: (report) => core.renderSketchReportMarkdown(report)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
async function loadBridgeFactory() {
|
|
13
|
+
const { createSketchToolBridge } = await import("@nodetool-ai/agents");
|
|
14
|
+
return (initial) => createSketchToolBridge(initial);
|
|
15
|
+
}
|
|
16
|
+
/** Load a sketch and validate it — no bridge, no bundle. */
|
|
17
|
+
export async function runSketchValidate(ref, deps) {
|
|
18
|
+
const resolved = await resolveSketchTarget(ref, deps);
|
|
19
|
+
const core = deps.core ?? (await loadCore());
|
|
20
|
+
const validation = await core.validateSketchDocument(resolved.raw, resolved.meta);
|
|
21
|
+
return { target: resolved.target, validation };
|
|
22
|
+
}
|
|
23
|
+
function reconstructDocument(snapshot, resolved) {
|
|
24
|
+
const layers = (snapshot.layers ?? []).map((layer) => ({
|
|
25
|
+
id: layer.id,
|
|
26
|
+
name: layer.name,
|
|
27
|
+
type: layer.type,
|
|
28
|
+
visible: layer.visible,
|
|
29
|
+
locked: false,
|
|
30
|
+
opacity: layer.opacity,
|
|
31
|
+
blendMode: layer.blendMode,
|
|
32
|
+
data: null
|
|
33
|
+
}));
|
|
34
|
+
const activeLayerId = snapshot.activeLayerId ?? "";
|
|
35
|
+
const background = snapshot.backgroundColor ??
|
|
36
|
+
resolved.document.canvas.backgroundColor ??
|
|
37
|
+
resolved.meta.backgroundColor;
|
|
38
|
+
const canvas = {
|
|
39
|
+
width: snapshot.width ?? resolved.document.canvas.width ?? 0,
|
|
40
|
+
height: snapshot.height ?? resolved.document.canvas.height ?? 0
|
|
41
|
+
};
|
|
42
|
+
if (background !== undefined) {
|
|
43
|
+
canvas.backgroundColor = background;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
sketch: {
|
|
47
|
+
version: resolved.document.version,
|
|
48
|
+
canvas,
|
|
49
|
+
layers,
|
|
50
|
+
activeLayerId,
|
|
51
|
+
maskLayerId: null
|
|
52
|
+
},
|
|
53
|
+
layerBindings: []
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Replay `--interact` against the headless bridge and write the bundle.
|
|
58
|
+
*
|
|
59
|
+
* A failing step is recorded and the script continues: a run that stops at the
|
|
60
|
+
* first error hides every problem behind it, and the report is what the caller
|
|
61
|
+
* came for.
|
|
62
|
+
*/
|
|
63
|
+
export async function runSketchDebug(ref, options, deps) {
|
|
64
|
+
const resolved = await resolveSketchTarget(ref, deps);
|
|
65
|
+
const core = deps.core ?? (await loadCore());
|
|
66
|
+
const steps = options.interact ?? [];
|
|
67
|
+
const interactions = [];
|
|
68
|
+
let snapshot;
|
|
69
|
+
if (steps.length > 0) {
|
|
70
|
+
const createBridge = deps.createBridge ?? (await loadBridgeFactory());
|
|
71
|
+
const bridgeInit = {
|
|
72
|
+
// The bridge seeds names and types only; a group layer has no headless
|
|
73
|
+
// equivalent, so it enters the stack as a raster.
|
|
74
|
+
layers: resolved.document.layers.map((layer) => ({
|
|
75
|
+
name: layer.name,
|
|
76
|
+
type: layer.type === "mask" ? "mask" : "raster"
|
|
77
|
+
}))
|
|
78
|
+
};
|
|
79
|
+
if (resolved.target.name) {
|
|
80
|
+
bridgeInit.name = resolved.target.name;
|
|
81
|
+
}
|
|
82
|
+
if (resolved.document.canvas.width !== undefined) {
|
|
83
|
+
bridgeInit.width = resolved.document.canvas.width;
|
|
84
|
+
}
|
|
85
|
+
if (resolved.document.canvas.height !== undefined) {
|
|
86
|
+
bridgeInit.height = resolved.document.canvas.height;
|
|
87
|
+
}
|
|
88
|
+
const bridge = await createBridge(bridgeInit);
|
|
89
|
+
interactions.push(...(await runInteractionSteps(steps, bridge.tools, "sketch", deps.onLog)));
|
|
90
|
+
snapshot = bridge.finalState();
|
|
91
|
+
}
|
|
92
|
+
const finalDocument = snapshot
|
|
93
|
+
? reconstructDocument(snapshot, resolved)
|
|
94
|
+
: undefined;
|
|
95
|
+
const reportInput = {
|
|
96
|
+
target: resolved.target,
|
|
97
|
+
document: resolved.raw,
|
|
98
|
+
meta: resolved.meta,
|
|
99
|
+
interactions
|
|
100
|
+
};
|
|
101
|
+
if (snapshot) {
|
|
102
|
+
reportInput.finalState = snapshot;
|
|
103
|
+
}
|
|
104
|
+
if (finalDocument) {
|
|
105
|
+
reportInput.finalDocument = finalDocument;
|
|
106
|
+
}
|
|
107
|
+
const report = await core.buildSketchDebugReport(reportInput);
|
|
108
|
+
const bundleDir = await writeDebugBundle({
|
|
109
|
+
kind: "sketch",
|
|
110
|
+
ref,
|
|
111
|
+
outDir: options.outDir,
|
|
112
|
+
raw: resolved.raw,
|
|
113
|
+
report,
|
|
114
|
+
reportMarkdown: core.renderSketchReportMarkdown(report),
|
|
115
|
+
});
|
|
116
|
+
return { report, bundleDir };
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.js","sourceRoot":"","sources":["../../src/sketch-debug/harness.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,mBA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AM,GAAG,MAAM,YAAY,CAAC,UAAU,CAAC,CAAC;QAC9C,YAAY,CAAC,IAAI,CACf,GAAG,CAAC,MAAM,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAC1E,CAAC;QACF,QAAQ,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,aAAa,GAAG,QAAQ;QAC5B,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC;QACzC,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,WAAW,GAAsD;QACrE,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,QAAQ,EAAE,QAAQ,CAAC,GAAG;QACtB,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,YAAY;KACb,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,WAAW,CAAC,UAAU,GAAG,QAAQ,CAAC;IACpC,CAAC;IACD,IAAI,aAAa,EAAE,CAAC;QAClB,WAAW,CAAC,aAAa,GAAG,aAAa,CAAC;IAC5C,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAE9D,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC;QACvC,IAAI,EAAE,QAAQ;QACd,GAAG;QACH,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,MAAM;QACN,cAAc,EAAE,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC;KACxD,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI host for the sketch debug harness: target resolution, the
|
|
3
|
+
* `--interact` script, and the bundle writer. The rules themselves live in
|
|
4
|
+
* `@nodetool-ai/execution/sketch-debug`.
|
|
5
|
+
*/
|
|
6
|
+
export { runSketchDebug, runSketchValidate, type CreateSketchBridge, type SketchBridge, type SketchBridgeLayer, type SketchBridgeSnapshot, type SketchBridgeTool, type SketchDebugCore, type SketchDebugDeps, type SketchDebugOptions, type SketchDebugResult, type SketchValidateResult } from "./harness.js";
|
|
7
|
+
export { normalizeToolName, parseInteractionScript, type SketchInteractionStep } from "./interactions.js";
|
|
8
|
+
export { resolveSketchTarget, type ImageDocumentRecord, type ResolvedSketchTarget, type SketchCanvasSettings, type SketchDocumentView, type SketchLayerView, type SketchTargetDeps } from "./target.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sketch-debug/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,qBAAqB,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI host for the sketch debug harness: target resolution, the
|
|
3
|
+
* `--interact` script, and the bundle writer. The rules themselves live in
|
|
4
|
+
* `@nodetool-ai/execution/sketch-debug`.
|
|
5
|
+
*/
|
|
6
|
+
export { runSketchDebug, runSketchValidate } from "./harness.js";
|
|
7
|
+
export { normalizeToolName, parseInteractionScript } from "./interactions.js";
|
|
8
|
+
export { resolveSketchTarget } from "./target.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sketch-debug/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,iBAAiB,EAWlB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EAEvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mBAAmB,EAOpB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `--interact` script for `nodetool sketch debug`.
|
|
3
|
+
*
|
|
4
|
+
* A step names one sketch tool and the input to call it with:
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* [{"tool": "add_layer", "input": {"name": "Glow", "type": "raster"}},
|
|
8
|
+
* {"tool": "ui_sketch_set_layer_props",
|
|
9
|
+
* "input": {"target": "Glow", "opacity": 0.5, "blendMode": "multiply"}}]
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Both spellings resolve to the same tool: the `ui_sketch_` prefix is what the
|
|
13
|
+
* bridge and the browser call it, and typing it for every step is noise.
|
|
14
|
+
*/
|
|
15
|
+
import { type InteractionStep } from "@nodetool-ai/cli-common/interaction-script";
|
|
16
|
+
/** One parsed step, with the tool name in its canonical `ui_sketch_*` form. */
|
|
17
|
+
export type SketchInteractionStep = InteractionStep;
|
|
18
|
+
export declare const normalizeToolName: (name: string) => string, parseInteractionScript: (json: string) => InteractionStep[];
|
|
19
|
+
//# sourceMappingURL=interactions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions.d.ts","sourceRoot":"","sources":["../../src/sketch-debug/interactions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,4CAA4C,CAAC;AAEpD,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAEpD,eAAO,MAAQ,iBAAiB,4BAAE,sBAAsB,qCAIrD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `--interact` script for `nodetool sketch debug`.
|
|
3
|
+
*
|
|
4
|
+
* A step names one sketch tool and the input to call it with:
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* [{"tool": "add_layer", "input": {"name": "Glow", "type": "raster"}},
|
|
8
|
+
* {"tool": "ui_sketch_set_layer_props",
|
|
9
|
+
* "input": {"target": "Glow", "opacity": 0.5, "blendMode": "multiply"}}]
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Both spellings resolve to the same tool: the `ui_sketch_` prefix is what the
|
|
13
|
+
* bridge and the browser call it, and typing it for every step is noise.
|
|
14
|
+
*/
|
|
15
|
+
import { createInteractionScript } from "@nodetool-ai/cli-common/interaction-script";
|
|
16
|
+
export const { normalizeToolName, parseInteractionScript } = createInteractionScript("ui_sketch_", '{"tool":"add_layer","input":{"name":"Glow"}}');
|
|
17
|
+
//# sourceMappingURL=interactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactions.js","sourceRoot":"","sources":["../../src/sketch-debug/interactions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,uBAAuB,EAExB,MAAM,4CAA4C,CAAC;AAKpD,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,GACxD,uBAAuB,CACrB,YAAY,EACZ,8CAA8C,CAC/C,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SketchDebugTarget } from "@nodetool-ai/execution/sketch-debug";
|
|
2
|
+
/** An `image_documents` row as the harness needs it. */
|
|
3
|
+
export interface ImageDocumentRecord {
|
|
4
|
+
id: string;
|
|
5
|
+
name?: string | null;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
/** camelCase on the API response, snake_case on the row. */
|
|
9
|
+
backgroundColor?: string;
|
|
10
|
+
background_color?: string;
|
|
11
|
+
/** The stored document — a JSON string or an already-parsed object. */
|
|
12
|
+
document: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface SketchTargetDeps {
|
|
15
|
+
/** Load an image document by DB id. */
|
|
16
|
+
loadDocument: (id: string) => Promise<ImageDocumentRecord | null>;
|
|
17
|
+
}
|
|
18
|
+
/** The canvas settings the row carries beside the document. */
|
|
19
|
+
export interface SketchCanvasSettings {
|
|
20
|
+
width?: number;
|
|
21
|
+
height?: number;
|
|
22
|
+
backgroundColor?: string;
|
|
23
|
+
}
|
|
24
|
+
/** The layer stack, read down to what the headless bridge can be seeded with. */
|
|
25
|
+
export interface SketchLayerView {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
type: "raster" | "mask" | "group";
|
|
29
|
+
}
|
|
30
|
+
/** The document read as a canvas plus a layer stack. */
|
|
31
|
+
export interface SketchDocumentView {
|
|
32
|
+
version: number;
|
|
33
|
+
canvas: SketchCanvasSettings;
|
|
34
|
+
layers: SketchLayerView[];
|
|
35
|
+
activeLayerId: string;
|
|
36
|
+
maskLayerId: string | null;
|
|
37
|
+
}
|
|
38
|
+
export interface ResolvedSketchTarget {
|
|
39
|
+
target: SketchDebugTarget;
|
|
40
|
+
/** The document exactly as loaded — validation's input, unrepaired. */
|
|
41
|
+
raw: unknown;
|
|
42
|
+
/** The same document, read as a canvas + layer stack. */
|
|
43
|
+
document: SketchDocumentView;
|
|
44
|
+
meta: SketchCanvasSettings;
|
|
45
|
+
}
|
|
46
|
+
/** Resolve a sketch target: a JSON file path or an image document row id. */
|
|
47
|
+
export declare function resolveSketchTarget(ref: string, deps: SketchTargetDeps): Promise<ResolvedSketchTarget>;
|
|
48
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../src/sketch-debug/target.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAQ7E,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uEAAuE;IACvE,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;CACnE;AAED,+DAA+D;AAC/D,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,iFAAiF;AACjF,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;CACnC;AAED,wDAAwD;AACxD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,uEAAuE;IACvE,GAAG,EAAE,OAAO,CAAC;IACb,yDAAyD;IACzD,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,IAAI,EAAE,oBAAoB,CAAC;CAC5B;AAwDD,6EAA6E;AAC7E,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAiD/B"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a sketch debug target into an image document plus its canvas
|
|
3
|
+
* settings.
|
|
4
|
+
*
|
|
5
|
+
* A sketch is named two ways, and both end up in the same shape:
|
|
6
|
+
*
|
|
7
|
+
* - a **JSON file** — either a bare `ImageDocumentData` (`sketch` +
|
|
8
|
+
* `layerBindings`) or a wrapper carrying one under `document`, as the
|
|
9
|
+
* `image_documents` row and the `sketch.get` response do;
|
|
10
|
+
* - an **image_documents row id**, read through an injected loader so this
|
|
11
|
+
* module needs no database.
|
|
12
|
+
*
|
|
13
|
+
* A path that exists on disk wins over an id, so a file named like an id is
|
|
14
|
+
* still readable.
|
|
15
|
+
*/
|
|
16
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
17
|
+
import { isFiniteNumber, isRecord, isString } from "@nodetool-ai/cli-common/predicates";
|
|
18
|
+
import { documentOf } from "@nodetool-ai/cli-common/document-json";
|
|
19
|
+
const numberOr = (value) => isFiniteNumber(value) ? value : undefined;
|
|
20
|
+
/** Read width/height/background off whatever wrapper carried the document. */
|
|
21
|
+
function settingsOf(raw) {
|
|
22
|
+
if (!isRecord(raw))
|
|
23
|
+
return {};
|
|
24
|
+
const settings = {};
|
|
25
|
+
const width = numberOr(raw.width);
|
|
26
|
+
const height = numberOr(raw.height);
|
|
27
|
+
const background = isString(raw.backgroundColor)
|
|
28
|
+
? raw.backgroundColor
|
|
29
|
+
: isString(raw.background_color)
|
|
30
|
+
? raw.background_color
|
|
31
|
+
: undefined;
|
|
32
|
+
if (width !== undefined)
|
|
33
|
+
settings.width = width;
|
|
34
|
+
if (height !== undefined)
|
|
35
|
+
settings.height = height;
|
|
36
|
+
if (background !== undefined)
|
|
37
|
+
settings.backgroundColor = background;
|
|
38
|
+
return settings;
|
|
39
|
+
}
|
|
40
|
+
/** A document is anything with a `sketch` object and a `layerBindings` array. */
|
|
41
|
+
const looksLikeDocument = (value) => isRecord(value) &&
|
|
42
|
+
isRecord(value.sketch) &&
|
|
43
|
+
Array.isArray(value.layerBindings);
|
|
44
|
+
const layerType = (value) => value === "mask" || value === "group" ? value : "raster";
|
|
45
|
+
/** Read a document as a canvas + layer stack, defaulting what is missing. */
|
|
46
|
+
function asDocument(raw) {
|
|
47
|
+
const record = isRecord(raw) ? raw : {};
|
|
48
|
+
const sketch = isRecord(record.sketch) ? record.sketch : {};
|
|
49
|
+
const layers = [];
|
|
50
|
+
for (const entry of Array.isArray(sketch.layers) ? sketch.layers : []) {
|
|
51
|
+
if (!isRecord(entry) || !isString(entry.id))
|
|
52
|
+
continue;
|
|
53
|
+
layers.push({
|
|
54
|
+
id: entry.id,
|
|
55
|
+
name: isString(entry.name) ? entry.name : entry.id,
|
|
56
|
+
type: layerType(entry.type)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
version: numberOr(sketch.version) ?? 1,
|
|
61
|
+
canvas: settingsOf(sketch.canvas),
|
|
62
|
+
layers,
|
|
63
|
+
activeLayerId: isString(sketch.activeLayerId) ? sketch.activeLayerId : "",
|
|
64
|
+
maskLayerId: isString(sketch.maskLayerId) ? sketch.maskLayerId : null
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Resolve a sketch target: a JSON file path or an image document row id. */
|
|
68
|
+
export async function resolveSketchTarget(ref, deps) {
|
|
69
|
+
if (existsSync(ref)) {
|
|
70
|
+
let parsed;
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(readFileSync(ref, "utf8"));
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
throw new Error(`${ref} is not valid JSON: ${e.message}`);
|
|
76
|
+
}
|
|
77
|
+
const raw = documentOf(parsed);
|
|
78
|
+
if (!looksLikeDocument(raw)) {
|
|
79
|
+
throw new Error(`${ref} is not an image document (no \`sketch\`/\`layerBindings\`, and no \`document\` field carrying them).`);
|
|
80
|
+
}
|
|
81
|
+
const name = isRecord(parsed) && isString(parsed.name)
|
|
82
|
+
? parsed.name
|
|
83
|
+
: undefined;
|
|
84
|
+
const document = asDocument(raw);
|
|
85
|
+
const target = { kind: "file", ref };
|
|
86
|
+
if (name) {
|
|
87
|
+
target.name = name;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
target,
|
|
91
|
+
raw,
|
|
92
|
+
document,
|
|
93
|
+
// The wrapper's own width/height, never the canvas's: the validator
|
|
94
|
+
// compares the two, so folding one into the other hides the mismatch.
|
|
95
|
+
meta: settingsOf(parsed)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const record = await deps.loadDocument(ref);
|
|
99
|
+
if (!record) {
|
|
100
|
+
throw new Error(`Image document not found: ${ref}`);
|
|
101
|
+
}
|
|
102
|
+
const raw = documentOf(record);
|
|
103
|
+
const document = asDocument(raw);
|
|
104
|
+
const target = { kind: "id", ref };
|
|
105
|
+
if (record.name) {
|
|
106
|
+
target.name = record.name;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
target,
|
|
110
|
+
raw,
|
|
111
|
+
document,
|
|
112
|
+
meta: settingsOf(record)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.js","sourceRoot":"","sources":["../../src/sketch-debug/target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;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AAoE;YACpE,sEAAsE;YACtE,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;SACzB,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,MAAM,GAAsB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACtD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAC5B,CAAC;IACD,OAAO;QACL,MAAM;QACN,GAAG;QACH,QAAQ;QACR,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;KACzB,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodetool-ai/cli-sketch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.9-beta.1",
|
|
4
|
+
"description": "Independent sketch command feature for NodeTool",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22.0.0"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"bin": {
|
|
12
|
+
"nodetool-sketch": "dist/nodetool.js"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"nodetool-dev": "./src/index.ts",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./*": {
|
|
22
|
+
"nodetool-dev": "./src/*.ts",
|
|
23
|
+
"types": "./dist/*.d.ts",
|
|
24
|
+
"import": "./dist/*.js",
|
|
25
|
+
"default": "./dist/*.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "node ../../scripts/build-typescript-workspace.mjs",
|
|
30
|
+
"test": "node ../../scripts/run-vitest.mjs run",
|
|
31
|
+
"lint": "node ../../scripts/run-tsc.mjs --noEmit"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@nodetool-ai/agents": "0.8.9-beta.1",
|
|
35
|
+
"@nodetool-ai/cli-common": "0.8.9-beta.1",
|
|
36
|
+
"@nodetool-ai/config": "0.8.9-beta.1",
|
|
37
|
+
"@nodetool-ai/execution": "0.8.9-beta.1",
|
|
38
|
+
"@nodetool-ai/models": "0.8.9-beta.1",
|
|
39
|
+
"@nodetool-ai/pack-manager": "0.8.9-beta.1",
|
|
40
|
+
"@nodetool-ai/runtime": "0.8.9-beta.1",
|
|
41
|
+
"@nodetool-ai/storage": "0.8.9-beta.1",
|
|
42
|
+
"commander": "^12.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@nodetool-ai/protocol": "*",
|
|
46
|
+
"@types/node": "^22.0.0",
|
|
47
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
48
|
+
"vitest": "^5.0.1"
|
|
49
|
+
},
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/nodetool-ai/nodetool.git",
|
|
54
|
+
"directory": "packages/cli-sketch"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"dist",
|
|
61
|
+
"README.md"
|
|
62
|
+
]
|
|
63
|
+
}
|