@xano/cli 1.0.6-beta.2 → 1.0.6-beta.5

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.
@@ -3,7 +3,7 @@ import * as fs from 'node:fs';
3
3
  import * as path from 'node:path';
4
4
  import snakeCase from 'lodash.snakecase';
5
5
  import BaseCommand from '../../../base-command.js';
6
- import { buildApiGroupFolderResolver, channelPathSegments, parseDocument, } from '../../../utils/document-parser.js';
6
+ import { buildApiGroupFolderResolver, buildChannelServerResolver, parseDocument, resolveDocumentPath, } from '../../../utils/document-parser.js';
7
7
  import { fetchKnowledge, writeKnowledge } from '../../../utils/knowledge-sync.js';
8
8
  export default class Pull extends BaseCommand {
9
9
  static description = 'Pull a workspace multidoc from the Xano Metadata API and split into individual files';
@@ -134,116 +134,19 @@ Pulled 58 documents
134
134
  // Resolve api_group names to unique folder names, disambiguating collisions
135
135
  // where different names produce the same snakeCase (e.g., "Authentication" vs "authentication")
136
136
  const getApiGroupFolder = buildApiGroupFolderResolver(documents, snakeCase);
137
+ // Resolve a realtime v2 channel path -> owning realtime_server name, so
138
+ // messages can nest under their channel's server (see resolver docs).
139
+ const getChannelServer = buildChannelServerResolver(documents);
137
140
  // Track filenames per type to handle duplicates
138
141
  const filenameCounters = new Map();
139
142
  let writtenCount = 0;
140
143
  for (const doc of documents) {
141
- let typeDir;
142
- let baseName;
143
- if (doc.type === 'workspace') {
144
- // workspace → workspace/{name}.xs
145
- typeDir = path.join(outputDir, 'workspace');
146
- baseName = this.sanitizeFilename(doc.name);
147
- }
148
- else if (doc.type === 'workspace_trigger') {
149
- // workspace_trigger → workspace/trigger/{name}.xs
150
- typeDir = path.join(outputDir, 'workspace', 'trigger');
151
- baseName = this.sanitizeFilename(doc.name);
152
- }
153
- else if (doc.type === 'error_trigger') {
154
- // error_trigger → workspace/trigger/{name}.xs (singleton, colocated with workspace triggers)
155
- typeDir = path.join(outputDir, 'workspace', 'trigger');
156
- baseName = this.sanitizeFilename(doc.name);
157
- }
158
- else if (doc.type === 'agent') {
159
- // agent → ai/agent/{name}.xs
160
- typeDir = path.join(outputDir, 'ai', 'agent');
161
- baseName = this.sanitizeFilename(doc.name);
162
- }
163
- else if (doc.type === 'mcp_server') {
164
- // mcp_server → ai/mcp_server/{name}.xs
165
- typeDir = path.join(outputDir, 'ai', 'mcp_server');
166
- baseName = this.sanitizeFilename(doc.name);
167
- }
168
- else if (doc.type === 'tool') {
169
- // tool → ai/tool/{name}.xs
170
- typeDir = path.join(outputDir, 'ai', 'tool');
171
- baseName = this.sanitizeFilename(doc.name);
172
- }
173
- else if (doc.type === 'agent_trigger') {
174
- // agent_trigger → ai/agent/trigger/{name}.xs
175
- typeDir = path.join(outputDir, 'ai', 'agent', 'trigger');
176
- baseName = this.sanitizeFilename(doc.name);
177
- }
178
- else if (doc.type === 'mcp_server_trigger') {
179
- // mcp_server_trigger → ai/mcp_server/trigger/{name}.xs
180
- typeDir = path.join(outputDir, 'ai', 'mcp_server', 'trigger');
181
- baseName = this.sanitizeFilename(doc.name);
182
- }
183
- else if (doc.type === 'table_trigger') {
184
- // table_trigger → table/trigger/{name}.xs
185
- typeDir = path.join(outputDir, 'table', 'trigger');
186
- baseName = this.sanitizeFilename(doc.name);
187
- }
188
- else if (doc.type === 'realtime_channel') {
189
- // realtime_channel → realtime/channel/{name}.xs
190
- typeDir = path.join(outputDir, 'realtime', 'channel');
191
- baseName = this.sanitizeFilename(doc.name);
192
- }
193
- else if (doc.type === 'realtime_trigger') {
194
- // realtime_trigger → realtime/trigger/{name}.xs
195
- typeDir = path.join(outputDir, 'realtime', 'trigger');
196
- baseName = this.sanitizeFilename(doc.name);
197
- }
198
- else if (doc.type === 'channel') {
199
- // Realtime v2. The channel owns a directory mirroring its path and its
200
- // messages live inside it, so ownership is visible in the tree.
201
- // channel "rooms/{room_id}" → channel/rooms/[room_id]/_channel.xs
202
- //
203
- // The document uses a FIXED "_channel.xs" leaf: naming it after the
204
- // last segment yields "[room_id].xs", which names the parameter rather
205
- // than the channel. A fixed leaf also sorts first, making "the channel
206
- // vs its messages" obvious.
207
- typeDir = path.join(outputDir, 'channel', ...channelPathSegments(doc.name, snakeCase));
208
- baseName = '_channel';
209
- }
210
- else if (doc.type === 'message' && doc.channel) {
211
- // Realtime v2 message → channel/{channel_path}/{message_name}.xs
212
- // Nesting matters beyond tidiness: message names are unique only WITHIN
213
- // a channel, so a flat message/ directory would collide when two
214
- // channels both define e.g. "say".
215
- typeDir = path.join(outputDir, 'channel', ...channelPathSegments(doc.channel, snakeCase));
216
- baseName = this.sanitizeFilename(doc.name);
217
- }
218
- else if (doc.type === 'api_group') {
219
- // api_group "test" → api/{resolved_folder}/{name}.xs
220
- const groupFolder = getApiGroupFolder(doc.name);
221
- typeDir = path.join(outputDir, 'api', groupFolder);
222
- baseName = this.sanitizeFilename(doc.name);
223
- }
224
- else if (doc.type === 'query' && doc.apiGroup) {
225
- // query in group "test" → api/{resolved_folder}/{query_name}.xs
226
- const groupFolder = getApiGroupFolder(doc.apiGroup);
227
- const nameParts = doc.name.split('/');
228
- const leafName = nameParts.pop();
229
- const folderParts = nameParts.map((part) => snakeCase(part));
230
- typeDir = path.join(outputDir, 'api', groupFolder, ...folderParts);
231
- baseName = this.sanitizeFilename(leafName);
232
- if (doc.verb) {
233
- baseName = `${baseName}_${doc.verb}`;
234
- }
235
- }
236
- else {
237
- // Default: split folder path from name
238
- const nameParts = doc.name.split('/');
239
- const leafName = nameParts.pop();
240
- const folderParts = nameParts.map((part) => snakeCase(part));
241
- typeDir = path.join(outputDir, doc.type, ...folderParts);
242
- baseName = this.sanitizeFilename(leafName);
243
- if (doc.verb) {
244
- baseName = `${baseName}_${doc.verb}`;
245
- }
246
- }
144
+ const { baseName, typeDir } = resolveDocumentPath(doc, outputDir, {
145
+ getApiGroupFolder,
146
+ getChannelServer,
147
+ join: path.join,
148
+ snakeCase,
149
+ });
247
150
  fs.mkdirSync(typeDir, { recursive: true });
248
151
  // Track duplicates per directory
249
152
  const dirKey = path.relative(outputDir, typeDir);
@@ -272,12 +175,4 @@ Pulled 58 documents
272
175
  parts.push(`${knowledgeCount} knowledge file${knowledgeCount === 1 ? '' : 's'}`);
273
176
  this.log(`Pulled ${parts.join(' + ')} to ${flags.directory}`);
274
177
  }
275
- /**
276
- * Sanitize a document name for use as a filename.
277
- * Strips quotes, replaces spaces with underscores, and removes
278
- * characters that are unsafe in filenames.
279
- */
280
- sanitizeFilename(name) {
281
- return snakeCase(name.replaceAll('"', ''));
282
- }
283
178
  }
@@ -6,6 +6,8 @@ export interface ParsedDocument {
6
6
  content: string;
7
7
  guid?: string;
8
8
  name: string;
9
+ /** Owning realtime_server name for realtime v2 `channel` documents. */
10
+ server?: string;
9
11
  type: string;
10
12
  verb?: string;
11
13
  }
@@ -38,6 +40,63 @@ export declare function parseDocument(content: string): null | ParsedDocument;
38
40
  * Mirrors Vfs::channelSegment() on the server.
39
41
  */
40
42
  export declare function channelPathSegments(name: string, snakeCaseFn: (s: string) => string): string[];
43
+ /**
44
+ * Build a map of realtime v2 channel path -> owning realtime_server name.
45
+ *
46
+ * This is the cross-document lookup the on-disk nesting needs: a `message`
47
+ * document names its channel (`channel = "..."`), while a `channel` document
48
+ * names its server (`realtime_server = "..."`). To place a message under
49
+ * `realtime/server/<server>/channel/<path>/...` we resolve the message's channel
50
+ * to that channel's server — which the channel document carries. (Messages now
51
+ * also carry `realtime_server` directly, but resolving via the channel keeps a
52
+ * single source of truth for the channel→server mapping.)
53
+ *
54
+ * Because every pull path parses the WHOLE multidoc into memory before writing,
55
+ * we can build this map from the `channel` docs in the same batch (a two-pass
56
+ * resolve), keyed by the channel's own name (its path). A channel with no
57
+ * `realtime_server` (e.g. a pre-server export) simply isn't in the map, and
58
+ * callers fall back accordingly.
59
+ */
60
+ export declare function buildChannelServerResolver(documents: ParsedDocument[]): (channelName: string) => string | undefined;
61
+ /**
62
+ * Sanitize a document name for use as a single on-disk filename segment.
63
+ * Strips quotes and snake_cases the rest. Mirrors the per-command
64
+ * `sanitizeFilename` the pull commands used to each define privately.
65
+ */
66
+ export declare function sanitizeDocumentName(name: string, snakeCaseFn: (s: string) => string): string;
67
+ /**
68
+ * The directory + base filename (no extension, no duplicate suffix) a document
69
+ * is written to on disk. `resolveDocumentPath` returns this; callers append the
70
+ * `.xs` extension and any `_N` duplicate suffix.
71
+ */
72
+ export interface DocumentPlacement {
73
+ baseName: string;
74
+ typeDir: string;
75
+ }
76
+ /**
77
+ * Resolve where a parsed document lands on disk — the SINGLE source of truth for
78
+ * the pull layout, shared by every pull command (workspace, tenant, release,
79
+ * sandbox, ephemeral). Previously each command inlined a ~130-line copy of this
80
+ * decision; the copies drifted (the realtime v2 realtime_server/channel/message
81
+ * branches existed only in workspace/tenant), so an ephemeral pull dumped v2
82
+ * objects into flat top-level channel/, message/ and realtime_server/ folders —
83
+ * detaching messages from their channels and risking name collisions (message
84
+ * names are unique only WITHIN a channel).
85
+ *
86
+ * @param doc - the parsed document
87
+ * @param outputDir - the resolved pull output root
88
+ * @param deps - injected dependencies
89
+ * @param deps.getApiGroupFolder - resolves an api_group name to its unique folder
90
+ * @param deps.getChannelServer - resolves a v2 channel path to its owning realtime_server
91
+ * @param deps.join - the path.join implementation (injectable for testing)
92
+ * @param deps.snakeCase - the snakeCase implementation the caller uses
93
+ */
94
+ export declare function resolveDocumentPath(doc: ParsedDocument, outputDir: string, deps: {
95
+ getApiGroupFolder: (groupName: string) => string;
96
+ getChannelServer: (channelName: string) => string | undefined;
97
+ join: (...parts: string[]) => string;
98
+ snakeCase: (s: string) => string;
99
+ }): DocumentPlacement;
41
100
  /**
42
101
  * Build a unique key for a document based on its type, name, verb, and api_group.
43
102
  * Used to match server GUID map entries back to local files.
@@ -53,6 +53,17 @@ export function parseDocument(content) {
53
53
  if (channelMatch) {
54
54
  channel = channelMatch[1];
55
55
  }
56
+ // Extract realtime_server if present (e.g., realtime_server = "chat").
57
+ // Realtime v2 channels/messages reference their owning realtime_server by NAME
58
+ // via a top-level `realtime_server = "..."`, which is what nests them under it
59
+ // on disk (mirrors how a message names its channel via `channel = "..."`).
60
+ // The keyword is `realtime_server` (renamed from a bare `server` to match the
61
+ // api_group/mcp_server convention — reference the container by its full type).
62
+ let server;
63
+ const serverMatch = content.match(/^\s*realtime_server\s*=\s*"([^"]*)"/m);
64
+ if (serverMatch) {
65
+ server = serverMatch[1];
66
+ }
56
67
  // Extract canonical if present (e.g., canonical = "abc123")
57
68
  let canonical;
58
69
  const canonicalMatch = content.match(/canonical\s*=\s*"([^"]*)"/);
@@ -65,7 +76,7 @@ export function parseDocument(content) {
65
76
  if (guidMatch) {
66
77
  guid = guidMatch[1];
67
78
  }
68
- return { apiGroup, canonical, channel, content, guid, name, type, verb };
79
+ return { apiGroup, canonical, channel, content, guid, name, server, type, verb };
69
80
  }
70
81
  /**
71
82
  * Map a realtime v2 channel path onto directory segments.
@@ -96,6 +107,171 @@ export function channelPathSegments(name, snakeCaseFn) {
96
107
  const isParam = /^\{.*\}$/;
97
108
  return name.split('/').map((segment) => (isParam.test(segment) ? `[${segment.slice(1, -1)}]` : snakeCaseFn(segment)));
98
109
  }
110
+ /**
111
+ * Build a map of realtime v2 channel path -> owning realtime_server name.
112
+ *
113
+ * This is the cross-document lookup the on-disk nesting needs: a `message`
114
+ * document names its channel (`channel = "..."`), while a `channel` document
115
+ * names its server (`realtime_server = "..."`). To place a message under
116
+ * `realtime/server/<server>/channel/<path>/...` we resolve the message's channel
117
+ * to that channel's server — which the channel document carries. (Messages now
118
+ * also carry `realtime_server` directly, but resolving via the channel keeps a
119
+ * single source of truth for the channel→server mapping.)
120
+ *
121
+ * Because every pull path parses the WHOLE multidoc into memory before writing,
122
+ * we can build this map from the `channel` docs in the same batch (a two-pass
123
+ * resolve), keyed by the channel's own name (its path). A channel with no
124
+ * `realtime_server` (e.g. a pre-server export) simply isn't in the map, and
125
+ * callers fall back accordingly.
126
+ */
127
+ export function buildChannelServerResolver(documents) {
128
+ const channelToServer = new Map();
129
+ for (const doc of documents) {
130
+ if (doc.type === 'channel' && doc.server) {
131
+ channelToServer.set(doc.name, doc.server);
132
+ }
133
+ }
134
+ return (channelName) => channelToServer.get(channelName);
135
+ }
136
+ /**
137
+ * Sanitize a document name for use as a single on-disk filename segment.
138
+ * Strips quotes and snake_cases the rest. Mirrors the per-command
139
+ * `sanitizeFilename` the pull commands used to each define privately.
140
+ */
141
+ export function sanitizeDocumentName(name, snakeCaseFn) {
142
+ return snakeCaseFn(name.replaceAll('"', ''));
143
+ }
144
+ /**
145
+ * Resolve where a parsed document lands on disk — the SINGLE source of truth for
146
+ * the pull layout, shared by every pull command (workspace, tenant, release,
147
+ * sandbox, ephemeral). Previously each command inlined a ~130-line copy of this
148
+ * decision; the copies drifted (the realtime v2 realtime_server/channel/message
149
+ * branches existed only in workspace/tenant), so an ephemeral pull dumped v2
150
+ * objects into flat top-level channel/, message/ and realtime_server/ folders —
151
+ * detaching messages from their channels and risking name collisions (message
152
+ * names are unique only WITHIN a channel).
153
+ *
154
+ * @param doc - the parsed document
155
+ * @param outputDir - the resolved pull output root
156
+ * @param deps - injected dependencies
157
+ * @param deps.getApiGroupFolder - resolves an api_group name to its unique folder
158
+ * @param deps.getChannelServer - resolves a v2 channel path to its owning realtime_server
159
+ * @param deps.join - the path.join implementation (injectable for testing)
160
+ * @param deps.snakeCase - the snakeCase implementation the caller uses
161
+ */
162
+ export function resolveDocumentPath(doc, outputDir, deps) {
163
+ const { getApiGroupFolder, getChannelServer, join, snakeCase } = deps;
164
+ const sanitize = (name) => sanitizeDocumentName(name, snakeCase);
165
+ if (doc.type === 'workspace') {
166
+ // workspace → workspace/{name}.xs
167
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'workspace') };
168
+ }
169
+ if (doc.type === 'workspace_trigger' || doc.type === 'error_trigger') {
170
+ // workspace_trigger / error_trigger → workspace/trigger/{name}.xs
171
+ // (error_trigger is a singleton, colocated with workspace triggers)
172
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'workspace', 'trigger') };
173
+ }
174
+ if (doc.type === 'agent') {
175
+ // agent → ai/agent/{name}.xs
176
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'ai', 'agent') };
177
+ }
178
+ if (doc.type === 'mcp_server') {
179
+ // mcp_server → ai/mcp_server/{name}.xs
180
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'ai', 'mcp_server') };
181
+ }
182
+ if (doc.type === 'tool') {
183
+ // tool → ai/tool/{name}.xs
184
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'ai', 'tool') };
185
+ }
186
+ if (doc.type === 'agent_trigger') {
187
+ // agent_trigger → ai/agent/trigger/{name}.xs
188
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'ai', 'agent', 'trigger') };
189
+ }
190
+ if (doc.type === 'mcp_server_trigger') {
191
+ // mcp_server_trigger → ai/mcp_server/trigger/{name}.xs
192
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'ai', 'mcp_server', 'trigger') };
193
+ }
194
+ if (doc.type === 'table_trigger') {
195
+ // table_trigger → table/trigger/{name}.xs
196
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'table', 'trigger') };
197
+ }
198
+ if (doc.type === 'realtime_channel') {
199
+ // Realtime v1: realtime_channel → realtime/channel/{name}.xs
200
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'realtime', 'channel') };
201
+ }
202
+ if (doc.type === 'realtime_trigger') {
203
+ // Realtime v1: realtime_trigger → realtime/trigger/{name}.xs
204
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'realtime', 'trigger') };
205
+ }
206
+ if (doc.type === 'realtime_server') {
207
+ // Realtime v2. The realtime_server is the top-level container that owns
208
+ // channels (which own messages). Its own document is named after itself
209
+ // inside its name directory, mirroring api_group (api/<group>/<group>.xs).
210
+ // realtime_server "chat" → realtime/server/chat/chat.xs
211
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'realtime', 'server', sanitize(doc.name)) };
212
+ }
213
+ if (doc.type === 'channel') {
214
+ // Realtime v2. The channel owns a directory named after itself (the full
215
+ // channel name, snake_cased into a single flat segment), and its messages
216
+ // live in a message/ subfolder inside it. It nests under its owning
217
+ // realtime_server (from `realtime_server = "..."`):
218
+ // channel "rooms/{room_id}" (server "chat")
219
+ // → realtime/server/chat/channel/rooms_room_id/rooms_room_id.xs
220
+ //
221
+ // A channel with no resolvable server (e.g. a pre-server export) falls back
222
+ // to the legacy flat channel/<path>/_channel.xs layout.
223
+ if (doc.server) {
224
+ return {
225
+ baseName: snakeCase(doc.name),
226
+ typeDir: join(outputDir, 'realtime', 'server', sanitize(doc.server), 'channel', snakeCase(doc.name)),
227
+ };
228
+ }
229
+ return { baseName: '_channel', typeDir: join(outputDir, 'channel', ...channelPathSegments(doc.name, snakeCase)) };
230
+ }
231
+ if (doc.type === 'message' && doc.channel) {
232
+ // Realtime v2 message → nests in a message/ subfolder under its channel,
233
+ // under that channel's server (resolved via the two-pass channel→server map).
234
+ // message "post" on channel "rooms/{room_id}" (server "chat")
235
+ // → realtime/server/chat/channel/rooms_room_id/message/post.xs
236
+ //
237
+ // Nesting matters beyond tidiness: message names are unique only WITHIN a
238
+ // channel, so a flat message/ directory would collide when two channels
239
+ // both define e.g. "say". A channel whose server can't be resolved falls
240
+ // back to the legacy flat channel/ layout.
241
+ const messageServer = getChannelServer(doc.channel);
242
+ return {
243
+ baseName: sanitize(doc.name),
244
+ typeDir: messageServer
245
+ ? join(outputDir, 'realtime', 'server', sanitize(messageServer), 'channel', snakeCase(doc.channel), 'message')
246
+ : join(outputDir, 'channel', ...channelPathSegments(doc.channel, snakeCase)),
247
+ };
248
+ }
249
+ if (doc.type === 'api_group') {
250
+ // api_group "test" → api/{resolved_folder}/{name}.xs
251
+ return { baseName: sanitize(doc.name), typeDir: join(outputDir, 'api', getApiGroupFolder(doc.name)) };
252
+ }
253
+ if (doc.type === 'query' && doc.apiGroup) {
254
+ // query in group "test" → api/{resolved_folder}/{folders}/{query_name}[_verb].xs
255
+ const groupFolder = getApiGroupFolder(doc.apiGroup);
256
+ const nameParts = doc.name.split('/');
257
+ const leafName = nameParts.pop();
258
+ const folderParts = nameParts.map((part) => snakeCase(part));
259
+ const baseName = sanitize(leafName);
260
+ return {
261
+ baseName: doc.verb ? `${baseName}_${doc.verb}` : baseName,
262
+ typeDir: join(outputDir, 'api', groupFolder, ...folderParts),
263
+ };
264
+ }
265
+ // Default: split folder path from name
266
+ const nameParts = doc.name.split('/');
267
+ const leafName = nameParts.pop();
268
+ const folderParts = nameParts.map((part) => snakeCase(part));
269
+ const baseName = sanitize(leafName);
270
+ return {
271
+ baseName: doc.verb ? `${baseName}_${doc.verb}` : baseName,
272
+ typeDir: join(outputDir, doc.type, ...folderParts),
273
+ };
274
+ }
99
275
  /**
100
276
  * Build a unique key for a document based on its type, name, verb, and api_group.
101
277
  * Used to match server GUID map entries back to local files.
@@ -17,6 +17,7 @@ export interface KnowledgeObject {
17
17
  mode?: string;
18
18
  name: string;
19
19
  scope?: string;
20
+ tag?: string[];
20
21
  }
21
22
  /** A locally-collected object that also remembers its primary file on disk (for GUID writeback). */
22
23
  export interface LocalKnowledgeObject extends KnowledgeObject {
@@ -12,7 +12,7 @@ import { dirname, join, relative, sep } from 'node:path';
12
12
  // let the server dictate file paths.
13
13
  export const KNOWLEDGE_DIR = 'knowledge';
14
14
  // ── Frontmatter ──────────────────────────────────────────────────────────────
15
- const FRONTMATTER_ORDER = ['name', 'description', 'knowledge_type', 'scope', 'inclusion', 'enabled', 'guid'];
15
+ const FRONTMATTER_ORDER = ['name', 'description', 'knowledge_type', 'inclusion', 'tags', 'guid'];
16
16
  /**
17
17
  * Build a primary `.md` file body: YAML frontmatter (built from the object's
18
18
  * structured fields) followed by the markdown content.
@@ -23,12 +23,10 @@ export function buildPrimaryContent(obj) {
23
23
  if (obj.description !== undefined)
24
24
  meta.description = obj.description;
25
25
  meta.knowledge_type = obj.knowledge_type;
26
- if (obj.scope !== undefined)
27
- meta.scope = obj.scope;
28
26
  if (obj.mode !== undefined)
29
27
  meta.inclusion = modeToInclusion(obj.mode);
30
- if (obj.enabled !== undefined)
31
- meta.enabled = obj.enabled;
28
+ if (obj.tag !== undefined && obj.tag.length > 0)
29
+ meta.tags = obj.tag;
32
30
  if (obj.guid !== undefined)
33
31
  meta.guid = obj.guid;
34
32
  // Emit keys in a stable, human-friendly order.
@@ -107,6 +105,10 @@ const MODE_TO_INCLUSION = {
107
105
  function modeToInclusion(mode) {
108
106
  return MODE_TO_INCLUSION[mode] ?? mode;
109
107
  }
108
+ /** Parse the on-disk `tags:` frontmatter value into a string array, or `undefined` if absent/malformed. */
109
+ function parseTags(tags) {
110
+ return Array.isArray(tags) && tags.every((t) => typeof t === 'string') ? tags : undefined;
111
+ }
110
112
  // ── Path mapping (CLI-owned layout) ────────────────────────────────────────────
111
113
  /**
112
114
  * Allocate a unique snake_case folder/file segment per call, suffixing
@@ -246,6 +248,9 @@ export function collectKnowledgeObjects(inputDir, include, exclude) {
246
248
  };
247
249
  if (typeof meta.guid === 'string')
248
250
  obj.guid = meta.guid;
251
+ const tags = parseTags(meta.tags);
252
+ if (tags)
253
+ obj.tag = tags;
249
254
  if (knowledgeType === 'skill') {
250
255
  const skillFolder = posixPath.slice('skills/'.length, posixPath.indexOf('/SKILL.md'));
251
256
  const refPrefix = `skills/${skillFolder}/references/`;
@@ -345,6 +350,7 @@ function canonical(obj) {
345
350
  files,
346
351
  mode: obj.mode ?? '',
347
352
  scope: obj.scope ?? '',
353
+ tag: [...(obj.tag ?? [])].sort(),
348
354
  });
349
355
  }
350
356
  /**
@@ -28,6 +28,16 @@ const REFERENCE_PATTERNS = [
28
28
  },
29
29
  // Schema foreign key references: table = "name" inside field definitions
30
30
  { keyword: 'table (FK)', regex: /\btable\s*=\s*"([^"]*)"/gm, targetType: 'table' },
31
+ // Realtime v2: a channel references its owning realtime_server by name via a
32
+ // top-level `realtime_server = "..."` (renamed from a bare `server` to match
33
+ // the api_group/mcp_server convention). The full keyword is unambiguous, so no
34
+ // false-match against another object type's `server` field.
35
+ {
36
+ keyword: 'channel (realtime_server)',
37
+ regex: /^\s*realtime_server\s*=\s*"([^"]*)"/gm,
38
+ sourceType: 'channel',
39
+ targetType: 'realtime_server',
40
+ },
31
41
  ];
32
42
  /**
33
43
  * Strip surrounding quotes from a name if present.
@@ -119,6 +129,9 @@ export function checkReferences(documents, serverOperations) {
119
129
  if (!parsed)
120
130
  continue;
121
131
  for (const pattern of REFERENCE_PATTERNS) {
132
+ // Skip patterns scoped to a different source document type.
133
+ if (pattern.sourceType && pattern.sourceType !== parsed.type)
134
+ continue;
122
135
  // Reset regex state for each document
123
136
  pattern.regex.lastIndex = 0;
124
137
  let match;