@engini/cli 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +33 -1
  2. package/dist/cli.js +409 -16
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -19,13 +19,15 @@ engini login --api-key eng_… # or run interactively on a TTY
19
19
  engini applications list --available # discover connector apps
20
20
  engini tools list --application monday # discover tools
21
21
  engini tools call monday_create_item --args '{}' --connection 3
22
+ engini tools call gmail_send_mail --args '{}' --file attachmentsarray=@report.pdf # attach a file
23
+ engini tools result <handle> --select items.email # drill into a large result
22
24
  ```
23
25
 
24
26
  ## Commands
25
27
 
26
28
  ```
27
29
  engini login | logout | whoami # auth
28
- engini tools list | get | call # discover & execute tools
30
+ engini tools list | get | call | result # discover, execute & drill into results
29
31
  engini applications list | get # browse connector apps
30
32
  engini connections list | get # inspect connections
31
33
  engini connect # open the connections page in your browser
@@ -46,6 +48,36 @@ with `--json`. Every command also accepts:
46
48
  Exit codes are a stable contract: `0` success · `1` general error · `2` usage error ·
47
49
  `3` authentication error · `4` not found · `5` validation error · `124` timeout.
48
50
 
51
+ ## Large results (token economy)
52
+
53
+ Tool outputs can be huge — an agent shouldn't pay tokens for data it hasn't asked
54
+ for. When a `tools call` result exceeds `--max-bytes` (default `4096`), it is
55
+ spilled to a local sandbox and the command prints a compact envelope instead:
56
+
57
+ ```jsonc
58
+ { "handle": "h42", "history_id": 42, "data_size": 84211,
59
+ "shape": { "type": "object", "keys": { "items": "array", "total": "number" } },
60
+ "preview": { "id": 1, "email": "a@x.io" },
61
+ "hint": "Full result stored. Pull data with: engini tools result h42 …" }
62
+ ```
63
+
64
+ Then drill in with `tools result <handle>`, paying only for what you pull:
65
+
66
+ ```bash
67
+ engini tools result h42 --select items.email # dot-path (maps over a list)
68
+ engini tools result h42 --fields id,name # project keys per item
69
+ engini tools result h42 --select items --offset 20 --limit 10 # page a list
70
+ engini tools result h42 --full # the whole payload
71
+ engini tools result --list # known handles
72
+ engini tools result --clear # wipe the sandbox
73
+ ```
74
+
75
+ `--inline` (or `--max-bytes 0`) forces the full result inline; `--raw` / `--llm`
76
+ emit the full output as before and bypass the sandbox. Stored results live under
77
+ `$XDG_CACHE_HOME/engini/results/` (`%APPDATA%` on Windows) and are auto-pruned to
78
+ the most-recent 20, dropping anything older than 24h — so a handle is short-lived;
79
+ drill in during the same session.
80
+
49
81
  ## Configuration
50
82
 
51
83
  Credentials and host config live in `$XDG_CONFIG_HOME/engini/config.toml`
package/dist/cli.js CHANGED
@@ -107,17 +107,17 @@ function printOutput(obj) {
107
107
  pretty(obj);
108
108
  }
109
109
  }
110
- function fail(code, message, hint) {
110
+ function fail(code, message, hint2) {
111
111
  if (isTty()) {
112
112
  console.error(`Error: ${message}`);
113
- if (hint) console.error(`Hint: ${hint}`);
113
+ if (hint2) console.error(`Hint: ${hint2}`);
114
114
  } else {
115
115
  const payload = {
116
116
  error: ERROR_NAMES[code] ?? "Error",
117
117
  message,
118
118
  exit_code: code
119
119
  };
120
- if (hint) payload.hint = hint;
120
+ if (hint2) payload.hint = hint2;
121
121
  console.error(JSON.stringify(payload));
122
122
  }
123
123
  throw new CliError(code);
@@ -503,8 +503,13 @@ CORE COMMANDS
503
503
  Discover available tools (one concise summary per tool).
504
504
  tools get <tool_id>
505
505
  Full input/output schema + capability flags for one tool.
506
- tools call <tool_id> --args <json|@file|-> [--connection <id>] [--raw] [--llm <vendor>]
507
- Execute a tool against a connection. Validate first with --dry-run.
506
+ tools call <tool_id> --args <json|@file|-> [--file <field=@path>] [--connection <id>] [--raw] [--llm <vendor>] [--inline]
507
+ Execute a tool against a connection. Attach files with --file (repeat for a
508
+ list). Validate first with --dry-run. A large result spills to a local
509
+ handle (use --inline / --max-bytes <n> to control this).
510
+ tools result <handle> [--select <path>] [--fields <a,b>] [--offset <n>] [--limit <m>] [--full] [--list] [--clear]
511
+ Drill into a stored tools call result: extract a dot-path, project fields,
512
+ or page a list \u2014 paying tokens only for what you pull.
508
513
  applications list [--search <q>] [--available] [--limit <n>]
509
514
  Browse connector apps (slug, categories, tool counts).
510
515
  applications get <slug>
@@ -557,9 +562,17 @@ EXAMPLES
557
562
  engini tools call monday_create_item --args @item.json --connection 3
558
563
  echo '{"name":"x"}' | engini tools call monday_create_item --args -
559
564
 
565
+ # Attach files (repeat --file for a list of files)
566
+ engini tools call gmail_send_mail --args '{"to":"a@b.com","subject":"hi","body":"see attached"}' --file attachmentsarray=@report.pdf
567
+
560
568
  # Provider-shaped result for an agent loop
561
569
  engini tools call monday_create_item --args '{}' --llm openai --tool-call-id call_1
562
570
 
571
+ # Large result -> handle; drill in without paying for the whole payload
572
+ engini tools call list_rows --args '{}' # prints {handle, shape, preview, \u2026}
573
+ engini tools result <handle> --select items.email
574
+ engini tools result <handle> --fields id,name --offset 20 --limit 10
575
+
563
576
  # Machine-readable arg schema (for agents)
564
577
  engini tools call --schema
565
578
 
@@ -584,7 +597,16 @@ var EXAMPLES = {
584
597
  engini tools call monday_create_item --args '{}' --dry-run
585
598
  engini tools call monday_create_item --args @item.json --connection 3
586
599
  echo '{"name":"x"}' | engini tools call monday_create_item --args -
587
- engini tools call monday_create_item --args '{}' --llm openai --tool-call-id call_1`,
600
+ engini tools call gmail_send_mail --args '{}' --file attachmentsarray=@report.pdf
601
+ engini tools call monday_create_item --args '{}' --llm openai --tool-call-id call_1
602
+ engini tools call list_rows --args '{}' # large result -> handle; then: engini tools result <handle>`,
603
+ "tools result": `Examples:
604
+ engini tools result h42 # shape + preview
605
+ engini tools result h42 --select items.email # one dot-path (maps over a list)
606
+ engini tools result h42 --fields id,name # project keys per item
607
+ engini tools result h42 --select items --offset 20 --limit 10
608
+ engini tools result --list # known handles
609
+ engini tools result --clear # wipe the sandbox`,
588
610
  "applications list": `Examples:
589
611
  engini applications list --available --limit 10
590
612
  engini applications list --search crm --json
@@ -612,6 +634,7 @@ function installHelp(program) {
612
634
  addExamples(sub("list"), EXAMPLES["tools list"]);
613
635
  addExamples(sub("get"), EXAMPLES["tools get"]);
614
636
  addExamples(sub("call"), EXAMPLES["tools call"]);
637
+ addExamples(sub("result"), EXAMPLES["tools result"]);
615
638
  }
616
639
  const applications = find("applications");
617
640
  if (applications) {
@@ -694,18 +717,254 @@ function registerLogout(program) {
694
717
  }
695
718
 
696
719
  // src/tools/call.ts
697
- import { readFileSync as readFileSync2 } from "fs";
720
+ import { readFileSync as readFileSync3 } from "fs";
698
721
  import {
699
722
  AnthropicProvider,
723
+ File,
700
724
  OpenAIProvider
701
725
  } from "@engini/sdk";
726
+
727
+ // src/results.ts
728
+ import { randomBytes } from "crypto";
729
+ import {
730
+ existsSync as existsSync2,
731
+ mkdirSync as mkdirSync2,
732
+ readFileSync as readFileSync2,
733
+ readdirSync,
734
+ rmSync,
735
+ statSync,
736
+ writeFileSync as writeFileSync2
737
+ } from "fs";
738
+ import { homedir as homedir2 } from "os";
739
+ import { join as join2 } from "path";
740
+ var MAX_RESULTS = 20;
741
+ var TTL_SECONDS = 24 * 60 * 60;
742
+ var PREVIEW_BYTES = 512;
743
+ function cacheDir() {
744
+ const base = process.platform === "win32" ? process.env.APPDATA ?? homedir2() : process.env.XDG_CACHE_HOME ?? join2(homedir2(), ".cache");
745
+ return join2(base, "engini", "results");
746
+ }
747
+ function serialize(value) {
748
+ return JSON.stringify(value ?? null);
749
+ }
750
+ function byteLength(value) {
751
+ return Buffer.byteLength(serialize(value), "utf8");
752
+ }
753
+ function jsonFiles(dir) {
754
+ if (!existsSync2(dir)) return [];
755
+ return readdirSync(dir).filter((name) => name.endsWith(".json"));
756
+ }
757
+ function storeResult(output, historyId) {
758
+ const handle = historyId !== null ? `h${historyId}` : `r${randomBytes(6).toString("hex")}`;
759
+ const dir = cacheDir();
760
+ mkdirSync2(dir, { recursive: true, mode: 448 });
761
+ const dataSize = byteLength(output);
762
+ const payload = {
763
+ output: output ?? null,
764
+ history_id: historyId,
765
+ data_size: dataSize,
766
+ created: Math.floor(Date.now() / 1e3)
767
+ };
768
+ writeFileSync2(join2(dir, `${handle}.json`), JSON.stringify(payload), { mode: 384 });
769
+ prune();
770
+ return { handle, dataSize };
771
+ }
772
+ function loadResult(handle) {
773
+ const path = join2(cacheDir(), `${handle}.json`);
774
+ if (!existsSync2(path)) return null;
775
+ try {
776
+ const data = JSON.parse(readFileSync2(path, "utf8"));
777
+ return data && typeof data === "object" ? data : null;
778
+ } catch {
779
+ return null;
780
+ }
781
+ }
782
+ function listResults() {
783
+ const dir = cacheDir();
784
+ const now = Date.now();
785
+ const rows = [];
786
+ for (const name of jsonFiles(dir)) {
787
+ const handle = name.slice(0, -".json".length);
788
+ let mtimeMs;
789
+ try {
790
+ mtimeMs = statSync(join2(dir, name)).mtimeMs;
791
+ } catch {
792
+ continue;
793
+ }
794
+ const data = loadResult(handle);
795
+ rows.push({
796
+ mtime: mtimeMs,
797
+ row: {
798
+ handle,
799
+ history_id: data?.history_id ?? null,
800
+ data_size: data?.data_size ?? null,
801
+ age_seconds: Math.floor((now - mtimeMs) / 1e3)
802
+ }
803
+ });
804
+ }
805
+ rows.sort((a, b) => b.mtime - a.mtime);
806
+ return rows.map((r) => r.row);
807
+ }
808
+ function clearResults() {
809
+ const dir = cacheDir();
810
+ let count = 0;
811
+ for (const name of jsonFiles(dir)) {
812
+ rmSync(join2(dir, name), { force: true });
813
+ count += 1;
814
+ }
815
+ return count;
816
+ }
817
+ function prune() {
818
+ const dir = cacheDir();
819
+ if (!existsSync2(dir)) return;
820
+ const now = Date.now();
821
+ const entries = [];
822
+ for (const name of jsonFiles(dir)) {
823
+ const path = join2(dir, name);
824
+ try {
825
+ entries.push({ path, mtime: statSync(path).mtimeMs });
826
+ } catch {
827
+ }
828
+ }
829
+ entries.sort((a, b) => b.mtime - a.mtime);
830
+ const survivors = [];
831
+ for (const { path, mtime } of entries) {
832
+ if (now - mtime > TTL_SECONDS * 1e3) rmSync(path, { force: true });
833
+ else survivors.push(path);
834
+ }
835
+ for (const path of survivors.slice(MAX_RESULTS)) rmSync(path, { force: true });
836
+ }
837
+ function typeName(value) {
838
+ if (value === null || value === void 0) return "null";
839
+ if (Array.isArray(value)) return "array";
840
+ switch (typeof value) {
841
+ case "boolean":
842
+ return "boolean";
843
+ case "number":
844
+ return "number";
845
+ case "string":
846
+ return "string";
847
+ case "object":
848
+ return "object";
849
+ default:
850
+ return "string";
851
+ }
852
+ }
853
+ function inferShape(value) {
854
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
855
+ const keys = {};
856
+ for (const [k, v] of Object.entries(value)) keys[k] = typeName(v);
857
+ return { type: "object", keys };
858
+ }
859
+ if (Array.isArray(value)) {
860
+ const shape = { type: "array", length: value.length };
861
+ if (value.length > 0) {
862
+ const first = typeName(value[0]);
863
+ const homogeneous = value.every((item) => typeName(item) === first);
864
+ shape.item_shape = homogeneous ? inferShape(value[0]) : "mixed";
865
+ }
866
+ return shape;
867
+ }
868
+ return typeName(value);
869
+ }
870
+ function makePreview(value) {
871
+ const candidate = Array.isArray(value) ? value.length > 0 ? value[0] : null : value;
872
+ if (byteLength(candidate) <= PREVIEW_BYTES) return candidate ?? null;
873
+ if (typeof candidate === "string") return `${candidate.slice(0, PREVIEW_BYTES)}\u2026`;
874
+ return { _truncated: true, _note: "preview omitted; use --select/--fields" };
875
+ }
876
+ function hint(handle) {
877
+ return `Full result stored. Pull data with: engini tools result ${handle} --select <path> | --fields a,b | --offset N --limit M`;
878
+ }
879
+ function buildEnvelope(handle, historyId, dataSize, output) {
880
+ return {
881
+ handle,
882
+ history_id: historyId,
883
+ data_size: dataSize,
884
+ shape: inferShape(output),
885
+ preview: makePreview(output),
886
+ hint: hint(handle)
887
+ };
888
+ }
889
+ function parsePath(path) {
890
+ const atoms = [];
891
+ let token = "";
892
+ let i = 0;
893
+ while (i < path.length) {
894
+ const ch = path[i];
895
+ if (ch === ".") {
896
+ if (token) {
897
+ atoms.push({ kind: "key", value: token });
898
+ token = "";
899
+ }
900
+ i += 1;
901
+ } else if (ch === "[") {
902
+ if (token) {
903
+ atoms.push({ kind: "key", value: token });
904
+ token = "";
905
+ }
906
+ const j = path.indexOf("]", i);
907
+ if (j === -1) break;
908
+ const digits = path.slice(i + 1, j);
909
+ if (/^\d+$/.test(digits)) atoms.push({ kind: "index", value: Number(digits) });
910
+ i = j + 1;
911
+ } else {
912
+ token += ch;
913
+ i += 1;
914
+ }
915
+ }
916
+ if (token) atoms.push({ kind: "key", value: token });
917
+ return atoms;
918
+ }
919
+ function step(cur, atom) {
920
+ if (atom.kind === "index") {
921
+ if (Array.isArray(cur) && atom.value >= 0 && atom.value < cur.length) return cur[atom.value];
922
+ return null;
923
+ }
924
+ if (Array.isArray(cur)) return cur.map((item) => step(item, atom));
925
+ if (cur !== null && typeof cur === "object") {
926
+ const value = cur[atom.value];
927
+ return value === void 0 ? null : value;
928
+ }
929
+ return null;
930
+ }
931
+ function selectPath(value, path) {
932
+ let cur = value;
933
+ for (const atom of parsePath(path)) {
934
+ cur = step(cur, atom);
935
+ if (cur === null) return null;
936
+ }
937
+ return cur;
938
+ }
939
+ function pick(obj, fields) {
940
+ const out = {};
941
+ for (const k of fields) if (k in obj) out[k] = obj[k];
942
+ return out;
943
+ }
944
+ function projectFields(value, fields) {
945
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
946
+ return pick(value, fields);
947
+ }
948
+ if (Array.isArray(value)) {
949
+ return value.map(
950
+ (item) => item !== null && typeof item === "object" && !Array.isArray(item) ? pick(item, fields) : null
951
+ );
952
+ }
953
+ return null;
954
+ }
955
+ function paginate(value, offset, limit) {
956
+ const sliced = value.slice(offset);
957
+ return limit !== null ? sliced.slice(0, limit) : sliced;
958
+ }
959
+
960
+ // src/tools/call.ts
702
961
  function loadArgs(spec) {
703
962
  let text;
704
963
  if (spec === "-") {
705
- text = readFileSync2(0, "utf8");
964
+ text = readFileSync3(0, "utf8");
706
965
  } else if (spec.startsWith("@")) {
707
966
  try {
708
- text = readFileSync2(spec.slice(1), "utf8");
967
+ text = readFileSync3(spec.slice(1), "utf8");
709
968
  } catch (err) {
710
969
  return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
711
970
  }
@@ -723,6 +982,45 @@ function loadArgs(spec) {
723
982
  }
724
983
  return data;
725
984
  }
985
+ function loadFiles(specs) {
986
+ const out = {};
987
+ for (const spec of specs ?? []) {
988
+ const eq = spec.indexOf("=");
989
+ if (eq <= 0) {
990
+ return fail(2 /* USAGE */, `--file must be field=@path, got '${spec}'.`);
991
+ }
992
+ const name = spec.slice(0, eq);
993
+ const raw = spec.slice(eq + 1);
994
+ const path = raw.startsWith("@") ? raw.slice(1) : raw;
995
+ let attached;
996
+ try {
997
+ attached = File.fromPath(path);
998
+ } catch (err) {
999
+ return fail(2 /* USAGE */, `Cannot read ${path}: ${err.message}`);
1000
+ }
1001
+ const existing = out[name];
1002
+ if (existing === void 0) out[name] = attached;
1003
+ else out[name] = Array.isArray(existing) ? [...existing, attached] : [existing, attached];
1004
+ }
1005
+ return out;
1006
+ }
1007
+ function previewArgs(value) {
1008
+ if (value instanceof File) {
1009
+ return { filename: value.filename, mime_type: value.mimeType, size: value.content.length };
1010
+ }
1011
+ if (Array.isArray(value)) return value.map((item) => previewArgs(item));
1012
+ if (value && typeof value === "object") {
1013
+ const out = {};
1014
+ for (const [key, item] of Object.entries(value)) {
1015
+ out[key] = previewArgs(item);
1016
+ }
1017
+ return out;
1018
+ }
1019
+ return value;
1020
+ }
1021
+ function collectFile(value, previous = []) {
1022
+ return [...previous, value];
1023
+ }
726
1024
  function parseConnection(value) {
727
1025
  if (value === void 0) return void 0;
728
1026
  const id = Number(value);
@@ -743,8 +1041,15 @@ function renderResult(result, opts) {
743
1041
  const call = { id: opts.toolCallId ?? opts.toolId, name: opts.toolId, arguments: {} };
744
1042
  return provider.formatToolResult(call, { output: result.output });
745
1043
  }
1044
+ const output = result.output;
1045
+ const size = Buffer.byteLength(serialize(output), "utf8");
1046
+ const historyId = result.historyId ?? null;
1047
+ if (!opts.inline && opts.maxBytes > 0 && size > opts.maxBytes) {
1048
+ const stored = storeResult(output, historyId);
1049
+ return buildEnvelope(stored.handle, historyId, stored.dataSize, output);
1050
+ }
746
1051
  return {
747
- output: result.output,
1052
+ output,
748
1053
  history_id: result.historyId,
749
1054
  execution_info: result.executionInfo
750
1055
  };
@@ -756,16 +1061,27 @@ async function callBody(toolId, opts) {
756
1061
  if (opts.args === void 0) {
757
1062
  fail(2 /* USAGE */, "Missing required option --args.");
758
1063
  }
759
- if (opts.raw && opts.llm) {
760
- fail(2 /* USAGE */, "Pass only one of --raw / --llm.");
1064
+ const modes = [
1065
+ ["--raw", Boolean(opts.raw)],
1066
+ ["--llm", Boolean(opts.llm)],
1067
+ ["--inline", Boolean(opts.inline)]
1068
+ ];
1069
+ const explicit = modes.filter(([, on]) => on).map(([name]) => name);
1070
+ if (explicit.length > 1) {
1071
+ fail(2 /* USAGE */, `Pass only one of ${explicit.join(", ")}.`);
1072
+ }
1073
+ const maxBytes = opts.maxBytes === void 0 ? 4096 : Number(opts.maxBytes);
1074
+ if (!Number.isFinite(maxBytes) || maxBytes < 0) {
1075
+ fail(2 /* USAGE */, "--max-bytes must be a non-negative integer.");
761
1076
  }
762
1077
  const args = loadArgs(opts.args);
1078
+ Object.assign(args, loadFiles(opts.file));
763
1079
  const connection = parseConnection(opts.connection);
764
1080
  if (dryRun()) {
765
1081
  printOutput({
766
1082
  would_call: {
767
1083
  tool_slug: toolId,
768
- arguments: args,
1084
+ arguments: previewArgs(args),
769
1085
  connection_id: connection ?? null,
770
1086
  toolset_id: opts.toolset ?? null
771
1087
  }
@@ -784,12 +1100,18 @@ async function callBody(toolId, opts) {
784
1100
  raw: opts.raw,
785
1101
  llm: opts.llm,
786
1102
  toolId,
787
- toolCallId: opts.toolCallId
1103
+ toolCallId: opts.toolCallId,
1104
+ maxBytes,
1105
+ inline: opts.inline
788
1106
  })
789
1107
  );
790
1108
  }
791
1109
  function registerToolsCall(tools) {
792
- const cmd = tools.command("call").description("Execute a tool against a connection.").argument("[tool_id]", "Tool slug").option("--args <args>", "JSON object, @file.json, or - for stdin").option("--connection <id>", "Connection id to run against").option("--toolset <id>", "Toolset id to resolve the connection").option("--raw", "Emit the tool output verbatim (no envelope)").option("--llm <vendor>", "Provider-shaped result: openai|anthropic").option("--tool-call-id <id>", "Correlation id for --llm output");
1110
+ const cmd = tools.command("call").description("Execute a tool against a connection.").argument("[tool_id]", "Tool slug").option("--args <args>", "JSON object, @file.json, or - for stdin").option(
1111
+ "--file <spec>",
1112
+ "Attach a file: field=@path (repeat the same field for a list of files)",
1113
+ collectFile
1114
+ ).option("--connection <id>", "Connection id to run against").option("--toolset <id>", "Toolset id to resolve the connection").option("--raw", "Emit the tool output verbatim (no envelope)").option("--llm <vendor>", "Provider-shaped result: openai|anthropic").option("--tool-call-id <id>", "Correlation id for --llm output").option("--max-bytes <n>", "Spill default-mode results larger than N bytes (0 = never)").option("--inline", "Force the full inline result, bypassing the sandbox");
793
1115
  addUniversalOptions(cmd, { mutating: true });
794
1116
  cmd.action(async (toolId, opts, command) => {
795
1117
  await runCommand(command, opts, true, () => callBody(toolId, opts));
@@ -880,12 +1202,83 @@ function registerToolsList(tools) {
880
1202
  });
881
1203
  }
882
1204
 
1205
+ // src/tools/result.ts
1206
+ function collectSelect(value, previous = []) {
1207
+ return [...previous, value];
1208
+ }
1209
+ function resultBody(handle, opts) {
1210
+ if (opts.list) {
1211
+ printOutput(listResults());
1212
+ return;
1213
+ }
1214
+ if (opts.clear) {
1215
+ printOutput({ cleared: clearResults() });
1216
+ return;
1217
+ }
1218
+ if (!handle) {
1219
+ fail(2 /* USAGE */, "Missing required argument 'handle'.", "Pass a handle, or use --list.");
1220
+ }
1221
+ const stored = loadResult(handle);
1222
+ if (stored === null) {
1223
+ fail(
1224
+ 4 /* NOT_FOUND */,
1225
+ `No stored result for handle '${handle}'.`,
1226
+ "It may have expired or been pruned; re-run the tool."
1227
+ );
1228
+ }
1229
+ const output = stored.output;
1230
+ if (opts.full) {
1231
+ printOutput(output);
1232
+ return;
1233
+ }
1234
+ const offset = opts.offset === void 0 ? 0 : Number(opts.offset);
1235
+ const limit = opts.limit === void 0 ? null : Number(opts.limit);
1236
+ const select = opts.select ?? [];
1237
+ const paging = offset !== 0 || limit !== null;
1238
+ if (select.length === 0 && opts.fields === void 0 && !paging) {
1239
+ printOutput(buildEnvelope(handle, stored.history_id ?? null, stored.data_size ?? null, output));
1240
+ return;
1241
+ }
1242
+ let value = output;
1243
+ if (select.length === 1) {
1244
+ value = selectPath(value, select[0]);
1245
+ } else if (select.length > 1) {
1246
+ const out = {};
1247
+ for (const path of select) out[path] = selectPath(output, path);
1248
+ value = out;
1249
+ }
1250
+ if (opts.fields !== void 0) {
1251
+ const keys = opts.fields.split(",").map((f) => f.trim()).filter(Boolean);
1252
+ value = projectFields(value, keys);
1253
+ }
1254
+ if (paging) {
1255
+ if (!Array.isArray(value)) {
1256
+ fail(2 /* USAGE */, "--offset/--limit require a list value.", "Use --select to reach a list first.");
1257
+ }
1258
+ value = paginate(value, offset, limit);
1259
+ }
1260
+ printOutput(value);
1261
+ }
1262
+ function registerToolsResult(tools) {
1263
+ const cmd = tools.command("result").description("Drill into a sandboxed tools call result.").argument("[handle]", "Result handle from a prior tools call").option("--select <path>", "Dot-path to extract, e.g. items.email (repeatable)", collectSelect).option("--fields <keys>", "Comma-separated keys to project from object(s)").option("--offset <n>", "Skip N items of a list value").option("--limit <m>", "Return at most M list items").option("--full", "Emit the entire stored payload").option("--list", "List stored result handles").option("--clear", "Delete all stored results");
1264
+ addUniversalOptions(cmd);
1265
+ cmd.action(async (handle, opts, command) => {
1266
+ await runCommand(
1267
+ command,
1268
+ opts,
1269
+ false,
1270
+ () => resultBody(handle, opts)
1271
+ );
1272
+ });
1273
+ }
1274
+
883
1275
  // src/tools/index.ts
884
1276
  function registerTools(program) {
885
1277
  const tools = program.command("tools").description("Discover and execute tools.");
886
1278
  registerToolsList(tools);
887
1279
  registerToolsGet(tools);
888
1280
  registerToolsCall(tools);
1281
+ registerToolsResult(tools);
889
1282
  }
890
1283
 
891
1284
  // src/whoami.ts
@@ -915,7 +1308,7 @@ function registerWhoami(program) {
915
1308
  }
916
1309
 
917
1310
  // src/version.ts
918
- var VERSION = true ? "0.5.1" : "0.0.0";
1311
+ var VERSION = true ? "0.7.0" : "0.0.0";
919
1312
 
920
1313
  // src/main.ts
921
1314
  function buildProgram() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "description": "Engini CLI — machine-first command line over the Engini Public API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "test": "vitest run"
22
22
  },
23
23
  "dependencies": {
24
- "@engini/sdk": "^0.5.1",
24
+ "@engini/sdk": "^0.7.0",
25
25
  "commander": "^12.1.0",
26
26
  "smol-toml": "^1.3.0"
27
27
  },