@gethmy/mcp 2.11.2 → 2.13.0

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/cli.js CHANGED
@@ -990,6 +990,7 @@ import { createRequire as createRequire2 } from "node:module";
990
990
  import { program } from "commander";
991
991
 
992
992
  // src/server.ts
993
+ import { createHash as createHash4 } from "node:crypto";
993
994
  import { readFile } from "node:fs/promises";
994
995
  import { basename } from "node:path";
995
996
  // ../memory/dist/sync.js
@@ -1496,6 +1497,9 @@ var TIMINGS = {
1496
1497
  QUERY_STALE_TIME: 1000 * 60 * 5,
1497
1498
  QUERY_GC_TIME: 1000 * 60 * 60 * 24
1498
1499
  };
1500
+ // ../harmony-shared/dist/stageHandoff.js
1501
+ var HANDOFF_MARKER = "harmony:stage-handoff";
1502
+ var HANDOFF_BLOCK_RE = new RegExp("```json\\s*\\n//\\s*" + HANDOFF_MARKER + "\\s*\\n([\\s\\S]*?)\\n```", "m");
1499
1503
  // src/api-client.ts
1500
1504
  init_config();
1501
1505
  var RETRY_CONFIG = {
@@ -1855,9 +1859,29 @@ class HarmonyApiClient {
1855
1859
  async uploadCardAttachment(cardId, data) {
1856
1860
  return this.request("POST", `/cards/${cardId}/attachments`, data);
1857
1861
  }
1862
+ async requestCardAttachmentUploadUrl(cardId, data) {
1863
+ return this.request("POST", `/cards/${cardId}/attachment-upload-url`, data);
1864
+ }
1865
+ async finalizeCardAttachment(cardId, data) {
1866
+ return this.request("POST", `/cards/${cardId}/attachments/finalize`, data);
1867
+ }
1858
1868
  async getCardExternalLinks(cardId) {
1859
1869
  return this.request("GET", `/cards/${cardId}/external-links`);
1860
1870
  }
1871
+ async uploadArtifact(data) {
1872
+ return this.request("POST", "/artifacts", data);
1873
+ }
1874
+ async requestArtifactUploadUrl(data) {
1875
+ return this.request("POST", "/artifacts/upload-url", data);
1876
+ }
1877
+ async finalizeArtifact(data) {
1878
+ return this.request("POST", "/artifacts/finalize", data);
1879
+ }
1880
+ async createArtifactShareLink(artifactId, expiresAt) {
1881
+ return this.request("POST", `/artifacts/${artifactId}/share`, {
1882
+ expires_at: expiresAt
1883
+ });
1884
+ }
1861
1885
  async classifyCard(cardId) {
1862
1886
  return this.request("POST", `/cards/${cardId}/classify`);
1863
1887
  }
@@ -2324,6 +2348,30 @@ ${planContent.trim()}`;
2324
2348
  title: cardData.title
2325
2349
  };
2326
2350
  }
2351
+ async listPlaybooks(workspaceId) {
2352
+ return this.request("GET", `/playbooks?workspaceId=${encodeURIComponent(workspaceId)}`);
2353
+ }
2354
+ async getPlaybook(playbookId) {
2355
+ return this.request("GET", `/playbooks/${playbookId}`);
2356
+ }
2357
+ async getPlaybookVersion(playbookId, version) {
2358
+ return this.request("GET", `/playbooks/${encodeURIComponent(playbookId)}/versions/${version}`);
2359
+ }
2360
+ async recordStageGateEvidence(insert) {
2361
+ return this.request("POST", `/cards/${encodeURIComponent(insert.card_id)}/stage-gate-evidence`, insert);
2362
+ }
2363
+ async createPlaybook(data) {
2364
+ return this.request("POST", "/playbooks", data);
2365
+ }
2366
+ async updatePlaybook(playbookId, updates) {
2367
+ return this.request("PATCH", `/playbooks/${playbookId}`, updates);
2368
+ }
2369
+ async runPlaybook(playbookId) {
2370
+ return this.request("POST", `/playbooks/${playbookId}/run`);
2371
+ }
2372
+ async savePlaybookFromCard(data) {
2373
+ return this.request("POST", "/playbooks/from-card", data);
2374
+ }
2327
2375
  }
2328
2376
  var _promptModules = null;
2329
2377
  async function loadPromptModules() {
@@ -3410,6 +3458,52 @@ async function refreshSkills(opts = {}) {
3410
3458
  }
3411
3459
 
3412
3460
  // src/server.ts
3461
+ var MAX_ARTIFACT_SIZE = 2 * 1024 * 1024;
3462
+ var MAX_ATTACHMENT_SIZE = 5 * 1024 * 1024;
3463
+ function base64ByteLength(base64) {
3464
+ const stripped = base64.replace(/^data:[^,]*,/, "");
3465
+ return Buffer.from(stripped, "base64").byteLength;
3466
+ }
3467
+ function sha256Hex(bytes) {
3468
+ return createHash4("sha256").update(bytes).digest("hex");
3469
+ }
3470
+ async function readFileForUpload(filePath, maxSize, kind) {
3471
+ const bytes = await readFile(filePath);
3472
+ if (bytes.byteLength === 0) {
3473
+ throw new Error(`File is empty: ${filePath}`);
3474
+ }
3475
+ if (bytes.byteLength > maxSize) {
3476
+ const mb = Math.round(maxSize / (1024 * 1024));
3477
+ throw new Error(`File is ${bytes.byteLength} bytes, over the ${maxSize}-byte (${mb}MB) ${kind} limit.`);
3478
+ }
3479
+ return bytes;
3480
+ }
3481
+ function requireExactlyOneScope(scope) {
3482
+ if ([scope.cardId, scope.planId, scope.workspaceId].filter(Boolean).length !== 1) {
3483
+ throw new Error("Provide exactly one of cardId, planId, or workspaceId.");
3484
+ }
3485
+ }
3486
+ var SIGNED_UPLOAD_TIMEOUT_MS = 30000;
3487
+ async function putToSignedUrl(uploadUrl, bytes, contentType) {
3488
+ let res;
3489
+ try {
3490
+ res = await fetch(uploadUrl, {
3491
+ method: "PUT",
3492
+ headers: { "Content-Type": contentType },
3493
+ body: bytes,
3494
+ signal: AbortSignal.timeout(SIGNED_UPLOAD_TIMEOUT_MS)
3495
+ });
3496
+ } catch (err) {
3497
+ if (err instanceof DOMException && err.name === "TimeoutError") {
3498
+ throw new Error(`Direct storage upload timed out after ${SIGNED_UPLOAD_TIMEOUT_MS}ms.`);
3499
+ }
3500
+ throw err;
3501
+ }
3502
+ if (!res.ok) {
3503
+ const detail = await res.text().catch(() => "");
3504
+ throw new Error(`Direct storage upload failed: ${res.status}${detail ? ` — ${detail}` : ""}`);
3505
+ }
3506
+ }
3413
3507
  var memorySessions = new Map;
3414
3508
  function parseLabelList(raw) {
3415
3509
  if (raw === undefined || raw === null)
@@ -3870,7 +3964,7 @@ var TOOLS = {
3870
3964
  }
3871
3965
  },
3872
3966
  harmony_upload_card_attachment: {
3873
- description: "Upload a file attachment to a card (e.g. a pasted screenshot or a document). Provide the file either as `filePath` (a local path the MCP server can read — works in local/stdio mode) or as `base64Data` (raw base64 bytes — works everywhere, including remote mode). Max 5MB. Allowed: PNG, JPEG, GIF, WebP, HEIC/HEIF, PDF, DOC/DOCX, XLS/XLSX, TXT, CSV. Returns the stored attachment with a short-lived signed URL.",
3967
+ description: "Upload a file attachment to a card (e.g. a pasted screenshot or a document). Provide the file either as `filePath` (a local path the MCP server can read — works in local/stdio mode) or as `base64Data` (raw base64 bytes — works everywhere, including remote mode). With `filePath` the server uploads direct-to-storage (no base64 through the model context); `base64Data` is the small-file fallback. Max 5MB. Allowed: PNG, JPEG, GIF, WebP, HEIC/HEIF, PDF, DOC/DOCX, XLS/XLSX, TXT, CSV. Returns the stored attachment with a short-lived signed URL. For large files on the hosted MCP server (where only base64Data works), prefer the two-step harmony_request_card_attachment_upload_url + harmony_finalize_card_attachment handshake, which keeps bytes out of the model context.",
3874
3968
  inputSchema: {
3875
3969
  type: "object",
3876
3970
  properties: {
@@ -3895,6 +3989,58 @@ var TOOLS = {
3895
3989
  required: ["cardId"]
3896
3990
  }
3897
3991
  },
3992
+ harmony_request_card_attachment_upload_url: {
3993
+ description: "Step 1 of the agent-driven card-attachment upload — use this for large files or when running against the hosted MCP server (which cannot read your local disk). Mints a one-shot signed Supabase Storage upload URL for a server-chosen path under the card. Provide cardId, fileName (with extension), the byte size, and optionally fileType. Returns { uploadUrl, token, storagePath, fileType }. Next: PUT the raw bytes straight to uploadUrl (e.g. `curl -X PUT --data-binary @file.png '<uploadUrl>'`) — no bytes pass through the model context — then call harmony_finalize_card_attachment with the returned storagePath. Max 5MB; allowed: PNG, JPEG, GIF, WebP, HEIC/HEIF, PDF, DOC/DOCX, XLS/XLSX, TXT, CSV.",
3994
+ inputSchema: {
3995
+ type: "object",
3996
+ properties: {
3997
+ cardId: { type: "string", description: "Card UUID" },
3998
+ fileName: {
3999
+ type: "string",
4000
+ description: "File name including extension (e.g. 'screenshot.png')."
4001
+ },
4002
+ fileType: {
4003
+ type: "string",
4004
+ description: "Optional MIME type (e.g. 'image/png'). Inferred from the file extension when omitted."
4005
+ },
4006
+ size: {
4007
+ type: "number",
4008
+ description: "File size in bytes (rejected early if over 5MB)."
4009
+ }
4010
+ },
4011
+ required: ["cardId", "fileName", "size"]
4012
+ }
4013
+ },
4014
+ harmony_finalize_card_attachment: {
4015
+ description: "Step 2 of the agent-driven card-attachment upload. After PUTting the bytes to the signed uploadUrl from harmony_request_card_attachment_upload_url, call this with the returned storagePath to validate and register the attachment. The server re-downloads the object and enforces size, an allowlisted content-type (magic-byte sniff, never the declared type), and — when you pass sha256 — an integrity check, deleting the object and failing on any mismatch. Returns the stored attachment with a short-lived signed URL.",
4016
+ inputSchema: {
4017
+ type: "object",
4018
+ properties: {
4019
+ cardId: { type: "string", description: "Card UUID" },
4020
+ storagePath: {
4021
+ type: "string",
4022
+ description: "The storagePath returned by harmony_request_card_attachment_upload_url."
4023
+ },
4024
+ fileName: {
4025
+ type: "string",
4026
+ description: "File name including extension (e.g. 'screenshot.png')."
4027
+ },
4028
+ fileType: {
4029
+ type: "string",
4030
+ description: "Optional MIME type; inferred from the extension when omitted."
4031
+ },
4032
+ sha256: {
4033
+ type: "string",
4034
+ description: "Optional hex SHA-256 of the uploaded bytes; verified against the stored object."
4035
+ },
4036
+ size: {
4037
+ type: "number",
4038
+ description: "Optional byte size (advisory; re-validated server-side)."
4039
+ }
4040
+ },
4041
+ required: ["cardId", "storagePath", "fileName"]
4042
+ }
4043
+ },
3898
4044
  harmony_classify_card: {
3899
4045
  description: "Classify a card with the LLM classifier: sets `intent` (plan/think/implement/review), `complexity_score` (0-10), and `model_tier` (simple/advanced/research), stamps `classified_at`, and applies the canonical type label (feature/bug/idea). Use this right after creating a card (e.g. in the `hmy-new` flow) so it's classified in-flow instead of waiting for it to surface on the web board. Idempotent — safe to re-run. Never touches the user-owned `model_override`.",
3900
4046
  inputSchema: {
@@ -3905,6 +4051,102 @@ var TOOLS = {
3905
4051
  required: ["cardId"]
3906
4052
  }
3907
4053
  },
4054
+ harmony_upload_artifact: {
4055
+ description: "Host a self-contained HTML document (e.g. a visual design draft or diagram) in Harmony and link it to a card, a plan, or a workspace. The file is stored privately and rendered in-app inside a sandboxed cross-origin iframe. Provide exactly one of cardId, planId, or workspaceId. Supply the HTML as `filePath` (a local path the MCP server can read — uploaded direct-to-storage, no base64 through the model context) or `base64Data` (the small-file fallback). Only text/html, max 2MB. Returns the stored artifact with a short-lived signed URL; call harmony_share_artifact to mint a public link. For large files on the hosted MCP server (where only base64Data works), prefer the two-step harmony_request_artifact_upload_url + harmony_finalize_artifact handshake, which keeps bytes out of the model context.",
4056
+ inputSchema: {
4057
+ type: "object",
4058
+ properties: {
4059
+ title: {
4060
+ type: "string",
4061
+ description: "Display title (defaults to the file basename)."
4062
+ },
4063
+ cardId: { type: "string", description: "Link to this card (UUID)." },
4064
+ planId: { type: "string", description: "Link to this plan (UUID)." },
4065
+ workspaceId: {
4066
+ type: "string",
4067
+ description: "Attach to this workspace as a standalone artifact (UUID)."
4068
+ },
4069
+ filePath: {
4070
+ type: "string",
4071
+ description: "Absolute path to a local .html file the MCP server process can read. Mutually exclusive with base64Data."
4072
+ },
4073
+ base64Data: {
4074
+ type: "string",
4075
+ description: "Base64-encoded HTML bytes (a `data:` URL prefix is accepted and stripped). Mutually exclusive with filePath."
4076
+ }
4077
+ },
4078
+ required: []
4079
+ }
4080
+ },
4081
+ harmony_request_artifact_upload_url: {
4082
+ description: "Step 1 of the agent-driven artifact upload — use this for large files or when running against the hosted MCP server (which cannot read your local disk), instead of streaming base64 through the model context. Mints a one-shot signed Supabase Storage upload URL for a server-chosen path. Provide exactly one of cardId/planId/workspaceId, optionally a title and the byte size. Returns { uploadUrl, token, storagePath }. Next: PUT the raw HTML bytes straight to uploadUrl (e.g. `curl -X PUT --data-binary @doc.html '<uploadUrl>'`), then call harmony_finalize_artifact with the returned storagePath. Only text/html, max 2MB.",
4083
+ inputSchema: {
4084
+ type: "object",
4085
+ properties: {
4086
+ title: {
4087
+ type: "string",
4088
+ description: "Display title (defaults to the file basename at finalize)."
4089
+ },
4090
+ cardId: { type: "string", description: "Link to this card (UUID)." },
4091
+ planId: { type: "string", description: "Link to this plan (UUID)." },
4092
+ workspaceId: {
4093
+ type: "string",
4094
+ description: "Attach to this workspace as a standalone artifact (UUID)."
4095
+ },
4096
+ contentType: {
4097
+ type: "string",
4098
+ description: "MIME type; only 'text/html' is accepted (the default)."
4099
+ },
4100
+ size: {
4101
+ type: "number",
4102
+ description: "File size in bytes (rejected early if over 2MB)."
4103
+ }
4104
+ },
4105
+ required: []
4106
+ }
4107
+ },
4108
+ harmony_finalize_artifact: {
4109
+ description: "Step 2 of the agent-driven artifact upload. After PUTting the HTML bytes to the signed uploadUrl from harmony_request_artifact_upload_url, call this with the returned storagePath to validate and register the artifact. The server re-downloads the object and enforces size, the text/html content-type (magic-byte sniff), and — when you pass sha256 — an integrity check, deleting the object and failing on any mismatch. Provide the same one of cardId/planId/workspaceId used for the upload URL. Returns the stored artifact with a short-lived signed URL; call harmony_share_artifact to mint a public link.",
4110
+ inputSchema: {
4111
+ type: "object",
4112
+ properties: {
4113
+ storagePath: {
4114
+ type: "string",
4115
+ description: "The storagePath returned by harmony_request_artifact_upload_url."
4116
+ },
4117
+ title: { type: "string", description: "Display title." },
4118
+ cardId: { type: "string", description: "Link to this card (UUID)." },
4119
+ planId: { type: "string", description: "Link to this plan (UUID)." },
4120
+ workspaceId: {
4121
+ type: "string",
4122
+ description: "Attach to this workspace as a standalone artifact (UUID)."
4123
+ },
4124
+ sha256: {
4125
+ type: "string",
4126
+ description: "Optional hex SHA-256 of the uploaded bytes; verified against the stored object."
4127
+ },
4128
+ size: {
4129
+ type: "number",
4130
+ description: "Optional byte size (advisory; re-validated server-side)."
4131
+ }
4132
+ },
4133
+ required: ["storagePath"]
4134
+ }
4135
+ },
4136
+ harmony_share_artifact: {
4137
+ description: "Create a public, unauthenticated share link for a hosted artifact. Anyone with the link can view the rendered HTML without a Harmony account. Returns the share token and the full public URL.",
4138
+ inputSchema: {
4139
+ type: "object",
4140
+ properties: {
4141
+ artifactId: { type: "string", description: "Artifact UUID" },
4142
+ expiresInDays: {
4143
+ type: "number",
4144
+ description: "Optional expiry in days. Omit for a link that never expires."
4145
+ }
4146
+ },
4147
+ required: ["artifactId"]
4148
+ }
4149
+ },
3908
4150
  harmony_get_card_external_links: {
3909
4151
  description: "Get external URL references attached to a card (links to docs, gists, dashboards, etc.).",
3910
4152
  inputSchema: {
@@ -4864,6 +5106,110 @@ var TOOLS = {
4864
5106
  required: ["planId"]
4865
5107
  }
4866
5108
  },
5109
+ harmony_list_playbook: {
5110
+ description: "List a workspace's playbooks (reusable process definitions). Returns each playbook's name, version, steps_version, and state. Read-only.",
5111
+ inputSchema: {
5112
+ type: "object",
5113
+ properties: {
5114
+ workspaceId: {
5115
+ type: "string",
5116
+ description: "Workspace ID (optional if context set)"
5117
+ }
5118
+ },
5119
+ required: []
5120
+ }
5121
+ },
5122
+ harmony_get_playbook: {
5123
+ description: "Get one playbook by ID, including its steps/stages definition and its recent runs. Read-only.",
5124
+ inputSchema: {
5125
+ type: "object",
5126
+ properties: {
5127
+ playbookId: { type: "string", description: "Playbook ID (UUID)" }
5128
+ },
5129
+ required: ["playbookId"]
5130
+ }
5131
+ },
5132
+ harmony_run_playbook: {
5133
+ description: "Run a playbook server-side and return the finalized run. Only legacy automation playbooks (steps_version 1) are runnable; stage playbooks (steps_version 2) are rejected. The server drives every step to completion.",
5134
+ inputSchema: {
5135
+ type: "object",
5136
+ properties: {
5137
+ playbookId: {
5138
+ type: "string",
5139
+ description: "Playbook ID to run (UUID)"
5140
+ }
5141
+ },
5142
+ required: ["playbookId"]
5143
+ }
5144
+ },
5145
+ harmony_create_playbook: {
5146
+ description: "Create a new playbook in a workspace. Default steps_version 1 is a legacy automation macro (an array of tool steps); steps_version 2 is the Method stage model (an array of stage objects).",
5147
+ inputSchema: {
5148
+ type: "object",
5149
+ properties: {
5150
+ workspaceId: {
5151
+ type: "string",
5152
+ description: "Workspace ID (optional if context set)"
5153
+ },
5154
+ name: { type: "string", description: "Playbook name" },
5155
+ description: { type: "string", description: "Playbook description" },
5156
+ stepsVersion: {
5157
+ type: "number",
5158
+ enum: [1, 2],
5159
+ description: "1 = automation macro (tool steps), 2 = Method stage model (stage objects). Default 1."
5160
+ },
5161
+ steps: {
5162
+ type: "array",
5163
+ description: "Steps (steps_version 1: tool-step objects) or stages (steps_version 2: stage objects).",
5164
+ items: { type: "object" }
5165
+ }
5166
+ },
5167
+ required: ["name"]
5168
+ }
5169
+ },
5170
+ harmony_update_playbook: {
5171
+ description: "Update a playbook's name, description, steps/stages, enabled flag, or lifecycle state ('active'|'deprecated').",
5172
+ inputSchema: {
5173
+ type: "object",
5174
+ properties: {
5175
+ playbookId: {
5176
+ type: "string",
5177
+ description: "Playbook ID to update (UUID)"
5178
+ },
5179
+ name: { type: "string", description: "New name" },
5180
+ description: { type: "string", description: "New description" },
5181
+ steps: {
5182
+ type: "array",
5183
+ description: "New steps (v1) or stages (v2) array.",
5184
+ items: { type: "object" }
5185
+ },
5186
+ enabled: {
5187
+ type: "boolean",
5188
+ description: "Enable/disable the playbook"
5189
+ },
5190
+ state: {
5191
+ type: "string",
5192
+ enum: ["active", "deprecated"],
5193
+ description: "Lifecycle state"
5194
+ }
5195
+ },
5196
+ required: ["playbookId"]
5197
+ }
5198
+ },
5199
+ harmony_save_card_as_playbook: {
5200
+ description: "Save an existing card as a new steps_version 1 (automation) playbook, seeding one create-card step from the card. Returns the created playbook.",
5201
+ inputSchema: {
5202
+ type: "object",
5203
+ properties: {
5204
+ cardId: { type: "string", description: "Card ID to template (UUID)" },
5205
+ name: {
5206
+ type: "string",
5207
+ description: "Name for the new playbook (defaults to the card title)"
5208
+ }
5209
+ },
5210
+ required: ["cardId"]
5211
+ }
5212
+ },
4867
5213
  harmony_signup: {
4868
5214
  description: "Create a new user account. Returns a JWT session for subsequent authenticated calls. No API key required.",
4869
5215
  inputSchema: {
@@ -5384,32 +5730,163 @@ async function handleToolCall(name, args, deps) {
5384
5730
  const cardId = z.string().uuid().parse(args.cardId);
5385
5731
  const filePath = args.filePath != null ? z.string().parse(args.filePath) : undefined;
5386
5732
  const base64Data = args.base64Data != null ? z.string().parse(args.base64Data) : undefined;
5387
- let fileName = args.fileName != null ? z.string().parse(args.fileName) : undefined;
5733
+ const fileName = args.fileName != null ? z.string().parse(args.fileName) : undefined;
5388
5734
  const contentType = args.contentType != null ? z.string().parse(args.contentType) : undefined;
5389
5735
  if (filePath && base64Data) {
5390
5736
  throw new Error("Provide either filePath or base64Data, not both.");
5391
5737
  }
5392
- let data;
5393
5738
  if (filePath) {
5394
- const bytes = await readFile(filePath);
5395
- if (bytes.byteLength === 0) {
5396
- throw new Error(`File is empty: ${filePath}`);
5397
- }
5398
- data = bytes.toString("base64");
5399
- fileName = fileName || basename(filePath);
5400
- } else if (base64Data) {
5739
+ const bytes = await readFileForUpload(filePath, MAX_ATTACHMENT_SIZE, "attachment");
5740
+ const resolvedName = fileName || basename(filePath);
5741
+ const signed = await client3.requestCardAttachmentUploadUrl(cardId, {
5742
+ fileName: resolvedName,
5743
+ fileType: contentType,
5744
+ size: bytes.byteLength
5745
+ });
5746
+ await putToSignedUrl(signed.uploadUrl, bytes, contentType || signed.fileType || "application/octet-stream");
5747
+ return await client3.finalizeCardAttachment(cardId, {
5748
+ storagePath: signed.storagePath,
5749
+ fileName: resolvedName,
5750
+ fileType: contentType || signed.fileType,
5751
+ sha256: sha256Hex(bytes),
5752
+ size: bytes.byteLength
5753
+ });
5754
+ }
5755
+ if (base64Data) {
5401
5756
  if (!fileName) {
5402
5757
  throw new Error("fileName is required when using base64Data.");
5403
5758
  }
5404
- data = base64Data;
5405
- } else {
5406
- throw new Error("Provide either filePath or base64Data.");
5759
+ if (base64ByteLength(base64Data) > MAX_ATTACHMENT_SIZE) {
5760
+ throw new Error(`File is over the 5MB attachment limit. Use the harmony_request_card_attachment_upload_url + harmony_finalize_card_attachment handshake for large files.`);
5761
+ }
5762
+ return await client3.uploadCardAttachment(cardId, {
5763
+ fileName,
5764
+ data: base64Data,
5765
+ fileType: contentType
5766
+ });
5767
+ }
5768
+ throw new Error("Provide either filePath or base64Data.");
5769
+ }
5770
+ case "harmony_upload_artifact": {
5771
+ const title = args.title != null ? z.string().parse(args.title) : undefined;
5772
+ const cardId = args.cardId != null ? z.string().uuid().parse(args.cardId) : undefined;
5773
+ const planId = args.planId != null ? z.string().uuid().parse(args.planId) : undefined;
5774
+ const workspaceId = args.workspaceId != null ? z.string().uuid().parse(args.workspaceId) : undefined;
5775
+ requireExactlyOneScope({ cardId, planId, workspaceId });
5776
+ const filePath = args.filePath != null ? z.string().parse(args.filePath) : undefined;
5777
+ const base64Data = args.base64Data != null ? z.string().parse(args.base64Data) : undefined;
5778
+ if (filePath && base64Data) {
5779
+ throw new Error("Provide either filePath or base64Data, not both.");
5780
+ }
5781
+ if (filePath) {
5782
+ const bytes = await readFileForUpload(filePath, MAX_ARTIFACT_SIZE, "artifact");
5783
+ const resolvedTitle = title || basename(filePath);
5784
+ const signed = await client3.requestArtifactUploadUrl({
5785
+ title: resolvedTitle,
5786
+ cardId,
5787
+ planId,
5788
+ workspaceId,
5789
+ contentType: "text/html",
5790
+ size: bytes.byteLength
5791
+ });
5792
+ await putToSignedUrl(signed.uploadUrl, bytes, "text/html");
5793
+ return await client3.finalizeArtifact({
5794
+ storagePath: signed.storagePath,
5795
+ sha256: sha256Hex(bytes),
5796
+ size: bytes.byteLength,
5797
+ title: resolvedTitle,
5798
+ cardId,
5799
+ planId,
5800
+ workspaceId
5801
+ });
5802
+ }
5803
+ if (base64Data) {
5804
+ if (base64ByteLength(base64Data) > MAX_ARTIFACT_SIZE) {
5805
+ throw new Error(`Artifact is over the 2MB limit. Use the harmony_request_artifact_upload_url + harmony_finalize_artifact handshake for large files.`);
5806
+ }
5807
+ return await client3.uploadArtifact({
5808
+ title,
5809
+ cardId,
5810
+ planId,
5811
+ workspaceId,
5812
+ data: base64Data
5813
+ });
5814
+ }
5815
+ throw new Error("Provide either filePath or base64Data.");
5816
+ }
5817
+ case "harmony_request_artifact_upload_url": {
5818
+ const title = args.title != null ? z.string().parse(args.title) : undefined;
5819
+ const cardId = args.cardId != null ? z.string().uuid().parse(args.cardId) : undefined;
5820
+ const planId = args.planId != null ? z.string().uuid().parse(args.planId) : undefined;
5821
+ const workspaceId = args.workspaceId != null ? z.string().uuid().parse(args.workspaceId) : undefined;
5822
+ requireExactlyOneScope({ cardId, planId, workspaceId });
5823
+ const contentType = args.contentType != null ? z.string().parse(args.contentType) : undefined;
5824
+ const size = args.size != null ? z.number().positive().parse(args.size) : undefined;
5825
+ if (size != null && size > MAX_ARTIFACT_SIZE) {
5826
+ throw new Error(`Declared size ${size} bytes is over the ${MAX_ARTIFACT_SIZE}-byte (2MB) artifact limit.`);
5827
+ }
5828
+ return await client3.requestArtifactUploadUrl({
5829
+ title,
5830
+ cardId,
5831
+ planId,
5832
+ workspaceId,
5833
+ contentType,
5834
+ size
5835
+ });
5836
+ }
5837
+ case "harmony_finalize_artifact": {
5838
+ const storagePath = z.string().parse(args.storagePath);
5839
+ const title = args.title != null ? z.string().parse(args.title) : undefined;
5840
+ const cardId = args.cardId != null ? z.string().uuid().parse(args.cardId) : undefined;
5841
+ const planId = args.planId != null ? z.string().uuid().parse(args.planId) : undefined;
5842
+ const workspaceId = args.workspaceId != null ? z.string().uuid().parse(args.workspaceId) : undefined;
5843
+ requireExactlyOneScope({ cardId, planId, workspaceId });
5844
+ const sha256 = args.sha256 != null ? z.string().parse(args.sha256) : undefined;
5845
+ const size = args.size != null ? z.number().positive().parse(args.size) : undefined;
5846
+ return await client3.finalizeArtifact({
5847
+ storagePath,
5848
+ sha256,
5849
+ size,
5850
+ title,
5851
+ cardId,
5852
+ planId,
5853
+ workspaceId
5854
+ });
5855
+ }
5856
+ case "harmony_request_card_attachment_upload_url": {
5857
+ const cardId = z.string().uuid().parse(args.cardId);
5858
+ const fileName = z.string().parse(args.fileName);
5859
+ const fileType = args.fileType != null ? z.string().parse(args.fileType) : undefined;
5860
+ const size = z.number().positive().parse(args.size);
5861
+ if (size > MAX_ATTACHMENT_SIZE) {
5862
+ throw new Error(`Declared size ${size} bytes is over the ${MAX_ATTACHMENT_SIZE}-byte (5MB) attachment limit.`);
5407
5863
  }
5408
- const result = await client3.uploadCardAttachment(cardId, {
5864
+ return await client3.requestCardAttachmentUploadUrl(cardId, {
5409
5865
  fileName,
5410
- data,
5411
- fileType: contentType
5866
+ fileType,
5867
+ size
5412
5868
  });
5869
+ }
5870
+ case "harmony_finalize_card_attachment": {
5871
+ const cardId = z.string().uuid().parse(args.cardId);
5872
+ const storagePath = z.string().parse(args.storagePath);
5873
+ const fileName = z.string().parse(args.fileName);
5874
+ const fileType = args.fileType != null ? z.string().parse(args.fileType) : undefined;
5875
+ const sha256 = args.sha256 != null ? z.string().parse(args.sha256) : undefined;
5876
+ const size = args.size != null ? z.number().positive().parse(args.size) : undefined;
5877
+ return await client3.finalizeCardAttachment(cardId, {
5878
+ storagePath,
5879
+ fileName,
5880
+ fileType,
5881
+ sha256,
5882
+ size
5883
+ });
5884
+ }
5885
+ case "harmony_share_artifact": {
5886
+ const artifactId = z.string().uuid().parse(args.artifactId);
5887
+ const expiresInDays = args.expiresInDays != null ? z.number().positive().parse(args.expiresInDays) : undefined;
5888
+ const expiresAt = expiresInDays ? new Date(Date.now() + expiresInDays * 86400000).toISOString() : undefined;
5889
+ const result = await client3.createArtifactShareLink(artifactId, expiresAt);
5413
5890
  return result;
5414
5891
  }
5415
5892
  case "harmony_get_card_external_links": {
@@ -6315,6 +6792,57 @@ async function handleToolCall(name, args, deps) {
6315
6792
  ...results
6316
6793
  };
6317
6794
  }
6795
+ case "harmony_list_playbook": {
6796
+ const workspaceId = args.workspaceId || getWorkspaceId();
6797
+ const result = await client3.listPlaybooks(workspaceId);
6798
+ return {
6799
+ success: true,
6800
+ playbooks: result.playbooks,
6801
+ count: result.playbooks.length
6802
+ };
6803
+ }
6804
+ case "harmony_get_playbook": {
6805
+ const playbookId = z.string().uuid().parse(args.playbookId);
6806
+ const result = await client3.getPlaybook(playbookId);
6807
+ return { success: true, playbook: result.playbook, runs: result.runs };
6808
+ }
6809
+ case "harmony_run_playbook": {
6810
+ const playbookId = z.string().uuid().parse(args.playbookId);
6811
+ const result = await client3.runPlaybook(playbookId);
6812
+ return { success: true, run: result.run };
6813
+ }
6814
+ case "harmony_create_playbook": {
6815
+ const workspaceId = args.workspaceId || getWorkspaceId();
6816
+ const name2 = z.string().min(1).max(200).parse(args.name);
6817
+ const stepsVersion = args.stepsVersion !== undefined ? z.union([z.literal(1), z.literal(2)]).parse(args.stepsVersion) : undefined;
6818
+ const result = await client3.createPlaybook({
6819
+ workspaceId,
6820
+ name: name2,
6821
+ description: args.description,
6822
+ steps: args.steps,
6823
+ stepsVersion
6824
+ });
6825
+ return { success: true, playbook: result.playbook };
6826
+ }
6827
+ case "harmony_update_playbook": {
6828
+ const playbookId = z.string().uuid().parse(args.playbookId);
6829
+ const result = await client3.updatePlaybook(playbookId, {
6830
+ name: args.name,
6831
+ description: args.description,
6832
+ steps: args.steps,
6833
+ enabled: args.enabled,
6834
+ state: args.state
6835
+ });
6836
+ return { success: true, playbook: result.playbook };
6837
+ }
6838
+ case "harmony_save_card_as_playbook": {
6839
+ const cardId = z.string().uuid().parse(args.cardId);
6840
+ const result = await client3.savePlaybookFromCard({
6841
+ cardId,
6842
+ name: args.name
6843
+ });
6844
+ return { success: true, playbook: result.playbook };
6845
+ }
6318
6846
  case "harmony_signup": {
6319
6847
  const email = z.string().email().max(254).parse(args.email);
6320
6848
  const password = z.string().min(8).max(128).parse(args.password);
@@ -6479,7 +7007,7 @@ class HarmonyMCPServer {
6479
7007
  }
6480
7008
 
6481
7009
  // src/tui/setup.ts
6482
- import { createHash as createHash4 } from "node:crypto";
7010
+ import { createHash as createHash5 } from "node:crypto";
6483
7011
  import {
6484
7012
  existsSync as existsSync8,
6485
7013
  lstatSync,
@@ -7674,7 +8202,7 @@ ${summary}`);
7674
8202
  }
7675
8203
  try {
7676
8204
  const updateCheckFetched = await client3.fetchSkill("hmy-update-check");
7677
- const actualHash = createHash4("sha256").update(updateCheckFetched.content).digest("hex");
8205
+ const actualHash = createHash5("sha256").update(updateCheckFetched.content).digest("hex");
7678
8206
  if (actualHash !== updateCheckFetched.sha256) {
7679
8207
  throw new Error(`hmy-update-check integrity check failed: expected ${updateCheckFetched.sha256}, got ${actualHash}`);
7680
8208
  }