@llodev/pm-tasks-clickup 0.0.0-pr-130-7078a2a

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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +196 -0
  3. package/SKILL.md +258 -0
  4. package/anti-patterns/clickup.md +73 -0
  5. package/dist/adapter.d.ts +39 -0
  6. package/dist/adapter.d.ts.map +1 -0
  7. package/dist/adapter.js +83 -0
  8. package/dist/adapter.js.map +1 -0
  9. package/dist/bin/init.d.ts +3 -0
  10. package/dist/bin/init.d.ts.map +1 -0
  11. package/dist/bin/init.js +20 -0
  12. package/dist/bin/init.js.map +1 -0
  13. package/dist/doctor-cli.d.ts +27 -0
  14. package/dist/doctor-cli.d.ts.map +1 -0
  15. package/dist/doctor-cli.js +315 -0
  16. package/dist/doctor-cli.js.map +1 -0
  17. package/dist/env.d.ts +6 -0
  18. package/dist/env.d.ts.map +1 -0
  19. package/dist/env.js +11 -0
  20. package/dist/env.js.map +1 -0
  21. package/dist/envelope.d.ts +44 -0
  22. package/dist/envelope.d.ts.map +1 -0
  23. package/dist/envelope.js +95 -0
  24. package/dist/envelope.js.map +1 -0
  25. package/dist/errors.d.ts +30 -0
  26. package/dist/errors.d.ts.map +1 -0
  27. package/dist/errors.js +60 -0
  28. package/dist/errors.js.map +1 -0
  29. package/dist/estimation.d.ts +20 -0
  30. package/dist/estimation.d.ts.map +1 -0
  31. package/dist/estimation.js +40 -0
  32. package/dist/estimation.js.map +1 -0
  33. package/dist/index.d.ts +5 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +3 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/init-api.d.ts +67 -0
  38. package/dist/init-api.d.ts.map +1 -0
  39. package/dist/init-api.js +271 -0
  40. package/dist/init-api.js.map +1 -0
  41. package/dist/init-flow.d.ts +27 -0
  42. package/dist/init-flow.d.ts.map +1 -0
  43. package/dist/init-flow.js +206 -0
  44. package/dist/init-flow.js.map +1 -0
  45. package/dist/status-map.d.ts +31 -0
  46. package/dist/status-map.d.ts.map +1 -0
  47. package/dist/status-map.js +38 -0
  48. package/dist/status-map.js.map +1 -0
  49. package/dist/status.d.ts +17 -0
  50. package/dist/status.d.ts.map +1 -0
  51. package/dist/status.js +21 -0
  52. package/dist/status.js.map +1 -0
  53. package/dist/transport-clickup.d.ts +99 -0
  54. package/dist/transport-clickup.d.ts.map +1 -0
  55. package/dist/transport-clickup.js +676 -0
  56. package/dist/transport-clickup.js.map +1 -0
  57. package/docs/i18n/README.es-ES.md +196 -0
  58. package/docs/i18n/README.pt-BR.md +196 -0
  59. package/i18n/en-US.json +62 -0
  60. package/i18n/es-ES.json +62 -0
  61. package/i18n/pt-BR.json +62 -0
  62. package/manifest.json +14 -0
  63. package/package.json +64 -0
  64. package/references/autonomous.md +85 -0
  65. package/references/estimation.md +115 -0
  66. package/references/operations.md +128 -0
  67. package/schemas/config.json +140 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Response shapes of the ClickUp MCP. Writes return an envelope
3
+ * `{success, task_id, custom_id, task_url}`; `clickup_get_task` returns a bare,
4
+ * flat task; failures are `{"error": "<text>"}`, either thrown or resolved.
5
+ */
6
+ export function isObj(value) {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+ export function nonEmptyString(value) {
10
+ return typeof value === "string" && value !== "" ? value : undefined;
11
+ }
12
+ /** A non-empty string id, or a finite number id stringified (user ids are numbers). */
13
+ export function idString(value) {
14
+ if (typeof value === "number" && Number.isFinite(value))
15
+ return String(value);
16
+ return nonEmptyString(value);
17
+ }
18
+ /** A finite number given as a number or a numeric string (ClickUp sends both); else null. */
19
+ export function finiteNumber(value) {
20
+ if (typeof value !== "string" && typeof value !== "number")
21
+ return null;
22
+ if (value === "")
23
+ return null;
24
+ const n = Number(value);
25
+ return Number.isFinite(n) ? n : null;
26
+ }
27
+ /** ISO instant of an epoch-millisecond string or number; null when absent or unreadable. */
28
+ export function epochToIso(value) {
29
+ const ms = finiteNumber(value);
30
+ return ms === null ? null : new Date(ms).toISOString();
31
+ }
32
+ /** `https://app.clickup.com/t/<id>`: the task URL shape ClickUp returns (no workspace segment). */
33
+ export function taskUrl(id) {
34
+ return `https://app.clickup.com/t/${id}`;
35
+ }
36
+ /** Normalize a bare task or a write envelope; null when neither carries an id. */
37
+ export function unwrapTask(resp) {
38
+ if (!isObj(resp))
39
+ return null;
40
+ const id = nonEmptyString(resp.id) ?? nonEmptyString(resp.task_id);
41
+ if (id === undefined)
42
+ return null;
43
+ const url = nonEmptyString(resp.url) ?? nonEmptyString(resp.task_url);
44
+ const status = nonEmptyString(resp.status);
45
+ const listId = isObj(resp.list) ? idString(resp.list.id) : undefined;
46
+ const assigneeIds = Array.isArray(resp.assignees)
47
+ ? resp.assignees.flatMap((a) => {
48
+ const aid = isObj(a) ? idString(a.id) : undefined;
49
+ return aid === undefined ? [] : [aid];
50
+ })
51
+ : [];
52
+ const tagNames = Array.isArray(resp.tags)
53
+ ? resp.tags.flatMap((t) => {
54
+ const name = isObj(t) ? nonEmptyString(t.name) : undefined;
55
+ return name === undefined ? [] : [name];
56
+ })
57
+ : [];
58
+ let subtaskCount = 0;
59
+ if (typeof resp.subtasks_count === "number")
60
+ subtaskCount = resp.subtasks_count;
61
+ else if (Array.isArray(resp.subtasks))
62
+ subtaskCount = resp.subtasks.length;
63
+ const spaceId = isObj(resp.space) ? idString(resp.space.id) : undefined;
64
+ return {
65
+ id,
66
+ ...(url !== undefined ? { url } : {}),
67
+ ...(status !== undefined ? { status } : {}),
68
+ ...(listId !== undefined ? { listId } : {}),
69
+ parentId: nonEmptyString(resp.parent) ?? null,
70
+ assigneeIds,
71
+ tagNames,
72
+ dueDate: epochToIso(resp.due_date),
73
+ subtaskCount,
74
+ ...(spaceId !== undefined ? { spaceId } : {}),
75
+ timeEstimateMs: finiteNumber(resp.time_estimate),
76
+ };
77
+ }
78
+ /**
79
+ * Call a ClickUp MCP tool and turn a resolved failure (`{error}` without
80
+ * `success: true`, or `success: false`) into a thrown error, so every verb
81
+ * handles a resolved and a thrown failure the same way.
82
+ */
83
+ export async function callTool(mcp, tool, args) {
84
+ const resp = await mcp(tool, args);
85
+ if (isObj(resp)) {
86
+ if ("error" in resp && resp.success !== true) {
87
+ const err = resp.error;
88
+ throw new Error(typeof err === "string" ? err : JSON.stringify(err));
89
+ }
90
+ if (resp.success === false)
91
+ throw new Error(`${tool} reported success: false`);
92
+ }
93
+ return resp;
94
+ }
95
+ //# sourceMappingURL=envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH,MAAM,UAAU,KAAK,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvE,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9E,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACxE,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC9B,MAAM,CAAC,GAAG,MAAM,C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
+ /**
2
+ * Error helpers shared by the ClickUp transport verbs. Details carry the server
3
+ * message only: request arguments (names, descriptions, tokens) are never echoed.
4
+ */
5
+ import type { TransportErrorCode } from "@llodev/pm-tasks-core/runtime";
6
+ export interface TransportFailure {
7
+ ok: false;
8
+ code: TransportErrorCode;
9
+ details: Record<string, unknown>;
10
+ }
11
+ /**
12
+ * Classify a thrown error (or a resolved `{error}` already turned into one by
13
+ * `callTool`) into a TransportErrorCode. Status codes match as whole words, so an
14
+ * id that merely contains "404" is not a 404. "Status does not exist" stays
15
+ * MCP_ERROR here: the status verbs map it to INVALID_REQUEST `status_rejected`.
16
+ */
17
+ export declare function classifyError(e: unknown): {
18
+ code: TransportErrorCode;
19
+ details: Record<string, unknown>;
20
+ };
21
+ /** The MCP answered, but not with the shape the verb needs. */
22
+ export declare function shapeError(verb: string): TransportFailure;
23
+ /**
24
+ * A request ClickUp cannot honor. `reason` is a stable machine-readable token.
25
+ * `extra` carries ids and pinned status names from config or a task read (such
26
+ * as `listId`, `status`, `role`), never request arguments; it cannot replace
27
+ * `verb`, `reason` or `message`.
28
+ */
29
+ export declare function invalidRequest(verb: string, reason: string, message: string, extra?: Record<string, unknown>): TransportFailure;
30
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,KAAK,CAAC;IACV,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAaD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG;IACzC,IAAI,EAAE,kBAAkB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAmBA;AAED,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAMzD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAClC,gBAAgB,CAElB"}
package/dist/errors.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Error helpers shared by the ClickUp transport verbs. Details carry the server
3
+ * message only: request arguments (names, descriptions, tokens) are never echoed.
4
+ */
5
+ function messageOf(e) {
6
+ if (e instanceof Error)
7
+ return e.message;
8
+ if (typeof e === "string")
9
+ return e;
10
+ if (typeof e === "object" && e !== null) {
11
+ const { error, message } = e;
12
+ if (typeof error === "string")
13
+ return error;
14
+ if (typeof message === "string")
15
+ return message;
16
+ }
17
+ return String(e);
18
+ }
19
+ /**
20
+ * Classify a thrown error (or a resolved `{error}` already turned into one by
21
+ * `callTool`) into a TransportErrorCode. Status codes match as whole words, so an
22
+ * id that merely contains "404" is not a 404. "Status does not exist" stays
23
+ * MCP_ERROR here: the status verbs map it to INVALID_REQUEST `status_rejected`.
24
+ */
25
+ export function classifyError(e) {
26
+ const message = messageOf(e);
27
+ const msg = message.toLowerCase();
28
+ let code = "MCP_ERROR";
29
+ // ClickUp auth failures also read "not authorized", "Oauth token not found" or
30
+ // carry an `OAUTH_<n>` code; checked before "not found" so they stay AUTH.
31
+ if (/\b(401|403)\b/.test(msg) ||
32
+ ["unauthorized", "forbidden", "not authorized", "token not found", "oauth_"].some((s) => msg.includes(s))) {
33
+ code = "AUTH_ERROR";
34
+ }
35
+ else if (/\b429\b/.test(msg) || msg.includes("rate limit")) {
36
+ code = "RATE_LIMITED";
37
+ }
38
+ else if (/\b404\b/.test(msg) || msg.includes("not found")) {
39
+ code = "NOT_FOUND";
40
+ }
41
+ return { code, details: { message } };
42
+ }
43
+ /** The MCP answered, but not with the shape the verb needs. */
44
+ export function shapeError(verb) {
45
+ return {
46
+ ok: false,
47
+ code: "MCP_ERROR",
48
+ details: { message: "ClickUp MCP returned an unexpected response shape", verb },
49
+ };
50
+ }
51
+ /**
52
+ * A request ClickUp cannot honor. `reason` is a stable machine-readable token.
53
+ * `extra` carries ids and pinned status names from config or a task read (such
54
+ * as `listId`, `status`, `role`), never request arguments; it cannot replace
55
+ * `verb`, `reason` or `message`.
56
+ */
57
+ export function invalidRequest(verb, reason, message, extra = {}) {
58
+ return { ok: false, code: "INVALID_REQUEST", details: { ...extra, verb, reason, message } };
59
+ }
60
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,SAAS,SAAS,CAAC,CAAU;IAC3B,IAAI,CAAC,YAAY,KAAK;QAAE,OAAO,CAAC,CAAC,OAAO,CAAC;IACzC,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QACxC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAA2C,CAAC;QACvE,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC5C,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,OAAO,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,CAAU;IAItC,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAClC,IAAI,IAAI,GAAuB,WAAW,CAAC;IAC3C,+EAA+E;I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4
+ * Core's normalizeEstimate yields a time only for these strategies, so only they
5
+ * can target ClickUp's native time estimate; every other strategy yields points.
6
+ */
7
+ export declare const TIME_STRATEGIES: ReadonlySet<unknown>;
8
+ /**
9
+ * Minutes in `<n>m`, `<n>h` or `<n>d` (one day is `hoursPerDay` hours), rounded to a
10
+ * whole minute: `"2h"` → 120, `"1.5d"` at 6 hours a day → 540. NaN for any other form
11
+ * (a negative, NaN, Infinity or an exponent such as `1e-9h`); the caller rejects a
12
+ * result that is not a positive whole number.
13
+ */
14
+ export declare function toMinutes(timeString: string, hoursPerDay: number): number;
15
+ /**
16
+ * A tag-safe slug: lowercase, runs of anything but [a-z0-9] become one "-", no
17
+ * leading or trailing "-". `"1.5 ideal days"` → `"1-5-ideal-days"`.
18
+ */
19
+ export declare function slugify(s: string): string;
20
+ //# sourceMappingURL=estimation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimation.d.ts","sourceRoot":"","sources":["../src/estimation.ts"],"names":[],"mappings":"AAMA,0FAA0F;AAC1F,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,OAAO,CAG/C,CAAC;AAOH;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAMzE;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CASzC"}
@@ -0,0 +1,40 @@
1
+ /** Hours in one ideal day when `estimation.hoursPerDay` is unset (core's focused day). */
2
+ export const DEFAULT_HOURS_PER_DAY = 6;
3
+ /**
4
+ * Core's normalizeEstimate yields a time only for these strategies, so only they
5
+ * can target ClickUp's native time estimate; every other strategy yields points.
6
+ */
7
+ export const TIME_STRATEGIES = new Set([
8
+ "ideal_hours",
9
+ "ideal_days",
10
+ ]);
11
+ /** The time strings core's normalizeEstimate emits (`<n>h`, `<n>d`), plus minutes. */
12
+ const TIME_STRING = /^(\d+(?:\.\d+)?)([mhd])$/;
13
+ const UNIT_MINUTES = { m: 1, h: 60 };
14
+ /**
15
+ * Minutes in `<n>m`, `<n>h` or `<n>d` (one day is `hoursPerDay` hours), rounded to a
16
+ * whole minute: `"2h"` → 120, `"1.5d"` at 6 hours a day → 540. NaN for any other form
17
+ * (a negative, NaN, Infinity or an exponent such as `1e-9h`); the caller rejects a
18
+ * result that is not a positive whole number.
19
+ */
20
+ export function toMinutes(timeString, hoursPerDay) {
21
+ const match = TIME_STRING.exec(timeString);
22
+ if (!match)
23
+ return Number.NaN;
24
+ const unit = match[2];
25
+ const perUnit = unit === "d" ? hoursPerDay * 60 : UNIT_MINUTES[unit];
26
+ return Math.round(Number(match[1]) * perUnit);
27
+ }
28
+ /**
29
+ * A tag-safe slug: lowercase, runs of anything but [a-z0-9] become one "-", no
30
+ * leading or trailing "-". `"1.5 ideal days"` → `"1-5-ideal-days"`.
31
+ */
32
+ export function slugify(s) {
33
+ return (s
34
+ .toLowerCase()
35
+ .replace(/[^a-z0-9]+/g, "-")
36
+ // The previous replace already collapsed runs to one dash, so no `+` here
37
+ // (avoids polynomial ReDoS).
38
+ .replace(/^-|-$/g, ""));
39
+ }
40
+ //# sourceMappingURL=estimation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimation.js","sourceRoot":"","sources":["../src/estimation.ts"],"names":[],"mappings":"AAMA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAyB,IAAI,GAAG,CAAqB;IAC/E,aAAa;IACb,YAAY;CACb,CAAC,CAAC;AAEH,sFAAsF;AACtF,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAE/C,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAW,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,UAAkB,EAAE,WAAmB;IAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC;IAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAoB,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACrE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,CAAS;IAC/B,OAAO,CACL,CAAC;SACE,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;QAC5B,0EAA0E;QAC1E,6BAA6B;SAC5B,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CACzB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createClickUpTransport } from "./transport-clickup.js";
2
+ export type { McpCaller, ClickUpConfig, ClickUpListConfig, ClickUpEstimationConfig, ClickUpTaskEstimateSetRequest, ClickUpTransport, CreateClickUpTransportOptions, } from "./transport-clickup.js";
3
+ export { createAdapter } from "./adapter.js";
4
+ export type { CreateAdapterOptions } from "./adapter.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,YAAY,EACV,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,uBAAuB,EACvB,6BAA6B,EAC7B,gBAAgB,EAChB,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createClickUpTransport } from "./transport-clickup.js";
2
+ export { createAdapter } from "./adapter.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAUhE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Read-only discovery for `init` and `doctor`: workspaces, lists (with their
3
+ * space and folder), list statuses and members. One interface, two sources:
4
+ * the ClickUp MCP inside an agent session, and the REST API v2 with a personal
5
+ * token in a terminal. Nothing here prompts, writes or logs.
6
+ */
7
+ import type { ClickUpStatus } from "./status-map.js";
8
+ import type { McpCaller } from "./transport-clickup.js";
9
+ export interface ClickUpWorkspace {
10
+ id: string;
11
+ name: string;
12
+ }
13
+ export interface ClickUpListSummary {
14
+ id: string;
15
+ name: string;
16
+ space: {
17
+ id: string;
18
+ name: string;
19
+ };
20
+ /** Absent for a folderless list (ClickUp's hidden container is never a folder). */
21
+ folder?: {
22
+ id: string;
23
+ name: string;
24
+ };
25
+ }
26
+ export interface ClickUpMember {
27
+ id: string;
28
+ name: string;
29
+ email?: string;
30
+ }
31
+ export interface ClickUpInitApi {
32
+ getWorkspaces(): Promise<ClickUpWorkspace[]>;
33
+ /** Every non-archived list of the workspace: folder lists, then folderless lists, per space. */
34
+ getLists(workspaceId: string): Promise<ClickUpListSummary[]>;
35
+ getListStatuses(listId: string): Promise<ClickUpStatus[]>;
36
+ getMembers(workspaceId: string): Promise<ClickUpMember[]>;
37
+ }
38
+ /**
39
+ * - `AUTH`: the token is malformed, or the API answered 401/403.
40
+ * - `RATE_LIMIT`: the API answered 429.
41
+ * - `HTTP`: any other non-2xx answer (`status` holds the code).
42
+ * - `NETWORK`: the request failed or timed out.
43
+ * - `PARSE`: the answer is not JSON or lacks the expected shape.
44
+ * - `INVALID_ID`: an id meant for a URL path is not a digit string.
45
+ * - `NOT_FOUND`: the workspace is not among the token's workspaces.
46
+ *
47
+ * Messages never carry the token, a response body, a name or an id.
48
+ */
49
+ export type ClickUpInitErrorCode = "AUTH" | "RATE_LIMIT" | "HTTP" | "NETWORK" | "PARSE" | "INVALID_ID" | "NOT_FOUND";
50
+ export declare class ClickUpInitError extends Error {
51
+ readonly code: ClickUpInitErrorCode;
52
+ readonly status?: number;
53
+ constructor(code: ClickUpInitErrorCode, message: string, status?: number);
54
+ }
55
+ /**
56
+ * REST discovery with a personal token. The token is sent only as the raw
57
+ * `Authorization` header value (no `Bearer`), only on GET requests to the
58
+ * ClickUp API; it is never logged, put in a URL, returned or echoed in an error.
59
+ * Default requests return non-archived items only, which is what `init` offers.
60
+ */
61
+ export declare function createRestInitApi(token: string, fetchFn?: typeof fetch): ClickUpInitApi;
62
+ /**
63
+ * MCP discovery. The session is bound to one workspace: the hierarchy root.
64
+ * `workspace_id` is passed where the call is workspace-scoped (lists, members).
65
+ */
66
+ export declare function createMcpInitApi(mcp: McpCaller): ClickUpInitApi;
67
+ //# sourceMappingURL=init-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-api.d.ts","sourceRoot":"","sources":["../src/init-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK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0,0 +1,271 @@
1
+ /**
2
+ * Read-only discovery for `init` and `doctor`: workspaces, lists (with their
3
+ * space and folder), list statuses and members. One interface, two sources:
4
+ * the ClickUp MCP inside an agent session, and the REST API v2 with a personal
5
+ * token in a terminal. Nothing here prompts, writes or logs.
6
+ */
7
+ import { callTool, finiteNumber, idString, isObj, nonEmptyString } from "./envelope.js";
8
+ export class ClickUpInitError extends Error {
9
+ code;
10
+ status;
11
+ constructor(code, message, status) {
12
+ super(message);
13
+ this.name = "ClickUpInitError";
14
+ this.code = code;
15
+ if (status !== undefined)
16
+ this.status = status;
17
+ }
18
+ }
19
+ const STATUS_TYPES = new Set([
20
+ "open",
21
+ "custom",
22
+ "done",
23
+ "closed",
24
+ ]);
25
+ function str(value) {
26
+ return typeof value === "string" ? value : "";
27
+ }
28
+ function parseError(detail) {
29
+ return new ClickUpInitError("PARSE", `ClickUp init: unexpected ClickUp response (${detail}).`);
30
+ }
31
+ /** The objects of `body[key]`; a missing array is a shape error (fail closed). */
32
+ function arrayOf(body, key) {
33
+ const value = isObj(body) ? body[key] : undefined;
34
+ if (!Array.isArray(value))
35
+ throw parseError(`no "${key}" array`);
36
+ return value.filter(isObj);
37
+ }
38
+ function toStatuses(raw) {
39
+ return raw.flatMap((s) => {
40
+ if (typeof s.type !== "string" || !STATUS_TYPES.has(s.type))
41
+ return [];
42
+ const status = nonEmptyString(s.status);
43
+ if (status === undefined)
44
+ return [];
45
+ const orderindex = finiteNumber(s.orderindex);
46
+ return [
47
+ {
48
+ status,
49
+ type: s.type,
50
+ ...(orderindex !== null ? { orderindex } : {}),
51
+ },
52
+ ];
53
+ });
54
+ }
55
+ /** Member ids are numbers in ClickUp: normalized to strings. Never keyed by email. */
56
+ function toMember(raw) {
57
+ if (!isObj(raw))
58
+ return [];
59
+ const id = idString(raw.id);
60
+ if (id === undefined)
61
+ return [];
62
+ const email = nonEmptyString(raw.email);
63
+ const name = nonEmptyString(raw.name) ?? nonEmptyString(raw.username) ?? email ?? id;
64
+ return [{ id, name, ...(email !== undefined ? { email } : {}) }];
65
+ }
66
+ /** A user folder; undefined for ClickUp's hidden container (`hidden: true`) or no id. */
67
+ function userFolder(raw) {
68
+ if (!isObj(raw) || raw.hidden === true)
69
+ return undefined;
70
+ const id = idString(raw.id);
71
+ return id === undefined ? undefined : { id, name: str(raw.name) };
72
+ }
73
+ /** An archived list is never offered, whatever the response that carries it. */
74
+ function listSummary(raw, space, folder) {
75
+ if (!isObj(raw) || raw.archived === true)
76
+ return [];
77
+ const id = idString(raw.id);
78
+ if (id === undefined)
79
+ return [];
80
+ return [{ id, name: str(raw.name), space, ...(folder !== undefined ? { folder } : {}) }];
81
+ }
82
+ /** First occurrence wins: a list seen twice (two pages, two sources) is returned once. */
83
+ function uniqueById(items) {
84
+ const seen = new Set();
85
+ return items.filter((item) => {
86
+ if (seen.has(item.id))
87
+ return false;
88
+ seen.add(item.id);
89
+ return true;
90
+ });
91
+ }
92
+ // ---------------------------------------------------------------------------
93
+ // REST API v2 (terminal path, personal token)
94
+ // ---------------------------------------------------------------------------
95
+ const BASE_URL = "https://api.clickup.com/api/v2";
96
+ const REQUEST_TIMEOUT_MS = 30_000;
97
+ const TOKEN_HINT = "Set CLICKUP_API_TOKEN to a valid ClickUp personal API token.";
98
+ /** Visible ASCII only: no whitespace or control character can reach the header. */
99
+ const TOKEN_SHAPE = /^[\x21-\x7e]+$/;
100
+ const DIGITS = /^[0-9]+$/;
101
+ /** ClickUp ids are digit strings; anything else is rejected, never interpolated. */
102
+ function pathId(id, what) {
103
+ if (typeof id !== "string" || !DIGITS.test(id)) {
104
+ throw new ClickUpInitError("INVALID_ID", `ClickUp init: invalid ${what} id (expected digits only).`);
105
+ }
106
+ return id;
107
+ }
108
+ /**
109
+ * REST discovery with a personal token. The token is sent only as the raw
110
+ * `Authorization` header value (no `Bearer`), only on GET requests to the
111
+ * ClickUp API; it is never logged, put in a URL, returned or echoed in an error.
112
+ * Default requests return non-archived items only, which is what `init` offers.
113
+ */
114
+ export function createRestInitApi(token, fetchFn) {
115
+ const auth = typeof token === "string" ? token.trim() : "";
116
+ if (!TOKEN_SHAPE.test(auth)) {
117
+ throw new ClickUpInitError("AUTH", `ClickUp init: the API token is empty or malformed (it must not contain spaces, control characters or non-ASCII characters). ${TOKEN_HINT}`);
118
+ }
119
+ const doFetch = fetchFn ?? ((input, init) => globalThis.fetch(input, init));
120
+ async function get(path) {
121
+ let res;
122
+ try {
123
+ res = await doFetch(`${BASE_URL}${path}`, {
124
+ method: "GET",
125
+ headers: { Authorization: auth },
126
+ redirect: "error",
127
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
128
+ });
129
+ }
130
+ catch {
131
+ throw new ClickUpInitError("NETWORK", "ClickUp init: could not reach the ClickUp API (network error or timeout). Check the connection and try again.");
132
+ }
133
+ if (res.status === 401 || res.status === 403) {
134
+ throw new ClickUpInitError("AUTH", `ClickUp init: authentication failed (HTTP ${res.status}). ${TOKEN_HINT}`, res.status);
135
+ }
136
+ if (res.status === 429) {
137
+ throw new ClickUpInitError("RATE_LIMIT", "ClickUp init: the ClickUp API rate limit was reached (HTTP 429). Wait a minute and try again.", 429);
138
+ }
139
+ if (!res.ok) {
140
+ throw new ClickUpInitError("HTTP", `ClickUp init: the ClickUp API returned HTTP ${res.status}.`, res.status);
141
+ }
142
+ try {
143
+ return (await res.json());
144
+ }
145
+ catch {
146
+ throw parseError("the body is not valid JSON");
147
+ }
148
+ }
149
+ // `GET /team` carries the workspaces and their members: fetched once per api.
150
+ let teams;
151
+ function getTeams() {
152
+ teams ??= get("/team")
153
+ .then((body) => arrayOf(body, "teams"))
154
+ .catch((e) => {
155
+ teams = undefined; // a failure is not cached: a retry asks again
156
+ throw e;
157
+ });
158
+ return teams;
159
+ }
160
+ return {
161
+ getWorkspaces: async () => (await getTeams()).flatMap((t) => {
162
+ const id = idString(t.id);
163
+ return id === undefined ? [] : [{ id, name: str(t.name) }];
164
+ }),
165
+ // 1 call for the spaces, then 2 per space (folders with inline lists, folderless lists).
166
+ getLists: async (workspaceId) => {
167
+ const spaces = arrayOf(await get(`/team/${pathId(workspaceId, "workspace")}/space`), "spaces");
168
+ const lists = [];
169
+ for (const s of spaces) {
170
+ const space = { id: pathId(idString(s.id), "space"), name: str(s.name) };
171
+ for (const f of arrayOf(await get(`/space/${space.id}/folder`), "folders")) {
172
+ if (f.archived === true)
173
+ continue;
174
+ const folder = userFolder(f);
175
+ for (const l of arrayOf(f, "lists"))
176
+ lists.push(...listSummary(l, space, folder));
177
+ }
178
+ for (const l of arrayOf(await get(`/space/${space.id}/list`), "lists")) {
179
+ lists.push(...listSummary(l, space, userFolder(l.folder)));
180
+ }
181
+ }
182
+ return uniqueById(lists);
183
+ },
184
+ getListStatuses: async (listId) => toStatuses(arrayOf(await get(`/list/${pathId(listId, "list")}`), "statuses")),
185
+ getMembers: async (workspaceId) => {
186
+ const team = (await getTeams()).find((t) => idString(t.id) === workspaceId);
187
+ if (team === undefined) {
188
+ throw new ClickUpInitError("NOT_FOUND", "ClickUp init: the workspace is not among the token's workspaces.");
189
+ }
190
+ const members = Array.isArray(team.members) ? team.members : [];
191
+ return members.flatMap((m) => (isObj(m) ? toMember(m.user) : []));
192
+ },
193
+ };
194
+ }
195
+ // ---------------------------------------------------------------------------
196
+ // ClickUp MCP (agent-session path)
197
+ // ---------------------------------------------------------------------------
198
+ const HIERARCHY_TOOL = "clickup_get_workspace_hierarchy";
199
+ /** A bound on the cursor loop: a server that never stops paging fails instead of hanging. */
200
+ const MAX_HIERARCHY_PAGES = 50;
201
+ function hierarchyRoot(resp) {
202
+ const root = isObj(resp) && isObj(resp.hierarchy) ? resp.hierarchy.root : undefined;
203
+ if (!isObj(root))
204
+ throw parseError("no hierarchy root");
205
+ return root;
206
+ }
207
+ function childNodes(node, type) {
208
+ return Array.isArray(node.children)
209
+ ? node.children.filter((c) => isObj(c) && c.type === type)
210
+ : [];
211
+ }
212
+ /**
213
+ * MCP discovery. The session is bound to one workspace: the hierarchy root.
214
+ * `workspace_id` is passed where the call is workspace-scoped (lists, members).
215
+ */
216
+ export function createMcpInitApi(mcp) {
217
+ return {
218
+ getWorkspaces: async () => {
219
+ const root = hierarchyRoot(await callTool(mcp, HIERARCHY_TOOL, { max_depth: "2" }));
220
+ const id = idString(root.id);
221
+ if (id === undefined)
222
+ throw parseError("no workspace id");
223
+ return [{ id, name: str(root.name) }];
224
+ },
225
+ getLists: async (workspaceId) => {
226
+ const lists = [];
227
+ const seenCursors = new Set();
228
+ let cursor;
229
+ for (let pages = 1;; pages++) {
230
+ const resp = await callTool(mcp, HIERARCHY_TOOL, {
231
+ max_depth: "2",
232
+ workspace_id: workspaceId,
233
+ ...(cursor !== undefined ? { cursor } : {}),
234
+ });
235
+ for (const spaceNode of childNodes(hierarchyRoot(resp), "space")) {
236
+ const spaceId = idString(spaceNode.id);
237
+ if (spaceId === undefined)
238
+ continue;
239
+ const space = { id: spaceId, name: str(spaceNode.name) };
240
+ for (const folderNode of childNodes(spaceNode, "folder")) {
241
+ const folder = userFolder(folderNode);
242
+ for (const l of childNodes(folderNode, "list")) {
243
+ lists.push(...listSummary(l, space, folder));
244
+ }
245
+ }
246
+ for (const l of childNodes(spaceNode, "list")) {
247
+ lists.push(...listSummary(l, space, undefined));
248
+ }
249
+ }
250
+ const next = isObj(resp) ? nonEmptyString(resp.next_cursor) : undefined;
251
+ if (next === undefined) {
252
+ // More pages but no cursor: fail closed rather than return a partial list.
253
+ if (isObj(resp) && resp.has_more === true)
254
+ throw parseError("has_more without a cursor");
255
+ break;
256
+ }
257
+ if (seenCursors.has(next))
258
+ throw parseError("the pagination cursor did not advance");
259
+ if (pages >= MAX_HIERARCHY_PAGES) {
260
+ throw parseError(`more than ${MAX_HIERARCHY_PAGES} hierarchy pages`);
261
+ }
262
+ seenCursors.add(next);
263
+ cursor = next;
264
+ }
265
+ return uniqueById(lists);
266
+ },
267
+ getListStatuses: async (listId) => toStatuses(arrayOf(await callTool(mcp, "clickup_get_list", { list_id: listId }), "statuses")),
268
+ getMembers: async (workspaceId) => arrayOf(await callTool(mcp, "clickup_get_workspace_members", { workspace_id: workspaceId }), "members").flatMap(toMember),
269
+ };
270
+ }
271
+ //# sourceMappingURL=init-api.js.map