@assemblyline/al-orc 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +56 -0
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +98 -2
- package/bin/cli.js +5 -0
- package/package.json +59 -4
- package/src/cli/_helpers.js +67 -0
- package/src/cli/config/add.js +10 -0
- package/src/cli/config/current.js +20 -0
- package/src/cli/config/index.js +63 -0
- package/src/cli/config/list.js +22 -0
- package/src/cli/config/remove.js +6 -0
- package/src/cli/config/use.js +6 -0
- package/src/cli/config-store.js +127 -0
- package/src/cli/factory-sessions/index.js +35 -0
- package/src/cli/factory-sessions/list.js +93 -0
- package/src/cli/factory-sessions/show.js +83 -0
- package/src/cli/index.js +61 -0
- package/src/cli/lines/index.js +53 -0
- package/src/cli/lines/list.js +36 -0
- package/src/cli/lines/pull.js +46 -0
- package/src/cli/lines/push.js +82 -0
- package/src/cli/lines/show.js +36 -0
- package/src/cli/shared/edit-tags.js +43 -0
- package/src/cli/stations/archive.js +24 -0
- package/src/cli/stations/delete.js +8 -0
- package/src/cli/stations/edit.js +30 -0
- package/src/cli/stations/index.js +104 -0
- package/src/cli/stations/list.js +34 -0
- package/src/cli/stations/pull.js +73 -0
- package/src/cli/stations/push.js +212 -0
- package/src/cli/stations/run.js +87 -0
- package/src/cli/stations/show.js +74 -0
- package/src/cli/status.js +23 -0
- package/src/cli/supporting-docs/index.js +21 -0
- package/src/cli/supporting-docs/show.js +49 -0
- package/src/cli/tags/create.js +21 -0
- package/src/cli/tags/delete.js +8 -0
- package/src/cli/tags/edit.js +27 -0
- package/src/cli/tags/index.js +49 -0
- package/src/cli/tags/list.js +24 -0
- package/src/cli/utils/format.js +206 -0
- package/src/cli/utils/line-files.js +84 -0
- package/src/cli/utils/station-files.js +151 -0
- package/src/cli/utils/station-labels.js +48 -0
- package/src/cli/work-records/cancel.js +24 -0
- package/src/cli/work-records/edit.js +22 -0
- package/src/cli/work-records/index.js +59 -0
- package/src/cli/work-records/list.js +48 -0
- package/src/cli/work-records/show.js +103 -0
- package/src/http.js +255 -0
- package/src/index.js +104 -0
- package/src/resources/factory-sessions.js +86 -0
- package/src/resources/lines.js +57 -0
- package/src/resources/stations.js +90 -0
- package/src/resources/supporting-docs.js +37 -0
- package/src/resources/tags.js +68 -0
- package/src/resources/work-records.js +77 -0
- package/src/types/api/Line.types.js +22 -0
- package/src/types/api/Station.types.js +34 -0
- package/src/types/api/SupportingDoc.types.js +14 -0
- package/src/types/api/Tag.types.js +10 -0
- package/src/types/api/WorkRecord.types.js +27 -0
- package/src/types/general/Credentials.types.js +18 -0
- package/src/types/general/Transport.types.js +21 -0
- package/src/types/general/index.js +8 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI credential store — reads/writes ~/.assemblyline/al-orc/config.yml (mode 0600) and
|
|
3
|
+
* resolves which credentials the current command uses.
|
|
4
|
+
*
|
|
5
|
+
* Config lives under the shared family root ~/.assemblyline/ so every al-<tool>
|
|
6
|
+
* keeps its config in one place. Path is home-dir based (os.homedir()) for
|
|
7
|
+
* multi-OS support; not XDG. Override the whole dir with AL_ORC_CONFIG_DIR.
|
|
8
|
+
*
|
|
9
|
+
* CLI-only: the importable client (src/index.js) never imports this. CLI
|
|
10
|
+
* handlers call resolveCredentials() and pass the result to alOrc() as the
|
|
11
|
+
* `credentials`. Single tool, per-org (no per-app nesting).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
15
|
+
import { homedir } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import yaml from 'js-yaml';
|
|
18
|
+
|
|
19
|
+
const CONFIG_DIR = process.env.AL_ORC_CONFIG_DIR || join(homedir(), '.assemblyline', 'al-orc');
|
|
20
|
+
const CONFIG_PATH = join(CONFIG_DIR, 'config.yml');
|
|
21
|
+
|
|
22
|
+
let orgOverride = null;
|
|
23
|
+
|
|
24
|
+
/** Set by the `--profile <name>` global flag (alias `--org`; yargs middleware). Beats current_org. */
|
|
25
|
+
export function setOrgOverride(name) {
|
|
26
|
+
orgOverride = name;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function loadConfig() {
|
|
30
|
+
if (existsSync(CONFIG_PATH)) {
|
|
31
|
+
const cfg = yaml.load(readFileSync(CONFIG_PATH, 'utf8')) || {};
|
|
32
|
+
return { current_org: cfg.current_org ?? null, orgs: cfg.orgs ?? {} };
|
|
33
|
+
}
|
|
34
|
+
return { current_org: null, orgs: {} };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function saveConfig(cfg) {
|
|
38
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
39
|
+
writeFileSync(CONFIG_PATH, yaml.dump(cfg), { mode: 0o600 });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function addOrg(name, { api_url, api_key, api_secret }) {
|
|
43
|
+
const cfg = loadConfig();
|
|
44
|
+
cfg.orgs[name] = { api_url, api_key, api_secret };
|
|
45
|
+
if (!cfg.current_org) cfg.current_org = name;
|
|
46
|
+
saveConfig(cfg);
|
|
47
|
+
return cfg;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function removeOrg(name) {
|
|
51
|
+
const cfg = loadConfig();
|
|
52
|
+
if (!cfg.orgs[name]) throw new Error(`No profile named '${name}'.`);
|
|
53
|
+
delete cfg.orgs[name];
|
|
54
|
+
if (cfg.current_org === name) cfg.current_org = Object.keys(cfg.orgs)[0] ?? null;
|
|
55
|
+
saveConfig(cfg);
|
|
56
|
+
return cfg;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function useOrg(name) {
|
|
60
|
+
const cfg = loadConfig();
|
|
61
|
+
if (!cfg.orgs[name]) throw new Error(`No profile named '${name}'. Run \`al-orc config profiles add ${name}\`.`);
|
|
62
|
+
cfg.current_org = name;
|
|
63
|
+
saveConfig(cfg);
|
|
64
|
+
return cfg;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Absolute path to the config file (shown in the `profiles list` footer). */
|
|
68
|
+
export function configPath() {
|
|
69
|
+
return CONFIG_PATH;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Profiles for display. Returns the current profile name, the config path, and
|
|
74
|
+
* one row per profile with non-secret metadata only (api_url). Secrets are never
|
|
75
|
+
* included.
|
|
76
|
+
*/
|
|
77
|
+
export function listProfiles() {
|
|
78
|
+
const cfg = loadConfig();
|
|
79
|
+
const profiles = Object.entries(cfg.orgs).map(([name, o]) => ({
|
|
80
|
+
name,
|
|
81
|
+
current: name === cfg.current_org,
|
|
82
|
+
api_url: o.api_url,
|
|
83
|
+
}));
|
|
84
|
+
return { current: cfg.current_org, path: CONFIG_PATH, profiles };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Resolve credentials for the current command from the config profiles.
|
|
89
|
+
* Precedence: `--profile`/`--org` override > config `current_org`. The CLI's
|
|
90
|
+
* credential model is profiles (config.yml); it does not read env — an env var
|
|
91
|
+
* that silently overrode the active profile would be a footgun.
|
|
92
|
+
* @returns {{ api_url: string, api_key: string, api_secret: string, source: string }}
|
|
93
|
+
*/
|
|
94
|
+
export function resolveCredentials() {
|
|
95
|
+
const cfg = loadConfig();
|
|
96
|
+
|
|
97
|
+
if (orgOverride) {
|
|
98
|
+
const org = cfg.orgs[orgOverride];
|
|
99
|
+
if (!org) throw new Error(`Profile '${orgOverride}' is not configured. Run \`al-orc config profiles add ${orgOverride}\`.`);
|
|
100
|
+
return { ...org, name: orgOverride, source: `profile '${orgOverride}'` };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (cfg.current_org && cfg.orgs[cfg.current_org]) {
|
|
104
|
+
return { ...cfg.orgs[cfg.current_org], name: cfg.current_org, source: `profile '${cfg.current_org}'` };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
throw new Error(
|
|
108
|
+
'No orchestrator profile selected. Run `al-orc config profiles add <name>`, then `al-orc config profiles use <name>` (or pass --profile <name>).',
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Non-secret description of the identity the CLI would use right now — the same
|
|
114
|
+
* flag > current-profile resolution as resolveCredentials(), minus the secrets.
|
|
115
|
+
* Returns null when nothing is configured. Powers `profiles current`.
|
|
116
|
+
* @returns {{ api_url: string, source: string, name: string|null }|null}
|
|
117
|
+
*/
|
|
118
|
+
export function describeCurrent() {
|
|
119
|
+
let creds;
|
|
120
|
+
try {
|
|
121
|
+
creds = resolveCredentials();
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const { api_key, api_secret, ...rest } = creds;
|
|
126
|
+
return rest;
|
|
127
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subtree builder for `al-orc factory-sessions <action>`.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { safe, localOptions } from '../_helpers.js';
|
|
6
|
+
|
|
7
|
+
import { listFactorySessionsHandler } from './list.js';
|
|
8
|
+
import { showFactorySessionHandler } from './show.js';
|
|
9
|
+
|
|
10
|
+
export function buildFactorySessionsSubcommands(yargs) {
|
|
11
|
+
return yargs
|
|
12
|
+
.usage('$0 factory-sessions <action> [options]')
|
|
13
|
+
.command(
|
|
14
|
+
'list',
|
|
15
|
+
'List factory sessions (one per factory session start)',
|
|
16
|
+
(y) =>
|
|
17
|
+
localOptions(y)
|
|
18
|
+
.option('limit', { describe: 'Max sessions', type: 'number' })
|
|
19
|
+
.option('status', { describe: 'Filter by status (active, expired, disconnected)', type: 'string' })
|
|
20
|
+
.option('location', { describe: 'Filter by location', type: 'string' })
|
|
21
|
+
.option('stale', { describe: 'Only sessions that are no longer active', type: 'boolean' })
|
|
22
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
23
|
+
safe(listFactorySessionsHandler),
|
|
24
|
+
)
|
|
25
|
+
.command(
|
|
26
|
+
'show <id>',
|
|
27
|
+
'Show a factory session and its per-step outcomes (--tasks for the task list)',
|
|
28
|
+
(y) =>
|
|
29
|
+
localOptions(y.positional('id', { describe: 'Factory session ID', type: 'string' }))
|
|
30
|
+
.option('tasks', { describe: 'Include the tasks this session claimed', type: 'boolean' })
|
|
31
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
32
|
+
safe(showFactorySessionHandler),
|
|
33
|
+
)
|
|
34
|
+
.demandCommand(1, 'Specify an action: list, show');
|
|
35
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { clientFor } from '../_helpers.js';
|
|
2
|
+
import { formatTable, formatDate, localTzLabel } from '../utils/format.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Group active sessions by location and flag the ones that disagree.
|
|
6
|
+
*
|
|
7
|
+
* More than one factory session at a location is legitimate scale-out on its own, but
|
|
8
|
+
* if they run different code or out of different directories they are not
|
|
9
|
+
* interchangeable — and the orchestrator hands each task to whoever polls
|
|
10
|
+
* first. That is the 2026-08-11 failure mode: two factory sessions on `dev-laptop1`,
|
|
11
|
+
* one without the EM steps, so EM runs failed at random.
|
|
12
|
+
*
|
|
13
|
+
* D1 (one active session per org+location) now refuses the second session, so
|
|
14
|
+
* this should be empty on a healthy fleet. It stays because historical rows
|
|
15
|
+
* still show it, and because a refused session is only refused at *session
|
|
16
|
+
* creation* — anything already active when D1 shipped kept running.
|
|
17
|
+
*
|
|
18
|
+
* @param {any[]} sessions
|
|
19
|
+
* @returns {Array<{ location: string, count: number, versions: string[], cwds: string[] }>}
|
|
20
|
+
*/
|
|
21
|
+
export function findLocationCollisions(sessions) {
|
|
22
|
+
/** @type {Record<string, any[]>} */
|
|
23
|
+
const by_location = {};
|
|
24
|
+
for (const s of sessions) {
|
|
25
|
+
if (s.status !== 'active') continue;
|
|
26
|
+
(by_location[s.location] ||= []).push(s);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const collisions = [];
|
|
30
|
+
for (const [location, group] of Object.entries(by_location)) {
|
|
31
|
+
if (group.length < 2) continue;
|
|
32
|
+
const versions = [...new Set(group.map((s) => s.factory_version).filter(Boolean))];
|
|
33
|
+
const cwds = [...new Set(group.map((s) => s.cwd).filter(Boolean))];
|
|
34
|
+
collisions.push({ location, count: group.length, versions, cwds });
|
|
35
|
+
}
|
|
36
|
+
return collisions;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** `al-orc factory-sessions list` — factory sessions the orchestrator knows about. */
|
|
40
|
+
export async function listFactorySessionsHandler(argv) {
|
|
41
|
+
const { limit, status, location, stale, json } = argv;
|
|
42
|
+
|
|
43
|
+
const orc = clientFor();
|
|
44
|
+
const { data } = await orc.factorySessions.list({ limit, status, location });
|
|
45
|
+
let sessions = data || [];
|
|
46
|
+
|
|
47
|
+
// --stale is a client-side view over the same rows: anything not currently
|
|
48
|
+
// active. Kept out of the API because "stale" is a judgement, not a column.
|
|
49
|
+
if (stale) {
|
|
50
|
+
sessions = sessions.filter((s) => s.status !== 'active');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (json) {
|
|
54
|
+
console.log(JSON.stringify(sessions, null, 2));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (sessions.length === 0) {
|
|
59
|
+
console.log('No factory sessions found');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const rows = sessions.map((s) => [
|
|
64
|
+
s.id,
|
|
65
|
+
s.factory_name || '—',
|
|
66
|
+
s.hostname || '—',
|
|
67
|
+
s.pid != null ? String(s.pid) : '—',
|
|
68
|
+
s.factory_version || '—',
|
|
69
|
+
s.status,
|
|
70
|
+
String(s.tasks_completed ?? 0),
|
|
71
|
+
String(s.tasks_failed ?? 0),
|
|
72
|
+
formatDate(s.last_seen_at),
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
console.log(formatTable(
|
|
76
|
+
['SESSION', 'FACTORY_NAME', 'HOST', 'PID', 'VER', 'STATUS', 'TASKS', 'FAIL', `LAST SEEN (${localTzLabel()})`],
|
|
77
|
+
rows,
|
|
78
|
+
));
|
|
79
|
+
console.log('');
|
|
80
|
+
console.log(`Total: ${sessions.length} sessions`);
|
|
81
|
+
|
|
82
|
+
for (const c of findLocationCollisions(sessions)) {
|
|
83
|
+
console.log('');
|
|
84
|
+
console.log(`! ${c.count} active sessions share location '${c.location}'`);
|
|
85
|
+
if (c.versions.length > 1) {
|
|
86
|
+
console.log(` Running different factory versions (${c.versions.join(', ')}).`);
|
|
87
|
+
console.log(' Tasks go to whichever polls first — version skew fails nondeterministically.');
|
|
88
|
+
} else if (c.cwds.length > 1) {
|
|
89
|
+
console.log(` Running from different directories (${c.cwds.join(', ')}).`);
|
|
90
|
+
console.log(' Workpiece bundles live under each cwd, so a run split across them loses its files.');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { clientFor } from '../_helpers.js';
|
|
2
|
+
import { formatTable, formatDate, formatField, formatSection, localTzLabel, truncate } from '../utils/format.js';
|
|
3
|
+
|
|
4
|
+
/** `al-orc factory-sessions show <id>` — one factory session, and what it did. */
|
|
5
|
+
export async function showFactorySessionHandler(argv) {
|
|
6
|
+
const { id, tasks, json } = argv;
|
|
7
|
+
|
|
8
|
+
const orc = clientFor();
|
|
9
|
+
const session = await orc.factorySessions.get(id);
|
|
10
|
+
|
|
11
|
+
if (!session) {
|
|
12
|
+
console.log(`Factory session ${id} not found`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (json) {
|
|
17
|
+
console.log(JSON.stringify(session, null, 2));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.log(formatSection(`Factory session ${session.id}`));
|
|
22
|
+
console.log(formatField('Factory', session.factory_name || '—', 14));
|
|
23
|
+
console.log(formatField('Location', session.location || '—', 14));
|
|
24
|
+
console.log(formatField('Status', session.status, 14));
|
|
25
|
+
console.log(formatField('Host', session.hostname || '—', 14));
|
|
26
|
+
console.log(formatField('PID', session.pid != null ? String(session.pid) : '—', 14));
|
|
27
|
+
console.log(formatField('Version', session.factory_version || '—', 14));
|
|
28
|
+
console.log(formatField('Directory', session.cwd || '—', 14));
|
|
29
|
+
console.log(formatField('Started', formatDate(session.started_at), 14));
|
|
30
|
+
console.log(formatField('Last seen', formatDate(session.last_seen_at), 14));
|
|
31
|
+
if (session.ended_at) {
|
|
32
|
+
console.log(formatField('Ended', formatDate(session.ended_at), 14));
|
|
33
|
+
}
|
|
34
|
+
console.log(formatField('Tasks', `${session.tasks_completed ?? 0} completed, ${session.tasks_failed ?? 0} failed`, 14));
|
|
35
|
+
|
|
36
|
+
const breakdown = session.slug_breakdown || [];
|
|
37
|
+
console.log('');
|
|
38
|
+
console.log(formatSection(`Outcomes by step (${breakdown.length})`));
|
|
39
|
+
if (breakdown.length === 0) {
|
|
40
|
+
console.log('This session never claimed a task.');
|
|
41
|
+
} else {
|
|
42
|
+
console.log(formatTable(
|
|
43
|
+
['STEP', 'OK', 'FAILED', 'OTHER'],
|
|
44
|
+
breakdown.map((s) => [s.step_slug, String(s.completed), String(s.failed), String(s.other)]),
|
|
45
|
+
));
|
|
46
|
+
|
|
47
|
+
// The stale-deploy signature: some slugs work, others never do. A factory session
|
|
48
|
+
// with bad credentials or a dead upstream fails everything; one whose code
|
|
49
|
+
// predates a station fails only that station's slugs.
|
|
50
|
+
const all_fail = breakdown.filter((s) => s.completed === 0 && s.failed > 0);
|
|
51
|
+
const any_ok = breakdown.filter((s) => s.completed > 0);
|
|
52
|
+
if (all_fail.length > 0 && any_ok.length > 0) {
|
|
53
|
+
console.log('');
|
|
54
|
+
console.log(`! ${all_fail.length} step(s) never succeeded here while ${any_ok.length} did.`);
|
|
55
|
+
console.log(` Never succeeded: ${all_fail.map((s) => s.step_slug).join(', ')}`);
|
|
56
|
+
console.log(" A factory session that handles some steps and no others usually predates them — check its version and restart it.");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (tasks) {
|
|
61
|
+
const recent = session.recent_tasks || [];
|
|
62
|
+
console.log('');
|
|
63
|
+
console.log(formatSection(`Recent tasks (${recent.length})`));
|
|
64
|
+
if (recent.length === 0) {
|
|
65
|
+
console.log('No tasks.');
|
|
66
|
+
} else {
|
|
67
|
+
console.log(formatTable(
|
|
68
|
+
['WORK RECORD', 'STEP', 'STATUS', 'TRIES', `CLAIMED (${localTzLabel()})`, 'ERROR'],
|
|
69
|
+
recent.map((t) => [
|
|
70
|
+
t.work_record,
|
|
71
|
+
t.step_slug,
|
|
72
|
+
t.status,
|
|
73
|
+
String(t.retry_count ?? 0),
|
|
74
|
+
formatDate(t.claimed_at),
|
|
75
|
+
truncate(t.error, 60),
|
|
76
|
+
]),
|
|
77
|
+
));
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
console.log('');
|
|
81
|
+
console.log('Use --tasks to list the tasks this session claimed.');
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/cli/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI entry point — three-level command tree:
|
|
3
|
+
*
|
|
4
|
+
* al-orc <resource> <action> [target] [options]
|
|
5
|
+
*
|
|
6
|
+
* The orchestrator control plane (canonical station/process definitions, work
|
|
7
|
+
* records, tags, supporting docs). Credentials come from ~/.assemblyline/al-orc/config.yml;
|
|
8
|
+
* `config` manages them. (Local run-state / pm2 / step execution live in the
|
|
9
|
+
* sibling `al-factory` CLI, not here.)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import yargs from 'yargs';
|
|
13
|
+
|
|
14
|
+
import { setOrgOverride } from './config-store.js';
|
|
15
|
+
import { buildConfigSubcommands } from './config/index.js';
|
|
16
|
+
import { buildLinesSubcommands } from './lines/index.js';
|
|
17
|
+
import { buildStationsSubcommands } from './stations/index.js';
|
|
18
|
+
import { buildWorkRecordsSubcommands } from './work-records/index.js';
|
|
19
|
+
import { buildTagsSubcommands } from './tags/index.js';
|
|
20
|
+
import { buildSupportingDocsSubcommands } from './supporting-docs/index.js';
|
|
21
|
+
import { buildFactorySessionsSubcommands } from './factory-sessions/index.js';
|
|
22
|
+
import { safe, localOptions } from './_helpers.js';
|
|
23
|
+
import { statusHandler } from './status.js';
|
|
24
|
+
|
|
25
|
+
export function run(argv) {
|
|
26
|
+
return yargs(argv)
|
|
27
|
+
.scriptName('al-orc')
|
|
28
|
+
.usage('$0 <resource> <action> [target] [options]')
|
|
29
|
+
.option('profile', {
|
|
30
|
+
alias: 'org',
|
|
31
|
+
describe: 'Use credentials from a specific configured profile (overrides current)',
|
|
32
|
+
type: 'string',
|
|
33
|
+
})
|
|
34
|
+
.middleware((argv) => {
|
|
35
|
+
if (argv.profile) setOrgOverride(argv.profile);
|
|
36
|
+
})
|
|
37
|
+
.command('config <resource>', 'Manage credential profiles (alias: orgs)', buildConfigSubcommands)
|
|
38
|
+
.command('lines <action>', 'Manage lines (a line owns the location its stations run at)', buildLinesSubcommands)
|
|
39
|
+
.command('stations <action>', 'Query and run stations (orchestrator definitions)', buildStationsSubcommands)
|
|
40
|
+
.command('work-records <action>', 'Query and manage work records', buildWorkRecordsSubcommands)
|
|
41
|
+
.command('tags <action>', 'Manage tags', buildTagsSubcommands)
|
|
42
|
+
.command('supporting-docs <action>', 'View and download supporting documents', buildSupportingDocsSubcommands)
|
|
43
|
+
.command('factory-sessions <action>', 'Inspect factory sessions and what they ran', buildFactorySessionsSubcommands)
|
|
44
|
+
.command(
|
|
45
|
+
'status',
|
|
46
|
+
'Check connectivity to the orchestrator (active profile)',
|
|
47
|
+
(y) => localOptions(y).option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
48
|
+
safe(statusHandler),
|
|
49
|
+
)
|
|
50
|
+
.demandCommand(1, 'Specify a resource. Try `al-orc --help`.')
|
|
51
|
+
.strict()
|
|
52
|
+
.help()
|
|
53
|
+
.alias('h', 'help')
|
|
54
|
+
.version()
|
|
55
|
+
.alias('v', 'version')
|
|
56
|
+
// Global options (inherited by every command) render under their own
|
|
57
|
+
// heading; each command's own options stay under "Options:", shown first
|
|
58
|
+
// via localOptions() in the command builders.
|
|
59
|
+
.group(['profile', 'help', 'version'], 'Global Options:')
|
|
60
|
+
.parse();
|
|
61
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subtree builder for `al-orc lines <action>`.
|
|
3
|
+
*
|
|
4
|
+
* A line is a sequence of stations that runs at exactly one location.
|
|
5
|
+
* The line owns `location`; stations name their line by `code` and inherit it.
|
|
6
|
+
* Local files: `.orchestrator/lines/<CODE>.json`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { safe, paginationOptions, localOptions } from '../_helpers.js';
|
|
10
|
+
|
|
11
|
+
import { listLinesHandler } from './list.js';
|
|
12
|
+
import { showLineHandler } from './show.js';
|
|
13
|
+
import { pullLinesHandler } from './pull.js';
|
|
14
|
+
import { pushLinesHandler } from './push.js';
|
|
15
|
+
|
|
16
|
+
export function buildLinesSubcommands(yargs) {
|
|
17
|
+
return yargs
|
|
18
|
+
.usage('$0 lines <action> [options]')
|
|
19
|
+
.command(
|
|
20
|
+
'list',
|
|
21
|
+
'List lines from the orchestrator',
|
|
22
|
+
(y) =>
|
|
23
|
+
paginationOptions(y)
|
|
24
|
+
.option('location', { describe: 'Only lines served by this location', type: 'string' })
|
|
25
|
+
.option('include-archived', { describe: 'Include archived lines', type: 'boolean' }),
|
|
26
|
+
safe(listLinesHandler),
|
|
27
|
+
)
|
|
28
|
+
.command(
|
|
29
|
+
'show <id>',
|
|
30
|
+
'Show a line by code or ID, with its stations',
|
|
31
|
+
(y) =>
|
|
32
|
+
localOptions(y.positional('id', { describe: 'Line code or ID', type: 'string' }))
|
|
33
|
+
.option('json', { describe: 'Output raw JSON', type: 'boolean' }),
|
|
34
|
+
safe(showLineHandler),
|
|
35
|
+
)
|
|
36
|
+
.command(
|
|
37
|
+
'pull [id]',
|
|
38
|
+
'Pull line definitions to .orchestrator/lines/ (--all for every line)',
|
|
39
|
+
(y) =>
|
|
40
|
+
localOptions(y.positional('id', { describe: 'Line code or ID (omit with --all)', type: 'string' }))
|
|
41
|
+
.option('all', { describe: 'Pull every line', type: 'boolean' }),
|
|
42
|
+
safe(pullLinesHandler),
|
|
43
|
+
)
|
|
44
|
+
.command(
|
|
45
|
+
'push [id]',
|
|
46
|
+
'Push local line files to the orchestrator (create/update; --all for every file)',
|
|
47
|
+
(y) =>
|
|
48
|
+
localOptions(y.positional('id', { describe: 'Filename, line code, or ID (omit with --all)', type: 'string' }))
|
|
49
|
+
.option('all', { describe: 'Push every local line file', type: 'boolean' }),
|
|
50
|
+
safe(pushLinesHandler),
|
|
51
|
+
)
|
|
52
|
+
.demandCommand(1, 'Specify an action: list, show, pull, push');
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { clientFor } from '../_helpers.js';
|
|
2
|
+
import { formatTable } from '../utils/format.js';
|
|
3
|
+
|
|
4
|
+
/** `al-orc lines list` — lines from the orchestrator, with their station codes. */
|
|
5
|
+
export async function listLinesHandler(argv) {
|
|
6
|
+
const { location, json, includeArchived } = argv || {};
|
|
7
|
+
|
|
8
|
+
const orc = clientFor();
|
|
9
|
+
const { data } = await orc.lines.list({ location, include_archived: includeArchived });
|
|
10
|
+
const lines = data || [];
|
|
11
|
+
|
|
12
|
+
if (json) {
|
|
13
|
+
console.log(JSON.stringify(lines, null, 2));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (lines.length === 0) {
|
|
18
|
+
console.log('No lines found');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const rows = lines.map((l) => [
|
|
23
|
+
l.code,
|
|
24
|
+
l.name === l.code ? '—' : l.name || '—',
|
|
25
|
+
l.location || '—',
|
|
26
|
+
String(l.stations?.length ?? 0),
|
|
27
|
+
(l.stations || []).map((s) => s.short_code || s.id).join(', ') || '—',
|
|
28
|
+
...(includeArchived ? [l.archived_at ? 'yes' : '—'] : []),
|
|
29
|
+
]);
|
|
30
|
+
const headers = ['CODE', 'NAME', 'LOCATION', 'STATIONS', 'MEMBERS', ...(includeArchived ? ['ARCHIVED'] : [])];
|
|
31
|
+
|
|
32
|
+
console.log(formatTable(headers, rows));
|
|
33
|
+
console.log('');
|
|
34
|
+
const station_total = lines.reduce((n, l) => n + (l.stations?.length ?? 0), 0);
|
|
35
|
+
console.log(`Total: ${lines.length} lines, ${station_total} stations`);
|
|
36
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { clientFor } from '../_helpers.js';
|
|
2
|
+
import { saveLine, getLinesDir } from '../utils/line-files.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Write every line to `.orchestrator/lines/`. Shared with `stations pull --all`,
|
|
6
|
+
* which pulls lines first so a factory repo never has station files whose line it
|
|
7
|
+
* cannot resolve.
|
|
8
|
+
* @returns {Promise<number>} lines written
|
|
9
|
+
*/
|
|
10
|
+
export async function pullAllLines(orc) {
|
|
11
|
+
const lines = await orc.lines.getAll({ include_archived: true });
|
|
12
|
+
for (const line of lines) {
|
|
13
|
+
console.log(`Saved: ${saveLine(line)}`);
|
|
14
|
+
}
|
|
15
|
+
return lines.length;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** `al-orc lines pull` — write orchestrator line definitions to `.orchestrator/lines/`. */
|
|
19
|
+
export async function pullLinesHandler(argv) {
|
|
20
|
+
const { id, all } = argv;
|
|
21
|
+
|
|
22
|
+
if (!id && !all) {
|
|
23
|
+
console.error('Usage: al-orc lines pull <code|id>');
|
|
24
|
+
console.error(' al-orc lines pull --all');
|
|
25
|
+
console.error('');
|
|
26
|
+
console.error('Run "al-orc lines list" to see available lines');
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const orc = clientFor();
|
|
31
|
+
console.log(`Saving to: ${getLinesDir()}/`);
|
|
32
|
+
|
|
33
|
+
if (id) {
|
|
34
|
+
const line = await orc.lines.get(id);
|
|
35
|
+
if (!line) {
|
|
36
|
+
console.error(`Line not found: ${id}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
console.log(`Saved: ${saveLine(line)}`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const count = await pullAllLines(orc);
|
|
44
|
+
console.log('');
|
|
45
|
+
console.log(`Total: ${count} lines pulled`);
|
|
46
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { clientFor } from '../_helpers.js';
|
|
2
|
+
import { listAllLineFiles, loadLineByFilename, findLineFile, saveLine, getLinesDir } from '../utils/line-files.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Push one line file — create (no `id`) or update (has `id`). On create the
|
|
6
|
+
* file is rewritten with the server-assigned id.
|
|
7
|
+
*/
|
|
8
|
+
async function pushLineFile(orc, filepath) {
|
|
9
|
+
const line = loadLineByFilename(filepath);
|
|
10
|
+
if (!line) {
|
|
11
|
+
console.error(`Line file not found: ${filepath}`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
if (!line.code || !line.location) {
|
|
15
|
+
throw new Error(`${filepath}: a line file needs at least "code" and "location"`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { id, stations, created_at, archived_at, ...data } = line;
|
|
19
|
+
|
|
20
|
+
if (!id) {
|
|
21
|
+
const created = await orc.lines.create(data);
|
|
22
|
+
console.log(`Created: ${created.id} -> ${saveLine(created)}`);
|
|
23
|
+
return { created: true };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const updated = await orc.lines.update(id, data);
|
|
27
|
+
console.log(`Updated: ${updated.code} (${id})`);
|
|
28
|
+
return { created: false };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Push every local line file. Shared with `stations push --all`, which pushes
|
|
33
|
+
* lines first so a new station's `line` code already exists server-side.
|
|
34
|
+
* @returns {Promise<{ created: number, updated: number }>}
|
|
35
|
+
*/
|
|
36
|
+
export async function pushAllLines(orc) {
|
|
37
|
+
const totals = { created: 0, updated: 0 };
|
|
38
|
+
for (const filepath of listAllLineFiles()) {
|
|
39
|
+
const { created } = await pushLineFile(orc, filepath);
|
|
40
|
+
if (created) totals.created++;
|
|
41
|
+
else totals.updated++;
|
|
42
|
+
}
|
|
43
|
+
return totals;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `al-orc lines push` — create/update orchestrator lines from local files. */
|
|
47
|
+
export async function pushLinesHandler(argv) {
|
|
48
|
+
const { id, all } = argv;
|
|
49
|
+
|
|
50
|
+
if (!id && !all) {
|
|
51
|
+
console.error('Usage: al-orc lines push <filename|code|id>');
|
|
52
|
+
console.error(' al-orc lines push --all');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const orc = clientFor();
|
|
57
|
+
console.log(`Reading from: ${getLinesDir()}/`);
|
|
58
|
+
|
|
59
|
+
if (id) {
|
|
60
|
+
const filepath = id.endsWith('.json') ? id : findLineFile(id);
|
|
61
|
+
if (!filepath) {
|
|
62
|
+
console.error(`line not found locally: ${id}`);
|
|
63
|
+
console.error('Use a filename (e.g. VM.json) or a line code/ID');
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
await pushLineFile(orc, filepath);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (listAllLineFiles().length === 0) {
|
|
71
|
+
console.log('No local lines found');
|
|
72
|
+
console.log('Run "al-orc lines pull --all" first, or create a line file in .orchestrator/lines/');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const { created, updated } = await pushAllLines(orc);
|
|
77
|
+
console.log('');
|
|
78
|
+
const parts = [];
|
|
79
|
+
if (updated > 0) parts.push(`${updated} updated`);
|
|
80
|
+
if (created > 0) parts.push(`${created} created`);
|
|
81
|
+
console.log(`Total: ${parts.join(', ')}`);
|
|
82
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { clientFor } from '../_helpers.js';
|
|
2
|
+
import { formatHeader, formatField, formatTable, formatSection } from '../utils/format.js';
|
|
3
|
+
|
|
4
|
+
/** `al-orc lines show <code|id>` — one line's definition and its stations. */
|
|
5
|
+
export async function showLineHandler(argv) {
|
|
6
|
+
const { id, json } = argv;
|
|
7
|
+
|
|
8
|
+
const orc = clientFor();
|
|
9
|
+
const line = await orc.lines.get(id);
|
|
10
|
+
|
|
11
|
+
if (json) {
|
|
12
|
+
console.log(JSON.stringify(line, null, 2));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!line) {
|
|
17
|
+
console.error(`Line not found: ${id}`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.log(formatHeader('Line', line.code));
|
|
22
|
+
const lw = 14;
|
|
23
|
+
console.log(formatField('Name', line.name, lw));
|
|
24
|
+
console.log(formatField('ID', line.id, lw));
|
|
25
|
+
console.log(formatField('Location', line.location, lw));
|
|
26
|
+
if (line.description) console.log(formatField('Description', line.description, lw));
|
|
27
|
+
if (line.archived_at) console.log(formatField('Archived', line.archived_at, lw));
|
|
28
|
+
|
|
29
|
+
const stations = line.stations || [];
|
|
30
|
+
console.log(formatSection(`Stations (${stations.length})`));
|
|
31
|
+
if (stations.length === 0) {
|
|
32
|
+
console.log(' (none — push station files with "line": "' + line.code + '")');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
console.log(formatTable(['CODE', 'ID', 'NAME'], stations.map((s) => [s.short_code || '—', s.id, s.name || '—'])));
|
|
36
|
+
}
|