@eventmodelers/cli 1.0.7 → 1.0.8
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/cli.js +4 -3
- package/lib/fetch.js +52 -6
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1932,9 +1932,10 @@ program
|
|
|
1932
1932
|
.command('fetch')
|
|
1933
1933
|
.description('Pull full slice detail for one context on the board via the slicedata API and write it into .slices/ — the pull-based counterpart to `listen`, without screen images')
|
|
1934
1934
|
.requiredOption('--context <name>', 'Name of the MODEL_CONTEXT to fetch')
|
|
1935
|
-
.option('--
|
|
1936
|
-
.option('--slice-
|
|
1937
|
-
.option('--
|
|
1935
|
+
.option('--format <format>', 'Output format: json (default, builds the full .slices/ folder structure), yaml, textual, toon, emlang, or esdm (each of these five is dumped to a single .slices/<context>/slicedata.<ext> file instead)', 'json')
|
|
1936
|
+
.option('--slice-id <id>', 'After fetching, print just the slice with this id (requires --format json)')
|
|
1937
|
+
.option('--slice-title <title>', 'After fetching, print just the slice with this title, case-insensitive (requires --format json)')
|
|
1938
|
+
.option('--spec-kitty', "After fetching, also restate this context as a Spec Kitty mission brief (.kittify/mission-brief.md via `spec-kitty intake`) — deterministic, no LLM call, no mission/spec.md/tasks created. Run `/spec-kitty.specify` afterward to turn the brief into a mission. Requires `spec-kitty init` to already be set up in this project (see lib/adapters/spec-kitty-adapter.js) and --format json. One-shot: does not start a loop.")
|
|
1938
1939
|
.action(async (opts, command) => {
|
|
1939
1940
|
const cwd = process.cwd();
|
|
1940
1941
|
const kitDir = findInstalledKitDir(cwd);
|
package/lib/fetch.js
CHANGED
|
@@ -17,6 +17,14 @@ export class FetchAuthError extends Error {
|
|
|
17
17
|
|
|
18
18
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19
19
|
|
|
20
|
+
// Mirrors the server's exporter registry (backend/src/slices/change/slicedata/exporters/
|
|
21
|
+
// ExporterRegistry.ts) — json is the canonical shape (drives the full .slices/ folder
|
|
22
|
+
// structure below); every other format is a transform of it and gets dumped as a single
|
|
23
|
+
// file instead, so its extension reflects the transform's actual output, not its name
|
|
24
|
+
// (textual is JSON-wrapped; emlang/esdm are YAML documents; toon is its own thing).
|
|
25
|
+
const SUPPORTED_FORMATS = ['json', 'yaml', 'textual', 'toon', 'emlang', 'esdm'];
|
|
26
|
+
const FORMAT_EXTENSIONS = { yaml: 'yaml', textual: 'json', toon: 'toon', emlang: 'yaml', esdm: 'yaml' };
|
|
27
|
+
|
|
20
28
|
// `--context` accepts any of: a MODEL_CONTEXT name or id, or a timeline (CHAPTER) name or id.
|
|
21
29
|
// /slicedata's contextId/contextName params now both resolve against MODEL_CONTEXT nodes first,
|
|
22
30
|
// then timelines (id matched exactly, name case-insensitively) — including a timeline with no
|
|
@@ -72,7 +80,7 @@ export async function runFetch({ cwd, kitDir, cfg, opts = {} }) {
|
|
|
72
80
|
// never "board not found". Only 401/403 are credential problems worth the
|
|
73
81
|
// reconfigure-and-retry dance in cli.js; 404 gets reported and the process exits,
|
|
74
82
|
// same as any other non-auth error.
|
|
75
|
-
async function
|
|
83
|
+
async function fetchResponse(url, what, { allow404 = false } = {}) {
|
|
76
84
|
let res;
|
|
77
85
|
try {
|
|
78
86
|
res = await fetch(url, { headers });
|
|
@@ -92,7 +100,19 @@ export async function runFetch({ cwd, kitDir, cfg, opts = {} }) {
|
|
|
92
100
|
console.error(`❌ ${what}: HTTP ${res.status}`);
|
|
93
101
|
process.exit(1);
|
|
94
102
|
}
|
|
95
|
-
return res
|
|
103
|
+
return res;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function fetchJson(url, what, options) {
|
|
107
|
+
const res = await fetchResponse(url, what, options);
|
|
108
|
+
return res ? res.json() : res;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Non-json formats aren't a {slices: [...]} payload — just the exporter's raw output
|
|
112
|
+
// (a YAML doc, a TOON encoding, ...) — so it's written straight to disk, not parsed.
|
|
113
|
+
async function fetchText(url, what, options) {
|
|
114
|
+
const res = await fetchResponse(url, what, options);
|
|
115
|
+
return res ? res.text() : res;
|
|
96
116
|
}
|
|
97
117
|
|
|
98
118
|
// Falls back to cwd when no kit is installed — fetch doesn't need kit-specific
|
|
@@ -100,6 +120,17 @@ export async function runFetch({ cwd, kitDir, cfg, opts = {} }) {
|
|
|
100
120
|
const SLICES_DIR = join(kitDir || cwd, '.slices');
|
|
101
121
|
|
|
102
122
|
const contextInput = opts.context;
|
|
123
|
+
const format = (opts.format || 'json').toLowerCase();
|
|
124
|
+
if (!SUPPORTED_FORMATS.includes(format)) {
|
|
125
|
+
console.error(`❌ Unsupported format "${format}". Supported: ${SUPPORTED_FORMATS.join(', ')}`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
// --slice-id/--slice-title/--spec-kitty all depend on the parsed {slices: [...]} list
|
|
129
|
+
// that only the json format produces — fail fast instead of silently ignoring them.
|
|
130
|
+
if (format !== 'json' && (opts.sliceId || opts.sliceTitle || opts.specKitty)) {
|
|
131
|
+
console.error('❌ --slice-id, --slice-title, and --spec-kitty require --format json (the default).');
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
103
134
|
|
|
104
135
|
console.log(`▶ Fetching context "${contextInput}" from ${baseUrl} (board ${cfg.boardId})...`);
|
|
105
136
|
|
|
@@ -112,10 +143,25 @@ export async function runFetch({ cwd, kitDir, cfg, opts = {} }) {
|
|
|
112
143
|
const contextQuery = UUID_RE.test(contextInput)
|
|
113
144
|
? `contextId=${encodeURIComponent(contextInput)}`
|
|
114
145
|
: `contextName=${encodeURIComponent(contextInput)}`;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
146
|
+
const url = `${baseUrl}/api/org/${cfg.organizationId}/boards/${cfg.boardId}/slicedata?${contextQuery}&format=${format}`;
|
|
147
|
+
|
|
148
|
+
// Only json builds the full .slices/<context>/<slice>/slice.json folder structure —
|
|
149
|
+
// every other format has no guaranteed {slices: [...]} shape to walk (it's the
|
|
150
|
+
// exporter's raw output: a YAML doc, a TOON encoding, ...), so it's just dumped
|
|
151
|
+
// as a single file. The resolved context name isn't known without parsing JSON,
|
|
152
|
+
// so the folder is slugified from the raw --context input instead.
|
|
153
|
+
if (format !== 'json') {
|
|
154
|
+
const body = await fetchText(url, `slicedata?${contextQuery}&format=${format}`);
|
|
155
|
+
const contextSlug = slugify(contextInput) || 'default';
|
|
156
|
+
const baseFolder = join(SLICES_DIR, contextSlug);
|
|
157
|
+
mkdirSync(baseFolder, { recursive: true });
|
|
158
|
+
const outFile = join(baseFolder, `slicedata.${FORMAT_EXTENSIONS[format]}`);
|
|
159
|
+
writeFileSync(outFile, body);
|
|
160
|
+
console.log(`✅ Fetched context "${contextInput}" as ${format} → ${relative(cwd, outFile)}`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const payload = await fetchJson(url, `slicedata?${contextQuery}&format=${format}`);
|
|
119
165
|
const { slices: allSlices } = payload;
|
|
120
166
|
const displayContext = allSlices[0]?.context || contextInput;
|
|
121
167
|
|
package/package.json
CHANGED