@assemblyline/al-orc 0.4.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.0] - 2026-12-03
11
+
12
+ ### Changed
13
+ - `stations pull` writes a station's config as `"config": { … }`. A local file that still has
14
+ `steps` (a factory not yet on lib-factory 0.41's `defineStation`) keeps `steps` instead.
15
+ `stations push` sends whichever the file has; the orchestrator keeps the two in step.
16
+ - `stations run --set` sends `config_overrides` (the orchestrator's new name for
17
+ `step_overrides`).
18
+
19
+ ## [0.6.0] - 2026-12-02
20
+
21
+ ### Added
22
+ - `stations push` and `pull` carry a station's `conveyor` (`{ "from": … }`). The file is the
23
+ truth: a file without one clears it in the orchestrator.
24
+
25
+ ## [0.5.0] - 2026-12-02
26
+
27
+ ### Changed (breaking)
28
+
29
+ - `stations run` takes per-run step overrides as `--set key=value` (repeatable; the value is
30
+ read as JSON, else text), the same spelling as lib-factory's `factory steps run --set`. A bare
31
+ `--key=value` is now rejected as an unknown argument, so a typo no longer becomes an override.
32
+
33
+ ### Removed (breaking)
34
+
35
+ - `stations run --scenario` and station scenarios (`.orchestrator/scenarios/stations/`).
36
+
10
37
  ## [0.4.1] - 2026-11-05
11
38
 
12
39
  ### Changed
package/README.md CHANGED
@@ -10,6 +10,7 @@ al-orc login # pick orgs in the browser; one p
10
10
  al-orc status # org and key the profile belongs to
11
11
  al-orc lines push --all && al-orc stations push --all # from a factory repo root
12
12
  al-orc stations run EX0
13
+ al-orc stations run EX1 --set dry_run=true # change a step config key for this run
13
14
  al-orc work-records list --station EX0
14
15
  ```
15
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assemblyline/al-orc",
3
- "version": "0.4.1",
3
+ "version": "0.7.0",
4
4
  "description": "Assembly Line Orchestrator client + al-orc CLI (2-in-1): push lines and stations, run them, read work records.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -41,13 +41,15 @@ export function buildStationsSubcommands(yargs) {
41
41
  )
42
42
  .command(
43
43
  'run <id>',
44
- 'Trigger an orchestrator run (--scenario <name> + extra --key=value flags become per-run step overrides)',
44
+ 'Trigger an orchestrator run (--set key=value changes a step config key for this run)',
45
45
  (y) =>
46
46
  localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' }))
47
- .option('scenario', { describe: 'Apply a local station scenario (.orchestrator/scenarios/stations/<code>/)', type: 'string' })
48
- .option('json', { describe: 'Output raw JSON', type: 'boolean' })
49
- // Any other --key=value is a step override, so unknown flags are the point here.
50
- .strict(false),
47
+ .option('set', {
48
+ describe: 'Change a config key in every step for this run; repeatable. The value is read as JSON (true, 2, "x"), else text',
49
+ type: 'string',
50
+ array: true,
51
+ })
52
+ .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
51
53
  safe(runStationHandler),
52
54
  )
53
55
  .command(
@@ -102,20 +102,23 @@ async function pushByFilename(orc, cache, filename, { force = false } = {}) {
102
102
  }
103
103
 
104
104
  if (!station.id) {
105
- const { created_at, org, tags, ...createData } = station;
106
- createData.dependencies = await resolveDependencies(orc, cache, createData.dependencies);
107
- const created = await orc.stations.create(createData);
108
- const newPath = finalizeNewStationFile(filename, created);
109
- console.log(`Created: ${created.id} -> ${newPath}`);
105
+ const { created_at, org, tags, ...create_data } = station;
106
+ create_data.dependencies = await resolveDependencies(orc, cache, create_data.dependencies);
107
+ create_data.conveyor = station.conveyor ?? null;
108
+ const created = await orc.stations.create(create_data);
109
+ const new_path = finalizeNewStationFile(filename, created);
110
+ console.log(`Created: ${created.id} -> ${new_path}`);
110
111
  await syncTags(orc, created.id, tags);
111
112
  return;
112
113
  }
113
114
 
114
- const { id, created_at, org, tags, ...updateData } = station;
115
- updateData.dependencies = await resolveDependencies(orc, cache, updateData.dependencies);
115
+ const { id, created_at, org, tags, ...update_data } = station;
116
+ update_data.dependencies = await resolveDependencies(orc, cache, update_data.dependencies);
117
+ // The file is the truth: a file without a conveyor clears the station's.
118
+ update_data.conveyor = station.conveyor ?? null;
116
119
 
117
120
  try {
118
- await orc.stations.update(id, updateData);
121
+ await orc.stations.update(id, update_data);
119
122
  console.log(`Updated: ${id}`);
120
123
  await syncTags(orc, id, tags);
121
124
  } catch (err) {
@@ -130,7 +133,7 @@ async function pushByFilename(orc, cache, filename, { force = false } = {}) {
130
133
  console.log(` Not visible to this org (${id}), creating with --force...`);
131
134
  let created;
132
135
  try {
133
- created = await orc.stations.create({ id, ...updateData });
136
+ created = await orc.stations.create({ id, ...update_data });
134
137
  } catch (createErr) {
135
138
  if (createErr.status === 409) {
136
139
  const label = station.short_code ? `station "${station.short_code}"` : 'station';
@@ -143,8 +146,8 @@ async function pushByFilename(orc, cache, filename, { force = false } = {}) {
143
146
  }
144
147
  throw createErr;
145
148
  }
146
- const newPath = finalizeNewStationFile(filename, created);
147
- console.log(`Created: ${created.id} -> ${newPath}`);
149
+ const new_path = finalizeNewStationFile(filename, created);
150
+ console.log(`Created: ${created.id} -> ${new_path}`);
148
151
  await syncTags(orc, created.id, tags);
149
152
  }
150
153
  }
@@ -189,25 +192,25 @@ export async function pushStationsHandler(argv) {
189
192
  console.log('');
190
193
  }
191
194
 
192
- const allPaths = listAllStationFiles();
193
- if (allPaths.length === 0) {
195
+ const all_paths = listAllStationFiles();
196
+ if (all_paths.length === 0) {
194
197
  console.log('No local stations found');
195
198
  console.log('Run "al-orc stations pull --all" first, or create a new station file');
196
199
  return;
197
200
  }
198
201
 
199
- let updatedCount = 0;
200
- let createdCount = 0;
201
- for (const filepath of allPaths) {
202
+ let updated_count = 0;
203
+ let created_count = 0;
204
+ for (const filepath of all_paths) {
202
205
  const has_id =!!loadStationByFilename(filepath).id;
203
206
  await pushByFilename(orc, cache, filepath, { force });
204
- if (has_id)updatedCount++;
205
- else createdCount++;
207
+ if (has_id)updated_count++;
208
+ else created_count++;
206
209
  }
207
210
 
208
211
  console.log('');
209
212
  const parts = [];
210
- if (updatedCount > 0) parts.push(`${updatedCount} updated`);
211
- if (createdCount > 0) parts.push(`${createdCount} created`);
213
+ if (updated_count > 0) parts.push(`${updated_count} updated`);
214
+ if (created_count > 0) parts.push(`${created_count} created`);
212
215
  console.log(`Total: ${parts.join(', ')}`);
213
216
  }
@@ -1,91 +1,50 @@
1
1
  // @ts-check
2
2
  import { clientFor } from '../_helpers.js';
3
- import { loadStation, loadStationScenario, listStationScenarios } from '../utils/station-files.js';
4
-
5
- // yargs auto-fills these on every argv; everything else is a candidate override.
6
- const YARGS_KEYS = new Set(['_', '$0', 'help', 'version', 'h', 'v', 'profile', 'org']);
7
- // Flags this command owns explicitly — not treated as step overrides.
8
- const COMMAND_KEYS = new Set(['id', 'scenario', 'json']);
9
3
 
10
4
  /**
11
- * Build the merged step-override map: a local scenario file (if any) applied
12
- * first, then direct CLI flags (which win on conflict). Any flag that isn't a
13
- * reserved/known key becomes a per-run override, shallow-merged into every
14
- * step's config server-side.
5
+ * Turn `--set key=value` flags into per-run config overrides, shallow-merged into the station's
6
+ * config by the orchestrator. The value is read as JSON (`true`, `2`, `"x"`, `[1,2]`) and,
7
+ * when it isn't JSON, kept as text. A later flag for the same key wins. The same spelling as
8
+ * lib-factory's `factory steps run --set`.
9
+ *
10
+ * @param {string[]} [sets]
11
+ * @returns {Record<string, unknown>}
15
12
  */
16
- export function buildStepOverrides(argv, station) {
13
+ export function parseSets(sets = []) {
14
+ /** @type {Record<string, unknown>} */
17
15
  const overrides = {};
18
- const fromScenario = [];
19
- const fromCli = [];
20
-
21
- if (argv.scenario) {
22
- const shortCode = station?.short_code || station?.id || argv.id;
23
- const scenario = loadStationScenario(shortCode, argv.scenario);
24
- if (scenario === null) {
25
- const available = listStationScenarios(shortCode);
26
- const hint = available.length
27
- ? `Available scenarios for ${shortCode}: ${available.join(', ')}`
28
- : `No scenarios defined under .orchestrator/scenarios/stations/${shortCode}/`;
29
- throw new Error(`Scenario not found: ${argv.scenario}\n${hint}`);
30
- }
31
- for (const [k, v] of Object.entries(scenario)) {
32
- overrides[k] = v;
33
- fromScenario.push(k);
16
+ for (const arg of sets) {
17
+ const eq = arg.indexOf('=');
18
+ if (eq < 1) throw new Error(`--set needs key=value, got: ${arg}`);
19
+ const raw = arg.slice(eq + 1);
20
+ let value;
21
+ try {
22
+ value = JSON.parse(raw);
23
+ } catch {
24
+ value = raw;
34
25
  }
26
+ overrides[arg.slice(0, eq)] = value;
35
27
  }
36
-
37
- // yargs adds a camelCase copy of every kebab-case flag (--max-files → maxFiles).
38
- // Step configs are snake_case, so a kebab flag becomes max_files and its
39
- // camelCase copy is dropped.
40
- const camel_copies = new Set(
41
- Object.keys(argv).filter((k) => k.includes('-')).map((k) => k.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase())),
42
- );
43
- for (const [k, v] of Object.entries(argv)) {
44
- if (YARGS_KEYS.has(k) || COMMAND_KEYS.has(k) || camel_copies.has(k)) continue;
45
- const key = k.replace(/-/g, '_');
46
- overrides[key] = v;
47
- fromCli.push(key);
48
- }
49
-
50
- return { overrides, fromScenario, fromCli };
51
- }
52
-
53
- function formatOverridesLine(overrides, fromScenario, fromCli, scenarioName) {
54
- return Object.entries(overrides)
55
- .map(([k, v]) => {
56
- const sources = [];
57
- if (fromScenario.includes(k)) sources.push(`scenario ${scenarioName}`);
58
- if (fromCli.includes(k)) sources.push('CLI');
59
- return `${k}=${JSON.stringify(v)} (${sources.join(' + ')})`;
60
- })
61
- .join(', ');
28
+ return overrides;
62
29
  }
63
30
 
64
31
  /** `al-orc stations run <id>` — trigger an orchestrator run; returns a work record id. */
65
32
  export async function runStationHandler(argv) {
66
- const { id, scenario, json } = argv;
67
-
68
- // A local station file is only needed to resolve short_code for scenario lookup.
69
- const station = loadStation(id);
70
- if (!station && scenario) {
71
- console.error(`Error: --scenario requires a local station definition for ${id}.`);
72
- console.error(`Run "al-orc stations pull ${id}" first.`);
73
- process.exit(1);
74
- }
75
-
76
- const { overrides, fromScenario, fromCli } = buildStepOverrides(argv, station);
77
- const hasOverrides = Object.keys(overrides).length > 0;
33
+ const { id, json } = argv;
34
+ const overrides = parseSets(argv.set);
35
+ const has_overrides = Object.keys(overrides).length > 0;
78
36
 
79
37
  const orc = clientFor();
80
- const result = await orc.stations.run(id, { overrides: hasOverrides ? overrides : undefined });
38
+ const result = await orc.stations.run(id, { overrides: has_overrides ? overrides : undefined });
81
39
 
82
40
  if (json) {
83
41
  console.log(JSON.stringify(result, null, 2));
84
42
  return;
85
43
  }
86
44
 
87
- if (hasOverrides) {
88
- console.log(`Overrides: ${formatOverridesLine(overrides, fromScenario, fromCli, scenario)}`);
45
+ if (has_overrides) {
46
+ const line = Object.entries(overrides).map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(', ');
47
+ console.log(`Overrides: ${line}`);
89
48
  }
90
49
  console.log(`Triggered: ${id}`);
91
50
  console.log(`Work Record: ${result?.work_record_id ?? '—'}`);
@@ -33,13 +33,13 @@ export function formatTable(headers, rows, options = {}) {
33
33
  const pad = (text, width, i) =>
34
34
  align[i] === 'right' ? text.padStart(width) : text.padEnd(width);
35
35
 
36
- const headerLine = headers.map((h, i) => pad(h, widths[i], i)).join(' ');
37
- const separator = '-'.repeat(headerLine.length);
36
+ const header_line = headers.map((h, i) => pad(h, widths[i], i)).join(' ');
37
+ const separator = '-'.repeat(header_line.length);
38
38
  const dataLines = rows.map((row) =>
39
39
  row.map((cell, i) => pad(cell || '—', widths[i], i)).join(' '),
40
40
  );
41
41
 
42
- return [headerLine, separator, ...dataLines].join('\n');
42
+ return [header_line, separator, ...dataLines].join('\n');
43
43
  }
44
44
 
45
45
  /**
@@ -1,21 +1,18 @@
1
1
  // @ts-check
2
2
  /**
3
- * Local station + station-scenario file cache — the bridge between the
4
- * orchestrator (remote truth) and the working tree.
3
+ * Local station file cache — the bridge between the orchestrator (remote truth)
4
+ * and the working tree.
5
5
  *
6
6
  * Station files live in: .orchestrator/stations/<short_code>__<name>.json
7
- * Station scenarios in: .orchestrator/scenarios/stations/<short_code>/<name>.json
8
7
  *
9
8
  * Line membership is encoded by the `line` field inside each JSON, not by folder
10
- * hierarchy. (Ported from cli-fob for the al-orc pull/push/run bridges; the
11
- * step scenarios live in lib-factory's `factory` command.)
9
+ * hierarchy. (Ported from cli-fob for the al-orc pull/push bridges.)
12
10
  */
13
11
 
14
12
  import fs from 'node:fs';
15
13
  import path from 'node:path';
16
14
 
17
15
  const STATIONS_DIR = '.orchestrator/stations';
18
- const SCENARIOS_DIR = '.orchestrator/scenarios';
19
16
 
20
17
  /** All station JSON file paths under `.orchestrator/stations/`. */
21
18
  function getAllStationFilePaths() {
@@ -55,6 +52,26 @@ export function findStationFile(identifier) {
55
52
  return null;
56
53
  }
57
54
 
55
+ /**
56
+ * The station as its local file holds it:
57
+ * - a station with no conveyor has no `conveyor` key, rather than `"conveyor": null`;
58
+ * - its config as `config`, unless the file it replaces still has `steps` (a factory not yet
59
+ * on lib-factory 0.41's `defineStation`), which keeps `steps` instead. The orchestrator sends
60
+ * both and keeps them in step.
61
+ *
62
+ * @param {any} station - As the API returns it
63
+ * @param {any} [previous] - The local file it replaces
64
+ */
65
+ function forLocalFile(station, previous) {
66
+ if (station.conveyor == null) delete station.conveyor;
67
+ if (previous?.steps !== undefined && previous?.config === undefined) {
68
+ delete station.config;
69
+ } else if (station.config !== undefined) {
70
+ delete station.steps;
71
+ }
72
+ return station;
73
+ }
74
+
58
75
  /** Save a station locally, removing any existing file(s) for it first. */
59
76
  export function saveStation(station) {
60
77
  const toRemove = new Set();
@@ -64,12 +81,20 @@ export function saveStation(station) {
64
81
  const existingByCode = findStationFile(station.short_code);
65
82
  if (existingByCode) toRemove.add(existingByCode);
66
83
  }
67
- for (const f of toRemove) fs.unlinkSync(f);
84
+ let previous;
85
+ for (const f of toRemove) {
86
+ try {
87
+ previous ??= JSON.parse(fs.readFileSync(f, 'utf8'));
88
+ } catch {
89
+ // a malformed file is replaced
90
+ }
91
+ fs.unlinkSync(f);
92
+ }
68
93
 
69
94
  if (!fs.existsSync(STATIONS_DIR)) fs.mkdirSync(STATIONS_DIR, { recursive: true });
70
95
 
71
96
  const filepath = path.join(STATIONS_DIR, buildFilename(station));
72
- fs.writeFileSync(filepath, JSON.stringify(station, null, 2));
97
+ fs.writeFileSync(filepath, JSON.stringify(forLocalFile(station, previous), null, 2));
73
98
  return filepath;
74
99
  }
75
100
 
@@ -123,7 +148,7 @@ export function finalizeNewStationFile(originalArg, station) {
123
148
  if (!fs.existsSync(STATIONS_DIR)) fs.mkdirSync(STATIONS_DIR, { recursive: true });
124
149
 
125
150
  const newPath = path.join(STATIONS_DIR, buildFilename(station));
126
- fs.writeFileSync(newPath, JSON.stringify(station, null, 2));
151
+ fs.writeFileSync(newPath, JSON.stringify(forLocalFile(station), null, 2));
127
152
  return newPath;
128
153
  }
129
154
 
@@ -131,22 +156,3 @@ export function finalizeNewStationFile(originalArg, station) {
131
156
  export function getStationsDir() {
132
157
  return STATIONS_DIR;
133
158
  }
134
-
135
- // --- Station scenarios (flat key→value override maps applied to a whole run) ---
136
-
137
- function getScenarioDirForStation(stationShortCode) {
138
- return path.join(SCENARIOS_DIR, 'stations', stationShortCode);
139
- }
140
-
141
- /** Scenario names available for a station (without .json). */
142
- export function listStationScenarios(stationShortCode) {
143
- const dir = getScenarioDirForStation(stationShortCode);
144
- if (!fs.existsSync(dir)) return [];
145
- return fs.readdirSync(dir).filter((f) => f.endsWith('.json')).map((f) => f.replace('.json', ''));
146
- }
147
-
148
- /** Load a station scenario (flat key→value map), or null. */
149
- export function loadStationScenario(stationShortCode, scenarioName) {
150
- const filepath = path.join(getScenarioDirForStation(stationShortCode), `${scenarioName}.json`);
151
- return fs.existsSync(filepath) ? JSON.parse(fs.readFileSync(filepath, 'utf8')) : null;
152
- }
@@ -72,12 +72,12 @@ export function buildStations(ctx) {
72
72
  unarchive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/unarchive`).then(unwrap),
73
73
 
74
74
  /**
75
- * Trigger a station run. `overrides` are shallow-merged into every step's
76
- * config server-side. Returns `{ work_record_id }`.
75
+ * Trigger a station run. `overrides` are shallow-merged into the station's config
76
+ * server-side. Returns `{ work_record_id }`.
77
77
  */
78
78
  run: (id, { overrides } = {}) => {
79
79
  const body = {};
80
- if (overrides && Object.keys(overrides).length > 0) body.step_overrides = overrides;
80
+ if (overrides && Object.keys(overrides).length > 0) body.config_overrides = overrides;
81
81
  return ctx.post(`/api/v1/stations/${enc(id)}/run`, body).then(unwrap);
82
82
  },
83
83
 
@@ -8,6 +8,7 @@
8
8
  * @property {string} line Line code. The line owns the location; a station has none of its own.
9
9
  * @property {string} [description]
10
10
  * @property {StationStep[]} [steps]
11
+ * @property {{ from: string | string[] } | null} [conveyor] Bins the factory session moves workpieces from into input/
11
12
  * @property {(string|{ id: string, short_code?: string })[]} [dependencies] Station ids or short_codes this one depends on (or station objects).
12
13
  * @property {(string|Tag)[]} [tags]
13
14
  * @property {string} [applies_to]