opencode-gitlab-dap 1.16.4 → 1.16.5
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.cjs +33 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -124
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3950,73 +3950,6 @@ ${e.content}`).join("\n\n---\n\n");
|
|
|
3950
3950
|
|
|
3951
3951
|
// src/tools/skill-tools.ts
|
|
3952
3952
|
var import_plugin6 = require("@opencode-ai/plugin");
|
|
3953
|
-
|
|
3954
|
-
// src/snippets.ts
|
|
3955
|
-
function snippetApi(instanceUrl, token, projectId) {
|
|
3956
|
-
const base = instanceUrl.replace(/\/$/, "");
|
|
3957
|
-
const encoded = typeof projectId === "number" ? projectId : encodeURIComponent(projectId);
|
|
3958
|
-
return {
|
|
3959
|
-
url: `${base}/api/v4/projects/${encoded}/snippets`,
|
|
3960
|
-
headers: {
|
|
3961
|
-
"Content-Type": "application/json",
|
|
3962
|
-
Authorization: `Bearer ${token}`
|
|
3963
|
-
}
|
|
3964
|
-
};
|
|
3965
|
-
}
|
|
3966
|
-
async function handleResponse2(res) {
|
|
3967
|
-
if (!res.ok) {
|
|
3968
|
-
const text = await res.text();
|
|
3969
|
-
throw new Error(`Snippet API error (${res.status}): ${text}`);
|
|
3970
|
-
}
|
|
3971
|
-
return res.json();
|
|
3972
|
-
}
|
|
3973
|
-
async function createProjectSnippet(instanceUrl, token, projectId, title, description, files, visibility = "private") {
|
|
3974
|
-
const { url, headers } = snippetApi(instanceUrl, token, projectId);
|
|
3975
|
-
const res = await fetch(url, {
|
|
3976
|
-
method: "POST",
|
|
3977
|
-
headers,
|
|
3978
|
-
body: JSON.stringify({ title, description, visibility, files })
|
|
3979
|
-
});
|
|
3980
|
-
return handleResponse2(res);
|
|
3981
|
-
}
|
|
3982
|
-
async function deleteProjectSnippet(instanceUrl, token, projectId, snippetId) {
|
|
3983
|
-
const { url, headers } = snippetApi(instanceUrl, token, projectId);
|
|
3984
|
-
const res = await fetch(`${url}/${snippetId}`, { method: "DELETE", headers });
|
|
3985
|
-
if (!res.ok) {
|
|
3986
|
-
const text = await res.text();
|
|
3987
|
-
throw new Error(`Snippet API error (${res.status}): ${text}`);
|
|
3988
|
-
}
|
|
3989
|
-
}
|
|
3990
|
-
async function getSnippetFileRaw(instanceUrl, token, projectId, snippetId, filePath, ref = "main") {
|
|
3991
|
-
const base = instanceUrl.replace(/\/$/, "");
|
|
3992
|
-
const encoded = typeof projectId === "number" ? projectId : encodeURIComponent(projectId);
|
|
3993
|
-
const encodedPath = encodeURIComponent(filePath);
|
|
3994
|
-
const url = `${base}/api/v4/projects/${encoded}/snippets/${snippetId}/files/${ref}/${encodedPath}/raw`;
|
|
3995
|
-
const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
|
3996
|
-
if (!res.ok) {
|
|
3997
|
-
const text = await res.text();
|
|
3998
|
-
throw new Error(`Snippet file API error (${res.status}): ${text}`);
|
|
3999
|
-
}
|
|
4000
|
-
return res.text();
|
|
4001
|
-
}
|
|
4002
|
-
async function listSnippetFiles(instanceUrl, token, projectId, snippetId) {
|
|
4003
|
-
const base = instanceUrl.replace(/\/$/, "");
|
|
4004
|
-
const encoded = typeof projectId === "number" ? projectId : encodeURIComponent(projectId);
|
|
4005
|
-
const url = `${base}/api/v4/projects/${encoded}/snippets/${snippetId}`;
|
|
4006
|
-
const res = await fetch(url, {
|
|
4007
|
-
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }
|
|
4008
|
-
});
|
|
4009
|
-
const snippet = await handleResponse2(res);
|
|
4010
|
-
if (snippet.files) {
|
|
4011
|
-
return snippet.files.map((f) => ({ path: f.path, raw_url: f.raw_url }));
|
|
4012
|
-
}
|
|
4013
|
-
if (snippet.file_name) {
|
|
4014
|
-
return [{ path: snippet.file_name, raw_url: snippet.raw_url }];
|
|
4015
|
-
}
|
|
4016
|
-
return [];
|
|
4017
|
-
}
|
|
4018
|
-
|
|
4019
|
-
// src/tools/skill-tools.ts
|
|
4020
3953
|
var import_fs3 = require("fs");
|
|
4021
3954
|
var import_path3 = require("path");
|
|
4022
3955
|
|
|
@@ -4042,14 +3975,12 @@ function parseFrontmatter(content) {
|
|
|
4042
3975
|
if (k === "name") meta.name = val;
|
|
4043
3976
|
else if (k === "description") meta.description = val;
|
|
4044
3977
|
else if (k === "source") meta.source = val;
|
|
4045
|
-
else if (k === "snippet") meta.snippetId = parseInt(val, 10) || void 0;
|
|
4046
3978
|
}
|
|
4047
3979
|
return { meta, body: match[2] };
|
|
4048
3980
|
}
|
|
4049
3981
|
function formatFrontmatter(meta, body) {
|
|
4050
3982
|
const lines = ["---", `name: ${meta.name}`, `description: ${meta.description}`];
|
|
4051
3983
|
if (meta.source) lines.push(`source: ${meta.source}`);
|
|
4052
|
-
if (meta.snippetId) lines.push(`snippet: ${meta.snippetId}`);
|
|
4053
3984
|
lines.push("---", "");
|
|
4054
3985
|
return lines.join("\n") + body;
|
|
4055
3986
|
}
|
|
@@ -4207,11 +4138,12 @@ async function listSkills(instanceUrl, token, scope, id, prefix) {
|
|
|
4207
4138
|
const name = extractSkillNameFromSlug(page.slug, prefix);
|
|
4208
4139
|
if (!name || !page.content) continue;
|
|
4209
4140
|
const { meta } = parseFrontmatter(page.content);
|
|
4141
|
+
const hasBundle = pages.some((p) => p.slug === `${prefix}/${name}/bundle`);
|
|
4210
4142
|
skills.push({
|
|
4211
4143
|
name: meta.name ?? name,
|
|
4212
4144
|
description: meta.description ?? "",
|
|
4213
4145
|
source: meta.source,
|
|
4214
|
-
|
|
4146
|
+
hasScripts: hasBundle,
|
|
4215
4147
|
draft: prefix === DRAFTS_PREFIX
|
|
4216
4148
|
});
|
|
4217
4149
|
}
|
|
@@ -4277,7 +4209,7 @@ function makeSkillTools(ctx) {
|
|
|
4277
4209
|
id,
|
|
4278
4210
|
`${prefix}/${args.name}/SKILL`
|
|
4279
4211
|
);
|
|
4280
|
-
const {
|
|
4212
|
+
const { body } = parseFrontmatter(page.content);
|
|
4281
4213
|
const isDraft = prefix === DRAFTS_PREFIX;
|
|
4282
4214
|
const pages = await listWikiPages(auth.instanceUrl, auth.token, scope, id);
|
|
4283
4215
|
const skillPrefix = `${prefix}/${args.name}/`;
|
|
@@ -4293,10 +4225,11 @@ ${body}` : body;
|
|
|
4293
4225
|
---
|
|
4294
4226
|
Available references: ${refs.join(", ")}`;
|
|
4295
4227
|
}
|
|
4296
|
-
|
|
4228
|
+
const hasBundle = refs.some((r) => r === "bundle");
|
|
4229
|
+
if (hasBundle) {
|
|
4297
4230
|
result += `
|
|
4298
4231
|
|
|
4299
|
-
This skill has executable scripts
|
|
4232
|
+
This skill has executable scripts.`;
|
|
4300
4233
|
result += `
|
|
4301
4234
|
Run \`gitlab_skill_setup(name="${args.name}")\` to extract them locally.`;
|
|
4302
4235
|
}
|
|
@@ -4493,25 +4426,12 @@ Install: \`gitlab_skill_install(name="${r.identifier}", source="skills.sh")\``
|
|
|
4493
4426
|
try {
|
|
4494
4427
|
const mdFiles = downloaded.files.filter((f) => isMarkdownFile(f.path));
|
|
4495
4428
|
const scriptFiles = downloaded.files.filter((f) => !isMarkdownFile(f.path));
|
|
4496
|
-
|
|
4497
|
-
if (scriptFiles.length > 0) {
|
|
4498
|
-
const snippet = await createProjectSnippet(
|
|
4499
|
-
auth.instanceUrl,
|
|
4500
|
-
auth.token,
|
|
4501
|
-
args.project_id,
|
|
4502
|
-
`skill:${downloaded.name}`,
|
|
4503
|
-
`Scripts for skill "${downloaded.name}"`,
|
|
4504
|
-
[{ file_path: `${downloaded.name}.bundle`, content: packFiles(scriptFiles) }],
|
|
4505
|
-
"private"
|
|
4506
|
-
);
|
|
4507
|
-
snippetId = snippet.id;
|
|
4508
|
-
}
|
|
4429
|
+
const hasBundle = scriptFiles.length > 0;
|
|
4509
4430
|
const skillBody = formatFrontmatter(
|
|
4510
4431
|
{
|
|
4511
4432
|
name: downloaded.name,
|
|
4512
4433
|
description: downloaded.description,
|
|
4513
|
-
source: `skills.sh:${args.name}
|
|
4514
|
-
snippetId
|
|
4434
|
+
source: `skills.sh:${args.name}`
|
|
4515
4435
|
},
|
|
4516
4436
|
downloaded.content.replace(/^---[\s\S]*?---\s*\n/, "")
|
|
4517
4437
|
);
|
|
@@ -4536,8 +4456,20 @@ Install: \`gitlab_skill_install(name="${r.identifier}", source="skills.sh")\``
|
|
|
4536
4456
|
);
|
|
4537
4457
|
wikiCount++;
|
|
4538
4458
|
}
|
|
4459
|
+
if (hasBundle) {
|
|
4460
|
+
const bundleSlug = `${targetPrefix}/${downloaded.name}/bundle`;
|
|
4461
|
+
await upsertPage(
|
|
4462
|
+
auth.instanceUrl,
|
|
4463
|
+
auth.token,
|
|
4464
|
+
projectScope.scope,
|
|
4465
|
+
projectScope.id,
|
|
4466
|
+
bundleSlug,
|
|
4467
|
+
packFiles(scriptFiles)
|
|
4468
|
+
);
|
|
4469
|
+
wikiCount++;
|
|
4470
|
+
}
|
|
4539
4471
|
const parts = [`${wikiCount} wiki page(s)`];
|
|
4540
|
-
if (
|
|
4472
|
+
if (hasBundle) parts.push(`${scriptFiles.length} bundled script(s)`);
|
|
4541
4473
|
return `Installed skill "${downloaded.name}" from skills.sh. ${parts.join(", ")}. Use gitlab_skill_setup to extract scripts.`;
|
|
4542
4474
|
} catch (err) {
|
|
4543
4475
|
return `Error installing from skills.sh: ${err.message}`;
|
|
@@ -4605,7 +4537,7 @@ Install: \`gitlab_skill_install(name="${r.identifier}", source="skills.sh")\``
|
|
|
4605
4537
|
if (!skillPage) {
|
|
4606
4538
|
return `Skill "${args.name}" not found. Use gitlab_skill_list to see available skills.`;
|
|
4607
4539
|
}
|
|
4608
|
-
const {
|
|
4540
|
+
const { body } = parseFrontmatter(skillPage.content);
|
|
4609
4541
|
(0, import_fs3.mkdirSync)(targetDir, { recursive: true });
|
|
4610
4542
|
(0, import_fs3.writeFileSync)((0, import_path3.join)(targetDir, "SKILL.md"), body);
|
|
4611
4543
|
const pages = await listWikiPages(
|
|
@@ -4630,23 +4562,17 @@ Install: \`gitlab_skill_install(name="${r.identifier}", source="skills.sh")\``
|
|
|
4630
4562
|
}
|
|
4631
4563
|
}
|
|
4632
4564
|
let scriptCount = 0;
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
auth.token,
|
|
4637
|
-
args.project_id,
|
|
4638
|
-
meta.snippetId
|
|
4639
|
-
);
|
|
4640
|
-
for (const bf of bundleFiles) {
|
|
4641
|
-
const raw = await getSnippetFileRaw(
|
|
4565
|
+
for (const prefix of [SKILLS_PREFIX, DRAFTS_PREFIX]) {
|
|
4566
|
+
try {
|
|
4567
|
+
const bundlePage = await getWikiPage(
|
|
4642
4568
|
auth.instanceUrl,
|
|
4643
4569
|
auth.token,
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4570
|
+
scope,
|
|
4571
|
+
id,
|
|
4572
|
+
`${prefix}/${args.name}/bundle`
|
|
4647
4573
|
);
|
|
4648
|
-
if (
|
|
4649
|
-
for (const file of unpackFiles(
|
|
4574
|
+
if (bundlePage.content) {
|
|
4575
|
+
for (const file of unpackFiles(bundlePage.content)) {
|
|
4650
4576
|
const filePath = (0, import_path3.join)(targetDir, file.path);
|
|
4651
4577
|
(0, import_fs3.mkdirSync)((0, import_path3.dirname)(filePath), { recursive: true });
|
|
4652
4578
|
(0, import_fs3.writeFileSync)(filePath, file.content);
|
|
@@ -4654,6 +4580,8 @@ Install: \`gitlab_skill_install(name="${r.identifier}", source="skills.sh")\``
|
|
|
4654
4580
|
scriptCount++;
|
|
4655
4581
|
}
|
|
4656
4582
|
}
|
|
4583
|
+
break;
|
|
4584
|
+
} catch {
|
|
4657
4585
|
}
|
|
4658
4586
|
}
|
|
4659
4587
|
ensureGitignore(workDir);
|
|
@@ -4686,29 +4614,10 @@ Install: \`gitlab_skill_install(name="${r.identifier}", source="skills.sh")\``
|
|
|
4686
4614
|
if (skillPages.length === 0) {
|
|
4687
4615
|
return `Skill "${args.name}" not found.`;
|
|
4688
4616
|
}
|
|
4689
|
-
const skillPage = await getWikiPage(
|
|
4690
|
-
auth.instanceUrl,
|
|
4691
|
-
auth.token,
|
|
4692
|
-
scope,
|
|
4693
|
-
id,
|
|
4694
|
-
`${prefix}/${args.name}/SKILL`
|
|
4695
|
-
);
|
|
4696
|
-
const { meta } = parseFrontmatter(skillPage.content);
|
|
4697
4617
|
for (const page of skillPages) {
|
|
4698
4618
|
await deleteWikiPage(auth.instanceUrl, auth.token, scope, id, page.slug);
|
|
4699
4619
|
}
|
|
4700
|
-
|
|
4701
|
-
try {
|
|
4702
|
-
await deleteProjectSnippet(
|
|
4703
|
-
auth.instanceUrl,
|
|
4704
|
-
auth.token,
|
|
4705
|
-
args.project_id,
|
|
4706
|
-
meta.snippetId
|
|
4707
|
-
);
|
|
4708
|
-
} catch {
|
|
4709
|
-
}
|
|
4710
|
-
}
|
|
4711
|
-
return `Deleted skill "${args.name}" (${skillPages.length} page(s)${meta.snippetId ? " + snippet" : ""}).`;
|
|
4620
|
+
return `Deleted skill "${args.name}" (${skillPages.length} page(s) removed).`;
|
|
4712
4621
|
} catch (err) {
|
|
4713
4622
|
return `Error deleting skill: ${err.message}`;
|
|
4714
4623
|
}
|