opencode-gitlab-duo-agentic-custom-tools 0.3.1 → 0.3.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 +49 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1325,9 +1325,16 @@ function mapDuoToolRequest(toolName, args) {
|
|
|
1325
1325
|
case "shell_command": {
|
|
1326
1326
|
const command = asString2(args.command);
|
|
1327
1327
|
if (!command) return { toolName, args };
|
|
1328
|
+
const bridged = mapTodoBridgeCommand(command);
|
|
1329
|
+
if (bridged) return bridged;
|
|
1328
1330
|
return { toolName: "bash", args: { command, description: "Run shell command", workdir: "." } };
|
|
1329
1331
|
}
|
|
1330
1332
|
case "run_command": {
|
|
1333
|
+
const command = asString2(args.command);
|
|
1334
|
+
if (command) {
|
|
1335
|
+
const bridged = mapTodoBridgeCommand(command);
|
|
1336
|
+
if (bridged) return bridged;
|
|
1337
|
+
}
|
|
1331
1338
|
const program = asString2(args.program);
|
|
1332
1339
|
if (program === TODO_READ_PROGRAM) {
|
|
1333
1340
|
return { toolName: "todoread", args: {} };
|
|
@@ -1341,7 +1348,6 @@ function mapDuoToolRequest(toolName, args) {
|
|
|
1341
1348
|
if (Array.isArray(args.arguments)) parts.push(...args.arguments.map((a) => shellQuote(String(a))));
|
|
1342
1349
|
return { toolName: "bash", args: { command: parts.join(" "), description: "Run command", workdir: "." } };
|
|
1343
1350
|
}
|
|
1344
|
-
const command = asString2(args.command);
|
|
1345
1351
|
if (!command) return { toolName, args };
|
|
1346
1352
|
return { toolName: "bash", args: { command, description: "Run command", workdir: "." } };
|
|
1347
1353
|
}
|
|
@@ -1384,8 +1390,30 @@ function mapDuoToolRequest(toolName, args) {
|
|
|
1384
1390
|
function asString2(value) {
|
|
1385
1391
|
return typeof value === "string" ? value : void 0;
|
|
1386
1392
|
}
|
|
1393
|
+
function mapTodoBridgeCommand(command) {
|
|
1394
|
+
const normalized = command.trim();
|
|
1395
|
+
if (normalized === TODO_READ_PROGRAM) {
|
|
1396
|
+
return { toolName: "todoread", args: {} };
|
|
1397
|
+
}
|
|
1398
|
+
if (normalized === TODO_WRITE_PROGRAM) {
|
|
1399
|
+
return invalidTool("todowrite", `${TODO_WRITE_PROGRAM} expects JSON payload after command prefix`);
|
|
1400
|
+
}
|
|
1401
|
+
if (!normalized.startsWith(`${TODO_WRITE_PROGRAM} `)) {
|
|
1402
|
+
return null;
|
|
1403
|
+
}
|
|
1404
|
+
const payload = normalized.slice(TODO_WRITE_PROGRAM.length).trim();
|
|
1405
|
+
if (!payload) {
|
|
1406
|
+
return invalidTool("todowrite", `${TODO_WRITE_PROGRAM} expects JSON payload after command prefix`);
|
|
1407
|
+
}
|
|
1408
|
+
return mapTodoWritePayload(payload);
|
|
1409
|
+
}
|
|
1387
1410
|
function mapTodoWriteCall(rawArguments) {
|
|
1388
|
-
const payloadResult =
|
|
1411
|
+
const payloadResult = parseTodoPayloadFromArguments(rawArguments);
|
|
1412
|
+
if ("error" in payloadResult) return invalidTool("todowrite", payloadResult.error);
|
|
1413
|
+
return mapTodoWritePayload(payloadResult.payload);
|
|
1414
|
+
}
|
|
1415
|
+
function mapTodoWritePayload(rawPayload) {
|
|
1416
|
+
const payloadResult = parseTodoPayload(rawPayload);
|
|
1389
1417
|
if ("error" in payloadResult) return invalidTool("todowrite", payloadResult.error);
|
|
1390
1418
|
const todosResult = parseTodos(payloadResult.payload);
|
|
1391
1419
|
if ("error" in todosResult) return invalidTool("todowrite", todosResult.error);
|
|
@@ -1396,7 +1424,7 @@ function mapTodoWriteCall(rawArguments) {
|
|
|
1396
1424
|
}
|
|
1397
1425
|
};
|
|
1398
1426
|
}
|
|
1399
|
-
function
|
|
1427
|
+
function parseTodoPayloadFromArguments(rawArguments) {
|
|
1400
1428
|
if (!Array.isArray(rawArguments) || rawArguments.length === 0) {
|
|
1401
1429
|
return {
|
|
1402
1430
|
error: `${TODO_WRITE_PROGRAM} expects JSON payload in arguments[0]`
|
|
@@ -1408,8 +1436,12 @@ function parseTodoPayload(rawArguments) {
|
|
|
1408
1436
|
error: `${TODO_WRITE_PROGRAM} expects arguments[0] to be a JSON string`
|
|
1409
1437
|
};
|
|
1410
1438
|
}
|
|
1439
|
+
return { payload: rawPayload };
|
|
1440
|
+
}
|
|
1441
|
+
function parseTodoPayload(rawPayload) {
|
|
1442
|
+
const normalized = unwrapWrappingQuotes(rawPayload);
|
|
1411
1443
|
try {
|
|
1412
|
-
const parsed = JSON.parse(
|
|
1444
|
+
const parsed = JSON.parse(normalized);
|
|
1413
1445
|
if (!isRecord(parsed)) {
|
|
1414
1446
|
return {
|
|
1415
1447
|
error: `${TODO_WRITE_PROGRAM} payload must be a JSON object`
|
|
@@ -1422,6 +1454,16 @@ function parseTodoPayload(rawArguments) {
|
|
|
1422
1454
|
};
|
|
1423
1455
|
}
|
|
1424
1456
|
}
|
|
1457
|
+
function unwrapWrappingQuotes(value) {
|
|
1458
|
+
const trimmed = value.trim();
|
|
1459
|
+
if (trimmed.length < 2) return trimmed;
|
|
1460
|
+
const first = trimmed[0];
|
|
1461
|
+
const last = trimmed[trimmed.length - 1];
|
|
1462
|
+
if (first === last && (first === "'" || first === '"')) {
|
|
1463
|
+
return trimmed.slice(1, -1);
|
|
1464
|
+
}
|
|
1465
|
+
return trimmed;
|
|
1466
|
+
}
|
|
1425
1467
|
function parseTodos(payload) {
|
|
1426
1468
|
const rawTodos = payload.todos;
|
|
1427
1469
|
if (!Array.isArray(rawTodos)) {
|
|
@@ -1630,10 +1672,9 @@ var TOOL_ALLOWLIST = [
|
|
|
1630
1672
|
];
|
|
1631
1673
|
var TODO_BRIDGE_INSTRUCTIONS = [
|
|
1632
1674
|
"Todo bridge (required):",
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
'- For todo read, call run_command with program="__todo_read__" and arguments=[].',
|
|
1675
|
+
"- For todo write/update, call run_command with command:",
|
|
1676
|
+
' __todo_write__ {"todos":[{"content":"...","status":"pending|in_progress|completed|cancelled","priority":"high|medium|low"}]}',
|
|
1677
|
+
"- For todo read, call run_command with command: __todo_read__",
|
|
1637
1678
|
"- Use strict JSON with double quotes.",
|
|
1638
1679
|
"- If validation fails, correct payload and retry.",
|
|
1639
1680
|
"- Do not use regular shell commands for todo operations."
|