@moondeck/station 1.0.12 → 1.0.14
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/images/standard/Dockerfile +32 -0
- package/images/standard/README.md +7 -7
- package/lib/agent-cli-issue-attachments.ts +117 -0
- package/lib/agent-cli-issue-comments.ts +103 -0
- package/lib/agent-cli-issues.ts +445 -0
- package/lib/agent-cli.ts +153 -45
- package/lib/agents/agy-pin.ts +36 -0
- package/lib/agents/agy-scrub.ts +11 -0
- package/lib/agents/claude.ts +5 -2
- package/lib/agents/codex.ts +5 -0
- package/lib/agents/factory.ts +1 -0
- package/lib/agents/gemini-credentials.ts +61 -0
- package/lib/agents/gemini-stream.fixture.json +439 -0
- package/lib/agents/gemini.ts +836 -0
- package/lib/agents/transport.ts +5 -2
- package/lib/credential-cleanup-inventory.ts +19 -1
- package/lib/credential-consumers/engines.ts +70 -9
- package/lib/engine-accounts.ts +3 -0
- package/lib/engine-login.ts +162 -7
- package/lib/engine-spawn-env.ts +63 -0
- package/lib/issue-markdown.generated.ts +658 -0
- package/lib/orchestrator.ts +68 -25
- package/lib/standard-image-pin.ts +2 -1
- package/lib/standard-image.ts +9 -1
- package/lib/task-credential-cleanup.ts +3 -1
- package/package.json +1 -1
- package/scripts/agent/task-up.sh +36 -0
- package/scripts/agent/uai-env-exec.sh +89 -1
- package/src/cloud-credentials.ts +6 -0
- package/src/engine-account-paths.ts +2 -0
- package/src/engine-usage.ts +1 -0
- package/src/index.ts +4 -1
- package/src/main.ts +7 -1
- package/src/protocol.ts +7 -4
- package/src/task-env-names.ts +70 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/** Embedded into the standalone CLI. No runtime dependency is shipped. */
|
|
2
|
+
export const ISSUE_CLI_SOURCE = String.raw`
|
|
3
|
+
function issueUsage(message) { throw new Error("issue: " + message); }
|
|
4
|
+
function issueFlags(args, allowed, booleans = ["json"]) {
|
|
5
|
+
const flags = {}; const positional = [];
|
|
6
|
+
for (let i = 0; i < args.length; i++) {
|
|
7
|
+
let arg = args[i];
|
|
8
|
+
if (arg === "-q") arg = "--q";
|
|
9
|
+
if (!arg.startsWith("--")) {
|
|
10
|
+
if (arg.startsWith("-")) issueUsage("unknown option " + arg);
|
|
11
|
+
positional.push(arg); continue;
|
|
12
|
+
}
|
|
13
|
+
const name = arg.slice(2);
|
|
14
|
+
if (!allowed.includes(name)) issueUsage("unknown option --" + name);
|
|
15
|
+
const repeated = ["assignee", "label", "labels", "remove-label", "mention"].includes(name);
|
|
16
|
+
if (!repeated && flags[name] !== undefined) issueUsage("duplicate option --" + name);
|
|
17
|
+
if (booleans.includes(name)) { flags[name] = true; continue; }
|
|
18
|
+
const value = args[++i];
|
|
19
|
+
if (value === undefined || value.startsWith("--") || value === "-q") issueUsage("--" + name + " needs a value");
|
|
20
|
+
if (repeated) (flags[name] ||= []).push(value);
|
|
21
|
+
else flags[name] = value;
|
|
22
|
+
}
|
|
23
|
+
if (flags.limit !== undefined && (!/^[0-9]+$/.test(flags.limit) || Number(flags.limit) < 1 || Number(flags.limit) > 100))
|
|
24
|
+
issueUsage("--limit must be an integer from 1 to 100");
|
|
25
|
+
if (flags.priority !== undefined && !["none", "low", "normal", "high", "urgent"].includes(flags.priority))
|
|
26
|
+
issueUsage("--priority must be none, low, normal, high or urgent");
|
|
27
|
+
return { flags, positional };
|
|
28
|
+
}
|
|
29
|
+
function issueKey(positional) {
|
|
30
|
+
if (positional.length !== 1 || !/^[a-z][a-z0-9]{1,5}-[1-9][0-9]*$/i.test(positional[0]))
|
|
31
|
+
issueUsage("supply one Issue identifier, such as ISS-12");
|
|
32
|
+
return positional[0];
|
|
33
|
+
}
|
|
34
|
+
function issueExpectedRevision(flags) {
|
|
35
|
+
const expected = flags["expected-revision"];
|
|
36
|
+
if (expected !== undefined && (!/^[0-9]+$/.test(expected) || !Number.isSafeInteger(Number(expected))))
|
|
37
|
+
issueUsage("--expected-revision must be a nonnegative safe integer");
|
|
38
|
+
return expected === undefined ? undefined : Number(expected);
|
|
39
|
+
}
|
|
40
|
+
function issueViewerDate() {
|
|
41
|
+
const date = new Date();
|
|
42
|
+
return String(date.getFullYear()).padStart(4, "0") + "-" + String(date.getMonth() + 1).padStart(2, "0") + "-" + String(date.getDate()).padStart(2, "0");
|
|
43
|
+
}
|
|
44
|
+
function issueCalendarDate(value, flag) {
|
|
45
|
+
if (value === undefined) return undefined;
|
|
46
|
+
const date = new Date(value + "T00:00:00.000Z");
|
|
47
|
+
if (!/^(19|[2-9]\d)\d{2}-\d{2}-\d{2}$/.test(value) || !Number.isFinite(date.getTime()) || date.toISOString().slice(0, 10) !== value)
|
|
48
|
+
issueUsage("--" + flag + " must be a real calendar date in YYYY-MM-DD format, from 1900-01-01 through 9999-12-31; nothing was sent");
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function issueDeadline(flags) {
|
|
52
|
+
if (flags.deadline !== undefined && flags["clear-deadline"])
|
|
53
|
+
issueUsage("--deadline and --clear-deadline cannot be combined; nothing was sent");
|
|
54
|
+
return flags["clear-deadline"] ? null : issueCalendarDate(flags.deadline, "deadline");
|
|
55
|
+
}
|
|
56
|
+
function issueLabelOptions(flags) {
|
|
57
|
+
const add = flags.label || [], remove = flags["remove-label"] || [];
|
|
58
|
+
const replace = flags.labels !== undefined, clear = !!flags["clear-labels"];
|
|
59
|
+
if ((replace && clear) || ((replace || clear) && (add.length || remove.length)))
|
|
60
|
+
issueUsage("--labels and --clear-labels cannot be combined with each other or --label/--remove-label");
|
|
61
|
+
const names = replace ? flags.labels : [...add, ...remove];
|
|
62
|
+
if (names.some(name => !name.trim())) issueUsage("label names cannot be empty; use --clear-labels to remove all labels");
|
|
63
|
+
return { add, remove, replace: replace ? names : undefined, clear, changed: replace || clear || !!names.length };
|
|
64
|
+
}
|
|
65
|
+
async function issueLabelCatalog() {
|
|
66
|
+
return api("GET", "/api/agent/issues/labels");
|
|
67
|
+
}
|
|
68
|
+
function issueLabelIds(catalog, names) {
|
|
69
|
+
return [...new Set(names.map(name => {
|
|
70
|
+
const key = name.trim().replace(/\s+/g, " ").toLowerCase();
|
|
71
|
+
const label = catalog.labels.find(label => (label.nameKey ?? label.name.toLowerCase()) === key);
|
|
72
|
+
if (!label) issueUsage("unknown label " + JSON.stringify(name) + ". Run issue labels to see the workspace catalog; ask a human to create missing labels. Nothing was changed");
|
|
73
|
+
return label.id;
|
|
74
|
+
}))];
|
|
75
|
+
}
|
|
76
|
+
async function issueLabelSet(options, current = []) {
|
|
77
|
+
if (options.clear) return [];
|
|
78
|
+
const catalog = await issueLabelCatalog();
|
|
79
|
+
if (options.replace) return issueLabelLimit(issueLabelIds(catalog, options.replace));
|
|
80
|
+
const add = issueLabelIds(catalog, options.add), remove = issueLabelIds(catalog, options.remove);
|
|
81
|
+
if (add.some(id => remove.includes(id))) issueUsage("cannot add and remove the same label in one update");
|
|
82
|
+
return issueLabelLimit([...new Set([...current.filter(id => !remove.includes(id)), ...add])]);
|
|
83
|
+
}
|
|
84
|
+
function issueLabelLimit(ids) {
|
|
85
|
+
if (ids.length > 50) issueUsage("an Issue accepts at most 50 labels; nothing was changed");
|
|
86
|
+
return ids;
|
|
87
|
+
}
|
|
88
|
+
function issueDescription(flags) {
|
|
89
|
+
if (flags["description-file"] !== undefined && flags.description !== undefined)
|
|
90
|
+
issueUsage("--description-file cannot be combined with --description (text or stdin)");
|
|
91
|
+
const file = flags["description-file"];
|
|
92
|
+
if (file === undefined && flags.description === undefined) return flags["clear-description"] ? "" : undefined;
|
|
93
|
+
if ((file === "-" || flags.description === "-") && process.stdin.isTTY)
|
|
94
|
+
issueUsage("description stdin is a terminal; pipe Markdown or use --description-file PATH");
|
|
95
|
+
const description = file !== undefined ? readFlagFile(file) : flags.description === "-" ? readFlagFile("-") : flags.description;
|
|
96
|
+
if (description.length > 100000) issueUsage("description exceeds the 100,000 UTF-16 code unit limit (received " + description.length + "); nothing was sent");
|
|
97
|
+
if (description.includes(String.fromCharCode(0))) issueUsage("description cannot contain NUL; nothing was sent");
|
|
98
|
+
if (!description.trim()) {
|
|
99
|
+
if (!flags["clear-description"]) issueUsage("description is empty or whitespace-only; nothing was sent. Use --clear-description to erase it intentionally");
|
|
100
|
+
return "";
|
|
101
|
+
}
|
|
102
|
+
if (flags["clear-description"]) issueUsage("--clear-description cannot be combined with a nonempty description");
|
|
103
|
+
return description;
|
|
104
|
+
}
|
|
105
|
+
function issueChecklistLine(item) {
|
|
106
|
+
return item.index + " [" + (item.checked ? "x" : " ") + "] " + item.text;
|
|
107
|
+
}
|
|
108
|
+
function issueParentKey(flags) {
|
|
109
|
+
if (flags.parent !== undefined) {
|
|
110
|
+
if (!/^[a-z][a-z0-9]{1,5}-[1-9][0-9]*$/i.test(flags.parent))
|
|
111
|
+
issueUsage("--parent needs an Issue identifier, such as ISS-12");
|
|
112
|
+
if (flags["no-parent"]) issueUsage("--parent and --no-parent cannot be combined");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async function issueParentId(base, key) {
|
|
116
|
+
const detail = await api("GET", base + "/" + encodeURIComponent(key), undefined, { parentLookup: key });
|
|
117
|
+
return detail.issue.id;
|
|
118
|
+
}
|
|
119
|
+
function issueHierarchyLine(issue) {
|
|
120
|
+
return issue.key + " " + issue.title + " [" + issue.status.name + "]";
|
|
121
|
+
}
|
|
122
|
+
function issueErrorHint(code, status, context, retryAfter, details) {
|
|
123
|
+
if (code === "ISSUE_CURSOR_INVALID" && context?.deadlineFilter)
|
|
124
|
+
console.error("If the viewer day rolled over between pages, restart from page 1 without --cursor. Use --viewer-date YYYY-MM-DD for a human's local day.");
|
|
125
|
+
if (context?.commentAction && status === 403)
|
|
126
|
+
console.error("Comments require issues.read + issues.write within the owner's rights; a human must grant missing issues.write. Edit/delete requires the same owner, Task and agent that posted the comment.");
|
|
127
|
+
if (context?.commentAction && code === "ISSUE_COMMENT_CONFLICT")
|
|
128
|
+
console.error("No changes saved: the comment changed since revision " + context.commentRevision + ". Rerun issue comments --json and use the comment revision, not the Issue revision. No automatic retry.");
|
|
129
|
+
if (context?.commentAction && code === "ISSUE_CHAT_IDEMPOTENCY_CONFLICT")
|
|
130
|
+
console.error("No new comment saved: this clientRequestId belongs to different content or another agent. Inspect issue comments --json; do not blindly post again.");
|
|
131
|
+
if (context?.commentAction && code === "ISSUE_MENTION_INVALID")
|
|
132
|
+
console.error("A mentioned member is no longer eligible to read this Issue. Refresh member names and permissions before posting; no automatic retry.");
|
|
133
|
+
if (status === 403 && context?.archiveAction)
|
|
134
|
+
console.error("No changes saved. Issue " + context.archiveAction + " requires issues.read + issues.write within the owner's rights; a human must grant issues.write if it is missing in Task permissions.");
|
|
135
|
+
if (status === 409 && context?.checklistIndex !== undefined) {
|
|
136
|
+
console.error("Nothing changed. Inspect the current checklist before retrying intentionally with --expected-revision.");
|
|
137
|
+
if (typeof details?.description === "string") {
|
|
138
|
+
const item = parseIssueChecklist(details.description).items[context.checklistIndex];
|
|
139
|
+
console.error("Current item at index " + context.checklistIndex + " (revision " + details.currentRevision + "): " +
|
|
140
|
+
(item ? issueChecklistLine(item) : "no item at this index"));
|
|
141
|
+
} else console.error("Current checklist unavailable in the conflict response; rerun issue checklist.");
|
|
142
|
+
}
|
|
143
|
+
if (status === 503 && code === "ISSUE_ACCESS_BUSY") {
|
|
144
|
+
const delay = /^\d+$/.test(retryAfter || "") ? Number(retryAfter) : Math.ceil((Date.parse(retryAfter) - Date.now()) / 1000);
|
|
145
|
+
const seconds = Number.isFinite(delay) ? Math.max(0, delay) : 1;
|
|
146
|
+
console.error("No changes saved; wait " + seconds + " s" + (retryAfter ? " (from Retry-After)" : " (Retry-After unavailable)") + ", rerun issue show, retry with --expected-revision. No automatic retry.");
|
|
147
|
+
}
|
|
148
|
+
if (code === "ISSUE_PARENT_CYCLE")
|
|
149
|
+
console.error("No changes saved. An Issue cannot be its own parent or have one of its descendants as parent (cycle).");
|
|
150
|
+
if (code === "ISSUE_DEPTH_LIMIT")
|
|
151
|
+
console.error("No changes saved. The parent would exceed 10 parent edges from the root, including the moved subtree. Choose a shallower parent.");
|
|
152
|
+
if (context?.parentLookup && status === 404)
|
|
153
|
+
console.error("Parent " + context.parentLookup + " was not found in this workspace. Cross-workspace parents are not supported; check the key and workspace.");
|
|
154
|
+
else if (context?.parentKey && code === "ISSUE_NOT_FOUND")
|
|
155
|
+
console.error("The Issue or parent was not found in this workspace. Cross-workspace parents are not supported; inspect both Issues before retrying.");
|
|
156
|
+
if (context?.parentLookup && status === 403)
|
|
157
|
+
console.error("Reading parent " + context.parentLookup + " requires issues.read within the human owner's Issue permissions. A human must grant the missing access before setting this parent.");
|
|
158
|
+
else if (context?.parentKey && status === 403)
|
|
159
|
+
console.error("Setting a parent requires issues.read on the parent and issues.write on the child, within the human owner's permissions. A human must grant any missing access.");
|
|
160
|
+
}
|
|
161
|
+
function issueLine(issue, viewerDate = issueViewerDate()) {
|
|
162
|
+
const assignees = (issue.assignees || []).map((a) => a.handle ? "@" + a.handle : a.name || a.userId).join(", ") || "unassigned";
|
|
163
|
+
return issue.identifier + (issue.archivedAt != null ? " [archived]" : "") + " " + issue.title + " [" + (issue.status?.name || issue.statusId) + "] " + issue.priority +
|
|
164
|
+
" " + (issue.project?.key || issue.projectId) + " " + assignees +
|
|
165
|
+
" labels: " + ((issue.labels || []).map(label => label.name).join(", ") || "none") +
|
|
166
|
+
(issue.deadline ? " deadline: " + issue.deadline + (issue.deadline < viewerDate && !["done", "canceled"].includes(issue.status?.category) ? " [overdue]" : "") : "");
|
|
167
|
+
}
|
|
168
|
+
function issuePage(page, current, json, viewerDate) {
|
|
169
|
+
if (json) return out(page);
|
|
170
|
+
const issues = current ? page.issues.map((entry) => entry.issue) : page.issues;
|
|
171
|
+
out(issues.length ? issues.map(issue => issueLine(issue, viewerDate)).join(NL) : "No issues.");
|
|
172
|
+
if (page.nextCursor) out("More issues: repeat this command with --cursor " + page.nextCursor);
|
|
173
|
+
}
|
|
174
|
+
async function issueReadDetail(key, initial) {
|
|
175
|
+
const base = "/api/agent/issues";
|
|
176
|
+
const detail = initial || await api("GET", base + "/" + encodeURIComponent(key));
|
|
177
|
+
// Detail's first page is scoped on the server. Continue only when the
|
|
178
|
+
// agent is allowed linked Task details; never reconstruct scope locally.
|
|
179
|
+
let cursor = detail.tasksPage?.nextCursor;
|
|
180
|
+
while (detail.linkedTasksAvailable && cursor) {
|
|
181
|
+
const page = await api("GET", base + "/" + encodeURIComponent(key) + "/tasks?limit=100&cursor=" + encodeURIComponent(cursor));
|
|
182
|
+
detail.tasks.push(...page.tasks); cursor = page.nextCursor;
|
|
183
|
+
}
|
|
184
|
+
if (detail.tasksPage) detail.tasksPage.nextCursor = cursor || null;
|
|
185
|
+
// Children use the detail endpoint's own cursor, independently of Task
|
|
186
|
+
// visibility. Keep the first snapshot's fields and server progress counts.
|
|
187
|
+
let childrenCursor = detail.childrenPage?.nextCursor;
|
|
188
|
+
const seenCursors = new Set();
|
|
189
|
+
const children = new Map();
|
|
190
|
+
let duplicateChildren = false;
|
|
191
|
+
function addChildren(rows) {
|
|
192
|
+
for (const child of rows || []) {
|
|
193
|
+
if (children.has(child.id)) duplicateChildren = true;
|
|
194
|
+
else children.set(child.id, child);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
addChildren(detail.children);
|
|
198
|
+
let pages = 1;
|
|
199
|
+
let stopReason;
|
|
200
|
+
let changedTotal = false;
|
|
201
|
+
while (childrenCursor) {
|
|
202
|
+
if (seenCursors.has(childrenCursor)) { stopReason = "repeated cursor"; break; }
|
|
203
|
+
if (pages >= 50) { stopReason = "50-page limit"; break; }
|
|
204
|
+
seenCursors.add(childrenCursor);
|
|
205
|
+
const page = await api("GET", base + "/" + encodeURIComponent(key) + "?childrenLimit=100&childrenCursor=" + encodeURIComponent(childrenCursor));
|
|
206
|
+
pages++;
|
|
207
|
+
addChildren(page.children);
|
|
208
|
+
if (page.childrenPage?.totalCount !== detail.childrenPage.totalCount) changedTotal = true;
|
|
209
|
+
childrenCursor = page.childrenPage?.nextCursor;
|
|
210
|
+
}
|
|
211
|
+
if (detail.children) detail.children = [...children.values()];
|
|
212
|
+
if (detail.childrenPage) {
|
|
213
|
+
detail.childrenPage.nextCursor = childrenCursor || null;
|
|
214
|
+
const reasons = [];
|
|
215
|
+
if (stopReason) reasons.push("stopped at " + stopReason);
|
|
216
|
+
if (duplicateChildren) reasons.push("duplicate children across pages");
|
|
217
|
+
if (changedTotal) reasons.push("total count changed between pages");
|
|
218
|
+
if (children.size !== detail.childrenPage.totalCount)
|
|
219
|
+
reasons.push("merged " + children.size + " children; expected " + detail.childrenPage.totalCount);
|
|
220
|
+
detail.childrenPage.consistent = reasons.length === 0;
|
|
221
|
+
if (stopReason) detail.childrenPage.stopReason = stopReason;
|
|
222
|
+
if (reasons.length) console.error("Warning: child listing may be incomplete or changed during paging (" + reasons.join("; ") + "). Rerun issue show before relying on this list.");
|
|
223
|
+
}
|
|
224
|
+
return issueDetailContext(detail);
|
|
225
|
+
}
|
|
226
|
+
function issueDetailContext(detail) {
|
|
227
|
+
// Absolute appOrigin links take precedence. Only a relative server fallback
|
|
228
|
+
// uses the CLI app base, retaining any explicitly configured proxy prefix.
|
|
229
|
+
if (detail.url) detail.url = new URL(detail.url.replace(/^\/+/, ""), APP_URL.replace(/\/+$/, "") + "/").href;
|
|
230
|
+
detail.checklist ||= parseIssueChecklist(detail.issue.description || "");
|
|
231
|
+
return detail;
|
|
232
|
+
}
|
|
233
|
+
async function issueCommand(action, args) {
|
|
234
|
+
if (action === "comment") return issueCommentCommand(args);
|
|
235
|
+
if (action === "attachment") return issueAttachmentGet(args);
|
|
236
|
+
if (["attachments", "attach", "detach"].includes(action)) return issueAttachmentsCommand(action, args);
|
|
237
|
+
const base = "/api/agent/issues";
|
|
238
|
+
if (action === "labels") {
|
|
239
|
+
const { flags, positional } = issueFlags(args, ["json"]);
|
|
240
|
+
if (positional.length) issueUsage("labels does not take positional arguments");
|
|
241
|
+
const catalog = await issueLabelCatalog();
|
|
242
|
+
return out(flags.json ? catalog : catalog.labels.length
|
|
243
|
+
? catalog.labels.map(label => label.name + " " + label.color + " " + label.id).join(NL) : "No workspace labels.");
|
|
244
|
+
}
|
|
245
|
+
if (action === "list" || action === "current") {
|
|
246
|
+
const allowed = action === "list" ? ["status", "assignee", "project", "priority", "label", "archived", "deadline", "viewer-date", "sort", "q", "limit", "cursor", "no-sub-issues", "exclude-tree-of", "json"] : ["limit", "cursor", "json"];
|
|
247
|
+
const { flags, positional } = issueFlags(args, allowed, ["json", "no-sub-issues"]);
|
|
248
|
+
if (positional.length) issueUsage(action + " does not take positional arguments");
|
|
249
|
+
if (action === "current" && flags.limit !== undefined && Number(flags.limit) > 5) issueUsage("current --limit must be from 1 to 5");
|
|
250
|
+
if (flags.assignee?.length > 1) issueUsage("list accepts one --assignee");
|
|
251
|
+
if (flags.archived !== undefined && !["only", "include"].includes(flags.archived))
|
|
252
|
+
issueUsage("--archived must be only or include; omit it to exclude archived Issues");
|
|
253
|
+
if (flags.deadline !== undefined && !["overdue", "next7", "none"].includes(flags.deadline))
|
|
254
|
+
issueUsage("list --deadline must be overdue, next7 or none");
|
|
255
|
+
if (flags.sort !== undefined && flags.sort !== "deadline") issueUsage("--sort must be deadline");
|
|
256
|
+
const viewerDate = issueCalendarDate(flags["viewer-date"], "viewer-date") ?? issueViewerDate();
|
|
257
|
+
const labels = issueLabelOptions(flags);
|
|
258
|
+
const query = new URLSearchParams();
|
|
259
|
+
for (const [name, value] of Object.entries(flags)) if (name !== "json" && name !== "label" && name !== "no-sub-issues" && name !== "exclude-tree-of" && name !== "viewer-date") query.set(name, name === "assignee" ? value[0] : value);
|
|
260
|
+
if (flags.deadline !== undefined || flags["viewer-date"] !== undefined) query.set("viewerDate", viewerDate);
|
|
261
|
+
if (labels.changed) for (const id of await issueLabelSet(labels)) query.append("labelIds", id);
|
|
262
|
+
if (flags["exclude-tree-of"] !== undefined) {
|
|
263
|
+
const selector = flags["exclude-tree-of"];
|
|
264
|
+
if (!selector.trim() || selector.length > 128 || selector.includes(String.fromCharCode(0))) issueUsage("--exclude-tree-of needs an Issue key or internal ID");
|
|
265
|
+
const root = await api("GET", base + "/" + encodeURIComponent(selector));
|
|
266
|
+
query.set("excludeTreeOf", root.issue.id);
|
|
267
|
+
}
|
|
268
|
+
if (flags["no-sub-issues"]) query.set("showSubIssues", "false");
|
|
269
|
+
const page = await api("GET", base + (action === "current" ? "/current" : "") + "?" + query, undefined, { deadlineFilter: flags.deadline });
|
|
270
|
+
if (action === "current" && flags.json) {
|
|
271
|
+
page.issues = page.issues.map(issueDetailContext);
|
|
272
|
+
}
|
|
273
|
+
if (page.skippedIssues) console.error("Warning: " + page.skippedIssues + " Issue(s) disappeared while reading current; refresh or continue with the returned cursor.");
|
|
274
|
+
return issuePage(page, action === "current", flags.json, viewerDate);
|
|
275
|
+
}
|
|
276
|
+
if (action === "comments") {
|
|
277
|
+
const { flags, positional } = issueFlags(args, ["limit", "before-seq", "json"]);
|
|
278
|
+
const key = issueKey(positional);
|
|
279
|
+
if (flags["before-seq"] !== undefined && (!/^[0-9]+$/.test(flags["before-seq"]) || !Number.isSafeInteger(Number(flags["before-seq"])) || Number(flags["before-seq"]) < 1))
|
|
280
|
+
issueUsage("--before-seq must be a positive safe integer");
|
|
281
|
+
const limit = Number(flags.limit || 50), comments = [], seen = new Set(), cursors = new Set();
|
|
282
|
+
let cursor = flags["before-seq"] === undefined ? null : Number(flags["before-seq"]);
|
|
283
|
+
let warning;
|
|
284
|
+
for (let pages = 0; pages < 50; pages++) {
|
|
285
|
+
if (cursor !== null && cursors.has(cursor)) { warning = "repeated history cursor"; break; }
|
|
286
|
+
if (cursor !== null) cursors.add(cursor);
|
|
287
|
+
const query = new URLSearchParams({ limit: "100" });
|
|
288
|
+
if (cursor !== null) query.set("beforeSeq", String(cursor));
|
|
289
|
+
const page = await api("GET", base + "/" + encodeURIComponent(key) + "/chat?" + query);
|
|
290
|
+
const rows = page.messages.filter(message => message.kind === "comment" && !seen.has(message.id)).sort((a, b) => b.seq - a.seq);
|
|
291
|
+
const selected = rows.slice(0, limit - comments.length);
|
|
292
|
+
for (const row of selected) { seen.add(row.id); comments.push(row); }
|
|
293
|
+
cursor = rows.length > selected.length ? selected.at(-1).seq : page.nextBeforeSeq;
|
|
294
|
+
if (cursor == null || comments.length >= limit) break;
|
|
295
|
+
if (pages === 49) warning = "50-page limit";
|
|
296
|
+
}
|
|
297
|
+
if (warning) console.error("Warning: stopped at " + warning + "; comment listing may be incomplete.");
|
|
298
|
+
const result = { comments, nextBeforeSeq: cursor ?? null, ...(warning ? { warning } : {}) };
|
|
299
|
+
if (flags.json) return out(result);
|
|
300
|
+
out(comments.length ? comments.map(comment => new Date(comment.createdAt).toISOString() + " " + comment.actor.name +
|
|
301
|
+
" " + comment.id + " (revision " + comment.revision + ")" + (comment.deletedAt != null ? " [removed]" : "") + NL +
|
|
302
|
+
(comment.deletedAt != null ? "Message removed" : comment.body)).join(NL + NL) : "No comments.");
|
|
303
|
+
if (cursor != null) out("More comments: issue comments " + key + " --before-seq " + cursor);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (action === "archive" || action === "restore") {
|
|
307
|
+
const { flags, positional } = issueFlags(args, ["expected-revision", "json", ...(action === "archive" ? ["include-sub-issues"] : [])], ["json", "include-sub-issues"]);
|
|
308
|
+
const key = issueKey(positional);
|
|
309
|
+
const expected = issueExpectedRevision(flags);
|
|
310
|
+
const path = base + "/" + encodeURIComponent(key);
|
|
311
|
+
const body = { expectedRevision: expected ?? (await api("GET", path)).issue.revision };
|
|
312
|
+
if (action === "archive") body.includeSubIssues = !!flags["include-sub-issues"];
|
|
313
|
+
const result = await api("POST", path + "/" + action, body, { archiveAction: action });
|
|
314
|
+
return out(flags.json ? result : (action === "archive" ? "Archived " : "Restored ") + result.issue.identifier +
|
|
315
|
+
" (" + result.affectedIssueIds.length + " Issue(s) affected; revision " + result.issue.revision + "). " +
|
|
316
|
+
(action === "archive" ? "No Issues deleted; linked Tasks keep running." : "Only this Issue restored; status retained."));
|
|
317
|
+
}
|
|
318
|
+
if (action === "activity") {
|
|
319
|
+
const { flags, positional } = issueFlags(args, ["limit", "cursor", "json"]);
|
|
320
|
+
const key = issueKey(positional);
|
|
321
|
+
const query = new URLSearchParams();
|
|
322
|
+
for (const name of ["limit", "cursor"]) if (flags[name] !== undefined) query.set(name, flags[name]);
|
|
323
|
+
const page = await api("GET", base + "/" + encodeURIComponent(key) + "/activity" + (query.size ? "?" + query : ""));
|
|
324
|
+
if (flags.json) return out(page);
|
|
325
|
+
out(page.events.length ? page.events.map((event) => {
|
|
326
|
+
const actor = event.actor.kind === "system" ? "system" : event.actor.kind === "agent"
|
|
327
|
+
? "agent " + (event.actor.agentId || "(unavailable)") + " (owner " + event.actor.userId + ")" : event.actor.userId;
|
|
328
|
+
return new Date(event.occurredAt).toISOString() + " " + actor + " " + event.summary;
|
|
329
|
+
}).join(NL) : "No activity.");
|
|
330
|
+
if (page.nextCursor) out("More activity: repeat this command with --cursor " + page.nextCursor);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (action === "checklist" || action === "check" || action === "uncheck") {
|
|
334
|
+
const reading = action === "checklist";
|
|
335
|
+
const { flags, positional } = issueFlags(args, reading ? ["json"] : ["expected-revision", "json"]);
|
|
336
|
+
const key = issueKey(reading ? positional : positional.slice(0, 1));
|
|
337
|
+
const expected = issueExpectedRevision(flags);
|
|
338
|
+
const index = positional[1];
|
|
339
|
+
if (!reading && (positional.length !== 2 || !/^[0-9]+$/.test(index) || !Number.isSafeInteger(Number(index)) || Number(index) > 99999))
|
|
340
|
+
issueUsage("check/uncheck needs a zero-based checklist index from 0 to 99999");
|
|
341
|
+
const path = base + "/" + encodeURIComponent(key);
|
|
342
|
+
const detail = await api("GET", path);
|
|
343
|
+
const checklist = parseIssueChecklist(detail.issue.description || "");
|
|
344
|
+
if (reading) {
|
|
345
|
+
if (flags.json) return out({ identifier: detail.issue.identifier, revision: detail.issue.revision, ...checklist });
|
|
346
|
+
out("Checklist: " + checklist.checked + "/" + checklist.total + " checked (revision " + detail.issue.revision + ")");
|
|
347
|
+
return out(checklist.items.length ? checklist.items.map(issueChecklistLine).join(NL) : "No checklist items.");
|
|
348
|
+
}
|
|
349
|
+
const itemIndex = Number(index);
|
|
350
|
+
const item = checklist.items[itemIndex];
|
|
351
|
+
if (!item) issueUsage("no checklist item at index " + itemIndex + " in revision " + detail.issue.revision + "; nothing changed");
|
|
352
|
+
const checked = action === "check";
|
|
353
|
+
// Preview/validate through the shared source helper: GFM markers can span
|
|
354
|
+
// tabs or multiple lines. Only the atomic tick identity is sent below.
|
|
355
|
+
const preview = issueMarkdownParser().applyIssueChecklistTick(detail.issue.description || "", item, checked);
|
|
356
|
+
if (preview === null) issueUsage("checklist source marker no longer matches; nothing changed. Rerun issue checklist");
|
|
357
|
+
const result = await api("POST", path + "/checklist", {
|
|
358
|
+
itemIndex, textHash: await hashIssueChecklistText(item.text), checked,
|
|
359
|
+
expectedRevision: expected ?? detail.issue.revision,
|
|
360
|
+
}, { checklistIndex: itemIndex });
|
|
361
|
+
return out(flags.json ? result : (result.changed ? "Updated " : "Already set: ") + key + " item " + itemIndex + " " + (checked ? "[x] " : "[ ] ") + item.text + " (revision " + result.issue.revision + ")");
|
|
362
|
+
}
|
|
363
|
+
if (action === "show") {
|
|
364
|
+
const { flags, positional } = issueFlags(args, ["viewer-date", "json"]);
|
|
365
|
+
const key = issueKey(positional);
|
|
366
|
+
const viewerDate = issueCalendarDate(flags["viewer-date"], "viewer-date") ?? issueViewerDate();
|
|
367
|
+
const detail = await issueReadDetail(key);
|
|
368
|
+
if (flags.json) return out(detail);
|
|
369
|
+
out(issueLine(detail.issue, viewerDate));
|
|
370
|
+
out("Revision: " + detail.issue.revision);
|
|
371
|
+
if (detail.url) out("URL: " + detail.url);
|
|
372
|
+
const progress = detail.issue.checklistProgress || issueChecklistProgress(detail.issue.description || "");
|
|
373
|
+
out("Checklist: " + progress.checked + "/" + progress.total + " checked");
|
|
374
|
+
out("Description:" + NL + (detail.issue.description || "(empty)"));
|
|
375
|
+
const parent = detail.parent ?? detail.issue.parent;
|
|
376
|
+
out("Parent: " + (parent ? issueHierarchyLine(parent) : "None."));
|
|
377
|
+
if (detail.children) {
|
|
378
|
+
out("Direct children: " + detail.issue.childDoneCount + "/" + detail.issue.childCount + " done (canceled excluded from progress)");
|
|
379
|
+
out(detail.children.length ? detail.children.map((child) => " " + issueHierarchyLine(child) + (child.hasRunningTask ? " [running Task]" : "")).join(NL) : " None.");
|
|
380
|
+
}
|
|
381
|
+
if (!detail.linkedTasksAvailable) out("Linked Task details require tasks.read; a human can grant it in Task permissions.");
|
|
382
|
+
else out("Linked Tasks:" + NL + (detail.tasks.length ? detail.tasks.map((t) => " " + t.taskId + " " + t.name + " " + t.runtimeStatus).join(NL) : " None visible."));
|
|
383
|
+
if (detail.attachments) out("Attachments:" + NL + (detail.attachments.length ? detail.attachments.map(item => issueAttachmentLine(item, detail.issue.identifier)).join(NL) : " None."));
|
|
384
|
+
if (detail.activity) out("Recent activity:" + NL + (detail.activity.events.length ? detail.activity.events.map(event => " " + new Date(event.occurredAt).toISOString() + " " + event.summary).join(NL) : " None."));
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (action === "create") {
|
|
388
|
+
const { flags, positional } = issueFlags(args, ["title", "description", "project", "status", "assignee", "priority", "parent", "label", "deadline", "json"]);
|
|
389
|
+
if (positional.length || !flags.title?.trim()) issueUsage("create needs --title and no positional arguments");
|
|
390
|
+
issueParentKey(flags);
|
|
391
|
+
const labels = issueLabelOptions(flags);
|
|
392
|
+
const body = {};
|
|
393
|
+
const deadline = issueDeadline(flags);
|
|
394
|
+
if (deadline !== undefined) body.deadline = deadline;
|
|
395
|
+
for (const name of ["title", "description", "project", "status", "priority"]) if (flags[name] !== undefined) body[name] = flags[name];
|
|
396
|
+
if (flags.assignee) body.assignees = flags.assignee;
|
|
397
|
+
if (labels.changed) body.labelIds = await issueLabelSet(labels);
|
|
398
|
+
if (flags.parent !== undefined) body.parentId = await issueParentId(base, flags.parent);
|
|
399
|
+
const result = await api("POST", base, body, { parentKey: flags.parent });
|
|
400
|
+
return out(flags.json ? result : "Created " + issueLine(result.issue));
|
|
401
|
+
}
|
|
402
|
+
if (action === "update") {
|
|
403
|
+
const { flags, positional } = issueFlags(args, ["status", "assignee", "priority", "title", "description", "description-file", "clear-description", "expected-revision", "parent", "no-parent", "label", "remove-label", "labels", "clear-labels", "deadline", "clear-deadline", "override-active-tasks", "json"], ["json", "override-active-tasks", "no-parent", "clear-description", "clear-labels", "clear-deadline"]);
|
|
404
|
+
const key = issueKey(positional);
|
|
405
|
+
issueParentKey(flags);
|
|
406
|
+
const expected = issueExpectedRevision(flags);
|
|
407
|
+
const labels = issueLabelOptions(flags);
|
|
408
|
+
const body = {};
|
|
409
|
+
const deadline = issueDeadline(flags);
|
|
410
|
+
if (deadline !== undefined) body.deadline = deadline;
|
|
411
|
+
const description = issueDescription(flags);
|
|
412
|
+
if (description !== undefined) body.description = description;
|
|
413
|
+
if (flags["no-parent"]) body.parentId = null;
|
|
414
|
+
for (const name of ["status", "priority", "title"]) if (flags[name] !== undefined) body[name] = flags[name];
|
|
415
|
+
if (flags.assignee) {
|
|
416
|
+
if (flags.assignee.some((s) => !/^[+-].+/.test(s))) issueUsage("update --assignee needs +HANDLE or -HANDLE (repeat for multiple changes)");
|
|
417
|
+
body.assignees = flags.assignee;
|
|
418
|
+
}
|
|
419
|
+
if (!Object.keys(body).length && flags.parent === undefined && !labels.changed) issueUsage("update needs a field change (status, assignee, priority, title, description, parent, labels or deadline)");
|
|
420
|
+
if (flags["override-active-tasks"] && !flags.status) issueUsage("--override-active-tasks requires --status");
|
|
421
|
+
if (flags["override-active-tasks"]) body.overrideActiveTasks = true;
|
|
422
|
+
const path = base + "/" + encodeURIComponent(key);
|
|
423
|
+
const current = expected === undefined || labels.add.length || labels.remove.length ? (await api("GET", path)).issue : undefined;
|
|
424
|
+
body.expectedRevision = expected ?? current.revision;
|
|
425
|
+
if (labels.changed) body.labelIds = await issueLabelSet(labels, current?.labelIds ?? current?.labels?.map(label => label.id) ?? []);
|
|
426
|
+
if (flags.parent !== undefined) body.parentId = await issueParentId(base, flags.parent);
|
|
427
|
+
if ((labels.add.length || labels.remove.length) && body.expectedRevision === current.revision &&
|
|
428
|
+
Object.keys(body).every(name => name === "labelIds" || name === "expectedRevision")) {
|
|
429
|
+
const existing = new Set(current.labelIds ?? current.labels?.map(label => label.id) ?? []);
|
|
430
|
+
if (existing.size === body.labelIds.length && body.labelIds.every(id => existing.has(id)))
|
|
431
|
+
return out(flags.json ? { issue: current, changed: false } : "Unchanged " + issueLine(current) + " (revision " + current.revision + ")");
|
|
432
|
+
}
|
|
433
|
+
const result = await api("PATCH", path, body, { parentKey: flags.parent });
|
|
434
|
+
return out(flags.json ? result : "Updated " + issueLine(result.issue));
|
|
435
|
+
}
|
|
436
|
+
if (action === "link" || action === "unlink") {
|
|
437
|
+
const { flags, positional } = issueFlags(args, ["task", "json"]);
|
|
438
|
+
const key = issueKey(positional);
|
|
439
|
+
// Omission is meaningful: the server resolves the authenticated Task.
|
|
440
|
+
const result = await api(action === "link" ? "POST" : "DELETE", base + "/" + encodeURIComponent(key) + "/tasks", flags.task === undefined ? {} : { taskId: flags.task });
|
|
441
|
+
return out(flags.json ? result : (action === "link" ? "Linked " : "Unlinked ") + key + " " + (action === "link" ? "to " : "from ") + result.taskId + (result.changed ? "" : " (already so)"));
|
|
442
|
+
}
|
|
443
|
+
issueUsage("commands: list, labels, comment KEY-N, comment edit/delete KEY-N ID, comments KEY-N, archive KEY-N, restore KEY-N, show KEY-N, current, create --title T, update KEY-N, link KEY-N, unlink KEY-N, checklist KEY-N, check/uncheck KEY-N INDEX, activity KEY-N, attachments KEY-N, attach KEY-N FILES_PATH..., detach KEY-N ID; all accept --json");
|
|
444
|
+
}
|
|
445
|
+
`;
|