opencode-gitlab-dap 1.8.0 → 1.8.2

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/dist/index.js CHANGED
@@ -3442,16 +3442,17 @@ async function searchWikiPages(instanceUrl, token, scope, id, query) {
3442
3442
 
3443
3443
  // src/tools/memory-tools.ts
3444
3444
  var z5 = tool5.schema;
3445
+ var PREFIX = "agents";
3445
3446
  var MEMORY_SLUGS = {
3446
- all: ["memory/facts", "memory/decisions", "memory/patterns"],
3447
- facts: ["memory/facts"],
3448
- decisions: ["memory/decisions"],
3449
- patterns: ["memory/patterns"]
3447
+ all: [`${PREFIX}/memory/facts`, `${PREFIX}/memory/decisions`, `${PREFIX}/memory/patterns`],
3448
+ facts: [`${PREFIX}/memory/facts`],
3449
+ decisions: [`${PREFIX}/memory/decisions`],
3450
+ patterns: [`${PREFIX}/memory/patterns`]
3450
3451
  };
3451
3452
  var RECORD_SLUG = {
3452
- fact: "memory/facts",
3453
- decision: "memory/decisions",
3454
- pattern: "memory/patterns"
3453
+ fact: `${PREFIX}/memory/facts`,
3454
+ decision: `${PREFIX}/memory/decisions`,
3455
+ pattern: `${PREFIX}/memory/patterns`
3455
3456
  };
3456
3457
  function today() {
3457
3458
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
@@ -3467,15 +3468,20 @@ async function safeRead(instanceUrl, token, scope, id, slug) {
3467
3468
  return null;
3468
3469
  }
3469
3470
  }
3470
- async function appendToPage(instanceUrl, token, scope, id, slug, newContent, pageTitle) {
3471
+ async function appendToPage(instanceUrl, token, scope, id, slug, newContent) {
3471
3472
  const existing = await safeRead(instanceUrl, token, scope, id, slug);
3472
3473
  if (existing !== null) {
3473
3474
  await updateWikiPage(instanceUrl, token, scope, id, slug, existing + "\n\n" + newContent);
3474
3475
  } else {
3475
- const title = pageTitle ?? slug.split("/").pop() ?? slug;
3476
- await createWikiPage(instanceUrl, token, scope, id, title, newContent);
3476
+ await createWikiPage(instanceUrl, token, scope, id, slug, newContent);
3477
3477
  }
3478
3478
  }
3479
+ function validateProjectId(projectId) {
3480
+ if (!projectId.includes("/")) {
3481
+ return `Invalid project_id "${projectId}". Must be the full project path containing at least one slash (e.g., "my-group/my-project"), not just the project name.`;
3482
+ }
3483
+ return null;
3484
+ }
3479
3485
  function resolveScope(args) {
3480
3486
  if (args.scope === "groups" && args.group_id) {
3481
3487
  return { scope: "groups", id: args.group_id };
@@ -3483,18 +3489,26 @@ function resolveScope(args) {
3483
3489
  return { scope: "projects", id: args.project_id };
3484
3490
  }
3485
3491
  function makeMemoryTools(ctx) {
3492
+ function authAndValidate(projectId) {
3493
+ const auth = ctx.ensureAuth();
3494
+ if (!auth) throw new Error("GitLab authentication not available");
3495
+ const err = validateProjectId(projectId);
3496
+ if (err) throw new Error(err);
3497
+ return auth;
3498
+ }
3486
3499
  return {
3487
3500
  gitlab_memory_load: tool5({
3488
3501
  description: "Load project memory to understand context, known facts, past decisions, and observed patterns.\nUse this at the start of complex tasks to check what is already known about the project.\nReturns accumulated knowledge from previous sessions.",
3489
3502
  args: {
3490
- project_id: z5.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3503
+ project_id: z5.string().describe(
3504
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3505
+ ),
3491
3506
  type: z5.enum(["all", "facts", "decisions", "patterns"]).optional().describe('Which memory to load: "all" (default), "facts", "decisions", or "patterns"'),
3492
3507
  scope: z5.enum(["projects", "groups"]).optional().describe("Scope (default: projects)"),
3493
3508
  group_id: z5.string().optional().describe("Group path (required when scope is groups)")
3494
3509
  },
3495
3510
  execute: async (args) => {
3496
- const auth = ctx.ensureAuth();
3497
- if (!auth) throw new Error("GitLab authentication not available");
3511
+ const auth = authAndValidate(args.project_id);
3498
3512
  const { scope, id } = resolveScope(args);
3499
3513
  const memType = args.type ?? "all";
3500
3514
  const slugs = MEMORY_SLUGS[memType];
@@ -3515,17 +3529,18 @@ ${content}`);
3515
3529
  }
3516
3530
  }),
3517
3531
  gitlab_memory_record: tool5({
3518
- description: "Record a fact, decision, or pattern in project memory.\nFacts: stable truths about the project (e.g., deploy targets, tech stack, team conventions).\nDecisions: architectural choices with reasoning (why X was chosen over Y).\nPatterns: recurring observations that may evolve into skills over time.\nEntries are automatically timestamped.",
3532
+ description: "Record a fact, decision, or pattern in project memory.\nFacts: stable truths about the project (e.g., deploy targets, tech stack, team conventions).\nDecisions: architectural choices with reasoning (why X was chosen over Y).\nPatterns: recurring observations that may evolve into skills over time.\nEntries are automatically timestamped and appended to the appropriate memory page.\nMultiple facts can be recorded in a single call by separating them with newlines.",
3519
3533
  args: {
3520
- project_id: z5.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3534
+ project_id: z5.string().describe(
3535
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3536
+ ),
3521
3537
  type: z5.enum(["fact", "decision", "pattern"]).describe("Type of knowledge to record"),
3522
3538
  content: z5.string().describe("The knowledge to record (markdown)"),
3523
3539
  scope: z5.enum(["projects", "groups"]).optional().describe("Scope (default: projects)"),
3524
3540
  group_id: z5.string().optional().describe("Group path (required when scope is groups)")
3525
3541
  },
3526
3542
  execute: async (args) => {
3527
- const auth = ctx.ensureAuth();
3528
- if (!auth) throw new Error("GitLab authentication not available");
3543
+ const auth = authAndValidate(args.project_id);
3529
3544
  const { scope, id } = resolveScope(args);
3530
3545
  const slug = RECORD_SLUG[args.type];
3531
3546
  if (!slug) return `Unknown memory type: ${args.type}`;
@@ -3553,14 +3568,15 @@ ${args.content}`;
3553
3568
  gitlab_memory_recall: tool5({
3554
3569
  description: "Search project knowledge for relevant information.\nSearches across all memory pages, session logs, and skills.\nUse this to check if something is already known before investigating.",
3555
3570
  args: {
3556
- project_id: z5.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3571
+ project_id: z5.string().describe(
3572
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3573
+ ),
3557
3574
  query: z5.string().describe("What to search for"),
3558
3575
  scope: z5.enum(["projects", "groups"]).optional().describe("Scope (default: projects)"),
3559
3576
  group_id: z5.string().optional().describe("Group path (required when scope is groups)")
3560
3577
  },
3561
3578
  execute: async (args) => {
3562
- const auth = ctx.ensureAuth();
3563
- if (!auth) throw new Error("GitLab authentication not available");
3579
+ const auth = authAndValidate(args.project_id);
3564
3580
  const { scope, id } = resolveScope(args);
3565
3581
  try {
3566
3582
  const results = await searchWikiPages(
@@ -3572,7 +3588,7 @@ ${args.content}`;
3572
3588
  );
3573
3589
  if (results.length === 0) return `No knowledge found matching "${args.query}".`;
3574
3590
  return results.map((r) => {
3575
- const category = r.path.startsWith("memory/") ? "memory" : r.path.startsWith("skills") ? "skill" : "other";
3591
+ const category = r.path.includes("/memory/") ? "memory" : r.path.includes("/skills") ? "skill" : "other";
3576
3592
  const snippet = (r.data ?? "").slice(0, 200).replace(/\n/g, " ");
3577
3593
  return `[${category}] ${r.path}: ${snippet}`;
3578
3594
  }).join("\n\n");
@@ -3584,7 +3600,9 @@ ${args.content}`;
3584
3600
  gitlab_memory_log_session: tool5({
3585
3601
  description: "Log a session summary including what was accomplished, what was learned, and any suggestions.\nUse this at the end of significant work sessions to preserve context for future sessions.",
3586
3602
  args: {
3587
- project_id: z5.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3603
+ project_id: z5.string().describe(
3604
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3605
+ ),
3588
3606
  title: z5.string().describe('Brief session title (e.g., "fix-ai-gateway-healthcheck")'),
3589
3607
  summary: z5.string().describe(
3590
3608
  "Session summary in markdown (what happened, what was learned, what went wrong)"
@@ -3593,27 +3611,17 @@ ${args.content}`;
3593
3611
  group_id: z5.string().optional().describe("Group path (required when scope is groups)")
3594
3612
  },
3595
3613
  execute: async (args) => {
3596
- const auth = ctx.ensureAuth();
3597
- if (!auth) throw new Error("GitLab authentication not available");
3614
+ const auth = authAndValidate(args.project_id);
3598
3615
  const { scope, id } = resolveScope(args);
3599
3616
  const date = today();
3600
- const slug = `memory/sessions/${date}-${slugify(args.title)}`;
3601
- const pageTitle = `${date}: ${args.title}`;
3617
+ const slug = `${PREFIX}/memory/sessions/${date}-${slugify(args.title)}`;
3602
3618
  try {
3603
- await createWikiPage(auth.instanceUrl, auth.token, scope, id, pageTitle, args.summary);
3619
+ await createWikiPage(auth.instanceUrl, auth.token, scope, id, slug, args.summary);
3604
3620
  return `Session logged: ${slug}`;
3605
3621
  } catch (err) {
3606
3622
  if (err.message?.includes("already exists") || err.message?.includes("422")) {
3607
3623
  try {
3608
- await updateWikiPage(
3609
- auth.instanceUrl,
3610
- auth.token,
3611
- scope,
3612
- id,
3613
- slug,
3614
- args.summary,
3615
- pageTitle
3616
- );
3624
+ await updateWikiPage(auth.instanceUrl, auth.token, scope, id, slug, args.summary);
3617
3625
  return `Session log updated: ${slug}`;
3618
3626
  } catch (err2) {
3619
3627
  return `Error logging session: ${err2.message}`;
@@ -3629,35 +3637,56 @@ ${args.content}`;
3629
3637
  // src/tools/skill-tools.ts
3630
3638
  import { tool as tool6 } from "@opencode-ai/plugin";
3631
3639
  var z6 = tool6.schema;
3640
+ var PREFIX2 = "agents";
3641
+ var SKILLS_PREFIX = `${PREFIX2}/skills`;
3642
+ var DRAFTS_PREFIX = `${PREFIX2}/skills-drafts`;
3632
3643
  function resolveScope2(args) {
3633
3644
  if (args.scope === "groups" && args.group_id) {
3634
3645
  return { scope: "groups", id: args.group_id };
3635
3646
  }
3636
3647
  return { scope: "projects", id: args.project_id };
3637
3648
  }
3649
+ function validateProjectId2(projectId) {
3650
+ if (!projectId.includes("/")) {
3651
+ return `Invalid project_id "${projectId}". Must be the full project path containing at least one slash (e.g., "my-group/my-project"), not just the project name.`;
3652
+ }
3653
+ return null;
3654
+ }
3638
3655
  function makeSkillTools(ctx) {
3656
+ function authAndValidate(projectId) {
3657
+ const auth = ctx.ensureAuth();
3658
+ if (!auth) throw new Error("GitLab authentication not available");
3659
+ const err = validateProjectId2(projectId);
3660
+ if (err) throw new Error(err);
3661
+ return auth;
3662
+ }
3639
3663
  return {
3640
3664
  gitlab_skill_list: tool6({
3641
3665
  description: "List available project skills and optionally draft skills.\nSkills define step-by-step procedures for common tasks (e.g., incident retros, debugging, deployments).",
3642
3666
  args: {
3643
- project_id: z6.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3667
+ project_id: z6.string().describe(
3668
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3669
+ ),
3644
3670
  include_drafts: z6.boolean().optional().describe("Also list draft skills (default: false)"),
3645
3671
  scope: z6.enum(["projects", "groups"]).optional().describe("Scope (default: projects)"),
3646
3672
  group_id: z6.string().optional().describe("Group path (required when scope is groups)")
3647
3673
  },
3648
3674
  execute: async (args) => {
3649
- const auth = ctx.ensureAuth();
3650
- if (!auth) throw new Error("GitLab authentication not available");
3675
+ const auth = authAndValidate(args.project_id);
3651
3676
  const { scope, id } = resolveScope2(args);
3652
3677
  try {
3653
3678
  const pages = await listWikiPages(auth.instanceUrl, auth.token, scope, id);
3654
- const skills = pages.filter((p) => p.slug.startsWith("skills/") && p.slug !== "skills/index").map((p) => ({ name: p.slug.replace("skills/", ""), title: p.title, draft: false }));
3679
+ const indexSlug = `${SKILLS_PREFIX}/index`;
3680
+ const skills = pages.filter((p) => p.slug.startsWith(`${SKILLS_PREFIX}/`) && p.slug !== indexSlug).map((p) => ({
3681
+ name: p.slug.slice(SKILLS_PREFIX.length + 1),
3682
+ title: p.title,
3683
+ draft: false
3684
+ }));
3655
3685
  let drafts = [];
3656
3686
  if (args.include_drafts) {
3657
- drafts = pages.filter(
3658
- (p) => p.slug.startsWith("skills-drafts/") && p.slug !== "skills-drafts/index"
3659
- ).map((p) => ({
3660
- name: p.slug.replace("skills-drafts/", ""),
3687
+ const draftsIndexSlug = `${DRAFTS_PREFIX}/index`;
3688
+ drafts = pages.filter((p) => p.slug.startsWith(`${DRAFTS_PREFIX}/`) && p.slug !== draftsIndexSlug).map((p) => ({
3689
+ name: p.slug.slice(DRAFTS_PREFIX.length + 1),
3661
3690
  title: p.title,
3662
3691
  draft: true
3663
3692
  }));
@@ -3673,14 +3702,15 @@ function makeSkillTools(ctx) {
3673
3702
  gitlab_skill_load: tool6({
3674
3703
  description: "Load a specific skill by name.\nSkills contain step-by-step instructions for common tasks.\nChecks published skills first, then falls back to draft skills.",
3675
3704
  args: {
3676
- project_id: z6.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3705
+ project_id: z6.string().describe(
3706
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3707
+ ),
3677
3708
  name: z6.string().describe('Skill name (e.g., "incident-retro", "helm-rollback")'),
3678
3709
  scope: z6.enum(["projects", "groups"]).optional().describe("Scope (default: projects)"),
3679
3710
  group_id: z6.string().optional().describe("Group path (required when scope is groups)")
3680
3711
  },
3681
3712
  execute: async (args) => {
3682
- const auth = ctx.ensureAuth();
3683
- if (!auth) throw new Error("GitLab authentication not available");
3713
+ const auth = authAndValidate(args.project_id);
3684
3714
  const { scope, id } = resolveScope2(args);
3685
3715
  try {
3686
3716
  const page = await getWikiPage(
@@ -3688,7 +3718,7 @@ function makeSkillTools(ctx) {
3688
3718
  auth.token,
3689
3719
  scope,
3690
3720
  id,
3691
- `skills/${args.name}`
3721
+ `${SKILLS_PREFIX}/${args.name}`
3692
3722
  );
3693
3723
  return page.content;
3694
3724
  } catch {
@@ -3698,7 +3728,7 @@ function makeSkillTools(ctx) {
3698
3728
  auth.token,
3699
3729
  scope,
3700
3730
  id,
3701
- `skills-drafts/${args.name}`
3731
+ `${DRAFTS_PREFIX}/${args.name}`
3702
3732
  );
3703
3733
  return `[DRAFT SKILL]
3704
3734
 
@@ -3712,7 +3742,9 @@ ${draft.content}`;
3712
3742
  gitlab_skill_save: tool6({
3713
3743
  description: "Create or update a skill.\nSkills define step-by-step procedures for common tasks.\nUse draft=true for skills that haven't been proven yet.",
3714
3744
  args: {
3715
- project_id: z6.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3745
+ project_id: z6.string().describe(
3746
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3747
+ ),
3716
3748
  name: z6.string().describe('Skill name (e.g., "incident-retro")'),
3717
3749
  content: z6.string().describe("Skill content in markdown"),
3718
3750
  draft: z6.boolean().optional().describe("Save as draft skill (default: false)"),
@@ -3720,25 +3752,16 @@ ${draft.content}`;
3720
3752
  group_id: z6.string().optional().describe("Group path (required when scope is groups)")
3721
3753
  },
3722
3754
  execute: async (args) => {
3723
- const auth = ctx.ensureAuth();
3724
- if (!auth) throw new Error("GitLab authentication not available");
3755
+ const auth = authAndValidate(args.project_id);
3725
3756
  const { scope, id } = resolveScope2(args);
3726
- const prefix = args.draft ? "skills-drafts" : "skills";
3757
+ const prefix = args.draft ? DRAFTS_PREFIX : SKILLS_PREFIX;
3727
3758
  const slug = `${prefix}/${args.name}`;
3728
3759
  try {
3729
- await updateWikiPage(
3730
- auth.instanceUrl,
3731
- auth.token,
3732
- scope,
3733
- id,
3734
- slug,
3735
- args.content,
3736
- args.name
3737
- );
3760
+ await updateWikiPage(auth.instanceUrl, auth.token, scope, id, slug, args.content);
3738
3761
  return `Updated ${args.draft ? "draft " : ""}skill: ${args.name}`;
3739
3762
  } catch {
3740
3763
  try {
3741
- await createWikiPage(auth.instanceUrl, auth.token, scope, id, args.name, args.content);
3764
+ await createWikiPage(auth.instanceUrl, auth.token, scope, id, slug, args.content);
3742
3765
  return `Created ${args.draft ? "draft " : ""}skill: ${args.name}`;
3743
3766
  } catch (err) {
3744
3767
  return `Error saving skill: ${err.message}`;
@@ -3749,43 +3772,40 @@ ${draft.content}`;
3749
3772
  gitlab_skill_promote: tool6({
3750
3773
  description: "Promote a draft skill to published.\nMoves the skill from the drafts directory to the published skills directory.",
3751
3774
  args: {
3752
- project_id: z6.string().describe('Project path (e.g., "gitlab-org/gitlab"). Use the same value consistently.'),
3775
+ project_id: z6.string().describe(
3776
+ 'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
3777
+ ),
3753
3778
  name: z6.string().describe("Skill name to promote"),
3754
3779
  scope: z6.enum(["projects", "groups"]).optional().describe("Scope (default: projects)"),
3755
3780
  group_id: z6.string().optional().describe("Group path (required when scope is groups)")
3756
3781
  },
3757
3782
  execute: async (args) => {
3758
- const auth = ctx.ensureAuth();
3759
- if (!auth) throw new Error("GitLab authentication not available");
3783
+ const auth = authAndValidate(args.project_id);
3760
3784
  const { scope, id } = resolveScope2(args);
3785
+ const draftSlug = `${DRAFTS_PREFIX}/${args.name}`;
3786
+ const publishedSlug = `${SKILLS_PREFIX}/${args.name}`;
3761
3787
  try {
3762
- const draft = await getWikiPage(
3763
- auth.instanceUrl,
3764
- auth.token,
3765
- scope,
3766
- id,
3767
- `skills-drafts/${args.name}`
3768
- );
3788
+ const draft = await getWikiPage(auth.instanceUrl, auth.token, scope, id, draftSlug);
3769
3789
  try {
3770
3790
  await updateWikiPage(
3771
3791
  auth.instanceUrl,
3772
3792
  auth.token,
3773
3793
  scope,
3774
3794
  id,
3775
- `skills/${args.name}`,
3776
- draft.content,
3777
- args.name
3795
+ publishedSlug,
3796
+ draft.content
3778
3797
  );
3779
3798
  } catch {
3780
- await createWikiPage(auth.instanceUrl, auth.token, scope, id, args.name, draft.content);
3799
+ await createWikiPage(
3800
+ auth.instanceUrl,
3801
+ auth.token,
3802
+ scope,
3803
+ id,
3804
+ publishedSlug,
3805
+ draft.content
3806
+ );
3781
3807
  }
3782
- await deleteWikiPage(
3783
- auth.instanceUrl,
3784
- auth.token,
3785
- scope,
3786
- id,
3787
- `skills-drafts/${args.name}`
3788
- );
3808
+ await deleteWikiPage(auth.instanceUrl, auth.token, scope, id, draftSlug);
3789
3809
  return `Promoted skill "${args.name}" from draft to published.`;
3790
3810
  } catch (err) {
3791
3811
  if (err.message?.includes("not found") || err.message?.includes("404")) {