@ted-galago/wave-cli 0.1.14 → 0.1.16

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/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  // src/index.ts
5
5
  var import_commander2 = require("commander");
6
- var import_zod16 = require("zod");
6
+ var import_zod17 = require("zod");
7
7
 
8
8
  // src/cli.ts
9
9
  var import_commander = require("commander");
@@ -5143,6 +5143,13 @@ function baseNodeFields() {
5143
5143
  "nodeKey",
5144
5144
  "nodeKind",
5145
5145
  "runtimeLabel",
5146
+ "path",
5147
+ "source",
5148
+ "access",
5149
+ "owner",
5150
+ "parentRef",
5151
+ "agentChildrenAllowed",
5152
+ "exists",
5146
5153
  "resolvedScope { parentId recordId memberId teamId contentType }",
5147
5154
  "isLeaf",
5148
5155
  "treeView",
@@ -6077,6 +6084,778 @@ function registerMutationCapabilityCommands(program) {
6077
6084
  });
6078
6085
  }
6079
6086
 
6087
+ // src/commands/osmd.ts
6088
+ var import_promises = require("fs/promises");
6089
+ var import_zod16 = require("zod");
6090
+ var sourceSchema = import_zod16.z.enum(["canonical_osmd", "agent_overlay", "agent_wiki"]);
6091
+ var accessSchema = import_zod16.z.enum(["read_only", "read_write", "append_only"]);
6092
+ var ownerSchema = import_zod16.z.enum(["system", "atlas"]);
6093
+ var suggestedActionSchema = import_zod16.z.enum([
6094
+ "read",
6095
+ "create",
6096
+ "init",
6097
+ "update",
6098
+ "append",
6099
+ "forbidden",
6100
+ "invalid_parent"
6101
+ ]);
6102
+ var agentMarkdownErrorCodeSchema = import_zod16.z.enum([
6103
+ "canonical_osmd_read_only",
6104
+ "agent_parent_not_found",
6105
+ "agent_file_not_found",
6106
+ "agent_file_already_exists",
6107
+ "agent_path_forbidden",
6108
+ "append_only_violation",
6109
+ "unsupported_agent_file",
6110
+ "invalid_agent_wiki_path"
6111
+ ]);
6112
+ var nonEmptyString3 = import_zod16.z.string().min(1);
6113
+ var nonNegativeInt3 = import_zod16.z.coerce.number().int().min(0);
6114
+ var agentOverlayFileSchema = import_zod16.z.enum(["notes.md", "log.md"]);
6115
+ var agentMarkdownFileSchema = import_zod16.z.object({
6116
+ path: import_zod16.z.string(),
6117
+ source: sourceSchema,
6118
+ access: accessSchema,
6119
+ owner: ownerSchema,
6120
+ exists: import_zod16.z.boolean(),
6121
+ canCreate: import_zod16.z.boolean(),
6122
+ canUpdate: import_zod16.z.boolean(),
6123
+ canAppend: import_zod16.z.boolean(),
6124
+ parentRef: import_zod16.z.string().nullable().optional(),
6125
+ agentChildrenAllowed: import_zod16.z.boolean(),
6126
+ suggestedAction: suggestedActionSchema,
6127
+ errorCode: agentMarkdownErrorCodeSchema.nullable().optional(),
6128
+ content: import_zod16.z.string().nullable().optional(),
6129
+ url: import_zod16.z.string().nullable().optional()
6130
+ }).transform((value) => ({
6131
+ ...value,
6132
+ parentRef: value.parentRef ?? null,
6133
+ errorCode: value.errorCode ?? null,
6134
+ content: value.content ?? null,
6135
+ url: value.url ?? null
6136
+ }));
6137
+ var agentMarkdownFilesSchema = import_zod16.z.array(agentMarkdownFileSchema);
6138
+ var agentMarkdownMutationDataSchema = import_zod16.z.union([
6139
+ agentMarkdownFileSchema,
6140
+ import_zod16.z.object({ files: agentMarkdownFilesSchema })
6141
+ ]);
6142
+ var mutationPayloadSchema = import_zod16.z.object({
6143
+ ok: import_zod16.z.boolean(),
6144
+ status: import_zod16.z.number(),
6145
+ errorCode: import_zod16.z.string().nullable().optional(),
6146
+ data: import_zod16.z.unknown().nullable().optional(),
6147
+ errors: import_zod16.z.unknown().nullable().optional()
6148
+ });
6149
+ var markdownTreeNodeSchema = import_zod16.z.lazy(
6150
+ () => import_zod16.z.object({
6151
+ toolKey: import_zod16.z.string(),
6152
+ nodeKey: import_zod16.z.string(),
6153
+ nodeKind: import_zod16.z.string(),
6154
+ runtimeLabel: import_zod16.z.string(),
6155
+ path: import_zod16.z.string().nullable().optional().transform((value) => value ?? null),
6156
+ source: sourceSchema,
6157
+ access: accessSchema,
6158
+ owner: ownerSchema,
6159
+ parentRef: import_zod16.z.string().nullable().optional().transform((value) => value ?? null),
6160
+ agentChildrenAllowed: import_zod16.z.boolean(),
6161
+ exists: import_zod16.z.boolean(),
6162
+ resolvedScope: import_zod16.z.object({
6163
+ parentId: import_zod16.z.string().nullable().optional().transform((value) => value ?? null),
6164
+ recordId: import_zod16.z.string().nullable().optional().transform((value) => value ?? null),
6165
+ memberId: import_zod16.z.string().nullable().optional().transform((value) => value ?? null),
6166
+ teamId: import_zod16.z.string().nullable().optional().transform((value) => value ?? null),
6167
+ contentType: import_zod16.z.string().nullable().optional().transform((value) => value ?? null)
6168
+ }),
6169
+ isLeaf: import_zod16.z.boolean(),
6170
+ treeView: import_zod16.z.boolean(),
6171
+ details: import_zod16.z.unknown().nullable(),
6172
+ children: import_zod16.z.array(markdownTreeNodeSchema).optional().transform((value) => value ?? [])
6173
+ })
6174
+ );
6175
+ var AGENT_MARKDOWN_FILE_SELECTION = `{
6176
+ path
6177
+ source
6178
+ access
6179
+ owner
6180
+ exists
6181
+ canCreate
6182
+ canUpdate
6183
+ canAppend
6184
+ parentRef
6185
+ agentChildrenAllowed
6186
+ suggestedAction
6187
+ errorCode
6188
+ content
6189
+ url
6190
+ }`;
6191
+ var MUTATION_RESULT_SELECTION = "{ ok status errorCode data errors }";
6192
+ var AGENT_JSON_KEY_ALIASES = {
6193
+ can_create: "canCreate",
6194
+ can_update: "canUpdate",
6195
+ can_append: "canAppend",
6196
+ parent_ref: "parentRef",
6197
+ agent_children_allowed: "agentChildrenAllowed",
6198
+ suggested_action: "suggestedAction",
6199
+ error_code: "errorCode"
6200
+ };
6201
+ var contentStdinPromise = null;
6202
+ function isRecord5(value) {
6203
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6204
+ }
6205
+ function normalizeAgentMarkdownJsonKeys(value) {
6206
+ if (Array.isArray(value)) {
6207
+ return value.map((entry) => normalizeAgentMarkdownJsonKeys(entry));
6208
+ }
6209
+ if (!isRecord5(value)) {
6210
+ return value;
6211
+ }
6212
+ const normalized = {};
6213
+ for (const [key, entry] of Object.entries(value)) {
6214
+ const normalizedKey = AGENT_JSON_KEY_ALIASES[key] ?? key;
6215
+ normalized[normalizedKey] = normalizeAgentMarkdownJsonKeys(entry);
6216
+ }
6217
+ return normalized;
6218
+ }
6219
+ function buildSuccessEnvelope(params) {
6220
+ return {
6221
+ ok: true,
6222
+ command: params.command,
6223
+ status: params.status,
6224
+ data: params.data,
6225
+ error: null,
6226
+ meta: { requestId: params.requestId }
6227
+ };
6228
+ }
6229
+ function buildErrorEnvelope(params) {
6230
+ return {
6231
+ ok: false,
6232
+ command: params.command,
6233
+ status: params.status,
6234
+ data: params.data,
6235
+ error: {
6236
+ code: params.code,
6237
+ message: params.message,
6238
+ suggestedAction: params.suggestedAction,
6239
+ details: params.details ?? {}
6240
+ },
6241
+ meta: { requestId: params.requestId }
6242
+ };
6243
+ }
6244
+ function printLocalError(params) {
6245
+ return printEnvelopeAndExit({
6246
+ envelope: buildErrorEnvelope(params),
6247
+ exitCode: mapStatusToExitCode(params.status)
6248
+ });
6249
+ }
6250
+ function printInvalidPayloadError(params) {
6251
+ return printLocalError({
6252
+ command: params.command,
6253
+ status: 502,
6254
+ code: "upstream_error",
6255
+ message: "GraphQL response did not match the expected OSMD contract.",
6256
+ requestId: params.requestId,
6257
+ data: null,
6258
+ details: { issues: params.issues }
6259
+ });
6260
+ }
6261
+ async function requestOsmdQuery(params) {
6262
+ const result = await graphqlRequest({
6263
+ config: getConfig(params.runtimeOptions),
6264
+ command: params.command,
6265
+ operationName: params.operationName,
6266
+ operationType: "query",
6267
+ field: params.field,
6268
+ variables: params.variables,
6269
+ selectionSet: params.selectionSet,
6270
+ isShow: true
6271
+ });
6272
+ if (!result.envelope.ok) {
6273
+ return printEnvelopeAndExit(result);
6274
+ }
6275
+ const dataRecord = isRecord5(result.envelope.data) ? result.envelope.data : {};
6276
+ const parsed = params.schema.safeParse(dataRecord[params.field]);
6277
+ if (!parsed.success) {
6278
+ return printInvalidPayloadError({
6279
+ command: params.command,
6280
+ requestId: result.envelope.meta.requestId,
6281
+ issues: parsed.error.issues
6282
+ });
6283
+ }
6284
+ return {
6285
+ data: parsed.data,
6286
+ status: result.envelope.status,
6287
+ requestId: result.envelope.meta.requestId
6288
+ };
6289
+ }
6290
+ async function requestAgentMarkdownStatus(params) {
6291
+ return requestOsmdQuery({
6292
+ command: params.command,
6293
+ operationName: "AgentMarkdownStatus",
6294
+ runtimeOptions: params.runtimeOptions,
6295
+ field: "agent_markdown_status",
6296
+ variables: {
6297
+ organization_id: params.organizationId,
6298
+ path: params.path,
6299
+ parent_ref: params.parentRef
6300
+ },
6301
+ selectionSet: AGENT_MARKDOWN_FILE_SELECTION,
6302
+ schema: agentMarkdownFileSchema
6303
+ });
6304
+ }
6305
+ async function requestAgentMarkdownFile(params) {
6306
+ return requestOsmdQuery({
6307
+ command: params.command,
6308
+ operationName: "AgentMarkdownFile",
6309
+ runtimeOptions: params.runtimeOptions,
6310
+ field: "agent_markdown_file",
6311
+ variables: {
6312
+ organization_id: params.organizationId,
6313
+ path: params.path,
6314
+ parent_ref: params.parentRef
6315
+ },
6316
+ selectionSet: AGENT_MARKDOWN_FILE_SELECTION,
6317
+ schema: agentMarkdownFileSchema
6318
+ });
6319
+ }
6320
+ async function requestAgentMarkdownChildren(params) {
6321
+ return requestOsmdQuery({
6322
+ command: params.command,
6323
+ operationName: "AgentMarkdownChildren",
6324
+ runtimeOptions: params.runtimeOptions,
6325
+ field: "agent_markdown_children",
6326
+ variables: {
6327
+ organization_id: params.organizationId,
6328
+ path: params.path,
6329
+ parent_ref: params.parentRef,
6330
+ source: params.source
6331
+ },
6332
+ selectionSet: AGENT_MARKDOWN_FILE_SELECTION,
6333
+ schema: agentMarkdownFilesSchema
6334
+ });
6335
+ }
6336
+ async function runAgentMarkdownMutation(params) {
6337
+ const result = await graphqlRequest({
6338
+ config: getConfig(params.runtimeOptions),
6339
+ command: params.command,
6340
+ operationName: params.operationName,
6341
+ operationType: "mutation",
6342
+ field: params.field,
6343
+ variables: params.variables,
6344
+ selectionSet: MUTATION_RESULT_SELECTION
6345
+ });
6346
+ if (!result.envelope.ok) {
6347
+ return printEnvelopeAndExit(result);
6348
+ }
6349
+ const dataRecord = isRecord5(result.envelope.data) ? result.envelope.data : {};
6350
+ const parsedPayload = mutationPayloadSchema.safeParse(dataRecord[params.field]);
6351
+ if (!parsedPayload.success) {
6352
+ return printInvalidPayloadError({
6353
+ command: params.command,
6354
+ requestId: result.envelope.meta.requestId,
6355
+ issues: parsedPayload.error.issues
6356
+ });
6357
+ }
6358
+ const mutationPayload = parsedPayload.data;
6359
+ const parsedData = agentMarkdownMutationDataSchema.safeParse(
6360
+ normalizeAgentMarkdownJsonKeys(mutationPayload.data)
6361
+ );
6362
+ if (!parsedData.success) {
6363
+ return printInvalidPayloadError({
6364
+ command: params.command,
6365
+ requestId: result.envelope.meta.requestId,
6366
+ issues: parsedData.error.issues
6367
+ });
6368
+ }
6369
+ return printEnvelopeAndExit({
6370
+ envelope: buildSuccessEnvelope({
6371
+ command: params.command,
6372
+ status: mutationPayload.status,
6373
+ data: parsedData.data,
6374
+ requestId: result.envelope.meta.requestId
6375
+ })
6376
+ });
6377
+ }
6378
+ function normalizeAgentFilePath(file) {
6379
+ const trimmed = nonEmptyString3.parse(file).trim().replace(/^\/+|\/+$/g, "");
6380
+ const fileName = trimmed.startsWith(".agent/") ? trimmed.slice(".agent/".length) : trimmed;
6381
+ const parsed = agentOverlayFileSchema.safeParse(fileName);
6382
+ if (!parsed.success) {
6383
+ throw new CliError({
6384
+ message: ".agent supports only notes.md and log.md in this CLI slice.",
6385
+ kind: "invalid_args",
6386
+ status: 400,
6387
+ exitCode: EXIT_CODES.invalidArgs,
6388
+ details: { supportedFiles: ["notes.md", "log.md"] }
6389
+ });
6390
+ }
6391
+ return `.agent/${parsed.data}`;
6392
+ }
6393
+ function normalizeWikiPath(path) {
6394
+ const trimmed = nonEmptyString3.parse(path).trim().replace(/^\/+/, "");
6395
+ if (trimmed.localeCompare("Agent Wiki", void 0, { sensitivity: "accent" }) === 0) {
6396
+ return "Agent Wiki";
6397
+ }
6398
+ if (trimmed.toLowerCase().startsWith("agent wiki/")) {
6399
+ return `Agent Wiki/${trimmed.slice("Agent Wiki/".length)}`;
6400
+ }
6401
+ return `Agent Wiki/${trimmed}`;
6402
+ }
6403
+ function parseOptionalParentRef(value) {
6404
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
6405
+ }
6406
+ function parseOptionalSource(value) {
6407
+ if (value === void 0 || value === null || value === "") {
6408
+ return void 0;
6409
+ }
6410
+ const parsed = sourceSchema.safeParse(value);
6411
+ if (!parsed.success) {
6412
+ throw new CliError({
6413
+ message: "Invalid OSMD source. Use canonical_osmd, agent_overlay, or agent_wiki.",
6414
+ kind: "invalid_args",
6415
+ status: 400,
6416
+ exitCode: EXIT_CODES.invalidArgs,
6417
+ details: { supportedSources: sourceSchema.options }
6418
+ });
6419
+ }
6420
+ return parsed.data;
6421
+ }
6422
+ function parseDepth(value) {
6423
+ if (value === void 0 || value === null || value === "") {
6424
+ return 1;
6425
+ }
6426
+ return nonNegativeInt3.parse(value);
6427
+ }
6428
+ function readContentStdin() {
6429
+ if (!contentStdinPromise) {
6430
+ contentStdinPromise = new Promise((resolve, reject) => {
6431
+ if (process.stdin.isTTY) {
6432
+ resolve("");
6433
+ return;
6434
+ }
6435
+ let data = "";
6436
+ process.stdin.setEncoding("utf8");
6437
+ process.stdin.on("data", (chunk) => {
6438
+ data += chunk;
6439
+ });
6440
+ process.stdin.on("end", () => resolve(data));
6441
+ process.stdin.on("error", reject);
6442
+ });
6443
+ }
6444
+ return contentStdinPromise;
6445
+ }
6446
+ async function resolveContentInput(opts, globals) {
6447
+ const hasContent = typeof opts.content === "string";
6448
+ const hasFile = typeof opts.file === "string" && opts.file.trim() !== "";
6449
+ if (hasContent && hasFile) {
6450
+ throw new CliError({
6451
+ message: "Use only one markdown content source: --content, --file, or stdin.",
6452
+ kind: "invalid_args",
6453
+ status: 400,
6454
+ exitCode: EXIT_CODES.invalidArgs
6455
+ });
6456
+ }
6457
+ if (hasContent) {
6458
+ return String(opts.content);
6459
+ }
6460
+ if (hasFile) {
6461
+ try {
6462
+ return await (0, import_promises.readFile)(opts.file, "utf8");
6463
+ } catch (error) {
6464
+ throw new CliError({
6465
+ message: `Unable to read markdown file: ${opts.file}`,
6466
+ kind: "invalid_args",
6467
+ status: 400,
6468
+ exitCode: EXIT_CODES.invalidArgs,
6469
+ details: {
6470
+ cause: error instanceof Error ? error.message : String(error)
6471
+ }
6472
+ });
6473
+ }
6474
+ }
6475
+ if (globals.tokenStdin === true || globals.authJsonStdin === true) {
6476
+ throw new CliError({
6477
+ message: "Markdown content cannot share stdin with --token-stdin or --auth-json-stdin. Use --content or --file.",
6478
+ kind: "invalid_args",
6479
+ status: 400,
6480
+ exitCode: EXIT_CODES.invalidArgs
6481
+ });
6482
+ }
6483
+ const stdin = await readContentStdin();
6484
+ if (stdin.length === 0) {
6485
+ throw new CliError({
6486
+ message: "Provide markdown content with --content, --file, or stdin.",
6487
+ kind: "invalid_args",
6488
+ status: 400,
6489
+ exitCode: EXIT_CODES.invalidArgs
6490
+ });
6491
+ }
6492
+ return stdin;
6493
+ }
6494
+ function writePreflightError(status, action) {
6495
+ if (status.errorCode) {
6496
+ return {
6497
+ code: status.errorCode,
6498
+ message: `OSMD write is not allowed: ${status.errorCode}.`,
6499
+ suggestedAction: status.suggestedAction,
6500
+ status: statusCodeForAgentError(status.errorCode)
6501
+ };
6502
+ }
6503
+ if (status.source === "canonical_osmd" || status.access === "read_only") {
6504
+ return {
6505
+ code: "canonical_osmd_read_only",
6506
+ message: "Canonical OSMD files are read-only. Write to .agent overlays or Agent Wiki.",
6507
+ suggestedAction: status.suggestedAction,
6508
+ status: 403
6509
+ };
6510
+ }
6511
+ if (action === "create") {
6512
+ if (status.exists) {
6513
+ return {
6514
+ code: "agent_file_already_exists",
6515
+ message: `Agent markdown file already exists: ${status.path}`,
6516
+ suggestedAction: status.suggestedAction,
6517
+ status: 409
6518
+ };
6519
+ }
6520
+ if (!status.canCreate) {
6521
+ return {
6522
+ code: status.access === "append_only" ? "append_only_violation" : "agent_path_forbidden",
6523
+ message: `Create is not allowed for ${status.path}.`,
6524
+ suggestedAction: status.suggestedAction,
6525
+ status: 403
6526
+ };
6527
+ }
6528
+ }
6529
+ if (action === "update") {
6530
+ if (!status.exists) {
6531
+ return {
6532
+ code: "agent_file_not_found",
6533
+ message: `Agent markdown file does not exist: ${status.path}`,
6534
+ suggestedAction: status.suggestedAction,
6535
+ status: 404
6536
+ };
6537
+ }
6538
+ if (!status.canUpdate) {
6539
+ return {
6540
+ code: status.access === "append_only" ? "append_only_violation" : "agent_path_forbidden",
6541
+ message: `Update is not allowed for ${status.path}.`,
6542
+ suggestedAction: status.suggestedAction,
6543
+ status: 403
6544
+ };
6545
+ }
6546
+ }
6547
+ return null;
6548
+ }
6549
+ function statusCodeForAgentError(code) {
6550
+ if (code === "agent_parent_not_found" || code === "agent_file_not_found") {
6551
+ return 404;
6552
+ }
6553
+ if (code === "agent_file_already_exists") {
6554
+ return 409;
6555
+ }
6556
+ if (code === "unsupported_agent_file" || code === "invalid_agent_wiki_path") {
6557
+ return 422;
6558
+ }
6559
+ return 403;
6560
+ }
6561
+ async function runWriteFlow(params) {
6562
+ const status = await requestAgentMarkdownStatus({
6563
+ command: `${params.command}.status`,
6564
+ runtimeOptions: params.runtimeOptions,
6565
+ organizationId: params.organizationId,
6566
+ path: params.path,
6567
+ parentRef: params.parentRef
6568
+ });
6569
+ const preflightError = writePreflightError(status.data, params.action);
6570
+ if (preflightError) {
6571
+ return printLocalError({
6572
+ command: params.command,
6573
+ status: preflightError.status,
6574
+ code: preflightError.code,
6575
+ message: preflightError.message,
6576
+ suggestedAction: preflightError.suggestedAction,
6577
+ requestId: status.requestId,
6578
+ data: status.data
6579
+ });
6580
+ }
6581
+ const mutation = {
6582
+ create: {
6583
+ operationName: "CreateAgentMarkdownFile",
6584
+ field: "create_agent_markdown_file"
6585
+ },
6586
+ update: {
6587
+ operationName: "UpdateAgentMarkdownFile",
6588
+ field: "update_agent_markdown_file"
6589
+ }
6590
+ }[params.action];
6591
+ return runAgentMarkdownMutation({
6592
+ command: params.command,
6593
+ operationName: mutation.operationName,
6594
+ runtimeOptions: params.runtimeOptions,
6595
+ field: mutation.field,
6596
+ variables: {
6597
+ organization_id: params.organizationId,
6598
+ path: status.data.path,
6599
+ parent_ref: status.data.parentRef ?? params.parentRef,
6600
+ content: params.content
6601
+ }
6602
+ });
6603
+ }
6604
+ function addContentOptions(command) {
6605
+ return command.option("--content <content>", "Markdown content").option("--file <file>", "Read markdown content from a local file");
6606
+ }
6607
+ async function resolveOsmdContext(cmd) {
6608
+ const context = await resolveCommandContext(cmd.optsWithGlobals());
6609
+ return {
6610
+ organizationId: resolveOrganizationId(context.organizationId),
6611
+ runtimeOptions: context.runtimeOptions
6612
+ };
6613
+ }
6614
+ function registerOsmdCommands(program) {
6615
+ const osmd = program.command("osmd").description("OSMD and agent markdown operations; canonical OSMD is read-only");
6616
+ osmd.command("tree").description("Read the canonical OSMD tree with source/access metadata").option("--depth <depth>", "Selection depth for nested children", "1").option("--tree-view").action(async (opts, cmd) => {
6617
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6618
+ const depth = parseDepth(opts.depth);
6619
+ const result = await requestOsmdQuery({
6620
+ command: "osmd.tree",
6621
+ operationName: "MarkdownTreeRoot",
6622
+ runtimeOptions,
6623
+ field: "markdown_tree_root",
6624
+ variables: {
6625
+ organization_id: organizationId,
6626
+ tree_view: opts.treeView === true ? true : void 0
6627
+ },
6628
+ selectionSet: buildNodeSelectionSet(depth),
6629
+ schema: markdownTreeNodeSchema
6630
+ });
6631
+ return printEnvelopeAndExit({
6632
+ envelope: buildSuccessEnvelope({
6633
+ command: "osmd.tree",
6634
+ status: result.status,
6635
+ data: result.data,
6636
+ requestId: result.requestId
6637
+ })
6638
+ });
6639
+ });
6640
+ osmd.command("status <path>").description("Inspect canonical OSMD, .agent overlay, or Agent Wiki file metadata").option("--parent-ref <parentRef>", "Canonical OSMD parent ref for .agent files").action(async (path, opts, cmd) => {
6641
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6642
+ const result = await requestAgentMarkdownStatus({
6643
+ command: "osmd.status",
6644
+ runtimeOptions,
6645
+ organizationId,
6646
+ path: nonEmptyString3.parse(path).trim(),
6647
+ parentRef: parseOptionalParentRef(opts.parentRef)
6648
+ });
6649
+ return printEnvelopeAndExit({
6650
+ envelope: buildSuccessEnvelope({
6651
+ command: "osmd.status",
6652
+ status: result.status,
6653
+ data: result.data,
6654
+ requestId: result.requestId
6655
+ })
6656
+ });
6657
+ });
6658
+ osmd.command("read <path>").description("Read canonical OSMD, .agent overlay, or Agent Wiki markdown without creating files").option("--parent-ref <parentRef>", "Canonical OSMD parent ref for .agent files").action(async (path, opts, cmd) => {
6659
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6660
+ const result = await requestAgentMarkdownFile({
6661
+ command: "osmd.read",
6662
+ runtimeOptions,
6663
+ organizationId,
6664
+ path: nonEmptyString3.parse(path).trim(),
6665
+ parentRef: parseOptionalParentRef(opts.parentRef)
6666
+ });
6667
+ return printEnvelopeAndExit({
6668
+ envelope: buildSuccessEnvelope({
6669
+ command: "osmd.read",
6670
+ status: result.status,
6671
+ data: result.data,
6672
+ requestId: result.requestId
6673
+ })
6674
+ });
6675
+ });
6676
+ osmd.command("children [path]").description("List backend-supported agent markdown children; search remains canonical-only").option("--parent-ref <parentRef>", "Canonical OSMD parent ref for .agent files").option("--source <source>", "Filter by canonical_osmd, agent_overlay, or agent_wiki").action(async (path, opts, cmd) => {
6677
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6678
+ const result = await requestAgentMarkdownChildren({
6679
+ command: "osmd.children",
6680
+ runtimeOptions,
6681
+ organizationId,
6682
+ path: typeof path === "string" && path.trim() !== "" ? path.trim() : void 0,
6683
+ parentRef: parseOptionalParentRef(opts.parentRef),
6684
+ source: parseOptionalSource(opts.source)
6685
+ });
6686
+ return printEnvelopeAndExit({
6687
+ envelope: buildSuccessEnvelope({
6688
+ command: "osmd.children",
6689
+ status: result.status,
6690
+ data: result.data,
6691
+ requestId: result.requestId
6692
+ })
6693
+ });
6694
+ });
6695
+ const agent = osmd.command("agent").description(".agent overlay files writable by agents; supports notes.md and log.md");
6696
+ agent.command("status <parent-ref> <file>").action(async (parentRef, file, _opts, cmd) => {
6697
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6698
+ const result = await requestAgentMarkdownStatus({
6699
+ command: "osmd.agent.status",
6700
+ runtimeOptions,
6701
+ organizationId,
6702
+ path: normalizeAgentFilePath(file),
6703
+ parentRef: nonEmptyString3.parse(parentRef).trim()
6704
+ });
6705
+ return printEnvelopeAndExit({
6706
+ envelope: buildSuccessEnvelope({
6707
+ command: "osmd.agent.status",
6708
+ status: result.status,
6709
+ data: result.data,
6710
+ requestId: result.requestId
6711
+ })
6712
+ });
6713
+ });
6714
+ agent.command("init <parent-ref>").action(async (parentRef, _opts, cmd) => {
6715
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6716
+ return runAgentMarkdownMutation({
6717
+ command: "osmd.agent.init",
6718
+ operationName: "InitAgentMarkdown",
6719
+ runtimeOptions,
6720
+ field: "init_agent_markdown",
6721
+ variables: {
6722
+ organization_id: organizationId,
6723
+ path: ".agent",
6724
+ parent_ref: nonEmptyString3.parse(parentRef).trim()
6725
+ }
6726
+ });
6727
+ });
6728
+ agent.command("read <parent-ref> <file>").action(async (parentRef, file, _opts, cmd) => {
6729
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6730
+ const result = await requestAgentMarkdownFile({
6731
+ command: "osmd.agent.read",
6732
+ runtimeOptions,
6733
+ organizationId,
6734
+ path: normalizeAgentFilePath(file),
6735
+ parentRef: nonEmptyString3.parse(parentRef).trim()
6736
+ });
6737
+ return printEnvelopeAndExit({
6738
+ envelope: buildSuccessEnvelope({
6739
+ command: "osmd.agent.read",
6740
+ status: result.status,
6741
+ data: result.data,
6742
+ requestId: result.requestId
6743
+ })
6744
+ });
6745
+ });
6746
+ addContentOptions(agent.command("create <parent-ref> <file>")).action(
6747
+ async (parentRef, file, opts, cmd) => {
6748
+ const globals = cmd.optsWithGlobals();
6749
+ const content = await resolveContentInput(opts, globals);
6750
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6751
+ return runWriteFlow({
6752
+ command: "osmd.agent.create",
6753
+ action: "create",
6754
+ runtimeOptions,
6755
+ organizationId,
6756
+ path: normalizeAgentFilePath(file),
6757
+ parentRef: nonEmptyString3.parse(parentRef).trim(),
6758
+ content
6759
+ });
6760
+ }
6761
+ );
6762
+ addContentOptions(agent.command("update <parent-ref> <file>")).action(
6763
+ async (parentRef, file, opts, cmd) => {
6764
+ const globals = cmd.optsWithGlobals();
6765
+ const content = await resolveContentInput(opts, globals);
6766
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6767
+ return runWriteFlow({
6768
+ command: "osmd.agent.update",
6769
+ action: "update",
6770
+ runtimeOptions,
6771
+ organizationId,
6772
+ path: normalizeAgentFilePath(file),
6773
+ parentRef: nonEmptyString3.parse(parentRef).trim(),
6774
+ content
6775
+ });
6776
+ }
6777
+ );
6778
+ const wiki = osmd.command("wiki").description("Agent Wiki files writable by agents; first slice should use index.md and log.md");
6779
+ wiki.command("status <path>").action(async (path, _opts, cmd) => {
6780
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6781
+ const result = await requestAgentMarkdownStatus({
6782
+ command: "osmd.wiki.status",
6783
+ runtimeOptions,
6784
+ organizationId,
6785
+ path: normalizeWikiPath(path)
6786
+ });
6787
+ return printEnvelopeAndExit({
6788
+ envelope: buildSuccessEnvelope({
6789
+ command: "osmd.wiki.status",
6790
+ status: result.status,
6791
+ data: result.data,
6792
+ requestId: result.requestId
6793
+ })
6794
+ });
6795
+ });
6796
+ wiki.command("read <path>").action(async (path, _opts, cmd) => {
6797
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6798
+ const result = await requestAgentMarkdownFile({
6799
+ command: "osmd.wiki.read",
6800
+ runtimeOptions,
6801
+ organizationId,
6802
+ path: normalizeWikiPath(path)
6803
+ });
6804
+ return printEnvelopeAndExit({
6805
+ envelope: buildSuccessEnvelope({
6806
+ command: "osmd.wiki.read",
6807
+ status: result.status,
6808
+ data: result.data,
6809
+ requestId: result.requestId
6810
+ })
6811
+ });
6812
+ });
6813
+ wiki.command("children [path]").action(async (path, _opts, cmd) => {
6814
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6815
+ const result = await requestAgentMarkdownChildren({
6816
+ command: "osmd.wiki.children",
6817
+ runtimeOptions,
6818
+ organizationId,
6819
+ path: typeof path === "string" && path.trim() !== "" ? normalizeWikiPath(path) : "Agent Wiki",
6820
+ source: "agent_wiki"
6821
+ });
6822
+ return printEnvelopeAndExit({
6823
+ envelope: buildSuccessEnvelope({
6824
+ command: "osmd.wiki.children",
6825
+ status: result.status,
6826
+ data: result.data,
6827
+ requestId: result.requestId
6828
+ })
6829
+ });
6830
+ });
6831
+ addContentOptions(wiki.command("create <path>")).action(async (path, opts, cmd) => {
6832
+ const globals = cmd.optsWithGlobals();
6833
+ const content = await resolveContentInput(opts, globals);
6834
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6835
+ return runWriteFlow({
6836
+ command: "osmd.wiki.create",
6837
+ action: "create",
6838
+ runtimeOptions,
6839
+ organizationId,
6840
+ path: normalizeWikiPath(path),
6841
+ content
6842
+ });
6843
+ });
6844
+ addContentOptions(wiki.command("update <path>")).action(async (path, opts, cmd) => {
6845
+ const globals = cmd.optsWithGlobals();
6846
+ const content = await resolveContentInput(opts, globals);
6847
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6848
+ return runWriteFlow({
6849
+ command: "osmd.wiki.update",
6850
+ action: "update",
6851
+ runtimeOptions,
6852
+ organizationId,
6853
+ path: normalizeWikiPath(path),
6854
+ content
6855
+ });
6856
+ });
6857
+ }
6858
+
6080
6859
  // src/cli.ts
6081
6860
  function buildCli(options) {
6082
6861
  const program = new import_commander.Command();
@@ -6114,6 +6893,7 @@ function buildCli(options) {
6114
6893
  registerContentCommands(program);
6115
6894
  registerMutationCapabilityCommands(program);
6116
6895
  registerMarkdownTreeCommands(program);
6896
+ registerOsmdCommands(program);
6117
6897
  registerNavigationCommands(program);
6118
6898
  return program;
6119
6899
  }
@@ -6169,13 +6949,13 @@ main().catch((error) => {
6169
6949
  });
6170
6950
  return;
6171
6951
  }
6172
- if (error instanceof import_zod16.ZodError || error instanceof import_commander2.InvalidArgumentError) {
6952
+ if (error instanceof import_zod17.ZodError || error instanceof import_commander2.InvalidArgumentError) {
6173
6953
  printCliFailure({
6174
6954
  status: 400,
6175
6955
  code: "invalid_args",
6176
6956
  message: "Invalid command arguments.",
6177
6957
  details: {
6178
- issues: error instanceof import_zod16.ZodError ? error.issues : [{ message: error.message, code: "invalid_argument" }]
6958
+ issues: error instanceof import_zod17.ZodError ? error.issues : [{ message: error.message, code: "invalid_argument" }]
6179
6959
  },
6180
6960
  exitCode: EXIT_CODES.invalidArgs
6181
6961
  });