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