@ted-galago/wave-cli 0.1.13 → 0.1.15

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");
@@ -3073,10 +3073,14 @@ function registerMemberCommands(program) {
3073
3073
  members.command("list").option("--page <page>").option("--per <per>").option(
3074
3074
  "--include-coaches <includeCoaches>",
3075
3075
  "Include linked coach members. Defaults to false; omitted/false returns organization members only."
3076
+ ).option(
3077
+ "--include-disabled <includeDisabled>",
3078
+ "Include deactivated members. Defaults to false; omitted/false returns active members only."
3076
3079
  ).action(async (opts, cmd) => {
3077
3080
  const context = await resolveCommandContext(cmd.optsWithGlobals());
3078
3081
  const organizationId = resolveOrganizationId(context.organizationId);
3079
3082
  const includeCoaches = opts.includeCoaches === void 0 ? void 0 : parseStrictBooleanOption(opts.includeCoaches, "--include-coaches");
3083
+ const includeDisabled = opts.includeDisabled === void 0 ? void 0 : parseStrictBooleanOption(opts.includeDisabled, "--include-disabled");
3080
3084
  await runGraphqlQueryCommand({
3081
3085
  command: "members.list",
3082
3086
  runtimeOptions: context.runtimeOptions,
@@ -3085,7 +3089,8 @@ function registerMemberCommands(program) {
3085
3089
  organization_id: organizationId,
3086
3090
  page: opts.page,
3087
3091
  per: opts.per,
3088
- include_coaches: includeCoaches
3092
+ include_coaches: includeCoaches,
3093
+ include_disabled: includeDisabled
3089
3094
  }),
3090
3095
  isList: true
3091
3096
  });
@@ -5138,6 +5143,13 @@ function baseNodeFields() {
5138
5143
  "nodeKey",
5139
5144
  "nodeKind",
5140
5145
  "runtimeLabel",
5146
+ "path",
5147
+ "source",
5148
+ "access",
5149
+ "owner",
5150
+ "parentRef",
5151
+ "agentChildrenAllowed",
5152
+ "exists",
5141
5153
  "resolvedScope { parentId recordId memberId teamId contentType }",
5142
5154
  "isLeaf",
5143
5155
  "treeView",
@@ -6072,6 +6084,829 @@ function registerMutationCapabilityCommands(program) {
6072
6084
  });
6073
6085
  }
6074
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
+ if (action === "append") {
6548
+ if (!status.exists) {
6549
+ return {
6550
+ code: "agent_file_not_found",
6551
+ message: `Agent markdown file does not exist: ${status.path}`,
6552
+ suggestedAction: status.suggestedAction,
6553
+ status: 404
6554
+ };
6555
+ }
6556
+ if (!status.canAppend) {
6557
+ return {
6558
+ code: "append_only_violation",
6559
+ message: `Append is not allowed for ${status.path}.`,
6560
+ suggestedAction: status.suggestedAction,
6561
+ status: 403
6562
+ };
6563
+ }
6564
+ }
6565
+ return null;
6566
+ }
6567
+ function statusCodeForAgentError(code) {
6568
+ if (code === "agent_parent_not_found" || code === "agent_file_not_found") {
6569
+ return 404;
6570
+ }
6571
+ if (code === "agent_file_already_exists") {
6572
+ return 409;
6573
+ }
6574
+ if (code === "unsupported_agent_file" || code === "invalid_agent_wiki_path") {
6575
+ return 422;
6576
+ }
6577
+ return 403;
6578
+ }
6579
+ async function runWriteFlow(params) {
6580
+ const status = await requestAgentMarkdownStatus({
6581
+ command: `${params.command}.status`,
6582
+ runtimeOptions: params.runtimeOptions,
6583
+ organizationId: params.organizationId,
6584
+ path: params.path,
6585
+ parentRef: params.parentRef
6586
+ });
6587
+ const preflightError = writePreflightError(status.data, params.action);
6588
+ if (preflightError) {
6589
+ return printLocalError({
6590
+ command: params.command,
6591
+ status: preflightError.status,
6592
+ code: preflightError.code,
6593
+ message: preflightError.message,
6594
+ suggestedAction: preflightError.suggestedAction,
6595
+ requestId: status.requestId,
6596
+ data: status.data
6597
+ });
6598
+ }
6599
+ const mutation = {
6600
+ create: {
6601
+ operationName: "CreateAgentMarkdownFile",
6602
+ field: "create_agent_markdown_file"
6603
+ },
6604
+ update: {
6605
+ operationName: "UpdateAgentMarkdownFile",
6606
+ field: "update_agent_markdown_file"
6607
+ },
6608
+ append: {
6609
+ operationName: "AppendAgentMarkdownFile",
6610
+ field: "append_agent_markdown_file"
6611
+ }
6612
+ }[params.action];
6613
+ return runAgentMarkdownMutation({
6614
+ command: params.command,
6615
+ operationName: mutation.operationName,
6616
+ runtimeOptions: params.runtimeOptions,
6617
+ field: mutation.field,
6618
+ variables: {
6619
+ organization_id: params.organizationId,
6620
+ path: status.data.path,
6621
+ parent_ref: status.data.parentRef ?? params.parentRef,
6622
+ content: params.content
6623
+ }
6624
+ });
6625
+ }
6626
+ function addContentOptions(command) {
6627
+ return command.option("--content <content>", "Markdown content").option("--file <file>", "Read markdown content from a local file");
6628
+ }
6629
+ async function resolveOsmdContext(cmd) {
6630
+ const context = await resolveCommandContext(cmd.optsWithGlobals());
6631
+ return {
6632
+ organizationId: resolveOrganizationId(context.organizationId),
6633
+ runtimeOptions: context.runtimeOptions
6634
+ };
6635
+ }
6636
+ function registerOsmdCommands(program) {
6637
+ const osmd = program.command("osmd").description("OSMD and agent markdown operations; canonical OSMD is read-only");
6638
+ 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) => {
6639
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6640
+ const depth = parseDepth(opts.depth);
6641
+ const result = await requestOsmdQuery({
6642
+ command: "osmd.tree",
6643
+ operationName: "MarkdownTreeRoot",
6644
+ runtimeOptions,
6645
+ field: "markdown_tree_root",
6646
+ variables: {
6647
+ organization_id: organizationId,
6648
+ tree_view: opts.treeView === true ? true : void 0
6649
+ },
6650
+ selectionSet: buildNodeSelectionSet(depth),
6651
+ schema: markdownTreeNodeSchema
6652
+ });
6653
+ return printEnvelopeAndExit({
6654
+ envelope: buildSuccessEnvelope({
6655
+ command: "osmd.tree",
6656
+ status: result.status,
6657
+ data: result.data,
6658
+ requestId: result.requestId
6659
+ })
6660
+ });
6661
+ });
6662
+ 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) => {
6663
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6664
+ const result = await requestAgentMarkdownStatus({
6665
+ command: "osmd.status",
6666
+ runtimeOptions,
6667
+ organizationId,
6668
+ path: nonEmptyString3.parse(path).trim(),
6669
+ parentRef: parseOptionalParentRef(opts.parentRef)
6670
+ });
6671
+ return printEnvelopeAndExit({
6672
+ envelope: buildSuccessEnvelope({
6673
+ command: "osmd.status",
6674
+ status: result.status,
6675
+ data: result.data,
6676
+ requestId: result.requestId
6677
+ })
6678
+ });
6679
+ });
6680
+ 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) => {
6681
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6682
+ const result = await requestAgentMarkdownFile({
6683
+ command: "osmd.read",
6684
+ runtimeOptions,
6685
+ organizationId,
6686
+ path: nonEmptyString3.parse(path).trim(),
6687
+ parentRef: parseOptionalParentRef(opts.parentRef)
6688
+ });
6689
+ return printEnvelopeAndExit({
6690
+ envelope: buildSuccessEnvelope({
6691
+ command: "osmd.read",
6692
+ status: result.status,
6693
+ data: result.data,
6694
+ requestId: result.requestId
6695
+ })
6696
+ });
6697
+ });
6698
+ 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) => {
6699
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6700
+ const result = await requestAgentMarkdownChildren({
6701
+ command: "osmd.children",
6702
+ runtimeOptions,
6703
+ organizationId,
6704
+ path: typeof path === "string" && path.trim() !== "" ? path.trim() : void 0,
6705
+ parentRef: parseOptionalParentRef(opts.parentRef),
6706
+ source: parseOptionalSource(opts.source)
6707
+ });
6708
+ return printEnvelopeAndExit({
6709
+ envelope: buildSuccessEnvelope({
6710
+ command: "osmd.children",
6711
+ status: result.status,
6712
+ data: result.data,
6713
+ requestId: result.requestId
6714
+ })
6715
+ });
6716
+ });
6717
+ const agent = osmd.command("agent").description(".agent overlay files writable by agents; supports notes.md and log.md");
6718
+ agent.command("status <parent-ref> <file>").action(async (parentRef, file, _opts, cmd) => {
6719
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6720
+ const result = await requestAgentMarkdownStatus({
6721
+ command: "osmd.agent.status",
6722
+ runtimeOptions,
6723
+ organizationId,
6724
+ path: normalizeAgentFilePath(file),
6725
+ parentRef: nonEmptyString3.parse(parentRef).trim()
6726
+ });
6727
+ return printEnvelopeAndExit({
6728
+ envelope: buildSuccessEnvelope({
6729
+ command: "osmd.agent.status",
6730
+ status: result.status,
6731
+ data: result.data,
6732
+ requestId: result.requestId
6733
+ })
6734
+ });
6735
+ });
6736
+ agent.command("init <parent-ref>").action(async (parentRef, _opts, cmd) => {
6737
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6738
+ return runAgentMarkdownMutation({
6739
+ command: "osmd.agent.init",
6740
+ operationName: "InitAgentMarkdown",
6741
+ runtimeOptions,
6742
+ field: "init_agent_markdown",
6743
+ variables: {
6744
+ organization_id: organizationId,
6745
+ path: ".agent",
6746
+ parent_ref: nonEmptyString3.parse(parentRef).trim()
6747
+ }
6748
+ });
6749
+ });
6750
+ agent.command("read <parent-ref> <file>").action(async (parentRef, file, _opts, cmd) => {
6751
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6752
+ const result = await requestAgentMarkdownFile({
6753
+ command: "osmd.agent.read",
6754
+ runtimeOptions,
6755
+ organizationId,
6756
+ path: normalizeAgentFilePath(file),
6757
+ parentRef: nonEmptyString3.parse(parentRef).trim()
6758
+ });
6759
+ return printEnvelopeAndExit({
6760
+ envelope: buildSuccessEnvelope({
6761
+ command: "osmd.agent.read",
6762
+ status: result.status,
6763
+ data: result.data,
6764
+ requestId: result.requestId
6765
+ })
6766
+ });
6767
+ });
6768
+ addContentOptions(agent.command("create <parent-ref> <file>")).action(
6769
+ async (parentRef, file, opts, cmd) => {
6770
+ const globals = cmd.optsWithGlobals();
6771
+ const content = await resolveContentInput(opts, globals);
6772
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6773
+ return runWriteFlow({
6774
+ command: "osmd.agent.create",
6775
+ action: "create",
6776
+ runtimeOptions,
6777
+ organizationId,
6778
+ path: normalizeAgentFilePath(file),
6779
+ parentRef: nonEmptyString3.parse(parentRef).trim(),
6780
+ content
6781
+ });
6782
+ }
6783
+ );
6784
+ addContentOptions(agent.command("update <parent-ref> <file>")).action(
6785
+ async (parentRef, file, opts, cmd) => {
6786
+ const globals = cmd.optsWithGlobals();
6787
+ const content = await resolveContentInput(opts, globals);
6788
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6789
+ return runWriteFlow({
6790
+ command: "osmd.agent.update",
6791
+ action: "update",
6792
+ runtimeOptions,
6793
+ organizationId,
6794
+ path: normalizeAgentFilePath(file),
6795
+ parentRef: nonEmptyString3.parse(parentRef).trim(),
6796
+ content
6797
+ });
6798
+ }
6799
+ );
6800
+ addContentOptions(agent.command("append <parent-ref> <file>")).action(
6801
+ async (parentRef, file, opts, cmd) => {
6802
+ const globals = cmd.optsWithGlobals();
6803
+ const content = await resolveContentInput(opts, globals);
6804
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6805
+ return runWriteFlow({
6806
+ command: "osmd.agent.append",
6807
+ action: "append",
6808
+ runtimeOptions,
6809
+ organizationId,
6810
+ path: normalizeAgentFilePath(file),
6811
+ parentRef: nonEmptyString3.parse(parentRef).trim(),
6812
+ content
6813
+ });
6814
+ }
6815
+ );
6816
+ const wiki = osmd.command("wiki").description("Agent Wiki files writable by agents; first slice should use index.md and log.md");
6817
+ wiki.command("status <path>").action(async (path, _opts, cmd) => {
6818
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6819
+ const result = await requestAgentMarkdownStatus({
6820
+ command: "osmd.wiki.status",
6821
+ runtimeOptions,
6822
+ organizationId,
6823
+ path: normalizeWikiPath(path)
6824
+ });
6825
+ return printEnvelopeAndExit({
6826
+ envelope: buildSuccessEnvelope({
6827
+ command: "osmd.wiki.status",
6828
+ status: result.status,
6829
+ data: result.data,
6830
+ requestId: result.requestId
6831
+ })
6832
+ });
6833
+ });
6834
+ wiki.command("read <path>").action(async (path, _opts, cmd) => {
6835
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6836
+ const result = await requestAgentMarkdownFile({
6837
+ command: "osmd.wiki.read",
6838
+ runtimeOptions,
6839
+ organizationId,
6840
+ path: normalizeWikiPath(path)
6841
+ });
6842
+ return printEnvelopeAndExit({
6843
+ envelope: buildSuccessEnvelope({
6844
+ command: "osmd.wiki.read",
6845
+ status: result.status,
6846
+ data: result.data,
6847
+ requestId: result.requestId
6848
+ })
6849
+ });
6850
+ });
6851
+ wiki.command("children [path]").action(async (path, _opts, cmd) => {
6852
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6853
+ const result = await requestAgentMarkdownChildren({
6854
+ command: "osmd.wiki.children",
6855
+ runtimeOptions,
6856
+ organizationId,
6857
+ path: typeof path === "string" && path.trim() !== "" ? normalizeWikiPath(path) : "Agent Wiki",
6858
+ source: "agent_wiki"
6859
+ });
6860
+ return printEnvelopeAndExit({
6861
+ envelope: buildSuccessEnvelope({
6862
+ command: "osmd.wiki.children",
6863
+ status: result.status,
6864
+ data: result.data,
6865
+ requestId: result.requestId
6866
+ })
6867
+ });
6868
+ });
6869
+ addContentOptions(wiki.command("create <path>")).action(async (path, opts, cmd) => {
6870
+ const globals = cmd.optsWithGlobals();
6871
+ const content = await resolveContentInput(opts, globals);
6872
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6873
+ return runWriteFlow({
6874
+ command: "osmd.wiki.create",
6875
+ action: "create",
6876
+ runtimeOptions,
6877
+ organizationId,
6878
+ path: normalizeWikiPath(path),
6879
+ content
6880
+ });
6881
+ });
6882
+ addContentOptions(wiki.command("update <path>")).action(async (path, opts, cmd) => {
6883
+ const globals = cmd.optsWithGlobals();
6884
+ const content = await resolveContentInput(opts, globals);
6885
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6886
+ return runWriteFlow({
6887
+ command: "osmd.wiki.update",
6888
+ action: "update",
6889
+ runtimeOptions,
6890
+ organizationId,
6891
+ path: normalizeWikiPath(path),
6892
+ content
6893
+ });
6894
+ });
6895
+ addContentOptions(wiki.command("append <path>")).action(async (path, opts, cmd) => {
6896
+ const globals = cmd.optsWithGlobals();
6897
+ const content = await resolveContentInput(opts, globals);
6898
+ const { organizationId, runtimeOptions } = await resolveOsmdContext(cmd);
6899
+ return runWriteFlow({
6900
+ command: "osmd.wiki.append",
6901
+ action: "append",
6902
+ runtimeOptions,
6903
+ organizationId,
6904
+ path: normalizeWikiPath(path),
6905
+ content
6906
+ });
6907
+ });
6908
+ }
6909
+
6075
6910
  // src/cli.ts
6076
6911
  function buildCli(options) {
6077
6912
  const program = new import_commander.Command();
@@ -6109,6 +6944,7 @@ function buildCli(options) {
6109
6944
  registerContentCommands(program);
6110
6945
  registerMutationCapabilityCommands(program);
6111
6946
  registerMarkdownTreeCommands(program);
6947
+ registerOsmdCommands(program);
6112
6948
  registerNavigationCommands(program);
6113
6949
  return program;
6114
6950
  }
@@ -6164,13 +7000,13 @@ main().catch((error) => {
6164
7000
  });
6165
7001
  return;
6166
7002
  }
6167
- if (error instanceof import_zod16.ZodError || error instanceof import_commander2.InvalidArgumentError) {
7003
+ if (error instanceof import_zod17.ZodError || error instanceof import_commander2.InvalidArgumentError) {
6168
7004
  printCliFailure({
6169
7005
  status: 400,
6170
7006
  code: "invalid_args",
6171
7007
  message: "Invalid command arguments.",
6172
7008
  details: {
6173
- issues: error instanceof import_zod16.ZodError ? error.issues : [{ message: error.message, code: "invalid_argument" }]
7009
+ issues: error instanceof import_zod17.ZodError ? error.issues : [{ message: error.message, code: "invalid_argument" }]
6174
7010
  },
6175
7011
  exitCode: EXIT_CODES.invalidArgs
6176
7012
  });