@zalosai/zalos-cli 0.2.32 → 0.2.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -131,6 +131,7 @@ zl execution list --limit 1
131
131
  zl execution view <id>
132
132
  zl execution summary <id>
133
133
  zl execution artifact download <artifact-id> --output /tmp/artifact
134
+ zl execution inputs <execution-id> --output /tmp/<execution-id>-inputs
134
135
  zl execution replay export <execution-id> --output .zalosai/replays/<execution-id>
135
136
  zl page list --fields id,title,updatedAt
136
137
  zl page export <page-id> --output /tmp/month-end-close.md
@@ -287,7 +288,9 @@ Downloads request a short-lived URL through the authenticated API and write to a
287
288
  file; they do not require direct S3 access. File moves remain scoped to the selected team profile.
288
289
  Execution artifact downloads use the same private-file and no-overwrite guarantees. Select the
289
290
  artifact's team before downloading; the immutable artifact API enforces that team boundary.
290
- `execution replay export` packages the selected team's ready immutable input and output artifacts
291
+ `execution inputs` lists the files an execution ran with, from every attempt and whatever its
292
+ status (cancelled and failed runs included); `--output` downloads and SHA-256-verifies them into a
293
+ new directory. `execution replay export` packages the selected team's ready immutable input and output artifacts
291
294
  with their recorded SHA-256 hashes. It verifies every downloaded byte, writes a new private local
292
295
  directory, and never prints signed URLs. Run the bundle locally with
293
296
  `uv run zalosai run --replay-bundle <directory>` from Agent Studio; this does not use database,
@@ -154,6 +154,22 @@ export function registerCloseCommand(program) {
154
154
  sources: (o.source ?? []).map(parseSourceOption),
155
155
  })));
156
156
  }));
157
+ registry
158
+ .command('import')
159
+ .description("Start a new team's registry from a Mesh document (e.g. another team's export, edited); previews unless --confirm")
160
+ .requiredOption('--team-id <ref>', 'Team public ID or UUID (select it before confirming)')
161
+ .requiredOption('--file <document.yaml>', 'Mesh registry document, YAML or JSON')
162
+ .option('--confirm <digest>', 'Publish the previewed document with its confirmation digest')
163
+ .action(async (o) => action(async () => {
164
+ const document = parseYaml(await readFile(o.file, 'utf8'));
165
+ if (!isRow(document))
166
+ throw new ValidationError('file', `${o.file} is not a registry document`);
167
+ printJson(dataRow(await client.post('/developer/finance/registry/init-document', {
168
+ teamId: resourceId(o.teamId),
169
+ document,
170
+ ...(o.confirm ? { confirm: confirmDigest(o.confirm) } : {}),
171
+ }, { timeoutMs: APPLY_TIMEOUT_MS })));
172
+ }));
157
173
  registry
158
174
  .command('export')
159
175
  .description("Print a Mesh-native team's registry document as YAML")
@@ -26,6 +26,22 @@ function isReplayBundleInput(value) {
26
26
  typeof value.fieldName === 'string' &&
27
27
  value.fieldName.length > 0);
28
28
  }
29
+ function isExecutionInputFile(value) {
30
+ return (isReplayBundleArtifact(value) &&
31
+ isRow(value) &&
32
+ (value.inputName === null || typeof value.inputName === 'string') &&
33
+ (value.attemptId === null || typeof value.attemptId === 'string'));
34
+ }
35
+ function executionInputFiles(value) {
36
+ const listing = dataRow(value);
37
+ if (typeof listing.executionId !== 'string' ||
38
+ !listing.executionId ||
39
+ (listing.status !== null && typeof listing.status !== 'string') ||
40
+ !Array.isArray(listing.inputs) ||
41
+ !listing.inputs.every(isExecutionInputFile))
42
+ throw new ApiError(502, 'Invalid execution input files response');
43
+ return { executionId: listing.executionId, status: listing.status, inputs: listing.inputs };
44
+ }
29
45
  function replayBundlePlan(value) {
30
46
  const plan = dataRow(value);
31
47
  if (plan.schemaVersion !== 1 ||
@@ -79,42 +95,6 @@ async function downloadReplayBundleArtifact(artifact, output, allowDataUrl) {
79
95
  throw new ApiError(502, `Artifact ${artifact.artifactId} hash does not match replay evidence`);
80
96
  }
81
97
  }
82
- export async function inspectRecoveryAction(id, options) {
83
- const executionId = resourceId(id);
84
- const bundle = dataRow(await client.get(`/executions/${executionId}/recovery/inspect`));
85
- if (bundle.schemaVersion !== 1 ||
86
- bundle.executionId !== executionId ||
87
- typeof bundle.sha256 !== 'string' ||
88
- !isRow(bundle.evidence) ||
89
- !Array.isArray(bundle.evidence.entries) ||
90
- !bundle.evidence.entries.every(isRow))
91
- throw new ApiError(502, 'Invalid recovery evidence bundle');
92
- const encoded = `${JSON.stringify(bundle, null, 2)}\n`;
93
- if (Buffer.byteLength(encoded) > 4 * 1024 * 1024)
94
- throw new ApiError(502, 'Recovery evidence bundle exceeds the size limit');
95
- if (options.output)
96
- await writeFile(options.output, encoded, { flag: 'wx', mode: 0o600 });
97
- if (options.json) {
98
- printJson(bundle);
99
- return;
100
- }
101
- const timeline = bundle.evidence.entries.map((entry) => {
102
- const data = isRow(entry.data) ? entry.data : {};
103
- const outcome = data.outcome ?? data.stage ?? data.status ?? '';
104
- return `${entry.sequence}. ${entry.at} ${entry.kind}: ${outcome}`;
105
- });
106
- // Terminal control characters from remote text must never be interpreted by the terminal.
107
- const text = [
108
- `Recovery evidence for ${executionId}`,
109
- ...timeline,
110
- `Bundle SHA-256: ${bundle.sha256}`,
111
- ...(options.output ? [`Saved to ${options.output}`] : []),
112
- ]
113
- .join('\n')
114
- // oxlint-disable-next-line no-control-regex -- intentional terminal output sanitization
115
- .replace(/[\u0000-\u0008\u000b-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, '');
116
- process.stdout.write(`${text}\n`);
117
- }
118
98
  export async function downloadExecutionArtifactAction(artifactId, options) {
119
99
  const id = resourceId(artifactId);
120
100
  const download = dataRow(await client.get(`/execution-artifacts/${id}/download`));
@@ -156,6 +136,40 @@ export async function exportExecutionReplayBundleAction(id, options) {
156
136
  outputs: plan.outputs.length,
157
137
  });
158
138
  }
139
+ /**
140
+ * Input files are frozen when a run starts, so they stay retrievable whatever
141
+ * the run's final status, including cancelled runs that `replay export` rejects.
142
+ */
143
+ export async function listExecutionInputFilesAction(id, options) {
144
+ const executionId = resourceId(id);
145
+ const listing = executionInputFiles(await client.get(`/executions/${executionId}/input-files`));
146
+ if (!options.output) {
147
+ printJson(listing);
148
+ return;
149
+ }
150
+ await mkdir(dirname(options.output), { recursive: true, mode: 0o700 });
151
+ await mkdir(options.output, { mode: 0o700 });
152
+ try {
153
+ const inputs = listing.inputs.map((artifact, index) => ({
154
+ ...artifact,
155
+ path: replayBundleFileName(artifact.name, index),
156
+ }));
157
+ for (const artifact of inputs) {
158
+ await downloadReplayBundleArtifact(artifact, join(options.output, artifact.path), options.allowDataUrl);
159
+ }
160
+ await writeFile(join(options.output, 'inputs.json'), `${JSON.stringify({ ...listing, inputs }, null, 2)}\n`, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
161
+ }
162
+ catch (error) {
163
+ await rm(options.output, { recursive: true, force: true });
164
+ throw error;
165
+ }
166
+ printJson({
167
+ executionId: listing.executionId,
168
+ status: listing.status,
169
+ output: options.output,
170
+ inputs: listing.inputs.length,
171
+ });
172
+ }
159
173
  export async function listExecutionsAction(options) {
160
174
  const filter = {};
161
175
  if (options.workflowId)
@@ -193,14 +207,6 @@ export async function stopExecutionAction(id) {
193
207
  }
194
208
  export function registerExecutionCommand(program) {
195
209
  const cmd = program.command('execution').description('Inspect and control workflow executions');
196
- cmd
197
- .command('recovery')
198
- .description('Owner/internal recovery evidence')
199
- .command('inspect <execution-id>')
200
- .description('Read the durable recovery timeline without contacting the provider or sandbox')
201
- .option('--output <path>', 'Save the evidence bundle to a new private JSON file')
202
- .option('--json', 'Print the full evidence bundle as JSON')
203
- .action(async (id, options) => action(() => inspectRecoveryAction(id, options)));
204
210
  cmd
205
211
  .command('list')
206
212
  .option('--workflow-id <id>', 'Workflow ID')
@@ -229,6 +235,17 @@ export function registerExecutionCommand(program) {
229
235
  allowDataUrl: ['localhost', '127.0.0.1', '[::1]'].includes(hostname),
230
236
  });
231
237
  }));
238
+ cmd
239
+ .command('inputs <execution-id>')
240
+ .description('List the input files an execution ran with, whatever its status; --output downloads them')
241
+ .option('--output <path>', 'Download every input file into a new directory')
242
+ .action(async (id, options) => action(() => {
243
+ const hostname = new URL(currentEnvironment().apiUrl).hostname;
244
+ return listExecutionInputFilesAction(id, {
245
+ ...options,
246
+ allowDataUrl: ['localhost', '127.0.0.1', '[::1]'].includes(hostname),
247
+ });
248
+ }));
232
249
  const artifact = cmd.command('artifact').description('Access immutable execution artifacts');
233
250
  artifact
234
251
  .command('download <artifact-id>')
@@ -1,6 +1,6 @@
1
1
  import { client } from '../client.js';
2
2
  import { currentEnvironment, ENVIRONMENTS } from '../environments.js';
3
- import { ApiError } from '../utils/errors.js';
3
+ import { ApiError, ValidationError } from '../utils/errors.js';
4
4
  import { printJson } from '../utils/output.js';
5
5
  import { action, resourceId } from '../utils/product-api.js';
6
6
  function inspectedVersion(identity) {
@@ -11,6 +11,17 @@ function shellArg(value) {
11
11
  }
12
12
  function renderReport(report, environment, actionKey) {
13
13
  const { worker, actions, dependencies } = report;
14
+ if (report.node) {
15
+ const { nodeName, nodeId, workflow, language, code } = report.node;
16
+ return [
17
+ worker.name + ' / ' + environment.name,
18
+ 'Action: ' + actionKey,
19
+ 'Workflow: ' + workflow.name + ' (' + workflow.id + ') · ' + inspectedVersion(workflow),
20
+ 'Node: ' + nodeName + ' (' + nodeId + ') · ' + language,
21
+ '',
22
+ code,
23
+ ].join('\n');
24
+ }
14
25
  const lines = [
15
26
  `${worker.name} ${worker.id} ${report.teamName} / ${environment.name}`,
16
27
  `${worker.visibility} · ${worker.publicationState} · ${worker.active ? 'active' : 'inactive'} · inspected ${inspectedVersion(worker)}`,
@@ -88,10 +99,19 @@ function renderReport(report, environment, actionKey) {
88
99
  }
89
100
  async function inspectWorker(id, options) {
90
101
  const environment = currentEnvironment();
91
- const query = options.action === undefined ? undefined : { action: options.action };
102
+ if (options.node !== undefined && !options.action)
103
+ throw new ValidationError('node', '--node requires --action');
104
+ const query = options.action === undefined
105
+ ? undefined
106
+ : {
107
+ action: options.action,
108
+ ...(options.node !== undefined ? { node: options.node } : {}),
109
+ };
92
110
  const { data } = await client.get(`/workers/${resourceId(id)}/inspect`, query);
93
111
  if (data?.schemaVersion !== 1 || !data.worker)
94
112
  throw new ApiError(502, 'Invalid Worker inspection response');
113
+ if (options.node !== undefined && !data.node)
114
+ throw new ApiError(502, 'Regional API did not return the requested node source');
95
115
  if (options.json || !process.stdout.isTTY)
96
116
  printJson({ ...data, environment: environment.name });
97
117
  else
@@ -104,6 +124,7 @@ export function registerWorkerCommand(program) {
104
124
  .command('inspect <id>')
105
125
  .description('Inspect the Worker configuration and its workflow dependencies')
106
126
  .option('--action <key>', 'Inspect one exact action key')
127
+ .option('--node <id>', 'Show inline code by node ID within the action (or workflow-id/node-id)')
107
128
  .option('--json', 'Print JSON (default when stdout is piped)')
108
129
  .action((id, options) => action(() => inspectWorker(id, options)));
109
130
  }
@@ -1,6 +1,8 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { ValidationError } from './utils/errors.js';
3
3
  import { isRow } from './utils/product-api.js';
4
+ // Match the API's Worker Home limit without a runtime dependency on internal workspace packages.
5
+ const WORKER_HOME_MAX_STARTERS = 4;
4
6
  export function parseWorkflowFile(raw, expectedId) {
5
7
  let value;
6
8
  try {
@@ -16,6 +18,12 @@ export function parseWorkflowFile(raw, expectedId) {
16
18
  throw new ValidationError('input', 'Workflow requires nodes array and connections object');
17
19
  if (expectedId && value.id !== undefined && value.id !== expectedId)
18
20
  throw new ValidationError('id', 'Workflow file ID does not match requested ID');
21
+ const settings = isRow(value.settings) ? value.settings : undefined;
22
+ const home = isRow(settings?.home) ? settings.home : undefined;
23
+ const starters = home?.starters;
24
+ if (Array.isArray(starters) && starters.length > WORKER_HOME_MAX_STARTERS) {
25
+ throw new ValidationError('settings.home.starters', `Use at most ${WORKER_HOME_MAX_STARTERS} starter prompts.`);
26
+ }
19
27
  return value;
20
28
  }
21
29
  export async function readWorkflowFile(path, expectedId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zalosai/zalos-cli",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
4
4
  "description": "API-only product command-line interface for Zalos",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,7 +51,7 @@
51
51
  "@types/node": "^20.0.0",
52
52
  "tsx": "^4.0.0",
53
53
  "typescript": "^5.0.0",
54
- "vitest": "3.2.7"
54
+ "vitest": "4.1.12"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public",
@@ -59,6 +59,8 @@ then download the immutable artifact through the authenticated CLI:
59
59
 
60
60
  ```bash
61
61
  zl --environment <us-prod|eu-prod> execution artifact download <artifact-id> --output /tmp/artifact
62
+ # Input files of any execution, including cancelled runs:
63
+ zl --environment <us-prod|eu-prod> execution inputs <execution-id> --output /tmp/<execution-id>-inputs
62
64
  ```
63
65
 
64
66
  ## Make controlled changes