@assemblyline/al-orc 0.7.0 → 0.10.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,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.10.0] - 2026-12-04
11
+
12
+ The Orchestrator holds every station and line definition; these commands change it there
13
+ (lib-factory simplify stage 7).
14
+
15
+ ### Added
16
+ - `stations create <code> --line --name [--from] [--config] [--set] [--schedule] …`.
17
+ - `stations edit` changes every definition field: `--set`/`--unset` a config key, `--config`,
18
+ `--from`, `--schedule`, `--timezone`, `--enabled`, `--schedule-enabled`,
19
+ `--auto-drain-enabled`, `--name`, `--description`, `--line`, besides `--short-code` and tags.
20
+ - `lines create`, `lines edit`, `lines archive`, `lines unarchive`.
21
+ - `lines export` and `lines import [--as CODE] [--location]`: copy a line and its stations.
22
+ - Restart warnings: a change the factory session reads only at start prints
23
+ `⚠ Restart the factory session at <location> …`. The client keeps them as `warnings` on the
24
+ returned record.
25
+
26
+ ### Changed
27
+ - `stations show` prints From, Enabled, Schedule and Auto-drain instead of Dependencies.
28
+
29
+ ## [0.9.0] - 2026-12-03
30
+
31
+ ### Changed
32
+ - **Breaking:** `factory-sessions show --tasks` is now `--runs`. The orchestrator reads a
33
+ session's runs from work records (the step queue is gone): outcomes by station and the
34
+ recent runs, each with its station code.
35
+
36
+ ## [0.8.0] - 2026-12-03
37
+
38
+ ### Changed
39
+ - **Breaking:** `work-records show --steps` is now `--output`: the config the run used (with
40
+ any overrides) and what its handler returned. The orchestrator no longer keeps step outputs.
41
+ - `stations list` drops the STEPS column; `stations show` prints the station's config.
42
+ - `factory-sessions show` groups outcomes and recent tasks by station.
43
+
44
+ ### Removed
45
+ - `stations pull` no longer keeps `steps` in a local file that has them: every factory is on
46
+ lib-factory 0.42, and the orchestrator refuses `steps`.
47
+ - `supporting-docs show` no longer prints a document's step.
48
+
10
49
  ## [0.7.0] - 2026-12-03
11
50
 
12
51
  ### Changed
package/README.md CHANGED
@@ -1,16 +1,19 @@
1
1
  # @assemblyline/al-orc
2
2
 
3
3
  The [Assembly Line](https://assemblyline.sh) Orchestrator's client + `al-orc` CLI — a **2-in-1**:
4
- import the client in code, or use the CLI to push lines and stations, run them, and read work
5
- records.
4
+ import the client in code, or use the CLI to create and change lines and stations, run them, and
5
+ read work records. The Orchestrator holds every line and station definition; you change it here
6
+ or in its UI, and the factory session reads it when it starts.
6
7
 
7
8
  ```bash
8
9
  npm install -g @assemblyline/al-orc
9
10
  al-orc login # pick orgs in the browser; one profile per org
10
11
  al-orc status # org and key the profile belongs to
11
- al-orc lines push --all && al-orc stations push --all # from a factory repo root
12
+ al-orc lines create EX --location my-laptop --name "Example"
13
+ al-orc stations create EX1 --line EX --name "Check" --from EX0/output --auto-drain-enabled
14
+ al-orc stations edit EX1 --set batch_size=20 # one config key; the value is read as JSON
12
15
  al-orc stations run EX0
13
- al-orc stations run EX1 --set dry_run=true # change a step config key for this run
16
+ al-orc stations run EX1 --set dry_run=true # change a config key for this run
14
17
  al-orc work-records list --station EX0
15
18
  ```
16
19
 
@@ -19,6 +22,41 @@ printed link on any device). Orgs you already have a profile for show as connect
19
22
  profile changes only when there was none. To add a key by hand instead:
20
23
  `al-orc config profiles add acme --api-key <key> --api-secret <secret>`.
21
24
 
25
+ ## Changing a definition
26
+
27
+ `stations edit` changes one field at a time, never a whole definition from a file:
28
+
29
+ ```bash
30
+ al-orc stations edit EM1 --set ignore_senders='["a.com","b.com"]' # a top-level config key
31
+ al-orc stations edit EM1 --unset model
32
+ al-orc stations edit EM1 --config '{"batch_size": 20}' # replace the whole config
33
+ al-orc stations edit EM1 --from EM0/output # --from "" removes the conveyor
34
+ al-orc stations edit EM1 --schedule "0 * * * *" --timezone Asia/Kolkata
35
+ al-orc stations edit EM1 --enabled false | --schedule-enabled false | --auto-drain-enabled true
36
+ al-orc stations edit EM1 --name "Classify email" --short-code EM2 --add-tag email
37
+ al-orc lines edit EM --location alex-linux-pc
38
+ ```
39
+
40
+ The factory session reads definitions when it starts. A change it acts on (`from`,
41
+ `auto_drain_enabled`, a line-head's `watch_path`, a code, a line's location, creating or archiving)
42
+ prints a warning to restart the session at the line's location:
43
+
44
+ ```
45
+ $ al-orc stations edit EM1 --from EM0/out2
46
+ Updated EM1: conveyor.
47
+ ⚠ Restart the factory session at alex-linux-pc for this to take effect (from).
48
+ ```
49
+
50
+ Config, cron, `schedule_enabled`, `is_enabled`, names and tags take effect at once.
51
+
52
+ To copy a line to another org, or under a new code:
53
+
54
+ ```bash
55
+ al-orc lines export BK-SR > bk-sr.json # the line and its stations, without ids
56
+ al-orc lines import bk-sr.json --profile chisel # create them in another org
57
+ al-orc lines import bk-sr.json --as BK-SR2 # or a copy: BK-SR1 becomes BK-SR21
58
+ ```
59
+
22
60
  Profiles live in `~/.al/al-orc/config.yml` (mode 0600; override the folder with
23
61
  `AL_ORC_CONFIG_DIR`). The CLI never reads `.env`.
24
62
 
@@ -40,7 +78,7 @@ Credentials are **explicit** — the client never reads `process.env`. Code serv
40
78
 
41
79
  | Namespace | Methods |
42
80
  |---|---|
43
- | `orc.lines` | `list · getAll · get · create · update · delete` — a line owns the location its stations run at |
81
+ | `orc.lines` | `list · getAll · get · create · update · delete · archive · unarchive` — a line owns the location its stations run at |
44
82
  | `orc.stations` | `list · getAll · get · create · update · delete · archive · unarchive · run · getTags · setTags` |
45
83
  | `orc.workRecords` | `list · getAll · get · activity · cancel · getTags · setTags` |
46
84
  | `orc.tags` | `list · create · update · delete · resolveNames · ensure` |
@@ -49,7 +87,8 @@ Credentials are **explicit** — the client never reads `process.env`. Code serv
49
87
  | `orc.me()` | the org and API key the credentials belong to |
50
88
  | `orc.checkConnection()` | credentials check via `me`; never throws and never claims work |
51
89
 
52
- Return shapes: single-record ops return the unwrapped record; `list` returns `{ data, page_context }`;
90
+ Return shapes: single-record ops return the unwrapped record (a write adds `warnings` when the
91
+ factory session must restart for it); `list` returns `{ data, page_context }`;
53
92
  `getAll` returns a flat array.
54
93
 
55
94
  ## Endpoint contract
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assemblyline/al-orc",
3
- "version": "0.7.0",
3
+ "version": "0.10.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",
@@ -25,10 +25,10 @@ export function buildFactorySessionsSubcommands(yargs) {
25
25
  )
26
26
  .command(
27
27
  'show <id>',
28
- 'Show a factory session and its per-step outcomes (--tasks for the task list)',
28
+ 'Show a factory session and its outcomes by station (--runs for the runs it claimed)',
29
29
  (y) =>
30
30
  localOptions(y.positional('id', { describe: 'Factory session ID', type: 'string' }))
31
- .option('tasks', { describe: 'Include the tasks this session claimed', type: 'boolean' })
31
+ .option('runs', { describe: 'Include the runs this session claimed', type: 'boolean' })
32
32
  .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
33
33
  safe(showFactorySessionHandler),
34
34
  )
@@ -9,7 +9,7 @@ import { formatTable, formatDate, localTzLabel } from '../utils/format.js';
9
9
  * if they run different code or out of different directories they are not
10
10
  * interchangeable — and the orchestrator hands each task to whoever polls
11
11
  * first. That is the 2026-08-11 failure mode: two factory sessions on `dev-laptop1`,
12
- * one without the EM steps, so EM runs failed at random.
12
+ * one without the EM stations, so EM runs failed at random.
13
13
  *
14
14
  * D1 (one active session per org+location) now refuses the second session, so
15
15
  * this should be empty on a healthy fleet. It stays because historical rows
@@ -4,7 +4,7 @@ import { formatTable, formatDate, formatField, formatSection, localTzLabel, trun
4
4
 
5
5
  /** `al-orc factory-sessions show <id>` — one factory session, and what it did. */
6
6
  export async function showFactorySessionHandler(argv) {
7
- const { id, tasks, json } = argv;
7
+ const { id, runs, json } = argv;
8
8
 
9
9
  const orc = clientFor();
10
10
  const session = await orc.factorySessions.get(id);
@@ -32,44 +32,44 @@ export async function showFactorySessionHandler(argv) {
32
32
  if (session.ended_at) {
33
33
  console.log(formatField('Ended', formatDate(session.ended_at), 14));
34
34
  }
35
- console.log(formatField('Tasks', `${session.tasks_completed ?? 0} completed, ${session.tasks_failed ?? 0} failed`, 14));
35
+ console.log(formatField('Runs', `${session.tasks_completed ?? 0} completed, ${session.tasks_failed ?? 0} failed`, 14));
36
36
 
37
- const breakdown = session.slug_breakdown || [];
37
+ const breakdown = session.station_breakdown || [];
38
38
  console.log('');
39
- console.log(formatSection(`Outcomes by step (${breakdown.length})`));
39
+ console.log(formatSection(`Outcomes by station (${breakdown.length})`));
40
40
  if (breakdown.length === 0) {
41
- console.log('This session never claimed a task.');
41
+ console.log('This session never claimed a run.');
42
42
  } else {
43
43
  console.log(formatTable(
44
- ['STEP', 'OK', 'FAILED', 'OTHER'],
45
- breakdown.map((s) => [s.step_slug, String(s.completed), String(s.failed), String(s.other)]),
44
+ ['STATION', 'OK', 'FAILED', 'OTHER'],
45
+ breakdown.map((s) => [s.station, String(s.completed), String(s.failed), String(s.other)]),
46
46
  ));
47
47
 
48
- // The stale-deploy signature: some slugs work, others never do. A factory session
49
- // with bad credentials or a dead upstream fails everything; one whose code
50
- // predates a station fails only that station's slugs.
48
+ // The stale-deploy signature: some stations work, others never do. A factory session
49
+ // with bad credentials or a dead upstream fails everything; one whose code predates a
50
+ // station fails only that station.
51
51
  const all_fail = breakdown.filter((s) => s.completed === 0 && s.failed > 0);
52
52
  const any_ok = breakdown.filter((s) => s.completed > 0);
53
53
  if (all_fail.length > 0 && any_ok.length > 0) {
54
54
  console.log('');
55
- console.log(`! ${all_fail.length} step(s) never succeeded here while ${any_ok.length} did.`);
56
- console.log(` Never succeeded: ${all_fail.map((s) => s.step_slug).join(', ')}`);
57
- console.log(" A factory session that handles some steps and no others usually predates them — check its version and restart it.");
55
+ console.log(`! ${all_fail.length} station(s) never succeeded here while ${any_ok.length} did.`);
56
+ console.log(` Never succeeded: ${all_fail.map((s) => s.station).join(', ')}`);
57
+ console.log(" A factory session that handles some stations and no others usually predates them — check its version and restart it.");
58
58
  }
59
59
  }
60
60
 
61
- if (tasks) {
62
- const recent = session.recent_tasks || [];
61
+ if (runs) {
62
+ const recent = session.recent_runs || [];
63
63
  console.log('');
64
- console.log(formatSection(`Recent tasks (${recent.length})`));
64
+ console.log(formatSection(`Recent runs (${recent.length})`));
65
65
  if (recent.length === 0) {
66
- console.log('No tasks.');
66
+ console.log('No runs.');
67
67
  } else {
68
68
  console.log(formatTable(
69
- ['WORK RECORD', 'STEP', 'STATUS', 'TRIES', `CLAIMED (${localTzLabel()})`, 'ERROR'],
69
+ ['WORK RECORD', 'STATION', 'STATUS', 'TRIES', `CLAIMED (${localTzLabel()})`, 'ERROR'],
70
70
  recent.map((t) => [
71
71
  t.work_record,
72
- t.step_slug,
72
+ t.station,
73
73
  t.status,
74
74
  String(t.retry_count ?? 0),
75
75
  formatDate(t.claimed_at),
@@ -79,6 +79,6 @@ export async function showFactorySessionHandler(argv) {
79
79
  }
80
80
  } else {
81
81
  console.log('');
82
- console.log('Use --tasks to list the tasks this session claimed.');
82
+ console.log('Use --runs to list the runs this session claimed.');
83
83
  }
84
84
  }
@@ -0,0 +1,96 @@
1
+ // @ts-check
2
+ /**
3
+ * `al-orc lines export` and `import`: copy a line and its stations, to another org or under a
4
+ * new code. The export file is made once and imported once, like a database dump; it is never
5
+ * kept or edited as the definition, which lives in the orchestrator.
6
+ */
7
+
8
+ import fs from 'node:fs';
9
+ import { clientFor } from '../_helpers.js';
10
+ import { printWarnings } from '../shared/print-warnings.js';
11
+
12
+ /** The station fields an export carries: the definition, without ids or orchestrator state. */
13
+ const STATION_FIELDS = [
14
+ 'short_code', 'name', 'description', 'config', 'conveyor', 'is_enabled',
15
+ 'schedule_cron', 'schedule_timezone', 'schedule_enabled', 'auto_drain_enabled',
16
+ ];
17
+
18
+ /**
19
+ * @typedef {Object} LineExport
20
+ * @property {{ code: string, name: string, description: string|null, location: string }} line
21
+ * @property {Array<Record<string, any>>} stations
22
+ */
23
+
24
+ /**
25
+ * The export of a line and its stations, ordered by code.
26
+ *
27
+ * @param {Record<string, any>} line - As the API returns it
28
+ * @param {Array<Record<string, any>>} stations - The line's stations, as the API returns them
29
+ * @returns {LineExport}
30
+ */
31
+ export function buildExport(line, stations) {
32
+ return {
33
+ line: { code: line.code, name: line.name, description: line.description ?? null, location: line.location },
34
+ stations: [...stations]
35
+ .sort((a, b) => String(a.short_code).localeCompare(String(b.short_code)))
36
+ .map((s) => Object.fromEntries(STATION_FIELDS.filter((f) => s[f] !== undefined).map((f) => [f, s[f]]))),
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Rename a line on import: the line's code, every station code that starts with it, and the
42
+ * bins in `conveyor.from` that name those stations. `BK-SR` → `BK-SR2` turns `BK-SR1` into
43
+ * `BK-SR21` and `BK-SR0/output` into `BK-SR20/output`.
44
+ *
45
+ * @param {LineExport} data
46
+ * @param {string} new_code
47
+ * @returns {LineExport}
48
+ */
49
+ export function renameLine(data, new_code) {
50
+ const old_code = data.line.code;
51
+ const rename = (code) => (typeof code === 'string' && code.startsWith(old_code) ? new_code + code.slice(old_code.length) : code);
52
+ const renameBin = (bin) => {
53
+ const [code, ...rest] = bin.split('/');
54
+ return [rename(code), ...rest].join('/');
55
+ };
56
+ return {
57
+ line: { ...data.line, code: new_code, name: data.line.name === old_code ? new_code : data.line.name },
58
+ stations: data.stations.map((s) => {
59
+ const from = s.conveyor?.from;
60
+ return {
61
+ ...s,
62
+ short_code: rename(s.short_code),
63
+ ...(from ? { conveyor: { from: Array.isArray(from) ? from.map(renameBin) : renameBin(from) } } : {}),
64
+ };
65
+ }),
66
+ };
67
+ }
68
+
69
+ /** `al-orc lines export <code>` — the line and its stations as JSON, on stdout. */
70
+ export async function exportLineHandler(argv) {
71
+ const orc = clientFor();
72
+ const line = await orc.lines.get(argv.id);
73
+ if (!line) throw new Error(`Line not found: ${argv.id}`);
74
+ const stations = await orc.stations.getAll({ line: line.code });
75
+ console.log(JSON.stringify(buildExport(line, stations), null, 2));
76
+ }
77
+
78
+ /** `al-orc lines import <file> [--as CODE] [--location LOC]` — create the line and its stations. */
79
+ export async function importLineHandler(argv) {
80
+ let data = /** @type {LineExport} */ (JSON.parse(fs.readFileSync(argv.file, 'utf8')));
81
+ if (!data?.line?.code || !Array.isArray(data.stations)) {
82
+ throw new Error(`${argv.file} is not a line export: it needs { line: { code, … }, stations: [ … ] }`);
83
+ }
84
+ if (argv.as) data = renameLine(data, argv.as);
85
+ if (argv.location) data = { ...data, line: { ...data.line, location: argv.location } };
86
+
87
+ const orc = clientFor();
88
+ const line = await orc.lines.create(data.line);
89
+ console.log(`Created line ${line?.code ?? data.line.code} at ${data.line.location}.`);
90
+ let last = null;
91
+ for (const station of data.stations) {
92
+ last = await orc.stations.create({ ...station, line: data.line.code });
93
+ console.log(`Created ${last?.short_code ?? station.short_code}.`);
94
+ }
95
+ printWarnings(last ?? line);
96
+ }
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * A line is a sequence of stations that runs at exactly one location.
6
6
  * The line owns `location`; stations name their line by `code` and inherit it.
7
- * Local files: `.orchestrator/lines/<CODE>.json`.
7
+ * The orchestrator holds the definition; create and edit change it there.
8
8
  */
9
9
 
10
10
  import { safe, paginationOptions, localOptions } from '../_helpers.js';
@@ -13,6 +13,8 @@ import { listLinesHandler } from './list.js';
13
13
  import { showLineHandler } from './show.js';
14
14
  import { pullLinesHandler } from './pull.js';
15
15
  import { pushLinesHandler } from './push.js';
16
+ import { createLineHandler, editLineHandler, archiveLineHandler, unarchiveLineHandler } from './write.js';
17
+ import { exportLineHandler, importLineHandler } from './copy.js';
16
18
 
17
19
  export function buildLinesSubcommands(yargs) {
18
20
  return yargs
@@ -34,6 +36,56 @@ export function buildLinesSubcommands(yargs) {
34
36
  .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
35
37
  safe(showLineHandler),
36
38
  )
39
+ .command(
40
+ 'create <code>',
41
+ 'Create a line: al-orc lines create EM --location alex-linux-pc --name "Email"',
42
+ (y) =>
43
+ localOptions(y.positional('code', { describe: 'Line code, e.g. EM', type: 'string' }))
44
+ .option('location', { describe: 'Where the line runs (FACTORY_LOCATION of its session)', type: 'string', demandOption: true })
45
+ .option('name', { describe: 'Display name (defaults to the code)', type: 'string' })
46
+ .option('description', { describe: 'What the line does', type: 'string' })
47
+ .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
48
+ safe(createLineHandler),
49
+ )
50
+ .command(
51
+ 'edit <id>',
52
+ 'Change a line\'s code, name, description or location',
53
+ (y) =>
54
+ localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' }))
55
+ .option('code', { describe: 'New code', type: 'string' })
56
+ .option('name', { describe: 'Display name', type: 'string' })
57
+ .option('description', { describe: 'What the line does ("" clears it)', type: 'string' })
58
+ .option('location', { describe: 'Where the line runs', type: 'string' })
59
+ .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
60
+ safe(editLineHandler),
61
+ )
62
+ .command(
63
+ 'archive <id>',
64
+ 'Archive a line (its stations must be archived first)',
65
+ (y) => localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' })),
66
+ safe(archiveLineHandler),
67
+ )
68
+ .command(
69
+ 'unarchive <id>',
70
+ 'Unarchive a line (its stations stay archived)',
71
+ (y) => localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' })),
72
+ safe(unarchiveLineHandler),
73
+ )
74
+ .command(
75
+ 'export <id>',
76
+ 'Print a line and its stations as JSON, without ids, to import elsewhere',
77
+ (y) => localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' })),
78
+ safe(exportLineHandler),
79
+ )
80
+ .command(
81
+ 'import <file>',
82
+ 'Create a line and its stations from an export (into the --profile org)',
83
+ (y) =>
84
+ localOptions(y.positional('file', { describe: 'A file from al-orc lines export', type: 'string' }))
85
+ .option('as', { describe: 'Import under a new line code; station codes and from bins follow', type: 'string' })
86
+ .option('location', { describe: 'Run the line at another location', type: 'string' }),
87
+ safe(importLineHandler),
88
+ )
37
89
  .command(
38
90
  'pull [id]',
39
91
  'Pull line definitions to .orchestrator/lines/ (--all for every line)',
@@ -50,5 +102,5 @@ export function buildLinesSubcommands(yargs) {
50
102
  .option('all', { describe: 'Push every local line file', type: 'boolean' }),
51
103
  safe(pushLinesHandler),
52
104
  )
53
- .demandCommand(1, 'Specify an action: list, show, pull, push');
105
+ .demandCommand(1, 'Specify an action: list, show, create, edit, archive, unarchive, export, import, pull, push');
54
106
  }
@@ -30,7 +30,7 @@ export async function showLineHandler(argv) {
30
30
  const stations = line.stations || [];
31
31
  console.log(formatSection(`Stations (${stations.length})`));
32
32
  if (stations.length === 0) {
33
- console.log(' (none — push station files with "line": "' + line.code + '")');
33
+ console.log(' (none — al-orc stations create <CODE> --line ' + line.code + ')');
34
34
  return;
35
35
  }
36
36
  console.log(formatTable(['CODE', 'ID', 'NAME'], stations.map((s) => [s.short_code || '—', s.id, s.name || '—'])));
@@ -0,0 +1,51 @@
1
+ // @ts-check
2
+ import { clientFor } from '../_helpers.js';
3
+ import { printWarnings } from '../shared/print-warnings.js';
4
+
5
+ /** `al-orc lines create <code> --location <loc> [--name] [--description]` */
6
+ export async function createLineHandler(argv) {
7
+ const { code, location, name, description, json } = argv;
8
+ const line = await clientFor().lines.create({ code, location, name, description });
9
+ if (json) {
10
+ console.log(JSON.stringify(line, null, 2));
11
+ return;
12
+ }
13
+ console.log(`Created line ${line?.code ?? code} at ${line?.location ?? location}.`);
14
+ printWarnings(line);
15
+ }
16
+
17
+ /** `al-orc lines edit <id> [--code] [--name] [--description] [--location]` */
18
+ export async function editLineHandler(argv) {
19
+ const { id, code, name, description, location, json } = argv;
20
+ /** @type {Record<string, any>} */
21
+ const body = {};
22
+ if (code !== undefined) body.code = code;
23
+ if (name !== undefined) body.name = name;
24
+ if (description !== undefined) body.description = description || null;
25
+ if (location !== undefined) body.location = location;
26
+ if (Object.keys(body).length === 0) {
27
+ throw new Error('Nothing to change: give --code, --name, --description or --location');
28
+ }
29
+
30
+ const line = await clientFor().lines.update(id, body);
31
+ if (json) {
32
+ console.log(JSON.stringify(line, null, 2));
33
+ return;
34
+ }
35
+ console.log(`Updated line ${line?.code ?? id}: ${Object.keys(body).join(', ')}.`);
36
+ printWarnings(line);
37
+ }
38
+
39
+ /** `al-orc lines archive <id>` */
40
+ export async function archiveLineHandler(argv) {
41
+ const line = await clientFor().lines.archive(argv.id);
42
+ console.log(`Archived line ${argv.id}.`);
43
+ printWarnings(line);
44
+ }
45
+
46
+ /** `al-orc lines unarchive <id>` */
47
+ export async function unarchiveLineHandler(argv) {
48
+ const line = await clientFor().lines.unarchive(argv.id);
49
+ console.log(`Unarchived line ${argv.id}.`);
50
+ printWarnings(line);
51
+ }
@@ -0,0 +1,11 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * Print the restart warnings an orchestrator write returned: changes the factory session reads
5
+ * only when it starts. To stderr, like every diagnostic.
6
+ *
7
+ * @param {{ warnings?: string[] } | null | undefined} record
8
+ */
9
+ export function printWarnings(record) {
10
+ for (const warning of record?.warnings ?? []) console.error(`⚠ ${warning}`);
11
+ }
@@ -1,5 +1,6 @@
1
1
  // @ts-check
2
2
  import { clientFor } from '../_helpers.js';
3
+ import { printWarnings } from '../shared/print-warnings.js';
3
4
 
4
5
  /** `al-orc stations archive <id>` — hide from default list, preserve history, block execution. */
5
6
  export async function archiveStationHandler(argv) {
@@ -11,6 +12,7 @@ export async function archiveStationHandler(argv) {
11
12
  }
12
13
  // The API response carries short_code; `id` is only what the user typed.
13
14
  console.log(`Archived station ${station?.short_code || id}.`);
15
+ printWarnings(station);
14
16
  }
15
17
 
16
18
  /** `al-orc stations unarchive <id>` — undo archive. */
@@ -22,4 +24,5 @@ export async function unarchiveStationHandler(argv) {
22
24
  return;
23
25
  }
24
26
  console.log(`Unarchived station ${station?.short_code || id}.`);
27
+ printWarnings(station);
25
28
  }
@@ -0,0 +1,21 @@
1
+ // @ts-check
2
+ import { clientFor } from '../_helpers.js';
3
+ import { printWarnings } from '../shared/print-warnings.js';
4
+ import { definitionBody } from './definition.js';
5
+
6
+ /** `al-orc stations create <code> --line <code> --name "…"` — create a station in the orchestrator. */
7
+ export async function createStationHandler(argv) {
8
+ const { code, json } = argv;
9
+ /** @type {Record<string, any>} */
10
+ const body = { short_code: code, ...definitionBody(argv) };
11
+ if (!body.line) throw new Error('--line is required: every station is on a line');
12
+ if (!body.name) throw new Error('--name is required');
13
+
14
+ const station = await clientFor().stations.create(body);
15
+ if (json) {
16
+ console.log(JSON.stringify(station, null, 2));
17
+ return;
18
+ }
19
+ console.log(`Created ${station?.short_code ?? code} (${station?.id}).`);
20
+ printWarnings(station);
21
+ }
@@ -0,0 +1,83 @@
1
+ // @ts-check
2
+ /**
3
+ * The definition options `stations create` and `stations edit` share, and the request body
4
+ * they build. A definition is changed one field at a time, never sent whole from a file.
5
+ */
6
+
7
+ import { parseSets } from './run.js';
8
+
9
+ /**
10
+ * Register the definition options on a command.
11
+ * @param {any} yargs
12
+ */
13
+ export function definitionOptions(yargs) {
14
+ return yargs
15
+ .option('name', { describe: 'Display name', type: 'string' })
16
+ .option('description', { describe: 'What the station does', type: 'string' })
17
+ .option('line', { describe: 'Line code (moves the station when editing)', type: 'string' })
18
+ .option('config', { describe: 'The whole config, as a JSON object (replaces it)', type: 'string' })
19
+ .option('set', {
20
+ describe: 'Set one top-level config key; repeatable. The value is read as JSON (true, 2, "x", [..]), else text',
21
+ type: 'string',
22
+ array: true,
23
+ })
24
+ .option('unset', { describe: 'Remove a top-level config key; repeatable', type: 'string', array: true })
25
+ .option('from', {
26
+ describe: 'Bin(s) the conveyor moves work from, e.g. EM0/output; repeatable. --from "" removes the conveyor',
27
+ type: 'string',
28
+ array: true,
29
+ })
30
+ .option('schedule', { describe: 'Cron expression ("" clears it)', type: 'string' })
31
+ .option('timezone', { describe: 'IANA timezone for the schedule, e.g. Asia/Kolkata', type: 'string' })
32
+ .option('enabled', { describe: 'Station on or off (off: nothing runs, not even by hand)', type: 'boolean' })
33
+ .option('schedule-enabled', { describe: 'Cron on or off, keeping its expression', type: 'boolean' })
34
+ .option('auto-drain-enabled', {
35
+ describe: 'Run automatically whenever work is waiting (input/, or a line-head\'s watch_path)',
36
+ type: 'boolean',
37
+ });
38
+ }
39
+
40
+ /**
41
+ * The API body for the definition options given.
42
+ *
43
+ * @param {Record<string, any>} argv
44
+ * @param {Record<string, any>} [current_config] - The station's config now; --set and --unset change a copy of it
45
+ * @returns {Record<string, any>}
46
+ */
47
+ export function definitionBody(argv, current_config = {}) {
48
+ /** @type {Record<string, any>} */
49
+ const body = {};
50
+ if (argv.name !== undefined) body.name = argv.name;
51
+ if (argv.description !== undefined) body.description = argv.description || null;
52
+ if (argv.line !== undefined) body.line = argv.line;
53
+
54
+ const sets = argv.set ?? [];
55
+ const unsets = argv.unset ?? [];
56
+ if (argv.config !== undefined || sets.length > 0 || unsets.length > 0) {
57
+ let config = { ...current_config };
58
+ if (argv.config !== undefined) {
59
+ try {
60
+ config = JSON.parse(argv.config);
61
+ } catch (err) {
62
+ throw new Error(`--config is not valid JSON: ${err.message}`);
63
+ }
64
+ if (config === null || typeof config !== 'object' || Array.isArray(config)) {
65
+ throw new Error('--config must be a JSON object');
66
+ }
67
+ }
68
+ Object.assign(config, parseSets(sets));
69
+ for (const key of unsets) delete config[key];
70
+ body.config = config;
71
+ }
72
+
73
+ if (argv.from !== undefined) {
74
+ const bins = argv.from.filter((bin) => bin !== '');
75
+ body.conveyor = bins.length === 0 ? null : { from: bins.length === 1 ? bins[0] : bins };
76
+ }
77
+ if (argv.schedule !== undefined) body.schedule_cron = argv.schedule || null;
78
+ if (argv.timezone !== undefined) body.schedule_timezone = argv.timezone;
79
+ if (argv.enabled !== undefined) body.is_enabled = argv.enabled;
80
+ if (argv.scheduleEnabled !== undefined) body.schedule_enabled = argv.scheduleEnabled;
81
+ if (argv.autoDrainEnabled !== undefined) body.auto_drain_enabled = argv.autoDrainEnabled;
82
+ return body;
83
+ }
@@ -1,31 +1,44 @@
1
1
  // @ts-check
2
2
  import { clientFor } from '../_helpers.js';
3
3
  import { editEntityTags } from '../shared/edit-tags.js';
4
+ import { printWarnings } from '../shared/print-warnings.js';
5
+ import { definitionBody } from './definition.js';
4
6
 
5
- /** `al-orc stations edit <id>` — set short_code and/or add/remove tags. */
7
+ /**
8
+ * `al-orc stations edit <id> [options]` — change a station's definition in the orchestrator,
9
+ * field by field, and its tags.
10
+ */
6
11
  export async function editStationHandler(argv) {
7
- const { id, shortCode: short_code, addTag: add_tag, removeTag: remove_tag } = argv;
12
+ const { id, shortCode: short_code, addTag: add_tag, removeTag: remove_tag, json } = argv;
8
13
 
9
14
  const add_tags = add_tag ? [].concat(add_tag) : [];
10
15
  const remove_tags = remove_tag ? [].concat(remove_tag) : [];
11
- const has_tag_changes = add_tags.length > 0 || remove_tags.length > 0;
16
+ const orc = clientFor();
12
17
 
13
- if (!has_tag_changes && short_code === undefined) {
14
- console.error('Usage: al-orc stations edit <id|short_code> --short-code P1 --add-tag <name> [--remove-tag <name>]');
15
- console.error('At least one of --short-code, --add-tag, or --remove-tag is required');
16
- process.exit(1);
17
- }
18
+ const changes_config = (argv.set ?? []).length > 0 || (argv.unset ?? []).length > 0;
19
+ const current = changes_config ? await orc.stations.get(id) : null;
20
+ if (changes_config && !current) throw new Error(`Station not found: ${id}`);
18
21
 
19
- console.log(`Station: ${id}`);
20
- const orc = clientFor();
22
+ const body = definitionBody(argv, current?.config ?? {});
23
+ if (short_code !== undefined) body.short_code = short_code || null;
21
24
 
22
- if (short_code !== undefined) {
23
- await orc.stations.update(id, { short_code: short_code || null });
24
- console.log(`Short code set: ${short_code || '(cleared)'}`);
25
+ if (Object.keys(body).length === 0 && add_tags.length === 0 && remove_tags.length === 0) {
26
+ throw new Error('Nothing to change: give at least one option (see al-orc stations edit --help)');
25
27
  }
26
28
 
27
- if (has_tag_changes) {
29
+ let station = null;
30
+ if (Object.keys(body).length > 0) {
31
+ station = await orc.stations.update(id, body);
32
+ }
33
+ if (add_tags.length > 0 || remove_tags.length > 0) {
28
34
  await editEntityTags(orc.stations, orc.tags, id, add_tags, remove_tags);
29
- console.log('Tags updated');
30
35
  }
36
+
37
+ if (json) {
38
+ console.log(JSON.stringify(station ?? (await orc.stations.get(id)), null, 2));
39
+ return;
40
+ }
41
+ const changed = [...Object.keys(body), ...(add_tags.length || remove_tags.length ? ['tags'] : [])];
42
+ console.log(`Updated ${station?.short_code ?? id}: ${changed.join(', ')}.`);
43
+ printWarnings(station);
31
44
  }
@@ -13,6 +13,8 @@ import { runStationHandler } from './run.js';
13
13
  import { archiveStationHandler, unarchiveStationHandler } from './archive.js';
14
14
  import { deleteStationHandler } from './delete.js';
15
15
  import { editStationHandler } from './edit.js';
16
+ import { createStationHandler } from './create.js';
17
+ import { definitionOptions } from './definition.js';
16
18
  import { pullStationsHandler } from './pull.js';
17
19
  import { pushStationsHandler } from './push.js';
18
20
 
@@ -41,25 +43,34 @@ export function buildStationsSubcommands(yargs) {
41
43
  )
42
44
  .command(
43
45
  'run <id>',
44
- 'Trigger an orchestrator run (--set key=value changes a step config key for this run)',
46
+ 'Trigger an orchestrator run (--set key=value changes a config key for this run)',
45
47
  (y) =>
46
48
  localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' }))
47
49
  .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',
50
+ describe: 'Change a config key for this run; repeatable. The value is read as JSON (true, 2, "x"), else text',
49
51
  type: 'string',
50
52
  array: true,
51
53
  })
52
54
  .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
53
55
  safe(runStationHandler),
54
56
  )
57
+ .command(
58
+ 'create <code>',
59
+ 'Create a station: al-orc stations create EM5 --line EM --name "…" --from EM4/output',
60
+ (y) =>
61
+ definitionOptions(localOptions(y.positional('code', { describe: 'Station code, e.g. EM5', type: 'string' })))
62
+ .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
63
+ safe(createStationHandler),
64
+ )
55
65
  .command(
56
66
  'edit <id>',
57
- 'Set a station short_code and/or add/remove tags',
67
+ 'Change a station\'s definition, field by field: config keys, from, schedule, switches, name, code, tags',
58
68
  (y) =>
59
- localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' }))
69
+ definitionOptions(localOptions(y.positional('id', { describe: 'Station ID or short_code', type: 'string' })))
60
70
  .option('short-code', { describe: 'Set the short_code (empty string clears it)', type: 'string' })
61
71
  .option('add-tag', { describe: 'Tag name to add (repeatable)', type: 'string', array: true })
62
- .option('remove-tag', { describe: 'Tag name to remove (repeatable)', type: 'string', array: true }),
72
+ .option('remove-tag', { describe: 'Tag name to remove (repeatable)', type: 'string', array: true })
73
+ .option('json', { describe: 'Output raw JSON', type: 'boolean' }),
63
74
  safe(editStationHandler),
64
75
  )
65
76
  .command(
@@ -103,5 +114,5 @@ export function buildStationsSubcommands(yargs) {
103
114
  .option('cascade', { describe: 'Also delete its work records (otherwise refused while any exist)', type: 'boolean' }),
104
115
  safe(deleteStationHandler),
105
116
  )
106
- .demandCommand(1, 'Specify an action: list, show, run, edit, pull, push, archive, unarchive, delete');
117
+ .demandCommand(1, 'Specify an action: list, show, run, create, edit, pull, push, archive, unarchive, delete');
107
118
  }
@@ -24,10 +24,9 @@ export async function listStationsHandler(argv) {
24
24
  s.short_code || '—',
25
25
  s.id,
26
26
  s.name || '—',
27
- String(s.steps ? s.steps.length : 0),
28
27
  ...(include_archived ? [s.archived || s.archived_at ? 'yes' : '—'] : []),
29
28
  ]);
30
- const headers = ['CODE', 'ID', 'NAME', 'STEPS', ...(include_archived ? ['ARCHIVED'] : [])];
29
+ const headers = ['CODE', 'ID', 'NAME', ...(include_archived ? ['ARCHIVED'] : [])];
31
30
 
32
31
  console.log(formatTable(headers, rows));
33
32
  console.log('');
@@ -5,7 +5,7 @@ import { clientFor } from '../_helpers.js';
5
5
  * Turn `--set key=value` flags into per-run config overrides, shallow-merged into the station's
6
6
  * config by the orchestrator. The value is read as JSON (`true`, `2`, `"x"`, `[1,2]`) and,
7
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`.
8
+ * lib-factory's `factory stations run --set`.
9
9
  *
10
10
  * @param {string[]} [sets]
11
11
  * @returns {Record<string, unknown>}
@@ -1,6 +1,5 @@
1
1
  // @ts-check
2
2
  import { clientFor } from '../_helpers.js';
3
- import { buildStationLabelMap, stationLabel } from '../utils/station-labels.js';
4
3
  import { formatHeader, formatField, formatTable, formatSection, formatDate, formatDuration, localTzLabel, truncate } from '../utils/format.js';
5
4
 
6
5
  /** `al-orc stations show <id>` — one station's definition, optionally with recent work records. */
@@ -30,22 +29,17 @@ export async function showStationHandler(argv) {
30
29
  const tags = station.tags?.map((t) => (typeof t === 'string' ? t : t.name)).join(', ');
31
30
  if (tags) console.log(formatField('Tags', tags, lw));
32
31
 
33
- // `dependencies` comes back as bare station ids, so each needs resolving to a
34
- // short_code — printing them verbatim shows opaque ids where the reader
35
- // expects `EM0`. Best-effort: an unresolvable ref falls through unchanged.
36
- let deps = 'none';
37
- if (station.dependencies?.length) {
38
- const labels = await buildStationLabelMap(orc);
39
- deps = station.dependencies
40
- .map((d) => (typeof d === 'string' ? stationLabel(d, labels) : d.short_code || stationLabel(d.id, labels)))
41
- .join(', ');
42
- }
43
- console.log(formatField('Dependencies', deps, lw));
32
+ const from = station.conveyor?.from;
33
+ console.log(formatField('From', from ? [].concat(from).join(', ') : 'none', lw));
34
+ console.log(formatField('Enabled', station.is_enabled ? 'yes' : 'no', lw));
35
+ const schedule = station.schedule_cron
36
+ ? `${station.schedule_cron} (${station.schedule_timezone || 'UTC'}), ${station.schedule_enabled ? 'on' : 'off'}`
37
+ : 'none';
38
+ console.log(formatField('Schedule', schedule, lw));
39
+ console.log(formatField('Auto-drain', (station.auto_drain_enabled ?? station.watch_enabled) ? 'on' : 'off', lw));
44
40
 
45
- if (station.steps?.length) {
46
- console.log(`\nSteps (${station.steps.length}):`);
47
- station.steps.forEach((s, i) => console.log(` ${i + 1}. ${s.slug}`));
48
- }
41
+ console.log(formatSection('Config'));
42
+ console.log(JSON.stringify(station.config ?? {}, null, 2));
49
43
 
50
44
  if (workRecords || all) {
51
45
  const records = await orc.workRecords.list({ station: station.id, limit: 10 }).then((r) => r.data || []);
@@ -25,7 +25,6 @@ export async function showSupportingDocHandler(argv) {
25
25
  const lw = 16;
26
26
  console.log(formatField('Title', doc.title ?? doc.name, lw));
27
27
  console.log(formatField('Type', doc.type, lw));
28
- if (doc.step_slug) console.log(formatField('Step', doc.step_slug, lw));
29
28
  if (doc.filename) console.log(formatField('Filename', doc.filename, lw));
30
29
  if (doc.mime_type) console.log(formatField('MIME Type', doc.mime_type, lw));
31
30
  if (doc.size_bytes) console.log(formatField('Size', formatBytes(doc.size_bytes), lw));
@@ -55,20 +55,11 @@ export function findStationFile(identifier) {
55
55
  /**
56
56
  * The station as its local file holds it:
57
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
58
  *
62
59
  * @param {any} station - As the API returns it
63
- * @param {any} [previous] - The local file it replaces
64
60
  */
65
- function forLocalFile(station, previous) {
61
+ function forLocalFile(station) {
66
62
  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
63
  return station;
73
64
  }
74
65
 
@@ -81,20 +72,12 @@ export function saveStation(station) {
81
72
  const existingByCode = findStationFile(station.short_code);
82
73
  if (existingByCode) toRemove.add(existingByCode);
83
74
  }
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
- }
75
+ for (const f of toRemove) fs.unlinkSync(f);
93
76
 
94
77
  if (!fs.existsSync(STATIONS_DIR)) fs.mkdirSync(STATIONS_DIR, { recursive: true });
95
78
 
96
79
  const filepath = path.join(STATIONS_DIR, buildFilename(station));
97
- fs.writeFileSync(filepath, JSON.stringify(forLocalFile(station, previous), null, 2));
80
+ fs.writeFileSync(filepath, JSON.stringify(forLocalFile(station), null, 2));
98
81
  return filepath;
99
82
  }
100
83
 
@@ -29,11 +29,11 @@ export function buildWorkRecordsSubcommands(yargs) {
29
29
  )
30
30
  .command(
31
31
  'show <id>',
32
- 'Show a work record (--report/--steps/--supporting-docs/--activity/--all for detail)',
32
+ 'Show a work record (--report/--output/--supporting-docs/--activity/--all for detail)',
33
33
  (y) =>
34
34
  localOptions(y.positional('id', { describe: 'Work record ID', type: 'string' }))
35
35
  .option('report', { describe: 'Include the report', type: 'boolean' })
36
- .option('steps', { describe: 'Include step outputs', type: 'boolean' })
36
+ .option('output', { describe: 'Include the config the run used and its output', type: 'boolean' })
37
37
  .option('supporting-docs', { describe: 'Include supporting documents', type: 'boolean' })
38
38
  .option('activity', { describe: 'Include activity events', type: 'boolean' })
39
39
  .option('all', { describe: 'Include every detail section', type: 'boolean' })
@@ -5,13 +5,12 @@ import { buildStationLabelMap, stationLabel } from '../utils/station-labels.js';
5
5
 
6
6
  /** `al-orc work-records show <id>` — one work record, with optional detail sections. */
7
7
  export async function showWorkRecordHandler(argv) {
8
- const { id, report, steps, supportingDocs, activity, all, json } = argv;
8
+ const { id, report, output, supportingDocs, activity, all, json } = argv;
9
9
 
10
10
  const orc = clientFor();
11
11
 
12
12
  const include = [];
13
13
  if (report || all) include.push('report');
14
- if (steps || all) include.push('step_outputs');
15
14
  if (supportingDocs || all) include.push('supporting_docs');
16
15
 
17
16
  const record = await orc.workRecords.get(id, { include: include.length ? include : undefined });
@@ -49,19 +48,13 @@ export async function showWorkRecordHandler(argv) {
49
48
  console.log(record.report ? (typeof record.report === 'string' ? record.report : JSON.stringify(record.report, null, 2)) : 'No report available.');
50
49
  }
51
50
 
52
- if (steps || all) {
53
- console.log(formatSection('Step Outputs'));
54
- const outputs = record.step_outputs || {};
55
- const slugs = Object.keys(outputs);
56
- if (slugs.length) {
57
- for (const slug of slugs) {
58
- console.log(`\n[${slug}]`);
59
- const output = outputs[slug];
60
- console.log(typeof output === 'object' ? JSON.stringify(output, null, 2) : String(output));
61
- }
62
- } else {
63
- console.log('No step outputs.');
64
- }
51
+ if (output || all) {
52
+ const show = (/** @type {any} */ v) => (v === null || v === undefined ? '—' : JSON.stringify(v, null, 2));
53
+ console.log(formatSection('Config'));
54
+ console.log(show(record.config_snapshot));
55
+ if (record.config_overrides) console.log(`\nOverrides: ${JSON.stringify(record.config_overrides)}`);
56
+ console.log(formatSection('Output'));
57
+ console.log(show(record.output));
65
58
  }
66
59
 
67
60
  if (supportingDocs || all) {
@@ -98,7 +91,7 @@ export async function showWorkRecordHandler(argv) {
98
91
  }
99
92
  }
100
93
 
101
- if (!report && !steps && !supportingDocs && !activity && !all) {
102
- console.log('\nUse --report, --steps, --supporting-docs, --activity, or --all for details.');
94
+ if (!report && !output && !supportingDocs && !activity && !all) {
95
+ console.log('\nUse --report, --output, --supporting-docs, --activity, or --all for details.');
103
96
  }
104
97
  }
@@ -33,8 +33,8 @@
33
33
  */
34
34
 
35
35
  /**
36
- * @typedef {Object} SlugOutcome
37
- * @property {string} step_slug
36
+ * @typedef {Object} StationOutcome
37
+ * @property {string} station The station's code
38
38
  * @property {number} completed
39
39
  * @property {number} failed
40
40
  * @property {number} other
@@ -42,10 +42,10 @@
42
42
 
43
43
  /**
44
44
  * @typedef {FactorySession & {
45
- * slug_breakdown: SlugOutcome[],
46
- * recent_tasks: Array<{ id: string, work_record: string, step_slug: string, status: string,
47
- * retry_count: number, error: string|null,
48
- * claimed_at: string|null, completed_at: string|null }>
45
+ * station_breakdown: StationOutcome[],
46
+ * recent_runs: Array<{ work_record: string, station: string, status: string,
47
+ * retry_count: number, error: string|null,
48
+ * claimed_at: string|null, completed_at: string|null }>
49
49
  * }} FactorySessionDetail
50
50
  */
51
51
 
@@ -23,10 +23,15 @@
23
23
  * @property {(data: object) => Promise<Line|null>} create
24
24
  * @property {(id: string, data: object) => Promise<Line|null>} update
25
25
  * @property {(id: string) => Promise<any>} delete
26
+ * @property {(id: string) => Promise<Line|null>} archive
27
+ * @property {(id: string) => Promise<Line|null>} unarchive
26
28
  */
27
29
 
28
30
  /** @param {any} r @returns {any} */
29
31
  const unwrap = (r) => r?.data ?? null;
32
+ /** Unwrap a write's response, keeping the restart warnings the orchestrator sent with it.
33
+ * @param {any} r @returns {any} */
34
+ const unwrapWithWarnings = (r) => (r?.data && r.warnings ? { ...r.data, warnings: r.warnings } : unwrap(r));
30
35
  /** @param {string} s */
31
36
  const enc = (s) => encodeURIComponent(s);
32
37
 
@@ -49,7 +54,13 @@ export function buildLines(ctx) {
49
54
  create: (data) => ctx.post('/api/v1/lines', data).then(unwrap),
50
55
 
51
56
  /** Update line fields (PUT). Returns the updated record. */
52
- update: (id, data) => ctx.put(`/api/v1/lines/${enc(id)}`, data).then(unwrap),
57
+ update: (id, data) => ctx.put(`/api/v1/lines/${enc(id)}`, data).then(unwrapWithWarnings),
58
+
59
+ /** Archive a line. Refused by the server while a station on it is not archived. */
60
+ archive: (id) => ctx.post(`/api/v1/lines/${enc(id)}/archive`).then(unwrapWithWarnings),
61
+
62
+ /** Unarchive a line. Its stations stay archived. */
63
+ unarchive: (id) => ctx.post(`/api/v1/lines/${enc(id)}/unarchive`).then(unwrapWithWarnings),
53
64
 
54
65
  /** Delete a line. Refused by the server while stations are still on it. */
55
66
  delete: (id) => ctx.delete(`/api/v1/lines/${enc(id)}`).then(unwrap),
@@ -4,7 +4,8 @@
4
4
  *
5
5
  * Every route lives under `/api/v1/stations/*`.
6
6
  *
7
- * Return shapes: single-record ops return the unwrapped record; `list` returns
7
+ * Return shapes: single-record ops return the unwrapped record (a write adds the orchestrator's
8
+ * restart `warnings` when there are any); `list` returns
8
9
  * the raw `{ data, page_context }` envelope; `getAll` returns a flat array.
9
10
  */
10
11
 
@@ -37,6 +38,11 @@
37
38
  * @returns {any} */
38
39
  const unwrap = (r) => r?.data ?? null;
39
40
 
41
+ /** Unwrap a write's response, keeping the restart warnings the orchestrator sent with it.
42
+ * @param {any} r
43
+ * @returns {any} */
44
+ const unwrapWithWarnings = (r) => (r?.data && r.warnings ? { ...r.data, warnings: r.warnings } : unwrap(r));
45
+
40
46
  /** @param {string} s */
41
47
  const enc = (s) => encodeURIComponent(s);
42
48
 
@@ -56,20 +62,20 @@ export function buildStations(ctx) {
56
62
  get: (id) => ctx.get(`/api/v1/stations/${enc(id)}`).then(unwrap),
57
63
 
58
64
  /** Create a station (`data` uses API field names). Returns the created record. */
59
- create: (data) => ctx.post('/api/v1/stations', data).then(unwrap),
65
+ create: (data) => ctx.post('/api/v1/stations', data).then(unwrapWithWarnings),
60
66
 
61
67
  /** Update station fields (PUT). Returns the updated record. */
62
- update: (id, data) => ctx.put(`/api/v1/stations/${enc(id)}`, data).then(unwrap),
68
+ update: (id, data) => ctx.put(`/api/v1/stations/${enc(id)}`, data).then(unwrapWithWarnings),
63
69
 
64
70
  /** Delete a station. Refused while it has work records, unless `cascade` (which deletes them too). */
65
71
  delete: (id, { cascade } = {}) =>
66
72
  ctx.delete(`/api/v1/stations/${enc(id)}`, cascade ? { searchParams: { cascade: true } } : undefined).then(unwrap),
67
73
 
68
74
  /** Archive — preserves history, hides from default list, blocks execution. Canonical /stations/* surface. */
69
- archive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/archive`).then(unwrap),
75
+ archive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/archive`).then(unwrapWithWarnings),
70
76
 
71
77
  /** Unarchive — undoes archive. */
72
- unarchive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/unarchive`).then(unwrap),
78
+ unarchive: (id) => ctx.post(`/api/v1/stations/${enc(id)}/unarchive`).then(unwrapWithWarnings),
73
79
 
74
80
  /**
75
81
  * Trigger a station run. `overrides` are shallow-merged into the station's config
@@ -57,7 +57,7 @@ export function buildWorkRecords(ctx) {
57
57
  getAll: async (params = {}) =>
58
58
  (await ctx.getAll('/api/v1/work-records', { searchParams: toSearchParams(params) })).data,
59
59
 
60
- /** One work record. `include` pulls optional blocks: 'report', 'step_outputs', 'supporting_docs'. */
60
+ /** One work record. `include` pulls optional blocks: 'report', 'supporting_docs'. */
61
61
  get: (id, { include } = {}) =>
62
62
  ctx
63
63
  .get(`/api/v1/work-records/${enc(id)}`, include?.length ? { searchParams: { include: include.join(',') } } : undefined)
@@ -11,6 +11,7 @@
11
11
  * @property {LineStationRef[]} [stations] Live stations on the line (read-only, server-derived).
12
12
  * @property {string} [created_at]
13
13
  * @property {string|null} [archived_at]
14
+ * @property {string[]} [warnings] Restart warnings returned by a write.
14
15
  */
15
16
 
16
17
  /**
@@ -7,9 +7,16 @@
7
7
  * @property {string} [short_code]
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
- * @property {StationStep[]} [steps]
10
+ * @property {Record<string, any>} [config] The station's config, passed to its handler.
11
11
  * @property {{ from: string | string[] } | null} [conveyor] Bins the factory session moves workpieces from into input/
12
- * @property {(string|{ id: string, short_code?: string })[]} [dependencies] Station ids or short_codes this one depends on (or station objects).
12
+ * @property {boolean} [is_enabled] Off: nothing runs, not even by hand.
13
+ * @property {string|null} [schedule_cron]
14
+ * @property {string|null} [schedule_timezone]
15
+ * @property {boolean} [schedule_enabled] Cron on or off.
16
+ * @property {boolean} [auto_drain_enabled] The factory session runs it whenever work is waiting (was watch_enabled).
17
+ * @property {boolean} [watch_enabled] The old name of auto_drain_enabled, returned until the orchestrator drops it.
18
+ * @property {(string|{ id: string, short_code?: string })[]} [dependencies] Being removed: order comes from conveyor.from.
19
+ * @property {string[]} [warnings] Restart warnings returned by a write.
13
20
  * @property {(string|Tag)[]} [tags]
14
21
  * @property {string} [applies_to]
15
22
  * @property {boolean} [archived]
@@ -17,13 +24,6 @@
17
24
  * @property {string} [created_at]
18
25
  */
19
26
 
20
- /**
21
- * One step within a station definition.
22
- * @typedef {Object} StationStep
23
- * @property {string} slug
24
- * @property {Record<string, any>} [config]
25
- */
26
-
27
27
  /**
28
28
  * The result of triggering a station run.
29
29
  * @typedef {Object} StationRunResult
@@ -12,7 +12,6 @@
12
12
  * @property {string} [title]
13
13
  * @property {string} [filename]
14
14
  * @property {number} [size_bytes]
15
- * @property {string} [step_slug] The step that produced it.
16
15
  * @property {string} [work_record_id]
17
16
  * @property {string} [created_at]
18
17
  */
@@ -8,7 +8,9 @@
8
8
  * @property {string} [status]
9
9
  * @property {(string|Tag)[]} [tags]
10
10
  * @property {Record<string, any>} [report]
11
- * @property {Record<string, any>[]} [step_outputs]
11
+ * @property {Record<string, any>|null} [config_snapshot] The config the run used, overrides applied.
12
+ * @property {Record<string, any>|null} [config_overrides] Per-run overrides, if any.
13
+ * @property {any} [output] What the station's handler returned.
12
14
  * @property {string} [created_at]
13
15
  * @property {string} [updated_at]
14
16
  * @property {string|null} [started_at]