@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
|
@@ -38,6 +38,12 @@ ENV UAI_CLAUDE_CODE_VERSION=2.1.322
|
|
|
38
38
|
ENV UAI_CODEX_CLI_VERSION=0.164.0
|
|
39
39
|
ENV UAI_CURSOR_AGENT_VERSION=2026.10.22-27dcf5f
|
|
40
40
|
ENV UAI_GROK_CLI_VERSION=1.0.70
|
|
41
|
+
# Antigravity CLI (gemini engine). Pinned by tarball URL + SHA-512 from Google's
|
|
42
|
+
# per-platform manifest (antigravity-cli-auto-updater…/manifests/linux_*.json).
|
|
43
|
+
ENV UAI_AGY_CLI_VERSION=1.5.16
|
|
44
|
+
ENV UAI_AGY_CLI_BUILD=1.5.16-5250855658717184
|
|
45
|
+
ENV UAI_AGY_SHA512_X64=3dee9f26e298156db673f6ce2a0f5dfed5b30006e04ceb9809c68070e7b717587b33a3da0f8bc2eda45af81a50bc8b14c82b28ae5832bcfe3e7fd49397117b31
|
|
46
|
+
ENV UAI_AGY_SHA512_ARM64=23c193151499a4986fd5fa0d8132665cc8ffbad6cc0b3ff4fd53a2cb68abb76b149a992b836d53063443cd89add335f14d8134fb02abdcecbf6e1eaef6c53d33
|
|
41
47
|
|
|
42
48
|
# ---------------------------------------------------------------------------
|
|
43
49
|
# 1. System packages.
|
|
@@ -349,6 +355,32 @@ RUN if [ "$INSTALL_OPENCODE" = "1" ]; then \
|
|
|
349
355
|
|| echo "[warn] opencode install failed — opencode engine unavailable in this image"; \
|
|
350
356
|
fi
|
|
351
357
|
|
|
358
|
+
# Antigravity CLI (`agy`, the gemini engine) — one ~246 MB Go binary at
|
|
359
|
+
# /home/node/.local/bin/agy. Pinned build, checksum-verified, self-update off
|
|
360
|
+
# (AGY_CLI_DISABLE_AUTO_UPDATE). Non-fatal like the others.
|
|
361
|
+
ARG INSTALL_GEMINI=0
|
|
362
|
+
RUN if [ "$INSTALL_GEMINI" = "1" ]; then \
|
|
363
|
+
bash -lc 'set -e; \
|
|
364
|
+
case "$(uname -m)" in \
|
|
365
|
+
x86_64|amd64) agy_dir=linux-x64; agy_pkg=cli_linux_x64; agy_sum="$UAI_AGY_SHA512_X64" ;; \
|
|
366
|
+
aarch64|arm64) agy_dir=linux-arm; agy_pkg=cli_linux_arm64; agy_sum="$UAI_AGY_SHA512_ARM64" ;; \
|
|
367
|
+
*) echo "unsupported Antigravity CLI architecture: $(uname -m)" >&2; exit 1 ;; \
|
|
368
|
+
esac; \
|
|
369
|
+
agy_tmp="$(mktemp -d)"; \
|
|
370
|
+
curl -fsSL -o "$agy_tmp/agy.tar.gz" "https://storage.googleapis.com/antigravity-public/antigravity-cli/$UAI_AGY_CLI_BUILD/$agy_dir/$agy_pkg.tar.gz"; \
|
|
371
|
+
echo "$agy_sum $agy_tmp/agy.tar.gz" | sha512sum -c -; \
|
|
372
|
+
tar -xzf "$agy_tmp/agy.tar.gz" -C "$agy_tmp" antigravity; \
|
|
373
|
+
mkdir -p "$HOME/.local/bin"; \
|
|
374
|
+
install -m 0755 "$agy_tmp/antigravity" "$HOME/.local/bin/agy"; \
|
|
375
|
+
rm -rf -- "$agy_tmp"; \
|
|
376
|
+
test "$(AGY_CLI_DISABLE_AUTO_UPDATE=true "$HOME/.local/bin/agy" --version)" = "$UAI_AGY_CLI_VERSION"' \
|
|
377
|
+
|| { \
|
|
378
|
+
rm -f -- "$HOME/.local/bin/agy"; \
|
|
379
|
+
echo "[warn] antigravity cli install failed — gemini engine unavailable in this image"; \
|
|
380
|
+
}; \
|
|
381
|
+
fi
|
|
382
|
+
ENV AGY_CLI_DISABLE_AUTO_UPDATE=true
|
|
383
|
+
|
|
352
384
|
ENV PATH=/home/node/.local/bin:$PATH
|
|
353
385
|
|
|
354
386
|
# ---------------------------------------------------------------------------
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The single per-host workbench image, built once at host startup and cached as
|
|
4
4
|
`moondeck-standard:dev` (ADR-022). Every task reuses it unchanged unless a selected
|
|
5
|
-
|
|
5
|
+
repository declares an [`extra`](../../../docs/runtime.md#the-extra-escape-hatch)
|
|
6
6
|
snippet, in which case task-up derives `uai-task-<id>` FROM this image.
|
|
7
7
|
|
|
8
8
|
See [`docs/runtime.md`](../../../docs/runtime.md) for the authoritative spec.
|
|
@@ -28,9 +28,9 @@ See [`docs/runtime.md`](../../../docs/runtime.md) for the authoritative spec.
|
|
|
28
28
|
pinning a default Node + Python. The `tool-versions` file in this directory is
|
|
29
29
|
the authoritative source for the numbers; the `Dockerfile` `COPY`s it to
|
|
30
30
|
`/home/node/.tool-versions` and installs exactly those versions at build time.
|
|
31
|
-
This guarantees the agent CLIs and a 0-
|
|
31
|
+
This guarantees the agent CLIs and a 0-repository scratchpad always have a
|
|
32
32
|
runtime. asdf uses its default `.tool-versions` filename and walks UP from the
|
|
33
|
-
cwd, so a
|
|
33
|
+
cwd, so a repository's `/workspace/<slug>/.tool-versions` **takes precedence**;
|
|
34
34
|
the home file is only the fallback. (Do **not** set
|
|
35
35
|
`ASDF_DEFAULT_TOOL_VERSIONS_FILENAME` to an absolute path — that overrides the
|
|
36
36
|
search filename and makes asdf ignore per-project files.)
|
|
@@ -47,9 +47,9 @@ See [`docs/runtime.md`](../../../docs/runtime.md) for the authoritative spec.
|
|
|
47
47
|
- **`uai-materialize-runtimes`** baked at
|
|
48
48
|
`/usr/local/bin/uai-materialize-runtimes`; it is the credential-free,
|
|
49
49
|
workspace-read-only shared-cache writer used before Compose starts a task.
|
|
50
|
-
The host supplies the selected
|
|
50
|
+
The host supplies the selected repository slugs at the fixed, read-only
|
|
51
51
|
`/run/uai/runtime-projects` allowlist; only those immediate Git worktrees are
|
|
52
|
-
inspected, so workspace control/shared directories cannot become
|
|
52
|
+
inspected, so workspace control/shared directories cannot become repositories.
|
|
53
53
|
- **`uai-init`** baked at `/usr/local/bin/uai-init`; it installs task-local
|
|
54
54
|
dependencies and starts code-server, but does not mutate asdf runtimes.
|
|
55
55
|
- **Task-private npm globals** under `/home/node/.local/share/uai-npm`, with
|
|
@@ -83,7 +83,7 @@ stale. To build by hand from the repo root:
|
|
|
83
83
|
docker build -t moondeck-standard:dev host-agent/images/standard
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
A derived per-task image (when a
|
|
86
|
+
A derived per-task image (when a repository has `extra`) is built by `task-up`
|
|
87
87
|
from a generated `.uai/Dockerfile` that is `FROM moondeck-standard:dev` plus the
|
|
88
88
|
concatenated `extra` RUN lines, tagged `uai-task-<id>`.
|
|
89
89
|
|
|
@@ -97,7 +97,7 @@ steps below are for local image iteration only.
|
|
|
97
97
|
docker build -t moondeck-standard:dev host-agent/images/standard
|
|
98
98
|
|
|
99
99
|
# 2. Create the shared asdf data volume + a throwaway Git worktree and the
|
|
100
|
-
# host-controlled selected-
|
|
100
|
+
# host-controlled selected-repository allowlist.
|
|
101
101
|
docker volume create moondeck-asdf-data
|
|
102
102
|
mkdir -p /tmp/uai-smoke/workspace/demo/.git
|
|
103
103
|
printf 'nodejs 22.11.0\n' > /tmp/uai-smoke/workspace/demo/.tool-versions
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Standalone Issue attachment commands. All references resolve on the server. */
|
|
2
|
+
export const ISSUE_ATTACHMENTS_CLI_SOURCE = String.raw`
|
|
3
|
+
async function issueAttachmentGet(args) {
|
|
4
|
+
if (args[0] !== "get") issueUsage("attachment get KEY-N ATTACHMENT_ID [-o PATH] [--json]");
|
|
5
|
+
const { flags, positional } = issueFlags(args.slice(1).map(arg => arg === "-o" ? "--output" : arg), ["output", "json"]);
|
|
6
|
+
const key = issueKey(positional.slice(0, 1)), id = positional[1];
|
|
7
|
+
if (positional.length !== 2 || !id || id.length > 128 || id.includes(String.fromCharCode(0)))
|
|
8
|
+
issueUsage("attachment get needs an Issue key and attachment ID");
|
|
9
|
+
const resolved = await api("POST", "/api/agent/issues/" + encodeURIComponent(key) + "/attachments/resolve",
|
|
10
|
+
{ attachmentIds: [id] }, { attachmentAction: "get" });
|
|
11
|
+
const item = resolved.attachments.find(item => item.id === id);
|
|
12
|
+
if (!item || item.state === "no_access") issueUsage("attachment no_access: a human must grant Files read access within the owner's rights; no file downloaded");
|
|
13
|
+
if (item.state === "deleted") issueUsage("attachment file was deleted; no file downloaded");
|
|
14
|
+
if (item.state === "unavailable") issueUsage("attachment unavailable (retryable); retry later. No file downloaded");
|
|
15
|
+
if (item.state !== "available") issueUsage("unknown attachment state; no file downloaded");
|
|
16
|
+
const file = issueAttachmentFile(item.scope + "/" + item.path);
|
|
17
|
+
const dest = flags.output || defaultFilesDest(file.scope, file.path);
|
|
18
|
+
// Reuse Files' fresh authorization, ETag verification, bounded streaming,
|
|
19
|
+
// destination containment and atomic write. Never send the Task token to S3.
|
|
20
|
+
await downloadFile(file.scope, file.path, dest, flags.output === undefined, { remaining: FILES_CAP_BYTES });
|
|
21
|
+
out(flags.json ? { attachmentId: id, path: dest, downloaded: true } : "Downloaded " + id + " to " + dest);
|
|
22
|
+
}
|
|
23
|
+
function issueAttachmentFile(raw) {
|
|
24
|
+
const file = filesTarget(raw);
|
|
25
|
+
if (!file || !file.path || file.path.length > 900 || file.path.includes("\\") || file.path.includes(String.fromCharCode(0)) ||
|
|
26
|
+
file.path.split("/").some((part) => !part || part === "." || part === ".."))
|
|
27
|
+
issueUsage("Files paths must be org/relative/path or me/relative/path (no empty, dot or parent segments)");
|
|
28
|
+
return file;
|
|
29
|
+
}
|
|
30
|
+
async function issueUploadData(path) {
|
|
31
|
+
const limit = 200 * 1024 * 1024;
|
|
32
|
+
let file;
|
|
33
|
+
try {
|
|
34
|
+
file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
35
|
+
const stat = await file.stat();
|
|
36
|
+
if (!stat.isFile()) issueUsage("--upload needs a regular local file");
|
|
37
|
+
if (stat.size > limit) issueUsage("upload exceeds the 200 MiB Files limit");
|
|
38
|
+
const chunks = []; let size = 0;
|
|
39
|
+
for await (const chunk of file.createReadStream({ start: 0, end: limit, autoClose: false })) {
|
|
40
|
+
size += chunk.length;
|
|
41
|
+
if (size > limit) issueUsage("upload exceeds the 200 MiB Files limit");
|
|
42
|
+
chunks.push(chunk);
|
|
43
|
+
}
|
|
44
|
+
return Buffer.concat(chunks);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
issueUsage("cannot upload local file: " + error.message);
|
|
47
|
+
} finally { if (file) await file.close(); }
|
|
48
|
+
}
|
|
49
|
+
function issueAttachmentLine(item, key) {
|
|
50
|
+
if (item.state === "readable") return item.id + " readable (download: issue attachment get " + key + " " + item.id + ") " + item.reference;
|
|
51
|
+
if (item.state === "available") return item.id + " available " + item.scope + "/" + item.path + " " + item.size + " bytes " + item.reference;
|
|
52
|
+
if (item.state === "deleted") return item.id + " deleted " + item.name + " " + item.reference;
|
|
53
|
+
if (item.state === "unavailable") return item.id + " unavailable (retryable; rerun issue attachments later) " + item.reference;
|
|
54
|
+
return item.id + " no_access " + item.reference;
|
|
55
|
+
}
|
|
56
|
+
async function issueAttachmentsCommand(action, args) {
|
|
57
|
+
const { flags, positional } = issueFlags(args, action === "attachments" ? ["json"]
|
|
58
|
+
: action === "attach" ? ["upload", "expected-revision", "json"] : ["expected-revision", "json"]);
|
|
59
|
+
const key = issueKey(positional.slice(0, 1));
|
|
60
|
+
const expected = issueExpectedRevision(flags);
|
|
61
|
+
const upload = flags.upload !== undefined;
|
|
62
|
+
let files, bytes;
|
|
63
|
+
if (action === "attachments" && positional.length !== 1) issueUsage("attachments takes one Issue key");
|
|
64
|
+
if (action === "detach" && (positional.length !== 2 || !positional[1] || positional[1].length > 128 || positional[1].includes(String.fromCharCode(0))))
|
|
65
|
+
issueUsage("detach needs one Issue key and attachment ID");
|
|
66
|
+
if (action === "attach") {
|
|
67
|
+
if (upload && positional.length !== 1) issueUsage("--upload cannot be combined with existing Files paths");
|
|
68
|
+
if (!upload && (positional.length < 2 || positional.length > 21)) issueUsage("attach needs 1–20 Files paths, or --upload LOCAL_PATH");
|
|
69
|
+
if (!upload) {
|
|
70
|
+
files = positional.slice(1).map(issueAttachmentFile);
|
|
71
|
+
if (new Set(files.map(file => JSON.stringify(file))).size !== files.length) issueUsage("duplicate Files paths");
|
|
72
|
+
} else bytes = await issueUploadData(flags.upload);
|
|
73
|
+
}
|
|
74
|
+
const path = "/api/agent/issues/" + encodeURIComponent(key) + "/attachments";
|
|
75
|
+
const context = { attachmentAction: action };
|
|
76
|
+
// This also checks live Issue write and Files admission before uploading.
|
|
77
|
+
const current = await api("GET", path, undefined, context);
|
|
78
|
+
if (action === "attachments") {
|
|
79
|
+
if (current.attachments.length > 100) issueUsage("Cannot resolve more than 100 attachment references per request; an Issue supports at most 100. Rerun issue show to inspect its current revision");
|
|
80
|
+
const resolved = current.attachments.length ? await api("POST", path + "/resolve", {
|
|
81
|
+
attachmentIds: current.attachments.map(item => item.id),
|
|
82
|
+
}, context) : { issueId: current.issueId, revision: current.revision, attachments: [] };
|
|
83
|
+
const references = new Map(current.attachments.map(item => [item.id, item.reference]));
|
|
84
|
+
const result = { ...resolved, attachments: resolved.attachments.map(item => ({ ...item, reference: references.get(item.id) })) };
|
|
85
|
+
if (flags.json) return out(result);
|
|
86
|
+
out("Attachment references for " + key + " (revision " + result.revision + "):");
|
|
87
|
+
return out(result.attachments.length ? result.attachments.map(item => issueAttachmentLine(item, key)).join(NL) : "No attachments.");
|
|
88
|
+
}
|
|
89
|
+
const expectedRevision = expected ?? current.revision;
|
|
90
|
+
if (action === "detach") {
|
|
91
|
+
const result = await api("DELETE", path, { expectedRevision, attachmentIds: [positional[1]] }, context);
|
|
92
|
+
return out(flags.json ? { ...result, fileDeleted: false } : "Detached " + positional[1] + " from " + key + " (unlinked only; file not deleted). Revision: " + result.revision);
|
|
93
|
+
}
|
|
94
|
+
let uploadedFile;
|
|
95
|
+
if (upload) {
|
|
96
|
+
const detail = await api("GET", "/api/agent/issues/" + encodeURIComponent(key), undefined, context);
|
|
97
|
+
if (detail.issue.revision !== expectedRevision) issueUsage("The Issue changed since revision " + expectedRevision + "; nothing uploaded or attached. Rerun issue show and retry with --expected-revision");
|
|
98
|
+
const canonicalKey = issueKey([detail.issue.identifier]);
|
|
99
|
+
const folder = "Issues/" + canonicalKey;
|
|
100
|
+
// Validate org read before writing; attaching needs it even with files.write.
|
|
101
|
+
await api("GET", filesQuery("org", folder), undefined, context);
|
|
102
|
+
// A unique basename avoids replacing an existing Files object or changing
|
|
103
|
+
// the contents of somebody else's reference to the same scoped key.
|
|
104
|
+
uploadedFile = issueAttachmentFile("org/" + folder + "/" + randomUUID() + "-" + basename(flags.upload));
|
|
105
|
+
const uploadedPath = "org/" + uploadedFile.path;
|
|
106
|
+
await api("PUT", "/api/agent/files/content?scope=org&path=" + encodeURIComponent(uploadedFile.path), bytes,
|
|
107
|
+
{ raw: true, uploadPath: uploadedPath });
|
|
108
|
+
files = [uploadedFile];
|
|
109
|
+
context.uploadedPath = uploadedPath;
|
|
110
|
+
}
|
|
111
|
+
const result = await api("POST", path, { expectedRevision, files }, context);
|
|
112
|
+
if (flags.json) return out(uploadedFile ? { ...result, uploadedFile } : result);
|
|
113
|
+
if (uploadedFile) out("Uploaded to Files: org/" + uploadedFile.path);
|
|
114
|
+
out((result.changed ? "Attached " : "Already attached: ") + files.length + " file reference(s) to " + key + ". Revision: " + result.revision);
|
|
115
|
+
for (const item of result.attachments) out(item.id + " " + item.reference);
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** Embedded alongside the Issue commands; all authority stays on the server. */
|
|
2
|
+
export const ISSUE_COMMENTS_CLI_SOURCE = String.raw`
|
|
3
|
+
function issueCommentText(flags) {
|
|
4
|
+
if ((flags.body === undefined) === (flags["body-file"] === undefined))
|
|
5
|
+
issueUsage("comment needs exactly one of --body TEXT or --body-file PATH (use - for stdin)");
|
|
6
|
+
if (flags["body-file"] === "-" && process.stdin.isTTY)
|
|
7
|
+
issueUsage("comment stdin is a terminal; pipe text or use --body-file PATH");
|
|
8
|
+
const text = (flags.body !== undefined ? flags.body : readFlagFile(flags["body-file"])).trim();
|
|
9
|
+
if (!text || text.length > 4000 || text.includes(String.fromCharCode(0)))
|
|
10
|
+
issueUsage("comment body must contain 1–4000 UTF-16 code units after trimming, without NUL; nothing was sent");
|
|
11
|
+
return text;
|
|
12
|
+
}
|
|
13
|
+
async function issueMentionIds(names) {
|
|
14
|
+
if (!names.length) return [];
|
|
15
|
+
const normalize = value => value.trim().replace(/\s+/g, " ").toLowerCase();
|
|
16
|
+
if (names.some(name => !normalize(name))) issueUsage("--mention needs a nonempty member name");
|
|
17
|
+
if (names.length > 50) issueUsage("at most 50 --mention values are allowed");
|
|
18
|
+
const members = new Map(), cursors = new Set();
|
|
19
|
+
let cursor;
|
|
20
|
+
for (let pages = 0; pages < 50; pages++) {
|
|
21
|
+
if (cursor && cursors.has(cursor)) issueUsage("member lookup repeated a cursor; nothing changed. Retry the lookup later");
|
|
22
|
+
if (cursor) cursors.add(cursor);
|
|
23
|
+
const query = new URLSearchParams({ limit: "100" });
|
|
24
|
+
if (cursor) query.set("cursor", cursor);
|
|
25
|
+
const page = await api("GET", "/api/agent/issues/members?" + query);
|
|
26
|
+
for (const member of page.members) members.set(member.userId, member);
|
|
27
|
+
cursor = page.nextCursor;
|
|
28
|
+
if (!cursor) break;
|
|
29
|
+
}
|
|
30
|
+
if (cursor) issueUsage("member lookup exceeded 50 pages; cannot safely resolve names. Nothing was changed");
|
|
31
|
+
return [...new Set(names.map(name => {
|
|
32
|
+
const normalized = normalize(name);
|
|
33
|
+
const exactId = members.get(name.trim());
|
|
34
|
+
const matches = exactId ? [exactId] : [...members.values()].filter(member => normalize(member.name) === normalized);
|
|
35
|
+
if (!matches.length) issueUsage("unknown or unreadable workspace member " + JSON.stringify(name) + "; use a current human member's display name or user ID, not an agent handle. Nothing was changed");
|
|
36
|
+
if (matches.length > 1) issueUsage("ambiguous member " + JSON.stringify(name) + "; use a user ID: " + matches.map(member => member.userId).join(", ") + ". Nothing was changed");
|
|
37
|
+
return matches[0].userId;
|
|
38
|
+
}))];
|
|
39
|
+
}
|
|
40
|
+
async function issueFindComment(key, id) {
|
|
41
|
+
let cursor;
|
|
42
|
+
const cursors = new Set();
|
|
43
|
+
for (let pages = 0; pages < 50; pages++) {
|
|
44
|
+
if (cursor && cursors.has(cursor)) issueUsage("comment history repeated a cursor; rerun issue comments before changing anything");
|
|
45
|
+
if (cursor) cursors.add(cursor);
|
|
46
|
+
const query = new URLSearchParams({ limit: "100" });
|
|
47
|
+
if (cursor) query.set("beforeSeq", String(cursor));
|
|
48
|
+
const page = await api("GET", "/api/agent/issues/" + encodeURIComponent(key) + "/chat?" + query);
|
|
49
|
+
const comment = page.messages.find(message => message.kind === "comment" && message.id === id);
|
|
50
|
+
if (comment) return comment;
|
|
51
|
+
cursor = page.nextBeforeSeq;
|
|
52
|
+
if (cursor == null) return null;
|
|
53
|
+
}
|
|
54
|
+
issueUsage("comment not found in 50 history pages; inspect issue comments before retrying");
|
|
55
|
+
}
|
|
56
|
+
async function issueCommentCommand(args) {
|
|
57
|
+
const action = ["post", "edit", "delete"].includes(args[0]) ? args.shift() : "post";
|
|
58
|
+
const writing = action !== "delete";
|
|
59
|
+
const allowed = ["json", ...(writing ? ["body", "body-file", "mention"] : []),
|
|
60
|
+
...(action !== "post" ? ["expected-revision"] : []), ...(action === "edit" ? ["clear-mentions"] : [])];
|
|
61
|
+
const { flags, positional } = issueFlags(args, allowed, ["json", "clear-mentions"]);
|
|
62
|
+
const key = issueKey(positional.slice(0, 1));
|
|
63
|
+
if (positional.length !== (action === "post" ? 1 : 2)) issueUsage("comment " + action + " needs an Issue key" + (action === "post" ? "" : " and comment ID"));
|
|
64
|
+
const id = positional[1];
|
|
65
|
+
if (id !== undefined && (!id.trim() || id.length > 128 || /[\s/\x00]/.test(id))) issueUsage("invalid comment ID");
|
|
66
|
+
const expected = issueExpectedRevision(flags);
|
|
67
|
+
if (expected !== undefined && expected < 1) issueUsage("comment --expected-revision must be positive (use the comment revision)");
|
|
68
|
+
const text = writing ? issueCommentText(flags) : undefined;
|
|
69
|
+
if (flags["clear-mentions"] && flags.mention) issueUsage("--clear-mentions cannot be combined with --mention");
|
|
70
|
+
const path = "/api/agent/issues/" + encodeURIComponent(key) + "/chat/comments";
|
|
71
|
+
let current;
|
|
72
|
+
if (action !== "post" && (expected === undefined || (action === "edit" && !flags.mention && !flags["clear-mentions"]))) {
|
|
73
|
+
current = await issueFindComment(key, id);
|
|
74
|
+
if (!current) issueUsage("comment not found; nothing changed. Run issue comments --json");
|
|
75
|
+
if (current[action === "edit" ? "canEdit" : "canDelete"] !== true)
|
|
76
|
+
issueUsage("cannot " + action + " this comment: issues.read + issues.write and the same owner, Task and agent are required. A human must grant missing issues.write; removed comments cannot be edited");
|
|
77
|
+
}
|
|
78
|
+
const body = writing ? { text, mentionedUserIds: flags.mention ? await issueMentionIds(flags.mention)
|
|
79
|
+
: action === "edit" && !flags["clear-mentions"] ? current.mentionedUserIds || [] : [] } : {};
|
|
80
|
+
const context = { commentAction: action };
|
|
81
|
+
if (action === "post") {
|
|
82
|
+
body.clientRequestId = randomUUID();
|
|
83
|
+
context.commentRequestId = body.clientRequestId;
|
|
84
|
+
} else {
|
|
85
|
+
body.expectedRevision = expected ?? current.revision;
|
|
86
|
+
context.commentRevision = body.expectedRevision;
|
|
87
|
+
}
|
|
88
|
+
const result = await api(action === "post" ? "POST" : action === "edit" ? "PATCH" : "DELETE",
|
|
89
|
+
path + (id === undefined ? "" : "/" + encodeURIComponent(id)), body, context);
|
|
90
|
+
if (context.transportRetries) {
|
|
91
|
+
// A replay receipt is the original admission, even if it was edited/deleted
|
|
92
|
+
// since. Refresh rather than claiming that original body is still current.
|
|
93
|
+
console.error("Comment accepted (clientRequestId " + body.clientRequestId + "). Refreshing history after the transport retry; receipt revision may be historical.");
|
|
94
|
+
result.currentComment = await issueFindComment(key, result.id);
|
|
95
|
+
if (!result.currentComment) console.error("Accepted comment is absent from current history; inspect issue comments --json before taking further action.");
|
|
96
|
+
}
|
|
97
|
+
if (flags.json) return out(result);
|
|
98
|
+
out((action === "post" ? "Comment accepted: " : action === "edit" ? "Comment edited: " : "Comment removed (placeholder retained): ") + result.id +
|
|
99
|
+
" (comment revision " + (result.currentComment?.revision ?? result.revision) + ")" + (result.clientRequestId ? "; clientRequestId " + result.clientRequestId : ""));
|
|
100
|
+
if (result.currentComment) out("Current: " + result.currentComment.actor.name + " — " +
|
|
101
|
+
(result.currentComment.deletedAt != null ? "Message removed" : result.currentComment.body));
|
|
102
|
+
}
|
|
103
|
+
`;
|