soltask 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,3 @@
1
+ import type { CommandSpec } from "../context.js";
2
+ /** Every top-level command in the order help lists them. */
3
+ export declare function buildRegistry(): readonly CommandSpec[];
@@ -0,0 +1,10 @@
1
+ import { actionCommands } from "./actions.js";
2
+ import { authCommands } from "./auth.js";
3
+ import { draftCommands } from "./drafts.js";
4
+ import { metaCommands } from "./meta.js";
5
+ import { readCommands } from "./read.js";
6
+ import { watchCommands } from "./watch.js";
7
+ /** Every top-level command in the order help lists them. */
8
+ export function buildRegistry() {
9
+ return [...authCommands, ...readCommands, ...watchCommands, ...draftCommands, ...metaCommands, ...actionCommands];
10
+ }
@@ -0,0 +1,4 @@
1
+ import type { CommandContext, CommandSpec } from "../context.js";
2
+ /** `meta <TASK_REF>`: reads or updates a task's priority and labels. */
3
+ export declare function cmdMeta(ctx: CommandContext): Promise<number>;
4
+ export declare const metaCommands: readonly CommandSpec[];
@@ -0,0 +1,195 @@
1
+ import { PRIORITIES, resolveTaskRef } from "../domain.js";
2
+ import { CliError, EXIT_OK, EXIT_VALIDATION } from "../errors.js";
3
+ import { displayText, emitJson, out } from "../output.js";
4
+ import { splitCsvList } from "../util.js";
5
+ const MAX_LABELS = 10;
6
+ const MAX_LABEL_LEN = 40;
7
+ function validateLabels(labels) {
8
+ if (labels.length > MAX_LABELS) {
9
+ throw new CliError(`At most ${MAX_LABELS} labels are allowed (got ${labels.length}).`, {
10
+ exitCode: EXIT_VALIDATION,
11
+ });
12
+ }
13
+ for (const label of labels) {
14
+ if (label.length === 0 || label.length > MAX_LABEL_LEN) {
15
+ throw new CliError(`Each label must be 1..${MAX_LABEL_LEN} characters (got '${label}').`, {
16
+ exitCode: EXIT_VALIDATION,
17
+ });
18
+ }
19
+ }
20
+ }
21
+ function formatLabelsText(labels) {
22
+ return labels.length > 0 ? labels.map(displayText).join(", ") : "(none)";
23
+ }
24
+ /** `meta <TASK_REF>`: reads or updates a task's priority and labels. */
25
+ export async function cmdMeta(ctx) {
26
+ const ref = (ctx.positionals[0] ?? "").trim();
27
+ if (ref === "") {
28
+ throw new CliError("Task reference cannot be empty.", { exitCode: EXIT_VALIDATION });
29
+ }
30
+ const optPriority = ctx.opt("priority");
31
+ const rawLabels = ctx.optList("labels");
32
+ const hasLabels = rawLabels.length > 0;
33
+ const clearLabels = ctx.flag("clear-labels");
34
+ const rawAddLabels = ctx.optList("add-label");
35
+ const hasAddLabels = rawAddLabels.length > 0;
36
+ const rawRemoveLabels = ctx.optList("remove-label");
37
+ const hasRemoveLabels = rawRemoveLabels.length > 0;
38
+ if (hasLabels && clearLabels) {
39
+ throw new CliError("Cannot combine --labels with --clear-labels.", { exitCode: EXIT_VALIDATION });
40
+ }
41
+ if ((hasLabels || clearLabels) && (hasAddLabels || hasRemoveLabels)) {
42
+ throw new CliError("Cannot combine --labels or --clear-labels with --add-label or --remove-label.", {
43
+ exitCode: EXIT_VALIDATION,
44
+ });
45
+ }
46
+ const toAdd = splitCsvList(rawAddLabels);
47
+ const toRemoveList = splitCsvList(rawRemoveLabels);
48
+ if (hasAddLabels && toAdd.length === 0) {
49
+ throw new CliError("--add-label requires at least one non-empty label.", { exitCode: EXIT_VALIDATION });
50
+ }
51
+ if (hasRemoveLabels && toRemoveList.length === 0) {
52
+ throw new CliError("--remove-label requires at least one non-empty label.", { exitCode: EXIT_VALIDATION });
53
+ }
54
+ const client = ctx.client();
55
+ const targetCommunity = ctx.community();
56
+ let allTasks;
57
+ if (targetCommunity !== undefined) {
58
+ if (ctx.global.waitLive) {
59
+ await client.waitUntilLive([targetCommunity]);
60
+ }
61
+ const listRes = await client.request("GET", "/api/tasks", {
62
+ query: { community: targetCommunity },
63
+ });
64
+ allTasks = listRes.body.tasks;
65
+ }
66
+ else {
67
+ const communities = ctx.global.waitLive ? (await client.waitUntilLive()).communities : await client.communities();
68
+ const lists = await Promise.all(communities.map((community) => client.request("GET", "/api/tasks", { query: { community: community.id } })));
69
+ allTasks = lists.flatMap((res) => res.body.tasks);
70
+ }
71
+ const matched = resolveTaskRef(ref, allTasks);
72
+ const detailRes = await client.request("GET", `/api/tasks/${encodeURIComponent(matched.community)}/${encodeURIComponent(matched.root)}`);
73
+ const task = detailRes.body.task;
74
+ const isUpdate = optPriority !== undefined || hasLabels || clearLabels || hasAddLabels || hasRemoveLabels;
75
+ if (!isUpdate) {
76
+ if (ctx.global.json) {
77
+ emitJson({
78
+ key: task.key,
79
+ root: task.root,
80
+ community: task.community,
81
+ priority: task.priority,
82
+ labels: task.labels,
83
+ });
84
+ }
85
+ else {
86
+ out(`Task: ${displayText(task.key)} (${displayText(task.community)})`);
87
+ out(`Priority: ${displayText(task.priority)}`);
88
+ out(`Labels: ${formatLabelsText(task.labels)}`);
89
+ }
90
+ return EXIT_OK;
91
+ }
92
+ const nextPriority = optPriority ?? task.priority;
93
+ let nextLabels;
94
+ if (clearLabels) {
95
+ nextLabels = [];
96
+ }
97
+ else if (hasLabels) {
98
+ nextLabels = splitCsvList(rawLabels);
99
+ }
100
+ else if (hasAddLabels || hasRemoveLabels) {
101
+ const toRemove = new Set(toRemoveList);
102
+ const merged = [];
103
+ const seen = new Set();
104
+ for (const label of task.labels) {
105
+ if (!toRemove.has(label) && !seen.has(label)) {
106
+ seen.add(label);
107
+ merged.push(label);
108
+ }
109
+ }
110
+ for (const label of toAdd) {
111
+ if (!seen.has(label)) {
112
+ seen.add(label);
113
+ merged.push(label);
114
+ }
115
+ }
116
+ nextLabels = merged;
117
+ }
118
+ else {
119
+ nextLabels = [...task.labels];
120
+ }
121
+ validateLabels(nextLabels);
122
+ const previous = { priority: task.priority, labels: task.labels };
123
+ const next = { priority: nextPriority, labels: nextLabels };
124
+ if (ctx.global.dryRun) {
125
+ const plan = {
126
+ ok: true,
127
+ dry_run: true,
128
+ action: "meta.update",
129
+ key: task.key,
130
+ root: task.root,
131
+ community: task.community,
132
+ previous,
133
+ next,
134
+ };
135
+ if (ctx.global.json) {
136
+ emitJson(plan);
137
+ }
138
+ else {
139
+ out(`Dry run: would update ${displayText(task.key)} metadata:`);
140
+ out(` previous: priority=${displayText(previous.priority)}, labels=${formatLabelsText(previous.labels)}`);
141
+ out(` next: priority=${displayText(next.priority)}, labels=${formatLabelsText(next.labels)}`);
142
+ }
143
+ return EXIT_OK;
144
+ }
145
+ const putRes = await client.request("PUT", `/api/tasks/${encodeURIComponent(task.community)}/${encodeURIComponent(task.root)}/meta`, { jsonBody: { priority: nextPriority, labels: nextLabels } });
146
+ const updatedPriority = putRes.body.priority;
147
+ const updatedLabels = putRes.body.labels;
148
+ if (ctx.global.json) {
149
+ emitJson({
150
+ ok: true,
151
+ key: task.key,
152
+ root: task.root,
153
+ community: task.community,
154
+ priority: updatedPriority,
155
+ labels: updatedLabels,
156
+ previous,
157
+ });
158
+ }
159
+ else {
160
+ out(`Updated ${displayText(task.key)} metadata: priority=${displayText(updatedPriority)}, labels=${formatLabelsText(updatedLabels)}`);
161
+ }
162
+ return EXIT_OK;
163
+ }
164
+ const META_OPTIONS = {
165
+ priority: { type: "string", placeholder: "LEVEL", choices: PRIORITIES, description: "Set task priority" },
166
+ labels: {
167
+ type: "string",
168
+ placeholder: "CSV",
169
+ multiple: true,
170
+ description: "Replace all labels with a comma-separated list (repeatable)",
171
+ },
172
+ "clear-labels": { type: "boolean", description: "Replace all labels with an empty list" },
173
+ "add-label": {
174
+ type: "string",
175
+ placeholder: "LABEL",
176
+ multiple: true,
177
+ description: "Add labels to the existing list (repeatable or comma-separated)",
178
+ },
179
+ "remove-label": {
180
+ type: "string",
181
+ placeholder: "LABEL",
182
+ multiple: true,
183
+ description: "Remove matching labels from the existing list (repeatable or comma-separated)",
184
+ },
185
+ };
186
+ export const metaCommands = [
187
+ {
188
+ name: "meta",
189
+ summary: "Read or update task priority and labels",
190
+ usage: "meta <TASK_REF> [--priority P] [--labels L | --clear-labels | --add-label L | --remove-label L]",
191
+ options: META_OPTIONS,
192
+ positionals: { min: 1, max: 1 },
193
+ handler: cmdMeta,
194
+ },
195
+ ];
@@ -0,0 +1,24 @@
1
+ import type { CommandContext, CommandSpec } from "../context.js";
2
+ import type { ColumnId, CommunityView, LinkState, TaskSummary } from "../types.js";
3
+ export interface CommunitySyncSummary {
4
+ id: string;
5
+ status: LinkState;
6
+ lagSeconds: number;
7
+ }
8
+ export interface ParsedColumnFilter {
9
+ cols: ReadonlySet<ColumnId> | null;
10
+ serverCol: ColumnId | undefined;
11
+ }
12
+ /** Parses repeatable/CSV `--col` values (supporting `open` alias) with strict validation. */
13
+ export declare function parseColumnFilter(rawItems: readonly string[]): ParsedColumnFilter;
14
+ /** Fetches community views from `/api/communities`, waiting for cold communities when `--wait-live` is set. */
15
+ export declare function fetchCommunities(ctx: CommandContext, targetIds?: readonly string[]): Promise<CommunityView[]>;
16
+ /** Emits a stderr warning in text mode for any community whose sync status is not `live`. */
17
+ export declare function warnUnhealthyCommunities(ctx: CommandContext, statuses: readonly CommunitySyncSummary[]): void;
18
+ /** Resolves a task reference across `--community` or all configured communities. */
19
+ export declare function resolveTaskAcrossCommunities(ctx: CommandContext, ref: string): Promise<{
20
+ task: TaskSummary;
21
+ communities: CommunityView[];
22
+ syncStatus: CommunitySyncSummary | undefined;
23
+ }>;
24
+ export declare const readCommands: readonly CommandSpec[];