@lotics/cli 0.106.0 → 0.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -57,5 +57,20 @@ whether something exists, read `lotics --help` § COMMANDS — the whole section
57
57
  half — an agent's `tool_names`/`inputs`/`outputs`, a workflow's schemas — is authored by the
58
58
  `set_app_*` tools. A manifest alias with no server binding only fails at the app's first call, so
59
59
  deploy warns about the mismatch.
60
+
61
+ **The five `lotics.*` keys look alike and point in three different directions.** Before editing one,
62
+ know which you are touching — this is the single most expensive thing to get wrong in a manifest:
63
+
64
+ | `lotics.<key>` | Owned by | Your edit reaches the app via |
65
+ |---|---|---|
66
+ | `queries`, `capabilities` | the manifest | `app deploy` — re-synced on every one (an absent `capabilities` block turns them all OFF) |
67
+ | `knowledge`, `config` | the manifest | `opctl app publish` / `app release` — package authoring only |
68
+ | `workflows` | the workflow row's verified contract | `app workflow set`, which type-checks the BODY against your declaration and refuses a schema the body cannot satisfy |
69
+ | `agents` | the app row | **nothing.** It is a mirror: `app codegen` re-silvers it from the app, and an agent is changed with `set_app_agent` |
70
+
71
+ `agents` is the one that bites, because editing a mirror still retypes `useAgentRun` — green
72
+ locally, unchanged in production. `app codegen` reverts such an edit and `app deploy` refuses while
73
+ the two disagree. An agent's PROSE is not in the manifest at all: it lives in
74
+ `src/agents/<alias>.md` and is pushed by `app agent set`.
60
75
  - **OAuth connections.** Attaching a connected account is web-only; the CLI can list them.
61
76
  - **Anything needing a browser.** `app dev` and `file preview` shell out to a local Chrome.
package/README.md CHANGED
@@ -209,6 +209,11 @@ lotics app versions app_... # ...for any app, without pulling it
209
209
  # use this after a rename, or when a pull ran offline.
210
210
  lotics app codegen # import { F, OPT } from "../.lotics/app_fields"
211
211
 
212
+ # Every deploy pre-flight, WITHOUT the build or the version row: agent schemas vs
213
+ # the live app, aliases the code calls that nothing bound, undeclared capabilities,
214
+ # query drift. Exits 1 on what a deploy refuses, so CI can gate on it.
215
+ lotics app check
216
+
212
217
  # Execute a bound app workflow end-to-end (inputs: inline / @file / stdin)
213
218
  lotics app workflow run issueInvoice '{"record_id":"rec_..."}'
214
219
  cat inputs.json | lotics app workflow run importRates # bulk inputs bypass ARG_MAX
package/dist/src/cli.js CHANGED
@@ -45332,7 +45332,7 @@ import { randomUUID } from "node:crypto";
45332
45332
  import { tmpdir } from "node:os";
45333
45333
 
45334
45334
  // src/starter_template.ts
45335
- var STARTER_FALLBACK_UI_VERSION = "12.1.0";
45335
+ var STARTER_FALLBACK_UI_VERSION = "27.11.0";
45336
45336
  var STARTER_FALLBACK_SDK_VERSION = "0.52.0";
45337
45337
  var STARTER_REACT_NATIVE_VERSION = "0.85.3";
45338
45338
  var VITEST_SETUP_FILENAME = "vitest.setup.ts";
@@ -45486,7 +45486,7 @@ function buildStarterTemplate(args) {
45486
45486
  import { defineConfig } from "vite";
45487
45487
  import type { Plugin } from "vite";
45488
45488
  import react from "@vitejs/plugin-react";
45489
- import { loticsOptimizeDeps } from "@lotics/ui/vite";
45489
+ import { loticsOptimizeDeps, loticsResolve } from "@lotics/ui/vite";
45490
45490
 
45491
45491
  // @lotics/ui/icon.tsx deep-imports \`lucide-react-native/dist/esm/icons/<name>\`.
45492
45492
  // lucide-react-native's \`exports\` map lists only "." and "./icons", so a strict
@@ -45515,11 +45515,6 @@ function lucideIconsWebAlias(): Plugin {
45515
45515
  // render endpoint rewrites those to /v1/apps/{id}/asset/... so the bundle
45516
45516
  // loads via the platform's asset proxy. Don't change \`base\` unless you
45517
45517
  // also adjust the rewrite logic in backend/api/apps.ts:rewriteAssetPaths.
45518
- //
45519
- // react-native \u2192 react-native-web alias lets @lotics/ui's RN primitives
45520
- // (View, Text, Pressable, StyleSheet, etc.) render in a pure-web environment.
45521
- // .web.tsx is prioritized in resolve.extensions so per-target variants
45522
- // (avatar.web.tsx, wave_avatar.web.tsx) win over the native .tsx file.
45523
45518
  export default defineConfig({
45524
45519
  plugins: [lucideIconsWebAlias(), react()],
45525
45520
  // RN libraries reference globals Metro injects but Vite does not \u2014 undefined
@@ -45531,41 +45526,18 @@ export default defineConfig({
45531
45526
  // rn-web only reads \`global.x\` as a free var, so mapping it to \`globalThis\`
45532
45527
  // is safe. Define both so dev and the deployed build behave identically.
45533
45528
  define: { __DEV__: "false", global: "globalThis" },
45534
- resolve: {
45535
- // \`LOTICS_UI_SRC\` dev-links @lotics/ui to a monorepo checkout, so kit edits
45536
- // go live (HMR) and bundle on deploy without a publish round-trip:
45537
- // LOTICS_UI_SRC=/abs/path/to/packages/ui/src lotics app dev
45538
- // Unset \u21D2 the kit resolves from node_modules as normal. It lives in the ENV,
45539
- // never in this file: the link used to be written here by \`lotics ui link\`
45540
- // and removed by \`--remove\`, which is a regex editing TypeScript \u2014 it twice
45541
- // took the react-native alias below with it and left the app unable to build.
45542
- // State that only exists for the length of one command belongs in the command.
45543
- // VITE ONLY: \`tsc\` still resolves @lotics/ui from node_modules (the kit's
45544
- // src is RN-Web and cannot typecheck inside an app), so typecheck the kit in
45545
- // packages/ui and let the publish restore this app's own typecheck.
45546
- alias: [
45547
- ...(process.env.LOTICS_UI_SRC
45548
- ? [{ find: /^@lotics\\/ui\\/(.+)$/, replacement: \`\${process.env.LOTICS_UI_SRC}/$1\` }]
45549
- : []),
45550
- { find: "react-native", replacement: "react-native-web" },
45551
- ],
45552
- // \`.web.js\` resolves the web build of RN packages that ship \`X.js\` (native)
45553
- // beside \`X.web.js\` (web) \u2014 e.g. @react-native-picker/picker, whose compiled
45554
- // \`Picker.web.js\` renders a real <select>. Without it the extensionless
45555
- // \`require("./Picker")\` picks native \`Picker.js\` and the standard Picker
45556
- // renders nothing on web.
45557
- // \`.mjs\`/\`.mts\` keep parity with Vite's DEFAULT resolver, which this override
45558
- // otherwise drops \u2014 a bare package subpath that ships ONLY as \`.mjs\` (e.g.
45559
- // \`lucide-react/dynamic\`, imported by @lotics/ui's DynamicIcon/AppIcon) would
45560
- // fail to resolve under \`lotics app dev\` while the prod rollup build resolves
45561
- // it, so the gap is dev-only and silent (build/typecheck/lint stay green).
45562
- extensions: [".web.tsx", ".web.ts", ".web.js", ".tsx", ".ts", ".jsx", ".js", ".mjs", ".mts"],
45563
- // @lotics/ui ships source and is consumed across many subpath entries
45564
- // (./card, ./metric, ./use_screen_size, \u2026). Without dedupe, Vite can
45565
- // pre-bundle a subpath into its own chunk with a second React copy \u2014 a
45566
- // hook called from there hits a null dispatcher ("Invalid hook call").
45567
- // Pin React (and RN-Web) to a single instance shared by every chunk.
45568
- dedupe: ["react", "react-dom", "react-native-web"],
45529
+ // The kit owns its own resolution \u2014 the react-native \u2192 react-native-web alias,
45530
+ // \`.web.tsx\`-first extensions, the React dedupe, and the \`LOTICS_UI_SRC\`
45531
+ // dev-link \u2014 for the same reason it owns \`loticsOptimizeDeps\`: every entry is
45532
+ // dictated by @lotics/ui's internals, so shipping it WITH the kit means it can
45533
+ // never drift from the version installed here. It also stops being an app's job
45534
+ // to hand-carry a load-bearing alias that a regex edit twice deleted (GAP-133/142).
45535
+ // \`lotics app codegen\` writes the matching \`paths\` into
45536
+ // .lotics/tsconfig.link.json, so tsc/vitest/eslint/your editor resolve the same
45537
+ // @lotics/ui this does. To add your own alias, spread it:
45538
+ // const base = loticsResolve();
45539
+ // resolve: { ...base, alias: [...base.alias, { find: "x", replacement: "y" }] }
45540
+ resolve: loticsResolve(),
45569
45541
  },
45570
45542
  optimizeDeps: {
45571
45543
  // The dev dep-optimizer must pre-bundle @lotics/ui's RN-ecosystem + markdown
@@ -45942,48 +45914,6 @@ declare module "lucide-react-native/dist/esm/icons/*" {
45942
45914
 
45943
45915
  // Plain side-effect CSS imports (@lotics/ui ships .tsx with import "./x.css").
45944
45916
  declare module "*.css";
45945
- `
45946
- },
45947
- {
45948
- path: "src/react_native.d.ts",
45949
- content: `import "react-native";
45950
-
45951
- // Augments react-native's types with the web-only fields @lotics/ui consumes:
45952
- // Pressable's \`hovered\` callback state, plus web-only ViewStyle / TextStyle
45953
- // properties (cursor, outline, boxShadow, etc.) used by its primitives.
45954
- // Each iframe app needs its own copy \u2014 TypeScript doesn't auto-pick-up
45955
- // \`.d.ts\` files inside dependencies.
45956
- declare module "react-native" {
45957
- interface PressableStateCallbackType {
45958
- hovered: boolean;
45959
- }
45960
-
45961
- interface ViewStyle {
45962
- backdropFilter?: string;
45963
- backgroundImage?: string;
45964
- boxShadow?: string;
45965
- boxSizing?: string;
45966
- cursor?: string;
45967
- touchAction?: string;
45968
- transitionDuration?: string;
45969
- transitionProperty?: string;
45970
- appearance?: string;
45971
- outline?: string;
45972
- outlineColor?: string;
45973
- outlineStyle?: string;
45974
- outlineWidth?: number;
45975
- outlineOffset?: number;
45976
- }
45977
-
45978
- interface TextStyle {
45979
- outline?: string;
45980
- outlineColor?: string;
45981
- outlineStyle?: string;
45982
- outlineWidth?: number;
45983
- outlineOffset?: number;
45984
- appearance?: string;
45985
- }
45986
- }
45987
45917
  `
45988
45918
  },
45989
45919
  {
@@ -70180,11 +70110,58 @@ async function fetchLatestNpmVersion(packageName) {
70180
70110
  return null;
70181
70111
  }
70182
70112
  }
70113
+ function orderedLike(value, template) {
70114
+ if (Array.isArray(value)) {
70115
+ const t = Array.isArray(template) ? template : [];
70116
+ return value.map((v, i2) => orderedLike(v, t[i2]));
70117
+ }
70118
+ if (value === null || typeof value !== "object") return value;
70119
+ const from = value;
70120
+ const tmpl = template !== null && typeof template === "object" && !Array.isArray(template) ? template : {};
70121
+ const has2 = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
70122
+ const first3 = Object.keys(tmpl).filter((k) => has2(from, k));
70123
+ const taken = new Set(first3);
70124
+ const rest = Object.keys(from).filter((k) => !taken.has(k));
70125
+ return Object.fromEntries(
70126
+ [...first3, ...rest].map((k) => [k, orderedLike(from[k], tmpl[k])])
70127
+ );
70128
+ }
70183
70129
  function toManifestAgents(agents) {
70184
70130
  return Object.fromEntries(
70185
70131
  Object.entries(agents).map(([alias, { instructions: _prose, ...typed }]) => [alias, typed])
70186
70132
  );
70187
70133
  }
70134
+ var AGENT_TYPED_KEYS = ["inputs", "outputs"];
70135
+ function sameSchema(a, b) {
70136
+ const canonical = (v) => {
70137
+ if (Array.isArray(v)) return v.map(canonical);
70138
+ if (v && typeof v === "object") {
70139
+ return Object.fromEntries(
70140
+ Object.entries(v).sort(([x2], [y]) => x2 < y ? -1 : x2 > y ? 1 : 0).map(([k, val]) => [k, canonical(val)])
70141
+ );
70142
+ }
70143
+ return v;
70144
+ };
70145
+ return JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
70146
+ }
70147
+ function agentTypeDivergences(manifestAgents, liveAgents) {
70148
+ const out = [];
70149
+ for (const [alias, declared] of Object.entries(manifestAgents ?? {})) {
70150
+ const live = (liveAgents ?? {})[alias];
70151
+ if (!live) {
70152
+ out.push(
70153
+ `${alias} \u2014 typed locally but NOT bound on the app, so useAgentRun("${alias}") 400s at runtime`
70154
+ );
70155
+ continue;
70156
+ }
70157
+ for (const key of AGENT_TYPED_KEYS) {
70158
+ if (!sameSchema(declared[key], live[key])) {
70159
+ out.push(`${alias}.${key} \u2014 local types disagree with the live agent`);
70160
+ }
70161
+ }
70162
+ }
70163
+ return out;
70164
+ }
70188
70165
  var WORKFLOWS_DIR = path5.join("src", "workflows");
70189
70166
  var WORKFLOW_GLOBALS_DIR = path5.join(".lotics", "workflows");
70190
70167
  var AGENTS_DIR = path5.join("src", "agents");
@@ -70483,10 +70460,75 @@ function ensureAppTsconfig(projectDir) {
70483
70460
  parsed.exclude = [...currentEx, ...toAdd];
70484
70461
  changes.push(`added ${toAdd.join(", ")} to "exclude"`);
70485
70462
  }
70463
+ const existingExtends = parsed.extends;
70464
+ if (existingExtends === void 0) {
70465
+ parsed.extends = `./${LINK_TSCONFIG}`;
70466
+ changes.push(`added "extends": "./${LINK_TSCONFIG}" (so tsc resolves the same @lotics/ui as Vite)`);
70467
+ } else if (existingExtends !== `./${LINK_TSCONFIG}`) {
70468
+ console.error(
70469
+ `\u26A0 tsconfig.json already extends ${JSON.stringify(existingExtends)}, so the dev-link config was not added \u2014 \`tsc\` will keep resolving @lotics/ui from node_modules even under LOTICS_UI_SRC. Add "./${LINK_TSCONFIG}" to "extends" (it accepts an array) to fix it.`
70470
+ );
70471
+ }
70486
70472
  if (changes.length === 0) return;
70487
70473
  fs4.writeFileSync(tsconfigPath, JSON.stringify(parsed, null, 2) + "\n");
70488
70474
  console.error(`Patched tsconfig.json: ${changes.join("; ")}.`);
70489
70475
  }
70476
+ var LINK_TSCONFIG = ".lotics/tsconfig.link.json";
70477
+ function writeDevLinkTsconfig(projectDir) {
70478
+ const uiSrc = process.env.LOTICS_UI_SRC;
70479
+ const paths = {};
70480
+ if (uiSrc) {
70481
+ paths["@lotics/ui/*"] = [`${uiSrc}/*`];
70482
+ for (const peer of readKitPeerNames(projectDir)) {
70483
+ const typesDir = path5.join(projectDir, "node_modules", typesPackageFor(peer));
70484
+ const runtimeDir = path5.join(projectDir, "node_modules", peer);
70485
+ const target = fs4.existsSync(typesDir) ? `../node_modules/${typesPackageFor(peer)}` : fs4.existsSync(runtimeDir) ? `../node_modules/${peer}` : null;
70486
+ if (!target) continue;
70487
+ paths[peer] = [target];
70488
+ paths[`${peer}/*`] = [`${target}/*`];
70489
+ }
70490
+ }
70491
+ const file2 = path5.join(projectDir, ".lotics", "tsconfig.link.json");
70492
+ const header = uiSrc ? `// GENERATED by \`lotics app codegen\` \u2014 do not edit.
70493
+ // LOTICS_UI_SRC is set, so @lotics/ui resolves to your working copy for tsc,
70494
+ // vitest, eslint and your editor \u2014 the same copy Vite is bundling. The peer
70495
+ // pins keep ONE react / react-native in the program; without them the kit's
70496
+ // source resolves its own copies and every shared type stops matching.
70497
+ // Unset LOTICS_UI_SRC and re-run to go back to the published kit.
70498
+ ` : `// GENERATED by \`lotics app codegen\` \u2014 do not edit.
70499
+ // LOTICS_UI_SRC is not set, so this is inert and @lotics/ui resolves from
70500
+ // node_modules as normal.
70501
+ `;
70502
+ fs4.writeFileSync(file2, `${header}${JSON.stringify({ compilerOptions: { paths } }, null, 2)}
70503
+ `);
70504
+ return file2;
70505
+ }
70506
+ function writeKitTypeAugmentation(projectDir) {
70507
+ const uiSrc = process.env.LOTICS_UI_SRC;
70508
+ const source = uiSrc ? path5.join(uiSrc, "react_native.d.ts") : path5.join(projectDir, "node_modules", "@lotics", "ui", "src", "react_native.d.ts");
70509
+ const target = path5.join(projectDir, ".lotics", "react_native.d.ts");
70510
+ if (!fs4.existsSync(source)) {
70511
+ if (fs4.existsSync(target)) fs4.rmSync(target);
70512
+ return;
70513
+ }
70514
+ fs4.writeFileSync(
70515
+ target,
70516
+ `// GENERATED by \`lotics app codegen\` from @lotics/ui \u2014 do not edit.
70517
+ // The kit's web-only ViewStyle/TextStyle properties, which react-native does
70518
+ // not model. Delete any hand-copied src/react_native.d.ts; this replaces it.
70519
+ ` + fs4.readFileSync(source, "utf-8")
70520
+ );
70521
+ }
70522
+ function typesPackageFor(peer) {
70523
+ return peer.startsWith("@") ? `@types/${peer.slice(1).replace("/", "__")}` : `@types/${peer}`;
70524
+ }
70525
+ function readKitPeerNames(projectDir) {
70526
+ const kitPkg = path5.join(projectDir, "node_modules", "@lotics", "ui", "package.json");
70527
+ if (!fs4.existsSync(kitPkg)) return [];
70528
+ const parsed = JSON.parse(fs4.readFileSync(kitPkg, "utf-8"));
70529
+ const peers = parsed.peerDependencies;
70530
+ return peers && typeof peers === "object" ? Object.keys(peers) : [];
70531
+ }
70490
70532
  function writeAppDts(projectDir, manifest) {
70491
70533
  const dotLotics = path5.join(projectDir, ".lotics");
70492
70534
  fs4.mkdirSync(dotLotics, { recursive: true });
@@ -70496,6 +70538,8 @@ function writeAppDts(projectDir, manifest) {
70496
70538
  [path5.join(dotLotics, "app_agents.d.ts"), generateAppAgentsDts(manifest.agents)]
70497
70539
  ];
70498
70540
  for (const [file2, content] of written) fs4.writeFileSync(file2, content);
70541
+ writeDevLinkTsconfig(projectDir);
70542
+ writeKitTypeAugmentation(projectDir);
70499
70543
  ensureAppTsconfig(projectDir);
70500
70544
  return written.map(([file2]) => file2);
70501
70545
  }
@@ -70564,28 +70608,26 @@ function warnAppFieldsUnwritten(projectDir, err2) {
70564
70608
  `\u26A0 Could not generate .lotics/app_fields.ts (${reason}), and this project has none. Any source importing F/OPT will fail to build with 'Could not resolve "../../.lotics/app_fields"'. Run 'lotics app codegen' once you can reach the workspace.`
70565
70609
  );
70566
70610
  }
70567
- function warnIfDeployingLinkedKit(projectDir) {
70568
- const uiSrc = process.env.LOTICS_UI_SRC;
70569
- if (!uiSrc) return;
70570
- const viteConfigPath = path5.join(projectDir, "vite.config.ts");
70571
- if (!fs4.existsSync(viteConfigPath)) return;
70572
- if (!fs4.readFileSync(viteConfigPath, "utf-8").includes("LOTICS_UI_SRC")) return;
70573
- console.error(
70574
- `\u26A0 LOTICS_UI_SRC is set \u2014 this deploy bundles @lotics/ui from ${uiSrc}, NOT the published package. The deployed app will run kit code that exists only on this machine. Unset it and re-deploy once the kit change is published if that is not what you want.`
70575
- );
70576
- }
70577
- function warnIfDevLinkIgnored(projectDir) {
70611
+ function warnAboutDevLink(projectDir, command) {
70578
70612
  const uiSrc = process.env.LOTICS_UI_SRC;
70579
70613
  if (!uiSrc) return;
70580
70614
  const viteConfigPath = path5.join(projectDir, "vite.config.ts");
70581
- if (!fs4.existsSync(viteConfigPath)) return;
70582
- if (fs4.readFileSync(viteConfigPath, "utf-8").includes("LOTICS_UI_SRC")) return;
70583
- console.error(
70584
- `\u26A0 LOTICS_UI_SRC is set but vite.config.ts never reads it \u2014 @lotics/ui will still resolve from node_modules, so kit edits will NOT appear. Add the dev-link entry to \`resolve.alias\` (refresh vite.config.ts from the starter, or paste):
70585
- ...(process.env.LOTICS_UI_SRC
70586
- ? [{ find: /^@lotics\\/ui\\/(.+)$/, replacement: \`\${process.env.LOTICS_UI_SRC}/$1\` }]
70587
- : []),`
70588
- );
70615
+ const config2 = fs4.existsSync(viteConfigPath) ? fs4.readFileSync(viteConfigPath, "utf-8") : "";
70616
+ const linked = config2.includes("loticsResolve") || config2.includes("LOTICS_UI_SRC");
70617
+ if (!linked) {
70618
+ console.error(
70619
+ `\u26A0 LOTICS_UI_SRC is set but vite.config.ts never reads it \u2014 @lotics/ui will still resolve from node_modules, so kit edits will NOT ${command === "deploy" ? "ship" : "appear"}. Hand the whole resolve block to the kit (it owns the dev-link, the react-native alias, the extensions and the dedupe):
70620
+ import { loticsOptimizeDeps, loticsResolve } from "@lotics/ui/vite";
70621
+ // \u2026
70622
+ resolve: loticsResolve(),`
70623
+ );
70624
+ return;
70625
+ }
70626
+ if (command === "deploy") {
70627
+ console.error(
70628
+ `\u26A0 LOTICS_UI_SRC is set \u2014 this deploy bundles @lotics/ui from ${uiSrc}, NOT the published package. The deployed app will run kit code that exists only on this machine. Unset it and re-deploy once the kit change is published if that is not what you want.`
70629
+ );
70630
+ }
70589
70631
  }
70590
70632
  function ensureAppVitestSetup(projectDir) {
70591
70633
  const setupPath = path5.join(projectDir, VITEST_SETUP_FILENAME);
@@ -70631,8 +70673,9 @@ async function appCodegen(args) {
70631
70673
  );
70632
70674
  return;
70633
70675
  }
70676
+ let app = null;
70634
70677
  try {
70635
- const app = await args.client.getApp(meta3.app_id);
70678
+ app = await args.client.getApp(meta3.app_id);
70636
70679
  await writeGeneratedAppFields(
70637
70680
  args.client,
70638
70681
  projectDir,
@@ -70642,6 +70685,20 @@ async function appCodegen(args) {
70642
70685
  } catch (err2) {
70643
70686
  warnAppFieldsUnwritten(projectDir, err2);
70644
70687
  }
70688
+ if (app) {
70689
+ const refreshedAgents = orderedLike(toManifestAgents(app.agents ?? {}), meta3.agents);
70690
+ if (!sameSchema(meta3.agents ?? {}, refreshedAgents)) {
70691
+ writeAppMeta(projectDir, { ...meta3, agents: refreshedAgents });
70692
+ writeAppDts(projectDir, {
70693
+ workflows: meta3.workflows,
70694
+ queries: meta3.queries,
70695
+ agents: refreshedAgents
70696
+ });
70697
+ console.error(
70698
+ `Refreshed package.json#lotics.agents from the app \u2014 that block reflects it, so a hand edit retypes useAgentRun without changing the agent. To change one: set_app_agent.`
70699
+ );
70700
+ }
70701
+ }
70645
70702
  await refreshWorkflowGlobals(args.client, projectDir, meta3.app_id, meta3.workflows ?? {});
70646
70703
  }
70647
70704
  async function refreshWorkflowGlobals(client, projectDir, app_id, workflows) {
@@ -70882,25 +70939,28 @@ function readAppSourceText(projectDir) {
70882
70939
  async function appDeploy(client, args) {
70883
70940
  const projectDir = path5.resolve(args.projectDir ?? process.cwd());
70884
70941
  const meta3 = readAppMeta(projectDir);
70885
- warnIfDeployingLinkedKit(projectDir);
70886
- const sourceText = readAppSourceText(projectDir);
70887
- const called = calledAppAliases(sourceText);
70888
- if (called.dynamic.length > 0) {
70889
- console.error(
70890
- `
70891
- \u26A0 This app calls ${called.dynamic.join(" / ")} with an alias it computes at runtime, which this deploy cannot read.
70892
- The version records only the aliases named as literals, so removing a binding this app reaches dynamically will NOT be refused.`
70893
- );
70894
- }
70895
- const undeclared = undeclaredCapabilities(sourceText, meta3.capabilities);
70896
- if (undeclared.length > 0) {
70897
- const block = JSON.stringify(Object.fromEntries(undeclared.map((c) => [c, true])));
70942
+ warnAboutDevLink(projectDir, "deploy");
70943
+ const liveApp = await client.getApp(meta3.app_id);
70944
+ const divergences = agentTypeDivergences(meta3.agents, liveApp.agents);
70945
+ if (divergences.length > 0) {
70898
70946
  console.error(
70899
70947
  `
70900
- \u26A0 This app calls capability-gated SDK functions for ${undeclared.join(", ")} but the manifest doesn't declare ${undeclared.length > 1 ? "them" : "it"} \u2014 those calls will 403 at runtime.
70901
- Add to package.json#lotics.capabilities: ${block}`
70948
+ Refusing to deploy \u2014 package.json#lotics.agents disagrees with the live app:
70949
+ ` + divergences.map((d) => ` \u2022 ${d}`).join("\n") + `
70950
+
70951
+ lotics.agents is a REFLECTION of the app, not an authoring surface, but it is what
70952
+ types useAgentRun \u2014 so this build was checked against an agent that does not exist.
70953
+ To take the app's shape: lotics app codegen (refreshes the block + the types)
70954
+ To CHANGE the agent instead: lotics run set_app_agent '{"app_id":"${meta3.app_id}","alias":"\u2026","outputs":{\u2026}}'
70955
+ (send only what changes \u2014 the server merges), then codegen.`
70902
70956
  );
70957
+ process.exit(1);
70903
70958
  }
70959
+ const sourceText = readAppSourceText(projectDir);
70960
+ const called = calledAppAliases(sourceText);
70961
+ warnIfAgentProseDiffers(projectDir, liveApp.agents);
70962
+ warnIfDynamicAliases(called);
70963
+ warnIfUndeclaredCapabilities(sourceText, meta3.capabilities);
70904
70964
  writeAppDts(projectDir, { workflows: meta3.workflows, queries: meta3.queries, agents: meta3.agents });
70905
70965
  console.error("Building...");
70906
70966
  await runNpm(["run", "build"], projectDir);
@@ -71019,6 +71079,63 @@ function warnIfQueriesDiffer(app, manifest) {
71019
71079
  (or one alias at a time), or adopt the app's with 'lotics app pull'.`
71020
71080
  );
71021
71081
  }
71082
+ async function appCheck(client, args = {}) {
71083
+ const projectDir = path5.resolve(args.projectDir ?? process.cwd());
71084
+ const meta3 = readAppMeta(projectDir);
71085
+ const app = await client.getApp(meta3.app_id);
71086
+ const sourceText = readAppSourceText(projectDir);
71087
+ const called = calledAppAliases(sourceText);
71088
+ const divergences = agentTypeDivergences(meta3.agents, app.agents);
71089
+ for (const d of divergences) {
71090
+ console.error(`\u2717 package.json#lotics.agents.${d}`);
71091
+ }
71092
+ if (divergences.length > 0) {
71093
+ console.error(
71094
+ ` A deploy REFUSES this: the bundle would be typed against an agent that does not exist.
71095
+ Take the app's shape with 'lotics app pull ${meta3.app_id}', or change the agent with set_app_agent.`
71096
+ );
71097
+ }
71098
+ warnAboutDevLink(projectDir, "deploy");
71099
+ warnIfAgentProseDiffers(projectDir, app.agents);
71100
+ warnIfDynamicAliases(called);
71101
+ warnIfUndeclaredCapabilities(sourceText, meta3.capabilities);
71102
+ warnIfUnboundAliases(app, called);
71103
+ warnIfQueriesDiffer(app, meta3.queries ?? {});
71104
+ warnIfUnbranded(app);
71105
+ if (divergences.length > 0) process.exit(1);
71106
+ console.error("Checked the app's bindings, capabilities and agent schemas \u2014 nothing blocking.");
71107
+ }
71108
+ function warnIfAgentProseDiffers(projectDir, liveAgents) {
71109
+ for (const [alias, live] of Object.entries(liveAgents ?? {})) {
71110
+ const file2 = agentFilePath2(projectDir, alias);
71111
+ if (!fs4.existsSync(file2)) continue;
71112
+ const local = stripAgentHeader(fs4.readFileSync(file2, "utf-8"));
71113
+ if (local === "" || local === (live.instructions ?? "")) continue;
71114
+ console.error(
71115
+ `
71116
+ \u26A0 ${path5.relative(projectDir, file2)} differs from the live agent's instructions.
71117
+ A deploy does not push prose. Send it with 'lotics app agent set ${alias}'.`
71118
+ );
71119
+ }
71120
+ }
71121
+ function warnIfDynamicAliases(called) {
71122
+ if (called.dynamic.length === 0) return;
71123
+ console.error(
71124
+ `
71125
+ \u26A0 This app calls ${called.dynamic.join(" / ")} with an alias it computes at runtime, which no static check can read.
71126
+ A version records only the aliases named as literals, so removing a binding this app reaches dynamically will NOT be refused.`
71127
+ );
71128
+ }
71129
+ function warnIfUndeclaredCapabilities(sourceText, capabilities) {
71130
+ const undeclared = undeclaredCapabilities(sourceText, capabilities);
71131
+ if (undeclared.length === 0) return;
71132
+ const block = JSON.stringify(Object.fromEntries(undeclared.map((c) => [c, true])));
71133
+ console.error(
71134
+ `
71135
+ \u26A0 This app calls capability-gated SDK functions for ${undeclared.join(", ")} but the manifest doesn't declare ${undeclared.length > 1 ? "them" : "it"} \u2014 those calls will 403 at runtime.
71136
+ Add to package.json#lotics.capabilities: ${block}`
71137
+ );
71138
+ }
71022
71139
  function warnIfUnboundAliases(app, called) {
71023
71140
  const {
71024
71141
  queries: unboundQueries,
@@ -71045,7 +71162,7 @@ function warnIfUnboundAliases(app, called) {
71045
71162
  async function appDev(client, args) {
71046
71163
  const projectDir = path5.resolve(args.projectDir ?? process.cwd());
71047
71164
  const meta3 = readAppMeta(projectDir);
71048
- warnIfDevLinkIgnored(projectDir);
71165
+ warnAboutDevLink(projectDir, "dev");
71049
71166
  writeAppDts(projectDir, { workflows: meta3.workflows, queries: meta3.queries, agents: meta3.agents });
71050
71167
  const app = await client.getApp(meta3.app_id);
71051
71168
  const handle = await startDevServer({
@@ -92068,6 +92185,11 @@ COMMANDS
92068
92185
  * marks the currently served version)
92069
92186
  lotics app codegen [path] Regenerate .lotics/* (types + field/option ids)
92070
92187
  from the manifest + workspace schema \u2014 no deploy
92188
+ lotics app check Run every deploy pre-flight WITHOUT building or
92189
+ shipping: agent schemas vs the live app, aliases
92190
+ the code calls but nothing bound, undeclared
92191
+ capabilities, query drift. Exits 1 on what a
92192
+ deploy would refuse, so CI can gate on it
92071
92193
  lotics app workflow run <alias> '<json>' Execute a bound app workflow end-to-end
92072
92194
  (inputs: inline JSON, @file, or stdin;
92073
92195
  --print-created reports created records +
@@ -92085,10 +92207,11 @@ COMMANDS
92085
92207
  (inputs: inline JSON, @file, or stdin; streams
92086
92208
  progress to stderr, reports the settled run;
92087
92209
  --session <id> continues a thread; --json)
92088
- lotics app agent set <alias> Push the edited src/agents/<alias>.md instructions
92089
- + the manifest's typed fields through set_app_agent
92090
- (set_app_agent REPLACES the declaration \u2014 this
92091
- sends it whole so nothing is silently dropped)
92210
+ lotics app agent set <alias> Push the edited src/agents/<alias>.md instructions,
92211
+ and ONLY those \u2014 the server merges, so the typed
92212
+ fields keep whatever is bound (a manifest is a
92213
+ snapshot; replaying it would revert them). Change
92214
+ those with set_app_agent, then pull.
92092
92215
  lotics app subdomain <new-subdomain> Rename the app's public <slug>.lotics.app address
92093
92216
  lotics app rename "<new name>" Rename the app's display name (launcher title)
92094
92217
  lotics app dev [path] Run the app locally with HMR (RPC forwarded to prod)
@@ -92608,6 +92731,7 @@ async function main() {
92608
92731
  console.error(" lotics app deploy -m <message> Build + upload the current directory (-m required)");
92609
92732
  console.error(" lotics app versions [app_id] Show deploy history (version, when, who, message)");
92610
92733
  console.error(" lotics app codegen [path] Regenerate .lotics/* (types + field ids) \u2014 no deploy");
92734
+ console.error(" lotics app check Deploy's pre-flight without the build (exits 1 on a blocker)");
92611
92735
  console.error(" lotics app workflow run <alias> '<json>' Execute a bound app workflow end-to-end");
92612
92736
  console.error(" lotics app workflow set <alias> Push the edited src/workflows/<alias>.ts body");
92613
92737
  console.error(" lotics app workflow pull Rewrite src/workflows/*.ts from the server");
@@ -92823,6 +92947,10 @@ Available workspaces:`);
92823
92947
  await appVersions(client, { app_id: appId });
92824
92948
  return;
92825
92949
  }
92950
+ if (subcommand === "check") {
92951
+ await appCheck(client, {});
92952
+ return;
92953
+ }
92826
92954
  if (subcommand === "workflow") {
92827
92955
  const action = toolArgs;
92828
92956
  const workflowUsage = () => {
@@ -32,10 +32,11 @@ Per-command syntax, flags, contracts, and gotchas for the public `lotics` CLI. S
32
32
  | `lotics app pull <app_id> [path]` | Download source archive from R2 (presigned), extract, npm install, stamp package.json's `lotics` field. With no `[path]`: refresh the cwd IN PLACE when it's already this app's own project (its manifest `app_id` matches — the documented `cd <app> && lotics app pull` flow), else clone into an `<name>/` subdir; this avoids the stray nested `./<name>/` subdir a pull-from-inside-the-app used to drop. — `workflows` and `agents` are sourced from the live App row (NOT the archived manifest), so `set_app_workflow` / `set_app_agent` authoring survives the pull. Regenerates `.lotics/app_{workflows,queries,agents}.d.ts` so `useWorkflow` / `useQuery` / `useAgentRun` stay typed, AND the runtime `.lotics/app_fields.ts` (the same linked-vs-bespoke branch `app codegen` runs, off the app row already fetched — see that row for the two forms). That one is not optional: `app deploy` tars source with `--exclude=.lotics`, so no archive can carry it, and a pulled project whose `src/` imports `F`/`OPT` would fail to build with `Could not resolve "../../.lotics/app_fields"` until `app codegen` was run by hand. The write NAMES the form and the reason, because an in-place pull can FLIP a project between them (`opctl app publish` links an origin, `package eject` unlinks it) and that changes what the module does at load. Skipped under `--view-as` (the schema is read as that member and silently drops tables they cannot see — a narrowed `F` map compiles and then throws at runtime, worse than the missing module). A binding/schema fetch failure is non-fatal and names the right recovery for what is on disk: an existing file is kept, an ABSENT one warns about the build error and points at `app codegen`. Pull GENERATES but never RECONCILES `.lotics/` — deleting a companion whose alias the manifest no longer declares is `app codegen`'s alone, since pull's authority is the server's alias set and a declared-but-not-yet-`set` alias is supported. Also writes one `src/workflows/<alias>.ts` per bound workflow (faithful body from `get_app_workflow`) and one `src/agents/<alias>.md` per bound agent (its instructions, straight off the live row) — so the prose an author actually edits lives in a file, and pull always overwrites it from live, leaving no second copy to drift. A legacy workflow alias with no rendered source, or an agent with no instructions, warns and is skipped. The stamped `lotics.agents` map carries the TYPED half only (`inputs`/`outputs`/`tool_names`/`model_id`/…) — an agent's prose lives solely in its `.md`, so there is never a second local copy to desync; a stale `instructions` left by an older CLI is inert and disappears on the next pull |
33
33
  | `lotics app deploy -m <message>` | **`-m` is REQUIRED** (CLI errors without a non-empty message) — each deploy is a version row read back by `lotics app versions`, so a blank message loses the audit trail. npm run build; tar source + dist; POST /v1/apps/{id}/versions multipart. Carries code + capabilities only — **neither queries nor workflow/agent bindings are a deploy concern** (`set_app_workflow` / `remove_app_workflow` own `apps.workflows`; the manifest's `workflows` map is a pulled reflection, read by `useWorkflow` codegen and by `app workflow set`, never written by a deploy). Deploy DOES send the manifest's `lotics.workflows` alias KEYS (not the bindings) as `workflow_aliases`, recorded on the version row so `remove_app_workflow` can refuse to unbind an alias the served version still declares. It also reports any `lotics.queries` alias whose declaration DIFFERS from the app's, naming both recoveries (`app query set --all` to push yours, `app pull` to adopt the app's) — a deploy no longer writes them, so the two are allowed to drift. After a successful deploy it **warns loudly about any alias the source CALLS that is NOT bound on the server** (a `getApp` diff via `warnIfUnboundAliases`) — since deploy never binds them, that would otherwise throw only at the app's first `useWorkflow` / `useAgentRun` call; the warning points to `lotics app workflow set` / `set_app_agent`. Advisory only (never fails the deploy). |
34
34
  | `lotics app versions [app_id]` | `GET /v1/apps/{id}/versions` — print deploy history newest-first (version number, timestamp, deployer name, build status, the `-m` message; `*` marks the currently-served version). app_id from the local manifest, or pass one to inspect any app without pulling it. Admin-only server-side (mirrors deploy + source download). Answers "what shipped, when, by whom" — e.g. whether a fix was live at an incident's time. The deploy pipeline already persisted all of this in `app_versions`; this is the read surface. Title → stderr, table → stdout (pipeable). |
35
- | `lotics app codegen [path]` | Regenerate `.lotics/*` from the manifest + workspace schema **without a deploy**. The three `.d.ts` companions (`app_{workflows,queries,agents}.d.ts`) are always rewritten (synchronous, no network). When credentials resolve, also rewrites the **runtime** `.lotics/app_fields.ts` — **branched on whether the app is a package installation** (`getApp().package_id` set, from `generate_package_fields.ts`): a **linked/published** app emits the BINDING form (`F`/`OPT`/`ROLE` resolved from the installation's LIVE binding — via `appBinding` / the `binding` RPC — at module load through `getAppBinding()` + top-level await, so the source stays portable across every install); a **bespoke** app emits the BAKED form (`generate_app_fields.ts`) — a real `.ts` exporting `F` (table→field→`"fld_…"`) + `OPT` (table→select-field→option→`"opt_…"`) keyed by display-name aliases, for the tables the app's queries reference (+ optional `package.json#lotics.codegen.tables` allowlist). Both forms share the `F`/`OPT` shape (contract aliases derive from the same slugified display names), so a published origin's deployed source compiles unchanged. Writing the BINDING form also heals the project's vitest setup (`ensureAppVitestSetup`, folded into the same write boundary): the binding form awaits `getAppBinding()` (a network call) at module load, so without a stub `npm test` fails to collect any test that imports the app graph — the heal writes `vitest.setup.ts` (mocks only `getAppBinding`, returning an echo binding: any alias → a self-identifying `fld:test:…`/`opt:test:…`/`grp:test:…` id) if absent, and warns the one-liner to add to `vite.config.ts`'s `test.setupFiles` if the wiring is missing (TS source isn't safely munged, mirroring `ensureAppTsconfig`'s JSONC-tsconfig warn). New scaffolds ship both. Also refreshes each bound workflow's `.lotics/workflows/<alias>.globals.d.ts` + re-wraps its EXISTING `src/workflows/<alias>.ts` body in the current envelope (strips + re-wraps; never re-fetches the body, so local edits survive). **`.lotics/` is reconciled to the manifest, not merely added to** — a `<alias>.globals.d.ts` whose alias the manifest no longer declares is DELETED (that directory is read as the app's alias inventory, so a companion for a binding nobody can reach misreports what the app has). Only that exact filename shape is removed; anything else in the directory is left alone. The reconcile runs before the credential branch, so it happens offline too. The authored counterpart is never deleted — a `src/workflows/<alias>.ts` the manifest does not declare is NAMED instead (`check` and `set` both take their alias set from the manifest, so editing an undeclared body is a silent no-op). A getApp / binding / schema / dts-fetch failure is non-fatal (warns, keeps the last-generated files). |
35
+ | `lotics app codegen [path]` | Regenerate `.lotics/*` from the manifest + workspace schema **without a deploy**. The three `.d.ts` companions (`app_{workflows,queries,agents}.d.ts`) are always rewritten (synchronous, no network). When credentials resolve, also rewrites the **runtime** `.lotics/app_fields.ts` — **branched on whether the app is a package installation** (`getApp().package_id` set, from `generate_package_fields.ts`): a **linked/published** app emits the BINDING form (`F`/`OPT`/`ROLE` resolved from the installation's LIVE binding — via `appBinding` / the `binding` RPC — at module load through `getAppBinding()` + top-level await, so the source stays portable across every install); a **bespoke** app emits the BAKED form (`generate_app_fields.ts`) — a real `.ts` exporting `F` (table→field→`"fld_…"`) + `OPT` (table→select-field→option→`"opt_…"`) keyed by display-name aliases, for the tables the app's queries reference (+ optional `package.json#lotics.codegen.tables` allowlist). Both forms share the `F`/`OPT` shape (contract aliases derive from the same slugified display names), so a published origin's deployed source compiles unchanged. Writing the BINDING form also heals the project's vitest setup (`ensureAppVitestSetup`, folded into the same write boundary): the binding form awaits `getAppBinding()` (a network call) at module load, so without a stub `npm test` fails to collect any test that imports the app graph — the heal writes `vitest.setup.ts` (mocks only `getAppBinding`, returning an echo binding: any alias → a self-identifying `fld:test:…`/`opt:test:…`/`grp:test:…` id) if absent, and warns the one-liner to add to `vite.config.ts`'s `test.setupFiles` if the wiring is missing (TS source isn't safely munged, mirroring `ensureAppTsconfig`'s JSONC-tsconfig warn). New scaffolds ship both. Also refreshes each bound workflow's `.lotics/workflows/<alias>.globals.d.ts` + re-wraps its EXISTING `src/workflows/<alias>.ts` body in the current envelope (strips + re-wraps; never re-fetches the body, so local edits survive). **`.lotics/` is reconciled to the manifest, not merely added to** — a `<alias>.globals.d.ts` whose alias the manifest no longer declares is DELETED (that directory is read as the app's alias inventory, so a companion for a binding nobody can reach misreports what the app has). Only that exact filename shape is removed; anything else in the directory is left alone. The reconcile runs before the credential branch, so it happens offline too. The authored counterpart is never deleted — a `src/workflows/<alias>.ts` the manifest does not declare is NAMED instead (`check` and `set` both take their alias set from the manifest, so editing an undeclared body is a silent no-op). A getApp / binding / schema / dts-fetch failure is non-fatal (warns, keeps the last-generated files). **Re-silvers `package.json#lotics.agents`** from the live app row whenever its `inputs`/`outputs` disagree, then rewrites the agent `.d.ts` from the refreshed block: that block is a mirror AND the offline seed for `useAgentRun` typings, so a stale copy types the app against an agent that does not exist. Refreshing here makes the divergence self-healing on a command already in the loop and keeps the remedy off `app pull` (which rewrites `src/workflows/*.ts` and would eat uncommitted body edits). The write is surgical and order-preserving (`orderedLike`), so it changes only the fields that actually differ. A hand edit to that block is therefore reverted — it never changed the agent anyway; to change one, `set_app_agent`. |
36
+ | `lotics app check` | Every pre-flight `deploy` runs, WITHOUT building or shipping: the manifest's agent schemas against the live app row, aliases the source calls that nothing bound (queries, workflows AND agents), capability-gated SDK calls the manifest doesn't declare, `lotics.queries` drift, a missing icon/theme, and a notice for any alias the source computes at runtime (invisible to every check here and to the deploy's unbind guard). Adds no rule of its own — each finding is the same helper `deploy` calls, so a green check means a deploy will not complain. **Exits 1 only on what `deploy` REFUSES** (an agent schema that disagrees with the live app), so CI can gate on it while advisories stay advisory. It also names any `src/agents/<alias>.md` that differs from the live agent's instructions — a WARNING, not a gate, because `deploy` never pushes prose and shipping unrelated UI while a prompt is mid-edit is normal; a stale prompt does not make the bundle lie about its own types the way a stale schema does. The point is the question being ASKABLE: these checks used to cost a build, a tar, an upload and a version row in the audit trail, which is expensive enough that the honest move was to skip them and find out in production. |
36
37
  | `lotics app workflow run <alias> '<json>'` | Execute a bound app workflow end-to-end via `appWorkflow`. `app_id` comes from the local manifest; the alias must be bound (`set_app_workflow`). Inputs ingest exactly like `lotics run` (inline JSON / `@file` / stdin — bulk inputs bypass `ARG_MAX`). Prints the full `{status,message,data,files,side_effects}` JSON to stdout + a one-line summary to stderr; exits non-zero on `status:"error"` (assertable). `--print-created` (alias `--report-effects`) renders the honest post-run harvest: created records grouped by table, a paste-ready `lotics run delete_records …` per table, then the **mandatory caveat** naming what cannot be auto-undone (external integrations + notifications) and that sub-workflows may have run. `--cleanup` (DEFAULT OFF, implies the report) additionally runs the deletes for harvested records ONLY — never files / external / notifications. Neither is a rollback — a rollback is structurally impossible here. |
37
38
  | `lotics app workflow set <alias>` | Push the edited `src/workflows/<alias>.ts` body through `set_app_workflow` (the single author of `apps.workflows`). Reads the body from disk (header + `/// <reference>` + `export {};` marker + the `__workflow` wrapper all stripped) + the typed `inputs`/`outputs` **and the `description`** from `package.json#lotics.workflows.<alias>`; the **server** re-verifies the body and echoes the bound `outputs` (declared, else DERIVED from `return({ data })`). The `description` is the one line an agent reads when choosing between the app's aliases (the workflow counterpart to a query's) — authored in the manifest so it lives beside the body in version control and rides every push; omit it and the workflow keeps whatever description it already has, so a push can never blank one set elsewhere. When the manifest declared NO `outputs`, the DERIVED echo is written back into `package.json#lotics.workflows.<alias>.outputs` (a SURGICAL write — preserves `knowledge`/`config` and every other manifest field) and that alias's types are refreshed in place, so `useWorkflow("<alias>")`'s `result.data` is typed immediately with no hand-copy and no second `lotics app codegen`; an explicitly-declared `outputs` is authoritative and never overwritten. Deploy still never authors workflows — this is a CLI convenience over the existing tool. Clear error + non-zero exit on a missing file, an alias absent from the manifest, or a verify failure. |
38
- | `lotics app agent set <alias>` | Push the edited `src/agents/<alias>.md` instructions back through `set_app_agent` — the agent mirror of `app workflow set`, and the deploy-free authoring path for `apps.agents`. Reads the prose from disk (the `<!-- lotics: … -->` header stripped) and the typed fields (`inputs`/`outputs`/`tool_names`/`model_id`/`effort_level`/`knowledge_doc_ids`/`query_aliases`/`workflow_aliases`) from `package.json#lotics.agents.<alias>`, then sends them as ONE declaration. That assembly is the point: **`set_app_agent` REPLACES the declaration rather than patching it**, so a hand-built payload that sets one field silently drops the instructions, the output schema and the model pin — a silent, unrecoverable edit against a live prompt. Clear error + non-zero exit on a missing file, an alias absent from the manifest, or a file that is empty once the header is stripped (refusing to push an empty prompt). `app pull` writes the file; edit, then `set`. |
39
+ | `lotics app agent set <alias>` | Push the edited `src/agents/<alias>.md` instructions back through `set_app_agent` — the agent mirror of `app workflow set`, and the deploy-free authoring path for an agent's PROSE. It sends the instructions and nothing else: the server merges against the stored declaration, so every typed field keeps exactly what is bound. This is deliberate and it is the opposite of what the symmetry with `app workflow set` suggests — **the manifest is a snapshot from the last `app pull`, so replaying its typed half would silently revert whatever was bound since** (the chat authoring agent adding `knowledge_doc_ids`, another operator granting `query_aliases`), and the CLI would print success while the agent quietly lost its knowledge and its read surface. To change a typed field, call `set_app_agent` with just that field (`lotics run set_app_agent '{"app_id":…,"alias":…,"outputs":{…}}'` — it merges), then `app pull` to bring the manifest back in step. Editing `package.json#lotics.agents` by hand pushes nothing, and since that block is what types `useAgentRun`, `codegen` warns and `deploy` REFUSES while it disagrees with the live app. Clear error + non-zero exit on a missing file, an alias absent from the manifest, or a file that is empty once the header is stripped (refusing to push an empty prompt). `app pull` writes the file; edit, then `set`. |
39
40
  | `lotics app query set <alias>` \| `--all` | Push `package.json#lotics.queries` (`{ ast, params? }` per alias) to `apps.queries` through `set_app_query` — **the only author of a query binding**, the mirror of `app workflow set`. A deploy ships code and binds nothing. The **server** validates each one exactly as it always did (alias identifier, workspace-only tables, resolvable fields, declared params). `--all` pushes every declared alias, alias-sorted, stopping at the first failure and naming what already landed. Clear error + non-zero exit on an alias absent from the manifest or a validation failure. |
40
41
  | `lotics app agent run <app_id> <alias> ['<json>'\|@file\|stdin]` | Run a bound app agent end-to-end. A run needs no deployed UI bundle — just the app row + the bound agent declaration + member auth — so the **`app_id` is explicit** (not read from a local manifest). Inputs ingest exactly like `lotics run` (inline JSON / `@file` / stdin; empty = `{}`). Opens the run's SSE (`appAgentRunStream`), streams `text-delta` prose to **stderr** as live progress, then reports from the **settled run RECORD** (`listAgentRuns`, polled to a terminal status — the client stream can close a beat before the run settles, or drop while it runs on server-side): default prints the run's structured `output` (JSON) or final text to **stdout** + a status line to stderr; `--json` prints the full run summary to stdout. Selects THIS run by the `x-app-agent-run-id` header (ordering-independent). Exits 0 **only** when the settled status is `completed`; otherwise non-zero with the run's error surfaced. A settled run that never appears fails loudly (never a silent success). A fresh `session_id` is minted per run (self-contained); `--session <id>` continues an existing thread (prior runs become the agent's context). |
41
42
  | `lotics app workflow pull` | Rewrite every `src/workflows/<alias>.ts` from the server (faithful body per bound alias via `get_app_workflow`) **+ its `.lotics/workflows/<alias>.globals.d.ts`** (via `getAppWorkflowDts`, so the body is locally typecheckable via `lotics app workflow check`) without a full `app pull` (no source archive, no npm install). A legacy alias with no rendered source warns and is skipped; a dts-fetch failure is non-fatal (body still written with the fallback wrapper, typecheck degraded). Each alias's `description` is folded back into `package.json#lotics.workflows.<alias>` from the same read — the alias binding the manifest is otherwise stamped from carries `inputs`/`outputs` but not the description, which lives on the workflow ROW, so without this a pull would erase an authored one. The server's GENERATED default is skipped, so an app that never described its workflows gains no manifest noise. Also idempotently patches the main `tsconfig.json` `exclude` to cover `src/workflows` + `.lotics/workflows` so a pre-existing app's `npm run typecheck` never loads the bodies or the colliding per-alias globals. |
@@ -43,7 +44,7 @@ Per-command syntax, flags, contracts, and gotchas for the public `lotics` CLI. S
43
44
  | `lotics app subdomain <new-subdomain>` | Rename the app's public `<slug>.lotics.app` address via `PUT /v1/apps/{id}/subdomain`. app_id comes from the local `package.json` manifest; the chosen slug must be a valid DNS label and free; the old address stops resolving. |
44
45
  | `lotics app rename "<new name>"` | Change the app's display name (launcher/title) via the `update_app` tool. app_id comes from the local `package.json` manifest; the public address (`subdomain`) and code (`deploy`) are unchanged. |
45
46
  | `lotics app dev [path] [--port=N] [--vite-port=N] [--view-as=<member_id>]` | Spawn Vite dev server + an RPC-forwarding HTTP server. The wrapper page embeds the iframe with `sandbox="allow-scripts allow-same-origin"` matching production; postMessage ops (query / workflow / members / context / upload / openExternal / urlState / agentRun) are forwarded to api.lotics.ai using the CLI's API key — file bytes move in **both** directions through the dev server's own relays, never browser↔storage: dev runs against the PROD bucket, whose CORS admits `https://*.lotics.app` and not `http://localhost:<port>`, so a direct browser transfer is blocked — no upload could complete and no preview engine (PDF/Word/Excel all FETCH the bytes) could read a file. `upload` mints a presigned URL and PUTs it **to `PUT /_upload/<file_id>`** (`dev/upload_relay.ts`) from the wrapper page — same-origin, so no preflight and no CORS — and Node forwards it on; every presigned `url`/`thumbnail_url`/`preview_url` on a **file object** in an RPC result is rewritten to **`GET /_file/<token>`** (`dev/file_relay.ts`, absolute — the iframe would resolve a relative path against Vite), which streams the bytes back with `Range` passthrough (206s intact, so PDF seeking works) and an `Access-Control-Allow-Origin` for the Vite origin (the one cross-origin hop left is OUR response to allow). Neither relay ever takes a destination from the client — it gets a `file_id`/token and transfers only to/from a URL it minted or observed itself, so there is no client-controlled target and no SSRF surface. A URL in a record's own text cell is NOT rewritten. Production is unchanged (direct-to-storage, no bytes through the API server); `openExternal` and `urlState.get/set` are handled locally (the latter read/write the wrapper page's own address bar — `set` writes in place via `replaceState` and browser back/forward broadcast a `url-state` message back, so `useUrlState` survives refresh and is shareable in the dev loop; in-app *routing* is the app's own (the iframe owns its url via `@lotics/app-sdk/router`), and the wrapper bakes the saved screen (`_loc`) into the iframe src on load so a refresh restores it, mirroring production); `agentRun` (streaming) is proxied through `POST /_agent_run`, which opens the run's SSE with the CLI key and pipes chunks back to the iframe (`stream-chunk`* → `stream-end`), so `useAgentRun` works in the dev loop just like production; `context` resolves the viewer (`member_id` from `cli/whoami` + `comments_enabled` from the local manifest) and fetches the installation's stored `config` live from the app row, so `useConfig()` renders the same values as production. `--view-as` (global flag; also `LOTICS_VIEW_AS`) threads `x-view-as-member-id` so `is_current_member` + `context` resolve to that member — **admin key only** (the server 403s a non-admin), writes stay attributed to the key owner. Hot reload via Vite; full DevTools / Playwright access via plain localhost. The dev-optimizer pre-bundle list (`optimizeDeps.include`, load-bearing for dev) is imported from `@lotics/ui/vite` (`loticsOptimizeDeps`) rather than hardcoded in the scaffold, so it tracks the installed `@lotics/ui` and can never go stale. Binds **loopback only** (`127.0.0.1`) — `/_rpc` dispatches with the developer's API key, so a socket on every interface would hand anyone on the network full read/write on the workspace. |
46
- | `LOTICS_UI_SRC=<abs path to packages/ui/src>` (env, not a command) | Dev-link `@lotics/ui` to a monorepo checkout for the length of ONE command: the app's own `vite.config.ts` reads the variable and adds a `{ find: /^@lotics\/ui\/(.+)$/, replacement: "<LOTICS_UI_SRC>/$1" }` entry to `resolve.alias`, so kit edits go live under `lotics app dev` (HMR) and bundle under `lotics app deploy`. Unset ⇒ the kit resolves from `node_modules` as normal. **Nothing is written to disk** — there is no link/unlink step, nothing to leave switched on, and no config for the CLI to corrupt (the `lotics ui link` command this replaces edited `vite.config.ts` by regex and twice deleted the load-bearing `react-native` → `react-native-web` alias with the array's closing bracket, breaking the app's build entirely). Identical for a monorepo app and an EXTERNAL one (e.g. `~/lotics_apps`). `app dev` **warns** when the variable is set but the app's `vite.config.ts` predates it (scaffolded earlier) and prints the lines to add; `app deploy` **warns** that the bundle carries kit code from your working copy rather than the published package. **Vite-only, by design:** the app's `tsc` still resolves `@lotics/ui` from `node_modules` (the published `.d.ts`) — the kit `src` can't be typechecked inside an app because it's RN-Web, so typecheck the kit in `packages/ui` and let the finalize publish restore the app's own typecheck. |
47
+ | `LOTICS_UI_SRC=<abs path to packages/ui/src>` (env, not a command) | Dev-link `@lotics/ui` to a monorepo checkout for the length of ONE command, **for every tool at once**. The app's `vite.config.ts` gets its whole `resolve` block from the kit (`resolve: loticsResolve()` — `@lotics/ui/vite`), which reads the variable at call time and adds the `@lotics/ui/*` → working-copy alias, so kit edits go live under `lotics app dev` (HMR) and bundle under `lotics app deploy`. In the same breath, every command that regenerates types (`create`/`pull`/`dev`/`deploy`/`codegen`, all via `writeAppDts`) writes **`.lotics/tsconfig.link.json`** — the matching `paths`, which the app's `tsconfig.json` `extends` — so `tsc`, vitest, eslint and your EDITOR resolve the same copy Vite does. Unset ⇒ every one of them goes back to `node_modules`, and the generated file is rewritten inert. **Why `paths` and not `npm link`:** the kit ships un-built `.tsx`, so a kit file outside `node_modules` resolves its OWN `react`/`react-native` from the monorepo — two copies in one program and every shared type stops matching ("Two different types with this name exist, but they are unrelated"). The generated file therefore also pins every peer @lotics/ui declares to the APP's copy, types-package first (`react` → `@types/react`; pinning the runtime package instead strands tsc on a `.js` with no declarations). The pin set is derived from the installed kit's `peerDependencies`, so it tracks the kit rather than rotting. **Nothing hand-written is touched** — the generated file lives in `.lotics/` (the CLI's own dir) and no config is edited by regex, which is what the deleted `lotics ui link` did when it twice destroyed the load-bearing `react-native` alias along with the array's closing bracket. Identical for a monorepo app and an EXTERNAL one (e.g. `~/lotics_apps`). `app deploy` still warns whenever the variable is set — that the bundle carries kit code from your working copy, or that the app's config predates `loticsResolve()` and never reads it, so the PUBLISHED kit is going out. An app whose `tsconfig.json` already `extends` something else is told rather than rewritten: add `./.lotics/tsconfig.link.json` to the array yourself. |
47
48
  | `lotics xlsx <subcmd>` | Local .xlsx read/write/edit using the bundled `@lotics/xlsx` engine (no auth, no network). 14 named subcommands (read, write, set-cell, clear-range, merge, unmerge, add-sheet, delete-sheet, rename-sheet, insert-rows, delete-rows, insert-cols, delete-cols, set-style) + `batch` for applying multiple of the same 14 ops in a single parse/export cycle. `read` also takes `--sheet <name>` (limit output to one sheet — unknown name fails with the available list) and `--range <sheet>!<A1:G60>` (limit to a cell window; the `<sheet>!` prefix is optional when `--sheet` supplies the sheet, a single cell like `S1!B2` is a 1×1 window) to trim a large workbook's JSON — the output shape is unchanged, only the `sheets` array and each sheet's `cells` map are filtered. Atomic in-place write (temp file + rename). |
48
49
  | `lotics docx <subcmd>` | Local .docx read/write/edit using the bundled `@lotics/docx` engine (OOXML round-trip surface only — no ProseMirror baggage). Subcommands: read, write, append-paragraph, insert-paragraph, delete-block, replace-text, batch. A legacy `.doc` (Word 97–2003 OLE2 binary) is detected in `loadFile` and routed through `@lotics/ooxml`'s `loadDocxFromBuffer` (which re-emits it as real OOXML) before reading — so `lotics docx read` works on a `.doc`, not just a `.docx`. Opaque blocks (tables, custom XML) preserved verbatim. Atomic in-place write. **`replace-text` matches across run boundaries** — Word splits a run at every formatting change, so a `{{marker}}` routinely lands split — and reads straight THROUGH marks that occupy no place in the sentence (`w:proofErr`, `w:footnoteReference`, endnote/comment refs + ranges, `w:bookmarkStart`/`End`, `w:lastRenderedPageBreak`). `w:proofErr` is the one that decides whether this works in practice — Word brackets every word its dictionary rejects, so on non-English text it lands between nearly every pair of runs. It still refuses to join across anything that occupies space in the text — `w:br`, `w:tab`, `w:sym`, a drawing, or any tag not on that allowlist — because the joined string does not represent the glyph and a match there would rewrite text the caller never saw. The SAME rule applies inside a table cell as outside it — both run one `replaceInParagraph` over paragraphs found at any depth, so a marker split by a line break is refused in both rather than rewritten in the cell and skipped in the body under a success message. Zero matches is always a hard error, never a silent no-op, and when the words ARE on the page the error names the block and the splitting mark (`The text IS present at block 1, split by w:br …`) rather than claiming the text is absent. |
49
50
  | `lotics file preview <file\|fil_id> [-o out.png]` | (also `lotics preview`) Render a .docx/.xlsx to a PNG using the SAME engines the frontend FilePreview uses (`@lotics/docx` `loadDocxIntoElement` / `@lotics/xlsx` `drawSpreadsheet`) — so what you see matches an operator. Accepts a **local path** OR a stored **`fil_…` id** (`isStoredFileId` — a bare id, no extension): an id is first downloaded to a temp dir via `downloadFileById` (the `signed_url` presign path — same authority as `lotics file download`), rendered, then the transient source is removed; with no `-o` the PNG lands in cwd under the stored file's base name (`defaultPreviewOutputPath`). Drives a headless Chrome over **CDP with only Node built-ins** (`WebSocket`/`fetch`/`http`/`child_process`) — zero npm deps, the CLI stays a single bundled binary. The browser render logic is a separate esbuild **browser** bundle shipped at `dist/render_page.js` (built by `build_cli.mjs`, excluded from the node `tsgo`), served over a throwaway localhost http server and screenshotted full-page. **Requires a Chrome/Chromium on the machine** — detected from `CHROME_PATH`/`LOTICS_CHROME`, then Playwright's installed chromium, then system paths — inherent to rendering these browser formats; a clear "install a browser" error otherwise. PDFs need no render (open them directly). |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/cli",
3
- "version": "0.106.0",
3
+ "version": "0.110.0",
4
4
  "description": "Lotics SDK and CLI for AI agents",
5
5
  "type": "module",
6
6
  "bin": {