@dypt/cli 0.1.17 → 0.1.19
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/README.md +73 -0
- package/dist/index.js +330 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Argument, Command, Option } from "commander";
|
|
|
9
9
|
// package.json
|
|
10
10
|
var package_default = {
|
|
11
11
|
name: "@dypt/cli",
|
|
12
|
-
version: "0.1.
|
|
12
|
+
version: "0.1.19",
|
|
13
13
|
description: "Command-line interface for dypt task management",
|
|
14
14
|
license: "SEE LICENSE IN LICENSE",
|
|
15
15
|
homepage: "https://dypt.app",
|
|
@@ -242,6 +242,156 @@ async function clearCliToken(baseUrl = getBaseUrl(), filePath = getScopedTokenFi
|
|
|
242
242
|
// src/lib/trpc.ts
|
|
243
243
|
import { createTRPCProxyClient, httpBatchLink } from "@trpc/client";
|
|
244
244
|
import superjson from "superjson";
|
|
245
|
+
|
|
246
|
+
// src/lib/maintenance.ts
|
|
247
|
+
var DYPT_MAINTENANCE_CODE = "DYPT_MAINTENANCE";
|
|
248
|
+
var DYPT_MAINTENANCE_EXIT_CODE = 75;
|
|
249
|
+
var MAINTENANCE_HEADER = "x-dypt-maintenance";
|
|
250
|
+
var DyptMaintenanceError = class extends Error {
|
|
251
|
+
constructor(retryAfter, retryAfterSeconds) {
|
|
252
|
+
super("dypt is temporarily under maintenance.");
|
|
253
|
+
this.retryAfter = retryAfter;
|
|
254
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
255
|
+
this.code = DYPT_MAINTENANCE_CODE;
|
|
256
|
+
this.retryable = true;
|
|
257
|
+
this.noChangeApplied = true;
|
|
258
|
+
this.name = "DyptMaintenanceError";
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
function parseRetryAfterSeconds(value) {
|
|
262
|
+
if (value === null) return null;
|
|
263
|
+
const seconds = Number(value);
|
|
264
|
+
if (Number.isInteger(seconds) && seconds >= 0) return seconds;
|
|
265
|
+
const timestamp = Date.parse(value);
|
|
266
|
+
if (Number.isNaN(timestamp)) return null;
|
|
267
|
+
return Math.max(0, Math.ceil((timestamp - Date.now()) / 1e3));
|
|
268
|
+
}
|
|
269
|
+
async function hasMaintenanceCode(response) {
|
|
270
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
271
|
+
if (!contentType.toLowerCase().includes("json")) return false;
|
|
272
|
+
try {
|
|
273
|
+
const body = await response.clone().json();
|
|
274
|
+
return body.code === DYPT_MAINTENANCE_CODE || typeof body.error === "object" && body.error?.code === DYPT_MAINTENANCE_CODE;
|
|
275
|
+
} catch {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async function getMaintenanceError(response) {
|
|
280
|
+
if (response.status !== 503) return null;
|
|
281
|
+
const hasHeader = response.headers.get(MAINTENANCE_HEADER)?.toLowerCase() === "true";
|
|
282
|
+
const hasCode = await hasMaintenanceCode(response);
|
|
283
|
+
const isHtml = (response.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
|
|
284
|
+
if (!hasHeader && !hasCode && !isHtml) return null;
|
|
285
|
+
const retryAfter = response.headers.get("retry-after");
|
|
286
|
+
return new DyptMaintenanceError(
|
|
287
|
+
retryAfter,
|
|
288
|
+
parseRetryAfterSeconds(retryAfter)
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
async function fetchWithMaintenanceCheck(input, init) {
|
|
292
|
+
const response = await globalThis.fetch(input, init);
|
|
293
|
+
const maintenanceError = await getMaintenanceError(response);
|
|
294
|
+
if (maintenanceError) throw maintenanceError;
|
|
295
|
+
return response;
|
|
296
|
+
}
|
|
297
|
+
function findCliReadRateLimitError(error) {
|
|
298
|
+
const seen = /* @__PURE__ */ new Set();
|
|
299
|
+
const pending = [error];
|
|
300
|
+
while (pending.length > 0) {
|
|
301
|
+
const current = pending.shift();
|
|
302
|
+
if (!current || seen.has(current) || typeof current !== "object") continue;
|
|
303
|
+
seen.add(current);
|
|
304
|
+
const candidate = current;
|
|
305
|
+
if (candidate.code === "CLI_READ_RATE_LIMITED" && candidate.retryable === true && typeof candidate.retryAfterSeconds === "number") {
|
|
306
|
+
return candidate;
|
|
307
|
+
}
|
|
308
|
+
pending.push(
|
|
309
|
+
candidate.cause,
|
|
310
|
+
candidate.data,
|
|
311
|
+
candidate.shape,
|
|
312
|
+
candidate.cliError
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
function findMaintenanceError(error) {
|
|
318
|
+
const seen = /* @__PURE__ */ new Set();
|
|
319
|
+
let current = error;
|
|
320
|
+
while (current && !seen.has(current)) {
|
|
321
|
+
seen.add(current);
|
|
322
|
+
if (current instanceof DyptMaintenanceError) return current;
|
|
323
|
+
if (typeof current !== "object") return null;
|
|
324
|
+
const candidate = current;
|
|
325
|
+
if (candidate.code === DYPT_MAINTENANCE_CODE && candidate.retryable === true) {
|
|
326
|
+
return new DyptMaintenanceError(
|
|
327
|
+
typeof candidate.retryAfter === "string" ? candidate.retryAfter : null,
|
|
328
|
+
typeof candidate.retryAfterSeconds === "number" ? candidate.retryAfterSeconds : null
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
current = candidate.cause;
|
|
332
|
+
}
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
function formatRetryGuidance(error) {
|
|
336
|
+
if (error.retryAfterSeconds !== null) {
|
|
337
|
+
const unit = error.retryAfterSeconds === 1 ? "second" : "seconds";
|
|
338
|
+
return ` Retry after ${error.retryAfterSeconds} ${unit}.`;
|
|
339
|
+
}
|
|
340
|
+
if (error.retryAfter) return ` Retry after ${error.retryAfter}.`;
|
|
341
|
+
return " Retry later.";
|
|
342
|
+
}
|
|
343
|
+
function formatCliFailure(error, json) {
|
|
344
|
+
const maintenanceError = findMaintenanceError(error);
|
|
345
|
+
const readRateLimitError = findCliReadRateLimitError(error);
|
|
346
|
+
if (readRateLimitError) {
|
|
347
|
+
const message = "CLI read budget exhausted.";
|
|
348
|
+
if (json) {
|
|
349
|
+
return {
|
|
350
|
+
exitCode: DYPT_MAINTENANCE_EXIT_CODE,
|
|
351
|
+
output: JSON.stringify({
|
|
352
|
+
error: {
|
|
353
|
+
code: readRateLimitError.code,
|
|
354
|
+
message,
|
|
355
|
+
retryable: true,
|
|
356
|
+
retryAfterSeconds: readRateLimitError.retryAfterSeconds
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
const unit = readRateLimitError.retryAfterSeconds === 1 ? "second" : "seconds";
|
|
362
|
+
return {
|
|
363
|
+
exitCode: DYPT_MAINTENANCE_EXIT_CODE,
|
|
364
|
+
output: `${message} Retry after ${readRateLimitError.retryAfterSeconds} ${unit} with backoff.`
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
if (!maintenanceError) {
|
|
368
|
+
return {
|
|
369
|
+
exitCode: 1,
|
|
370
|
+
output: error instanceof Error ? error.message : String(error)
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
if (json) {
|
|
374
|
+
return {
|
|
375
|
+
exitCode: DYPT_MAINTENANCE_EXIT_CODE,
|
|
376
|
+
output: JSON.stringify({
|
|
377
|
+
error: {
|
|
378
|
+
code: maintenanceError.code,
|
|
379
|
+
message: maintenanceError.message,
|
|
380
|
+
retryable: maintenanceError.retryable,
|
|
381
|
+
retryAfter: maintenanceError.retryAfter,
|
|
382
|
+
retryAfterSeconds: maintenanceError.retryAfterSeconds,
|
|
383
|
+
noChangeApplied: maintenanceError.noChangeApplied
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
exitCode: DYPT_MAINTENANCE_EXIT_CODE,
|
|
390
|
+
output: `${maintenanceError.message} No change was applied.${formatRetryGuidance(maintenanceError)}`
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// src/lib/trpc.ts
|
|
245
395
|
function resolveBaseUrl(baseUrl) {
|
|
246
396
|
return (baseUrl ?? getBaseUrl()).replace(/\/$/, "");
|
|
247
397
|
}
|
|
@@ -260,6 +410,7 @@ async function createCliTrpcClient(options = {}) {
|
|
|
260
410
|
httpBatchLink({
|
|
261
411
|
url: `${baseUrl}/api/trpc`,
|
|
262
412
|
transformer: superjson,
|
|
413
|
+
fetch: fetchWithMaintenanceCheck,
|
|
263
414
|
headers() {
|
|
264
415
|
return accessToken ? {
|
|
265
416
|
Authorization: `Bearer ${accessToken}`
|
|
@@ -270,13 +421,16 @@ async function createCliTrpcClient(options = {}) {
|
|
|
270
421
|
});
|
|
271
422
|
}
|
|
272
423
|
async function postJson(path4, body, options = {}) {
|
|
273
|
-
const response = await
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
424
|
+
const response = await fetchWithMaintenanceCheck(
|
|
425
|
+
new URL(path4, resolveBaseUrl(options.baseUrl)),
|
|
426
|
+
{
|
|
427
|
+
method: "POST",
|
|
428
|
+
headers: {
|
|
429
|
+
"content-type": "application/json"
|
|
430
|
+
},
|
|
431
|
+
body: JSON.stringify(body)
|
|
432
|
+
}
|
|
433
|
+
);
|
|
280
434
|
return {
|
|
281
435
|
status: response.status,
|
|
282
436
|
json: await response.json()
|
|
@@ -332,6 +486,7 @@ async function createCliApi(options = {}) {
|
|
|
332
486
|
getBranchFocusSignals: (input) => cliClient.cli.v1.tasks.planFocus.query(input),
|
|
333
487
|
listTasks: (input) => cliClient.cli.v1.tasks.list.query(input ?? {}),
|
|
334
488
|
searchTasks: (input) => cliClient.cli.v1.tasks.search.query(input),
|
|
489
|
+
resolveTaskReferences: (input) => cliClient.cli.v1.tasks.resolveMany.query(input),
|
|
335
490
|
getTaskTree: (input) => cliClient.cli.v1.tasks.tree.query(input),
|
|
336
491
|
deleteTasks: (input) => cliClient.cli.v1.tasks.deleteMany.mutate(input),
|
|
337
492
|
addDependency: (input) => cliClient.cli.v1.dependencies.add.mutate(input),
|
|
@@ -351,7 +506,8 @@ async function createCliApi(options = {}) {
|
|
|
351
506
|
deleteTag: (input) => cliClient.cli.v1.tags.delete.mutate(input),
|
|
352
507
|
mergeTag: (input) => cliClient.cli.v1.tags.merge.mutate(input),
|
|
353
508
|
getTaskTags: (input) => cliClient.cli.v1.tags.forTask.query(input),
|
|
354
|
-
assignTaskTags: (input) => cliClient.cli.v1.tags.assign.mutate(input)
|
|
509
|
+
assignTaskTags: (input) => cliClient.cli.v1.tags.assign.mutate(input),
|
|
510
|
+
assignManyTaskTags: (input) => cliClient.cli.v1.tags.assignMany.mutate(input)
|
|
355
511
|
};
|
|
356
512
|
}
|
|
357
513
|
|
|
@@ -431,6 +587,7 @@ import {
|
|
|
431
587
|
mkdtemp,
|
|
432
588
|
readFile as readFile2,
|
|
433
589
|
readdir,
|
|
590
|
+
realpath,
|
|
434
591
|
rm as rm2,
|
|
435
592
|
stat,
|
|
436
593
|
writeFile as writeFile2
|
|
@@ -676,6 +833,11 @@ async function installAgentSkill(input) {
|
|
|
676
833
|
const source = await resolveSource(input.source, fetchFn);
|
|
677
834
|
try {
|
|
678
835
|
const exists = await pathExists(targetPath);
|
|
836
|
+
if (exists && input.source.type === "local" && await realpath(source.skillPath) === await realpath(targetPath)) {
|
|
837
|
+
throw new Error(
|
|
838
|
+
"Local toolkit source must differ from the install path."
|
|
839
|
+
);
|
|
840
|
+
}
|
|
679
841
|
const action = exists ? "update" : "install";
|
|
680
842
|
const metadata = exists ? await readMetadata(targetPath) : null;
|
|
681
843
|
if (exists && !input.force && !input.backup) {
|
|
@@ -1122,6 +1284,20 @@ async function runTaskGet(input, deps) {
|
|
|
1122
1284
|
}
|
|
1123
1285
|
|
|
1124
1286
|
// src/commands/task/list.ts
|
|
1287
|
+
function getArchivedTagFilterWarnings(result) {
|
|
1288
|
+
if (typeof result !== "object" || result === null) return [];
|
|
1289
|
+
const warnings = result.warnings;
|
|
1290
|
+
if (!Array.isArray(warnings)) return [];
|
|
1291
|
+
return warnings.filter(
|
|
1292
|
+
(warning) => typeof warning === "object" && warning !== null && warning.code === "archived-tag-filter" && Array.isArray(warning.tagNames) && warning.tagNames.every(
|
|
1293
|
+
(tagName) => typeof tagName === "string"
|
|
1294
|
+
)
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
function formatArchivedTagFilterWarning(tagNames) {
|
|
1298
|
+
const formattedNames = tagNames.map((name) => `"${name}"`).join(", ");
|
|
1299
|
+
return tagNames.length === 1 ? `Archived tag ${formattedNames} was ignored. Restore it before filtering.` : `Archived tags ${formattedNames} were ignored. Restore them before filtering.`;
|
|
1300
|
+
}
|
|
1125
1301
|
async function runTaskList(input, deps) {
|
|
1126
1302
|
const result = await deps.listTasks({
|
|
1127
1303
|
parent: input.parent,
|
|
@@ -1156,6 +1332,9 @@ async function runTaskList(input, deps) {
|
|
|
1156
1332
|
deps.printJson(result);
|
|
1157
1333
|
return;
|
|
1158
1334
|
}
|
|
1335
|
+
for (const warning of getArchivedTagFilterWarnings(result)) {
|
|
1336
|
+
deps.printWarning(formatArchivedTagFilterWarning(warning.tagNames));
|
|
1337
|
+
}
|
|
1159
1338
|
deps.printTable({
|
|
1160
1339
|
...typeof result === "object" && result !== null ? result : {},
|
|
1161
1340
|
meta: {
|
|
@@ -1291,7 +1470,7 @@ async function runTaskUpdate(input, deps) {
|
|
|
1291
1470
|
const hasMutations = input.title !== void 0 || hasSharedTaskMutationFields(sharedArgs) || input.position !== void 0;
|
|
1292
1471
|
if (!hasMutations) {
|
|
1293
1472
|
throw new Error(
|
|
1294
|
-
"No changes specified. Use --title, --status, --priority, --deadline, --expected-time, --actual-time, --archive, --unarchive, --parent, or --position."
|
|
1473
|
+
"No changes specified. Use --title, --status, --priority, --deadline, --clear-deadline, --expected-time, --actual-time, --archive, --unarchive, --parent, or --position."
|
|
1295
1474
|
);
|
|
1296
1475
|
}
|
|
1297
1476
|
if (input.preview && input.title !== void 0) {
|
|
@@ -1321,7 +1500,7 @@ async function runTaskUpdateMany(input, deps) {
|
|
|
1321
1500
|
const hasMutations = hasSharedTaskMutationFields(sharedArgs);
|
|
1322
1501
|
if (!hasMutations) {
|
|
1323
1502
|
throw new Error(
|
|
1324
|
-
"No changes specified. Use --status, --priority, --deadline, --expected-time, --actual-time, --archive, --unarchive, or --parent."
|
|
1503
|
+
"No changes specified. Use --status, --priority, --deadline, --clear-deadline, --expected-time, --actual-time, --archive, --unarchive, or --parent."
|
|
1325
1504
|
);
|
|
1326
1505
|
}
|
|
1327
1506
|
const args = {
|
|
@@ -1453,18 +1632,26 @@ async function runTaskCleanupRelocateCollapse(input, deps) {
|
|
|
1453
1632
|
"Provide at least one surviving task with --tasks <refs...>."
|
|
1454
1633
|
);
|
|
1455
1634
|
}
|
|
1456
|
-
const
|
|
1457
|
-
|
|
1635
|
+
const refsToResolve = [
|
|
1636
|
+
input.wrapper,
|
|
1637
|
+
...input.to === "root" ? [] : [input.to],
|
|
1638
|
+
...input.tasks
|
|
1639
|
+
];
|
|
1640
|
+
const resolvedRefs = deps.resolveTaskRefs ? await deps.resolveTaskRefs(refsToResolve) : await Promise.all(refsToResolve.map((ref) => deps.resolveTaskRef(ref)));
|
|
1641
|
+
let resolvedIndex = 0;
|
|
1642
|
+
const wrapperId = resolvedRefs[resolvedIndex++];
|
|
1643
|
+
const toParentId = input.to === "root" ? null : resolvedRefs[resolvedIndex++];
|
|
1458
1644
|
if (toParentId === wrapperId) {
|
|
1459
1645
|
throw new Error("Destination cannot be the wrapper itself.");
|
|
1460
1646
|
}
|
|
1461
|
-
const movingTaskIds = dedupeTaskIds(
|
|
1462
|
-
await Promise.all(input.tasks.map((ref) => deps.resolveTaskRef(ref)))
|
|
1463
|
-
);
|
|
1647
|
+
const movingTaskIds = dedupeTaskIds(resolvedRefs.slice(resolvedIndex));
|
|
1464
1648
|
if (toParentId !== null && movingTaskIds.includes(toParentId)) {
|
|
1465
1649
|
throw new Error("Destination cannot be one of the tasks being moved.");
|
|
1466
1650
|
}
|
|
1467
|
-
const activeDirectChildren = await loadAllActiveDirectChildren(
|
|
1651
|
+
const activeDirectChildren = await loadAllActiveDirectChildren(
|
|
1652
|
+
wrapperId,
|
|
1653
|
+
deps
|
|
1654
|
+
);
|
|
1468
1655
|
const activeDirectChildIds = new Set(
|
|
1469
1656
|
activeDirectChildren.map((child) => child.id)
|
|
1470
1657
|
);
|
|
@@ -1510,6 +1697,16 @@ function print(result, json, deps) {
|
|
|
1510
1697
|
if (json) deps.printJson(result);
|
|
1511
1698
|
else deps.printTable(result);
|
|
1512
1699
|
}
|
|
1700
|
+
function normalizeBulkAssignmentOutput(result) {
|
|
1701
|
+
if (!Array.isArray(result)) return result;
|
|
1702
|
+
const taskTags = result.map((item) => {
|
|
1703
|
+
if (typeof item === "object" && item !== null && "tags" in item && Array.isArray(item.tags)) {
|
|
1704
|
+
return item.tags;
|
|
1705
|
+
}
|
|
1706
|
+
return item;
|
|
1707
|
+
});
|
|
1708
|
+
return taskTags.length === 1 ? taskTags[0] : taskTags;
|
|
1709
|
+
}
|
|
1513
1710
|
async function runTagList(input, deps) {
|
|
1514
1711
|
const result = await deps.listTags({
|
|
1515
1712
|
query: input.query,
|
|
@@ -1549,6 +1746,14 @@ async function runTagMerge(input, deps) {
|
|
|
1549
1746
|
deps
|
|
1550
1747
|
);
|
|
1551
1748
|
}
|
|
1749
|
+
async function runTaskTagsAssign(input, deps) {
|
|
1750
|
+
const result = await deps.assignTags({
|
|
1751
|
+
taskIds: input.taskIds,
|
|
1752
|
+
tagPublicIds: input.tagPublicIds,
|
|
1753
|
+
mode: input.clear ? "clear" : "add"
|
|
1754
|
+
});
|
|
1755
|
+
print(normalizeBulkAssignmentOutput(result), input.json, deps);
|
|
1756
|
+
}
|
|
1552
1757
|
|
|
1553
1758
|
// src/lib/banner.ts
|
|
1554
1759
|
var BANNER_LINES = [
|
|
@@ -2567,6 +2772,10 @@ function printTable(value) {
|
|
|
2567
2772
|
process.stdout.write(`${formatHumanOutput(value)}
|
|
2568
2773
|
`);
|
|
2569
2774
|
}
|
|
2775
|
+
function printWarning(message) {
|
|
2776
|
+
process.stderr.write(`Warning: ${message}
|
|
2777
|
+
`);
|
|
2778
|
+
}
|
|
2570
2779
|
async function confirmAction(message, deps = {}) {
|
|
2571
2780
|
if (deps.isTty === false) {
|
|
2572
2781
|
return false;
|
|
@@ -2758,6 +2967,32 @@ async function resolveTaskId(api, ref) {
|
|
|
2758
2967
|
const matches = result.items ?? [];
|
|
2759
2968
|
return resolveTaskRefFromSearchMatches(ref, matches);
|
|
2760
2969
|
}
|
|
2970
|
+
var MAX_BULK_NON_NUMERIC_TASK_REFERENCES = 100;
|
|
2971
|
+
async function resolveTaskIds(api, refs) {
|
|
2972
|
+
const nonNumericRefs = refs.filter((ref) => !/^\d+$/.test(ref));
|
|
2973
|
+
if (nonNumericRefs.length > MAX_BULK_NON_NUMERIC_TASK_REFERENCES) {
|
|
2974
|
+
throw new Error(
|
|
2975
|
+
`Resolve at most ${MAX_BULK_NON_NUMERIC_TASK_REFERENCES} non-numeric task references per command`
|
|
2976
|
+
);
|
|
2977
|
+
}
|
|
2978
|
+
const result = nonNumericRefs.length ? await api.resolveTaskReferences({
|
|
2979
|
+
refs: nonNumericRefs,
|
|
2980
|
+
archived: "all"
|
|
2981
|
+
}) : { items: [] };
|
|
2982
|
+
const resolvedItems = result.items ?? [];
|
|
2983
|
+
if (resolvedItems.length !== nonNumericRefs.length) {
|
|
2984
|
+
throw new Error("Task reference resolution returned an incomplete result");
|
|
2985
|
+
}
|
|
2986
|
+
let nonNumericIndex = 0;
|
|
2987
|
+
return refs.map((ref) => {
|
|
2988
|
+
if (/^\d+$/.test(ref)) return assertTaskId(ref);
|
|
2989
|
+
const item = resolvedItems[nonNumericIndex++];
|
|
2990
|
+
if (!item || item.ref !== ref) {
|
|
2991
|
+
throw new Error("Task reference resolution returned an invalid order");
|
|
2992
|
+
}
|
|
2993
|
+
return resolveTaskRefFromSearchMatches(ref, item.matches);
|
|
2994
|
+
});
|
|
2995
|
+
}
|
|
2761
2996
|
async function resolveParentId(parentRef, resolveRef) {
|
|
2762
2997
|
if (parentRef === void 0) {
|
|
2763
2998
|
return void 0;
|
|
@@ -2777,6 +3012,15 @@ function assertExclusiveArchiveOptions(archive, unarchive) {
|
|
|
2777
3012
|
throw new Error("Use either --archive or --unarchive, not both");
|
|
2778
3013
|
}
|
|
2779
3014
|
}
|
|
3015
|
+
function assertExclusiveDeadlineOptions(deadline, clearDeadline) {
|
|
3016
|
+
if (deadline && clearDeadline) {
|
|
3017
|
+
throw new Error("Use either --deadline or --clear-deadline, not both");
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
function toTaskMutationDeadline(deadline) {
|
|
3021
|
+
if (deadline === null) return null;
|
|
3022
|
+
return deadline ? new Date(deadline) : void 0;
|
|
3023
|
+
}
|
|
2780
3024
|
async function withCliApi(callback) {
|
|
2781
3025
|
const api = await createCliApi();
|
|
2782
3026
|
return callback(api);
|
|
@@ -2969,20 +3213,18 @@ function buildCli() {
|
|
|
2969
3213
|
);
|
|
2970
3214
|
tag.command("assign").argument("<task-refs...>").option(
|
|
2971
3215
|
"--tag <name>",
|
|
2972
|
-
"existing tag
|
|
3216
|
+
"existing tag to add; repeat to assign multiple",
|
|
2973
3217
|
(value, values = []) => [...values, value]
|
|
2974
|
-
).option("--clear", "remove all tags from the
|
|
3218
|
+
).option("--clear", "remove all tags from the selected tasks").option("--json", "print JSON output").action(
|
|
2975
3219
|
async (taskRefs, options) => {
|
|
2976
3220
|
if (!options.clear && !options.tag?.length)
|
|
2977
3221
|
throw new Error("Provide at least one --tag or use --clear.");
|
|
2978
3222
|
await withCliApi(async (api) => {
|
|
2979
|
-
const taskIds = await
|
|
2980
|
-
taskRefs.map((taskRef) => resolveTaskId(api, taskRef))
|
|
2981
|
-
);
|
|
2982
|
-
const catalogue = await api.listTags({});
|
|
3223
|
+
const taskIds = await resolveTaskIds(api, taskRefs);
|
|
2983
3224
|
const requested = (options.tag ?? []).map(
|
|
2984
3225
|
(name) => name.trim().replace(/\s+/g, " ").toLowerCase()
|
|
2985
3226
|
);
|
|
3227
|
+
const catalogue = requested.length ? await api.listTags({}) : [];
|
|
2986
3228
|
const matched = requested.map(
|
|
2987
3229
|
(name) => catalogue.find((tag2) => tag2.name === name)
|
|
2988
3230
|
);
|
|
@@ -2991,14 +3233,19 @@ function buildCli() {
|
|
|
2991
3233
|
"Every --tag must name an existing tag. Use `dypt tag create` first."
|
|
2992
3234
|
);
|
|
2993
3235
|
const tagPublicIds = options.clear ? [] : matched.map((item) => item.publicId);
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
3236
|
+
await runTaskTagsAssign(
|
|
3237
|
+
{
|
|
3238
|
+
taskIds,
|
|
3239
|
+
tagPublicIds,
|
|
3240
|
+
clear: Boolean(options.clear),
|
|
3241
|
+
json: Boolean(options.json)
|
|
3242
|
+
},
|
|
3243
|
+
{
|
|
3244
|
+
assignTags: (input) => api.assignManyTaskTags(input),
|
|
3245
|
+
printJson,
|
|
3246
|
+
printTable
|
|
3247
|
+
}
|
|
2998
3248
|
);
|
|
2999
|
-
const output = results.length === 1 ? results[0] : results;
|
|
3000
|
-
if (options.json) printJson(output);
|
|
3001
|
-
else printTable(output);
|
|
3002
3249
|
});
|
|
3003
3250
|
}
|
|
3004
3251
|
);
|
|
@@ -3219,7 +3466,8 @@ function buildCli() {
|
|
|
3219
3466
|
});
|
|
3220
3467
|
}),
|
|
3221
3468
|
printJson,
|
|
3222
|
-
printTable
|
|
3469
|
+
printTable,
|
|
3470
|
+
printWarning
|
|
3223
3471
|
}
|
|
3224
3472
|
);
|
|
3225
3473
|
}
|
|
@@ -3465,7 +3713,8 @@ function buildCli() {
|
|
|
3465
3713
|
deadline: options.deadline ? parseDateOption(options.deadline, "start") : void 0,
|
|
3466
3714
|
expectedTimeTaken: parseIntegerOption(
|
|
3467
3715
|
options.expectedTime,
|
|
3468
|
-
"expected-time"
|
|
3716
|
+
"expected-time",
|
|
3717
|
+
1
|
|
3469
3718
|
),
|
|
3470
3719
|
note: options.note,
|
|
3471
3720
|
timeBeforeDeadline: options.reminder ? parseReminderTimings(options.reminder) : void 0,
|
|
@@ -3536,9 +3785,7 @@ function buildCli() {
|
|
|
3536
3785
|
readLine: promptLine
|
|
3537
3786
|
}),
|
|
3538
3787
|
deleteTasks: (taskRefs) => withCliApi(async (api) => {
|
|
3539
|
-
const taskIds = await
|
|
3540
|
-
taskRefs.map((ref) => resolveTaskId(api, ref))
|
|
3541
|
-
);
|
|
3788
|
+
const taskIds = await resolveTaskIds(api, taskRefs);
|
|
3542
3789
|
return api.deleteTasks({ taskIds });
|
|
3543
3790
|
}),
|
|
3544
3791
|
printJson,
|
|
@@ -3557,16 +3804,17 @@ function buildCli() {
|
|
|
3557
3804
|
"--priority <priority>",
|
|
3558
3805
|
`new priority (${taskPriorityChoices.join("|")})`
|
|
3559
3806
|
).choices([...taskPriorityChoices])
|
|
3560
|
-
).option("--deadline <deadline>", "ISO deadline").option("--expected-time <minutes>", "expected minutes").option("--actual-time <minutes>", "actual minutes").option("--archive", "archive the task").option("--unarchive", "unarchive the task").option("--parent <ref>", 'move task under the given parent or "root"').option("--position <position>", "0-based sibling position").option("--preview", "preview the update without mutating").option("--json", "print JSON output").action(
|
|
3807
|
+
).option("--deadline <deadline>", "ISO deadline").option("--clear-deadline", "remove the task deadline").option("--expected-time <minutes>", "expected minutes").option("--actual-time <minutes>", "actual minutes").option("--archive", "archive the task").option("--unarchive", "unarchive the task").option("--parent <ref>", 'move task under the given parent or "root"').option("--position <position>", "0-based sibling position").option("--preview", "preview the update without mutating").option("--json", "print JSON output").action(
|
|
3561
3808
|
async (ref, options) => {
|
|
3562
3809
|
assertExclusiveArchiveOptions(options.archive, options.unarchive);
|
|
3810
|
+
assertExclusiveDeadlineOptions(options.deadline, options.clearDeadline);
|
|
3563
3811
|
await runTaskUpdate(
|
|
3564
3812
|
{
|
|
3565
3813
|
ref,
|
|
3566
3814
|
title: options.title,
|
|
3567
3815
|
status: options.status,
|
|
3568
3816
|
priority: options.priority,
|
|
3569
|
-
deadline: options.deadline ? parseDateOption(options.deadline, "start").toISOString() : void 0,
|
|
3817
|
+
deadline: options.clearDeadline ? null : options.deadline ? parseDateOption(options.deadline, "start").toISOString() : void 0,
|
|
3570
3818
|
expectedTimeTaken: options.expectedTime,
|
|
3571
3819
|
actualTimeTaken: options.actualTime,
|
|
3572
3820
|
archivedAt: options.archive ? /* @__PURE__ */ new Date() : options.unarchive ? null : void 0,
|
|
@@ -3582,14 +3830,16 @@ function buildCli() {
|
|
|
3582
3830
|
title: input.title,
|
|
3583
3831
|
status: normalizeStatus(input.status),
|
|
3584
3832
|
priority: normalizePriority(input.priority),
|
|
3585
|
-
deadline:
|
|
3833
|
+
deadline: toTaskMutationDeadline(input.deadline),
|
|
3586
3834
|
expectedTimeTaken: parseIntegerOption(
|
|
3587
3835
|
input.expectedTimeTaken,
|
|
3588
|
-
"expected-time"
|
|
3836
|
+
"expected-time",
|
|
3837
|
+
1
|
|
3589
3838
|
),
|
|
3590
3839
|
actualTimeTaken: parseIntegerOption(
|
|
3591
3840
|
input.actualTimeTaken,
|
|
3592
|
-
"actual-time"
|
|
3841
|
+
"actual-time",
|
|
3842
|
+
1
|
|
3593
3843
|
),
|
|
3594
3844
|
archivedAt: input.archivedAt,
|
|
3595
3845
|
parentId: await resolveParentId(
|
|
@@ -3604,14 +3854,16 @@ function buildCli() {
|
|
|
3604
3854
|
taskIds: [await resolveTaskId(api, String(input.ref))],
|
|
3605
3855
|
status: normalizeStatus(input.status),
|
|
3606
3856
|
priority: normalizePriority(input.priority),
|
|
3607
|
-
deadline:
|
|
3857
|
+
deadline: toTaskMutationDeadline(input.deadline),
|
|
3608
3858
|
expectedTimeTaken: parseIntegerOption(
|
|
3609
3859
|
input.expectedTimeTaken,
|
|
3610
|
-
"expected-time"
|
|
3860
|
+
"expected-time",
|
|
3861
|
+
1
|
|
3611
3862
|
),
|
|
3612
3863
|
actualTimeTaken: parseIntegerOption(
|
|
3613
3864
|
input.actualTimeTaken,
|
|
3614
|
-
"actual-time"
|
|
3865
|
+
"actual-time",
|
|
3866
|
+
1
|
|
3615
3867
|
),
|
|
3616
3868
|
archivedAt: input.archivedAt,
|
|
3617
3869
|
parentId: await resolveParentId(
|
|
@@ -3659,15 +3911,16 @@ function buildCli() {
|
|
|
3659
3911
|
"--priority <priority>",
|
|
3660
3912
|
`new priority (${taskPriorityChoices.join("|")})`
|
|
3661
3913
|
).choices([...taskPriorityChoices])
|
|
3662
|
-
).option("--deadline <deadline>", "ISO deadline").option("--expected-time <minutes>", "expected minutes").option("--actual-time <minutes>", "actual minutes").option("--archive", "archive the tasks").option("--unarchive", "unarchive the tasks").option("--parent <ref>", 'move tasks under the given parent or "root"').option("--preview", "preview the bulk update without mutating").option("--json", "print JSON output").action(
|
|
3914
|
+
).option("--deadline <deadline>", "ISO deadline").option("--clear-deadline", "remove deadlines from the tasks").option("--expected-time <minutes>", "expected minutes").option("--actual-time <minutes>", "actual minutes").option("--archive", "archive the tasks").option("--unarchive", "unarchive the tasks").option("--parent <ref>", 'move tasks under the given parent or "root"').option("--preview", "preview the bulk update without mutating").option("--json", "print JSON output").action(
|
|
3663
3915
|
async (refs, options) => {
|
|
3664
3916
|
assertExclusiveArchiveOptions(options.archive, options.unarchive);
|
|
3917
|
+
assertExclusiveDeadlineOptions(options.deadline, options.clearDeadline);
|
|
3665
3918
|
await runTaskUpdateMany(
|
|
3666
3919
|
{
|
|
3667
3920
|
refs,
|
|
3668
3921
|
status: options.status,
|
|
3669
3922
|
priority: options.priority,
|
|
3670
|
-
deadline: options.deadline ? parseDateOption(options.deadline, "start").toISOString() : void 0,
|
|
3923
|
+
deadline: options.clearDeadline ? null : options.deadline ? parseDateOption(options.deadline, "start").toISOString() : void 0,
|
|
3671
3924
|
expectedTimeTaken: options.expectedTime,
|
|
3672
3925
|
actualTimeTaken: options.actualTime,
|
|
3673
3926
|
archivedAt: options.archive ? /* @__PURE__ */ new Date() : options.unarchive ? null : void 0,
|
|
@@ -3677,21 +3930,21 @@ function buildCli() {
|
|
|
3677
3930
|
},
|
|
3678
3931
|
{
|
|
3679
3932
|
updateManyTasks: (input) => withCliApi(async (api) => {
|
|
3680
|
-
const taskIds = await
|
|
3681
|
-
input.refs.map((ref) => resolveTaskId(api, ref))
|
|
3682
|
-
);
|
|
3933
|
+
const taskIds = await resolveTaskIds(api, input.refs);
|
|
3683
3934
|
return api.updateManyTasks({
|
|
3684
3935
|
taskIds,
|
|
3685
3936
|
status: normalizeStatus(input.status),
|
|
3686
3937
|
priority: normalizePriority(input.priority),
|
|
3687
|
-
deadline:
|
|
3938
|
+
deadline: toTaskMutationDeadline(input.deadline),
|
|
3688
3939
|
expectedTimeTaken: parseIntegerOption(
|
|
3689
3940
|
input.expectedTimeTaken,
|
|
3690
|
-
"expected-time"
|
|
3941
|
+
"expected-time",
|
|
3942
|
+
1
|
|
3691
3943
|
),
|
|
3692
3944
|
actualTimeTaken: parseIntegerOption(
|
|
3693
3945
|
input.actualTimeTaken,
|
|
3694
|
-
"actual-time"
|
|
3946
|
+
"actual-time",
|
|
3947
|
+
1
|
|
3695
3948
|
),
|
|
3696
3949
|
archivedAt: input.archivedAt,
|
|
3697
3950
|
parentId: await resolveParentId(
|
|
@@ -3701,21 +3954,21 @@ function buildCli() {
|
|
|
3701
3954
|
});
|
|
3702
3955
|
}),
|
|
3703
3956
|
previewManyTasks: (input) => withCliApi(async (api) => {
|
|
3704
|
-
const taskIds = await
|
|
3705
|
-
input.refs.map((ref) => resolveTaskId(api, ref))
|
|
3706
|
-
);
|
|
3957
|
+
const taskIds = await resolveTaskIds(api, input.refs);
|
|
3707
3958
|
return api.previewManyTasks({
|
|
3708
3959
|
taskIds,
|
|
3709
3960
|
status: normalizeStatus(input.status),
|
|
3710
3961
|
priority: normalizePriority(input.priority),
|
|
3711
|
-
deadline:
|
|
3962
|
+
deadline: toTaskMutationDeadline(input.deadline),
|
|
3712
3963
|
expectedTimeTaken: parseIntegerOption(
|
|
3713
3964
|
input.expectedTimeTaken,
|
|
3714
|
-
"expected-time"
|
|
3965
|
+
"expected-time",
|
|
3966
|
+
1
|
|
3715
3967
|
),
|
|
3716
3968
|
actualTimeTaken: parseIntegerOption(
|
|
3717
3969
|
input.actualTimeTaken,
|
|
3718
|
-
"actual-time"
|
|
3970
|
+
"actual-time",
|
|
3971
|
+
1
|
|
3719
3972
|
),
|
|
3720
3973
|
archivedAt: input.archivedAt,
|
|
3721
3974
|
parentId: await resolveParentId(
|
|
@@ -3744,9 +3997,7 @@ function buildCli() {
|
|
|
3744
3997
|
},
|
|
3745
3998
|
{
|
|
3746
3999
|
reorderTasks: (input) => withCliApi(async (api) => {
|
|
3747
|
-
const taskIds = await
|
|
3748
|
-
input.refs.map((ref) => resolveTaskId(api, ref))
|
|
3749
|
-
);
|
|
4000
|
+
const taskIds = await resolveTaskIds(api, input.refs);
|
|
3750
4001
|
return api.reorderTasks({
|
|
3751
4002
|
taskIds,
|
|
3752
4003
|
parentId: await resolveParentId(
|
|
@@ -3756,9 +4007,7 @@ function buildCli() {
|
|
|
3756
4007
|
});
|
|
3757
4008
|
}),
|
|
3758
4009
|
previewReorderTasks: (input) => withCliApi(async (api) => {
|
|
3759
|
-
const taskIds = await
|
|
3760
|
-
input.refs.map((ref) => resolveTaskId(api, ref))
|
|
3761
|
-
);
|
|
4010
|
+
const taskIds = await resolveTaskIds(api, input.refs);
|
|
3762
4011
|
return api.previewReorderTasks({
|
|
3763
4012
|
taskIds,
|
|
3764
4013
|
parentId: await resolveParentId(
|
|
@@ -3806,6 +4055,7 @@ function buildCli() {
|
|
|
3806
4055
|
},
|
|
3807
4056
|
{
|
|
3808
4057
|
resolveTaskRef: (ref) => resolveTaskId(api, ref),
|
|
4058
|
+
resolveTaskRefs: (refs) => resolveTaskIds(api, refs),
|
|
3809
4059
|
listActiveDirectChildren: ({ wrapperId, cursor }) => api.listTasks({
|
|
3810
4060
|
parentTaskId: wrapperId,
|
|
3811
4061
|
archived: "active",
|
|
@@ -4052,12 +4302,6 @@ async function runCli(argv) {
|
|
|
4052
4302
|
await cli.parseAsync(argv);
|
|
4053
4303
|
return 0;
|
|
4054
4304
|
}
|
|
4055
|
-
function formatCliError(error) {
|
|
4056
|
-
if (error instanceof Error) {
|
|
4057
|
-
return error.message;
|
|
4058
|
-
}
|
|
4059
|
-
return String(error);
|
|
4060
|
-
}
|
|
4061
4305
|
function isCliEntrypoint(invokedPath, moduleUrl) {
|
|
4062
4306
|
if (!invokedPath) {
|
|
4063
4307
|
return false;
|
|
@@ -4072,20 +4316,31 @@ function isCliEntrypoint(invokedPath, moduleUrl) {
|
|
|
4072
4316
|
return pathToFileURL(invokedPath).href === moduleUrl;
|
|
4073
4317
|
}
|
|
4074
4318
|
}
|
|
4319
|
+
async function runCliEntrypoint(argv, deps = {}) {
|
|
4320
|
+
try {
|
|
4321
|
+
return await (deps.run ?? runCli)(argv);
|
|
4322
|
+
} catch (error) {
|
|
4323
|
+
const failure = formatCliFailure(error, argv.includes("--json"));
|
|
4324
|
+
(deps.writeError ?? ((output) => process.stderr.write(`${output}
|
|
4325
|
+
`)))(
|
|
4326
|
+
failure.output
|
|
4327
|
+
);
|
|
4328
|
+
return failure.exitCode;
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4075
4331
|
if (isCliEntrypoint(process.argv[1], import.meta.url)) {
|
|
4076
|
-
void
|
|
4332
|
+
void runCliEntrypoint(process.argv).then((exitCode) => {
|
|
4077
4333
|
process.exitCode = exitCode;
|
|
4078
|
-
}).catch((error) => {
|
|
4079
|
-
process.stderr.write(`${formatCliError(error)}
|
|
4080
|
-
`);
|
|
4081
|
-
process.exitCode = 1;
|
|
4082
4334
|
});
|
|
4083
4335
|
}
|
|
4084
4336
|
export {
|
|
4085
4337
|
buildCli,
|
|
4086
4338
|
isCliEntrypoint,
|
|
4087
4339
|
resolveParentId,
|
|
4340
|
+
resolveTaskIds,
|
|
4088
4341
|
resolveTaskRefFromSearchMatches,
|
|
4089
|
-
runCli
|
|
4342
|
+
runCli,
|
|
4343
|
+
runCliEntrypoint,
|
|
4344
|
+
toTaskMutationDeadline
|
|
4090
4345
|
};
|
|
4091
4346
|
//# sourceMappingURL=index.js.map
|