@enhance-eng/enhance 0.1.22 → 0.1.25

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.
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { z } from "zod";
3
2
  import process from "node:process";
3
+ import { z } from "zod";
4
4
  import path from "node:path";
5
5
  import { chmod, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
6
6
 
package/dist/main.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import { $ as createOrganisationOutputSchema, A as parseCanvasReference, At as canvasLayoutPriorityDeclarations, D as assertCanvasReferenceOperations, Dt as canvasAuthoredStyleDeclarations, E as assertCanvasReferenceNodes, Et as canvasAuthoredLayoutValueOf, F as completeScreenOutputSchema, I as createScreenOutputSchema, L as appendRecordingChunkOutputSchema, M as CliError, Mt as canvasSchema, O as canvasReferenceNodeIds, Ot as canvasAxisStyleProperties, P as appErrorSchema, R as completeRecordingOutputSchema, T as canvasEditsSchema, Tt as canvasReadableSceneDocumentSchema, _t as RENDER_MIN_SCALE, a as toExitCode, at as beginCanvasActivityOutputSchema, bt as canvasWorldBoundsSchema, c as toSharedCapabilities, ct as getCanvasDocumentOutputSchema, d as createCapabilityCatalogAdapter, et as emptyFixtureDocument, f as createRouterShapeAdapter, g as PROCEDURE_DESCRIPTIONS, h as OPTION_DESCRIPTIONS, i as toCanvasAuthoringResult, it as canvasTextRunsOf, j as PartialBatchError, k as fromCanvasReference, kt as canvasLayoutMainAxisOf, l as createMcpCapabilityDiscoveryAdapter, lt as saveCanvasDocumentOutputSchema, n as withCommandName, o as toFailurePayload, ot as canvasAgentActivityPhaseSchema, p as createCapabilityPolicyAdapter, pt as canvasOperationSchema, t as withCommandInFailure, tt as withFixtureScreen, u as ProcessExitError, ut as MAX_CANVAS_OPERATIONS, z as startRecordingOutputSchema } from "./cli-output-identity.lib-a1wTreJ6.mjs";
3
- import { a as createOauthLoopbackAdapter, c as createWriteHtmlCanvasComposite, d as createApplyCanvasComposite, f as createCanvasActivityComposite, l as createEditCanvasComposite, m as createAuthUseCase, n as createHttpRemoteAdapter, o as createCapabilityInvocationAdapter, p as createRenderCanvasComposite, r as CLI_CONFIG, s as createRenderFileAdapter, t as createMutationKeyAdapter, u as sceneAtVersion } from "./mutation-key.adapter-B3ugNA3r.mjs";
2
+ import { At as fromCanvasReference, Bt as completeRecordingOutputSchema, Dn as canvasTextRunsOf, Dt as assertCanvasReferenceNodes, Et as canvasEditsSchema, Fn as beginCanvasActivityOutputSchema, Gn as getCanvasDocumentOutputSchema, Ht as startRecordingOutputSchema, In as canvasAgentActivityPhaseSchema, It as appErrorSchema, Jn as canvasOperationSchema, Kn as saveCanvasDocumentOutputSchema, Lt as completeScreenOutputSchema, Mt as parseCanvasReference, Nt as PartialBatchError, Pt as CliError, Rt as createScreenOutputSchema, _ as PROCEDURE_DESCRIPTIONS, a as toFailurePayload, an as withFixtureScreen, d as ProcessExitError, dr as canvasAuthoredLayoutValueOf, et as canvasRenderScopedInputSchema, f as createCapabilityCatalogAdapter, fr as canvasAuthoredStyleDeclarations, g as OPTION_DESCRIPTIONS, gt as canvasFindInputSchema, hr as canvasLayoutPriorityDeclarations, i as toExitCode, in as emptyFixtureDocument, it as canvasRemoveCapabilityInputSchema, jt as hasCanvasReferenceScope, k as operationStatusInputSchema, kt as canvasReferenceRenderTarget, l as toSharedCapabilities, lr as canvasReadableSceneDocumentSchema, lt as canvasUpdateHtmlCapabilityInputSchema, m as createCapabilityPolicyAdapter, mr as canvasLayoutMainAxisOf, n as withCommandName, nn as createOrganisationOutputSchema, p as createRouterShapeAdapter, pr as canvasAxisStyleProperties, qn as MAX_CANVAS_OPERATIONS, r as toCanvasAuthoringResult, sr as RENDER_MIN_SCALE, st as canvasReadInputSchema, t as withCommandInFailure, tr as canvasWorldBoundsSchema, u as createMcpCapabilityDiscoveryAdapter, wr as canvasSchema, zt as appendRecordingChunkOutputSchema } from "./cli-output-identity.lib-DpON8As5.mjs";
3
+ import { _ as sceneAtVersion, b as createRenderCanvasComposite, d as createRenderFileAdapter, f as readCanvasReferenceScene, g as assertCanvasReferenceOperations, h as createEditCanvasComposite, m as fromCapabilityReference, n as createHttpRemoteAdapter, o as createOauthLoopbackAdapter, p as createWriteHtmlCanvasComposite, r as readCliEnvironment, s as createCapabilityInvocationAdapter, t as createMutationKeyAdapter, v as createApplyCanvasComposite, x as createAuthUseCase, y as createCanvasActivityComposite } from "./mutation-key.adapter-CXQ08HQY.mjs";
4
4
  import { t as toCapabilityInventory } from "./capability-inventory.mapper-DyYXyVBJ.mjs";
5
- import { t as createFileCredentialAdapter } from "./file-credential.adapter-rI5HpMEo.mjs";
5
+ import { t as createFileCredentialAdapter } from "./file-credential.adapter-C78gc9OK.mjs";
6
+ import process from "node:process";
6
7
  import { Command } from "commander";
7
8
  import { createCli, parseRouter } from "trpc-cli";
8
9
  import { z } from "zod";
9
10
  import { hostname, tmpdir } from "node:os";
10
- import process from "node:process";
11
11
  import { createInterface } from "node:readline";
12
12
  import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync } from "node:fs";
13
13
  import path from "node:path";
@@ -434,7 +434,7 @@ const applyAuthoringOperations = async (input, options, purpose, operations) =>
434
434
  selectAuthoringToken(input, options.clientToken, false);
435
435
  const reference = parseCanvasReference(options.canvas);
436
436
  const baseVersion = authoringBaseVersion(options.baseVersion);
437
- if (reference.nodeIds.length > 0) assertCanvasReferenceOperations(reference, await sceneAtVersion(input, reference.canvasId, baseVersion), operations);
437
+ if (hasCanvasReferenceScope(reference)) assertCanvasReferenceOperations(reference, await sceneAtVersion(input, reference.canvasId, baseVersion), operations);
438
438
  return createApplyCanvasComposite(input.remote).execute({
439
439
  canvasId: reference.canvasId,
440
440
  mutationId: authoringMutationId(input, purpose),
@@ -489,14 +489,6 @@ const createCanvasOperationInputAdapter = (value) => {
489
489
  return parsed.data;
490
490
  };
491
491
 
492
- //#endregion
493
- //#region src/infrastructure/capability-reference.mapper.ts
494
- const fromCapabilityReference = (catalog, id) => {
495
- const capability = catalog.find((candidate) => candidate.id === id);
496
- if (capability === void 0) throw new TypeError(`${id} is missing from the capability catalogue`);
497
- return capability;
498
- };
499
-
500
492
  //#endregion
501
493
  //#region src/infrastructure/canvas-apply.program.ts
502
494
  const positiveInteger$3 = z.coerce.number().int().positive();
@@ -512,7 +504,7 @@ const selectMutationToken = (input, value) => {
512
504
  return input.mutationKey.current("canvas.applyOperations", {});
513
505
  };
514
506
  const configureCanvasApply = (canvas, input) => {
515
- canvas.command("apply").description("Apply an atomic canvas edit batch and return its affected bounds.").requiredOption("--canvas <url-or-id>", "Canvas URL or UUID to edit.").requiredOption("--base-version <integer>", "Exact version returned by canvas inspect or tree.").requiredOption("--operations <json-or-@path>", "JSON operation array inline, or @path to a JSON file.").option("--client-token <uuid>", "Stable UUID to reuse only when retrying this exact batch.").addHelpText("after", [
507
+ canvas.command("apply").description("Apply an atomic canvas edit batch and return its affected bounds.").summary("Apply edits and return affected bounds.").requiredOption("--canvas <url-or-id>", "Canvas URL or UUID to edit.").requiredOption("--base-version <integer>", "Exact version returned by canvas inspect or tree.").requiredOption("--operations <json-or-@path>", "JSON operation array inline, or @path to a JSON file.").option("--client-token <uuid>", "Stable UUID to reuse only when retrying this exact batch.").addHelpText("after", [
516
508
  "",
517
509
  "Supported operations: insertNode, insertText, insertPrototype, setText, editText, setBox, setLabel, setVisibility, setLocked, setConstraints, setStyles, setAppearance, setLayout, patchTypography, setTypography, patchAdditionalStyles, setAdditionalStyles, setProps, setParentage, move, remove.",
518
510
  "Use editText for revision-aware character or range changes. setText replaces the whole text and is rejected if it conflicts with a newer text edit.",
@@ -523,7 +515,7 @@ const configureCanvasApply = (canvas, input) => {
523
515
  const reference = parseCanvasReference(options.canvas);
524
516
  const baseVersion = baseVersionFrom(options.baseVersion);
525
517
  const operations = createCanvasOperationInputAdapter(options.operations);
526
- if (reference.nodeIds.length > 0) assertCanvasReferenceOperations(reference, await sceneAtVersion(input, reference.canvasId, baseVersion), operations);
518
+ if (hasCanvasReferenceScope(reference)) assertCanvasReferenceOperations(reference, await sceneAtVersion(input, reference.canvasId, baseVersion), operations);
527
519
  const result = await input.invocation.invoke({
528
520
  capability: fromCapabilityReference(input.catalog(), "canvas.apply"),
529
521
  arguments: {
@@ -1179,21 +1171,43 @@ const configureCanvasAuthoringSource = (canvas, input) => {
1179
1171
 
1180
1172
  //#endregion
1181
1173
  //#region src/infrastructure/canvas-authoring-structure.program.ts
1182
- const configureDuplicate = (canvas, input) => {
1183
- canvas.command("duplicate-nodes").description("Deep-clone node subtrees.").requiredOption("--canvas <url-or-id>", "Canvas URL or UUID to edit.").requiredOption("--base-version <integer>", "Exact current canvas version.").requiredOption("--nodes <json-or-@path>", "Array of {id,parentId?} requests.").option("--id-prefix <prefix>", "Stable namespace for cloned ids.").option("--client-token <uuid>", "Stable UUID for retrying this exact batch.").action(async (options) => {
1184
- const result = await applyAuthoringEdits(input, options, createCanvasJsonInputAdapter(options.nodes, duplicateInputsSchema, "--nodes").map((node) => ({
1185
- kind: "duplicate",
1186
- nodeIds: [node.id],
1187
- ...node.parentId !== void 0 && { parentId: node.parentId }
1188
- })), options.idPrefix);
1189
- const { duplicatedNodes, ...apply } = result;
1190
- input.output.result({
1191
- ...result,
1192
- duplicatedNodes,
1193
- apply
1194
- });
1174
+ const executeDuplicate = async (input, options) => {
1175
+ if (options.input !== void 0) {
1176
+ if ([
1177
+ options.canvas,
1178
+ options.baseVersion,
1179
+ options.nodes,
1180
+ options.idPrefix
1181
+ ].some((value) => value !== void 0)) throw new CliError("BAD_REQUEST", "Choose --input or the individual duplicate options.", "Use --input with --client-token for native measured duplication.");
1182
+ const capability = fromCapabilityReference(input.catalog(), "canvas.duplicateNodes");
1183
+ input.output.result(await input.invocation.invoke({
1184
+ capability,
1185
+ arguments: createCanvasJsonInputAdapter(options.input, capability.inputSchema, "--input"),
1186
+ clientToken: z.uuid().parse(options.clientToken)
1187
+ }));
1188
+ return;
1189
+ }
1190
+ if (options.canvas === void 0 || options.baseVersion === void 0 || options.nodes === void 0) throw new CliError("BAD_REQUEST", "Duplicate needs --canvas, --base-version and --nodes, or --input.", "Run duplicate-nodes --help.");
1191
+ const edits = createCanvasJsonInputAdapter(options.nodes, duplicateInputsSchema, "--nodes").map((node) => ({
1192
+ kind: "duplicate",
1193
+ nodeIds: [node.id],
1194
+ ...node.parentId !== void 0 && { parentId: node.parentId }
1195
+ }));
1196
+ const result = await applyAuthoringEdits(input, {
1197
+ canvas: options.canvas,
1198
+ baseVersion: options.baseVersion,
1199
+ ...options.clientToken !== void 0 && { clientToken: options.clientToken }
1200
+ }, edits, options.idPrefix);
1201
+ const { duplicatedNodes, ...apply } = result;
1202
+ input.output.result({
1203
+ ...result,
1204
+ duplicatedNodes,
1205
+ apply
1195
1206
  });
1196
1207
  };
1208
+ const configureDuplicate = (canvas, input) => {
1209
+ canvas.command("duplicate-nodes").description("Deep-clone node subtrees; --input uses native measured layout and durable copy receipts.").option("--input <json-or-@path>", "Scoped native duplication request; requires --client-token.").option("--canvas <url-or-id>", "Canvas URL or UUID to edit.").option("--base-version <integer>", "Exact current canvas version.").option("--nodes <json-or-@path>", "Array of {id,parentId?} requests.").option("--id-prefix <prefix>", "Stable namespace for cloned ids.").option("--client-token <uuid>", "Stable UUID for retrying this exact batch.").action(async (options) => executeDuplicate(input, options));
1210
+ };
1197
1211
  const configureMove = (canvas, input) => {
1198
1212
  canvas.command("move-nodes").description("Reorder or reparent nodes.").requiredOption("--canvas <url-or-id>", "Canvas URL or UUID to edit.").requiredOption("--base-version <integer>", "Exact current canvas version.").requiredOption("--moves <json-or-@path>", "Sequential before, after, or parent/index moves.").option("--client-token <uuid>", "Stable UUID for retrying this exact batch.").action(async (options) => {
1199
1213
  const result = await applyAuthoringEdits(input, options, createCanvasJsonInputAdapter(options.moves, moveInputsSchema, "--moves").map((move) => ({
@@ -1257,6 +1271,7 @@ const writeHtml = async (input, options) => {
1257
1271
  capability: fromCapabilityReference(input.catalog(), "canvas.writeHtml"),
1258
1272
  arguments: {
1259
1273
  canvasId: reference.canvasId,
1274
+ ...reference.pageId !== void 0 && { pageId: reference.pageId },
1260
1275
  ...reference.nodeIds.length > 0 && { selectionNodeIds: [...reference.nodeIds] },
1261
1276
  targetNodeId: options.targetNodeId,
1262
1277
  mode,
@@ -1323,9 +1338,105 @@ const configureCanvasAuthoringWrites = (canvas, input) => {
1323
1338
  configureCreateArtboard(canvas, input);
1324
1339
  };
1325
1340
 
1341
+ //#endregion
1342
+ //#region src/infrastructure/canvas-conversion.program.ts
1343
+ const configureCanvasConversions = (canvas, input) => {
1344
+ for (const id of [
1345
+ "canvas.insertHtml",
1346
+ "canvas.makeEditable",
1347
+ "canvas.capture",
1348
+ "canvas.arrange"
1349
+ ]) {
1350
+ const capability = fromCapabilityReference(input.catalog(), id);
1351
+ const name = id === "canvas.insertHtml" ? "insert-html" : id === "canvas.makeEditable" ? "make-editable" : id.slice(7);
1352
+ canvas.command(name).description(capability.guide.summary).requiredOption("--input <json-or-@path>", "Canvas reference, base version and explicit native authoring request.").requiredOption("--client-token <uuid>", "Stable intent ID; reuse unchanged after an uncertain outcome.").action(async (options) => {
1353
+ input.output.result(await input.invocation.invoke({
1354
+ capability,
1355
+ arguments: createCanvasJsonInputAdapter(options.input, capability.inputSchema, "--input"),
1356
+ clientToken: z.uuid().parse(options.clientToken)
1357
+ }));
1358
+ });
1359
+ }
1360
+ };
1361
+
1362
+ //#endregion
1363
+ //#region src/infrastructure/canvas-exchange.program.ts
1364
+ const configureRemove = (canvas, input) => {
1365
+ canvas.command("remove").description("Remove explicitly named canvas subtrees with scope, lock and revision checks.").requiredOption("--input <json-or-@path>", "Request containing canvasRef, baseVersion and rootNodeIds.").requiredOption("--client-token <uuid>", "Stable intent ID; reuse unchanged after an uncertain outcome.").action(async (options) => {
1366
+ input.output.result(await input.invocation.invoke({
1367
+ capability: fromCapabilityReference(input.catalog(), "canvas.remove"),
1368
+ arguments: createCanvasJsonInputAdapter(options.input, canvasRemoveCapabilityInputSchema, "--input"),
1369
+ clientToken: z.uuid().parse(options.clientToken)
1370
+ }));
1371
+ });
1372
+ };
1373
+ const configureRead = (canvas, input) => {
1374
+ canvas.command("read").description("Read complete editable content, bounded evidence, or the supplied reference.").summary("Read linked canvas content.").option("--input <json-or-@path>", "Bounded read request containing canvasRef, view and target options.").option("--canvas <url-or-id>", "Complete canvas, page or selection URL for comprehensive reads.").option("--node-id <id>", "Subtree within --canvas; unavailable with --input.").action(async (options) => {
1375
+ if (options.input === void 0 === (options.canvas === void 0) || options.input !== void 0 && options.nodeId !== void 0) throw new CliError("BAD_REQUEST", "Choose exactly one of --input or --canvas; --node-id requires --canvas.", "Use --input for bounded views, or --canvas with an optional --node-id for comprehensive reads.");
1376
+ const request = options.input === void 0 ? {
1377
+ canvas: options.canvas,
1378
+ ...options.nodeId !== void 0 && { nodeId: options.nodeId }
1379
+ } : createCanvasJsonInputAdapter(options.input, canvasReadInputSchema, "--input");
1380
+ input.output.result(await input.invocation.invoke({
1381
+ capability: fromCapabilityReference(input.catalog(), "canvas.read"),
1382
+ arguments: request,
1383
+ clientToken: null
1384
+ }));
1385
+ });
1386
+ };
1387
+ const configureCanvasExchange = (canvas, input) => {
1388
+ canvas.command("find").description("Find accessible canvases and existing creation destinations with bounded results.").option("--input <json-or-@path>", "Search title, collection, limit and continuation cursor.", "{}").action(async (options) => {
1389
+ input.output.result(await input.invocation.invoke({
1390
+ capability: fromCapabilityReference(input.catalog(), "canvas.find"),
1391
+ arguments: createCanvasJsonInputAdapter(options.input, canvasFindInputSchema, "--input"),
1392
+ clientToken: null
1393
+ }));
1394
+ });
1395
+ configureRemove(canvas, input);
1396
+ configureRead(canvas, input);
1397
+ canvas.command("update-html").description("Apply an identity-preserving edit from a complete HTML snapshot.").requiredOption("--input <json-or-@path>", "Request containing canvasRef, snapshotToken, html and removeNodeIds.").requiredOption("--client-token <uuid>", "Stable intent ID; reuse unchanged after an uncertain outcome.").action(async (options) => {
1398
+ const request = createCanvasJsonInputAdapter(options.input, canvasUpdateHtmlCapabilityInputSchema, "--input");
1399
+ input.output.result(await input.invocation.invoke({
1400
+ capability: fromCapabilityReference(input.catalog(), "canvas.updateHtml"),
1401
+ arguments: request,
1402
+ clientToken: z.uuid().parse(options.clientToken)
1403
+ }));
1404
+ });
1405
+ };
1406
+
1407
+ //#endregion
1408
+ //#region src/infrastructure/canvas-prototype.program.ts
1409
+ const configureCanvasPrototype = (canvas, input) => {
1410
+ const capability = fromCapabilityReference(input.catalog(), "prototype.publishCanvas");
1411
+ canvas.command("publish-prototype").description(capability.guide.summary).requiredOption("--input <json-or-@path>", "Complete canvas reference, baseVersion, unpacked build directory or existing deployment, and bounded waitMs.").requiredOption("--client-token <uuid>", "Stable attachment intent; reuse the same arguments after uncertainty, use a new token after replanning.").action(async (options) => {
1412
+ input.output.result(await input.invocation.invoke({
1413
+ capability,
1414
+ arguments: createCanvasJsonInputAdapter(options.input, capability.inputSchema, "--input"),
1415
+ clientToken: z.uuid().parse(options.clientToken)
1416
+ }));
1417
+ });
1418
+ };
1419
+
1420
+ //#endregion
1421
+ //#region src/infrastructure/canvas-asset.program.ts
1422
+ const configureCanvasAsset = (canvas, input) => {
1423
+ const capability = fromCapabilityReference(input.catalog(), "canvas.importAsset");
1424
+ canvas.command("import-asset").description(capability.guide.summary).requiredOption("--input <json-or-@path>", "Canvas reference and selected local file source.").requiredOption("--client-token <uuid>", "Stable import intent; reuse after uncertainty.").action(async (options) => {
1425
+ input.output.result(await input.invocation.invoke({
1426
+ capability,
1427
+ arguments: createCanvasJsonInputAdapter(options.input, capability.inputSchema, "--input"),
1428
+ clientToken: z.uuid().parse(options.clientToken)
1429
+ }));
1430
+ });
1431
+ };
1432
+
1326
1433
  //#endregion
1327
1434
  //#region src/infrastructure/canvas-authoring.program.ts
1328
1435
  const configureCanvasAuthoring = (canvas, input) => {
1436
+ configureCanvasExchange(canvas, input);
1437
+ configureCanvasPrototype(canvas, input);
1438
+ configureCanvasAsset(canvas, input);
1439
+ configureCanvasConversions(canvas, input);
1329
1440
  configureCanvasAuthoringSource(canvas, input);
1330
1441
  configureCanvasAuthoringWrites(canvas, input);
1331
1442
  configureCanvasAuthoringEdits(canvas, input);
@@ -1352,33 +1463,16 @@ const nodeIdFor = (command, reference) => {
1352
1463
  return nodeId;
1353
1464
  };
1354
1465
  const readLinkedSelection = async (command, input, reference, url) => {
1355
- const held = getCanvasDocumentOutputSchema.parse(await input.remote.query("canvas.document.get", { canvasId: reference.canvasId }));
1356
- const document = canvasReadableSceneDocumentSchema.parse(held.document);
1357
- const scope = canvasReferenceNodeIds(reference, document);
1358
- const nodes = Object.values(document.nodes).filter((node) => scope.has(node.id)).map((node) => ({
1359
- ...node,
1360
- kind: node.component,
1361
- parentId: document.relationships[node.id]?.parentId ?? null,
1362
- children: Object.entries(document.relationships).filter(([, relation]) => relation.parentId === node.id).map(([id]) => id)
1363
- }));
1364
- const context = {
1365
- canvasId: reference.canvasId,
1366
- version: held.version,
1367
- source: "selection-link",
1368
- selectedNodeIds: reference.nodeIds,
1369
- next: [`Keep this selection link as --canvas for every edit: ${url}`, "Edit only these nodes or their descendants; other canvas content is outside the request."]
1370
- };
1371
- if (command.name() === "node") {
1372
- const nodeId = nodeIdFor(command, reference);
1373
- assertCanvasReferenceNodes(reference, document, [nodeId]);
1374
- return {
1375
- ...context,
1376
- node: nodes.find((node) => node.id === nodeId)
1377
- };
1378
- }
1466
+ const nodeId = command.name() === "node" ? nodeIdFor(command, reference) : void 0;
1467
+ const context = await readCanvasReferenceScene(input.remote, {
1468
+ canvas: url,
1469
+ ...nodeId !== void 0 && { nodeId }
1470
+ });
1471
+ if (nodeId === void 0) return context;
1472
+ const { nodes, ...metadata } = context;
1379
1473
  return {
1380
- ...context,
1381
- nodes
1474
+ ...metadata,
1475
+ node: nodes.find((node) => node.id === nodeId)
1382
1476
  };
1383
1477
  };
1384
1478
  const configureCanvasInspection = (canvas, input) => {
@@ -1396,7 +1490,7 @@ const configureCanvasInspection = (canvas, input) => {
1396
1490
  command.option("--canvas <url-or-id>", "Pasted canvas URL or UUID. Selection links limit reads and edits to the linked subtree.");
1397
1491
  command.action(async () => {
1398
1492
  const { reference, url } = referenceFor(command);
1399
- const result = reference.nodeIds.length > 0 ? await readLinkedSelection(command, input, reference, url) : await input.remote.query(`canvas.${name}`, {
1493
+ const result = hasCanvasReferenceScope(reference) ? await readLinkedSelection(command, input, reference, url) : await input.remote.query(`canvas.${name}`, {
1400
1494
  canvasId: reference.canvasId,
1401
1495
  ...name === "node" && { nodeId: nodeIdFor(command, reference) }
1402
1496
  });
@@ -1405,6 +1499,17 @@ const configureCanvasInspection = (canvas, input) => {
1405
1499
  }
1406
1500
  };
1407
1501
 
1502
+ //#endregion
1503
+ //#region src/infrastructure/canvas-render-input.adapter.ts
1504
+ const createCanvasRenderInputAdapter = (options) => {
1505
+ if (options.input === void 0) return null;
1506
+ if (options.canvas !== void 0 || options.nodeId !== void 0 || options.bounds !== void 0 || options.expectedVersion !== void 0 || options.atMs !== void 0 || options.output !== void 0 || options.force === true || options.scale !== "1" || options.timeoutMs !== "120000") throw new CliError("BAD_REQUEST", "The bounded --input request cannot be combined with individual render options.", "Put the entire scoped render request in --input.");
1507
+ return {
1508
+ arguments: createCanvasJsonInputAdapter(options.input, canvasRenderScopedInputSchema, "--input"),
1509
+ clientToken: z.uuid().parse(options.clientToken)
1510
+ };
1511
+ };
1512
+
1408
1513
  //#endregion
1409
1514
  //#region src/infrastructure/canvas.program.ts
1410
1515
  const positiveInteger$2 = z.coerce.number().int().positive();
@@ -1445,19 +1550,26 @@ const selectClientToken = (input, value) => {
1445
1550
  input.mutationKey.select(clientToken.data, false);
1446
1551
  return input.mutationKey.current("canvas.render.create", {});
1447
1552
  };
1448
- const selectedRenderNode = async (options, input) => {
1553
+ const selectedRenderTarget = async (options, input) => {
1449
1554
  const reference = parseCanvasReference(options.canvas ?? "");
1450
- if (reference.nodeIds.length === 0) return options.nodeId;
1451
- const nodeId = options.nodeId ?? (reference.nodeIds.length === 1 ? reference.nodeIds[0] : void 0);
1452
- if (nodeId === void 0 || options.bounds !== void 0) throw new CliError("BAD_REQUEST", "A selection link requires one selected node to render.", "Pass --node-id for one node in the selection; bounds and whole-canvas renders would include unrelated content.");
1555
+ const target = targetFrom(options.nodeId, boundsFrom(options.bounds));
1556
+ const expectedVersion = options.expectedVersion === void 0 ? null : numberFrom(positiveInteger$2, options.expectedVersion, "--expected-version");
1557
+ if (!hasCanvasReferenceScope(reference)) return {
1558
+ target,
1559
+ expectedVersion
1560
+ };
1453
1561
  const held = getCanvasDocumentOutputSchema.parse(await input.remote.query("canvas.document.get", { canvasId: reference.canvasId }));
1454
- assertCanvasReferenceNodes(reference, canvasReadableSceneDocumentSchema.parse(held.document), [nodeId]);
1455
- return nodeId;
1562
+ if (expectedVersion !== null && expectedVersion !== held.version) throw new CliError("CONFLICT", "The canvas changed before rendering.", "Read the linked page or selection and render its current version.");
1563
+ return {
1564
+ target: canvasReferenceRenderTarget(reference, canvasReadableSceneDocumentSchema.parse(held.document), target),
1565
+ expectedVersion: held.version
1566
+ };
1456
1567
  };
1457
1568
  const executeRender = async (options, input) => {
1458
1569
  if (options.canvas === void 0) throw new CliError("BAD_REQUEST", "--canvas is required.", "Pass a pasted Enhance canvas URL or bare UUID through --canvas.");
1459
1570
  if (options.nodeId !== void 0 && options.bounds !== void 0) throw new CliError("BAD_REQUEST", "--node-id and --bounds cannot be combined.", "Choose one focused target, or omit both to render all authored content.");
1460
- const nodeId = await selectedRenderNode(options, input);
1571
+ const resolved = await selectedRenderTarget(options, input);
1572
+ const nodeId = resolved.target.kind === "node" ? resolved.target.nodeId : void 0;
1461
1573
  if (nodeId === void 0 && options.atMs !== void 0) throw new CliError("BAD_REQUEST", "--at-ms requires --node-id.", "Render the stable recording node returned by `enhance canvas tree`.");
1462
1574
  const recordingId = options.atMs === void 0 ? null : recordingIdFrom(nodeId);
1463
1575
  if (recordingId === void 0 && options.atMs !== void 0) throw new CliError("BAD_REQUEST", "--at-ms requires a stable recording node id such as rec_<recording-uuid>.", "Run `enhance canvas tree --canvas <url-or-id>` and choose a recording node.");
@@ -1466,8 +1578,7 @@ const executeRender = async (options, input) => {
1466
1578
  capability: fromCapabilityReference(input.catalog(), "canvas.render"),
1467
1579
  arguments: {
1468
1580
  canvasId: parseCanvasReference(options.canvas).canvasId,
1469
- expectedVersion: options.expectedVersion === void 0 ? null : numberFrom(positiveInteger$2, options.expectedVersion, "--expected-version"),
1470
- target: targetFrom(nodeId, boundsFrom(options.bounds)),
1581
+ ...resolved,
1471
1582
  sourceState: recordingId === null || recordingId === void 0 ? null : {
1472
1583
  kind: "recording",
1473
1584
  recordingId,
@@ -1483,11 +1594,19 @@ const executeRender = async (options, input) => {
1483
1594
  input.output.result(result);
1484
1595
  };
1485
1596
  const configureRender = (render, input) => {
1486
- render.option("--canvas <url-or-id>", "Canvas URL or UUID to render.").option("--node-id <id>", "Render one stable canvas node instead of all authored content.").option("--bounds <json>", "Render an explicit rectangle in canvas world coordinates.").option("--expected-version <integer>", "Refuse pixels from any other document version.").option("--at-ms <integer>", "Pause a recording node at this millisecond; inspect the PNG before snapshotting it.").option("--scale <number>", "Output pixels per canvas unit, from 0.1 to 4.", "1").option("--output <path>", "Write the PNG to this path instead of a protected temporary file.").option("--force", "Replace an existing --output file deliberately.", false).option("--timeout-ms <integer>", "Local polling deadline in milliseconds.", "120000").option("--client-token <uuid>", "Stable UUID to reuse only when retrying this render request.").addHelpText("after", "\nFor transcript-led selection, inspect nearby --at-ms renders and reject transitions or duplicate states before running recording snapshot.\n").action(async (options) => executeRender(options, input));
1597
+ render.option("--input <json-or-@path>", "Bounded scoped render request; requires --client-token.").option("--canvas <url-or-id>", "Canvas URL or UUID to render.").option("--node-id <id>", "Render one stable canvas node instead of all authored content.").option("--bounds <json>", "Render an explicit rectangle in canvas world coordinates.").option("--expected-version <integer>", "Refuse pixels from any other document version.").option("--at-ms <integer>", "Pause a recording node at this millisecond; inspect the PNG before snapshotting it.").option("--scale <number>", "Output pixels per canvas unit, from 0.1 to 4.", "1").option("--output <path>", "Write the PNG to this path instead of a protected temporary file.").option("--force", "Replace an existing --output file deliberately.", false).option("--timeout-ms <integer>", "Local polling deadline in milliseconds.", "120000").option("--client-token <uuid>", "Stable UUID to reuse only when retrying this render request.").addHelpText("after", "\nFor transcript-led selection, inspect nearby --at-ms renders and reject transitions or duplicate states before running recording snapshot.\n").action(async (options) => {
1598
+ const bounded = createCanvasRenderInputAdapter(options);
1599
+ if (bounded === null) return executeRender(options, input);
1600
+ input.output.result(await input.invocation.invoke({
1601
+ capability: fromCapabilityReference(input.catalog(), "canvas.render"),
1602
+ ...bounded
1603
+ }));
1604
+ });
1487
1605
  };
1488
1606
  const registerCanvasProgram = (program, input) => {
1489
1607
  const canvas = program.commands.find((command) => command.name() === "canvas");
1490
1608
  if (canvas === void 0) throw new TypeError("the API router did not supply canvas commands");
1609
+ canvas.configureHelp({ subcommandTerm: (command) => command.name() });
1491
1610
  const render = canvas.commands.find((command) => command.name() === "render");
1492
1611
  if (render === void 0) throw new TypeError("the API router did not supply canvas render");
1493
1612
  const composite = createRenderCanvasComposite(input.remote, createRenderFileAdapter(input.configDirectory), input.now, input.output.result);
@@ -1503,29 +1622,44 @@ const registerCanvasProgram = (program, input) => {
1503
1622
  //#endregion
1504
1623
  //#region src/infrastructure/command-summaries.consts.ts
1505
1624
  const COMMAND_SUMMARIES = {
1506
- "canvas.createEditableFrame": "Insert editable primitives beside a source screen.",
1507
- "canvas.create": "Create a canvas and return its id.",
1508
- "canvas.get": "Read one canvas and viewer access.",
1625
+ "canvas chats": "Chat history.",
1626
+ "canvas.createEditableFrame": "Make a screen editable.",
1627
+ "canvas.create": "Create a canvas.",
1628
+ "canvas.get": "Read a canvas and access.",
1509
1629
  "canvas.setAccess": "Change canvas link access.",
1510
1630
  "canvas.markViewed": "Mark a canvas as viewed.",
1511
- "canvas.list": "Find canvases by shelf, title, access, or state.",
1631
+ "canvas.list": "List canvases.",
1512
1632
  "canvas.rename": "Rename a canvas.",
1513
- "canvas.setReviewState": "Change your canvas review state.",
1514
- "canvas.delete": "Move a canvas to its recoverable bin.",
1515
- "canvas.move": "Move a canvas between shelves.",
1516
- "canvas.duplicate": "Copy a canvas into a shelf.",
1517
- "canvas.deletePermanently": "Permanently delete a binned canvas.",
1633
+ "canvas.setReviewState": "Set review state.",
1634
+ "canvas.delete": "Bin a canvas.",
1635
+ "canvas.move": "Move between shelves.",
1636
+ "canvas.duplicate": "Copy a canvas.",
1637
+ "canvas.deletePermanently": "Permanently delete a canvas.",
1518
1638
  "canvas.restore": "Restore a binned canvas.",
1519
- "canvas.inspect": "Read canvas URL, structure, and next steps.",
1520
- "canvas.tree": "List canvas node ids, hierarchy, kinds, and boxes.",
1521
- "canvas.node": "Read one canvas node and its children.",
1522
- "canvas.selection": "Read the person’s current live browser selection.",
1523
- "canvas text-style-library": "Discover and publish text styles.",
1639
+ "canvas.inspect": "Inspect a canvas.",
1640
+ "canvas.tree": "Read the node hierarchy.",
1641
+ "canvas.node": "Read a node and children.",
1642
+ "canvas.selection": "Read the live selection.",
1643
+ "canvas asset": "Manage uploaded assets.",
1644
+ "canvas mutation": "Read mutation receipts.",
1645
+ "canvas apply": "Apply canvas operations.",
1646
+ "canvas find": "Find accessible canvases.",
1647
+ "canvas remove": "Remove scoped subtrees.",
1648
+ "canvas read": "Read linked content.",
1649
+ "canvas update-html": "Update an HTML snapshot.",
1650
+ "canvas publish-prototype": "Publish a static build.",
1651
+ "canvas import-asset": "Import an image or font.",
1652
+ "canvas insert-html": "Insert compiled HTML.",
1653
+ "canvas make-editable": "Convert a captured screen.",
1654
+ "canvas capture": "Capture a recording moment.",
1655
+ "canvas arrange": "Arrange canvas objects.",
1656
+ "canvas duplicate-nodes": "Duplicate node subtrees.",
1657
+ "canvas text-style-library": "Manage text styles.",
1524
1658
  "canvas realtime": "Canvas presence and activity.",
1525
- "canvas document": "Read or replace a canvas document.",
1659
+ "canvas document": "Read or replace documents.",
1526
1660
  "canvas version": "Retained canvas history.",
1527
- "canvas render": "Create and inspect faithful canvas renders.",
1528
- "canvas participants": "List and change canvas participants.",
1661
+ "canvas render": "Render canvas pixels.",
1662
+ "canvas participants": "Manage participants.",
1529
1663
  "canvas invites": "Invite people to a canvas."
1530
1664
  };
1531
1665
 
@@ -1560,7 +1694,8 @@ const createProcessAdapter = () => ({ exit: (code) => {
1560
1694
  //#region src/infrastructure/cli-polish.lib.ts
1561
1695
  const NAMESPACES = {
1562
1696
  "canvas text-style-library": "Find, read, and publish reusable text styles across canvases.",
1563
- canvas: "Canvases: create, find, share, and manage review surfaces.",
1697
+ "canvas chats": "Inspect and manage authorized canvas chat history.",
1698
+ canvas: "Create, find, share and manage canvases.",
1564
1699
  "canvas render": "Render production-faithful canvas pixels after inspecting exact structure and geometry.",
1565
1700
  "canvas version": "Inspect and name retained canvas history.",
1566
1701
  "canvas document": "Read or replace the opaque document stored on a canvas.",
@@ -1871,6 +2006,18 @@ const registerFixtureProgram = (program, composites, output) => {
1871
2006
  registerWorldFixture(fixture, composites.world, output);
1872
2007
  };
1873
2008
 
2009
+ //#endregion
2010
+ //#region src/infrastructure/operation.program.ts
2011
+ const registerOperationProgram = (program, input) => {
2012
+ program.command("operation").description("Read existing domain-owned operation outcomes.").command("status").description("Recover an existing outcome without creating or resuming work.").requiredOption("--input <json-or-@path>", "Operation reference and optional detail offset/limit.").action(async (options) => {
2013
+ input.output.result(await input.invocation.invoke({
2014
+ capability: fromCapabilityReference(input.catalog(), "operation.status"),
2015
+ arguments: createCanvasJsonInputAdapter(options.input, operationStatusInputSchema, "--input"),
2016
+ clientToken: null
2017
+ }));
2018
+ });
2019
+ };
2020
+
1874
2021
  //#endregion
1875
2022
  //#region src/infrastructure/prototype.program.ts
1876
2023
  const finiteNumber = (value) => z.coerce.number().parse(value);
@@ -1989,8 +2136,7 @@ const descriptionFrom = (meta) => {
1989
2136
  const description = record === null ? void 0 : record["description"];
1990
2137
  return typeof description === "string" && description !== "" ? description : null;
1991
2138
  };
1992
- const cliMetadataFrom = (source) => {
1993
- const procedures = parseRouter({ router: source });
2139
+ const cliMetadataFrom = (procedures) => {
1994
2140
  return {
1995
2141
  descriptions: new Map(procedures.flatMap(([path, info]) => {
1996
2142
  const description = descriptionFrom(info.meta);
@@ -2017,6 +2163,11 @@ const registerUtilityPrograms = (program, input, catalog) => {
2017
2163
  });
2018
2164
  registerAuthProgram(program, createAuthUseCase(input.credentials, input.remote, createOauthLoopbackAdapter(input.remote)), input.output);
2019
2165
  registerCommentProgram(program, invocation, catalog, input.output);
2166
+ registerOperationProgram(program, {
2167
+ invocation,
2168
+ catalog,
2169
+ output: input.output
2170
+ });
2020
2171
  registerDoctorProgram(program, {
2021
2172
  version: input.version,
2022
2173
  credentials: input.credentials,
@@ -2051,11 +2202,11 @@ const registerUtilityPrograms = (program, input, catalog) => {
2051
2202
  });
2052
2203
  };
2053
2204
  const createCliProgram = (input) => {
2054
- const source = createRouterShapeAdapter();
2205
+ const procedures = parseRouter({ router: createRouterShapeAdapter() });
2055
2206
  const catalog = createLazyCapabilityCatalog();
2056
- const { descriptions, mutationPaths } = cliMetadataFrom(source);
2207
+ const { descriptions, mutationPaths } = cliMetadataFrom(procedures);
2057
2208
  const cli = createCli({
2058
- router: createRemoteRouterAdapter(source, input.remote),
2209
+ router: createRemoteRouterAdapter(procedures, input.remote),
2059
2210
  name: input.commandName,
2060
2211
  version: input.version,
2061
2212
  description: "Operate Enhance as the authenticated person.",
@@ -2109,6 +2260,7 @@ const isObject = (value) => typeof value === "object" && value !== null && !Arra
2109
2260
  const linesFor = (value) => {
2110
2261
  if (Array.isArray(value)) return value.map((entry) => JSON.stringify(entry));
2111
2262
  if (!isObject(value) || !Array.isArray(value["items"])) return [JSON.stringify(value)];
2263
+ if ("nextCursor" in value) return [JSON.stringify(value)];
2112
2264
  const items = value["items"];
2113
2265
  if (items.length === 0) return [JSON.stringify(value)];
2114
2266
  const isTruncated = value["truncated"] === true;
@@ -2313,22 +2465,23 @@ const createNdjsonLoggerAdapter = (state, configDirectory, commandName = "enhanc
2313
2465
  //#endregion
2314
2466
  //#region src/main.ts
2315
2467
  const main = async () => {
2468
+ const config = readCliEnvironment();
2316
2469
  const state = {
2317
2470
  exitCode: 1,
2318
2471
  pendingParserMessage: null
2319
2472
  };
2320
- const output = createNdjsonLoggerAdapter(state, CLI_CONFIG.configDirectory, CLI_CONFIG.commandName);
2321
- const credentials = createFileCredentialAdapter(CLI_CONFIG.configDirectory);
2473
+ const output = createNdjsonLoggerAdapter(state, config.configDirectory, config.commandName);
2474
+ const credentials = createFileCredentialAdapter(config.configDirectory);
2322
2475
  const mutationKey = createMutationKeyAdapter();
2323
2476
  const cli = createCliProgram({
2324
- version: "0.1.22",
2477
+ version: "0.1.25",
2325
2478
  credentials,
2326
- remote: createHttpRemoteAdapter(CLI_CONFIG.apiUrl, credentials, mutationKey),
2479
+ remote: createHttpRemoteAdapter(config.apiUrl, credentials, mutationKey),
2327
2480
  mutationKey,
2328
2481
  output,
2329
2482
  state,
2330
- configDirectory: CLI_CONFIG.configDirectory,
2331
- commandName: CLI_CONFIG.commandName
2483
+ configDirectory: config.configDirectory,
2484
+ commandName: config.commandName
2332
2485
  });
2333
2486
  try {
2334
2487
  await cli.run();
@@ -2338,7 +2491,10 @@ const main = async () => {
2338
2491
  exitProcess(1);
2339
2492
  }
2340
2493
  };
2341
- main();
2494
+ main().catch((error) => {
2495
+ process.stderr.write(`${error instanceof Error ? error.message : "CLI startup failed."}\n`);
2496
+ process.exitCode = 1;
2497
+ });
2342
2498
 
2343
2499
  //#endregion
2344
2500
  export { };