huly-mcp-selfhost 2.0.0 → 3.1.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.
Files changed (185) hide show
  1. package/.env.example +29 -2
  2. package/README.md +450 -15
  3. package/dist/connection.js +1 -1
  4. package/dist/connection.js.map +1 -1
  5. package/dist/env.d.ts +1 -0
  6. package/dist/env.js +17 -0
  7. package/dist/env.js.map +1 -0
  8. package/dist/guard.d.ts +28 -0
  9. package/dist/guard.js +152 -0
  10. package/dist/guard.js.map +1 -0
  11. package/dist/index.js +13 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/junit-cli.d.ts +8 -0
  14. package/dist/junit-cli.js +106 -0
  15. package/dist/junit-cli.js.map +1 -0
  16. package/dist/registry.d.ts +18 -0
  17. package/dist/registry.js +316 -0
  18. package/dist/registry.js.map +1 -0
  19. package/dist/resources.d.ts +12 -0
  20. package/dist/resources.js +212 -0
  21. package/dist/resources.js.map +1 -0
  22. package/dist/schemas.d.ts +1352 -435
  23. package/dist/schemas.js +881 -76
  24. package/dist/schemas.js.map +1 -1
  25. package/dist/server.d.ts +14 -1
  26. package/dist/server.js +141 -123
  27. package/dist/server.js.map +1 -1
  28. package/dist/tools/activity.d.ts +10 -0
  29. package/dist/tools/activity.js +62 -0
  30. package/dist/tools/activity.js.map +1 -0
  31. package/dist/tools/agent.d.ts +121 -0
  32. package/dist/tools/agent.js +400 -0
  33. package/dist/tools/agent.js.map +1 -0
  34. package/dist/tools/attachments.d.ts +4 -4
  35. package/dist/tools/calendar.d.ts +49 -0
  36. package/dist/tools/calendar.js +116 -0
  37. package/dist/tools/calendar.js.map +1 -0
  38. package/dist/tools/cards.d.ts +87 -0
  39. package/dist/tools/cards.js +246 -0
  40. package/dist/tools/cards.js.map +1 -0
  41. package/dist/tools/channels.d.ts +78 -9
  42. package/dist/tools/channels.js +86 -5
  43. package/dist/tools/channels.js.map +1 -1
  44. package/dist/tools/comments.d.ts +17 -5
  45. package/dist/tools/comments.js +26 -9
  46. package/dist/tools/comments.js.map +1 -1
  47. package/dist/tools/components.d.ts +28 -4
  48. package/dist/tools/components.js +69 -19
  49. package/dist/tools/components.js.map +1 -1
  50. package/dist/tools/contacts.d.ts +69 -0
  51. package/dist/tools/contacts.js +130 -0
  52. package/dist/tools/contacts.js.map +1 -0
  53. package/dist/tools/crm.d.ts +61 -0
  54. package/dist/tools/crm.js +117 -0
  55. package/dist/tools/crm.js.map +1 -0
  56. package/dist/tools/documents.d.ts +36 -13
  57. package/dist/tools/documents.js +105 -21
  58. package/dist/tools/documents.js.map +1 -1
  59. package/dist/tools/drive.d.ts +107 -0
  60. package/dist/tools/drive.js +277 -0
  61. package/dist/tools/drive.js.map +1 -0
  62. package/dist/tools/fields.d.ts +33 -0
  63. package/dist/tools/fields.js +124 -0
  64. package/dist/tools/fields.js.map +1 -0
  65. package/dist/tools/generic.d.ts +72 -0
  66. package/dist/tools/generic.js +242 -0
  67. package/dist/tools/generic.js.map +1 -0
  68. package/dist/tools/github.d.ts +21 -0
  69. package/dist/tools/github.js +80 -0
  70. package/dist/tools/github.js.map +1 -0
  71. package/dist/tools/hr.d.ts +97 -0
  72. package/dist/tools/hr.js +150 -0
  73. package/dist/tools/hr.js.map +1 -0
  74. package/dist/tools/inbox.d.ts +23 -0
  75. package/dist/tools/inbox.js +76 -0
  76. package/dist/tools/inbox.js.map +1 -0
  77. package/dist/tools/inventory.d.ts +61 -0
  78. package/dist/tools/inventory.js +103 -0
  79. package/dist/tools/inventory.js.map +1 -0
  80. package/dist/tools/issues.d.ts +61 -13
  81. package/dist/tools/issues.js +231 -35
  82. package/dist/tools/issues.js.map +1 -1
  83. package/dist/tools/labels.d.ts +52 -4
  84. package/dist/tools/labels.js +86 -4
  85. package/dist/tools/labels.js.map +1 -1
  86. package/dist/tools/log-time.d.ts +15 -1
  87. package/dist/tools/log-time.js +70 -6
  88. package/dist/tools/log-time.js.map +1 -1
  89. package/dist/tools/meetings.d.ts +30 -0
  90. package/dist/tools/meetings.js +78 -0
  91. package/dist/tools/meetings.js.map +1 -0
  92. package/dist/tools/members.d.ts +1 -1
  93. package/dist/tools/members.js +17 -1
  94. package/dist/tools/members.js.map +1 -1
  95. package/dist/tools/message-templates.d.ts +54 -0
  96. package/dist/tools/message-templates.js +88 -0
  97. package/dist/tools/message-templates.js.map +1 -0
  98. package/dist/tools/milestones.d.ts +40 -5
  99. package/dist/tools/milestones.js +102 -10
  100. package/dist/tools/milestones.js.map +1 -1
  101. package/dist/tools/organizations.d.ts +6 -6
  102. package/dist/tools/overview.d.ts +55 -0
  103. package/dist/tools/overview.js +395 -0
  104. package/dist/tools/overview.js.map +1 -0
  105. package/dist/tools/planner.d.ts +60 -0
  106. package/dist/tools/planner.js +145 -0
  107. package/dist/tools/planner.js.map +1 -0
  108. package/dist/tools/process.d.ts +50 -0
  109. package/dist/tools/process.js +137 -0
  110. package/dist/tools/process.js.map +1 -0
  111. package/dist/tools/products.d.ts +17 -0
  112. package/dist/tools/products.js +45 -0
  113. package/dist/tools/products.js.map +1 -0
  114. package/dist/tools/projects.d.ts +18 -5
  115. package/dist/tools/projects.js +31 -2
  116. package/dist/tools/projects.js.map +1 -1
  117. package/dist/tools/qms.d.ts +57 -0
  118. package/dist/tools/qms.js +171 -0
  119. package/dist/tools/qms.js.map +1 -0
  120. package/dist/tools/recruiting.d.ts +112 -0
  121. package/dist/tools/recruiting.js +203 -0
  122. package/dist/tools/recruiting.js.map +1 -0
  123. package/dist/tools/relations.d.ts +45 -3
  124. package/dist/tools/relations.js +128 -39
  125. package/dist/tools/relations.js.map +1 -1
  126. package/dist/tools/search.d.ts +15 -2
  127. package/dist/tools/search.js +29 -1
  128. package/dist/tools/search.js.map +1 -1
  129. package/dist/tools/sharing.d.ts +62 -0
  130. package/dist/tools/sharing.js +149 -0
  131. package/dist/tools/sharing.js.map +1 -0
  132. package/dist/tools/statuses.d.ts +3 -3
  133. package/dist/tools/surveys.d.ts +22 -0
  134. package/dist/tools/surveys.js +53 -0
  135. package/dist/tools/surveys.js.map +1 -0
  136. package/dist/tools/templates.d.ts +95 -0
  137. package/dist/tools/templates.js +260 -0
  138. package/dist/tools/templates.js.map +1 -0
  139. package/dist/tools/test-automation.d.ts +81 -0
  140. package/dist/tools/test-automation.js +225 -0
  141. package/dist/tools/test-automation.js.map +1 -0
  142. package/dist/tools/testing.d.ts +234 -0
  143. package/dist/tools/testing.js +401 -0
  144. package/dist/tools/testing.js.map +1 -0
  145. package/dist/tools/workspace-admin.d.ts +55 -0
  146. package/dist/tools/workspace-admin.js +117 -0
  147. package/dist/tools/workspace-admin.js.map +1 -0
  148. package/dist/tools/workspaces.d.ts +2 -2
  149. package/dist/utils/attributes.d.ts +37 -0
  150. package/dist/utils/attributes.js +188 -0
  151. package/dist/utils/attributes.js.map +1 -0
  152. package/dist/utils/classes.d.ts +51 -0
  153. package/dist/utils/classes.js +73 -0
  154. package/dist/utils/classes.js.map +1 -0
  155. package/dist/utils/content.d.ts +6 -0
  156. package/dist/utils/content.js +54 -0
  157. package/dist/utils/content.js.map +1 -0
  158. package/dist/utils/errors.js +1 -1
  159. package/dist/utils/errors.js.map +1 -1
  160. package/dist/utils/files.d.ts +5 -0
  161. package/dist/utils/files.js +50 -0
  162. package/dist/utils/files.js.map +1 -0
  163. package/dist/utils/format.d.ts +4 -0
  164. package/dist/utils/format.js +29 -0
  165. package/dist/utils/format.js.map +1 -1
  166. package/dist/utils/junit.d.ts +13 -0
  167. package/dist/utils/junit.js +81 -0
  168. package/dist/utils/junit.js.map +1 -0
  169. package/dist/utils/markdown.js +9 -4
  170. package/dist/utils/markdown.js.map +1 -1
  171. package/dist/utils/people.d.ts +25 -0
  172. package/dist/utils/people.js +80 -0
  173. package/dist/utils/people.js.map +1 -0
  174. package/dist/utils/resolve.d.ts +17 -0
  175. package/dist/utils/resolve.js +54 -0
  176. package/dist/utils/resolve.js.map +1 -0
  177. package/dist/utils/storage.js.map +1 -1
  178. package/dist/utils/tasks.d.ts +22 -0
  179. package/dist/utils/tasks.js +81 -0
  180. package/dist/utils/tasks.js.map +1 -0
  181. package/dist/watch.d.ts +62 -0
  182. package/dist/watch.js +405 -0
  183. package/dist/watch.js.map +1 -0
  184. package/package.json +9 -5
  185. package/scripts/setup.js +3 -1
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getActivity = void 0;
4
+ const core_1 = require("@hcengineering/core");
5
+ const connection_1 = require("../connection");
6
+ const errors_1 = require("../utils/errors");
7
+ const classes_1 = require("../utils/classes");
8
+ const format_1 = require("../utils/format");
9
+ const people_1 = require("../utils/people");
10
+ const resolve_1 = require("../utils/resolve");
11
+ const when = (ts) => new Date(ts).toISOString().slice(0, 16).replace('T', ' ');
12
+ async function describeValue(client, attrClass, value) {
13
+ if (value == null)
14
+ return '—';
15
+ if (typeof value === 'string' && attrClass != null && attrClass.includes(':class:') && !attrClass.startsWith('core:class:Type')) {
16
+ const label = await (0, resolve_1.loadLabel)(client, attrClass, value);
17
+ return label === value ? value : label.replace(/^[A-Z]+-\d+: /, '');
18
+ }
19
+ if (typeof value === 'number' && value > 1e12)
20
+ return when(value);
21
+ if (typeof value === 'string')
22
+ return (0, format_1.markupToText)(value).slice(0, 80);
23
+ return JSON.stringify(value).slice(0, 80);
24
+ }
25
+ exports.getActivity = (0, errors_1.wrapToolHandler)(async (args) => {
26
+ const client = await (0, connection_1.getConnection)(args.workspace);
27
+ const obj = await (0, resolve_1.resolveObject)(client, args.object);
28
+ const messages = await client.findAll(classes_1.C.ActivityMessage, { attachedTo: obj._id }, { sort: { createdOn: core_1.SortingOrder.Descending }, limit: args.limit });
29
+ if (messages.length === 0)
30
+ return `No activity for ${obj.label}.`;
31
+ messages.reverse();
32
+ const who = await (0, people_1.socialIdNames)(client, [...new Set(messages.map((m) => m.createdBy).filter((x) => x != null))]);
33
+ const lines = [];
34
+ for (const m of messages) {
35
+ const by = who.get(m.createdBy) ?? 'System';
36
+ let what;
37
+ if (m._class === classes_1.C.DocUpdateMessage) {
38
+ const u = m.attributeUpdates;
39
+ if (m.action === 'create')
40
+ what = 'created';
41
+ else if (m.action === 'remove')
42
+ what = `removed ${String(m.objectClass ?? '').split(':').pop() ?? ''}`;
43
+ else if (u != null) {
44
+ const set = await Promise.all((u.set ?? []).map(async (v) => await describeValue(client, u.attrClass, v)));
45
+ const added = await Promise.all((u.added ?? []).map(async (v) => await describeValue(client, u.attrClass, v)));
46
+ const removed = await Promise.all((u.removed ?? []).map(async (v) => await describeValue(client, u.attrClass, v)));
47
+ what = `${u.attrKey}: ${[set.length > 0 ? `→ ${set.join(', ')}` : '', added.length > 0 ? `+ ${added.join(', ')}` : '', removed.length > 0 ? `− ${removed.join(', ')}` : ''].filter(Boolean).join(' ') || 'changed'}`;
48
+ }
49
+ else
50
+ what = `updated ${String(m.objectClass ?? '').split(':').pop() ?? ''}`;
51
+ }
52
+ else if (typeof m.message === 'string') {
53
+ what = `💬 ${(0, format_1.markupToText)(m.message).slice(0, 200)}${(m.replies ?? 0) > 0 ? ` (${m.replies} replies)` : ''} \`${m._id}\``;
54
+ }
55
+ else {
56
+ what = String(m._class).split(':').pop() ?? 'activity';
57
+ }
58
+ lines.push(`- ${when(m.createdOn)} **${by}** ${what}`);
59
+ }
60
+ return `## Activity of ${obj.label} (last ${messages.length})\n\n${lines.join('\n')}`;
61
+ });
62
+ //# sourceMappingURL=activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activity.js","sourceRoot":"","sources":["../../src/tools/activity.ts"],"names":[],"mappings":";;;AAAA,8CAAkD;AAClD,8CAA6C;AAC7C,4CAAiD;AACjD,8CAAoC;AACpC,4CAA8C;AAC9C,4CAA+C;AAC/C,8CAA2D;AAI3D,MAAM,IAAI,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAA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CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAA;QAC/E,CAAC;aAAM,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzC,IAAI,GAAG,MAAM,IAAA,qBAAY,EAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAiB,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAa,IAAI,CAAA;QAC/I,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,UAAU,CAAA;QACxD,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,kBAAkB,GAAG,CAAC,KAAK,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AACvF,CAAC,CAAC,CAAA"}
@@ -0,0 +1,121 @@
1
+ export declare const CLAIM_LABEL = "agent:working";
2
+ export declare function branchName(identifier: string, title: string): string;
3
+ /** Full working context of an issue as one Markdown block. */
4
+ export declare function issueContext(workspace: string | undefined, identifier: string, commentLimit?: number): Promise<string>;
5
+ export declare const getIssueContext: (args: {
6
+ workspace?: string | undefined;
7
+ identifier: string;
8
+ commentLimit: number;
9
+ }) => Promise<{
10
+ content: Array<{
11
+ type: 'text';
12
+ text: string;
13
+ }>;
14
+ }>;
15
+ export declare const startWork: (args: {
16
+ workspace: string;
17
+ identifier: string;
18
+ statusName: string;
19
+ assignToMe: boolean;
20
+ claimAs?: string | undefined;
21
+ }) => Promise<{
22
+ content: Array<{
23
+ type: 'text';
24
+ text: string;
25
+ }>;
26
+ }>;
27
+ /** Finds a synced GitHub PR by "#12", "12", a GitHub URL or its Huly identifier. */
28
+ export declare function findPullRequest(client: any, project: string, ref: string): Promise<any>;
29
+ export declare const finishWork: (args: {
30
+ workspace: string;
31
+ identifier: string;
32
+ summary: string;
33
+ pullRequest?: string | undefined;
34
+ statusName: string | null;
35
+ }) => Promise<{
36
+ content: Array<{
37
+ type: 'text';
38
+ text: string;
39
+ }>;
40
+ }>;
41
+ export declare const createIssueTree: (args: {
42
+ workspace: string;
43
+ projectIdentifier: string;
44
+ epic?: {
45
+ title: string;
46
+ description?: string | undefined;
47
+ priority?: "High" | "Low" | "Medium" | "NoPriority" | "Urgent" | undefined;
48
+ labels?: string[] | undefined;
49
+ } | undefined;
50
+ epicIdentifier?: string | undefined;
51
+ children: {
52
+ title: string;
53
+ description?: string | undefined;
54
+ priority?: "High" | "Low" | "Medium" | "NoPriority" | "Urgent" | undefined;
55
+ componentLabel?: string | undefined;
56
+ milestoneLabel?: string | undefined;
57
+ assignee?: string | undefined;
58
+ labels?: string[] | undefined;
59
+ blockedBy?: string[] | undefined;
60
+ }[];
61
+ componentLabel?: string | undefined;
62
+ milestoneLabel?: string | undefined;
63
+ skipDuplicates: boolean;
64
+ dryRun: boolean;
65
+ }) => Promise<{
66
+ content: Array<{
67
+ type: 'text';
68
+ text: string;
69
+ }>;
70
+ }>;
71
+ /** "2026-11-01", "2026-11-01T08:00", "24h", "7d", "90m" → timestamp. */
72
+ export declare function parseSince(value: string, now?: number): number;
73
+ export declare const changesSince: (args: {
74
+ workspace?: string | undefined;
75
+ since: string;
76
+ projectIdentifiers?: string[] | undefined;
77
+ limit: number;
78
+ }) => Promise<{
79
+ content: Array<{
80
+ type: 'text';
81
+ text: string;
82
+ }>;
83
+ }>;
84
+ /** Latest claim marker → active claim, or undefined when released/expired. */
85
+ export declare function claimState(markers: any[], now?: number): {
86
+ agent: string;
87
+ until: number;
88
+ } | undefined;
89
+ export declare const claimIssue: (args: {
90
+ workspace: string;
91
+ identifier: string;
92
+ agent?: string | undefined;
93
+ minutes: number;
94
+ force: boolean;
95
+ }) => Promise<{
96
+ content: Array<{
97
+ type: 'text';
98
+ text: string;
99
+ }>;
100
+ }>;
101
+ export declare const releaseIssue: (args: {
102
+ workspace: string;
103
+ identifier: string;
104
+ agent?: string | undefined;
105
+ }) => Promise<{
106
+ content: Array<{
107
+ type: 'text';
108
+ text: string;
109
+ }>;
110
+ }>;
111
+ /** "owner/repo" from a slug, https URL or git@ remote. */
112
+ export declare function repoSlug(value: string): string;
113
+ export declare const findProjectForRepo: (args: {
114
+ workspace?: string | undefined;
115
+ repository: string;
116
+ }) => Promise<{
117
+ content: Array<{
118
+ type: 'text';
119
+ text: string;
120
+ }>;
121
+ }>;
@@ -0,0 +1,400 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findProjectForRepo = exports.releaseIssue = exports.claimIssue = exports.changesSince = exports.createIssueTree = exports.finishWork = exports.startWork = exports.getIssueContext = exports.CLAIM_LABEL = void 0;
7
+ exports.branchName = branchName;
8
+ exports.issueContext = issueContext;
9
+ exports.findPullRequest = findPullRequest;
10
+ exports.parseSince = parseSince;
11
+ exports.claimState = claimState;
12
+ exports.repoSlug = repoSlug;
13
+ // Agent workflow: one call per step of "pick up → work → hand back" instead of five to ten
14
+ // single-purpose calls. Built on the single tools, so their rules (ranks, parent bookkeeping,
15
+ // status lookup) apply unchanged.
16
+ const tracker_1 = __importDefault(require("@hcengineering/tracker"));
17
+ const core_1 = require("@hcengineering/core");
18
+ const connection_1 = require("../connection");
19
+ const errors_1 = require("../utils/errors");
20
+ const format_1 = require("../utils/format");
21
+ const people_1 = require("../utils/people");
22
+ const content_1 = require("../utils/content");
23
+ const classes_1 = require("../utils/classes");
24
+ const issues_1 = require("./issues");
25
+ const comments_1 = require("./comments");
26
+ const relations_1 = require("./relations");
27
+ const labels_1 = require("./labels");
28
+ const text = (r) => r.content[0]?.text ?? '';
29
+ const PR_STATE = ['open', 'closed', 'merged'];
30
+ exports.CLAIM_LABEL = 'agent:working';
31
+ const CLAIM_RE = /\[huly-(claim|release) agent=(\S+?)(?: until=(\S+?))?\]/;
32
+ async function findIssue(client, identifier) {
33
+ const issue = await client.findOne(tracker_1.default.class.Issue, { identifier });
34
+ if (issue == null)
35
+ throw new Error(`Issue '${identifier}' not found.`);
36
+ return issue;
37
+ }
38
+ async function findStatus(client, name) {
39
+ const statuses = await client.findAll(tracker_1.default.class.IssueStatus, {});
40
+ const status = statuses.find((s) => s.name.toLowerCase() === name.toLowerCase());
41
+ if (status == null)
42
+ throw new Error(`Status '${name}' not found. Available: ${[...new Set(statuses.map((s) => s.name))].join(', ')}.`);
43
+ return status;
44
+ }
45
+ function branchName(identifier, title) {
46
+ const slug = title.toLowerCase().normalize('NFKD').replace(/[̀-ͯ]/g, '')
47
+ .replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').split('-').slice(0, 6).join('-');
48
+ return `${identifier.toLowerCase()}${slug !== '' ? '-' + slug : ''}`;
49
+ }
50
+ /** Full working context of an issue as one Markdown block. */
51
+ async function issueContext(workspace, identifier, commentLimit = 20) {
52
+ const client = await (0, connection_1.getConnection)(workspace);
53
+ const issue = await findIssue(client, identifier);
54
+ const [status, milestone, component, labels, names] = await Promise.all([
55
+ client.findOne(tracker_1.default.class.IssueStatus, { _id: issue.status }),
56
+ issue.milestone != null ? client.findOne(tracker_1.default.class.Milestone, { _id: issue.milestone }) : undefined,
57
+ issue.component != null ? client.findOne(tracker_1.default.class.Component, { _id: issue.component }) : undefined,
58
+ client.findAll('tags:class:TagReference', { attachedTo: issue._id }),
59
+ (0, people_1.peopleNames)(client)
60
+ ]);
61
+ const refs = async (list) => {
62
+ const out = [];
63
+ for (const r of list ?? []) {
64
+ const other = await client.findOne(r._class ?? tracker_1.default.class.Issue, { _id: r._id });
65
+ if (other == null)
66
+ continue;
67
+ out.push(other.identifier != null ? `${other.identifier}: ${other.title}` : `${String(other.title ?? other.name ?? r._id)} (${String(r._class).split(':').pop() ?? ''} \`${String(r._id)}\`)`);
68
+ }
69
+ return out;
70
+ };
71
+ const blockedBy = await refs(issue.blockedBy);
72
+ const related = await refs(issue.relations);
73
+ // Reverse lookup ("which issues does this one block?"); the server cannot query inside blockedBy[].
74
+ const sameProject = await client.findAll(tracker_1.default.class.Issue, { space: issue.space }, { projection: { identifier: 1, title: 1, blockedBy: 1 } });
75
+ const blocking = sameProject.filter((i) => (i.blockedBy ?? []).some((b) => b._id === issue._id));
76
+ const lines = [
77
+ `## ${issue.identifier}: ${issue.title}`,
78
+ `**Status:** ${status?.name ?? '?'} · **Priority:** ${(0, format_1.priorityLabel)(issue.priority)} · **Assignee:** ${issue.assignee != null ? names.get(issue.assignee) ?? 'unknown' : 'unassigned'}`,
79
+ `**Component:** ${component?.label ?? '—'} · **Milestone:** ${milestone?.label ?? '—'} · **Due:** ${(0, format_1.formatDate)(issue.dueDate)}`,
80
+ `**Labels:** ${labels.length > 0 ? labels.map((l) => l.title).join(', ') : '—'}`,
81
+ `**Parent chain:** ${(issue.parents ?? []).length > 0 ? [...issue.parents].reverse().map((p) => `${p.identifier} ${p.parentTitle}`).join(' › ') : '—'}`,
82
+ `**Suggested branch:** \`${branchName(issue.identifier, issue.title)}\``
83
+ ];
84
+ if (blockedBy.length > 0)
85
+ lines.push(`**Blocked by:** ${blockedBy.join('; ')}`);
86
+ if (blocking.length > 0)
87
+ lines.push(`**Blocks:** ${blocking.map((b) => `${b.identifier}: ${b.title}`).join('; ')}`);
88
+ if (related.length > 0)
89
+ lines.push(`**Related:** ${related.join('; ')}`);
90
+ const description = await (0, content_1.readMarkup)(workspace, issue.description);
91
+ lines.push('', '### Description', description !== '' ? description : '_(none)_');
92
+ if ((issue.subIssues ?? 0) > 0) {
93
+ lines.push('', '### Sub-issues', text(await (0, issues_1.listSubIssues)({ workspace, identifier, depth: 2 })).split('\n').slice(1).join('\n').trim());
94
+ }
95
+ const prs = await client.findAll(classes_1.C.PullRequest, { attachedTo: issue._id }, { sort: { modifiedOn: core_1.SortingOrder.Descending } });
96
+ if (prs.length > 0) {
97
+ lines.push('', '### Pull requests');
98
+ for (const pr of prs) {
99
+ const gh = pr[classes_1.IDS.GithubIssueMixin] ?? {};
100
+ lines.push(`- ${pr.identifier} [${PR_STATE[pr.state] ?? pr.state}] ${pr.title} — #${gh.githubNumber ?? '?'} ${gh.url ?? ''}`);
101
+ }
102
+ }
103
+ if ((issue.comments ?? 0) > 0) {
104
+ const comments = text(await (0, comments_1.listComments)({ workspace, identifier, limit: commentLimit }));
105
+ lines.push('', '### Comments', comments.split('\n').slice(2).join('\n').trim());
106
+ }
107
+ return lines.join('\n');
108
+ }
109
+ exports.getIssueContext = (0, errors_1.wrapToolHandler)(async (args) => {
110
+ return await issueContext(args.workspace, args.identifier, args.commentLimit);
111
+ });
112
+ exports.startWork = (0, errors_1.wrapToolHandler)(async (args) => {
113
+ const client = await (0, connection_1.getConnection)(args.workspace);
114
+ const issue = await findIssue(client, args.identifier);
115
+ const status = await findStatus(client, args.statusName);
116
+ const update = {};
117
+ if (issue.status !== status._id)
118
+ update.status = status._id;
119
+ let me;
120
+ if (args.assignToMe) {
121
+ const person = await (0, people_1.currentPerson)(client);
122
+ me = person.name;
123
+ if (issue.assignee !== person._id)
124
+ update.assignee = person._id;
125
+ }
126
+ if (Object.keys(update).length > 0)
127
+ await client.update(issue, update);
128
+ let claim = '';
129
+ if (args.claimAs != null)
130
+ claim = '\n' + text(await (0, exports.claimIssue)({ workspace: args.workspace, identifier: args.identifier, agent: args.claimAs, minutes: 120, force: false }));
131
+ const head = `▶️ Started **${args.identifier}** — status ${status.name}${me != null ? `, assigned to ${me}` : ''}.${claim}`;
132
+ return `${head}\n\n${await issueContext(args.workspace, args.identifier)}`;
133
+ });
134
+ /** Finds a synced GitHub PR by "#12", "12", a GitHub URL or its Huly identifier. */
135
+ async function findPullRequest(client, project, ref) {
136
+ if (/^[A-Z][A-Z0-9]*-\d+$/.test(ref)) {
137
+ const pr = await client.findOne(classes_1.C.PullRequest, { identifier: ref });
138
+ if (pr == null)
139
+ throw new Error(`Pull request '${ref}' not found.`);
140
+ return pr;
141
+ }
142
+ const url = /^https?:\/\//.test(ref) ? ref.replace(/\/$/, '') : undefined;
143
+ const number = url == null ? Number(ref.replace(/^#/, '')) : Number(/\/pull\/(\d+)/.exec(url)?.[1]);
144
+ const prs = await client.findAll(classes_1.C.PullRequest, { space: project });
145
+ const hits = prs.filter((pr) => {
146
+ const gh = pr[classes_1.IDS.GithubIssueMixin] ?? {};
147
+ return url != null ? String(gh.url ?? '').replace(/\/$/, '') === url : gh.githubNumber === number;
148
+ });
149
+ if (hits.length === 0)
150
+ throw new Error(`Pull request '${ref}' not synced to this project yet (GitHub sync can take a minute).`);
151
+ if (hits.length > 1)
152
+ throw new Error(`Pull request '${ref}' is ambiguous here — pass its URL or Huly id.`);
153
+ return hits[0];
154
+ }
155
+ exports.finishWork = (0, errors_1.wrapToolHandler)(async (args) => {
156
+ const client = await (0, connection_1.getConnection)(args.workspace);
157
+ const issue = await findIssue(client, args.identifier);
158
+ const done = [];
159
+ const notes = [];
160
+ // Resolve everything that can fail before changing anything.
161
+ const pr = args.pullRequest != null ? await findPullRequest(client, issue.space, args.pullRequest) : undefined;
162
+ await (0, comments_1.addComment)({ workspace: args.workspace, identifier: args.identifier, message: `🤖 **Work summary**\n\n${args.summary}` });
163
+ done.push('summary comment added');
164
+ if (pr != null) {
165
+ if (pr.attachedTo === issue._id) {
166
+ done.push(`${pr.identifier} already under ${args.identifier}`);
167
+ }
168
+ else {
169
+ await (0, relations_1.setParent)({ workspace: args.workspace, identifier: pr.identifier, parentIdentifier: args.identifier });
170
+ done.push(`${pr.identifier} linked as sub-issue`);
171
+ }
172
+ }
173
+ if (args.statusName != null) {
174
+ try {
175
+ const status = await findStatus(client, args.statusName);
176
+ if (issue.status !== status._id)
177
+ await client.update(issue, { status: status._id });
178
+ done.push(`status → ${status.name}`);
179
+ }
180
+ catch (e) {
181
+ notes.push(e.message);
182
+ }
183
+ }
184
+ const labels = await client.findAll('tags:class:TagReference', { attachedTo: issue._id });
185
+ if (labels.some((l) => l.title === exports.CLAIM_LABEL)) {
186
+ const agent = claimState(await claimComments(client, issue))?.agent ?? 'agent';
187
+ await (0, exports.releaseIssue)({ workspace: args.workspace, identifier: args.identifier, agent });
188
+ done.push('claim released');
189
+ }
190
+ return `✅ Finished **${args.identifier}**: ${done.join(', ')}.${notes.length > 0 ? `\n⚠️ ${notes.join(' ')}` : ''}`;
191
+ });
192
+ // ── Issue trees from a plan ───────────────────────────────────────────────────
193
+ const norm = (s) => s.trim().toLowerCase().replace(/\s+/g, ' ');
194
+ exports.createIssueTree = (0, errors_1.wrapToolHandler)(async (args) => {
195
+ const client = await (0, connection_1.getConnection)(args.workspace);
196
+ const project = await client.findOne(tracker_1.default.class.Project, { identifier: args.projectIdentifier });
197
+ if (project == null)
198
+ throw new Error(`Project '${args.projectIdentifier}' not found.`);
199
+ if (args.epic == null && args.epicIdentifier == null)
200
+ throw new Error('Pass epic (new) or epicIdentifier (existing).');
201
+ if (args.epic != null && args.epicIdentifier != null)
202
+ throw new Error('Pass either epic or epicIdentifier, not both.');
203
+ const existing = await client.findAll(tracker_1.default.class.Issue, { space: project._id });
204
+ const byTitle = new Map(existing.map((i) => [norm(i.title), i.identifier]));
205
+ const epicExisting = args.epicIdentifier != null ? (await findIssue(client, args.epicIdentifier)).identifier : undefined;
206
+ const epicDup = args.epic != null ? byTitle.get(norm(args.epic.title)) : undefined;
207
+ // Children may reference each other as "#1" (1-based position) in blockedBy.
208
+ for (const [i, child] of args.children.entries()) {
209
+ for (const ref of child.blockedBy ?? []) {
210
+ const m = /^#(\d+)$/.exec(ref);
211
+ if (m != null && (Number(m[1]) < 1 || Number(m[1]) > args.children.length || Number(m[1]) === i + 1))
212
+ throw new Error(`children[${i}].blockedBy '${ref}' must point to another child (#1–#${args.children.length}).`);
213
+ }
214
+ }
215
+ const plan = [];
216
+ plan.push(epicExisting != null
217
+ ? `Epic: existing **${epicExisting}**`
218
+ : epicDup != null && args.skipDuplicates ? `Epic: "${args.epic.title}" → reuse existing **${epicDup}** (same title)` : `Epic: create "${args.epic.title}"`);
219
+ args.children.forEach((c, i) => {
220
+ const dup = byTitle.get(norm(c.title));
221
+ const extras = [c.componentLabel ?? args.componentLabel, c.milestoneLabel ?? args.milestoneLabel, c.assignee, ...(c.labels ?? [])].filter((x) => x != null);
222
+ const blockers = (c.blockedBy ?? []).length > 0 ? ` · blocked by ${(c.blockedBy ?? []).join(', ')}` : '';
223
+ plan.push(`#${i + 1} ${dup != null && args.skipDuplicates ? `"${c.title}" → reuse existing **${dup}**` : `create "${c.title}"`}${extras.length > 0 ? ` · ${extras.join(', ')}` : ''}${blockers}`);
224
+ });
225
+ if (args.dryRun)
226
+ return `🔍 Dry run in ${args.projectIdentifier}:\n${plan.map((p) => `- ${p}`).join('\n')}\nRun again with dryRun=false to create.`;
227
+ const ws = args.workspace;
228
+ const create = async (title, description, priority) => {
229
+ const out = text(await (0, issues_1.createIssue)({ workspace: ws, projectIdentifier: args.projectIdentifier, title, description, priority: priority ?? 'NoPriority' }));
230
+ const id = /\*\*([A-Z][A-Z0-9]*-\d+)\*\*/.exec(out)?.[1];
231
+ if (id == null)
232
+ throw new Error(`Could not read new issue id from: ${out}`);
233
+ return id;
234
+ };
235
+ const decorate = async (id, c) => {
236
+ const component = c.componentLabel ?? args.componentLabel;
237
+ const milestone = c.milestoneLabel ?? args.milestoneLabel;
238
+ if (component != null || milestone != null || c.assignee != null) {
239
+ await (0, issues_1.updateIssue)({ workspace: ws, identifier: id, componentLabel: component, milestoneLabel: milestone, assignee: c.assignee });
240
+ }
241
+ for (const label of c.labels ?? [])
242
+ await (0, labels_1.addLabel)({ workspace: ws, identifier: id, labelName: label });
243
+ };
244
+ const created = [];
245
+ let epicId = epicExisting;
246
+ if (epicId == null) {
247
+ if (epicDup != null && args.skipDuplicates)
248
+ epicId = epicDup;
249
+ else {
250
+ epicId = await create(args.epic.title, args.epic.description, args.epic.priority);
251
+ await decorate(epicId, { labels: args.epic.labels });
252
+ created.push(`${epicId} (epic)`);
253
+ }
254
+ }
255
+ const ids = [];
256
+ for (const c of args.children) {
257
+ const dup = byTitle.get(norm(c.title));
258
+ if (dup != null && args.skipDuplicates) {
259
+ ids.push(dup);
260
+ continue;
261
+ }
262
+ const id = await create(c.title, c.description, c.priority);
263
+ await decorate(id, c);
264
+ await (0, relations_1.setParent)({ workspace: ws, identifier: id, parentIdentifier: epicId });
265
+ created.push(id);
266
+ ids.push(id);
267
+ }
268
+ for (const [i, c] of args.children.entries()) {
269
+ for (const ref of c.blockedBy ?? []) {
270
+ const m = /^#(\d+)$/.exec(ref);
271
+ await (0, relations_1.addBlockedBy)({ workspace: ws, identifier: ids[i], blockedBy: m != null ? ids[Number(m[1]) - 1] : ref });
272
+ }
273
+ }
274
+ const reused = args.children.length - (created.length - (created[0]?.endsWith('(epic)') === true ? 1 : 0));
275
+ return `✅ Issue tree under **${epicId}**: created ${created.length > 0 ? created.join(', ') : 'nothing'}${reused > 0 ? `; ${reused} existing reused` : ''}.\n${args.children.map((c, i) => `- ${ids[i]}: ${c.title}`).join('\n')}`;
276
+ });
277
+ // ── What changed ──────────────────────────────────────────────────────────────
278
+ /** "2026-11-01", "2026-11-01T08:00", "24h", "7d", "90m" → timestamp. */
279
+ function parseSince(value, now = Date.now()) {
280
+ const rel = /^(\d+)\s*([mhd])$/i.exec(value.trim());
281
+ if (rel != null)
282
+ return now - Number(rel[1]) * { m: 60_000, h: 3_600_000, d: 86_400_000 }[rel[2].toLowerCase()];
283
+ const ts = Date.parse(value);
284
+ if (Number.isNaN(ts))
285
+ throw new Error(`Cannot read since='${value}'. Use ISO (2026-11-01, 2026-11-01T08:00) or relative (90m, 24h, 7d).`);
286
+ return ts;
287
+ }
288
+ exports.changesSince = (0, errors_1.wrapToolHandler)(async (args) => {
289
+ const client = await (0, connection_1.getConnection)(args.workspace);
290
+ const since = parseSince(args.since);
291
+ const query = { modifiedOn: { $gte: since } };
292
+ if (args.projectIdentifiers != null && args.projectIdentifiers.length > 0) {
293
+ const projects = await client.findAll(tracker_1.default.class.Project, { identifier: { $in: args.projectIdentifiers } });
294
+ const missing = args.projectIdentifiers.filter((p) => !projects.some((x) => x.identifier === p));
295
+ if (missing.length > 0)
296
+ throw new Error(`Project(s) not found: ${missing.join(', ')}.`);
297
+ query.space = { $in: projects.map((p) => p._id) };
298
+ }
299
+ const issues = await client.findAll(tracker_1.default.class.Issue, query, { sort: { modifiedOn: core_1.SortingOrder.Descending }, limit: args.limit });
300
+ if (issues.length === 0)
301
+ return `No issue changes since ${new Date(since).toISOString()}.`;
302
+ const ids = issues.map((i) => i._id);
303
+ const [updates, comments, statuses] = await Promise.all([
304
+ client.findAll('activity:class:DocUpdateMessage', { attachedTo: { $in: ids }, createdOn: { $gte: since } }),
305
+ client.findAll('chunter:class:ChatMessage', { attachedTo: { $in: ids }, createdOn: { $gte: since } }),
306
+ client.findAll(tracker_1.default.class.IssueStatus, {})
307
+ ]);
308
+ const authors = await (0, people_1.socialIdNames)(client, [...new Set([...updates, ...comments].map((m) => m.createdBy).filter((x) => x != null))]);
309
+ const statusName = new Map(statuses.map((s) => [s._id, s.name]));
310
+ const lines = issues.map((issue) => {
311
+ const ups = updates.filter((u) => u.attachedTo === issue._id);
312
+ const fields = [...new Set(ups.map((u) => u.attributeUpdates?.attrKey).filter((k) => k != null && k !== 'rank').map((k) => k === 'attachedTo' ? 'parent' : k))];
313
+ const cs = comments.filter((c) => c.attachedTo === issue._id);
314
+ const who = [...new Set([...ups, ...cs].map((m) => authors.get(m.createdBy)).filter((n) => n != null))];
315
+ const parts = [
316
+ issue.createdOn >= since ? 'new' : undefined,
317
+ fields.length > 0 ? `changed ${fields.join(', ')}` : undefined,
318
+ cs.length > 0 ? `+${cs.length} comment(s)` : undefined
319
+ ].filter((p) => p != null);
320
+ const kind = issue._class === classes_1.C.PullRequest ? 'PR ' : '';
321
+ return `- ${kind}**${issue.identifier}** [${statusName.get(issue.status) ?? '?'}] ${issue.title} — ${parts.length > 0 ? parts.join(' · ') : 'updated'}${who.length > 0 ? ` (by ${who.join(', ')})` : ''} · ${(0, format_1.formatDate)(issue.modifiedOn)}`;
322
+ });
323
+ return `## Changes since ${new Date(since).toISOString()} (${issues.length}${issues.length === args.limit ? '+' : ''})\n\n${lines.join('\n')}`;
324
+ });
325
+ // ── Claims: lightweight leases so parallel agents do not work on the same issue ──
326
+ async function claimComments(client, issue) {
327
+ const comments = await client.findAll('chunter:class:ChatMessage', { attachedTo: issue._id }, { sort: { createdOn: core_1.SortingOrder.Descending }, limit: 50 });
328
+ return comments.filter((c) => CLAIM_RE.test(String(c.message ?? '')));
329
+ }
330
+ /** Latest claim marker → active claim, or undefined when released/expired. */
331
+ function claimState(markers, now = Date.now()) {
332
+ const latest = markers[0];
333
+ if (latest == null)
334
+ return undefined;
335
+ const m = CLAIM_RE.exec(String(latest.message));
336
+ if (m[1] !== 'claim')
337
+ return undefined;
338
+ const until = Date.parse(m[3] ?? '');
339
+ if (Number.isNaN(until) || until < now)
340
+ return undefined;
341
+ return { agent: m[2], until };
342
+ }
343
+ const agentName = (agent) => (agent ?? process.env.HULY_AGENT_NAME ?? 'claude').replace(/\s+/g, '-');
344
+ exports.claimIssue = (0, errors_1.wrapToolHandler)(async (args) => {
345
+ const client = await (0, connection_1.getConnection)(args.workspace);
346
+ const issue = await findIssue(client, args.identifier);
347
+ const agent = agentName(args.agent);
348
+ const active = claimState(await claimComments(client, issue));
349
+ if (active != null && active.agent !== agent && !args.force) {
350
+ throw new Error(`${args.identifier} is claimed by '${active.agent}' until ${new Date(active.until).toISOString()}. Pick another issue or pass force=true.`);
351
+ }
352
+ const until = new Date(Date.now() + args.minutes * 60_000).toISOString();
353
+ await (0, comments_1.addComment)({ workspace: args.workspace, identifier: args.identifier, message: `🤖 Claimed by **${agent}** until ${until} [huly-claim agent=${agent} until=${until}]` });
354
+ await (0, labels_1.addLabel)({ workspace: args.workspace, identifier: args.identifier, labelName: exports.CLAIM_LABEL });
355
+ return `🔒 **${args.identifier}** claimed by ${agent} until ${until}.`;
356
+ });
357
+ exports.releaseIssue = (0, errors_1.wrapToolHandler)(async (args) => {
358
+ const client = await (0, connection_1.getConnection)(args.workspace);
359
+ const issue = await findIssue(client, args.identifier);
360
+ const agent = agentName(args.agent);
361
+ await (0, comments_1.addComment)({ workspace: args.workspace, identifier: args.identifier, message: `🤖 Released by **${agent}** [huly-release agent=${agent}]` });
362
+ const labels = await client.findAll('tags:class:TagReference', { attachedTo: issue._id });
363
+ if (labels.some((l) => l.title === exports.CLAIM_LABEL))
364
+ await (0, labels_1.removeLabel)({ workspace: args.workspace, identifier: args.identifier, labelName: exports.CLAIM_LABEL });
365
+ return `🔓 **${args.identifier}** released by ${agent}.`;
366
+ });
367
+ // ── Repository → project (Huly GitHub integration) ───────────────────────────
368
+ /** "owner/repo" from a slug, https URL or git@ remote. */
369
+ function repoSlug(value) {
370
+ const v = value.trim().replace(/\.git$/, '').replace(/\/$/, '');
371
+ const m = /github\.com[:/]([^/]+\/[^/]+)$/i.exec(v);
372
+ return (m?.[1] ?? v).toLowerCase();
373
+ }
374
+ exports.findProjectForRepo = (0, errors_1.wrapToolHandler)(async (args) => {
375
+ const slug = repoSlug(args.repository);
376
+ if (!/^[^/\s]+\/[^/\s]+$/.test(slug))
377
+ throw new Error(`'${args.repository}' is not a GitHub repository (owner/name, URL or git remote).`);
378
+ const targets = args.workspace != null ? [{ url: args.workspace, name: args.workspace }] : await (0, connection_1.listWorkspaces)();
379
+ const hits = [];
380
+ for (const ws of targets) {
381
+ let client;
382
+ try {
383
+ client = await (0, connection_1.getConnection)(ws.url);
384
+ }
385
+ catch {
386
+ continue;
387
+ }
388
+ const repos = (await client.findAll('github:class:GithubIntegrationRepository', {})).filter((r) => String(r.resourcePath ?? '').toLowerCase() === slug);
389
+ if (repos.length === 0)
390
+ continue;
391
+ const repoIds = new Set(repos.map((r) => r._id));
392
+ const projects = (await client.findAll(tracker_1.default.class.Project, {})).filter((p) => (p[classes_1.IDS.GithubProject]?.repositories ?? []).some((id) => repoIds.has(id)));
393
+ for (const p of projects)
394
+ hits.push(`- workspace \`${ws.url}\` · project **${p.identifier}** (${p.name})`);
395
+ }
396
+ if (hits.length === 0)
397
+ return `No Huly project is linked to GitHub repository ${slug}. (Link it in Huly → Settings → GitHub, or pass workspace and project explicitly.)`;
398
+ return `## Huly project(s) for ${slug}\n\n${hits.join('\n')}`;
399
+ });
400
+ //# sourceMappingURL=agent.js.map