@withgateway/sdk 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +5 -1
  2. package/dist/cli.js +1497 -712
  3. package/dist/cli.js.map +1 -1
  4. package/dist/cli.mjs +1500 -715
  5. package/dist/cli.mjs.map +1 -1
  6. package/dist/files/index.js +34 -0
  7. package/dist/files/index.js.map +1 -1
  8. package/dist/files/index.mjs +34 -0
  9. package/dist/files/index.mjs.map +1 -1
  10. package/dist/{index-DAb-FCMg.d.ts → index-CBqbB_0J.d.ts} +2 -12
  11. package/dist/{index-D6oi1TWE.d.mts → index-D-AMnAMa.d.mts} +2 -12
  12. package/dist/index.d.mts +3 -3
  13. package/dist/index.d.ts +3 -3
  14. package/dist/index.js +173 -50
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +171 -50
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/traces/index.js +34 -0
  19. package/dist/traces/index.js.map +1 -1
  20. package/dist/traces/index.mjs +34 -0
  21. package/dist/traces/index.mjs.map +1 -1
  22. package/dist/tracing/index.d.mts +1 -1
  23. package/dist/tracing/index.d.ts +1 -1
  24. package/dist/tracing/index.js +39 -20
  25. package/dist/tracing/index.js.map +1 -1
  26. package/dist/tracing/index.mjs +39 -20
  27. package/dist/tracing/index.mjs.map +1 -1
  28. package/dist/worlds/index.d.mts +66 -18
  29. package/dist/worlds/index.d.ts +66 -18
  30. package/dist/worlds/index.js +171 -50
  31. package/dist/worlds/index.js.map +1 -1
  32. package/dist/worlds/index.mjs +171 -50
  33. package/dist/worlds/index.mjs.map +1 -1
  34. package/package.json +1 -1
  35. package/runtime/gatewaysdk/environment/schema/api.py +7 -8
  36. package/runtime/gatewaysdk/environment/schema/cast.py +31 -4
  37. package/runtime/gatewaysdk/environment/schema/platform.py +1 -7
  38. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +3 -3
  39. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +2 -2
  40. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +6 -6
  41. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +1 -1
  42. package/skills/connector-schema-authoring/SKILL.md +3 -3
  43. package/skills/connector-schema-authoring/connector-worlds.md +12 -5
  44. package/skills/connector-schema-authoring/world-schema.md +8 -0
  45. package/skills/world-data-ingestion/SKILL.md +2 -2
  46. package/skills/worlds-getting-started/SKILL.md +6 -6
  47. package/skills/worlds-getting-started/references/cli-mcp-map.md +1 -1
package/dist/cli.js CHANGED
@@ -131,24 +131,24 @@ function looksLikeFlag(token, known) {
131
131
  const name = token.replace(/^--?/, "").split("=")[0];
132
132
  return known.has(name);
133
133
  }
134
- function usageLine(path44, spec) {
134
+ function usageLine(path49, spec) {
135
135
  const pos = (spec.positionals ?? []).map(
136
136
  (p) => p.variadic ? `<${p.name}...>` : p.optional ? `[${p.name}]` : `<${p.name}>`
137
137
  ).join(" ");
138
- return `${path44.join(" ")} ${pos}`.trim();
138
+ return `${path49.join(" ")} ${pos}`.trim();
139
139
  }
140
- function helpFor(path44, node) {
140
+ function helpFor(path49, node) {
141
141
  if (node instanceof CommandGroup) {
142
- const lines2 = [`${path44.join(" ")} \u2014 ${node.help}`, ""];
142
+ const lines2 = [`${path49.join(" ")} \u2014 ${node.help}`, ""];
143
143
  for (const [name, g] of node.groups)
144
144
  lines2.push(` ${name.padEnd(16)} ${g.help}`);
145
145
  for (const [name, c] of node.commands)
146
146
  lines2.push(` ${name.padEnd(16)} ${c.help}`);
147
147
  if (node.notes) lines2.push("", node.notes);
148
- lines2.push("", `Run '${path44.join(" ")} <command> --help' for details.`);
148
+ lines2.push("", `Run '${path49.join(" ")} <command> --help' for details.`);
149
149
  return lines2.join("\n");
150
150
  }
151
- const lines = [usageLine(path44, node), "", ` ${node.help}`];
151
+ const lines = [usageLine(path49, node), "", ` ${node.help}`];
152
152
  const pos = node.positionals ?? [];
153
153
  if (pos.length) {
154
154
  lines.push("", "Arguments:");
@@ -173,12 +173,12 @@ function helpFor(path44, node) {
173
173
  }
174
174
  async function dispatch(root, argv, ctx) {
175
175
  let node = root;
176
- const path44 = [root.name];
176
+ const path49 = [root.name];
177
177
  let i = 0;
178
178
  while (i < argv.length) {
179
179
  const token = argv[i];
180
180
  if (token === "--help" || token === "-h") {
181
- ctx.stdout(helpFor(path44, node));
181
+ ctx.stdout(helpFor(path49, node));
182
182
  return 0;
183
183
  }
184
184
  if (node === root && root.version !== void 0 && (token === "--version" || token === "-V")) {
@@ -188,7 +188,7 @@ async function dispatch(root, argv, ctx) {
188
188
  const group = node.groups.get(token);
189
189
  if (group) {
190
190
  node = group;
191
- path44.push(token);
191
+ path49.push(token);
192
192
  i++;
193
193
  continue;
194
194
  }
@@ -196,7 +196,7 @@ async function dispatch(root, argv, ctx) {
196
196
  if (command2) {
197
197
  const rest = argv.slice(i + 1);
198
198
  if (rest.includes("--help") || rest.includes("-h")) {
199
- ctx.stdout(helpFor([...path44, token], command2));
199
+ ctx.stdout(helpFor([...path49, token], command2));
200
200
  return 0;
201
201
  }
202
202
  try {
@@ -213,13 +213,13 @@ async function dispatch(root, argv, ctx) {
213
213
  }
214
214
  }
215
215
  ctx.stderr(
216
- `Unknown command '${token}' under '${path44.join(" ")}'.
216
+ `Unknown command '${token}' under '${path49.join(" ")}'.
217
217
 
218
- ${helpFor(path44, node)}`
218
+ ${helpFor(path49, node)}`
219
219
  );
220
220
  return 2;
221
221
  }
222
- ctx.stdout(helpFor(path44, node));
222
+ ctx.stdout(helpFor(path49, node));
223
223
  return node === root ? 0 : 2;
224
224
  }
225
225
  var CommandGroup, JSON_FLAG, JSON_OUTPUT_FLAG, CliError, arg;
@@ -569,9 +569,9 @@ function surfaceKinds(s) {
569
569
  if (s.browser) kinds.push("browser");
570
570
  return kinds;
571
571
  }
572
- function uiUrl(ui, path44) {
572
+ function uiUrl(ui, path49) {
573
573
  const base = ui.url.replace(/\/+$/, "");
574
- const rel = path44.startsWith("/") ? path44 : `/${path44}`;
574
+ const rel = path49.startsWith("/") ? path49 : `/${path49}`;
575
575
  if (!ui.token) return base + rel;
576
576
  const [beforeHash, hash] = splitHash(rel);
577
577
  const joiner = beforeHash.includes("?") ? "&" : "?";
@@ -765,8 +765,8 @@ var init_browser = __esm({
765
765
  }
766
766
  resolveBase() {
767
767
  if (this.base === null) {
768
- const resolve29 = this.opts.resumeFrom ?? (async () => 0);
769
- this.base = resolve29().then((n) => {
768
+ const resolve32 = this.opts.resumeFrom ?? (async () => 0);
769
+ this.base = resolve32().then((n) => {
770
770
  if (!Number.isInteger(n) || n < 0)
771
771
  throw new Error(
772
772
  `browser event base seq must be a non-negative integer, got ${String(n)}`
@@ -1466,13 +1466,13 @@ var init_screen = __esm({
1466
1466
  });
1467
1467
  }
1468
1468
  async drag(action) {
1469
- const path44 = action.args.path ?? [];
1470
- if (path44.length < 2) throw new Error("a drag needs at least two points");
1469
+ const path49 = action.args.path ?? [];
1470
+ if (path49.length < 2) throw new Error("a drag needs at least two points");
1471
1471
  return this.held(action.args.modifiers ?? [], async () => {
1472
- await this.moveTo(path44[0]);
1472
+ await this.moveTo(path49[0]);
1473
1473
  await this.page.mouse.down({ button: "left" });
1474
1474
  try {
1475
- for (const point2 of path44.slice(1)) await this.moveTo(point2, DRAG_STEPS);
1475
+ for (const point2 of path49.slice(1)) await this.moveTo(point2, DRAG_STEPS);
1476
1476
  } finally {
1477
1477
  await this.page.mouse.up({ button: "left" });
1478
1478
  }
@@ -2490,9 +2490,9 @@ function getCurrentWorldSessionId() {
2490
2490
  return currentWorldSessionStorage.getStore();
2491
2491
  }
2492
2492
  function runIn(storage, value, fn) {
2493
- return new Promise((resolve29, reject) => {
2493
+ return new Promise((resolve32, reject) => {
2494
2494
  storage.run(value, () => {
2495
- Promise.resolve().then(fn).then(resolve29, reject);
2495
+ Promise.resolve().then(fn).then(resolve32, reject);
2496
2496
  });
2497
2497
  });
2498
2498
  }
@@ -2911,18 +2911,18 @@ var init_session2 = __esm({
2911
2911
  }
2912
2912
  /** The reporter `browser()` uses; exposed for a page you drive yourself. */
2913
2913
  browserRecorder(agentId) {
2914
- const path44 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
2914
+ const path49 = `/api/public/world-sessions/${encodeURIComponent(this.sessionId)}/browser-events`;
2915
2915
  const id = agentId ?? process.env.GATEWAY_AGENT_ID ?? `agent-${(0, import_node_crypto2.randomUUID)().replace(/-/g, "").slice(0, 8)}`;
2916
2916
  return new BrowserActionRecorder(
2917
2917
  async (events) => {
2918
- await apiRequest(this.options, "POST", path44, { events });
2918
+ await apiRequest(this.options, "POST", path49, { events });
2919
2919
  },
2920
2920
  id,
2921
2921
  {
2922
2922
  // Continue this agent's timeline where the platform has it, so the
2923
2923
  // same id reopened later never re-numbers from zero.
2924
2924
  resumeFrom: async () => {
2925
- const summary2 = await apiRequest(this.options, "GET", path44);
2925
+ const summary2 = await apiRequest(this.options, "GET", path49);
2926
2926
  return summary2.agents.find((a) => a.agentId === id)?.nextSeq ?? 0;
2927
2927
  }
2928
2928
  }
@@ -3308,6 +3308,28 @@ var init_tasks = __esm({
3308
3308
  }
3309
3309
  });
3310
3310
 
3311
+ // src/worlds/surfaceDescriptor.ts
3312
+ function surfaceDescriptor(s) {
3313
+ return {
3314
+ surfaces: surfaceKinds(s),
3315
+ ...s.api ? { api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} } } : {},
3316
+ ...s.ui ? { ui: { url: s.ui.url, entry: uiEntryUrl(s.ui), apiPath: s.ui.apiPath ?? null } } : {},
3317
+ ...s.browser ? {
3318
+ browser: {
3319
+ wsUrl: s.browser.wsUrl,
3320
+ viewport: s.browser.viewport,
3321
+ ...s.browser.tier ? { tier: s.browser.tier } : {}
3322
+ }
3323
+ } : {}
3324
+ };
3325
+ }
3326
+ var init_surfaceDescriptor = __esm({
3327
+ "src/worlds/surfaceDescriptor.ts"() {
3328
+ "use strict";
3329
+ init_browser();
3330
+ }
3331
+ });
3332
+
3311
3333
  // src/worlds/taskSessions.ts
3312
3334
  function aggregateTaskGrade(worlds) {
3313
3335
  const rewards = {};
@@ -3458,6 +3480,7 @@ var init_taskSessions = __esm({
3458
3480
  "use strict";
3459
3481
  init_worlds();
3460
3482
  init_browser();
3483
+ init_surfaceDescriptor();
3461
3484
  init_session2();
3462
3485
  TASK_SESSIONS = "/api/public/world-task-sessions";
3463
3486
  VERIFIER_REWARD_PREFIX = "x.";
@@ -3469,18 +3492,7 @@ var init_taskSessions = __esm({
3469
3492
  sessionId: state2.sessionId,
3470
3493
  ready: state2.ready,
3471
3494
  state: state2.state,
3472
- surfaces: surfaceKinds(s),
3473
- ...s.api ? {
3474
- api: { url: s.api.url, ...s.api.token ? { token: s.api.token } : {} }
3475
- } : {},
3476
- ...s.ui ? {
3477
- ui: {
3478
- url: s.ui.url,
3479
- entry: uiEntryUrl(s.ui),
3480
- apiPath: s.ui.apiPath ?? null
3481
- }
3482
- } : {},
3483
- ...s.browser ? { browser: { wsUrl: s.browser.wsUrl, viewport: s.browser.viewport } } : {}
3495
+ ...surfaceDescriptor(s)
3484
3496
  });
3485
3497
  TaskSessions = class {
3486
3498
  constructor(taskId, taskVersion, name, instruction, sessions, worlds, hash = null) {
@@ -3659,6 +3671,49 @@ var init_evals = __esm({
3659
3671
  }
3660
3672
  });
3661
3673
 
3674
+ // src/tracing/prerequisites.ts
3675
+ function getEnv(key2) {
3676
+ const value = process.env[key2];
3677
+ return value ? value : void 0;
3678
+ }
3679
+ function isGatewayConfigured() {
3680
+ return !!(getEnv(GATEWAY_ENV.HOST) && getEnv(GATEWAY_ENV.PUBLIC_KEY) && getEnv(GATEWAY_ENV.SECRET_KEY));
3681
+ }
3682
+ var GATEWAY_ENV, OPENTELEMETRY_PEERS, MODULE_NOT_FOUND, OpenTelemetryMissing;
3683
+ var init_prerequisites = __esm({
3684
+ "src/tracing/prerequisites.ts"() {
3685
+ "use strict";
3686
+ GATEWAY_ENV = {
3687
+ HOST: "GATEWAY_HOST",
3688
+ PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
3689
+ SECRET_KEY: "GATEWAY_SECRET_KEY",
3690
+ ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
3691
+ };
3692
+ OPENTELEMETRY_PEERS = [
3693
+ "@opentelemetry/api",
3694
+ "@opentelemetry/exporter-trace-otlp-http",
3695
+ "@opentelemetry/resources",
3696
+ "@opentelemetry/sdk-trace-base",
3697
+ "@opentelemetry/sdk-trace-node"
3698
+ ];
3699
+ MODULE_NOT_FOUND = /* @__PURE__ */ new Set(["MODULE_NOT_FOUND", "ERR_MODULE_NOT_FOUND"]);
3700
+ OpenTelemetryMissing = class _OpenTelemetryMissing extends Error {
3701
+ constructor() {
3702
+ super(
3703
+ `OpenTelemetry packages not found. Install them with:
3704
+ npm install ${OPENTELEMETRY_PEERS.join(" ")}`
3705
+ );
3706
+ this.name = "OpenTelemetryMissing";
3707
+ }
3708
+ static explains(error) {
3709
+ if (error instanceof _OpenTelemetryMissing) return true;
3710
+ const { code, message } = error ?? {};
3711
+ return MODULE_NOT_FOUND.has(String(code)) && String(message).includes("@opentelemetry/");
3712
+ }
3713
+ };
3714
+ }
3715
+ });
3716
+
3662
3717
  // src/users/index.ts
3663
3718
  function parseEvent(payload) {
3664
3719
  return {
@@ -3821,10 +3876,10 @@ var init_users = __esm({
3821
3876
  totalItems: Number(meta.totalItems ?? rows.length)
3822
3877
  };
3823
3878
  }
3824
- async requestJson(method, path44, payload) {
3879
+ async requestJson(method, path49, payload) {
3825
3880
  let response;
3826
3881
  try {
3827
- response = await fetch(`${this.host}${path44}`, {
3882
+ response = await fetch(`${this.host}${path49}`, {
3828
3883
  method,
3829
3884
  headers: {
3830
3885
  Authorization: this.authHeader(),
@@ -3835,17 +3890,17 @@ var init_users = __esm({
3835
3890
  });
3836
3891
  } catch (error) {
3837
3892
  throw new UserProfileError(
3838
- `${method} ${path44} failed: ${error instanceof Error ? error.message : String(error)}`,
3893
+ `${method} ${path49} failed: ${error instanceof Error ? error.message : String(error)}`,
3839
3894
  { cause: error }
3840
3895
  );
3841
3896
  }
3842
3897
  const text2 = await response.text();
3843
3898
  if (!response.ok) {
3844
3899
  throw new UserProfileError(
3845
- `${method} ${path44} failed (${response.status}): ${text2.slice(0, 500)}`
3900
+ `${method} ${path49} failed (${response.status}): ${text2.slice(0, 500)}`
3846
3901
  );
3847
3902
  }
3848
- this.log("%s %s -> %s", method, path44, response.status);
3903
+ this.log("%s %s -> %s", method, path49, response.status);
3849
3904
  return safeJson(text2);
3850
3905
  }
3851
3906
  authHeader() {
@@ -4140,14 +4195,14 @@ function coerceSignalValue(value) {
4140
4195
  return { numericValue: value, inferredType: "NUMERIC" };
4141
4196
  }
4142
4197
  async function success(name, value = true, options = {}) {
4143
- let client4;
4198
+ let client5;
4144
4199
  try {
4145
- client4 = ScoresClient.fromEnv();
4200
+ client5 = ScoresClient.fromEnv();
4146
4201
  } catch (error) {
4147
4202
  console.warn(`[gateway.scores] success '${name}' skipped`, error);
4148
4203
  return;
4149
4204
  }
4150
- await client4.success(name, value, options);
4205
+ await client5.success(name, value, options);
4151
4206
  }
4152
4207
  var import_api2, SUCCESS_SIGNAL_KEY, SUCCESS_METRIC_NAME_KEY, AGENT_ID_KEY, ScoreError, ScoresClient, scores;
4153
4208
  var init_scores = __esm({
@@ -4290,10 +4345,10 @@ var init_scores = __esm({
4290
4345
  metadata: signalMetadata
4291
4346
  });
4292
4347
  }
4293
- async request(method, path44, payload) {
4348
+ async request(method, path49, payload) {
4294
4349
  let response;
4295
4350
  try {
4296
- response = await fetch(`${this.host}${path44}`, {
4351
+ response = await fetch(`${this.host}${path49}`, {
4297
4352
  method,
4298
4353
  headers: {
4299
4354
  Authorization: this.authHeader(),
@@ -4304,17 +4359,17 @@ var init_scores = __esm({
4304
4359
  });
4305
4360
  } catch (error) {
4306
4361
  throw new ScoreError(
4307
- `${method} ${path44} failed: ${error instanceof Error ? error.message : String(error)}`,
4362
+ `${method} ${path49} failed: ${error instanceof Error ? error.message : String(error)}`,
4308
4363
  { cause: error }
4309
4364
  );
4310
4365
  }
4311
4366
  const text2 = await response.text();
4312
4367
  if (!response.ok) {
4313
4368
  throw new ScoreError(
4314
- `${method} ${path44} failed (${response.status}): ${text2.slice(0, 500)}`
4369
+ `${method} ${path49} failed (${response.status}): ${text2.slice(0, 500)}`
4315
4370
  );
4316
4371
  }
4317
- this.log("%s %s -> %s", method, path44, response.status);
4372
+ this.log("%s %s -> %s", method, path49, response.status);
4318
4373
  }
4319
4374
  authHeader() {
4320
4375
  return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
@@ -4342,7 +4397,7 @@ var require_package = __commonJS({
4342
4397
  "package.json"(exports2, module2) {
4343
4398
  module2.exports = {
4344
4399
  name: "@withgateway/sdk",
4345
- version: "0.3.0",
4400
+ version: "0.3.1",
4346
4401
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
4347
4402
  main: "./dist/index.js",
4348
4403
  module: "./dist/index.mjs",
@@ -4751,10 +4806,6 @@ __export(init_exports, {
4751
4806
  isInitialized: () => isInitialized,
4752
4807
  shutdown: () => shutdown
4753
4808
  });
4754
- function getEnv(key2) {
4755
- const value = process.env[key2];
4756
- return value ? value : void 0;
4757
- }
4758
4809
  function log(message, ...args) {
4759
4810
  if (state.debug) {
4760
4811
  console.log(`[gatewaysdk.tracing] ${message}`, ...args);
@@ -4764,10 +4815,10 @@ function warn(message, ...args) {
4764
4815
  console.warn(`[gatewaysdk.tracing] ${message}`, ...args);
4765
4816
  }
4766
4817
  function buildProvider(config, logFn) {
4767
- const host = config.host ?? getEnv(ENV_VARS.HOST);
4768
- const publicKey = config.publicKey ?? getEnv(ENV_VARS.PUBLIC_KEY);
4769
- const secretKey = config.secretKey ?? getEnv(ENV_VARS.SECRET_KEY);
4770
- const endpoint = config.endpoint ?? getEnv(ENV_VARS.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
4818
+ const host = config.host ?? getEnv(GATEWAY_ENV.HOST);
4819
+ const publicKey = config.publicKey ?? getEnv(GATEWAY_ENV.PUBLIC_KEY);
4820
+ const secretKey = config.secretKey ?? getEnv(GATEWAY_ENV.SECRET_KEY);
4821
+ const endpoint = config.endpoint ?? getEnv(GATEWAY_ENV.ENDPOINT) ?? (host ? `${host.replace(/\/$/, "")}${DEFAULT_OTLP_PATH}` : void 0);
4771
4822
  const missing = [];
4772
4823
  if (!host) missing.push("host (or GATEWAY_HOST env var)");
4773
4824
  if (!publicKey) missing.push("publicKey (or GATEWAY_PUBLIC_KEY env var)");
@@ -4804,9 +4855,7 @@ function buildProvider(config, logFn) {
4804
4855
  ATTR_SERVICE_NAME = "service.name";
4805
4856
  }
4806
4857
  } catch {
4807
- throw new Error(
4808
- "OpenTelemetry packages not found. Install them with:\nnpm install @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources"
4809
- );
4858
+ throw new OpenTelemetryMissing();
4810
4859
  }
4811
4860
  const resourceAttrs = {
4812
4861
  [ATTR_SERVICE_NAME]: config.serviceName ?? "gatewaysdk-tracing"
@@ -5012,13 +5061,7 @@ async function shutdown() {
5012
5061
  function isInitialized() {
5013
5062
  return state.initialized;
5014
5063
  }
5015
- function isGatewayConfigured() {
5016
- const host = getEnv(ENV_VARS.HOST);
5017
- const publicKey = getEnv(ENV_VARS.PUBLIC_KEY);
5018
- const secretKey = getEnv(ENV_VARS.SECRET_KEY);
5019
- return !!(host && publicKey && secretKey);
5020
- }
5021
- var ENV_VARS, DEFAULT_OTLP_PATH, state;
5064
+ var DEFAULT_OTLP_PATH, state;
5022
5065
  var init_init = __esm({
5023
5066
  "src/tracing/init.ts"() {
5024
5067
  "use strict";
@@ -5027,12 +5070,8 @@ var init_init = __esm({
5027
5070
  init_session();
5028
5071
  init_scores();
5029
5072
  init_build();
5030
- ENV_VARS = {
5031
- HOST: "GATEWAY_HOST",
5032
- PUBLIC_KEY: "GATEWAY_PUBLIC_KEY",
5033
- SECRET_KEY: "GATEWAY_SECRET_KEY",
5034
- ENDPOINT: "GATEWAY_OTLP_ENDPOINT"
5035
- };
5073
+ init_prerequisites();
5074
+ init_prerequisites();
5036
5075
  DEFAULT_OTLP_PATH = "/api/public/otel/v1/traces";
5037
5076
  state = {
5038
5077
  initialized: false,
@@ -5041,6 +5080,45 @@ var init_init = __esm({
5041
5080
  }
5042
5081
  });
5043
5082
 
5083
+ // src/worlds/taskTracing.ts
5084
+ var TaskTracing;
5085
+ var init_taskTracing = __esm({
5086
+ "src/worlds/taskTracing.ts"() {
5087
+ "use strict";
5088
+ init_prerequisites();
5089
+ TaskTracing = class _TaskTracing {
5090
+ constructor(load = () => Promise.resolve().then(() => (init_init(), init_exports))) {
5091
+ this.load = load;
5092
+ }
5093
+ load;
5094
+ static warned = false;
5095
+ async start(requested) {
5096
+ if (!requested || !isGatewayConfigured()) return false;
5097
+ try {
5098
+ (await this.load()).init();
5099
+ return true;
5100
+ } catch (error) {
5101
+ _TaskTracing.warnOnce(error);
5102
+ return false;
5103
+ }
5104
+ }
5105
+ static warnOnce(error) {
5106
+ if (_TaskTracing.warned) return;
5107
+ _TaskTracing.warned = true;
5108
+ console.warn(
5109
+ `[gatewaysdk.tracing] Task runs in this process are not traced. ${_TaskTracing.reason(error)}
5110
+ Pass --no-trace (trace: false) to run untraced without this warning.`
5111
+ );
5112
+ }
5113
+ static reason(error) {
5114
+ if (OpenTelemetryMissing.explains(error))
5115
+ return new OpenTelemetryMissing().message;
5116
+ return error instanceof Error ? error.message : String(error);
5117
+ }
5118
+ };
5119
+ }
5120
+ });
5121
+
5044
5122
  // src/worlds/taskRun.ts
5045
5123
  function worldRef(live, alias) {
5046
5124
  const { slug, ref } = live.worldRef(alias);
@@ -5153,18 +5231,7 @@ async function runTask(ref, agent, opts) {
5153
5231
  const started = Date.now();
5154
5232
  try {
5155
5233
  await live.ready();
5156
- let traced = false;
5157
- if (opts.trace !== false) {
5158
- try {
5159
- const { isGatewayConfigured: isGatewayConfigured2, init: init2 } = await Promise.resolve().then(() => (init_init(), init_exports));
5160
- if (isGatewayConfigured2()) {
5161
- init2();
5162
- traced = true;
5163
- }
5164
- } catch {
5165
- traced = false;
5166
- }
5167
- }
5234
+ const traced = await new TaskTracing().start(opts.trace !== false);
5168
5235
  const taskRun = new TaskRun(
5169
5236
  runId,
5170
5237
  live.instruction ?? "",
@@ -5255,6 +5322,7 @@ var init_taskRun = __esm({
5255
5322
  init_evals();
5256
5323
  init_session2();
5257
5324
  init_taskSessions();
5325
+ init_taskTracing();
5258
5326
  TaskRun = class {
5259
5327
  constructor(runId, instruction, model, sessions, manifest) {
5260
5328
  this.runId = runId;
@@ -5353,9 +5421,9 @@ var init_checkoutProvenance = __esm({
5353
5421
  static withoutCredentials(url) {
5354
5422
  return url.replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]+@/i, "$1");
5355
5423
  }
5356
- withPr(checkout) {
5424
+ withPr(checkout2) {
5357
5425
  const pr = this.pullRequest();
5358
- return pr ? { ...checkout, pr } : checkout;
5426
+ return pr ? { ...checkout2, pr } : checkout2;
5359
5427
  }
5360
5428
  pullRequest() {
5361
5429
  const url = this.env.GATEWAY_PR_URL;
@@ -5458,6 +5526,52 @@ var init_setRun = __esm({
5458
5526
  }
5459
5527
  });
5460
5528
 
5529
+ // src/worlds/requestLog.ts
5530
+ var WorldRequestLog;
5531
+ var init_requestLog = __esm({
5532
+ "src/worlds/requestLog.ts"() {
5533
+ "use strict";
5534
+ WorldRequestLog = class _WorldRequestLog {
5535
+ constructor(requests) {
5536
+ this.requests = requests;
5537
+ }
5538
+ requests;
5539
+ static async read(session) {
5540
+ const state2 = await session.state();
5541
+ const calls = state2?.calls;
5542
+ if (!Array.isArray(calls)) return null;
5543
+ return new _WorldRequestLog(calls.filter((c) => typeof c === "object" && c !== null));
5544
+ }
5545
+ /** How many older requests the world no longer keeps (its log is bounded): the gap
5546
+ * before the first entry it still holds. */
5547
+ get dropped() {
5548
+ const first = Number(this.requests[0]?.seq) || 1;
5549
+ return Math.max(0, first - 1);
5550
+ }
5551
+ /** Each request in the shape of a ledger line, `kind: "request"`, so one JSONL
5552
+ * file holds both. */
5553
+ asCalls() {
5554
+ return this.requests.map((r) => ({
5555
+ seq: Number(r.seq) || 0,
5556
+ kind: "request",
5557
+ tool: r.operation ?? null,
5558
+ args: {
5559
+ method: r.method ?? null,
5560
+ path: r.path ?? null,
5561
+ args: r.args ?? null,
5562
+ query: r.query ?? null,
5563
+ body: r.body ?? null,
5564
+ via: r.via ?? null
5565
+ },
5566
+ result: { status: r.status ?? null, rows: r.rows ?? null, found: r.found ?? null },
5567
+ error: null,
5568
+ completedAt: r.at ?? null
5569
+ }));
5570
+ }
5571
+ };
5572
+ }
5573
+ });
5574
+
5461
5575
  // src/worlds/checkoutTarget.ts
5462
5576
  var fs2, path2, CheckoutRefusedError, NAMED_EDITS, CheckoutTarget;
5463
5577
  var init_checkoutTarget = __esm({
@@ -6070,7 +6184,7 @@ async function push(dir, opts = {}) {
6070
6184
  ...opts.tags !== void 0 ? { tags: opts.tags } : {},
6071
6185
  ...opts.visibility ? { visibility: opts.visibility } : {}
6072
6186
  };
6073
- const resolve29 = await apiRequest(
6187
+ const resolve32 = await apiRequest(
6074
6188
  options,
6075
6189
  "POST",
6076
6190
  "/api/public/benchmark-containers/resolve",
@@ -6079,7 +6193,7 @@ async function push(dir, opts = {}) {
6079
6193
  const tarball = buildSourceTarball(dir);
6080
6194
  const bundleSha256 = sha256b64(tarball);
6081
6195
  const version = await apiRequest(options, "POST", "/api/public/benchmark-containers/versions", {
6082
- containerId: resolve29.containerId,
6196
+ containerId: resolve32.containerId,
6083
6197
  contentHash,
6084
6198
  bundleSha256,
6085
6199
  bundleSizeBytes: tarball.length,
@@ -6118,7 +6232,7 @@ async function push(dir, opts = {}) {
6118
6232
  baseFiles: snapshotTreeHashes(dir)
6119
6233
  });
6120
6234
  return {
6121
- containerId: resolve29.containerId,
6235
+ containerId: resolve32.containerId,
6122
6236
  slug,
6123
6237
  versionId: version.versionId,
6124
6238
  contentHash,
@@ -6143,7 +6257,7 @@ async function pull(slugRef, target, options = {}, opts = {}) {
6143
6257
  const at = slugRef.indexOf("@");
6144
6258
  const slug = at === -1 ? slugRef : slugRef.slice(0, at);
6145
6259
  const ref = at === -1 ? "latest" : slugRef.slice(at + 1);
6146
- const landing = CheckoutTarget.resolve(slug, target, {
6260
+ const landing2 = CheckoutTarget.resolve(slug, target, {
6147
6261
  cwd: process.cwd(),
6148
6262
  force: opts.force ?? false,
6149
6263
  state: localTreeState
@@ -6163,9 +6277,9 @@ async function pull(slugRef, target, options = {}, opts = {}) {
6163
6277
  `bundle integrity check failed for ${slug}@${ref}: downloaded sha256 != recorded bundleSha256`
6164
6278
  );
6165
6279
  }
6166
- const dir = landing.dir;
6280
+ const dir = landing2.dir;
6167
6281
  fs5.mkdirSync(dir, { recursive: true });
6168
- landing.clear();
6282
+ landing2.clear();
6169
6283
  const files = extractBundle(bundle, dir);
6170
6284
  writeLocalMeta(dir, {
6171
6285
  slug,
@@ -6462,7 +6576,7 @@ function rebaseConflicts(error) {
6462
6576
  }
6463
6577
  const conflicts = body?.conflicts;
6464
6578
  if (!Array.isArray(conflicts)) return null;
6465
- return conflicts.filter(isConflictPath).map(({ path: path44, reason }) => ({ path: path44, reason }));
6579
+ return conflicts.filter(isConflictPath).map(({ path: path49, reason }) => ({ path: path49, reason }));
6466
6580
  }
6467
6581
  function isConflictPath(value) {
6468
6582
  const entry = value;
@@ -6502,8 +6616,8 @@ var init_sandbox = __esm({
6502
6616
  this.options = options;
6503
6617
  }
6504
6618
  options;
6505
- request(method, path44, body) {
6506
- return apiRequest(this.options, method, path44, body, {
6619
+ request(method, path49, body) {
6620
+ return apiRequest(this.options, method, path49, body, {
6507
6621
  timeoutMs: SANDBOX_REQUEST_TIMEOUT_MS
6508
6622
  });
6509
6623
  }
@@ -7091,6 +7205,7 @@ var init_migrate = __esm({
7091
7205
  // src/cli/runtime/local.ts
7092
7206
  var local_exports = {};
7093
7207
  __export(local_exports, {
7208
+ MIN_PYTHON_LABEL: () => MIN_PYTHON_LABEL,
7094
7209
  assertPortFree: () => assertPortFree,
7095
7210
  credentialsForRuntime: () => credentialsForRuntime,
7096
7211
  findPython: () => findPython,
@@ -7215,7 +7330,7 @@ function localPythonHasYaml(python) {
7215
7330
  }
7216
7331
  async function localBridge(request, local, opts = {}) {
7217
7332
  const input = JSON.stringify(request);
7218
- return await new Promise((resolve29, reject) => {
7333
+ return await new Promise((resolve32, reject) => {
7219
7334
  const child = (0, import_node_child_process2.spawn)(
7220
7335
  local.python,
7221
7336
  ["-I", "-B", "-c", BRIDGE_BOOTSTRAP, local.root],
@@ -7260,7 +7375,7 @@ async function localBridge(request, local, opts = {}) {
7260
7375
  payload = null;
7261
7376
  }
7262
7377
  if (payload && typeof payload === "object") {
7263
- resolve29(payload);
7378
+ resolve32(payload);
7264
7379
  return;
7265
7380
  }
7266
7381
  reject(
@@ -7289,10 +7404,10 @@ function portOwner(port) {
7289
7404
  return `pid ${pid}${command2 ? ` (${command2})` : ""}`;
7290
7405
  }
7291
7406
  async function assertPortFree(port, host = "127.0.0.1") {
7292
- const taken = await new Promise((resolve29) => {
7407
+ const taken = await new Promise((resolve32) => {
7293
7408
  const probe = net.createServer();
7294
- probe.once("error", () => resolve29(true));
7295
- probe.listen(port, host, () => probe.close(() => resolve29(false)));
7409
+ probe.once("error", () => resolve32(true));
7410
+ probe.listen(port, host, () => probe.close(() => resolve32(false)));
7296
7411
  });
7297
7412
  if (!taken) return;
7298
7413
  const owner = portOwner(port);
@@ -7302,7 +7417,7 @@ async function assertPortFree(port, host = "127.0.0.1") {
7302
7417
  );
7303
7418
  }
7304
7419
  async function localModule(argv, local, opts = {}) {
7305
- return await new Promise((resolve29, reject) => {
7420
+ return await new Promise((resolve32, reject) => {
7306
7421
  const child = (0, import_node_child_process2.spawn)(
7307
7422
  local.python,
7308
7423
  ["-B", "-c", MODULE_BOOTSTRAP, local.root, ...argv],
@@ -7335,7 +7450,7 @@ async function localModule(argv, local, opts = {}) {
7335
7450
  });
7336
7451
  child.on("close", (code, signal) => {
7337
7452
  release();
7338
- resolve29(code ?? (signal ? 130 : 1));
7453
+ resolve32(code ?? (signal ? 130 : 1));
7339
7454
  });
7340
7455
  });
7341
7456
  }
@@ -7347,7 +7462,7 @@ function credentialsForRuntime(hostFlag) {
7347
7462
  throw error;
7348
7463
  }
7349
7464
  }
7350
- var import_node_child_process2, fs6, net, path6, MIN_PYTHON, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, MODULE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
7465
+ var import_node_child_process2, fs6, net, path6, MIN_PYTHON, MIN_PYTHON_LABEL, DIAGNOSTIC_TAIL, BRIDGE_BOOTSTRAP, MODULE_BOOTSTRAP, pythonCache, pythonProbes, PYTHON_CANDIDATES, UV_FIND;
7351
7466
  var init_local = __esm({
7352
7467
  "src/cli/runtime/local.ts"() {
7353
7468
  "use strict";
@@ -7358,6 +7473,7 @@ var init_local = __esm({
7358
7473
  init_router();
7359
7474
  init_config();
7360
7475
  MIN_PYTHON = [3, 12];
7476
+ MIN_PYTHON_LABEL = MIN_PYTHON.join(".");
7361
7477
  DIAGNOSTIC_TAIL = 600;
7362
7478
  BRIDGE_BOOTSTRAP = `import sys,runpy,types,os
7363
7479
  root=sys.argv[1]
@@ -7855,7 +7971,7 @@ async function runTransform(script, records2, opts = {}) {
7855
7971
  try {
7856
7972
  const { file, args } = command(resolved, scratch);
7857
7973
  const env = Object.fromEntries(Object.entries(process.env).filter(([key2]) => !SCRUBBED.test(key2)));
7858
- const done = await new Promise((resolve29, reject) => {
7974
+ const done = await new Promise((resolve32, reject) => {
7859
7975
  const child = (0, import_node_child_process3.spawn)(file, args, { cwd: path9.dirname(resolved), env, stdio: ["pipe", "pipe", "pipe"] });
7860
7976
  let stdout = "";
7861
7977
  let stderr = "";
@@ -7872,7 +7988,7 @@ async function runTransform(script, records2, opts = {}) {
7872
7988
  });
7873
7989
  child.on("close", (code) => {
7874
7990
  clearTimeout(timer);
7875
- resolve29({ code, stdout, stderr, timedOut });
7991
+ resolve32({ code, stdout, stderr, timedOut });
7876
7992
  });
7877
7993
  child.stdin.on("error", () => void 0);
7878
7994
  child.stdin.end(records2.map((record) => JSON.stringify(record) + "\n").join(""));
@@ -8020,12 +8136,12 @@ async function forEachLimited(items, limit, fn) {
8020
8136
  await Promise.all(inFlight);
8021
8137
  if (failure) throw failure;
8022
8138
  }
8023
- async function waitForBatch(client4, batchId, opts = {}) {
8024
- const sleep4 = opts.sleep ?? client4.sleep;
8139
+ async function waitForBatch(client5, batchId, opts = {}) {
8140
+ const sleep4 = opts.sleep ?? client5.sleep;
8025
8141
  let delay = opts.initialDelayMs ?? 1e3;
8026
8142
  let last = "";
8027
8143
  for (; ; ) {
8028
- const status = await client4.get(batchId);
8144
+ const status = await client5.get(batchId);
8029
8145
  const phase = phaseLine(status);
8030
8146
  if (phase !== last) {
8031
8147
  opts.onPhase?.(phase);
@@ -8075,7 +8191,7 @@ var init_batches = __esm({
8075
8191
  "published",
8076
8192
  "failed"
8077
8193
  ]);
8078
- sleepMs = (ms) => new Promise((resolve29) => setTimeout(resolve29, ms));
8194
+ sleepMs = (ms) => new Promise((resolve32) => setTimeout(resolve32, ms));
8079
8195
  slugOf = (world) => world.split("@", 1)[0];
8080
8196
  WorldDataApi = class {
8081
8197
  constructor(creds, slug, sleep4 = sleepMs) {
@@ -8347,8 +8463,8 @@ __export(push_exports, {
8347
8463
  pushRows: () => pushRows
8348
8464
  });
8349
8465
  async function pushRows(creds, slug, rows, opts = {}) {
8350
- const client4 = opts.sleep ? new WorldDataApi(creds, slug, opts.sleep) : new WorldDataApi(creds, slug);
8351
- const opened = await client4.open({
8466
+ const client5 = opts.sleep ? new WorldDataApi(creds, slug, opts.sleep) : new WorldDataApi(creds, slug);
8467
+ const opened = await client5.open({
8352
8468
  mode: opts.mode ?? "append",
8353
8469
  merge: "upsert",
8354
8470
  ...opts.redact && opts.redact !== "off" ? { redact: opts.redact } : {},
@@ -8365,10 +8481,10 @@ async function pushRows(creds, slug, rows, opts = {}) {
8365
8481
  })();
8366
8482
  const chunks = buildChunks(tagged, { chunkBytes: opts.chunkBytes ?? DEFAULT_CHUNK_BYTES, chunkRows: null, entity: null });
8367
8483
  await forEachLimited(chunks, Math.max(1, opts.parallel ?? 4), async (chunk) => {
8368
- await client4.upload(opened.batchId, chunk);
8484
+ await client5.upload(opened.batchId, chunk);
8369
8485
  });
8370
- await client4.complete(opened.batchId);
8371
- return waitForBatch(client4, opened.batchId, { initialDelayMs: pollMs() });
8486
+ await client5.complete(opened.batchId);
8487
+ return waitForBatch(client5, opened.batchId, { initialDelayMs: pollMs() });
8372
8488
  }
8373
8489
  function pollMs() {
8374
8490
  const raw = Number(process.env.GATEWAY_WORLD_DATA_POLL_MS ?? 1e3);
@@ -8731,7 +8847,7 @@ var init_dryRun = __esm({
8731
8847
  /** Poll until the run settles or `timeoutSeconds` pass; the last verdict either way. */
8732
8848
  async settle(runId, opts) {
8733
8849
  const now = opts.now ?? Date.now;
8734
- const sleep4 = opts.sleep ?? ((ms) => new Promise((resolve29) => setTimeout(resolve29, ms)));
8850
+ const sleep4 = opts.sleep ?? ((ms) => new Promise((resolve32) => setTimeout(resolve32, ms)));
8735
8851
  const deadline = now() + opts.timeoutSeconds * 1e3;
8736
8852
  for (; ; ) {
8737
8853
  const budget = Math.floor(
@@ -8844,6 +8960,7 @@ __export(worlds_exports, {
8844
8960
  WorldBrowser: () => WorldBrowser,
8845
8961
  WorldCallTooLarge: () => WorldCallTooLarge,
8846
8962
  WorldEditClient: () => WorldEditClient,
8963
+ WorldRequestLog: () => WorldRequestLog,
8847
8964
  WorldSandboxClient: () => WorldSandboxClient,
8848
8965
  WorldSession: () => WorldSession,
8849
8966
  WorldSessionCallError: () => WorldSessionCallError,
@@ -8937,6 +9054,7 @@ __export(worlds_exports, {
8937
9054
  shapeText: () => shapeText,
8938
9055
  snapshotTreeHashes: () => snapshotTreeHashes,
8939
9056
  storedForms: () => storedForms,
9057
+ surfaceDescriptor: () => surfaceDescriptor,
8940
9058
  surfaceKinds: () => surfaceKinds,
8941
9059
  taskLabel: () => taskLabel,
8942
9060
  toolCallRecordsIn: () => toolCallRecordsIn,
@@ -8982,9 +9100,9 @@ function parseErrorBody(text2, limit = 600) {
8982
9100
  code: stableCode
8983
9101
  };
8984
9102
  }
8985
- async function apiRequest(options, method, path44, body, init2 = {}) {
8986
- const reply = await new PlatformTransport(resolveEnv(options)).send(method, path44, body, init2);
8987
- if (!reply.ok) throw new ApiError(reply.status, method, path44, reply.text);
9103
+ async function apiRequest(options, method, path49, body, init2 = {}) {
9104
+ const reply = await new PlatformTransport(resolveEnv(options)).send(method, path49, body, init2);
9105
+ if (!reply.ok) throw new ApiError(reply.status, method, path49, reply.text);
8988
9106
  return JSON.parse(reply.text);
8989
9107
  }
8990
9108
  async function setEnvSecret(slug, key2, value, options = {}) {
@@ -9079,7 +9197,7 @@ async function waitForRun(runId, opts = {}) {
9079
9197
  );
9080
9198
  opts.onTick?.(run);
9081
9199
  await new Promise(
9082
- (resolve29) => setTimeout(resolve29, (opts.intervalSeconds ?? 20) * 1e3)
9200
+ (resolve32) => setTimeout(resolve32, (opts.intervalSeconds ?? 20) * 1e3)
9083
9201
  );
9084
9202
  }
9085
9203
  }
@@ -9178,6 +9296,8 @@ var init_worlds = __esm({
9178
9296
  init_checkoutProvenance();
9179
9297
  init_evals();
9180
9298
  init_browser();
9299
+ init_surfaceDescriptor();
9300
+ init_requestLog();
9181
9301
  init_browserReconnect();
9182
9302
  init_nativeComputer();
9183
9303
  init_hub();
@@ -9192,9 +9312,9 @@ var init_worlds = __esm({
9192
9312
  init_editSessions();
9193
9313
  init_dryRun();
9194
9314
  ApiError = class extends Error {
9195
- constructor(status, method, path44, text2) {
9315
+ constructor(status, method, path49, text2) {
9196
9316
  const parsed = parseErrorBody(text2);
9197
- super(`${method} ${path44} -> ${status}: ${parsed.detail}`);
9317
+ super(`${method} ${path49} -> ${status}: ${parsed.detail}`);
9198
9318
  this.status = status;
9199
9319
  this.text = text2;
9200
9320
  this.name = "ApiError";
@@ -9494,21 +9614,21 @@ function listFiles(dir, rel = "") {
9494
9614
  function packagedFiles(name) {
9495
9615
  const directory = skillDir(name);
9496
9616
  const files = {};
9497
- for (const relative4 of listFiles(directory)) files[`.claude/skills/${name}/${relative4}`] = path15.join(directory, relative4);
9617
+ for (const relative6 of listFiles(directory)) files[`.claude/skills/${name}/${relative6}`] = path15.join(directory, relative6);
9498
9618
  for (const agent of SKILL_AGENTS[name] ?? []) files[`.claude/agents/${agent}`] = path15.join(skillsRoot(), "agents", agent);
9499
9619
  return files;
9500
9620
  }
9501
9621
  function installSkill(destination, name, force = false) {
9502
9622
  const report = { written: [], unchanged: [], conflicts: [] };
9503
9623
  const planned = [];
9504
- for (const [relative4, source2] of Object.entries(packagedFiles(name))) {
9624
+ for (const [relative6, source2] of Object.entries(packagedFiles(name))) {
9505
9625
  const content = fs17.readFileSync(source2);
9506
- const target = path15.join(destination, relative4);
9507
- if (fs17.existsSync(target) && fs17.readFileSync(target).equals(content)) report.unchanged.push(relative4);
9508
- else if (fs17.existsSync(target) && !force) report.conflicts.push(relative4);
9626
+ const target = path15.join(destination, relative6);
9627
+ if (fs17.existsSync(target) && fs17.readFileSync(target).equals(content)) report.unchanged.push(relative6);
9628
+ else if (fs17.existsSync(target) && !force) report.conflicts.push(relative6);
9509
9629
  else {
9510
9630
  planned.push([target, content]);
9511
- report.written.push(relative4);
9631
+ report.written.push(relative6);
9512
9632
  }
9513
9633
  }
9514
9634
  if (report.conflicts.length) {
@@ -9530,12 +9650,12 @@ function printOrInstallSkill(ctx, name, install, force) {
9530
9650
  const report = installSkill(install, name, force);
9531
9651
  if (report.conflicts.length) {
9532
9652
  ctx.stderr("Refusing to overwrite files that differ from the packaged skill:");
9533
- for (const relative4 of report.conflicts) ctx.stderr(` ${path15.join(install, relative4)}`);
9653
+ for (const relative6 of report.conflicts) ctx.stderr(` ${path15.join(install, relative6)}`);
9534
9654
  ctx.stderr("Pass --force to replace them.");
9535
9655
  return 1;
9536
9656
  }
9537
- for (const relative4 of report.written) ctx.stdout(`wrote ${path15.join(install, relative4)}`);
9538
- for (const relative4 of report.unchanged) ctx.stdout(`unchanged ${path15.join(install, relative4)}`);
9657
+ for (const relative6 of report.written) ctx.stdout(`wrote ${path15.join(install, relative6)}`);
9658
+ for (const relative6 of report.unchanged) ctx.stdout(`unchanged ${path15.join(install, relative6)}`);
9539
9659
  const step = NEXT_STEPS[name];
9540
9660
  if (step) ctx.stdout(`next: ${step}`);
9541
9661
  }
@@ -9682,10 +9802,10 @@ ${equivalent}`);
9682
9802
  return 2;
9683
9803
  }
9684
9804
  function appendStepSummary(text2) {
9685
- const path44 = process.env.GITHUB_STEP_SUMMARY;
9686
- if (!path44) return;
9805
+ const path49 = process.env.GITHUB_STEP_SUMMARY;
9806
+ if (!path49) return;
9687
9807
  try {
9688
- fs20.appendFileSync(path44, text2 + "\n\n");
9808
+ fs20.appendFileSync(path49, text2 + "\n\n");
9689
9809
  } catch {
9690
9810
  }
9691
9811
  }
@@ -9693,7 +9813,14 @@ function printDeprecations(ctx, deprecations) {
9693
9813
  for (const notice of deprecations ?? [])
9694
9814
  ctx.stderr(`deprecated (${notice.code}): ${notice.message} Instead: ${notice.replacement}`);
9695
9815
  }
9696
- var fs20, HOST_FLAG, API_KEY_FLAG, BROWSER_TIER_FLAG, LIST_LIMIT_MAX, sleep2, SECRET_PROMPT;
9816
+ async function requestLines(session, ctx, label) {
9817
+ const log2 = await WorldRequestLog.read(session);
9818
+ if (!log2) ctx.stderr(`# ${label} keeps no request log (a world without HTTP routes, or not on the World Host)`);
9819
+ if (log2?.dropped)
9820
+ ctx.stderr(`# ${label}: the world keeps its newest requests only; ${log2.dropped} older ones are gone (WORLDS_CALL_LOG_MAX)`);
9821
+ return log2?.asCalls() ?? [];
9822
+ }
9823
+ var fs20, HOST_FLAG, API_KEY_FLAG, BROWSER_TIER_FLAG, LIST_LIMIT_MAX, sleep2, SECRET_PROMPT, REQUEST_LOG_NOTES;
9697
9824
  var init_shared = __esm({
9698
9825
  "src/cli/platform/shared.ts"() {
9699
9826
  "use strict";
@@ -9717,16 +9844,17 @@ var init_shared = __esm({
9717
9844
  help: "Browser capacity for a World Host session: standard (spot, may be reclaimed) or premium (on-demand). Default: the organization's setting."
9718
9845
  };
9719
9846
  LIST_LIMIT_MAX = 200;
9720
- sleep2 = (ms) => new Promise((resolve29) => setTimeout(resolve29, ms));
9847
+ sleep2 = (ms) => new Promise((resolve32) => setTimeout(resolve32, ms));
9721
9848
  SECRET_PROMPT = "Paste the value, then Ctrl-D:";
9849
+ REQUEST_LOG_NOTES = "The ledger holds the calls the platform brokered: tool calls, seeds, grades, resets. --requests appends the\nworld's own request log as kind \"request\" lines: the `calls` its grader reads, every route request (the\nbrowser's and a direct api.url client's included) with `via`, the newest WORLDS_CALL_LOG_MAX (5000) of them;\nstderr says when older ones are gone. It is read from the live session with one\n`state` call, which the ledger records like any other; export before you close. A world that keeps no request\nlog is named on stderr; a session that cannot answer fails the command (exit 1) and nothing is written.";
9722
9850
  }
9723
9851
  });
9724
9852
 
9725
9853
  // src/cli/platform/connector.ts
9726
- function isCarriedTemplatePath(relative4) {
9727
- const slash = relative4.indexOf("/");
9728
- if (slash === -1) return WORLD_ARTIFACT_FILES.has(relative4);
9729
- return WORLD_ARTIFACT_DIRS.has(relative4.slice(0, slash));
9854
+ function isCarriedTemplatePath(relative6) {
9855
+ const slash = relative6.indexOf("/");
9856
+ if (slash === -1) return WORLD_ARTIFACT_FILES.has(relative6);
9857
+ return WORLD_ARTIFACT_DIRS.has(relative6.slice(0, slash));
9730
9858
  }
9731
9859
  function splitTemplateFiles(files) {
9732
9860
  const kept = files.filter((file) => !CONNECTOR_ONLY_FILES.has(file.path));
@@ -9738,8 +9866,8 @@ function splitTemplateFiles(files) {
9738
9866
  function walk(root) {
9739
9867
  const out = [];
9740
9868
  const visit = (rel) => {
9741
- const abs = rel ? path21.join(root, rel) : root;
9742
- for (const entry of fs30.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
9869
+ const abs = rel ? path22.join(root, rel) : root;
9870
+ for (const entry of fs31.readdirSync(abs, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
9743
9871
  const childRel = rel ? `${rel}/${entry.name}` : entry.name;
9744
9872
  if (entry.isSymbolicLink()) continue;
9745
9873
  if (entry.isDirectory()) {
@@ -9755,66 +9883,66 @@ function walk(root) {
9755
9883
  visit("");
9756
9884
  return out;
9757
9885
  }
9758
- function readText3(root, relative4) {
9759
- const bytes = fs30.readFileSync(path21.join(root, relative4));
9886
+ function readText3(root, relative6) {
9887
+ const bytes = fs31.readFileSync(path22.join(root, relative6));
9760
9888
  const text2 = bytes.toString("utf8");
9761
9889
  if (Buffer.from(text2, "utf8").length !== bytes.length || text2.includes("\uFFFD"))
9762
9890
  return null;
9763
9891
  return text2;
9764
9892
  }
9765
- function isBuildOutput2(relative4) {
9766
- const name = path21.basename(relative4);
9893
+ function isBuildOutput2(relative6) {
9894
+ const name = path22.basename(relative6);
9767
9895
  if (BUILD_OUTPUT_NAMES.has(name)) return true;
9768
9896
  for (const suffix of BUILD_OUTPUT_SUFFIXES)
9769
9897
  if (name.endsWith(suffix)) return true;
9770
9898
  return false;
9771
9899
  }
9772
- function templatePath(relative4) {
9773
- const parts2 = relative4.split("/");
9774
- if (WORLD_SKIPPED_DIRS.has(parts2[0]) || WORLD_SKIPPED_FILES.has(relative4))
9900
+ function templatePath(relative6) {
9901
+ const parts2 = relative6.split("/");
9902
+ if (WORLD_SKIPPED_DIRS.has(parts2[0]) || WORLD_SKIPPED_FILES.has(relative6))
9775
9903
  return null;
9776
- if (isBuildOutput2(relative4)) return null;
9904
+ if (isBuildOutput2(relative6)) return null;
9777
9905
  if (parts2.length === 1)
9778
- return ROOT_CARRIED_FILES.has(relative4) ? relative4 : null;
9906
+ return ROOT_CARRIED_FILES.has(relative6) ? relative6 : null;
9779
9907
  if (parts2[0] === "schema") {
9780
9908
  const name = parts2[parts2.length - 1];
9781
- if (parts2.length !== 2 || !SUPPORTING_SUFFIXES.has(path21.extname(name)) || GENERATED_NAMES.has(name))
9909
+ if (parts2.length !== 2 || !SUPPORTING_SUFFIXES.has(path22.extname(name)) || GENERATED_NAMES.has(name))
9782
9910
  return null;
9783
9911
  return name;
9784
9912
  }
9785
- if (relative4 === "tools/handlers.py") return "handlers.py";
9786
- if (WORLD_CARRIED_DIRS.has(parts2[0])) return relative4;
9913
+ if (relative6 === "tools/handlers.py") return "handlers.py";
9914
+ if (WORLD_CARRIED_DIRS.has(parts2[0])) return relative6;
9787
9915
  return null;
9788
9916
  }
9789
9917
  function collectTemplate(directory) {
9790
- if (fs30.existsSync(path21.join(directory, "world.json"))) {
9918
+ if (fs31.existsSync(path22.join(directory, "world.json"))) {
9791
9919
  const files2 = {};
9792
- for (const relative4 of walk(directory)) {
9793
- const text2 = readText3(directory, relative4);
9920
+ for (const relative6 of walk(directory)) {
9921
+ const text2 = readText3(directory, relative6);
9794
9922
  if (text2 === null)
9795
9923
  throw new CliError(
9796
- `${relative4} is not UTF-8 text; a connector template holds text files only`,
9924
+ `${relative6} is not UTF-8 text; a connector template holds text files only`,
9797
9925
  1
9798
9926
  );
9799
- files2[relative4] = text2;
9927
+ files2[relative6] = text2;
9800
9928
  }
9801
9929
  return { source: "template", files: files2, skipped: [] };
9802
9930
  }
9803
- if (!fs30.existsSync(path21.join(directory, "schema", "world.json")))
9931
+ if (!fs31.existsSync(path22.join(directory, "schema", "world.json")))
9804
9932
  throw new CliError(
9805
9933
  `${directory}: neither a connector template (world.json) nor a world (schema/world.json)`,
9806
9934
  1
9807
9935
  );
9808
9936
  const files = {};
9809
9937
  const skipped = [];
9810
- for (const relative4 of walk(directory)) {
9811
- const target = templatePath(relative4);
9938
+ for (const relative6 of walk(directory)) {
9939
+ const target = templatePath(relative6);
9812
9940
  if (target === null) {
9813
- skipped.push(relative4);
9941
+ skipped.push(relative6);
9814
9942
  continue;
9815
9943
  }
9816
- const text2 = readText3(directory, relative4);
9817
- if (text2 === null) skipped.push(`${relative4} (not UTF-8 text)`);
9944
+ const text2 = readText3(directory, relative6);
9945
+ if (text2 === null) skipped.push(`${relative6} (not UTF-8 text)`);
9818
9946
  else files[target] = text2;
9819
9947
  }
9820
9948
  return { source: "world", files, skipped };
@@ -9867,7 +9995,7 @@ function registerConnectorCommands(root) {
9867
9995
  run: async (args, ctx) => {
9868
9996
  const dir = args.positionals[0];
9869
9997
  const gathered = collectTemplate(dir);
9870
- const slug = arg.str(args, "slug") ?? path21.basename(path21.resolve(dir));
9998
+ const slug = arg.str(args, "slug") ?? path22.basename(path22.resolve(dir));
9871
9999
  const creds = credentials(args);
9872
10000
  const files = Object.fromEntries(
9873
10001
  Object.entries(gathered.files).map(([p, content]) => [
@@ -9982,7 +10110,7 @@ function registerConnectorCommands(root) {
9982
10110
  run: async (args, ctx) => {
9983
10111
  const slug = args.positionals[0];
9984
10112
  const out = arg.str(args, "out") ?? slug;
9985
- if (fs30.existsSync(out) && (!fs30.statSync(out).isDirectory() || fs30.readdirSync(out).length > 0))
10113
+ if (fs31.existsSync(out) && (!fs31.statSync(out).isDirectory() || fs31.readdirSync(out).length > 0))
9986
10114
  throw new CliError(`${out}: must be a new or empty directory`, 1);
9987
10115
  const pulled = await api(
9988
10116
  credentials(args),
@@ -9990,16 +10118,16 @@ function registerConnectorCommands(root) {
9990
10118
  oneRoute(slug, { version: arg.str(args, "version") })
9991
10119
  );
9992
10120
  const files = flattenFiles(slug, pulled);
9993
- for (const relative4 of Object.keys(files).sort()) {
9994
- if (relative4.startsWith("/") || relative4.split("/").includes(".."))
10121
+ for (const relative6 of Object.keys(files).sort()) {
10122
+ if (relative6.startsWith("/") || relative6.split("/").includes(".."))
9995
10123
  throw new CliError(
9996
- `Refusing a template path outside the directory: ${relative4}`,
10124
+ `Refusing a template path outside the directory: ${relative6}`,
9997
10125
  1
9998
10126
  );
9999
- const target = path21.join(out, relative4);
10000
- fs30.mkdirSync(path21.dirname(target), { recursive: true });
10001
- fs30.writeFileSync(target, files[relative4]);
10002
- ctx.stdout(relative4);
10127
+ const target = path22.join(out, relative6);
10128
+ fs31.mkdirSync(path22.dirname(target), { recursive: true });
10129
+ fs31.writeFileSync(target, files[relative6]);
10130
+ ctx.stdout(relative6);
10003
10131
  }
10004
10132
  ctx.stderr(
10005
10133
  `# ${slug} @ ${pulled.commit?.commitHash ?? pulled.commit?.id ?? ""} -> ${out}`
@@ -10106,12 +10234,12 @@ function flattenFiles(slug, pulled) {
10106
10234
  }
10107
10235
  return files;
10108
10236
  }
10109
- var fs30, path21, CONNECTORS, HUB, CLONE, WORLD_SKIPPED_DIRS, WORLD_SKIPPED_FILES, WORLD_CARRIED_DIRS, ROOT_CARRIED_FILES, SUPPORTING_SUFFIXES, GENERATED_NAMES, BUILD_OUTPUT_SUFFIXES, BUILD_OUTPUT_NAMES, WORLD_ARTIFACT_DIRS, WORLD_ARTIFACT_FILES, CONNECTOR_ONLY_FILES;
10237
+ var fs31, path22, CONNECTORS, HUB, CLONE, WORLD_SKIPPED_DIRS, WORLD_SKIPPED_FILES, WORLD_CARRIED_DIRS, ROOT_CARRIED_FILES, SUPPORTING_SUFFIXES, GENERATED_NAMES, BUILD_OUTPUT_SUFFIXES, BUILD_OUTPUT_NAMES, WORLD_ARTIFACT_DIRS, WORLD_ARTIFACT_FILES, CONNECTOR_ONLY_FILES;
10110
10238
  var init_connector = __esm({
10111
10239
  "src/cli/platform/connector.ts"() {
10112
10240
  "use strict";
10113
- fs30 = __toESM(require("fs"));
10114
- path21 = __toESM(require("path"));
10241
+ fs31 = __toESM(require("fs"));
10242
+ path22 = __toESM(require("path"));
10115
10243
  init_config();
10116
10244
  init_router();
10117
10245
  init_shared();
@@ -10199,9 +10327,9 @@ async function readFile(options = {}, filePath, limits = {}) {
10199
10327
  async function downloadFile(options = {}, filePath, outPath, onProgress) {
10200
10328
  const file = await getFile(options, filePath);
10201
10329
  const res = await openDownload(file.url);
10202
- fs32.mkdirSync(path23.dirname(path23.resolve(outPath)), { recursive: true });
10330
+ fs33.mkdirSync(path24.dirname(path24.resolve(outPath)), { recursive: true });
10203
10331
  const source2 = import_node_stream.Readable.fromWeb(res.body);
10204
- await (0, import_promises.pipeline)(source2, counting((n) => onProgress?.(n, file.sizeBytes)), fs32.createWriteStream(outPath));
10332
+ await (0, import_promises.pipeline)(source2, counting((n) => onProgress?.(n, file.sizeBytes)), fs33.createWriteStream(outPath));
10205
10333
  return { ...file, out: outPath };
10206
10334
  }
10207
10335
  async function requestUpload(options = {}, body) {
@@ -10212,11 +10340,11 @@ async function confirmUpload(options = {}, fileId, ok = true) {
10212
10340
  }
10213
10341
  async function sha256Base64(localPath) {
10214
10342
  const hash = (0, import_node_crypto15.createHash)("sha256");
10215
- for await (const chunk of fs32.createReadStream(localPath)) hash.update(chunk);
10343
+ for await (const chunk of fs33.createReadStream(localPath)) hash.update(chunk);
10216
10344
  return hash.digest("base64");
10217
10345
  }
10218
10346
  function contentTypeFor(name) {
10219
- return CONTENT_TYPES[path23.extname(name).toLowerCase()] ?? "application/octet-stream";
10347
+ return CONTENT_TYPES[path24.extname(name).toLowerCase()] ?? "application/octet-stream";
10220
10348
  }
10221
10349
  function counting(report) {
10222
10350
  let seen = 0;
@@ -10243,37 +10371,37 @@ async function putPresigned(uploadUrl, body, headers) {
10243
10371
  if (!res.ok) throw new Error(`upload failed: storage answered HTTP ${res.status}: ${(await res.text()).slice(0, 300)}`);
10244
10372
  }
10245
10373
  async function uploadFile(options = {}, localPath, targetPath, upload = {}) {
10246
- const stat = fs32.statSync(localPath);
10374
+ const stat = fs33.statSync(localPath);
10247
10375
  if (!stat.isFile()) throw new Error(`${localPath} is not a file`);
10248
10376
  if (stat.size === 0) throw new Error(`${localPath} is empty; the drive refuses zero-byte uploads`);
10249
10377
  const contentType = upload.contentType ?? contentTypeFor(localPath);
10250
- const sha2562 = await sha256Base64(localPath);
10378
+ const sha2563 = await sha256Base64(localPath);
10251
10379
  const target = drivePath(targetPath);
10252
- const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
10380
+ const granted = await requestUpload(options, { path: target, contentLength: stat.size, contentType, sha256: sha2563, ...upload.overwrite ? { overwrite: true } : {} });
10253
10381
  try {
10254
- const stream = fs32.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
10255
- await putPresigned(granted.uploadUrl, import_node_stream.Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256: sha2562 });
10382
+ const stream = fs33.createReadStream(localPath).pipe(counting((n) => upload.onProgress?.(n, stat.size)));
10383
+ await putPresigned(granted.uploadUrl, import_node_stream.Readable.toWeb(stream), { contentType, contentLength: stat.size, sha256: sha2563 });
10256
10384
  } catch (error) {
10257
10385
  await confirmUpload(options, granted.fileId, false).catch(() => void 0);
10258
10386
  throw error;
10259
10387
  }
10260
10388
  const confirmed = await confirmUpload(options, granted.fileId, true);
10261
- return { path: confirmed.path, fileId: granted.fileId, sizeBytes: stat.size, sha256: sha2562, contentType };
10389
+ return { path: confirmed.path, fileId: granted.fileId, sizeBytes: stat.size, sha256: sha2563, contentType };
10262
10390
  }
10263
10391
  async function uploadBytes(options = {}, bytes, targetPath, upload = {}) {
10264
10392
  if (!bytes.length) throw new Error("nothing to upload: the content is empty");
10265
10393
  const target = drivePath(targetPath);
10266
10394
  const contentType = upload.contentType ?? contentTypeFor(target);
10267
- const sha2562 = (0, import_node_crypto15.createHash)("sha256").update(bytes).digest("base64");
10268
- const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2562, ...upload.overwrite ? { overwrite: true } : {} });
10395
+ const sha2563 = (0, import_node_crypto15.createHash)("sha256").update(bytes).digest("base64");
10396
+ const granted = await requestUpload(options, { path: target, contentLength: bytes.length, contentType, sha256: sha2563, ...upload.overwrite ? { overwrite: true } : {} });
10269
10397
  try {
10270
- await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2562 });
10398
+ await putPresigned(granted.uploadUrl, new Uint8Array(bytes), { contentType, contentLength: bytes.length, sha256: sha2563 });
10271
10399
  } catch (error) {
10272
10400
  await confirmUpload(options, granted.fileId, false).catch(() => void 0);
10273
10401
  throw error;
10274
10402
  }
10275
10403
  const confirmed = await confirmUpload(options, granted.fileId, true);
10276
- return { path: confirmed.path, fileId: granted.fileId, sizeBytes: bytes.length, sha256: sha2562, contentType };
10404
+ return { path: confirmed.path, fileId: granted.fileId, sizeBytes: bytes.length, sha256: sha2563, contentType };
10277
10405
  }
10278
10406
  async function deleteFile(options = {}, filePath) {
10279
10407
  return apiRequest(options, "DELETE", `${BASE}${qs({ path: drivePath(filePath) })}`);
@@ -10299,13 +10427,13 @@ async function listFileConnectors(options = {}) {
10299
10427
  async function syncFileConnector(options = {}, connectorId) {
10300
10428
  return apiRequest(options, "POST", `${BASE}/connectors/sync`, { connectorId });
10301
10429
  }
10302
- var import_node_crypto15, fs32, path23, import_node_stream, import_promises, DRIVE_PREFIX, BASE, CONTENT_TYPES;
10430
+ var import_node_crypto15, fs33, path24, import_node_stream, import_promises, DRIVE_PREFIX, BASE, CONTENT_TYPES;
10303
10431
  var init_files = __esm({
10304
10432
  "src/files/index.ts"() {
10305
10433
  "use strict";
10306
10434
  import_node_crypto15 = require("crypto");
10307
- fs32 = __toESM(require("fs"));
10308
- path23 = __toESM(require("path"));
10435
+ fs33 = __toESM(require("fs"));
10436
+ path24 = __toESM(require("path"));
10309
10437
  import_node_stream = require("stream");
10310
10438
  import_promises = require("stream/promises");
10311
10439
  init_worlds();
@@ -10424,8 +10552,8 @@ var init_publicUrl = __esm({
10424
10552
  { base: ip4("192.168.0.0"), bits: 16 }
10425
10553
  ];
10426
10554
  PublicUrl = class {
10427
- constructor(resolve29 = (host) => (0, import_promises2.lookup)(host, { all: true }), doFetch = (url, init2) => fetch(url, init2)) {
10428
- this.resolve = resolve29;
10555
+ constructor(resolve32 = (host) => (0, import_promises2.lookup)(host, { all: true }), doFetch = (url, init2) => fetch(url, init2)) {
10556
+ this.resolve = resolve32;
10429
10557
  this.doFetch = doFetch;
10430
10558
  }
10431
10559
  resolve;
@@ -10544,12 +10672,12 @@ async function initFromOpenApi(args, ctx, dir) {
10544
10672
  const { files: _files, ...rest } = report;
10545
10673
  ctx.stdout(sortedJson({ ...rest, kind: "schema", api: "connector.toml" }, 0));
10546
10674
  }
10547
- var fs33, path24, OPENAPI_MAX_BYTES, FROM_OPENAPI_FLAGS, OpenApiSourceArg, LocalSource, UrlSource, DriveSource;
10675
+ var fs34, path25, OPENAPI_MAX_BYTES, FROM_OPENAPI_FLAGS, OpenApiSourceArg, LocalSource, UrlSource, DriveSource;
10548
10676
  var init_schemaOpenApi = __esm({
10549
10677
  "src/cli/runtime/schemaOpenApi.ts"() {
10550
10678
  "use strict";
10551
- fs33 = __toESM(require("fs"));
10552
- path24 = __toESM(require("path"));
10679
+ fs34 = __toESM(require("fs"));
10680
+ path25 = __toESM(require("path"));
10553
10681
  init_router();
10554
10682
  init_config();
10555
10683
  init_files();
@@ -10607,12 +10735,12 @@ var init_schemaOpenApi = __esm({
10607
10735
  };
10608
10736
  LocalSource = class extends OpenApiSourceArg {
10609
10737
  async bytes() {
10610
- const abs = path24.resolve(this.spelled);
10611
- if (!fs33.existsSync(abs) || !fs33.statSync(abs).isFile())
10738
+ const abs = path25.resolve(this.spelled);
10739
+ if (!fs34.existsSync(abs) || !fs34.statSync(abs).isFile())
10612
10740
  throw new CliError(`--from-openapi ${this.spelled}: no such file`);
10613
- const { size } = fs33.statSync(abs);
10741
+ const { size } = fs34.statSync(abs);
10614
10742
  if (size > OPENAPI_MAX_BYTES) throw this.tooBig(size);
10615
- return fs33.readFileSync(abs);
10743
+ return fs34.readFileSync(abs);
10616
10744
  }
10617
10745
  };
10618
10746
  UrlSource = class extends OpenApiSourceArg {
@@ -10722,16 +10850,16 @@ function uiSection(toml) {
10722
10850
  return out;
10723
10851
  }
10724
10852
  function declareUi(dir) {
10725
- const spec = path25.join(dir, "connector.toml");
10726
- if (!fs34.existsSync(spec))
10853
+ const spec = path26.join(dir, "connector.toml");
10854
+ if (!fs35.existsSync(spec))
10727
10855
  throw new CliError(
10728
10856
  `${dir} has no connector.toml: a ui shows the world's routes, and this world declares none. Add the vendor's routes first (\`gateway worlds connector route add\`), or start from a connector template.`
10729
10857
  );
10730
- const text2 = fs34.readFileSync(spec, "utf8");
10858
+ const text2 = fs35.readFileSync(spec, "utf8");
10731
10859
  if (/^\[ui\]\s*$/m.test(text2)) return false;
10732
10860
  const firstRoute = /^\[\[operations\]\]/m.exec(text2);
10733
10861
  const next = firstRoute ? text2.slice(0, firstRoute.index) + UI_SECTION + "\n" + text2.slice(firstRoute.index) : text2.replace(/\n*$/, "\n") + "\n" + UI_SECTION;
10734
- fs34.writeFileSync(spec, next);
10862
+ fs35.writeFileSync(spec, next);
10735
10863
  return true;
10736
10864
  }
10737
10865
  async function listTemplates(creds) {
@@ -10766,7 +10894,8 @@ function initNextSteps(dir, shape) {
10766
10894
  const steps = [];
10767
10895
  if (shape.blank)
10768
10896
  steps.push(
10769
- `gateway worlds schema entity add ${dir} <entity> --fields id:string,name:string --key id`
10897
+ `gateway worlds schema entity add ${dir} <entity> --fields id:string,name:string --key id`,
10898
+ `gateway worlds schema entity remove ${dir} records # the example entity, once yours is declared`
10770
10899
  );
10771
10900
  if (!shape.hasRoutes)
10772
10901
  steps.push(
@@ -10844,6 +10973,12 @@ function whereLine(description) {
10844
10973
  return `where: platform${description.versionId ? `, version ${String(description.versionId)}` : ""}`;
10845
10974
  return null;
10846
10975
  }
10976
+ function fieldLine(field2) {
10977
+ const optional = field2.required ? "" : "?";
10978
+ const allowed = Array.isArray(field2.enum) ? ` one of: ${field2.enum.map(enumValue).join(" | ")}` : "";
10979
+ const tag = field2.redaction ? ` [${String(field2.redaction)}]` : "";
10980
+ return `${String(field2.name)}: ${String(field2.type ?? "any")}${optional}${allowed}${tag}`;
10981
+ }
10847
10982
  function renderDescription(description) {
10848
10983
  const lines = [];
10849
10984
  const domain = description.domainId ?? description.slug ?? "(no $id)";
@@ -10859,12 +10994,8 @@ function renderDescription(description) {
10859
10994
  const pk = Array.isArray(entity.primaryKey) ? entity.primaryKey.join(", ") : "";
10860
10995
  const rows = typeof entity.rowCount === "number" ? ` (rows: ${entity.rowCount})` : "";
10861
10996
  lines.push(` ${String(entity.name)}${pk ? ` (pk: ${pk})` : ""}${rows}`);
10862
- for (const field2 of Array.isArray(entity.fields) ? entity.fields : []) {
10863
- const tag = field2.redaction ? ` [${String(field2.redaction)}]` : "";
10864
- lines.push(
10865
- ` ${String(field2.name)}: ${String(field2.type ?? "any")}${field2.required ? "" : "?"}${tag}`
10866
- );
10867
- }
10997
+ for (const field2 of Array.isArray(entity.fields) ? entity.fields : [])
10998
+ lines.push(` ${fieldLine(field2)}`);
10868
10999
  if (Array.isArray(entity.relationships) && entity.relationships.length)
10869
11000
  lines.push(
10870
11001
  ` relationships: ${entity.relationships.map(relationshipText).join(", ")}`
@@ -10975,7 +11106,7 @@ function registerSchemaCommands(schema) {
10975
11106
  ],
10976
11107
  notes: "The world is a gateway-world/1 tree: schema/world.json (entities), gateway-env.toml ([schema], [tools],\n[[tasks]]), tools/handlers.py, verifiers/*.sql, and connector.toml + api/handlers.py for its API surface.\nA shipped template arrives with its routes; a custom world declares its own with\n`gateway worlds connector route add`, which creates connector.toml on the first route. The output's\n`next` lists the commands in order.\nHave a vendor's Swagger/OpenAPI document and no world yet? `--from-openapi <path|drive:<path>|url>`\nwrites both from it: keyed schemas become entities, path+method pairs become routes; `--plan-only`\npreviews, `--include '/repos/{owner}/{repo}/issues*'` narrows a big spec. `connector conform` then\nchecks the served world back against the same document.",
10977
11108
  run: async (args, ctx) => {
10978
- const dir = path25.resolve(args.positionals[0]);
11109
+ const dir = path26.resolve(args.positionals[0]);
10979
11110
  if (arg.str(args, "from-openapi")) return initFromOpenApi(args, ctx, dir);
10980
11111
  assertEmptyTarget(dir);
10981
11112
  const connector = arg.str(args, "connector") ?? "custom";
@@ -11026,7 +11157,7 @@ function registerSchemaCommands(schema) {
11026
11157
  1
11027
11158
  );
11028
11159
  writeWorldFiles(dir, files);
11029
- const hasRoutes = fs34.existsSync(path25.join(dir, "connector.toml"));
11160
+ const hasRoutes = fs35.existsSync(path26.join(dir, "connector.toml"));
11030
11161
  const out = {
11031
11162
  status: "ok",
11032
11163
  domain: report.domain,
@@ -11061,7 +11192,7 @@ function registerSchemaCommands(schema) {
11061
11192
  notes: "With the bundled runtime (a python3 on this machine) the world is checked in place: its handlers are\nimported and every declared tool bound (`handler_execution.status: ok`), the verifiers run over the\ninitial state (`verifiers.<name>.initial_score`), and each `[dependencies]` entry with a `path` is\nopened beside it so a cross-world verifier runs too. On the platform the handlers report `not_run`.\n`tools` (top level and under handler_execution) is the declared handlers; `handler_execution.served`\nis every name `worlds call` answers: handlers plus connector routes and a dependency's `alias.tool`.\nA stale tree says whether `schema compile` will succeed or refuse (rows written against the old contract).\nThe handler pass also reads every tools/*.py statically: a `store.<name>` off the store API is refused at\nfile:line with the available methods, before any handler is imported.\n" + STORE_API_NOTE
11062
11193
  } : {},
11063
11194
  run: async (args, ctx) => {
11064
- const dir = path25.resolve(args.positionals[0]);
11195
+ const dir = path26.resolve(args.positionals[0]);
11065
11196
  const creds = credentialsForRuntime(arg.str(args, "host"));
11066
11197
  const report = await runtime(
11067
11198
  creds,
@@ -11091,7 +11222,7 @@ function registerSchemaCommands(schema) {
11091
11222
  ],
11092
11223
  notes: "`gateway worlds describe <dir|slug>` is the same view with row counts, and works on a platform slug.",
11093
11224
  run: async (args, ctx) => {
11094
- const dir = path25.resolve(args.positionals[0]);
11225
+ const dir = path26.resolve(args.positionals[0]);
11095
11226
  const creds = credentialsForRuntime(arg.str(args, "host"));
11096
11227
  const description = await describeLocalWorld(dir, creds);
11097
11228
  if (arg.bool(args, "json"))
@@ -11130,7 +11261,7 @@ function registerSchemaCommands(schema) {
11130
11261
  flags: [HOST_FLAG2],
11131
11262
  notes: "Writes ui/static/{index.html, app.js, contract.json}: a dependency-free page that lists, reads, creates,\nupdates and deletes every entity through the world's own routes, with foreign keys linked. `schema compile`\nregenerates it as the contract changes; set `[ui] generated = false` to hand-write the directory instead.\n`worlds serve` mounts it at /__ui/; `worlds session open --surface ui,browser` serves it on the session's\nui origin and `worlds session browse` drives it. A world with no connector.toml has no routes for a ui to\ncall and is refused.",
11132
11263
  run: async (args, ctx) => {
11133
- const dir = path25.resolve(args.positionals[0]);
11264
+ const dir = path26.resolve(args.positionals[0]);
11134
11265
  const declared = declareUi(dir);
11135
11266
  const creds = credentialsForRuntime(arg.str(args, "host"));
11136
11267
  const report = await runtime(creds, {
@@ -11139,7 +11270,7 @@ function registerSchemaCommands(schema) {
11139
11270
  });
11140
11271
  if (report.files?.length) writeWorldFiles(dir, report.files);
11141
11272
  const ui = uiSection(
11142
- fs34.readFileSync(path25.join(dir, "connector.toml"), "utf8")
11273
+ fs35.readFileSync(path26.join(dir, "connector.toml"), "utf8")
11143
11274
  );
11144
11275
  const staticDir = ui.static ?? "ui/static";
11145
11276
  const files = (report.files ?? []).map((f) => f.path).filter((p) => p.startsWith(`${staticDir}/`));
@@ -11213,12 +11344,12 @@ function registerSchemaCommands(schema) {
11213
11344
  }
11214
11345
  });
11215
11346
  }
11216
- var fs34, path25, HOST_FLAG2, UI_SECTION, WORKSPACE_PREFIX, describedOnPlatform, describedLocally;
11347
+ var fs35, path26, HOST_FLAG2, UI_SECTION, WORKSPACE_PREFIX, describedOnPlatform, describedLocally, enumValue;
11217
11348
  var init_schema = __esm({
11218
11349
  "src/cli/runtime/schema.ts"() {
11219
11350
  "use strict";
11220
- fs34 = __toESM(require("fs"));
11221
- path25 = __toESM(require("path"));
11351
+ fs35 = __toESM(require("fs"));
11352
+ path26 = __toESM(require("path"));
11222
11353
  init_router();
11223
11354
  init_config();
11224
11355
  init_local();
@@ -11245,8 +11376,9 @@ var init_schema = __esm({
11245
11376
  ...description,
11246
11377
  where: "local",
11247
11378
  path: dir,
11248
- on_platform: `gateway worlds describe ${path25.basename(dir)}@main`
11379
+ on_platform: `gateway worlds describe ${path26.basename(dir)}@main`
11249
11380
  });
11381
+ enumValue = (value) => typeof value === "string" ? value : JSON.stringify(value);
11250
11382
  }
11251
11383
  });
11252
11384
 
@@ -11318,8 +11450,8 @@ var standingAlone = /* @__PURE__ */ new Map();
11318
11450
  function standingAlonePattern(needle) {
11319
11451
  let pattern = standingAlone.get(needle);
11320
11452
  if (pattern === void 0) {
11321
- const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
11322
- pattern = new RegExp(`(?<![A-Za-z0-9])${escaped}(?![A-Za-z0-9])`, "gi");
11453
+ const escaped2 = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
11454
+ pattern = new RegExp(`(?<![A-Za-z0-9])${escaped2}(?![A-Za-z0-9])`, "gi");
11323
11455
  standingAlone.set(needle, pattern);
11324
11456
  }
11325
11457
  return pattern;
@@ -12828,17 +12960,17 @@ function splitTopLevel(text2) {
12828
12960
  const parts2 = [];
12829
12961
  let depth = 0;
12830
12962
  let current = "";
12831
- let escaped = false;
12963
+ let escaped2 = false;
12832
12964
  let inClass = false;
12833
12965
  for (const char of text2) {
12834
- if (escaped) {
12966
+ if (escaped2) {
12835
12967
  current += char;
12836
- escaped = false;
12968
+ escaped2 = false;
12837
12969
  continue;
12838
12970
  }
12839
12971
  if (char === "\\") {
12840
12972
  current += char;
12841
- escaped = true;
12973
+ escaped2 = true;
12842
12974
  continue;
12843
12975
  }
12844
12976
  if (inClass) {
@@ -12865,9 +12997,9 @@ function alternatives(raw) {
12865
12997
  if (!parts2.length || parts2.includes("*")) return [];
12866
12998
  return parts2;
12867
12999
  }
12868
- function hasPath(node, path44) {
13000
+ function hasPath(node, path49) {
12869
13001
  let current = node;
12870
- for (const part of path44.split(".")) {
13002
+ for (const part of path49.split(".")) {
12871
13003
  if (current && typeof current === "object" && !Array.isArray(current) && part in current) {
12872
13004
  current = current[part];
12873
13005
  continue;
@@ -12908,7 +13040,7 @@ function matches(m, event) {
12908
13040
  if (m.args.length) {
12909
13041
  const haystacks = event.event === "pre_request" || event.event === "post_response" ? [event.request?.query, event.request?.body] : [event.toolInput];
12910
13042
  const present = haystacks.filter((h) => h !== void 0 && h !== null);
12911
- if (!m.args.every((path44) => present.some((h) => hasPath(h, path44))))
13043
+ if (!m.args.every((path49) => present.some((h) => hasPath(h, path49))))
12912
13044
  return false;
12913
13045
  }
12914
13046
  return true;
@@ -13774,7 +13906,7 @@ var CommandHandler = class {
13774
13906
  run(event) {
13775
13907
  const input = JSON.stringify(eventToJson(event));
13776
13908
  const exec = this.opts.args !== void 0;
13777
- return new Promise((resolve29, reject) => {
13909
+ return new Promise((resolve32, reject) => {
13778
13910
  let child;
13779
13911
  try {
13780
13912
  child = exec ? (0, import_node_child_process4.spawn)(this.command, this.opts.args, {
@@ -13835,7 +13967,7 @@ var CommandHandler = class {
13835
13967
  return;
13836
13968
  }
13837
13969
  try {
13838
- resolve29(
13970
+ resolve32(
13839
13971
  parseStdout(Buffer.concat(out).toString("utf8"), this.describe())
13840
13972
  );
13841
13973
  } catch (error) {
@@ -14239,7 +14371,7 @@ var Pacer = class {
14239
14371
  /** Waits until the interval since the tool's last call has passed; resolves to the
14240
14372
  * seconds waited. `sleep`/`clock` are injectable for tests. */
14241
14373
  async wait(name, intervalMs, opts = {}) {
14242
- const sleep4 = opts.sleep ?? ((seconds) => new Promise((resolve29) => setTimeout(resolve29, seconds * 1e3)));
14374
+ const sleep4 = opts.sleep ?? ((seconds) => new Promise((resolve32) => setTimeout(resolve32, seconds * 1e3)));
14243
14375
  const clock = opts.clock ?? (() => Date.now() / 1e3);
14244
14376
  const now = clock();
14245
14377
  const due = (this.last.get(name) ?? -Infinity) + intervalMs / 1e3;
@@ -15764,14 +15896,14 @@ var HookedSession = class {
15764
15896
  * `apiHeaders()`), `pre_request` before it and `post_response` after. Returns
15765
15897
  * `{status, body, headers}`; a 4xx/5xx is returned, not thrown, so the agent sees
15766
15898
  * the vendor's own error shape (rewritten like any result). */
15767
- async request(method, path44, opts = {}) {
15899
+ async request(method, path49, opts = {}) {
15768
15900
  if (!this.inner.api && !this.requestFn)
15769
15901
  throw new Error(
15770
15902
  "this session has no api surface (pass requestFn for a transport of your own)"
15771
15903
  );
15772
15904
  let request = {
15773
15905
  method: method.toUpperCase(),
15774
- path: path44,
15906
+ path: path49,
15775
15907
  query: { ...opts.query ?? {} },
15776
15908
  body: opts.body ?? null
15777
15909
  };
@@ -17786,13 +17918,13 @@ function decodeKey(text2) {
17786
17918
  var LINE_CAP = 1024 * 1024;
17787
17919
  var refuse = (message) => new CliError(message, 1);
17788
17920
  var isGzName = (name) => /\.gz$/i.test(name);
17789
- var csvNeedsEntity = (path44) => `${path44} is a CSV; say which entity its columns fill with --entity (the header row names the fields; cells are cast by the entity's schema \u2014 integer, number, boolean, array, object \u2014 and an empty cell is null)`;
17790
- function fileInput(path44) {
17921
+ var csvNeedsEntity = (path49) => `${path49} is a CSV; say which entity its columns fill with --entity (the header row names the fields; cells are cast by the entity's schema \u2014 integer, number, boolean, array, object \u2014 and an empty cell is null)`;
17922
+ function fileInput(path49) {
17791
17923
  return {
17792
- name: path44,
17924
+ name: path49,
17793
17925
  open: () => {
17794
- const raw = fs22.createReadStream(path44);
17795
- return isGzName(path44) ? raw.pipe((0, import_node_zlib4.createGunzip)()) : raw;
17926
+ const raw = fs22.createReadStream(path49);
17927
+ return isGzName(path49) ? raw.pipe((0, import_node_zlib4.createGunzip)()) : raw;
17796
17928
  }
17797
17929
  };
17798
17930
  }
@@ -17836,8 +17968,8 @@ function openBytes(input) {
17836
17968
  return new ByteReader(stream, input.name);
17837
17969
  }
17838
17970
  async function* readOne(input, entity, options) {
17839
- const path44 = input.name;
17840
- if (isDelimitedName(path44)) {
17971
+ const path49 = input.name;
17972
+ if (isDelimitedName(path49)) {
17841
17973
  yield* csvTaggedRows(input, entity, options);
17842
17974
  return;
17843
17975
  }
@@ -17851,30 +17983,30 @@ async function* readOne(input, entity, options) {
17851
17983
  if (!opened) return;
17852
17984
  if (opened.kind === "other")
17853
17985
  throw refuse(
17854
- `${path44} is neither a JSON object of entity -> rows nor an array of rows`
17986
+ `${path49} is neither a JSON object of entity -> rows nor an array of rows`
17855
17987
  );
17856
17988
  if (opened.kind === "array") {
17857
17989
  if (entity === void 0)
17858
17990
  throw refuse(
17859
- `${path44} is a bare array; say which entity it holds with --entity`
17991
+ `${path49} is a bare array; say which entity it holds with --entity`
17860
17992
  );
17861
- for await (const { value, where } of streamValues(opened.bytes, path44))
17993
+ for await (const { value, where } of streamValues(opened.bytes, path49))
17862
17994
  yield { entity, row: rowObject(value, where), where };
17863
17995
  return;
17864
17996
  }
17865
17997
  if (opened.kind === "lines") {
17866
- yield* jsonlRows(opened.lines, path44, entity);
17998
+ yield* jsonlRows(opened.lines, path49, entity);
17867
17999
  return;
17868
18000
  }
17869
- const values = streamValues(opened.bytes, path44, {
18001
+ const values = streamValues(opened.bytes, path49, {
17870
18002
  key: (key2, isArray) => {
17871
18003
  if (!isArray)
17872
18004
  throw refuse(
17873
- `${path44}: ${key2} must map to an array of rows (JSONL lines are {"entity", "row"})`
18005
+ `${path49}: ${key2} must map to an array of rows (JSONL lines are {"entity", "row"})`
17874
18006
  );
17875
18007
  if (entity !== void 0 && key2 !== entity)
17876
18008
  throw refuse(
17877
- `${path44} maps entities; drop --entity or make the file a bare array`
18009
+ `${path49} maps entities; drop --entity or make the file a bare array`
17878
18010
  );
17879
18011
  }
17880
18012
  });
@@ -17882,29 +18014,29 @@ async function* readOne(input, entity, options) {
17882
18014
  yield { entity: key2, row: rowObject(value, where), where };
17883
18015
  }
17884
18016
  async function* csvTaggedRows(input, entity, options) {
17885
- const path44 = input.name;
17886
- if (entity === void 0) throw refuse(csvNeedsEntity(path44));
18017
+ const path49 = input.name;
18018
+ if (entity === void 0) throw refuse(csvNeedsEntity(path49));
17887
18019
  const caster = options.casters?.(entity) ?? TEXT_CASTER;
17888
- const delimiter = csvDelimiter(path44, options.delimiter);
18020
+ const delimiter = csvDelimiter(path49, options.delimiter);
17889
18021
  for await (const { record, number } of csvRecords(
17890
18022
  openBytes(input).remaining(),
17891
- path44,
18023
+ path49,
17892
18024
  delimiter
17893
18025
  )) {
17894
- const where = `${path44}:${number}`;
18026
+ const where = `${path49}:${number}`;
17895
18027
  yield { entity, row: caster.row(record, where), where };
17896
18028
  }
17897
18029
  }
17898
- async function* streamValues(bytes, path44, hooks = {}) {
18030
+ async function* streamValues(bytes, path49, hooks = {}) {
17899
18031
  const queue = [];
17900
- const whereOf = (key2, index2) => key2 === null ? `${path44}[${index2}]` : `${path44}:${key2}[${index2}]`;
18032
+ const whereOf = (key2, index2) => key2 === null ? `${path49}[${index2}]` : `${path49}:${key2}[${index2}]`;
17901
18033
  const scanner = new TopLevelScanner({
17902
18034
  key: (key2, isArray) => hooks.key?.(key2, isArray),
17903
18035
  element: (key2, text2, index2) => {
17904
18036
  const where = whereOf(key2, index2);
17905
18037
  queue.push({ key: key2, value: parseElement(text2, where), index: index2, where });
17906
18038
  },
17907
- other: (key2, text2) => hooks.other?.(key2, parseElement(text2, `${path44}:${key2}`))
18039
+ other: (key2, text2) => hooks.other?.(key2, parseElement(text2, `${path49}:${key2}`))
17908
18040
  });
17909
18041
  try {
17910
18042
  for await (const chunk of bytes) {
@@ -17915,7 +18047,7 @@ async function* streamValues(bytes, path44, hooks = {}) {
17915
18047
  } catch (error) {
17916
18048
  if (error instanceof ScanError)
17917
18049
  throw refuse(
17918
- `${error.open ? whereOf(error.open.key, error.open.index) : path44}: not valid JSON`
18050
+ `${error.open ? whereOf(error.open.key, error.open.index) : path49}: not valid JSON`
17919
18051
  );
17920
18052
  throw error;
17921
18053
  }
@@ -17928,7 +18060,7 @@ function parseElement(text2, where) {
17928
18060
  throw refuse(`${where}: not valid JSON`);
17929
18061
  }
17930
18062
  }
17931
- async function* jsonlRows(lines, path44, entity) {
18063
+ async function* jsonlRows(lines, path49, entity) {
17932
18064
  let number = 0;
17933
18065
  for await (const raw of lines) {
17934
18066
  number++;
@@ -17938,9 +18070,9 @@ async function* jsonlRows(lines, path44, entity) {
17938
18070
  try {
17939
18071
  item = parseJson(line);
17940
18072
  } catch {
17941
- throw refuse(`${path44}:${number} is not JSON`);
18073
+ throw refuse(`${path49}:${number} is not JSON`);
17942
18074
  }
17943
- const where = `${path44}:${number}`;
18075
+ const where = `${path49}:${number}`;
17944
18076
  if (entity !== void 0) {
17945
18077
  yield { entity, row: rowObject(item, where), where };
17946
18078
  continue;
@@ -17964,8 +18096,8 @@ var isWs = (c) => c === 32 || c === 10 || c === 13 || c === 9;
17964
18096
  var BOM = Buffer.from([239, 187, 191]);
17965
18097
  var ByteReader = class {
17966
18098
  // bytes of leading whitespace (and a BOM) already skipped
17967
- constructor(stream, path44) {
17968
- this.path = path44;
18099
+ constructor(stream, path49) {
18100
+ this.path = path49;
17969
18101
  this.iterator = stream[Symbol.asyncIterator]();
17970
18102
  }
17971
18103
  path;
@@ -18062,9 +18194,9 @@ var ByteReader = class {
18062
18194
  // src/cli/platform/rows.ts
18063
18195
  function parseRows(paths, entity, options = {}) {
18064
18196
  const rows = {};
18065
- for (const path44 of paths) {
18066
- const text2 = readText(path44);
18067
- const parsed = isDelimitedName(path44) ? csvRowsIn(text2, path44, entity, options) : rowsIn(text2, path44, entity);
18197
+ for (const path49 of paths) {
18198
+ const text2 = readText(path49);
18199
+ const parsed = isDelimitedName(path49) ? csvRowsIn(text2, path49, entity, options) : rowsIn(text2, path49, entity);
18068
18200
  for (const [name, listed2] of Object.entries(parsed)) {
18069
18201
  (rows[name] ??= []).push(...listed2);
18070
18202
  }
@@ -18074,32 +18206,32 @@ function parseRows(paths, entity, options = {}) {
18074
18206
  function refuse2(message) {
18075
18207
  return new CliError(message, 1);
18076
18208
  }
18077
- function readText(path44) {
18209
+ function readText(path49) {
18078
18210
  try {
18079
- const bytes = fs23.readFileSync(path44);
18080
- return (isGzName(path44) ? (0, import_node_zlib5.gunzipSync)(bytes) : bytes).toString("utf8");
18211
+ const bytes = fs23.readFileSync(path49);
18212
+ return (isGzName(path49) ? (0, import_node_zlib5.gunzipSync)(bytes) : bytes).toString("utf8");
18081
18213
  } catch {
18082
- throw refuse2(`Cannot read ${path44} as UTF-8 text`);
18214
+ throw refuse2(`Cannot read ${path49} as UTF-8 text`);
18083
18215
  }
18084
18216
  }
18085
- function csvRowsIn(text2, path44, entity, options) {
18086
- if (entity === void 0) throw refuse2(csvNeedsEntity(path44));
18217
+ function csvRowsIn(text2, path49, entity, options) {
18218
+ if (entity === void 0) throw refuse2(csvNeedsEntity(path49));
18087
18219
  const caster = options.casters?.(entity) ?? TEXT_CASTER;
18088
- const records2 = parseCsv(text2, path44, csvDelimiter(path44, options.delimiter));
18220
+ const records2 = parseCsv(text2, path49, csvDelimiter(path49, options.delimiter));
18089
18221
  return {
18090
18222
  [entity]: records2.map(
18091
- (record, index2) => plainValue(caster.row(record, `${path44}:${index2 + 2}`))
18223
+ (record, index2) => plainValue(caster.row(record, `${path49}:${index2 + 2}`))
18092
18224
  )
18093
18225
  };
18094
18226
  }
18095
- function rowsIn(text2, path44, entity) {
18227
+ function rowsIn(text2, path49, entity) {
18096
18228
  const stripped = text2.trim();
18097
18229
  if (!stripped) return {};
18098
18230
  let document;
18099
18231
  try {
18100
18232
  document = JSON.parse(stripped);
18101
18233
  } catch {
18102
- return jsonlRows2(stripped, path44, entity);
18234
+ return jsonlRows2(stripped, path49, entity);
18103
18235
  }
18104
18236
  if (isObject8(document)) {
18105
18237
  if (entity !== void 0) {
@@ -18107,20 +18239,20 @@ function rowsIn(text2, path44, entity) {
18107
18239
  if (keys.length === 1 && keys[0] === entity && Array.isArray(document[entity])) {
18108
18240
  return {
18109
18241
  [entity]: document[entity].map(
18110
- (row, i) => rowObject2(row, `${path44}:${entity}[${i}]`)
18242
+ (row, i) => rowObject2(row, `${path49}:${entity}[${i}]`)
18111
18243
  )
18112
18244
  };
18113
18245
  }
18114
- return jsonlRows2(stripped, path44, entity);
18246
+ return jsonlRows2(stripped, path49, entity);
18115
18247
  }
18116
18248
  const out = {};
18117
18249
  for (const [name, listed2] of Object.entries(document)) {
18118
18250
  if (!Array.isArray(listed2))
18119
18251
  throw refuse2(
18120
- `${path44}: ${name} must map to an array of rows (JSONL lines are {"entity", "row"})`
18252
+ `${path49}: ${name} must map to an array of rows (JSONL lines are {"entity", "row"})`
18121
18253
  );
18122
18254
  out[name] = listed2.map(
18123
- (row, index2) => rowObject2(row, `${path44}:${name}[${index2}]`)
18255
+ (row, index2) => rowObject2(row, `${path49}:${name}[${index2}]`)
18124
18256
  );
18125
18257
  }
18126
18258
  return out;
@@ -18128,19 +18260,19 @@ function rowsIn(text2, path44, entity) {
18128
18260
  if (Array.isArray(document)) {
18129
18261
  if (entity === void 0)
18130
18262
  throw refuse2(
18131
- `${path44} is a bare array; say which entity it holds with --entity`
18263
+ `${path49} is a bare array; say which entity it holds with --entity`
18132
18264
  );
18133
18265
  return {
18134
18266
  [entity]: document.map(
18135
- (row, index2) => rowObject2(row, `${path44}[${index2}]`)
18267
+ (row, index2) => rowObject2(row, `${path49}[${index2}]`)
18136
18268
  )
18137
18269
  };
18138
18270
  }
18139
18271
  throw refuse2(
18140
- `${path44} is neither a JSON object of entity -> rows nor an array of rows`
18272
+ `${path49} is neither a JSON object of entity -> rows nor an array of rows`
18141
18273
  );
18142
18274
  }
18143
- function jsonlRows2(text2, path44, entity) {
18275
+ function jsonlRows2(text2, path49, entity) {
18144
18276
  const out = {};
18145
18277
  const lines = text2.split(/\r?\n/);
18146
18278
  for (let index2 = 0; index2 < lines.length; index2++) {
@@ -18151,9 +18283,9 @@ function jsonlRows2(text2, path44, entity) {
18151
18283
  try {
18152
18284
  item = JSON.parse(line);
18153
18285
  } catch {
18154
- throw refuse2(`${path44}:${number} is not JSON`);
18286
+ throw refuse2(`${path49}:${number} is not JSON`);
18155
18287
  }
18156
- const where = `${path44}:${number}`;
18288
+ const where = `${path49}:${number}`;
18157
18289
  if (entity !== void 0) {
18158
18290
  (out[entity] ??= []).push(rowObject2(item, where));
18159
18291
  continue;
@@ -19448,12 +19580,12 @@ function registerBenchCommands(root) {
19448
19580
  const creds = credentials(args);
19449
19581
  const runId = arg.str(args, "run");
19450
19582
  if (runId) {
19451
- const one = await api(
19583
+ const one2 = await api(
19452
19584
  creds,
19453
19585
  "GET",
19454
19586
  `/api/public/worlds/${encodeURIComponent(slug)}/tests/${encodeURIComponent(runId)}`
19455
19587
  );
19456
- printJson(ctx, one.run);
19588
+ printJson(ctx, one2.run);
19457
19589
  return 0;
19458
19590
  }
19459
19591
  const limit = arg.int(args, "limit");
@@ -19586,8 +19718,8 @@ function registerBenchCommands(root) {
19586
19718
  }
19587
19719
 
19588
19720
  // src/cli/platform/benchmarks.ts
19589
- var fs36 = __toESM(require("fs"));
19590
- var path27 = __toESM(require("path"));
19721
+ var fs37 = __toESM(require("fs"));
19722
+ var path28 = __toESM(require("path"));
19591
19723
  init_config();
19592
19724
  init_router();
19593
19725
  init_hub();
@@ -20668,9 +20800,9 @@ async function hostedDryRun(args, ctx, creds, pushDir) {
20668
20800
  ctx.stderr(
20669
20801
  `target ${target.slug}${target.ref ? `@${target.ref}` : ""} (${target.source}) \xB7 task ${task} \xB7 hosted, harbor oracle`
20670
20802
  );
20671
- const client4 = new HostedDryRunClient(worldsOptions(creds));
20803
+ const client5 = new HostedDryRunClient(worldsOptions(creds));
20672
20804
  const containerId = target.containerId ?? await resolveEnvironmentId(creds, target.slug);
20673
- const dispatched = await client4.dispatch({
20805
+ const dispatched = await client5.dispatch({
20674
20806
  containerId,
20675
20807
  task,
20676
20808
  ...listed2.versionId ? { versionId: listed2.versionId } : {}
@@ -20682,7 +20814,7 @@ async function hostedDryRun(args, ctx, creds, pushDir) {
20682
20814
  return 0;
20683
20815
  }
20684
20816
  const timeoutSeconds = arg.int(args, "wait-timeout") ?? 1200;
20685
- const verdict = await client4.settle(dispatched.runId, {
20817
+ const verdict = await client5.settle(dispatched.runId, {
20686
20818
  timeoutSeconds,
20687
20819
  onProgress: (v) => ctx.stderr(`# ${dispatched.task}: ${progressLine(v)}`)
20688
20820
  });
@@ -20931,12 +21063,90 @@ function printProvider(ctx, providers, only) {
20931
21063
 
20932
21064
  // src/cli/platform/benchmarks.ts
20933
21065
  init_client();
21066
+
21067
+ // src/cli/runtime/scaffoldVerifiers.ts
21068
+ var fs30 = __toESM(require("fs"));
21069
+ var path21 = __toESM(require("path"));
21070
+ init_router();
21071
+ var SCAFFOLD_VERIFIER = /^-- Scores 1\.0 once the world holds any (\S+) row; edit for real tasks\.\n/;
21072
+ function scaffoldVerifier(entity) {
21073
+ return `-- Scores 1.0 once the world holds any ${entity} row; edit for real tasks.
21074
+ -- It names the ${entity} entity: rename or remove that entity and \`gateway worlds schema check\`
21075
+ -- refuses this file until the FROM is edited or the file is deleted with it.
21076
+ SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}";
21077
+ `;
21078
+ }
21079
+ function scaffoldVerifierEntity(file) {
21080
+ if (!fs30.existsSync(file)) return void 0;
21081
+ const text2 = fs30.readFileSync(file, "utf8");
21082
+ const entity = SCAFFOLD_VERIFIER.exec(text2)?.[1];
21083
+ return entity !== void 0 && text2 === scaffoldVerifier(entity) ? entity : void 0;
21084
+ }
21085
+ function verifierNames(dir) {
21086
+ const folder = path21.join(dir, "verifiers");
21087
+ if (!fs30.existsSync(folder)) return void 0;
21088
+ return fs30.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
21089
+ }
21090
+ function verifierSql(name, entity, where) {
21091
+ if (!/^[A-Za-z_][A-Za-z0-9_-]*$/.test(name)) throw new CliError(`Verifier names match [A-Za-z_][A-Za-z0-9_-]*, got ${JSON.stringify(name)}`);
21092
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(entity)) throw new CliError(`Entity names match [A-Za-z_][A-Za-z0-9_]*, got ${JSON.stringify(entity)}`);
21093
+ if (where === void 0) return scaffoldVerifier(entity);
21094
+ const clause = where.trim();
21095
+ if (!clause) throw new CliError("--where is a SQL condition over the entity's columns; it cannot be empty");
21096
+ const defect = whereClauseDefect(clause);
21097
+ if (defect)
21098
+ throw new CliError(
21099
+ `--where ${JSON.stringify(clause)} cannot be a SQL condition: ${defect}. The file would fail \`gateway worlds schema check\` at once; fix the condition here instead.`
21100
+ );
21101
+ return `-- ${name}: scores 1.0 once a ${entity} row satisfies the condition; edit for real tasks.
21102
+ -- A verifier is one SQL statement returning one number in 0..1 (0.5 is partial credit).
21103
+ SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}" WHERE ${clause};
21104
+ `;
21105
+ }
21106
+ function whereClauseDefect(clause) {
21107
+ let depth = 0;
21108
+ let quote;
21109
+ for (const ch of clause) {
21110
+ if (quote) {
21111
+ if (ch === quote) quote = void 0;
21112
+ continue;
21113
+ }
21114
+ if (ch === "'" || ch === '"') quote = ch;
21115
+ else if (ch === "(") depth += 1;
21116
+ else if (ch === ")") depth -= 1;
21117
+ else if (ch === ";") return "a `;` would end the statement early; a verifier is one SQL statement";
21118
+ if (depth < 0) return "a `)` closes a parenthesis that was never opened";
21119
+ }
21120
+ if (quote) return `a ${quote} quote is never closed`;
21121
+ if (depth > 0) return `${depth} parenthes${depth === 1 ? "is is" : "es are"} never closed`;
21122
+ if (/(?:^|[\s(])(?:AND|OR|NOT|IN|IS|LIKE|BETWEEN)$/i.test(clause) || /[=<>!+\-*/,(]$/.test(clause))
21123
+ return "it ends in an operator with nothing after it";
21124
+ return void 0;
21125
+ }
21126
+ function addVerifier(dir, name, entity, where) {
21127
+ const sql = verifierSql(name, entity, where);
21128
+ const file = path21.join(dir, "verifiers", `${name}.sql`);
21129
+ if (fs30.existsSync(file))
21130
+ throw new CliError(`verifiers/${name}.sql already exists (have: ${(verifierNames(dir) ?? []).join(", ")}); edit it, or pick another name`);
21131
+ fs30.mkdirSync(path21.dirname(file), { recursive: true });
21132
+ fs30.writeFileSync(file, sql);
21133
+ return file;
21134
+ }
21135
+ function repointScaffoldVerifier(dir, entity, declared) {
21136
+ const file = path21.join(dir, "verifiers", "state_present.sql");
21137
+ const named2 = scaffoldVerifierEntity(file);
21138
+ if (named2 === void 0 || declared.includes(named2)) return null;
21139
+ fs30.writeFileSync(file, scaffoldVerifier(entity));
21140
+ return file;
21141
+ }
21142
+
21143
+ // src/cli/platform/benchmarks.ts
20934
21144
  init_local();
20935
21145
  init_shared();
20936
21146
 
20937
21147
  // src/cli/platform/worlds.ts
20938
- var fs35 = __toESM(require("fs"));
20939
- var path26 = __toESM(require("path"));
21148
+ var fs36 = __toESM(require("fs"));
21149
+ var path27 = __toESM(require("path"));
20940
21150
  init_config();
20941
21151
  init_router();
20942
21152
  init_describe();
@@ -21000,13 +21210,13 @@ var isDirectory = (p) => import_node_fs.default.existsSync(p) && import_node_fs.
21000
21210
  // src/cli/platform/worlds.ts
21001
21211
  var WORLDS2 = "/api/public/worlds";
21002
21212
  function collectFiles(directory) {
21003
- if (!fs35.existsSync(directory) || !fs35.statSync(directory).isDirectory())
21213
+ if (!fs36.existsSync(directory) || !fs36.statSync(directory).isDirectory())
21004
21214
  throw new CliError(`${directory}: not a directory`, 1);
21005
- return walk(directory).map((relative4) => {
21006
- const bytes = fs35.readFileSync(path26.join(directory, relative4));
21215
+ return walk(directory).map((relative6) => {
21216
+ const bytes = fs36.readFileSync(path27.join(directory, relative6));
21007
21217
  const text2 = bytes.toString("utf8");
21008
- return Buffer.from(text2, "utf8").equals(bytes) && !text2.includes("\uFFFD") ? { path: relative4, content: text2 } : {
21009
- path: relative4,
21218
+ return Buffer.from(text2, "utf8").equals(bytes) && !text2.includes("\uFFFD") ? { path: relative6, content: text2 } : {
21219
+ path: relative6,
21010
21220
  content: bytes.toString("base64"),
21011
21221
  encoding: "base64"
21012
21222
  };
@@ -21021,7 +21231,7 @@ async function describeLocalDirectory(dir, hostFlag) {
21021
21231
  const counts = await showLocalWorldData2(dir, void 0, creds);
21022
21232
  return describedLocally2(withRowCounts2(description, counts.entity_counts ?? {}), dir);
21023
21233
  }
21024
- var isDir = (candidate) => fs35.existsSync(candidate) && fs35.statSync(candidate).isDirectory();
21234
+ var isDir = (candidate) => fs36.existsSync(candidate) && fs36.statSync(candidate).isDirectory();
21025
21235
  function worldTreeFiles(from) {
21026
21236
  if (classifyTree(from).shape !== "none") return collectFiles(from);
21027
21237
  const files = collectFiles(from);
@@ -21129,7 +21339,7 @@ async function createOne(creds, body) {
21129
21339
  return api(creds, "POST", WORLDS2, body, { timeoutMs: 6e5 });
21130
21340
  }
21131
21341
  async function runBatch(file, args, ctx) {
21132
- const text2 = file === "-" ? fs35.readFileSync(0, "utf8") : fs35.readFileSync(file, "utf8");
21342
+ const text2 = file === "-" ? fs36.readFileSync(0, "utf8") : fs36.readFileSync(file, "utf8");
21133
21343
  const requests = text2.split("\n").map((line) => line.trim()).filter(Boolean).map(batchLine);
21134
21344
  if (requests.length === 0)
21135
21345
  throw new CliError("batch file holds no worlds", 1);
@@ -21396,7 +21606,7 @@ function refuseKind(dir, classified, wanted, command2) {
21396
21606
  );
21397
21607
  }
21398
21608
  function resolveKind(dir, args, command2) {
21399
- if (!fs36.existsSync(dir) || !fs36.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
21609
+ if (!fs37.existsSync(dir) || !fs37.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
21400
21610
  const classified = classifyTree(dir);
21401
21611
  const actual = kindOfTree(classified);
21402
21612
  const wanted = arg.str(args, "kind");
@@ -21406,7 +21616,7 @@ function resolveKind(dir, args, command2) {
21406
21616
  }
21407
21617
  function firstEntity(dir) {
21408
21618
  try {
21409
- const world = JSON.parse(fs36.readFileSync(path27.join(dir, "schema", "world.json"), "utf8"));
21619
+ const world = JSON.parse(fs37.readFileSync(path28.join(dir, "schema", "world.json"), "utf8"));
21410
21620
  const entities = world["x-gateway"]?.entities ?? world.entities;
21411
21621
  if (Array.isArray(entities)) return entities[0]?.name ?? null;
21412
21622
  if (entities && typeof entities === "object") return Object.keys(entities)[0] ?? null;
@@ -21414,22 +21624,17 @@ function firstEntity(dir) {
21414
21624
  }
21415
21625
  return null;
21416
21626
  }
21417
- function verifierNames(dir) {
21418
- const folder = path27.join(dir, "verifiers");
21419
- if (!fs36.existsSync(folder)) return [];
21420
- return fs36.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
21421
- }
21422
21627
  function readConfig2(dir) {
21423
- const file = path27.join(dir, BENCHMARK_CONFIG2);
21424
- if (!fs36.existsSync(file)) return {};
21628
+ const file = path28.join(dir, BENCHMARK_CONFIG2);
21629
+ if (!fs37.existsSync(file)) return {};
21425
21630
  try {
21426
- return JSON.parse(fs36.readFileSync(file, "utf8"));
21631
+ return JSON.parse(fs37.readFileSync(file, "utf8"));
21427
21632
  } catch {
21428
21633
  throw new CliError(`${file} is not JSON`, 1);
21429
21634
  }
21430
21635
  }
21431
21636
  function writeConfig2(dir, config) {
21432
- fs36.writeFileSync(path27.join(dir, BENCHMARK_CONFIG2), JSON.stringify({ ...config, note: "Defaults for `gateway benchmarks run` when --model / --rollouts are not given." }, null, 2) + "\n");
21637
+ fs37.writeFileSync(path28.join(dir, BENCHMARK_CONFIG2), JSON.stringify({ ...config, note: "Defaults for `gateway benchmarks run` when --model / --rollouts are not given." }, null, 2) + "\n");
21433
21638
  }
21434
21639
  function printValidation(ctx, report) {
21435
21640
  ctx.stdout(`${report.dir}: ${report.kind} benchmark \u2014 runner reads it as ${report.detectedKind} \u2014 ${report.ok ? "ok" : `${report.problems.length + report.tasks.reduce((n, t) => n + t.problems.length, 0)} problem(s)`}`);
@@ -21512,7 +21717,7 @@ async function dryRunWorld(dir, task, opts = {}) {
21512
21717
  };
21513
21718
  if (!local)
21514
21719
  return { ...base, note: `not executed: ${opts.plan ? "--plan" : localRuntimeReason() || "no bundled runtime"} \u2014 the steps above are what would run. ${base.note}` };
21515
- const payload = await localBridge({ command: "dry-run", world: path27.resolve(dir), task }, local);
21720
+ const payload = await localBridge({ command: "dry-run", world: path28.resolve(dir), task }, local);
21516
21721
  const detail = detailFrom(payload);
21517
21722
  if (detail) throw new BridgeRejected(detail);
21518
21723
  const answer = payload;
@@ -21609,11 +21814,11 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
21609
21814
  "benchmarks init --kind image is not shipped: the benchmark runner has no hub engine for a bring-your-own image \u2014 its generic engine (deploy/benchmark-runner/engines/generic_runner.py) runs registry entries from benchmarks.json, not pushed versions, and `bench push --image` only records the ref on a world's server image. Shipping it needs an `image` kind in detect_env_kind, a runner branch that runs the version's imageRef through the generic engine and harvests a reward, and the harvest itself. Package the benchmark as a harbor task instead (`--kind harbor`: your image in [environment] docker_image, your grader in tests/test.sh).",
21610
21815
  2
21611
21816
  );
21612
- if (fs36.existsSync(dir) && fs36.readdirSync(dir).length > 0)
21817
+ if (fs37.existsSync(dir) && fs37.readdirSync(dir).length > 0)
21613
21818
  throw new CliError(`${dir} is not empty; init writes a fresh ${kind} tree`, 1);
21614
21819
  const models = arg.list(args, "model");
21615
21820
  const rollouts = arg.int(args, "rollouts") ?? 1;
21616
- const slug = path27.basename(path27.resolve(dir));
21821
+ const slug = path28.basename(path28.resolve(dir));
21617
21822
  if (kind === "harbor") {
21618
21823
  const scaffold = writeHarborScaffold(dir, {
21619
21824
  name: arg.str(args, "name"),
@@ -21659,17 +21864,12 @@ proposals: \`gateway bench\`. Walkthrough: \`gateway worlds skill ${BENCHMARKS_S
21659
21864
  if (host) initArgs.push("--host", host);
21660
21865
  const init2 = await captureSub(root, initArgs, ctx);
21661
21866
  if (init2.code !== 0) return init2.code;
21662
- let verifiers = verifierNames(dir);
21867
+ let verifiers = verifierNames(dir) ?? [];
21663
21868
  if (verifiers.length === 0) {
21664
21869
  const entity = firstEntity(dir);
21665
21870
  if (!entity) throw new CliError(`${dir}: schema/world.json declares no entity to write a verifier for`, 1);
21666
- fs36.mkdirSync(path27.join(dir, "verifiers"), { recursive: true });
21667
- fs36.writeFileSync(
21668
- path27.join(dir, "verifiers", "state_present.sql"),
21669
- `-- Scores 1.0 once the world holds any ${entity} row; edit for real tasks.
21670
- SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}";
21671
- `
21672
- );
21871
+ fs37.mkdirSync(path28.join(dir, "verifiers"), { recursive: true });
21872
+ fs37.writeFileSync(path28.join(dir, "verifiers", "state_present.sql"), scaffoldVerifier(entity));
21673
21873
  verifiers = ["state_present"];
21674
21874
  }
21675
21875
  const taskId = arg.str(args, "task") ?? "first_task";
@@ -21924,7 +22124,7 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
21924
22124
  const dirFlag = arg.str(args, "dir");
21925
22125
  const config = dirFlag ? readConfig2(dirFlag) : {};
21926
22126
  if (dirFlag) {
21927
- const owner = config.slug ?? path27.basename(path27.resolve(dirFlag));
22127
+ const owner = config.slug ?? path28.basename(path28.resolve(dirFlag));
21928
22128
  if (owner !== slug)
21929
22129
  throw new CliError(`benchmarks run: --dir ${dirFlag} is the benchmark \`${owner}\` (its benchmark.json), not \`${slug}\`; pass that benchmark's --dir, or --model and -k explicitly`, 2);
21930
22130
  }
@@ -21958,7 +22158,7 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
21958
22158
  const dir = args.positionals[0];
21959
22159
  const from = arg.str(args, "from");
21960
22160
  if (from !== "harbor" && from !== "verifiers") throw new CliError("benchmarks import needs --from harbor|verifiers");
21961
- if (!fs36.existsSync(dir) || !fs36.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
22161
+ if (!fs37.existsSync(dir) || !fs37.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
21962
22162
  const report = importReport(dir, from);
21963
22163
  if (arg.bool(args, "json")) printJson(ctx, report);
21964
22164
  else {
@@ -21976,10 +22176,405 @@ before anything is sent); dispatch again for more. Never set max_tokens on the m
21976
22176
  // src/cli/platform/index.ts
21977
22177
  init_connector();
21978
22178
 
22179
+ // src/cli/platform/dashboards.ts
22180
+ var import_node_child_process6 = require("child_process");
22181
+ var fs39 = __toESM(require("fs"));
22182
+ var path30 = __toESM(require("path"));
22183
+ init_config();
22184
+ init_router();
22185
+ init_checkoutTarget();
22186
+
22187
+ // src/cli/platform/dashboards/dashboardClient.ts
22188
+ init_config();
22189
+ init_shared();
22190
+ var one = (id) => `/api/public/dashboards/${encodeURIComponent(id)}`;
22191
+ var DashboardClient = class {
22192
+ constructor(creds) {
22193
+ this.creds = creds;
22194
+ }
22195
+ creds;
22196
+ list(limit) {
22197
+ return api(this.creds, "GET", `/api/public/dashboards${query({ limit })}`);
22198
+ }
22199
+ create(body) {
22200
+ return api(this.creds, "POST", "/api/public/dashboards", body);
22201
+ }
22202
+ pull(id) {
22203
+ return api(this.creds, "GET", `${one(id)}`);
22204
+ }
22205
+ push(id, body) {
22206
+ return api(this.creds, "PUT", `${one(id)}/code`, body);
22207
+ }
22208
+ testTransform(id, body) {
22209
+ return api(this.creds, "POST", `${one(id)}/test-transform`, body);
22210
+ }
22211
+ render(id, body) {
22212
+ return api(this.creds, "POST", `${one(id)}/render`, body);
22213
+ }
22214
+ };
22215
+
22216
+ // src/cli/platform/dashboards/dashboardDir.ts
22217
+ var import_node_crypto16 = require("crypto");
22218
+ var fs38 = __toESM(require("fs"));
22219
+ var path29 = __toESM(require("path"));
22220
+ init_router();
22221
+ var DASHBOARD_MANIFEST = "gateway-dashboard.json";
22222
+ var RENDER_DIR = "render";
22223
+ var TRANSFORM_FILE = "transform.js";
22224
+ var sha2562 = (text2) => (0, import_node_crypto16.createHash)("sha256").update(text2, "utf8").digest("hex");
22225
+ var DashboardDir = class _DashboardDir {
22226
+ constructor(root, manifest) {
22227
+ this.root = root;
22228
+ this.manifest = manifest;
22229
+ }
22230
+ root;
22231
+ manifest;
22232
+ static at(root) {
22233
+ return new _DashboardDir(path29.resolve(root), _DashboardDir.readManifest(root));
22234
+ }
22235
+ static isDashboard(root) {
22236
+ return _DashboardDir.readManifest(root) !== null;
22237
+ }
22238
+ static readManifest(root) {
22239
+ try {
22240
+ const parsed = JSON.parse(fs38.readFileSync(path29.join(root, DASHBOARD_MANIFEST), "utf8"));
22241
+ return typeof parsed?.id === "string" && typeof parsed.stamp === "string" ? parsed : null;
22242
+ } catch {
22243
+ return null;
22244
+ }
22245
+ }
22246
+ tracked() {
22247
+ if (this.manifest) return this.manifest;
22248
+ throw new CliError(
22249
+ `${this.root} is not a dashboard directory (no ${DASHBOARD_MANIFEST}). Run \`gateway dashboards pull <id>\` or \`gateway dashboards create <name>\` first.`,
22250
+ 2
22251
+ );
22252
+ }
22253
+ /** The directory as `CheckoutTarget` reads a checkout: its identity, its base, its edits. */
22254
+ state() {
22255
+ const base = this.manifest?.files;
22256
+ if (!this.manifest || !base) return { meta: null, dirty: [], clean: false };
22257
+ const now = this.hashes();
22258
+ const dirty = /* @__PURE__ */ new Set();
22259
+ for (const [rel, hash] of Object.entries(now)) if (base[rel] !== hash) dirty.add(rel);
22260
+ for (const rel of Object.keys(base)) if (!(rel in now)) dirty.add(rel);
22261
+ return {
22262
+ meta: { slug: this.manifest.id, baseFiles: base },
22263
+ dirty: [...dirty].sort(),
22264
+ clean: dirty.size === 0
22265
+ };
22266
+ }
22267
+ /** What a push sends: the render files (paths relative to `render/`), the entrypoint and the transform. */
22268
+ source() {
22269
+ const manifest = this.tracked();
22270
+ const local = this.localFiles();
22271
+ const files = [...local.entries()].filter(([rel]) => rel.startsWith(`${RENDER_DIR}/`)).map(([rel, content]) => ({ path: rel.slice(RENDER_DIR.length + 1), content }));
22272
+ if (files.length === 0)
22273
+ throw new CliError(`no render files under ${path29.join(this.root, RENDER_DIR)} \u2014 nothing to push`, 2);
22274
+ const entry = manifest.entrypoint ?? void 0;
22275
+ return {
22276
+ files,
22277
+ entrypoint: files.some((file) => file.path === entry) ? entry : void 0,
22278
+ transform: local.get(TRANSFORM_FILE) ?? null
22279
+ };
22280
+ }
22281
+ /** The local transform, or a usage error when there is none to test. */
22282
+ transform() {
22283
+ const transform = this.localFiles().get(TRANSFORM_FILE);
22284
+ if (transform !== void 0) return transform;
22285
+ throw new CliError(`no ${TRANSFORM_FILE} in ${this.root} \u2014 nothing to test`, 2);
22286
+ }
22287
+ /** Lay a pulled or created dashboard into the directory and record it. */
22288
+ write(code) {
22289
+ fs38.mkdirSync(this.root, { recursive: true });
22290
+ for (const file of code.files) this.writeFile(`${RENDER_DIR}/${file.path}`, file.content);
22291
+ if (code.transform !== null) this.writeFile(TRANSFORM_FILE, code.transform);
22292
+ return this.record({ ...code, files: this.hashes() });
22293
+ }
22294
+ /** After a push: the new stamp and the files as they now stand on the platform. */
22295
+ pushed(result) {
22296
+ const manifest = this.tracked();
22297
+ return this.record({ ...manifest, ...result, files: this.hashes() });
22298
+ }
22299
+ record(manifest) {
22300
+ const kept = {
22301
+ id: manifest.id,
22302
+ name: manifest.name,
22303
+ kind: manifest.kind,
22304
+ entrypoint: manifest.entrypoint,
22305
+ stamp: manifest.stamp,
22306
+ url: manifest.url,
22307
+ files: manifest.files
22308
+ };
22309
+ fs38.writeFileSync(path29.join(this.root, DASHBOARD_MANIFEST), JSON.stringify(kept, null, 2) + "\n");
22310
+ return new _DashboardDir(this.root, kept);
22311
+ }
22312
+ hashes() {
22313
+ const out = {};
22314
+ for (const [rel, content] of this.localFiles()) out[rel] = sha2562(content);
22315
+ return out;
22316
+ }
22317
+ /** Every regular file under `render/` plus `transform.js`; hidden files are skipped, links refused. */
22318
+ localFiles() {
22319
+ const out = /* @__PURE__ */ new Map();
22320
+ const renderRoot = path29.join(this.root, RENDER_DIR);
22321
+ if (fs38.existsSync(renderRoot)) this.walk(renderRoot, out);
22322
+ const transform = path29.join(this.root, TRANSFORM_FILE);
22323
+ if (fs38.existsSync(transform)) out.set(TRANSFORM_FILE, this.readRegular(transform));
22324
+ return new Map([...out.entries()].sort(([a], [b]) => a.localeCompare(b)));
22325
+ }
22326
+ walk(dir, out) {
22327
+ for (const entry of fs38.readdirSync(dir, { withFileTypes: true })) {
22328
+ if (entry.name.startsWith(".")) continue;
22329
+ const full = path29.join(dir, entry.name);
22330
+ if (entry.isDirectory()) this.walk(full, out);
22331
+ else out.set(path29.relative(this.root, full).split(path29.sep).join("/"), this.readRegular(full));
22332
+ }
22333
+ }
22334
+ readRegular(file) {
22335
+ if (!fs38.lstatSync(file).isFile())
22336
+ throw new CliError(`${file} is not a regular file (links are not followed) \u2014 replace it with the file itself`, 2);
22337
+ return fs38.readFileSync(file, "utf8");
22338
+ }
22339
+ /** A server-named path lands under the directory or not at all (B4). */
22340
+ writeFile(rel, content) {
22341
+ const parts2 = rel.split("/");
22342
+ const escapes = path29.isAbsolute(rel) || rel.includes("\\") || parts2.some((p) => p === ".." || p === "");
22343
+ if (escapes) throw new CliError(`refusing to write ${JSON.stringify(rel)}: not a path inside the dashboard`, 1);
22344
+ const target = path29.join(this.root, ...parts2);
22345
+ fs38.mkdirSync(path29.dirname(target), { recursive: true });
22346
+ fs38.writeFileSync(target, content);
22347
+ }
22348
+ };
22349
+ function dashboardDirName(name) {
22350
+ const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
22351
+ return slug || "dashboard";
22352
+ }
22353
+
22354
+ // src/cli/platform/dashboards.ts
22355
+ init_shared();
22356
+ var TARGET_FLAG = { name: "target", short: "t", help: "Directory to write (defaults to ./<name>)." };
22357
+ var FORCE_FLAG = {
22358
+ name: "force",
22359
+ help: "Overwrite an explicit --target that has local edits or holds another dashboard.",
22360
+ boolean: true
22361
+ };
22362
+ var DIR_POSITIONAL = {
22363
+ name: "dir",
22364
+ help: "A dashboard directory (default: the current directory).",
22365
+ optional: true
22366
+ };
22367
+ var TARGET_POSITIONAL = {
22368
+ name: "target",
22369
+ help: "A dashboard directory or a dashboard id (default: the current directory).",
22370
+ optional: true
22371
+ };
22372
+ var client3 = (args) => new DashboardClient(credentials(args));
22373
+ function landing(identity, name, args) {
22374
+ const target = arg.str(args, "target");
22375
+ try {
22376
+ return CheckoutTarget.resolve(target === void 0 ? dashboardDirName(name) : identity, target, {
22377
+ cwd: process.cwd(),
22378
+ force: arg.bool(args, "force"),
22379
+ state: (dir) => DashboardDir.at(dir).state()
22380
+ });
22381
+ } catch (error) {
22382
+ if (error instanceof CheckoutRefusedError) throw new CliError(error.message, 1);
22383
+ throw error;
22384
+ }
22385
+ }
22386
+ function checkout(ctx, code, landing2) {
22387
+ landing2.clear();
22388
+ DashboardDir.at(landing2.dir).write(code);
22389
+ if (code.compiledOnly)
22390
+ ctx.stderr(
22391
+ "warning: this dashboard's render exists only as compiled code; add render/index.ts (exporting render) and push to replace it"
22392
+ );
22393
+ printJson(ctx, {
22394
+ id: code.id,
22395
+ name: code.name,
22396
+ kind: code.kind,
22397
+ dir: landing2.dir,
22398
+ files: code.files.map((file) => `render/${file.path}`).concat(code.transform === null ? [] : ["transform.js"]),
22399
+ url: code.url
22400
+ });
22401
+ }
22402
+ var looksLikePath = (value) => value === "." || value.includes("/") || value.includes(path30.sep) || fs39.existsSync(value);
22403
+ function dashboardId(target) {
22404
+ const candidate = target ?? ".";
22405
+ if (!looksLikePath(candidate)) return candidate;
22406
+ return DashboardDir.at(candidate).tracked().id;
22407
+ }
22408
+ function launch(url, args) {
22409
+ if (arg.bool(args, "no-launch") || process.env.GATEWAY_NO_BROWSER || !process.stdout.isTTY) return;
22410
+ const opener = { darwin: "open", linux: "xdg-open" }[process.platform];
22411
+ if (opener) (0, import_node_child_process6.execFile)(opener, [url], () => void 0);
22412
+ }
22413
+ function registerDashboardCommands(root) {
22414
+ const dashboards = root.group(
22415
+ "dashboards",
22416
+ "Design dashboards as code: pull one into a directory, edit its TypeScript render files and transform, push it back."
22417
+ );
22418
+ dashboards.notes = [
22419
+ "A dashboard directory holds gateway-dashboard.json, render/ (the TypeScript render files; the entrypoint",
22420
+ "exports render(ctx) returning HTML) and an optional transform.js. The code-design agent's checks run on every push.",
22421
+ "",
22422
+ " gateway dashboards create 'Support review' # a working starter in ./support-review",
22423
+ " cd support-review && $EDITOR render/index.ts",
22424
+ " gateway dashboards push # refused, with every problem, if it does not compile",
22425
+ " gateway dashboards render # renders it on real data and prints the app URL"
22426
+ ].join("\n");
22427
+ dashboards.command({
22428
+ name: "list",
22429
+ help: "List the project's dashboards, newest first.",
22430
+ flags: [{ name: "limit", help: "Most dashboards to return (1\u2013200, default 50)." }, JSON_OUTPUT_FLAG, HOST_FLAG],
22431
+ run: async (args, ctx) => {
22432
+ const limit = listLimit(arg.int(args, "limit"));
22433
+ const listed2 = await client3(args).list(limit);
22434
+ emit(
22435
+ ctx,
22436
+ args,
22437
+ listed2,
22438
+ () => listed2.data.length === 0 ? ["No dashboards yet. Run `gateway dashboards create <name>`."] : listed2.data.map((d) => `${d.id} ${d.kind.padEnd(11)} ${d.name}`)
22439
+ );
22440
+ }
22441
+ });
22442
+ dashboards.command({
22443
+ name: "create",
22444
+ help: "Create a dashboard (from working starter code unless --template empty) and check it out into a directory.",
22445
+ positionals: [{ name: "name", help: "Dashboard name, unique in the project." }],
22446
+ flags: [
22447
+ { name: "description", help: "One line on what it shows." },
22448
+ { name: "task-set", help: "Render each task of this task set (id) instead of sessions." },
22449
+ { name: "environment", help: "Render this environment (id) instead of sessions." },
22450
+ { name: "template", help: "starter (default) or empty." },
22451
+ TARGET_FLAG,
22452
+ FORCE_FLAG,
22453
+ HOST_FLAG
22454
+ ],
22455
+ output: "json",
22456
+ run: async (args, ctx) => {
22457
+ const template = arg.str(args, "template") ?? "starter";
22458
+ if (template !== "starter" && template !== "empty")
22459
+ throw new CliError(`--template must be starter or empty, not \`${template}\`.`, 2);
22460
+ if (arg.str(args, "task-set") && arg.str(args, "environment"))
22461
+ throw new CliError("pass --task-set or --environment, not both.", 2);
22462
+ const name = args.positionals[0];
22463
+ const where = landing(name, name, args);
22464
+ const body = {
22465
+ name,
22466
+ template,
22467
+ description: arg.str(args, "description"),
22468
+ taskSetId: arg.str(args, "task-set"),
22469
+ environmentId: arg.str(args, "environment")
22470
+ };
22471
+ checkout(ctx, await client3(args).create(body), where);
22472
+ }
22473
+ });
22474
+ dashboards.command({
22475
+ name: "pull",
22476
+ help: "Check a dashboard's code out into a directory: render/, transform.js and gateway-dashboard.json.",
22477
+ positionals: [{ name: "id", help: "Dashboard id (from `gateway dashboards list`)." }],
22478
+ flags: [TARGET_FLAG, FORCE_FLAG, HOST_FLAG],
22479
+ output: "json",
22480
+ run: async (args, ctx) => {
22481
+ const code = await client3(args).pull(args.positionals[0]);
22482
+ checkout(ctx, code, landing(code.id, code.name, args));
22483
+ }
22484
+ });
22485
+ dashboards.command({
22486
+ name: "push",
22487
+ help: "Replace the dashboard's code with the directory's files, refused (nothing written) if it does not compile or changed since your pull.",
22488
+ positionals: [DIR_POSITIONAL],
22489
+ flags: [
22490
+ { name: "dry-run", help: "Check the code and the stamp without writing.", boolean: true },
22491
+ { name: "force", help: "Overwrite even if the dashboard changed since your pull.", boolean: true },
22492
+ HOST_FLAG
22493
+ ],
22494
+ output: "json",
22495
+ run: async (args, ctx) => {
22496
+ const dir = DashboardDir.at(args.positionals[0] ?? ".");
22497
+ const manifest = dir.tracked();
22498
+ const dryRun = arg.bool(args, "dry-run");
22499
+ const pushed = await client3(args).push(manifest.id, {
22500
+ ...dir.source(),
22501
+ baseStamp: manifest.stamp,
22502
+ force: arg.bool(args, "force") || void 0,
22503
+ dryRun: dryRun || void 0
22504
+ });
22505
+ if (!dryRun) dir.pushed(pushed);
22506
+ printJson(ctx, pushed);
22507
+ }
22508
+ });
22509
+ dashboards.command({
22510
+ name: "test-transform",
22511
+ help: "Run the directory's transform.js against a real session and print its output and shape; nothing is saved.",
22512
+ positionals: [DIR_POSITIONAL],
22513
+ flags: [{ name: "session", help: "Session id (default: the newest session the dashboard matches)." }, HOST_FLAG],
22514
+ output: "json",
22515
+ run: async (args, ctx) => {
22516
+ const dir = DashboardDir.at(args.positionals[0] ?? ".");
22517
+ const tested = await client3(args).testTransform(dir.tracked().id, {
22518
+ transform: dir.transform(),
22519
+ sessionId: arg.str(args, "session")
22520
+ });
22521
+ printJson(ctx, tested);
22522
+ return tested.success ? 0 : 1;
22523
+ }
22524
+ });
22525
+ dashboards.command({
22526
+ name: "render",
22527
+ help: "Render the pushed dashboard on real data and print whether it rendered and the app URL. Exit 1 when it did not.",
22528
+ positionals: [TARGET_POSITIONAL],
22529
+ flags: [
22530
+ { name: "session", help: "Session id for a session dashboard (default: the newest matching session)." },
22531
+ { name: "task-set", help: "Task set id for a task dashboard (default: its bound task set)." },
22532
+ { name: "task", help: "Task id for a task dashboard (default: the first task)." },
22533
+ { name: "out", help: "Also write the rendered HTML to this file." },
22534
+ HOST_FLAG
22535
+ ],
22536
+ output: "json",
22537
+ run: async (args, ctx) => {
22538
+ const out = arg.str(args, "out");
22539
+ const rendered = await client3(args).render(dashboardId(args.positionals[0]), {
22540
+ sessionId: arg.str(args, "session"),
22541
+ taskSetId: arg.str(args, "task-set"),
22542
+ taskId: arg.str(args, "task"),
22543
+ includeHtml: out ? true : void 0
22544
+ });
22545
+ if (out && rendered.html !== null) fs39.writeFileSync(out, rendered.html);
22546
+ const summary2 = {
22547
+ success: rendered.success,
22548
+ error: rendered.error,
22549
+ kind: rendered.kind,
22550
+ target: rendered.target,
22551
+ executionTimeMs: rendered.executionTimeMs,
22552
+ url: rendered.url
22553
+ };
22554
+ printJson(ctx, out ? { ...summary2, out: path30.resolve(out) } : summary2);
22555
+ return rendered.success ? 0 : 1;
22556
+ }
22557
+ });
22558
+ dashboards.command({
22559
+ name: "open",
22560
+ help: "Print the app URL of a dashboard and open it in the browser when run from a terminal.",
22561
+ positionals: [TARGET_POSITIONAL],
22562
+ flags: [
22563
+ { name: "no-launch", help: "Print the URL only (also when GATEWAY_NO_BROWSER is set or stdout is not a terminal).", boolean: true },
22564
+ HOST_FLAG
22565
+ ],
22566
+ run: async (args, ctx) => {
22567
+ const code = await client3(args).pull(dashboardId(args.positionals[0]));
22568
+ ctx.stdout(code.url);
22569
+ launch(code.url, args);
22570
+ }
22571
+ });
22572
+ }
22573
+
21979
22574
  // src/cli/platform/data.ts
21980
- var fs43 = __toESM(require("fs"));
22575
+ var fs46 = __toESM(require("fs"));
21981
22576
  var os7 = __toESM(require("os"));
21982
- var path33 = __toESM(require("path"));
22577
+ var path36 = __toESM(require("path"));
21983
22578
  var import_node_stream2 = require("stream");
21984
22579
  init_config();
21985
22580
  init_router();
@@ -22273,9 +22868,9 @@ function objects(value) {
22273
22868
  if (isObject(value)) return [value];
22274
22869
  return [];
22275
22870
  }
22276
- function dig(value, path44) {
22871
+ function dig(value, path49) {
22277
22872
  let at = value;
22278
- for (const part of path44.split(".").filter(Boolean)) {
22873
+ for (const part of path49.split(".").filter(Boolean)) {
22279
22874
  if (!isObject(at) || !at.has(part)) return null;
22280
22875
  at = at.get(part);
22281
22876
  }
@@ -22293,11 +22888,11 @@ function shaped2(slug, item) {
22293
22888
  if (typeof item === "string") return shapeText(slug, item, "str");
22294
22889
  return new JsonNumber(shapeText(slug, pyStr(item), item.isFloat ? "float" : "int"));
22295
22890
  }
22296
- function redact(value, policy, slug, path44 = "") {
22891
+ function redact(value, policy, slug, path49 = "") {
22297
22892
  if (isObject(value)) {
22298
22893
  const out = /* @__PURE__ */ new Map();
22299
22894
  for (const [key2, item] of value) {
22300
- const here = path44 ? `${path44}.${key2}` : key2;
22895
+ const here = path49 ? `${path49}.${key2}` : key2;
22301
22896
  if (named(key2, here, policy.drop)) continue;
22302
22897
  if (named(key2, here, policy.hash) && item !== null) out.set(key2, digest(slug, item));
22303
22898
  else if (named(key2, here, policy.preserve) && item !== null) out.set(key2, shaped2(slug, item));
@@ -22306,7 +22901,7 @@ function redact(value, policy, slug, path44 = "") {
22306
22901
  }
22307
22902
  return out;
22308
22903
  }
22309
- if (Array.isArray(value)) return value.map((item) => redact(item, policy, slug, path44 ? `${path44}.*` : "*"));
22904
+ if (Array.isArray(value)) return value.map((item) => redact(item, policy, slug, path49 ? `${path49}.*` : "*"));
22310
22905
  return value;
22311
22906
  }
22312
22907
  function pyDumpsPlain(value) {
@@ -22319,15 +22914,15 @@ function pyDumpsPlain(value) {
22319
22914
  }
22320
22915
 
22321
22916
  // src/cli/platform/worldData/ingestMap.ts
22322
- var fs37 = __toESM(require("fs"));
22323
- var path28 = __toESM(require("path"));
22917
+ var fs40 = __toESM(require("fs"));
22918
+ var path31 = __toESM(require("path"));
22324
22919
  init_router();
22325
22920
  var MAP_FILE = "ingest.toml";
22326
22921
  var MAP_KINDS = ["tool-call", "rows", "csv"];
22327
22922
  var SAMPLE_WIDTH = 48;
22328
22923
  function readMapping(file) {
22329
- if (!fs37.existsSync(file) || !fs37.statSync(file).isFile()) throw new CliError(`no mapping file at ${file}`, 1);
22330
- const text2 = fs37.readFileSync(file, "utf8");
22924
+ if (!fs40.existsSync(file) || !fs40.statSync(file).isFile()) throw new CliError(`no mapping file at ${file}`, 1);
22925
+ const text2 = fs40.readFileSync(file, "utf8");
22331
22926
  try {
22332
22927
  parseToml(text2);
22333
22928
  } catch (error) {
@@ -22337,8 +22932,8 @@ function readMapping(file) {
22337
22932
  return text2;
22338
22933
  }
22339
22934
  function worldMapping(dir) {
22340
- const file = path28.join(dir, MAP_FILE);
22341
- return fs37.existsSync(file) ? fs37.readFileSync(file, "utf8") : null;
22935
+ const file = path31.join(dir, MAP_FILE);
22936
+ return fs40.existsSync(file) ? fs40.readFileSync(file, "utf8") : null;
22342
22937
  }
22343
22938
  var isObject10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
22344
22939
  function sample2(value) {
@@ -22447,7 +23042,7 @@ function skeleton(records2, entities, kind, opts = {}) {
22447
23042
  }
22448
23043
 
22449
23044
  // src/cli/platform/worldData/records.ts
22450
- var fs38 = __toESM(require("fs"));
23045
+ var fs41 = __toESM(require("fs"));
22451
23046
  init_router();
22452
23047
  init_ingest();
22453
23048
  var FROM = ["tool-calls", "traces", "rows", "csv"];
@@ -22477,24 +23072,24 @@ function readInputRecords(files, from, readText4, options = {}) {
22477
23072
  return records2;
22478
23073
  }
22479
23074
  var readFileText = (file) => {
22480
- if (!fs38.existsSync(file) || !fs38.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
22481
- return fs38.readFileSync(file, "utf8");
23075
+ if (!fs41.existsSync(file) || !fs41.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
23076
+ return fs41.readFileSync(file, "utf8");
22482
23077
  };
22483
23078
 
22484
23079
  // src/cli/platform/data.ts
22485
23080
  init_transform();
22486
23081
 
22487
23082
  // src/cli/platform/worldData/manifest.ts
22488
- var fs39 = __toESM(require("fs"));
22489
- var path29 = __toESM(require("path"));
23083
+ var fs42 = __toESM(require("fs"));
23084
+ var path32 = __toESM(require("path"));
22490
23085
  init_router();
22491
- var MANIFEST_DIR = path29.join(".gateway", "imports");
23086
+ var MANIFEST_DIR = path32.join(".gateway", "imports");
22492
23087
  function manifestDir(cwd = process.cwd()) {
22493
- return path29.join(cwd, MANIFEST_DIR);
23088
+ return path32.join(cwd, MANIFEST_DIR);
22494
23089
  }
22495
23090
  function manifestPath(batchId, cwd = process.cwd()) {
22496
23091
  if (!/^[A-Za-z0-9_-]+$/.test(batchId)) throw new CliError(`Not a batch id: ${batchId}`);
22497
- return path29.join(manifestDir(cwd), `${batchId}.json`);
23092
+ return path32.join(manifestDir(cwd), `${batchId}.json`);
22498
23093
  }
22499
23094
  var stamp = () => (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z");
22500
23095
  function newManifest(fields) {
@@ -22503,18 +23098,18 @@ function newManifest(fields) {
22503
23098
  }
22504
23099
  function writeManifest(manifest, cwd = process.cwd()) {
22505
23100
  const file = manifestPath(manifest.batchId, cwd);
22506
- fs39.mkdirSync(path29.dirname(file), { recursive: true });
22507
- const ignore = path29.join(cwd, ".gateway", ".gitignore");
22508
- if (!fs39.existsSync(ignore)) fs39.writeFileSync(ignore, "*\n");
23101
+ fs42.mkdirSync(path32.dirname(file), { recursive: true });
23102
+ const ignore = path32.join(cwd, ".gateway", ".gitignore");
23103
+ if (!fs42.existsSync(ignore)) fs42.writeFileSync(ignore, "*\n");
22509
23104
  manifest.updatedAt = stamp();
22510
23105
  const tmp = `${file}.tmp`;
22511
- fs39.writeFileSync(tmp, JSON.stringify(manifest, null, 1) + "\n");
22512
- fs39.renameSync(tmp, file);
23106
+ fs42.writeFileSync(tmp, JSON.stringify(manifest, null, 1) + "\n");
23107
+ fs42.renameSync(tmp, file);
22513
23108
  return file;
22514
23109
  }
22515
23110
  function readManifest(batchId, cwd = process.cwd()) {
22516
23111
  try {
22517
- const parsed = JSON.parse(fs39.readFileSync(manifestPath(batchId, cwd), "utf8"));
23112
+ const parsed = JSON.parse(fs42.readFileSync(manifestPath(batchId, cwd), "utf8"));
22518
23113
  return parsed && parsed.version === 1 && parsed.batchId === batchId ? parsed : null;
22519
23114
  } catch {
22520
23115
  return null;
@@ -22528,9 +23123,9 @@ function uploadedEntry(manifest, ordinal, digest2) {
22528
23123
  }
22529
23124
  function listManifests(cwd = process.cwd()) {
22530
23125
  const dir = manifestDir(cwd);
22531
- if (!fs39.existsSync(dir)) return [];
23126
+ if (!fs42.existsSync(dir)) return [];
22532
23127
  const out = [];
22533
- for (const name of fs39.readdirSync(dir)) {
23128
+ for (const name of fs42.readdirSync(dir)) {
22534
23129
  if (!name.endsWith(".json")) continue;
22535
23130
  const manifest = readManifest(name.slice(0, -5), cwd);
22536
23131
  if (manifest) out.push(manifest);
@@ -22546,15 +23141,15 @@ function findResumable(slug, inputs, cwd = process.cwd()) {
22546
23141
  init_describe();
22547
23142
 
22548
23143
  // src/cli/platform/worldData/worldConfig.ts
22549
- var fs40 = __toESM(require("fs"));
22550
- var path30 = __toESM(require("path"));
23144
+ var fs43 = __toESM(require("fs"));
23145
+ var path33 = __toESM(require("path"));
22551
23146
  init_router();
22552
23147
  function loadWorldConfig(dir) {
22553
- const worldFile = ["schema/world.json", "world.json"].map((p) => path30.join(dir, p)).find((p) => fs40.existsSync(p));
23148
+ const worldFile = ["schema/world.json", "world.json"].map((p) => path33.join(dir, p)).find((p) => fs43.existsSync(p));
22554
23149
  if (!worldFile) throw new CliError(`${dir} has no schema/world.json; extract needs a schema world`, 1);
22555
23150
  let document;
22556
23151
  try {
22557
- document = JSON.parse(fs40.readFileSync(worldFile, "utf8"));
23152
+ document = JSON.parse(fs43.readFileSync(worldFile, "utf8"));
22558
23153
  } catch {
22559
23154
  throw new CliError(`${worldFile} is not valid JSON`, 1);
22560
23155
  }
@@ -22566,8 +23161,8 @@ function loadWorldConfig(dir) {
22566
23161
  const primaryKey = Array.isArray(entity.primary_key) ? entity.primary_key : [];
22567
23162
  entities[name] = { primaryKey, fields: declaredFields(document, entity.schema) };
22568
23163
  }
22569
- const connectorFile = path30.join(dir, "connector.toml");
22570
- const spec = fs40.existsSync(connectorFile) ? readSpec(connectorFile) : readEnvPolicy(path30.join(dir, "gateway-env.toml"));
23164
+ const connectorFile = path33.join(dir, "connector.toml");
23165
+ const spec = fs43.existsSync(connectorFile) ? readSpec(connectorFile) : readEnvPolicy(path33.join(dir, "gateway-env.toml"));
22571
23166
  return { dir, slug: spec.slug, entities, redact: spec.redact, envelope: spec.envelope, hitsKey: spec.hitsKey, operations: spec.operations };
22572
23167
  }
22573
23168
  function declaredFields(document, schema) {
@@ -22585,7 +23180,7 @@ function declaredFields(document, schema) {
22585
23180
  var NO_SPEC = { slug: null, redact: { hash: [], drop: [], preserve: [], round: {} }, envelope: "", hitsKey: "hits", operations: {} };
22586
23181
  function readToml(file) {
22587
23182
  try {
22588
- return parseToml(fs40.readFileSync(file, "utf8"));
23183
+ return parseToml(fs43.readFileSync(file, "utf8"));
22589
23184
  } catch (error) {
22590
23185
  if (error instanceof TomlError) throw new CliError(`${file}: ${error.message}`, 1);
22591
23186
  throw error;
@@ -22605,7 +23200,7 @@ function readSpec(file) {
22605
23200
  };
22606
23201
  }
22607
23202
  function readEnvPolicy(file) {
22608
- if (!fs40.existsSync(file)) return NO_SPEC;
23203
+ if (!fs43.existsSync(file)) return NO_SPEC;
22609
23204
  const raw = readToml(file);
22610
23205
  if (raw.redact === void 0) return NO_SPEC;
22611
23206
  const name = table3(raw.environment).name;
@@ -22642,24 +23237,24 @@ function rounding(value) {
22642
23237
  }
22643
23238
 
22644
23239
  // src/cli/platform/worldData/treeImport.ts
22645
- var fs42 = __toESM(require("fs"));
23240
+ var fs45 = __toESM(require("fs"));
22646
23241
  var os6 = __toESM(require("os"));
22647
- var path32 = __toESM(require("path"));
23242
+ var path35 = __toESM(require("path"));
22648
23243
  init_config();
22649
23244
  init_router();
22650
23245
  init_hub();
22651
23246
 
22652
23247
  // src/cli/platform/worldData/driveIo.ts
22653
- var fs41 = __toESM(require("fs"));
23248
+ var fs44 = __toESM(require("fs"));
22654
23249
  var os5 = __toESM(require("os"));
22655
- var path31 = __toESM(require("path"));
23250
+ var path34 = __toESM(require("path"));
22656
23251
  init_files();
22657
23252
  init_shared();
22658
23253
  async function stageDriveInputs(inputs, creds) {
22659
23254
  if (!inputs.some(isDriveRef))
22660
23255
  return { files: inputs, labels: {}, cleanup: () => void 0 };
22661
- const scratch = fs41.mkdtempSync(path31.join(os5.tmpdir(), "gateway-drive-in-"));
22662
- const cleanup = () => fs41.rmSync(scratch, { recursive: true, force: true });
23256
+ const scratch = fs44.mkdtempSync(path34.join(os5.tmpdir(), "gateway-drive-in-"));
23257
+ const cleanup = () => fs44.rmSync(scratch, { recursive: true, force: true });
22663
23258
  const labels = {};
22664
23259
  const files = [];
22665
23260
  try {
@@ -22670,7 +23265,7 @@ async function stageDriveInputs(inputs, creds) {
22670
23265
  continue;
22671
23266
  }
22672
23267
  const target = drivePath(input);
22673
- const local = path31.join(scratch, `${index2}-${path31.basename(target)}`);
23268
+ const local = path34.join(scratch, `${index2}-${path34.basename(target)}`);
22674
23269
  await downloadFile(options, target, local);
22675
23270
  labels[local] = `drive:${target}`;
22676
23271
  files.push(local);
@@ -22693,10 +23288,10 @@ async function landInDrive(localFile, to, creds) {
22693
23288
  });
22694
23289
  }
22695
23290
  function scratchFile(name) {
22696
- const dir = fs41.mkdtempSync(path31.join(os5.tmpdir(), "gateway-drive-out-"));
23291
+ const dir = fs44.mkdtempSync(path34.join(os5.tmpdir(), "gateway-drive-out-"));
22697
23292
  return {
22698
- file: path31.join(dir, name),
22699
- cleanup: () => fs41.rmSync(dir, { recursive: true, force: true })
23293
+ file: path34.join(dir, name),
23294
+ cleanup: () => fs44.rmSync(dir, { recursive: true, force: true })
22700
23295
  };
22701
23296
  }
22702
23297
  var TO_FLAG = {
@@ -22739,7 +23334,7 @@ var TreeImport = class _TreeImport {
22739
23334
  /** The platform slug this directory would import into: its pulled metadata, else its name. */
22740
23335
  get slug() {
22741
23336
  const slug = readLocalMeta(this.dir)?.slug;
22742
- return typeof slug === "string" && slug ? slug : path32.basename(path32.resolve(this.dir));
23337
+ return typeof slug === "string" && slug ? slug : path35.basename(path35.resolve(this.dir));
22743
23338
  }
22744
23339
  /** Import (or, `dryRun`, prove) the files; prints the report `data check` prints; the exit code. */
22745
23340
  async run(dryRun) {
@@ -22812,7 +23407,7 @@ var TreeImport = class _TreeImport {
22812
23407
  `${what} across ${paths.length} file(s) exceed the inline cap (${INLINE_ROWS} rows / ${INLINE_BYTES} bytes) a directory takes at once without the bundled runtime; install python3 (the runtime then streams the files in place, 4 MiB / 100000 rows), split the rows into smaller files, or import into the platform world \`${this.slug}\` (\`gateway worlds data import ${this.slug} <rows>\`), which streams them`,
22813
23408
  1
22814
23409
  );
22815
- const size = paths.reduce((n, p) => n + fs42.statSync(p).size, 0);
23410
+ const size = paths.reduce((n, p) => n + fs45.statSync(p).size, 0);
22816
23411
  if (size > INLINE_BYTES) throw tooLarge(`${size} bytes`);
22817
23412
  let count = 0;
22818
23413
  for await (const _ of readRows(paths.map(fileInput), this.entity))
@@ -22835,7 +23430,7 @@ var TreeImport = class _TreeImport {
22835
23430
  return 2;
22836
23431
  }
22837
23432
  write(report) {
22838
- if (this.report !== void 0) fs42.writeFileSync(this.report, report);
23433
+ if (this.report !== void 0) fs45.writeFileSync(this.report, report);
22839
23434
  }
22840
23435
  };
22841
23436
  var StagedPaths = class {
@@ -22848,13 +23443,13 @@ var StagedPaths = class {
22848
23443
  async stage(ctx) {
22849
23444
  for (const file of this.files) {
22850
23445
  if (file === "-") {
22851
- this.scratch ??= fs42.mkdtempSync(path32.join(os6.tmpdir(), "gateway-stdin-"));
22852
- const stdin = path32.join(this.scratch, "stdin.rows");
22853
- fs42.writeFileSync(stdin, await ctx.stdin());
23446
+ this.scratch ??= fs45.mkdtempSync(path35.join(os6.tmpdir(), "gateway-stdin-"));
23447
+ const stdin = path35.join(this.scratch, "stdin.rows");
23448
+ fs45.writeFileSync(stdin, await ctx.stdin());
22854
23449
  this.list.push(stdin);
22855
23450
  continue;
22856
23451
  }
22857
- if (!fs42.existsSync(file) || !fs42.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
23452
+ if (!fs45.existsSync(file) || !fs45.statSync(file).isFile()) throw new CliError(`Cannot read ${file}`, 1);
22858
23453
  this.list.push(file);
22859
23454
  }
22860
23455
  }
@@ -22869,7 +23464,7 @@ var StagedPaths = class {
22869
23464
  return total;
22870
23465
  }
22871
23466
  dispose() {
22872
- if (this.scratch) fs42.rmSync(this.scratch, { recursive: true, force: true });
23467
+ if (this.scratch) fs45.rmSync(this.scratch, { recursive: true, force: true });
22873
23468
  }
22874
23469
  };
22875
23470
  function refusalsFromBridge(detail) {
@@ -22965,13 +23560,13 @@ async function rowsOrRefuse(source2, files) {
22965
23560
  yield* source2;
22966
23561
  })();
22967
23562
  }
22968
- async function stageDriveChunks(client4, batchId, drive, entity, manifest, progress) {
22969
- for (const [ordinal, path44] of drive.entries()) {
22970
- const entry = await client4.stageDrive(batchId, { ordinal, path: path44, entity });
23563
+ async function stageDriveChunks(client5, batchId, drive, entity, manifest, progress) {
23564
+ for (const [ordinal, path49] of drive.entries()) {
23565
+ const entry = await client5.stageDrive(batchId, { ordinal, path: path49, entity });
22971
23566
  recordChunk(manifest, entry);
22972
23567
  writeManifest(manifest);
22973
23568
  progress(
22974
- `chunk ${ordinal}: drive:${path44} staged on the platform, ${entry.bytes} bytes (${entry.chunkId})`
23569
+ `chunk ${ordinal}: drive:${path49} staged on the platform, ${entry.bytes} bytes (${entry.chunkId})`
22975
23570
  );
22976
23571
  }
22977
23572
  return drive.length;
@@ -23230,7 +23825,7 @@ primary key, the world's [redact] policy applied. Summary on stderr:
23230
23825
  const file = local ?? scratch?.file ?? null;
23231
23826
  try {
23232
23827
  const input = source2 === "-" ? stdinInput(ctx) : fileInput(staged.files[0]);
23233
- const sink = file ? fs43.createWriteStream(file) : null;
23828
+ const sink = file ? fs46.createWriteStream(file) : null;
23234
23829
  const write = sink ? (line) => void sink.write(line + "\n") : (line) => ctx.stdout(line);
23235
23830
  const summary2 = await extractRows(
23236
23831
  input,
@@ -23245,8 +23840,8 @@ primary key, the world's [redact] policy applied. Summary on stderr:
23245
23840
  );
23246
23841
  if (sink)
23247
23842
  await new Promise(
23248
- (resolve29, reject) => sink.end(
23249
- (error) => error ? reject(error) : resolve29()
23843
+ (resolve32, reject) => sink.end(
23844
+ (error) => error ? reject(error) : resolve32()
23250
23845
  )
23251
23846
  );
23252
23847
  if (Object.keys(staged.labels).length)
@@ -23704,7 +24299,7 @@ function rowInputs(files, ctx) {
23704
24299
  if (files.filter((f) => f === "-").length > 1)
23705
24300
  throw new CliError("stdin (-) can be read once");
23706
24301
  for (const file of files) {
23707
- if (file !== "-" && !(fs43.existsSync(file) && fs43.statSync(file).isFile()))
24302
+ if (file !== "-" && !(fs46.existsSync(file) && fs46.statSync(file).isFile()))
23708
24303
  throw new CliError(`Cannot read ${file}`, 1);
23709
24304
  }
23710
24305
  return files.map((f) => f === "-" ? stdinInput(ctx) : fileInput(f));
@@ -23728,7 +24323,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
23728
24323
  const named2 = inputLabels(files, labels);
23729
24324
  const creds = credentials(args);
23730
24325
  const flags = importFlags(args, purpose);
23731
- const client4 = new WorldDataApi(creds, slug);
24326
+ const client5 = new WorldDataApi(creds, slug);
23732
24327
  const progress = (line) => {
23733
24328
  if (showProgress()) ctx.stderr(line);
23734
24329
  };
@@ -23760,7 +24355,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
23760
24355
  );
23761
24356
  let manifest;
23762
24357
  if (resumable) {
23763
- const status2 = await client4.get(resumable.batchId);
24358
+ const status2 = await client5.get(resumable.batchId);
23764
24359
  if (status2.state !== "open" && status2.state !== "uploading")
23765
24360
  throw new CliError(
23766
24361
  `batch ${resumable.batchId} is ${status2.state}; only an open or uploading batch resumes`,
@@ -23771,7 +24366,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
23771
24366
  `resuming batch ${manifest.batchId} (${manifest.chunks.length} chunks recorded)`
23772
24367
  );
23773
24368
  } else {
23774
- const opened = await client4.open({
24369
+ const opened = await client5.open({
23775
24370
  mode: plan.mode,
23776
24371
  merge: plan.merge,
23777
24372
  ...plan.redact && plan.redact !== "off" ? { redact: plan.redact } : {},
@@ -23803,7 +24398,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
23803
24398
  }
23804
24399
  const batchId = manifest.batchId;
23805
24400
  const staged = await stageDriveChunks(
23806
- client4,
24401
+ client5,
23807
24402
  batchId,
23808
24403
  drive,
23809
24404
  plan.entity,
@@ -23824,14 +24419,14 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
23824
24419
  progress(`chunk ${chunk.ordinal}: already uploaded (${chunk.rows} rows)`);
23825
24420
  return;
23826
24421
  }
23827
- const entry = await client4.upload(batchId, chunk);
24422
+ const entry = await client5.upload(batchId, chunk);
23828
24423
  recordChunk(manifest, entry);
23829
24424
  writeManifest(manifest);
23830
24425
  progress(
23831
24426
  `chunk ${chunk.ordinal}: uploaded ${chunk.rows} rows, ${chunk.bytes} bytes (${entry.chunkId})`
23832
24427
  );
23833
24428
  });
23834
- await client4.complete(batchId);
24429
+ await client5.complete(batchId);
23835
24430
  manifest.completed = true;
23836
24431
  writeManifest(manifest);
23837
24432
  progress(`batch ${batchId} complete: ${manifest.chunks.length} chunks`);
@@ -23840,7 +24435,7 @@ async function importBatch(world, files, args, ctx, purpose, onStatus, labels =
23840
24435
  else ctx.stdout(JSON.stringify({ batchId, state: "queued" }));
23841
24436
  return 0;
23842
24437
  }
23843
- const status = await waitForBatch(client4, batchId, {
24438
+ const status = await waitForBatch(client5, batchId, {
23844
24439
  onPhase: (line) => progress(line),
23845
24440
  initialDelayMs: pollMs2()
23846
24441
  });
@@ -23967,11 +24562,11 @@ async function pullCalls(out, to, from, staged, args, ctx) {
23967
24562
  const toStdout = out === "-";
23968
24563
  if (toStdout) {
23969
24564
  if (text2) process.stdout.write(text2);
23970
- } else if (out) fs43.writeFileSync(out, text2);
24565
+ } else if (out) fs46.writeFileSync(out, text2);
23971
24566
  let landed;
23972
24567
  if (to) {
23973
24568
  const scratch = out && !toStdout ? null : scratchFile("calls.jsonl");
23974
- if (scratch) fs43.writeFileSync(scratch.file, text2);
24569
+ if (scratch) fs46.writeFileSync(scratch.file, text2);
23975
24570
  try {
23976
24571
  landed = `drive:${(await landInDrive(scratch?.file ?? out, to, credentials(args))).path}`;
23977
24572
  } finally {
@@ -24028,20 +24623,20 @@ async function mapInitCommand(world, samples, args, ctx) {
24028
24623
  delimiter: delimiterFlag(args) ?? void 0
24029
24624
  });
24030
24625
  const text2 = skeleton(records2, config.entities, kind, {
24031
- sampleName: samples.map((f) => path33.basename(f)).join(", "),
24626
+ sampleName: samples.map((f) => path36.basename(f)).join(", "),
24032
24627
  entity: arg.str(args, "entity")
24033
24628
  });
24034
- const out = arg.str(args, "out") ?? (local ? path33.join(world, MAP_FILE) : "-");
24629
+ const out = arg.str(args, "out") ?? (local ? path36.join(world, MAP_FILE) : "-");
24035
24630
  if (out === "-") {
24036
24631
  ctx.stdout(text2.replace(/\n$/, ""));
24037
24632
  return 0;
24038
24633
  }
24039
- if (fs43.existsSync(out) && !arg.bool(args, "dry-run"))
24634
+ if (fs46.existsSync(out) && !arg.bool(args, "dry-run"))
24040
24635
  throw new CliError(
24041
24636
  `${out} exists; pass --out for another path, or move it first`,
24042
24637
  1
24043
24638
  );
24044
- fs43.writeFileSync(out, text2);
24639
+ fs46.writeFileSync(out, text2);
24045
24640
  const fromFlag = from === "tool-calls" ? "" : ` --from ${from}`;
24046
24641
  ctx.stderr(
24047
24642
  `wrote ${out}: fill in the entity and fields, then run \`gateway worlds data ingest ${world} ${samples[0]}${fromFlag} --map ${out} --dry-run\``
@@ -24269,12 +24864,12 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
24269
24864
  const full = out;
24270
24865
  let code = full.refusals.length ? 2 : 0;
24271
24866
  if (!local && !dryRun && !full.refusals.length && Object.keys(projected).length) {
24272
- const scratch = fs43.mkdtempSync(
24273
- path33.join(os7.tmpdir(), "gateway-ingest-rows-")
24867
+ const scratch = fs46.mkdtempSync(
24868
+ path36.join(os7.tmpdir(), "gateway-ingest-rows-")
24274
24869
  );
24275
24870
  try {
24276
- const rowsFile = path33.join(scratch, "rows.json");
24277
- fs43.writeFileSync(rowsFile, JSON.stringify(projected));
24871
+ const rowsFile = path36.join(scratch, "rows.json");
24872
+ fs46.writeFileSync(rowsFile, JSON.stringify(projected));
24278
24873
  code = await importBatch(
24279
24874
  world,
24280
24875
  [rowsFile],
@@ -24289,11 +24884,11 @@ async function ingestCommand(world, inputs, args, ctx, labels = {}) {
24289
24884
  }
24290
24885
  );
24291
24886
  } finally {
24292
- fs43.rmSync(scratch, { recursive: true, force: true });
24887
+ fs46.rmSync(scratch, { recursive: true, force: true });
24293
24888
  }
24294
24889
  }
24295
24890
  if (reportFile !== void 0)
24296
- fs43.writeFileSync(
24891
+ fs46.writeFileSync(
24297
24892
  reportFile,
24298
24893
  full.refusals.map((r) => JSON.stringify(r) + "\n").join("")
24299
24894
  );
@@ -24350,8 +24945,8 @@ function renderSource(source2, ctx) {
24350
24945
  ctx.stdout(` ${entity} fields never set: ${fields.join(", ")}`);
24351
24946
  }
24352
24947
  async function pullWorld(slugRef, creds) {
24353
- const target = path33.join(
24354
- fs43.mkdtempSync(path33.join(os7.tmpdir(), "gateway-world-data-")),
24948
+ const target = path36.join(
24949
+ fs46.mkdtempSync(path36.join(os7.tmpdir(), "gateway-world-data-")),
24355
24950
  slugOf(slugRef)
24356
24951
  );
24357
24952
  const pulled = await pull(slugRef, target, worldsOptions(creds));
@@ -24359,20 +24954,20 @@ async function pullWorld(slugRef, creds) {
24359
24954
  }
24360
24955
 
24361
24956
  // src/cli/platform/dataset.ts
24362
- var fs44 = __toESM(require("fs"));
24363
- var path34 = __toESM(require("path"));
24957
+ var fs47 = __toESM(require("fs"));
24958
+ var path37 = __toESM(require("path"));
24364
24959
  init_config();
24365
24960
  init_router();
24366
24961
  init_shared();
24367
24962
  function readDatasetItems(file) {
24368
- const raw = fs44.readFileSync(file, "utf8").trim();
24369
- const looksJson = path34.extname(file) === ".json" || raw.startsWith("{") || raw.startsWith("[");
24963
+ const raw = fs47.readFileSync(file, "utf8").trim();
24964
+ const looksJson = path37.extname(file) === ".json" || raw.startsWith("{") || raw.startsWith("[");
24370
24965
  if (looksJson) {
24371
24966
  let data;
24372
24967
  try {
24373
24968
  data = JSON.parse(raw);
24374
24969
  } catch (error) {
24375
- if (path34.extname(file) === ".json") throw error;
24970
+ if (path37.extname(file) === ".json") throw error;
24376
24971
  data = void 0;
24377
24972
  }
24378
24973
  if (data !== void 0) {
@@ -24410,10 +25005,10 @@ function registerDatasetCommands(root) {
24410
25005
  const file = args.positionals[0];
24411
25006
  const name = arg.str(args, "name");
24412
25007
  if (!name) throw new CliError("dataset upload needs --name");
24413
- if (!fs44.existsSync(file)) throw new CliError(`Error: File not found: ${file}`, 1);
25008
+ if (!fs47.existsSync(file)) throw new CliError(`Error: File not found: ${file}`, 1);
24414
25009
  const items = readDatasetItems(file);
24415
25010
  if (items.length === 0) throw new CliError("Error: No items found in file.", 1);
24416
- ctx.stdout(`Found ${items.length} items in ${path34.basename(file)}`);
25011
+ ctx.stdout(`Found ${items.length} items in ${path37.basename(file)}`);
24417
25012
  const creds = credentials(args);
24418
25013
  const agent = arg.str(args, "agent");
24419
25014
  if (agent) {
@@ -24445,8 +25040,8 @@ function registerDatasetCommands(root) {
24445
25040
  }
24446
25041
 
24447
25042
  // src/cli/platform/files.ts
24448
- var fs45 = __toESM(require("fs"));
24449
- var path35 = __toESM(require("path"));
25043
+ var fs48 = __toESM(require("fs"));
25044
+ var path38 = __toESM(require("path"));
24450
25045
  init_config();
24451
25046
  init_router();
24452
25047
  init_files();
@@ -24526,7 +25121,7 @@ function registerFilesCommands(root) {
24526
25121
  flags: [{ name: "out", help: "Local path to write (default the file's own name in the working directory)." }, HOST_FLAG],
24527
25122
  run: async (args, ctx) => {
24528
25123
  const target = drivePath(args.positionals[0]);
24529
- const out = arg.str(args, "out") ?? path35.basename(target);
25124
+ const out = arg.str(args, "out") ?? path38.basename(target);
24530
25125
  const result = await downloadFile(worldsOptions(credentials(args)), target, out, progressReporter(ctx, `drive:${target}`));
24531
25126
  ctx.stdout(`drive:${result.path} -> ${out} (${result.sizeBytes ?? "?"} bytes)`);
24532
25127
  }
@@ -24635,26 +25230,26 @@ function registerFilesCommands(root) {
24635
25230
  }
24636
25231
  function planUploads(inputs, to) {
24637
25232
  const base = to ? drivePath(to).replace(/\/+$/, "") : "";
24638
- const join33 = (...parts2) => parts2.filter(Boolean).join("/");
25233
+ const join37 = (...parts2) => parts2.filter(Boolean).join("/");
24639
25234
  const plan = [];
24640
25235
  for (const input of inputs) {
24641
- if (!fs45.existsSync(input)) throw new CliError(`${input} does not exist`, 1);
24642
- if (fs45.statSync(input).isDirectory()) {
24643
- const root = path35.resolve(input);
24644
- for (const file of walk2(root)) plan.push({ local: file, path: join33(base, path35.basename(root), path35.relative(root, file).split(path35.sep).join("/")) });
25236
+ if (!fs48.existsSync(input)) throw new CliError(`${input} does not exist`, 1);
25237
+ if (fs48.statSync(input).isDirectory()) {
25238
+ const root = path38.resolve(input);
25239
+ for (const file of walk2(root)) plan.push({ local: file, path: join37(base, path38.basename(root), path38.relative(root, file).split(path38.sep).join("/")) });
24645
25240
  continue;
24646
25241
  }
24647
- const oneFileNamedInFull = inputs.length === 1 && base !== "" && !to.endsWith("/") && path35.extname(base) !== "";
24648
- plan.push({ local: input, path: oneFileNamedInFull ? base : join33(base, path35.basename(input)) });
25242
+ const oneFileNamedInFull = inputs.length === 1 && base !== "" && !to.endsWith("/") && path38.extname(base) !== "";
25243
+ plan.push({ local: input, path: oneFileNamedInFull ? base : join37(base, path38.basename(input)) });
24649
25244
  }
24650
25245
  if (!plan.length) throw new CliError("nothing to upload: the directories are empty", 1);
24651
25246
  return plan;
24652
25247
  }
24653
25248
  function walk2(dir) {
24654
25249
  const out = [];
24655
- for (const entry of fs45.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
25250
+ for (const entry of fs48.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
24656
25251
  if (entry.name.startsWith(".")) continue;
24657
- const full = path35.join(dir, entry.name);
25252
+ const full = path38.join(dir, entry.name);
24658
25253
  if (entry.isDirectory()) out.push(...walk2(full));
24659
25254
  else if (entry.isFile()) out.push(full);
24660
25255
  }
@@ -25066,22 +25661,23 @@ function registerSecretCommands(root) {
25066
25661
  }
25067
25662
 
25068
25663
  // src/cli/platform/session.ts
25069
- var fs49 = __toESM(require("fs"));
25664
+ var fs52 = __toESM(require("fs"));
25070
25665
  init_config();
25071
25666
  init_router();
25072
25667
  init_worlds();
25668
+ init_surfaceDescriptor();
25073
25669
  init_shared();
25074
25670
 
25075
25671
  // src/cli/platform/task.ts
25076
- var fs48 = __toESM(require("fs"));
25077
- var path37 = __toESM(require("path"));
25672
+ var fs51 = __toESM(require("fs"));
25673
+ var path40 = __toESM(require("path"));
25078
25674
  var import_node_url3 = require("url");
25079
25675
  init_config();
25080
25676
  init_router();
25081
25677
 
25082
25678
  // src/cli/runtime/run.ts
25083
- var fs46 = __toESM(require("fs"));
25084
- var path36 = __toESM(require("path"));
25679
+ var fs49 = __toESM(require("fs"));
25680
+ var path39 = __toESM(require("path"));
25085
25681
  var import_node_url2 = require("url");
25086
25682
  init_router();
25087
25683
  init_config();
@@ -25158,9 +25754,9 @@ var toOptions = (creds) => ({
25158
25754
  secretKey: creds.secretKey
25159
25755
  });
25160
25756
  async function loadAgent(file) {
25161
- const abs = path36.resolve(file);
25162
- if (!fs46.existsSync(abs)) throw new CliError(`--agent ${file} does not exist`);
25163
- const ext = path36.extname(abs);
25757
+ const abs = path39.resolve(file);
25758
+ if (!fs49.existsSync(abs)) throw new CliError(`--agent ${file} does not exist`);
25759
+ const ext = path39.extname(abs);
25164
25760
  if (ext === ".ts" || ext === ".mts" || ext === ".cts")
25165
25761
  await registerTypeScriptLoader(abs);
25166
25762
  else if (![".js", ".mjs", ".cjs"].includes(ext))
@@ -25204,11 +25800,11 @@ async function registerTypeScriptLoader(agentPath) {
25204
25800
  );
25205
25801
  }
25206
25802
  function resolveTarget(target, versionFlag) {
25207
- if (fs46.existsSync(target) && fs46.statSync(target).isDirectory()) {
25208
- const dir = path36.resolve(target);
25803
+ if (fs49.existsSync(target) && fs49.statSync(target).isDirectory()) {
25804
+ const dir = path39.resolve(target);
25209
25805
  const meta = readLocalMeta(dir);
25210
25806
  return {
25211
- slug: meta?.slug ?? path36.basename(dir),
25807
+ slug: meta?.slug ?? path39.basename(dir),
25212
25808
  ref: meta?.branch ?? null,
25213
25809
  versionId: versionFlag ?? meta?.versionId ?? null,
25214
25810
  dir
@@ -25231,10 +25827,10 @@ function openTargetWorld(target, options) {
25231
25827
  );
25232
25828
  }
25233
25829
  async function resolveTasks(target, args, creds) {
25234
- const one = arg.str(args, "task");
25830
+ const one2 = arg.str(args, "task");
25235
25831
  const all = arg.bool(args, "all");
25236
- if (!one && !all) throw new CliError("pass --task <name> or --all");
25237
- const pinned = one && !all ? [one] : null;
25832
+ if (!one2 && !all) throw new CliError("pass --task <name> or --all");
25833
+ const pinned = one2 && !all ? [one2] : null;
25238
25834
  if (pinned && (target.versionId || !target.ref))
25239
25835
  return { tasks: pinned, versionId: target.versionId };
25240
25836
  const world = await openTargetWorld(target, toOptions(creds));
@@ -25349,7 +25945,7 @@ function writeStepSummary(title, rows) {
25349
25945
  ...rows.map(([k, v]) => `| ${k} | ${v} |`)
25350
25946
  ];
25351
25947
  try {
25352
- fs46.appendFileSync(summaryPath, lines.join("\n") + "\n\n");
25948
+ fs49.appendFileSync(summaryPath, lines.join("\n") + "\n\n");
25353
25949
  } catch {
25354
25950
  }
25355
25951
  }
@@ -25438,8 +26034,8 @@ function registerRunCommands2(worlds) {
25438
26034
  }
25439
26035
  ],
25440
26036
  run: async (args, ctx) => {
25441
- const dir = path36.resolve(args.positionals[0]);
25442
- if (!fs46.existsSync(dir) || !fs46.statSync(dir).isDirectory())
26037
+ const dir = path39.resolve(args.positionals[0]);
26038
+ if (!fs49.existsSync(dir) || !fs49.statSync(dir).isDirectory())
25443
26039
  throw new CliError(`path is not a directory: ${args.positionals[0]}`);
25444
26040
  const agentFile = arg.str(args, "agent");
25445
26041
  const runConfig = arg.str(args, "run-config");
@@ -25478,14 +26074,14 @@ function registerRunCommands2(worlds) {
25478
26074
  const { markdown, ...summary3 } = report;
25479
26075
  ctx.stdout(JSON.stringify(summary3, null, 2));
25480
26076
  if (summaryFile)
25481
- fs46.writeFileSync(
26077
+ fs49.writeFileSync(
25482
26078
  summaryFile,
25483
26079
  JSON.stringify(summary3, null, 2) + "\n"
25484
26080
  );
25485
26081
  const stepSummary2 = process.env.GITHUB_STEP_SUMMARY;
25486
26082
  if (stepSummary2) {
25487
26083
  try {
25488
- fs46.appendFileSync(stepSummary2, markdown + "\n\n");
26084
+ fs49.appendFileSync(stepSummary2, markdown + "\n\n");
25489
26085
  } catch {
25490
26086
  }
25491
26087
  }
@@ -25536,7 +26132,7 @@ function registerRunCommands2(worlds) {
25536
26132
  const out = { ...summary2, branch, contentHash: pushed.contentHash };
25537
26133
  ctx.stdout(JSON.stringify(out, null, 2));
25538
26134
  if (summaryFile)
25539
- fs46.writeFileSync(summaryFile, JSON.stringify(out, null, 2) + "\n");
26135
+ fs49.writeFileSync(summaryFile, JSON.stringify(out, null, 2) + "\n");
25540
26136
  const rows = [
25541
26137
  ["avg reward", summary2.mean === null ? "n/a" : summary2.mean.toFixed(3)],
25542
26138
  ["tasks", String(summary2.results.length)],
@@ -25562,7 +26158,7 @@ init_worlds();
25562
26158
  init_shared();
25563
26159
 
25564
26160
  // src/cli/platform/taskSpec.ts
25565
- var fs47 = __toESM(require("fs"));
26161
+ var fs50 = __toESM(require("fs"));
25566
26162
  init_router();
25567
26163
  var TASK_SPEC_HELP = 'A task spec is JSON:\n {"instruction": "<what the agent is told>",\n "name": "<optional>",\n "seed": {"mode": "append|replace", "rows": {"<entity>": [{...row}, ...]}}, # rows go UNDER seed.rows\n "grader": {"kind": "assertions", "checks": [{"entity": "<entity>", "where": {"<field>": <scalar>},\n "assert": "exists|absent|count|all|any",\n "count": {"eq"|"gte"|"lte": <n>}, # assert: count\n "field": "<field>", "op": "eq|neq|in|gt|gte|lt|lte|contains", "value": <scalar>}]} # assert: all|any\n | {"kind": "python", "source": "<verify.py body>", "timeoutSeconds"?: <n>}\n | {"kind": "rubric", "rubric": "<what the judge looks for>", "criteria"?: [{"id", "description", "weight"?}]},\n "tools": ["<tool>", ...], # optional allow-list\n "metadata": {...}, # optional, echoed back\n "worlds": {"<alias>": {"slug": "<world>", "ref"?: "<branch|tag|version id>", "seed"?, "grader"?, "tools"?}}, # multi-world: one session per alias\n "verifiers": [{"name": "<name>", "scope": ["<alias>", "<alias>", ...], "kind": "assertions|python", "checks"|"source": ...}]} # cross-world: entities as <alias>.<entity>, call logs as <alias>.calls\nWithout seed the session starts on the version\'s base data; without grader `grade` answers reward: null.\nWith worlds, seed/grader/tools live under each alias (not at the top level) and `worlds task up` opens the sessions.\nWithout worlds, a verifier runs on the session named by its first scope alias, so "name" must be that alias.';
25568
26164
  var SPEC_KEYS = /* @__PURE__ */ new Set([
@@ -25846,7 +26442,7 @@ function taskSpecIssues(spec) {
25846
26442
  function readTaskSpec(file, flag = "--spec") {
25847
26443
  let parsed;
25848
26444
  try {
25849
- parsed = JSON.parse(fs47.readFileSync(file, "utf8"));
26445
+ parsed = JSON.parse(fs50.readFileSync(file, "utf8"));
25850
26446
  } catch (error) {
25851
26447
  throw new CliError(
25852
26448
  `${flag} ${file}: ${error instanceof Error ? error.message : String(error)}`
@@ -25895,9 +26491,9 @@ async function loadTaskAgent(spec) {
25895
26491
  const hash = spec.indexOf("#");
25896
26492
  const file = hash === -1 ? spec : spec.slice(0, hash);
25897
26493
  const exportName = hash === -1 ? void 0 : spec.slice(hash + 1);
25898
- const abs = path37.resolve(file);
25899
- if (!fs48.existsSync(abs)) throw new CliError(`--agent ${spec} does not exist`);
25900
- const ext = path37.extname(abs);
26494
+ const abs = path40.resolve(file);
26495
+ if (!fs51.existsSync(abs)) throw new CliError(`--agent ${spec} does not exist`);
26496
+ const ext = path40.extname(abs);
25901
26497
  if (ext === ".ts" || ext === ".mts" || ext === ".cts")
25902
26498
  await registerTypeScriptLoader(abs);
25903
26499
  else if (![".js", ".mjs", ".cjs"].includes(ext))
@@ -25922,7 +26518,7 @@ function worldFromFlags(world, noWorld) {
25922
26518
  }
25923
26519
  function readJsonFile(file, what) {
25924
26520
  try {
25925
- return JSON.parse(fs48.readFileSync(file, "utf8"));
26521
+ return JSON.parse(fs51.readFileSync(file, "utf8"));
25926
26522
  } catch (error) {
25927
26523
  throw new CliError(
25928
26524
  `${what} ${file}: ${error instanceof Error ? error.message : String(error)}`
@@ -25930,7 +26526,7 @@ function readJsonFile(file, what) {
25930
26526
  }
25931
26527
  }
25932
26528
  function taskTarget(positional) {
25933
- if (!fs48.existsSync(positional)) return { kind: "id", taskId: positional };
26529
+ if (!fs51.existsSync(positional)) return { kind: "id", taskId: positional };
25934
26530
  const parsed = readJsonFile(positional, "task");
25935
26531
  if (isTaskManifest(parsed)) return { kind: "manifest", manifest: parsed };
25936
26532
  if (parsed && typeof parsed === "object" && typeof parsed.instruction === "string")
@@ -25947,12 +26543,12 @@ async function attachTarget(target, options) {
25947
26543
  "a spec file has no sessions to act on; pass the task id or the manifest `task up` printed"
25948
26544
  );
25949
26545
  }
25950
- var TARGET_POSITIONAL = {
26546
+ var TARGET_POSITIONAL2 = {
25951
26547
  name: "task",
25952
26548
  help: "Task id, or the manifest file `task up --out` wrote."
25953
26549
  };
25954
26550
  function emitManifest(ctx, manifest, out) {
25955
- if (out) fs48.writeFileSync(out, JSON.stringify(manifest, null, 2) + "\n");
26551
+ if (out) fs51.writeFileSync(out, JSON.stringify(manifest, null, 2) + "\n");
25956
26552
  printJson(ctx, manifest);
25957
26553
  if (out) ctx.stderr(`wrote the manifest to ${out}`);
25958
26554
  }
@@ -26244,7 +26840,7 @@ function registerTaskCommands(root) {
26244
26840
  task.command({
26245
26841
  name: "down",
26246
26842
  help: "Close every session of a task.",
26247
- positionals: [TARGET_POSITIONAL],
26843
+ positionals: [TARGET_POSITIONAL2],
26248
26844
  flags: [
26249
26845
  {
26250
26846
  name: "keep-warm",
@@ -26303,7 +26899,7 @@ function registerTaskCommands(root) {
26303
26899
  name: "status",
26304
26900
  output: "json",
26305
26901
  help: "Where every world of a task answers, and whether each is ready.",
26306
- positionals: [TARGET_POSITIONAL],
26902
+ positionals: [TARGET_POSITIONAL2],
26307
26903
  flags: [HOST_FLAG],
26308
26904
  notes: "Prints the same manifest `task up` did, read back from the platform. With a task id, lists that stored task's live\nsessions; an alias that is up twice is refused \u2014 pass the manifest.",
26309
26905
  run: async (args, ctx) => {
@@ -26323,7 +26919,7 @@ function registerTaskCommands(root) {
26323
26919
  task.command({
26324
26920
  name: "grade",
26325
26921
  help: "Grade every world of a task; prints per-world rewards and the aggregate.",
26326
- positionals: [TARGET_POSITIONAL],
26922
+ positionals: [TARGET_POSITIONAL2],
26327
26923
  flags: [
26328
26924
  {
26329
26925
  name: "timeout",
@@ -26346,20 +26942,32 @@ function registerTaskCommands(root) {
26346
26942
  });
26347
26943
  task.command({
26348
26944
  name: "export",
26349
- help: "Every world's call log as JSONL, one {world, seq, kind, tool, args, result, error, completedAt} per line.",
26350
- positionals: [TARGET_POSITIONAL],
26945
+ help: "Every world's call ledger as JSONL, one {world, seq, kind, tool, args, result, error, completedAt} per line; --requests appends each world's own request log.",
26946
+ positionals: [TARGET_POSITIONAL2],
26351
26947
  flags: [
26352
26948
  { name: "out", help: "Write the JSONL here instead of stdout." },
26949
+ {
26950
+ name: "requests",
26951
+ help: 'Also append the world\'s own request log (kind "request"), read from the live session with one `state` call.',
26952
+ boolean: true
26953
+ },
26353
26954
  HOST_FLAG
26354
26955
  ],
26355
- notes: "Each line carries `world`, the alias whose session it came from; within a world, oldest first. The same records\n`session export` writes, prefixed so one file holds the whole task.",
26956
+ notes: "Each line carries `world`, the alias whose session it came from; within a world, oldest first. The same records\n`session export` writes, prefixed so one file holds the whole task.\n" + REQUEST_LOG_NOTES,
26356
26957
  run: async (args, ctx) => {
26357
26958
  const live = await attachTarget(
26358
26959
  taskTarget(args.positionals[0]),
26359
26960
  worldsOptions(credentials(args))
26360
26961
  );
26361
26962
  const exported = await live.export();
26963
+ const wanted = arg.bool(args, "requests");
26362
26964
  const lines = [];
26965
+ let requests = 0;
26966
+ for (const [alias, session] of Object.entries(live.sessions)) {
26967
+ const logged = wanted ? await requestLines(session, ctx, alias) : [];
26968
+ requests += logged.length;
26969
+ exported[alias] = [...exported[alias] ?? [], ...logged];
26970
+ }
26363
26971
  for (const [alias, calls] of Object.entries(exported))
26364
26972
  for (const call3 of calls)
26365
26973
  lines.push(
@@ -26377,9 +26985,9 @@ function registerTaskCommands(root) {
26377
26985
  const text2 = lines.join("\n") + (lines.length ? "\n" : "");
26378
26986
  const out = arg.str(args, "out");
26379
26987
  if (out) {
26380
- fs48.writeFileSync(out, text2);
26988
+ fs51.writeFileSync(out, text2);
26381
26989
  ctx.stdout(
26382
- `wrote ${lines.length} calls from ${Object.keys(exported).length} worlds to ${out}`
26990
+ `wrote ${lines.length - requests} calls${wanted ? ` and ${requests} requests` : ""} from ${Object.keys(exported).length} worlds to ${out}`
26383
26991
  );
26384
26992
  } else if (text2) process.stdout.write(text2);
26385
26993
  }
@@ -26540,30 +27148,9 @@ var EXPORT_KEYS = [
26540
27148
  "tool"
26541
27149
  ];
26542
27150
  async function surfacesJson(session) {
26543
- const s = await session.surfaces();
26544
27151
  return {
26545
27152
  sessionId: session.sessionId,
26546
- surfaces: surfaceKinds(s),
26547
- ...s.api ? {
26548
- api: {
26549
- url: s.api.url,
26550
- ...s.api.token ? { token: s.api.token } : {}
26551
- }
26552
- } : {},
26553
- ...s.ui ? {
26554
- ui: {
26555
- url: s.ui.url,
26556
- entry: uiEntryUrl(s.ui),
26557
- apiPath: s.ui.apiPath ?? null
26558
- }
26559
- } : {},
26560
- ...s.browser ? {
26561
- browser: {
26562
- wsUrl: s.browser.wsUrl,
26563
- viewport: s.browser.viewport,
26564
- ...s.browser.tier ? { tier: s.browser.tier } : {}
26565
- }
26566
- } : {}
27153
+ ...surfaceDescriptor(await session.surfaces())
26567
27154
  };
26568
27155
  }
26569
27156
  var sessionRoute = (id) => `/api/public/world-sessions/${encodeURIComponent(id)}`;
@@ -26764,7 +27351,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
26764
27351
  });
26765
27352
  session.command({
26766
27353
  name: "list",
26767
- help: "The project's live sessions, newest first \u2014 find one to attach to. One line each: id, state, world, task, last used. A batch run's shard containers are not sessions and never appear.",
27354
+ help: "The project's sessions in every state, from provisioning to stopped, newest first \u2014 find one to attach to. The live ones are RUNNING and IDLE (`--state RUNNING`, `--state IDLE`). One line each: id, state, world, task, last used. A batch run's shard containers are not sessions and never appear.",
26768
27355
  flags: [
26769
27356
  {
26770
27357
  name: "state",
@@ -26788,7 +27375,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
26788
27375
  ctx,
26789
27376
  args,
26790
27377
  { sessions },
26791
- () => sessions.length === 0 ? ["No live sessions. Open one with `gateway worlds session open <slug>`."] : sessions.map(
27378
+ () => sessions.length === 0 ? ["No sessions. Open one with `gateway worlds session open <slug>`."] : sessions.map(
26792
27379
  (s) => `${s.sessionId} ${s.state.padEnd(12)} ${s.slug} task=${s.taskName ?? "-"} lastUsed=${s.lastUsedAt}`
26793
27380
  )
26794
27381
  );
@@ -26820,7 +27407,7 @@ source (bundled|stored|inline|none)/name/hash/id/version.
26820
27407
  try {
26821
27408
  const url = await browser.goto(arg.str(args, "path"));
26822
27409
  const shot = arg.str(args, "screenshot");
26823
- if (shot) fs49.writeFileSync(shot, await browser.screenshot());
27410
+ if (shot) fs52.writeFileSync(shot, await browser.screenshot());
26824
27411
  printJson(ctx, {
26825
27412
  url,
26826
27413
  title: await browser.title(),
@@ -26969,13 +27556,19 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
26969
27556
  });
26970
27557
  session.command({
26971
27558
  name: "export",
26972
- help: "The session's call log as JSONL, one {seq, kind, tool, args, result, error, completedAt} per line, oldest first.",
27559
+ help: "The session's call ledger as JSONL, one {seq, kind, tool, args, result, error, completedAt} per line, oldest first: the calls the platform brokered (tool calls, seeds, grades, resets); --requests appends the world's own request log.",
26973
27560
  positionals: [{ name: "session_id", help: "Session id." }],
26974
27561
  flags: [
26975
27562
  { name: "out", help: "Write the JSONL here instead of stdout." },
27563
+ {
27564
+ name: "requests",
27565
+ help: 'Also append the world\'s own request log (kind "request"), read from the live session with one `state` call.',
27566
+ boolean: true
27567
+ },
26976
27568
  TO_FLAG,
26977
27569
  HOST_FLAG
26978
27570
  ],
27571
+ notes: REQUEST_LOG_NOTES,
26979
27572
  run: async (args, ctx) => {
26980
27573
  const sessionId = args.positionals[0];
26981
27574
  const creds = credentials(args);
@@ -26992,26 +27585,29 @@ world's [redact] policy over the rows first; --redact refuse rejects plaintext i
26992
27585
  calls.push(...page.calls);
26993
27586
  cursor = page.nextCursor ?? void 0;
26994
27587
  } while (cursor);
26995
- const lines = calls.map(
27588
+ const requests = arg.bool(args, "requests") ? await requestLines(await attachSession(sessionId, worldsOptions(creds)), ctx, sessionId) : void 0;
27589
+ const ledger = calls.map(
26996
27590
  (call3) => JSON.stringify(
26997
27591
  Object.fromEntries(
26998
27592
  EXPORT_KEYS.map((key2) => [key2, call3[key2] ?? null])
26999
27593
  )
27000
27594
  )
27001
27595
  );
27596
+ const lines = [...ledger, ...(requests ?? []).map((line) => JSON.stringify(line))];
27002
27597
  const text2 = lines.join("\n") + (lines.length ? "\n" : "");
27598
+ const counted = `${ledger.length} calls${requests ? ` and ${requests.length} requests` : ""}`;
27003
27599
  const out = arg.str(args, "out");
27004
27600
  const to = arg.str(args, "to");
27005
27601
  if (out) {
27006
- fs49.writeFileSync(out, text2);
27007
- ctx.stdout(`wrote ${lines.length} calls to ${out}`);
27602
+ fs52.writeFileSync(out, text2);
27603
+ ctx.stdout(`wrote ${counted} to ${out}`);
27008
27604
  } else if (!to && text2) process.stdout.write(text2);
27009
27605
  if (!to) return;
27010
27606
  const scratch = out ? null : scratchFile(`${sessionId}.calls.jsonl`);
27011
- if (scratch) fs49.writeFileSync(scratch.file, text2);
27607
+ if (scratch) fs52.writeFileSync(scratch.file, text2);
27012
27608
  try {
27013
27609
  const landed = await landInDrive(scratch?.file ?? out, to, creds);
27014
- ctx.stdout(`wrote ${lines.length} calls to drive:${landed.path}`);
27610
+ ctx.stdout(`wrote ${counted} to drive:${landed.path}`);
27015
27611
  } finally {
27016
27612
  scratch?.cleanup();
27017
27613
  }
@@ -27068,7 +27664,7 @@ function taskEditTarget(positional, version) {
27068
27664
  )
27069
27665
  };
27070
27666
  }
27071
- function client3(args) {
27667
+ function client4(args) {
27072
27668
  return new TaskEditClient(worldsOptions(credentials(args)));
27073
27669
  }
27074
27670
  async function call2(run) {
@@ -27100,7 +27696,7 @@ function registerTaskEditVerbs(root) {
27100
27696
  args.positionals[0],
27101
27697
  arg.int(args, "task-version")
27102
27698
  );
27103
- printJson(ctx, await call2(() => client3(args).status(task)));
27699
+ printJson(ctx, await call2(() => client4(args).status(task)));
27104
27700
  }
27105
27701
  });
27106
27702
  edit.command({
@@ -27131,7 +27727,7 @@ function registerTaskEditVerbs(root) {
27131
27727
  printJson(
27132
27728
  ctx,
27133
27729
  await call2(
27134
- () => client3(args).close(task, {
27730
+ () => client4(args).close(task, {
27135
27731
  requireAll: arg.bool(args, "require-all") || void 0,
27136
27732
  force: arg.bool(args, "force") || void 0,
27137
27733
  message: arg.str(args, "message")
@@ -27171,7 +27767,7 @@ function registerTaskEditVerbs(root) {
27171
27767
  printJson(
27172
27768
  ctx,
27173
27769
  await call2(
27174
- () => client3(args).rollback(task, {
27770
+ () => client4(args).rollback(task, {
27175
27771
  groupId,
27176
27772
  force: arg.bool(args, "force") || void 0,
27177
27773
  message: arg.str(args, "message")
@@ -27266,7 +27862,7 @@ function registerTaskRunSet(root) {
27266
27862
  }
27267
27863
 
27268
27864
  // src/cli/platform/traces.ts
27269
- var fs50 = __toESM(require("fs"));
27865
+ var fs53 = __toESM(require("fs"));
27270
27866
  init_config();
27271
27867
  init_router();
27272
27868
 
@@ -27485,7 +28081,7 @@ function registerTracesCommands(root) {
27485
28081
  const scratch = toDrive ? scratchFile("traces.jsonl") : null;
27486
28082
  const file = toStdout ? null : scratch?.file ?? out;
27487
28083
  try {
27488
- const sink = file ? fs50.createWriteStream(file) : null;
28084
+ const sink = file ? fs53.createWriteStream(file) : null;
27489
28085
  const write = (record) => {
27490
28086
  const line = JSON.stringify(record) + "\n";
27491
28087
  if (sink) sink.write(line);
@@ -27493,7 +28089,7 @@ function registerTracesCommands(root) {
27493
28089
  };
27494
28090
  const limit = arg.int(args, "limit");
27495
28091
  const summary2 = await exportTraces(worldsOptions(creds), filtersOf(args), { observations: arg.bool(args, "observations"), type, max: limit }, write);
27496
- if (sink) await new Promise((resolve29, reject) => sink.end((error) => error ? reject(error) : resolve29()));
28092
+ if (sink) await new Promise((resolve32, reject) => sink.end((error) => error ? reject(error) : resolve32()));
27497
28093
  const what = `${summary2.traces} traces${arg.bool(args, "observations") ? ` (${summary2.observations} observations)` : ""}`;
27498
28094
  if (toDrive) ctx.stderr(`wrote ${what} to drive:${(await landInDrive(file, toDrive, creds)).path}`);
27499
28095
  else ctx.stderr(toStdout ? `wrote ${what}` : `wrote ${what} to ${out}`);
@@ -27603,8 +28199,8 @@ function registerTracesCommands(root) {
27603
28199
  });
27604
28200
  }
27605
28201
  function readFile2(file) {
27606
- if (!fs50.existsSync(file)) throw new CliError(`${file} does not exist`, 1);
27607
- return fs50.readFileSync(file, "utf8");
28202
+ if (!fs53.existsSync(file)) throw new CliError(`${file} does not exist`, 1);
28203
+ return fs53.readFileSync(file, "utf8");
27608
28204
  }
27609
28205
 
27610
28206
  // src/cli/platform/worldData/chunks.ts
@@ -27803,6 +28399,7 @@ function registerPlatformCommands(root) {
27803
28399
  registerReleaseCommands(root);
27804
28400
  registerTracesCommands(root);
27805
28401
  registerFilesCommands(root);
28402
+ registerDashboardCommands(root);
27806
28403
  registerPythonOnlyCommands(root);
27807
28404
  }
27808
28405
 
@@ -27810,8 +28407,8 @@ function registerPlatformCommands(root) {
27810
28407
  init_schema();
27811
28408
 
27812
28409
  // src/cli/runtime/connector.ts
27813
- var fs51 = __toESM(require("fs"));
27814
- var path38 = __toESM(require("path"));
28410
+ var fs54 = __toESM(require("fs"));
28411
+ var path41 = __toESM(require("path"));
27815
28412
  init_router();
27816
28413
  init_config();
27817
28414
  init_local();
@@ -27845,10 +28442,10 @@ function wireParams(params) {
27845
28442
  return names.size === list.length ? Object.fromEntries(list) : list;
27846
28443
  }
27847
28444
  function requireConnectorToml(dir) {
27848
- const file = path38.join(dir, "connector.toml");
27849
- if (!fs51.existsSync(file))
28445
+ const file = path41.join(dir, "connector.toml");
28446
+ if (!fs54.existsSync(file))
27850
28447
  throw new CliError(`${dir} holds no connector.toml`, 1);
27851
- return fs51.readFileSync(file, "utf8");
28448
+ return fs54.readFileSync(file, "utf8");
27852
28449
  }
27853
28450
  function renderConnection(spec) {
27854
28451
  const lines = [`${spec.slug} ${spec.baseUrl} auth=${spec.auth}`];
@@ -27882,7 +28479,7 @@ async function remoteCapture(creds, world, opts, ctx) {
27882
28479
  const specText = requireConnectorToml(world);
27883
28480
  const containerId = await resolveEnvironmentId2(
27884
28481
  creds,
27885
- opts.environment ?? path38.basename(path38.resolve(world))
28482
+ opts.environment ?? path41.basename(path41.resolve(world))
27886
28483
  );
27887
28484
  const base = `/api/public/environments/${encodeURIComponent(containerId)}`;
27888
28485
  const params = wireParams(opts.params);
@@ -27925,8 +28522,8 @@ async function remoteCapture(creds, world, opts, ctx) {
27925
28522
  const written = [];
27926
28523
  for (const file of view.files ?? []) {
27927
28524
  const drivePath2 = String(file.path);
27928
- const relative4 = drivePath2.startsWith(slugPrefix) ? drivePath2.slice(slugPrefix.length) : drivePath2;
27929
- if (!relative4.startsWith(`${CAPTURES}/`) || relative4.split("/").includes(".."))
28525
+ const relative6 = drivePath2.startsWith(slugPrefix) ? drivePath2.slice(slugPrefix.length) : drivePath2;
28526
+ if (!relative6.startsWith(`${CAPTURES}/`) || relative6.split("/").includes(".."))
27930
28527
  throw new CliError(
27931
28528
  `Refusing a capture outside ${CAPTURES}/: ${drivePath2}`,
27932
28529
  1
@@ -27939,18 +28536,18 @@ async function remoteCapture(creds, world, opts, ctx) {
27939
28536
  const res = await fetch(info.url);
27940
28537
  if (!res.ok)
27941
28538
  throw new CliError(`download ${drivePath2} -> ${res.status}`, 1);
27942
- const destination = path38.join(world, relative4);
27943
- fs51.mkdirSync(path38.dirname(destination), { recursive: true });
28539
+ const destination = path41.join(world, relative6);
28540
+ fs54.mkdirSync(path41.dirname(destination), { recursive: true });
27944
28541
  const bytes = Buffer.from(await res.arrayBuffer());
27945
- fs51.writeFileSync(destination, bytes);
27946
- written.push(relative4);
28542
+ fs54.writeFileSync(destination, bytes);
28543
+ written.push(relative6);
27947
28544
  for (const name of undeclaredParams(bytes))
27948
28545
  ctx.stderr(
27949
28546
  `# note: ${name} is not declared by operation ${opts.op} in connector.toml; sent as given`
27950
28547
  );
27951
28548
  }
27952
- const manifestPath2 = path38.join(world, CAPTURES, MANIFEST);
27953
- const existing = fs51.existsSync(manifestPath2) ? JSON.parse(fs51.readFileSync(manifestPath2, "utf8")) : [];
28549
+ const manifestPath2 = path41.join(world, CAPTURES, MANIFEST);
28550
+ const existing = fs54.existsSync(manifestPath2) ? JSON.parse(fs54.readFileSync(manifestPath2, "utf8")) : [];
27954
28551
  const known = new Set(
27955
28552
  existing.map(
27956
28553
  (e) => e && typeof e === "object" ? e.file : void 0
@@ -27963,8 +28560,8 @@ async function remoteCapture(creds, world, opts, ctx) {
27963
28560
  existing.push(entry);
27964
28561
  known.add(file);
27965
28562
  }
27966
- fs51.mkdirSync(path38.dirname(manifestPath2), { recursive: true });
27967
- fs51.writeFileSync(manifestPath2, sortedJson(existing, 1) + "\n");
28563
+ fs54.mkdirSync(path41.dirname(manifestPath2), { recursive: true });
28564
+ fs54.writeFileSync(manifestPath2, sortedJson(existing, 1) + "\n");
27968
28565
  return written;
27969
28566
  }
27970
28567
  function outcomeOk(outcome) {
@@ -27991,7 +28588,7 @@ function registerConnectorCommands2(connector) {
27991
28588
  ],
27992
28589
  flags: [HOST_FLAG4],
27993
28590
  run: async (args, ctx) => {
27994
- const dir = path38.resolve(args.positionals[0]);
28591
+ const dir = path41.resolve(args.positionals[0]);
27995
28592
  requireConnectorToml(dir);
27996
28593
  const creds = credentialsForRuntime(arg.str(args, "host"));
27997
28594
  const res = await runtime(creds, {
@@ -28010,7 +28607,10 @@ function registerConnectorCommands2(connector) {
28010
28607
  connector.command({
28011
28608
  name: "capture",
28012
28609
  help: "Call the live connection once (following its cursor) and record every page under captures/.",
28013
- notes: "The platform makes the calls (--remote) \u2014 from the pod whose IP the vendor allow-listed, with the\ncredential held as the environment's secret (`gateway secret set`) \u2014 and the redacted pages land in\ncaptures/ here, ready for `connector ingest`. A local capture runs the vendor call from this machine\nand runs on this machine when a python3 >= 3.12 is installed (the CLI bundles the runtime).",
28610
+ notes: `The platform makes the calls (--remote) \u2014 from the pod whose IP the vendor allow-listed, with the
28611
+ credential held as the environment's secret (\`gateway secret set\`) \u2014 and the redacted pages land in
28612
+ captures/ here, ready for \`connector ingest\`. A local capture runs the vendor call from this machine
28613
+ and runs on this machine when a python3 >= ${MIN_PYTHON_LABEL} is installed (the CLI bundles the runtime).`,
28014
28614
  positionals: [
28015
28615
  { name: "path", help: "World directory holding connector.toml" }
28016
28616
  ],
@@ -28044,14 +28644,14 @@ function registerConnectorCommands2(connector) {
28044
28644
  HOST_FLAG4
28045
28645
  ],
28046
28646
  run: async (args, ctx) => {
28047
- const dir = path38.resolve(args.positionals[0]);
28647
+ const dir = path41.resolve(args.positionals[0]);
28048
28648
  const op = arg.str(args, "op");
28049
28649
  if (!op) throw new CliError("capture needs --op");
28050
28650
  if (!arg.bool(args, "remote")) {
28051
28651
  const local = localRuntime();
28052
28652
  if (!local)
28053
28653
  throw new CliError(
28054
- `local capture runs the vendor call from this machine and needs python3 >= 3.12 (the CLI bundles the runtime). ${localRuntimeReason()} Or use --remote to capture from the platform.`
28654
+ `local capture runs the vendor call from this machine and needs python3 >= ${MIN_PYTHON_LABEL} (the CLI bundles the runtime). ${localRuntimeReason()} Or use --remote to capture from the platform.`
28055
28655
  );
28056
28656
  const argv = ["connector-capture", dir, "--op", op];
28057
28657
  for (const pair3 of arg.list(args, "arg")) argv.push("--arg", pair3);
@@ -28094,17 +28694,17 @@ function registerConnectorCommands2(connector) {
28094
28694
  HOST_FLAG4
28095
28695
  ],
28096
28696
  run: async (args, ctx) => {
28097
- const dir = path38.resolve(args.positionals[0]);
28697
+ const dir = path41.resolve(args.positionals[0]);
28098
28698
  const documents = arg.list(args, "openapi");
28099
28699
  if (!documents.length)
28100
28700
  throw new CliError("conform needs --openapi FILE (repeatable)");
28101
28701
  requireConnectorToml(dir);
28102
28702
  const openapi = documents.map((file) => {
28103
- if (!fs51.existsSync(file))
28703
+ if (!fs54.existsSync(file))
28104
28704
  throw new CliError(`--openapi ${file} does not exist`);
28105
28705
  return {
28106
- path: path38.basename(file),
28107
- content: fs51.readFileSync(file).toString("base64")
28706
+ path: path41.basename(file),
28707
+ content: fs54.readFileSync(file).toString("base64")
28108
28708
  };
28109
28709
  });
28110
28710
  const limit = arg.int(args, "limit");
@@ -28122,7 +28722,7 @@ function registerConnectorCommands2(connector) {
28122
28722
  ctx.stdout(JSON.stringify(summary2));
28123
28723
  const out = arg.str(args, "out");
28124
28724
  if (out) {
28125
- fs51.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
28725
+ fs54.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
28126
28726
  ctx.stdout(`report: ${out}`);
28127
28727
  }
28128
28728
  return Number(summary2.status_mismatch) || Number(summary2.schema_violations) ? 1 : 0;
@@ -28150,8 +28750,8 @@ function registerConnectorCommands2(connector) {
28150
28750
  ],
28151
28751
  notes: "An ingest stops at the first row the contract refuses; --dry-run reports all of them at once, grouped\nby capture, entity and pointer, so a forty-capture world is fixed in one pass. Exit 2 when any row is refused.",
28152
28752
  run: async (args, ctx) => {
28153
- const dir = path38.resolve(args.positionals[0]);
28154
- if (!fs51.existsSync(path38.join(dir, CAPTURES)))
28753
+ const dir = path41.resolve(args.positionals[0]);
28754
+ if (!fs54.existsSync(path41.join(dir, CAPTURES)))
28155
28755
  throw new CliError(
28156
28756
  `${dir} holds no ${CAPTURES}/ \u2014 run \`connector capture --remote\` first`,
28157
28757
  1
@@ -28182,7 +28782,7 @@ function registerConnectorCommands2(connector) {
28182
28782
  ` ${refusal.capture ?? "?"} ${refusal.pointer}: ${refusal.detail}`
28183
28783
  );
28184
28784
  if (report) {
28185
- fs51.writeFileSync(
28785
+ fs54.writeFileSync(
28186
28786
  report,
28187
28787
  refusals.map((r) => JSON.stringify(r) + "\n").join("")
28188
28788
  );
@@ -28209,8 +28809,8 @@ function registerConnectorCommands2(connector) {
28209
28809
  }
28210
28810
 
28211
28811
  // src/cli/runtime/serve.ts
28212
- var fs52 = __toESM(require("fs"));
28213
- var path39 = __toESM(require("path"));
28812
+ var fs55 = __toESM(require("fs"));
28813
+ var path42 = __toESM(require("path"));
28214
28814
  init_router();
28215
28815
  init_config();
28216
28816
  init_worlds();
@@ -28221,7 +28821,31 @@ function registerServeCommand(worlds) {
28221
28821
  worlds.command({
28222
28822
  name: "serve",
28223
28823
  help: "Serve one session of the world here (bundled runtime + python3): its tools over HTTP, the vendor routes when it has them, its ui on its own port when it declares one; or open a hosted api session when no Python is installed.",
28224
- notes: "With a python3 >= 3.12 on this machine the CLI serves the world here from its bundled runtime\n(the same files the platform runs), on --port, in the foreground, as ONE session with state that\nlasts until you stop it or a client closes it. Every schema world gets the session verbs (loopback,\nno credential), the surface an outside agent acts on:\n GET /__session/task {task, prompt, tools, verifiers, worlds: {alias: [verifiers]}}\n GET /__session/tools what it serves: the tools and the connector.toml operations (a dependency's tools as alias.tool)\n POST /__session/call {tool, args} -> {status, body}, as a hosted session answers; an operation by name too\n GET /__session/state rows per entity (a dependency's under worlds.<alias>)\n POST /__session/grade {reward, rewards}: the root's verifiers by name, a dependency's as alias/name\n POST /__session/seed {rows: {entity: [row, ...]}, mode?: append|replace} (a dependency's entity as alias.entity; a\n bare {entity: [row, ...]} is taken as rows); POST /__session/reset back to the start\n POST /__session/close end the session; this command returns\n--task <id> opens the session on one of the world's tasks: its prompt is in the banner and at\n/__session/task, its verifiers grade, and each dependency starts in the scenario its link's `task`\nnames. `gateway worlds call <url> <tool> [--grade] [--close]` acts on the session from another shell.\nA world with a connector.toml serves its vendor routes beside them, and with `[ui]` its page on its own\nport (--ui-port, default the port after --port) at /, the layout the host serves it in, so a frontend\nbuilt for the root works unchanged; the same page is at /__ui/ on --port. The page's api_path calls are\nanswered with the pin; the bare routes still need it. `[dependencies]` entries with\na `path` open beside the root. A --port another process holds is refused by name (its pid when lsof\ncan see it): this serve never answers from another server. The runtime closes when the process that\nstarted it is gone, so a killed CLI leaves no server on the port. Without a python3 it does what `gateway worlds session open <slug>\n--task <scenario> --surface api --no-wait` does: the platform serves the world's vendor API for one\nsession, and the session id + api url are printed. Close it with `gateway worlds session close <id>`.\nGATEWAY_RUNTIME=platform forces the hosted path.",
28824
+ notes: `With a python3 >= ${MIN_PYTHON_LABEL} on this machine the CLI serves the world here from its bundled runtime
28825
+ (the same files the platform runs), on --port, in the foreground, as ONE session with state that
28826
+ lasts until you stop it or a client closes it. Every schema world gets the session verbs (loopback,
28827
+ no credential), the surface an outside agent acts on:
28828
+ GET /__session/task {task, prompt, tools, verifiers, worlds: {alias: [verifiers]}}
28829
+ GET /__session/tools what it serves: the tools and the connector.toml operations (a dependency's tools as alias.tool)
28830
+ POST /__session/call {tool, args} -> {status, body}, as a hosted session answers; an operation by name too
28831
+ GET /__session/state rows per entity (a dependency's under worlds.<alias>)
28832
+ POST /__session/grade {reward, rewards}: the root's verifiers by name, a dependency's as alias/name
28833
+ POST /__session/seed {rows: {entity: [row, ...]}, mode?: append|replace} (a dependency's entity as alias.entity; a
28834
+ bare {entity: [row, ...]} is taken as rows); POST /__session/reset back to the start
28835
+ POST /__session/close end the session; this command returns
28836
+ --task <id> opens the session on one of the world's tasks: its prompt is in the banner and at
28837
+ /__session/task, its verifiers grade, and each dependency starts in the scenario its link's \`task\`
28838
+ names. \`gateway worlds call <url> <tool> [--grade] [--close]\` acts on the session from another shell.
28839
+ A world with a connector.toml serves its vendor routes beside them, and with \`[ui]\` its page on its own
28840
+ port (--ui-port, default the port after --port) at /, the layout the host serves it in, so a frontend
28841
+ built for the root works unchanged; the same page is at /__ui/ on --port. The page's api_path calls are
28842
+ answered with the pin; the bare routes still need it. \`[dependencies]\` entries with
28843
+ a \`path\` open beside the root. A --port another process holds is refused by name (its pid when lsof
28844
+ can see it): this serve never answers from another server. The runtime closes when the process that
28845
+ started it is gone, so a killed CLI leaves no server on the port. Without a python3 it does what \`gateway worlds session open <slug>
28846
+ --task <scenario> --surface api --no-wait\` does: the platform serves the world's vendor API for one
28847
+ session, and the session id + api url are printed. Close it with \`gateway worlds session close <id>\`.
28848
+ GATEWAY_RUNTIME=platform forces the hosted path.`,
28225
28849
  positionals: [
28226
28850
  {
28227
28851
  name: "path",
@@ -28248,7 +28872,7 @@ function registerServeCommand(worlds) {
28248
28872
  },
28249
28873
  {
28250
28874
  name: "api-key",
28251
- help: "Pin the credential the local server accepts (a hosted session carries its own)."
28875
+ help: "Pin the credential the local server accepts (default `conform`; a hosted session carries its own)."
28252
28876
  },
28253
28877
  {
28254
28878
  name: "host",
@@ -28259,14 +28883,14 @@ function registerServeCommand(worlds) {
28259
28883
  run: async (args, ctx) => {
28260
28884
  const target = args.positionals[0];
28261
28885
  const local = localRuntime();
28262
- if (local && fs52.existsSync(target) && fs52.statSync(target).isDirectory()) {
28886
+ if (local && fs55.existsSync(target) && fs55.statSync(target).isDirectory()) {
28263
28887
  const port = arg.int(args, "port") ?? 8080;
28264
28888
  if (!Number.isInteger(port) || port < 0 || port > 65535)
28265
28889
  throw new CliError(
28266
28890
  `--port must be a port number (got ${String(args.flags.port)})`
28267
28891
  );
28268
28892
  if (port !== 0) await assertPortFree(port);
28269
- const argv = ["serve", path39.resolve(target), "--port", String(port)];
28893
+ const argv = ["serve", path42.resolve(target), "--port", String(port)];
28270
28894
  const apiKey = arg.str(args, "api-key");
28271
28895
  if (apiKey) argv.push("--api-key", apiKey);
28272
28896
  const uiPort = arg.str(args, "ui-port");
@@ -28276,11 +28900,11 @@ function registerServeCommand(worlds) {
28276
28900
  const task = arg.str(args, "task");
28277
28901
  if (task) argv.push("--task", task);
28278
28902
  ctx.stderr(
28279
- `# serving ${path39.resolve(target)} on http://127.0.0.1:${port} (local runtime: ${local.python})`
28903
+ `# serving ${path42.resolve(target)} on http://127.0.0.1:${port} (local runtime: ${local.python})`
28280
28904
  );
28281
28905
  return localModule(argv, local);
28282
28906
  }
28283
- if (!local && fs52.existsSync(target) && fs52.statSync(target).isDirectory())
28907
+ if (!local && fs55.existsSync(target) && fs55.statSync(target).isDirectory())
28284
28908
  ctx.stderr(
28285
28909
  `# ${localRuntimeReason()}
28286
28910
  # A local directory is served here only by the bundled Python runtime; without one the CLI can only open a hosted session of a world already published (gateway worlds create <slug> --from ${target}), which needs a login (gateway auth login).`
@@ -28293,17 +28917,17 @@ function registerServeCommand(worlds) {
28293
28917
  };
28294
28918
  let slugRef = target;
28295
28919
  let versionId;
28296
- if (fs52.existsSync(target) && fs52.statSync(target).isDirectory()) {
28297
- const dir = path39.resolve(target);
28920
+ if (fs55.existsSync(target) && fs55.statSync(target).isDirectory()) {
28921
+ const dir = path42.resolve(target);
28298
28922
  const meta = readLocalMeta(dir);
28299
- const slug = meta?.slug ?? path39.basename(dir);
28923
+ const slug = meta?.slug ?? path42.basename(dir);
28300
28924
  slugRef = meta?.branch ? `${slug}@${meta.branch}` : slug;
28301
28925
  versionId = meta?.versionId;
28302
28926
  }
28303
28927
  ctx.stderr(
28304
28928
  "`worlds serve` runs a local session with the Python runtime; opening a hosted api-surface session instead."
28305
28929
  );
28306
- if (!local && !(fs52.existsSync(target) && fs52.statSync(target).isDirectory())) ctx.stderr(`# ${localRuntimeReason()}`);
28930
+ if (!local && !(fs55.existsSync(target) && fs55.statSync(target).isDirectory())) ctx.stderr(`# ${localRuntimeReason()}`);
28307
28931
  let scenario = arg.str(args, "scenario") ?? arg.str(args, "task");
28308
28932
  if (!scenario) {
28309
28933
  const world = await openWorld(slugRef, options);
@@ -28341,8 +28965,8 @@ function registerServeCommand(worlds) {
28341
28965
  }
28342
28966
 
28343
28967
  // src/cli/runtime/test.ts
28344
- var fs53 = __toESM(require("fs"));
28345
- var path40 = __toESM(require("path"));
28968
+ var fs56 = __toESM(require("fs"));
28969
+ var path43 = __toESM(require("path"));
28346
28970
  init_router();
28347
28971
  init_shared();
28348
28972
  init_local();
@@ -28365,7 +28989,7 @@ function renderWorldTestReport(report) {
28365
28989
  }
28366
28990
  const py = report.python;
28367
28991
  if (py && py.status !== "none") {
28368
- const detail = py.status === "skipped" ? py.reason ?? "skipped" : `${py.tests ?? 0} tests, ${py.failures ?? 0} failures, ${py.errors ?? 0} errors`;
28992
+ const detail = py.reason ?? (py.status === "skipped" ? "skipped" : `${py.tests ?? 0} tests, ${py.failures ?? 0} failures, ${py.errors ?? 0} errors`);
28369
28993
  lines.push(
28370
28994
  `${py.status === "passed" ? " ok " : py.status === "skipped" ? "skip" : "FAIL"} python tests (${(py.files ?? []).join(", ")}) ${detail}`
28371
28995
  );
@@ -28402,8 +29026,8 @@ function registerTestCommand(worlds) {
28402
29026
  notes: 'A world\'s tests live in <world>/tests/ and run in order against ONE session of the world, so a case sees\nwhat the cases before it wrote. *.json files hold cases of two shapes:\n {name, tool: "send_message", args: {...}, expect} a tool call (root tools by name, a dependency\'s as alias.tool);\n {name, request: {method, path, query?, headers?, body?, auth?}, expect} an HTTP call on the vendor routes (connector.toml).\nexpect is {status?, json?, length?, contains?, headers?}; a refused call (unknown tool, arguments off the\nschema) answers 400 with {error, detail}; a handler that raises answers 500 with {error: its message}.\ntests/test_*.py run under pytest with WORLD_DIR, WORLD_URL and\nWORLD_API_KEY set (a Python without pytest FAILS the suite, it never skips it). No tests/ directory passes as\nzero cases. With `[actions] on_push = ["tests"]` in gateway-env.toml the platform runs the same suite on\nevery push; `gateway bench tests <slug>` reads those runs. Exit 1 when any test fails.',
28403
29027
  run: async (args, ctx) => {
28404
29028
  const target = args.positionals[0] ?? ".";
28405
- const dir = path40.resolve(target);
28406
- if (!fs53.existsSync(dir) || !fs53.statSync(dir).isDirectory()) {
29029
+ const dir = path43.resolve(target);
29030
+ if (!fs56.existsSync(dir) || !fs56.statSync(dir).isDirectory()) {
28407
29031
  if (/[\/\\]/.test(target) || target.startsWith("."))
28408
29032
  throw new CliError(`Not a directory: ${dir}`, 1);
28409
29033
  const creds2 = resolveCredentials(arg.str(args, "host"));
@@ -28434,7 +29058,7 @@ function registerTestCommand(worlds) {
28434
29058
  `Test run ${run.id} still ${run.state} after 15 minutes`,
28435
29059
  1
28436
29060
  );
28437
- await new Promise((resolve29) => setTimeout(resolve29, 2e3));
29061
+ await new Promise((resolve32) => setTimeout(resolve32, 2e3));
28438
29062
  try {
28439
29063
  run = (await api(
28440
29064
  creds2,
@@ -28453,6 +29077,7 @@ function registerTestCommand(worlds) {
28453
29077
  {
28454
29078
  runId: run.id,
28455
29079
  state: run.state,
29080
+ trigger: run.trigger ?? null,
28456
29081
  versionId: run.versionId,
28457
29082
  ...report2
28458
29083
  },
@@ -28464,18 +29089,19 @@ function registerTestCommand(worlds) {
28464
29089
  for (const line of renderWorldTestReport(report2)) ctx.stdout(line);
28465
29090
  const s = run.summary ?? report2.summary ?? {};
28466
29091
  ctx.stdout(
28467
- `${run.state}: ${s.passed ?? 0} passed, ${s.failed ?? 0} failed, ${s.skipped ?? 0} skipped (run ${run.id} on ${run.versionId})`
29092
+ `${run.state}: ${s.passed ?? 0} passed, ${s.failed ?? 0} failed, ${s.skipped ?? 0} skipped (run ${run.id}${run.trigger ? `, trigger ${run.trigger}` : ""}, on ${run.versionId})`
28468
29093
  );
28469
29094
  if (run.error) ctx.stdout(`error: ${run.error}`);
28470
29095
  }
28471
29096
  const out2 = arg.str(args, "out");
28472
29097
  if (out2)
28473
- fs53.writeFileSync(
29098
+ fs56.writeFileSync(
28474
29099
  out2,
28475
29100
  JSON.stringify(
28476
29101
  {
28477
29102
  runId: run.id,
28478
29103
  state: run.state,
29104
+ trigger: run.trigger ?? null,
28479
29105
  versionId: run.versionId,
28480
29106
  ...report2
28481
29107
  },
@@ -28498,8 +29124,8 @@ function registerTestCommand(worlds) {
28498
29124
  for (const line of renderWorldTestReport(report)) ctx.stdout(line);
28499
29125
  const s = report.summary ?? {};
28500
29126
  if (!(s.total ?? 0) && !(report.python?.files?.length ?? 0)) {
28501
- const tests = path40.join(dir, "tests");
28502
- const state2 = fs53.existsSync(tests) ? "holds none" : "does not exist";
29127
+ const tests = path43.join(dir, "tests");
29128
+ const state2 = fs56.existsSync(tests) ? "holds none" : "does not exist";
28503
29129
  ctx.stdout(`no cases: ${tests} ${state2} (see \`gateway worlds test --help\` for the shapes)`);
28504
29130
  }
28505
29131
  ctx.stdout(
@@ -28508,7 +29134,7 @@ function registerTestCommand(worlds) {
28508
29134
  }
28509
29135
  const out = arg.str(args, "out");
28510
29136
  if (out) {
28511
- fs53.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
29137
+ fs56.writeFileSync(out, JSON.stringify(report, null, 1) + "\n");
28512
29138
  ctx.stdout(`report: ${out}`);
28513
29139
  }
28514
29140
  return report.summary?.status === "passed" ? 0 : 1;
@@ -28517,8 +29143,8 @@ function registerTestCommand(worlds) {
28517
29143
  }
28518
29144
 
28519
29145
  // src/cli/runtime/call.ts
28520
- var fs54 = __toESM(require("fs"));
28521
- var path41 = __toESM(require("path"));
29146
+ var fs57 = __toESM(require("fs"));
29147
+ var path44 = __toESM(require("path"));
28522
29148
  init_router();
28523
29149
  init_session2();
28524
29150
  init_sessionContract();
@@ -28532,8 +29158,8 @@ function parseArgs2(raw, stdin) {
28532
29158
  if (raw === "-") text2 = stdin;
28533
29159
  else if (raw.startsWith("@")) {
28534
29160
  const file = raw.slice(1);
28535
- if (!fs54.existsSync(file)) throw new CliError(`--args ${raw}: ${file} does not exist`);
28536
- text2 = fs54.readFileSync(file, "utf8");
29161
+ if (!fs57.existsSync(file)) throw new CliError(`--args ${raw}: ${file} does not exist`);
29162
+ text2 = fs57.readFileSync(file, "utf8");
28537
29163
  }
28538
29164
  let value;
28539
29165
  try {
@@ -28608,7 +29234,7 @@ async function callHosted(sessionId, tool, args, wants, options) {
28608
29234
  return settleStatus(report);
28609
29235
  }
28610
29236
  function looksLikeSessionId(target) {
28611
- return !target.includes("/") && !target.startsWith(".") && !fs54.existsSync(target);
29237
+ return !target.includes("/") && !target.startsWith(".") && !fs57.existsSync(target);
28612
29238
  }
28613
29239
  async function callServed(base, tool, args, wants) {
28614
29240
  const url = base.replace(/\/+$/, "");
@@ -28667,7 +29293,14 @@ function registerCallCommand(worlds) {
28667
29293
  { name: "close", help: "On a served session (url) or a hosted one (id): end it after the call.", boolean: true },
28668
29294
  HOST_FLAG
28669
29295
  ],
28670
- notes: 'The world is opened in place, so `[dependencies]` entries with a `path` open beside it and their tools\nanswer as alias.tool; a pin without a path is refused here (add path = "../<dir>"). The world\'s handlers\nrun on this machine through the bundled runtime (a python3 >= 3.12); the platform never runs them for you.\nExit 0 when the tool answered 2xx, 1 otherwise: a refused call (unknown tool, arguments off the schema, a\ntool outside --task\'s allow-list) prints the refusal. A handler\'s own bug (an AttributeError, TypeError or\nNameError \u2014 say store.upsert, which does not exist) is a 400 {error: "handler", detail, handler}; anything\nelse the handler raises is a 500 {error: "engine", detail, handler}. Never a bare exception string.\n' + STORE_API_NOTE + `
29296
+ notes: `The world is opened in place, so \`[dependencies]\` entries with a \`path\` open beside it and their tools
29297
+ answer as alias.tool; a pin without a path is refused here (add path = "../<dir>"). The world's handlers
29298
+ run on this machine through the bundled runtime (a python3 >= ${MIN_PYTHON_LABEL}); the platform never runs them for you.
29299
+ Exit 0 when the tool answered 2xx, 1 otherwise: a refused call (unknown tool, arguments off the schema, a
29300
+ tool outside --task's allow-list) prints the refusal. A handler's own bug (an AttributeError, TypeError or
29301
+ NameError \u2014 say store.upsert, which does not exist) is a 400 {error: "handler", detail, handler}; anything
29302
+ else the handler raises is a 500 {error: "engine", detail, handler}. Never a bare exception string.
29303
+ ` + STORE_API_NOTE + `
28671
29304
  With a url (the \`url\` \`gateway worlds serve <dir> --task <id>\` prints) the call goes to THAT session over
28672
29305
  POST /__session/call, so state carries from call to call, --state/--grade read it, and --close ends it;
28673
29306
  --task and --scenario belong to the serve. This is the outside-agent path: any HTTP client does the same.
@@ -28727,8 +29360,8 @@ Examples:
28727
29360
  }
28728
29361
  }
28729
29362
  if (arg.bool(args, "close")) throw new CliError("--close ends a served or hosted session; pass its url or id instead of a directory");
28730
- const dir = path41.resolve(target);
28731
- if (!fs54.existsSync(dir) || !fs54.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
29363
+ const dir = path44.resolve(target);
29364
+ if (!fs57.existsSync(dir) || !fs57.statSync(dir).isDirectory()) throw new CliError(`Not a directory: ${dir}`, 1);
28732
29365
  const local = localRuntime();
28733
29366
  if (!local)
28734
29367
  throw new CliError(
@@ -28764,12 +29397,12 @@ Examples:
28764
29397
  }
28765
29398
 
28766
29399
  // src/cli/runtime/scaffold.ts
28767
- var fs56 = __toESM(require("fs"));
28768
- var path42 = __toESM(require("path"));
29400
+ var fs61 = __toESM(require("fs"));
29401
+ var path47 = __toESM(require("path"));
28769
29402
  init_router();
28770
29403
 
28771
29404
  // src/cli/runtime/scaffoldJson.ts
28772
- var fs55 = __toESM(require("fs"));
29405
+ var fs58 = __toESM(require("fs"));
28773
29406
  init_router();
28774
29407
  var PROPERTY_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
28775
29408
  var isObject12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -28784,10 +29417,10 @@ function resolveObjectSchema(root, schema) {
28784
29417
  return schema;
28785
29418
  }
28786
29419
  function readJsonFile2(file) {
28787
- if (!fs55.existsSync(file)) throw new CliError(`${file} does not exist; run \`gateway worlds schema init\` first`, 1);
29420
+ if (!fs58.existsSync(file)) throw new CliError(`${file} does not exist; run \`gateway worlds schema init\` first`, 1);
28788
29421
  let parsed;
28789
29422
  try {
28790
- parsed = JSON.parse(fs55.readFileSync(file, "utf8"));
29423
+ parsed = JSON.parse(fs58.readFileSync(file, "utf8"));
28791
29424
  } catch (err) {
28792
29425
  throw new CliError(`${file} is not valid JSON: ${err.message}`, 1);
28793
29426
  }
@@ -28812,7 +29445,7 @@ function keyGenerators(spec, entities) {
28812
29445
  return { [field2]: type === "integer" ? "int" : "uuid" };
28813
29446
  }
28814
29447
  var tomlString = (value) => JSON.stringify(value);
28815
- var pathArgs = (path44) => [...path44.matchAll(PATH_ARGUMENT)].map((m) => m[1]);
29448
+ var pathArgs = (path49) => [...path49.matchAll(PATH_ARGUMENT)].map((m) => m[1]);
28816
29449
  function unboundPathArgs(spec, entities) {
28817
29450
  if (spec.api.action === "handler") return [];
28818
29451
  const fields = entities?.[spec.entity ?? ""]?.fields ?? [];
@@ -29012,6 +29645,214 @@ function declaredEntityShapes(root) {
29012
29645
  return shapes;
29013
29646
  }
29014
29647
 
29648
+ // src/cli/runtime/scaffoldEntityRemove.ts
29649
+ var fs59 = __toESM(require("fs"));
29650
+ var path45 = __toESM(require("path"));
29651
+ init_router();
29652
+ var LOCAL_DEF = "#/$defs/";
29653
+ function localRefs(value, found = /* @__PURE__ */ new Set()) {
29654
+ if (Array.isArray(value)) value.forEach((item) => localRefs(item, found));
29655
+ if (!isObject12(value)) return found;
29656
+ for (const [key2, child] of Object.entries(value)) {
29657
+ if (key2 === "$ref" && typeof child === "string" && child.startsWith(LOCAL_DEF)) found.add(child.slice(LOCAL_DEF.length));
29658
+ else localRefs(child, found);
29659
+ }
29660
+ return found;
29661
+ }
29662
+ function closure(start, defs) {
29663
+ const reached = /* @__PURE__ */ new Set();
29664
+ const pending = [...start];
29665
+ while (pending.length) {
29666
+ const name = pending.pop();
29667
+ if (reached.has(name)) continue;
29668
+ reached.add(name);
29669
+ pending.push(...localRefs(defs[name]));
29670
+ }
29671
+ return reached;
29672
+ }
29673
+ var escaped = (text2) => text2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
29674
+ var sqlMentions = (sql, name) => new RegExp(`(^|[^A-Za-z0-9_])"?${escaped(name)}"?([^A-Za-z0-9_]|$)`, "i").test(sql.replace(/--[^\n]*/g, ""));
29675
+ var EntityRemoval = class _EntityRemoval {
29676
+ constructor(dir, file, root) {
29677
+ this.dir = dir;
29678
+ this.file = file;
29679
+ this.root = root;
29680
+ }
29681
+ dir;
29682
+ file;
29683
+ root;
29684
+ static open(dir) {
29685
+ const file = path45.join(dir, "schema", "world.json");
29686
+ if (!fs59.existsSync(file)) throw new CliError(`${dir} has no schema/world.json`);
29687
+ return new _EntityRemoval(dir, file, readJsonFile2(file));
29688
+ }
29689
+ get entities() {
29690
+ const gateway = this.root["x-gateway"];
29691
+ if (!isObject12(gateway) || !isObject12(gateway.entities))
29692
+ throw new CliError("schema/world.json is not a gateway-world/1 root: it has no x-gateway.entities");
29693
+ return gateway.entities;
29694
+ }
29695
+ read(rel) {
29696
+ const file = path45.join(this.dir, rel);
29697
+ return fs59.existsSync(file) ? fs59.readFileSync(file, "utf8") : void 0;
29698
+ }
29699
+ relationships(name) {
29700
+ return Object.entries(this.entities).filter(([other]) => other !== name).filter(
29701
+ ([, declaration]) => isObject12(declaration) && Array.isArray(declaration.relationships) ? declaration.relationships.some((r) => isObject12(r) && r.target === name) : false
29702
+ ).map(([other]) => `entity ${other} relates to ${name}`);
29703
+ }
29704
+ routes(name) {
29705
+ const found = [];
29706
+ let operation;
29707
+ let named2 = false;
29708
+ for (const line of (this.read("connector.toml") ?? "").split("\n").map((l) => l.trim())) {
29709
+ if (line === "[[operations]]") [operation, named2] = [void 0, false];
29710
+ const key2 = /^(name|entity)\s*=\s*["']([^"']*)["']/.exec(line);
29711
+ if (key2?.[1] === "name" && !named2) [operation, named2] = [key2[2], true];
29712
+ if (key2?.[1] === "entity" && key2[2] === name) found.push(`connector.toml operation ${operation ?? "?"} answers from ${name}`);
29713
+ }
29714
+ return [...new Set(found)];
29715
+ }
29716
+ verifiers(name) {
29717
+ const placeholder = path45.join(this.dir, "verifiers", "state_present.sql");
29718
+ return (verifierNames(this.dir) ?? []).map((verifier) => path45.join(this.dir, "verifiers", `${verifier}.sql`)).filter((file) => !(file === placeholder && scaffoldVerifierEntity(file) === name)).filter((file) => sqlMentions(fs59.readFileSync(file, "utf8"), name)).map((file) => `verifiers/${path45.basename(file)} reads ${name}`);
29719
+ }
29720
+ data(name) {
29721
+ const text2 = this.read(path45.join("data", "initial.json"));
29722
+ if (text2 === void 0) return [];
29723
+ const journal = this.journal(text2);
29724
+ const rows = (journal.mutations ?? []).filter((m) => m.entity === name).length;
29725
+ return rows ? [`data/initial.json holds ${rows} ${name} row(s)`] : [];
29726
+ }
29727
+ journal(text2) {
29728
+ try {
29729
+ return JSON.parse(text2);
29730
+ } catch {
29731
+ throw new CliError("data/initial.json is not valid JSON; fix it before removing an entity");
29732
+ }
29733
+ }
29734
+ dependencyMaps(name) {
29735
+ const found = [];
29736
+ let section;
29737
+ for (const line of (this.read("gateway-env.toml") ?? "").split("\n").map((l) => l.trim())) {
29738
+ if (line.startsWith("[")) section = /^\[(dependencies\.[^.\]]+\.entities)\]$/.exec(line)?.[1];
29739
+ if (section && line.startsWith(`"${name}.`)) found.push(`gateway-env.toml [${section}] maps ${name}`);
29740
+ }
29741
+ return [...new Set(found)];
29742
+ }
29743
+ references(name) {
29744
+ return [
29745
+ ...this.relationships(name),
29746
+ ...this.routes(name),
29747
+ ...this.verifiers(name),
29748
+ ...this.data(name),
29749
+ ...this.dependencyMaps(name)
29750
+ ];
29751
+ }
29752
+ prunableDefs(name) {
29753
+ const defs = isObject12(this.root.$defs) ? this.root.$defs : {};
29754
+ const { $defs: _defs, ...rest } = this.root;
29755
+ const kept = structuredClone(rest);
29756
+ delete kept["x-gateway"].entities[name];
29757
+ const keep = closure(localRefs(kept), defs);
29758
+ return [...closure(localRefs(this.entities[name]), defs)].filter((def) => !keep.has(def) && def in defs).sort();
29759
+ }
29760
+ remove(name) {
29761
+ const declared = Object.keys(this.entities);
29762
+ if (!declared.includes(name)) throw new CliError(`Unknown entity ${name}; the world has ${declared.join(", ") || "none"}`);
29763
+ if (declared.length === 1)
29764
+ throw new CliError(
29765
+ `${name} is the world's only entity; declare the one that replaces it first (\`gateway worlds schema entity add\`)`
29766
+ );
29767
+ const blockers = this.references(name);
29768
+ if (blockers.length)
29769
+ throw new CliError(`${name} is still in use; remove these references first:
29770
+ ${blockers.join("\n ")}`);
29771
+ const removedDefs = this.prunableDefs(name);
29772
+ const defs = isObject12(this.root.$defs) ? this.root.$defs : {};
29773
+ removedDefs.forEach((def) => delete defs[def]);
29774
+ delete this.entities[name];
29775
+ fs59.writeFileSync(this.file, JSON.stringify(this.root, null, 2) + "\n");
29776
+ const remaining = Object.keys(this.entities).sort();
29777
+ return { removedDefs, verifier: repointScaffoldVerifier(this.dir, remaining[0], remaining) };
29778
+ }
29779
+ };
29780
+ function registerEntityRemove(entity) {
29781
+ entity.command({
29782
+ name: "remove",
29783
+ help: "Remove one entity from schema/world.json, with the $defs only it used; refused while a route, verifier, row or relationship needs it.",
29784
+ positionals: [
29785
+ { name: "path", help: "World directory holding schema/world.json" },
29786
+ { name: "entity", help: "Entity name, e.g. records (the custom scaffold's example)" }
29787
+ ],
29788
+ notes: "Nothing is written when the entity is still referenced: every connector.toml operation that answers from\nit, every verifiers/*.sql that reads it, rows of it in data/initial.json, a [dependencies.<alias>.entities]\nmap and another entity's relationship are named, one per line (exit 2). The world keeps at least one entity:\n`gateway worlds schema entity add` the replacement first. The untouched placeholder verifiers/state_present.sql\nis re-pointed at an entity that stays. Then `gateway worlds schema compile <path>` and `gateway worlds schema check <path>`.",
29789
+ run: async (args, ctx) => {
29790
+ const dir = path45.resolve(args.positionals[0]);
29791
+ const name = args.positionals[1];
29792
+ const { removedDefs, verifier } = EntityRemoval.open(dir).remove(name);
29793
+ const rel = path45.relative(process.cwd(), dir) || ".";
29794
+ ctx.stdout(
29795
+ JSON.stringify(
29796
+ {
29797
+ status: "ok",
29798
+ entity: name,
29799
+ removedDefs,
29800
+ ...verifier ? { verifier: path45.relative(process.cwd(), verifier) || verifier } : {},
29801
+ file: path45.relative(process.cwd(), path45.join(dir, "schema", "world.json")),
29802
+ next: [`gateway worlds schema compile ${rel}`, `gateway worlds schema check ${rel}`]
29803
+ },
29804
+ null,
29805
+ 2
29806
+ )
29807
+ );
29808
+ }
29809
+ });
29810
+ }
29811
+
29812
+ // src/cli/runtime/scaffoldHandlers.ts
29813
+ var fs60 = __toESM(require("fs"));
29814
+ var path46 = __toESM(require("path"));
29815
+ init_router();
29816
+ var PYTHON_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
29817
+ var HANDLERS_FILE = "api/handlers.py";
29818
+ var HEADER = '"""The world\'s own logic. Each connector.toml operation with action = "handler" calls the\nfunction it names here as fn(ctx, args, query, body), which answers (status, body) or a body;\n`ctx` reads and writes the store (rows, get, insert, update, delete) and mints ids and times."""\n';
29819
+ var HandlerStub = class {
29820
+ constructor(dir, name) {
29821
+ this.name = name;
29822
+ if (!PYTHON_NAME.test(name))
29823
+ throw new CliError(`--handler is a Python function name ([A-Za-z_][A-Za-z0-9_]*), got ${JSON.stringify(name)}`);
29824
+ this.file = path46.join(dir, HANDLERS_FILE);
29825
+ }
29826
+ name;
29827
+ file;
29828
+ get source() {
29829
+ return fs60.existsSync(this.file) ? fs60.readFileSync(this.file, "utf8") : void 0;
29830
+ }
29831
+ get defined() {
29832
+ const source2 = this.source ?? "";
29833
+ const imported = [...source2.matchAll(/^from\s+\S+\s+import\s+(\([^)]*\)|[^\n]*)/gm)].some(
29834
+ (m) => new RegExp(`\\b${this.name}\\b`).test(m[1])
29835
+ );
29836
+ return imported || new RegExp(`^(?:(?:async\\s+)?def\\s+${this.name}\\s*\\(|${this.name}\\s*=)`, "m").test(source2);
29837
+ }
29838
+ stub() {
29839
+ return `def ${this.name}(ctx, args, query, body):
29840
+ return 501, {"error": "not_implemented", "detail": "${this.name} in ${HANDLERS_FILE} is a stub"}
29841
+ `;
29842
+ }
29843
+ /** Writes the stub unless the function exists; true when it wrote. */
29844
+ ensure() {
29845
+ if (this.defined) return false;
29846
+ const current = this.source;
29847
+ fs60.mkdirSync(path46.dirname(this.file), { recursive: true });
29848
+ const head = current === void 0 ? HEADER : current.replace(/\n*$/, "\n");
29849
+ fs60.writeFileSync(this.file, `${head}
29850
+
29851
+ ${this.stub()}`);
29852
+ return true;
29853
+ }
29854
+ };
29855
+
29015
29856
  // src/cli/runtime/scaffold.ts
29016
29857
  var ENTITY_NAME = /^[A-Za-z][A-Za-z0-9_]*$/;
29017
29858
  var MAX_ENTITY_NAME = 64;
@@ -29285,11 +30126,11 @@ function removeDependency(toml, alias) {
29285
30126
  return kept.join("\n") + "\n";
29286
30127
  }
29287
30128
  function dependencyServes(depDir) {
29288
- const manifest = path42.join(depDir, "gateway-env.toml");
29289
- if (!fs56.existsSync(manifest)) return void 0;
29290
- const tools = manifestServedTools(fs56.readFileSync(manifest, "utf8"));
29291
- const connector = path42.join(depDir, "connector.toml");
29292
- const routes = fs56.existsSync(connector) ? declaredRoutes(fs56.readFileSync(connector, "utf8")).map((r) => r.name).filter(Boolean) : [];
30129
+ const manifest = path47.join(depDir, "gateway-env.toml");
30130
+ if (!fs61.existsSync(manifest)) return void 0;
30131
+ const tools = manifestServedTools(fs61.readFileSync(manifest, "utf8"));
30132
+ const connector = path47.join(depDir, "connector.toml");
30133
+ const routes = fs61.existsSync(connector) ? declaredRoutes(fs61.readFileSync(connector, "utf8")).map((r) => r.name).filter(Boolean) : [];
29293
30134
  return tools === void 0 ? void 0 : { tools, routes };
29294
30135
  }
29295
30136
  function addDependency(toml, spec, depServes, opts = {}) {
@@ -29302,7 +30143,7 @@ function addDependency(toml, spec, depServes, opts = {}) {
29302
30143
  toml = removeDependency(toml, spec.alias);
29303
30144
  }
29304
30145
  if (!PIN.test(spec.pin)) throw new CliError(`--pin is <slug>@<ref>, got ${JSON.stringify(spec.pin)}`);
29305
- if (path42.isAbsolute(spec.path)) throw new CliError("The dependency path is stored relative to the world");
30146
+ if (path47.isAbsolute(spec.path)) throw new CliError("The dependency path is stored relative to the world");
29306
30147
  if (depServes) {
29307
30148
  const serves = Array.isArray(depServes) ? { tools: depServes, routes: [] } : depServes;
29308
30149
  for (const tool of spec.tools)
@@ -29372,42 +30213,37 @@ function dependencyPath(toml, alias) {
29372
30213
  return void 0;
29373
30214
  }
29374
30215
  function readManifest2(dir) {
29375
- const file = path42.join(dir, "gateway-env.toml");
29376
- if (!fs56.existsSync(file)) throw new CliError(`${dir} holds no gateway-env.toml; run \`gateway worlds schema init\` first`, 1);
29377
- return { file, toml: fs56.readFileSync(file, "utf8") };
29378
- }
29379
- function verifierNames2(dir) {
29380
- const folder = path42.join(dir, "verifiers");
29381
- if (!fs56.existsSync(folder)) return void 0;
29382
- return fs56.readdirSync(folder).filter((f) => f.endsWith(".sql")).map((f) => f.slice(0, -4)).sort();
30216
+ const file = path47.join(dir, "gateway-env.toml");
30217
+ if (!fs61.existsSync(file)) throw new CliError(`${dir} holds no gateway-env.toml; run \`gateway worlds schema init\` first`, 1);
30218
+ return { file, toml: fs61.readFileSync(file, "utf8") };
29383
30219
  }
29384
- var toPosix = (p) => p.split(path42.sep).join("/");
30220
+ var toPosix = (p) => p.split(path47.sep).join("/");
29385
30221
  var pinSlug = (name) => name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "") || "world";
29386
30222
  function declaredEntities(dir) {
29387
- const file = path42.join(dir, "schema", "world.json");
29388
- if (!fs56.existsSync(file)) return void 0;
30223
+ const file = path47.join(dir, "schema", "world.json");
30224
+ if (!fs61.existsSync(file)) return void 0;
29389
30225
  const gateway = readJsonFile2(file)["x-gateway"];
29390
30226
  return isObject12(gateway) && isObject12(gateway.entities) ? Object.keys(gateway.entities) : [];
29391
30227
  }
29392
30228
  function worldEntityShapes(dir) {
29393
- const file = path42.join(dir, "schema", "world.json");
29394
- return fs56.existsSync(file) ? declaredEntityShapes(readJsonFile2(file)) : void 0;
30229
+ const file = path47.join(dir, "schema", "world.json");
30230
+ return fs61.existsSync(file) ? declaredEntityShapes(readJsonFile2(file)) : void 0;
29395
30231
  }
29396
30232
  function declaredHandlerTools(dir) {
29397
- const file = path42.join(dir, "schema", "world.json");
29398
- if (!fs56.existsSync(file)) return [];
30233
+ const file = path47.join(dir, "schema", "world.json");
30234
+ if (!fs61.existsSync(file)) return [];
29399
30235
  const gateway = readJsonFile2(file)["x-gateway"];
29400
30236
  return isObject12(gateway) && isObject12(gateway.tools) ? Object.keys(gateway.tools) : [];
29401
30237
  }
29402
30238
  var WORLD_SLUG = /^[a-z0-9][a-z0-9-]*$/;
29403
30239
  function connectorTomlSkeleton(dir) {
29404
- const manifest = path42.join(dir, "gateway-env.toml");
29405
- if (!fs56.existsSync(dir))
30240
+ const manifest = path47.join(dir, "gateway-env.toml");
30241
+ if (!fs61.existsSync(dir))
29406
30242
  throw new CliError(`${dir} does not exist; run \`gateway worlds schema init ${dir} --connector custom\` to start a world there`, 1);
29407
- if (!fs56.existsSync(manifest))
30243
+ if (!fs61.existsSync(manifest))
29408
30244
  throw new CliError(`${dir} holds no connector.toml and no gateway-env.toml (not a world); run \`gateway worlds schema init ${dir} --connector custom\` first`, 1);
29409
- const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(fs56.readFileSync(manifest, "utf8"))?.[1];
29410
- const slug = name && WORLD_SLUG.test(name) ? name : path42.basename(dir).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "world";
30245
+ const name = /^\s*name\s*=\s*"([^"]*)"/m.exec(fs61.readFileSync(manifest, "utf8"))?.[1];
30246
+ const slug = name && WORLD_SLUG.test(name) ? name : path47.basename(dir).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "world";
29411
30247
  return [
29412
30248
  `# ${slug}'s API surface: the HTTP routes the world serves beside its tools, from one`,
29413
30249
  "# World Host session. Declare routes with `gateway worlds connector route add`; an",
@@ -29415,70 +30251,14 @@ function connectorTomlSkeleton(dir) {
29415
30251
  "[connector]",
29416
30252
  `slug = "${slug}"`,
29417
30253
  `base_url = "https://${slug}.example"`,
30254
+ "",
30255
+ "# A hosted session's api token is a bearer; `gateway worlds serve` accepts the one --api-key pins (default `conform`).",
30256
+ "[auth]",
30257
+ 'scheme = "bearer"',
30258
+ `secret_env = "${slug.toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_API_KEY"`,
29418
30259
  ""
29419
30260
  ].join("\n");
29420
30261
  }
29421
- var SCAFFOLD_VERIFIER = /^-- Scores 1\.0 once the world holds any (\S+) row; edit for real tasks\.\n/;
29422
- function scaffoldVerifier(entity) {
29423
- return `-- Scores 1.0 once the world holds any ${entity} row; edit for real tasks.
29424
- SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}";
29425
- `;
29426
- }
29427
- function verifierSql(name, entity, where) {
29428
- if (!/^[A-Za-z_][A-Za-z0-9_-]*$/.test(name)) throw new CliError(`Verifier names match [A-Za-z_][A-Za-z0-9_-]*, got ${JSON.stringify(name)}`);
29429
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(entity)) throw new CliError(`Entity names match [A-Za-z_][A-Za-z0-9_]*, got ${JSON.stringify(entity)}`);
29430
- if (where === void 0) return scaffoldVerifier(entity);
29431
- const clause = where.trim();
29432
- if (!clause) throw new CliError("--where is a SQL condition over the entity's columns; it cannot be empty");
29433
- const defect = whereClauseDefect(clause);
29434
- if (defect)
29435
- throw new CliError(
29436
- `--where ${JSON.stringify(clause)} cannot be a SQL condition: ${defect}. The file would fail \`gateway worlds schema check\` at once; fix the condition here instead.`
29437
- );
29438
- return `-- ${name}: scores 1.0 once a ${entity} row satisfies the condition; edit for real tasks.
29439
- -- A verifier is one SQL statement returning one number in 0..1 (0.5 is partial credit).
29440
- SELECT CASE WHEN COUNT(*) > 0 THEN 1.0 ELSE 0.0 END FROM "${entity}" WHERE ${clause};
29441
- `;
29442
- }
29443
- function whereClauseDefect(clause) {
29444
- let depth = 0;
29445
- let quote;
29446
- for (const ch of clause) {
29447
- if (quote) {
29448
- if (ch === quote) quote = void 0;
29449
- continue;
29450
- }
29451
- if (ch === "'" || ch === '"') quote = ch;
29452
- else if (ch === "(") depth += 1;
29453
- else if (ch === ")") depth -= 1;
29454
- else if (ch === ";") return "a `;` would end the statement early; a verifier is one SQL statement";
29455
- if (depth < 0) return "a `)` closes a parenthesis that was never opened";
29456
- }
29457
- if (quote) return `a ${quote} quote is never closed`;
29458
- if (depth > 0) return `${depth} parenthes${depth === 1 ? "is is" : "es are"} never closed`;
29459
- if (/(?:^|[\s(])(?:AND|OR|NOT|IN|IS|LIKE|BETWEEN)$/i.test(clause) || /[=<>!+\-*/,(]$/.test(clause))
29460
- return "it ends in an operator with nothing after it";
29461
- return void 0;
29462
- }
29463
- function addVerifier(dir, name, entity, where) {
29464
- const sql = verifierSql(name, entity, where);
29465
- const file = path42.join(dir, "verifiers", `${name}.sql`);
29466
- if (fs56.existsSync(file))
29467
- throw new CliError(`verifiers/${name}.sql already exists (have: ${(verifierNames2(dir) ?? []).join(", ")}); edit it, or pick another name`);
29468
- fs56.mkdirSync(path42.dirname(file), { recursive: true });
29469
- fs56.writeFileSync(file, sql);
29470
- return file;
29471
- }
29472
- function repointScaffoldVerifier(dir, entity, declared) {
29473
- const file = path42.join(dir, "verifiers", "state_present.sql");
29474
- if (!fs56.existsSync(file)) return null;
29475
- const text2 = fs56.readFileSync(file, "utf8");
29476
- const match = SCAFFOLD_VERIFIER.exec(text2);
29477
- if (!match || text2 !== scaffoldVerifier(match[1])) return null;
29478
- if (declared.includes(match[1])) return null;
29479
- fs56.writeFileSync(file, scaffoldVerifier(entity));
29480
- return file;
29481
- }
29482
30262
  function parsePairs(values, flag) {
29483
30263
  const out = {};
29484
30264
  for (const item of values) {
@@ -29493,7 +30273,8 @@ function registerScaffoldCommands(worlds) {
29493
30273
  "schema",
29494
30274
  "Compile and check gateway-world/1 contracts (the runtime runs on the platform)."
29495
30275
  );
29496
- schema.group("entity", "Declare entities in schema/world.json without hand-editing the catalog.").command({
30276
+ const entity = schema.group("entity", "Declare or remove entities in schema/world.json without hand-editing the catalog.");
30277
+ entity.command({
29497
30278
  name: "add",
29498
30279
  help: "Declare one entity in schema/world.json: its payload, primary key, unique keys and relationships.",
29499
30280
  positionals: [
@@ -29514,8 +30295,8 @@ function registerScaffoldCommands(worlds) {
29514
30295
  ],
29515
30296
  notes: "Exactly one of --ref, --fields or --schema. The file is rewritten with two-space indentation;\nrun `gateway worlds schema compile <path>` afterwards (the compiled contract is stale until then), then\n`gateway worlds schema check <path>` for the full contract check.",
29516
30297
  run: async (args, ctx) => {
29517
- const dir = path42.resolve(args.positionals[0]);
29518
- const file = path42.join(dir, "schema", "world.json");
30298
+ const dir = path47.resolve(args.positionals[0]);
30299
+ const file = path47.join(dir, "schema", "world.json");
29519
30300
  const root = readJsonFile2(file);
29520
30301
  let inline;
29521
30302
  const schemaFlag = arg.str(args, "schema");
@@ -29539,17 +30320,18 @@ function registerScaffoldCommands(worlds) {
29539
30320
  unique: arg.list(args, "unique").map((u) => u.split(",").map((f) => f.trim()).filter(Boolean)),
29540
30321
  relationships: arg.list(args, "relationship").map(parseRelationship)
29541
30322
  });
29542
- fs56.writeFileSync(file, JSON.stringify(document, null, 2) + "\n");
29543
- const out = { status: "ok", entity: name, declaration, file: path42.relative(process.cwd(), file) || file };
30323
+ fs61.writeFileSync(file, JSON.stringify(document, null, 2) + "\n");
30324
+ const out = { status: "ok", entity: name, declaration, file: path47.relative(process.cwd(), file) || file };
29544
30325
  if (def) out.def = def;
29545
30326
  const verifier = repointScaffoldVerifier(dir, name, declaredEntities(dir) ?? []);
29546
30327
  if (verifier) {
29547
- out.verifier = path42.relative(process.cwd(), verifier) || verifier;
30328
+ out.verifier = path47.relative(process.cwd(), verifier) || verifier;
29548
30329
  ctx.stderr(`# ${out.verifier} named an entity the catalog no longer declares; it now scores over ${name}`);
29549
30330
  }
29550
30331
  ctx.stdout(JSON.stringify(out, null, 2));
29551
30332
  }
29552
30333
  });
30334
+ registerEntityRemove(entity);
29553
30335
  schema.group("verifier", "Write verifiers/<name>.sql: the SQL that grades a task on the world's end state.").command({
29554
30336
  name: "add",
29555
30337
  help: "Scaffold one verifier: a SQL statement over an entity's table returning 1.0 when a row satisfies --where (or any row exists).",
@@ -29563,22 +30345,22 @@ function registerScaffoldCommands(worlds) {
29563
30345
  ],
29564
30346
  notes: "A verifier is one SQL statement returning one number in 0..1 (1.0 passed, 0.0 failed, in between partial\ncredit); each entity is a table named as in the catalog, each field a column. Edit the file freely, then\n`gateway worlds schema task add <path> <task> --verifier <name>` grades a task on it.",
29565
30347
  run: async (args, ctx) => {
29566
- const dir = path42.resolve(args.positionals[0]);
30348
+ const dir = path47.resolve(args.positionals[0]);
29567
30349
  const name = args.positionals[1];
29568
- const entity = arg.str(args, "entity");
30350
+ const entity2 = arg.str(args, "entity");
29569
30351
  const declared = declaredEntities(dir);
29570
30352
  if (declared === void 0) throw new CliError(`${dir} has no schema/world.json; run \`gateway worlds schema init ${args.positionals[0]} --connector custom\` first`);
29571
- if (!entity) throw new CliError(`--entity is required: one of ${declared.join(", ") || "(declare one with `gateway worlds schema entity add` first)"}`);
29572
- if (!declared.includes(entity)) throw new CliError(`Unknown entity ${entity}; the world has ${declared.join(", ") || "none"}`);
29573
- const file = addVerifier(dir, name, entity, arg.str(args, "where"));
29574
- const rel = path42.relative(process.cwd(), dir) || ".";
30353
+ if (!entity2) throw new CliError(`--entity is required: one of ${declared.join(", ") || "(declare one with `gateway worlds schema entity add` first)"}`);
30354
+ if (!declared.includes(entity2)) throw new CliError(`Unknown entity ${entity2}; the world has ${declared.join(", ") || "none"}`);
30355
+ const file = addVerifier(dir, name, entity2, arg.str(args, "where"));
30356
+ const rel = path47.relative(process.cwd(), dir) || ".";
29575
30357
  ctx.stdout(
29576
30358
  JSON.stringify(
29577
30359
  {
29578
30360
  status: "ok",
29579
30361
  verifier: name,
29580
- entity,
29581
- file: path42.relative(process.cwd(), file) || file,
30362
+ entity: entity2,
30363
+ file: path47.relative(process.cwd(), file) || file,
29582
30364
  next: `gateway worlds schema task add ${rel} <task_id> --prompt "<what the agent is told>" --verifier ${name}`
29583
30365
  },
29584
30366
  null,
@@ -29615,39 +30397,39 @@ function registerScaffoldCommands(worlds) {
29615
30397
  ],
29616
30398
  notes: "The block is appended; existing text is untouched. `path` is written relative to the world so\n`schema check`, `test`, `serve` and `call` open the dependency here; the pin is what the platform\nresolves when both worlds are pushed. Then `gateway worlds schema check <path>` shows the link under\n`dependencies`, and `gateway worlds schema task add` grades it with --world <alias>=<verifier>.",
29617
30399
  run: async (args, ctx) => {
29618
- const dir = path42.resolve(args.positionals[0]);
30400
+ const dir = path47.resolve(args.positionals[0]);
29619
30401
  const alias = args.positionals[1];
29620
30402
  const depArg = args.positionals[2];
29621
- const depDir = path42.resolve(depArg);
30403
+ const depDir = path47.resolve(depArg);
29622
30404
  const { file, toml } = readManifest2(dir);
29623
- if (!fs56.existsSync(path42.join(depDir, "gateway-env.toml"))) {
29624
- const fromWorld = path42.resolve(dir, depArg);
29625
- const hint = fromWorld !== depDir && fs56.existsSync(path42.join(fromWorld, "gateway-env.toml")) ? `; paths resolve from your shell, not from the world: did you mean ${path42.relative(process.cwd(), fromWorld) || "."}?` : "";
30405
+ if (!fs61.existsSync(path47.join(depDir, "gateway-env.toml"))) {
30406
+ const fromWorld = path47.resolve(dir, depArg);
30407
+ const hint = fromWorld !== depDir && fs61.existsSync(path47.join(fromWorld, "gateway-env.toml")) ? `; paths resolve from your shell, not from the world: did you mean ${path47.relative(process.cwd(), fromWorld) || "."}?` : "";
29626
30408
  throw new CliError(
29627
30409
  `${depDir} holds no gateway-env.toml; the dependency must be a schema world (\`gateway worlds schema init\`)${hint}`,
29628
30410
  1
29629
30411
  );
29630
30412
  }
29631
- if (path42.resolve(depDir) === dir) throw new CliError("A world cannot depend on itself");
29632
- const depToml = fs56.readFileSync(path42.join(depDir, "gateway-env.toml"), "utf8");
30413
+ if (path47.resolve(depDir) === dir) throw new CliError("A world cannot depend on itself");
30414
+ const depToml = fs61.readFileSync(path47.join(depDir, "gateway-env.toml"), "utf8");
29633
30415
  if (declaredAliases(depToml).length)
29634
30416
  throw new CliError(`${depDir} has [dependencies] of its own (${declaredAliases(depToml).join(", ")}); links nest one level`);
29635
30417
  const task = arg.str(args, "task");
29636
- if (task !== void 0 && !fs56.existsSync(path42.join(depDir, "scenarios", task))) {
29637
- const have = fs56.existsSync(path42.join(depDir, "scenarios")) ? fs56.readdirSync(path42.join(depDir, "scenarios")) : [];
30418
+ if (task !== void 0 && !fs61.existsSync(path47.join(depDir, "scenarios", task))) {
30419
+ const have = fs61.existsSync(path47.join(depDir, "scenarios")) ? fs61.readdirSync(path47.join(depDir, "scenarios")) : [];
29638
30420
  throw new CliError(`${depDir} has no scenarios/${task}/ (have: ${have.join(", ") || "none"})`);
29639
30421
  }
29640
- const rel = toPosix(path42.relative(dir, depDir)) || ".";
30422
+ const rel = toPosix(path47.relative(dir, depDir)) || ".";
29641
30423
  const spec = {
29642
30424
  alias,
29643
- pin: arg.str(args, "pin") ?? `${pinSlug(manifestName(depToml) ?? path42.basename(depDir))}@main`,
30425
+ pin: arg.str(args, "pin") ?? `${pinSlug(manifestName(depToml) ?? path47.basename(depDir))}@main`,
29644
30426
  path: rel.startsWith(".") ? rel : `./${rel}`,
29645
30427
  task,
29646
30428
  tools: arg.list(args, "tools").flatMap((t) => t.split(",")).map((t) => t.trim()).filter(Boolean),
29647
30429
  entities: arg.list(args, "map").map(parseEntityMap)
29648
30430
  };
29649
30431
  const updated = addDependency(toml, spec, dependencyServes(depDir), { replace: arg.bool(args, "replace") });
29650
- fs56.writeFileSync(file, updated);
30432
+ fs61.writeFileSync(file, updated);
29651
30433
  ctx.stdout(
29652
30434
  JSON.stringify(
29653
30435
  {
@@ -29657,9 +30439,9 @@ function registerScaffoldCommands(worlds) {
29657
30439
  path: spec.path,
29658
30440
  task: spec.task ?? null,
29659
30441
  tools: spec.tools.map((t) => `${alias}.${t}`),
29660
- verifiers: (verifierNames2(depDir) ?? []).map((v) => `${alias}/${v}`),
29661
- file: path42.relative(process.cwd(), file) || file,
29662
- next: `gateway worlds schema check ${path42.relative(process.cwd(), dir) || "."}`
30442
+ verifiers: (verifierNames(depDir) ?? []).map((v) => `${alias}/${v}`),
30443
+ file: path47.relative(process.cwd(), file) || file,
30444
+ next: `gateway worlds schema check ${path47.relative(process.cwd(), dir) || "."}`
29663
30445
  },
29664
30446
  null,
29665
30447
  2
@@ -29690,7 +30472,7 @@ function registerScaffoldCommands(worlds) {
29690
30472
  ],
29691
30473
  notes: "Verifiers are SQL files returning one number in 0..1; each becomes a key in `rewards` (`slack/state_present`\nfor a dependency's). Then `gateway worlds schema check <path>` lists the task, and\n`gateway worlds serve <path> --task <id>` opens a session on it.\nAn id that is already declared (benchmarks init pre-declares one graded by its placeholder verifier)\nis refused unless --replace, which swaps that block for this one.",
29692
30474
  run: async (args, ctx) => {
29693
- const dir = path42.resolve(args.positionals[0]);
30475
+ const dir = path47.resolve(args.positionals[0]);
29694
30476
  const { file, toml } = readManifest2(dir);
29695
30477
  const prompt = arg.str(args, "prompt");
29696
30478
  if (prompt === void 0) throw new CliError("--prompt is required: what the agent is told");
@@ -29706,7 +30488,7 @@ function registerScaffoldCommands(worlds) {
29706
30488
  const depVerifiers = {};
29707
30489
  for (const alias of Object.keys(worlds2)) {
29708
30490
  const rel = dependencyPath(toml, alias);
29709
- if (rel !== void 0) depVerifiers[alias] = verifierNames2(path42.resolve(dir, rel));
30491
+ if (rel !== void 0) depVerifiers[alias] = verifierNames(path47.resolve(dir, rel));
29710
30492
  }
29711
30493
  const spec = {
29712
30494
  id: args.positionals[1],
@@ -29717,10 +30499,10 @@ function registerScaffoldCommands(worlds) {
29717
30499
  const updated = addTask(
29718
30500
  toml,
29719
30501
  spec,
29720
- { verifiers: verifierNames2(dir), depVerifiers },
30502
+ { verifiers: verifierNames(dir), depVerifiers },
29721
30503
  { replace: arg.bool(args, "replace") }
29722
30504
  );
29723
- fs56.writeFileSync(file, updated);
30505
+ fs61.writeFileSync(file, updated);
29724
30506
  ctx.stdout(
29725
30507
  JSON.stringify(
29726
30508
  {
@@ -29730,11 +30512,11 @@ function registerScaffoldCommands(worlds) {
29730
30512
  verifiers: spec.verifiers,
29731
30513
  worlds: worlds2,
29732
30514
  rewards: [...spec.verifiers, ...Object.entries(worlds2).flatMap(([a, names]) => names.map((n) => `${a}/${n}`))],
29733
- file: path42.relative(process.cwd(), file) || file,
30515
+ file: path47.relative(process.cwd(), file) || file,
29734
30516
  next: [
29735
- `gateway worlds schema compile ${path42.relative(process.cwd(), dir) || "."} # a manifest edit invalidates the compiled contract`,
29736
- `gateway worlds schema check ${path42.relative(process.cwd(), dir) || "."}`,
29737
- `gateway worlds serve ${path42.relative(process.cwd(), dir) || "."} --task ${spec.id}`
30517
+ `gateway worlds schema compile ${path47.relative(process.cwd(), dir) || "."} # a manifest edit invalidates the compiled contract`,
30518
+ `gateway worlds schema check ${path47.relative(process.cwd(), dir) || "."}`,
30519
+ `gateway worlds serve ${path47.relative(process.cwd(), dir) || "."} --task ${spec.id}`
29738
30520
  ]
29739
30521
  },
29740
30522
  null,
@@ -29783,11 +30565,11 @@ function registerScaffoldCommands(worlds) {
29783
30565
  { name: "handler", help: "Function in api/handlers.py (with --action handler)." },
29784
30566
  { name: "replace", help: "Rewrite the existing [[operations]] block of this name instead of refusing it.", boolean: true }
29785
30567
  ],
29786
- notes: "A schema world with no connector.toml yet gets one: [connector] slug from its [environment] name, a\nplaceholder base_url, then this route. That file is the world's API surface, served with its tools.\nExisting text is untouched; the block is appended. With --replace the block already declared under this\nname (and its [operations.api]) is removed first and the new one appended, every other byte kept.\n--entity must already be declared in schema/world.json (`gateway worlds schema entity add`). A create\nroute mints its entity's primary key (uuid, or int for an integer key) unless --body maps it or\n--generate names it, so a POST without an id is created rather than refused. Then\n`gateway worlds connector validate <path>`.",
30568
+ notes: "A schema world with no connector.toml yet gets one: [connector] slug from its [environment] name, a\nplaceholder base_url, then this route. That file is the world's API surface, served with its tools.\nExisting text is untouched; the block is appended. With --replace the block already declared under this\nname (and its [operations.api]) is removed first and the new one appended, every other byte kept.\n--entity must already be declared in schema/world.json (`gateway worlds schema entity add`). A create\nroute mints its entity's primary key (uuid, or int for an integer key) unless --body maps it or\n--generate names it, so a POST without an id is created rather than refused. --action handler\n--handler <fn> writes a 501 stub def <fn>(ctx, args, query, body) into api/handlers.py unless it is\ndefined there already. A new connector.toml starts with [auth] scheme = \"bearer\": the token a hosted\nsession hands the agent; `worlds serve` accepts the bearer --api-key pins (default `conform`). Then\n`gateway worlds connector validate <path>`.",
29787
30569
  run: async (args, ctx) => {
29788
- const dir = path42.resolve(args.positionals[0]);
29789
- const file = path42.join(dir, "connector.toml");
29790
- const created = !fs56.existsSync(file);
30570
+ const dir = path47.resolve(args.positionals[0]);
30571
+ const file = path47.join(dir, "connector.toml");
30572
+ const created = !fs61.existsSync(file);
29791
30573
  const routePath = arg.str(args, "path");
29792
30574
  if (routePath === void 0) throw new CliError("--path is required, e.g. --path /users");
29793
30575
  const spec = {
@@ -29810,13 +30592,15 @@ function registerScaffoldCommands(worlds) {
29810
30592
  }
29811
30593
  };
29812
30594
  const replace = arg.bool(args, "replace");
29813
- const current = created ? connectorTomlSkeleton(dir) : fs56.readFileSync(file, "utf8");
30595
+ const handler = spec.api.action === "handler" && spec.api.handler ? new HandlerStub(dir, spec.api.handler) : void 0;
30596
+ const current = created ? connectorTomlSkeleton(dir) : fs61.readFileSync(file, "utf8");
29814
30597
  const updated = addRoute(current, spec, declaredEntities(dir), {
29815
30598
  replace,
29816
30599
  handlerTools: declaredHandlerTools(dir),
29817
30600
  entities: worldEntityShapes(dir)
29818
30601
  });
29819
- fs56.writeFileSync(file, updated);
30602
+ fs61.writeFileSync(file, updated);
30603
+ const written = handler?.ensure();
29820
30604
  ctx.stdout(
29821
30605
  JSON.stringify(
29822
30606
  {
@@ -29827,7 +30611,8 @@ function registerScaffoldCommands(worlds) {
29827
30611
  entity: spec.entity ?? null,
29828
30612
  ...replace ? { replaced: true } : {},
29829
30613
  ...created ? { created: true } : {},
29830
- file: path42.relative(process.cwd(), file) || file
30614
+ ...handler ? { handler: { file: HANDLERS_FILE, function: handler.name, written } } : {},
30615
+ file: path47.relative(process.cwd(), file) || file
29831
30616
  },
29832
30617
  null,
29833
30618
  2
@@ -29862,13 +30647,13 @@ function registerRuntimeCommands(root) {
29862
30647
  }
29863
30648
 
29864
30649
  // src/cli/version.ts
29865
- var fs57 = __toESM(require("fs"));
29866
- var path43 = __toESM(require("path"));
30650
+ var fs62 = __toESM(require("fs"));
30651
+ var path48 = __toESM(require("path"));
29867
30652
  function cliVersion() {
29868
- if (true) return "0.3.0";
30653
+ if (true) return "0.3.1";
29869
30654
  if (typeof __dirname !== "string") return "unknown";
29870
30655
  try {
29871
- const pkg = JSON.parse(fs57.readFileSync(path43.resolve(__dirname, "../../package.json"), "utf8"));
30656
+ const pkg = JSON.parse(fs62.readFileSync(path48.resolve(__dirname, "../../package.json"), "utf8"));
29872
30657
  return pkg.version ?? "unknown";
29873
30658
  } catch {
29874
30659
  return "unknown";