opencode-gitlab-dap 1.8.3 → 1.8.4

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
@@ -3443,13 +3443,13 @@ async function searchWikiPages(instanceUrl, token, scope, id, query) {
3443
3443
  // src/tools/memory-tools.ts
3444
3444
  var z5 = tool5.schema;
3445
3445
  var PREFIX = "agents";
3446
- var MEMORY_SLUGS = {
3446
+ var MEMORY_DIRS = {
3447
3447
  all: [`${PREFIX}/memory/facts`, `${PREFIX}/memory/decisions`, `${PREFIX}/memory/patterns`],
3448
3448
  facts: [`${PREFIX}/memory/facts`],
3449
3449
  decisions: [`${PREFIX}/memory/decisions`],
3450
3450
  patterns: [`${PREFIX}/memory/patterns`]
3451
3451
  };
3452
- var RECORD_SLUG = {
3452
+ var RECORD_DIR = {
3453
3453
  fact: `${PREFIX}/memory/facts`,
3454
3454
  decision: `${PREFIX}/memory/decisions`,
3455
3455
  pattern: `${PREFIX}/memory/patterns`
@@ -3460,52 +3460,9 @@ function today() {
3460
3460
  function slugify(text) {
3461
3461
  return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "").slice(0, 60);
3462
3462
  }
3463
- async function safeRead(instanceUrl, token, scope, id, slug) {
3464
- try {
3465
- const page = await getWikiPage(instanceUrl, token, scope, id, slug);
3466
- return page.content;
3467
- } catch {
3468
- return null;
3469
- }
3470
- }
3471
- var MAX_RETRIES = 3;
3472
- var RETRY_DELAY_MS = 1e3;
3473
- async function sleep2(ms) {
3474
- return new Promise((resolve) => setTimeout(resolve, ms));
3475
- }
3476
- async function appendToPage(instanceUrl, token, scope, id, slug, newContent) {
3477
- for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3478
- const existing2 = await safeRead(instanceUrl, token, scope, id, slug);
3479
- if (existing2 !== null) {
3480
- try {
3481
- await updateWikiPage(instanceUrl, token, scope, id, slug, existing2 + "\n\n" + newContent);
3482
- return;
3483
- } catch (err) {
3484
- if (attempt < MAX_RETRIES - 1 && err.message?.includes("reference update")) {
3485
- await sleep2(RETRY_DELAY_MS * (attempt + 1));
3486
- continue;
3487
- }
3488
- throw err;
3489
- }
3490
- } else {
3491
- try {
3492
- await createWikiPage(instanceUrl, token, scope, id, slug, newContent);
3493
- return;
3494
- } catch (err) {
3495
- if (err.message?.includes("Duplicate page") || err.message?.includes("reference update")) {
3496
- await sleep2(RETRY_DELAY_MS * (attempt + 1));
3497
- continue;
3498
- }
3499
- throw err;
3500
- }
3501
- }
3502
- }
3503
- const existing = await safeRead(instanceUrl, token, scope, id, slug);
3504
- if (existing !== null) {
3505
- await updateWikiPage(instanceUrl, token, scope, id, slug, existing + "\n\n" + newContent);
3506
- } else {
3507
- throw new Error(`Failed to append to ${slug} after ${MAX_RETRIES} retries`);
3508
- }
3463
+ function titleFromContent(content) {
3464
+ const first = content.split("\n")[0].replace(/^[#*\->\s]+/, "").trim();
3465
+ return first.slice(0, 80) || "untitled";
3509
3466
  }
3510
3467
  function validateProjectId(projectId) {
3511
3468
  if (!projectId.includes("/")) {
@@ -3542,25 +3499,38 @@ function makeMemoryTools(ctx) {
3542
3499
  const auth = authAndValidate(args.project_id);
3543
3500
  const { scope, id } = resolveScope(args);
3544
3501
  const memType = args.type ?? "all";
3545
- const slugs = MEMORY_SLUGS[memType];
3546
- if (!slugs) return `Unknown memory type: ${memType}`;
3547
- const sections = [];
3548
- for (const slug of slugs) {
3549
- const content = await safeRead(auth.instanceUrl, auth.token, scope, id, slug);
3550
- if (content) {
3551
- const label = slug.split("/").pop();
3552
- sections.push(`## ${label.charAt(0).toUpperCase() + label.slice(1)}
3553
-
3554
- ${content}`);
3502
+ const dirs = MEMORY_DIRS[memType];
3503
+ if (!dirs) return `Unknown memory type: ${memType}`;
3504
+ try {
3505
+ const allPages = await listWikiPages(
3506
+ auth.instanceUrl,
3507
+ auth.token,
3508
+ scope,
3509
+ id,
3510
+ true
3511
+ );
3512
+ const sections = [];
3513
+ for (const dir of dirs) {
3514
+ const label = dir.split("/").pop();
3515
+ const pages = allPages.filter((p) => p.slug.startsWith(dir + "/") && p.content);
3516
+ if (pages.length === 0) continue;
3517
+ const entries = pages.map((p) => p.content).join("\n\n---\n\n");
3518
+ sections.push(
3519
+ `## ${label.charAt(0).toUpperCase() + label.slice(1)} (${pages.length})
3520
+
3521
+ ${entries}`
3522
+ );
3555
3523
  }
3524
+ if (sections.length === 0)
3525
+ return "No project memory found. Use gitlab_memory_record to start building project knowledge.";
3526
+ return sections.join("\n\n---\n\n");
3527
+ } catch (err) {
3528
+ return `Error loading memory: ${err.message}`;
3556
3529
  }
3557
- if (sections.length === 0)
3558
- return "No project memory found. Use gitlab_memory_record to start building project knowledge.";
3559
- return sections.join("\n\n---\n\n");
3560
3530
  }
3561
3531
  }),
3562
3532
  gitlab_memory_record: tool5({
3563
- 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.",
3533
+ 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.\nEach record creates its own page \u2014 safe for parallel writes.",
3564
3534
  args: {
3565
3535
  project_id: z5.string().describe(
3566
3536
  'FULL project path with namespace (e.g., "gitlab-org/gitlab"). Must contain a slash. Never use just the project name.'
@@ -3573,24 +3543,18 @@ ${content}`);
3573
3543
  execute: async (args) => {
3574
3544
  const auth = authAndValidate(args.project_id);
3575
3545
  const { scope, id } = resolveScope(args);
3576
- const slug = RECORD_SLUG[args.type];
3577
- if (!slug) return `Unknown memory type: ${args.type}`;
3546
+ const dir = RECORD_DIR[args.type];
3547
+ if (!dir) return `Unknown memory type: ${args.type}`;
3578
3548
  const date = today();
3579
- let formatted;
3580
- if (args.type === "decision") {
3581
- const firstLine = args.content.split("\n")[0];
3582
- const rest = args.content.split("\n").slice(1).join("\n").trim();
3583
- formatted = `## ${date}: ${firstLine}${rest ? "\n" + rest : ""}`;
3584
- } else if (args.type === "fact") {
3585
- formatted = `## ${date}
3586
- - ${args.content.replace(/\n/g, "\n- ")}`;
3587
- } else {
3588
- formatted = `## ${date}
3589
- ${args.content}`;
3590
- }
3549
+ const title = titleFromContent(args.content);
3550
+ const slug = `${dir}/${date}-${slugify(title)}`;
3551
+ const header = `*Recorded: ${date} | Type: ${args.type}*
3552
+
3553
+ `;
3554
+ const body = header + args.content;
3591
3555
  try {
3592
- await appendToPage(auth.instanceUrl, auth.token, scope, id, slug, formatted);
3593
- return `Recorded ${args.type} in project memory.`;
3556
+ await createWikiPage(auth.instanceUrl, auth.token, scope, id, slug, body);
3557
+ return `Recorded ${args.type} in project memory: ${slug}`;
3594
3558
  } catch (err) {
3595
3559
  return `Error recording ${args.type}: ${err.message}`;
3596
3560
  }
@@ -3646,32 +3610,12 @@ ${args.content}`;
3646
3610
  const { scope, id } = resolveScope(args);
3647
3611
  const date = today();
3648
3612
  const slug = `${PREFIX}/memory/sessions/${date}-${slugify(args.title)}`;
3649
- for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3650
- try {
3651
- await createWikiPage(auth.instanceUrl, auth.token, scope, id, slug, args.summary);
3652
- return `Session logged: ${slug}`;
3653
- } catch (err) {
3654
- const msg = err.message ?? "";
3655
- if (msg.includes("Duplicate page") || msg.includes("already exists") || msg.includes("422")) {
3656
- try {
3657
- await updateWikiPage(auth.instanceUrl, auth.token, scope, id, slug, args.summary);
3658
- return `Session log updated: ${slug}`;
3659
- } catch (err2) {
3660
- if (attempt < MAX_RETRIES - 1 && err2.message?.includes("reference update")) {
3661
- await sleep2(RETRY_DELAY_MS * (attempt + 1));
3662
- continue;
3663
- }
3664
- return `Error logging session: ${err2.message}`;
3665
- }
3666
- }
3667
- if (attempt < MAX_RETRIES - 1 && msg.includes("reference update")) {
3668
- await sleep2(RETRY_DELAY_MS * (attempt + 1));
3669
- continue;
3670
- }
3671
- return `Error logging session: ${msg}`;
3672
- }
3613
+ try {
3614
+ await createWikiPage(auth.instanceUrl, auth.token, scope, id, slug, args.summary);
3615
+ return `Session logged: ${slug}`;
3616
+ } catch (err) {
3617
+ return `Error logging session: ${err.message}`;
3673
3618
  }
3674
- return `Error logging session: failed after ${MAX_RETRIES} retries`;
3675
3619
  }
3676
3620
  })
3677
3621
  };