gennady 0.8.4-draft.2 → 0.8.4-draft.3

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 (146) hide show
  1. package/ai/directives/sdd-v2/root.directive.xml +36 -3
  2. package/ai/directives/sdd-v2/router.directive.xml +22 -1
  3. package/ai/kit/templates/sdd-v2/root.directive.hbs +11 -3
  4. package/ai/kit/templates/sdd-v2/router.directive.hbs +22 -1
  5. package/ai/skills/agent-inbox/SKILL.md +1 -1
  6. package/ai/skills/sdd/SKILL.md +5 -3
  7. package/ai/skills/sdd-audit/SKILL.md +5 -2
  8. package/ai/skills/sdd-check/SKILL.md +2 -2
  9. package/ai/skills/sdd-code-review/SKILL.md +4 -1
  10. package/ai/skills/sdd-critic/SKILL.md +5 -2
  11. package/ai/skills/sdd-execute/SKILL.md +5 -2
  12. package/ai/skills/sdd-reconcile/SKILL.md +5 -2
  13. package/ai/skills/sdd-scaffold/SKILL.md +5 -2
  14. package/dist/ai/directives/sdd-v2/root.directive.xml +36 -3
  15. package/dist/ai/directives/sdd-v2/router.directive.xml +22 -1
  16. package/dist/ai/kit/templates/sdd-v2/root.directive.hbs +11 -3
  17. package/dist/ai/kit/templates/sdd-v2/router.directive.hbs +22 -1
  18. package/dist/ai/skills/agent-inbox/SKILL.md +1 -1
  19. package/dist/ai/skills/sdd/SKILL.md +5 -3
  20. package/dist/ai/skills/sdd-audit/SKILL.md +5 -2
  21. package/dist/ai/skills/sdd-check/SKILL.md +2 -2
  22. package/dist/ai/skills/sdd-code-review/SKILL.md +4 -1
  23. package/dist/ai/skills/sdd-critic/SKILL.md +5 -2
  24. package/dist/ai/skills/sdd-execute/SKILL.md +5 -2
  25. package/dist/ai/skills/sdd-reconcile/SKILL.md +5 -2
  26. package/dist/ai/skills/sdd-scaffold/SKILL.md +5 -2
  27. package/dist/chunks/{classify-mr-stage.logic-BiCHTmPp.js → classify-mr-stage.logic-CazmQDwZ.js} +2 -2
  28. package/dist/chunks/{config-index-9VHWSDQD.js → config-index-DU8-FEjq.js} +1 -1
  29. package/dist/chunks/{devtools-b0DwO1x_.js → devtools-1JmXJjUG.js} +1 -1
  30. package/dist/chunks/{eval.cmd-CwNPaNJd.js → eval.cmd-CBANnOFG.js} +1 -1
  31. package/dist/chunks/{help-D5cXtdMI.js → help-DVloaFF5.js} +1 -1
  32. package/dist/chunks/{index-BVnJEutp.js → index-2xhpqJtd.js} +2 -2
  33. package/dist/chunks/{index-RR5OUxje.js → index-AxsLBUAx.js} +14 -14
  34. package/dist/chunks/{index-CUkeTGqM.js → index-B7sydB0W.js} +2 -2
  35. package/dist/chunks/{index-CMCn9ErF.js → index-BKxk4zOz.js} +2 -2
  36. package/dist/chunks/{index-Db13NlHh.js → index-BNMmX_Mv.js} +21 -21
  37. package/dist/chunks/{index-CmQO-RmM.js → index-BPzldG3a.js} +2 -2
  38. package/dist/chunks/{index-BOQl7F_Z.js → index-BQlFDvKW.js} +2 -2
  39. package/dist/chunks/{index-RzkvIfJQ.js → index-Baq7RL1L.js} +3 -3
  40. package/dist/chunks/index-BbPiwvY9.js +2 -0
  41. package/dist/chunks/{index-ClJLPEUB.js → index-BreGNLJ_.js} +1 -1
  42. package/dist/chunks/{index-DjSafAkN.js → index-BslPwGtM.js} +2 -2
  43. package/dist/chunks/{index-DiMFxS0z.js → index-BtCUN2fZ.js} +16 -16
  44. package/dist/chunks/{index-CS0VbiLD.js → index-C10-EOdB.js} +1 -1
  45. package/dist/chunks/{index-2BOEcJIa.js → index-C4JmZLaj.js} +2 -2
  46. package/dist/chunks/index-CA-JKLr4.js +2 -0
  47. package/dist/chunks/{index-43GiH--T.js → index-CG_jJZVu.js} +2 -2
  48. package/dist/chunks/{index-BdkFKsMm.js → index-CGyP2uDE.js} +3 -3
  49. package/dist/chunks/{index-BOKv0b01.js → index-CPl1s9XJ.js} +2 -2
  50. package/dist/chunks/{index-DIPrBH-4.js → index-CSxE4cEm.js} +9 -9
  51. package/dist/chunks/{index-Cm7U1-fU.js → index-CWR5EzXx.js} +2 -2
  52. package/dist/chunks/{index-BwN5llCR.js → index-Camql5kL.js} +2 -2
  53. package/dist/chunks/{index-Drh-J9O7.js → index-CdUiTipO.js} +7 -7
  54. package/dist/chunks/{index-Cn029KTN.js → index-Crg61pK5.js} +2 -2
  55. package/dist/chunks/{index-Dja2O-hV.js → index-Cv9ZYXso.js} +1 -1
  56. package/dist/chunks/{index-Ck8v_Gv7.js → index-D7ADMlG3.js} +1 -1
  57. package/dist/chunks/index-DNl2gC8l.js +158 -0
  58. package/dist/chunks/{index-BYIzl-Ut.js → index-DVJA0qVm.js} +36 -36
  59. package/dist/chunks/{index-BAEIZVx0.js → index-DcFJhkY1.js} +2 -2
  60. package/dist/chunks/{index-Dx5_CB2E.js → index-DdEd-L3x.js} +2 -2
  61. package/dist/chunks/{index-DVmqMmgb.js → index-DkGA1eW_.js} +32 -32
  62. package/dist/chunks/{index-3k7mPX1e.js → index-Dnwxlti3.js} +1 -1
  63. package/dist/chunks/{index-CrizvxOJ.js → index-DqdEJDi2.js} +2 -2
  64. package/dist/chunks/{index-BIPebtDl.js → index-DqiwmBt4.js} +1 -1
  65. package/dist/chunks/{index-DS4MhAw-.js → index-PfuqBWjY.js} +2 -2
  66. package/dist/chunks/{index-BmFT1Kx2.js → index-SVP6RfVl.js} +2 -2
  67. package/dist/chunks/{index-CDxV4b81.js → index-Y8wu48Q0.js} +1 -1
  68. package/dist/chunks/index-_ewSKppm.js +2 -0
  69. package/dist/chunks/{index-Ctcr_Qeu.js → index-aBVtCLIJ.js} +2 -2
  70. package/dist/chunks/index-dNdz9j6d.js +2 -0
  71. package/dist/chunks/{index-BFUkVkSo.js → index-gskOpu3H.js} +16 -16
  72. package/dist/chunks/{index-CXpkT25O.js → index-pBSLMn5Q.js} +3 -3
  73. package/dist/chunks/index-sqPhX5Io.js +2 -0
  74. package/dist/chunks/{index-BzmR4Es2.js → index-vfrjhUD1.js} +39 -39
  75. package/dist/chunks/{index-J2NvjjDV.js → index-xGF5XC_i.js} +2 -2
  76. package/dist/chunks/{run-review-command.logic-CA2Rjymb.js → run-review-command.logic-B9GoCxh-.js} +24 -24
  77. package/dist/chunks/{serve.cmd-RxYS6WoN.js → serve.cmd-UXkaeaPI.js} +2 -2
  78. package/dist/chunks/{services-Csd556Tv.js → services-BYCeGBlO.js} +4 -4
  79. package/dist/chunks/{shared-B5CTGvpG.js → shared-B3cXL2Np.js} +1178 -1117
  80. package/dist/chunks/{stats-index-BLztvK69.js → stats-index-AIAnnp9S.js} +2 -2
  81. package/dist/gennady.js +46 -46
  82. package/dist/index.js +4 -4
  83. package/dist/shared/sdd/ladder.d.ts +42 -0
  84. package/dist/shared/sdd/module-specs.d.ts +7 -0
  85. package/dist/shared/sdd/tracker.d.ts +9 -0
  86. package/package.json +1 -1
  87. package/dist/chunks/classify-mr-stage.logic-ClmhzQPQ.js +0 -53
  88. package/dist/chunks/config-index-RFeqlDWs.js +0 -104
  89. package/dist/chunks/devtools-p8tmPuLn.js +0 -79
  90. package/dist/chunks/eval.cmd-ewU5lcUY.js +0 -34
  91. package/dist/chunks/help-DzGnMNi2.js +0 -7
  92. package/dist/chunks/index--AXFi0ty.js +0 -89
  93. package/dist/chunks/index-64TSesTc.js +0 -186
  94. package/dist/chunks/index-9Gv5trS_.js +0 -125
  95. package/dist/chunks/index-B1DQIryA.js +0 -2
  96. package/dist/chunks/index-B1PiBeQ3.js +0 -2
  97. package/dist/chunks/index-B4rzuhkt.js +0 -183
  98. package/dist/chunks/index-B97HJjkg.js +0 -159
  99. package/dist/chunks/index-BF6qypm0.js +0 -131
  100. package/dist/chunks/index-BK84ZQsh.js +0 -128
  101. package/dist/chunks/index-BRVIirjj.js +0 -141
  102. package/dist/chunks/index-BXnryCGW.js +0 -96
  103. package/dist/chunks/index-BaZm7Otb.js +0 -2
  104. package/dist/chunks/index-Bhk746A2.js +0 -129
  105. package/dist/chunks/index-Bi-eY_dY.js +0 -164
  106. package/dist/chunks/index-BjumU69g.js +0 -2
  107. package/dist/chunks/index-BkWXcpXU.js +0 -16979
  108. package/dist/chunks/index-BlY4jQIA.js +0 -168
  109. package/dist/chunks/index-C0iy7GxD.js +0 -140
  110. package/dist/chunks/index-CCBTXczb.js +0 -56
  111. package/dist/chunks/index-CDAfkSrr.js +0 -2
  112. package/dist/chunks/index-CDHymWzC.js +0 -102
  113. package/dist/chunks/index-CNfXJAao.js +0 -2
  114. package/dist/chunks/index-CQsae1nq.js +0 -207
  115. package/dist/chunks/index-CVmd0prf.js +0 -2
  116. package/dist/chunks/index-CZuTNeNm.js +0 -2
  117. package/dist/chunks/index-CasNhhrL.js +0 -96
  118. package/dist/chunks/index-Ce7GWENF.js +0 -377
  119. package/dist/chunks/index-Cf-02TAg.js +0 -265
  120. package/dist/chunks/index-CfjQWSrh.js +0 -52
  121. package/dist/chunks/index-Chr7gBBz.js +0 -443
  122. package/dist/chunks/index-Ci875Zlg.js +0 -346
  123. package/dist/chunks/index-CwA6RzIB.js +0 -3793
  124. package/dist/chunks/index-D1dI63ej.js +0 -46
  125. package/dist/chunks/index-DCS32A2i.js +0 -663
  126. package/dist/chunks/index-DOFoNxvb.js +0 -131
  127. package/dist/chunks/index-DVkCEuws.js +0 -136
  128. package/dist/chunks/index-DkadaaXq.js +0 -658
  129. package/dist/chunks/index-Dn11CLtk.js +0 -7
  130. package/dist/chunks/index-Do3spFJT.js +0 -340
  131. package/dist/chunks/index-DrFRZ0Yg.js +0 -2
  132. package/dist/chunks/index-DvEQhXi2.js +0 -1054
  133. package/dist/chunks/index-GiS0x6jg.js +0 -90
  134. package/dist/chunks/index-NacvqeQ5.js +0 -69
  135. package/dist/chunks/index-RNJhFzdr.js +0 -227
  136. package/dist/chunks/index-R_vUB6CL.js +0 -2
  137. package/dist/chunks/index-TQft1s5H.js +0 -20
  138. package/dist/chunks/index-ZmQRP38W.js +0 -26969
  139. package/dist/chunks/index-jdOZ4AkD.js +0 -143
  140. package/dist/chunks/index-kNa21kUI.js +0 -279
  141. package/dist/chunks/index-v4AV9kAc.js +0 -108
  142. package/dist/chunks/run-review-command.logic-CU1Slmc_.js +0 -331
  143. package/dist/chunks/serve.cmd-dWu_k_G_.js +0 -162
  144. package/dist/chunks/services-CwvXl2MB.js +0 -46832
  145. package/dist/chunks/shared-DSZTUx5b.js +0 -4509
  146. package/dist/chunks/stats-index-H6ALcjxy.js +0 -66
@@ -1,331 +0,0 @@
1
- import { p as R, b as y, aA as _, aB as j, aC as A, aD as x, aE as E, s as u } from "./shared-B5CTGvpG.js";
2
- import { a as w } from "./services-Csd556Tv.js";
3
- function z(t) {
4
- const e = R(t, {
5
- branch: ["branch", "b"],
6
- url: ["url"],
7
- ref: ["ref"],
8
- project: ["project"],
9
- iid: ["iid"],
10
- all: ["all"],
11
- since: ["since"],
12
- draft: ["draft"],
13
- host: { aliases: ["host", "vcs-host"], takesValue: !0 }
14
- }), r = e._.filter((a) => typeof a == "string"), o = r.find((a) => a.startsWith("http")), n = r.find((a) => a.includes("!")), i = typeof e.url == "string" ? e.url : void 0, s = typeof e.ref == "string" ? e.ref : void 0, c = i ? void 0 : o, d = s ? void 0 : n;
15
- return {
16
- branch: e.branch,
17
- url: i ?? c,
18
- ref: s ?? d,
19
- project: e.project,
20
- iid: e.iid,
21
- all: e.all,
22
- since: e.since,
23
- draft: e.draft,
24
- host: typeof e.host == "string" ? e.host : void 0
25
- };
26
- }
27
- function L(t) {
28
- const e = y();
29
- if (!e)
30
- throw new Error("Не найден удалённый репозиторий origin.");
31
- return {
32
- branch: t?.trim() || _(),
33
- remote: e
34
- };
35
- }
36
- function T(t, e) {
37
- const r = process.env.GITLAB_PERSONAL_TOKEN;
38
- if (!r)
39
- throw new Error(
40
- "Не найден токен доступа GitLab. Установите GITLAB_PERSONAL_TOKEN и повторите попытку."
41
- );
42
- if (!/gitlab/i.test(t))
43
- throw new Error(`Провайдер "${t}" пока не поддерживается.`);
44
- const o = process.env.GITLAB_API_PATH ?? "/api/v4", n = `https://${t}${o}`;
45
- return {
46
- host: t,
47
- project: e,
48
- vcs: new w({ token: r, baseUrl: n })
49
- };
50
- }
51
- function C(t) {
52
- return t.map((e) => {
53
- const r = String(e.id ?? ""), o = e.updated_at ?? e.created_at;
54
- return {
55
- id: r,
56
- resolvable: !0,
57
- resolved: !1,
58
- resolved_by: null,
59
- notes: [
60
- {
61
- id: typeof e.id == "number" ? e.id : void 0,
62
- body: e.note ?? "",
63
- system: !1,
64
- position: e.position ?? void 0,
65
- resolvable: !0,
66
- updated_at: o,
67
- resolved: !1,
68
- resolved_by: null
69
- }
70
- ]
71
- };
72
- });
73
- }
74
- async function P(t, e, r, o) {
75
- let n = null;
76
- if (t.source === "branch") {
77
- const c = r?.branch;
78
- if (!c)
79
- throw new Error("Не удалось определить ветку для поиска Merge Request.");
80
- n = await e.vcs.MergeRequests.getOne({
81
- project: e.project,
82
- sourceBranch: c,
83
- state: "opened"
84
- });
85
- } else
86
- n = await e.vcs.MergeRequests.getByIid({
87
- project: e.project,
88
- iid: t.iid
89
- });
90
- if (!n)
91
- return null;
92
- const i = n, s = o ? C(
93
- await e.vcs.MergeDiscussions.listDraftNotes({
94
- iid: i.iid,
95
- project: e.project
96
- })
97
- ) : await e.vcs.MergeDiscussions.getAll({
98
- iid: i.iid,
99
- project: e.project
100
- });
101
- return {
102
- mergeRequest: i,
103
- discussions: s
104
- };
105
- }
106
- function B(t) {
107
- const e = t.split("!");
108
- if (e.length !== 2)
109
- return null;
110
- const r = e[0]?.trim(), o = e[1]?.trim();
111
- return !r || !o ? null : { project: r, iid: o };
112
- }
113
- function k(t) {
114
- try {
115
- const e = new URL(t), r = e.pathname.match(/^(?<project>.+?)\/-\/merge_requests\/(?<iid>\d+)\/?$/);
116
- return r?.groups ? {
117
- host: e.hostname.toLowerCase(),
118
- project: r.groups.project.replace(/^\/+/, ""),
119
- iid: r.groups.iid
120
- } : null;
121
- } catch {
122
- return null;
123
- }
124
- }
125
- function I(t) {
126
- if (t.url) {
127
- const e = k(t.url);
128
- if (!e)
129
- throw new Error("Некорректный --url. Ожидается ссылка на GitLab MR.");
130
- return {
131
- source: "url",
132
- host: e.host,
133
- project: e.project,
134
- iid: e.iid
135
- };
136
- }
137
- if (typeof t.ref == "string") {
138
- const e = B(t.ref);
139
- if (!e)
140
- throw new Error("Некорректный --ref. Ожидается формат <PROJECT>!<IID>.");
141
- return {
142
- source: "ref",
143
- project: e.project,
144
- iid: e.iid
145
- };
146
- }
147
- if (t.project || t.iid) {
148
- if (!t.project || !t.iid)
149
- throw new Error("Для явного MR укажите оба параметра: --project и --iid.");
150
- return {
151
- source: "project-iid",
152
- project: t.project,
153
- iid: t.iid
154
- };
155
- }
156
- return {
157
- source: "branch",
158
- branch: t.branch
159
- };
160
- }
161
- function M(t, e) {
162
- const r = t.author?.username ?? "";
163
- return t.system ? "Skip" : t.body?.includes("🤖") ? "AI_Agent" : /group_|bot\d*/.test(r) ? "Skip" : r === e ? "Author" : "Reviewer";
164
- }
165
- function U(t) {
166
- if (!t) return "";
167
- try {
168
- const r = new URL(t).pathname.split("/").filter(Boolean);
169
- return r.indexOf("-") > 0 ? `${r[0]}/${r[1]}` : r.length >= 2 ? `${r[0]}/${r[1]}` : r[0] ?? "";
170
- } catch {
171
- return "";
172
- }
173
- }
174
- function $(t) {
175
- if (!t) return "";
176
- try {
177
- return new URL(t).host ?? "";
178
- } catch {
179
- return "";
180
- }
181
- }
182
- function G(t) {
183
- let e;
184
- for (const r of t)
185
- for (const o of r.notes ?? [])
186
- o.updated_at && (!e || o.updated_at > e) && (e = o.updated_at);
187
- return e;
188
- }
189
- function S(t, e) {
190
- return (t.notes ?? []).some((r) => !!r.updated_at && r.updated_at > e);
191
- }
192
- function O(t, e, r = !1, o) {
193
- const n = t.author?.username, i = U(t.web_url), s = $(t.web_url), c = G(e), d = e.map((l) => {
194
- const h = l.notes?.[0];
195
- if (!h || !r && (l.resolved || h.resolved) || o && !S(l, o))
196
- return null;
197
- const f = h.position ?? {}, g = f.new_path ?? f.old_path ?? "unknown", b = String(f.new_line ?? f.old_line ?? 0), m = (l.notes ?? []).map((p) => {
198
- const v = M(p, n);
199
- return v === "Skip" ? null : {
200
- tag: v,
201
- attrs: {
202
- uid: p.author?.username ?? "",
203
- noteId: String(p.id ?? "")
204
- },
205
- children: { cdata: p.body ?? "" }
206
- };
207
- }).filter(Boolean);
208
- return m.length === 0 ? null : {
209
- tag: "Thread",
210
- attrs: {
211
- fullId: l.id,
212
- shortId: l.id.slice(0, 4),
213
- file: g,
214
- line: b,
215
- resolved: l.resolved ? "true" : "false"
216
- },
217
- children: m
218
- };
219
- }).filter(Boolean), a = {
220
- tag: "Meta",
221
- children: [
222
- { tag: "Task_Objective", children: { cdata: t.title ?? "" } },
223
- { tag: "Author", children: n ?? "" },
224
- { tag: "Branch", children: t.source_branch ?? "" },
225
- { tag: "URL", children: t.web_url ?? "" }
226
- ]
227
- };
228
- return {
229
- tag: "MR_Audit_Context",
230
- attrs: {
231
- iid: t.iid + "",
232
- host: s,
233
- target_repo: i,
234
- ...c ? {
235
- cursor: c,
236
- "tip-cursor": "Rerun with --since <cursor> to receive only threads updated after this fetch"
237
- } : {}
238
- },
239
- children: [
240
- a,
241
- {
242
- tag: "Review_Threads",
243
- children: d
244
- }
245
- ]
246
- };
247
- }
248
- function D(t, e, r = !1, o) {
249
- const n = O(t, e, r, o);
250
- return j(n);
251
- }
252
- async function X() {
253
- return A("agent-review-verifier.xml");
254
- }
255
- async function q(t, e = process.cwd()) {
256
- const r = await X(), o = x(e);
257
- let n = r.replace("<!--Review_Audit_Artifact-->", t);
258
- return n = n.replace("<!--ai:first-->", E(e)), n = n.replace("<!--ai:verify-axiom-hint-->", o.axiomHint), n = n.replace("<!--ai:verify-tools-example-->", o.toolsExample), n = n.replace("<!--ai:verify-step-commands-->", o.verifyStep), n;
259
- }
260
- function H(t, e) {
261
- if (t.source === "url")
262
- return t.host;
263
- if (e?.remote.host)
264
- return e.remote.host;
265
- throw new Error("Не удалось определить GitLab host. Укажите --url или настройте origin remote.");
266
- }
267
- function N(t, e) {
268
- if (t.source === "branch") {
269
- if (!e?.remote.project)
270
- throw new Error("Не удалось определить проект из origin remote.");
271
- return e.remote.project;
272
- }
273
- return t.project;
274
- }
275
- async function J(t) {
276
- try {
277
- const e = I(t.args);
278
- let r, o, n, i;
279
- if (t.vcsContext) {
280
- if (r = t.vcsContext.host, o = t.vcsContext.project, i = t.vcsContext.branch ? { branch: t.vcsContext.branch, remote: { host: r, project: o, scheme: "https" } } : void 0, !/gitlab/i.test(r))
281
- throw new Error(`Провайдер "${r}" пока не поддерживается.`);
282
- const a = process.env.GITLAB_API_PATH ?? "/api/v4", l = `https://${r}${a}`;
283
- n = {
284
- host: r,
285
- project: o,
286
- vcs: new w({ token: t.vcsContext.token, baseUrl: l })
287
- };
288
- } else
289
- i = e.source !== "url" ? L(t.args.branch) : void 0, r = H(e, i), o = N(e, i), n = T(r, o);
290
- const s = await P(
291
- e,
292
- n,
293
- i,
294
- t.args.draft
295
- );
296
- if (!s)
297
- return e.source === "branch" ? console.info(
298
- u.yellow("ℹ Merge Request не найден для ветки:"),
299
- u.cyan(i?.branch ?? "")
300
- ) : (console.info(u.yellow("ℹ Merge Request не найден:")), console.info(`- project: ${u.cyan(o)}`), console.info(`- iid: ${u.cyan(e.iid)}`)), {
301
- ok: !0,
302
- code: 0
303
- };
304
- const c = D(
305
- s.mergeRequest,
306
- s.discussions,
307
- t.args.all,
308
- t.args.since
309
- );
310
- return {
311
- ok: !0,
312
- code: 0,
313
- output: t.mode === "verify" ? await q(c) : c,
314
- artifact: {
315
- mergeRequest: s.mergeRequest,
316
- discussions: s.discussions,
317
- reviewArtifactXml: c
318
- }
319
- };
320
- } catch (e) {
321
- const r = e.message ?? String(e);
322
- return console.error(u.redBright.bold("✖ Ошибка:"), r), {
323
- ok: !1,
324
- code: 1
325
- };
326
- }
327
- }
328
- export {
329
- z as p,
330
- J as r
331
- };
@@ -1,162 +0,0 @@
1
- import { s as o } from "./shared-B5CTGvpG.js";
2
- import { existsSync as E, readFileSync as I, unlinkSync as b, readdirSync as T } from "node:fs";
3
- import { join as v } from "node:path";
4
- import { homedir as O } from "node:os";
5
- import { i as $, t as k, e as M, g as N, S as P, R as V, f as B, h as D, j as _, O as C, k as F, m as U, n as j } from "./services-Csd556Tv.js";
6
- function L(e) {
7
- const n = e.includes("--mocks"), s = e.find(
8
- (c) => typeof c == "string" && c.startsWith("--port=")
9
- ), t = s ? Number(s.slice(7)) : void 0;
10
- return t !== void 0 && (!Number.isFinite(t) || t < 1 || t > 65535) && (console.error(o.redBright.bold("✖ Ошибка:"), `Некорректный порт: ${s}`), process.exit(1)), { mocks: n, port: t };
11
- }
12
- const R = "https://gitlab.example.com/group/project/-/merge_requests/510", G = [R], W = { version: 1, mrs: { [R]: { state: "fresh" } } };
13
- function g(e, n) {
14
- const s = e.find(
15
- (c) => typeof c == "string" && c.startsWith(`${n}=`)
16
- );
17
- if (s) return s.slice(n.length + 1);
18
- const t = e.indexOf(n);
19
- return t !== -1 ? e[t + 1] : void 0;
20
- }
21
- async function J(e, n) {
22
- if (n !== void 0)
23
- return console.info(o.cyan(` attaching to opencode on explicit port ${n}`)), `http://localhost:${n}`;
24
- const s = v(e, "agent-inbox");
25
- let t = [];
26
- try {
27
- t = T(s).filter(
28
- (c) => c.startsWith("opencode-") && c.endsWith(".pid")
29
- );
30
- } catch {
31
- return "http://localhost:4096";
32
- }
33
- for (const c of t)
34
- try {
35
- const { pid: a, port: r } = JSON.parse(I(v(s, c), "utf-8"));
36
- if (await $(a))
37
- return console.info(
38
- o.cyan(
39
- ` attaching to running opencode on port ${r} (pid ${a}, from ${c}${t.length > 1 ? ` — ${t.length} instances found, pass --opencode-port to pick another` : ""})`
40
- )
41
- ), `http://localhost:${r}`;
42
- } catch {
43
- }
44
- return "http://localhost:4096";
45
- }
46
- function X(e) {
47
- return e === "@fixture" ? G : e.split(",").map((n) => n.trim()).filter(Boolean);
48
- }
49
- async function H(e) {
50
- return e === "@fixture" ? W : j(e);
51
- }
52
- async function q(e, n, s) {
53
- try {
54
- if (!e.includes("--once"))
55
- return console.error(
56
- o.redBright.bold("✖ Ошибка:"),
57
- "--mrs требует --once (run-mode — единственный однопроходный режим)"
58
- ), 1;
59
- const t = X(n), c = g(e, "--seed"), a = c ? await H(c) : void 0, r = g(e, "--dry-run") !== "false";
60
- console.info(o.bold("gennady inbox serve --mrs (run-mode, dry-run)")), console.info("");
61
- const p = new P(), y = new V();
62
- await y.loadAll();
63
- const w = s ? void 0 : await B(t, p), f = s ? new D() : new _({ host: w, token: process.env.GITLAB_PERSONAL_TOKEN }), d = g(e, "--opencode-port"), i = d ? Number(d) : void 0, l = s ? void 0 : await J(p.getStateDir(), i), u = s ? new C() : new F({ directory: p.getStateDir(), baseUrl: l }), m = await U({
64
- mrs: t,
65
- seedState: a,
66
- dryRun: r,
67
- deps: { engine: y, store: p, vcs: f, opencode: u, fetchDiffRefs: s ? async () => {
68
- } : void 0 }
69
- });
70
- return console.info(JSON.stringify(m, null, 2)), 0;
71
- } catch (t) {
72
- return console.error(o.redBright.bold("✖ Ошибка:"), t.message), 1;
73
- }
74
- }
75
- async function K() {
76
- try {
77
- const e = process.argv.slice(3), { mocks: n, port: s } = L(e), t = g(e, "--mrs");
78
- if (t)
79
- return await q(e, t, n);
80
- const c = v(O(), ".gennady"), a = v(c, "agent-inbox", `opencode-${s ?? 4174}.pid`);
81
- if (console.info(o.bold("gennady inbox serve")), console.info(""), E(a))
82
- try {
83
- const i = I(a, "utf-8"), { pid: l, port: u } = JSON.parse(i);
84
- if (await $(l)) {
85
- const h = s ?? 4174;
86
- let m = !1;
87
- try {
88
- const S = new AbortController(), x = setTimeout(() => S.abort(), 2e3), A = await fetch(`http://localhost:${h}/api/board`, {
89
- signal: S.signal
90
- });
91
- clearTimeout(x), m = A.ok;
92
- } catch {
93
- }
94
- if (m)
95
- return console.info(
96
- o.yellow(
97
- `⚠ Уже запущен на порту ${h} (opencode PID ${l}:${u})`
98
- )
99
- ), 0;
100
- console.info(o.yellow("⚠ Обнаружен orphan-процесс opencode — очистка...")), await k(
101
- l,
102
- `orphan detected at serve.cmd.ts pre-check for port ${h}`
103
- );
104
- try {
105
- b(a);
106
- } catch {
107
- }
108
- } else
109
- try {
110
- b(a);
111
- } catch {
112
- }
113
- } catch {
114
- }
115
- const r = await M({ mocks: n, port: s });
116
- await r.server.start();
117
- const p = setInterval(() => {
118
- r.scheduler.tick();
119
- }, r.pollingInterval);
120
- r.scheduler.tick();
121
- const w = setInterval(() => {
122
- r.scheduler.advanceInstances();
123
- }, 3e3);
124
- console.info(""), console.info(
125
- `${o.green("✓")} Server started on ${o.bold(`http://localhost:${r.port}`)}`
126
- ), console.info(` OpenCode: ${o.cyan(r.opencodeStatus)}`), console.info(` Polling: every ${Math.round(r.pollingInterval / 1e3)}s`), console.info(` Roles: ${r.roles.map((i) => o.cyan(i)).join(", ")}`), r.degraded && console.info(
127
- ` ${o.yellow("⚠")} AI engine degraded — dashboard available, AI steps disabled`
128
- ), console.info(""), console.info(o.dim("Press Ctrl+C to stop"));
129
- let f = !1;
130
- const d = async (i, l = 0) => {
131
- if (f) return;
132
- f = !0, console.info(""), console.info(o.dim(`Received ${i}, shutting down...`)), clearInterval(p), clearInterval(w);
133
- const u = setTimeout(() => {
134
- console.info(o.dim("Shutdown timed out — forcing exit.")), process.exit(1);
135
- }, 15e3);
136
- try {
137
- await N({
138
- server: r.server,
139
- opencode: r.opencode,
140
- opencodeProcess: r.opencodeProcess,
141
- opencodePidFile: r.opencodePidFile,
142
- scheduler: r.scheduler,
143
- backgroundVerifier: r.backgroundVerifier
144
- });
145
- } catch {
146
- }
147
- clearTimeout(u), process.exit(l);
148
- };
149
- return process.on("SIGTERM", () => void d("SIGTERM")), process.on("SIGINT", () => void d("SIGINT")), process.on("uncaughtException", (i) => {
150
- console.error(o.redBright.bold("✖ Unhandled error:"), i.message), d("uncaughtException", 1);
151
- }), process.on("unhandledRejection", (i) => {
152
- console.error(o.redBright.bold("✖ Unhandled rejection:"), i), d("unhandledRejection", 1);
153
- }), await new Promise(() => {
154
- });
155
- } catch (e) {
156
- const n = e.message ?? String(e);
157
- return n.includes("не настроен") ? (console.info(o.yellow(`ℹ ${n}`)), 0) : n.includes("opencode not found") ? (console.error(o.redBright.bold("✖ Ошибка:"), n), console.info(
158
- o.dim(" Установите @opencode-ai/sdk или запустите с флагом --mocks для dev-режима.")
159
- ), 1) : (console.error(o.redBright.bold("✖ Ошибка:"), n), 1);
160
- }
161
- }
162
- process.exit(await K());