@granular-software/sdk 0.4.23 → 0.4.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.
@@ -137,14 +137,22 @@ function reviewGeneratedJobCode(code) {
137
137
  }
138
138
  }
139
139
  }
140
- const hasConversationalReturn = /return\s+[`'"]/.test(normalized) || /\breply\s*:/.test(normalized) || /\bagent_message\s*\(/.test(normalized);
140
+ const hasConversationalReturn = /return\s+[`'"]/.test(normalized) || /\breply\s*:/.test(normalized) || /\bagent_message\s*\(/.test(normalized) || /\bagent_text_message\s*\(/.test(normalized);
141
141
  const returnsObjectLiteral = /return\s+\{[\s\S]*?\}/.test(normalized);
142
+ const returnsShowPayload = /return\s+\{[\s\S]*?\bshow\s*:/.test(normalized);
142
143
  const closesLoop = /loop\.close_loop\s*\(/.test(normalized);
143
144
  if (!hasConversationalReturn && returnsObjectLiteral && !closesLoop) {
144
145
  issues.push({
145
146
  code: "missing_user_reply",
146
147
  severity: "error",
147
- message: "User-facing jobs must end with a natural-language answer. Return a short string, an object with a top-level `reply` string, or use agent_message({ reply, show }). Do not end with bare structured JSON."
148
+ message: "User-facing jobs must end with a natural-language answer. Return a short string, an object with a top-level `reply` string, or post text with agent_text_message(...). Do not end with bare structured JSON."
149
+ });
150
+ }
151
+ if (returnsShowPayload) {
152
+ issues.push({
153
+ code: "return_show_not_for_ui",
154
+ severity: "error",
155
+ message: "Do not use the final return value to send UI record refs through `show`. Use agent_heap_objects(...) for heap-backed UI, then return plain text if you still want a final textual answer."
148
156
  });
149
157
  }
150
158
  return issues;
@@ -994,7 +1002,7 @@ ${loopBlock}
994
1002
 
995
1003
  \u2500\u2500\u2500 CODE RULES \u2500\u2500\u2500
996
1004
  - Import from \`./sandbox-tools\`.
997
- - If you use \`heap\`, \`loop\`, or \`agent_message\`, import them explicitly from \`./sandbox-tools\`.
1005
+ - If you use \`heap\`, \`loop\`, \`agent_text_message\`, \`agent_heap_objects\`, or legacy \`agent_message\`, import them explicitly from \`./sandbox-tools\`.
998
1006
  - Write top-level executable code with \`await\` at top level.
999
1007
  - The generated job body must be plain runnable JavaScript. The DOMAIN TYPES block is only a reference for shapes and available methods.
1000
1008
  - Do not write TypeScript-only syntax in executable code: no type annotations, no interfaces, no enums, no \`as Type\` casts, no \`satisfies\`, and no generic type parameters in code.
@@ -1003,9 +1011,9 @@ ${loopBlock}
1003
1011
  - Never invent helper methods such as \`find(...)\` or unsupported parameters such as \`id\` when the typedefs require \`path\`.
1004
1012
  - Use \`ClassName.get({ path })\` only when you already know an object's graph path.
1005
1013
  - Use \`ClassName.count()\` when you only need a total.
1006
- - Use \`ClassName.page({ page, perPage, saveAs })\` when you need both records and pagination metadata like \`totalCount\` or \`hasMore\`.
1007
- - Use \`ClassName.list({ page, perPage, saveAs })\` to load one typed page of records. \`limit\` is only a legacy alias for \`perPage\`.
1008
- - Use \`for await (const item of ClassName.iterate({ perPage, maxItems }))\` for large batch jobs so you do not materialize the whole result set at once.
1014
+ - Use \`ClassName.page({ page, perPage, saveAs })\` when you need both records and pagination metadata like \`totalCount\` or \`hasMore\`. \`perPage\` defaults to \`100\` and larger values are clamped to \`100\`.
1015
+ - Use \`ClassName.list({ page, perPage, saveAs })\` to load one typed page of records. \`limit\` is only a legacy alias for \`perPage\`, \`perPage\` defaults to \`100\`, and larger values are clamped to \`100\`.
1016
+ - Use \`for await (const item of ClassName.iterate({ perPage, maxItems }))\` for large batch jobs so you do not materialize the whole result set at once. \`perPage\` defaults to \`100\` and larger values are clamped to \`100\`.
1009
1017
  - Instance methods: \`await instance.method_name(params)\`.
1010
1018
  - Static methods: \`await ClassName.static_method(params)\`.
1011
1019
  - Global effects: \`await effect_name(params)\`.
@@ -1036,14 +1044,17 @@ ${loopBlock}
1036
1044
  - \`loop.close_loop(...)\`: record the current workflow outcome with a short summary before stopping. Do not call it in the same job that opens a new user prompt unless the workflow is explicitly blocked. This does not end the session forever.
1037
1045
  - Avoid \`as any\` and other broad casts when the DOMAIN TYPES block already tells you the correct class or list type.
1038
1046
  - Prefer manipulating heap-backed instances and typed lists instead of returning raw JSON blobs or object IDs unless the user explicitly asks for them.
1039
- - If the user expects an answer after the job runs, the final \`return\` value must be either a short natural-language string or an object with a top-level \`reply\` string.
1040
- - You may call \`agent_message(...)\` multiple times in one job to post several assistant messages while the job is still running.
1041
- - Prefer \`agent_message({ reply, show })\` when you want to leave a user-facing answer and optionally show heap-backed records in the UI.
1042
- - \`agent_message(...)\` also accepts \`content\`, \`message\`, or \`text\` instead of \`reply\`.
1043
- - \`agent_message({ show })\` may receive explicit refs or sandbox instances and arrays of sandbox instances. The runtime will convert those into UI references.
1044
- - When it helps the UI show specific heap-backed results, you may instead return:
1045
- \`{ reply: string, show: { entryPaths?: string[], listNames?: string[], variableNames?: string[] } }\`
1046
- - If you create or load objects the user should see, save them in the heap and return references to them through \`show\` instead of serializing full objects.
1047
+ - Every job that intends to answer the user must emit at least one explicit UI message with \`agent_text_message(...)\` and/or \`agent_heap_objects(...)\`.
1048
+ - Use \`agent_text_message("...")\` for all user-visible text shown in the UI.
1049
+ - Use \`agent_heap_objects(...)\` only when you want the UI to render heap-backed records or lists.
1050
+ - If you want to show both text and records, call \`agent_text_message(...)\` and \`agent_heap_objects(...)\` separately in whatever order fits the interaction.
1051
+ - \`agent_text_message(...)\` should be used with a plain text string in normal generated code.
1052
+ - \`agent_heap_objects(...)\` should point at heap-backed values: explicit \`entryPaths\` / \`listNames\` / \`variableNames\`, a named list saved with \`saveAs\`, or values read back from \`heap.getVar(...)\`.
1053
+ - If you just fetched records and want to show them in the UI, save or reference them through the heap first, then call \`agent_heap_objects(...)\`. Do not try to hand-build UI payloads in job code.
1054
+ - Do not assume heap changes will be displayed automatically. If records should appear in the UI, you must call \`agent_heap_objects(...)\`.
1055
+ - Never write \`return { reply, show }\` or \`return { show: ... }\` for UI. If you want the UI to render records or lists, call \`agent_heap_objects(...)\` instead.
1056
+ - Do not rely on the final return value for user-visible output. A plain return value is not considered a displayed UI answer.
1057
+ - \`agent_message(...)\` remains available as a legacy compatibility alias, but prefer \`agent_text_message(...)\` and \`agent_heap_objects(...)\` in new code.
1047
1058
  - Do not return bare structured JSON, low-level diagnostics, or database-shaped payloads as the final answer unless the user explicitly asks for them.
1048
1059
  - Prefer simple executable JavaScript over clever interpolation. Avoid nested template literals or unusually dense inline expressions when a small temporary variable or string concatenation would be clearer and safer.
1049
1060
  - Use \`console.log()\` only for intermediate diagnostics, not for the final user-facing answer.`;