catenext 0.2.0 → 0.5.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 +62 -0
- package/README.md +173 -32
- package/dist/index.js +1015 -250
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ import { z as z5 } from "zod";
|
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
var IdSchema = z.uuid();
|
|
15
15
|
var SlugSchema = z.string().min(1).max(64).regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Harus slug huruf kecil (a-z, 0-9, '-' atau '_')");
|
|
16
|
+
var PROJECT_LAYOUTS = ["monorepo", "polyrepo"];
|
|
17
|
+
var ProjectLayoutSchema = z.enum(PROJECT_LAYOUTS);
|
|
16
18
|
var RepoNameSchema = SlugSchema;
|
|
17
19
|
var RoleSchema = SlugSchema.max(32);
|
|
18
20
|
var AgentAliasSchema = SlugSchema.max(32);
|
|
@@ -148,7 +150,7 @@ var TASK_EVENTS = [
|
|
|
148
150
|
"claim",
|
|
149
151
|
// agent: TODO | REVISION_REQUESTED -> IN_PROGRESS
|
|
150
152
|
"complete",
|
|
151
|
-
// agent: IN_PROGRESS ->
|
|
153
|
+
// agent: IN_PROGRESS -> NEEDS_REVIEW (PR wajib di complete_handoff)
|
|
152
154
|
"report_blocker",
|
|
153
155
|
// agent: IN_PROGRESS -> BLOCKED
|
|
154
156
|
"release",
|
|
@@ -223,6 +225,8 @@ var ProjectSchema = z5.object({
|
|
|
223
225
|
workspace_id: IdSchema,
|
|
224
226
|
name: z5.string().min(1).max(120),
|
|
225
227
|
detected_stack: z5.array(z5.string()),
|
|
228
|
+
/** monorepo = satu git (claim wajib worktree); polyrepo = clone terpisah per Cloud repo. */
|
|
229
|
+
layout: ProjectLayoutSchema.default("polyrepo"),
|
|
226
230
|
agent_connected_at: IsoDateTimeSchema.nullable(),
|
|
227
231
|
created_at: IsoDateTimeSchema,
|
|
228
232
|
updated_at: IsoDateTimeSchema
|
|
@@ -255,6 +259,7 @@ var AgentPersonaSchema = z5.object({
|
|
|
255
259
|
alias: AgentAliasSchema,
|
|
256
260
|
role: RoleSchema,
|
|
257
261
|
rules: z5.array(z5.string()),
|
|
262
|
+
repos: z5.array(z5.string()),
|
|
258
263
|
created_at: IsoDateTimeSchema,
|
|
259
264
|
updated_at: IsoDateTimeSchema
|
|
260
265
|
});
|
|
@@ -291,11 +296,13 @@ var ProjectMetricsSchema = z5.object({
|
|
|
291
296
|
});
|
|
292
297
|
var CreateProjectInput = z5.object({
|
|
293
298
|
name: z5.string().trim().min(1).max(120),
|
|
294
|
-
detected_stack: z5.array(z5.string().min(1).max(40)).max(20).default([])
|
|
299
|
+
detected_stack: z5.array(z5.string().min(1).max(40)).max(20).default([]),
|
|
300
|
+
layout: ProjectLayoutSchema.default("polyrepo")
|
|
295
301
|
});
|
|
296
302
|
var UpdateProjectInput = z5.object({
|
|
297
303
|
name: z5.string().trim().min(1).max(120).optional(),
|
|
298
|
-
detected_stack: z5.array(z5.string().min(1).max(40)).max(20).optional()
|
|
304
|
+
detected_stack: z5.array(z5.string().min(1).max(40)).max(20).optional(),
|
|
305
|
+
layout: ProjectLayoutSchema.optional()
|
|
299
306
|
});
|
|
300
307
|
var CreateEpicInput = z5.object({
|
|
301
308
|
title: z5.string().trim().min(1).max(200),
|
|
@@ -344,12 +351,14 @@ var PersonaInput = z5.object({
|
|
|
344
351
|
alias: AgentAliasSchema,
|
|
345
352
|
role: RoleSchema,
|
|
346
353
|
rules: z5.array(z5.string().trim().min(1).max(300)).max(30).default([]),
|
|
354
|
+
repos: z5.array(RepoNameSchema).max(10).default([]),
|
|
347
355
|
project_id: IdSchema.nullish()
|
|
348
356
|
});
|
|
349
357
|
var UpdatePersonaInput = z5.object({
|
|
350
358
|
alias: AgentAliasSchema.optional(),
|
|
351
359
|
role: RoleSchema.optional(),
|
|
352
360
|
rules: z5.array(z5.string().trim().min(1).max(300)).max(30).optional(),
|
|
361
|
+
repos: z5.array(RepoNameSchema).max(10).optional(),
|
|
353
362
|
project_id: IdSchema.nullish()
|
|
354
363
|
});
|
|
355
364
|
var CreateApiKeyInput = z5.object({
|
|
@@ -506,11 +515,84 @@ var DeviceApproveInput = z7.object({
|
|
|
506
515
|
project_id: IdSchema.nullish()
|
|
507
516
|
});
|
|
508
517
|
|
|
518
|
+
// shared/src/documents.ts
|
|
519
|
+
import { z as z8 } from "zod";
|
|
520
|
+
var DOCUMENT_KINDS = [
|
|
521
|
+
"blueprint",
|
|
522
|
+
"erd",
|
|
523
|
+
"architecture",
|
|
524
|
+
"api_contract",
|
|
525
|
+
"decision",
|
|
526
|
+
"runbook",
|
|
527
|
+
"other"
|
|
528
|
+
];
|
|
529
|
+
var DocumentKindSchema = z8.enum(DOCUMENT_KINDS);
|
|
530
|
+
var DOCUMENT_LIMITS = {
|
|
531
|
+
/** Karakter per dokumen (~15k token). Lebih dari itu: pecah per bagian. */
|
|
532
|
+
content: 6e4,
|
|
533
|
+
perProject: 50
|
|
534
|
+
};
|
|
535
|
+
var DocumentSlugSchema = SlugSchema.max(64);
|
|
536
|
+
var DocumentIndexEntrySchema = z8.object({
|
|
537
|
+
slug: DocumentSlugSchema,
|
|
538
|
+
title: z8.string(),
|
|
539
|
+
kind: DocumentKindSchema,
|
|
540
|
+
version: z8.number().int().min(1),
|
|
541
|
+
/** "human:<nama>" atau nama agen (mis. claude-code@be). */
|
|
542
|
+
updated_by: z8.string(),
|
|
543
|
+
updated_at: IsoDateTimeSchema,
|
|
544
|
+
/** Panjang isi dalam karakter, agar agen bisa menimbang biaya membaca. */
|
|
545
|
+
size: z8.number().int().min(0)
|
|
546
|
+
});
|
|
547
|
+
var ProjectDocumentSchema = DocumentIndexEntrySchema.extend({
|
|
548
|
+
content: z8.string()
|
|
549
|
+
});
|
|
550
|
+
var SaveDocumentInput = z8.object({
|
|
551
|
+
slug: DocumentSlugSchema,
|
|
552
|
+
title: z8.string().trim().min(1).max(120),
|
|
553
|
+
kind: DocumentKindSchema,
|
|
554
|
+
content: z8.string().trim().min(1).max(DOCUMENT_LIMITS.content),
|
|
555
|
+
/**
|
|
556
|
+
* Versi yang dibaca penulis. 0 = dokumen baru. Bila versi di server sudah berubah, simpan
|
|
557
|
+
* ditolak (document_version_conflict) agar sesi lain tidak tertimpa diam-diam.
|
|
558
|
+
*/
|
|
559
|
+
expected_version: z8.number().int().min(0).optional()
|
|
560
|
+
});
|
|
561
|
+
var GetDocumentInput = z8.object({ slug: DocumentSlugSchema });
|
|
562
|
+
var SaveDocumentOutput = z8.object({
|
|
563
|
+
document: DocumentIndexEntrySchema,
|
|
564
|
+
created: z8.boolean()
|
|
565
|
+
});
|
|
566
|
+
|
|
509
567
|
// shared/src/mcp-tools.ts
|
|
568
|
+
import { z as z11 } from "zod";
|
|
569
|
+
|
|
570
|
+
// shared/src/search.ts
|
|
510
571
|
import { z as z9 } from "zod";
|
|
572
|
+
var SEARCH_SOURCES = ["document", "skill", "task"];
|
|
573
|
+
var SearchSourceSchema = z9.enum(SEARCH_SOURCES);
|
|
574
|
+
var SearchContextInput = z9.object({
|
|
575
|
+
query: z9.string().trim().min(1).max(500),
|
|
576
|
+
sources: z9.array(SearchSourceSchema).min(1).max(3).default(["document", "skill", "task"]),
|
|
577
|
+
limit: z9.number().int().min(1).max(20).default(8)
|
|
578
|
+
});
|
|
579
|
+
var SearchHitSchema = z9.object({
|
|
580
|
+
source: SearchSourceSchema,
|
|
581
|
+
ref: z9.string().min(1).max(200),
|
|
582
|
+
title: z9.string().min(1).max(300),
|
|
583
|
+
snippet: z9.string().max(800),
|
|
584
|
+
score: z9.number()
|
|
585
|
+
});
|
|
586
|
+
var SearchContextOutput = z9.object({
|
|
587
|
+
hits: z9.array(SearchHitSchema),
|
|
588
|
+
reranked: z9.boolean(),
|
|
589
|
+
/** true bila embedding/rerank memakai fallback lokal (tanpa API key provider). */
|
|
590
|
+
degraded: z9.boolean().default(false)
|
|
591
|
+
});
|
|
592
|
+
var LOCAL_EMBED_DIMS = 64;
|
|
511
593
|
|
|
512
594
|
// shared/src/skill.ts
|
|
513
|
-
import { z as
|
|
595
|
+
import { z as z10 } from "zod";
|
|
514
596
|
var SKILL_LIMITS = {
|
|
515
597
|
maxWords: 500,
|
|
516
598
|
maxWhenToUseLength: 160,
|
|
@@ -518,9 +600,9 @@ var SKILL_LIMITS = {
|
|
|
518
600
|
maxCodeBlockLines: 15
|
|
519
601
|
};
|
|
520
602
|
var SkillNameSchema = SlugSchema.max(48);
|
|
521
|
-
var SkillFrontmatterSchema =
|
|
603
|
+
var SkillFrontmatterSchema = z10.object({
|
|
522
604
|
name: SkillNameSchema,
|
|
523
|
-
when_to_use:
|
|
605
|
+
when_to_use: z10.string().min(1).max(SKILL_LIMITS.maxWhenToUseLength),
|
|
524
606
|
updated_at: IsoDateTimeSchema
|
|
525
607
|
});
|
|
526
608
|
function longestCodeBlockLines(markdown) {
|
|
@@ -532,14 +614,14 @@ function longestCodeBlockLines(markdown) {
|
|
|
532
614
|
}
|
|
533
615
|
return longest;
|
|
534
616
|
}
|
|
535
|
-
var SkillContentSchema =
|
|
617
|
+
var SkillContentSchema = z10.string().min(1).refine((s) => countWords(s) <= SKILL_LIMITS.maxWords, {
|
|
536
618
|
message: `Skill maksimal ${SKILL_LIMITS.maxWords} kata`
|
|
537
619
|
}).refine((s) => longestCodeBlockLines(s) <= SKILL_LIMITS.maxCodeBlockLines, {
|
|
538
620
|
message: `Blok kode maksimal ${SKILL_LIMITS.maxCodeBlockLines} baris; rujuk path file, jangan menyalin kode`
|
|
539
621
|
});
|
|
540
|
-
var SkillIndexEntrySchema =
|
|
622
|
+
var SkillIndexEntrySchema = z10.object({
|
|
541
623
|
name: SkillNameSchema,
|
|
542
|
-
when_to_use:
|
|
624
|
+
when_to_use: z10.string().min(1).max(SKILL_LIMITS.maxWhenToUseLength),
|
|
543
625
|
repo_name: RepoNameSchema
|
|
544
626
|
});
|
|
545
627
|
function skillPath(name) {
|
|
@@ -551,117 +633,203 @@ var PersonaFilter = {
|
|
|
551
633
|
agent_alias: AgentAliasSchema.optional(),
|
|
552
634
|
role: RoleSchema.optional()
|
|
553
635
|
};
|
|
554
|
-
var
|
|
636
|
+
var PersonaReposSchema = z11.array(RepoNameSchema).max(10);
|
|
637
|
+
var PersonaSchema = z11.object({
|
|
555
638
|
alias: AgentAliasSchema,
|
|
556
639
|
role: RoleSchema,
|
|
557
|
-
rules:
|
|
640
|
+
rules: z11.array(z11.string().min(1).max(300)).max(30),
|
|
641
|
+
repos: PersonaReposSchema.default([])
|
|
558
642
|
});
|
|
559
|
-
var DependencyHandoffSchema =
|
|
643
|
+
var DependencyHandoffSchema = z11.object({
|
|
560
644
|
task_id: IdSchema,
|
|
561
|
-
title:
|
|
645
|
+
title: z11.string(),
|
|
562
646
|
handoff_summary: HandoffSummarySchema,
|
|
563
|
-
integrated_commit:
|
|
647
|
+
integrated_commit: z11.object({ branch: z11.string(), sha: CommitShaSchema }).optional()
|
|
564
648
|
});
|
|
565
|
-
var GetProjectContextInput =
|
|
566
|
-
var GetProjectContextOutput =
|
|
567
|
-
project:
|
|
649
|
+
var GetProjectContextInput = z11.object({ ...PersonaFilter, lease_id: IdSchema.optional() });
|
|
650
|
+
var GetProjectContextOutput = z11.object({
|
|
651
|
+
project: z11.object({
|
|
568
652
|
id: IdSchema,
|
|
569
|
-
name:
|
|
653
|
+
name: z11.string(),
|
|
570
654
|
repo_name: RepoNameSchema,
|
|
571
|
-
stack:
|
|
655
|
+
stack: z11.array(z11.string()),
|
|
656
|
+
layout: z11.enum(["monorepo", "polyrepo"]).default("polyrepo")
|
|
572
657
|
}),
|
|
573
658
|
/** Aturan keras untuk agen (mis. jangan mengedit config MCP). Statis di atas agar ramah cache. */
|
|
574
|
-
directives:
|
|
659
|
+
directives: z11.array(z11.string()),
|
|
575
660
|
persona: PersonaSchema.optional(),
|
|
576
|
-
epic_summary:
|
|
661
|
+
epic_summary: z11.string().max(1e3).optional(),
|
|
577
662
|
/** Tier 1: indeks skill saja, isi lengkap lewat load_skill. */
|
|
578
|
-
skills:
|
|
663
|
+
skills: z11.array(SkillIndexEntrySchema),
|
|
579
664
|
skill_revision: CommitShaSchema.optional(),
|
|
580
665
|
/**
|
|
581
666
|
* Handoff dari dependensi langsung task aktif (dependency-scoped context). Jika belum ada
|
|
582
667
|
* task aktif: handoff dependensi task yang siap diklaim (maks. 5).
|
|
583
668
|
*/
|
|
584
|
-
recent_handoffs:
|
|
669
|
+
recent_handoffs: z11.array(DependencyHandoffSchema),
|
|
670
|
+
/** Repo yang dikenal proyek, agar orchestrator tahu ke mana task bisa diarahkan. */
|
|
671
|
+
project_repos: z11.array(RepoNameSchema).default([]),
|
|
672
|
+
/** Indeks dokumen proyek di Cloud (blueprint, ERD, ...); isi lewat get_document. */
|
|
673
|
+
documents: z11.array(DocumentIndexEntrySchema).default([])
|
|
674
|
+
});
|
|
675
|
+
var GetProjectBoardInput = z11.object({
|
|
676
|
+
epic_id: IdSchema.optional(),
|
|
677
|
+
/** Tanpa filter: semua status. */
|
|
678
|
+
status: z11.array(TaskStatusSchema).max(7).optional(),
|
|
679
|
+
limit: z11.number().int().min(1).max(200).default(100)
|
|
680
|
+
});
|
|
681
|
+
var BoardTaskSchema = z11.object({
|
|
682
|
+
id: IdSchema,
|
|
683
|
+
title: z11.string(),
|
|
684
|
+
epic_id: IdSchema,
|
|
685
|
+
status: TaskStatusSchema,
|
|
686
|
+
target_repo: RepoNameSchema.nullable(),
|
|
687
|
+
role: RoleSchema.nullable(),
|
|
688
|
+
persona: AgentAliasSchema.nullable(),
|
|
689
|
+
depends_on: z11.array(IdSchema),
|
|
690
|
+
/** TODO/REVISION_REQUESTED dengan semua dependensi DONE. */
|
|
691
|
+
is_ready: z11.boolean(),
|
|
692
|
+
is_stale: z11.boolean(),
|
|
693
|
+
revision_count: z11.number().int().min(0),
|
|
694
|
+
/** Repo yang sedang memegang lease (IN_PROGRESS). */
|
|
695
|
+
locked_by_repo: RepoNameSchema.nullable(),
|
|
696
|
+
blocker_reason: z11.string().nullable()
|
|
697
|
+
});
|
|
698
|
+
var GetProjectBoardOutput = z11.object({
|
|
699
|
+
epics: z11.array(
|
|
700
|
+
z11.object({
|
|
701
|
+
id: IdSchema,
|
|
702
|
+
title: z11.string(),
|
|
703
|
+
counts: z11.record(z11.string(), z11.number().int())
|
|
704
|
+
})
|
|
705
|
+
),
|
|
706
|
+
/** Repo yang dikenal proyek (dari task, skill, dan persona) beserta persona pemegangnya. */
|
|
707
|
+
repos: z11.array(z11.object({ repo: RepoNameSchema, personas: z11.array(AgentAliasSchema) })),
|
|
708
|
+
personas: z11.array(PersonaSchema),
|
|
709
|
+
tasks: z11.array(BoardTaskSchema),
|
|
710
|
+
truncated: z11.boolean()
|
|
585
711
|
});
|
|
586
|
-
var GetReadyTasksInput =
|
|
712
|
+
var GetReadyTasksInput = z11.object({
|
|
587
713
|
...PersonaFilter,
|
|
588
714
|
lease_id: IdSchema.optional(),
|
|
589
|
-
limit:
|
|
715
|
+
limit: z11.number().int().min(1).max(50).default(10)
|
|
590
716
|
});
|
|
591
|
-
var GetReadyTasksOutput =
|
|
592
|
-
tasks:
|
|
717
|
+
var GetReadyTasksOutput = z11.object({
|
|
718
|
+
tasks: z11.array(TaskSummarySchema)
|
|
593
719
|
});
|
|
594
|
-
var ClaimTaskInput =
|
|
595
|
-
worktree:
|
|
720
|
+
var ClaimTaskInput = z11.object({
|
|
721
|
+
worktree: z11.object({
|
|
596
722
|
session_id: IdSchema,
|
|
597
|
-
branch:
|
|
723
|
+
branch: z11.string().min(1).max(255).regex(/^[a-zA-Z0-9_./-]+$/).refine((s) => s !== "HEAD" && !s.startsWith("-") && !s.includes(".."))
|
|
598
724
|
}).optional(),
|
|
599
725
|
task_id: IdSchema,
|
|
600
726
|
/** Alias persona yang sedang dipakai agen. Task milik persona lain ditolak. */
|
|
601
727
|
agent_alias: AgentAliasSchema.optional()
|
|
602
728
|
});
|
|
603
|
-
var ClaimTaskOutput =
|
|
604
|
-
task:
|
|
729
|
+
var ClaimTaskOutput = z11.object({
|
|
730
|
+
task: z11.object({
|
|
605
731
|
id: IdSchema,
|
|
606
|
-
title:
|
|
607
|
-
prompt_instruction:
|
|
608
|
-
status:
|
|
732
|
+
title: z11.string(),
|
|
733
|
+
prompt_instruction: z11.string(),
|
|
734
|
+
status: z11.literal("IN_PROGRESS"),
|
|
609
735
|
role: RoleSchema.optional(),
|
|
610
736
|
target_repo: RepoNameSchema.optional(),
|
|
611
|
-
revision_count:
|
|
737
|
+
revision_count: z11.number().int().min(0)
|
|
612
738
|
}),
|
|
613
739
|
/** Persona penanggung jawab task (atau persona agen): ikuti aturan dan batas wilayahnya. */
|
|
614
740
|
persona: PersonaSchema.optional(),
|
|
615
741
|
lease_expires_at: IsoDateTimeSchema,
|
|
616
742
|
lease_id: IdSchema.optional(),
|
|
617
|
-
dependencies:
|
|
743
|
+
dependencies: z11.array(DependencyHandoffSchema),
|
|
618
744
|
/** Diisi bila task diambil dari REVISION_REQUESTED. */
|
|
619
|
-
revision:
|
|
620
|
-
review_feedback:
|
|
745
|
+
revision: z11.object({
|
|
746
|
+
review_feedback: z11.string(),
|
|
621
747
|
previous_handoff: HandoffSummarySchema.nullable()
|
|
622
748
|
}).optional(),
|
|
623
749
|
/** Peringatan bila branch lokal berbeda dari git_branch handoff dependensi. */
|
|
624
|
-
warnings:
|
|
750
|
+
warnings: z11.array(z11.string()).default([])
|
|
625
751
|
});
|
|
626
|
-
var CompleteHandoffInput =
|
|
752
|
+
var CompleteHandoffInput = z11.object({
|
|
627
753
|
lease_id: IdSchema.optional(),
|
|
628
754
|
task_id: IdSchema,
|
|
629
755
|
handoff_summary: HandoffSummarySchema
|
|
756
|
+
}).superRefine((input, ctx) => {
|
|
757
|
+
if (!input.handoff_summary.pull_request) {
|
|
758
|
+
ctx.addIssue({
|
|
759
|
+
code: "custom",
|
|
760
|
+
message: "pull_request wajib: buat PR di branch kerja lalu sertakan url, base_branch, dan head_sha.",
|
|
761
|
+
path: ["handoff_summary", "pull_request"]
|
|
762
|
+
});
|
|
763
|
+
}
|
|
630
764
|
});
|
|
631
|
-
var CompleteHandoffOutput =
|
|
765
|
+
var CompleteHandoffOutput = z11.object({
|
|
632
766
|
task_id: IdSchema,
|
|
633
|
-
status:
|
|
634
|
-
unlocked_task_ids:
|
|
767
|
+
status: z11.literal("NEEDS_REVIEW"),
|
|
768
|
+
unlocked_task_ids: z11.array(IdSchema),
|
|
635
769
|
/** Mis. saran mereset sesi chat (1 Task = 1 Fresh Session). */
|
|
636
|
-
next_step_hint:
|
|
770
|
+
next_step_hint: z11.string()
|
|
637
771
|
});
|
|
638
|
-
var ReportBlockerInput =
|
|
772
|
+
var ReportBlockerInput = z11.object({
|
|
639
773
|
lease_id: IdSchema.optional(),
|
|
640
774
|
task_id: IdSchema,
|
|
641
775
|
category: BlockerCategorySchema,
|
|
642
|
-
reason:
|
|
776
|
+
reason: z11.string().min(10).max(1e3)
|
|
643
777
|
});
|
|
644
|
-
var ReportBlockerOutput =
|
|
778
|
+
var ReportBlockerOutput = z11.object({
|
|
645
779
|
task_id: IdSchema,
|
|
646
|
-
status:
|
|
780
|
+
status: z11.literal("BLOCKED")
|
|
781
|
+
});
|
|
782
|
+
var MANAGE_TASK_ACTIONS = ["request_revision", "assign"];
|
|
783
|
+
var ManageTaskInput = z11.object({
|
|
784
|
+
action: z11.enum(MANAGE_TASK_ACTIONS),
|
|
785
|
+
task_id: IdSchema,
|
|
786
|
+
/** Wajib untuk request_revision: apa yang harus diperbaiki (feedback manusia/orchestrator). */
|
|
787
|
+
feedback: z11.string().trim().min(5).max(2e3).optional(),
|
|
788
|
+
/** Persona penanggung jawab baru. null = lepas persona (task diambil berdasarkan role). */
|
|
789
|
+
agent_alias: AgentAliasSchema.nullable().optional(),
|
|
790
|
+
/** Role task tanpa persona tertentu. Diabaikan bila agent_alias diisi (role ikut persona). */
|
|
791
|
+
role: RoleSchema.nullable().optional()
|
|
792
|
+
}).superRefine((v, ctx) => {
|
|
793
|
+
if (v.action === "request_revision" && !v.feedback) {
|
|
794
|
+
ctx.addIssue({
|
|
795
|
+
code: "custom",
|
|
796
|
+
path: ["feedback"],
|
|
797
|
+
message: "request_revision butuh feedback: apa yang harus diperbaiki."
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
if (v.action === "assign" && v.agent_alias === void 0 && v.role === void 0) {
|
|
801
|
+
ctx.addIssue({
|
|
802
|
+
code: "custom",
|
|
803
|
+
path: ["agent_alias"],
|
|
804
|
+
message: "assign butuh agent_alias atau role."
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
var ManageTaskOutput = z11.object({
|
|
809
|
+
task_id: IdSchema,
|
|
810
|
+
status: TaskStatusSchema,
|
|
811
|
+
persona: AgentAliasSchema.nullable(),
|
|
812
|
+
role: RoleSchema.nullable(),
|
|
813
|
+
revision_count: z11.number().int().min(0),
|
|
814
|
+
stale_task_ids: z11.array(IdSchema)
|
|
647
815
|
});
|
|
648
816
|
var MAX_TASKS_PER_PLAN = 30;
|
|
649
|
-
var PlanRefSchema =
|
|
650
|
-
var PlannedTaskSchema =
|
|
817
|
+
var PlanRefSchema = z11.string().min(1).max(40).regex(/^[a-z0-9][a-z0-9_-]*$/, "ref harus huruf kecil, angka, '-' atau '_'");
|
|
818
|
+
var PlannedTaskSchema = z11.object({
|
|
651
819
|
ref: PlanRefSchema,
|
|
652
|
-
title:
|
|
653
|
-
prompt_instruction:
|
|
820
|
+
title: z11.string().min(1).max(200),
|
|
821
|
+
prompt_instruction: z11.string().min(1).max(8e3),
|
|
654
822
|
/** Berisi ref task lain dalam rencana ini, atau UUID task yang sudah ada. */
|
|
655
|
-
depends_on:
|
|
823
|
+
depends_on: z11.array(z11.union([PlanRefSchema, IdSchema])).max(10).default([]),
|
|
656
824
|
target_repo: RepoNameSchema.optional(),
|
|
657
825
|
role: RoleSchema.optional(),
|
|
658
826
|
/** Alias persona penanggung jawab (lihat list_personas). Role task mengikuti persona ini. */
|
|
659
827
|
persona: AgentAliasSchema.optional(),
|
|
660
|
-
requires_approval:
|
|
828
|
+
requires_approval: z11.boolean().default(false)
|
|
661
829
|
});
|
|
662
|
-
var CreateTasksInput =
|
|
830
|
+
var CreateTasksInput = z11.object({
|
|
663
831
|
epic_id: IdSchema,
|
|
664
|
-
tasks:
|
|
832
|
+
tasks: z11.array(PlannedTaskSchema).min(1).max(MAX_TASKS_PER_PLAN)
|
|
665
833
|
}).superRefine((plan, ctx) => {
|
|
666
834
|
const refs = /* @__PURE__ */ new Set();
|
|
667
835
|
plan.tasks.forEach((t, i) => {
|
|
@@ -704,67 +872,73 @@ var CreateTasksInput = z9.object({
|
|
|
704
872
|
});
|
|
705
873
|
}
|
|
706
874
|
});
|
|
707
|
-
var CreateTasksOutput =
|
|
708
|
-
created:
|
|
709
|
-
|
|
710
|
-
ref:
|
|
875
|
+
var CreateTasksOutput = z11.object({
|
|
876
|
+
created: z11.array(
|
|
877
|
+
z11.object({
|
|
878
|
+
ref: z11.string(),
|
|
711
879
|
task_id: IdSchema,
|
|
712
880
|
status: TaskStatusSchema
|
|
713
881
|
})
|
|
714
882
|
)
|
|
715
883
|
});
|
|
716
|
-
var LoadSkillInput =
|
|
884
|
+
var LoadSkillInput = z11.object({
|
|
717
885
|
name: SkillNameSchema,
|
|
718
886
|
revision: CommitShaSchema.optional()
|
|
719
887
|
});
|
|
720
|
-
var LoadSkillOutput =
|
|
888
|
+
var LoadSkillOutput = z11.object({
|
|
721
889
|
name: SkillNameSchema,
|
|
722
890
|
revision: CommitShaSchema.optional(),
|
|
723
|
-
when_to_use:
|
|
724
|
-
content:
|
|
891
|
+
when_to_use: z11.string(),
|
|
892
|
+
content: z11.string()
|
|
725
893
|
});
|
|
726
|
-
var SaveRepoSkillInput =
|
|
894
|
+
var SaveRepoSkillInput = z11.object({
|
|
727
895
|
name: SkillNameSchema,
|
|
728
|
-
when_to_use:
|
|
896
|
+
when_to_use: z11.string().min(1).max(SKILL_LIMITS.maxWhenToUseLength),
|
|
729
897
|
content: SkillContentSchema
|
|
730
898
|
});
|
|
731
|
-
var SaveRepoSkillOutput =
|
|
732
|
-
path:
|
|
733
|
-
created:
|
|
899
|
+
var SaveRepoSkillOutput = z11.object({
|
|
900
|
+
path: z11.string(),
|
|
901
|
+
created: z11.boolean()
|
|
734
902
|
});
|
|
735
|
-
var EpicSummarySchema =
|
|
903
|
+
var EpicSummarySchema = z11.object({
|
|
736
904
|
id: IdSchema,
|
|
737
|
-
title:
|
|
738
|
-
description:
|
|
905
|
+
title: z11.string(),
|
|
906
|
+
description: z11.string().nullable(),
|
|
739
907
|
/** Jumlah task per status, mis. { DRAFT: 3, TODO: 1 }. */
|
|
740
|
-
task_counts:
|
|
908
|
+
task_counts: z11.record(z11.string(), z11.number().int().min(0))
|
|
741
909
|
});
|
|
742
|
-
var ListEpicsInput =
|
|
743
|
-
var ListEpicsOutput =
|
|
744
|
-
epics:
|
|
910
|
+
var ListEpicsInput = z11.object({});
|
|
911
|
+
var ListEpicsOutput = z11.object({
|
|
912
|
+
epics: z11.array(EpicSummarySchema)
|
|
745
913
|
});
|
|
746
|
-
var CreateEpicToolInput =
|
|
747
|
-
title:
|
|
748
|
-
description:
|
|
914
|
+
var CreateEpicToolInput = z11.object({
|
|
915
|
+
title: z11.string().trim().min(1).max(200),
|
|
916
|
+
description: z11.string().max(4e3).optional()
|
|
749
917
|
});
|
|
750
|
-
var CreateEpicToolOutput =
|
|
918
|
+
var CreateEpicToolOutput = z11.object({
|
|
751
919
|
epic: EpicSummarySchema
|
|
752
920
|
});
|
|
753
|
-
var ListPersonasInput =
|
|
754
|
-
var ListPersonasOutput =
|
|
755
|
-
personas:
|
|
921
|
+
var ListPersonasInput = z11.object({});
|
|
922
|
+
var ListPersonasOutput = z11.object({
|
|
923
|
+
personas: z11.array(
|
|
756
924
|
PersonaSchema.extend({
|
|
757
925
|
/** "project" = khusus proyek ini (bisa diubah agen); "workspace" = global, hanya dari Web. */
|
|
758
|
-
scope:
|
|
926
|
+
scope: z11.enum(["project", "workspace"])
|
|
759
927
|
})
|
|
760
928
|
)
|
|
761
929
|
});
|
|
762
930
|
var UpsertPersonaInput = PersonaSchema.extend({
|
|
763
|
-
|
|
931
|
+
/**
|
|
932
|
+
* Tidak dikirim = aturan dipertahankan; persona proyek baru mewarisi aturan persona master
|
|
933
|
+
* (workspace) dengan alias yang sama.
|
|
934
|
+
*/
|
|
935
|
+
rules: z11.array(z11.string().trim().min(1).max(300)).max(30).optional(),
|
|
936
|
+
/** Tidak dikirim = repo persona yang ada dipertahankan. */
|
|
937
|
+
repos: PersonaReposSchema.optional()
|
|
764
938
|
});
|
|
765
|
-
var UpsertPersonaOutput =
|
|
939
|
+
var UpsertPersonaOutput = z11.object({
|
|
766
940
|
persona: PersonaSchema,
|
|
767
|
-
created:
|
|
941
|
+
created: z11.boolean()
|
|
768
942
|
});
|
|
769
943
|
function tool(description, input, output) {
|
|
770
944
|
return { description, input, output };
|
|
@@ -773,11 +947,36 @@ var MCP_TOOLS = {
|
|
|
773
947
|
release_task: tool(
|
|
774
948
|
"Lepas lease task supaya sesi lain bisa mengambilnya.",
|
|
775
949
|
ReleaseTaskInput,
|
|
776
|
-
|
|
950
|
+
z11.object({ task_id: IdSchema, status: z11.enum(["TODO", "REVISION_REQUESTED"]) })
|
|
951
|
+
),
|
|
952
|
+
get_project_board: tool(
|
|
953
|
+
"Khusus orchestrator: papan seluruh proyek lintas repo (epic, task, status, persona, repo, dependensi) untuk membagi, melanjutkan, dan menyerahkan task.",
|
|
954
|
+
GetProjectBoardInput,
|
|
955
|
+
GetProjectBoardOutput
|
|
956
|
+
),
|
|
957
|
+
search_context: tool(
|
|
958
|
+
"Cari semantik di dokumen Cloud, indeks skill, dan task proyek (embedding + cache; rerank bila tersedia). Pakai sebelum load_skill/get_document buta.",
|
|
959
|
+
SearchContextInput,
|
|
960
|
+
SearchContextOutput
|
|
961
|
+
),
|
|
962
|
+
get_document: tool(
|
|
963
|
+
"Baca isi dokumen proyek di Cloud (blueprint, ERD, arsitektur, kontrak API, keputusan) berdasarkan slug dari get_project_context.",
|
|
964
|
+
GetDocumentInput,
|
|
965
|
+
ProjectDocumentSchema
|
|
966
|
+
),
|
|
967
|
+
save_document: tool(
|
|
968
|
+
"Buat/perbarui dokumen proyek di Cloud agar sesi/IDE/CLI lain tidak kehilangan konteks. Markdown ringkas, tanpa code dump atau secret. Kirim expected_version dari versi yang Anda baca (0 = baru).",
|
|
969
|
+
SaveDocumentInput,
|
|
970
|
+
SaveDocumentOutput
|
|
971
|
+
),
|
|
972
|
+
manage_task: tool(
|
|
973
|
+
"Khusus orchestrator (agen utama, bukan subagent persona): request_revision memindahkan task NEEDS_REVIEW/DONE ke kolom Revisi dengan feedback (bukan membuat task baru) dan opsional mengganti persona; assign mengatur persona/role task yang belum dikerjakan.",
|
|
974
|
+
ManageTaskInput,
|
|
975
|
+
ManageTaskOutput
|
|
777
976
|
),
|
|
778
977
|
review_pull_request: tool(
|
|
779
978
|
"Antrean, claim, hasil review, atau cek merge pull request.",
|
|
780
|
-
|
|
979
|
+
z11.object({ request: ReviewInput }),
|
|
781
980
|
ReviewOutput
|
|
782
981
|
),
|
|
783
982
|
get_project_context: tool(
|
|
@@ -791,12 +990,12 @@ var MCP_TOOLS = {
|
|
|
791
990
|
GetReadyTasksOutput
|
|
792
991
|
),
|
|
793
992
|
claim_task: tool(
|
|
794
|
-
"Kunci task (lease 30 menit) dan ambil instruksi lengkap, handoff dependensi, serta aturan persona
|
|
993
|
+
"Kunci task (lease 30 menit) dan ambil instruksi lengkap, handoff dependensi, serta aturan persona. Bila project.layout=monorepo, kirim worktree (branch + session_id). Polyrepo: worktree opsional. Kirim agent_alias bila bekerja sebagai persona tertentu.",
|
|
795
994
|
ClaimTaskInput,
|
|
796
995
|
ClaimTaskOutput
|
|
797
996
|
),
|
|
798
997
|
complete_handoff: tool(
|
|
799
|
-
"Selesaikan task dengan
|
|
998
|
+
"Selesaikan task dengan handoff terstruktur; pull_request wajib (url, base_branch, head_sha). Status selalu NEEDS_REVIEW sampai manusia approve/merge PR. Commit di branch kerja OK; jangan merge ke default branch sendiri.",
|
|
800
999
|
CompleteHandoffInput,
|
|
801
1000
|
CompleteHandoffOutput
|
|
802
1001
|
),
|
|
@@ -843,10 +1042,61 @@ var MCP_TOOLS = {
|
|
|
843
1042
|
};
|
|
844
1043
|
var MCP_TOOL_NAMES = Object.keys(MCP_TOOLS);
|
|
845
1044
|
|
|
1045
|
+
// shared/src/orchestrator.ts
|
|
1046
|
+
var ORCHESTRATOR_RULES = [
|
|
1047
|
+
"Anda, agen utama sesi ini, adalah **orchestrator**. Persona Catenext (mis. `bambang` backend di repo `be`, `mira` frontend di repo `fe`, `qori` QA) adalah **subagent** Anda. Orchestrator tidak memakai `agent_alias`.",
|
|
1048
|
+
"",
|
|
1049
|
+
"### Konteks di awal setiap sesi",
|
|
1050
|
+
"",
|
|
1051
|
+
"1. `get_project_context`: repo proyek (`project_repos`), indeks dokumen Cloud (`documents`), skill, dan handoff terbaru.",
|
|
1052
|
+
"2. Baca dokumen yang relevan dengan `get_document` (mis. `blueprint`, `erd`, `architecture`). Dokumen ini sumber kebenaran lintas sesi, IDE, dan CLI; jangan mengandalkan ingatan sesi sebelumnya.",
|
|
1053
|
+
"3. `get_project_board` (CLI: `catenext board`): semua epic dan task lintas repo, status, persona, repo tujuan, dan dependensi. Lanjutkan dari sini, bukan dari awal.",
|
|
1054
|
+
"",
|
|
1055
|
+
"### Tugas orchestrator",
|
|
1056
|
+
"",
|
|
1057
|
+
"1. Rencanakan: `list_epics`/`create_epic` lalu `create_tasks`. Setiap task wajib punya `target_repo` (repo tempat kode berubah) dan `persona` atau `role`. Pecah pekerjaan lintas repo per repo (mis. kontrak API di `be`, layar di `fe`, uji di `qa`) dan hubungkan dengan `depends_on`. Rencana masuk DRAFT sampai manusia menyetujuinya di Web.",
|
|
1058
|
+
'2. Bagi tugas: tetapkan pemegang repo dengan `upsert_persona` (`repos: ["be"]`; CLI: `catenext persona set bambang --role backend --repo be`). Task tanpa `target_repo` milik persona yang memegang satu repo otomatis diarahkan ke repo itu.',
|
|
1059
|
+
'3. Delegasikan: untuk task yang `is_ready` di board, panggil subagent persona penanggung jawab (mis. "bambang, kerjakan task <task_id> di repo be"). Jangan mengerjakan sendiri task milik persona kecuali manusia memintanya.',
|
|
1060
|
+
"4. Tinjau handoff subagent: ringkasan, perintah verifikasi, dan PR. Jalankan verifikasinya, lalu lanjutkan task hilir yang terbuka.",
|
|
1061
|
+
'5. Revisi: bila hasil perlu diperbaiki (temuan review Anda atau permintaan manusia), pakai `manage_task` dengan `action: request_revision` dan `feedback` yang spesifik (CLI: `catenext revise <task_id> --feedback "..." [--to <alias>]`). Task pindah ke kolom **Revisi**; **jangan membuat task baru untuk revisi**. Lalu delegasikan lagi ke subagent penanggung jawabnya.',
|
|
1062
|
+
"6. Assign: `manage_task` dengan `action: assign` (CLI: `catenext assign <task_id> --to <alias>` atau `--role <role>`) untuk menetapkan atau mengganti penanggung jawab task yang belum dikerjakan.",
|
|
1063
|
+
"7. Catat konteks: keputusan arsitektur, skema data (ERD), dan kontrak antar-repo disimpan dengan `save_document` (kirim `expected_version` dari versi yang Anda baca; 0 = dokumen baru). Ringkas, Markdown, tanpa code dump atau secret.",
|
|
1064
|
+
"",
|
|
1065
|
+
"### Subagent per persona dan repo terpisah",
|
|
1066
|
+
"",
|
|
1067
|
+
"Setiap persona dari `list_personas` menjadi satu subagent: nama = alias, isi = role, repo yang dipegang, aturan persona, dan alur subagent di bawah.",
|
|
1068
|
+
"",
|
|
1069
|
+
"- Claude Code: `catenext sync` membuat `.claude/agents/<alias>.md` secara otomatis.",
|
|
1070
|
+
"- IDE/CLI lain: buat subagent, mode, atau rule dengan format bawaan IDE Anda. Bila IDE tidak punya subagent, buka satu sesi baru per persona.",
|
|
1071
|
+
"- Repo di folder terpisah: jalankan `catenext init --project <project_id> --repo <nama>` sekali di setiap folder repo (`--repo be` di folder backend, `--repo fe` di folder frontend). Subagent bekerja dari folder repo yang ia pegang; dari folder lain ia memakai CLI di folder itu (`cd <folder-be> && npx catenext next --as bambang`), karena MCP di folder ini terikat ke repo folder ini.",
|
|
1072
|
+
"- Persona master (tingkat workspace) berlaku lintas proyek. Untuk memegang repo di proyek ini, buat persona proyek dengan alias yang sama: aturan master diwarisi bila `rules` tidak dikirim.",
|
|
1073
|
+
"- Persona belum ada: usulkan alias, role, repo, dan aturannya ke manusia, lalu `upsert_persona` setelah disetujui.",
|
|
1074
|
+
"",
|
|
1075
|
+
"### Alur subagent (persona)",
|
|
1076
|
+
"",
|
|
1077
|
+
"1. Pastikan berada di folder repo yang dipegang. `get_ready_tasks` dan `claim_task` dengan `agent_alias: <alias>`; patuhi aturan persona di hasil claim. Bila `layout` proyek = `monorepo`, claim wajib mode worktree. Task di kolom Revisi didahulukan dan membawa feedback revisinya.",
|
|
1078
|
+
"2. Baca dokumen proyek yang dirujuk task (`get_document`) bila perlu konteks desain.",
|
|
1079
|
+
"3. Kerjakan, jalankan tes, commit di branch/worktree kerja (boleh commit sewaktu-waktu; jangan merge ke default branch).",
|
|
1080
|
+
"4. Buat PR, lalu `complete_handoff` dengan `pull_request` wajib (status \u2192 NEEDS_REVIEW), atau `report_blocker` bila buntu.",
|
|
1081
|
+
"5. Laporkan ke orchestrator: task, status, URL PR, dan perintah verifikasi.",
|
|
1082
|
+
"",
|
|
1083
|
+
"Subagent hanya mengerjakan satu task per pemanggilan dan tidak memanggil `create_tasks`, `manage_task`, `upsert_persona`, atau `save_document`."
|
|
1084
|
+
];
|
|
1085
|
+
var CLI_FALLBACK_RULES = [
|
|
1086
|
+
"### Tanpa tool MCP",
|
|
1087
|
+
"",
|
|
1088
|
+
"- Orchestrator: `catenext board`, `catenext doc list|get|save`, `catenext persona list|set`, `catenext revise`, `catenext assign`.",
|
|
1089
|
+
'- Subagent: `catenext next --as <alias>`, `catenext claim <task_id> --as <alias> [--worktree]` (wajib `--worktree` di monorepo), kerjakan & commit di branch, buat PR, lalu `catenext done <task_id> --notes "..." --verify "..." --pr <url> --base <branch>`.',
|
|
1090
|
+
'- Bila buntu: `catenext block <task_id> --category <missing_env|ambiguous_requirement|failing_tests|dependency_issue|other> --reason "..."`.'
|
|
1091
|
+
];
|
|
1092
|
+
var GENERAL_RULES = [
|
|
1093
|
+
"Aturan: jangan menyalin kode atau secret ke handoff atau dokumen (rujuk path file); jangan mengedit `.catenext/config.yaml` atau file konfigurasi MCP IDE. Skill repo ada di `.catenext/skills/`."
|
|
1094
|
+
];
|
|
1095
|
+
|
|
846
1096
|
// shared/src/quota.ts
|
|
847
|
-
import { z as
|
|
1097
|
+
import { z as z12 } from "zod";
|
|
848
1098
|
var PLANS = ["free", "pro", "team"];
|
|
849
|
-
var PlanSchema =
|
|
1099
|
+
var PlanSchema = z12.enum(PLANS);
|
|
850
1100
|
var QUOTA_DIMENSIONS = [
|
|
851
1101
|
/** Jumlah proyek di workspace. */
|
|
852
1102
|
"projects",
|
|
@@ -861,38 +1111,52 @@ var QUOTA_DIMENSIONS = [
|
|
|
861
1111
|
/** Persona di workspace (semua proyek). */
|
|
862
1112
|
"personas",
|
|
863
1113
|
/** Indeks skill per repo yang disinkronkan ke Cloud. */
|
|
864
|
-
"skills"
|
|
1114
|
+
"skills",
|
|
1115
|
+
/** Dokumen proyek di Cloud (blueprint, ERD, ...) di workspace. */
|
|
1116
|
+
"documents",
|
|
1117
|
+
/** Panjang maksimum satu dokumen (karakter). Pemakaian = dokumen terpanjang. */
|
|
1118
|
+
"document_chars",
|
|
1119
|
+
/** Repo yang dikenal satu proyek (mis. be, fe, qa). Pemakaian = proyek dengan repo terbanyak. */
|
|
1120
|
+
"repos_per_project",
|
|
1121
|
+
/** Task yang dipindah ke kolom Revisi per bulan oleh manusia (Web) atau orchestrator. */
|
|
1122
|
+
"revisions_per_month",
|
|
1123
|
+
/** Task yang sedang dikerjakan bersamaan (IN_PROGRESS) di workspace. */
|
|
1124
|
+
"active_tasks",
|
|
1125
|
+
/** Panggilan search_context per hari kalender. */
|
|
1126
|
+
"search_queries_per_day",
|
|
1127
|
+
/** Total karakter teks yang diindeks embedding per workspace. */
|
|
1128
|
+
"indexed_chars"
|
|
865
1129
|
];
|
|
866
|
-
var QuotaDimensionSchema =
|
|
1130
|
+
var QuotaDimensionSchema = z12.enum(QUOTA_DIMENSIONS);
|
|
867
1131
|
var QUOTA_WARNING_HEADER = "x-catenext-quota-warning";
|
|
868
|
-
var QuotaExceededDetailsSchema =
|
|
1132
|
+
var QuotaExceededDetailsSchema = z12.object({
|
|
869
1133
|
dimension: QuotaDimensionSchema,
|
|
870
1134
|
plan: PlanSchema,
|
|
871
|
-
limit:
|
|
872
|
-
used:
|
|
1135
|
+
limit: z12.number().int(),
|
|
1136
|
+
used: z12.number().int(),
|
|
873
1137
|
/** Kapan kuota bulanan direset; null untuk kuota jumlah (proyek, persona, ...). */
|
|
874
1138
|
reset_at: IsoDateTimeSchema.nullable(),
|
|
875
|
-
upgrade_url:
|
|
1139
|
+
upgrade_url: z12.string()
|
|
876
1140
|
});
|
|
877
|
-
var UsageItemSchema =
|
|
1141
|
+
var UsageItemSchema = z12.object({
|
|
878
1142
|
dimension: QuotaDimensionSchema,
|
|
879
|
-
label:
|
|
880
|
-
used:
|
|
881
|
-
limit:
|
|
1143
|
+
label: z12.string(),
|
|
1144
|
+
used: z12.number().int().min(0),
|
|
1145
|
+
limit: z12.number().int().nullable()
|
|
882
1146
|
});
|
|
883
|
-
var UsageOutput =
|
|
1147
|
+
var UsageOutput = z12.object({
|
|
884
1148
|
plan: PlanSchema,
|
|
885
|
-
plans:
|
|
886
|
-
|
|
1149
|
+
plans: z12.array(
|
|
1150
|
+
z12.object({
|
|
887
1151
|
plan: PlanSchema,
|
|
888
|
-
available:
|
|
889
|
-
limits:
|
|
1152
|
+
available: z12.boolean(),
|
|
1153
|
+
limits: z12.record(z12.string(), z12.number().nullable())
|
|
890
1154
|
})
|
|
891
1155
|
),
|
|
892
1156
|
period_start: IsoDateTimeSchema,
|
|
893
1157
|
reset_at: IsoDateTimeSchema,
|
|
894
|
-
retention_days:
|
|
895
|
-
usage:
|
|
1158
|
+
retention_days: z12.number().int().nullable(),
|
|
1159
|
+
usage: z12.array(UsageItemSchema)
|
|
896
1160
|
});
|
|
897
1161
|
|
|
898
1162
|
// src/index.ts
|
|
@@ -1055,7 +1319,7 @@ async function findProjectRoot(start = process.cwd()) {
|
|
|
1055
1319
|
import { chmod, mkdir, readFile as readFile2, rename, writeFile } from "node:fs/promises";
|
|
1056
1320
|
import { homedir } from "node:os";
|
|
1057
1321
|
import { join as join2 } from "node:path";
|
|
1058
|
-
import { z as
|
|
1322
|
+
import { z as z13 } from "zod";
|
|
1059
1323
|
function catenextHome() {
|
|
1060
1324
|
return process.env.CATENEXT_HOME ?? join2(homedir(), ".catenext");
|
|
1061
1325
|
}
|
|
@@ -1064,10 +1328,10 @@ function credentialsPath() {
|
|
|
1064
1328
|
}
|
|
1065
1329
|
var PRODUCTION_API_URL = "https://catenext.mapan.digital";
|
|
1066
1330
|
var DEFAULT_API_URL = PRODUCTION_API_URL;
|
|
1067
|
-
var CredentialsSchema =
|
|
1068
|
-
api_key:
|
|
1069
|
-
api_url:
|
|
1070
|
-
saved_at:
|
|
1331
|
+
var CredentialsSchema = z13.object({
|
|
1332
|
+
api_key: z13.string().startsWith(API_KEY_PREFIX),
|
|
1333
|
+
api_url: z13.url().optional(),
|
|
1334
|
+
saved_at: z13.string().optional()
|
|
1071
1335
|
});
|
|
1072
1336
|
var CredentialsError = class extends Error {
|
|
1073
1337
|
constructor(message) {
|
|
@@ -1244,12 +1508,178 @@ async function deviceLogin(opts) {
|
|
|
1244
1508
|
}
|
|
1245
1509
|
|
|
1246
1510
|
// src/fallback.ts
|
|
1247
|
-
import { execFile } from "node:child_process";
|
|
1511
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
1248
1512
|
import { randomUUID } from "node:crypto";
|
|
1249
|
-
import { promisify } from "node:util";
|
|
1513
|
+
import { promisify as promisify2 } from "node:util";
|
|
1250
1514
|
|
|
1251
1515
|
// src/planning.ts
|
|
1252
|
-
import { readFile as
|
|
1516
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
1517
|
+
|
|
1518
|
+
// src/code-search.ts
|
|
1519
|
+
import { execFile } from "node:child_process";
|
|
1520
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1521
|
+
import { mkdir as mkdir2, readdir, readFile as readFile3, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
1522
|
+
import { join as join3, relative } from "node:path";
|
|
1523
|
+
import { promisify } from "node:util";
|
|
1524
|
+
var execFileAsync = promisify(execFile);
|
|
1525
|
+
var CACHE_DIR = ".catenext/cache/code-embeddings";
|
|
1526
|
+
var TEXT_EXT = /* @__PURE__ */ new Set([
|
|
1527
|
+
".ts",
|
|
1528
|
+
".tsx",
|
|
1529
|
+
".js",
|
|
1530
|
+
".jsx",
|
|
1531
|
+
".mjs",
|
|
1532
|
+
".cjs",
|
|
1533
|
+
".md",
|
|
1534
|
+
".mdx",
|
|
1535
|
+
".json",
|
|
1536
|
+
".yml",
|
|
1537
|
+
".yaml",
|
|
1538
|
+
".toml",
|
|
1539
|
+
".css",
|
|
1540
|
+
".scss",
|
|
1541
|
+
".html",
|
|
1542
|
+
".py",
|
|
1543
|
+
".rs",
|
|
1544
|
+
".go",
|
|
1545
|
+
".java",
|
|
1546
|
+
".kt",
|
|
1547
|
+
".swift",
|
|
1548
|
+
".sql",
|
|
1549
|
+
".sh"
|
|
1550
|
+
]);
|
|
1551
|
+
function hashEmbed(text2, dims = LOCAL_EMBED_DIMS) {
|
|
1552
|
+
const vec = new Array(dims).fill(0);
|
|
1553
|
+
const tokens = text2.toLowerCase().split(/[^a-z0-9_\u00c0-\u024f]+/i).filter(Boolean);
|
|
1554
|
+
for (const tok of tokens) {
|
|
1555
|
+
const h = createHash2("sha256").update(tok).digest();
|
|
1556
|
+
const i = h.readUInt32BE(0) % dims;
|
|
1557
|
+
const sign = (h[4] ?? 0) & 1 ? 1 : -1;
|
|
1558
|
+
vec[i] = (vec[i] ?? 0) + sign;
|
|
1559
|
+
}
|
|
1560
|
+
if (tokens.length === 0) vec[0] = 1;
|
|
1561
|
+
let s = 0;
|
|
1562
|
+
for (const x of vec) s += x * x;
|
|
1563
|
+
const n = Math.sqrt(s) || 1;
|
|
1564
|
+
return vec.map((x) => x / n);
|
|
1565
|
+
}
|
|
1566
|
+
function cosine(a, b) {
|
|
1567
|
+
const n = Math.min(a.length, b.length);
|
|
1568
|
+
let dot = 0;
|
|
1569
|
+
for (let i = 0; i < n; i++) dot += (a[i] ?? 0) * (b[i] ?? 0);
|
|
1570
|
+
return dot;
|
|
1571
|
+
}
|
|
1572
|
+
function sha256(text2) {
|
|
1573
|
+
return createHash2("sha256").update(text2, "utf8").digest("hex");
|
|
1574
|
+
}
|
|
1575
|
+
async function listTrackedFiles(root) {
|
|
1576
|
+
try {
|
|
1577
|
+
const { stdout } = await execFileAsync("git", ["ls-files", "-z"], {
|
|
1578
|
+
cwd: root,
|
|
1579
|
+
maxBuffer: 2e7
|
|
1580
|
+
});
|
|
1581
|
+
return stdout.split("\0").filter(Boolean).filter((p) => {
|
|
1582
|
+
const ext = p.includes(".") ? `.${p.split(".").pop()?.toLowerCase()}` : "";
|
|
1583
|
+
return TEXT_EXT.has(ext) && !p.startsWith(".catenext/cache/");
|
|
1584
|
+
});
|
|
1585
|
+
} catch {
|
|
1586
|
+
return walkFallback(root, root);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
async function walkFallback(root, dir) {
|
|
1590
|
+
const out = [];
|
|
1591
|
+
let entries;
|
|
1592
|
+
try {
|
|
1593
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
1594
|
+
} catch {
|
|
1595
|
+
return out;
|
|
1596
|
+
}
|
|
1597
|
+
for (const e of entries) {
|
|
1598
|
+
if (e.name === "node_modules" || e.name === ".git" || e.name === "dist" || e.name === ".next")
|
|
1599
|
+
continue;
|
|
1600
|
+
const abs = join3(dir, e.name);
|
|
1601
|
+
if (e.isDirectory()) {
|
|
1602
|
+
out.push(...await walkFallback(root, abs));
|
|
1603
|
+
continue;
|
|
1604
|
+
}
|
|
1605
|
+
const rel = relative(root, abs);
|
|
1606
|
+
const ext = rel.includes(".") ? `.${rel.split(".").pop()?.toLowerCase()}` : "";
|
|
1607
|
+
if (TEXT_EXT.has(ext)) out.push(rel);
|
|
1608
|
+
}
|
|
1609
|
+
return out;
|
|
1610
|
+
}
|
|
1611
|
+
async function loadEntry(cacheRoot, rel) {
|
|
1612
|
+
const key = sha256(rel).slice(0, 24);
|
|
1613
|
+
try {
|
|
1614
|
+
return JSON.parse(await readFile3(join3(cacheRoot, `${key}.json`), "utf8"));
|
|
1615
|
+
} catch {
|
|
1616
|
+
return null;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
async function saveEntry(cacheRoot, rel, entry) {
|
|
1620
|
+
const key = sha256(rel).slice(0, 24);
|
|
1621
|
+
await writeFile2(join3(cacheRoot, `${key}.json`), JSON.stringify({ ...entry, path: rel }));
|
|
1622
|
+
}
|
|
1623
|
+
async function searchLocalCode(root, query, limit = 8) {
|
|
1624
|
+
const cacheRoot = join3(root, CACHE_DIR);
|
|
1625
|
+
await mkdir2(cacheRoot, { recursive: true });
|
|
1626
|
+
const files = await listTrackedFiles(root);
|
|
1627
|
+
const qVec = hashEmbed(query);
|
|
1628
|
+
const scored = [];
|
|
1629
|
+
for (const rel of files) {
|
|
1630
|
+
const abs = join3(root, rel);
|
|
1631
|
+
let st;
|
|
1632
|
+
try {
|
|
1633
|
+
st = await stat(abs);
|
|
1634
|
+
} catch {
|
|
1635
|
+
continue;
|
|
1636
|
+
}
|
|
1637
|
+
if (st.size > 2e5) continue;
|
|
1638
|
+
let text2;
|
|
1639
|
+
try {
|
|
1640
|
+
text2 = await readFile3(abs, "utf8");
|
|
1641
|
+
} catch {
|
|
1642
|
+
continue;
|
|
1643
|
+
}
|
|
1644
|
+
const sha = sha256(text2);
|
|
1645
|
+
let entry = await loadEntry(cacheRoot, rel);
|
|
1646
|
+
if (!entry || entry.sha !== sha) {
|
|
1647
|
+
const snippet = text2.slice(0, 400).replace(/\s+/g, " ").trim();
|
|
1648
|
+
entry = { sha, vector: hashEmbed(text2.slice(0, 8e3)), snippet, mtimeMs: st.mtimeMs };
|
|
1649
|
+
await saveEntry(cacheRoot, rel, entry);
|
|
1650
|
+
}
|
|
1651
|
+
scored.push({
|
|
1652
|
+
source: "code",
|
|
1653
|
+
ref: rel,
|
|
1654
|
+
title: rel,
|
|
1655
|
+
snippet: entry.snippet,
|
|
1656
|
+
score: cosine(qVec, entry.vector)
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1660
|
+
return {
|
|
1661
|
+
hits: scored.slice(0, limit),
|
|
1662
|
+
degraded: true,
|
|
1663
|
+
note: process.env.CATENEXT_EMBEDDING_API_KEY ? void 0 : "Tanpa CATENEXT_EMBEDDING_API_KEY: embedding kode memakai hash lokal (degraded)."
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
async function keywordFallback(root, query, limit = 8) {
|
|
1667
|
+
try {
|
|
1668
|
+
const { stdout } = await execFileAsync("rg", ["-l", "--max-count", "1", "-i", query, "."], {
|
|
1669
|
+
cwd: root,
|
|
1670
|
+
maxBuffer: 5e6
|
|
1671
|
+
});
|
|
1672
|
+
return stdout.split("\n").map((l) => l.trim()).filter(Boolean).slice(0, limit).map((rel) => ({
|
|
1673
|
+
source: "code",
|
|
1674
|
+
ref: rel,
|
|
1675
|
+
title: rel,
|
|
1676
|
+
snippet: `Keyword match: ${query}`,
|
|
1677
|
+
score: 0.1
|
|
1678
|
+
}));
|
|
1679
|
+
} catch {
|
|
1680
|
+
return [];
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1253
1683
|
|
|
1254
1684
|
// src/scrubber.ts
|
|
1255
1685
|
var redact = (kind) => `[REDACTED:${kind}]`;
|
|
@@ -1388,7 +1818,7 @@ async function readJsonInput(file) {
|
|
|
1388
1818
|
});
|
|
1389
1819
|
process.stdin.on("end", () => res(data));
|
|
1390
1820
|
process.stdin.on("error", rej);
|
|
1391
|
-
}) : await
|
|
1821
|
+
}) : await readFile4(file, "utf8");
|
|
1392
1822
|
} catch (err) {
|
|
1393
1823
|
throw new PlanningInputError(`Tidak bisa membaca ${file}: ${err.message}`);
|
|
1394
1824
|
}
|
|
@@ -1425,21 +1855,156 @@ async function personaList(api, asJson) {
|
|
|
1425
1855
|
);
|
|
1426
1856
|
}
|
|
1427
1857
|
for (const p of res.personas) {
|
|
1428
|
-
|
|
1858
|
+
const repos = p.repos.length > 0 ? `, repo ${p.repos.join("/")}` : "";
|
|
1859
|
+
console.log(
|
|
1860
|
+
`${p.alias} (${p.role}${repos}, ${p.scope === "project" ? "proyek" : "workspace"})`
|
|
1861
|
+
);
|
|
1429
1862
|
for (const r of p.rules) console.log(` - ${r}`);
|
|
1430
1863
|
}
|
|
1431
1864
|
}
|
|
1432
|
-
async function personaSet(api, alias, role, rules, asJson) {
|
|
1433
|
-
const body = prepare(
|
|
1865
|
+
async function personaSet(api, alias, role, rules, asJson, repos) {
|
|
1866
|
+
const body = prepare(
|
|
1867
|
+
UpsertPersonaInput,
|
|
1868
|
+
{
|
|
1869
|
+
alias,
|
|
1870
|
+
role,
|
|
1871
|
+
// Tanpa --rule: aturan lama dipertahankan (persona baru mewarisi persona master).
|
|
1872
|
+
...rules.length > 0 ? { rules } : {},
|
|
1873
|
+
...repos ? { repos } : {}
|
|
1874
|
+
},
|
|
1875
|
+
["alias", "role", "repos"]
|
|
1876
|
+
);
|
|
1434
1877
|
const res = await api.put("personas", body);
|
|
1435
1878
|
if (asJson) return console.log(JSON.stringify(res, null, 2));
|
|
1436
1879
|
console.log(
|
|
1437
|
-
`\u2713 Persona "${res.persona.alias}" (${res.persona.role}) ${res.created ? "dibuat" : "diperbarui"} untuk proyek ini, ${res.persona.rules.length} aturan.`
|
|
1880
|
+
`\u2713 Persona "${res.persona.alias}" (${res.persona.role}) ${res.created ? "dibuat" : "diperbarui"} untuk proyek ini, ${res.persona.rules.length} aturan${res.persona.repos.length > 0 ? `, memegang repo ${res.persona.repos.join(", ")}` : ""}.`
|
|
1881
|
+
);
|
|
1882
|
+
}
|
|
1883
|
+
async function boardShow(api, opts) {
|
|
1884
|
+
const body = prepare(
|
|
1885
|
+
GetProjectBoardInput,
|
|
1886
|
+
{
|
|
1887
|
+
...opts.epic ? { epic_id: opts.epic } : {},
|
|
1888
|
+
...opts.status?.length ? { status: opts.status } : {}
|
|
1889
|
+
},
|
|
1890
|
+
["epic_id", "status"]
|
|
1891
|
+
);
|
|
1892
|
+
const res = await api.post("board", body);
|
|
1893
|
+
if (opts.json) return console.log(JSON.stringify(res, null, 2));
|
|
1894
|
+
console.log("Repo:");
|
|
1895
|
+
for (const r of res.repos)
|
|
1896
|
+
console.log(
|
|
1897
|
+
` ${r.repo}: ${r.personas.length ? r.personas.join(", ") : "(belum ada persona)"}`
|
|
1898
|
+
);
|
|
1899
|
+
for (const e of res.epics) {
|
|
1900
|
+
console.log(`
|
|
1901
|
+
# ${e.title} ${JSON.stringify(e.counts)}`);
|
|
1902
|
+
for (const t of res.tasks.filter((x) => x.epic_id === e.id)) {
|
|
1903
|
+
const who = t.persona ? `@${t.persona}` : t.role ? `role ${t.role}` : "-";
|
|
1904
|
+
const flags = [t.is_ready ? "siap" : null, t.is_stale ? "stale" : null].filter(Boolean).join(",");
|
|
1905
|
+
console.log(
|
|
1906
|
+
` ${t.status.padEnd(18)} ${t.id} ${t.title} [${t.target_repo ?? "repo bebas"} \xB7 ${who}]${flags ? ` (${flags})` : ""}`
|
|
1907
|
+
);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
if (res.truncated) console.log("\n(daftar dipotong; pakai --epic untuk mempersempit)");
|
|
1911
|
+
}
|
|
1912
|
+
async function docList(api, asJson) {
|
|
1913
|
+
const res = await api.post("documents/list");
|
|
1914
|
+
if (asJson) return console.log(JSON.stringify(res, null, 2));
|
|
1915
|
+
if (res.documents.length === 0)
|
|
1916
|
+
return console.log(
|
|
1917
|
+
"Belum ada dokumen proyek. Buat dengan: catenext doc save <slug> --file <path.md>"
|
|
1918
|
+
);
|
|
1919
|
+
for (const d of res.documents)
|
|
1920
|
+
console.log(`${d.slug} v${d.version} ${d.kind} ${d.title} (${d.size} karakter)`);
|
|
1921
|
+
}
|
|
1922
|
+
async function docGet(api, slug, asJson) {
|
|
1923
|
+
const body = prepare(GetDocumentInput, { slug }, ["slug"]);
|
|
1924
|
+
const res = await api.post("documents/get", body);
|
|
1925
|
+
if (asJson) return console.log(JSON.stringify(res, null, 2));
|
|
1926
|
+
console.log(`<!-- ${res.slug} v${res.version} (${res.kind}) -->`);
|
|
1927
|
+
console.log(res.content);
|
|
1928
|
+
}
|
|
1929
|
+
async function docSave(api, slug, opts) {
|
|
1930
|
+
const content = await readFile4(opts.file, "utf8");
|
|
1931
|
+
const body = prepare(
|
|
1932
|
+
SaveDocumentInput,
|
|
1933
|
+
{
|
|
1934
|
+
slug,
|
|
1935
|
+
title: opts.title ?? slug,
|
|
1936
|
+
kind: opts.kind,
|
|
1937
|
+
content,
|
|
1938
|
+
...opts.version !== void 0 ? { expected_version: Number(opts.version) } : {}
|
|
1939
|
+
},
|
|
1940
|
+
["slug", "kind", "expected_version"]
|
|
1941
|
+
);
|
|
1942
|
+
const res = await api.put("documents", body);
|
|
1943
|
+
if (opts.json) return console.log(JSON.stringify(res, null, 2));
|
|
1944
|
+
console.log(
|
|
1945
|
+
`\u2713 Dokumen "${res.document.slug}" ${res.created ? "dibuat" : "diperbarui"} (v${res.document.version}).`
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
var CLOUD_SOURCES = new Set(SEARCH_SOURCES);
|
|
1949
|
+
async function searchShow(api, query, opts) {
|
|
1950
|
+
const scrubbed = scrubDeep({ query }, /* @__PURE__ */ new Set());
|
|
1951
|
+
if (scrubbed.total > 0) console.error(`! ${describeRedactions(scrubbed)}`);
|
|
1952
|
+
const q = String(scrubbed.value.query).trim();
|
|
1953
|
+
if (!q) throw new PlanningInputError("Query kosong.");
|
|
1954
|
+
const wanted = opts.source?.length ? opts.source : ["document", "skill", "task", "code"];
|
|
1955
|
+
const cloudSources = wanted.filter(
|
|
1956
|
+
(s) => CLOUD_SOURCES.has(s)
|
|
1438
1957
|
);
|
|
1958
|
+
const wantCode = wanted.includes("code");
|
|
1959
|
+
const limit = opts.limit ?? 8;
|
|
1960
|
+
let cloud = null;
|
|
1961
|
+
if (cloudSources.length > 0) {
|
|
1962
|
+
const body = prepare(SearchContextInput, { query: q, sources: cloudSources, limit }, [
|
|
1963
|
+
"sources",
|
|
1964
|
+
"limit"
|
|
1965
|
+
]);
|
|
1966
|
+
cloud = await api.post("search", body);
|
|
1967
|
+
}
|
|
1968
|
+
let codeHits = [];
|
|
1969
|
+
let codeNote;
|
|
1970
|
+
if (wantCode) {
|
|
1971
|
+
const root = await findProjectRoot();
|
|
1972
|
+
if (root) {
|
|
1973
|
+
try {
|
|
1974
|
+
const local = await searchLocalCode(root, q, limit);
|
|
1975
|
+
codeHits = local.hits;
|
|
1976
|
+
codeNote = local.note;
|
|
1977
|
+
if (codeHits.length === 0) codeHits = await keywordFallback(root, q, limit);
|
|
1978
|
+
} catch (err) {
|
|
1979
|
+
codeNote = `Indeks kode gagal: ${err.message}. Fallback keyword.`;
|
|
1980
|
+
codeHits = await keywordFallback(root, q, limit);
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
const merged = [
|
|
1985
|
+
...(cloud?.hits ?? []).map((h) => ({ ...h, origin: "cloud" })),
|
|
1986
|
+
...codeHits.map((h) => ({ ...h, origin: "local" }))
|
|
1987
|
+
].sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1988
|
+
const payload = {
|
|
1989
|
+
hits: merged,
|
|
1990
|
+
reranked: cloud?.reranked ?? false,
|
|
1991
|
+
degraded: cloud?.degraded ?? true,
|
|
1992
|
+
...codeNote ? { note: codeNote } : {}
|
|
1993
|
+
};
|
|
1994
|
+
if (opts.json) return console.log(JSON.stringify(payload, null, 2));
|
|
1995
|
+
if (merged.length === 0) return console.log("Tidak ada hasil.");
|
|
1996
|
+
for (const h of merged) {
|
|
1997
|
+
console.log(
|
|
1998
|
+
`${h.score.toFixed(3)} [${h.source}] ${h.ref} ${h.title}
|
|
1999
|
+
${h.snippet.slice(0, 120)}`
|
|
2000
|
+
);
|
|
2001
|
+
}
|
|
2002
|
+
if (payload.degraded) console.error("! Mode degraded (embedding/rerank lokal atau tanpa key).");
|
|
2003
|
+
if (codeNote) console.error(`! ${codeNote}`);
|
|
1439
2004
|
}
|
|
1440
2005
|
|
|
1441
2006
|
// src/fallback.ts
|
|
1442
|
-
var exec =
|
|
2007
|
+
var exec = promisify2(execFile2);
|
|
1443
2008
|
async function git(args, cwd) {
|
|
1444
2009
|
try {
|
|
1445
2010
|
const { stdout } = await exec("git", args, { cwd });
|
|
@@ -1476,8 +2041,9 @@ async function taskNext(api, opts) {
|
|
|
1476
2041
|
}
|
|
1477
2042
|
console.log(
|
|
1478
2043
|
`
|
|
1479
|
-
Ambil satu: catenext claim ${res.tasks[0]?.id}${opts.as ? ` --as ${opts.as}` : ""}`
|
|
2044
|
+
Ambil satu: catenext claim ${res.tasks[0]?.id}${opts.as ? ` --as ${opts.as}` : ""} [--worktree]`
|
|
1480
2045
|
);
|
|
2046
|
+
console.log(" (Monorepo: --worktree wajib. Polyrepo: opsional.)");
|
|
1481
2047
|
}
|
|
1482
2048
|
function renderClaim(res) {
|
|
1483
2049
|
const out = [];
|
|
@@ -1517,12 +2083,23 @@ function renderClaim(res) {
|
|
|
1517
2083
|
out.push(
|
|
1518
2084
|
"## Setelah selesai",
|
|
1519
2085
|
"",
|
|
1520
|
-
|
|
2086
|
+
"Commit di branch/worktree ini OK. Jangan merge ke default branch \u2014 serahkan lewat PR.",
|
|
2087
|
+
`catenext done ${res.task.id} --notes "<ringkasan>" --verify "<perintah tes>" --pr <url> --base <branch>${res.lease_id ? ` --lease ${res.lease_id}` : ""}`,
|
|
1521
2088
|
`Bila buntu: catenext block ${res.task.id} --category <kategori> --reason "<alasan spesifik>"`
|
|
1522
2089
|
);
|
|
1523
2090
|
return out.join("\n");
|
|
1524
2091
|
}
|
|
1525
2092
|
async function taskClaim(api, taskId, opts) {
|
|
2093
|
+
if (!opts.worktree) {
|
|
2094
|
+
const ctx = await api.post("context", {
|
|
2095
|
+
...opts.as ? { agent_alias: opts.as } : {}
|
|
2096
|
+
});
|
|
2097
|
+
if (ctx.project.layout === "monorepo") {
|
|
2098
|
+
throw new PlanningInputError(
|
|
2099
|
+
"Proyek ini layout monorepo: claim wajib --worktree (branch/sesi terpisah). Contoh: catenext claim <id> --worktree"
|
|
2100
|
+
);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
1526
2103
|
const branch = opts.worktree ? await git(["symbolic-ref", "--short", "HEAD"], process.cwd()) : null;
|
|
1527
2104
|
if (opts.worktree && !branch)
|
|
1528
2105
|
throw new PlanningInputError("Checkout branch kerja sebelum memakai --worktree.");
|
|
@@ -1550,8 +2127,11 @@ function buildHandoff(opts, gitState) {
|
|
|
1550
2127
|
"Tidak bisa membaca branch/commit git. Jalankan di dalam repo git dan commit pekerjaan Anda dulu."
|
|
1551
2128
|
);
|
|
1552
2129
|
}
|
|
1553
|
-
if (
|
|
1554
|
-
throw new PlanningInputError(
|
|
2130
|
+
if (!opts.pr || !opts.base) {
|
|
2131
|
+
throw new PlanningInputError(
|
|
2132
|
+
"--pr dan --base wajib: buat PR di branch kerja lalu `catenext done \u2026 --pr <url> --base <branch>`."
|
|
2133
|
+
);
|
|
2134
|
+
}
|
|
1555
2135
|
const files = opts.file.length ? opts.file : gitState.changedFiles;
|
|
1556
2136
|
return {
|
|
1557
2137
|
files_modified: files.slice(0, HANDOFF_LIMITS.maxFilesModified),
|
|
@@ -1560,7 +2140,7 @@ function buildHandoff(opts, gitState) {
|
|
|
1560
2140
|
notes_for_next_agent: opts.notes,
|
|
1561
2141
|
git_branch: gitState.branch,
|
|
1562
2142
|
last_commit_hash: gitState.commit,
|
|
1563
|
-
|
|
2143
|
+
pull_request: { url: opts.pr, base_branch: opts.base, head_sha: gitState.commit }
|
|
1564
2144
|
};
|
|
1565
2145
|
}
|
|
1566
2146
|
async function taskDone(api, taskId, opts) {
|
|
@@ -1572,9 +2152,7 @@ async function taskDone(api, taskId, opts) {
|
|
|
1572
2152
|
);
|
|
1573
2153
|
const res = await api.post("complete", body);
|
|
1574
2154
|
if (opts.json) return console.log(JSON.stringify(res, null, 2));
|
|
1575
|
-
console.log(
|
|
1576
|
-
res.status === "DONE" ? `\u2713 Task selesai (DONE). ${res.unlocked_task_ids.length} task hilir terbuka.` : "\u2713 Handoff terkirim, menunggu review (NEEDS_REVIEW)."
|
|
1577
|
-
);
|
|
2155
|
+
console.log("\u2713 Handoff + PR terkirim (NEEDS_REVIEW). Menunggu review/merge manusia.");
|
|
1578
2156
|
console.log(` ${res.next_step_hint}`);
|
|
1579
2157
|
}
|
|
1580
2158
|
async function taskBlock(api, taskId, opts) {
|
|
@@ -1608,10 +2186,28 @@ async function taskReview(api, input, json2) {
|
|
|
1608
2186
|
}
|
|
1609
2187
|
if ("warning" in result && result.warning) process.exitCode = 1;
|
|
1610
2188
|
}
|
|
2189
|
+
async function taskManage(api, input, json2) {
|
|
2190
|
+
const body = prepare(ManageTaskInput, input, ["action", "task_id", "agent_alias", "role"]);
|
|
2191
|
+
const res = await api.post("tasks/manage", body);
|
|
2192
|
+
if (json2) return console.log(JSON.stringify(res, null, 2));
|
|
2193
|
+
const owner = res.persona ? `@${res.persona}` : res.role ? `role ${res.role}` : "tanpa persona";
|
|
2194
|
+
if (body.action === "request_revision") {
|
|
2195
|
+
console.log(
|
|
2196
|
+
`\u2713 Task dipindah ke kolom Revisi (revisi ke-${res.revision_count}) untuk ${owner}.`
|
|
2197
|
+
);
|
|
2198
|
+
console.log(
|
|
2199
|
+
res.persona ? ` Delegasikan ke subagent ${res.persona}; ia akan mengambilnya lewat claim_task.` : " Subagent dengan role yang cocok dapat mengambilnya lewat claim_task."
|
|
2200
|
+
);
|
|
2201
|
+
if (res.stale_task_ids.length > 0)
|
|
2202
|
+
console.log(` ${res.stale_task_ids.length} task hilir ditandai stale.`);
|
|
2203
|
+
} else {
|
|
2204
|
+
console.log(`\u2713 Penanggung jawab task: ${owner} (status ${res.status}).`);
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
1611
2207
|
|
|
1612
2208
|
// src/init/index.ts
|
|
1613
|
-
import { mkdir as
|
|
1614
|
-
import { basename, dirname as dirname2, join as
|
|
2209
|
+
import { mkdir as mkdir3, readFile as readFile6, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
|
|
2210
|
+
import { basename, dirname as dirname2, join as join5, resolve as resolve2 } from "node:path";
|
|
1615
2211
|
import { createTwoFilesPatch } from "diff";
|
|
1616
2212
|
|
|
1617
2213
|
// src/init/agents-md.ts
|
|
@@ -1621,25 +2217,15 @@ var BLOCK_END = "<!-- catenext:end -->";
|
|
|
1621
2217
|
function renderAgentsBlock() {
|
|
1622
2218
|
return [
|
|
1623
2219
|
BLOCK_START,
|
|
1624
|
-
"## Catenext:
|
|
2220
|
+
"## Catenext: orchestrator & subagent",
|
|
1625
2221
|
"",
|
|
1626
|
-
"Repo ini memakai Catenext
|
|
1627
|
-
"(`get_project_context` -> `get_ready_tasks` -> `claim_task` -> `complete_handoff`).",
|
|
1628
|
-
"Bila tidak, pakai CLI berikut:",
|
|
2222
|
+
"Repo ini memakai Catenext lewat tool MCP `catenext` (atau CLI `catenext` bila MCP tidak ada).",
|
|
1629
2223
|
"",
|
|
1630
|
-
|
|
1631
|
-
"2. `catenext claim <task_id>`: kunci task dan baca instruksi + handoff dependensinya.",
|
|
1632
|
-
"3. Kerjakan, jalankan tes, lalu commit.",
|
|
1633
|
-
'4. `catenext done <task_id> --notes "<ringkasan>" --verify "<perintah tes>" [--decision "..."]`',
|
|
1634
|
-
'5. Bila buntu: `catenext block <task_id> --category <missing_env|ambiguous_requirement|failing_tests|dependency_issue|other> --reason "..."`',
|
|
2224
|
+
...ORCHESTRATOR_RULES,
|
|
1635
2225
|
"",
|
|
1636
|
-
|
|
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/`.",
|
|
2226
|
+
...CLI_FALLBACK_RULES,
|
|
1640
2227
|
"",
|
|
1641
|
-
|
|
1642
|
-
"jangan mengedit `.catenext/config.yaml`. Skill repo ada di `.catenext/skills/`.",
|
|
2228
|
+
...GENERAL_RULES,
|
|
1643
2229
|
BLOCK_END
|
|
1644
2230
|
].join("\n");
|
|
1645
2231
|
}
|
|
@@ -1689,30 +2275,30 @@ function renderNewConfig(f) {
|
|
|
1689
2275
|
return out;
|
|
1690
2276
|
}
|
|
1691
2277
|
function updateConfig(source, changes) {
|
|
1692
|
-
const
|
|
2278
|
+
const doc2 = parseDocument(source);
|
|
1693
2279
|
for (const [key, value] of Object.entries(changes)) {
|
|
1694
2280
|
if (value === void 0) continue;
|
|
1695
|
-
if (JSON.stringify(
|
|
1696
|
-
|
|
2281
|
+
if (JSON.stringify(doc2.get(key)) === JSON.stringify(value)) continue;
|
|
2282
|
+
doc2.set(key, value);
|
|
1697
2283
|
}
|
|
1698
|
-
const out =
|
|
2284
|
+
const out = doc2.toString();
|
|
1699
2285
|
if (out === parseDocument(source).toString()) return source;
|
|
1700
2286
|
parseConfig(out);
|
|
1701
2287
|
return out;
|
|
1702
2288
|
}
|
|
1703
2289
|
|
|
1704
2290
|
// src/init/detect.ts
|
|
1705
|
-
import { readFile as
|
|
1706
|
-
import { join as
|
|
1707
|
-
var exists = async (p) =>
|
|
2291
|
+
import { readFile as readFile5 } from "node:fs/promises";
|
|
2292
|
+
import { join as join4 } from "node:path";
|
|
2293
|
+
var exists = async (p) => readFile5(p, "utf8").then(
|
|
1708
2294
|
(s) => s,
|
|
1709
2295
|
() => null
|
|
1710
2296
|
);
|
|
1711
2297
|
async function detectStack(root) {
|
|
1712
2298
|
const stack = /* @__PURE__ */ new Set();
|
|
1713
|
-
const goMod = await exists(
|
|
2299
|
+
const goMod = await exists(join4(root, "go.mod"));
|
|
1714
2300
|
if (goMod !== null) stack.add("go");
|
|
1715
|
-
const pkg = await exists(
|
|
2301
|
+
const pkg = await exists(join4(root, "package.json"));
|
|
1716
2302
|
if (pkg !== null) {
|
|
1717
2303
|
stack.add("node");
|
|
1718
2304
|
try {
|
|
@@ -1734,32 +2320,43 @@ async function detectStack(root) {
|
|
|
1734
2320
|
} catch {
|
|
1735
2321
|
}
|
|
1736
2322
|
}
|
|
1737
|
-
const composer = await exists(
|
|
2323
|
+
const composer = await exists(join4(root, "composer.json"));
|
|
1738
2324
|
if (composer !== null) {
|
|
1739
2325
|
stack.add("php");
|
|
1740
2326
|
if (composer.includes('"laravel/framework"')) stack.add("laravel");
|
|
1741
2327
|
}
|
|
1742
|
-
if (await exists(
|
|
1743
|
-
else if (await exists(
|
|
1744
|
-
if (await exists(
|
|
2328
|
+
if (await exists(join4(root, "pyproject.toml")) !== null) stack.add("python");
|
|
2329
|
+
else if (await exists(join4(root, "requirements.txt")) !== null) stack.add("python");
|
|
2330
|
+
if (await exists(join4(root, "Cargo.toml")) !== null) stack.add("rust");
|
|
1745
2331
|
return [...stack].slice(0, 20);
|
|
1746
2332
|
}
|
|
1747
2333
|
|
|
1748
2334
|
// src/init/gitignore.ts
|
|
1749
2335
|
var CACHE_IGNORE = ".catenext/cache.json";
|
|
2336
|
+
var CACHE_DIR_IGNORE = ".catenext/cache/";
|
|
1750
2337
|
var COVERS = /* @__PURE__ */ new Set([
|
|
1751
2338
|
CACHE_IGNORE,
|
|
1752
2339
|
`/${CACHE_IGNORE}`,
|
|
1753
2340
|
".catenext/cache.json",
|
|
1754
|
-
".catenext/*.json"
|
|
2341
|
+
".catenext/*.json",
|
|
2342
|
+
CACHE_DIR_IGNORE,
|
|
2343
|
+
`/${CACHE_DIR_IGNORE}`,
|
|
2344
|
+
".catenext/cache"
|
|
1755
2345
|
]);
|
|
1756
2346
|
function ensureGitignore(source) {
|
|
1757
2347
|
const text2 = source ?? "";
|
|
1758
2348
|
const lines = text2.split(/\r?\n/).map((l) => l.trim());
|
|
1759
|
-
if (lines.some((l) => COVERS.has(l))) return text2;
|
|
1760
2349
|
const eol = text2.includes("\r\n") ? "\r\n" : "\n";
|
|
2350
|
+
const missing = [];
|
|
2351
|
+
if (!lines.some((l) => COVERS.has(l) || l === CACHE_IGNORE)) missing.push(CACHE_IGNORE);
|
|
2352
|
+
if (!lines.some(
|
|
2353
|
+
(l) => l === CACHE_DIR_IGNORE || l === ".catenext/cache" || l === `/${CACHE_DIR_IGNORE}`
|
|
2354
|
+
)) {
|
|
2355
|
+
missing.push(CACHE_DIR_IGNORE);
|
|
2356
|
+
}
|
|
2357
|
+
if (missing.length === 0) return text2;
|
|
1761
2358
|
const prefix = text2 === "" ? "" : text2.endsWith("\n") ? eol : `${eol}${eol}`;
|
|
1762
|
-
return `${text2}${prefix}# Catenext: cache lokal, jangan di-commit${eol}${
|
|
2359
|
+
return `${text2}${prefix}# Catenext: cache lokal, jangan di-commit${eol}${missing.join(eol)}${eol}`;
|
|
1763
2360
|
}
|
|
1764
2361
|
|
|
1765
2362
|
// src/init/mcp-config.ts
|
|
@@ -1793,13 +2390,13 @@ function detectFormatting(source) {
|
|
|
1793
2390
|
function upsertMcpEntry(source, entry, file) {
|
|
1794
2391
|
const base = source && source.trim() !== "" ? source : "{}\n";
|
|
1795
2392
|
const errors = [];
|
|
1796
|
-
const
|
|
1797
|
-
if (errors.length > 0 ||
|
|
2393
|
+
const doc2 = parse2(base, errors, { allowTrailingComma: true, disallowComments: false });
|
|
2394
|
+
if (errors.length > 0 || doc2 === null || typeof doc2 !== "object" || Array.isArray(doc2)) {
|
|
1798
2395
|
throw new McpConfigError(
|
|
1799
2396
|
`${file} bukan JSON/JSONC objek yang valid, jadi tidak disentuh. Perbaiki manual lalu jalankan ulang \`catenext init\`.`
|
|
1800
2397
|
);
|
|
1801
2398
|
}
|
|
1802
|
-
const servers =
|
|
2399
|
+
const servers = doc2.mcpServers;
|
|
1803
2400
|
if (servers !== void 0 && (servers === null || typeof servers !== "object" || Array.isArray(servers))) {
|
|
1804
2401
|
throw new McpConfigError(`${file}: "mcpServers" harus berupa objek. Perbaiki manual dulu.`);
|
|
1805
2402
|
}
|
|
@@ -1814,14 +2411,14 @@ function upsertMcpEntry(source, entry, file) {
|
|
|
1814
2411
|
}
|
|
1815
2412
|
function readMcpEntry(source) {
|
|
1816
2413
|
const errors = [];
|
|
1817
|
-
const
|
|
2414
|
+
const doc2 = parse2(source, errors, { allowTrailingComma: true });
|
|
1818
2415
|
if (errors.length > 0) return null;
|
|
1819
|
-
const entry =
|
|
2416
|
+
const entry = doc2?.mcpServers?.[MCP_SERVER_KEY];
|
|
1820
2417
|
return entry && typeof entry.command === "string" && Array.isArray(entry.args) ? entry : null;
|
|
1821
2418
|
}
|
|
1822
2419
|
|
|
1823
2420
|
// src/init/index.ts
|
|
1824
|
-
var readOrNull = (p) =>
|
|
2421
|
+
var readOrNull = (p) => readFile6(p, "utf8").then(
|
|
1825
2422
|
(s) => s,
|
|
1826
2423
|
() => null
|
|
1827
2424
|
);
|
|
@@ -1839,7 +2436,7 @@ async function planInit(opts) {
|
|
|
1839
2436
|
);
|
|
1840
2437
|
}
|
|
1841
2438
|
const changes = [];
|
|
1842
|
-
const configBefore = await readOrNull(
|
|
2439
|
+
const configBefore = await readOrNull(join5(root, CONFIG_PATH));
|
|
1843
2440
|
let configAfter;
|
|
1844
2441
|
if (configBefore === null) {
|
|
1845
2442
|
if (!opts.projectId) {
|
|
@@ -1863,7 +2460,7 @@ async function planInit(opts) {
|
|
|
1863
2460
|
}
|
|
1864
2461
|
changes.push({ path: CONFIG_PATH, before: configBefore, after: configAfter });
|
|
1865
2462
|
for (const adapter of ADAPTERS) {
|
|
1866
|
-
const before = await readOrNull(
|
|
2463
|
+
const before = await readOrNull(join5(root, adapter.path));
|
|
1867
2464
|
const entry = {
|
|
1868
2465
|
command: opts.mcpCommand.command,
|
|
1869
2466
|
args: [...opts.mcpCommand.args, "mcp", ...adapter.extraArgs]
|
|
@@ -1874,14 +2471,14 @@ async function planInit(opts) {
|
|
|
1874
2471
|
after: upsertMcpEntry(before, entry, adapter.path)
|
|
1875
2472
|
});
|
|
1876
2473
|
}
|
|
1877
|
-
const gitignoreBefore = await readOrNull(
|
|
2474
|
+
const gitignoreBefore = await readOrNull(join5(root, ".gitignore"));
|
|
1878
2475
|
changes.push({
|
|
1879
2476
|
path: ".gitignore",
|
|
1880
2477
|
before: gitignoreBefore,
|
|
1881
2478
|
after: ensureGitignore(gitignoreBefore)
|
|
1882
2479
|
});
|
|
1883
2480
|
if (opts.agentsMd !== false) {
|
|
1884
|
-
const before = await readOrNull(
|
|
2481
|
+
const before = await readOrNull(join5(root, AGENTS_MD));
|
|
1885
2482
|
changes.push({ path: AGENTS_MD, before, after: upsertAgentsBlock(before) });
|
|
1886
2483
|
}
|
|
1887
2484
|
return changes.filter((c) => c.before !== c.after);
|
|
@@ -1901,29 +2498,29 @@ function renderDiff(changes) {
|
|
|
1901
2498
|
}
|
|
1902
2499
|
async function applyInit(root, changes) {
|
|
1903
2500
|
for (const c of changes) {
|
|
1904
|
-
const target =
|
|
1905
|
-
await
|
|
2501
|
+
const target = join5(resolve2(root), c.path);
|
|
2502
|
+
await mkdir3(dirname2(target), { recursive: true });
|
|
1906
2503
|
const tmp = `${target}.catenext-${process.pid}.tmp`;
|
|
1907
|
-
await
|
|
2504
|
+
await writeFile3(tmp, c.after);
|
|
1908
2505
|
await rename2(tmp, target);
|
|
1909
2506
|
}
|
|
1910
2507
|
}
|
|
1911
2508
|
|
|
1912
2509
|
// src/maintenance.ts
|
|
1913
2510
|
import { existsSync } from "node:fs";
|
|
1914
|
-
import { copyFile, mkdir as
|
|
1915
|
-
import { dirname as dirname3, isAbsolute, join as
|
|
2511
|
+
import { copyFile, mkdir as mkdir5, readFile as readFile9, rename as rename4, rm, rmdir, writeFile as writeFile5 } from "node:fs/promises";
|
|
2512
|
+
import { dirname as dirname3, isAbsolute, join as join9, resolve as resolve3 } from "node:path";
|
|
1916
2513
|
import { applyEdits as applyEdits2, modify as modify2, parse as parse4, visit } from "jsonc-parser";
|
|
1917
2514
|
|
|
1918
2515
|
// src/node-command.ts
|
|
1919
2516
|
import { accessSync, constants, realpathSync } from "node:fs";
|
|
1920
|
-
import { delimiter, join as
|
|
2517
|
+
import { delimiter, join as join6 } from "node:path";
|
|
1921
2518
|
function stableNodeCommand(execPath, pathEnv, resolveReal = realpathSync, isExecutable = defaultIsExecutable) {
|
|
1922
2519
|
const target = safeReal(execPath, resolveReal);
|
|
1923
2520
|
for (const dir of (pathEnv ?? "").split(delimiter)) {
|
|
1924
2521
|
if (!dir) continue;
|
|
1925
2522
|
for (const name of process.platform === "win32" ? ["node.exe", "node"] : ["node"]) {
|
|
1926
|
-
const candidate =
|
|
2523
|
+
const candidate = join6(dir, name);
|
|
1927
2524
|
if (!isExecutable(candidate)) continue;
|
|
1928
2525
|
return safeReal(candidate, resolveReal) === target ? "node" : execPath;
|
|
1929
2526
|
}
|
|
@@ -1953,19 +2550,19 @@ function npxLaunch(entry) {
|
|
|
1953
2550
|
}
|
|
1954
2551
|
|
|
1955
2552
|
// src/skills.ts
|
|
1956
|
-
import { execFile as
|
|
1957
|
-
import { mkdir as
|
|
1958
|
-
import { join as
|
|
1959
|
-
import { promisify as
|
|
2553
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
2554
|
+
import { mkdir as mkdir4, readdir as readdir2, readFile as readFile7, rename as rename3, writeFile as writeFile4 } from "node:fs/promises";
|
|
2555
|
+
import { join as join7 } from "node:path";
|
|
2556
|
+
import { promisify as promisify3 } from "node:util";
|
|
1960
2557
|
import { parse as parse3, stringify } from "yaml";
|
|
1961
|
-
var SKILLS_DIR =
|
|
2558
|
+
var SKILLS_DIR = join7(".catenext", "skills");
|
|
1962
2559
|
var SkillError = class extends Error {
|
|
1963
2560
|
constructor(message) {
|
|
1964
2561
|
super(message);
|
|
1965
2562
|
this.name = "SkillError";
|
|
1966
2563
|
}
|
|
1967
2564
|
};
|
|
1968
|
-
var exec2 =
|
|
2565
|
+
var exec2 = promisify3(execFile3);
|
|
1969
2566
|
var FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
|
|
1970
2567
|
function parseSkill(source, fileName) {
|
|
1971
2568
|
const m = FRONTMATTER.exec(source);
|
|
@@ -1999,7 +2596,7 @@ ${skill.content.trim()}
|
|
|
1999
2596
|
async function listSkills(root) {
|
|
2000
2597
|
let files;
|
|
2001
2598
|
try {
|
|
2002
|
-
files = await
|
|
2599
|
+
files = await readdir2(join7(root, SKILLS_DIR));
|
|
2003
2600
|
} catch {
|
|
2004
2601
|
return { skills: [], invalid: [] };
|
|
2005
2602
|
}
|
|
@@ -2007,7 +2604,7 @@ async function listSkills(root) {
|
|
|
2007
2604
|
const invalid = [];
|
|
2008
2605
|
for (const file of files.filter((f) => f.endsWith(".md")).sort()) {
|
|
2009
2606
|
try {
|
|
2010
|
-
const skill = parseSkill(await
|
|
2607
|
+
const skill = parseSkill(await readFile7(join7(root, SKILLS_DIR, file), "utf8"), file);
|
|
2011
2608
|
if (`${skill.name}.md` !== file) {
|
|
2012
2609
|
throw new SkillError(`${file}: name "${skill.name}" harus sama dengan nama file.`);
|
|
2013
2610
|
}
|
|
@@ -2042,7 +2639,7 @@ async function loadSkill(root, name, revision) {
|
|
|
2042
2639
|
}
|
|
2043
2640
|
let source;
|
|
2044
2641
|
try {
|
|
2045
|
-
source = await
|
|
2642
|
+
source = await readFile7(join7(root, SKILLS_DIR, file), "utf8");
|
|
2046
2643
|
} catch {
|
|
2047
2644
|
const { skills } = await listSkills(root);
|
|
2048
2645
|
const names = skills.map((s) => s.name).join(", ") || "(belum ada)";
|
|
@@ -2057,20 +2654,20 @@ async function saveSkill(root, input, now = /* @__PURE__ */ new Date()) {
|
|
|
2057
2654
|
if (!when || when.length > SKILL_LIMITS.maxWhenToUseLength) {
|
|
2058
2655
|
throw new SkillError(`when_to_use wajib, maks ${SKILL_LIMITS.maxWhenToUseLength} karakter.`);
|
|
2059
2656
|
}
|
|
2060
|
-
const dir =
|
|
2061
|
-
await
|
|
2062
|
-
const target =
|
|
2657
|
+
const dir = join7(root, SKILLS_DIR);
|
|
2658
|
+
await mkdir4(dir, { recursive: true });
|
|
2659
|
+
const target = join7(dir, `${name}.md`);
|
|
2063
2660
|
let created = true;
|
|
2064
2661
|
try {
|
|
2065
|
-
await
|
|
2662
|
+
await readFile7(target);
|
|
2066
2663
|
created = false;
|
|
2067
2664
|
} catch {
|
|
2068
2665
|
}
|
|
2069
2666
|
const skill = { name, when_to_use: when, updated_at: now.toISOString(), content };
|
|
2070
2667
|
const tmp = `${target}.${process.pid}.tmp`;
|
|
2071
|
-
await
|
|
2668
|
+
await writeFile4(tmp, renderSkill(skill), "utf8");
|
|
2072
2669
|
await rename3(tmp, target);
|
|
2073
|
-
return { path:
|
|
2670
|
+
return { path: join7(SKILLS_DIR, `${name}.md`), created, skill };
|
|
2074
2671
|
}
|
|
2075
2672
|
async function committedSkillIndex(root, previous) {
|
|
2076
2673
|
const config = { cwd: root };
|
|
@@ -2107,9 +2704,9 @@ async function committedSkillIndex(root, previous) {
|
|
|
2107
2704
|
}
|
|
2108
2705
|
|
|
2109
2706
|
// src/subagents.ts
|
|
2110
|
-
import { readdir as
|
|
2111
|
-
import { join as
|
|
2112
|
-
var SUBAGENTS_DIR =
|
|
2707
|
+
import { readdir as readdir3, readFile as readFile8 } from "node:fs/promises";
|
|
2708
|
+
import { join as join8 } from "node:path";
|
|
2709
|
+
var SUBAGENTS_DIR = join8(".claude", "agents");
|
|
2113
2710
|
var SUBAGENT_MARKER = "<!-- catenext:persona -->";
|
|
2114
2711
|
function renderSubagent(p) {
|
|
2115
2712
|
const rules = p.rules.length > 0 ? p.rules.map((r) => `- ${r}`) : ["- (belum ada aturan)"];
|
|
@@ -2124,16 +2721,26 @@ function renderSubagent(p) {
|
|
|
2124
2721
|
"",
|
|
2125
2722
|
`Anda adalah persona Catenext **${p.alias}** (role: ${p.role}).`,
|
|
2126
2723
|
"",
|
|
2724
|
+
...p.repos.length > 0 ? [
|
|
2725
|
+
`Repo yang dipegang: ${p.repos.map((r) => `\`${r}\``).join(", ")}. Kerjakan dari folder checkout repo itu (yang berisi \`.catenext/config.yaml\` dengan \`repo_name\` tersebut). Bila dipanggil dari folder repo lain, pindah ke folder repo Anda dan pakai CLI di sana: \`cd <folder-${p.repos[0]}> && npx catenext next --as ${p.alias}\`.`,
|
|
2726
|
+
""
|
|
2727
|
+
] : [],
|
|
2127
2728
|
"## Alur kerja (satu task per pemanggilan)",
|
|
2128
2729
|
"",
|
|
2129
2730
|
`1. \`get_project_context\` dengan \`agent_alias: ${alias}\`.`,
|
|
2130
2731
|
`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
|
|
2133
|
-
"5. `complete_handoff` dengan
|
|
2134
|
-
"6. Laporkan ke pemanggil: task
|
|
2732
|
+
`3. \`claim_task\` dengan \`task_id\` dan \`agent_alias: ${alias}\`. Bila \`layout\`=monorepo, sertakan \`worktree\`. Patuhi field \`persona\` di hasilnya.`,
|
|
2733
|
+
"4. Kerjakan, jalankan tes, commit di branch/worktree (jangan merge ke default branch).",
|
|
2734
|
+
"5. Buat PR, lalu `complete_handoff` dengan `pull_request` wajib, atau `report_blocker` bila buntu.",
|
|
2735
|
+
"6. Laporkan ke orchestrator (pemanggil): task, status, URL PR, dan perintah verifikasi.",
|
|
2736
|
+
"",
|
|
2737
|
+
`Tanpa tool MCP: \`catenext next --as ${p.alias}\`, \`catenext claim <id> --as ${p.alias} [--worktree]\`, \`catenext done <id> --notes "..." --pr <url> --base <branch>\`.`,
|
|
2135
2738
|
"",
|
|
2136
|
-
|
|
2739
|
+
"## Batas subagent",
|
|
2740
|
+
"",
|
|
2741
|
+
`- Anda subagent dari orchestrator (agen utama). Hanya kerjakan task milik ${p.alias} yang didelegasikan.`,
|
|
2742
|
+
"- Task di kolom Revisi didahulukan; baca feedback revisi di hasil claim dan perbaiki di branch/PR yang sama.",
|
|
2743
|
+
"- Jangan memanggil `create_tasks`, `manage_task`, atau `upsert_persona`; perencanaan, revisi, dan assign adalah tugas orchestrator.",
|
|
2137
2744
|
"",
|
|
2138
2745
|
"## Aturan & batas wilayah",
|
|
2139
2746
|
"",
|
|
@@ -2141,7 +2748,7 @@ function renderSubagent(p) {
|
|
|
2141
2748
|
""
|
|
2142
2749
|
].join("\n");
|
|
2143
2750
|
}
|
|
2144
|
-
var readOrNull2 = (p) =>
|
|
2751
|
+
var readOrNull2 = (p) => readFile8(p, "utf8").then(
|
|
2145
2752
|
(s) => s,
|
|
2146
2753
|
() => null
|
|
2147
2754
|
);
|
|
@@ -2150,9 +2757,9 @@ async function planSubagents(root, personas) {
|
|
|
2150
2757
|
const skipped = [];
|
|
2151
2758
|
const wanted = /* @__PURE__ */ new Set();
|
|
2152
2759
|
for (const p of personas) {
|
|
2153
|
-
const path =
|
|
2760
|
+
const path = join8(SUBAGENTS_DIR, `${p.alias}.md`);
|
|
2154
2761
|
wanted.add(path);
|
|
2155
|
-
const before = await readOrNull2(
|
|
2762
|
+
const before = await readOrNull2(join8(root, path));
|
|
2156
2763
|
if (before !== null && !before.includes(SUBAGENT_MARKER)) {
|
|
2157
2764
|
skipped.push(path);
|
|
2158
2765
|
continue;
|
|
@@ -2162,23 +2769,23 @@ async function planSubagents(root, personas) {
|
|
|
2162
2769
|
}
|
|
2163
2770
|
for (const path of await catenextSubagentFiles(root)) {
|
|
2164
2771
|
if (!wanted.has(path)) {
|
|
2165
|
-
edits.push({ path, before: await readOrNull2(
|
|
2772
|
+
edits.push({ path, before: await readOrNull2(join8(root, path)), after: null });
|
|
2166
2773
|
}
|
|
2167
2774
|
}
|
|
2168
2775
|
return { edits, skipped };
|
|
2169
2776
|
}
|
|
2170
2777
|
async function catenextSubagentFiles(root) {
|
|
2171
|
-
const names = await
|
|
2778
|
+
const names = await readdir3(join8(root, SUBAGENTS_DIR)).catch(() => []);
|
|
2172
2779
|
const out = [];
|
|
2173
2780
|
for (const n of names.filter((n2) => n2.endsWith(".md")).sort()) {
|
|
2174
|
-
const path =
|
|
2175
|
-
if ((await readOrNull2(
|
|
2781
|
+
const path = join8(SUBAGENTS_DIR, n);
|
|
2782
|
+
if ((await readOrNull2(join8(root, path)))?.includes(SUBAGENT_MARKER)) out.push(path);
|
|
2176
2783
|
}
|
|
2177
2784
|
return out;
|
|
2178
2785
|
}
|
|
2179
2786
|
|
|
2180
2787
|
// src/maintenance.ts
|
|
2181
|
-
var readOrNull3 = (p) =>
|
|
2788
|
+
var readOrNull3 = (p) => readFile9(p, "utf8").then(
|
|
2182
2789
|
(s) => s,
|
|
2183
2790
|
() => null
|
|
2184
2791
|
);
|
|
@@ -2219,8 +2826,8 @@ function removeMcpEntries(source) {
|
|
|
2219
2826
|
}
|
|
2220
2827
|
function isValidJsonObject(source) {
|
|
2221
2828
|
const errors = [];
|
|
2222
|
-
const
|
|
2223
|
-
return errors.length === 0 &&
|
|
2829
|
+
const doc2 = parse4(source, errors, { allowTrailingComma: true, disallowComments: false });
|
|
2830
|
+
return errors.length === 0 && doc2 !== null && typeof doc2 === "object" && !Array.isArray(doc2);
|
|
2224
2831
|
}
|
|
2225
2832
|
function entryIsStale(entry) {
|
|
2226
2833
|
if (isAbsolute(entry.command) && !existsSync(entry.command)) return true;
|
|
@@ -2239,7 +2846,7 @@ async function planSync(opts) {
|
|
|
2239
2846
|
const edits = [];
|
|
2240
2847
|
const findings = [];
|
|
2241
2848
|
for (const adapter of ADAPTERS) {
|
|
2242
|
-
const before = await readOrNull3(
|
|
2849
|
+
const before = await readOrNull3(join9(root, adapter.path));
|
|
2243
2850
|
if (before !== null && before.trim() !== "" && !isValidJsonObject(before)) {
|
|
2244
2851
|
if (!opts.fix) {
|
|
2245
2852
|
findings.push({
|
|
@@ -2302,12 +2909,12 @@ async function planSync(opts) {
|
|
|
2302
2909
|
);
|
|
2303
2910
|
if (after !== before) edits.push({ path: adapter.path, before, after });
|
|
2304
2911
|
}
|
|
2305
|
-
const gitignore = await readOrNull3(
|
|
2912
|
+
const gitignore = await readOrNull3(join9(root, ".gitignore"));
|
|
2306
2913
|
const gitignoreAfter = ensureGitignore(gitignore);
|
|
2307
2914
|
if (gitignoreAfter !== gitignore) {
|
|
2308
2915
|
edits.push({ path: ".gitignore", before: gitignore, after: gitignoreAfter });
|
|
2309
2916
|
}
|
|
2310
|
-
const agents = await readOrNull3(
|
|
2917
|
+
const agents = await readOrNull3(join9(root, AGENTS_MD));
|
|
2311
2918
|
if (agents?.includes(BLOCK_START)) {
|
|
2312
2919
|
const after = upsertAgentsBlock(agents);
|
|
2313
2920
|
if (after !== agents) edits.push({ path: AGENTS_MD, before: agents, after });
|
|
@@ -2331,42 +2938,49 @@ async function planRemove(opts) {
|
|
|
2331
2938
|
const root = resolve3(opts.root);
|
|
2332
2939
|
const edits = [];
|
|
2333
2940
|
for (const adapter of ADAPTERS) {
|
|
2334
|
-
const before = await readOrNull3(
|
|
2941
|
+
const before = await readOrNull3(join9(root, adapter.path));
|
|
2335
2942
|
if (before === null || countEntries(before) === 0) continue;
|
|
2336
2943
|
const stripped = removeMcpEntries(before);
|
|
2337
|
-
const
|
|
2338
|
-
const servers =
|
|
2339
|
-
const emptyDoc = Object.keys(
|
|
2944
|
+
const doc2 = parse4(stripped, [], { allowTrailingComma: true });
|
|
2945
|
+
const servers = doc2?.mcpServers;
|
|
2946
|
+
const emptyDoc = Object.keys(doc2 ?? {}).every((k) => k === "mcpServers") && Object.keys(servers ?? {}).length === 0 && !/\/\/|\/\*/.test(stripped);
|
|
2340
2947
|
edits.push({ path: adapter.path, before, after: emptyDoc ? null : stripped });
|
|
2341
2948
|
}
|
|
2342
|
-
const gitignore = await readOrNull3(
|
|
2949
|
+
const gitignore = await readOrNull3(join9(root, ".gitignore"));
|
|
2343
2950
|
if (gitignore !== null) {
|
|
2344
2951
|
const eol = gitignore.includes("\r\n") ? "\r\n" : "\n";
|
|
2345
2952
|
const lines = gitignore.split(/\r?\n/);
|
|
2346
|
-
const
|
|
2347
|
-
|
|
2348
|
-
|
|
2953
|
+
const catenextIgnore = /* @__PURE__ */ new Set([CACHE_IGNORE, CACHE_DIR_IGNORE, ".catenext/cache"]);
|
|
2954
|
+
const kept = lines.filter((l, i) => {
|
|
2955
|
+
const t = l.trim();
|
|
2956
|
+
if (catenextIgnore.has(t)) return false;
|
|
2957
|
+
if (l.startsWith("# Catenext:")) {
|
|
2958
|
+
const next = lines[i + 1]?.trim();
|
|
2959
|
+
if (next && catenextIgnore.has(next)) return false;
|
|
2960
|
+
}
|
|
2961
|
+
return true;
|
|
2962
|
+
});
|
|
2349
2963
|
if (kept.length !== lines.length) {
|
|
2350
2964
|
const text2 = kept.join(eol).replace(/(\r?\n)+$/, "");
|
|
2351
2965
|
edits.push({ path: ".gitignore", before: gitignore, after: text2 ? `${text2}${eol}` : null });
|
|
2352
2966
|
}
|
|
2353
2967
|
}
|
|
2354
|
-
const agents = await readOrNull3(
|
|
2968
|
+
const agents = await readOrNull3(join9(root, AGENTS_MD));
|
|
2355
2969
|
if (agents?.includes(BLOCK_START)) {
|
|
2356
2970
|
edits.push({ path: AGENTS_MD, before: agents, after: removeAgentsBlock(agents) });
|
|
2357
2971
|
}
|
|
2358
2972
|
for (const p of await catenextSubagentFiles(root)) {
|
|
2359
|
-
edits.push({ path: p, before: await readOrNull3(
|
|
2973
|
+
edits.push({ path: p, before: await readOrNull3(join9(root, p)), after: null });
|
|
2360
2974
|
}
|
|
2361
|
-
for (const p of [CONFIG_PATH,
|
|
2362
|
-
const before = await readOrNull3(
|
|
2975
|
+
for (const p of [CONFIG_PATH, join9(".catenext", "cache.json")]) {
|
|
2976
|
+
const before = await readOrNull3(join9(root, p));
|
|
2363
2977
|
if (before !== null) edits.push({ path: p, before, after: null });
|
|
2364
2978
|
}
|
|
2365
2979
|
if (opts.all) {
|
|
2366
2980
|
const { skills, invalid } = await listSkills(root);
|
|
2367
2981
|
for (const f of [...skills.map((s) => `${s.name}.md`), ...invalid.map((i) => i.file)]) {
|
|
2368
|
-
const p =
|
|
2369
|
-
edits.push({ path: p, before: await readOrNull3(
|
|
2982
|
+
const p = join9(SKILLS_DIR, f);
|
|
2983
|
+
edits.push({ path: p, before: await readOrNull3(join9(root, p)), after: null });
|
|
2370
2984
|
}
|
|
2371
2985
|
}
|
|
2372
2986
|
return edits;
|
|
@@ -2374,19 +2988,19 @@ async function planRemove(opts) {
|
|
|
2374
2988
|
async function applyFileEdits(root, edits) {
|
|
2375
2989
|
const base = resolve3(root);
|
|
2376
2990
|
for (const e of edits) {
|
|
2377
|
-
const target =
|
|
2991
|
+
const target = join9(base, e.path);
|
|
2378
2992
|
if (e.after === null) {
|
|
2379
2993
|
await rm(target, { force: true });
|
|
2380
2994
|
continue;
|
|
2381
2995
|
}
|
|
2382
|
-
await
|
|
2996
|
+
await mkdir5(dirname3(target), { recursive: true });
|
|
2383
2997
|
if (e.backup && e.before !== null) await copyFile(target, `${target}.bak`);
|
|
2384
2998
|
const tmp = `${target}.catenext-${process.pid}.tmp`;
|
|
2385
|
-
await
|
|
2999
|
+
await writeFile5(tmp, e.after);
|
|
2386
3000
|
await rename4(tmp, target);
|
|
2387
3001
|
}
|
|
2388
3002
|
for (const dir of [SKILLS_DIR, ".catenext", ".cursor", SUBAGENTS_DIR, ".claude"]) {
|
|
2389
|
-
await rmdir(
|
|
3003
|
+
await rmdir(join9(base, dir)).catch(() => {
|
|
2390
3004
|
});
|
|
2391
3005
|
}
|
|
2392
3006
|
}
|
|
@@ -2403,9 +3017,13 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
2403
3017
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2404
3018
|
var SERVER_INSTRUCTIONS = [
|
|
2405
3019
|
"Catenext mengatur estafet task antar-agen AI untuk repo ini.",
|
|
2406
|
-
"Alur: get_project_context -> get_ready_tasks -> claim_task -> kerjakan &
|
|
3020
|
+
"Alur: get_project_context -> get_ready_tasks -> claim_task (worktree wajib jika layout=monorepo) -> kerjakan & commit di branch -> buat PR -> complete_handoff (pull_request wajib \u2192 NEEDS_REVIEW).",
|
|
2407
3021
|
"Merencanakan: list_epics/create_epic -> create_tasks (masuk DRAFT, disetujui manusia di Web sebelum bisa dikerjakan).",
|
|
3022
|
+
"Orchestrator = agen utama sesi (bukan subagent persona): ia merencanakan, mendelegasikan task ke subagent per persona, dan meninjau hasilnya. Revisi atas task yang sudah diserahkan memakai manage_task action request_revision (task pindah ke kolom Revisi dan diambil lagi oleh persona penanggung jawabnya); jangan membuat task baru untuk revisi. manage_task action assign menetapkan persona/role task. Subagent persona tidak memakai manage_task maupun create_tasks.",
|
|
2408
3023
|
'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.',
|
|
3024
|
+
"Multi-repo: satu proyek bisa membawahi banyak repo (mis. be dan fe di folder terpisah). Orchestrator memakai get_project_board untuk melihat semua task lintas repo dan persona pemegang tiap repo, lalu mendelegasikan ke subagent yang bekerja dari folder repo tujuan.",
|
|
3025
|
+
"Dokumen proyek (blueprint, ERD, arsitektur, keputusan) tersimpan di Cloud: indeksnya di get_project_context, isi lewat get_document, perbarui lewat save_document dengan expected_version. Baca dokumen relevan di awal sesi agar konteks tidak hilang antar sesi/IDE/CLI.",
|
|
3026
|
+
"Sebelum load_skill atau get_document buta, boleh search_context (query singkat) untuk menemukan dokumen/skill/task relevan (embedding + cache; rerank bila tersedia).",
|
|
2409
3027
|
"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).",
|
|
2410
3028
|
"Bila buntu, panggil report_blocker. Jangan menyalin kode atau secret ke handoff; rujuk path file.",
|
|
2411
3029
|
"Jangan mengedit .catenext/config.yaml atau file konfigurasi MCP IDE."
|
|
@@ -2493,15 +3111,27 @@ function createCatenextMcpServer(opts) {
|
|
|
2493
3111
|
server.registerTool(
|
|
2494
3112
|
"claim_task",
|
|
2495
3113
|
{ description: MCP_TOOLS.claim_task.description, inputSchema: MCP_TOOLS.claim_task.input },
|
|
2496
|
-
(input) => call(
|
|
2497
|
-
|
|
3114
|
+
(input) => call(async ({ api, config }) => {
|
|
3115
|
+
const agentAlias = input.agent_alias ?? config.overrides?.default_agent_alias;
|
|
3116
|
+
if (!input.worktree) {
|
|
3117
|
+
const ctx = await api.post("context", {
|
|
3118
|
+
...agentAlias ? { agent_alias: agentAlias } : {}
|
|
3119
|
+
});
|
|
3120
|
+
if (ctx.project?.layout === "monorepo") {
|
|
3121
|
+
return text(
|
|
3122
|
+
"Proyek layout monorepo: claim_task wajib worktree { branch, session_id }. Checkout branch kerja lalu kirim worktree, atau catenext claim <id> --worktree.",
|
|
3123
|
+
true
|
|
3124
|
+
);
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
return json(
|
|
2498
3128
|
await api.post("claim", {
|
|
2499
3129
|
task_id: input.task_id,
|
|
2500
3130
|
worktree: input.worktree,
|
|
2501
|
-
agent_alias:
|
|
3131
|
+
agent_alias: agentAlias
|
|
2502
3132
|
})
|
|
2503
|
-
)
|
|
2504
|
-
)
|
|
3133
|
+
);
|
|
3134
|
+
})
|
|
2505
3135
|
);
|
|
2506
3136
|
server.registerTool(
|
|
2507
3137
|
"complete_handoff",
|
|
@@ -2589,6 +3219,62 @@ ${zodIssues(parsed.error)}`, true);
|
|
|
2589
3219
|
}
|
|
2590
3220
|
return json(await send(api, parsed.data), notes);
|
|
2591
3221
|
});
|
|
3222
|
+
server.registerTool(
|
|
3223
|
+
"manage_task",
|
|
3224
|
+
{ description: MCP_TOOLS.manage_task.description, inputSchema: MCP_TOOLS.manage_task.input },
|
|
3225
|
+
scrubbedWrite(
|
|
3226
|
+
ManageTaskInput,
|
|
3227
|
+
["action", "task_id", "agent_alias", "role"],
|
|
3228
|
+
(api, payload) => api.post("tasks/manage", payload)
|
|
3229
|
+
)
|
|
3230
|
+
);
|
|
3231
|
+
server.registerTool(
|
|
3232
|
+
"get_project_board",
|
|
3233
|
+
{
|
|
3234
|
+
description: MCP_TOOLS.get_project_board.description,
|
|
3235
|
+
inputSchema: MCP_TOOLS.get_project_board.input
|
|
3236
|
+
},
|
|
3237
|
+
(input) => call(async ({ api }) => json(await api.post("board", GetProjectBoardInput.parse(input))))
|
|
3238
|
+
);
|
|
3239
|
+
server.registerTool(
|
|
3240
|
+
"get_document",
|
|
3241
|
+
{ description: MCP_TOOLS.get_document.description, inputSchema: MCP_TOOLS.get_document.input },
|
|
3242
|
+
(input) => call(async ({ api }) => json(await api.post("documents/get", GetDocumentInput.parse(input))))
|
|
3243
|
+
);
|
|
3244
|
+
server.registerTool(
|
|
3245
|
+
"save_document",
|
|
3246
|
+
{
|
|
3247
|
+
description: MCP_TOOLS.save_document.description,
|
|
3248
|
+
inputSchema: MCP_TOOLS.save_document.input
|
|
3249
|
+
},
|
|
3250
|
+
scrubbedWrite(
|
|
3251
|
+
SaveDocumentInput,
|
|
3252
|
+
["slug", "kind", "expected_version"],
|
|
3253
|
+
(api, payload) => api.put("documents", payload)
|
|
3254
|
+
)
|
|
3255
|
+
);
|
|
3256
|
+
server.registerTool(
|
|
3257
|
+
"search_context",
|
|
3258
|
+
{
|
|
3259
|
+
description: MCP_TOOLS.search_context.description,
|
|
3260
|
+
inputSchema: MCP_TOOLS.search_context.input
|
|
3261
|
+
},
|
|
3262
|
+
(input) => call(async ({ api }) => {
|
|
3263
|
+
const scrubbed = scrubDeep(input, /* @__PURE__ */ new Set(["sources", "limit"]));
|
|
3264
|
+
const parsed = SearchContextInput.safeParse(scrubbed.value);
|
|
3265
|
+
if (!parsed.success) {
|
|
3266
|
+
return text(`Input ditolak sebelum dikirim:
|
|
3267
|
+
${zodIssues(parsed.error)}`, true);
|
|
3268
|
+
}
|
|
3269
|
+
const notes = [];
|
|
3270
|
+
if (scrubbed.total > 0) {
|
|
3271
|
+
const note = describeRedactions(scrubbed);
|
|
3272
|
+
log(note);
|
|
3273
|
+
notes.push(note);
|
|
3274
|
+
}
|
|
3275
|
+
return json(await api.post("search", parsed.data), notes);
|
|
3276
|
+
})
|
|
3277
|
+
);
|
|
2592
3278
|
server.registerTool(
|
|
2593
3279
|
"list_epics",
|
|
2594
3280
|
{ description: MCP_TOOLS.list_epics.description, inputSchema: MCP_TOOLS.list_epics.input },
|
|
@@ -2723,8 +3409,8 @@ async function runMcpServer(opts) {
|
|
|
2723
3409
|
}
|
|
2724
3410
|
|
|
2725
3411
|
// src/verify.ts
|
|
2726
|
-
import { readFile as
|
|
2727
|
-
import { join as
|
|
3412
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
3413
|
+
import { join as join10 } from "node:path";
|
|
2728
3414
|
async function verifySetup(root, config) {
|
|
2729
3415
|
const lines = [];
|
|
2730
3416
|
let tokenLine;
|
|
@@ -2764,7 +3450,7 @@ async function verifySetup(root, config) {
|
|
|
2764
3450
|
const missing = [];
|
|
2765
3451
|
const stale = [];
|
|
2766
3452
|
for (const adapter of ADAPTERS) {
|
|
2767
|
-
const src = await
|
|
3453
|
+
const src = await readFile10(join10(root, adapter.path), "utf8").catch(() => null);
|
|
2768
3454
|
const entry = src ? readMcpEntry(src) : null;
|
|
2769
3455
|
if (!entry) missing.push(adapter.label);
|
|
2770
3456
|
else if (entryIsStale(entry)) stale.push(adapter.label);
|
|
@@ -2788,7 +3474,7 @@ function formatChecks(lines) {
|
|
|
2788
3474
|
}
|
|
2789
3475
|
|
|
2790
3476
|
// src/index.ts
|
|
2791
|
-
var VERSION = "0.
|
|
3477
|
+
var VERSION = "0.5.0";
|
|
2792
3478
|
var program = new Command();
|
|
2793
3479
|
program.name("catenext").description("Estafet tugas & konteks antar-agen AI coding").version(VERSION);
|
|
2794
3480
|
async function friendly(fn) {
|
|
@@ -2934,9 +3620,56 @@ persona.command("set").description("Buat atau perbarui persona khusus proyek ini
|
|
|
2934
3620
|
"Aturan kerja (boleh diulang)",
|
|
2935
3621
|
(v, prev) => [...prev, v],
|
|
2936
3622
|
[]
|
|
3623
|
+
).option(
|
|
3624
|
+
"--repo <name>",
|
|
3625
|
+
"Repo yang dipegang persona di proyek ini, mis. be (boleh diulang)",
|
|
3626
|
+
(v, prev) => [...prev ?? [], v]
|
|
2937
3627
|
).option("--json", "Keluaran JSON").action(
|
|
2938
3628
|
(alias, opts) => friendly(
|
|
2939
|
-
async () => personaSet(await cliApi(), alias, opts.role, opts.rule, Boolean(opts.json))
|
|
3629
|
+
async () => personaSet(await cliApi(), alias, opts.role, opts.rule, Boolean(opts.json), opts.repo)
|
|
3630
|
+
)
|
|
3631
|
+
);
|
|
3632
|
+
program.command("board").description("Orchestrator: papan proyek lintas repo (task, status, persona, repo)").option("--epic <id>", "Batasi ke satu epic").option(
|
|
3633
|
+
"--status <status>",
|
|
3634
|
+
"Filter status (boleh diulang)",
|
|
3635
|
+
(v, p) => [...p, v],
|
|
3636
|
+
[]
|
|
3637
|
+
).option("--json", "Keluaran JSON").action(
|
|
3638
|
+
(opts) => friendly(async () => boardShow(await cliApi(), opts))
|
|
3639
|
+
);
|
|
3640
|
+
var doc = program.command("doc").description("Dokumen proyek di Cloud (blueprint, ERD, arsitektur, keputusan)");
|
|
3641
|
+
doc.command("list").option("--json", "Keluaran JSON").action(
|
|
3642
|
+
(opts) => friendly(async () => docList(await cliApi(), Boolean(opts.json)))
|
|
3643
|
+
);
|
|
3644
|
+
doc.command("get").argument("<slug>").option("--json", "Keluaran JSON").action(
|
|
3645
|
+
(slug, opts) => friendly(async () => docGet(await cliApi(), slug, Boolean(opts.json)))
|
|
3646
|
+
);
|
|
3647
|
+
doc.command("save").argument("<slug>", "Slug dokumen, mis. blueprint atau erd").requiredOption("--file <path>", "File Markdown berisi dokumen").option("--title <text>", "Judul dokumen (default: slug)").option("--kind <kind>", `Salah satu: ${DOCUMENT_KINDS.join(", ")}`, "other").option(
|
|
3648
|
+
"--expected-version <n>",
|
|
3649
|
+
"Versi yang Anda baca (0 = dokumen baru); mencegah menimpa sesi lain. Jangan pakai --version (bentrok flag versi CLI)."
|
|
3650
|
+
).option("--json", "Keluaran JSON").action(
|
|
3651
|
+
(slug, opts) => friendly(
|
|
3652
|
+
async () => docSave(await cliApi(), slug, {
|
|
3653
|
+
file: opts.file,
|
|
3654
|
+
title: opts.title,
|
|
3655
|
+
kind: opts.kind,
|
|
3656
|
+
version: opts.expectedVersion,
|
|
3657
|
+
json: opts.json
|
|
3658
|
+
})
|
|
3659
|
+
)
|
|
3660
|
+
);
|
|
3661
|
+
program.command("search").description("Cari semantik di dokumen/skill/task Cloud dan/atau kode lokal").argument("<query>", "Query pencarian").option(
|
|
3662
|
+
"--source <src>",
|
|
3663
|
+
"Sumber: document|skill|task|code (bisa diulang)",
|
|
3664
|
+
(v, prev) => [...prev, v],
|
|
3665
|
+
[]
|
|
3666
|
+
).option("-n, --limit <n>", "Jumlah hasil", (v) => Number.parseInt(v, 10), 8).option("--json", "Keluaran JSON").action(
|
|
3667
|
+
(query, opts) => friendly(
|
|
3668
|
+
async () => searchShow(await cliApi(), query, {
|
|
3669
|
+
source: opts.source.length ? opts.source : void 0,
|
|
3670
|
+
limit: opts.limit,
|
|
3671
|
+
json: opts.json
|
|
3672
|
+
})
|
|
2940
3673
|
)
|
|
2941
3674
|
);
|
|
2942
3675
|
var collect = (v, prev) => [...prev, v];
|
|
@@ -2948,7 +3681,7 @@ var AGENT_OPT = [
|
|
|
2948
3681
|
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(
|
|
2949
3682
|
(opts) => friendly(async () => taskNext(await cliApi(opts.agent), opts))
|
|
2950
3683
|
);
|
|
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
|
|
3684
|
+
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 + lease sesi (wajib di proyek layout monorepo)").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
2952
3685
|
(taskId, opts) => friendly(async () => taskClaim(await cliApi(opts.agent), taskId, opts))
|
|
2953
3686
|
);
|
|
2954
3687
|
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(
|
|
@@ -2961,7 +3694,7 @@ program.command("done").description("Selesaikan task dengan handoff terstruktur
|
|
|
2961
3694
|
"File yang diubah (boleh diulang; default dari git)",
|
|
2962
3695
|
collect,
|
|
2963
3696
|
[]
|
|
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(
|
|
3697
|
+
).option("--verify <cmd>", "Perintah verifikasi, mis. pnpm test").option("--pr <url>", "URL pull request GitHub (wajib bersama --base)").option("--base <branch>", "Branch tujuan PR (wajib bersama --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(
|
|
2965
3698
|
(taskId, opts) => friendly(async () => taskDone(await cliApi(opts.agent), taskId, opts))
|
|
2966
3699
|
);
|
|
2967
3700
|
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(
|
|
@@ -2977,6 +3710,38 @@ program.command("release").description("Lepas task untuk sesi lain").argument("<
|
|
|
2977
3710
|
console.log(JSON.stringify(await api.post("release", input), null, 2));
|
|
2978
3711
|
})
|
|
2979
3712
|
);
|
|
3713
|
+
program.command("revise").description(
|
|
3714
|
+
"Orchestrator: kembalikan task NEEDS_REVIEW/DONE ke kolom Revisi (bukan task baru; setara manage_task)"
|
|
3715
|
+
).argument("<task_id>").requiredOption("--feedback <text>", "Apa yang harus diperbaiki (min. 5 karakter)").option("--to <alias>", "Ganti persona penanggung jawab revisi").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
3716
|
+
(taskId, opts) => friendly(
|
|
3717
|
+
async () => taskManage(
|
|
3718
|
+
await cliApi(opts.agent),
|
|
3719
|
+
{
|
|
3720
|
+
action: "request_revision",
|
|
3721
|
+
task_id: taskId,
|
|
3722
|
+
feedback: opts.feedback,
|
|
3723
|
+
...opts.to ? { agent_alias: opts.to } : {}
|
|
3724
|
+
},
|
|
3725
|
+
Boolean(opts.json)
|
|
3726
|
+
)
|
|
3727
|
+
)
|
|
3728
|
+
);
|
|
3729
|
+
program.command("assign").description(
|
|
3730
|
+
"Orchestrator: tetapkan persona atau role penanggung jawab task (setara manage_task)"
|
|
3731
|
+
).argument("<task_id>").option("--to <alias>", "Persona penanggung jawab").option("--role <role>", "Role task tanpa persona tertentu").option("--unassign", "Lepas persona (task diambil berdasarkan role)").option(...AGENT_OPT).option("--json", "Keluaran JSON").action(
|
|
3732
|
+
(taskId, opts) => friendly(
|
|
3733
|
+
async () => taskManage(
|
|
3734
|
+
await cliApi(opts.agent),
|
|
3735
|
+
{
|
|
3736
|
+
action: "assign",
|
|
3737
|
+
task_id: taskId,
|
|
3738
|
+
...opts.unassign ? { agent_alias: null } : opts.to ? { agent_alias: opts.to } : {},
|
|
3739
|
+
...opts.role ? { role: opts.role } : {}
|
|
3740
|
+
},
|
|
3741
|
+
Boolean(opts.json)
|
|
3742
|
+
)
|
|
3743
|
+
)
|
|
3744
|
+
);
|
|
2980
3745
|
var review = program.command("review").description("Antrean dan keputusan review pull request");
|
|
2981
3746
|
review.command("list").option("-n, --limit <n>", "Jumlah maksimal", Number, 10).option(...AGENT_OPT).option("--json").action(
|
|
2982
3747
|
(opts) => friendly(
|