catenext 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/dist/index.js +785 -363
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createInterface } from "node:readline";
|
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
|
|
9
9
|
// shared/src/api.ts
|
|
10
|
-
import { z as
|
|
10
|
+
import { z as z5 } from "zod";
|
|
11
11
|
|
|
12
12
|
// shared/src/common.ts
|
|
13
13
|
import { z } from "zod";
|
|
@@ -25,11 +25,78 @@ function countWords(text2) {
|
|
|
25
25
|
return trimmed === "" ? 0 : trimmed.split(/\s+/).length;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
// shared/src/review.ts
|
|
29
|
+
import { z as z2 } from "zod";
|
|
30
|
+
var CommitShaSchema = z2.string().regex(/^[0-9a-f]{40}$/);
|
|
31
|
+
var PullRequestUrlSchema = z2.string().max(240).regex(
|
|
32
|
+
/^https:\/\/github\.com\/[a-z\d][a-z\d-]*\/[a-z\d_.-]+\/pull\/[1-9]\d*$/i,
|
|
33
|
+
"Gunakan URL pull request GitHub."
|
|
34
|
+
);
|
|
35
|
+
var PullRequestRefSchema = z2.object({
|
|
36
|
+
url: PullRequestUrlSchema,
|
|
37
|
+
base_branch: z2.string().min(1).max(255),
|
|
38
|
+
head_sha: CommitShaSchema
|
|
39
|
+
});
|
|
40
|
+
var REVIEW_STAGES = [
|
|
41
|
+
"draft",
|
|
42
|
+
"awaiting_review",
|
|
43
|
+
"in_review",
|
|
44
|
+
"changes_requested",
|
|
45
|
+
"revising",
|
|
46
|
+
"awaiting_human_approval",
|
|
47
|
+
"approved_awaiting_merge",
|
|
48
|
+
"closed_without_merge",
|
|
49
|
+
"merged"
|
|
50
|
+
];
|
|
51
|
+
var ReviewStageSchema = z2.enum(REVIEW_STAGES);
|
|
52
|
+
var PullRequestStateSchema = PullRequestRefSchema.extend({
|
|
53
|
+
stage: ReviewStageSchema,
|
|
54
|
+
checked_at: z2.iso.datetime(),
|
|
55
|
+
reviewer: z2.string().nullable(),
|
|
56
|
+
merge_sha: CommitShaSchema.nullable()
|
|
57
|
+
});
|
|
58
|
+
var ReviewInput = z2.discriminatedUnion("action", [
|
|
59
|
+
z2.object({ action: z2.literal("list"), limit: z2.number().int().min(1).max(30).default(10) }),
|
|
60
|
+
z2.object({
|
|
61
|
+
action: z2.literal("claim"),
|
|
62
|
+
task_id: IdSchema,
|
|
63
|
+
agent_alias: z2.string().min(1).max(80).optional()
|
|
64
|
+
}),
|
|
65
|
+
z2.object({ action: z2.literal("refresh"), task_id: IdSchema }),
|
|
66
|
+
z2.object({
|
|
67
|
+
action: z2.literal("submit"),
|
|
68
|
+
task_id: IdSchema,
|
|
69
|
+
lease_id: IdSchema,
|
|
70
|
+
head_sha: CommitShaSchema,
|
|
71
|
+
decision: z2.enum(["approve", "request_changes"]),
|
|
72
|
+
feedback: z2.string().trim().min(1).max(1e3)
|
|
73
|
+
})
|
|
74
|
+
]);
|
|
75
|
+
var ReviewEntrySchema = z2.object({
|
|
76
|
+
task_id: IdSchema,
|
|
77
|
+
title: z2.string(),
|
|
78
|
+
status: z2.enum(["NEEDS_REVIEW", "REVISION_REQUESTED", "DONE"]),
|
|
79
|
+
review: PullRequestStateSchema
|
|
80
|
+
});
|
|
81
|
+
var ReviewOutput = z2.union([
|
|
82
|
+
z2.object({ reviews: z2.array(ReviewEntrySchema) }),
|
|
83
|
+
ReviewEntrySchema.extend({
|
|
84
|
+
lease_id: IdSchema.optional(),
|
|
85
|
+
lease_expires_at: z2.iso.datetime().optional(),
|
|
86
|
+
notes_for_next_agent: z2.string().optional(),
|
|
87
|
+
warning: z2.string().optional()
|
|
88
|
+
})
|
|
89
|
+
]);
|
|
90
|
+
var HumanReviewInput = z2.discriminatedUnion("action", [
|
|
91
|
+
z2.object({ action: z2.literal("refresh") }),
|
|
92
|
+
z2.object({ action: z2.literal("approve"), head_sha: CommitShaSchema })
|
|
93
|
+
]);
|
|
94
|
+
|
|
28
95
|
// shared/src/task.ts
|
|
29
|
-
import { z as
|
|
96
|
+
import { z as z4 } from "zod";
|
|
30
97
|
|
|
31
98
|
// shared/src/handoff.ts
|
|
32
|
-
import { z as
|
|
99
|
+
import { z as z3 } from "zod";
|
|
33
100
|
var HANDOFF_LIMITS = {
|
|
34
101
|
maxFilesModified: 15,
|
|
35
102
|
maxPathLength: 200,
|
|
@@ -40,15 +107,18 @@ var HANDOFF_LIMITS = {
|
|
|
40
107
|
maxTokens: 600
|
|
41
108
|
};
|
|
42
109
|
var CODE_FENCE = /```/;
|
|
43
|
-
var FilePathSchema =
|
|
44
|
-
var NoCodeText = (max) =>
|
|
45
|
-
var HandoffSummarySchema =
|
|
46
|
-
files_modified:
|
|
47
|
-
key_decisions:
|
|
48
|
-
verification_command:
|
|
110
|
+
var FilePathSchema = z3.string().min(1).max(HANDOFF_LIMITS.maxPathLength).regex(/^[^\s]+$/, "Path file tidak boleh berisi spasi atau baris baru (tanpa potongan kode)");
|
|
111
|
+
var NoCodeText = (max) => z3.string().min(1).max(max).refine((s) => !CODE_FENCE.test(s), "Jangan menempelkan blok kode; cukup rujuk path file");
|
|
112
|
+
var HandoffSummarySchema = z3.object({
|
|
113
|
+
files_modified: z3.array(FilePathSchema).max(HANDOFF_LIMITS.maxFilesModified),
|
|
114
|
+
key_decisions: z3.array(NoCodeText(HANDOFF_LIMITS.maxKeyDecisionLength)).max(HANDOFF_LIMITS.maxKeyDecisions),
|
|
115
|
+
verification_command: z3.string().min(1).max(HANDOFF_LIMITS.maxVerificationCommandLength).nullable(),
|
|
49
116
|
notes_for_next_agent: NoCodeText(HANDOFF_LIMITS.maxNotesLength),
|
|
50
|
-
|
|
51
|
-
|
|
117
|
+
pull_request: PullRequestRefSchema.optional(),
|
|
118
|
+
git_branch: z3.string().min(1).max(255),
|
|
119
|
+
last_commit_hash: z3.string().regex(/^[0-9a-f]{7,64}$/, "Hash commit git (hex, 7\u201364 karakter)")
|
|
120
|
+
}).refine((h) => !h.pull_request || h.last_commit_hash === h.pull_request.head_sha, {
|
|
121
|
+
message: "SHA handoff harus sama dengan head SHA PR."
|
|
52
122
|
}).refine((h) => estimateHandoffTokens(h) <= HANDOFF_LIMITS.maxTokens, {
|
|
53
123
|
message: `Ringkasan handoff melebihi ~${HANDOFF_LIMITS.maxTokens} token; ringkas lagi`
|
|
54
124
|
});
|
|
@@ -66,7 +136,7 @@ var TASK_STATUSES = [
|
|
|
66
136
|
"BLOCKED",
|
|
67
137
|
"DONE"
|
|
68
138
|
];
|
|
69
|
-
var TaskStatusSchema =
|
|
139
|
+
var TaskStatusSchema = z4.enum(TASK_STATUSES);
|
|
70
140
|
var KANBAN_STATUSES = TASK_STATUSES.filter(
|
|
71
141
|
(s) => s !== "DRAFT"
|
|
72
142
|
);
|
|
@@ -92,41 +162,45 @@ var TASK_EVENTS = [
|
|
|
92
162
|
"unblock"
|
|
93
163
|
// human: BLOCKED -> TODO
|
|
94
164
|
];
|
|
95
|
-
var TaskEventSchema =
|
|
165
|
+
var TaskEventSchema = z4.enum(TASK_EVENTS);
|
|
96
166
|
var LOCK_LEASE_MS = 30 * 60 * 1e3;
|
|
97
|
-
var TaskSchema =
|
|
167
|
+
var TaskSchema = z4.object({
|
|
98
168
|
id: IdSchema,
|
|
99
169
|
/** Diduplikasi dari project agar kebijakan RLS cukup `workspace_id = current_setting(...)`. */
|
|
100
170
|
workspace_id: IdSchema,
|
|
101
171
|
project_id: IdSchema,
|
|
102
172
|
epic_id: IdSchema,
|
|
103
|
-
title:
|
|
104
|
-
prompt_instruction:
|
|
173
|
+
title: z4.string().min(1).max(200),
|
|
174
|
+
prompt_instruction: z4.string().min(1).max(8e3),
|
|
105
175
|
status: TaskStatusSchema,
|
|
106
|
-
requires_approval:
|
|
176
|
+
requires_approval: z4.boolean().default(false),
|
|
107
177
|
target_repo: RepoNameSchema.nullable(),
|
|
108
178
|
role: RoleSchema.nullable(),
|
|
179
|
+
/** Persona penanggung jawab. Bila diisi, hanya agen dengan alias persona ini yang boleh mengambilnya. */
|
|
180
|
+
persona_id: IdSchema.nullable(),
|
|
109
181
|
assignee_id: IdSchema.nullable(),
|
|
110
|
-
locked_by:
|
|
182
|
+
locked_by: z4.string().max(200).nullable(),
|
|
111
183
|
locked_at: IsoDateTimeSchema.nullable(),
|
|
112
184
|
lease_expires_at: IsoDateTimeSchema.nullable(),
|
|
113
185
|
handoff_summary: HandoffSummarySchema.nullable(),
|
|
114
|
-
review_feedback:
|
|
115
|
-
revision_count:
|
|
116
|
-
blocker_reason:
|
|
186
|
+
review_feedback: z4.string().max(2e3).nullable(),
|
|
187
|
+
revision_count: z4.number().int().min(0).default(0),
|
|
188
|
+
blocker_reason: z4.string().max(1e3).nullable(),
|
|
117
189
|
/** Ditandai bila dependensi hulu dibuka ulang setelah task ini berjalan. */
|
|
118
|
-
is_stale:
|
|
119
|
-
depends_on:
|
|
190
|
+
is_stale: z4.boolean().default(false),
|
|
191
|
+
depends_on: z4.array(IdSchema).default([]),
|
|
120
192
|
created_at: IsoDateTimeSchema,
|
|
121
193
|
updated_at: IsoDateTimeSchema
|
|
122
194
|
});
|
|
123
|
-
var TaskSummarySchema =
|
|
195
|
+
var TaskSummarySchema = z4.object({
|
|
124
196
|
id: IdSchema,
|
|
125
|
-
title:
|
|
126
|
-
depends_on:
|
|
197
|
+
title: z4.string().min(1).max(200),
|
|
198
|
+
depends_on: z4.array(IdSchema),
|
|
127
199
|
role: RoleSchema.optional(),
|
|
200
|
+
/** Alias persona penanggung jawab. */
|
|
201
|
+
persona: AgentAliasSchema.optional(),
|
|
128
202
|
target_repo: RepoNameSchema.optional(),
|
|
129
|
-
revision:
|
|
203
|
+
revision: z4.boolean().optional()
|
|
130
204
|
});
|
|
131
205
|
var BLOCKER_CATEGORIES = [
|
|
132
206
|
"missing_env",
|
|
@@ -135,144 +209,157 @@ var BLOCKER_CATEGORIES = [
|
|
|
135
209
|
"dependency_issue",
|
|
136
210
|
"other"
|
|
137
211
|
];
|
|
138
|
-
var BlockerCategorySchema =
|
|
212
|
+
var BlockerCategorySchema = z4.enum(BLOCKER_CATEGORIES);
|
|
139
213
|
|
|
140
214
|
// shared/src/api.ts
|
|
141
|
-
var WorkspaceSchema =
|
|
215
|
+
var WorkspaceSchema = z5.object({
|
|
142
216
|
id: IdSchema,
|
|
143
|
-
name:
|
|
144
|
-
slug:
|
|
145
|
-
role:
|
|
217
|
+
name: z5.string(),
|
|
218
|
+
slug: z5.string(),
|
|
219
|
+
role: z5.string()
|
|
146
220
|
});
|
|
147
|
-
var ProjectSchema =
|
|
221
|
+
var ProjectSchema = z5.object({
|
|
148
222
|
id: IdSchema,
|
|
149
223
|
workspace_id: IdSchema,
|
|
150
|
-
name:
|
|
151
|
-
detected_stack:
|
|
224
|
+
name: z5.string().min(1).max(120),
|
|
225
|
+
detected_stack: z5.array(z5.string()),
|
|
152
226
|
agent_connected_at: IsoDateTimeSchema.nullable(),
|
|
153
227
|
created_at: IsoDateTimeSchema,
|
|
154
228
|
updated_at: IsoDateTimeSchema
|
|
155
229
|
});
|
|
156
|
-
var EpicSchema =
|
|
230
|
+
var EpicSchema = z5.object({
|
|
157
231
|
id: IdSchema,
|
|
158
232
|
workspace_id: IdSchema,
|
|
159
233
|
project_id: IdSchema,
|
|
160
|
-
title:
|
|
161
|
-
description:
|
|
162
|
-
template_used:
|
|
234
|
+
title: z5.string().min(1).max(200),
|
|
235
|
+
description: z5.string().max(4e3).nullable(),
|
|
236
|
+
template_used: z5.string().max(80).nullable(),
|
|
163
237
|
created_at: IsoDateTimeSchema,
|
|
164
238
|
updated_at: IsoDateTimeSchema
|
|
165
239
|
});
|
|
166
240
|
var TaskDtoSchema = TaskSchema.extend({
|
|
167
|
-
|
|
241
|
+
pull_request: PullRequestStateSchema.nullable().optional(),
|
|
242
|
+
worktree_branch: z5.string().nullable().optional(),
|
|
243
|
+
position: z5.number(),
|
|
168
244
|
lock_repo: RepoNameSchema.nullable(),
|
|
169
245
|
blocker_category: BlockerCategorySchema.nullable(),
|
|
170
246
|
/** Dependensi yang belum DONE. Kosong = tidak tertahan dependensi. */
|
|
171
|
-
blocked_by:
|
|
247
|
+
blocked_by: z5.array(IdSchema),
|
|
172
248
|
/** TODO/REVISION_REQUESTED dan semua dependensinya DONE: bisa diklaim agen sekarang. */
|
|
173
|
-
is_ready:
|
|
249
|
+
is_ready: z5.boolean()
|
|
174
250
|
});
|
|
175
|
-
var AgentPersonaSchema =
|
|
251
|
+
var AgentPersonaSchema = z5.object({
|
|
176
252
|
id: IdSchema,
|
|
177
253
|
workspace_id: IdSchema,
|
|
178
254
|
project_id: IdSchema.nullable(),
|
|
179
255
|
alias: AgentAliasSchema,
|
|
180
256
|
role: RoleSchema,
|
|
181
|
-
rules:
|
|
257
|
+
rules: z5.array(z5.string()),
|
|
182
258
|
created_at: IsoDateTimeSchema,
|
|
183
259
|
updated_at: IsoDateTimeSchema
|
|
184
260
|
});
|
|
185
|
-
var ApiKeySchema =
|
|
261
|
+
var ApiKeySchema = z5.object({
|
|
186
262
|
id: IdSchema,
|
|
187
263
|
workspace_id: IdSchema,
|
|
188
264
|
project_id: IdSchema.nullable(),
|
|
189
|
-
name:
|
|
190
|
-
prefix:
|
|
265
|
+
name: z5.string(),
|
|
266
|
+
prefix: z5.string(),
|
|
191
267
|
last_used_at: IsoDateTimeSchema.nullable(),
|
|
192
268
|
revoked_at: IsoDateTimeSchema.nullable(),
|
|
193
269
|
created_at: IsoDateTimeSchema
|
|
194
270
|
});
|
|
195
271
|
var ACTIVITY_ACTORS = ["human", "agent", "system"];
|
|
196
|
-
var ActivityLogSchema =
|
|
272
|
+
var ActivityLogSchema = z5.object({
|
|
197
273
|
id: IdSchema,
|
|
198
274
|
workspace_id: IdSchema,
|
|
199
275
|
project_id: IdSchema.nullable(),
|
|
200
276
|
task_id: IdSchema.nullable(),
|
|
201
|
-
event_type:
|
|
202
|
-
actor:
|
|
203
|
-
persona_alias:
|
|
277
|
+
event_type: z5.string(),
|
|
278
|
+
actor: z5.enum(ACTIVITY_ACTORS),
|
|
279
|
+
persona_alias: z5.string().nullable(),
|
|
204
280
|
/** Nama agen + repo untuk event agen (mis. `claude-code@web`), null untuk manusia/sistem. */
|
|
205
|
-
agent_name:
|
|
206
|
-
duration_ms:
|
|
207
|
-
metadata:
|
|
281
|
+
agent_name: z5.string().nullable(),
|
|
282
|
+
duration_ms: z5.number().int().nullable(),
|
|
283
|
+
metadata: z5.record(z5.string(), z5.unknown()).nullable(),
|
|
208
284
|
created_at: IsoDateTimeSchema
|
|
209
285
|
});
|
|
210
|
-
var ProjectMetricsSchema =
|
|
211
|
-
handoffs_7d:
|
|
212
|
-
revisions_7d:
|
|
213
|
-
blockers_7d:
|
|
214
|
-
avg_task_duration_ms:
|
|
286
|
+
var ProjectMetricsSchema = z5.object({
|
|
287
|
+
handoffs_7d: z5.number().int(),
|
|
288
|
+
revisions_7d: z5.number().int(),
|
|
289
|
+
blockers_7d: z5.number().int(),
|
|
290
|
+
avg_task_duration_ms: z5.number().int().nullable()
|
|
291
|
+
});
|
|
292
|
+
var CreateProjectInput = z5.object({
|
|
293
|
+
name: z5.string().trim().min(1).max(120),
|
|
294
|
+
detected_stack: z5.array(z5.string().min(1).max(40)).max(20).default([])
|
|
215
295
|
});
|
|
216
|
-
var
|
|
217
|
-
name:
|
|
218
|
-
detected_stack:
|
|
296
|
+
var UpdateProjectInput = z5.object({
|
|
297
|
+
name: z5.string().trim().min(1).max(120).optional(),
|
|
298
|
+
detected_stack: z5.array(z5.string().min(1).max(40)).max(20).optional()
|
|
219
299
|
});
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
template_used: z4.string().max(80).nullish()
|
|
300
|
+
var CreateEpicInput = z5.object({
|
|
301
|
+
title: z5.string().trim().min(1).max(200),
|
|
302
|
+
description: z5.string().max(4e3).nullish(),
|
|
303
|
+
template_used: z5.string().max(80).nullish()
|
|
225
304
|
});
|
|
226
305
|
var UpdateEpicInput = CreateEpicInput.partial();
|
|
227
|
-
var CreateTaskInput =
|
|
228
|
-
title:
|
|
229
|
-
prompt_instruction:
|
|
306
|
+
var CreateTaskInput = z5.object({
|
|
307
|
+
title: z5.string().trim().min(1).max(200),
|
|
308
|
+
prompt_instruction: z5.string().min(1).max(8e3),
|
|
230
309
|
target_repo: RepoNameSchema.nullish(),
|
|
231
310
|
role: RoleSchema.nullish(),
|
|
232
|
-
|
|
233
|
-
|
|
311
|
+
/** Persona penanggung jawab; role task otomatis mengikuti role persona. */
|
|
312
|
+
persona_id: IdSchema.nullish(),
|
|
313
|
+
requires_approval: z5.boolean().default(false),
|
|
314
|
+
depends_on: z5.array(IdSchema).max(10).default([]),
|
|
234
315
|
/** Task buatan manusia langsung TODO; DRAFT bila ingin ditinjau bersama rencana agen. */
|
|
235
|
-
status:
|
|
316
|
+
status: z5.enum(["DRAFT", "TODO"]).default("TODO")
|
|
236
317
|
});
|
|
237
|
-
var UpdateTaskInput =
|
|
238
|
-
title:
|
|
239
|
-
prompt_instruction:
|
|
318
|
+
var UpdateTaskInput = z5.object({
|
|
319
|
+
title: z5.string().trim().min(1).max(200).optional(),
|
|
320
|
+
prompt_instruction: z5.string().min(1).max(8e3).optional(),
|
|
240
321
|
target_repo: RepoNameSchema.nullable().optional(),
|
|
241
322
|
role: RoleSchema.nullable().optional(),
|
|
242
|
-
|
|
323
|
+
persona_id: IdSchema.nullable().optional(),
|
|
324
|
+
requires_approval: z5.boolean().optional(),
|
|
243
325
|
assignee_id: IdSchema.nullable().optional(),
|
|
244
|
-
position:
|
|
326
|
+
position: z5.number().finite().optional(),
|
|
245
327
|
/** Hanya boleh false: manusia menandai task stale sudah diperiksa ulang. */
|
|
246
|
-
is_stale:
|
|
247
|
-
});
|
|
248
|
-
var SetDependenciesInput =
|
|
249
|
-
depends_on:
|
|
250
|
-
});
|
|
251
|
-
var TaskActionInput =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
event:
|
|
257
|
-
feedback:
|
|
328
|
+
is_stale: z5.literal(false).optional()
|
|
329
|
+
});
|
|
330
|
+
var SetDependenciesInput = z5.object({
|
|
331
|
+
depends_on: z5.array(IdSchema).max(10)
|
|
332
|
+
});
|
|
333
|
+
var TaskActionInput = z5.discriminatedUnion("event", [
|
|
334
|
+
z5.object({ event: z5.literal("approve_plan") }),
|
|
335
|
+
z5.object({ event: z5.literal("return_to_draft") }),
|
|
336
|
+
z5.object({ event: z5.literal("approve") }),
|
|
337
|
+
z5.object({
|
|
338
|
+
event: z5.literal("request_revision"),
|
|
339
|
+
feedback: z5.string().trim().min(5).max(2e3)
|
|
258
340
|
}),
|
|
259
|
-
|
|
341
|
+
z5.object({ event: z5.literal("unblock") })
|
|
260
342
|
]);
|
|
261
|
-
var PersonaInput =
|
|
343
|
+
var PersonaInput = z5.object({
|
|
262
344
|
alias: AgentAliasSchema,
|
|
263
345
|
role: RoleSchema,
|
|
264
|
-
rules:
|
|
346
|
+
rules: z5.array(z5.string().trim().min(1).max(300)).max(30).default([]),
|
|
347
|
+
project_id: IdSchema.nullish()
|
|
348
|
+
});
|
|
349
|
+
var UpdatePersonaInput = z5.object({
|
|
350
|
+
alias: AgentAliasSchema.optional(),
|
|
351
|
+
role: RoleSchema.optional(),
|
|
352
|
+
rules: z5.array(z5.string().trim().min(1).max(300)).max(30).optional(),
|
|
265
353
|
project_id: IdSchema.nullish()
|
|
266
354
|
});
|
|
267
|
-
var
|
|
268
|
-
|
|
269
|
-
name: z4.string().trim().min(1).max(80),
|
|
355
|
+
var CreateApiKeyInput = z5.object({
|
|
356
|
+
name: z5.string().trim().min(1).max(80),
|
|
270
357
|
project_id: IdSchema.nullish()
|
|
271
358
|
});
|
|
272
|
-
var CreateApiKeyOutput =
|
|
359
|
+
var CreateApiKeyOutput = z5.object({
|
|
273
360
|
api_key: ApiKeySchema,
|
|
274
361
|
/** Kunci mentah. Hanya dikirim sekali, saat dibuat. */
|
|
275
|
-
secret:
|
|
362
|
+
secret: z5.string()
|
|
276
363
|
});
|
|
277
364
|
var AGENT_HEADERS = {
|
|
278
365
|
project: "x-catenext-project",
|
|
@@ -280,43 +367,45 @@ var AGENT_HEADERS = {
|
|
|
280
367
|
agent: "x-catenext-agent"
|
|
281
368
|
};
|
|
282
369
|
var API_KEY_PREFIX = "ctnx_";
|
|
283
|
-
var ReleaseTaskInput =
|
|
284
|
-
var SyncSkillsInput =
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
370
|
+
var ReleaseTaskInput = z5.object({ task_id: IdSchema, lease_id: IdSchema.optional() });
|
|
371
|
+
var SyncSkillsInput = z5.object({
|
|
372
|
+
revision: CommitShaSchema.optional(),
|
|
373
|
+
previous_revision: CommitShaSchema.nullable().optional(),
|
|
374
|
+
skills: z5.array(
|
|
375
|
+
z5.object({
|
|
376
|
+
name: z5.string().min(1).max(48),
|
|
377
|
+
when_to_use: z5.string().min(1).max(160)
|
|
289
378
|
})
|
|
290
379
|
).max(100)
|
|
291
380
|
});
|
|
292
|
-
var VerifyOutput =
|
|
293
|
-
token_valid:
|
|
381
|
+
var VerifyOutput = z5.object({
|
|
382
|
+
token_valid: z5.literal(true),
|
|
294
383
|
workspace_id: IdSchema,
|
|
295
|
-
project:
|
|
384
|
+
project: z5.object({ id: IdSchema, name: z5.string() }),
|
|
296
385
|
repo_name: RepoNameSchema
|
|
297
386
|
});
|
|
298
|
-
var ApiErrorSchema =
|
|
299
|
-
error:
|
|
300
|
-
code:
|
|
301
|
-
message:
|
|
302
|
-
details:
|
|
387
|
+
var ApiErrorSchema = z5.object({
|
|
388
|
+
error: z5.object({
|
|
389
|
+
code: z5.string(),
|
|
390
|
+
message: z5.string(),
|
|
391
|
+
details: z5.unknown().optional()
|
|
303
392
|
})
|
|
304
393
|
});
|
|
305
394
|
|
|
306
395
|
// shared/src/config.ts
|
|
307
|
-
import { z as
|
|
396
|
+
import { z as z6 } from "zod";
|
|
308
397
|
var CONFIG_SCHEMA_VERSION = 1;
|
|
309
|
-
var CatenextConfigSchema =
|
|
310
|
-
schema_version:
|
|
398
|
+
var CatenextConfigSchema = z6.object({
|
|
399
|
+
schema_version: z6.number().int().positive(),
|
|
311
400
|
project_id: IdSchema,
|
|
312
401
|
repo_name: RepoNameSchema,
|
|
313
|
-
stack:
|
|
402
|
+
stack: z6.array(z6.string().min(1).max(40)).max(20).default([]),
|
|
314
403
|
/** URL Catenext Cloud API; kosong = default bawaan CLI. */
|
|
315
|
-
api_url:
|
|
316
|
-
overrides:
|
|
404
|
+
api_url: z6.url().optional(),
|
|
405
|
+
overrides: z6.object({
|
|
317
406
|
default_agent_alias: AgentAliasSchema.optional(),
|
|
318
407
|
default_role: RoleSchema.optional(),
|
|
319
|
-
extra_rules:
|
|
408
|
+
extra_rules: z6.array(z6.string().min(1).max(300)).max(20).optional()
|
|
320
409
|
}).optional()
|
|
321
410
|
});
|
|
322
411
|
function checkConfigCompatibility(schemaVersion, supported = CONFIG_SCHEMA_VERSION) {
|
|
@@ -378,50 +467,50 @@ function findCycle(edges) {
|
|
|
378
467
|
}
|
|
379
468
|
|
|
380
469
|
// shared/src/device.ts
|
|
381
|
-
import { z as
|
|
382
|
-
var UserCodeSchema =
|
|
383
|
-
var DeviceCodeInput =
|
|
470
|
+
import { z as z7 } from "zod";
|
|
471
|
+
var UserCodeSchema = z7.string().trim().toUpperCase().regex(/^[A-Z2-9]{4}-?[A-Z2-9]{4}$/, "Kode harus 8 karakter, mis. ABCD-EFGH").transform((s) => s.includes("-") ? s : `${s.slice(0, 4)}-${s.slice(4)}`);
|
|
472
|
+
var DeviceCodeInput = z7.object({
|
|
384
473
|
/** Nama mesin/klien yang ditampilkan saat menyetujui, mis. "catenext CLI @ macbook". */
|
|
385
|
-
client_name:
|
|
474
|
+
client_name: z7.string().trim().min(1).max(80),
|
|
386
475
|
/**
|
|
387
476
|
* Public key X25519 sementara milik CLI (SPKI DER, base64url). API key hasil persetujuan
|
|
388
477
|
* dienkripsi ke kunci ini, jadi baris database saja tidak cukup untuk membacanya.
|
|
389
478
|
*/
|
|
390
|
-
public_key:
|
|
391
|
-
});
|
|
392
|
-
var DeviceCodeOutput =
|
|
393
|
-
device_code:
|
|
394
|
-
user_code:
|
|
395
|
-
verification_uri:
|
|
396
|
-
verification_uri_complete:
|
|
397
|
-
expires_in:
|
|
398
|
-
interval:
|
|
399
|
-
});
|
|
400
|
-
var DeviceTokenInput =
|
|
401
|
-
var DeviceTokenOutput =
|
|
479
|
+
public_key: z7.string().min(40).max(200)
|
|
480
|
+
});
|
|
481
|
+
var DeviceCodeOutput = z7.object({
|
|
482
|
+
device_code: z7.string(),
|
|
483
|
+
user_code: z7.string(),
|
|
484
|
+
verification_uri: z7.string(),
|
|
485
|
+
verification_uri_complete: z7.string(),
|
|
486
|
+
expires_in: z7.number().int(),
|
|
487
|
+
interval: z7.number().int()
|
|
488
|
+
});
|
|
489
|
+
var DeviceTokenInput = z7.object({ device_code: z7.string().min(20).max(200) });
|
|
490
|
+
var DeviceTokenOutput = z7.object({
|
|
402
491
|
/** API key terenkripsi ke public_key CLI: <pub efemeral>.<iv>.<tag>.<ciphertext> (base64url). */
|
|
403
|
-
encrypted_key:
|
|
492
|
+
encrypted_key: z7.string(),
|
|
404
493
|
workspace_id: IdSchema,
|
|
405
494
|
project_id: IdSchema.nullable()
|
|
406
495
|
});
|
|
407
|
-
var DeviceLookupOutput =
|
|
408
|
-
user_code:
|
|
409
|
-
client_name:
|
|
410
|
-
status:
|
|
411
|
-
expires_at:
|
|
496
|
+
var DeviceLookupOutput = z7.object({
|
|
497
|
+
user_code: z7.string(),
|
|
498
|
+
client_name: z7.string(),
|
|
499
|
+
status: z7.enum(["pending", "approved", "denied"]),
|
|
500
|
+
expires_at: z7.string()
|
|
412
501
|
});
|
|
413
|
-
var DeviceApproveInput =
|
|
502
|
+
var DeviceApproveInput = z7.object({
|
|
414
503
|
user_code: UserCodeSchema,
|
|
415
|
-
approve:
|
|
504
|
+
approve: z7.boolean(),
|
|
416
505
|
/** Batasi API key ke satu proyek (disarankan). null = semua proyek di workspace. */
|
|
417
506
|
project_id: IdSchema.nullish()
|
|
418
507
|
});
|
|
419
508
|
|
|
420
509
|
// shared/src/mcp-tools.ts
|
|
421
|
-
import { z as
|
|
510
|
+
import { z as z9 } from "zod";
|
|
422
511
|
|
|
423
512
|
// shared/src/skill.ts
|
|
424
|
-
import { z as
|
|
513
|
+
import { z as z8 } from "zod";
|
|
425
514
|
var SKILL_LIMITS = {
|
|
426
515
|
maxWords: 500,
|
|
427
516
|
maxWhenToUseLength: 160,
|
|
@@ -429,9 +518,9 @@ var SKILL_LIMITS = {
|
|
|
429
518
|
maxCodeBlockLines: 15
|
|
430
519
|
};
|
|
431
520
|
var SkillNameSchema = SlugSchema.max(48);
|
|
432
|
-
var SkillFrontmatterSchema =
|
|
521
|
+
var SkillFrontmatterSchema = z8.object({
|
|
433
522
|
name: SkillNameSchema,
|
|
434
|
-
when_to_use:
|
|
523
|
+
when_to_use: z8.string().min(1).max(SKILL_LIMITS.maxWhenToUseLength),
|
|
435
524
|
updated_at: IsoDateTimeSchema
|
|
436
525
|
});
|
|
437
526
|
function longestCodeBlockLines(markdown) {
|
|
@@ -443,117 +532,136 @@ function longestCodeBlockLines(markdown) {
|
|
|
443
532
|
}
|
|
444
533
|
return longest;
|
|
445
534
|
}
|
|
446
|
-
var SkillContentSchema =
|
|
535
|
+
var SkillContentSchema = z8.string().min(1).refine((s) => countWords(s) <= SKILL_LIMITS.maxWords, {
|
|
447
536
|
message: `Skill maksimal ${SKILL_LIMITS.maxWords} kata`
|
|
448
537
|
}).refine((s) => longestCodeBlockLines(s) <= SKILL_LIMITS.maxCodeBlockLines, {
|
|
449
538
|
message: `Blok kode maksimal ${SKILL_LIMITS.maxCodeBlockLines} baris; rujuk path file, jangan menyalin kode`
|
|
450
539
|
});
|
|
451
|
-
var SkillIndexEntrySchema =
|
|
540
|
+
var SkillIndexEntrySchema = z8.object({
|
|
452
541
|
name: SkillNameSchema,
|
|
453
|
-
when_to_use:
|
|
542
|
+
when_to_use: z8.string().min(1).max(SKILL_LIMITS.maxWhenToUseLength),
|
|
454
543
|
repo_name: RepoNameSchema
|
|
455
544
|
});
|
|
545
|
+
function skillPath(name) {
|
|
546
|
+
return `.catenext/skills/${SkillNameSchema.parse(name)}.md`;
|
|
547
|
+
}
|
|
456
548
|
|
|
457
549
|
// shared/src/mcp-tools.ts
|
|
458
550
|
var PersonaFilter = {
|
|
459
551
|
agent_alias: AgentAliasSchema.optional(),
|
|
460
552
|
role: RoleSchema.optional()
|
|
461
553
|
};
|
|
462
|
-
var PersonaSchema =
|
|
554
|
+
var PersonaSchema = z9.object({
|
|
463
555
|
alias: AgentAliasSchema,
|
|
464
556
|
role: RoleSchema,
|
|
465
|
-
rules:
|
|
557
|
+
rules: z9.array(z9.string().min(1).max(300)).max(30)
|
|
466
558
|
});
|
|
467
|
-
var DependencyHandoffSchema =
|
|
559
|
+
var DependencyHandoffSchema = z9.object({
|
|
468
560
|
task_id: IdSchema,
|
|
469
|
-
title:
|
|
470
|
-
handoff_summary: HandoffSummarySchema
|
|
561
|
+
title: z9.string(),
|
|
562
|
+
handoff_summary: HandoffSummarySchema,
|
|
563
|
+
integrated_commit: z9.object({ branch: z9.string(), sha: CommitShaSchema }).optional()
|
|
471
564
|
});
|
|
472
|
-
var GetProjectContextInput =
|
|
473
|
-
var GetProjectContextOutput =
|
|
474
|
-
project:
|
|
565
|
+
var GetProjectContextInput = z9.object({ ...PersonaFilter, lease_id: IdSchema.optional() });
|
|
566
|
+
var GetProjectContextOutput = z9.object({
|
|
567
|
+
project: z9.object({
|
|
475
568
|
id: IdSchema,
|
|
476
|
-
name:
|
|
569
|
+
name: z9.string(),
|
|
477
570
|
repo_name: RepoNameSchema,
|
|
478
|
-
stack:
|
|
571
|
+
stack: z9.array(z9.string())
|
|
479
572
|
}),
|
|
480
573
|
/** Aturan keras untuk agen (mis. jangan mengedit config MCP). Statis di atas agar ramah cache. */
|
|
481
|
-
directives:
|
|
574
|
+
directives: z9.array(z9.string()),
|
|
482
575
|
persona: PersonaSchema.optional(),
|
|
483
|
-
epic_summary:
|
|
576
|
+
epic_summary: z9.string().max(1e3).optional(),
|
|
484
577
|
/** Tier 1: indeks skill saja, isi lengkap lewat load_skill. */
|
|
485
|
-
skills:
|
|
578
|
+
skills: z9.array(SkillIndexEntrySchema),
|
|
579
|
+
skill_revision: CommitShaSchema.optional(),
|
|
486
580
|
/**
|
|
487
581
|
* Handoff dari dependensi langsung task aktif (dependency-scoped context). Jika belum ada
|
|
488
582
|
* task aktif: handoff dependensi task yang siap diklaim (maks. 5).
|
|
489
583
|
*/
|
|
490
|
-
recent_handoffs:
|
|
584
|
+
recent_handoffs: z9.array(DependencyHandoffSchema)
|
|
491
585
|
});
|
|
492
|
-
var GetReadyTasksInput =
|
|
586
|
+
var GetReadyTasksInput = z9.object({
|
|
493
587
|
...PersonaFilter,
|
|
494
|
-
|
|
588
|
+
lease_id: IdSchema.optional(),
|
|
589
|
+
limit: z9.number().int().min(1).max(50).default(10)
|
|
495
590
|
});
|
|
496
|
-
var GetReadyTasksOutput =
|
|
497
|
-
tasks:
|
|
591
|
+
var GetReadyTasksOutput = z9.object({
|
|
592
|
+
tasks: z9.array(TaskSummarySchema)
|
|
498
593
|
});
|
|
499
|
-
var ClaimTaskInput =
|
|
500
|
-
|
|
594
|
+
var ClaimTaskInput = z9.object({
|
|
595
|
+
worktree: z9.object({
|
|
596
|
+
session_id: IdSchema,
|
|
597
|
+
branch: z9.string().min(1).max(255).regex(/^[a-zA-Z0-9_./-]+$/).refine((s) => s !== "HEAD" && !s.startsWith("-") && !s.includes(".."))
|
|
598
|
+
}).optional(),
|
|
599
|
+
task_id: IdSchema,
|
|
600
|
+
/** Alias persona yang sedang dipakai agen. Task milik persona lain ditolak. */
|
|
601
|
+
agent_alias: AgentAliasSchema.optional()
|
|
501
602
|
});
|
|
502
|
-
var ClaimTaskOutput =
|
|
503
|
-
task:
|
|
603
|
+
var ClaimTaskOutput = z9.object({
|
|
604
|
+
task: z9.object({
|
|
504
605
|
id: IdSchema,
|
|
505
|
-
title:
|
|
506
|
-
prompt_instruction:
|
|
507
|
-
status:
|
|
606
|
+
title: z9.string(),
|
|
607
|
+
prompt_instruction: z9.string(),
|
|
608
|
+
status: z9.literal("IN_PROGRESS"),
|
|
508
609
|
role: RoleSchema.optional(),
|
|
509
610
|
target_repo: RepoNameSchema.optional(),
|
|
510
|
-
revision_count:
|
|
611
|
+
revision_count: z9.number().int().min(0)
|
|
511
612
|
}),
|
|
613
|
+
/** Persona penanggung jawab task (atau persona agen): ikuti aturan dan batas wilayahnya. */
|
|
614
|
+
persona: PersonaSchema.optional(),
|
|
512
615
|
lease_expires_at: IsoDateTimeSchema,
|
|
513
|
-
|
|
616
|
+
lease_id: IdSchema.optional(),
|
|
617
|
+
dependencies: z9.array(DependencyHandoffSchema),
|
|
514
618
|
/** Diisi bila task diambil dari REVISION_REQUESTED. */
|
|
515
|
-
revision:
|
|
516
|
-
review_feedback:
|
|
619
|
+
revision: z9.object({
|
|
620
|
+
review_feedback: z9.string(),
|
|
517
621
|
previous_handoff: HandoffSummarySchema.nullable()
|
|
518
622
|
}).optional(),
|
|
519
623
|
/** Peringatan bila branch lokal berbeda dari git_branch handoff dependensi. */
|
|
520
|
-
warnings:
|
|
624
|
+
warnings: z9.array(z9.string()).default([])
|
|
521
625
|
});
|
|
522
|
-
var CompleteHandoffInput =
|
|
626
|
+
var CompleteHandoffInput = z9.object({
|
|
627
|
+
lease_id: IdSchema.optional(),
|
|
523
628
|
task_id: IdSchema,
|
|
524
629
|
handoff_summary: HandoffSummarySchema
|
|
525
630
|
});
|
|
526
|
-
var CompleteHandoffOutput =
|
|
631
|
+
var CompleteHandoffOutput = z9.object({
|
|
527
632
|
task_id: IdSchema,
|
|
528
|
-
status:
|
|
529
|
-
unlocked_task_ids:
|
|
633
|
+
status: z9.enum(["DONE", "NEEDS_REVIEW"]),
|
|
634
|
+
unlocked_task_ids: z9.array(IdSchema),
|
|
530
635
|
/** Mis. saran mereset sesi chat (1 Task = 1 Fresh Session). */
|
|
531
|
-
next_step_hint:
|
|
636
|
+
next_step_hint: z9.string()
|
|
532
637
|
});
|
|
533
|
-
var ReportBlockerInput =
|
|
638
|
+
var ReportBlockerInput = z9.object({
|
|
639
|
+
lease_id: IdSchema.optional(),
|
|
534
640
|
task_id: IdSchema,
|
|
535
641
|
category: BlockerCategorySchema,
|
|
536
|
-
reason:
|
|
642
|
+
reason: z9.string().min(10).max(1e3)
|
|
537
643
|
});
|
|
538
|
-
var ReportBlockerOutput =
|
|
644
|
+
var ReportBlockerOutput = z9.object({
|
|
539
645
|
task_id: IdSchema,
|
|
540
|
-
status:
|
|
646
|
+
status: z9.literal("BLOCKED")
|
|
541
647
|
});
|
|
542
648
|
var MAX_TASKS_PER_PLAN = 30;
|
|
543
|
-
var PlanRefSchema =
|
|
544
|
-
var PlannedTaskSchema =
|
|
649
|
+
var PlanRefSchema = z9.string().min(1).max(40).regex(/^[a-z0-9][a-z0-9_-]*$/, "ref harus huruf kecil, angka, '-' atau '_'");
|
|
650
|
+
var PlannedTaskSchema = z9.object({
|
|
545
651
|
ref: PlanRefSchema,
|
|
546
|
-
title:
|
|
547
|
-
prompt_instruction:
|
|
652
|
+
title: z9.string().min(1).max(200),
|
|
653
|
+
prompt_instruction: z9.string().min(1).max(8e3),
|
|
548
654
|
/** Berisi ref task lain dalam rencana ini, atau UUID task yang sudah ada. */
|
|
549
|
-
depends_on:
|
|
655
|
+
depends_on: z9.array(z9.union([PlanRefSchema, IdSchema])).max(10).default([]),
|
|
550
656
|
target_repo: RepoNameSchema.optional(),
|
|
551
657
|
role: RoleSchema.optional(),
|
|
552
|
-
|
|
658
|
+
/** Alias persona penanggung jawab (lihat list_personas). Role task mengikuti persona ini. */
|
|
659
|
+
persona: AgentAliasSchema.optional(),
|
|
660
|
+
requires_approval: z9.boolean().default(false)
|
|
553
661
|
});
|
|
554
|
-
var CreateTasksInput =
|
|
662
|
+
var CreateTasksInput = z9.object({
|
|
555
663
|
epic_id: IdSchema,
|
|
556
|
-
tasks:
|
|
664
|
+
tasks: z9.array(PlannedTaskSchema).min(1).max(MAX_TASKS_PER_PLAN)
|
|
557
665
|
}).superRefine((plan, ctx) => {
|
|
558
666
|
const refs = /* @__PURE__ */ new Set();
|
|
559
667
|
plan.tasks.forEach((t, i) => {
|
|
@@ -596,82 +704,94 @@ var CreateTasksInput = z8.object({
|
|
|
596
704
|
});
|
|
597
705
|
}
|
|
598
706
|
});
|
|
599
|
-
var CreateTasksOutput =
|
|
600
|
-
created:
|
|
601
|
-
|
|
602
|
-
ref:
|
|
707
|
+
var CreateTasksOutput = z9.object({
|
|
708
|
+
created: z9.array(
|
|
709
|
+
z9.object({
|
|
710
|
+
ref: z9.string(),
|
|
603
711
|
task_id: IdSchema,
|
|
604
712
|
status: TaskStatusSchema
|
|
605
713
|
})
|
|
606
714
|
)
|
|
607
715
|
});
|
|
608
|
-
var LoadSkillInput =
|
|
609
|
-
name: SkillNameSchema
|
|
716
|
+
var LoadSkillInput = z9.object({
|
|
717
|
+
name: SkillNameSchema,
|
|
718
|
+
revision: CommitShaSchema.optional()
|
|
610
719
|
});
|
|
611
|
-
var LoadSkillOutput =
|
|
720
|
+
var LoadSkillOutput = z9.object({
|
|
612
721
|
name: SkillNameSchema,
|
|
613
|
-
|
|
614
|
-
|
|
722
|
+
revision: CommitShaSchema.optional(),
|
|
723
|
+
when_to_use: z9.string(),
|
|
724
|
+
content: z9.string()
|
|
615
725
|
});
|
|
616
|
-
var SaveRepoSkillInput =
|
|
726
|
+
var SaveRepoSkillInput = z9.object({
|
|
617
727
|
name: SkillNameSchema,
|
|
618
|
-
when_to_use:
|
|
728
|
+
when_to_use: z9.string().min(1).max(SKILL_LIMITS.maxWhenToUseLength),
|
|
619
729
|
content: SkillContentSchema
|
|
620
730
|
});
|
|
621
|
-
var SaveRepoSkillOutput =
|
|
622
|
-
path:
|
|
623
|
-
created:
|
|
731
|
+
var SaveRepoSkillOutput = z9.object({
|
|
732
|
+
path: z9.string(),
|
|
733
|
+
created: z9.boolean()
|
|
624
734
|
});
|
|
625
|
-
var EpicSummarySchema =
|
|
735
|
+
var EpicSummarySchema = z9.object({
|
|
626
736
|
id: IdSchema,
|
|
627
|
-
title:
|
|
628
|
-
description:
|
|
737
|
+
title: z9.string(),
|
|
738
|
+
description: z9.string().nullable(),
|
|
629
739
|
/** Jumlah task per status, mis. { DRAFT: 3, TODO: 1 }. */
|
|
630
|
-
task_counts:
|
|
740
|
+
task_counts: z9.record(z9.string(), z9.number().int().min(0))
|
|
631
741
|
});
|
|
632
|
-
var ListEpicsInput =
|
|
633
|
-
var ListEpicsOutput =
|
|
634
|
-
epics:
|
|
742
|
+
var ListEpicsInput = z9.object({});
|
|
743
|
+
var ListEpicsOutput = z9.object({
|
|
744
|
+
epics: z9.array(EpicSummarySchema)
|
|
635
745
|
});
|
|
636
|
-
var CreateEpicToolInput =
|
|
637
|
-
title:
|
|
638
|
-
description:
|
|
746
|
+
var CreateEpicToolInput = z9.object({
|
|
747
|
+
title: z9.string().trim().min(1).max(200),
|
|
748
|
+
description: z9.string().max(4e3).optional()
|
|
639
749
|
});
|
|
640
|
-
var CreateEpicToolOutput =
|
|
750
|
+
var CreateEpicToolOutput = z9.object({
|
|
641
751
|
epic: EpicSummarySchema
|
|
642
752
|
});
|
|
643
|
-
var ListPersonasInput =
|
|
644
|
-
var ListPersonasOutput =
|
|
645
|
-
personas:
|
|
753
|
+
var ListPersonasInput = z9.object({});
|
|
754
|
+
var ListPersonasOutput = z9.object({
|
|
755
|
+
personas: z9.array(
|
|
646
756
|
PersonaSchema.extend({
|
|
647
757
|
/** "project" = khusus proyek ini (bisa diubah agen); "workspace" = global, hanya dari Web. */
|
|
648
|
-
scope:
|
|
758
|
+
scope: z9.enum(["project", "workspace"])
|
|
649
759
|
})
|
|
650
760
|
)
|
|
651
761
|
});
|
|
652
762
|
var UpsertPersonaInput = PersonaSchema.extend({
|
|
653
|
-
rules:
|
|
763
|
+
rules: z9.array(z9.string().trim().min(1).max(300)).max(30).default([])
|
|
654
764
|
});
|
|
655
|
-
var UpsertPersonaOutput =
|
|
765
|
+
var UpsertPersonaOutput = z9.object({
|
|
656
766
|
persona: PersonaSchema,
|
|
657
|
-
created:
|
|
767
|
+
created: z9.boolean()
|
|
658
768
|
});
|
|
659
769
|
function tool(description, input, output) {
|
|
660
770
|
return { description, input, output };
|
|
661
771
|
}
|
|
662
772
|
var MCP_TOOLS = {
|
|
773
|
+
release_task: tool(
|
|
774
|
+
"Lepas lease task supaya sesi lain bisa mengambilnya.",
|
|
775
|
+
ReleaseTaskInput,
|
|
776
|
+
z9.object({ task_id: IdSchema, status: z9.enum(["TODO", "REVISION_REQUESTED"]) })
|
|
777
|
+
),
|
|
778
|
+
review_pull_request: tool(
|
|
779
|
+
"Antrean, claim, hasil review, atau cek merge pull request.",
|
|
780
|
+
z9.object({ request: ReviewInput }),
|
|
781
|
+
ReviewOutput
|
|
782
|
+
),
|
|
663
783
|
get_project_context: tool(
|
|
664
784
|
"Baca konteks proyek: identitas repo, aturan persona, indeks skill, dan handoff dependensi langsung.",
|
|
665
785
|
GetProjectContextInput,
|
|
666
786
|
GetProjectContextOutput
|
|
667
787
|
),
|
|
668
788
|
get_ready_tasks: tool(
|
|
669
|
-
"Daftar ringkas task siap dikerjakan untuk repo ini (semua dependensi DONE).",
|
|
789
|
+
"Daftar ringkas task siap dikerjakan untuk repo ini (semua dependensi DONE). Dengan agent_alias, hanya task milik persona itu (dan task tanpa penanggung jawab yang role-nya cocok).",
|
|
670
790
|
GetReadyTasksInput,
|
|
671
791
|
GetReadyTasksOutput
|
|
672
792
|
),
|
|
673
793
|
claim_task: tool(
|
|
674
|
-
"Kunci task (lease 30 menit) dan ambil instruksi lengkap
|
|
794
|
+
"Kunci task (lease 30 menit) dan ambil instruksi lengkap, handoff dependensi, serta aturan persona penanggung jawabnya. Kirim agent_alias bila bekerja sebagai persona tertentu.",
|
|
675
795
|
ClaimTaskInput,
|
|
676
796
|
ClaimTaskOutput
|
|
677
797
|
),
|
|
@@ -724,9 +844,9 @@ var MCP_TOOLS = {
|
|
|
724
844
|
var MCP_TOOL_NAMES = Object.keys(MCP_TOOLS);
|
|
725
845
|
|
|
726
846
|
// shared/src/quota.ts
|
|
727
|
-
import { z as
|
|
847
|
+
import { z as z10 } from "zod";
|
|
728
848
|
var PLANS = ["free", "pro", "team"];
|
|
729
|
-
var PlanSchema =
|
|
849
|
+
var PlanSchema = z10.enum(PLANS);
|
|
730
850
|
var QUOTA_DIMENSIONS = [
|
|
731
851
|
/** Jumlah proyek di workspace. */
|
|
732
852
|
"projects",
|
|
@@ -743,36 +863,36 @@ var QUOTA_DIMENSIONS = [
|
|
|
743
863
|
/** Indeks skill per repo yang disinkronkan ke Cloud. */
|
|
744
864
|
"skills"
|
|
745
865
|
];
|
|
746
|
-
var QuotaDimensionSchema =
|
|
866
|
+
var QuotaDimensionSchema = z10.enum(QUOTA_DIMENSIONS);
|
|
747
867
|
var QUOTA_WARNING_HEADER = "x-catenext-quota-warning";
|
|
748
|
-
var QuotaExceededDetailsSchema =
|
|
868
|
+
var QuotaExceededDetailsSchema = z10.object({
|
|
749
869
|
dimension: QuotaDimensionSchema,
|
|
750
870
|
plan: PlanSchema,
|
|
751
|
-
limit:
|
|
752
|
-
used:
|
|
871
|
+
limit: z10.number().int(),
|
|
872
|
+
used: z10.number().int(),
|
|
753
873
|
/** Kapan kuota bulanan direset; null untuk kuota jumlah (proyek, persona, ...). */
|
|
754
874
|
reset_at: IsoDateTimeSchema.nullable(),
|
|
755
|
-
upgrade_url:
|
|
875
|
+
upgrade_url: z10.string()
|
|
756
876
|
});
|
|
757
|
-
var UsageItemSchema =
|
|
877
|
+
var UsageItemSchema = z10.object({
|
|
758
878
|
dimension: QuotaDimensionSchema,
|
|
759
|
-
label:
|
|
760
|
-
used:
|
|
761
|
-
limit:
|
|
879
|
+
label: z10.string(),
|
|
880
|
+
used: z10.number().int().min(0),
|
|
881
|
+
limit: z10.number().int().nullable()
|
|
762
882
|
});
|
|
763
|
-
var UsageOutput =
|
|
883
|
+
var UsageOutput = z10.object({
|
|
764
884
|
plan: PlanSchema,
|
|
765
|
-
plans:
|
|
766
|
-
|
|
885
|
+
plans: z10.array(
|
|
886
|
+
z10.object({
|
|
767
887
|
plan: PlanSchema,
|
|
768
|
-
available:
|
|
769
|
-
limits:
|
|
888
|
+
available: z10.boolean(),
|
|
889
|
+
limits: z10.record(z10.string(), z10.number().nullable())
|
|
770
890
|
})
|
|
771
891
|
),
|
|
772
892
|
period_start: IsoDateTimeSchema,
|
|
773
893
|
reset_at: IsoDateTimeSchema,
|
|
774
|
-
retention_days:
|
|
775
|
-
usage:
|
|
894
|
+
retention_days: z10.number().int().nullable(),
|
|
895
|
+
usage: z10.array(UsageItemSchema)
|
|
776
896
|
});
|
|
777
897
|
|
|
778
898
|
// src/index.ts
|
|
@@ -935,7 +1055,7 @@ async function findProjectRoot(start = process.cwd()) {
|
|
|
935
1055
|
import { chmod, mkdir, readFile as readFile2, rename, writeFile } from "node:fs/promises";
|
|
936
1056
|
import { homedir } from "node:os";
|
|
937
1057
|
import { join as join2 } from "node:path";
|
|
938
|
-
import { z as
|
|
1058
|
+
import { z as z11 } from "zod";
|
|
939
1059
|
function catenextHome() {
|
|
940
1060
|
return process.env.CATENEXT_HOME ?? join2(homedir(), ".catenext");
|
|
941
1061
|
}
|
|
@@ -944,10 +1064,10 @@ function credentialsPath() {
|
|
|
944
1064
|
}
|
|
945
1065
|
var PRODUCTION_API_URL = "https://catenext.mapan.digital";
|
|
946
1066
|
var DEFAULT_API_URL = PRODUCTION_API_URL;
|
|
947
|
-
var CredentialsSchema =
|
|
948
|
-
api_key:
|
|
949
|
-
api_url:
|
|
950
|
-
saved_at:
|
|
1067
|
+
var CredentialsSchema = z11.object({
|
|
1068
|
+
api_key: z11.string().startsWith(API_KEY_PREFIX),
|
|
1069
|
+
api_url: z11.url().optional(),
|
|
1070
|
+
saved_at: z11.string().optional()
|
|
951
1071
|
});
|
|
952
1072
|
var CredentialsError = class extends Error {
|
|
953
1073
|
constructor(message) {
|
|
@@ -1125,6 +1245,7 @@ async function deviceLogin(opts) {
|
|
|
1125
1245
|
|
|
1126
1246
|
// src/fallback.ts
|
|
1127
1247
|
import { execFile } from "node:child_process";
|
|
1248
|
+
import { randomUUID } from "node:crypto";
|
|
1128
1249
|
import { promisify } from "node:util";
|
|
1129
1250
|
|
|
1130
1251
|
// src/planning.ts
|
|
@@ -1339,7 +1460,9 @@ async function readGitState(cwd = process.cwd()) {
|
|
|
1339
1460
|
}
|
|
1340
1461
|
async function taskNext(api, opts) {
|
|
1341
1462
|
const res = await api.post("ready-tasks", {
|
|
1342
|
-
limit: opts.limit ?? 10
|
|
1463
|
+
limit: opts.limit ?? 10,
|
|
1464
|
+
...opts.lease ? { lease_id: opts.lease } : {},
|
|
1465
|
+
...opts.as ? { agent_alias: opts.as } : {}
|
|
1343
1466
|
});
|
|
1344
1467
|
if (opts.json) return console.log(JSON.stringify(res, null, 2));
|
|
1345
1468
|
if (res.tasks.length === 0) {
|
|
@@ -1348,20 +1471,30 @@ async function taskNext(api, opts) {
|
|
|
1348
1471
|
);
|
|
1349
1472
|
}
|
|
1350
1473
|
for (const t of res.tasks) {
|
|
1351
|
-
const tags = [t.role, t.revision ? "revisi" : null].filter(Boolean).join(", ");
|
|
1474
|
+
const tags = [t.persona ? `@${t.persona}` : null, t.role, t.revision ? "revisi" : null].filter(Boolean).join(", ");
|
|
1352
1475
|
console.log(`${t.id} ${t.title}${tags ? ` [${tags}]` : ""}`);
|
|
1353
1476
|
}
|
|
1354
|
-
console.log(
|
|
1355
|
-
|
|
1477
|
+
console.log(
|
|
1478
|
+
`
|
|
1479
|
+
Ambil satu: catenext claim ${res.tasks[0]?.id}${opts.as ? ` --as ${opts.as}` : ""}`
|
|
1480
|
+
);
|
|
1356
1481
|
}
|
|
1357
1482
|
function renderClaim(res) {
|
|
1358
1483
|
const out = [];
|
|
1359
1484
|
out.push(`# Task: ${res.task.title}`, "");
|
|
1360
1485
|
out.push(`- ID: ${res.task.id}`);
|
|
1361
1486
|
out.push(`- Lease sampai: ${res.lease_expires_at} (diperpanjang setiap perintah catenext)`);
|
|
1487
|
+
if (res.lease_id)
|
|
1488
|
+
out.push(`- Gunakan --lease ${res.lease_id} saat memperbarui atau menyerahkan task.`);
|
|
1362
1489
|
if (res.task.role) out.push(`- Role: ${res.task.role}`);
|
|
1363
1490
|
if (res.task.revision_count > 0) out.push(`- Revisi ke-${res.task.revision_count}`);
|
|
1364
1491
|
out.push("", "## Instruksi", "", res.task.prompt_instruction.trim(), "");
|
|
1492
|
+
if (res.persona) {
|
|
1493
|
+
out.push(`## Persona: ${res.persona.alias} (${res.persona.role})`, "");
|
|
1494
|
+
out.push("Patuhi aturan dan batas wilayah berikut:", "");
|
|
1495
|
+
for (const r of res.persona.rules) out.push(`- ${r}`);
|
|
1496
|
+
out.push("");
|
|
1497
|
+
}
|
|
1365
1498
|
if (res.revision) {
|
|
1366
1499
|
out.push("## Feedback revisi dari reviewer", "", res.revision.review_feedback.trim(), "");
|
|
1367
1500
|
}
|
|
@@ -1371,6 +1504,9 @@ function renderClaim(res) {
|
|
|
1371
1504
|
const h = d.handoff_summary;
|
|
1372
1505
|
out.push(`### ${d.title}`, "");
|
|
1373
1506
|
out.push(`- Branch/commit: ${h.git_branch} @ ${h.last_commit_hash}`);
|
|
1507
|
+
if (d.integrated_commit) {
|
|
1508
|
+
out.push(`- Terintegrasi: ${d.integrated_commit.branch} @ ${d.integrated_commit.sha}`);
|
|
1509
|
+
}
|
|
1374
1510
|
if (h.files_modified.length) out.push(`- File: ${h.files_modified.join(", ")}`);
|
|
1375
1511
|
for (const k of h.key_decisions) out.push(`- Keputusan: ${k}`);
|
|
1376
1512
|
if (h.verification_command) out.push(`- Verifikasi: \`${h.verification_command}\``);
|
|
@@ -1387,7 +1523,19 @@ function renderClaim(res) {
|
|
|
1387
1523
|
return out.join("\n");
|
|
1388
1524
|
}
|
|
1389
1525
|
async function taskClaim(api, taskId, opts) {
|
|
1390
|
-
const
|
|
1526
|
+
const branch = opts.worktree ? await git(["symbolic-ref", "--short", "HEAD"], process.cwd()) : null;
|
|
1527
|
+
if (opts.worktree && !branch)
|
|
1528
|
+
throw new PlanningInputError("Checkout branch kerja sebelum memakai --worktree.");
|
|
1529
|
+
const payload = prepare(
|
|
1530
|
+
ClaimTaskInput,
|
|
1531
|
+
{
|
|
1532
|
+
task_id: taskId,
|
|
1533
|
+
...opts.as ? { agent_alias: opts.as } : {},
|
|
1534
|
+
...branch ? { worktree: { branch, session_id: randomUUID() } } : {}
|
|
1535
|
+
},
|
|
1536
|
+
["task_id", "session_id"]
|
|
1537
|
+
);
|
|
1538
|
+
const res = await api.post("claim", payload);
|
|
1391
1539
|
if (opts.json) return console.log(JSON.stringify(res, null, 2));
|
|
1392
1540
|
console.log(renderClaim(res));
|
|
1393
1541
|
}
|
|
@@ -1402,6 +1550,8 @@ function buildHandoff(opts, gitState) {
|
|
|
1402
1550
|
"Tidak bisa membaca branch/commit git. Jalankan di dalam repo git dan commit pekerjaan Anda dulu."
|
|
1403
1551
|
);
|
|
1404
1552
|
}
|
|
1553
|
+
if (Boolean(opts.pr) !== Boolean(opts.base))
|
|
1554
|
+
throw new PlanningInputError("Gunakan --pr dan --base bersama.");
|
|
1405
1555
|
const files = opts.file.length ? opts.file : gitState.changedFiles;
|
|
1406
1556
|
return {
|
|
1407
1557
|
files_modified: files.slice(0, HANDOFF_LIMITS.maxFilesModified),
|
|
@@ -1409,32 +1559,55 @@ function buildHandoff(opts, gitState) {
|
|
|
1409
1559
|
verification_command: opts.verify ?? null,
|
|
1410
1560
|
notes_for_next_agent: opts.notes,
|
|
1411
1561
|
git_branch: gitState.branch,
|
|
1412
|
-
last_commit_hash: gitState.commit
|
|
1562
|
+
last_commit_hash: gitState.commit,
|
|
1563
|
+
...opts.pr && opts.base ? { pull_request: { url: opts.pr, base_branch: opts.base, head_sha: gitState.commit } } : {}
|
|
1413
1564
|
};
|
|
1414
1565
|
}
|
|
1415
1566
|
async function taskDone(api, taskId, opts) {
|
|
1416
1567
|
const summary = opts.handoff ? await readJsonInput(opts.handoff) : buildHandoff(opts, await readGitState());
|
|
1417
|
-
const body = prepare(
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1568
|
+
const body = prepare(
|
|
1569
|
+
CompleteHandoffInput,
|
|
1570
|
+
{ task_id: taskId, handoff_summary: summary, lease_id: opts.lease },
|
|
1571
|
+
["task_id", "last_commit_hash", "head_sha", "lease_id"]
|
|
1572
|
+
);
|
|
1421
1573
|
const res = await api.post("complete", body);
|
|
1422
1574
|
if (opts.json) return console.log(JSON.stringify(res, null, 2));
|
|
1423
1575
|
console.log(
|
|
1424
|
-
res.status === "DONE" ? `\u2713 Task selesai (DONE). ${res.unlocked_task_ids.length} task hilir terbuka.` : "\u2713 Handoff terkirim, menunggu review
|
|
1576
|
+
res.status === "DONE" ? `\u2713 Task selesai (DONE). ${res.unlocked_task_ids.length} task hilir terbuka.` : "\u2713 Handoff terkirim, menunggu review (NEEDS_REVIEW)."
|
|
1425
1577
|
);
|
|
1426
1578
|
console.log(` ${res.next_step_hint}`);
|
|
1427
1579
|
}
|
|
1428
1580
|
async function taskBlock(api, taskId, opts) {
|
|
1429
1581
|
const body = prepare(
|
|
1430
1582
|
ReportBlockerInput,
|
|
1431
|
-
{ task_id: taskId, category: opts.category, reason: opts.reason },
|
|
1432
|
-
["task_id", "category"]
|
|
1583
|
+
{ task_id: taskId, category: opts.category, reason: opts.reason, lease_id: opts.lease },
|
|
1584
|
+
["task_id", "category", "lease_id"]
|
|
1433
1585
|
);
|
|
1434
1586
|
const res = await api.post("blocker", body);
|
|
1435
1587
|
if (opts.json) return console.log(JSON.stringify(res, null, 2));
|
|
1436
1588
|
console.log("\u2713 Task ditandai BLOCKED dan lock dilepas. Manusia akan meninjau di Dashboard.");
|
|
1437
1589
|
}
|
|
1590
|
+
async function taskReview(api, input, json2) {
|
|
1591
|
+
const body = prepare(ReviewInput, input, ["task_id", "lease_id", "head_sha"]);
|
|
1592
|
+
const result = await api.post(
|
|
1593
|
+
body.action === "list" ? "review/list" : "review",
|
|
1594
|
+
body
|
|
1595
|
+
);
|
|
1596
|
+
if (json2) console.log(JSON.stringify(result, null, 2));
|
|
1597
|
+
else if ("reviews" in result) {
|
|
1598
|
+
if (!result.reviews.length) console.log("Belum ada PR yang bisa Anda review di repo ini.");
|
|
1599
|
+
for (const item of result.reviews)
|
|
1600
|
+
console.log(`${item.task_id} ${item.title} ${item.review.url}`);
|
|
1601
|
+
} else {
|
|
1602
|
+
console.log(`${result.title} ${result.status} \xB7 ${result.review.stage}`);
|
|
1603
|
+
console.log(`${result.review.url} @ ${result.review.head_sha}`);
|
|
1604
|
+
if (result.lease_id)
|
|
1605
|
+
console.log(`Lease review: ${result.lease_id} (sampai ${result.lease_expires_at})`);
|
|
1606
|
+
if (result.notes_for_next_agent) console.log(result.notes_for_next_agent);
|
|
1607
|
+
if (result.warning) console.error(result.warning);
|
|
1608
|
+
}
|
|
1609
|
+
if ("warning" in result && result.warning) process.exitCode = 1;
|
|
1610
|
+
}
|
|
1438
1611
|
|
|
1439
1612
|
// src/init/index.ts
|
|
1440
1613
|
import { mkdir as mkdir2, readFile as readFile5, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -1460,6 +1633,11 @@ function renderAgentsBlock() {
|
|
|
1460
1633
|
'4. `catenext done <task_id> --notes "<ringkasan>" --verify "<perintah tes>" [--decision "..."]`',
|
|
1461
1634
|
'5. Bila buntu: `catenext block <task_id> --category <missing_env|ambiguous_requirement|failing_tests|dependency_issue|other> --reason "..."`',
|
|
1462
1635
|
"",
|
|
1636
|
+
"Persona: tiap task bisa punya persona penanggung jawab (mis. `adel`). Bila diminta",
|
|
1637
|
+
'"adel, kerjakan", pakai `catenext next --as adel` lalu `catenext claim <task_id> --as adel`',
|
|
1638
|
+
"(dengan MCP: kirim `agent_alias` ke get_ready_tasks dan claim_task), dan patuhi aturannya.",
|
|
1639
|
+
"Di Claude Code, `catenext sync` membuat subagent per persona di `.claude/agents/`.",
|
|
1640
|
+
"",
|
|
1463
1641
|
"Aturan: satu task per sesi; jangan menyalin kode atau secret ke handoff (rujuk path file);",
|
|
1464
1642
|
"jangan mengedit `.catenext/config.yaml`. Skill repo ada di `.catenext/skills/`.",
|
|
1465
1643
|
BLOCK_END
|
|
@@ -1733,21 +1911,61 @@ async function applyInit(root, changes) {
|
|
|
1733
1911
|
|
|
1734
1912
|
// src/maintenance.ts
|
|
1735
1913
|
import { existsSync } from "node:fs";
|
|
1736
|
-
import { copyFile, mkdir as mkdir4, readFile as
|
|
1737
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
1914
|
+
import { copyFile, mkdir as mkdir4, readFile as readFile8, rename as rename4, rm, rmdir, writeFile as writeFile4 } from "node:fs/promises";
|
|
1915
|
+
import { dirname as dirname3, isAbsolute, join as join8, resolve as resolve3 } from "node:path";
|
|
1738
1916
|
import { applyEdits as applyEdits2, modify as modify2, parse as parse4, visit } from "jsonc-parser";
|
|
1739
1917
|
|
|
1918
|
+
// src/node-command.ts
|
|
1919
|
+
import { accessSync, constants, realpathSync } from "node:fs";
|
|
1920
|
+
import { delimiter, join as join5 } from "node:path";
|
|
1921
|
+
function stableNodeCommand(execPath, pathEnv, resolveReal = realpathSync, isExecutable = defaultIsExecutable) {
|
|
1922
|
+
const target = safeReal(execPath, resolveReal);
|
|
1923
|
+
for (const dir of (pathEnv ?? "").split(delimiter)) {
|
|
1924
|
+
if (!dir) continue;
|
|
1925
|
+
for (const name of process.platform === "win32" ? ["node.exe", "node"] : ["node"]) {
|
|
1926
|
+
const candidate = join5(dir, name);
|
|
1927
|
+
if (!isExecutable(candidate)) continue;
|
|
1928
|
+
return safeReal(candidate, resolveReal) === target ? "node" : execPath;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
return execPath;
|
|
1932
|
+
}
|
|
1933
|
+
function hasVersionedSegment(path) {
|
|
1934
|
+
return /[\\/]v?\d+\.\d+\.\d+[\\/]/.test(path);
|
|
1935
|
+
}
|
|
1936
|
+
function safeReal(p, resolveReal) {
|
|
1937
|
+
try {
|
|
1938
|
+
return resolveReal(p);
|
|
1939
|
+
} catch {
|
|
1940
|
+
return p;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
function defaultIsExecutable(p) {
|
|
1944
|
+
try {
|
|
1945
|
+
accessSync(p, constants.X_OK);
|
|
1946
|
+
return true;
|
|
1947
|
+
} catch {
|
|
1948
|
+
return false;
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
function npxLaunch(entry) {
|
|
1952
|
+
return /[\\/]_npx[\\/]/.test(entry) ? { command: "npx", args: ["-y", "catenext"] } : null;
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1740
1955
|
// src/skills.ts
|
|
1956
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
1741
1957
|
import { mkdir as mkdir3, readdir, readFile as readFile6, rename as rename3, writeFile as writeFile3 } from "node:fs/promises";
|
|
1742
|
-
import { join as
|
|
1958
|
+
import { join as join6 } from "node:path";
|
|
1959
|
+
import { promisify as promisify2 } from "node:util";
|
|
1743
1960
|
import { parse as parse3, stringify } from "yaml";
|
|
1744
|
-
var SKILLS_DIR =
|
|
1961
|
+
var SKILLS_DIR = join6(".catenext", "skills");
|
|
1745
1962
|
var SkillError = class extends Error {
|
|
1746
1963
|
constructor(message) {
|
|
1747
1964
|
super(message);
|
|
1748
1965
|
this.name = "SkillError";
|
|
1749
1966
|
}
|
|
1750
1967
|
};
|
|
1968
|
+
var exec2 = promisify2(execFile2);
|
|
1751
1969
|
var FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
1752
1970
|
function parseSkill(source, fileName) {
|
|
1753
1971
|
const m = FRONTMATTER.exec(source);
|
|
@@ -1781,7 +1999,7 @@ ${skill.content.trim()}
|
|
|
1781
1999
|
async function listSkills(root) {
|
|
1782
2000
|
let files;
|
|
1783
2001
|
try {
|
|
1784
|
-
files = await readdir(
|
|
2002
|
+
files = await readdir(join6(root, SKILLS_DIR));
|
|
1785
2003
|
} catch {
|
|
1786
2004
|
return { skills: [], invalid: [] };
|
|
1787
2005
|
}
|
|
@@ -1789,7 +2007,7 @@ async function listSkills(root) {
|
|
|
1789
2007
|
const invalid = [];
|
|
1790
2008
|
for (const file of files.filter((f) => f.endsWith(".md")).sort()) {
|
|
1791
2009
|
try {
|
|
1792
|
-
const skill = parseSkill(await readFile6(
|
|
2010
|
+
const skill = parseSkill(await readFile6(join6(root, SKILLS_DIR, file), "utf8"), file);
|
|
1793
2011
|
if (`${skill.name}.md` !== file) {
|
|
1794
2012
|
throw new SkillError(`${file}: name "${skill.name}" harus sama dengan nama file.`);
|
|
1795
2013
|
}
|
|
@@ -1803,13 +2021,28 @@ async function listSkills(root) {
|
|
|
1803
2021
|
function skillIndex(skills) {
|
|
1804
2022
|
return skills.map((s) => ({ name: s.name, when_to_use: s.when_to_use }));
|
|
1805
2023
|
}
|
|
1806
|
-
async function loadSkill(root, name) {
|
|
2024
|
+
async function loadSkill(root, name, revision) {
|
|
1807
2025
|
const parsedName = SkillNameSchema.safeParse(name);
|
|
1808
2026
|
if (!parsedName.success) throw new SkillError(`Nama skill "${name}" tidak valid.`);
|
|
1809
2027
|
const file = `${parsedName.data}.md`;
|
|
2028
|
+
if (revision) {
|
|
2029
|
+
const sha = CommitShaSchema.safeParse(revision);
|
|
2030
|
+
if (!sha.success) throw new SkillError("Gunakan SHA commit Git lengkap untuk revisi skill.");
|
|
2031
|
+
let source2;
|
|
2032
|
+
try {
|
|
2033
|
+
source2 = (await exec2("git", ["show", `${sha.data}:${skillPath(parsedName.data)}`], { cwd: root })).stdout;
|
|
2034
|
+
} catch {
|
|
2035
|
+
throw new SkillError(
|
|
2036
|
+
`Skill "${name}" tidak tersedia pada ${sha.data}. Fetch commit itu lalu coba kembali.`
|
|
2037
|
+
);
|
|
2038
|
+
}
|
|
2039
|
+
const skill = parseSkill(source2, file);
|
|
2040
|
+
if (skill.name !== name) throw new SkillError(`${file}: name harus sama dengan nama file.`);
|
|
2041
|
+
return skill;
|
|
2042
|
+
}
|
|
1810
2043
|
let source;
|
|
1811
2044
|
try {
|
|
1812
|
-
source = await readFile6(
|
|
2045
|
+
source = await readFile6(join6(root, SKILLS_DIR, file), "utf8");
|
|
1813
2046
|
} catch {
|
|
1814
2047
|
const { skills } = await listSkills(root);
|
|
1815
2048
|
const names = skills.map((s) => s.name).join(", ") || "(belum ada)";
|
|
@@ -1824,9 +2057,9 @@ async function saveSkill(root, input, now = /* @__PURE__ */ new Date()) {
|
|
|
1824
2057
|
if (!when || when.length > SKILL_LIMITS.maxWhenToUseLength) {
|
|
1825
2058
|
throw new SkillError(`when_to_use wajib, maks ${SKILL_LIMITS.maxWhenToUseLength} karakter.`);
|
|
1826
2059
|
}
|
|
1827
|
-
const dir =
|
|
2060
|
+
const dir = join6(root, SKILLS_DIR);
|
|
1828
2061
|
await mkdir3(dir, { recursive: true });
|
|
1829
|
-
const target =
|
|
2062
|
+
const target = join6(dir, `${name}.md`);
|
|
1830
2063
|
let created = true;
|
|
1831
2064
|
try {
|
|
1832
2065
|
await readFile6(target);
|
|
@@ -1837,14 +2070,118 @@ async function saveSkill(root, input, now = /* @__PURE__ */ new Date()) {
|
|
|
1837
2070
|
const tmp = `${target}.${process.pid}.tmp`;
|
|
1838
2071
|
await writeFile3(tmp, renderSkill(skill), "utf8");
|
|
1839
2072
|
await rename3(tmp, target);
|
|
1840
|
-
return { path:
|
|
2073
|
+
return { path: join6(SKILLS_DIR, `${name}.md`), created, skill };
|
|
2074
|
+
}
|
|
2075
|
+
async function committedSkillIndex(root, previous) {
|
|
2076
|
+
const config = { cwd: root };
|
|
2077
|
+
const branchRef = (await exec2("git", ["symbolic-ref", "-q", "refs/remotes/origin/HEAD"], config).catch(() => null))?.stdout.trim();
|
|
2078
|
+
const branch = (await exec2("git", ["symbolic-ref", "-q", "HEAD"], config).catch(() => null))?.stdout.trim();
|
|
2079
|
+
if (!branchRef?.startsWith("refs/remotes/origin/") || branch !== `refs/heads/${branchRef.slice("refs/remotes/origin/".length)}`)
|
|
2080
|
+
return null;
|
|
2081
|
+
const revision = CommitShaSchema.parse(
|
|
2082
|
+
(await exec2("git", ["rev-parse", branchRef], config)).stdout.trim()
|
|
2083
|
+
);
|
|
2084
|
+
const head = (await exec2("git", ["rev-parse", "HEAD"], config)).stdout.trim();
|
|
2085
|
+
if (head !== revision) return null;
|
|
2086
|
+
if (previous && previous !== revision && !await exec2("git", ["merge-base", "--is-ancestor", previous, revision], config).catch(
|
|
2087
|
+
() => null
|
|
2088
|
+
)) {
|
|
2089
|
+
throw new SkillError(
|
|
2090
|
+
"Revisi Git lokal tertinggal dari indeks Cloud. Fetch branch utama lalu coba lagi."
|
|
2091
|
+
);
|
|
2092
|
+
}
|
|
2093
|
+
const names = (await exec2("git", ["ls-tree", "-rz", "--name-only", revision, "--", SKILLS_DIR], config)).stdout.split("\0").flatMap((path) => {
|
|
2094
|
+
const file = /^\.catenext\/skills\/([^/]+)\.md$/.exec(path);
|
|
2095
|
+
return file?.[1] ? [file[1]] : [];
|
|
2096
|
+
});
|
|
2097
|
+
const skills = [];
|
|
2098
|
+
const invalid = [];
|
|
2099
|
+
for (const name of names) {
|
|
2100
|
+
try {
|
|
2101
|
+
skills.push(await loadSkill(root, name, revision));
|
|
2102
|
+
} catch (err) {
|
|
2103
|
+
invalid.push({ file: `${name}.md`, error: err.message });
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
return { revision, skills: skillIndex(skills), invalid };
|
|
1841
2107
|
}
|
|
1842
2108
|
|
|
1843
|
-
// src/
|
|
2109
|
+
// src/subagents.ts
|
|
2110
|
+
import { readdir as readdir2, readFile as readFile7 } from "node:fs/promises";
|
|
2111
|
+
import { join as join7 } from "node:path";
|
|
2112
|
+
var SUBAGENTS_DIR = join7(".claude", "agents");
|
|
2113
|
+
var SUBAGENT_MARKER = "<!-- catenext:persona -->";
|
|
2114
|
+
function renderSubagent(p) {
|
|
2115
|
+
const rules = p.rules.length > 0 ? p.rules.map((r) => `- ${r}`) : ["- (belum ada aturan)"];
|
|
2116
|
+
const alias = JSON.stringify(p.alias);
|
|
2117
|
+
return [
|
|
2118
|
+
"---",
|
|
2119
|
+
`name: ${p.alias}`,
|
|
2120
|
+
`description: Persona Catenext "${p.alias}" (role ${p.role}). Pakai saat diminta "${p.alias}, kerjakan" atau untuk task Catenext milik ${p.alias}. Mengerjakan satu task lalu melapor.`,
|
|
2121
|
+
"---",
|
|
2122
|
+
SUBAGENT_MARKER,
|
|
2123
|
+
`<!-- Dibuat oleh \`catenext sync\` dari persona di Cloud; ubah persona di Dashboard, bukan file ini. -->`,
|
|
2124
|
+
"",
|
|
2125
|
+
`Anda adalah persona Catenext **${p.alias}** (role: ${p.role}).`,
|
|
2126
|
+
"",
|
|
2127
|
+
"## Alur kerja (satu task per pemanggilan)",
|
|
2128
|
+
"",
|
|
2129
|
+
`1. \`get_project_context\` dengan \`agent_alias: ${alias}\`.`,
|
|
2130
|
+
`2. \`get_ready_tasks\` dengan \`agent_alias: ${alias}\`; pilih task teratas. Bila kosong, laporkan "tidak ada task untuk ${p.alias}" lalu berhenti.`,
|
|
2131
|
+
`3. \`claim_task\` dengan \`task_id\` dan \`agent_alias: ${alias}\`. Patuhi field \`persona\` di hasilnya.`,
|
|
2132
|
+
"4. Kerjakan, jalankan tes, commit di branch kerja.",
|
|
2133
|
+
"5. `complete_handoff` dengan ringkasan terstruktur, atau `report_blocker` bila buntu.",
|
|
2134
|
+
"6. Laporkan ke pemanggil: task apa yang selesai, status, dan perintah verifikasinya.",
|
|
2135
|
+
"",
|
|
2136
|
+
`Tanpa tool MCP: \`catenext next --as ${p.alias}\`, \`catenext claim <id> --as ${p.alias}\`, \`catenext done <id> ...\`.`,
|
|
2137
|
+
"",
|
|
2138
|
+
"## Aturan & batas wilayah",
|
|
2139
|
+
"",
|
|
2140
|
+
...rules,
|
|
2141
|
+
""
|
|
2142
|
+
].join("\n");
|
|
2143
|
+
}
|
|
1844
2144
|
var readOrNull2 = (p) => readFile7(p, "utf8").then(
|
|
1845
2145
|
(s) => s,
|
|
1846
2146
|
() => null
|
|
1847
2147
|
);
|
|
2148
|
+
async function planSubagents(root, personas) {
|
|
2149
|
+
const edits = [];
|
|
2150
|
+
const skipped = [];
|
|
2151
|
+
const wanted = /* @__PURE__ */ new Set();
|
|
2152
|
+
for (const p of personas) {
|
|
2153
|
+
const path = join7(SUBAGENTS_DIR, `${p.alias}.md`);
|
|
2154
|
+
wanted.add(path);
|
|
2155
|
+
const before = await readOrNull2(join7(root, path));
|
|
2156
|
+
if (before !== null && !before.includes(SUBAGENT_MARKER)) {
|
|
2157
|
+
skipped.push(path);
|
|
2158
|
+
continue;
|
|
2159
|
+
}
|
|
2160
|
+
const after = renderSubagent(p);
|
|
2161
|
+
if (after !== before) edits.push({ path, before, after });
|
|
2162
|
+
}
|
|
2163
|
+
for (const path of await catenextSubagentFiles(root)) {
|
|
2164
|
+
if (!wanted.has(path)) {
|
|
2165
|
+
edits.push({ path, before: await readOrNull2(join7(root, path)), after: null });
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
return { edits, skipped };
|
|
2169
|
+
}
|
|
2170
|
+
async function catenextSubagentFiles(root) {
|
|
2171
|
+
const names = await readdir2(join7(root, SUBAGENTS_DIR)).catch(() => []);
|
|
2172
|
+
const out = [];
|
|
2173
|
+
for (const n of names.filter((n2) => n2.endsWith(".md")).sort()) {
|
|
2174
|
+
const path = join7(SUBAGENTS_DIR, n);
|
|
2175
|
+
if ((await readOrNull2(join7(root, path)))?.includes(SUBAGENT_MARKER)) out.push(path);
|
|
2176
|
+
}
|
|
2177
|
+
return out;
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
// src/maintenance.ts
|
|
2181
|
+
var readOrNull3 = (p) => readFile8(p, "utf8").then(
|
|
2182
|
+
(s) => s,
|
|
2183
|
+
() => null
|
|
2184
|
+
);
|
|
1848
2185
|
function countEntries(source) {
|
|
1849
2186
|
let count = 0;
|
|
1850
2187
|
let depth = 0;
|
|
@@ -1888,7 +2225,8 @@ function isValidJsonObject(source) {
|
|
|
1888
2225
|
function entryIsStale(entry) {
|
|
1889
2226
|
if (isAbsolute(entry.command) && !existsSync(entry.command)) return true;
|
|
1890
2227
|
const script = entry.args[0];
|
|
1891
|
-
|
|
2228
|
+
if (!script || !isAbsolute(script) || !/\.[cm]?js$/.test(script)) return false;
|
|
2229
|
+
return !existsSync(script) || npxLaunch(script) !== null;
|
|
1892
2230
|
}
|
|
1893
2231
|
function baseCommand(entry, adapter) {
|
|
1894
2232
|
const suffix = ["mcp", ...adapter.extraArgs];
|
|
@@ -1901,7 +2239,7 @@ async function planSync(opts) {
|
|
|
1901
2239
|
const edits = [];
|
|
1902
2240
|
const findings = [];
|
|
1903
2241
|
for (const adapter of ADAPTERS) {
|
|
1904
|
-
const before = await
|
|
2242
|
+
const before = await readOrNull3(join8(root, adapter.path));
|
|
1905
2243
|
if (before !== null && before.trim() !== "" && !isValidJsonObject(before)) {
|
|
1906
2244
|
if (!opts.fix) {
|
|
1907
2245
|
findings.push({
|
|
@@ -1964,12 +2302,12 @@ async function planSync(opts) {
|
|
|
1964
2302
|
);
|
|
1965
2303
|
if (after !== before) edits.push({ path: adapter.path, before, after });
|
|
1966
2304
|
}
|
|
1967
|
-
const gitignore = await
|
|
2305
|
+
const gitignore = await readOrNull3(join8(root, ".gitignore"));
|
|
1968
2306
|
const gitignoreAfter = ensureGitignore(gitignore);
|
|
1969
2307
|
if (gitignoreAfter !== gitignore) {
|
|
1970
2308
|
edits.push({ path: ".gitignore", before: gitignore, after: gitignoreAfter });
|
|
1971
2309
|
}
|
|
1972
|
-
const agents = await
|
|
2310
|
+
const agents = await readOrNull3(join8(root, AGENTS_MD));
|
|
1973
2311
|
if (agents?.includes(BLOCK_START)) {
|
|
1974
2312
|
const after = upsertAgentsBlock(agents);
|
|
1975
2313
|
if (after !== agents) edits.push({ path: AGENTS_MD, before: agents, after });
|
|
@@ -1977,15 +2315,23 @@ async function planSync(opts) {
|
|
|
1977
2315
|
return { edits, findings };
|
|
1978
2316
|
}
|
|
1979
2317
|
async function syncSkills(root, api) {
|
|
1980
|
-
const {
|
|
1981
|
-
|
|
1982
|
-
return { count:
|
|
2318
|
+
const { revision: previous } = api ? await api.post("skills/ref") : { revision: null };
|
|
2319
|
+
const index = await committedSkillIndex(root, previous);
|
|
2320
|
+
if (!index) return { count: 0, invalid: [], skipped: true };
|
|
2321
|
+
if (api && previous !== index.revision) {
|
|
2322
|
+
await api.put("skills", {
|
|
2323
|
+
revision: index.revision,
|
|
2324
|
+
previous_revision: previous,
|
|
2325
|
+
skills: index.skills
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
return { count: index.skills.length, invalid: index.invalid, skipped: false };
|
|
1983
2329
|
}
|
|
1984
2330
|
async function planRemove(opts) {
|
|
1985
2331
|
const root = resolve3(opts.root);
|
|
1986
2332
|
const edits = [];
|
|
1987
2333
|
for (const adapter of ADAPTERS) {
|
|
1988
|
-
const before = await
|
|
2334
|
+
const before = await readOrNull3(join8(root, adapter.path));
|
|
1989
2335
|
if (before === null || countEntries(before) === 0) continue;
|
|
1990
2336
|
const stripped = removeMcpEntries(before);
|
|
1991
2337
|
const doc = parse4(stripped, [], { allowTrailingComma: true });
|
|
@@ -1993,7 +2339,7 @@ async function planRemove(opts) {
|
|
|
1993
2339
|
const emptyDoc = Object.keys(doc ?? {}).every((k) => k === "mcpServers") && Object.keys(servers ?? {}).length === 0 && !/\/\/|\/\*/.test(stripped);
|
|
1994
2340
|
edits.push({ path: adapter.path, before, after: emptyDoc ? null : stripped });
|
|
1995
2341
|
}
|
|
1996
|
-
const gitignore = await
|
|
2342
|
+
const gitignore = await readOrNull3(join8(root, ".gitignore"));
|
|
1997
2343
|
if (gitignore !== null) {
|
|
1998
2344
|
const eol = gitignore.includes("\r\n") ? "\r\n" : "\n";
|
|
1999
2345
|
const lines = gitignore.split(/\r?\n/);
|
|
@@ -2005,19 +2351,22 @@ async function planRemove(opts) {
|
|
|
2005
2351
|
edits.push({ path: ".gitignore", before: gitignore, after: text2 ? `${text2}${eol}` : null });
|
|
2006
2352
|
}
|
|
2007
2353
|
}
|
|
2008
|
-
const agents = await
|
|
2354
|
+
const agents = await readOrNull3(join8(root, AGENTS_MD));
|
|
2009
2355
|
if (agents?.includes(BLOCK_START)) {
|
|
2010
2356
|
edits.push({ path: AGENTS_MD, before: agents, after: removeAgentsBlock(agents) });
|
|
2011
2357
|
}
|
|
2012
|
-
for (const p of
|
|
2013
|
-
|
|
2358
|
+
for (const p of await catenextSubagentFiles(root)) {
|
|
2359
|
+
edits.push({ path: p, before: await readOrNull3(join8(root, p)), after: null });
|
|
2360
|
+
}
|
|
2361
|
+
for (const p of [CONFIG_PATH, join8(".catenext", "cache.json")]) {
|
|
2362
|
+
const before = await readOrNull3(join8(root, p));
|
|
2014
2363
|
if (before !== null) edits.push({ path: p, before, after: null });
|
|
2015
2364
|
}
|
|
2016
2365
|
if (opts.all) {
|
|
2017
2366
|
const { skills, invalid } = await listSkills(root);
|
|
2018
2367
|
for (const f of [...skills.map((s) => `${s.name}.md`), ...invalid.map((i) => i.file)]) {
|
|
2019
|
-
const p =
|
|
2020
|
-
edits.push({ path: p, before: await
|
|
2368
|
+
const p = join8(SKILLS_DIR, f);
|
|
2369
|
+
edits.push({ path: p, before: await readOrNull3(join8(root, p)), after: null });
|
|
2021
2370
|
}
|
|
2022
2371
|
}
|
|
2023
2372
|
return edits;
|
|
@@ -2025,7 +2374,7 @@ async function planRemove(opts) {
|
|
|
2025
2374
|
async function applyFileEdits(root, edits) {
|
|
2026
2375
|
const base = resolve3(root);
|
|
2027
2376
|
for (const e of edits) {
|
|
2028
|
-
const target =
|
|
2377
|
+
const target = join8(base, e.path);
|
|
2029
2378
|
if (e.after === null) {
|
|
2030
2379
|
await rm(target, { force: true });
|
|
2031
2380
|
continue;
|
|
@@ -2036,8 +2385,8 @@ async function applyFileEdits(root, edits) {
|
|
|
2036
2385
|
await writeFile4(tmp, e.after);
|
|
2037
2386
|
await rename4(tmp, target);
|
|
2038
2387
|
}
|
|
2039
|
-
for (const dir of [SKILLS_DIR, ".catenext", ".cursor"]) {
|
|
2040
|
-
await rmdir(
|
|
2388
|
+
for (const dir of [SKILLS_DIR, ".catenext", ".cursor", SUBAGENTS_DIR, ".claude"]) {
|
|
2389
|
+
await rmdir(join8(base, dir)).catch(() => {
|
|
2041
2390
|
});
|
|
2042
2391
|
}
|
|
2043
2392
|
}
|
|
@@ -2056,7 +2405,7 @@ var SERVER_INSTRUCTIONS = [
|
|
|
2056
2405
|
"Catenext mengatur estafet task antar-agen AI untuk repo ini.",
|
|
2057
2406
|
"Alur: get_project_context -> get_ready_tasks -> claim_task -> kerjakan & tes -> complete_handoff.",
|
|
2058
2407
|
"Merencanakan: list_epics/create_epic -> create_tasks (masuk DRAFT, disetujui manusia di Web sebelum bisa dikerjakan).",
|
|
2059
|
-
|
|
2408
|
+
'Persona: list_personas/upsert_persona untuk alias, role, dan aturan agen di proyek ini. Setiap task bisa punya persona penanggung jawab; bila diminta bekerja sebagai persona (mis. "adel, kerjakan"), kirim agent_alias-nya ke get_project_context, get_ready_tasks, dan claim_task, lalu patuhi aturan persona dari hasil claim_task.',
|
|
2060
2409
|
"Skill repo: indeksnya ada di get_project_context; panggil load_skill hanya bila relevan, dan save_repo_skill untuk mencatat konvensi/pitfall yang ditemukan (maks. 500 kata, tanpa code dump).",
|
|
2061
2410
|
"Bila buntu, panggil report_blocker. Jangan menyalin kode atau secret ke handoff; rujuk path file.",
|
|
2062
2411
|
"Jangan mengedit .catenext/config.yaml atau file konfigurasi MCP IDE."
|
|
@@ -2118,7 +2467,8 @@ function createCatenextMcpServer(opts) {
|
|
|
2118
2467
|
async ({ api, config }) => json(
|
|
2119
2468
|
await api.post("context", {
|
|
2120
2469
|
agent_alias: input.agent_alias ?? config.overrides?.default_agent_alias,
|
|
2121
|
-
role: input.role ?? config.overrides?.default_role
|
|
2470
|
+
role: input.role ?? config.overrides?.default_role,
|
|
2471
|
+
lease_id: input.lease_id
|
|
2122
2472
|
})
|
|
2123
2473
|
)
|
|
2124
2474
|
)
|
|
@@ -2134,7 +2484,8 @@ function createCatenextMcpServer(opts) {
|
|
|
2134
2484
|
await api.post("ready-tasks", {
|
|
2135
2485
|
agent_alias: input.agent_alias ?? config.overrides?.default_agent_alias,
|
|
2136
2486
|
role: input.role ?? config.overrides?.default_role,
|
|
2137
|
-
limit: input.limit
|
|
2487
|
+
limit: input.limit,
|
|
2488
|
+
lease_id: input.lease_id
|
|
2138
2489
|
})
|
|
2139
2490
|
)
|
|
2140
2491
|
)
|
|
@@ -2142,7 +2493,15 @@ function createCatenextMcpServer(opts) {
|
|
|
2142
2493
|
server.registerTool(
|
|
2143
2494
|
"claim_task",
|
|
2144
2495
|
{ description: MCP_TOOLS.claim_task.description, inputSchema: MCP_TOOLS.claim_task.input },
|
|
2145
|
-
(input) => call(
|
|
2496
|
+
(input) => call(
|
|
2497
|
+
async ({ api, config }) => json(
|
|
2498
|
+
await api.post("claim", {
|
|
2499
|
+
task_id: input.task_id,
|
|
2500
|
+
worktree: input.worktree,
|
|
2501
|
+
agent_alias: input.agent_alias ?? config.overrides?.default_agent_alias
|
|
2502
|
+
})
|
|
2503
|
+
)
|
|
2504
|
+
)
|
|
2146
2505
|
);
|
|
2147
2506
|
server.registerTool(
|
|
2148
2507
|
"complete_handoff",
|
|
@@ -2151,7 +2510,10 @@ function createCatenextMcpServer(opts) {
|
|
|
2151
2510
|
inputSchema: MCP_TOOLS.complete_handoff.input
|
|
2152
2511
|
},
|
|
2153
2512
|
(input) => call(async ({ api }) => {
|
|
2154
|
-
const scrubbed = scrubDeep(
|
|
2513
|
+
const scrubbed = scrubDeep(
|
|
2514
|
+
input,
|
|
2515
|
+
/* @__PURE__ */ new Set(["task_id", "last_commit_hash", "head_sha", "lease_id"])
|
|
2516
|
+
);
|
|
2155
2517
|
const parsed = CompleteHandoffInput.safeParse(scrubbed.value);
|
|
2156
2518
|
if (!parsed.success) {
|
|
2157
2519
|
return text(
|
|
@@ -2177,7 +2539,7 @@ Ringkas lalu panggil complete_handoff lagi.`,
|
|
|
2177
2539
|
inputSchema: MCP_TOOLS.report_blocker.input
|
|
2178
2540
|
},
|
|
2179
2541
|
(input) => call(async ({ api }) => {
|
|
2180
|
-
const scrubbed = scrubDeep(input, /* @__PURE__ */ new Set(["task_id", "category"]));
|
|
2542
|
+
const scrubbed = scrubDeep(input, /* @__PURE__ */ new Set(["task_id", "category", "lease_id"]));
|
|
2181
2543
|
const parsed = ReportBlockerInput.safeParse(scrubbed.value);
|
|
2182
2544
|
if (!parsed.success) {
|
|
2183
2545
|
return text(`Laporan blocker tidak valid:
|
|
@@ -2192,6 +2554,26 @@ ${zodIssues(parsed.error)}`, true);
|
|
|
2192
2554
|
return json(await api.post("blocker", parsed.data), notes);
|
|
2193
2555
|
})
|
|
2194
2556
|
);
|
|
2557
|
+
server.registerTool(
|
|
2558
|
+
"release_task",
|
|
2559
|
+
{ description: MCP_TOOLS.release_task.description, inputSchema: MCP_TOOLS.release_task.input },
|
|
2560
|
+
(input) => call(async ({ api }) => json(await api.post("release", input)))
|
|
2561
|
+
);
|
|
2562
|
+
server.registerTool(
|
|
2563
|
+
"review_pull_request",
|
|
2564
|
+
{
|
|
2565
|
+
description: MCP_TOOLS.review_pull_request.description,
|
|
2566
|
+
inputSchema: MCP_TOOLS.review_pull_request.input
|
|
2567
|
+
},
|
|
2568
|
+
({ request }) => call(async ({ api, config }) => {
|
|
2569
|
+
const scrubbed = scrubDeep(request, /* @__PURE__ */ new Set(["task_id", "head_sha", "lease_id"]));
|
|
2570
|
+
const input = ReviewInput.parse(scrubbed.value);
|
|
2571
|
+
if (input.action === "claim" && !input.agent_alias && config.overrides?.default_role === "reviewer") {
|
|
2572
|
+
input.agent_alias = config.overrides.default_agent_alias;
|
|
2573
|
+
}
|
|
2574
|
+
return json(await api.post(input.action === "list" ? "review/list" : "review", input));
|
|
2575
|
+
})
|
|
2576
|
+
);
|
|
2195
2577
|
const scrubbedWrite = (schema, keep, send) => (input) => call(async ({ api }) => {
|
|
2196
2578
|
const scrubbed = scrubDeep(input, new Set(keep));
|
|
2197
2579
|
const parsed = schema.safeParse(scrubbed.value);
|
|
@@ -2225,7 +2607,7 @@ ${zodIssues(parsed.error)}`, true);
|
|
|
2225
2607
|
},
|
|
2226
2608
|
scrubbedWrite(
|
|
2227
2609
|
CreateTasksInput,
|
|
2228
|
-
["epic_id", "ref", "depends_on", "target_repo", "role"],
|
|
2610
|
+
["epic_id", "ref", "depends_on", "target_repo", "role", "persona"],
|
|
2229
2611
|
(api, body) => api.post("tasks", body)
|
|
2230
2612
|
)
|
|
2231
2613
|
);
|
|
@@ -2249,17 +2631,22 @@ ${zodIssues(parsed.error)}`, true);
|
|
|
2249
2631
|
"load_skill",
|
|
2250
2632
|
{ description: MCP_TOOLS.load_skill.description, inputSchema: MCP_TOOLS.load_skill.input },
|
|
2251
2633
|
(input) => call(async ({ root }) => {
|
|
2252
|
-
const skill = await loadSkill(root, input.name);
|
|
2253
|
-
return json({
|
|
2634
|
+
const skill = await loadSkill(root, input.name, input.revision);
|
|
2635
|
+
return json({
|
|
2636
|
+
name: skill.name,
|
|
2637
|
+
when_to_use: skill.when_to_use,
|
|
2638
|
+
content: skill.content,
|
|
2639
|
+
...input.revision ? { revision: input.revision } : {}
|
|
2640
|
+
});
|
|
2254
2641
|
})
|
|
2255
2642
|
);
|
|
2256
2643
|
server.registerTool(
|
|
2257
2644
|
"save_repo_skill",
|
|
2258
2645
|
{
|
|
2259
|
-
description: `${MCP_TOOLS.save_repo_skill.description}
|
|
2646
|
+
description: `${MCP_TOOLS.save_repo_skill.description} File disimpan di checkout. Indeks Cloud diperbarui lewat sync dari branch utama.`,
|
|
2260
2647
|
inputSchema: MCP_TOOLS.save_repo_skill.input
|
|
2261
2648
|
},
|
|
2262
|
-
(input) => call(async ({
|
|
2649
|
+
(input) => call(async ({ root }) => {
|
|
2263
2650
|
const scrubbed = scrubDeep(input, /* @__PURE__ */ new Set(["name"]));
|
|
2264
2651
|
const parsed = SaveRepoSkillInput.safeParse(scrubbed.value);
|
|
2265
2652
|
if (!parsed.success) {
|
|
@@ -2277,14 +2664,7 @@ Ringkas (rujuk path file, jangan menyalin kode) lalu coba lagi.`,
|
|
|
2277
2664
|
notes.push(note);
|
|
2278
2665
|
}
|
|
2279
2666
|
const saved = await saveSkill(root, parsed.data);
|
|
2280
|
-
|
|
2281
|
-
const { skills } = await listSkills(root);
|
|
2282
|
-
await api.put("skills", { skills: skillIndex(skills) });
|
|
2283
|
-
} catch (err) {
|
|
2284
|
-
notes.push(
|
|
2285
|
-
`Skill tersimpan lokal, tetapi indeks belum tersinkron ke Cloud (${err.message}). Jalankan \`catenext sync\` nanti.`
|
|
2286
|
-
);
|
|
2287
|
-
}
|
|
2667
|
+
notes.push("Commit dan merge file skill, lalu jalankan catenext sync di branch utama.");
|
|
2288
2668
|
return json({ path: saved.path, created: saved.created }, notes);
|
|
2289
2669
|
})
|
|
2290
2670
|
);
|
|
@@ -2342,43 +2722,9 @@ async function runMcpServer(opts) {
|
|
|
2342
2722
|
await server.connect(new StdioServerTransport());
|
|
2343
2723
|
}
|
|
2344
2724
|
|
|
2345
|
-
// src/node-command.ts
|
|
2346
|
-
import { accessSync, constants, realpathSync } from "node:fs";
|
|
2347
|
-
import { delimiter, join as join7 } from "node:path";
|
|
2348
|
-
function stableNodeCommand(execPath, pathEnv, resolveReal = realpathSync, isExecutable = defaultIsExecutable) {
|
|
2349
|
-
const target = safeReal(execPath, resolveReal);
|
|
2350
|
-
for (const dir of (pathEnv ?? "").split(delimiter)) {
|
|
2351
|
-
if (!dir) continue;
|
|
2352
|
-
for (const name of process.platform === "win32" ? ["node.exe", "node"] : ["node"]) {
|
|
2353
|
-
const candidate = join7(dir, name);
|
|
2354
|
-
if (!isExecutable(candidate)) continue;
|
|
2355
|
-
return safeReal(candidate, resolveReal) === target ? "node" : execPath;
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
return execPath;
|
|
2359
|
-
}
|
|
2360
|
-
function hasVersionedSegment(path) {
|
|
2361
|
-
return /[\\/]v?\d+\.\d+\.\d+[\\/]/.test(path);
|
|
2362
|
-
}
|
|
2363
|
-
function safeReal(p, resolveReal) {
|
|
2364
|
-
try {
|
|
2365
|
-
return resolveReal(p);
|
|
2366
|
-
} catch {
|
|
2367
|
-
return p;
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
function defaultIsExecutable(p) {
|
|
2371
|
-
try {
|
|
2372
|
-
accessSync(p, constants.X_OK);
|
|
2373
|
-
return true;
|
|
2374
|
-
} catch {
|
|
2375
|
-
return false;
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
|
|
2379
2725
|
// src/verify.ts
|
|
2380
|
-
import { readFile as
|
|
2381
|
-
import { join as
|
|
2726
|
+
import { readFile as readFile9 } from "node:fs/promises";
|
|
2727
|
+
import { join as join9 } from "node:path";
|
|
2382
2728
|
async function verifySetup(root, config) {
|
|
2383
2729
|
const lines = [];
|
|
2384
2730
|
let tokenLine;
|
|
@@ -2418,7 +2764,7 @@ async function verifySetup(root, config) {
|
|
|
2418
2764
|
const missing = [];
|
|
2419
2765
|
const stale = [];
|
|
2420
2766
|
for (const adapter of ADAPTERS) {
|
|
2421
|
-
const src = await
|
|
2767
|
+
const src = await readFile9(join9(root, adapter.path), "utf8").catch(() => null);
|
|
2422
2768
|
const entry = src ? readMcpEntry(src) : null;
|
|
2423
2769
|
if (!entry) missing.push(adapter.label);
|
|
2424
2770
|
else if (entryIsStale(entry)) stale.push(adapter.label);
|
|
@@ -2442,14 +2788,14 @@ function formatChecks(lines) {
|
|
|
2442
2788
|
}
|
|
2443
2789
|
|
|
2444
2790
|
// src/index.ts
|
|
2445
|
-
var VERSION = "0.
|
|
2791
|
+
var VERSION = "0.2.0";
|
|
2446
2792
|
var program = new Command();
|
|
2447
2793
|
program.name("catenext").description("Estafet tugas & konteks antar-agen AI coding").version(VERSION);
|
|
2448
2794
|
async function friendly(fn) {
|
|
2449
2795
|
try {
|
|
2450
2796
|
await fn();
|
|
2451
2797
|
} catch (err) {
|
|
2452
|
-
if (err instanceof ConfigError || err instanceof CredentialsError || err instanceof McpConfigError || err instanceof PlanningInputError) {
|
|
2798
|
+
if (err instanceof ConfigError || err instanceof CredentialsError || err instanceof McpConfigError || err instanceof SkillError || err instanceof PlanningInputError) {
|
|
2453
2799
|
console.error(`\u2717 ${err.message}`);
|
|
2454
2800
|
process.exitCode = 1;
|
|
2455
2801
|
return;
|
|
@@ -2467,6 +2813,8 @@ async function friendly(fn) {
|
|
|
2467
2813
|
function defaultMcpCommand() {
|
|
2468
2814
|
const self = fileURLToPath(import.meta.url);
|
|
2469
2815
|
const entry = self.endsWith(".ts") ? resolve4(dirname4(self), "../dist/index.js") : self;
|
|
2816
|
+
const viaNpx = npxLaunch(entry);
|
|
2817
|
+
if (viaNpx) return viaNpx;
|
|
2470
2818
|
if (!existsSync2(entry)) {
|
|
2471
2819
|
console.error(
|
|
2472
2820
|
`! ${entry} belum ada. Jalankan \`pnpm --filter catenext build\` agar IDE bisa menjalankan server MCP.`
|
|
@@ -2597,10 +2945,10 @@ var AGENT_OPT = [
|
|
|
2597
2945
|
"Nama agen untuk log aktivitas, mis. codex",
|
|
2598
2946
|
"catenext-cli"
|
|
2599
2947
|
];
|
|
2600
|
-
program.command("next").description("Daftar task siap untuk repo ini (setara get_ready_tasks)").option("-n, --limit <n>", "Jumlah maksimal", (v) => Number.parseInt(v, 10), 10).option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2948
|
+
program.command("next").description("Daftar task siap untuk repo ini (setara get_ready_tasks)").option("-n, --limit <n>", "Jumlah maksimal", (v) => Number.parseInt(v, 10), 10).option("--as <alias>", "Bekerja sebagai persona ini: hanya task miliknya (mis. adel)").option("--lease <id>", "Perpanjang lease worktree yang aktif").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2601
2949
|
(opts) => friendly(async () => taskNext(await cliApi(opts.agent), opts))
|
|
2602
2950
|
);
|
|
2603
|
-
program.command("claim").description("Kunci task dan cetak instruksi + handoff dependensinya (setara claim_task)").argument("<task_id>").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2951
|
+
program.command("claim").description("Kunci task dan cetak instruksi + handoff dependensinya (setara claim_task)").argument("<task_id>").option("--as <alias>", "Bekerja sebagai persona ini; task milik persona lain ditolak").option("--worktree", "Reservasi branch checkout dan ambil lease sesi terpisah").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2604
2952
|
(taskId, opts) => friendly(async () => taskClaim(await cliApi(opts.agent), taskId, opts))
|
|
2605
2953
|
);
|
|
2606
2954
|
program.command("done").description("Selesaikan task dengan handoff terstruktur (setara complete_handoff)").argument("<task_id>").option("--notes <text>", "Ringkasan untuk agen berikutnya (maks. 500 karakter)").option(
|
|
@@ -2613,12 +2961,74 @@ program.command("done").description("Selesaikan task dengan handoff terstruktur
|
|
|
2613
2961
|
"File yang diubah (boleh diulang; default dari git)",
|
|
2614
2962
|
collect,
|
|
2615
2963
|
[]
|
|
2616
|
-
).option("--verify <cmd>", "Perintah verifikasi, mis. pnpm test").option("--handoff <file>", "File JSON handoff_summary lengkap, atau '-' untuk stdin").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2964
|
+
).option("--verify <cmd>", "Perintah verifikasi, mis. pnpm test").option("--pr <url>", "URL pull request GitHub").option("--base <branch>", "Branch tujuan PR").option("--lease <id>", "Lease worktree dari claim").option("--handoff <file>", "File JSON handoff_summary lengkap, atau '-' untuk stdin").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2617
2965
|
(taskId, opts) => friendly(async () => taskDone(await cliApi(opts.agent), taskId, opts))
|
|
2618
2966
|
);
|
|
2619
|
-
program.command("block").description("Lepas lock dan tandai task BLOCKED (setara report_blocker)").argument("<task_id>").requiredOption("--category <category>", `Salah satu: ${BLOCKER_CATEGORIES.join(", ")}`).requiredOption("--reason <text>", "Alasan spesifik (min. 10 karakter)").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2967
|
+
program.command("block").description("Lepas lock dan tandai task BLOCKED (setara report_blocker)").argument("<task_id>").requiredOption("--category <category>", `Salah satu: ${BLOCKER_CATEGORIES.join(", ")}`).requiredOption("--reason <text>", "Alasan spesifik (min. 10 karakter)").option("--lease <id>", "Lease worktree dari claim").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2620
2968
|
(taskId, opts) => friendly(async () => taskBlock(await cliApi(opts.agent), taskId, opts))
|
|
2621
2969
|
);
|
|
2970
|
+
program.command("release").description("Lepas task untuk sesi lain").argument("<task_id>").option("--lease <id>", "Lease worktree dari claim").option(...AGENT_OPT).action(
|
|
2971
|
+
(taskId, opts) => friendly(async () => {
|
|
2972
|
+
const input = prepare(ReleaseTaskInput, { task_id: taskId, lease_id: opts.lease }, [
|
|
2973
|
+
"task_id",
|
|
2974
|
+
"lease_id"
|
|
2975
|
+
]);
|
|
2976
|
+
const api = await cliApi(opts.agent);
|
|
2977
|
+
console.log(JSON.stringify(await api.post("release", input), null, 2));
|
|
2978
|
+
})
|
|
2979
|
+
);
|
|
2980
|
+
var review = program.command("review").description("Antrean dan keputusan review pull request");
|
|
2981
|
+
review.command("list").option("-n, --limit <n>", "Jumlah maksimal", Number, 10).option(...AGENT_OPT).option("--json").action(
|
|
2982
|
+
(opts) => friendly(
|
|
2983
|
+
async () => taskReview(
|
|
2984
|
+
await cliApi(opts.agent),
|
|
2985
|
+
{ action: "list", limit: opts.limit },
|
|
2986
|
+
Boolean(opts.json)
|
|
2987
|
+
)
|
|
2988
|
+
)
|
|
2989
|
+
);
|
|
2990
|
+
review.command("claim").argument("<task_id>").option("--as <alias>", "Persona reviewer").option(...AGENT_OPT).option("--json").action(
|
|
2991
|
+
(taskId, opts) => friendly(
|
|
2992
|
+
async () => taskReview(
|
|
2993
|
+
await cliApi(opts.agent),
|
|
2994
|
+
{ action: "claim", task_id: taskId, agent_alias: opts.as },
|
|
2995
|
+
Boolean(opts.json)
|
|
2996
|
+
)
|
|
2997
|
+
)
|
|
2998
|
+
);
|
|
2999
|
+
review.command("refresh").argument("<task_id>").option(...AGENT_OPT).option("--json").action(
|
|
3000
|
+
(taskId, opts) => friendly(
|
|
3001
|
+
async () => taskReview(
|
|
3002
|
+
await cliApi(opts.agent),
|
|
3003
|
+
{ action: "refresh", task_id: taskId },
|
|
3004
|
+
Boolean(opts.json)
|
|
3005
|
+
)
|
|
3006
|
+
)
|
|
3007
|
+
);
|
|
3008
|
+
review.command("submit").argument("<task_id>").requiredOption("--lease <id>").requiredOption("--sha <sha>").requiredOption("--decision <approve|request_changes>").requiredOption("--feedback <text>").option(...AGENT_OPT).option("--json").action(
|
|
3009
|
+
(taskId, opts) => friendly(
|
|
3010
|
+
async () => taskReview(
|
|
3011
|
+
await cliApi(opts.agent),
|
|
3012
|
+
{
|
|
3013
|
+
action: "submit",
|
|
3014
|
+
task_id: taskId,
|
|
3015
|
+
lease_id: opts.lease,
|
|
3016
|
+
head_sha: opts.sha,
|
|
3017
|
+
decision: opts.decision,
|
|
3018
|
+
feedback: opts.feedback
|
|
3019
|
+
},
|
|
3020
|
+
Boolean(opts.json)
|
|
3021
|
+
)
|
|
3022
|
+
)
|
|
3023
|
+
);
|
|
3024
|
+
program.command("skill").description("Baca skill repo dari checkout atau revisi Git").command("load").argument("<name>").option("--revision <sha>", "SHA commit Git untuk paritas lintas perangkat").option("--json").action(
|
|
3025
|
+
(name, opts) => friendly(async () => {
|
|
3026
|
+
const skill = await loadSkill(await requireRoot(), name, opts.revision);
|
|
3027
|
+
console.log(
|
|
3028
|
+
opts.json ? JSON.stringify({ ...skill, revision: opts.revision }, null, 2) : skill.content
|
|
3029
|
+
);
|
|
3030
|
+
})
|
|
3031
|
+
);
|
|
2622
3032
|
async function requireRoot() {
|
|
2623
3033
|
const root = await findProjectRoot();
|
|
2624
3034
|
if (!root) {
|
|
@@ -2650,9 +3060,9 @@ program.command("sync").description("Selaraskan entri MCP, .gitignore, blok AGEN
|
|
|
2650
3060
|
for (const f of plan.findings) console.log(`${f.level === "ok" ? "\u2022" : "!"} ${f.message}`);
|
|
2651
3061
|
if (opts.dryRun) {
|
|
2652
3062
|
for (const l of summarize(plan.edits)) console.log(l);
|
|
2653
|
-
const { count, invalid } = await syncSkills(root, null);
|
|
3063
|
+
const { count, invalid, skipped } = await syncSkills(root, null);
|
|
2654
3064
|
console.log(
|
|
2655
|
-
`(dry-run) ${plan.edits.length} file akan berubah; indeks ${count} skill akan dikirim.`
|
|
3065
|
+
`(dry-run) ${plan.edits.length} file akan berubah; ${skipped ? "indeks skill tidak akan diubah." : `indeks ${count} skill akan dikirim.`}`
|
|
2656
3066
|
);
|
|
2657
3067
|
for (const i of invalid) console.log(`! Skill dilewati: ${i.error}`);
|
|
2658
3068
|
return;
|
|
@@ -2662,12 +3072,24 @@ program.command("sync").description("Selaraskan entri MCP, .gitignore, blok AGEN
|
|
|
2662
3072
|
const fixable = plan.findings.some((f) => f.level === "fixable");
|
|
2663
3073
|
if (plan.edits.length === 0 && !fixable) console.log("\u2713 File lokal sudah selaras.");
|
|
2664
3074
|
try {
|
|
2665
|
-
const
|
|
2666
|
-
|
|
3075
|
+
const api = await cliApi();
|
|
3076
|
+
const { count, invalid, skipped } = await syncSkills(root, api);
|
|
3077
|
+
console.log(
|
|
3078
|
+
skipped ? "\u2022 Indeks Cloud mengikuti branch utama origin. Sinkronkan dari checkout branch itu setelah fetch." : `\u2713 Indeks ${count} skill tersinkron ke Cloud (isi skill tetap di Git).`
|
|
3079
|
+
);
|
|
2667
3080
|
for (const i of invalid) console.log(`! Skill dilewati: ${i.error}`);
|
|
3081
|
+
const { personas } = await api.post("personas/list");
|
|
3082
|
+
const sub = await planSubagents(root, personas);
|
|
3083
|
+
await applyFileEdits(root, sub.edits);
|
|
3084
|
+
for (const l of summarize(sub.edits)) console.log(l);
|
|
3085
|
+
for (const s of sub.skipped)
|
|
3086
|
+
console.log(`! ${s} sudah ada dan bukan buatan Catenext; tidak ditimpa.`);
|
|
3087
|
+
console.log(
|
|
3088
|
+
`\u2713 ${personas.length} persona tersedia sebagai subagent Claude Code di ${SUBAGENTS_DIR}/.`
|
|
3089
|
+
);
|
|
2668
3090
|
} catch (err) {
|
|
2669
3091
|
if (!(err instanceof CredentialsError || err instanceof ApiRequestError)) throw err;
|
|
2670
|
-
console.log(`!
|
|
3092
|
+
console.log(`! Skill/persona belum tersinkron: ${err.message}`);
|
|
2671
3093
|
}
|
|
2672
3094
|
console.log("");
|
|
2673
3095
|
console.log(formatChecks(await verifySetup(root, config)));
|